Re: [PATCH V6] riscv: errata: Add ERRATA WRITE_ONCE fixup

From: Guo Ren

Date: Mon Nov 23 2026 - 06:15:29 EST


On Mon, Nov 23, 2026 at 2:43 PM Drew Fustini <fustini@xxxxxxxxxx> wrote:
>
> On Thu, Nov 19, 2026 at 08:27:12PM -0500, guoren@xxxxxxxxxx wrote:
> > From: "GUO Ren (XuanTie)" <guoren@xxxxxxxxxx>
> >
> > The early version of XuanTie C910 core has a store merge buffer
> > delay problem. The store merge buffer could improve the store queue
> > performance by merging multi-store requests, but when there are not
> > continued store requests, the prior single store request would be
> > waiting in the store queue for a long time. That would cause
> > significant problems for communication between multi-cores. This
> > problem was found on sg2042 platform with the qspinlock lock torture
> > test.
> >
> > So appending a fence w.o could immediately flush the store merge
> > buffer and let other cores see the write result.
> >
> > This will apply the WRITE_ONCE errata to handle the non-standard
> > behavior via appending a fence w.o instruction for WRITE_ONCE().
> >
> > This problem is only observed on the sg2042 hardware platform by
> > running the lock_torture test program for half an hour. The problem
> > was not found in the user space application, because interrupt can
> > break the livelock.
> >
> > Acked-by: Arnd Bergmann <arnd@xxxxxxxx>
> > Reviewed-by: Alexandre Ghiti <alexghiti@xxxxxxxxxxxx>
> > Reviewed-by: Leonardo Bras <leobras@xxxxxxxxxx>
> > Reviewed-by: Inochi Amaoto <inochiama@xxxxxxxxx>
> > Tested-by: Han Gao <gaohan@xxxxxxxxxxx>
> > Tested-by: Yao Zi <me@xxxxxxxx>
> > Cc: Chen Wang <unicorn_wang@xxxxxxxxxxx>
> > Cc: Xiaoguang Xing <xiaoguang.xing@xxxxxxxxxx>
> > Cc: Paul Walmsley <pjw@xxxxxxxxxx>
> > Signed-off-by: GUO Ren (XuanTie) <guoren@xxxxxxxxxx>
> [..]
> > diff --git a/arch/riscv/errata/thead/errata.c b/arch/riscv/errata/thead/errata.c
> > index 6f1c683f0ec0..64683882d50b 100644
> > --- a/arch/riscv/errata/thead/errata.c
> > +++ b/arch/riscv/errata/thead/errata.c
> > @@ -168,6 +168,23 @@ static bool errata_probe_ghostwrite(unsigned int stage,
> > return true;
> > }
> >
> > +static bool errata_probe_write_once(unsigned int stage,
> > + unsigned long arch_id, unsigned long impid)
> > +{
> > + if (!IS_ENABLED(CONFIG_ERRATA_THEAD_WRITE_ONCE))
> > + return false;
> > +
> > + /* target-c9xx cores report arch_id and impid as 0 */
> > + if (arch_id != 0 || impid != 0)
> > + return false;
>
> Doesn't this match more SoCs than just the SG2042 and TH1520 like the
> commit message mentions?
The issue has only been observed on SG2042, though TH1520 is
theoretically affected as well. To the best of my knowledge, it has
not been observed on any other chips.

>
> [..]
>
> > +#if defined(CONFIG_ERRATA_THEAD_WRITE_ONCE) && !defined(NO_ALTERNATIVE)
> > +
> > +#define write_once_fence() \
> > +do { \
> > + asm volatile(ALTERNATIVE( \
> > + "nop", \
> > + "fence w, o", \
>
> I tried this on v7.4-rc3 in qemu with -cpu thead-c906 which matches this
> errata, and I discovered boot fails when CONFIG_DEBUG_VIRTUAL=y.
>
> kernel BUG at mm/vmalloc.c:879!
> epc : vmalloc_to_page+0x212/0x260
> ra : patch_insn_write+0x1a2/0x414
> [...]
> [<ffffffff8026ba1a>] vmalloc_to_page+0x212/0x260
> [<ffffffff8000fa76>] patch_insn_write+0x1a2/0x414
> [<ffffffff8000fcf6>] patch_text_nosync+0xe/0x22
> [<ffffffff8001b886>] thead_errata_patch_func+0xac/0x144
> [<ffffffff80009548>] _apply_alternatives+0x76/0x96
> [<ffffffff80e038a4>] apply_boot_alternatives+0x48/0x54
> [<ffffffff80e04d4a>] setup_arch+0x92/0xe8
>
> The vdso getrandom code uses WRITE_ONCE(), so it now has entries in
> .alternative. patch_map() ends up calling vmalloc_to_page() on an
> address in the vdso and triggers VIRTUAL_BUG_ON().
Oh, thx Drew for catching it. I would disable it in VDSO code.

diff --git a/arch/riscv/include/asm/rwonce.h b/arch/riscv/include/asm/rwonce.h
index 081793d4d772..5305b8bf82bd 100644
--- a/arch/riscv/include/asm/rwonce.h
+++ b/arch/riscv/include/asm/rwonce.h
@@ -8,7 +8,7 @@
#include <asm/vendorid_list.h>
#include <asm/errata_list_vendors.h>

-#if defined(CONFIG_ERRATA_THEAD_WRITE_ONCE) && !defined(NO_ALTERNATIVE)
+#if defined(CONFIG_ERRATA_THEAD_WRITE_ONCE) &&
!defined(NO_ALTERNATIVE) && !defined(BUILD_VDSO)

#define write_once_fence() \
do {

--
Best Regards



Guo Ren