sparc64: Report the M7 hardware capabilities
cover sparc64: Report the M7 hardware capabilities
A SPARC M7 lists 28 capabilities in its machine description. The kernel only recognises 20, so AT_HWCAP is missing six the chip has.
The list is readable from userspace through /dev/mdesc. All 256 cpu nodes on a T7-1 carry the same one:
vis vis2 popc vis3 vis3b fmaf hpc ASIBlkInit ima pause pause-nsec cbcond mwait adp sparc5 cfr aes des camellia md5 sha1 sha256 sha512 mpmul mont crc32c xmpmul xmont
Patch 1 prints what is not recognised. Patches 2 to 5 handle the M7 entries.
VA masking is not in the hwcap-list. The cpu node carries va-mask-nz-mask instead, so patch 4 reads that rather than matching on sun4v_chip_type.
AT_HWCAP before and after:
T7-1 (M7) 0xf47fbdf -> 0x1ff47fbdf
T4-1 0x747fbdf -> 0x747fbdfThe T4 is unchanged by design. Once patch 5 is in, its machine description names nothing the kernel lacks, and its CFR stops at bit 11.
'cfr' is still reported as unrecognised on the M7. It states that the CFR register is present rather than naming a capability. It cannot be used to gate the rd %asr26 reads either: a T4 has the register but does not advertise it.
Stian Halseth (5):
sparc64: Report unrecognised machine description hwcap-list entries
sparc64: Add the M7 capabilities carried in the hwcap-list
sparc64: Report the extended crypto capabilities
sparc64: Derive VA masking support from the machine description
sparc64: Match the machine description's combined crypto names
arch/sparc/include/asm/elf_64.h | 9 ++++++ arch/sparc/kernel/setup_64.c | 57 +++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/5 sparc64: Report unrecognised machine description hwcap-list entries
mdesc_cpu_hwcap_list() matches each string in the cpu node's hwcap-list against hwcaps[] and crypto_hwcaps[]. A string that matches neither is skipped silently, so firmware can advertise a capability the kernel has no name for and nothing reports it.
A SPARC T7-1 (M7) emits 28 entries, of which eight match nothing:
vis3b pause-nsec mwait sparc5 cfr mont xmpmul xmont
Print the ones that are not recognised.
--- arch/sparc/kernel/setup_64.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
arch/sparc/kernel/setup_64.c +9 -1
@@ -488,20 +488,28 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)while (len) {int i, plen; +bool known = false;for (i =0 ; i <ARRAY_SIZE (hwcaps); i++) {unsigned long bit =1UL << i;if (hwcaps[i] && !strcmp (prop, hwcaps[i])) { caps |= bit; + known = true;break ; } }for (i =0 ; i <ARRAY_SIZE (crypto_hwcaps); i++) { -if (!strcmp (prop, crypto_hwcaps[i])) +if (!strcmp (prop, crypto_hwcaps[i])) { caps |=HWCAP_SPARC_CRYPTO ; + known = true; + } } +if (!known) +pr_info ("CPU CAPS: unknown hwcap-list entry '%s'\n" , + prop); + plen =strlen (prop) +1 ; prop += plen; len -= plen;
Signature · 1 line
2.43.0
PATCH 2/5 sparc64: Add the M7 capabilities carried in the hwcap-list
In reply to Stian HalsethA SPARC M7's machine description names four capabilities the kernel does not know, so they never reach AT_HWCAP:
vis3b pause-nsec mwait sparc5
Add them. hwcaps[] is indexed by bit position and only ever appended to, so the four names take indices 28 to 31, in the order the machine description lists them. That fixes their bit values.
Read from /dev/mdesc on a SPARC T7-1, where all 256 cpu nodes carry an identical hwcap-list.
--- arch/sparc/include/asm/elf_64.h | 8 ++++++++ arch/sparc/kernel/setup_64.c | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-)
arch/sparc/include/asm/elf_64.h +8 -0
@@ -99,6 +99,14 @@#define HWCAP_SPARC_CRYPTO 0x04000000/* CRYPTO insns available */ #define HWCAP_SPARC_ADI 0x08000000/* ADI available */ +/* Linux has only AT_HWCAP, so these continue the single word. They are +* ABI: a bit once assigned cannot be moved. +*/ +#define HWCAP_SPARC_VIS3B 0x10000000/* VIS3B insns available */ +#define HWCAP_SPARC_PAUSE_NSEC 0x20000000/* PAUSE has nanosecond granularity */ +#define HWCAP_SPARC_MWAIT 0x40000000/* MWAIT available */ +#define HWCAP_SPARC_SPARC5 0x80000000/* SPARC5 insns available */ +#define CORE_DUMP_USE_REGSET /*
arch/sparc/kernel/setup_64.c +1 -1
@@ -387,7 +387,7 @@ static const char *hwcaps[] = {"mul32" ,"div32" ,"fsmuld" ,"v8plus" ,"popc" ,"vis" ,"vis2" ,"ASIBlkInit" ,"fmaf" ,"vis3" ,"hpc" ,"random" ,"trans" ,"fjfmau" ,"ima" ,"cspare" ,"pause" ,"cbcond" ,NULL /*reserved for crypto */ , - "adp", + "adp", "vis3b", "pause-nsec", "mwait", "sparc5", }; static const char *crypto_hwcaps[] = {
Signature · 1 line
2.43.0
PATCH 3/5 sparc64: Report the extended crypto capabilities
In reply to Stian Halsethcrypto_hwcaps[] is indexed by CFR bit and stops at crc32c in bit 11. The loops in cpucap_info() and report_crypto_hwcaps() are bounded by the array, so a higher bit is read out of CFR and then discarded.
A SPARC M7 sets CFR bits 12 to 14. Name them.
T7-1 CFR 0x7ffb bits 0-14 except kasumi, so 12-14 are set T4-1 CFR 0x0fff bits 0-11, unchanged by this patch
--- arch/sparc/kernel/setup_64.c | 1 + 1 file changed, 1 insertion(+)
arch/sparc/kernel/setup_64.c +1 -0
@@ -393,6 +393,7 @@ static const char *hwcaps[] = {static const char *crypto_hwcaps[] = {"aes" ,"des" ,"kasumi" ,"camellia" ,"md5" ,"sha1" ,"sha256" ,"sha512" ,"mpmul" ,"montmul" ,"montsqr" ,"crc32c" , +"xmpmul" ,"xmontmul" ,"xmontsqr" , };void cpucap_info (struct seq_file *m)
Signature · 1 line
2.43.0
PATCH 4/5 sparc64: Derive VA masking support from the machine description
In reply to Stian HalsethVA masking is not named in the cpu node's hwcap-list. The machine description carries va-mask-nz-mask instead, which is present and non-zero only on a chip that has the feature. A SPARC M7 reports 0x80808080.
Read that property rather than matching on sun4v_chip_type, so the kernel does not have to carry a list of every chip that implements VA masking.
hwcaps[] gains "vamask" as well, for firmware that does name it. The M7 does not.
The bit lands at 32, so a 32-bit task cannot see it: compat_binfmt_elf.c narrows AT_HWCAP to Elf32_Addr.
--- arch/sparc/include/asm/elf_64.h | 1 + arch/sparc/kernel/setup_64.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-)
arch/sparc/include/asm/elf_64.h +1 -0
@@ -106,6 +106,7 @@#define HWCAP_SPARC_PAUSE_NSEC 0x20000000/* PAUSE has nanosecond granularity */ #define HWCAP_SPARC_MWAIT 0x40000000/* MWAIT available */ #define HWCAP_SPARC_SPARC5 0x80000000/* SPARC5 insns available */ +#define HWCAP_SPARC_VAMASK 0x100000000UL/* VA masking available */ #define CORE_DUMP_USE_REGSET
arch/sparc/kernel/setup_64.c +31 -1
@@ -387,7 +387,7 @@ static const char *hwcaps[] = {"mul32" ,"div32" ,"fsmuld" ,"v8plus" ,"popc" ,"vis" ,"vis2" ,"ASIBlkInit" ,"fmaf" ,"vis3" ,"hpc" ,"random" ,"trans" ,"fjfmau" ,"ima" ,"cspare" ,"pause" ,"cbcond" ,NULL /*reserved for crypto */ , - "adp", "vis3b", "pause-nsec", "mwait", "sparc5", + "adp", "vis3b", "pause-nsec", "mwait", "sparc5", "vamask", }; static const char *crypto_hwcaps[] = {
@@ -521,6 +521,33 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)return caps; } +/* VA masking is not named in the hwcap-list. The cpu node describes it +* with va-mask-nz-mask instead, which is non-zero when the chip has it. +*/ +static bool __init mdesc_cpu_has_vamask (void ) +{ +struct mdesc_handle *hp; +const u64 *mask; +bool ret = false; +u64 pn; + + hp =mdesc_grab (); +if (!hp) +return false; + + pn =mdesc_node_by_name (hp,MDESC_NODE_NULL ,"cpu" ); +if (pn ==MDESC_NODE_NULL ) + goto out; + + mask =mdesc_get_property (hp, pn,"va-mask-nz-mask" ,NULL ); +if (mask && *mask) + ret = true; + +out: +mdesc_release (hp); +return ret; +} +/* This yields a mask that user programs can use to figure out what * instruction set this cpu supports. */
@@ -598,6 +625,9 @@ static void __init init_sparc64_elf_hwcap(void) AV_SPARC_FMAF); } } +if (mdesc_cpu_has_vamask ()) + cap |=HWCAP_SPARC_VAMASK ; + sparc64_elf_hwcap = cap | mdesc_caps;report_hwcaps (sparc64_elf_hwcap);
Signature · 1 line
2.43.0
PATCH 5/5 sparc64: Match the machine description's combined crypto names
In reply to Stian Halsethcrypto_hwcaps[] is indexed by CFR bit, and mdesc_cpu_hwcap_list() reuses it to match hwcap-list strings. Those are two different namespaces. CFR has a bit each for the Montgomery multiply and square, while the machine description names the pair with one string, so "mont" and "xmont" match nothing.
Nothing breaks today: any recognised crypto name sets HWCAP_SPARC_CRYPTO, and a chip offering the Montgomery operations offers "aes" too. It is still wrong, since a machine description listing only the Montgomery names would leave HWCAP_SPARC_CRYPTO clear.
Match them from a list of their own rather than adding them to crypto_hwcaps[], where they would claim a CFR bit that means something else.
--- arch/sparc/kernel/setup_64.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
arch/sparc/kernel/setup_64.c +14 -0
@@ -396,6 +396,14 @@ static const char *crypto_hwcaps[] = { "xmpmul", "xmontmul", "xmontsqr", }; +/* crypto_hwcaps[] is indexed by CFR bit. The machine description names +* the Montgomery operations with one string each where CFR splits them +* into a multiply and a square, so those names need a list of their own. +*/ +static const char *const crypto_mdesc_hwcaps[]__initconst = { +"mont" ,"xmont" , +}; +void cpucap_info (struct seq_file *m) {unsigned long caps = sparc64_elf_hwcap;
@@ -506,6 +514,12 @@ static unsigned long __init mdesc_cpu_hwcap_list(void) known = true; } } +for (i =0 ; i <ARRAY_SIZE (crypto_mdesc_hwcaps); i++) { +if (!strcmp (prop, crypto_mdesc_hwcaps[i])) { + caps |=HWCAP_SPARC_CRYPTO ; + known = true; + } + }if (!known) pr_info("CPU CAPS: unknown hwcap-list entry '%s'\n",
Signature · 1 line
2.43.0