From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.127.231.113 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796120903; b=w3AyJbpO5NP79O7CYfE7Ex1ynLlwVzZ8Gx6PVMhaBLjLZ4e9u2vKlutSLfPzJ80abvb0 hYDPo7Odk/vj2xQBlR2TqdXzpO8tRM/TKvOb3CuSIme0YlC8bi96Ait5x28ViEsGondIR DVOos/ue4EvlhB71FjLDmZXT+3ev2XWECVNnOUFUCPd7OSAjN7mKyE+ZwU4OJ76ZlGsC+ v3a4+uuWhxa/qpVPFOysw0yISoO/Dw2r22gXP8mxJzUV2wHr4fqRw/SbHHUgD/LqQNYZD 823iQbj6rRddP2fDXlliRCeDznuCmqHcvHTjFrljl58kj9SGYQi7HyRH3lZjXVIy7TQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796120903; h=DMARC-Filter:DKIM-Signature:Content-Type:References:Content-Language: In-Reply-To:User-Agent:Date:Mime-Version:X-Lms-Return-Path:Autocrypt: From:Cc:Subject:Message-Id:X-Original-From:Content-Transfer-Encoding: To; bh=9ua7FZjV8Ia5LSAp0IiWk4/ddAQCAFPClDIPineZGzQ=; b=VOnncf/hoKoZ0Yvm0su1/A6FgHIkHiq9D3lywG6LvDB2a+/YTbgOay6325aYXDr/wJPB qGHsTsNJqEvZ6V70uPo30FsYzEbC3GFM6kv2vvs5llcf8Yr/3331Jiq1IsrC4xy9eERYR 1hf94Xt9dkY2xlxBqpVA403uoJkgvc2StsL7ZVSHsNcOphUcGJVXVLNpElovis2SjDajV +A1Gif5TRAMXDkkgingJgTsbtDN8Xv8brI7EmOjYdHIL0X3pYrDwLJBDnDY2vr2ZliTUH 8zPJ12bgiUAq/1AGQpeMdANqte2MFxEc+4/JfjyG97S9f/TamQVnySqKwp6BZ4TrOSw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=2212171451 header.b=Rgnr6c+R; arc=none smtp.remote-ip=209.127.231.113 Received: from va-2-113.ptr.blmpb.com (va-2-113.ptr.blmpb.com [209.127.231.113]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DCE0606A6B9 for ; Tue, 1 Dec 2026 10:28:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6DCE0606A6B9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=2212171451 header.b=Rgnr6c+R DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1796120897; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=9ua7FZjV8Ia5LSAp0IiWk4/ddAQCAFPClDIPineZGzQ=; b=Rgnr6c+RlrAs2LhpetrN7isBIquW6RHg4QAFJut8JBU6x2WpMeuv7XyNxQzgx0cJqWERWs 4/rj1gugmIfp1DsydVZqVTSXlyxuME04rIDSHRBI3+KjfdSBOKt5Bb9zhxTCB+oAATxg+4 sbswRiBz0H+aYFLcgIdyMq9ZEl+jNykTtP2puHEl5CEKLB2kH8YNjnmr12aIqSVRmosdj6 +SwqgRsNCgMaqY+F+LvwnZ68DoziXRXNGqmDQzwvZeHfH+wlK4uF5BMkZqbk9hHclUaOuJ P1COVJZUAFC3FtLDpHQE0AV+E50TOYSlAC2Ciz1IWei9BOVXuNEdOgg4AnnzuQ== Content-Type: text/plain; charset=UTF-8 References: <20261128124922.3900189-1-hanguidong02@gmail.com> Content-Language: en-US In-Reply-To: <20261128124922.3900189-1-hanguidong02@gmail.com> User-Agent: Mozilla Thunderbird Date: Tue, 1 Dec 2026 18:28:04 +0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Lms-Return-Path: Autocrypt: addr=wuqiang.matt@bytedance.com; keydata= xsDNBGOidiIBDADKahCm8rTJ3ZgXTS0JR0JWkorMj3oNDI0HnLvHt8f9DBmjYyV11ol0FYUr uJ230wjVVKLMm0yBk3jX7Dsy0jggnIcVlINhaXV9DMxzLBM7Vc55FuB9M5/ZaSrM+V5LeG+t nPbZie6yzJbNpdGBdVXnXiOAEgT9+kYqgCRBOJdpzZyEHv14elfGOMo8PVCxiN2UEkCG+cg1 EwfMgy2lZXsGP/By0DaEHnDtyXHfNEwlyoPHOWu7t+PWCw3FgXndX4wvg0QN0IYqrdvP+Tbl YQLAnA9x4odjYvqwfUDXavAb7OHObEBrqNkMX7ifotg64QgZ0SZdB3cd1Az5dC3i0zmGx22Q pPFseJxGShaHZ0KeE+NSlbUrz0mbiU1ZpPCeXrkuj0ud5W3QfEdHh00/PupgL/Jiy6CHWUkK 1VN2jP52uUFYIpwUxaCj1IT9RzoHUMYdf/Pj4aUUn2gflaLMQFqH+aT68BncLylbaZybQn/X ywm05lNCmTq7M7vsh2wIZ1cAEQEAAc0kd3VxaWFuZyA8d3VxaWFuZy5tYXR0QGJ5dGVkYW5j ZS5jb20+wsEHBBMBCAAxFiEEhAnU1znx1I9+E57kDMyNdoDoPy8FAmOidiMCGwMECwkIBwUV CAkKCwUWAgMBAAAKCRAMzI12gOg/LzhCC/sEdGvOQbv0zaQw2tBfw7WFBvAuQ6ouWpPQZkSV 3mZ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EHKR0xQTm5yzgIpAi76f4yrRcoBgricEH22SnLyPZsUa4ZX/TKmX4WFsiOy4/J KxCFMiqdkBcUDw8g2hpbpUJgx7oikD06EnjJd+hplxxj+zVk4mwuEz+gdZBB01y8nwm2ZcS1 S7JyYL4UgbYunufUwnuFnD3CRDLD09hiVSnejNl2vTPiPYnA9bHfHEmb7jgpyAmxvxo9oiEj cpq+G9ZNRIKo2l/cF3LILHVES3uk+oWBJkvprWUE8LLPVRmJjlRrSMfoMnbZpzruaX+G0kdS 4BCIU7hQ4YnFMzki3xN3/N+TIOH9fADg/RRcFJRCZUxJVzeU36KCuwacpQu0O7TxTCtJarxg ePbcca4cQyC/iED4mJkivvFCp8H73oAo7kqiUwhMCGE0tJM0Gbn3N/bxf2MTfgaXEpqNIV5T Sl/YZTLL9Yqs64DPNIOOyaKp++Dg7TqBot9xtdRs2xB2UkljyL+un3RJ3nsMbb+T74kKd1WV 4mCJUdEkdwCS From: "wuqiang.matt" Cc: "Andrew Morton" , , , Subject: Re: [PATCH] objpool: fix missing acquire when reading slot->last Message-Id: X-Original-From: "wuqiang.matt" Content-Transfer-Encoding: quoted-printable To: "Gui-Dong Han" , "Masami Hiramatsu" Indeed, 'obj =3D READ_ONCE()' could be re-ordered before the if-branch. And smp_load_acquire() can make sure the correct order. Has this issue been reproduced on real hardware? If you don=E2=80=99t mind = sharing, what CPU/architecture is it? Masami, please help review and include this patch into your patch set if it's appropriate to you. Thanks. Reviewed-by: Matt Wu On 2026/11/28 20:49, Gui-Dong Han wrote: > __objpool_try_add_slot() writes slot->entries[idx] and publishes it with > smp_store_release(&slot->last, tail + 1). __objpool_try_get_slot() > checks slot->last with plain READ_ONCE() before loading > slot->entries[idx]. >=20 > Because idx is derived from head rather than slot->last, there is no > address dependency to order the entry load after the slot->last checks. > On weakly ordered architectures, the entry load can be reordered after > smp_load_acquire(&slot->head) but before the slot->last checks, reading > a stale entry from the previous ring cycle: >=20 > // Initially: head =3D=3D last =3D=3D k, entries[idx] holds old_obj >=20 > CPU 0 CPU 1 > ----- ----- > // __objpool_try_add_slot() // __objpool_try_get_slot() > head =3D smp_load_acquire(&slot->head); > // reordered before slot->last checks: > obj =3D READ_ONCE(slot->entries[idx]); > // reads old_obj > WRITE_ONCE(slot->entries[idx], new_obj); > smp_store_release(&slot->last, k + 1); > while (head !=3D READ_ONCE(slot->last)) > // sees k + 1 > if (READ_ONCE(slot->last) - head - 1 > >=3D pool->nr_objs) > // sees k + 1 > try_cmpxchg_release(&slot->head, > &head, k + 1); > return obj; >=20 > CPU 1 then returns old_obj while new_obj is lost. >=20 > Use smp_load_acquire(&slot->last) in the range check to pair with > smp_store_release(&slot->last, ...). The initial loop condition can > remain READ_ONCE(). >=20 > Fixes: b4edb8d2d464 ("lib: objpool added: ring-array based lockless MPMC"= ) > Signed-off-by: Gui-Dong Han > --- > include/linux/objpool.h | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) >=20 > diff --git a/include/linux/objpool.h b/include/linux/objpool.h > index b713a1fe7521..8350302d6e15 100644 > --- a/include/linux/objpool.h > +++ b/include/linux/objpool.h > @@ -144,7 +144,8 @@ static inline void *__objpool_try_get_slot(struct obj= pool_head *pool, int cpu) > * that is equivalent to 'last - head - 1 < nr_objs' as > * 'last' and 'head' are both unsigned int32 > */ > - if (READ_ONCE(slot->last) - head - 1 >=3D pool->nr_objs) { > + /* pair with smp_store_release() in __objpool_try_add_slot() */ > + if (smp_load_acquire(&slot->last) - head - 1 >=3D pool->nr_objs) { > head =3D READ_ONCE(slot->head); > continue; > } >=20 > base-commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc