From patchwork Thu Jul 30 10:19:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Qiang" X-Patchwork-Id: 11692717 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AE62F912 for ; Thu, 30 Jul 2020 10:08:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8539020838 for ; Thu, 30 Jul 2020 10:08:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8539020838 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=windriver.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7B2386B0006; Thu, 30 Jul 2020 06:08:19 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7630C6B0007; Thu, 30 Jul 2020 06:08:19 -0400 (EDT) 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 677FF6B0008; Thu, 30 Jul 2020 06:08:19 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0171.hostedemail.com [216.40.44.171]) by kanga.kvack.org (Postfix) with ESMTP id 52A536B0006 for ; Thu, 30 Jul 2020 06:08:19 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 04DAC8248D51 for ; Thu, 30 Jul 2020 10:08:19 +0000 (UTC) X-FDA: 77094317118.16.mice43_4e15ee626f7a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id B3B16100E6932 for ; Thu, 30 Jul 2020 10:08:18 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,qiang.zhang@windriver.com,,RULES_HIT:30045:30054:30070:30075:30090,0,RBL:147.11.146.13:@windriver.com:.lbl8.mailshell.net-62.18.0.100 64.10.201.10;04yrytc8zso5o1ia1834918w6st1yycumsechh9ytie4n3co66b8e4edoyxe31p.rozrztbwcnwr57pdqabmiprrc1my3ppye4u1p7aag6iauzc19abmknaooewk8ng.y-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: mice43_4e15ee626f7a X-Filterd-Recvd-Size: 3537 Received: from mail1.windriver.com (mail1.windriver.com [147.11.146.13]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Thu, 30 Jul 2020 10:08:17 +0000 (UTC) Received: from ALA-HCB.corp.ad.wrs.com (ala-hcb.corp.ad.wrs.com [147.11.189.41]) by mail1.windriver.com (8.15.2/8.15.2) with ESMTPS id 06UA89XB019930 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Thu, 30 Jul 2020 03:08:09 -0700 (PDT) Received: from pek-lpg-core1-vm1.wrs.com (128.224.156.106) by ALA-HCB.corp.ad.wrs.com (147.11.189.41) with Microsoft SMTP Server id 14.3.487.0; Thu, 30 Jul 2020 03:07:48 -0700 From: To: , , , , CC: , Subject: [PATCH v3] mm/slab.c: add node spinlock protect in __cache_free_alien Date: Thu, 30 Jul 2020 18:19:34 +0800 Message-ID: <20200730101934.38343-1-qiang.zhang@windriver.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: B3B16100E6932 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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: From: Zhang Qiang for example: node0 cpu0 cpu1 slab_dead_cpu >mutex_lock(&slab_mutex) >cpuup_canceled slab_dead_cpu >mask = cpumask_of_node(node) >mutex_lock(&slab_mutex) >n = get_node(cachep0, node0) >spin_lock_irq(n&->list_lock) >if (!cpumask_empty(mask)) == true >spin_unlock_irq(&n->list_lock) >goto free_slab .... >mutex_unlock(&slab_mutex) .... >cpuup_canceled >mask = cpumask_of_node(node) kmem_cache_free(cachep0 ) >n = get_node(cachep0, node0) >__cache_free_alien(cachep0 ) >spin_lock_irq(n&->list_lock) >n = get_node(cachep0, node0) >if (!cpumask_empty(mask)) == false >if (n->alien && n->alien[page_node]) >alien = n->alien >alien = n->alien[page_node] >n->alien = NULL >.... >spin_unlock_irq(&n->list_lock) >.... Due to multiple cpu offline, The same cache in a node may be operated in parallel,the "n->alien" should be protect. Fixes: 6731d4f12315 ("slab: Convert to hotplug state machine") Signed-off-by: Zhang Qiang --- v1->v2->v3: change submission information and fixes tags. mm/slab.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index a89633603b2d..290523c90b4e 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -759,8 +759,10 @@ static int __cache_free_alien(struct kmem_cache *cachep, void *objp, n = get_node(cachep, node); STATS_INC_NODEFREES(cachep); + spin_lock(&n->list_lock); if (n->alien && n->alien[page_node]) { alien = n->alien[page_node]; + spin_unlock(&n->list_lock); ac = &alien->ac; spin_lock(&alien->lock); if (unlikely(ac->avail == ac->limit)) { @@ -769,14 +771,15 @@ static int __cache_free_alien(struct kmem_cache *cachep, void *objp, } ac->entry[ac->avail++] = objp; spin_unlock(&alien->lock); - slabs_destroy(cachep, &list); } else { + spin_unlock(&n->list_lock); n = get_node(cachep, page_node); spin_lock(&n->list_lock); free_block(cachep, &objp, 1, page_node, &list); spin_unlock(&n->list_lock); - slabs_destroy(cachep, &list); } + + slabs_destroy(cachep, &list); return 1; }