Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp9104304imu; Tue, 4 Dec 2018 21:50:51 -0800 (PST) X-Google-Smtp-Source: AFSGD/WXvRI4lkbiN8mExQL50TElgqt73LEadFpl1enQ7q+LmVg8rZAYXhldKiFCXTwsu1NyXmV2 X-Received: by 2002:a63:cb4a:: with SMTP id m10mr18504763pgi.105.1543989051371; Tue, 04 Dec 2018 21:50:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543989051; cv=none; d=google.com; s=arc-20160816; b=PXTJgvVfjR+bGIG4G6mnFLiqwdlOOWAk+Elktr/lbkd198GWPNs8RsXK3UyUZo+qYy fa+6eMfQVhF+ht0uu0G/fQjeRyfgL8du6g209gb55vskhBTZ+/lW4+/4hQixRBx9nhw6 xAU/uj46H4xHFITh3rdogH4dSzOTn/Rw0x1Hv8PObNj5GsPC0nwEYB+DU60x6tRg/db/ +hrRh0WLOuq+i8jblVNGw+W1m0QlXzBPCE1ARWPOoFIaL0NA68Eom0wYev0GqI6HP342 FVQgcoOYNtfZkPUZFFk5O9rcVFxfziyvIdQ1f4YKYPjXn52ZIziBwzFOYxhcPkHNnrcE D51g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Mtj+5lLpDKXzv34oRdlikvP0Q/L3pkB7CbeDcaUQ2ak=; b=YRIV5M4Q32Q8obNMSYjZbzfK0nLSpYdBPamgmwjEtbnOkOtOLjAfgl+5A5IZ/4tpBm uJzlLdJnQgUTlRaYQfuS0OKbBogkh4j24H6OLQVdrwa4BrZU9tkWN1LJRkG15gNsXoFk SK4WTp+rfncmZ7mxHrLyK+W9BMsSPTvOYPPD3Dpqm5g7w6knSX8xlDr7EjUdvRLnw+HY /5Nnk777xxEqykGVXdX9RL3AJKnQq7Rtpq4FVO0QQehz3rPPuMqKt6C4v4XIqZ+q+AJQ oH2czMTleFQxxmqknOOjOTm+d+1gIJxzftcuwbz4yx1amczUXKu7azdgi4IrH/CbsJj5 Xm9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=RJSBonDD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q20si17434549pgl.268.2018.12.04.21.50.36; Tue, 04 Dec 2018 21:50:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=RJSBonDD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727029AbeLEFsw (ORCPT + 99 others); Wed, 5 Dec 2018 00:48:52 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:40554 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726092AbeLEFsu (ORCPT ); Wed, 5 Dec 2018 00:48:50 -0500 Received: by mail-pf1-f195.google.com with SMTP id i12so9443654pfo.7 for ; Tue, 04 Dec 2018 21:48:50 -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=Mtj+5lLpDKXzv34oRdlikvP0Q/L3pkB7CbeDcaUQ2ak=; b=RJSBonDDmVEWs69m9HOjZuGuqOpCHmEu3NrRrK9BUoJUXpNKmfFBa/K9sBDN9HQqGh 2ZMUshSZxpFyy3R/xn0fNdnzD/OwClqvrwVW7yxt56sC7V8w/aBqcc+M6P6ZdmJBInbV xpbXCfLfeacU+cokjOF3Z/mV3EHPLT5eakXq4= 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=Mtj+5lLpDKXzv34oRdlikvP0Q/L3pkB7CbeDcaUQ2ak=; b=QKr5tUt5vXDG0Ofzf7Tqs0kcrPJSn2IGCpy7dHDsfK7xEpwtLZI2O8ktDeb6eNagFe 6DBByPMbjya7g8LDGQMluEVnCUGuTamaxIp2LmISwyjPYN1FYP4ZsJZm5YQnwAVeRxOO 3CdiD51m1n2eqToKs1S1DpYUbNDNFeA+5RcIUkCzhzV5DcH7OON8F5FIkd5O7F2vunsB mrbK52UpBT6Lq9mGoX0GUFTVQlJyTHtfkAjcv7bnI2oRmsEszdmoEwC8ME5w0f5/wBfL s2/K22Su1EyqP72VtqOSp945rqexyuyLUeDrAID5KEYnK5KuFUIAVdBj1Uf25FfZ9+YN daaQ== X-Gm-Message-State: AA+aEWan/COISHzlMLTYkF4Hht2p7S3lErFjO3NJP1wNN/cHHtOG781m e3GW3ztGzE/zdbPMEYoA7Hyy1g== X-Received: by 2002:a62:7dcb:: with SMTP id y194mr23238987pfc.113.1543988930153; Tue, 04 Dec 2018 21:48:50 -0800 (PST) Received: from drinkcat2.tpe.corp.google.com ([2401:fa00:1:b:f659:7f17:ea11:4e8e]) by smtp.gmail.com with ESMTPSA id 4sm30806513pfq.10.2018.12.04.21.48.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Dec 2018 21:48:49 -0800 (PST) From: Nicolas Boichat To: Will Deacon Cc: Robin Murphy , Joerg Roedel , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Michal Hocko , Mel Gorman , Levin Alexander , Huaisheng Ye , Mike Rapoport , linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Yong Wu , Matthias Brugger , Tomasz Figa , yingjoe.chen@mediatek.com, hch@infradead.org, Matthew Wilcox Subject: [PATCH v4 1/3] mm: slab/slub: Add check_slab_flags function to check for valid flags Date: Wed, 5 Dec 2018 13:48:26 +0800 Message-Id: <20181205054828.183476-2-drinkcat@chromium.org> X-Mailer: git-send-email 2.20.0.rc1.387.gf8505762e3-goog In-Reply-To: <20181205054828.183476-1-drinkcat@chromium.org> References: <20181205054828.183476-1-drinkcat@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 18 ++++++++++++++++-- mm/slab.c | 8 +------- mm/slub.c | 8 +------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index f0c9ccde3bdb9e..a2ee82a0cd44ae 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 73fe23e649c91a..65a774f05e7836 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -2643,13 +2643,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 c229a9b7dd5448..21a3f6866da472 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1685,13 +1685,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); -- 2.20.0.rc1.387.gf8505762e3-goog