From patchwork Sun Nov 11 09:03:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Boichat X-Patchwork-Id: 10677533 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BD8E914E2 for ; Sun, 11 Nov 2018 09:04:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD5392B08D for ; Sun, 11 Nov 2018 09:04:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A10562B098; Sun, 11 Nov 2018 09:04:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1D4912B08D for ; Sun, 11 Nov 2018 09:04:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pxjYwl0N1LZ9racUdcI94FTABXgqViDMX4kdSTYshmE=; b=PnVKm1VbdBwC6s hoI0O/7zEC7/wIbLBRzmqqDSdvexmHEdESsJsRa0Px9Z94X4Hq276fmOSYrQTr6AYnfaR7E8Y8aBk dFbpDuqqC782KWrJpgBWBz8zlOJTRbnDl11r74Ho1B+FjOIIS1HNgwiuM28qs1aaegBm8vmS2T7S4 /iGtkxnZRZhT4u4uQphSsi3JmJr+kO9XbR7tzaxZQayl/AykeHiQcr2Pw4rEhn3N+ue+ZZiCglgOu YiZkh0efX28889VCFRg6UOmq+onsNAcLgNkNupsV5JQPGZjpGt9bb81HYAivF8RH+03rw4pErVnW3 l6ELLYsSSRVnHBfMcyTA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gLlfX-0005SD-9N; Sun, 11 Nov 2018 09:04:35 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gLlfF-00052l-TF for linux-arm-kernel@lists.infradead.org; Sun, 11 Nov 2018 09:04:19 +0000 Received: by mail-pg1-x543.google.com with SMTP id 70so2691590pgh.8 for ; Sun, 11 Nov 2018 01:04:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tHCTBgMG+6sJtZR5onayP64SmgPAtqMgziPQMQVZWKM=; b=l7Tlciw4q3K/mse2HceMtZDnrFM6ck6HToUmTsxs8jqxQdGLn9fB6x8w53HsMNvnTH RnBzgCGqDhuWKFO2CQ9TnefxUQWJI887Ol18UPHXQRc6lSN2Sh2R6hpIxxjJ+4jlSsKA FUktM+/wIwGDOTQ3nu7H7NgmdVXxlN0Iya5bc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tHCTBgMG+6sJtZR5onayP64SmgPAtqMgziPQMQVZWKM=; b=UyG5X6jLygN8SksDfDrttwtgDL6LJYqWC8BN9bvaSg9vaRkDibDiX9CHS0bWry8yn1 pXn661+pT2L6cOAe22ibsKLMnveE+nJ0Vz9jFjfo/iBQT8davKqrQPQWE3H6wgTN9cli n+trcqwqFYhdsKdFtK6wXKxFo3ZVuVynsAHKP9Kxc06SLGXr/7GWkRkvJ4W+XGOU5BfT kZpdy9VseeYXCiadrPlXiR+KFlqKSJDLAa1tSTDuTYqVsBJrR8CEtEobIiULI4BRiUD/ 90zMBlKlvnf/h/dVGcDJADqigxH2TiozUDqKYZdo1y+cdtwQMNOQj+K84i+LEUiWTEPk n9gg== X-Gm-Message-State: AGRZ1gLyr1xJw0iLaflDyj1GbjL0kRsf/a0t7FoCOcBUSAHeX0TF2mH1 D5esNnArujmHIqUXhYvZmjPFog== X-Google-Smtp-Source: AJdET5fqOgcNWbxIYJn57HFqDYGS+E0e9yJHKY4fkrYGQEuWX7H6W4a2yVrcs3FVlRHmJiNJMxoaDA== X-Received: by 2002:a63:920a:: with SMTP id o10mr13137383pgd.141.1541927046794; Sun, 11 Nov 2018 01:04:06 -0800 (PST) Received: from drinkcat2.tpe.corp.google.com ([2401:fa00:1:b:f659:7f17:ea11:4e8e]) by smtp.gmail.com with ESMTPSA id 69sm8107956pgg.86.2018.11.11.01.04.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Nov 2018 01:04:06 -0800 (PST) From: Nicolas Boichat To: Robin Murphy Subject: [PATCH v2 1/3] mm: slab/slub: Add check_slab_flags function to check for valid flags Date: Sun, 11 Nov 2018 17:03:39 +0800 Message-Id: <20181111090341.120786-2-drinkcat@chromium.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: <20181111090341.120786-1-drinkcat@chromium.org> References: <20181111090341.120786-1-drinkcat@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181111_010417_958775_06E6E6B2 X-CRM114-Status: GOOD ( 15.50 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Levin Alexander , Michal Hocko , Andrew Morton , Huaisheng Ye , Tomasz Figa , Joerg Roedel , Will Deacon , linux-kernel@vger.kernel.org, Pekka Enberg , linux-mm@kvack.org, iommu@lists.linux-foundation.org, Mike Rapoport , linux-arm-kernel@lists.infradead.org, David Rientjes , Matthias Brugger , yingjoe.chen@mediatek.com, Joonsoo Kim , Yong Wu , Mel Gorman , Christoph Lameter , Vlastimil Babka Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Remove duplicated code between slab and slub, and will make it easier to make the test more complicated in the next commits. Fixes: ad67f5a6545f ("arm64: replace ZONE_DMA with ZONE_DMA32") Signed-off-by: Nicolas Boichat --- mm/internal.h | 17 +++++++++++++++-- mm/slab.c | 8 +------- mm/slub.c | 8 +------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 3b1ec1412fd2cd..7a500b232e4a43 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -33,8 +33,22 @@ /* Control allocation cpuset and node placement constraints */ #define GFP_CONSTRAINT_MASK (__GFP_HARDWALL|__GFP_THISNODE) -/* Do not use these with a slab allocator */ -#define GFP_SLAB_BUG_MASK (__GFP_DMA32|__GFP_HIGHMEM|~__GFP_BITS_MASK) +/* Check for flags that must not be used with a slab allocator */ +static inline gfp_t check_slab_flags(gfp_t flags) +{ + gfp_t bug_mask = __GFP_DMA32 | __GFP_HIGHMEM | ~__GFP_BITS_MASK; + + if (unlikely(flags & bug_mask)) { + gfp_t invalid_mask = flags & bug_mask; + + flags &= ~bug_mask; + pr_warn("Unexpected gfp: %#x (%pGg). Fixing up to gfp: %#x (%pGg). Fix your code!\n", + invalid_mask, &invalid_mask, flags, &flags); + dump_stack(); + } + + return flags; +} void page_writeback_init(void); diff --git a/mm/slab.c b/mm/slab.c index 2a5654bb3b3ff3..251e09a5a3ef5c 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -2656,13 +2656,7 @@ static struct page *cache_grow_begin(struct kmem_cache *cachep, * Be lazy and only check for valid flags here, keeping it out of the * critical path in kmem_cache_alloc(). */ - if (unlikely(flags & GFP_SLAB_BUG_MASK)) { - gfp_t invalid_mask = flags & GFP_SLAB_BUG_MASK; - flags &= ~GFP_SLAB_BUG_MASK; - pr_warn("Unexpected gfp: %#x (%pGg). Fixing up to gfp: %#x (%pGg). Fix your code!\n", - invalid_mask, &invalid_mask, flags, &flags); - dump_stack(); - } + flags = check_slab_flags(flags); WARN_ON_ONCE(cachep->ctor && (flags & __GFP_ZERO)); local_flags = flags & (GFP_CONSTRAINT_MASK|GFP_RECLAIM_MASK); diff --git a/mm/slub.c b/mm/slub.c index e3629cd7aff164..1cca562bebdc8d 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1681,13 +1681,7 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node) static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node) { - if (unlikely(flags & GFP_SLAB_BUG_MASK)) { - gfp_t invalid_mask = flags & GFP_SLAB_BUG_MASK; - flags &= ~GFP_SLAB_BUG_MASK; - pr_warn("Unexpected gfp: %#x (%pGg). Fixing up to gfp: %#x (%pGg). Fix your code!\n", - invalid_mask, &invalid_mask, flags, &flags); - dump_stack(); - } + flags = check_slab_flags(flags); return allocate_slab(s, flags & (GFP_RECLAIM_MASK | GFP_CONSTRAINT_MASK), node); From patchwork Sun Nov 11 09:03:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Boichat X-Patchwork-Id: 10677535 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A731B13AD for ; Sun, 11 Nov 2018 09:04:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 924422B08D for ; Sun, 11 Nov 2018 09:04:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 824F42B09E; Sun, 11 Nov 2018 09:04:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 739562B08D for ; Sun, 11 Nov 2018 09:04:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=nUPoYC76hvLwrh6KJhjXJn8+cnCiNWOGKi6QFn5NSTg=; b=s4On6wZ1v01+oB 09eTsRf+Uw6MGJxVsOo7Bem4zqjHQ+63GUJyJ0ZI+iGIpHgPmjYl/jV8BxI1dp7mO2a6ghGQM9Ezr RN3k5J7JFqIDnzvZQ5NNKbyeBaaxoGOyNLDeAabSZws0KLQxgGP+iQy/n5xFZuNWjZVt+L8JB99/M XJIyyw3tH4xhQDA4crs1p687KAB9IdyuU9/LmykDyfK1vUi3eINDjZx6/hHwbSlTKySMn70hPb+kU GbmB+3ie8jIgAB4LtIZBB6YAvZULYTzum2Korz+hwl6Oky3sxUvxASooYP/eIH7vi7rPVam9ROURk ZbPuSeptz/zc8ORI+sGQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gLlfj-0005kS-Ft; Sun, 11 Nov 2018 09:04:47 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gLlfJ-00052m-AU for linux-arm-kernel@lists.infradead.org; Sun, 11 Nov 2018 09:04:22 +0000 Received: by mail-pg1-x541.google.com with SMTP id w3-v6so2682439pgs.11 for ; Sun, 11 Nov 2018 01:04:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KPUtoMHx+zKgWw/50SWdFRpPElnQtOmRn5WZTUEVzYs=; b=eF3UiDtKNpGLH8WDQRLmzM+lV68Qvk9qt98jNj/eWRr7yTj7wjQWF1pKGRyZXBAlGQ 5fjUfzRE3brXvb77u6LrT66F3nBShPfa2Rju+ADlBiwz33Qo7SW4AaTP/CLlzen61UU9 040zOTA/bUzkYsIGgDps0XsOwB+8LXkf0POOw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KPUtoMHx+zKgWw/50SWdFRpPElnQtOmRn5WZTUEVzYs=; b=c82q5yO6Ej6cIJ2ZfYBpbDgO4sQwlR1G9ELB3c53jPBotmUKBc+vZbRuXyP2/giaqu lUjBEHM+4a5HbY18EQnbl+Ry2tnbFqbEUSl47UnHzml+5n6k0Ys3wKm0Tvart/BN5g6U 9gBksGhydWUUbnzaIQ2So5/07Wxr3FbBNViN1R8fg+cCM2saei011qkDYKCl3crC0Oig oCAwY92UGp0FlZs+07Wp7R6b0BOtCEeDtqtWDkcGOGl44/YobJzy++Ps8LB8SfgTGJFW G0F1lCs17qB11oFHfXBWFK8Win0fAQS/0gCmWGjGYTW1FTrX73f6ygSZ60Z+NTa4rqss hBIw== X-Gm-Message-State: AGRZ1gKaW7ODUhyvcPRl4lXxxQ2cS+PT38eQRttsxeaTFHliW54aIQFR AGbYXoadQ5XUQFIyvJL89xkp6Q== X-Google-Smtp-Source: AJdET5f/RljYx3hHMrWqmXXwAtzTLJd4Rp8hdBqNgeWi6cSE9Td3CGTMfaHibnnZLHGJsOXrRRNlZQ== X-Received: by 2002:a63:9a52:: with SMTP id e18mr13479722pgo.14.1541927050533; Sun, 11 Nov 2018 01:04:10 -0800 (PST) Received: from drinkcat2.tpe.corp.google.com ([2401:fa00:1:b:f659:7f17:ea11:4e8e]) by smtp.gmail.com with ESMTPSA id 69sm8107956pgg.86.2018.11.11.01.04.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Nov 2018 01:04:09 -0800 (PST) From: Nicolas Boichat To: Robin Murphy Subject: [PATCH v2 2/3] mm: Add support for SLAB_CACHE_DMA32 Date: Sun, 11 Nov 2018 17:03:40 +0800 Message-Id: <20181111090341.120786-3-drinkcat@chromium.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: <20181111090341.120786-1-drinkcat@chromium.org> References: <20181111090341.120786-1-drinkcat@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181111_010421_372437_941AEDB1 X-CRM114-Status: GOOD ( 18.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Levin Alexander , Michal Hocko , Andrew Morton , Huaisheng Ye , Tomasz Figa , Joerg Roedel , Will Deacon , linux-kernel@vger.kernel.org, Pekka Enberg , linux-mm@kvack.org, iommu@lists.linux-foundation.org, Mike Rapoport , linux-arm-kernel@lists.infradead.org, David Rientjes , Matthias Brugger , yingjoe.chen@mediatek.com, Joonsoo Kim , Yong Wu , Mel Gorman , Christoph Lameter , Vlastimil Babka Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP SLAB_CACHE_DMA32 is only available after explicit kmem_cache_create calls, no default cache is created for kmalloc. Add a test in check_slab_flags for this. Fixes: ad67f5a6545f ("arm64: replace ZONE_DMA with ZONE_DMA32") Signed-off-by: Nicolas Boichat --- include/linux/slab.h | 2 ++ mm/internal.h | 8 ++++++-- mm/slab.c | 4 +++- mm/slab.h | 3 ++- mm/slab_common.c | 2 +- mm/slub.c | 18 +++++++++++++++++- 6 files changed, 31 insertions(+), 6 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 918f374e7156f4..afc51ee1dae5d4 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -32,6 +32,8 @@ #define SLAB_HWCACHE_ALIGN ((slab_flags_t __force)0x00002000U) /* Use GFP_DMA memory */ #define SLAB_CACHE_DMA ((slab_flags_t __force)0x00004000U) +/* Use GFP_DMA32 memory */ +#define SLAB_CACHE_DMA32 ((slab_flags_t __force)0x00008000U) /* DEBUG: Store the last owner for bug hunting */ #define SLAB_STORE_USER ((slab_flags_t __force)0x00010000U) /* Panic if kmem_cache_create() fails */ diff --git a/mm/internal.h b/mm/internal.h index 7a500b232e4a43..2aa9c8491d2ca2 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -14,6 +14,7 @@ #include #include #include +#include #include /* @@ -34,9 +35,12 @@ #define GFP_CONSTRAINT_MASK (__GFP_HARDWALL|__GFP_THISNODE) /* Check for flags that must not be used with a slab allocator */ -static inline gfp_t check_slab_flags(gfp_t flags) +static inline gfp_t check_slab_flags(gfp_t flags, slab_flags_t slab_flags) { - gfp_t bug_mask = __GFP_DMA32 | __GFP_HIGHMEM | ~__GFP_BITS_MASK; + gfp_t bug_mask = __GFP_HIGHMEM | ~__GFP_BITS_MASK; + + if (!IS_ENABLED(CONFIG_ZONE_DMA32) || !(slab_flags & SLAB_CACHE_DMA32)) + bug_mask |= __GFP_DMA32; if (unlikely(flags & bug_mask)) { gfp_t invalid_mask = flags & bug_mask; diff --git a/mm/slab.c b/mm/slab.c index 251e09a5a3ef5c..6efcaad6a02b70 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -2122,6 +2122,8 @@ int __kmem_cache_create(struct kmem_cache *cachep, slab_flags_t flags) cachep->allocflags = __GFP_COMP; if (flags & SLAB_CACHE_DMA) cachep->allocflags |= GFP_DMA; + if (flags & SLAB_CACHE_DMA32) + cachep->allocflags |= GFP_DMA32; if (flags & SLAB_RECLAIM_ACCOUNT) cachep->allocflags |= __GFP_RECLAIMABLE; cachep->size = size; @@ -2656,7 +2658,7 @@ static struct page *cache_grow_begin(struct kmem_cache *cachep, * Be lazy and only check for valid flags here, keeping it out of the * critical path in kmem_cache_alloc(). */ - flags = check_slab_flags(flags); + flags = check_slab_flags(flags, cachep->flags); WARN_ON_ONCE(cachep->ctor && (flags & __GFP_ZERO)); local_flags = flags & (GFP_CONSTRAINT_MASK|GFP_RECLAIM_MASK); diff --git a/mm/slab.h b/mm/slab.h index 58c6c1c2a78ee3..9632772e14beb2 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -127,7 +127,8 @@ static inline slab_flags_t kmem_cache_flags(unsigned int object_size, /* Legal flag mask for kmem_cache_create(), for various configurations */ -#define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \ +#define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | \ + SLAB_CACHE_DMA32 | SLAB_PANIC | \ SLAB_TYPESAFE_BY_RCU | SLAB_DEBUG_OBJECTS ) #if defined(CONFIG_DEBUG_SLAB) diff --git a/mm/slab_common.c b/mm/slab_common.c index 7eb8dc136c1cb8..f204385553bbac 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -53,7 +53,7 @@ static DECLARE_WORK(slab_caches_to_rcu_destroy_work, SLAB_FAILSLAB | SLAB_KASAN) #define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | \ - SLAB_ACCOUNT) + SLAB_CACHE_DMA32 | SLAB_ACCOUNT) /* * Merge control. If this is set then no merging of slab caches will occur. diff --git a/mm/slub.c b/mm/slub.c index 1cca562bebdc8d..c639bd008e8c11 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1681,7 +1681,7 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node) static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node) { - flags = check_slab_flags(flags); + flags = check_slab_flags(flags, s->flags); return allocate_slab(s, flags & (GFP_RECLAIM_MASK | GFP_CONSTRAINT_MASK), node); @@ -3571,6 +3571,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order) if (s->flags & SLAB_CACHE_DMA) s->allocflags |= GFP_DMA; + if (s->flags & SLAB_CACHE_DMA32) + s->allocflags |= GFP_DMA32; + if (s->flags & SLAB_RECLAIM_ACCOUNT) s->allocflags |= __GFP_RECLAIMABLE; @@ -5090,6 +5093,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf) SLAB_ATTR_RO(cache_dma); #endif +#ifdef CONFIG_ZONE_DMA32 +static ssize_t cache_dma32_show(struct kmem_cache *s, char *buf) +{ + return sprintf(buf, "%d\n", !!(s->flags & SLAB_CACHE_DMA32)); +} +SLAB_ATTR_RO(cache_dma32); +#endif + static ssize_t usersize_show(struct kmem_cache *s, char *buf) { return sprintf(buf, "%u\n", s->usersize); @@ -5430,6 +5441,9 @@ static struct attribute *slab_attrs[] = { #ifdef CONFIG_ZONE_DMA &cache_dma_attr.attr, #endif +#ifdef CONFIG_ZONE_DMA32 + &cache_dma32_attr.attr, +#endif #ifdef CONFIG_NUMA &remote_node_defrag_ratio_attr.attr, #endif @@ -5660,6 +5674,8 @@ static char *create_unique_id(struct kmem_cache *s) */ if (s->flags & SLAB_CACHE_DMA) *p++ = 'd'; + if (s->flags & SLAB_CACHE_DMA32) + *p++ = 'D'; if (s->flags & SLAB_RECLAIM_ACCOUNT) *p++ = 'a'; if (s->flags & SLAB_CONSISTENCY_CHECKS) From patchwork Sun Nov 11 09:03:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Boichat X-Patchwork-Id: 10677531 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4726413AD for ; Sun, 11 Nov 2018 09:04:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 376652B08D for ; Sun, 11 Nov 2018 09:04:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 294F72B098; Sun, 11 Nov 2018 09:04:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D07A42B08D for ; Sun, 11 Nov 2018 09:04:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LhKNcdr2bMBZKHlC1V3F7acMV/VV9e83lzIMFduFdq0=; b=B530DuBVLUUQKx LlbZzJltvVVmuwQwqk7+DWdDwhZiiBT1zkvTLZ108DPKrxf4eb10WYPpyIfSARKXcwekNzlXOUUTl 71FMSPLBWt9xn/CMLQnTlRM6+P8emuuOjsMaHJaqlx11xJgwuCCnPStqb7kdLDY7CHm5MhuWTKrnJ 3C1AN+6NfVaOSNeJx3euDm8LU0yVdsJZA2y9ttUPIeFKzzqeq7pxtHu4PR3kkDEu+A4KEZfuS2WfH J5aHj/zTI4jw/wtphvOfKRubmAyp24LTSkUR097YkOUqGIQmqQV9ADbe5wWjVsjpw6joxy9MlDev8 fztqW4pKNIStMkE02P6w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gLlfN-0005CH-Ag; Sun, 11 Nov 2018 09:04:25 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gLlfF-00052n-T8 for linux-arm-kernel@lists.infradead.org; Sun, 11 Nov 2018 09:04:19 +0000 Received: by mail-pg1-x543.google.com with SMTP id 70so2691663pgh.8 for ; Sun, 11 Nov 2018 01:04:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J3drSXNEQad/j7zI+ID7YdbI6KhfStGY6vScO313iR4=; b=DcjG9kTDXB4SQ7VqcCMrX/L11oHaZNfPg9bG1SMflAXtx7Sdu1dqaoGyXOCoJ27tqZ TXk+rgHoUJbj9EsRYITf58Qh9ZhpgwOmxbxRHsI9hfkN3Wuw3up8qbfLy+xDMg7VZc+c e1b6fwI4rwon3DJdb6ZCA5AYTpsyukkQJdy20= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=J3drSXNEQad/j7zI+ID7YdbI6KhfStGY6vScO313iR4=; b=O1myplMWT8YGbzat9Z/2+rFElXTISEsNLcoLcSaUmZJtE5igU/4pZeijGuL91hoZIV bBaIgU5KYLRwl0uvqix40aVPoEWbrQO1p0NXqGRnutF7sJUn8mB/cgwhr49omkK7uZ5m 5xxVGuhpF7Qha1KlwV5SqCybJ2a6KRQfkYLWTWaCoKNGB0n52aWRoK6nx8CzQv3vYH+J tiC8fmfkEb/bBNOYO+mF4R/GoOXWM6Y7fO3dVGhewQ8NCxuAObwAHWEst4MoHqiIMWd6 4xcrHik43Vy9cUmjGRLOOx5MutRDjI5n/GgtT6fdlcNC9DSP1L+kcsAyZdCg5O1+fEvC AjVw== X-Gm-Message-State: AGRZ1gIbABNaBNxXEMHV2bBDQjZXSZOUaCZHRdpMbm4ydYezEUx1t8s4 FjMukmPRMh8IH3OHZJ+85qVb7g== X-Google-Smtp-Source: AJdET5d2kWGbhQDjOrVfaAjb6eaSaPcg2FtnCOnFt4V3Lsv/PQqo/3P8/Z+UfUKpHSPr81IYnMgzzw== X-Received: by 2002:a63:f141:: with SMTP id o1mr13637587pgk.134.1541927054240; Sun, 11 Nov 2018 01:04:14 -0800 (PST) Received: from drinkcat2.tpe.corp.google.com ([2401:fa00:1:b:f659:7f17:ea11:4e8e]) by smtp.gmail.com with ESMTPSA id 69sm8107956pgg.86.2018.11.11.01.04.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Nov 2018 01:04:13 -0800 (PST) From: Nicolas Boichat To: Robin Murphy Subject: [PATCH v2 3/3] iommu/io-pgtable-arm-v7s: Request DMA32 memory, and improve debugging Date: Sun, 11 Nov 2018 17:03:41 +0800 Message-Id: <20181111090341.120786-4-drinkcat@chromium.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: <20181111090341.120786-1-drinkcat@chromium.org> References: <20181111090341.120786-1-drinkcat@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181111_010417_946246_005B5E2B X-CRM114-Status: GOOD ( 16.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Levin Alexander , Michal Hocko , Andrew Morton , Huaisheng Ye , Tomasz Figa , Joerg Roedel , Will Deacon , linux-kernel@vger.kernel.org, Pekka Enberg , linux-mm@kvack.org, iommu@lists.linux-foundation.org, Mike Rapoport , linux-arm-kernel@lists.infradead.org, David Rientjes , Matthias Brugger , yingjoe.chen@mediatek.com, Joonsoo Kim , Yong Wu , Mel Gorman , Christoph Lameter , Vlastimil Babka Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP For level 1/2 pages, ensure GFP_DMA32 is used if CONFIG_ZONE_DMA32 is defined (e.g. on arm64 platforms). For level 2 pages, allocate a slab cache in SLAB_CACHE_DMA32. Also, print an error when the physical address does not fit in 32-bit, to make debugging easier in the future. Fixes: ad67f5a6545f ("arm64: replace ZONE_DMA with ZONE_DMA32") Signed-off-by: Nicolas Boichat --- Changes since v1: - Changed approach to use SLAB_CACHE_DMA32 added by the previous commit. - Use DMA or DMA32 depending on the architecture (DMA for arm, DMA32 for arm64). drivers/iommu/io-pgtable-arm-v7s.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/io-pgtable-arm-v7s.c b/drivers/iommu/io-pgtable-arm-v7s.c index 445c3bde04800c..996f7b6d00b44a 100644 --- a/drivers/iommu/io-pgtable-arm-v7s.c +++ b/drivers/iommu/io-pgtable-arm-v7s.c @@ -161,6 +161,14 @@ #define ARM_V7S_TCR_PD1 BIT(5) +#ifdef CONFIG_ZONE_DMA32 +#define ARM_V7S_TABLE_GFP_DMA GFP_DMA32 +#define ARM_V7S_TABLE_SLAB_CACHE SLAB_CACHE_DMA32 +#else +#define ARM_V7S_TABLE_GFP_DMA GFP_DMA +#define ARM_V7S_TABLE_SLAB_CACHE SLAB_CACHE_DMA +#endif + typedef u32 arm_v7s_iopte; static bool selftest_running; @@ -198,13 +206,17 @@ static void *__arm_v7s_alloc_table(int lvl, gfp_t gfp, void *table = NULL; if (lvl == 1) - table = (void *)__get_dma_pages(__GFP_ZERO, get_order(size)); + table = (void *)__get_free_pages( + __GFP_ZERO | ARM_V7S_TABLE_GFP_DMA, get_order(size)); else if (lvl == 2) - table = kmem_cache_zalloc(data->l2_tables, gfp | GFP_DMA); + table = kmem_cache_zalloc(data->l2_tables, + gfp | ARM_V7S_TABLE_GFP_DMA); phys = virt_to_phys(table); - if (phys != (arm_v7s_iopte)phys) + if (phys != (arm_v7s_iopte)phys) { /* Doesn't fit in PTE */ + dev_err(dev, "Page table does not fit in PTE: %pa", &phys); goto out_free; + } if (table && !(cfg->quirks & IO_PGTABLE_QUIRK_NO_DMA)) { dma = dma_map_single(dev, table, size, DMA_TO_DEVICE); if (dma_mapping_error(dev, dma)) @@ -737,7 +749,7 @@ static struct io_pgtable *arm_v7s_alloc_pgtable(struct io_pgtable_cfg *cfg, data->l2_tables = kmem_cache_create("io-pgtable_armv7s_l2", ARM_V7S_TABLE_SIZE(2), ARM_V7S_TABLE_SIZE(2), - SLAB_CACHE_DMA, NULL); + ARM_V7S_TABLE_SLAB_CACHE, NULL); if (!data->l2_tables) goto out_free_data;