Received: by 2002:ab2:5d18:0:b0:1ef:7a0f:c32d with SMTP id j24csp57767lqk; Sat, 9 Mar 2024 00:02:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU+qjpYADhyVDaZ5GVoLykedrjVut5R67TMu7N6DONYJ0VlTSukyJw/dUMyh2rGuUluWj7W4Xtn8zLkaq/YqqQRKmlvOAZxRK7s+6wixg== X-Google-Smtp-Source: AGHT+IGS6hCE1cYLVKN/GAT8HyBJw55mpWisRf0MV+cZvnuDPkcdaVi7hrsC0nNzZ4jMMlhkN9Ym X-Received: by 2002:a05:6e02:1542:b0:365:fe08:8262 with SMTP id j2-20020a056e02154200b00365fe088262mr1349896ilu.26.1709971340295; Sat, 09 Mar 2024 00:02:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709971340; cv=pass; d=google.com; s=arc-20160816; b=MIqCHF/M4ZdhhRjn4rdBBjKbjJgQSeCbVbB0GvIvUvB/tb+pMLzf/S9U260GpU01Xo FIiBYe4sGSq9R3/WFaTxzrPraUXK1hC0h5JsZDtoajxZNujjIhT/nSBfZfKbso4ZVNOB cJ/OB4XL3RJHgdL8mDbPb0RBNpd79MFQnnCLG7sDFXD6Df5zJyg+1GPeUsmdxWnpsC5e NDG47wixHlDPB2ZufGT9BeyUH6LDavbgP0VudOEf9kWBeNFPfPb2Gb4RZfr+U4Z1zRPZ OhE2ksxPXxDpbPK7VaJfiGmLriDtH2QgYSPGb3nGpmeuLgRzWaKFggN1zBSnkuqOrdnp dt9w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:subject:cc:to:from :message-id:dkim-signature; bh=MgdYsqpogfEC4dYs/sinBQ9e0RstZ+X/AARjVyBi1JM=; fh=gN/GqQzbvi+2vQbvqR0wAl9aHHj13kvSGvwavNKh94o=; b=oFp6qiXIlVZ0vw/wW2qilmoLnx6IX2yfGtES234hbAGPd43F2P2G8dcSryXsvpJHgx D7yYtFcIyPO3uxftJpTOg523As/o01PgmqyrYjV3G+zdY/Q2CxJvMAaUxzytuueleQyD T49a64xYMhwRwrEtF62f5EekdDAhpHqiXByBAVOLQkw53CNM8g3+MaFazCW9pSGsdTj7 vYCNECNZ+Hfg2MX4rhtRtkrAkSlWzwF4nLtZkcKwLWLEph6cgUmttPyjvT4sFfL61ZbE VwAFsREUcUyd53Uy5jEVgFAAKPzxkTM1j+Q+rPxoz8zz4hcx8I/s85K+Mzw7WCUVsp8T 8DTQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@qq.com header.s=s201512 header.b=ePZulBAo; arc=pass (i=1 spf=pass spfdomain=qq.com dkim=pass dkdomain=qq.com dmarc=pass fromdomain=qq.com); spf=pass (google.com: domain of linux-kernel+bounces-97800-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97800-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=qq.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e18-20020a637452000000b005dbec97f04fsi1175348pgn.589.2024.03.09.00.02.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Mar 2024 00:02:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97800-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@qq.com header.s=s201512 header.b=ePZulBAo; arc=pass (i=1 spf=pass spfdomain=qq.com dkim=pass dkdomain=qq.com dmarc=pass fromdomain=qq.com); spf=pass (google.com: domain of linux-kernel+bounces-97800-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97800-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=qq.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 842D1281B32 for ; Sat, 9 Mar 2024 08:02:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 86749374C2; Sat, 9 Mar 2024 08:02:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b="ePZulBAo" Received: from out162-62-57-210.mail.qq.com (out162-62-57-210.mail.qq.com [162.62.57.210]) (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 890FD2C6A9 for ; Sat, 9 Mar 2024 08:02:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.62.57.210 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709971333; cv=none; b=EsLVL28LLt6Cd0c8Dn2zXDqayndLA+awniq+e3OwHzmNr70L3xIIftfuuudwbBa2Vb1KxqJxRMtpcuXaSu4KbkYjQazBpiw/Dghhi7eutLI6M+pBCIenF3hgPfoKVUus/JaUBDcgIv2HRBJkD1svAZH3rNUrLXSRTbBPXb/2hbE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709971333; c=relaxed/simple; bh=ONR25plKwc8F4QQjteikUYxTn8xZ48iS+AvAl7Lze7g=; h=Message-ID:From:To:Cc:Subject:Date:MIME-Version; b=ftzA79kE+cHunbmt6MwQIJDuUgshHhx4+d/YOH8vvHzgYsKXyY08BeU+Eiz3Wq6PFlkV8SJoTGNe/Yo3O0ORdtcrocAIRaP2xFs5cdNLVQUHfqMTcYuh33dJjMo/yLpORz0rHY7M0/eIYaluIA1uwlwaeeckupGigWxYz1Ro274= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com; spf=pass smtp.mailfrom=qq.com; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b=ePZulBAo; arc=none smtp.client-ip=162.62.57.210 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qq.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1709971020; bh=MgdYsqpogfEC4dYs/sinBQ9e0RstZ+X/AARjVyBi1JM=; h=From:To:Cc:Subject:Date; b=ePZulBAoAyWrXiNB7b+6u6WgnLF6h58HdHEeV5+ntoAb4Vax3aw9bMCvEUxSdQ+/V oN85RkMnralfZBe/kZFQsGYnEn2E3xQOV1LzB6194wUFEWK90IxqvnTHy8do3IPiNf 0UEYxESilPKaBKpv13tztRCh2rfal0Z9XXksrnMQ= Received: from localhost.localdomain ([58.213.8.163]) by newxmesmtplogicsvrszc5-1.qq.com (NewEsmtp) with SMTP id E3907482; Sat, 09 Mar 2024 15:56:57 +0800 X-QQ-mid: xmsmtpt1709971017tf0kf6ubj Message-ID: X-QQ-XMAILINFO: MIAHdi1iQo+zZ0BjCihli4BE3n5peZ8ehZdgt+CX+t6VAX7Vg4DYl3oLjf9ily cxzVXzLazy0ntdTUjO3IosXsJPIv8Lp8GHaaXRi8Wv5sa12GdzfOF16WV75+bASzw0mCA0XH3MfI whHosZOMB/RNG6n7bEk/SjQzq4NyoQ1ub0wuEW4hm0RECzeSv3RcDmI6vcapP1zJvo3qBsdZb7DG lOFakRUUn8bSxepyq7BKDYDTY2cQKE2eWoeW67QlMtc93Vdt6GdY257/kGeFj6lOuPFK/tbYaRk3 /dF3DUXG2aj3vDoRnpwW0RfRZ2XqeTgZa25L1g40nvZNRZOEoTEyeoGY0WM/hOzjGeP/M4LMZ8oG 3dTa7Q4i5ElDBsNo3JVKcomIX/3GSZ+PsDIoQ7dR6xOr78IMPoQ5ZdwnSMIZ9qG34W05uBEihnBl okU0zy8PMrVuXUUY/yULRmJdN9UPu+C399H1rR7/bYDmM9CdXdVqDpn7Zs1aPvIeTWC6ldTGoo7A jdbYjW80j79dfT/XiBUiNjPXWznOE241ihSj9Mgxu/f8yiVAYj3v5fLzsMIr6cuPE45gG9ESf+UL QDkqY5ntkHc2Ab1vhlNePtfgoJtCmHDOcrA+VlM2szfR1uUzakfJ0V5l4GJYybtZRa8eHDPz1E9G nAkine/urV8nIBjNAg/95ItzcBi9ImZpCcF+0jnYYrDeC0MVXLiJm9ZnJds3kIb4XQrJlewGEwt7 SiWMEldGn3LsT+zuipKk0ZLeE99c//WiAWQpborqHpm0X43E1TQSWXrtTA2f232YY5FR2P2S4Rtf V6Nmlo9usZJkZBOEKFHFMTyl1E4euuIj2Rc6r1GClJvaGSaFxVVOWcJ4kwLcKKKwlNwak6eiWKbF 995H7SDjf5aUnoXcd2Dg1Gra3IRNJ0flZK3C4PQftf5bMJdAi2Mp7vRzHSnE1Ba89Ujlnqk2uNN5 UEMgzhTIx3Ae9xLkl62rI4M12AcgLKnianHdYulybaA9ydK9yq4m0QitR69fZoIhkST04cGX0/WN 9cNUdtjPWBnQiHRD2dizb8qUUTUA4= X-QQ-XMRINFO: OWPUhxQsoeAVDbp3OJHYyFg= From: linke li To: Cc: lilinke99@qq.com, 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 Subject: [PATCH] mm/slub: mark racy accesses on slab->slabs Date: Sat, 9 Mar 2024 15:48:56 +0800 X-OQ-MSGID: <20240309074856.49648-1-lilinke99@qq.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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); -- 2.39.3 (Apple Git-146)