Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1221258pxb; Sat, 4 Sep 2021 03:52:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhIAGNx8asImA6HtR6yEbQ51RZ+waJBd8aKxf3DIpV/0Lb82XDI7d80kKp77rWz5AOYX+Q X-Received: by 2002:a05:6e02:1888:: with SMTP id o8mr2384533ilu.124.1630752761926; Sat, 04 Sep 2021 03:52:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630752761; cv=none; d=google.com; s=arc-20160816; b=JXyjdbKFrltkAk5nDKVFO9jPIKENx08Dc1+5V0LvzdRAff+/9O9+A+2LlaKuB0/+lt KxHet0OnRT+DrbXrD3PXuApJcsKbUkKsF3uHB8+NUQzUrx9x2pNkI83tnl3KYLd07VSP yUk5BZBkES1ECpjcD5x5RTx9DvvUM2RGRZYX1mtd38S13CCMc/XX/I0O/oaQ3nqq56Bw MOLsGSQI2jKSCgkkxN5N4X+hd4w8Br/PS93nZp5txSmdKwkUVS/qaMppXja46F/BXlkM dWc+qIHTmtZRRKuNbI/5Hs5CYimEOUm8bTrg6F0QXPCDbMmBYRTt6gCDfC3nzrxLLpLN IIBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=7mUlsuwJHAvWrWwqdtLB62kmN3qgv5TJrxQ2cxDjcmE=; b=pqPMB+BEoiIZKps2dT2DlEvmdtfkDYU+JzIQKHlGkQ4OkCvFb+4ajIdn4JZUsTZHDS ojvvHyiC54yZlGHz6gKx3EfwAudLijFu4iAJjSvmauXAJzZiDpEPYvmDUHUERXPAn5Ms 3jatrMMzBdF2DnH1Lb1wZ0V9nXNaGQ4jZ2xRSwlD40Fc1LD/81prxiCjQMhE2eM9phXn XMqyI+/uMr9nRrkcuwc5vy6d6hClmHihvLsHDPoDr5aaX9kDGfdSwpF+4Q2tOmDPg6z2 OCOxjBxCR4mlq5BxGZ7i9tX6KEBXqLT1OE8iGXO+4t+Mr06dvR27vgk0/gwuFYOs3af3 Avyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=BBSUyAXX; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=YrY9Y4Ga; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r19si1810596ioa.68.2021.09.04.03.52.31; Sat, 04 Sep 2021 03:52:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=BBSUyAXX; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=YrY9Y4Ga; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351248AbhIDKwD (ORCPT + 99 others); Sat, 4 Sep 2021 06:52:03 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:59828 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351115AbhIDKvO (ORCPT ); Sat, 4 Sep 2021 06:51:14 -0400 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 1661322693; Sat, 4 Sep 2021 10:50:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1630752612; 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=7mUlsuwJHAvWrWwqdtLB62kmN3qgv5TJrxQ2cxDjcmE=; b=BBSUyAXX5kguKuXcpd4Zj1oL/He0ejBI+SXoza9DHncYVVNpjlTy9zGdJdcZDBpta6SpJk ISDdoW5N3ioBayQOzVgjcFK9vco1QLOAq8ldv952sAuyKIFR4u/5PzYlig6Z6uHCLhy5UK +w5UH01Xmb9r4j7EAXB+GQldAAZBVLs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1630752612; 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=7mUlsuwJHAvWrWwqdtLB62kmN3qgv5TJrxQ2cxDjcmE=; b=YrY9Y4GaOV9p7Pgd7d7+0I31YZxo9L2gLFiZ+N4X/ZC+notpR3SH91NoAFRxu8aRVmG/iN YbR+aa+M8dweV9Cw== 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 E244713A2C; Sat, 4 Sep 2021 10:50:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qD6hNmNPM2HoUQAAMHmgww (envelope-from ); Sat, 04 Sep 2021 10:50:11 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, Christoph Lameter , David Rientjes , Pekka Enberg , Joonsoo Kim Cc: Andrew Morton , linux-kernel@vger.kernel.org, Mike Galbraith , Sebastian Andrzej Siewior , Thomas Gleixner , Mel Gorman , Vlastimil Babka Subject: [PATCH v6 15/33] mm, slub: validate slab from partial list or page allocator before making it cpu slab Date: Sat, 4 Sep 2021 12:49:45 +0200 Message-Id: <20210904105003.11688-16-vbabka@suse.cz> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210904105003.11688-1-vbabka@suse.cz> References: <20210904105003.11688-1-vbabka@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2080; h=from:subject; bh=6RMKkRPIFqUauCH8SJwma9svu+hJUqHG71X1n1a6wH8=; b=owEBbQGS/pANAwAIAeAhynPxiakQAcsmYgBhM08tI9N51RCa6f2o+EKv7HZaeUBnieZWGaRsW7io r6kzmKKJATMEAAEIAB0WIQSNS5MBqTXjGL5IXszgIcpz8YmpEAUCYTNPLQAKCRDgIcpz8YmpEFWHB/ oCpGr5YOouRz5tfSzXgWhHJK8AbYmNHL3IL9+OF0nrlOp91ELjXLFYcblzjoNzKoxjM7f8BWiVsA2P gdKi8lXtY+w0Bhl6l86tgO4reK1Gy9o6P5+Uwo4e0LcBV0ujx+h2pOkTNeD6PkEFcTf+FtiRs+Q6T2 GvwOHRh9hvoNiyHKbuoQJOXXjpjB1j/EiEwfjbp7VfCTx4d+XZGRZAfvlrCNcZoNx2ikR7baf1uiQ1 u9YQGAHLotozScAnM33PIrBzZr89vCYEPrIx4eac+MfaYnGNSdLt2sS3+v61oOLfWuQOqkb3PP/oIA PzpItUyBr1HK0LhAVIyH6F6T+2BsNw X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 undo 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 only 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 7798ba1c614f..a5e974defcb7 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2802,10 +2802,8 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, lockdep_assert_irqs_disabled(); freelist = get_partial(s, gfpflags, node, &page); - if (freelist) { - c->page = page; + if (freelist) goto check_new_page; - } local_irq_restore(flags); put_cpu_ptr(s->cpu_slab); @@ -2818,9 +2816,6 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, } 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 @@ -2829,14 +2824,12 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, page->freelist = NULL; stat(s, ALLOC_SLAB); - c->page = page; check_new_page: if (kmem_cache_debug(s)) { if (!alloc_debug_processing(s, page, freelist, addr)) { /* Slab failed checks. Next slab needed */ - c->page = NULL; local_irq_restore(flags); goto new_slab; } else { @@ -2855,10 +2848,18 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, */ goto return_single; + if (unlikely(c->page)) + flush_slab(s, c); + c->page = page; + goto load_freelist; return_single: + if (unlikely(c->page)) + flush_slab(s, c); + c->page = page; + deactivate_slab(s, page, get_freepointer(s, freelist), c); local_irq_restore(flags); return freelist; -- 2.33.0