Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2231208imc; Tue, 12 Mar 2019 09:29:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqymv+5K9jwtPN4lLhJ7TVZd5ZdYRdKi4R9W8R/POKaeO4Xv10zc51TjCmiC3dbiRgSWh2cQ X-Received: by 2002:a17:902:8693:: with SMTP id g19mr10304975plo.157.1552408191764; Tue, 12 Mar 2019 09:29:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552408191; cv=none; d=google.com; s=arc-20160816; b=sh1Gg3egn4qmxrnRMy9twXvBarZYNzMGMeNIOgdINrPGl7Z5H23Uc3XMW4aOwPB0aK xWCP0jExyFCBuh1iAEeTK3BPIgu1kee5irjNJUe/3i70D6X+CeawweimxAJkrZ11M3zi PaWkZqPMQQj8nm/X2+h5DZkGEH0nwMtqUP2izXcB60tUMPY31D5MwX6VLY0TSU1ThfOd 6vwIuy9HKFtMNYPkaIeopDJgo1xquZJEzZ2yKztGeNkCOZMIBaLs0EUM+7QTUZ+V7Z38 lW5rEDXNkXJvY/AK+p9LmqTwaZs2IZFx5xISCLYz9ez+edTD6D5HAsFd+NSix7A29RPP upCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date:from :references:cc:to:subject; bh=HoFU5tV2TtDpaPJHtvs+dGcS7i852A7xTa1Tq4bjwK0=; b=wBEaF3CgC0UMp93fuYVbU76u8EEqyyvgU9ihz/fNom3XyrhVtogvavyD/WSwsk6/MG lNdeXALsGJOrPRfl6VKWzx68cVqeJoASf7Ysw/l8oNCGxmxTpig3r/rUnzhAJIgh9xRo inBvN5ttjp9378tbaoAHANOldfYzZ08QQmtxq3A4ZGtbkRuEYUIGLwWKGKESqAUplCCS PSCsq89bpuEU2HAnxZPHX0vTMMmAb3rVF+HkXx9zn9zv8zQK4ueFg9VucOr778UErn7q wZelFK8TABW5+huB0IfarjqhjOPOAa6JuLZdSHCl04kfNANXR4wHfTjWAQvCMW9Esc/j znVg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id go9si3915144plb.404.2019.03.12.09.29.35; Tue, 12 Mar 2019 09:29:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726612AbfCLQ25 (ORCPT + 99 others); Tue, 12 Mar 2019 12:28:57 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:44216 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725894AbfCLQ25 (ORCPT ); Tue, 12 Mar 2019 12:28:57 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x2CGOJs5141171 for ; Tue, 12 Mar 2019 12:28:55 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0a-001b2d01.pphosted.com with ESMTP id 2r6fx4smyu-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 12 Mar 2019 12:28:54 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 12 Mar 2019 16:28:53 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 12 Mar 2019 16:28:50 -0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x2CGSnfi12189780 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Mar 2019 16:28:49 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4812352057; Tue, 12 Mar 2019 16:28:49 +0000 (GMT) Received: from nimbus.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.33]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 808BA5204F; Tue, 12 Mar 2019 16:28:48 +0000 (GMT) Subject: Re: [PATCH] mm/slab: protect cache_reap() against CPU and memory hot plug operations To: Michal Hocko Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org, Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton References: <20190311191701.24325-1-ldufour@linux.ibm.com> <20190312145813.GS5721@dhcp22.suse.cz> From: Laurent Dufour Date: Tue, 12 Mar 2019 17:28:47 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <20190312145813.GS5721@dhcp22.suse.cz> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19031216-0020-0000-0000-00000321B665 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19031216-0021-0000-0000-00002173E2BF Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-03-12_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903120114 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 12/03/2019 à 15:58, Michal Hocko a écrit : > On Mon 11-03-19 20:17:01, Laurent Dufour wrote: >> The commit 95402b382901 ("cpu-hotplug: replace per-subsystem mutexes with >> get_online_cpus()") remove the CPU_LOCK_ACQUIRE operation which was use to >> grap the cache_chain_mutex lock which was protecting cache_reap() against >> CPU hot plug operations. >> >> Later the commit 18004c5d4084 ("mm, sl[aou]b: Use a common mutex >> definition") changed cache_chain_mutex to slab_mutex but this didn't help >> fixing the missing the cache_reap() protection against CPU hot plug >> operations. >> >> Here we are stopping the per cpu worker while holding the slab_mutex to >> ensure that cache_reap() is not running in our back and will not be >> triggered anymore for this cpu. >> >> This patch fixes that race leading to SLAB's data corruption when CPU >> hotplug are triggered. We hit it while doing partition migration on PowerVM >> leading to CPU reconfiguration through the CPU hotplug mechanism. > > What is the actual race? slab_offline_cpu calls cancel_delayed_work_sync > so it removes a pending item and waits for the item to finish if they run > concurently. So why do we need an additional lock? You're right. Reading cancel_delayed_work_sync() again I can't see how this could help. The tests done with that patch were successful, while we were seeing a SLAB data corruption without it, but this needs to be investigated further since this one should not help. This was perhaps a lucky side effect. Please forgot about this one. > >> This fix is covering kernel containing to the commit 6731d4f12315 ("slab: >> Convert to hotplug state machine"), ie 4.9.1, earlier kernel needs a >> slightly different patch. >> >> Cc: stable@vger.kernel.org >> Cc: Christoph Lameter >> Cc: Pekka Enberg >> Cc: David Rientjes >> Cc: Joonsoo Kim >> Cc: Andrew Morton >> Signed-off-by: Laurent Dufour >> --- >> mm/slab.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/mm/slab.c b/mm/slab.c >> index 28652e4218e0..ba499d90f27f 100644 >> --- a/mm/slab.c >> +++ b/mm/slab.c >> @@ -1103,6 +1103,7 @@ static int slab_online_cpu(unsigned int cpu) >> >> static int slab_offline_cpu(unsigned int cpu) >> { >> + mutex_lock(&slab_mutex); >> /* >> * Shutdown cache reaper. Note that the slab_mutex is held so >> * that if cache_reap() is invoked it cannot do anything >> @@ -1112,6 +1113,7 @@ static int slab_offline_cpu(unsigned int cpu) >> cancel_delayed_work_sync(&per_cpu(slab_reap_work, cpu)); >> /* Now the cache_reaper is guaranteed to be not running. */ >> per_cpu(slab_reap_work, cpu).work.func = NULL; >> + mutex_unlock(&slab_mutex); >> return 0; >> } >> >> -- >> 2.21.0 >