Received: by 2002:ab2:5d18:0:b0:1ef:7a0f:c32d with SMTP id j24csp122349lqk; Sat, 9 Mar 2024 03:25:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUNAsI0DcT/K3XZHaBzI1F6S/vM2mgYbsD3f0mqOJPichP1zKQ43euaR9cIfwh0Ymdt6NgEqzkNo54l2hDin7Be2jHN5AbxHYDuByaeGg== X-Google-Smtp-Source: AGHT+IE9d0wRw54avmi17fW4ivK9wK1YPVFrZLO6UoIgAiKrKa2vN5zhVsY3VDvrZm+A7aoYjMp9 X-Received: by 2002:a17:907:a70c:b0:a45:4771:e0de with SMTP id vw12-20020a170907a70c00b00a454771e0demr1158585ejc.15.1709983505161; Sat, 09 Mar 2024 03:25:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709983505; cv=pass; d=google.com; s=arc-20160816; b=MqpBEcBPMnVlTAftl4PwlyNYy6EgkeFk9vq/kXWF524Zxc36CgtAKbe8MYgl5Hoagz kp6w8q/4ocKJImwjA/70R7IoI+tQHsrq5SppPsIyTRZT+8tw+JDETPNXaHnMscLIwpdz nG4wZ8JJqYOq+7lfzAqjlIp66mRmKMOWIJPLs+fPNi9FGaSXvXB4cJKnNenSJ5D4HLUB 2FS4Q6L0x8Sc6F7rlbYc8P82+THjQdvfWP2Qh24mDz0y/+kxAD6t6Nvm/ol2FIBRGKk2 8ZOFd0HRNjpnstZkboEISvNVq/HvinkwoZ7zTY1R+3BqJXo5CR/7tO0FPSQhNafyQfGz LVvg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature:message-id; bh=eL7mM7sZYIm+/FYyJAxbcAh676RdIHz8wgb5OtaQOqQ=; fh=dUVvQqY+a3JNFJR2sXuPOHYMTV5eH8KhjNuipt2ts9E=; b=CO3zWHwmpGwhlOqSEYyHh65MEnc17r2Ry8Vf0iMzfZic6ir4Ml0RQWx2ZpBmMxdkcJ 2r/xKMwQ7XV2GVKxO6Aqk1Ydx5/Tl8HeBZ8H3fmyxv/fWMCLUPIaZ+0a+0djYddS7YC5 cwKxQDwiDmgXtIA4u/cYXxuKJYhWQBpUcdy9yi3U6Pqeh1yrfWVi+2BjunztrkSLMC/M 2Pj+SqJtScU24sxdc3qPpPSBwV3lU/ZVc77SaJjQLbBcJklnfzwprXSaHWVzTsR9ZaR+ FWQ0+GwS0D77QzFeFHbcHCYgBPoQqScYlMZgzmFVmShZcungNTk7Go0SwTzOAhVycfR0 fgRw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=P8HBvKE8; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-97864-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97864-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id um3-20020a170906cf8300b00a45a738e8f1si691624ejb.706.2024.03.09.03.25.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Mar 2024 03:25:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97864-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=P8HBvKE8; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-97864-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97864-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id ADAB71F2171F for ; Sat, 9 Mar 2024 11:25:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 27FEA36AEC; Sat, 9 Mar 2024 11:24:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="P8HBvKE8" Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07134364AB for ; Sat, 9 Mar 2024 11:24:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709983497; cv=none; b=XFLpgV9tcZoPPUUHwe2XRaFzzZ93xmRg8Bhpy7m1DJgujzH1R/Ykeh/VmoU7ecmJa9i2ElHsGpKkpEQ4sKAY+sJd0MY3UwHOtJ/wGytCy1DBVqX+LXefuKF+onXsaUMl9qiXE3iNNglNhNUafVbgFvikkphLh2lFZlMVrQPhXUk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709983497; c=relaxed/simple; bh=1740AqjlhtbDQcgr3kz2VUTqsFMO67FamFli+bFM8gA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Wn1/gdgtXI/tzFrCC+HDqwESleB17A6niqrllWaDlNJyeZCdcWME1x6zTSn+If92qSKTsn20G4HI7QgiNRIMJc8H9mJbkmVmEe2yLOpc+2pOGMW1JC+pELUBgEbZDxjvKbRyVMba0bnJkLQn0bdBzdm/yzlxz7MyjM+Dj3g9F5U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=P8HBvKE8; arc=none smtp.client-ip=91.218.175.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Message-ID: <8bc1aebf-8395-416f-8c23-53cbd25d0eef@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1709983492; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eL7mM7sZYIm+/FYyJAxbcAh676RdIHz8wgb5OtaQOqQ=; b=P8HBvKE8AWR+nWpWUoVPjwvk3yc6jQPFvPcr7KtVMESfTR55wM1FSzLKpvQ8P+Kj4NCPPV ZeHlzKjWzvHSMuZHuHoYKKUykgys45sWKm+xuGAM9NBbqHnUXHQaaENnc9Ga7XRPOEsAZ8 aFxe15F4yQ3UMPDxHFKIOrsBBMWvMKI= Date: Sat, 9 Mar 2024 19:24:11 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH] mm/slub: mark racy accesses on slab->slabs Content-Language: en-US To: linke li Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 2024/3/9 15:48, linke li wrote: > The reads of slab->slabs are racy because it may be changed by > put_cpu_partial concurrently. And in slabs_cpu_partial_show ->slabs is > only used for output. Data-racy reads from shared variables that are used > only for diagnostic purposes should typically use data_race(), since it > is normally not a problem if the values are off by a little. > > This patch is aimed at reducing the number of benign races reported by > KCSAN in order to focus future debugging effort on harmful races. > > Signed-off-by: linke li > --- > mm/slub.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/mm/slub.c b/mm/slub.c > index 2ef88bbf56a3..7b20591e7f8a 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -6257,7 +6257,7 @@ static ssize_t slabs_cpu_partial_show(struct kmem_cache *s, char *buf) > slab = slub_percpu_partial(per_cpu_ptr(s->cpu_slab, cpu)); > > if (slab) > - slabs += slab->slabs; > + slabs += data_race(slab->slabs); > } > #endif > > @@ -6271,7 +6271,7 @@ static ssize_t slabs_cpu_partial_show(struct kmem_cache *s, char *buf) > > slab = slub_percpu_partial(per_cpu_ptr(s->cpu_slab, cpu)); > if (slab) { > - slabs = READ_ONCE(slab->slabs); > + slabs = data_race(slab->slabs); > objects = (slabs * oo_objects(s->oo)) / 2; > len += sysfs_emit_at(buf, len, " C%d=%d(%d)", > cpu, objects, slabs); There is another unmarked access of "slab->slabs" in the show_slab_objects(), which you can change too. I'm not sure that it's really safe to access "slab->slabs" here without any protection? Although it should be no problem in practice, alternative choice maybe putting partial slabs count in the kmem_cache_cpu struct. Thanks.