From: sashiko-bot@kernel.org
To: "Yunhui Cui" <cuiyunhui@bytedance.com>,
pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu,
alex@ghiti.fr, dennis@kernel.org, tj@kernel.org, cl@gentwo.org,
oleg@redhat.com, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com,
martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev,
jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev,
bjorn@kernel.org, pulehui@huawei.com, puranjay@kernel.org,
broonie@kernel.org, dave@stgolabs.net,
david.laight.linux@gmail.com, jszhang@kernel.org,
tglx@kernel.org, conor.dooley@microchip.com, thuth@redhat.com,
ajones@ventanamicro.com, ben.dooks@codethink.co.uk,
rkrcmar@ventanamicro.com, samuel.holland@sifive.com,
zong.li@sifive.com, debug@rivosinc.com, seanwascoding@gmail.com,
andybnac@gmail.com, menglong8.dong@gmail.com,
cyrilbur@tenstorrent.com, wangruikang@iscas.ac.cn,
atishp@rivosinc.com, apatel@ventanamicro.com, arnd@arndb.de,
nathan@kernel.org, nick.desaulniers+lkml@gma il.com,
morbo@google.com, justinstitt@google.com,
qingfang.deng@siflower.com.cn, linux-mm@kvack.org,
bpf@vger.kernel.org
Subject: Re: [PATCH v11 09/10] riscv: implement preemptible this_cpu cmpxchg128
Date: Thu, 03 Dec 2026 14:39:45 +0000 [thread overview]
Message-ID: <sashiko-outbox-247988@kernel.org> (raw)
In-Reply-To: <20261203135328.32990-10-cuiyunhui@bytedance.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] riscv: __percpu_generic_cmpxchg128() omits RELOC_HIDE(),
duplicates generic
--
commit b38800d13faff5874a8e355c1c5f3c4b3deddc6f
Author: Yunhui Cui <cuiyunhui@bytedance.com>
riscv: implement preemptible this_cpu cmpxchg128
This commit adds preemptible 128-bit this_cpu_cmpxchg128() support on
RISC-V using amocas.q when Zacas is available, with a local-IRQ-disabled
fallback otherwise.
> diff --git a/arch/riscv/include/asm/percpu.h b/arch/riscv/include/asm/percpu.h
> index 5e7365044eae5..a9d8620417e1b 100644
> --- a/arch/riscv/include/asm/percpu.h
> +++ b/arch/riscv/include/asm/percpu.h
[ ... ]
> +static __always_inline u128
> +__percpu_generic_cmpxchg128(void __percpu *pcp, u128 old, u128 new)
> +{
> + unsigned long flags;
> + u128 *ptr;
> + u128 ret;
> +
> + flags = arch_local_irq_save();
> + ptr = (u128 *)((__force unsigned long)pcp +
> + __my_cpu_offset);
> + ret = *ptr;
> + if (ret == old)
> + *ptr = new;
> + arch_local_irq_restore(flags);
> +
> + return ret;
> +}
[Severity: Medium]
Can computing ptr directly from pcp + __my_cpu_offset without RELOC_HIDE()
be miscompiled on CPUs without Zacas?
When this_cpu_cmpxchg128() is called on a static per-CPU variable in
.data..percpu, GCC assumes arithmetic derived from that symbol stays
within the object's bounds and does not wrap, risking miscompilation and
per-CPU data corruption. SHIFT_PERCPU_PTR() uses RELOC_HIDE() for this.
This helper also duplicates this_cpu_generic_cmpxchg() from
include/asm-generic/percpu.h, skips CONFIG_DEBUG_IRQFLAGS checks by using
arch_local_irq_save()/restore() instead of raw_local_irq_save()/restore(),
and loads __my_cpu_offset unconditionally even when !CONFIG_SMP.
Branching on system_has_cmpxchg128() in this_cpu_cmpxchg128() and falling
back to this_cpu_generic_cmpxchg() would avoid the pointer provenance
issue and drop the duplicate helper.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203135328.32990-1-cuiyunhui@bytedance.com?part=9
WARNING: multiple messages have this Message-ID (diff)
From: sashiko-bot@kernel.org
To: "Yunhui Cui" <cuiyunhui@bytedance.com>,
pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu,
alex@ghiti.fr, dennis@kernel.org, tj@kernel.org, cl@gentwo.org,
oleg@redhat.com, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com,
martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev,
jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev,
bjorn@kernel.org, pulehui@huawei.com, puranjay@kernel.org,
broonie@kernel.org, dave@stgolabs.net,
david.laight.linux@gmail.com, jszhang@kernel.org,
tglx@kernel.org, conor.dooley@microchip.com, thuth@redhat.com,
ajones@ventanamicro.com, ben.dooks@codethink.co.uk,
rkrcmar@ventanamicro.com, samuel.holland@sifive.com,
zong.li@sifive.com, debug@rivosinc.com, seanwascoding@gmail.com,
andybnac@gmail.com, menglong8.dong@gmail.com,
cyrilbur@tenstorrent.com, wangruikang@iscas.ac.cn,
atishp@rivosinc.com, apatel@ventanamicro.com, arnd@arndb.de,
nathan@kernel.org, nick.desaulniers+lkml@gmail.com,
morbo@google.com, justinstitt@google.com,
qingfang.deng@siflower.com.cn, linux-mm@kvack.org,
bpf@vger.kernel.org
Subject: Re: [PATCH v11 09/10] riscv: implement preemptible this_cpu cmpxchg128
Date: Thu, 03 Dec 2026 14:39:45 +0000 [thread overview]
Message-ID: <sashiko-outbox-247988@kernel.org> (raw)
In-Reply-To: <20261203135328.32990-10-cuiyunhui@bytedance.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] riscv: __percpu_generic_cmpxchg128() omits RELOC_HIDE(),
duplicates generic
--
commit b38800d13faff5874a8e355c1c5f3c4b3deddc6f
Author: Yunhui Cui <cuiyunhui@bytedance.com>
riscv: implement preemptible this_cpu cmpxchg128
This commit adds preemptible 128-bit this_cpu_cmpxchg128() support on
RISC-V using amocas.q when Zacas is available, with a local-IRQ-disabled
fallback otherwise.
> diff --git a/arch/riscv/include/asm/percpu.h b/arch/riscv/include/asm/percpu.h
> index 5e7365044eae5..a9d8620417e1b 100644
> --- a/arch/riscv/include/asm/percpu.h
> +++ b/arch/riscv/include/asm/percpu.h
[ ... ]
> +static __always_inline u128
> +__percpu_generic_cmpxchg128(void __percpu *pcp, u128 old, u128 new)
> +{
> + unsigned long flags;
> + u128 *ptr;
> + u128 ret;
> +
> + flags = arch_local_irq_save();
> + ptr = (u128 *)((__force unsigned long)pcp +
> + __my_cpu_offset);
> + ret = *ptr;
> + if (ret == old)
> + *ptr = new;
> + arch_local_irq_restore(flags);
> +
> + return ret;
> +}
[Severity: Medium]
Can computing ptr directly from pcp + __my_cpu_offset without RELOC_HIDE()
be miscompiled on CPUs without Zacas?
When this_cpu_cmpxchg128() is called on a static per-CPU variable in
.data..percpu, GCC assumes arithmetic derived from that symbol stays
within the object's bounds and does not wrap, risking miscompilation and
per-CPU data corruption. SHIFT_PERCPU_PTR() uses RELOC_HIDE() for this.
This helper also duplicates this_cpu_generic_cmpxchg() from
include/asm-generic/percpu.h, skips CONFIG_DEBUG_IRQFLAGS checks by using
arch_local_irq_save()/restore() instead of raw_local_irq_save()/restore(),
and loads __my_cpu_offset unconditionally even when !CONFIG_SMP.
Branching on system_has_cmpxchg128() in this_cpu_cmpxchg128() and falling
back to this_cpu_generic_cmpxchg() would avoid the pointer provenance
issue and drop the duplicate helper.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203135328.32990-1-cuiyunhui@bytedance.com?part=9
next prev parent reply other threads:[~2026-12-03 14:39 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 13:53 [PATCH v11 00/10] riscv: optimize percpu access Yunhui Cui
2026-12-03 13:53 ` Yunhui Cui
2026-12-03 13:53 ` [PATCH v11 01/10] riscv: store percpu offset into thread_info Yunhui Cui
2026-12-03 13:53 ` Yunhui Cui
2026-12-03 14:20 ` sashiko-bot
2026-12-03 14:20 ` sashiko-bot
2026-12-03 13:53 ` [PATCH v11 02/10] riscv: add infrastructure for preemptible this_cpu operations Yunhui Cui
2026-12-03 13:53 ` Yunhui Cui
2026-12-03 14:33 ` sashiko-bot
2026-12-03 14:33 ` sashiko-bot
2026-12-03 13:53 ` [PATCH v11 03/10] riscv: add common primitives " Yunhui Cui
2026-12-03 13:53 ` Yunhui Cui
2026-12-03 14:19 ` sashiko-bot
2026-12-03 14:19 ` sashiko-bot
2026-12-03 13:53 ` [PATCH v11 04/10] riscv: implement preemptible this_cpu read and write operations Yunhui Cui
2026-12-03 13:53 ` Yunhui Cui
2026-12-03 14:23 ` sashiko-bot
2026-12-03 14:23 ` sashiko-bot
2026-12-03 13:53 ` [PATCH v11 05/10] riscv: implement preemptible this_cpu void RMW operations Yunhui Cui
2026-12-03 13:53 ` Yunhui Cui
2026-12-03 14:18 ` sashiko-bot
2026-12-03 14:18 ` sashiko-bot
2026-12-03 13:53 ` [PATCH v11 06/10] riscv: implement preemptible this_cpu add_return operations Yunhui Cui
2026-12-03 13:53 ` Yunhui Cui
2026-12-03 13:53 ` [PATCH v11 07/10] riscv: implement preemptible this_cpu xchg operations Yunhui Cui
2026-12-03 13:53 ` Yunhui Cui
2026-12-03 13:53 ` [PATCH v11 08/10] riscv: implement preemptible this_cpu cmpxchg operations Yunhui Cui
2026-12-03 13:53 ` Yunhui Cui
2026-12-03 13:53 ` [PATCH v11 09/10] riscv: implement preemptible this_cpu cmpxchg128 Yunhui Cui
2026-12-03 13:53 ` Yunhui Cui
2026-12-03 14:39 ` sashiko-bot [this message]
2026-12-03 14:39 ` sashiko-bot
2026-12-03 13:53 ` [PATCH v11 10/10] riscv: select HAVE_CMPXCHG_LOCAL Yunhui Cui
2026-12-03 13:53 ` Yunhui Cui
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-247988@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ajones@ventanamicro.com \
--cc=alex@ghiti.fr \
--cc=andrii@kernel.org \
--cc=andybnac@gmail.com \
--cc=aou@eecs.berkeley.edu \
--cc=apatel@ventanamicro.com \
--cc=arnd@arndb.de \
--cc=ast@kernel.org \
--cc=atishp@rivosinc.com \
--cc=ben.dooks@codethink.co.uk \
--cc=bjorn@kernel.org \
--cc=broonie@kernel.org \
--cc=cl@gentwo.org \
--cc=conor.dooley@microchip.com \
--cc=cuiyunhui@bytedance.com \
--cc=cyrilbur@tenstorrent.com \
--cc=daniel@iogearbox.net \
--cc=dave@stgolabs.net \
--cc=david.laight.linux@gmail.com \
--cc=debug@rivosinc.com \
--cc=dennis@kernel.org \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=jszhang@kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=menglong8.dong@gmail.com \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gma \
--cc=oleg@redhat.com \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=pulehui@huawei.com \
--cc=puranjay@kernel.org \
--cc=rkrcmar@ventanamicro.com \
--cc=samuel.holland@sifive.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=seanwascoding@gmail.com \
--cc=song@kernel.org \
--cc=tglx@kernel.org \
--cc=thuth@redhat.com \
--cc=tj@kernel.org \
--cc=wangruikang@iscas.ac.cn \
--cc=yonghong.song@linux.dev \
--cc=zong.li@sifive.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.