Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=162.62.57.87 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795935668; b=gNIpQMLPw0HHLdaBHbbu+ViHiVmhHIoaKP56hz+/sNSLYuas6iVAVoCXqTDVIWyFagrq HnPG19SMhC7xTMjVD3Ee5PEmH2f/MkPTtaFOKFY1gDtTUU4l1Xrp8Y5dowNW1WskWQDOg apE0KnIOXgInSbEOnPD5j7HqDPyjz5jnZQVhvsZ2I0xsfulZwOH3UIsx760Eo3YtT5mOd tKDxOLjUYykmys05A/cNUaxOoaG47PG3WqEmo9lb+iyiExSKxIhbb4zIWVRfmaa+RyXj+ 8aQuJqLgS9tH1fdoItq7MoWkxX0Iku2dPuoPQiw0nQPgMDR8Oe0d2FivZImZj4yr8VA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795935668; h=DMARC-Filter:DKIM-Signature:Received:X-QQ-mid:Message-ID: X-QQ-XMAILINFO:X-QQ-XMRINFO:From:To:Cc:Subject:Date:X-OQ-MSGID: X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=/nxyLlhLJ93kL9oTFhm5f7fN9ls36IONQQMZokb3wCA=; b=5f860dPtOZqELEgK83qT3nUMvGWepFpm2rHRUiVMcRDekKg1GBI+xmvrqr9PE11+bsrr hXBZz9VXFBFwE5ydMTyEdMuAKIoRSnWOC4i3dsk+ffCU3CrHXPKD/QlGgu0gDdw8L6RRO NSjjI/3tpc47j6pNfSJ4ncZe2TN76jvpoRDfZ9DZx/rQJJ5PdU/XkqZGninbdxvVhPRUc CJwQ565xIR7fCziVsAfAJmYh2TfyfK77C95p6vt6f9e3DjVEtbVL/U9uly772PMVum/kF 4vcl89p10BwjUlqBDp86X9Uf1HmZ/M/yxGHpalSvNcl02rgd5cN6r9c7fY9vT3LOh/g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=qq.com; spf=pass smtp.mailfrom=qq.com; dkim=pass header.d=qq.com header.i=@qq.com header.a=rsa-sha256 header.s=s201512 header.b=EIljq6UY; arc=none smtp.remote-ip=162.62.57.87 Received: from out162-62-57-87.mail.qq.com (out162-62-57-87.mail.qq.com [162.62.57.87]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A697C606A31C for ; Sun, 29 Nov 2026 07:01:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A697C606A31C 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=qq.com header.i=@qq.com header.a=rsa-sha256 header.s=s201512 header.b=EIljq6UY DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1795935661; bh=/nxyLlhLJ93kL9oTFhm5f7fN9ls36IONQQMZokb3wCA=; h=From:To:Cc:Subject:Date; b=EIljq6UY8WCa60PJZDEuGEx2rAzvucLMKrOMMKcPCxdrGCRLRRHnCV0CmzJbtTlnO OiJ7jeg2udDr54cF1z2zYTDSdBjWnilLPPVWkDI+2HnUjxmE5pSOtVCefTkLNcgLFb zodzjMCMAXuHpUCtjOSaakAPrtTkD+rCQF9FNndM= Received: from shuai-VMware-Virtual-Platform.. ([39.165.245.102]) by newxmesmtplogicsvrszc56-0.qq.com (NewEsmtp) with SMTP id 3B38EA4; Sun, 29 Nov 2026 15:00:59 +0800 X-QQ-mid: xmsmtpt1795935659ti120defk Message-ID: X-QQ-XMAILINFO: MH5d/PVfwqP9TVmtJ4Lzf6vmHcombwcVwGep5kavS2trDFo6NWfoM0fnukLdrX aW27GKXlQmBCJ1QJIDY9RhmWXQJCac9bH13Ty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shuai Liu <847807867@qq.com> To: willy@infradead.org, linux-fsdevel@vger.kernel.org Cc: linux-mm@kvack.org, elver@google.com, syzbot+cc64b6bdf649b54047e0@syzkaller.appspotmail.com, Shuai Liu <847807867@qq.com> Subject: [PATCH] xarray: add READ_ONCE() in xas_find_chunk() Date: Sun, 29 Nov 2026 15:01:00 +0800 X-OQ-MSGID: <20261129070100.1012888-1-847807867@qq.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit xas_find_chunk() reads xa_node->marks with a plain dereference while concurrent xa_set_mark()/xa_clear_mark() writers use non-atomic __test_and_set_bit()/__test_and_clear_bit() under xa_lock. RCU readers in xa_find() -> xas_find_marked() -> xas_find_chunk() call this without xa_lock, so the plain read races with the locked non-atomic write. KCSAN flags this as a data race, and Marco Elver notes the failure scenario is worse than benign: the compiler can hoist *addr into a register on the reader. When a concurrent writer later clears a mark bit, the cached stale value causes xas_find_chunk() to keep returning the cleared offset. xas_find_marked() then loops forever looking for an entry at that offset under rcu_read_lock(). Load the marks word once via READ_ONCE(*addr) into a local variable, then do all bit operations on that snapshot. This silences KCSAN, forces a fresh load on each call, and prevents the compiler from caching the stale value across iterations. Reported-by: syzbot+cc64b6bdf649b54047e0@syzkaller.appspotmail.com Signed-off-by: Shuai Liu <847807867@qq.com> --- include/linux/xarray.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/linux/xarray.h b/include/linux/xarray.h index be850174e802e..8c898b846bde8 100644 --- a/include/linux/xarray.h +++ b/include/linux/xarray.h @@ -1744,19 +1744,21 @@ static inline unsigned int xas_find_chunk(struct xa_state *xas, bool advance, { unsigned long *addr = xas->xa_node->marks[(__force unsigned)mark]; unsigned int offset = xas->xa_offset; + unsigned long marks; if (advance) offset++; + marks = READ_ONCE(*addr); if (XA_CHUNK_SIZE == BITS_PER_LONG) { if (offset < XA_CHUNK_SIZE) { - unsigned long data = *addr & (~0UL << offset); + unsigned long data = marks & (~0UL << offset); if (data) return __ffs(data); } return XA_CHUNK_SIZE; } - return find_next_bit(addr, XA_CHUNK_SIZE, offset); + return find_next_bit(&marks, XA_CHUNK_SIZE, offset); } /** -- 2.43.0