The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Conor Dooley <conor@kernel.org>
To: Aleksa Paunovic <aleksa.paunovic@htecgroup.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Alexandre Ghiti <alex@ghiti.fr>, Will Deacon <will@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Yury Norov <yury.norov@gmail.com>,
	Djordje Todorovic <djordje.todorovic@htecgroup.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Charlie Jenkins <charlie@rivosinc.com>,
	Jessica Clarke <jrtc27@jrtc27.com>,
	Samuel Holland <samuel.holland@sifive.com>,
	Paul Walmsley <pjw@kernel.org>, Boqun Feng <boqun@kernel.org>,
	Gary Guo <gary@garyguo.net>,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	Chao-ying Fu <cfu@mips.com>,
	Aleksandar Rikalo <arikalo@gmail.com>
Subject: Re: [PATCH v4] riscv: Use Zalrsc extension to implement atomic functions
Date: Mon, 10 Aug 2026 16:57:00 +0100	[thread overview]
Message-ID: <20260810-preoccupy-earwig-c8d98044c1da@spud> (raw)
In-Reply-To: <20260723-p8700-zalrsc-v4-1-59c21b252e29@htecgroup.com>

[-- Attachment #1: Type: text/plain, Size: 4571 bytes --]

On Thu, Jul 23, 2026 at 05:51:53PM +0200, Aleksa Paunovic wrote:
> From: Chao-ying Fu <cfu@mips.com>
> 
> MIPS P8700 does not natively support Zaamo instructions.
> They are emulated with Zalrsc extension instructions instead [1].
> Since the emulation is implemented through M-mode traps in the SBI
> layer, it is best to avoid using these instructions wherever possible on
> the P8700.
> 
> Implement kernel atomic operations using LR/SC sequences only.

> This is achieved by using the errata mechanism, with minimal
> interference on other cores.

This does not seem appropriate, you don't have an actual erratum.
Rather, you don't meet the minimum extension requirements that linux
currently has and want to avoid emulation.

> 
> Signed-off-by: Chao-ying Fu <cfu@mips.com>
> Signed-off-by: Aleksandar Rikalo <arikalo@gmail.com>
> Co-developed-by: Aleksa Paunovic <aleksa.paunovic@htecgroup.com>
> Signed-off-by: Aleksa Paunovic <aleksa.paunovic@htecgroup.com>
> 
> [1] https://mips.com/wp-content/uploads/2026/03/MIPS_P8700_P8700-F_Programmers_Reference_Guide_Rev1.86_2-17-2026.pdf

This should be a Link: tag, and be above the signoffs.
> 
> ---
> The patch was tested on QEMU configured to emulate an eight-hart MIPS P8700 CPU.
> Testing done since v3: futex kselftests and perf futex tests. These tests caught the issues described below.
> The same tests were executed on the Boston board with a single-hart P8700 core.
> 
> Since the main issue was with an incorrectly written erratum, it shouldn't affect Vladimir's version [1].
> However, since chips supporting only one part of the A extension are rare, we believe it might be
> better to address this using the alternative mechanism, instead of demanding that the wider community
> relax the A extension requirement.

Alternatives, sure. Relaxing the A extension requirement on the other
hand basically makes no difference, if we have to insert an alternative into
anything using AMO instructions, may as well do it properly and support Zalrsc
only systems rather than abuse the errata mechanisms. Any multiplatform kernel
(so anything provided by a distro) is going to turn on any errata that are not
listed as being non-portable.

The minimum requirements have been known for a long time too, since the
port was merged, so I personally don't feel charitable here. Your
firmware already can deal with the emulation, so I don't really see why
we should be adding alternatives because people selling (or buying) IP
cannot be bothered to meet the extremely basic minimum requirements of the
software they want to support.

> 
> Changes in v4:
> - The amo part of the ALT_TEST_AND_OP_BIT_ORD erratum erroneously hardcoded zero as the destination register.
>   This is fixed in v4.
> - futex.h was missing the ANDN case.
> - Link to v3: https://lore.kernel.org/r/20250901-p8700-zalrsc-v3-1-ec64fabbe093@htecgroup.com
> 
> Changes in v3:
> - Use alternatives to replace AMO instructions with LR/SC
> - Rebase on Alexandre Ghiti's "for-next" branch.
> - Link to v2: https://lore.kernel.org/linux-riscv/20241225082412.36727-1-arikalo@gmail.com/
> 
> Links:
> [1] https://lore.kernel.org/linux-riscv/20260120-lrsc-only-v2-0-a522e640d27d@mobileye.com/
> 
> Signed-off-by: Aleksa Paunovic <aleksa.paunovic@htecgroup.com>
> ---
>  arch/riscv/Kconfig.errata                    |  11 ++
>  arch/riscv/errata/mips/errata.c              |  13 +-
>  arch/riscv/include/asm/atomic.h              |  29 ++--
>  arch/riscv/include/asm/bitops.h              |  28 ++--
>  arch/riscv/include/asm/cmpxchg.h             |   9 +-
>  arch/riscv/include/asm/errata_list.h         | 215 +++++++++++++++++++++++++++
>  arch/riscv/include/asm/errata_list_vendors.h |   3 +-
>  arch/riscv/include/asm/futex.h               |  40 ++---
>  arch/riscv/kernel/entry.S                    |  10 +-
>  9 files changed, 290 insertions(+), 68 deletions(-)
> 
> diff --git a/arch/riscv/Kconfig.errata b/arch/riscv/Kconfig.errata
> index 3c945d086c7d0266b685f9506d58b0662af071c4..cd5bd5e8eb395418c3ad103dbd836c775b7fd901 100644
> --- a/arch/riscv/Kconfig.errata
> +++ b/arch/riscv/Kconfig.errata
> @@ -44,6 +44,17 @@ config ERRATA_MIPS_P8700_PAUSE_OPCODE
>  
>  	   If you are not using the P8700 processor, say n.
>  
> +config ERRATA_MIPS_P8700_AMO_ZALRSC
> +	bool "Replace AMO instructions with LR/SC on MIPS P8700"
> +	depends on ERRATA_MIPS && 64BIT
> +	default n

Why is this default n if your platform does not work without it?

Cheers,
Conor.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  parent reply	other threads:[~2026-08-10 15:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-23 15:51 [PATCH v4] riscv: Use Zalrsc extension to implement atomic functions Aleksa Paunovic via B4 Relay
2026-07-27 21:03 ` Jesse Taube
2026-07-27 22:37   ` Jesse Taube
2026-08-10 15:20     ` Aleksa Paunovic
2026-08-10 15:57 ` Conor Dooley [this message]
2026-08-10 18:53   ` Conor Dooley

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=20260810-preoccupy-earwig-c8d98044c1da@spud \
    --to=conor@kernel.org \
    --cc=aleksa.paunovic@htecgroup.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=arikalo@gmail.com \
    --cc=boqun@kernel.org \
    --cc=cfu@mips.com \
    --cc=charlie@rivosinc.com \
    --cc=djordje.todorovic@htecgroup.com \
    --cc=gary@garyguo.net \
    --cc=jrtc27@jrtc27.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mark.rutland@arm.com \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=peterz@infradead.org \
    --cc=pjw@kernel.org \
    --cc=samuel.holland@sifive.com \
    --cc=will@kernel.org \
    --cc=yury.norov@gmail.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