Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp5023621rdb; Fri, 15 Sep 2023 23:00:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWXtNXDe3OcsKBz8zrI2ouExr0zJeBZbcBjGsAJd4Es2hyrc+yIM9+8p2D04mf8r2Ej0pj X-Received: by 2002:a05:6358:2813:b0:132:f612:1dbd with SMTP id k19-20020a056358281300b00132f6121dbdmr4352867rwb.26.1694844022286; Fri, 15 Sep 2023 23:00:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694844022; cv=none; d=google.com; s=arc-20160816; b=NHgTua2MSfU7aJKBxJzsoe+pdKQyXNk3WBfs84ahXvjlVYuNaLee2Y8h/5nLvUQucS +L2RUaDcavFus06Jfxk8KBlwSHaZIbg5TFN7WKaahadY1yPl3WEiiZOFsgAvSZ9fzjKn n8gnDO8yuh1iEiZZ5oT+X3TzSJd8S6cgYSjHbENPBGnrzuLgF/P4O045TxcpO+v0PX22 7B4kB+3ghDt475y+Zw3X3r+BjQ4TgCSBmZzyEJdAWCFIpSaoEB1E9Byjegk+trDg30ts VFJQQSSdqmPkCo1RW6ZeDoa7de4VuI7pMmpuP9OjQzYLNDyfChYBDDzLNqd/RsK5ziId FTOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=xIW8YzBnPzjMwFioxgcY2G/FS0UtBiM6jL3TdyU9mWA=; fh=jqyVLh6bCUdwF76+d1nSsH9gan5yVpKFn6DRJJLnHtk=; b=PtbnYfCrTRqMdqIVr7Z/QU05KTKYH/zruKHPitB6Rub0KEsguYrLvG3ZDBFRZWuYyr F8gXuiW8yrZD/hDHY3BTjMdCf6BPW64WrMz5MD7OYNFoaIK68NrYdA1WsVz0FSPMZYiW dpZK4WiiPrv7g3uHFEfW9Fswhu0I7rUYAeqgCqAXOTNtnANiNYpRAHMK+wATLr5fkMiS ADwpRlT/HAdBBz1Noci1zYvLYaimDJAPkqzbIthD//SZzJxAxvGpwqwcL+f2D+leKCbr m1oAYRNhbxfEfq0JpKIttassSTXACw2Qi4q4bexx2aurSPkle+RGBL6r0zReY6JjmeNd mD4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Ws6lioHk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id h184-20020a6383c1000000b0057851fc2b49si67015pge.84.2023.09.15.23.00.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 23:00:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Ws6lioHk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 00592837EBF6; Fri, 15 Sep 2023 14:03:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237762AbjIOVDD (ORCPT + 99 others); Fri, 15 Sep 2023 17:03:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237887AbjIOVCu (ORCPT ); Fri, 15 Sep 2023 17:02:50 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC261271F for ; Fri, 15 Sep 2023 14:02:14 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1bf5c314a57so21764375ad.1 for ; Fri, 15 Sep 2023 14:02:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1694811734; x=1695416534; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=xIW8YzBnPzjMwFioxgcY2G/FS0UtBiM6jL3TdyU9mWA=; b=Ws6lioHkXmZRkCOfm4sRK9gIiGAU1M/1cX+vG1UpxKtsUFMS5tgMAk2Vty2SXot0ET rHR25M8Qe1bG6gO6TZazHhKLScPzHe1xL3UiZzoTP2i3nnsLwdjc7SKg7snaRht+Kp4w uCvuzOSqj/FnYtu4X/9iXHFedOrE3aBTbrJ6A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694811734; x=1695416534; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=xIW8YzBnPzjMwFioxgcY2G/FS0UtBiM6jL3TdyU9mWA=; b=vVEstpI2dP9Es5ROnhEyJ9M7GW8AC0A5PALyHqeHoqCuz/6UC2ETJdcbSwxOP294Ao +YC0mDzTLCyH6LANSFLzFt/+Wxc7B2HVsWTLTS0mF812lEvjMgoCfBkWThLLH/X5LmWK n29A2UNpl4DCz6mSaKvaFZ2tIQNldaTCZZ28YFBzn5QmsEqyFqnbR6MoXNn/GWnTgxoZ EyeoHJR45qsqwDnhxQNCr246kHGOYkQ/EV7ftx1J9g6KyrKDaga9YbfYKZEzJlImA+8d ucpLaln0xQ/5ek0OtnGPbr50Im6+RiuaFs3wrhLDcWMZXY9fOtLkdufqG5QHyNASXUUb N3Cg== X-Gm-Message-State: AOJu0YwX70e398OIAxSfX/pZ5C1H3qeiDsBGWSz9wjwnQkaNrTSoyUrf shp3fkSSNt/jgBxjlZP6kvTvVA== X-Received: by 2002:a17:903:455:b0:1c0:b17a:7554 with SMTP id iw21-20020a170903045500b001c0b17a7554mr2433786plb.64.1694811734323; Fri, 15 Sep 2023 14:02:14 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id q15-20020a17090311cf00b001c3267ae317sm3902440plh.165.2023.09.15.14.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 14:02:13 -0700 (PDT) Date: Fri, 15 Sep 2023 14:02:13 -0700 From: Kees Cook To: Matteo Rizzo Cc: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, vbabka@suse.cz, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, corbet@lwn.net, luto@kernel.org, peterz@infradead.org, jannh@google.com, evn@google.com, poprdi@google.com, jordyzomer@google.com Subject: Re: [RFC PATCH 05/14] mm/slub: create folio_set/clear_slab helpers Message-ID: <202309151401.C49DDCE8@keescook> References: <20230915105933.495735-1-matteorizzo@google.com> <20230915105933.495735-6-matteorizzo@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230915105933.495735-6-matteorizzo@google.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 15 Sep 2023 14:03:46 -0700 (PDT) On Fri, Sep 15, 2023 at 10:59:24AM +0000, Matteo Rizzo wrote: > From: Jann Horn > > This is refactoring in preparation for SLAB_VIRTUAL. Extract this code > to separate functions so that it's not duplicated in the code that > allocates and frees page with SLAB_VIRTUAL enabled. > > Signed-off-by: Jann Horn > Co-developed-by: Matteo Rizzo > Signed-off-by: Matteo Rizzo > --- > mm/slub.c | 32 ++++++++++++++++++++++---------- > 1 file changed, 22 insertions(+), 10 deletions(-) > > diff --git a/mm/slub.c b/mm/slub.c > index ad33d9e1601d..9b87afade125 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -1849,6 +1849,26 @@ static void *setup_object(struct kmem_cache *s, void *object) > /* > * Slab allocation and freeing > */ > + > +static void folio_set_slab(struct folio *folio, struct slab *slab) > +{ > + __folio_set_slab(folio); > + /* Make the flag visible before any changes to folio->mapping */ > + smp_wmb(); > + > + if (folio_is_pfmemalloc(folio)) > + slab_set_pfmemalloc(slab); > +} > + > +static void folio_clear_slab(struct folio *folio, struct slab *slab) > +{ > + __slab_clear_pfmemalloc(slab); > + folio->mapping = NULL; > + /* Make the mapping reset visible before clearing the flag */ > + smp_wmb(); > + __folio_clear_slab(folio); > +} Perhaps these should be explicitly marked as inlines? > + > static inline struct slab *alloc_slab_page(gfp_t flags, int node, > struct kmem_cache_order_objects oo) > { > @@ -1865,11 +1885,7 @@ static inline struct slab *alloc_slab_page(gfp_t flags, int node, > return NULL; > > slab = folio_slab(folio); > - __folio_set_slab(folio); > - /* Make the flag visible before any changes to folio->mapping */ > - smp_wmb(); > - if (folio_is_pfmemalloc(folio)) > - slab_set_pfmemalloc(slab); > + folio_set_slab(folio, slab); > > return slab; > } > @@ -2067,11 +2083,7 @@ static void __free_slab(struct kmem_cache *s, struct slab *slab) > int order = folio_order(folio); > int pages = 1 << order; > > - __slab_clear_pfmemalloc(slab); > - folio->mapping = NULL; > - /* Make the mapping reset visible before clearing the flag */ > - smp_wmb(); > - __folio_clear_slab(folio); > + folio_clear_slab(folio, slab); > mm_account_reclaimed_pages(pages); > unaccount_slab(slab, order, s); > __free_pages(&folio->page, order); > -- > 2.42.0.459.ge4e396fd5e-goog Otherwise this is a straight function extraction. Reviewed-by: Kees Cook -- Kees Cook