mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Magnus Lindholm <linmag7@gmail.com>
To: davem@davemloft.net, andreas@gaisler.com
Cc: sam@ravnborg.org, sparclinux@vger.kernel.org,
	linux-kernel@vger.kernel.org, linmag7@gmail.com
Subject: [RFC PATCH 4/5] sparc32: advertise the compare-and-swap trap in AT_HWCAP
Date: Wed, 23 Sep 2026 22:17:20 +0200	[thread overview]
Message-ID: <20260923201830.865553-5-linmag7@gmail.com> (raw)
In-Reply-To: <20260923201830.865553-1-linmag7@gmail.com>

A process that wants the kernel to perform a compare-and-swap has no way
to find out whether this kernel will do it, and issuing the trap to find
out is not an option: on a kernel without it the trap is a bad trap and
the process dies.

Guessing is worse than dying. On sparc64 ta 0x11 is not an illegal
instruction but the old 64-bit system call trap, so a process that issued
it there would make a wild syscall rather than take a signal.

Advertise it in AT_HWCAP so the question can be asked first.  Bit
0x10000000 is unused on sparc32 and on sparc64, so it reads as clear in
exactly the cases where the trap is absent: an older kernel, or sparc64
compat mode, where a 32-bit process reads its hwcap word from elf_64.h.
Reserve the same bit there with a comment so it is not handed to something
else later and mistaken for this.

A caller that finds the bit clear must fall back to whatever it can do by
itself or report the operation unsupported. A private lock is not a
general answer: it cannot make a word atomic against another process,
which is the reason for the trap in the first place.

Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
 arch/sparc/include/asm/elf_32.h | 7 ++++++-
 arch/sparc/include/asm/elf_64.h | 3 +++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
index 37a6016c9ccd..c60d803cf556 100644
--- a/arch/sparc/include/asm/elf_32.h
+++ b/arch/sparc/include/asm/elf_32.h
@@ -64,6 +64,10 @@
 #define HWCAP_SPARC_MULDIV      8
 #define HWCAP_SPARC_V9		16
 #define HWCAP_SPARC_ULTRA3	32
+/* Kernel compare-and-swap trap available; see
+ * Documentation/arch/sparc/cas-trap.rst.  Do not issue the trap if clear.
+ */
+#define HWCAP_SPARC_CASTRAP	0x10000000
 
 #define CORE_DUMP_USE_REGSET
 
@@ -121,7 +125,8 @@ typedef struct {
 
 /* Most sun4m's have them all.  */
 #define ELF_HWCAP	(HWCAP_SPARC_FLUSH | HWCAP_SPARC_STBAR | \
-			 HWCAP_SPARC_SWAP | HWCAP_SPARC_MULDIV)
+			 HWCAP_SPARC_SWAP | HWCAP_SPARC_MULDIV | \
+			 HWCAP_SPARC_CASTRAP)
 
 /* This yields a string that ld.so will use to load implementation
    specific libraries for optimization.  This is more specific in
diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
index 694ed081cf8d..a2117a81b6d8 100644
--- a/arch/sparc/include/asm/elf_64.h
+++ b/arch/sparc/include/asm/elf_64.h
@@ -98,6 +98,9 @@
  */
 #define HWCAP_SPARC_CRYPTO	0x04000000 /* CRYPTO insns available */
 #define HWCAP_SPARC_ADI		0x08000000 /* ADI available */
+/* 0x10000000 is HWCAP_SPARC_CASTRAP on sparc32 and must stay clear here;
+ * a 32-bit process reads this word too and there is no such trap on sparc64.
+ */
 
 #define CORE_DUMP_USE_REGSET
 
-- 
2.43.0


  parent reply	other threads:[~2026-09-23 20:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23 20:17 [RFC PATCH 0/5] sparc32: kernel assisted compare-and-swap, and futex on SMP Magnus Lindholm
2026-09-23 20:17 ` [RFC PATCH 1/5] sparc32: detect the compare-and-swap instruction at boot Magnus Lindholm
2026-09-23 20:17 ` [RFC PATCH 2/5] sparc32: add a kernel assisted compare-and-swap Magnus Lindholm
2026-09-23 20:17 ` [RFC PATCH 3/5] sparc32: implement futex atomic ops with the compare-and-swap locks Magnus Lindholm
2026-09-23 20:17 ` Magnus Lindholm [this message]
2026-09-23 20:17 ` [RFC PATCH 5/5] sparc32: document the compare-and-swap trap ABI Magnus Lindholm

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=20260923201830.865553-5-linmag7@gmail.com \
    --to=linmag7@gmail.com \
    --cc=andreas@gaisler.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sam@ravnborg.org \
    --cc=sparclinux@vger.kernel.org \
    /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®