From patchwork Sat Sep 4 10:49:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 12475519 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 170A5C433EF for ; Sat, 4 Sep 2021 10:50:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BEF8560FDC for ; Sat, 4 Sep 2021 10:50:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BEF8560FDC 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 BBD776B0080; Sat, 4 Sep 2021 06:50:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EA6CD940010; Sat, 4 Sep 2021 06:50:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E90C6B0075; Sat, 4 Sep 2021 06:50:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0068.hostedemail.com [216.40.44.68]) by kanga.kvack.org (Postfix) with ESMTP id 45D376B007E for ; Sat, 4 Sep 2021 06:50:14 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 04C1D8248076 for ; Sat, 4 Sep 2021 10:50:14 +0000 (UTC) X-FDA: 78549571548.30.04D8C9A Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf02.hostedemail.com (Postfix) with ESMTP id AEDB37001A23 for ; Sat, 4 Sep 2021 10:50:13 +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 BA7FF2269C; 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=G6OGrx6GIz3up+TR10DXhEX3qqgzgoncBND4dqx46JQ=; b=R/1YG4pxxmCF+V/yfa7WCiwFyBQo20Ny9YGDYZV8bneQn/MKwawoZwwVLwS3yHIpfvx72N 6vxrODBuyOVufeH/DcY9o9rN7s6QocULpCIdjOQ3/xWsmGNxsmfrdx0u2TmAvl8inWkzM3 t0HZZoAPL1zbIUH3BR9GySFgS2q9B4M= 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=G6OGrx6GIz3up+TR10DXhEX3qqgzgoncBND4dqx46JQ=; b=/oDDZiF/f3RFroQeUBWyVfA2caJT7sYiXKxby/oVyDWYKFKKmWxbqaNRTD67QYNm340GCJ eEPmMS3xKcRpPfBw== 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 9346A13A2C; Sat, 4 Sep 2021 10:50:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kLZZI2RPM2HoUQAAMHmgww (envelope-from ); Sat, 04 Sep 2021 10:50:12 +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 19/33] mm, slub: make locking in deactivate_slab() irq-safe Date: Sat, 4 Sep 2021 12:49:49 +0200 Message-Id: <20210904105003.11688-20-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=1920; h=from:subject; bh=YzKb788v9/Uv70MA4Rhg3F13MEdyRR1sJKH4wo5Ptcg=; b=owEBbQGS/pANAwAIAeAhynPxiakQAcsmYgBhM082Dw6UQkycba/shrCzbIHxh8w0nLMMX1KTqEQs ZLqhCvmJATMEAAEIAB0WIQSNS5MBqTXjGL5IXszgIcpz8YmpEAUCYTNPNgAKCRDgIcpz8YmpEHtQB/ 9AilOZPBvAD9Ga6igYJHS3ePasiFqZE7IxQ5jt1aQ1KJZg/RLYIyAohaFk3aNzV5vAk5252TqW4FiP QDOUE0fspWrTpM2tdMkK6gpbCaMbHJnj4mgeSnguneIL/JUTk6cdMCdPSYp7Z3RvdD9Wu5waA8pdYs cjE7r9Ugyqe9XgVn8JdAVgOZtVnnu0QRSr1EEY9uX4dg7x+r6iwXX7ScU+8XTKbDU2+ieZbv2kp419 AzCGmTNLRh7Rqvkv+JQ74HhCfP80O+vID9xABa4MOfFz5RZCGRfWI7ZK98yHy9BWAwsbFXMnRg3dii 5YjPSB3PnLYDtEDLnlnfMPs3TXaLHq X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="R/1YG4px"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="/oDDZiF/"; spf=pass (imf02.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: AEDB37001A23 X-Stat-Signature: 1a1wko9b67te6op8eozjrxbc3me3nk6a X-HE-Tag: 1630752613-852263 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: dectivate_slab() now no longer touches the kmem_cache_cpu structure, so it will be possible to call it with irqs enabled. Just convert the spin_lock calls to their irq saving/restoring variants to make it irq-safe. Note we now have to use cmpxchg_double_slab() for irq-safe slab_lock(), because in some situations we don't take the list_lock, which would disable irqs. Signed-off-by: Vlastimil Babka --- mm/slub.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index cea7a2ad9e3e..6deb4080ef54 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2223,6 +2223,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page, enum slab_modes l = M_NONE, m = M_NONE; void *nextfree, *freelist_iter, *freelist_tail; int tail = DEACTIVATE_TO_HEAD; + unsigned long flags = 0; struct page new; struct page old; @@ -2298,7 +2299,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page, * that acquire_slab() will see a slab page that * is frozen */ - spin_lock(&n->list_lock); + spin_lock_irqsave(&n->list_lock, flags); } } else { m = M_FULL; @@ -2309,7 +2310,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page, * slabs from diagnostic functions will not see * any frozen slabs. */ - spin_lock(&n->list_lock); + spin_lock_irqsave(&n->list_lock, flags); } } @@ -2326,14 +2327,14 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page, } l = m; - if (!__cmpxchg_double_slab(s, page, + if (!cmpxchg_double_slab(s, page, old.freelist, old.counters, new.freelist, new.counters, "unfreezing slab")) goto redo; if (lock) - spin_unlock(&n->list_lock); + spin_unlock_irqrestore(&n->list_lock, flags); if (m == M_PARTIAL) stat(s, tail);