From patchwork Wed Dec 5 05:48:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Boichat X-Patchwork-Id: 10713013 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 C309F157A for ; Wed, 5 Dec 2018 05:48:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B13672C884 for ; Wed, 5 Dec 2018 05:48:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A38C32C8B2; Wed, 5 Dec 2018 05:48:53 +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.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F5462C884 for ; Wed, 5 Dec 2018 05:48:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B3D36B72C7; Wed, 5 Dec 2018 00:48:52 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2627B6B72C8; Wed, 5 Dec 2018 00:48:52 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12B1F6B72C9; Wed, 5 Dec 2018 00:48:52 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id C4CB06B72C7 for ; Wed, 5 Dec 2018 00:48:51 -0500 (EST) Received: by mail-pf1-f199.google.com with SMTP id s14so15930043pfk.16 for ; Tue, 04 Dec 2018 21:48:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Mtj+5lLpDKXzv34oRdlikvP0Q/L3pkB7CbeDcaUQ2ak=; b=RkcdlerUxX6lTwVSwmrxubSImI4vrx7tRr1g5+JogD1tJ5HTa8EZuTQBS+Okn+l7/D JdlDv5nO2gyuNEhOCXSwPDHXhNCrNuMaApHb8VpaU/5uOphMAXoP0+OywXbkvXfEEruc 5XB1rXWks918r2RhnC3YKbIK+rifkkpNSkn/1wTaAbRvg5UF1hRq9qFrIi5c5aW08xuM k3d0hMN2zNFoOQLSf7gAq+9ddnri1Zz2NFhJlPULXPGXvac8XkWb1SyHowGEDhankWJJ gB82j/2WwlAH1+F4ikNPB5QvQ7wv9QiiuiAHRB44sng9p4HNFtRgHJrjNx2bQleRB6me T+Mg== X-Gm-Message-State: AA+aEWaZTJk+2HUd65+8dvRs3i9ehWDRT44yFSKwQRapCcC/fYoqDjfw BhdV7RfE/inpXTvkwQ2bhgoGqH/gk+BD5zxb7/da+gzVZ/+cXxT7xbrlTCItUrKyMR2j0phv1wy 6psRlkn2OXM/o1+L/vP0yom9EmnfJO34yRqTRh9mLsV6UAfTD0o0XtGwPJn3qfBix9yr/jgYXDW I/mZ/zvq5jXLjsSKvN1BDK4r2Jh10OUZUgdhVY72gX5P3vHg33SDO79RSZZd1HMhCRpWfWupHTc JqdSw0SN837UqdDZqYvoSaMyIQxsgQF98KlDl0pUNwLviRwp6zTsd67gmfKhpD5HfpWDFzZPpHX iogIS50LRkMkh817rJGRkR4OzRX2UVl0GU5odN5JorsQoejhSenpUbdA78tEJZosadlUxn9eeTi X X-Received: by 2002:a63:d40a:: with SMTP id a10mr18961857pgh.394.1543988931447; Tue, 04 Dec 2018 21:48:51 -0800 (PST) X-Received: by 2002:a63:d40a:: with SMTP id a10mr18961835pgh.394.1543988930586; Tue, 04 Dec 2018 21:48:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543988930; cv=none; d=google.com; s=arc-20160816; b=y7OiKLzUfZetLlgLqpVxGslWk+S91TRA2TXcM5sCq24qvN8FRkRzhzK8i7NNgiknDy B/kWU3pxAKTOyAOCC7PZjZJzeoNVguwjyS33Nh2lv4IIQoKxsAZUUmeTc/CCW15L5M39 xhoKHI4XH77g96OhTVaXhMG9AgD14f1UO+wPrfSJV+6ILGkHvZAo50CWjjx6LhKG7KXq vvOp/bjfaAk0IM5l2AOMMTDaeLlEovN4RGi66p1kxlnQfYqp/AO0TelizxcjH2WE31IQ HBRPhlPwh423nBkNJIm3CFdyVlkyWcV/bQKeqqbC2y6c6l1Bqj8evRRFhBCFvVkdawu7 JxVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=Mtj+5lLpDKXzv34oRdlikvP0Q/L3pkB7CbeDcaUQ2ak=; b=oBwP5voSOixZXVyZl1cw7ndvWgzhjWwrPDp6Jv8Key/1HBiZbx0haM2ut4tNDpKv3t 19UwlJ5nJ0XtkNGrCPHK8sSvZB4TProoMdK0yd0ry/DaZnK5ruYI8Iq7vwO46lOOGcAG 6NmOLrBd37CqVgy4jse+iGt8bh6QDZYaa1OnBBRJRTZgoym35w57cf28x+SLDW4yhZcm nx5rszKPqa8solc4EijA1dKDm1Cu9lCQxv2MnZL8U1nP780kKmDBrBFM7WYiCKDj740W D/P1o+/Pf3y3DSGTKcaRUeeS8XOf8MMnxWpXLBflYPtiwwLkx8dDPj0A+/wySRlGmikn 47kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=RJSBonDD; spf=pass (google.com: domain of drinkcat@chromium.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=drinkcat@chromium.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id r29sor27233867pfk.38.2018.12.04.21.48.50 for (Google Transport Security); Tue, 04 Dec 2018 21:48:50 -0800 (PST) Received-SPF: pass (google.com: domain of drinkcat@chromium.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=RJSBonDD; spf=pass (google.com: domain of drinkcat@chromium.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=drinkcat@chromium.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org 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-Smtp-Source: AFSGD/XIZbASUT86Hq6bBLcbgIr8yOKCqq/M0hjDPq1OmQpZfK1rdsqT2OjTw5YTsOUmsgwtOM+HyQ== 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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Acked-by: Vlastimil Babka --- 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);