From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796376615; b=qBsDfmCe/ZYqS4ERHdotATxIavc7IAnb6o+JVdvqOUAlUpG3nDuiGI4n8NWebZLOOzXH 5TgreLzMxWkdH4JXVrMod/wrx+iCdoHetMO2SRmTeySm1wf10MP11tVv0KUtPdMVJ4FNL VfbejWPUTr8W9f/X02NFJPPivbyAm6y0oPj2phxCdKRNIkHflAtW15/V9LvsnChidgrFj lzkA4X6LDQdG9L6PJ2lHjaGDC8hBUjymSYyEvkmPaVHNbA4TOGkcStHqgju1ffNDJDQti PiGqkePsYFoNI7/WlyqcCeqM9wClOxhYEI2Waad9IkIlAlXGLSDaOtXpVAqCKpHTnLg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796376615; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=fvOVkZVauSE1IRY0o3YC7SITZtrRy4R5EZ9OuI7mu3E=; b=ufvnqlK7ov/DCDsZK+jeHa0hGp2ZjqCSVGhsv+SIAs/OjqKWO9TlS3k9BmuGTSTbHraG Eox4vAVcR4mmALTzEXv5wzwfBvfwEPB0cfzuLCVUAj9NNuCCYbVsa1Xf8eg+6tsYPeMrR hS6rprqFm15eeQpur/IER8HyRRWPydey0MmuS/T3uvkODZ/TFqQhHma8L0/TEZZBQ4vP6 /z21S2GOWS686/UcaeRLmDzGfnlGY4avr/m/el64C1sqSzzWArR2wkE12YcvioRhkZxvD M9owV8zk32IXvQin3YaZUBuOksqz++7GYef+Axqw+7KIvTFVxS9xVXG3oq736Beyehg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=j03QcKIo; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F625606A32C for ; Fri, 4 Dec 2026 09:30:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=j03QcKIo Received: by smtp.kernel.org (Postfix) with ESMTPSA id A420F1F000CE; Fri, 4 Dec 2026 09:30:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796376614; bh=fvOVkZVauSE1IRY0o3YC7SITZtrRy4R5EZ9OuI7mu3E=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=j03QcKIoKm6mHnPCQULFViUxisr04hXXEKEbfngQ9BAK0ZNYiRZR5lSuhYO+n+9Td PcNPKew2sy7RO/BOFjkvqCj259qI8x2ijFWn6dt0dfrmWvGLpW3fyNPwJxnkfPL8HD 4nlj1Nzwd+3zcLDeyzwDdMHwsDKRBQCQSBRq/bVIT3S0ZSjpuHpq+NzHiClS2OK81p RyIU5tNUpAs877SKwwbSHrIsGqU5Z2Az6Sz8Xvhf6sVhGgrj522WxQ2o/A9/L9JZvd c329kWm6ClkQiVXao1m7S4cJsY1DWXcMtfWf8CoZOat8EacvyIoDPoEzvhegjGafPh s52SqK7K81VVw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v12 04/10] riscv: implement preemptible this_cpu read and write operations Reply-To: sashiko-reviews@lists.linux.dev To: "Yunhui Cui" , 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 In-Reply-To: <20261204085859.42277-5-cuiyunhui@bytedance.com> References: <20261204085859.42277-1-cuiyunhui@bytedance.com> <20261204085859.42277-5-cuiyunhui@bytedance.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 09:30:12 +0000 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] riscv: thread_info.pcpu_gprs splits cachelines and false-shares task_struct -- commit 5e93938dbc3ac09b6f67a5c4d569de78c4baf9e3 Author: Yunhui Cui riscv: implement preemptible this_cpu read and write operations This commit implements preemptible this_cpu_read() and this_cpu_write() operations for RISC-V using the recoverable per-CPU address sequence. > diff --git a/arch/riscv/include/asm/percpu.h b/arch/riscv/include/asm/per= cpu.h > index 6fc4cfd6b679e..d46a32c78c5dc 100644 > --- a/arch/riscv/include/asm/percpu.h > +++ b/arch/riscv/include/asm/percpu.h > @@ -178,7 +178,73 @@ __percpu_##name##_amo_case_##sz(void __percpu *pcp, = unsigned long val) \ > (__force TYPEOF_UNQUAL(*__pcp_ptr))op(__pcp_ptr, ##args); \ > }) > =20 > +#define PERCPU_RW_OPS(load, store, sz) \ > +static __always_inline unsigned long \ > +__percpu_read_##sz(const void __percpu *pcp) \ > +{ \ > + __PCPU_OP_CONTEXT(); \ > + unsigned long val; \ > + \ > + asm volatile (__PCPU_GPRS_BEGIN(gprs, pcp, off, addr, pcpu_offset) \ > + load " %[val], 0(%[addr])\n" \ > + __PCPU_GPRS_END(gprs) \ > + : [gprs] "=3Dm" (__ti->pcpu_gprs), \ > + [off] "=3D&r" (__off), [addr] "=3D&r" (__addr), \ > + [val] "=3D&r" (val) \ > + : [pcpu_offset] "m" (__ti->pcpu_offset), \ > + [pcp] "r" (pcp) \ > + : "memory"); \ > + \ > + return (u##sz)val; \ > +} \ > + \ > +static __always_inline void __percpu_write_##sz(void __percpu *pcp, \ > + unsigned long val) \ > +{ \ > + __PCPU_OP_CONTEXT(); \ > + \ > + asm volatile (__PCPU_GPRS_BEGIN(gprs, pcp, off, addr, pcpu_offset) \ > + store " %[val], 0(%[addr])\n" \ > + __PCPU_GPRS_END(gprs) \ > + : [gprs] "=3Dm" (__ti->pcpu_gprs), \ > + [off] "=3D&r" (__off), [addr] "=3D&r" (__addr) \ > + : [pcpu_offset] "m" (__ti->pcpu_offset), \ > + [pcp] "r" (pcp), [val] "r" ((u##sz)val) \ > + : "memory"); \ > +} [Severity: Medium] Does accessing __ti->pcpu_offset and __ti->pcpu_gprs on every this_cpu_read= () and this_cpu_write() split the per-CPU hot path across two cachelines and false-share with task_struct? On 64-bit RISC-V SMP (64-byte L1 cachelines), struct thread_info sits at offset 0 of struct task_struct, with pcpu_offset at offset 40 (cacheline 0) and pcpu_gprs at the end of struct thread_info (offset 72 or higher, in cacheline 1): arch/riscv/include/asm/thread_info.h:struct thread_info { ... #ifdef CONFIG_SMP unsigned long pcpu_offset; #endif #ifdef CONFIG_SHADOW_CALL_STACK void *scs_base; void *scs_sp; #endif #ifdef CONFIG_64BIT unsigned long a0, a1, a2; #endif #ifdef CONFIG_RISCV_USER_CFI struct cfi_state user_cfi_state; #endif #ifdef CONFIG_SMP unsigned short pcpu_gprs; #endif }; Cacheline 1 of task_struct also holds remote-accessed scheduler fields such as __state, saved_state, stack, usage, flags, on_cpu, on_rq, and wake_entry. Hot callers like mod_zone_state() invoke this_cpu_read() on every page allocation or free, dirtying cacheline 1 twice per access and causing cacheline bounces when remote CPUs wake or reference-count the running task. Moving pcpu_gprs next to pcpu_offset in struct thread_info (before a0/a1/a2 and the optional shadow call stack and CFI fields) would keep both per-CPU fields in cacheline 0 and separate from remote-accessed task_struct fields. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204085859.4227= 7-1-cuiyunhui@bytedance.com?part=3D4