* [PATCH] riscv: cpu: Fix incorrect cached machine IDs on secondary harts
@ 2026-11-18 3:04 Peixin Xie
2026-11-18 6:50 ` Troy Mitchell
2026-11-18 10:07 ` Guo Ren
0 siblings, 2 replies; 3+ messages in thread
From: Peixin Xie @ 2026-11-18 3:04 UTC (permalink / raw)
To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
Yixun Lan, Troy Mitchell, Guo Ren, Conor Dooley, Charlie Jenkins
Cc: Palmer Dabbelt, linux-riscv, linux-kernel, spacemit, stable, Peixin Xie
During early ISA-string parsing, the boot hart stores its mvendorid
and marchid in riscv_cpuinfo. This happens before setup_per_cpu_areas(),
which copies the static per-CPU data to each CPU's allocated area.
When riscv_cpuinfo_starting() runs on the other harts, the copied IDs
are already nonzero, so it skips reading their own IDs. As a result,
secondary harts can retain the boot hart's IDs.
Read mvendorid and marchid unconditionally on each hart, as already
done for mimpid.
Fixes: e482eab4d1eb ("riscv: cpufeature: Fix thead vector hwcap removal")
Cc: stable@vger.kernel.org
Signed-off-by: Peixin Xie <peixin.xie@linux.spacemit.com>
---
arch/riscv/kernel/cpu.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c
index af84b97af3a1..64c0c83eff76 100644
--- a/arch/riscv/kernel/cpu.c
+++ b/arch/riscv/kernel/cpu.c
@@ -197,16 +197,12 @@ static int riscv_cpuinfo_starting(unsigned int cpu)
struct riscv_cpuinfo *ci = this_cpu_ptr(&riscv_cpuinfo);
#if IS_ENABLED(CONFIG_RISCV_SBI)
- if (!ci->mvendorid)
- ci->mvendorid = sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid();
- if (!ci->marchid)
- ci->marchid = sbi_spec_is_0_1() ? 0 : sbi_get_marchid();
+ ci->mvendorid = sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid();
+ ci->marchid = sbi_spec_is_0_1() ? 0 : sbi_get_marchid();
ci->mimpid = sbi_spec_is_0_1() ? 0 : sbi_get_mimpid();
#elif IS_ENABLED(CONFIG_RISCV_M_MODE)
- if (!ci->mvendorid)
- ci->mvendorid = csr_read(CSR_MVENDORID);
- if (!ci->marchid)
- ci->marchid = csr_read(CSR_MARCHID);
+ ci->mvendorid = csr_read(CSR_MVENDORID);
+ ci->marchid = csr_read(CSR_MARCHID);
ci->mimpid = csr_read(CSR_MIMPID);
#else
ci->mvendorid = 0;
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261118-riscv-marchid-fix-3ea3672d1e0e
Best regards,
--
Peixin Xie <peixin.xie@linux.spacemit.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] riscv: cpu: Fix incorrect cached machine IDs on secondary harts
2026-11-18 3:04 [PATCH] riscv: cpu: Fix incorrect cached machine IDs on secondary harts Peixin Xie
@ 2026-11-18 6:50 ` Troy Mitchell
2026-11-18 10:07 ` Guo Ren
1 sibling, 0 replies; 3+ messages in thread
From: Troy Mitchell @ 2026-11-18 6:50 UTC (permalink / raw)
To: Peixin Xie, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, Yixun Lan, Troy Mitchell, Guo Ren, Conor Dooley,
Charlie Jenkins
Cc: Palmer Dabbelt, linux-riscv, linux-kernel, spacemit, stable,
linux-riscv, Troy Mitchell
[-- Attachment #1: Type: text/plain, Size: 808 bytes --]
On Wed Nov 18, 2026 at 3:04 AM GMT, Peixin Xie wrote:
> During early ISA-string parsing, the boot hart stores its mvendorid
> and marchid in riscv_cpuinfo. This happens before setup_per_cpu_areas(),
> which copies the static per-CPU data to each CPU's allocated area.
>
> When riscv_cpuinfo_starting() runs on the other harts, the copied IDs
> are already nonzero, so it skips reading their own IDs. As a result,
> secondary harts can retain the boot hart's IDs.
>
> Read mvendorid and marchid unconditionally on each hart, as already
> done for mimpid.
>
> Fixes: e482eab4d1eb ("riscv: cpufeature: Fix thead vector hwcap removal")
> Cc: stable@vger.kernel.org
> Signed-off-by: Peixin Xie <peixin.xie@linux.spacemit.com>
Reviewed-by: Troy Mitchell <troy@kernel.org>
--
Troy Mitchell
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 252 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] riscv: cpu: Fix incorrect cached machine IDs on secondary harts
2026-11-18 3:04 [PATCH] riscv: cpu: Fix incorrect cached machine IDs on secondary harts Peixin Xie
2026-11-18 6:50 ` Troy Mitchell
@ 2026-11-18 10:07 ` Guo Ren
1 sibling, 0 replies; 3+ messages in thread
From: Guo Ren @ 2026-11-18 10:07 UTC (permalink / raw)
To: Peixin Xie
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
Yixun Lan, Troy Mitchell, Conor Dooley, Charlie Jenkins,
Palmer Dabbelt, linux-riscv, linux-kernel, spacemit, stable
On Wed, Nov 18, 2026 at 11:05 AM Peixin Xie
<peixin.xie@linux.spacemit.com> wrote:
>
> During early ISA-string parsing, the boot hart stores its mvendorid
> and marchid in riscv_cpuinfo. This happens before setup_per_cpu_areas(),
> which copies the static per-CPU data to each CPU's allocated area.
>
> When riscv_cpuinfo_starting() runs on the other harts, the copied IDs
> are already nonzero, so it skips reading their own IDs. As a result,
> secondary harts can retain the boot hart's IDs.
>
> Read mvendorid and marchid unconditionally on each hart, as already
> done for mimpid.
>
> Fixes: e482eab4d1eb ("riscv: cpufeature: Fix thead vector hwcap removal")
> Cc: stable@vger.kernel.org
> Signed-off-by: Peixin Xie <peixin.xie@linux.spacemit.com>
> ---
> arch/riscv/kernel/cpu.c | 12 ++++--------
> 1 file changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c
> index af84b97af3a1..64c0c83eff76 100644
> --- a/arch/riscv/kernel/cpu.c
> +++ b/arch/riscv/kernel/cpu.c
> @@ -197,16 +197,12 @@ static int riscv_cpuinfo_starting(unsigned int cpu)
> struct riscv_cpuinfo *ci = this_cpu_ptr(&riscv_cpuinfo);
>
> #if IS_ENABLED(CONFIG_RISCV_SBI)
> - if (!ci->mvendorid)
> - ci->mvendorid = sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid();
> - if (!ci->marchid)
> - ci->marchid = sbi_spec_is_0_1() ? 0 : sbi_get_marchid();
> + ci->mvendorid = sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid();
> + ci->marchid = sbi_spec_is_0_1() ? 0 : sbi_get_marchid();
> ci->mimpid = sbi_spec_is_0_1() ? 0 : sbi_get_mimpid();
> #elif IS_ENABLED(CONFIG_RISCV_M_MODE)
> - if (!ci->mvendorid)
> - ci->mvendorid = csr_read(CSR_MVENDORID);
> - if (!ci->marchid)
> - ci->marchid = csr_read(CSR_MARCHID);
> + ci->mvendorid = csr_read(CSR_MVENDORID);
> + ci->marchid = csr_read(CSR_MARCHID);
> ci->mimpid = csr_read(CSR_MIMPID);
> #else
> ci->mvendorid = 0;
>
> ---
> base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
> change-id: 20261118-riscv-marchid-fix-3ea3672d1e0e
>
> Best regards,
> --
> Peixin Xie <peixin.xie@linux.spacemit.com>
>
Hmm, it solved the problem on Big-little cores' SoC.
Reviewed-by: GUO Ren (XuanTie) <guoren@kernel.org>
--
Best Regards
Guo Ren
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-18 10:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 3:04 [PATCH] riscv: cpu: Fix incorrect cached machine IDs on secondary harts Peixin Xie
2026-11-18 6:50 ` Troy Mitchell
2026-11-18 10:07 ` Guo Ren
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®