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 v12 05/10] riscv: implement preemptible this_cpu void RMW operations
Date: Fri, 04 Dec 2026 09:28:03 +0000 [thread overview]
Message-ID: <sashiko-outbox-249504@kernel.org> (raw)
In-Reply-To: <20261204085859.42277-6-cuiyunhui@bytedance.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] riscv: pcpu_gprs false-shares task_struct cache line in
this_cpu RMWs
--
commit fcc4ea085ec85e941f656b028f16ce10e5de0a9f
Author: Yunhui Cui <cuiyunhui@bytedance.com>
riscv: implement preemptible this_cpu void RMW operations
This commit wires the RISC-V this_cpu_{add,and,or}_{1,2,4,8} operations to
the preemptible per-CPU AMO helpers instead of falling back to the generic
implementations.
Link: https://lore.kernel.org/r/20260826010748.zphu3wh2hlm4t4o2@offworld
> diff --git a/arch/riscv/include/asm/percpu.h b/arch/riscv/include/asm/percpu.h
> index d46a32c78c5dc..6d0a11b49563f 100644
> --- a/arch/riscv/include/asm/percpu.h
> +++ b/arch/riscv/include/asm/percpu.h
[ ... ]
> @@ -243,6 +260,27 @@ PERCPU_RW_OPS("lw", "sw", 32)
> _pcp_wrap(__percpu_write_64, pcp, (__force unsigned long)(val))
> #endif
>
> +#define this_cpu_add_1(pcp, val) _pcp_wrap(__percpu_add_amo_case_8, pcp, val)
> +#define this_cpu_add_2(pcp, val) _pcp_wrap(__percpu_add_amo_case_16, pcp, val)
> +#define this_cpu_add_4(pcp, val) _pcp_wrap(__percpu_add_amo_case_32, pcp, val)
> +#ifdef CONFIG_64BIT
> +#define this_cpu_add_8(pcp, val) _pcp_wrap(__percpu_add_amo_case_64, pcp, val)
> +#endif
> +
> +#define this_cpu_and_1(pcp, val) _pcp_wrap(__percpu_and_amo_case_8, pcp, val)
> +#define this_cpu_and_2(pcp, val) _pcp_wrap(__percpu_and_amo_case_16, pcp, val)
> +#define this_cpu_and_4(pcp, val) _pcp_wrap(__percpu_and_amo_case_32, pcp, val)
> +#ifdef CONFIG_64BIT
> +#define this_cpu_and_8(pcp, val) _pcp_wrap(__percpu_and_amo_case_64, pcp, val)
> +#endif
> +
> +#define this_cpu_or_1(pcp, val) _pcp_wrap(__percpu_or_amo_case_8, pcp, val)
> +#define this_cpu_or_2(pcp, val) _pcp_wrap(__percpu_or_amo_case_16, pcp, val)
> +#define this_cpu_or_4(pcp, val) _pcp_wrap(__percpu_or_amo_case_32, pcp, val)
> +#ifdef CONFIG_64BIT
> +#define this_cpu_or_8(pcp, val) _pcp_wrap(__percpu_or_amo_case_64, pcp, val)
> +#endif
[Severity: Medium]
Does placing pcpu_gprs at the end of struct thread_info cause split-line
accesses and false sharing with task_struct on every this_cpu RMW?
On RV64 SMP (L1_CACHE_BYTES == 64 with CONFIG_THREAD_INFO_IN_TASK),
pcpu_offset is at offset 40 (cache line 0), while pcpu_gprs follows a0,
a1, and a2 at offset 72 (cache line 1). Remotely accessed task_struct
fields (__state, usage, on_cpu, wake_entry) share the rest of that line.
Because these helpers read pcpu_offset and write pcpu_gprs twice on every
call, hot paths like percpu_ref_get() now touch two cache lines of current
and continuously dirty cache line 1, causing cross-CPU cacheline bouncing
whenever another CPU wakes or takes a reference on the running task.
Moving pcpu_gprs right after pcpu_offset (ahead of a0, a1, and a2) would
keep both fields in cache line 0 and avoid false sharing with task_struct.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204085859.42277-1-cuiyunhui@bytedance.com?part=5
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 v12 05/10] riscv: implement preemptible this_cpu void RMW operations
Date: Fri, 04 Dec 2026 09:28:03 +0000 [thread overview]
Message-ID: <sashiko-outbox-249504@kernel.org> (raw)
In-Reply-To: <20261204085859.42277-6-cuiyunhui@bytedance.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] riscv: pcpu_gprs false-shares task_struct cache line in
this_cpu RMWs
--
commit fcc4ea085ec85e941f656b028f16ce10e5de0a9f
Author: Yunhui Cui <cuiyunhui@bytedance.com>
riscv: implement preemptible this_cpu void RMW operations
This commit wires the RISC-V this_cpu_{add,and,or}_{1,2,4,8} operations to
the preemptible per-CPU AMO helpers instead of falling back to the generic
implementations.
Link: https://lore.kernel.org/r/20260826010748.zphu3wh2hlm4t4o2@offworld
> diff --git a/arch/riscv/include/asm/percpu.h b/arch/riscv/include/asm/percpu.h
> index d46a32c78c5dc..6d0a11b49563f 100644
> --- a/arch/riscv/include/asm/percpu.h
> +++ b/arch/riscv/include/asm/percpu.h
[ ... ]
> @@ -243,6 +260,27 @@ PERCPU_RW_OPS("lw", "sw", 32)
> _pcp_wrap(__percpu_write_64, pcp, (__force unsigned long)(val))
> #endif
>
> +#define this_cpu_add_1(pcp, val) _pcp_wrap(__percpu_add_amo_case_8, pcp, val)
> +#define this_cpu_add_2(pcp, val) _pcp_wrap(__percpu_add_amo_case_16, pcp, val)
> +#define this_cpu_add_4(pcp, val) _pcp_wrap(__percpu_add_amo_case_32, pcp, val)
> +#ifdef CONFIG_64BIT
> +#define this_cpu_add_8(pcp, val) _pcp_wrap(__percpu_add_amo_case_64, pcp, val)
> +#endif
> +
> +#define this_cpu_and_1(pcp, val) _pcp_wrap(__percpu_and_amo_case_8, pcp, val)
> +#define this_cpu_and_2(pcp, val) _pcp_wrap(__percpu_and_amo_case_16, pcp, val)
> +#define this_cpu_and_4(pcp, val) _pcp_wrap(__percpu_and_amo_case_32, pcp, val)
> +#ifdef CONFIG_64BIT
> +#define this_cpu_and_8(pcp, val) _pcp_wrap(__percpu_and_amo_case_64, pcp, val)
> +#endif
> +
> +#define this_cpu_or_1(pcp, val) _pcp_wrap(__percpu_or_amo_case_8, pcp, val)
> +#define this_cpu_or_2(pcp, val) _pcp_wrap(__percpu_or_amo_case_16, pcp, val)
> +#define this_cpu_or_4(pcp, val) _pcp_wrap(__percpu_or_amo_case_32, pcp, val)
> +#ifdef CONFIG_64BIT
> +#define this_cpu_or_8(pcp, val) _pcp_wrap(__percpu_or_amo_case_64, pcp, val)
> +#endif
[Severity: Medium]
Does placing pcpu_gprs at the end of struct thread_info cause split-line
accesses and false sharing with task_struct on every this_cpu RMW?
On RV64 SMP (L1_CACHE_BYTES == 64 with CONFIG_THREAD_INFO_IN_TASK),
pcpu_offset is at offset 40 (cache line 0), while pcpu_gprs follows a0,
a1, and a2 at offset 72 (cache line 1). Remotely accessed task_struct
fields (__state, usage, on_cpu, wake_entry) share the rest of that line.
Because these helpers read pcpu_offset and write pcpu_gprs twice on every
call, hot paths like percpu_ref_get() now touch two cache lines of current
and continuously dirty cache line 1, causing cross-CPU cacheline bouncing
whenever another CPU wakes or takes a reference on the running task.
Moving pcpu_gprs right after pcpu_offset (ahead of a0, a1, and a2) would
keep both fields in cache line 0 and avoid false sharing with task_struct.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204085859.42277-1-cuiyunhui@bytedance.com?part=5
next prev parent reply other threads:[~2026-12-04 9:28 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 8:58 [PATCH v12 00/10] riscv: optimize percpu access Yunhui Cui
2026-12-04 8:58 ` Yunhui Cui
2026-12-04 8:58 ` [PATCH v12 01/10] riscv: store percpu offset into thread_info Yunhui Cui
2026-12-04 8:58 ` Yunhui Cui
2026-12-04 8:58 ` [PATCH v12 02/10] riscv: add infrastructure for preemptible this_cpu operations Yunhui Cui
2026-12-04 8:58 ` Yunhui Cui
2026-12-04 9:22 ` sashiko-bot
2026-12-04 9:22 ` sashiko-bot
2026-12-04 10:09 ` David Laight
2026-12-04 10:09 ` David Laight
2026-12-04 8:58 ` [PATCH v12 03/10] riscv: add common helpers " Yunhui Cui
2026-12-04 8:58 ` Yunhui Cui
2026-12-04 8:58 ` [PATCH v12 04/10] riscv: implement preemptible this_cpu read and write operations Yunhui Cui
2026-12-04 8:58 ` Yunhui Cui
2026-12-04 9:30 ` sashiko-bot
2026-12-04 9:30 ` sashiko-bot
2026-12-04 8:58 ` [PATCH v12 05/10] riscv: implement preemptible this_cpu void RMW operations Yunhui Cui
2026-12-04 8:58 ` Yunhui Cui
2026-12-04 9:28 ` sashiko-bot [this message]
2026-12-04 9:28 ` sashiko-bot
2026-12-04 8:58 ` [PATCH v12 06/10] riscv: implement preemptible this_cpu add_return operations Yunhui Cui
2026-12-04 8:58 ` Yunhui Cui
2026-12-04 8:58 ` [PATCH v12 07/10] riscv: implement preemptible this_cpu xchg operations Yunhui Cui
2026-12-04 8:58 ` Yunhui Cui
2026-12-04 8:58 ` [PATCH v12 08/10] riscv: implement preemptible this_cpu cmpxchg operations Yunhui Cui
2026-12-04 8:58 ` Yunhui Cui
2026-12-04 8:58 ` [PATCH v12 09/10] riscv: implement preemptible this_cpu cmpxchg128 Yunhui Cui
2026-12-04 8:58 ` Yunhui Cui
2026-12-04 8:58 ` [PATCH v12 10/10] riscv: select HAVE_CMPXCHG_LOCAL Yunhui Cui
2026-12-04 8:58 ` 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-249504@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.