[PATCH V6] riscv: errata: Add ERRATA WRITE_ONCE fixup
Guo Ren
guoren at kernel.org
Mon Nov 23 03:15:07 PST 2026
On Mon, Nov 23, 2026 at 2:43 PM Drew Fustini <fustini at kernel.org> wrote:
>
> On Thu, Nov 19, 2026 at 08:27:12PM -0500, guoren at kernel.org wrote:
> > From: "GUO Ren (XuanTie)" <guoren at kernel.org>
> >
> > 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 at arndb.de>
> > Reviewed-by: Alexandre Ghiti <alexghiti at rivosinc.com>
> > Reviewed-by: Leonardo Bras <leobras at redhat.com>
> > Reviewed-by: Inochi Amaoto <inochiama at gmail.com>
> > Tested-by: Han Gao <gaohan at iscas.ac.cn>
> > Tested-by: Yao Zi <me at ziyao.cc>
> > Cc: Chen Wang <unicorn_wang at outlook.com>
> > Cc: Xiaoguang Xing <xiaoguang.xing at sophgo.com>
> > Cc: Paul Walmsley <pjw at kernel.org>
> > Signed-off-by: GUO Ren (XuanTie) <guoren at kernel.org>
> [..]
> > 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
More information about the linux-riscv
mailing list