From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 287CDC4338F for ; Thu, 29 Jul 2021 13:22:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D9E9E60EBC for ; Thu, 29 Jul 2021 13:22:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D9E9E60EBC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 27B4E8D000B; Thu, 29 Jul 2021 09:21:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 13C6990000B; Thu, 29 Jul 2021 09:21:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 83C128D0001; Thu, 29 Jul 2021 09:21:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0231.hostedemail.com [216.40.44.231]) by kanga.kvack.org (Postfix) with ESMTP id 0E0928D0006 for ; Thu, 29 Jul 2021 09:21:45 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B5BFF25709 for ; Thu, 29 Jul 2021 13:21:44 +0000 (UTC) X-FDA: 78415687728.22.B8C71E7 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf22.hostedemail.com (Postfix) with ESMTP id 5E63F1906 for ; Thu, 29 Jul 2021 13:21:44 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 66A38223D3; Thu, 29 Jul 2021 13:21:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1627564903; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nlAqPsEkB+TaxJN88gWtIIOVpIDjtByvKEzbcoIUzRs=; b=Cv+/OaF9dR4/NV8HJrxrG1gYGgghHJu8bTuNIiLrSaWW6SB0qf5fXEEAatCSEAcUj1gloM JuzhSVKDjy/DNFID3jnWi3/E8qSXPANvnnmuebGuM2cEMd07flwx2f8CXJulS+E6Vof6xj J2yRBU0TY9cuEQxAq3/KTxACHnfPJTk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1627564903; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nlAqPsEkB+TaxJN88gWtIIOVpIDjtByvKEzbcoIUzRs=; b=m1Vn8IN+W+qMCYG/E7jrNhB1+Fue6H+/BIw0Yk4nii6Gf8BmWzJMtMnP1qhHZHVH8n0NwV ijjyLN+kwNnOT9DQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3690313AE9; Thu, 29 Jul 2021 13:21:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id aGXBDGerAmF9AwAAMHmgww (envelope-from ); Thu, 29 Jul 2021 13:21:43 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Christoph Lameter , David Rientjes , Pekka Enberg , Joonsoo Kim Cc: Mike Galbraith , Sebastian Andrzej Siewior , Thomas Gleixner , Mel Gorman , Jesper Dangaard Brouer , Jann Horn , Vlastimil Babka Subject: [PATCH v3 16/35] mm, slub: validate slab from partial list or page allocator before making it cpu slab Date: Thu, 29 Jul 2021 15:21:13 +0200 Message-Id: <20210729132132.19691-17-vbabka@suse.cz> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210729132132.19691-1-vbabka@suse.cz> References: <20210729132132.19691-1-vbabka@suse.cz> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 5E63F1906 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="Cv+/OaF9"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=m1Vn8IN+; dmarc=none; spf=pass (imf22.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Stat-Signature: jyrpu5qs9af69qoy6gb9gjj744kh65gt X-HE-Tag: 1627564904-926242 Content-Transfer-Encoding: quoted-printable 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: When we obtain a new slab page from node partial list or page allocator, = we assign it to kmem_cache_cpu, perform some checks, and if they fail, we un= do the assignment. In order to allow doing the checks without irq disabled, restructure the = code so that the checks are done first, and kmem_cache_cpu.page assignment onl= y after they pass. Signed-off-by: Vlastimil Babka --- mm/slub.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 43f38fd47062..c1a88ad4048b 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2772,10 +2772,8 @@ static void *___slab_alloc(struct kmem_cache *s, g= fp_t gfpflags, int node, lockdep_assert_irqs_disabled(); =20 freelist =3D get_partial(s, gfpflags, node, &page); - if (freelist) { - c->page =3D page; + if (freelist) goto check_new_page; - } =20 local_irq_restore(flags); put_cpu_ptr(s->cpu_slab); @@ -2788,9 +2786,6 @@ static void *___slab_alloc(struct kmem_cache *s, gf= p_t gfpflags, int node, } =20 local_irq_save(flags); - if (c->page) - flush_slab(s, c); - /* * No other reference to the page yet so we can * muck around with it freely without cmpxchg @@ -2799,14 +2794,12 @@ static void *___slab_alloc(struct kmem_cache *s, = gfp_t gfpflags, int node, page->freelist =3D NULL; =20 stat(s, ALLOC_SLAB); - c->page =3D page; =20 check_new_page: =20 if (kmem_cache_debug(s)) { if (!alloc_debug_processing(s, page, freelist, addr)) { /* Slab failed checks. Next slab needed */ - c->page =3D NULL; local_irq_restore(flags); goto new_slab; } else { @@ -2825,10 +2818,18 @@ static void *___slab_alloc(struct kmem_cache *s, = gfp_t gfpflags, int node, */ goto return_single; =20 + if (unlikely(c->page)) + flush_slab(s, c); + c->page =3D page; + goto load_freelist; =20 return_single: =20 + if (unlikely(c->page)) + flush_slab(s, c); + c->page =3D page; + deactivate_slab(s, page, get_freepointer(s, freelist), c); local_irq_restore(flags); return freelist; --=20 2.32.0