mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Drew Fustini <fustini@kernel.org>
To: guoren@kernel.org
Cc: paul.walmsley@sifive.com, palmer@dabbelt.com, arnd@arndb.de,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-arch@vger.kernel.org,
	Alexandre Ghiti <alexghiti@rivosinc.com>,
	Leonardo Bras <leobras@redhat.com>,
	Inochi Amaoto <inochiama@gmail.com>, Han Gao <gaohan@iscas.ac.cn>,
	Yao Zi <me@ziyao.cc>, Chen Wang <unicorn_wang@outlook.com>,
	Xiaoguang Xing <xiaoguang.xing@sophgo.com>,
	Paul Walmsley <pjw@kernel.org>
Subject: Re: [PATCH V6] riscv: errata: Add ERRATA WRITE_ONCE fixup
Date: Sun, 22 Nov 2026 22:43:27 -0800	[thread overview]
Message-ID: <awPgjwuswbjeDftg@thelio> (raw)
In-Reply-To: <20261120012712.1957564-1-guoren@kernel.org>

On Thu, Nov 19, 2026 at 08:27:12PM -0500, guoren@kernel.org wrote:
> From: "GUO Ren (XuanTie)" <guoren@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@arndb.de>
> Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> Reviewed-by: Leonardo Bras <leobras@redhat.com>
> Reviewed-by: Inochi Amaoto <inochiama@gmail.com>
> Tested-by: Han Gao <gaohan@iscas.ac.cn>
> Tested-by: Yao Zi <me@ziyao.cc>
> Cc: Chen Wang <unicorn_wang@outlook.com>
> Cc: Xiaoguang Xing <xiaoguang.xing@sophgo.com>
> Cc: Paul Walmsley <pjw@kernel.org>
> Signed-off-by: GUO Ren (XuanTie) <guoren@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?

[..]

> +#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().

Thanks,
Drew

      reply	other threads:[~2026-11-23  6:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  1:27 guoren
2026-11-23  6:43 ` Drew Fustini [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=awPgjwuswbjeDftg@thelio \
    --to=fustini@kernel.org \
    --cc=alexghiti@rivosinc.com \
    --cc=arnd@arndb.de \
    --cc=gaohan@iscas.ac.cn \
    --cc=guoren@kernel.org \
    --cc=inochiama@gmail.com \
    --cc=leobras@redhat.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=me@ziyao.cc \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=pjw@kernel.org \
    --cc=unicorn_wang@outlook.com \
    --cc=xiaoguang.xing@sophgo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®