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: 10677523 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 EE4DB13AD for ; Sun, 11 Nov 2018 09:04:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF2A02B08D for ; Sun, 11 Nov 2018 09:04:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D36762B098; Sun, 11 Nov 2018 09:04:10 +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 581E52B08D for ; Sun, 11 Nov 2018 09:04:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB4306B0005; Sun, 11 Nov 2018 04:04:08 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B5ECF6B0007; Sun, 11 Nov 2018 04:04:08 -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 A831C6B0005; Sun, 11 Nov 2018 04:04:08 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 68C8A6B0005 for ; Sun, 11 Nov 2018 04:04:08 -0500 (EST) Received: by mail-pg1-f198.google.com with SMTP id 143so1172852pgc.3 for ; Sun, 11 Nov 2018 01:04:08 -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=tHCTBgMG+6sJtZR5onayP64SmgPAtqMgziPQMQVZWKM=; b=YXwLJKd9mHyyqW8fftR3HfxkgnDjyqb/gqSrd0uLFp+hsQJJWb7+wKiJL7PlnzjNFI KVI7/n/DzJnVMV/4sRvEM9ydc5V4706Jd1qBDcOg/iruorkUmBc7QkGMQftMijSR2Txl tb+4sCOPIlvJsmktAKAYNsshIydiilvAw3J/4f6NSucRu0yi3pr/TC8lvTF6bWmzHNL3 jCFSIF5IImhVjaav2gl0AKX+rF1R5R1wxW4LoZfSHi2HbD4GF/Ko3JYund2Hv3VjVrMz UVMkI+e1PszLdhXMt4LhKLffiTeeVj5+RjemJ6qyTEdQaXyln9nJ7FEjTvLDpihkLZjX jNpQ== X-Gm-Message-State: AGRZ1gKev1gndb37D1GCqTiqYZszYwcjfL0/tBCCC+E4hjXApQF055Kk aC8je31Kwi/epqyBA8Jfs5aRf+RIVBqmputD7aVZRdJOV7ypqXXU58eznFnYtRr9ul+7Q29gbTx hJkJuZRPHufS3q5lr5ZqdiQwDXsYW5rdUc5NSdCcs+USrS6gm/lypE1MAPVplnlx+hf4zydaRP+ d7CUcrJWREN9VH3xOpROI9WLGHSyzLy5yhN9HBBvdq1bquhdUKA9CTxnmNSWxxZgesdeRHIyYWy vQRF/pWSPeFx/ehDQ+mhEudsEzTITpIH57BwlDvrmpDwzDbnmhFwFbUc8ECz7LrzQMxtT1WVq2m QZ/1IEnnHD53Lgb2GQ+nMeAlyRc59rW1FogodDDXhoHUcds/Lz/WcxhKkvdkDe8EI1t16B4c/uo x X-Received: by 2002:a17:902:5e4:: with SMTP id f91-v6mr2460980plf.75.1541927048048; Sun, 11 Nov 2018 01:04:08 -0800 (PST) X-Received: by 2002:a17:902:5e4:: with SMTP id f91-v6mr2460932plf.75.1541927047270; Sun, 11 Nov 2018 01:04:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541927047; cv=none; d=google.com; s=arc-20160816; b=KFBJoWxOnCLZODkdrcSrk834jX0L2F0+/SbWWWO3/jHJarSJyD9OIln6GNZcBp7R0R snKCix/HflY4kS5m9EKMqS6qZWc3Xkg7WgHQb617U1chBjRUkIafnxn0oa+m594qaflc 0enrHLrB4md5LHT+T84gRaKFQSoG8y+clhZQ6ck5MYJqoF9I0yY7jt/KHq0uCmnh9VqY 2aglj62Yvj8W1Pu313ZweZQlprSyJIXa8DACKUaQOgIw1to6cw01cZiEmUNpERGWOcFl 8OqQrQLpvfft9Z17qN5feeJZwsOZ4kQb/E1+O6s6g1vWr9JNCqhzLF0cCsLRA4rTpCZJ z+wA== 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=tHCTBgMG+6sJtZR5onayP64SmgPAtqMgziPQMQVZWKM=; b=BlJbsuCIiFuUEeKDhejYxydVSeL2eyLm6LgBp0g+rJ7SuTYbdUbjKnfNB2YfoJ30ga LehIlUc6J16JBmdMZnm8PNxg+vO2DT9ztllJsAx2CdD7ZJ1n7MYqOGJ8zGIJh3B3J/xz EJ//Yo0KexAdxS85u2Y1H45PuBHTZETHJw6x569qZNlN2oKJGdSfIGH5GJgYjbDEkFpE HYP7ybJkGXnh7Yi800aSwxvKcY9YjvPXWOC8aN9WGUmtcJ1sdPsxuMVei4f8XVHadkGy 70F5HkfHBcOLNC9Kx4u34I56ulFgFeDnUHQiwKbuvbUi+iYiG76C94bNLdtbMU6oy6ir 2j0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=l7Tlciw4; 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 j38sor5502575pgm.3.2018.11.11.01.04.07 for (Google Transport Security); Sun, 11 Nov 2018 01:04:07 -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=l7Tlciw4; 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=tHCTBgMG+6sJtZR5onayP64SmgPAtqMgziPQMQVZWKM=; b=l7Tlciw4q3K/mse2HceMtZDnrFM6ck6HToUmTsxs8jqxQdGLn9fB6x8w53HsMNvnTH RnBzgCGqDhuWKFO2CQ9TnefxUQWJI887Ol18UPHXQRc6lSN2Sh2R6hpIxxjJ+4jlSsKA FUktM+/wIwGDOTQ3nu7H7NgmdVXxlN0Iya5bc= 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 Cc: Will Deacon , 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 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-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 --- 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: 10677525 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 0562814E2 for ; Sun, 11 Nov 2018 09:04:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E968E2B08D for ; Sun, 11 Nov 2018 09:04:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCD262B098; Sun, 11 Nov 2018 09:04:14 +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 3AE3C2B08D for ; Sun, 11 Nov 2018 09:04:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A02196B0006; Sun, 11 Nov 2018 04:04:12 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 990FF6B0007; Sun, 11 Nov 2018 04:04:12 -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 87B4A6B0008; Sun, 11 Nov 2018 04:04:12 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by kanga.kvack.org (Postfix) with ESMTP id 413516B0006 for ; Sun, 11 Nov 2018 04:04:12 -0500 (EST) Received: by mail-pl1-f199.google.com with SMTP id 3-v6so4696560plc.18 for ; Sun, 11 Nov 2018 01:04:12 -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=KPUtoMHx+zKgWw/50SWdFRpPElnQtOmRn5WZTUEVzYs=; b=lkRvhWVIEWmIbbn0Ga5KNOnr7o9X6e+yDs0thFPo093EQEAlSMnsQs31RLNVtnrj6h 7vovctEYmrhmWCQWWrGOaaZwpIKr8S+nh09Jq0IwJEGLo7G4QIILFWv5XjjMwV11OgIm qjs5wZz+DHtYbrYE8s2AM+WeOK8+7AizG7h9Mnu3RKT7NGE6NyPyJ8q6sfhQgrAtG0Mk EyrijhIiRV85p36k1pB+/J2pLw7li5OnK5//UxioHfSyiM+WJo1JeGbuOYvkhfBXnyjq 60dRriJiPCk6imvbYhnmMd7bsqmpqNVGmMPUu+kC5vgORCWvNrOyQ9J3XDzlX4+m1DJ/ SKMQ== X-Gm-Message-State: AGRZ1gI3jISVcEvdBTHJX0yE2UomZvceV8Hofbw8it2JP+UzZknzlJQs x/eVZ8cdWnlYV4L1JRYZIgvqBA/3HScwoY3Toeiu+xW95fvr4kLt2lkb44JAqardprwvIgh2WlY BVIm8LtpjouurIpqxjzr83oYW2zYirG9kpa2YjpdxSoYm4X9wnsPLY+mq1/P7Nz2d/twFbGWgdv s1c4nSckZIrDHg3cTRhRNCQrWl8EVXd2Ek7toBnH0r9vvx4Pg3jaL33EiImp4tshlpoP38A/RjZ aBz9pmjVbhrD3T+AYQcTZ5SUiaeVeiIZv65Q01Tcmg0zJrJNQze6X+usXYxy9Q4B117Y2oj+zH+ eVa0zftKvQjAIyhJG/8f/Hsn30a3bLzfqbASbtXn7zDU9w6BWuUMsnNHV7e2hqv1PJ7ylO0nLP/ 2 X-Received: by 2002:a17:902:8e8a:: with SMTP id bg10-v6mr15654580plb.214.1541927051901; Sun, 11 Nov 2018 01:04:11 -0800 (PST) X-Received: by 2002:a17:902:8e8a:: with SMTP id bg10-v6mr15654536plb.214.1541927051031; Sun, 11 Nov 2018 01:04:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541927051; cv=none; d=google.com; s=arc-20160816; b=mSQMZPGkt761SvuoJLk7mkR6KzTShF6CA5Bk5GPLMB/isRvnofqaLQQOQy3T24iXun wV38I+dOAJjC2hdomXWo3Wb46kXLFJId7MoijH3Mq+PEvC+CHOUp4fTc9OhpAUO+D9Kx 57xoHU5GRgzybLaa657pw2BeEdPHSD/JG4k+D6nonjMv86dn7dmUWw+Ld7t2wX3bcsJn IL/XOzMKK2gaHE8yA58N7h1xL1O4UfISxzJ49c1VFf6GQ6x7pujHJEf1sZ8fresYOcQP G+5/2mtnOZg7sXUcvl0aNJQ6Ypi0xSfLMnJcFH3XF9XXFk7ZteEE+jggT/2QQD+X+z9/ aWMA== 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=KPUtoMHx+zKgWw/50SWdFRpPElnQtOmRn5WZTUEVzYs=; b=c02lljCKJ+GUb5OBR6dEV6ZdO5XIMa2RJyWrFEsjU8/RMQ5kbTQoCoAnnW9slbUiNq QOl0HJeLHycM2e6pvg7EsxeFldWyZ22eNAlZIQpolJVyKJBLAQ0aiQTsfGdnErP1JBDX HpzdIF8a0Jjx347+U/FIJBC8yr+soNyDgTSKEi/R1qV/5iSPJO7p4yw6cKyD2KNmbByr 5EdXbJTMR36TDxxs+uWkMTWGfkYL+WFJu+8OiSODADnrsyGDuiLpa1b/QRmrctBh1a2f qFdHIHmYU3Wfn01EfM31tSBfqcOno1LpdwD8P4ur+OX4vVdoK7YjKPD+MZNyGX/CNsvZ NzVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=eF3UiDtK; 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 j15sor14444977pgc.41.2018.11.11.01.04.10 for (Google Transport Security); Sun, 11 Nov 2018 01:04:11 -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=eF3UiDtK; 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=KPUtoMHx+zKgWw/50SWdFRpPElnQtOmRn5WZTUEVzYs=; b=eF3UiDtKNpGLH8WDQRLmzM+lV68Qvk9qt98jNj/eWRr7yTj7wjQWF1pKGRyZXBAlGQ 5fjUfzRE3brXvb77u6LrT66F3nBShPfa2Rju+ADlBiwz33Qo7SW4AaTP/CLlzen61UU9 040zOTA/bUzkYsIGgDps0XsOwB+8LXkf0POOw= 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 Cc: Will Deacon , 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 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-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 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: 10677527 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 6077114E2 for ; Sun, 11 Nov 2018 09:04:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 520912B08D for ; Sun, 11 Nov 2018 09:04:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 455572B098; Sun, 11 Nov 2018 09:04:18 +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 BEB862B08D for ; Sun, 11 Nov 2018 09:04:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 34CDD6B0007; Sun, 11 Nov 2018 04:04:16 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2FC176B0008; Sun, 11 Nov 2018 04:04:16 -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 19DCF6B000A; Sun, 11 Nov 2018 04:04:16 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by kanga.kvack.org (Postfix) with ESMTP id CD1286B0007 for ; Sun, 11 Nov 2018 04:04:15 -0500 (EST) Received: by mail-pf1-f198.google.com with SMTP id g63-v6so5174423pfc.9 for ; Sun, 11 Nov 2018 01:04:15 -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=J3drSXNEQad/j7zI+ID7YdbI6KhfStGY6vScO313iR4=; b=ai5FbDAS4CKZ4ignbhc04OH75IbpUxVMVbskarDgrrprQv8mLtwPfwTpmCtdKV/oRs qz4n2ERg/47WR4K44NolIOmfCR7Dh/QmnLNn5WfcOgzdlHY19a8N/MXOk2tXGMIEWzb5 V0iK7Lfz9FVS3oFDMgBTLh8a0bPsGOW8exy+nqieMRqDTcc1osmoMPzVzRB39Gn+dyIT MyeWuNNwVi4ISh2tc75PlF4gkznjFxLTkl0F2rfn+YG95HZXOhu4LpPbY2+2YW55G8so C1wXb7SN6B0TyribuWh4vSTZg2d9fNz95S7uW0s6V0chujMUBXe4VTZ6mfjoGiF1nFzA ZOsQ== X-Gm-Message-State: AGRZ1gKfFPfO6lYy+RJYvBegDUhjaOmpsRkb1ki5DLwqyDJl08COig64 Ra5Z4N+AoRxQYn8ESMT7r7jRaHzXJo5Jq9wH5isipUTYAaTy+XWfJl6qWaUMjaXBeqZNS/9Yg+g PRK3e7/L/RDeRmml084qf3RG03MIt1ijbgrdaDLHh9mS5epEzXe0ZuTwLT38MRHGgCnm02sTLnN YN/9ah6c2ADFum4MiHNO9DmrCzaUYykGbLwzvOIbQEWKb9skRmejTFowPi77TQ56HGAj91LOaQa WZxjJ0D7gOgjpZXmSYj/nusGJhiPhE0PQhAcC0PK8QSP1BeJhpMzF2tIi/IK/Sw9aoIZFSpKO2c IIsu8qs/Jo9kVuWKOrWaeGzn11WR6uPG2Ph9+qZ+zpPrDcDtUrXDD00QUGx/ap6uLUhNk89uh4p 5 X-Received: by 2002:a63:9dca:: with SMTP id i193-v6mr12537068pgd.98.1541927055480; Sun, 11 Nov 2018 01:04:15 -0800 (PST) X-Received: by 2002:a63:9dca:: with SMTP id i193-v6mr12537033pgd.98.1541927054717; Sun, 11 Nov 2018 01:04:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541927054; cv=none; d=google.com; s=arc-20160816; b=kYbGJdSr2v9Rsc+UKK+5eA9s3vF7Lhmcz3B51CYcWvUTDox/5S2R3q6le67HJIQ3Su s0hLHh4ZO+D+Poi4f5F01a1fhc3DxoIVsnaeXtvE6avQp0fAJ03J8rBRxgocZCxcQqzJ FEjvBb6r065SmGqiPKvA71YZOsXh8RVsadqI7bi2m/yYGxDjLaTGWiRC60lZlp/MXFrj gN7BKp1fElrZeuRJwAFD7DWwIdN0CgE1IEGEztBPDrP+fPrVywLETotBixS6hFYVtNRC TAvkyTMF+svKLSmByrAhbLC8xJ9YU5aMGLN/252tuSDOeKYNP9ERITSyv7eP40GolWj4 Fw/g== 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=J3drSXNEQad/j7zI+ID7YdbI6KhfStGY6vScO313iR4=; b=Sn9Mq1KSCE+9MDosrBGjMQf5aMpI2Ev0hpzFE9v4PJWPHz3QvMNbv0s/6ksQRgyT33 wzvBYnP9Ie4MSVUvKUQ7EXCtVNk4GEigFpoK8GqTqeZhmDuyqazW1Y13gEE+sN/0pQWy 8wbhD4tHn1yU2Fo0CP/5IvLhmVN1chGuapxzgSmOjQ4iLACcTOaopnKE4SBWzrDgKKsi Er89CnAtzSi6wIzmIh1m0Uw1TvwxTaoHVtygcQA3e35FGJlPl7sy8981NfJJ8B3Hp/tV OsMWOiHNR+oANSPCzxo8SPMt7w7MEemSyekUcu36qTPwHY826LXUllvSy/QVQcYDEDYc rd7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DcjG9kTD; 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 p18sor14026140pgl.33.2018.11.11.01.04.14 for (Google Transport Security); Sun, 11 Nov 2018 01:04:14 -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=DcjG9kTD; 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=J3drSXNEQad/j7zI+ID7YdbI6KhfStGY6vScO313iR4=; b=DcjG9kTDXB4SQ7VqcCMrX/L11oHaZNfPg9bG1SMflAXtx7Sdu1dqaoGyXOCoJ27tqZ TXk+rgHoUJbj9EsRYITf58Qh9ZhpgwOmxbxRHsI9hfkN3Wuw3up8qbfLy+xDMg7VZc+c e1b6fwI4rwon3DJdb6ZCA5AYTpsyukkQJdy20= 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 Cc: Will Deacon , 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 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-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 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;