From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41476606A330 for ; Fri, 4 Dec 2026 09:30:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=j03QcKIo Received: by kanga.kvack.org (Postfix) id D5A4D6B05BB; Fri, 4 Dec 2026 04:30:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D30D76B05BC; Fri, 4 Dec 2026 04:30:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6F0C6B05BD; Fri, 4 Dec 2026 04:30:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 98AA16B05BB for ; Fri, 4 Dec 2026 04:30:17 -0500 (EST) Received: from smtpin04.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1E18BC02E3 for ; Fri, 4 Dec 2026 09:30:17 +0000 (UTC) X-FDA: 85505779674.04.FAEA891 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf27.hostedemail.com (Postfix) with ESMTP id 8687F40009 for ; Fri, 4 Dec 2026 09:30:15 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=j03QcKIo; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf27.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796376615; b=QkJ1A5PKRo4zdNwIGt/Z+UpIkDD+NnoJnWqxnUZjO14aIa8vUqSOvLV4loZ3zE7BHk8gcI 8garnkJBuJlfS7sN32Tiy4JbZyC8cZNxpCJZUyQFFy4YYYTLj8lLkhxp+aGeWCcXmG1g8Q FSwgNJu4bvXc+sqVJ+8s+BmY27rM4R0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796376615; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fvOVkZVauSE1IRY0o3YC7SITZtrRy4R5EZ9OuI7mu3E=; b=1H3ufTnTh2l46ZnlmYZhW3Nd+vfDg1wLIURTSo3SAkVJsIHVIn5eWEWnTeRQ5i2jlTHgTJ fmbdk3CQCNmD0z+4FELRVdhS6MO7bsHpJQlJJtrTsS0xZTO5mLW9esC6NIaaNX5ZuHC9Pd At55b1eqFPF1MOrcR/lEZeIvrU3XqaY= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=j03QcKIo; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf27.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id F30E16219B; Fri, 4 Dec 2026 09:30:14 +0000 (UTC) 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@gma il.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-Stat-Signature: cxban6ity7paf7yrhtuuj1k9mhuqimn8 X-Spam-Status: No, score=-8.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 8687F40009 X-HE-Tag: 1796376615-637997 X-HE-Meta: U2FsdGVkX1/vSupN/72Au1scEkvP/Dkb/G0RtXRzq+sl6XPq8vjb+vRH2fie/XIzCeAFhl3uBa+6lxjqek9j+e6Tm051iIvp7OsIZpY0IquFk9DwwLXiPi+NJ2R9xM8qnLIQMIj9bKmGkQIrYXzfbk0LpN9tktvKSskITSw97jVUfrALXH0fVPUgzgFxKGKPsYdGuhI9sx5FlmQQJ3rY6p724QOjkK/OdO+ccYDW+39YMBUzGS9jmT5WqtlnfE6ovxyOakbphsz19f9rrx8Mk9CqI2nxn+/LI3IfUDrrDsiqI09zN1zxdcZYvO6c4W2SpQJ73xbLjpxkChb9bk40NzGCe6fRjOqCd/YtI2QM/Gqcxz05Uo/i7QdwfWU8gf/KEa9vpCUsFXdtxYWK0o8gtEN5KcwOtPyFh/r4DkIkfjE4YHA7nzTtakYDLQMtSHrxXul7G4P5/hMyv7ZFoSYg9YaciH5bm3aht9IndCDuGQamqPEZIZ2quwHdm4ithkZ4HzQTUFckYGjnlUJG+OBcJ2iceB9TCQSLJtr4/fc2het4ZNMkiuJxmCP6Eoa2v0ow4A+sWrusVsLmbnbtDAGx35ZAG8pMfyZjEN+Ye+8OyRRE/12CF03nlomhmDzelWWyCz4guVp9rUff7XHLVJlUejQV8OWDrby+HPpt5YW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bACwLNazKKPej6QI8/dRxjR+bccaF898vPUx92ZdVlcWTbG9T225IkWM0eqFvDENUDjUaUsaBlKM+RqVmchkeGyKinSYTOYJCoOJZQfEipv6ZGfhU02RJxiu9ezuibQj9r5BYzV7lR4ErpAmUagJmVdQ1RBMxlAiiNLk3+oocAU43V+A8y/aGOCH5qxusxHKfSkSYaoeCYL+t18/BJx+UsQ== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: 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