From: Stian Halseth <stian@itx.no>
To: sparclinux@vger.kernel.org
Cc: Andreas Larsson <andreas@gaisler.com>,
"David S . Miller" <davem@davemloft.net>,
Eric Biggers <ebiggers@kernel.org>,
Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>,
linux-kernel@vger.kernel.org, Stian Halseth <stian@itx.no>
Subject: [PATCH] sparc64: Read qemu,hwcap-list from the OF cpu node on sun4u
Date: Tue, 17 Nov 2026 12:29:14 +0100 [thread overview]
Message-ID: <20261117112914.2300417-1-stian@itx.no> (raw)
The SPARC crypto opcodes are used only when hwcap-list names them.
Only the sun4v machine description carries a hwcap-list. QEMU's
default sparc64 machine is sun4u and has no machine description. The
kernel then never uses QEMU's crypto instructions, and the crypto
KUnit tests only exercise the generic code.
For CPUs with the crypto feature, QEMU passes a hwcap-list to the
firmware. OpenBIOS puts it on the cpu node as qemu,hwcap-list. Real
sun4u firmware has no such property.
Factor out the hwcap-list parser. When there is no machine
description, read the list from that property.
Signed-off-by: Stian Halseth <stian@itx.no>
---
The QEMU side is in master for 11.2: commit a1eb9a1720 ("hw/sparc64:
Pass hwcap-list to OpenBIOS via fw_cfg"). The OpenBIOS side is on the
OpenBIOS list:
https://mail.coreboot.org/archives/list/openbios@openbios.org/thread/3XVXVLHWT2T63IYWR67WPOHFSJGLP3NP/
Until QEMU ships an OpenBIOS with it, nvramrc can set the property.
This runs the crypto KUnit tests on the sparc64 code with QEMU master:
NV='" /SUNW,UltraSPARC-IIi" find-device " vis" encode-string " vis2" encode-string encode+ " vis3" encode-string encode+ " aes" encode-string encode+ " sha1" encode-string encode+ " sha256" encode-string encode+ " sha512" encode-string encode+ " crc32c" encode-string encode+ " qemu,hwcap-list" property device-end'
./tools/testing/kunit/kunit.py run --arch=sparc64 \
--kunitconfig=lib/crypto/.kunitconfig \
--kunitconfig=lib/crc/.kunitconfig \
--qemu_args='-cpu TI-UltraSparc-IIi,+vis3,+crypto' \
--qemu_args='-prom-env use-nvramrc?=true' \
--qemu_args="-prom-env 'nvramrc=$NV'"
The sparc64 crypto drivers load and the KUnit suites pass. Without
+crypto the CPU caps are unchanged. Once a QEMU release has the
OpenBIOS side, kunit's sparc64 config could pass +crypto. Older QEMU
rejects that flag.
With +crypto, the self-tests of ecb-, cbc- and ctr-aes-sparc64 fail.
The glue keeps the AES round keys in FP registers across
skcipher_walk_done(). On sun4u, the memcpy there uses VIS and
overwrites them. No real sun4u CPU has the crypto opcodes, so this
only shows up under QEMU.
Moving sparc's ECB, CBC and CTR into lib/crypto, as for riscv and x86,
would fix it. Eric, is that something you plan to do?
arch/sparc/kernel/setup_64.c | 63 ++++++++++++++++++++++++++----------
1 file changed, 46 insertions(+), 17 deletions(-)
diff --git a/arch/sparc/kernel/setup_64.c b/arch/sparc/kernel/setup_64.c
index 63615f5c99b47..87e7b1bf4aeca 100644
--- a/arch/sparc/kernel/setup_64.c
+++ b/arch/sparc/kernel/setup_64.c
@@ -32,6 +32,7 @@
#include <linux/module.h>
#include <linux/start_kernel.h>
#include <linux/memblock.h>
+#include <linux/of.h>
#include <uapi/linux/mount.h>
#include <asm/io.h>
@@ -466,25 +467,9 @@ static void __init report_hwcaps(unsigned long caps)
printk(KERN_CONT "]\n");
}
-static unsigned long __init mdesc_cpu_hwcap_list(void)
+static unsigned long __init hwcap_list_caps(const char *prop, int len)
{
- struct mdesc_handle *hp;
unsigned long caps = 0;
- const char *prop;
- int len;
- u64 pn;
-
- hp = mdesc_grab();
- if (!hp)
- return 0;
-
- pn = mdesc_node_by_name(hp, MDESC_NODE_NULL, "cpu");
- if (pn == MDESC_NODE_NULL)
- goto out;
-
- prop = mdesc_get_property(hp, pn, "hwcap-list", &len);
- if (!prop)
- goto out;
while (len) {
int i, plen;
@@ -507,11 +492,53 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
len -= plen;
}
+ return caps;
+}
+
+static unsigned long __init mdesc_cpu_hwcap_list(void)
+{
+ struct mdesc_handle *hp;
+ unsigned long caps = 0;
+ const char *prop;
+ int len;
+ u64 pn;
+
+ hp = mdesc_grab();
+ if (!hp)
+ return 0;
+
+ pn = mdesc_node_by_name(hp, MDESC_NODE_NULL, "cpu");
+ if (pn == MDESC_NODE_NULL)
+ goto out;
+
+ prop = mdesc_get_property(hp, pn, "hwcap-list", &len);
+ if (prop)
+ caps = hwcap_list_caps(prop, len);
+
out:
mdesc_release(hp);
return caps;
}
+/* sun4u has no machine description; QEMU lists the caps here. */
+static unsigned long __init of_cpu_hwcap_list(void)
+{
+ struct device_node *dp;
+ unsigned long caps = 0;
+ const char *prop;
+ int len;
+
+ dp = of_find_node_by_type(NULL, "cpu");
+ if (!dp)
+ return 0;
+
+ prop = of_get_property(dp, "qemu,hwcap-list", &len);
+ if (prop)
+ caps = hwcap_list_caps(prop, len);
+ of_node_put(dp);
+ return caps;
+}
+
/* This yields a mask that user programs can use to figure out what
* instruction set this cpu supports.
*/
@@ -549,6 +576,8 @@ static void __init init_sparc64_elf_hwcap(void)
cap |= (AV_SPARC_MUL32 | AV_SPARC_DIV32 | AV_SPARC_V8PLUS);
mdesc_caps = mdesc_cpu_hwcap_list();
+ if (!mdesc_caps)
+ mdesc_caps = of_cpu_hwcap_list();
if (!mdesc_caps) {
if (tlb_type == spitfire)
cap |= AV_SPARC_VIS;
--
2.43.0
next reply other threads:[~2026-11-17 11:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 11:29 Stian Halseth [this message]
[not found] ` <sashiko-outbox-218725@kernel.org>
2026-11-17 12:44 ` Stian Halseth
2026-11-18 4:38 ` Eric Biggers
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=20261117112914.2300417-1-stian@itx.no \
--to=stian@itx.no \
--cc=andreas@gaisler.com \
--cc=davem@davemloft.net \
--cc=ebiggers@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.cave-ayland@ilande.co.uk \
--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®