Skip to contentSkip to conversation

arm64/sme: Initial support for the Scalable Matrix Extension

PATCH Superseded Mark Brown 9 participants 136 messages Feb 7, 2022 – Mar 2, 2022

Subsystems (6)

v11 of 14 Superseded Latest is v14 →

lore
Share & tools
lore

Mark Brown

author
#0 lore raw

v11 cover arm64/sme: Initial support for the Scalable Matrix Extension

This series provides initial support for the ARMv9 Scalable Matrix Extension (SME). SME takes the approach used for vectors in SVE and extends this to provide architectural support for matrix operations. A more detailed overview can be found in [1].

For the kernel SME can be thought of as a series of features which are intended to be used together by applications but operate mostly orthogonally:

- The ZA matrix register.
- Streaming mode, in which ZA can be accessed and a subset of SVE features are available.
- A second vector length, used for streaming mode SVE and ZA and controlled using a similar interface to that for SVE.
- TPIDR2, a new userspace controllable system register intended for use by the C library for storing context related to the ZA ABI.

A substantial part of the series is dedicated to refactoring the existing SVE support so that we don't need to duplicate code for handling vector lengths and the SVE registers, this involves creating an array of vector types and making the users take the vector type as a parameter. I'm not 100% happy with this but wasn't able to come up with anything better, duplicating code definitely felt like a bad idea so this felt like the least bad thing. If this approach makes sense to people it might make sense to split this off into a separate series and/or merge it while the rest is pending review to try to make things a little more digestable, the series is very large so it'd probably make things easier to digest if some of the preparatory refactoring could be merged before the rest is ready.

One feature of the architecture of particular note is that switching to and from streaming mode may change the size of and invalidate the contents of the SVE registers, and when in streaming mode the FFR is not accessible. This complicates aspects of the ABI like signal handling and ptrace.

This initial implementation is mainly intended to get the ABI in place, there are several areas which will be worked on going forwards - some of these will be blockers, others could be handled in followup serieses:

- SME is currently not supported for KVM guests, this will be done as a followup series. A host system can use SME and run KVM guests but SME is not available in the guests.
- The KVM host support is done in a very simplistic way, were anyone to attempt to use it in production there would be performance impacts on hosts with SME support. As part of this we also add enumeration of fine grained traps.
- There is not currently ptrace or signal support TPIDR2, this will be done as a followup series.
- No support is currently provided for scheduler control of SME or SME applications, given the size of the SME register state the context switch overhead may be noticable so this may be needed especially for real time applications. Similar concerns already exist for larger SVE vector lengths but are amplified for SME, particularly as the vector length increases.
- There has been no work on optimising the performance of anything the kernel does.

It is not expected that any systems will be encountered that support SME but not SVE, SME is an ARMv9 feature and SVE is mandatory for ARMv9. The code attempts to handle any such systems that are encountered but this hasn't been tested extensively.

v11:
- Rebase onto v5.17-rc3.
- Provide a sme-inst.h to collect manual encodings in kselftest.
v10:
- Actually do the rebase of fixups from the previous version into relevant patches.
v9:
- Remove defensive programming around IS_ENABLED() and FGT in KVM code.
- Fix naming of TPIDR2 FGT register bit.
- Add patches making handling of floating point register bits more consistent (also sent as separate series).
- Drop now unused enumeration of fine grained traps.
v8:
- Rebase onto v5.17-rc1.
- Support interoperation with KVM, SME is disabled for KVM guests with minimal handling for cleaning up SME state when entering and leaving the guest.
- Document and implement that signal handlers are invoked with ZA and streaming mode disabled.
- Use the RDSVL instruction introduced in EAC2 of the architecture to obtain the streaming mode vector length during enumeration, ZA state loading/saving and in test programs.
- Store a pointer to SVCR in fpsimd_last_state and use it in fpsimd_save() for interoperation with KVM.
- Add a test case sme_trap_no_sm checking that we generate a SIGILL when using an instruction that requires streaming mode without enabling it.
- Add basic ZA context form validation to testcases helper library.
- Move signal tests over to validating streaming VL from ZA information.
- Pulled in patch removing ARRAY_SIZE() so that kselftest builds cleanly and to avoid trivial conflicts.
v7:
- Rebase onto v5.16-rc3.
- Reduce indentation when supporting custom triggers for signal tests as suggested by Catalin.
- Change to specifying a width for all CPU features rather than adding single bit specific infrastructure.
- Don't require zeroing of non-shared SVE state during syscalls.
v6:
- Rebase onto v5.16-rc1.
- Return to disabling TIF_SVE on kernel entry even if we have SME state, this avoids the need for KVM to handle the case where TIF_SVE is set on guest entry.
- Add syscall-abi.h to SME updates to syscall-abi, mistakenly omitted from commit.
v5:
- Rebase onto currently merged SVE and kselftest patches.
- Add support for the FA64 option, introduced in the recently published EAC1 update to the specification.
- Pull in test program for the syscall ABI previously sent separately with some revisions and add coverage for the SME ABI.
- Fix checking for options with 1 bit fields in ID_AA64SMFR0_EL1.
- Minor fixes and clarifications to the ABI documentation.
v4:
- Rebase onto merged patches.
- Remove an uneeded NULL check in vec_proc_do_default_vl().
- Include patch to factor out utility routines in kselftests written in assembler.
- Specify -ffreestanding when building TPIDR2 test.
v3:
- Skip FFR rather than predicate registers in sve_flush_live().
- Don't assume a bool is all zeros in sve_flush_live() as per AAPCS.
- Don't redundantly specify a zero index when clearing FFR.
v2:
- Fix several issues with !SME and !SVE configurations.
- Preserve TPIDR2 when creating a new thread/process unless CLONE_SETTLS is set.
- Report traps due to using features in an invalid mode as SIGILL.
- Spell out streaming mode behaviour in SVE ABI documentation more directly.
- Document TPIDR2 in the ABI document.
- Use SMSTART and SMSTOP rather than read/modify/write sequences.
- Rework logic for exiting streaming mode on syscall.
- Don't needlessly initialise SVCR on access trap.
- Always restore SME VL for userspace if SME traps are disabled.
- Only yield to encourage preemption every 128 iterations in za-test, otherwise do a getpid(), and validate SVCR after syscall.
- Leave streaming mode disabled except when reading the vector length in za-test, and disable ZA after detecting a mismatch.
- Add SME support to vlset.
- Clarifications and typo fixes in comments.
- Move sme_alloc() forward declaration back a patch.

[1] https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/scalable-matrix-extension-armv9-a-architecture

Mark Brown (40):
arm64: Define CPACR_EL1_FPEN similarly to other floating point
controls
arm64: Always use individual bits in CPACR floating point enables
arm64: cpufeature: Always specify and use a field width for
capabilities
kselftest/arm64: Remove local ARRAY_SIZE() definitions kselftest/arm64: signal: Allow tests to be incompatible with features arm64/sme: Provide ABI documentation for SME
arm64/sme: System register and exception syndrome definitions arm64/sme: Manually encode SME instructions
arm64/sme: Early CPU setup for SME
arm64/sme: Basic enumeration support
arm64/sme: Identify supported SME vector lengths at boot arm64/sme: Implement sysctl to set the default vector length arm64/sme: Implement vector length configuration prctl()s arm64/sme: Implement support for TPIDR2
arm64/sme: Implement SVCR context switching
arm64/sme: Implement streaming SVE context switching arm64/sme: Implement ZA context switching
arm64/sme: Implement traps and syscall handling for SME arm64/sme: Disable ZA and streaming mode when handling signals arm64/sme: Implement streaming SVE signal handling arm64/sme: Implement ZA signal handling
arm64/sme: Implement ptrace support for streaming mode SVE registers arm64/sme: Add ptrace support for ZA
arm64/sme: Disable streaming mode and ZA when flushing CPU state arm64/sme: Save and restore streaming mode over EFI runtime calls
KVM: arm64: Hide SME system registers from guests
KVM: arm64: Trap SME usage in guest
KVM: arm64: Handle SME host state when running guests arm64/sme: Provide Kconfig for SME
kselftest/arm64: Add manual encodings for SME instructions kselftest/arm64: sme: Add SME support to vlset kselftest/arm64: Add tests for TPIDR2
kselftest/arm64: Extend vector configuration API tests to cover SME kselftest/arm64: sme: Provide streaming mode SVE stress test kselftest/arm64: signal: Handle ZA signal context in core code kselftest/arm64: Add stress test for SME ZA context switching kselftest/arm64: signal: Add SME signal handling tests kselftest/arm64: Add streaming SVE to SVE ptrace tests kselftest/arm64: Add coverage for the ZA ptrace interface kselftest/arm64: Add SME support to syscall ABI test

 Documentation/arm64/elf_hwcaps.rst            |  33 +
 Documentation/arm64/index.rst                 |   1 +
 Documentation/arm64/sme.rst                   | 432 +++++++++++++
 Documentation/arm64/sve.rst                   |  70 ++-
 arch/arm64/Kconfig                            |  11 +
 arch/arm64/include/asm/cpu.h                  |   4 +
 arch/arm64/include/asm/cpufeature.h           |  25 +
 arch/arm64/include/asm/el2_setup.h            |  64 +-
 arch/arm64/include/asm/esr.h                  |  13 +-
 arch/arm64/include/asm/exception.h            |   1 +
 arch/arm64/include/asm/fpsimd.h               | 110 +++-
 arch/arm64/include/asm/fpsimdmacros.h         |  86 +++
 arch/arm64/include/asm/hwcap.h                |   8 +
 arch/arm64/include/asm/kvm_arm.h              |   5 +-
 arch/arm64/include/asm/kvm_host.h             |   4 +
 arch/arm64/include/asm/processor.h            |  18 +-
 arch/arm64/include/asm/sysreg.h               |  67 +-
 arch/arm64/include/asm/thread_info.h          |   2 +
 arch/arm64/include/uapi/asm/hwcap.h           |   8 +
 arch/arm64/include/uapi/asm/ptrace.h          |  69 ++-
 arch/arm64/include/uapi/asm/sigcontext.h      |  55 +-
 arch/arm64/kernel/cpufeature.c                | 273 ++++++--
 arch/arm64/kernel/cpuinfo.c                   |  13 +
 arch/arm64/kernel/entry-common.c              |  11 +
 arch/arm64/kernel/entry-fpsimd.S              |  36 ++
 arch/arm64/kernel/fpsimd.c                    | 585 ++++++++++++++++--
 arch/arm64/kernel/process.c                   |  28 +-
 arch/arm64/kernel/ptrace.c                    | 356 +++++++++--
 arch/arm64/kernel/signal.c                    | 194 +++++-
 arch/arm64/kernel/syscall.c                   |  34 +-
 arch/arm64/kernel/traps.c                     |   1 +
 arch/arm64/kvm/fpsimd.c                       |  43 +-
 arch/arm64/kvm/hyp/include/hyp/switch.h       |   4 +-
 arch/arm64/kvm/hyp/nvhe/switch.c              |  30 +
 arch/arm64/kvm/hyp/vhe/switch.c               |  15 +-
 arch/arm64/kvm/sys_regs.c                     |   9 +-
 arch/arm64/tools/cpucaps                      |   2 +
 include/uapi/linux/elf.h                      |   2 +
 include/uapi/linux/prctl.h                    |   9 +
 kernel/sys.c                                  |  12 +
 tools/testing/selftests/arm64/abi/.gitignore  |   1 +
 tools/testing/selftests/arm64/abi/Makefile    |   9 +-
 .../selftests/arm64/abi/syscall-abi-asm.S     |  69 ++-
 .../testing/selftests/arm64/abi/syscall-abi.c | 205 +++++-
 .../testing/selftests/arm64/abi/syscall-abi.h |  15 +
 tools/testing/selftests/arm64/abi/tpidr2.c    | 298 +++++++++
 tools/testing/selftests/arm64/fp/.gitignore   |   4 +
 tools/testing/selftests/arm64/fp/Makefile     |  12 +-
 tools/testing/selftests/arm64/fp/rdvl-sme.c   |  14 +
 tools/testing/selftests/arm64/fp/rdvl.S       |  10 +
 tools/testing/selftests/arm64/fp/rdvl.h       |   1 +
 tools/testing/selftests/arm64/fp/sme-inst.h   |  51 ++
 tools/testing/selftests/arm64/fp/ssve-stress  |  59 ++
 tools/testing/selftests/arm64/fp/sve-ptrace.c |  13 +-
 tools/testing/selftests/arm64/fp/sve-test.S   |  20 +
 tools/testing/selftests/arm64/fp/vec-syscfg.c |  10 +
 tools/testing/selftests/arm64/fp/vlset.c      |  10 +-
 tools/testing/selftests/arm64/fp/za-ptrace.c  | 354 +++++++++++
 tools/testing/selftests/arm64/fp/za-stress    |  59 ++
 tools/testing/selftests/arm64/fp/za-test.S    | 388 ++++++++++++
 .../testing/selftests/arm64/signal/.gitignore |   2 +
 .../selftests/arm64/signal/test_signals.h     |   5 +
 .../arm64/signal/test_signals_utils.c         |  40 +-
 .../arm64/signal/test_signals_utils.h         |   2 +
 .../testcases/fake_sigreturn_sme_change_vl.c  |  92 +++
 .../arm64/signal/testcases/sme_trap_no_sm.c   |  38 ++
 .../signal/testcases/sme_trap_non_streaming.c |  45 ++
 .../arm64/signal/testcases/sme_trap_za.c      |  36 ++
 .../selftests/arm64/signal/testcases/sme_vl.c |  68 ++
 .../arm64/signal/testcases/ssve_regs.c        | 129 ++++
 .../arm64/signal/testcases/testcases.c        |  36 ++
 .../arm64/signal/testcases/testcases.h        |   3 +-
 72 files changed, 4590 insertions(+), 251 deletions(-)
 create mode 100644 Documentation/arm64/sme.rst
 create mode 100644 tools/testing/selftests/arm64/abi/syscall-abi.h
 create mode 100644 tools/testing/selftests/arm64/abi/tpidr2.c
 create mode 100644 tools/testing/selftests/arm64/fp/rdvl-sme.c
 create mode 100644 tools/testing/selftests/arm64/fp/sme-inst.h
 create mode 100644 tools/testing/selftests/arm64/fp/ssve-stress
 create mode 100644 tools/testing/selftests/arm64/fp/za-ptrace.c
 create mode 100644 tools/testing/selftests/arm64/fp/za-stress
 create mode 100644 tools/testing/selftests/arm64/fp/za-test.S
 create mode 100644 tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_sme_change_vl.c
 create mode 100644 tools/testing/selftests/arm64/signal/testcases/sme_trap_no_sm.c
 create mode 100644 tools/testing/selftests/arm64/signal/testcases/sme_trap_non_streaming.c
 create mode 100644 tools/testing/selftests/arm64/signal/testcases/sme_trap_za.c
 create mode 100644 tools/testing/selftests/arm64/signal/testcases/sme_vl.c
 create mode 100644 tools/testing/selftests/arm64/signal/testcases/ssve_regs.c

base-commit: dfd42facf1e4ada021b939b4e19c935dcdd55566

Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#1 lore raw

PATCH v11 1/40 arm64: Define CPACR_EL1_FPEN similarly to other floating point controls

The base floating point, SVE and SME all have enable controls for EL0 and EL1 in CPACR_EL1 which have a similar layout and function. Currently the basic floating point enable FPEN is defined differently to the SVE control, specified as a single define in kvm_arm.h rather than in sysreg.h. Move the define to sysreg.h and provide separate EL0 and EL1 control bits so code managing the different floating point enables can look consistent.

---
 arch/arm64/include/asm/kvm_arm.h | 1 -
 arch/arm64/include/asm/sysreg.h  | 4 ++++
 2 files changed, 4 insertions(+), 1 deletion(-)
arch/arm64/include/asm/kvm_arm.h +0 -1
index 01d47c5886dc..eec790842fe2 100644
@@ -355,7 +355,6 @@
 	ECN(SOFTSTP_CUR), ECN(WATCHPT_LOW), ECN(WATCHPT_CUR), \
 	ECN(BKPT32), ECN(VECTOR32), ECN(BRK64)
 
-#define CPACR_EL1_FPEN		(3 << 20)
 #define CPACR_EL1_TTA		(1 << 28)
 #define CPACR_EL1_DEFAULT	(CPACR_EL1_FPEN | CPACR_EL1_ZEN_EL1EN)
 
arch/arm64/include/asm/sysreg.h +4 -0
index 898bee0004ae..1da4c43d597d 100644
@@ -1097,6 +1097,10 @@
 #define ZCR_ELx_LEN_SIZE	9
 #define ZCR_ELx_LEN_MASK	0x1ff
 
+#define CPACR_EL1_FPEN_EL1EN	(BIT(20)) /* enable EL1 access */
+#define CPACR_EL1_FPEN_EL0EN	(BIT(21)) /* enable EL0 access, if EL1EN set */
+#define CPACR_EL1_FPEN		(CPACR_EL1_FPEN_EL1EN | CPACR_EL1_FPEN_EL0EN)
+
 #define CPACR_EL1_ZEN_EL1EN	(BIT(16)) /* enable EL1 access */
 #define CPACR_EL1_ZEN_EL0EN	(BIT(17)) /* enable EL0 access, if EL1EN set */
 #define CPACR_EL1_ZEN		(CPACR_EL1_ZEN_EL1EN | CPACR_EL1_ZEN_EL0EN)
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#3 lore raw

PATCH v11 2/40 arm64: Always use individual bits in CPACR floating point enables

In reply to Mark Brown

CPACR_EL1 has several bitfields for controlling traps for floating point features to EL1, each of which has a separate bits for EL0 and EL1. Marc Zyngier noted that we are not consistent in our use of defines to manipulate these, sometimes using a define covering the whole field and sometimes using defines for the individual bits. Make this consistent by expanding the whole field defines where they are used (currently only in the KVM code) and deleting them so that no further uses can be introduced.

---
 arch/arm64/include/asm/kvm_arm.h        | 3 ++-
 arch/arm64/include/asm/sysreg.h         | 2 --
 arch/arm64/kvm/hyp/include/hyp/switch.h | 4 ++--
 arch/arm64/kvm/hyp/vhe/switch.c         | 6 +++---
 4 files changed, 7 insertions(+), 8 deletions(-)
arch/arm64/include/asm/kvm_arm.h +2 -1
index eec790842fe2..1767ded83888 100644
@@ -356,6 +356,7 @@
 	ECN(BKPT32), ECN(VECTOR32), ECN(BRK64)
 
 #define CPACR_EL1_TTA		(1 << 28)
-#define CPACR_EL1_DEFAULT	(CPACR_EL1_FPEN | CPACR_EL1_ZEN_EL1EN)
+#define CPACR_EL1_DEFAULT	(CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN |\
+				 CPACR_EL1_ZEN_EL1EN)
 
 #endif /* __ARM64_KVM_ARM_H__ */
arch/arm64/include/asm/sysreg.h +0 -2
index 1da4c43d597d..e66dd9ebc337 100644
@@ -1099,11 +1099,9 @@
 
 #define CPACR_EL1_FPEN_EL1EN	(BIT(20)) /* enable EL1 access */
 #define CPACR_EL1_FPEN_EL0EN	(BIT(21)) /* enable EL0 access, if EL1EN set */
-#define CPACR_EL1_FPEN		(CPACR_EL1_FPEN_EL1EN | CPACR_EL1_FPEN_EL0EN)
 
 #define CPACR_EL1_ZEN_EL1EN	(BIT(16)) /* enable EL1 access */
 #define CPACR_EL1_ZEN_EL0EN	(BIT(17)) /* enable EL0 access, if EL1EN set */
-#define CPACR_EL1_ZEN		(CPACR_EL1_ZEN_EL1EN | CPACR_EL1_ZEN_EL0EN)
 
 /* TCR EL1 Bit Definitions */
 #define SYS_TCR_EL1_TCMA1	(BIT(58))
arch/arm64/kvm/hyp/include/hyp/switch.h +2 -2
index 701cfb964905..6379a1e3e6e5 100644
@@ -174,9 +174,9 @@ static bool kvm_hyp_handle_fpsimd(struct kvm_vcpu *vcpu, u64 *exit_code)
 
 	/* Valid trap.  Switch the context: */
 	if (has_vhe()) {
-		reg = CPACR_EL1_FPEN;
+		reg = CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN;
 		if (sve_guest)
-			reg |= CPACR_EL1_ZEN;
+			reg |= CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN;
 
 		sysreg_clear_set(cpacr_el1, 0, reg);
 	} else {
arch/arm64/kvm/hyp/vhe/switch.c +3 -3
index 11d053fdd604..619353b06e38 100644
@@ -38,7 +38,7 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
 
 	val = read_sysreg(cpacr_el1);
 	val |= CPACR_EL1_TTA;
-	val &= ~CPACR_EL1_ZEN;
+	val &= ~(CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN);
 
 	/*
 	 * With VHE (HCR.E2H == 1), accesses to CPACR_EL1 are routed to
@@ -53,9 +53,9 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
 
 	if (update_fp_enabled(vcpu)) {
 		if (vcpu_has_sve(vcpu))
-			val |= CPACR_EL1_ZEN;
+			val |= CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN;
 	} else {
-		val &= ~CPACR_EL1_FPEN;
+		val &= ~(CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN);
 		__activate_traps_fpsimd32(vcpu);
 	}
 
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#5 lore raw

PATCH v11 3/40 arm64: cpufeature: Always specify and use a field width for capabilities

In reply to Mark Brown

Since all the fields in the main ID registers are 4 bits wide we have up until now not bothered specifying the width in the code. Since we now wish to use this mechanism to enumerate features from the floating point feature registers which do not follow this pattern add a width to the table. This means updating all the existing table entries but makes it less likely that we run into issues in future due to implicitly assuming a 4 bit width.

Cc Suzuki K Poulose <[email protected]>
---
 arch/arm64/include/asm/cpufeature.h |   1 +
 arch/arm64/kernel/cpufeature.c      | 167 +++++++++++++++++-----------
 2 files changed, 102 insertions(+), 66 deletions(-)
arch/arm64/include/asm/cpufeature.h +1 -0
index ef6be92b1921..2728abd9cae4 100644
@@ -356,6 +356,7 @@ struct arm64_cpu_capabilities {
 		struct {	/* Feature register checking */
 			u32 sys_reg;
 			u8 field_pos;
+			u8 field_width;
 			u8 min_field_value;
 			u8 hwcap_type;
 			bool sign;
arch/arm64/kernel/cpufeature.c +101 -66

417 lines not on this page · raw message

Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#13 lore raw

PATCH v11 4/40 kselftest/arm64: Remove local ARRAY_SIZE() definitions

In reply to Mark Brown

An ARRAY_SIZE() has been added to kselftest.h so remove the local versions in some of the arm64 selftests.

---
 tools/testing/selftests/arm64/abi/syscall-abi.c | 1 -
 tools/testing/selftests/arm64/fp/sve-ptrace.c   | 2 --
 2 files changed, 3 deletions(-)
tools/testing/selftests/arm64/abi/syscall-abi.c +0 -1
index d8eeeafb50dc..1e13b7523918 100644
@@ -18,7 +18,6 @@
 
 #include "../../kselftest.h"
 
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
 #define NUM_VL ((SVE_VQ_MAX - SVE_VQ_MIN) + 1)
 
 extern void do_syscall(int sve_vl);
tools/testing/selftests/arm64/fp/sve-ptrace.c +0 -2
index a3c1e67441f9..4bd333768cc4 100644
@@ -21,8 +21,6 @@
 
 #include "../../kselftest.h"
 
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
-
 /* <linux/elf.h> and <sys/auxv.h> don't like each other, so: */
 #ifndef NT_ARM_SVE
 #define NT_ARM_SVE 0x405
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#16 lore raw

PATCH v11 5/40 kselftest/arm64: signal: Allow tests to be incompatible with features

In reply to Mark Brown

Some features may invalidate some tests, for example by supporting an operation which would trap otherwise. Allow tests to list features that they are incompatible with so we can cover the case where a signal will be generated without disruption on systems where that won't happen.

---
 .../selftests/arm64/signal/test_signals.h     |  1 +
 .../arm64/signal/test_signals_utils.c         | 34 ++++++++++++++-----
 .../arm64/signal/test_signals_utils.h         |  2 ++
 3 files changed, 28 insertions(+), 9 deletions(-)
tools/testing/selftests/arm64/signal/test_signals.h +1 -0
index ebe8694dbef0..f909b70d9e98 100644
@@ -53,6 +53,7 @@ struct tdescr {
 	char			*name;
 	char			*descr;
 	unsigned long		feats_required;
+	unsigned long		feats_incompatible;
 	/* bitmask of effectively supported feats: populated at run-time */
 	unsigned long		feats_supported;
 	bool			initialized;
tools/testing/selftests/arm64/signal/test_signals_utils.c +25 -9
index 2f8c23af3b5e..5743897984b0 100644
@@ -36,6 +36,8 @@ static inline char *feats_to_string(unsigned long feats)
 {
 	size_t flen = MAX_FEATS_SZ - 1;
 
+	feats_string[0] = '\0';
+
 	for (int i = 0; i < FMAX_END; i++) {
 		if (feats & (1UL << i)) {
 			size_t tlen = strlen(feats_names[i]);
@@ -256,7 +258,7 @@ int test_init(struct tdescr *td)
 		td->minsigstksz = MINSIGSTKSZ;
 	fprintf(stderr, "Detected MINSTKSIGSZ:%d\n", td->minsigstksz);
 
-	if (td->feats_required) {
+	if (td->feats_required || td->feats_incompatible) {
 		td->feats_supported = 0;
 		/*
 		 * Checking for CPU required features using both the
@@ -267,15 +269,29 @@ int test_init(struct tdescr *td)
 		if (getauxval(AT_HWCAP) & HWCAP_SVE)
 			td->feats_supported |= FEAT_SVE;
 		if (feats_ok(td)) {
-			fprintf(stderr,
-				"Required Features: [%s] supported\n",
-				feats_to_string(td->feats_required &
-						td->feats_supported));
+			if (td->feats_required & td->feats_supported)
+				fprintf(stderr,
+					"Required Features: [%s] supported\n",
+					feats_to_string(td->feats_required &
+							td->feats_supported));
+			if (!(td->feats_incompatible & td->feats_supported))
+				fprintf(stderr,
+					"Incompatible Features: [%s] absent\n",
+					feats_to_string(td->feats_incompatible));
 		} else {
-			fprintf(stderr,
-				"Required Features: [%s] NOT supported\n",
-				feats_to_string(td->feats_required &
-						~td->feats_supported));
+			if ((td->feats_required & td->feats_supported) !=
+			    td->feats_supported)
+				fprintf(stderr,
+					"Required Features: [%s] NOT supported\n",
+					feats_to_string(td->feats_required &
+							~td->feats_supported));
+			if (td->feats_incompatible & td->feats_supported)
+				fprintf(stderr,
+					"Incompatible Features: [%s] supported\n",
+					feats_to_string(td->feats_incompatible &
+							~td->feats_supported));
+
+
 			td->result = KSFT_SKIP;
 			return 0;
 		}
tools/testing/selftests/arm64/signal/test_signals_utils.h +2 -0
index 6772b5c8d274..f3aa99ba67bb 100644
@@ -18,6 +18,8 @@ void test_result(struct tdescr *td);
 
 static inline bool feats_ok(struct tdescr *td)
 {
+	if (td->feats_incompatible & td->feats_supported)
+		return false;
 	return (td->feats_required & td->feats_supported) == td->feats_required;
 }
 
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#20 lore raw

PATCH v11 6/40 arm64/sme: Provide ABI documentation for SME

In reply to Mark Brown

Provide ABI documentation for SME similar to that for SVE. Due to the very large overlap around streaming SVE mode in both implementation and interfaces documentation for streaming mode SVE is added to the SVE document rather than the SME one.

---
 Documentation/arm64/index.rst |   1 +
 Documentation/arm64/sme.rst   | 432 ++++++++++++++++++++++++++++++++++
 Documentation/arm64/sve.rst   |  70 +++++-
 3 files changed, 493 insertions(+), 10 deletions(-)
 create mode 100644 Documentation/arm64/sme.rst
Documentation/arm64/index.rst +1 -0
index 4f840bac083e..ae21f8118830 100644
@@ -21,6 +21,7 @@ ARM64 Architecture
     perf
     pointer-authentication
     silicon-errata
+    sme
     sve
     tagged-address-abi
     tagged-pointers
Documentation/arm64/sme.rst new file +432 -0

432 lines not on this page · raw message

Documentation/arm64/sve.rst +60 -10

139 lines not on this page · raw message

Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#35 lore raw

PATCH v11 7/40 arm64/sme: System register and exception syndrome definitions

In reply to Mark Brown

The arm64 Scalable Matrix Extension (SME) adds some new system registers, fields in existing system registers and exception syndromes. This patch adds definitions for these for use in future patches implementing support for this extension.

Since SME will be the first user of FEAT_HCX in the kernel also include the definitions for enumerating it and the HCRX system register it adds.

---
 arch/arm64/include/asm/esr.h     | 12 +++++-
 arch/arm64/include/asm/kvm_arm.h |  1 +
 arch/arm64/include/asm/sysreg.h  | 63 ++++++++++++++++++++++++++++++++
 arch/arm64/kernel/traps.c        |  1 +
 4 files changed, 76 insertions(+), 1 deletion(-)
arch/arm64/include/asm/esr.h +11 -1
index d52a0b269ee8..43872e0cfd1e 100644
@@ -37,7 +37,8 @@
 #define ESR_ELx_EC_ERET		(0x1a)	/* EL2 only */
 /* Unallocated EC: 0x1B */
 #define ESR_ELx_EC_FPAC		(0x1C)	/* EL1 and above */
-/* Unallocated EC: 0x1D - 0x1E */
+#define ESR_ELx_EC_SME		(0x1D)
+/* Unallocated EC: 0x1E */
 #define ESR_ELx_EC_IMP_DEF	(0x1f)	/* EL3 only */
 #define ESR_ELx_EC_IABT_LOW	(0x20)
 #define ESR_ELx_EC_IABT_CUR	(0x21)
@@ -327,6 +328,15 @@
 #define ESR_ELx_CP15_32_ISS_SYS_CNTFRQ	(ESR_ELx_CP15_32_ISS_SYS_VAL(0, 0, 14, 0) |\
 					 ESR_ELx_CP15_32_ISS_DIR_READ)
 
+/*
+ * ISS values for SME traps
+ */
+
+#define ESR_ELx_SME_ISS_SME_DISABLED	0
+#define ESR_ELx_SME_ISS_ILL		1
+#define ESR_ELx_SME_ISS_SM_DISABLED	2
+#define ESR_ELx_SME_ISS_ZA_DISABLED	3
+
 #ifndef __ASSEMBLY__
 #include <asm/types.h>
 
arch/arm64/include/asm/kvm_arm.h +1 -0
index 1767ded83888..13ae232ec4a1 100644
@@ -279,6 +279,7 @@
 #define CPTR_EL2_TCPAC	(1U << 31)
 #define CPTR_EL2_TAM	(1 << 30)
 #define CPTR_EL2_TTA	(1 << 20)
+#define CPTR_EL2_TSM	(1 << 12)
 #define CPTR_EL2_TFP	(1 << CPTR_EL2_TFP_SHIFT)
 #define CPTR_EL2_TZ	(1 << 8)
 #define CPTR_NVHE_EL2_RES1	0x000032ff /* known RES1 bits in CPTR_EL2 (nVHE) */
arch/arm64/include/asm/sysreg.h +63 -0

164 lines not on this page · raw message

arch/arm64/kernel/traps.c +1 -0
index 70fc42470f13..88effb25c399 100644
@@ -822,6 +822,7 @@ static const char *esr_class_str[] = {
 	[ESR_ELx_EC_SVE]		= "SVE",
 	[ESR_ELx_EC_ERET]		= "ERET/ERETAA/ERETAB",
 	[ESR_ELx_EC_FPAC]		= "FPAC",
+	[ESR_ELx_EC_SME]		= "SME",
 	[ESR_ELx_EC_IMP_DEF]		= "EL3 IMP DEF",
 	[ESR_ELx_EC_IABT_LOW]		= "IABT (lower EL)",
 	[ESR_ELx_EC_IABT_CUR]		= "IABT (current EL)",
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#37 lore raw

PATCH v11 8/40 arm64/sme: Manually encode SME instructions

In reply to Mark Brown

As with SVE rather than impose ambitious toolchain requirements for SME we manually encode the few instructions which we require in order to perform the work the kernel needs to do. The instructions used to save and restore context are provided as assembler macros while those for entering and leaving streaming mode are done in asm volatile blocks since they are expected to be used from C.

We could do the SMSTART and SMSTOP operations with read/modify/write cycles on SVCR but using the aliases provided for individual field accesses should be slightly faster. These instructions are aliases for MSR but since our minimum toolchain requirements are old enough to mean that we can't use the sX_X_cX_cX_X form and they always use xzr rather than taking a value like write_sysreg_s() wants we just use .inst.

---
 arch/arm64/include/asm/fpsimd.h       | 25 +++++++++++++
 arch/arm64/include/asm/fpsimdmacros.h | 53 +++++++++++++++++++++++++++
 2 files changed, 78 insertions(+)
arch/arm64/include/asm/fpsimd.h +25 -0
index cb24385e3632..c90f7f99a768 100644
@@ -249,6 +249,31 @@ static inline void sve_setup(void) { }
 
 #endif /* ! CONFIG_ARM64_SVE */
 
+#ifdef CONFIG_ARM64_SME
+
+static inline void sme_smstart_sm(void)
+{
+	asm volatile(".inst 0xd503437f");
+}
+
+static inline void sme_smstop_sm(void)
+{
+	asm volatile(".inst 0xd503427f");
+}
+
+static inline void sme_smstop(void)
+{
+	asm volatile(".inst 0xd503467f");
+}
+
+#else
+
+static inline void sme_smstart_sm(void) { }
+static inline void sme_smstop_sm(void) { }
+static inline void sme_smstop(void) { }
+
+#endif /* ! CONFIG_ARM64_SME */
+
 /* For use by EFI runtime services calls only */
 extern void __efi_fpsimd_begin(void);
 extern void __efi_fpsimd_end(void);
arch/arm64/include/asm/fpsimdmacros.h +53 -0

65 lines not on this page · raw message

Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#39 lore raw

PATCH v11 9/40 arm64/sme: Early CPU setup for SME

In reply to Mark Brown

SME requires similar setup to that for SVE: disable traps to EL2 and make sure that the maximum vector length is available to EL1, for SME we have two traps - one for SME itself and one for TPIDR2.

In addition since we currently make no active use of priority control for SCMUs we map all SME priorities lower ELs may configure to 0, the architecture specified minimum priority, to ensure that nothing we manage is able to configure itself to consume excessive resources. This will need to be revisited should there be a need to manage SME priorities at runtime.

---
 arch/arm64/include/asm/el2_setup.h | 64 ++++++++++++++++++++++++++++--
 1 file changed, 60 insertions(+), 4 deletions(-)
arch/arm64/include/asm/el2_setup.h +60 -4
index 3198acb2aad8..31f1a69c9dd2 100644
@@ -143,6 +143,50 @@
 .Lskip_sve_\@:
 .endm
 
+/* SME register access and priority mapping */
+.macro __init_el2_nvhe_sme
+	mrs	x1, id_aa64pfr1_el1
+	ubfx	x1, x1, #ID_AA64PFR1_SME_SHIFT, #4
+	cbz	x1, .Lskip_sme_\@
+
+	bic	x0, x0, #CPTR_EL2_TSM		// Also disable SME traps
+	msr	cptr_el2, x0			// Disable copro. traps to EL2
+	isb
+
+	mrs	x1, sctlr_el2
+	orr	x1, x1, #SCTLR_ELx_ENTP2	// Disable TPIDR2 traps
+	msr	sctlr_el2, x1
+	isb
+
+	mov	x1, #0				// SMCR controls
+
+	mrs_s	x2, SYS_ID_AA64SMFR0_EL1
+	ubfx	x2, x2, #ID_AA64SMFR0_FA64_SHIFT, #1 // Full FP in SM?
+	cbz	x2, .Lskip_sme_fa64_\@
+
+	orr	x1, x1, SMCR_ELx_FA64_MASK
+.Lskip_sme_fa64_\@:
+
+	orr	x1, x1, #SMCR_ELx_LEN_MASK	// Enable full SME vector
+	msr_s	SYS_SMCR_EL2, x1		// length for EL1.
+
+	mrs_s	x1, SYS_SMIDR_EL1		// Priority mapping supported?
+	ubfx    x1, x1, #SYS_SMIDR_EL1_SMPS_SHIFT, #1
+	cbz     x1, .Lskip_sme_\@
+
+	msr_s	SYS_SMPRIMAP_EL2, xzr		// Make all priorities equal
+
+	mrs	x1, id_aa64mmfr1_el1		// HCRX_EL2 present?
+	ubfx	x1, x1, #ID_AA64MMFR1_HCX_SHIFT, #4
+	cbz	x1, .Lskip_sme_\@
+
+	mrs_s	x1, SYS_HCRX_EL2
+	orr	x1, x1, #HCRX_EL2_SMPME_MASK	// Enable priority mapping
+	msr_s	SYS_HCRX_EL2, x1
+
+.Lskip_sme_\@:
+.endm
+
 /* Disable any fine grained traps */
 .macro __init_el2_fgt
 	mrs	x1, id_aa64mmfr0_el1
@@ -153,15 +197,26 @@
 	mrs	x1, id_aa64dfr0_el1
 	ubfx	x1, x1, #ID_AA64DFR0_PMSVER_SHIFT, #4
 	cmp	x1, #3
-	b.lt	.Lset_fgt_\@
+	b.lt	.Lset_debug_fgt_\@
 	/* Disable PMSNEVFR_EL1 read and write traps */
 	orr	x0, x0, #(1 << 62)
 
-.Lset_fgt_\@:
+.Lset_debug_fgt_\@:
 	msr_s	SYS_HDFGRTR_EL2, x0
 	msr_s	SYS_HDFGWTR_EL2, x0
-	msr_s	SYS_HFGRTR_EL2, xzr
-	msr_s	SYS_HFGWTR_EL2, xzr
+
+	mov	x0, xzr
+	mrs	x1, id_aa64pfr1_el1
+	ubfx	x1, x1, #ID_AA64PFR1_SME_SHIFT, #4
+	cbz	x1, .Lset_fgt_\@
+
+	/* Disable nVHE traps of TPIDR2 and SMPRI */
+	orr	x0, x0, #HFGxTR_EL2_nSMPRI_EL1_MASK
+	orr	x0, x0, #HFGxTR_EL2_nTPIDR2_EL0_MASK
+
+.Lset_fgt_\@:
+	msr_s	SYS_HFGRTR_EL2, x0
+	msr_s	SYS_HFGWTR_EL2, x0
 	msr_s	SYS_HFGITR_EL2, xzr
 
 	mrs	x1, id_aa64pfr0_el1		// AMU traps UNDEF without AMU
@@ -196,6 +251,7 @@
 	__init_el2_nvhe_idregs
 	__init_el2_nvhe_cptr
 	__init_el2_nvhe_sve
+	__init_el2_nvhe_sme
 	__init_el2_fgt
 	__init_el2_nvhe_prepare_eret
 .endm
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#41 lore raw

PATCH v11 10/40 arm64/sme: Basic enumeration support

In reply to Mark Brown

This patch introduces basic cpufeature support for discovering the presence of the Scalable Matrix Extension.

---
 Documentation/arm64/elf_hwcaps.rst  | 33 +++++++++++++++++
 arch/arm64/include/asm/cpu.h        |  1 +
 arch/arm64/include/asm/cpufeature.h | 12 ++++++
 arch/arm64/include/asm/fpsimd.h     |  2 +
 arch/arm64/include/asm/hwcap.h      |  8 ++++
 arch/arm64/include/uapi/asm/hwcap.h |  8 ++++
 arch/arm64/kernel/cpufeature.c      | 57 +++++++++++++++++++++++++++++
 arch/arm64/kernel/cpuinfo.c         |  9 +++++
 arch/arm64/kernel/fpsimd.c          | 30 +++++++++++++++
 arch/arm64/tools/cpucaps            |  2 +
 10 files changed, 162 insertions(+)
Documentation/arm64/elf_hwcaps.rst +33 -0
index b72ff17d600a..5626cf208000 100644
@@ -259,6 +259,39 @@ HWCAP2_RPRES
 
     Functionality implied by ID_AA64ISAR2_EL1.RPRES == 0b0001.
 
+HWCAP2_SME
+
+    Functionality implied by ID_AA64PFR1_EL1.SME == 0b0001, as described
+    by Documentation/arm64/sme.rst.
+
+HWCAP2_SME_I16I64
+
+    Functionality implied by ID_AA64SMFR0_EL1.I16I64 == 0b1111.
+
+HWCAP2_SME_F64F64
+
+    Functionality implied by ID_AA64SMFR0_EL1.F64F64 == 0b1.
+
+HWCAP2_SME_I8I32
+
+    Functionality implied by ID_AA64SMFR0_EL1.I8I32 == 0b1111.
+
+HWCAP2_SME_F16F32
+
+    Functionality implied by ID_AA64SMFR0_EL1.F16F32 == 0b1.
+
+HWCAP2_SME_B16F32
+
+    Functionality implied by ID_AA64SMFR0_EL1.B16F32 == 0b1.
+
+HWCAP2_SME_F32F32
+
+    Functionality implied by ID_AA64SMFR0_EL1.F32F32 == 0b1.
+
+HWCAP2_SME_FA64
+
+    Functionality implied by ID_AA64SMFR0_EL1.FA64 == 0b1.
+
 4. Unused AT_HWCAP bits
 -----------------------
 
arch/arm64/include/asm/cpu.h +1 -0
index a58e366f0b07..d08062bcb9c1 100644
@@ -58,6 +58,7 @@ struct cpuinfo_arm64 {
 	u64		reg_id_aa64pfr0;
 	u64		reg_id_aa64pfr1;
 	u64		reg_id_aa64zfr0;
+	u64		reg_id_aa64smfr0;
 
 	struct cpuinfo_32bit	aarch32;
 
arch/arm64/include/asm/cpufeature.h +12 -0
index 2728abd9cae4..f93b1442143f 100644
@@ -728,6 +728,18 @@ static __always_inline bool system_supports_sve(void)
 		cpus_have_const_cap(ARM64_SVE);
 }
 
+static __always_inline bool system_supports_sme(void)
+{
+	return IS_ENABLED(CONFIG_ARM64_SME) &&
+		cpus_have_const_cap(ARM64_SME);
+}
+
+static __always_inline bool system_supports_fa64(void)
+{
+	return IS_ENABLED(CONFIG_ARM64_SME) &&
+		cpus_have_const_cap(ARM64_SME_FA64);
+}
+
 static __always_inline bool system_supports_cnp(void)
 {
 	return IS_ENABLED(CONFIG_ARM64_CNP) &&
arch/arm64/include/asm/fpsimd.h +2 -0
index c90f7f99a768..6b7eb6f2cecd 100644
@@ -74,6 +74,8 @@ extern void sve_set_vq(unsigned long vq_minus_1);
 
 struct arm64_cpu_capabilities;
 extern void sve_kernel_enable(const struct arm64_cpu_capabilities *__unused);
+extern void sme_kernel_enable(const struct arm64_cpu_capabilities *__unused);
+extern void fa64_kernel_enable(const struct arm64_cpu_capabilities *__unused);
 
 extern u64 read_zcr_features(void);
 
arch/arm64/include/asm/hwcap.h +8 -0
index f68fbb207473..76d9999527c5 100644
@@ -108,6 +108,14 @@
 #define KERNEL_HWCAP_ECV		__khwcap2_feature(ECV)
 #define KERNEL_HWCAP_AFP		__khwcap2_feature(AFP)
 #define KERNEL_HWCAP_RPRES		__khwcap2_feature(RPRES)
+#define KERNEL_HWCAP_SME		__khwcap2_feature(SME)
+#define KERNEL_HWCAP_SME_I16I64		__khwcap2_feature(SME_I16I64)
+#define KERNEL_HWCAP_SME_F64F64		__khwcap2_feature(SME_F64F64)
+#define KERNEL_HWCAP_SME_I8I32		__khwcap2_feature(SME_I8I32)
+#define KERNEL_HWCAP_SME_F16F32		__khwcap2_feature(SME_F16F32)
+#define KERNEL_HWCAP_SME_B16F32		__khwcap2_feature(SME_B16F32)
+#define KERNEL_HWCAP_SME_F32F32		__khwcap2_feature(SME_F32F32)
+#define KERNEL_HWCAP_SME_FA64		__khwcap2_feature(SME_FA64)
 
 /*
  * This yields a mask that user programs can use to figure out what
arch/arm64/include/uapi/asm/hwcap.h +8 -0
index f03731847d9d..60de5626f8fb 100644
@@ -78,5 +78,13 @@
 #define HWCAP2_ECV		(1 << 19)
 #define HWCAP2_AFP		(1 << 20)
 #define HWCAP2_RPRES		(1 << 21)
+#define HWCAP2_SME		(1 << 22)
+#define HWCAP2_SME_I16I64	(1 << 23)
+#define HWCAP2_SME_F64F64	(1 << 24)
+#define HWCAP2_SME_I8I32	(1 << 25)
+#define HWCAP2_SME_F16F32	(1 << 26)
+#define HWCAP2_SME_B16F32	(1 << 27)
+#define HWCAP2_SME_F32F32	(1 << 28)
+#define HWCAP2_SME_FA64		(1 << 29)
 
 #endif /* _UAPI__ASM_HWCAP_H */
arch/arm64/kernel/cpufeature.c +57 -0

93 lines not on this page · raw message

arch/arm64/kernel/cpuinfo.c +9 -0
index 591c18a889a5..33ec182e872e 100644
@@ -97,6 +97,14 @@ static const char *const hwcap_str[] = {
 	[KERNEL_HWCAP_ECV]		= "ecv",
 	[KERNEL_HWCAP_AFP]		= "afp",
 	[KERNEL_HWCAP_RPRES]		= "rpres",
+	[KERNEL_HWCAP_SME]		= "sme",
+	[KERNEL_HWCAP_SME_I16I64]	= "smei16i64",
+	[KERNEL_HWCAP_SME_F64F64]	= "smef64f64",
+	[KERNEL_HWCAP_SME_I8I32]	= "smei8i32",
+	[KERNEL_HWCAP_SME_F16F32]	= "smef16f32",
+	[KERNEL_HWCAP_SME_B16F32]	= "smeb16f32",
+	[KERNEL_HWCAP_SME_F32F32]	= "smef32f32",
+	[KERNEL_HWCAP_SME_FA64]		= "smefa64",
 };
 
 #ifdef CONFIG_COMPAT
@@ -400,6 +408,7 @@ static void __cpuinfo_store_cpu(struct cpuinfo_arm64 *info)
 	info->reg_id_aa64pfr0 = read_cpuid(ID_AA64PFR0_EL1);
 	info->reg_id_aa64pfr1 = read_cpuid(ID_AA64PFR1_EL1);
 	info->reg_id_aa64zfr0 = read_cpuid(ID_AA64ZFR0_EL1);
+	info->reg_id_aa64smfr0 = read_cpuid(ID_AA64SMFR0_EL1);
 
 	if (id_aa64pfr1_mte(info->reg_id_aa64pfr1))
 		info->reg_gmid = read_cpuid(GMID_EL1);
arch/arm64/kernel/fpsimd.c +30 -0
index 5280e098cfb5..576490be3c2b 100644
@@ -987,6 +987,32 @@ void fpsimd_release_task(struct task_struct *dead_task)
 
 #endif /* CONFIG_ARM64_SVE */
 
+#ifdef CONFIG_ARM64_SME
+
+void sme_kernel_enable(const struct arm64_cpu_capabilities *__always_unused p)
+{
+	/* Set priority for all PEs to architecturally defined minimum */
+	write_sysreg_s(read_sysreg_s(SYS_SMPRI_EL1) & ~SMPRI_EL1_PRIORITY_MASK,
+		       SYS_SMPRI_EL1);
+
+	/* Allow SME in kernel */
+	write_sysreg(read_sysreg(CPACR_EL1) | CPACR_EL1_SMEN_EL1EN, CPACR_EL1);
+	isb();
+}
+
+/*
+ * This must be called after sme_kernel_enable(), we rely on the
+ * feature table being sorted to ensure this.
+ */
+void fa64_kernel_enable(const struct arm64_cpu_capabilities *__always_unused p)
+{
+	/* Allow use of FA64 */
+	write_sysreg_s(read_sysreg_s(SYS_SMCR_EL1) | SMCR_ELx_FA64_MASK,
+		       SYS_SMCR_EL1);
+}
+
+#endif /* CONFIG_ARM64_SVE */
+
 /*
  * Trapped SVE access
  *
@@ -1532,6 +1558,10 @@ static int __init fpsimd_init(void)
 	if (!cpu_have_named_feature(ASIMD))
 		pr_notice("Advanced SIMD is not implemented\n");
 
+
+	if (cpu_have_named_feature(SME) && !cpu_have_named_feature(SVE))
+		pr_notice("SME is implemented but not SVE\n");
+
 	return sve_sysctl_init();
 }
 core_initcall(fpsimd_init);
arch/arm64/tools/cpucaps +2 -0
index 9c65b1e25a96..0a602525bda6 100644
@@ -41,6 +41,8 @@ KVM_PROTECTED_MODE
 MISMATCHED_CACHE_TYPE
 MTE
 MTE_ASYMM
+SME
+SME_FA64
 SPECTRE_V2
 SPECTRE_V3A
 SPECTRE_V4
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#49 lore raw

PATCH v11 11/40 arm64/sme: Identify supported SME vector lengths at boot

In reply to Mark Brown

The vector lengths used for SME are controlled through a similar set of registers to those for SVE and enumerated using a similar algorithm with some slight differences due to the fact that unlike SVE there are no restrictions on which combinations of vector lengths can be supported nor any mandatory vector lengths which must be implemented. Add a new vector type and implement support for enumerating it.

One slightly awkward feature is that we need to read the current vector length using a different instruction (or enter streaming mode which would have the same issue and be higher cost). Rather than add an ops structure we add special cases directly in the otherwise generic vec_probe_vqs() function, this is a bit inelegant but it's the only place where this is an issue.

---
 arch/arm64/include/asm/cpu.h        |   3 +
 arch/arm64/include/asm/cpufeature.h |   7 ++
 arch/arm64/include/asm/fpsimd.h     |  26 ++++++
 arch/arm64/include/asm/processor.h  |   1 +
 arch/arm64/kernel/cpufeature.c      |  49 +++++++++++
 arch/arm64/kernel/cpuinfo.c         |   4 +
 arch/arm64/kernel/entry-fpsimd.S    |   9 ++
 arch/arm64/kernel/fpsimd.c          | 123 +++++++++++++++++++++++++++-
 8 files changed, 220 insertions(+), 2 deletions(-)
arch/arm64/include/asm/cpu.h +3 -0
index d08062bcb9c1..550e1fc4ae6c 100644
@@ -64,6 +64,9 @@ struct cpuinfo_arm64 {
 
 	/* pseudo-ZCR for recording maximum ZCR_EL1 LEN value: */
 	u64		reg_zcr;
+
+	/* pseudo-SMCR for recording maximum ZCR_EL1 LEN value: */
+	u64		reg_smcr;
 };
 
 DECLARE_PER_CPU(struct cpuinfo_arm64, cpu_data);
arch/arm64/include/asm/cpufeature.h +7 -0
index f93b1442143f..9d36035acce3 100644
@@ -620,6 +620,13 @@ static inline bool id_aa64pfr0_sve(u64 pfr0)
 	return val > 0;
 }
 
+static inline bool id_aa64pfr1_sme(u64 pfr1)
+{
+	u32 val = cpuid_feature_extract_unsigned_field(pfr1, ID_AA64PFR1_SME_SHIFT);
+
+	return val > 0;
+}
+
 static inline bool id_aa64pfr1_mte(u64 pfr1)
 {
 	u32 val = cpuid_feature_extract_unsigned_field(pfr1, ID_AA64PFR1_MTE_SHIFT);
arch/arm64/include/asm/fpsimd.h +26 -0
index 6b7eb6f2cecd..8cb99b6fe565 100644
@@ -78,6 +78,7 @@ extern void sme_kernel_enable(const struct arm64_cpu_capabilities *__unused);
 extern void fa64_kernel_enable(const struct arm64_cpu_capabilities *__unused);
 
 extern u64 read_zcr_features(void);
+extern u64 read_smcr_features(void);
 
 /*
  * Helpers to translate bit indices in sve_vq_map to VQ values (and
@@ -172,6 +173,12 @@ static inline void write_vl(enum vec_type type, u64 val)
 		tmp = read_sysreg_s(SYS_ZCR_EL1) & ~ZCR_ELx_LEN_MASK;
 		write_sysreg_s(tmp | val, SYS_ZCR_EL1);
 		break;
+#endif
+#ifdef CONFIG_ARM64_SME
+	case ARM64_VEC_SME:
+		tmp = read_sysreg_s(SYS_SMCR_EL1) & ~SMCR_ELx_LEN_MASK;
+		write_sysreg_s(tmp | val, SYS_SMCR_EL1);
+		break;
 #endif
 	default:
 		WARN_ON_ONCE(1);
@@ -268,12 +275,31 @@ static inline void sme_smstop(void)
 	asm volatile(".inst 0xd503467f");
 }
 
+extern void __init sme_setup(void);
+
+static inline int sme_max_vl(void)
+{
+	return vec_max_vl(ARM64_VEC_SME);
+}
+
+static inline int sme_max_virtualisable_vl(void)
+{
+	return vec_max_virtualisable_vl(ARM64_VEC_SME);
+}
+
+extern unsigned int sme_get_vl(void);
+
 #else
 
 static inline void sme_smstart_sm(void) { }
 static inline void sme_smstop_sm(void) { }
 static inline void sme_smstop(void) { }
 
+static inline void sme_setup(void) { }
+static inline unsigned int sme_get_vl(void) { return 0; }
+static inline int sme_max_vl(void) { return 0; }
+static inline int sme_max_virtualisable_vl(void) { return 0; }
+
 #endif /* ! CONFIG_ARM64_SME */
 
 /* For use by EFI runtime services calls only */
arch/arm64/include/asm/processor.h +1 -0
index 6f41b65f9962..df68f0fb0ded 100644
@@ -117,6 +117,7 @@ struct debug_info {
 
 enum vec_type {
 	ARM64_VEC_SVE = 0,
+	ARM64_VEC_SME,
 	ARM64_VEC_MAX,
 };
 
arch/arm64/kernel/cpufeature.c +49 -0

97 lines not on this page · raw message

arch/arm64/kernel/cpuinfo.c +4 -0
index 33ec182e872e..72dc155719b0 100644
@@ -420,6 +420,10 @@ static void __cpuinfo_store_cpu(struct cpuinfo_arm64 *info)
 	    id_aa64pfr0_sve(info->reg_id_aa64pfr0))
 		info->reg_zcr = read_zcr_features();
 
+	if (IS_ENABLED(CONFIG_ARM64_SME) &&
+	    id_aa64pfr1_sme(info->reg_id_aa64pfr1))
+		info->reg_smcr = read_smcr_features();
+
 	cpuinfo_detect_icache_policy(info);
 }
 
arch/arm64/kernel/entry-fpsimd.S +9 -0
index dc242e269f9a..deee5f01462e 100644
@@ -86,3 +86,12 @@ SYM_FUNC_START(sve_flush_live)
 SYM_FUNC_END(sve_flush_live)
 
 #endif /* CONFIG_ARM64_SVE */
+
+#ifdef CONFIG_ARM64_SME
+
+SYM_FUNC_START(sme_get_vl)
+	_sme_rdsvl	0, 1
+	ret
+SYM_FUNC_END(sme_get_vl)
+
+#endif /* CONFIG_ARM64_SME */
arch/arm64/kernel/fpsimd.c +121 -2

153 lines not on this page · raw message

Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#52 lore raw

PATCH v11 12/40 arm64/sme: Implement sysctl to set the default vector length

In reply to Mark Brown

As for SVE provide a sysctl which allows the default SME vector length to be configured.

---
 arch/arm64/kernel/fpsimd.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
arch/arm64/kernel/fpsimd.c +28 -1
index 3fb2167f8af7..841b9609342f 100644
@@ -483,6 +483,30 @@ static int __init sve_sysctl_init(void)
 static int __init sve_sysctl_init(void) { return 0; }
 #endif /* ! (CONFIG_ARM64_SVE && CONFIG_SYSCTL) */
 
+#if defined(CONFIG_ARM64_SME) && defined(CONFIG_SYSCTL)
+static struct ctl_table sme_default_vl_table[] = {
+	{
+		.procname	= "sme_default_vector_length",
+		.mode		= 0644,
+		.proc_handler	= vec_proc_do_default_vl,
+		.extra1		= &vl_info[ARM64_VEC_SME],
+	},
+	{ }
+};
+
+static int __init sme_sysctl_init(void)
+{
+	if (system_supports_sme())
+		if (!register_sysctl("abi", sme_default_vl_table))
+			return -EINVAL;
+
+	return 0;
+}
+
+#else /* ! (CONFIG_ARM64_SME && CONFIG_SYSCTL) */
+static int __init sme_sysctl_init(void) { return 0; }
+#endif /* ! (CONFIG_ARM64_SME && CONFIG_SYSCTL) */
+
 #define ZREG(sve_state, vq, n) ((char *)(sve_state) +		\
 	(SVE_SIG_ZREG_OFFSET(vq, n) - SVE_SIG_REGS_OFFSET))
 
@@ -1681,6 +1705,9 @@ static int __init fpsimd_init(void)
 	if (cpu_have_named_feature(SME) && !cpu_have_named_feature(SVE))
 		pr_notice("SME is implemented but not SVE\n");
 
-	return sve_sysctl_init();
+	sve_sysctl_init();
+	sme_sysctl_init();
+
+	return 0;
 }
 core_initcall(fpsimd_init);
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#54 lore raw

PATCH v11 13/40 arm64/sme: Implement vector length configuration prctl()s

In reply to Mark Brown

As for SVE provide a prctl() interface which allows processes to configure their SME vector length.

---
 arch/arm64/include/asm/fpsimd.h      |  4 ++++
 arch/arm64/include/asm/processor.h   |  4 +++-
 arch/arm64/include/asm/thread_info.h |  1 +
 arch/arm64/kernel/fpsimd.c           | 32 ++++++++++++++++++++++++++++
 include/uapi/linux/prctl.h           |  9 ++++++++
 kernel/sys.c                         | 12 +++++++++++
 6 files changed, 61 insertions(+), 1 deletion(-)
arch/arm64/include/asm/fpsimd.h +4 -0
index 8cb99b6fe565..babf944e7c0c 100644
@@ -288,6 +288,8 @@ static inline int sme_max_virtualisable_vl(void)
 }
 
 extern unsigned int sme_get_vl(void);
+extern int sme_set_current_vl(unsigned long arg);
+extern int sme_get_current_vl(void);
 
 #else
 
@@ -299,6 +301,8 @@ static inline void sme_setup(void) { }
 static inline unsigned int sme_get_vl(void) { return 0; }
 static inline int sme_max_vl(void) { return 0; }
 static inline int sme_max_virtualisable_vl(void) { return 0; }
+static inline int sme_set_current_vl(unsigned long arg) { return -EINVAL; }
+static inline int sme_get_current_vl(void) { return -EINVAL; }
 
 #endif /* ! CONFIG_ARM64_SME */
 
arch/arm64/include/asm/processor.h +3 -1
index df68f0fb0ded..f2c2ebd440e2 100644
@@ -354,9 +354,11 @@ extern void __init minsigstksz_setup(void);
  */
 #include <asm/fpsimd.h>
 
-/* Userspace interface for PR_SVE_{SET,GET}_VL prctl()s: */
+/* Userspace interface for PR_S[MV]E_{SET,GET}_VL prctl()s: */
 #define SVE_SET_VL(arg)	sve_set_current_vl(arg)
 #define SVE_GET_VL()	sve_get_current_vl()
+#define SME_SET_VL(arg)	sme_set_current_vl(arg)
+#define SME_GET_VL()	sme_get_current_vl()
 
 /* PR_PAC_RESET_KEYS prctl */
 #define PAC_RESET_KEYS(tsk, arg)	ptrauth_prctl_reset_keys(tsk, arg)
arch/arm64/include/asm/thread_info.h +1 -0
index e1317b7c4525..4e6b58dcd6f9 100644
@@ -82,6 +82,7 @@ int arch_dup_task_struct(struct task_struct *dst,
 #define TIF_SVE_VL_INHERIT	24	/* Inherit SVE vl_onexec across exec */
 #define TIF_SSBD		25	/* Wants SSB mitigation */
 #define TIF_TAGGED_ADDR		26	/* Allow tagged user addresses */
+#define TIF_SME_VL_INHERIT	28	/* Inherit SME vl_onexec across exec */
 
 #define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
 #define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
arch/arm64/kernel/fpsimd.c +32 -0
index 841b9609342f..1edb3996f9cf 100644
@@ -149,6 +149,8 @@ static unsigned int vec_vl_inherit_flag(enum vec_type type)
 	switch (type) {
 	case ARM64_VEC_SVE:
 		return TIF_SVE_VL_INHERIT;
+	case ARM64_VEC_SME:
+		return TIF_SME_VL_INHERIT;
 	default:
 		WARN_ON_ONCE(1);
 		return 0;
@@ -801,6 +803,36 @@ int sve_get_current_vl(void)
 	return vec_prctl_status(ARM64_VEC_SVE, 0);
 }
 
+#ifdef CONFIG_ARM64_SME
+/* PR_SME_SET_VL */
+int sme_set_current_vl(unsigned long arg)
+{
+	unsigned long vl, flags;
+	int ret;
+
+	vl = arg & PR_SME_VL_LEN_MASK;
+	flags = arg & ~vl;
+
+	if (!system_supports_sme() || is_compat_task())
+		return -EINVAL;
+
+	ret = vec_set_vector_length(current, ARM64_VEC_SME, vl, flags);
+	if (ret)
+		return ret;
+
+	return vec_prctl_status(ARM64_VEC_SME, flags);
+}
+
+/* PR_SME_GET_VL */
+int sme_get_current_vl(void)
+{
+	if (!system_supports_sme() || is_compat_task())
+		return -EINVAL;
+
+	return vec_prctl_status(ARM64_VEC_SME, 0);
+}
+#endif /* CONFIG_ARM64_SME */
+
 static void vec_probe_vqs(struct vl_info *info,
 			  DECLARE_BITMAP(map, SVE_VQ_MAX))
 {
include/uapi/linux/prctl.h +9 -0
index e998764f0262..a5e06dcbba13 100644
@@ -272,6 +272,15 @@ struct prctl_mm_map {
 # define PR_SCHED_CORE_SCOPE_THREAD_GROUP	1
 # define PR_SCHED_CORE_SCOPE_PROCESS_GROUP	2
 
+/* arm64 Scalable Matrix Extension controls */
+/* Flag values must be in sync with SVE versions */
+#define PR_SME_SET_VL			63	/* set task vector length */
+# define PR_SME_SET_VL_ONEXEC		(1 << 18) /* defer effect until exec */
+#define PR_SME_GET_VL			64	/* get task vector length */
+/* Bits common to PR_SME_SET_VL and PR_SME_GET_VL */
+# define PR_SME_VL_LEN_MASK		0xffff
+# define PR_SME_VL_INHERIT		(1 << 17) /* inherit across exec */
+
 #define PR_SET_VMA		0x53564d41
 # define PR_SET_VMA_ANON_NAME		0
 
kernel/sys.c +12 -0
index ecc4cf019242..5cd4fffc7cd0 100644
@@ -116,6 +116,12 @@
 #ifndef SVE_GET_VL
 # define SVE_GET_VL()		(-EINVAL)
 #endif
+#ifndef SME_SET_VL
+# define SME_SET_VL(a)		(-EINVAL)
+#endif
+#ifndef SME_GET_VL
+# define SME_GET_VL()		(-EINVAL)
+#endif
 #ifndef PAC_RESET_KEYS
 # define PAC_RESET_KEYS(a, b)	(-EINVAL)
 #endif
@@ -2523,6 +2529,12 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 	case PR_SVE_GET_VL:
 		error = SVE_GET_VL();
 		break;
+	case PR_SME_SET_VL:
+		error = SME_SET_VL(arg2);
+		break;
+	case PR_SME_GET_VL:
+		error = SME_GET_VL();
+		break;
 	case PR_GET_SPECULATION_CTRL:
 		if (arg3 || arg4 || arg5)
 			return -EINVAL;
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#56 lore raw

PATCH v11 14/40 arm64/sme: Implement support for TPIDR2

In reply to Mark Brown

The Scalable Matrix Extension introduces support for a new thread specific data register TPIDR2 intended for use by libc. The kernel must save the value of TPIDR2 on context switch and should ensure that all new threads start off with a default value of 0. Add a field to the thread_struct to store TPIDR2 and context switch it with the other thread specific data.

In case there are future extensions which also use TPIDR2 we introduce system_supports_tpidr2() and use that rather than system_supports_sme() for TPIDR2 handling.

---
 arch/arm64/include/asm/cpufeature.h |  5 +++++
 arch/arm64/include/asm/processor.h  |  1 +
 arch/arm64/kernel/fpsimd.c          |  4 ++++
 arch/arm64/kernel/process.c         | 14 ++++++++++++--
 4 files changed, 22 insertions(+), 2 deletions(-)
arch/arm64/include/asm/cpufeature.h +5 -0
index 9d36035acce3..12252352d2ee 100644
@@ -747,6 +747,11 @@ static __always_inline bool system_supports_fa64(void)
 		cpus_have_const_cap(ARM64_SME_FA64);
 }
 
+static __always_inline bool system_supports_tpidr2(void)
+{
+	return system_supports_sme();
+}
+
 static __always_inline bool system_supports_cnp(void)
 {
 	return IS_ENABLED(CONFIG_ARM64_CNP) &&
arch/arm64/include/asm/processor.h +1 -0
index f2c2ebd440e2..008a1767ebff 100644
@@ -168,6 +168,7 @@ struct thread_struct {
 	u64			mte_ctrl;
 #endif
 	u64			sctlr_user;
+	u64			tpidr2_el0;
 };
 
 static inline unsigned int thread_get_vl(struct thread_struct *thread,
arch/arm64/kernel/fpsimd.c +4 -0
index 1edb3996f9cf..40ef89120774 100644
@@ -1092,6 +1092,10 @@ void sme_kernel_enable(const struct arm64_cpu_capabilities *__always_unused p)
 	/* Allow SME in kernel */
 	write_sysreg(read_sysreg(CPACR_EL1) | CPACR_EL1_SMEN_EL1EN, CPACR_EL1);
 	isb();
+
+	/* Allow EL0 to access TPIDR2 */
+	write_sysreg(read_sysreg(SCTLR_EL1) | SCTLR_ELx_ENTP2, SCTLR_EL1);
+	isb();
 }
 
 /*
arch/arm64/kernel/process.c +12 -2
index 5369e649fa79..e69a3dcdb0d9 100644
@@ -250,6 +250,8 @@ void show_regs(struct pt_regs *regs)
 static void tls_thread_flush(void)
 {
 	write_sysreg(0, tpidr_el0);
+	if (system_supports_tpidr2())
+		write_sysreg_s(0, SYS_TPIDR2_EL0);
 
 	if (is_compat_task()) {
 		current->thread.uw.tp_value = 0;
@@ -343,6 +345,8 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start,
 		 * out-of-sync with the saved value.
 		 */
 		*task_user_tls(p) = read_sysreg(tpidr_el0);
+		if (system_supports_tpidr2())
+			p->thread.tpidr2_el0 = read_sysreg_s(SYS_TPIDR2_EL0);
 
 		if (stack_start) {
 			if (is_compat_thread(task_thread_info(p)))
@@ -353,10 +357,12 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start,
 
 		/*
 		 * If a TLS pointer was passed to clone, use it for the new
-		 * thread.
+		 * thread.  We also reset TPIDR2 if it's in use.
 		 */
-		if (clone_flags & CLONE_SETTLS)
+		if (clone_flags & CLONE_SETTLS) {
 			p->thread.uw.tp_value = tls;
+			p->thread.tpidr2_el0 = 0;
+		}
 	} else {
 		/*
 		 * A kthread has no context to ERET to, so ensure any buggy
@@ -387,6 +393,8 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start,
 void tls_preserve_current_state(void)
 {
 	*task_user_tls(current) = read_sysreg(tpidr_el0);
+	if (system_supports_tpidr2() && !is_compat_task())
+		current->thread.tpidr2_el0 = read_sysreg_s(SYS_TPIDR2_EL0);
 }
 
 static void tls_thread_switch(struct task_struct *next)
@@ -399,6 +407,8 @@ static void tls_thread_switch(struct task_struct *next)
 		write_sysreg(0, tpidrro_el0);
 
 	write_sysreg(*task_user_tls(next), tpidr_el0);
+	if (system_supports_tpidr2())
+		write_sysreg_s(next->thread.tpidr2_el0, SYS_TPIDR2_EL0);
 }
 
 /*
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#58 lore raw

PATCH v11 15/40 arm64/sme: Implement SVCR context switching

In reply to Mark Brown

In SME the use of both streaming SVE mode and ZA are tracked through PSTATE.SM and PSTATE.ZA, visible through the system register SVCR. In order to context switch the floating point state for SME we need to context switch the contents of this register as part of context switching the floating point state.

Since changing the vector length exits streaming SVE mode and disables ZA we also make sure we update SVCR appropriately when setting vector length, and similarly ensure that new threads have streaming SVE mode and ZA disabled.

---
 arch/arm64/include/asm/fpsimd.h      |  3 ++-
 arch/arm64/include/asm/processor.h   |  1 +
 arch/arm64/include/asm/thread_info.h |  1 +
 arch/arm64/kernel/fpsimd.c           | 18 +++++++++++++++++-
 arch/arm64/kernel/process.c          |  2 ++
 arch/arm64/kvm/fpsimd.c              |  4 ++++
 6 files changed, 27 insertions(+), 2 deletions(-)
arch/arm64/include/asm/fpsimd.h +2 -1
index babf944e7c0c..d1bae65d3dba 100644
@@ -46,7 +46,8 @@ extern void fpsimd_restore_current_state(void);
 extern void fpsimd_update_current_state(struct user_fpsimd_state const *state);
 
 extern void fpsimd_bind_state_to_cpu(struct user_fpsimd_state *state,
-				     void *sve_state, unsigned int sve_vl);
+				     void *sve_state, unsigned int sve_vl,
+				     u64 *svcr);
 
 extern void fpsimd_flush_task_state(struct task_struct *target);
 extern void fpsimd_save_and_flush_cpu_state(void);
arch/arm64/include/asm/processor.h +1 -0
index 008a1767ebff..7e08a4d48c24 100644
@@ -168,6 +168,7 @@ struct thread_struct {
 	u64			mte_ctrl;
 #endif
 	u64			sctlr_user;
+	u64			svcr;
 	u64			tpidr2_el0;
 };
 
arch/arm64/include/asm/thread_info.h +1 -0
index 4e6b58dcd6f9..848739c15de8 100644
@@ -82,6 +82,7 @@ int arch_dup_task_struct(struct task_struct *dst,
 #define TIF_SVE_VL_INHERIT	24	/* Inherit SVE vl_onexec across exec */
 #define TIF_SSBD		25	/* Wants SSB mitigation */
 #define TIF_TAGGED_ADDR		26	/* Allow tagged user addresses */
+#define TIF_SME			27	/* SME in use */
 #define TIF_SME_VL_INHERIT	28	/* Inherit SME vl_onexec across exec */
 
 #define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
arch/arm64/kernel/fpsimd.c +17 -1
index 40ef89120774..a1918b71d335 100644
@@ -121,6 +121,7 @@
 struct fpsimd_last_state_struct {
 	struct user_fpsimd_state *st;
 	void *sve_state;
+	u64 *svcr;
 	unsigned int sve_vl;
 };
 
@@ -359,6 +360,9 @@ static void task_fpsimd_load(void)
 	WARN_ON(!system_supports_fpsimd());
 	WARN_ON(!have_cpu_fpsimd_context());
 
+	if (IS_ENABLED(CONFIG_ARM64_SME) && test_thread_flag(TIF_SME))
+		write_sysreg_s(current->thread.svcr, SYS_SVCR_EL0);
+
 	if (IS_ENABLED(CONFIG_ARM64_SVE) && test_thread_flag(TIF_SVE)) {
 		sve_set_vq(sve_vq_from_vl(task_get_sve_vl(current)) - 1);
 		sve_load_state(sve_pffr(&current->thread),
@@ -384,6 +388,12 @@ static void fpsimd_save(void)
 	if (test_thread_flag(TIF_FOREIGN_FPSTATE))
 		return;
 
+	if (IS_ENABLED(CONFIG_ARM64_SME) &&
+	    test_thread_flag(TIF_SME)) {
+		u64 *svcr = last->svcr;
+		*svcr = read_sysreg_s(SYS_SVCR_EL0);
+	}
+
 	if (IS_ENABLED(CONFIG_ARM64_SVE) &&
 	    test_thread_flag(TIF_SVE)) {
 		if (WARN_ON(sve_get_vl() != last->sve_vl)) {
@@ -735,6 +745,10 @@ int vec_set_vector_length(struct task_struct *task, enum vec_type type,
 	if (test_and_clear_tsk_thread_flag(task, TIF_SVE))
 		sve_to_fpsimd(task);
 
+	if (system_supports_sme() && type == ARM64_VEC_SME)
+		task->thread.svcr &= ~(SYS_SVCR_EL0_SM_MASK |
+				       SYS_SVCR_EL0_ZA_MASK);
+
 	if (task == current)
 		put_cpu_fpsimd_context();
 
@@ -1398,6 +1412,7 @@ static void fpsimd_bind_task_to_cpu(void)
 	last->st = &current->thread.uw.fpsimd_state;
 	last->sve_state = current->thread.sve_state;
 	last->sve_vl = task_get_sve_vl(current);
+	last->svcr = &current->thread.svcr;
 	current->thread.fpsimd_cpu = smp_processor_id();
 
 	if (system_supports_sve()) {
@@ -1412,7 +1427,7 @@ static void fpsimd_bind_task_to_cpu(void)
 }
 
 void fpsimd_bind_state_to_cpu(struct user_fpsimd_state *st, void *sve_state,
-			      unsigned int sve_vl)
+			      unsigned int sve_vl, u64 *svcr)
 {
 	struct fpsimd_last_state_struct *last =
 		this_cpu_ptr(&fpsimd_last_state);
@@ -1421,6 +1436,7 @@ void fpsimd_bind_state_to_cpu(struct user_fpsimd_state *st, void *sve_state,
 	WARN_ON(!in_softirq() && !irqs_disabled());
 
 	last->st = st;
+	last->svcr = svcr;
 	last->sve_state = sve_state;
 	last->sve_vl = sve_vl;
 }
arch/arm64/kernel/process.c +2 -0
index e69a3dcdb0d9..f2d32a29641c 100644
@@ -310,6 +310,8 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
 	dst->thread.sve_state = NULL;
 	clear_tsk_thread_flag(dst, TIF_SVE);
 
+	dst->thread.svcr = 0;
+
 	/* clear any pending asynchronous tag fault raised by the parent */
 	clear_tsk_thread_flag(dst, TIF_MTE_ASYNC_FAULT);
 
arch/arm64/kvm/fpsimd.c +4 -0
index 2f48fd362a8c..04698c4bcd30 100644
@@ -103,6 +103,10 @@ void kvm_arch_vcpu_ctxsync_fp(struct kvm_vcpu *vcpu)
 	WARN_ON_ONCE(!irqs_disabled());
 
 	if (vcpu->arch.flags & KVM_ARM64_FP_ENABLED) {
+		/*
+		 * Currently we do not support SME guests so SVCR is
+		 * always 0 and we just need a variable to point to.
+		 */
 		fpsimd_bind_state_to_cpu(&vcpu->arch.ctxt.fp_regs,
 					 vcpu->arch.sve_state,
 					 vcpu->arch.sve_max_vl);
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#60 lore raw

PATCH v11 16/40 arm64/sme: Implement streaming SVE context switching

In reply to Mark Brown

When in streaming mode we need to save and restore the streaming mode SVE register state rather than the regular SVE register state. This uses the streaming mode vector length and omits FFR but is otherwise identical, if TIF_SVE is enabled when we are in streaming mode then streaming mode takes precedence.

This does not handle use of streaming SVE state with KVM, ptrace or signals. This will be updated in further patches.

---
 arch/arm64/include/asm/fpsimd.h       |  22 +++++-
 arch/arm64/include/asm/fpsimdmacros.h |  11 +++
 arch/arm64/include/asm/processor.h    |  10 +++
 arch/arm64/kernel/entry-fpsimd.S      |   5 ++
 arch/arm64/kernel/fpsimd.c            | 109 +++++++++++++++++++++-----
 arch/arm64/kvm/fpsimd.c               |   3 +-
 6 files changed, 137 insertions(+), 23 deletions(-)
arch/arm64/include/asm/fpsimd.h +20 -2
index d1bae65d3dba..650ec642159c 100644
@@ -47,11 +47,21 @@ extern void fpsimd_update_current_state(struct user_fpsimd_state const *state);
 
 extern void fpsimd_bind_state_to_cpu(struct user_fpsimd_state *state,
 				     void *sve_state, unsigned int sve_vl,
-				     u64 *svcr);
+				     unsigned int sme_vl, u64 *svcr);
 
 extern void fpsimd_flush_task_state(struct task_struct *target);
 extern void fpsimd_save_and_flush_cpu_state(void);
 
+static inline bool thread_sm_enabled(struct thread_struct *thread)
+{
+	return system_supports_sme() && (thread->svcr & SYS_SVCR_EL0_SM_MASK);
+}
+
+static inline bool thread_za_enabled(struct thread_struct *thread)
+{
+	return system_supports_sme() && (thread->svcr & SYS_SVCR_EL0_ZA_MASK);
+}
+
 /* Maximum VL that SVE/SME VL-agnostic software can transparently support */
 #define VL_ARCH_MAX 0x100
 
@@ -63,7 +73,14 @@ static inline size_t sve_ffr_offset(int vl)
 
 static inline void *sve_pffr(struct thread_struct *thread)
 {
-	return (char *)thread->sve_state + sve_ffr_offset(thread_get_sve_vl(thread));
+	unsigned int vl;
+
+	if (system_supports_sme() && thread_sm_enabled(thread))
+		vl = thread_get_sme_vl(thread);
+	else
+		vl = thread_get_sve_vl(thread);
+
+	return (char *)thread->sve_state + sve_ffr_offset(vl);
 }
 
 extern void sve_save_state(void *state, u32 *pfpsr, int save_ffr);
@@ -72,6 +89,7 @@ extern void sve_load_state(void const *state, u32 const *pfpsr,
 extern void sve_flush_live(bool flush_ffr, unsigned long vq_minus_1);
 extern unsigned int sve_get_vl(void);
 extern void sve_set_vq(unsigned long vq_minus_1);
+extern void sme_set_vq(unsigned long vq_minus_1);
 
 struct arm64_cpu_capabilities;
 extern void sve_kernel_enable(const struct arm64_cpu_capabilities *__unused);
arch/arm64/include/asm/fpsimdmacros.h +11 -0
index 11c426ddd62c..a50fa1eab730 100644
@@ -261,6 +261,17 @@
 921:
 .endm
 
+/* Update SMCR_EL1.LEN with the new VQ */
+.macro sme_load_vq xvqminus1, xtmp, xtmp2
+		mrs_s		\xtmp, SYS_SMCR_EL1
+		bic		\xtmp2, \xtmp, SMCR_ELx_LEN_MASK
+		orr		\xtmp2, \xtmp2, \xvqminus1
+		cmp		\xtmp2, \xtmp
+		b.eq		921f
+		msr_s		SYS_SMCR_EL1, \xtmp2	//self-synchronising
+921:
+.endm
+
 /* Preserve the first 128-bits of Znz and zero the rest. */
 .macro _sve_flush_z nz
 	_sve_check_zreg \nz
arch/arm64/include/asm/processor.h +10 -0
index 7e08a4d48c24..6e2af9de153c 100644
@@ -183,6 +183,11 @@ static inline unsigned int thread_get_sve_vl(struct thread_struct *thread)
 	return thread_get_vl(thread, ARM64_VEC_SVE);
 }
 
+static inline unsigned int thread_get_sme_vl(struct thread_struct *thread)
+{
+	return thread_get_vl(thread, ARM64_VEC_SME);
+}
+
 unsigned int task_get_vl(const struct task_struct *task, enum vec_type type);
 void task_set_vl(struct task_struct *task, enum vec_type type,
 		 unsigned long vl);
@@ -196,6 +201,11 @@ static inline unsigned int task_get_sve_vl(const struct task_struct *task)
 	return task_get_vl(task, ARM64_VEC_SVE);
 }
 
+static inline unsigned int task_get_sme_vl(const struct task_struct *task)
+{
+	return task_get_vl(task, ARM64_VEC_SME);
+}
+
 static inline void task_set_sve_vl(struct task_struct *task, unsigned long vl)
 {
 	task_set_vl(task, ARM64_VEC_SVE, vl);
arch/arm64/kernel/entry-fpsimd.S +5 -0
index deee5f01462e..6f88c0f86d50 100644
@@ -94,4 +94,9 @@ SYM_FUNC_START(sme_get_vl)
 	ret
 SYM_FUNC_END(sme_get_vl)
 
+SYM_FUNC_START(sme_set_vq)
+	sme_load_vq x0, x1, x2
+	ret
+SYM_FUNC_END(sme_set_vq)
+
 #endif /* CONFIG_ARM64_SME */
arch/arm64/kernel/fpsimd.c +89 -20

206 lines not on this page · raw message

arch/arm64/kvm/fpsimd.c +2 -1
index 04698c4bcd30..902c598b7ed2 100644
@@ -109,7 +109,8 @@ void kvm_arch_vcpu_ctxsync_fp(struct kvm_vcpu *vcpu)
 		 */
 		fpsimd_bind_state_to_cpu(&vcpu->arch.ctxt.fp_regs,
 					 vcpu->arch.sve_state,
-					 vcpu->arch.sve_max_vl);
+					 vcpu->arch.sve_max_vl,
+					 0);
 
 		clear_thread_flag(TIF_FOREIGN_FPSTATE);
 		update_thread_flag(TIF_SVE, vcpu_has_sve(vcpu));
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#63 lore raw

PATCH v11 17/40 arm64/sme: Implement ZA context switching

In reply to Mark Brown

Allocate space for storing ZA on first access to SME and use that to save and restore ZA state when context switching. We do this by using the vector form of the LDR and STR ZA instructions, these do not require streaming mode and have implementation recommendations that they avoid contention issues in shared SMCU implementations.

Since ZA is architecturally guaranteed to be zeroed when enabled we do not need to explicitly zero ZA, either we will be restoring from a saved copy or trapping on first use of SME so we know that ZA must be disabled.

---
 arch/arm64/include/asm/fpsimd.h       |  5 ++++-
 arch/arm64/include/asm/fpsimdmacros.h | 22 ++++++++++++++++++++++
 arch/arm64/include/asm/kvm_host.h     |  3 +++
 arch/arm64/include/asm/processor.h    |  1 +
 arch/arm64/kernel/entry-fpsimd.S      | 22 ++++++++++++++++++++++
 arch/arm64/kernel/fpsimd.c            | 20 +++++++++++++-------
 arch/arm64/kvm/fpsimd.c               |  2 +-
 7 files changed, 66 insertions(+), 9 deletions(-)
arch/arm64/include/asm/fpsimd.h +4 -1
index 650ec642159c..af404e5b8d82 100644
@@ -47,7 +47,8 @@ extern void fpsimd_update_current_state(struct user_fpsimd_state const *state);
 
 extern void fpsimd_bind_state_to_cpu(struct user_fpsimd_state *state,
 				     void *sve_state, unsigned int sve_vl,
-				     unsigned int sme_vl, u64 *svcr);
+				     void *za_state, unsigned int sme_vl,
+				     u64 *svcr);
 
 extern void fpsimd_flush_task_state(struct task_struct *target);
 extern void fpsimd_save_and_flush_cpu_state(void);
@@ -90,6 +91,8 @@ extern void sve_flush_live(bool flush_ffr, unsigned long vq_minus_1);
 extern unsigned int sve_get_vl(void);
 extern void sve_set_vq(unsigned long vq_minus_1);
 extern void sme_set_vq(unsigned long vq_minus_1);
+extern void za_save_state(void *state);
+extern void za_load_state(void const *state);
 
 struct arm64_cpu_capabilities;
 extern void sve_kernel_enable(const struct arm64_cpu_capabilities *__unused);
arch/arm64/include/asm/fpsimdmacros.h +22 -0
index a50fa1eab730..35d67e393519 100644
@@ -318,3 +318,25 @@
 		ldr		w\nxtmp, [\xpfpsr, #4]
 		msr		fpcr, x\nxtmp
 .endm
+
+.macro sme_save_za nxbase, xvl, nw
+	mov	w\nw, #0
+
+423:
+	_sme_str_zav \nw, \nxbase
+	add	x\nxbase, x\nxbase, \xvl
+	add	x\nw, x\nw, #1
+	cmp	\xvl, x\nw
+	bne	423b
+.endm
+
+.macro sme_load_za nxbase, xvl, nw
+	mov	w\nw, #0
+
+423:
+	_sme_ldr_zav \nw, \nxbase
+	add	x\nxbase, x\nxbase, \xvl
+	add	x\nw, x\nw, #1
+	cmp	\xvl, x\nw
+	bne	423b
+.endm
arch/arm64/include/asm/kvm_host.h +3 -0
index 5bc01e62c08a..7dc85d5a6552 100644
@@ -280,8 +280,11 @@ struct vcpu_reset_state {
 
 struct kvm_vcpu_arch {
 	struct kvm_cpu_context ctxt;
+
+	/* Guest floating point state */
 	void *sve_state;
 	unsigned int sve_max_vl;
+	u64 svcr;
 
 	/* Stage 2 paging state used by the hardware on next switch */
 	struct kvm_s2_mmu *hw_mmu;
arch/arm64/include/asm/processor.h +1 -0
index 6e2af9de153c..5a5c5edd76df 100644
@@ -153,6 +153,7 @@ struct thread_struct {
 
 	unsigned int		fpsimd_cpu;
 	void			*sve_state;	/* SVE registers, if any */
+	void			*za_state;	/* ZA register, if any */
 	unsigned int		vl[ARM64_VEC_MAX];	/* vector length */
 	unsigned int		vl_onexec[ARM64_VEC_MAX]; /* vl after next exec */
 	unsigned long		fault_address;	/* fault info */
arch/arm64/kernel/entry-fpsimd.S +22 -0
index 6f88c0f86d50..229436f33df5 100644
@@ -99,4 +99,26 @@ SYM_FUNC_START(sme_set_vq)
 	ret
 SYM_FUNC_END(sme_set_vq)
 
+/*
+ * Save the SME state
+ *
+ * x0 - pointer to buffer for state
+ */
+SYM_FUNC_START(za_save_state)
+	_sme_rdsvl	1, 1		// x1 = VL/8
+	sme_save_za 0, x1, 12
+	ret
+SYM_FUNC_END(za_save_state)
+
+/*
+ * Load the SME state
+ *
+ * x0 - pointer to buffer for state
+ */
+SYM_FUNC_START(za_load_state)
+	_sme_rdsvl	1, 1		// x1 = VL/8
+	sme_load_za 0, x1, 12
+	ret
+SYM_FUNC_END(za_load_state)
+
 #endif /* CONFIG_ARM64_SME */
arch/arm64/kernel/fpsimd.c +13 -7
index 12fef62cf07a..c9e8186e69c0 100644
@@ -121,6 +121,7 @@
 struct fpsimd_last_state_struct {
 	struct user_fpsimd_state *st;
 	void *sve_state;
+	void *za_state;
 	u64 *svcr;
 	unsigned int sve_vl;
 	unsigned int sme_vl;
@@ -387,11 +388,15 @@ static void task_fpsimd_load(void)
 	if (system_supports_sme()) {
 		unsigned long sme_vl = task_get_sme_vl(current);
 
+		/* Ensure VL is set up for restoring data */
 		if (test_thread_flag(TIF_SME))
 			sme_set_vq(sve_vq_from_vl(sme_vl) - 1);
 
 		write_sysreg_s(current->thread.svcr, SYS_SVCR_EL0);
 
+		if (thread_za_enabled(&current->thread))
+			za_load_state(current->thread.za_state);
+
 		if (thread_sm_enabled(&current->thread)) {
 			restore_sve_regs = true;
 			restore_ffr = system_supports_fa64();
@@ -435,11 +440,10 @@ static void fpsimd_save(void)
 		u64 *svcr = last->svcr;
 		*svcr = read_sysreg_s(SYS_SVCR_EL0);
 
-		if (thread_za_enabled(&current->thread)) {
-			/* ZA state managment is not implemented yet */
-			force_signal_inject(SIGKILL, SI_KERNEL, 0, 0);
-			return;
-		}
+		*svcr = read_sysreg_s(SYS_SVCR_EL0);
+
+		if (*svcr & SYS_SVCR_EL0_ZA_MASK)
+			za_save_state(last->za_state);
 
 		/* If we are in streaming mode override regular SVE. */
 		if (*svcr & SYS_SVCR_EL0_SM_MASK) {
@@ -1477,6 +1481,7 @@ static void fpsimd_bind_task_to_cpu(void)
 	WARN_ON(!system_supports_fpsimd());
 	last->st = &current->thread.uw.fpsimd_state;
 	last->sve_state = current->thread.sve_state;
+	last->za_state = current->thread.za_state;
 	last->sve_vl = task_get_sve_vl(current);
 	last->sme_vl = task_get_sme_vl(current);
 	last->svcr = &current->thread.svcr;
@@ -1494,8 +1499,8 @@ static void fpsimd_bind_task_to_cpu(void)
 }
 
 void fpsimd_bind_state_to_cpu(struct user_fpsimd_state *st, void *sve_state,
-			      unsigned int sve_vl, unsigned int sme_vl,
-			      u64 *svcr)
+			      unsigned int sve_vl, void *za_state,
+			      unsigned int sme_vl, u64 *svcr)
 {
 	struct fpsimd_last_state_struct *last =
 		this_cpu_ptr(&fpsimd_last_state);
@@ -1506,6 +1511,7 @@ void fpsimd_bind_state_to_cpu(struct user_fpsimd_state *st, void *sve_state,
 	last->st = st;
 	last->svcr = svcr;
 	last->sve_state = sve_state;
+	last->za_state = za_state;
 	last->sve_vl = sve_vl;
 	last->sme_vl = sme_vl;
 }
arch/arm64/kvm/fpsimd.c +1 -1
index 902c598b7ed2..338733ac63f8 100644
@@ -110,7 +110,7 @@ void kvm_arch_vcpu_ctxsync_fp(struct kvm_vcpu *vcpu)
 		fpsimd_bind_state_to_cpu(&vcpu->arch.ctxt.fp_regs,
 					 vcpu->arch.sve_state,
 					 vcpu->arch.sve_max_vl,
-					 0);
+					 NULL, 0, &vcpu->arch.svcr);
 
 		clear_thread_flag(TIF_FOREIGN_FPSTATE);
 		update_thread_flag(TIF_SVE, vcpu_has_sve(vcpu));
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#65 lore raw

PATCH v11 18/40 arm64/sme: Implement traps and syscall handling for SME

In reply to Mark Brown

By default all SME operations in userspace will trap. When this happens we allocate storage space for the SME register state, set up the SVE registers and disable traps. We do not need to initialize ZA since the architecture guarantees that it will be zeroed when enabled and when we trap ZA is disabled.

On syscall we exit streaming mode if we were previously in it and ensure that all but the lower 128 bits of the registers are zeroed while preserving the state of ZA. This follows the aarch64 PCS for SME, ZA state is preserved over a function call and streaming mode is exited. Since the traps for SME do not distinguish between streaming mode SVE and ZA usage if ZA is in use rather than reenabling traps we instead zero the parts of the SVE registers not shared with FPSIMD and leave SME enabled, this simplifies handling SME traps. If ZA is not in use then we reenable SME traps and fall through to normal handling of SVE.

---
 arch/arm64/include/asm/esr.h       |   1 +
 arch/arm64/include/asm/exception.h |   1 +
 arch/arm64/include/asm/fpsimd.h    |  27 +++++
 arch/arm64/kernel/entry-common.c   |  11 ++
 arch/arm64/kernel/fpsimd.c         | 180 ++++++++++++++++++++++++++---
 arch/arm64/kernel/process.c        |  12 +-
 arch/arm64/kernel/syscall.c        |  34 +++++-
 7 files changed, 242 insertions(+), 24 deletions(-)
arch/arm64/include/asm/esr.h +1 -0
index 43872e0cfd1e..0467837fd66b 100644
@@ -76,6 +76,7 @@
 #define ESR_ELx_IL_SHIFT	(25)
 #define ESR_ELx_IL		(UL(1) << ESR_ELx_IL_SHIFT)
 #define ESR_ELx_ISS_MASK	(ESR_ELx_IL - 1)
+#define ESR_ELx_ISS(esr)	((esr) & ESR_ELx_ISS_MASK)
 
 /* ISS field definitions shared by different classes */
 #define ESR_ELx_WNR_SHIFT	(6)
arch/arm64/include/asm/exception.h +1 -0
index 339477dca551..2add7f33b7c2 100644
@@ -64,6 +64,7 @@ void do_debug_exception(unsigned long addr_if_watchpoint, unsigned int esr,
 			struct pt_regs *regs);
 void do_fpsimd_acc(unsigned int esr, struct pt_regs *regs);
 void do_sve_acc(unsigned int esr, struct pt_regs *regs);
+void do_sme_acc(unsigned int esr, struct pt_regs *regs);
 void do_fpsimd_exc(unsigned int esr, struct pt_regs *regs);
 void do_sysinstr(unsigned int esr, struct pt_regs *regs);
 void do_sp_pc_abort(unsigned long addr, unsigned int esr, struct pt_regs *regs);
arch/arm64/include/asm/fpsimd.h +27 -0
index af404e5b8d82..3ca152aaf7c9 100644
@@ -282,6 +282,16 @@ static inline void sve_setup(void) { }
 
 #ifdef CONFIG_ARM64_SME
 
+static inline void sme_user_disable(void)
+{
+	sysreg_clear_set(cpacr_el1, CPACR_EL1_SMEN_EL0EN, 0);
+}
+
+static inline void sme_user_enable(void)
+{
+	sysreg_clear_set(cpacr_el1, 0, CPACR_EL1_SMEN_EL0EN);
+}
+
 static inline void sme_smstart_sm(void)
 {
 	asm volatile(".inst 0xd503437f");
@@ -309,16 +319,33 @@ static inline int sme_max_virtualisable_vl(void)
 	return vec_max_virtualisable_vl(ARM64_VEC_SME);
 }
 
+extern void sme_alloc(struct task_struct *task);
 extern unsigned int sme_get_vl(void);
 extern int sme_set_current_vl(unsigned long arg);
 extern int sme_get_current_vl(void);
 
+/*
+ * Return how many bytes of memory are required to store the full SME
+ * specific state (currently just ZA) for task, given task's currently
+ * configured vector length.
+ */
+static inline size_t za_state_size(struct task_struct const *task)
+{
+	unsigned int vl = task_get_sme_vl(task);
+
+	return ZA_SIG_REGS_SIZE(sve_vq_from_vl(vl));
+}
+
 #else
 
+static inline void sme_user_disable(void) { BUILD_BUG(); }
+static inline void sme_user_enable(void) { BUILD_BUG(); }
+
 static inline void sme_smstart_sm(void) { }
 static inline void sme_smstop_sm(void) { }
 static inline void sme_smstop(void) { }
 
+static inline void sme_alloc(struct task_struct *task) { }
 static inline void sme_setup(void) { }
 static inline unsigned int sme_get_vl(void) { return 0; }
 static inline int sme_max_vl(void) { return 0; }
arch/arm64/kernel/entry-common.c +11 -0
index ef7fcefb96bd..b2ad525d6c87 100644
@@ -524,6 +524,14 @@ static void noinstr el0_sve_acc(struct pt_regs *regs, unsigned long esr)
 	exit_to_user_mode(regs);
 }
 
+static void noinstr el0_sme_acc(struct pt_regs *regs, unsigned long esr)
+{
+	enter_from_user_mode(regs);
+	local_daif_restore(DAIF_PROCCTX);
+	do_sme_acc(esr, regs);
+	exit_to_user_mode(regs);
+}
+
 static void noinstr el0_fpsimd_exc(struct pt_regs *regs, unsigned long esr)
 {
 	enter_from_user_mode(regs);
@@ -632,6 +640,9 @@ asmlinkage void noinstr el0t_64_sync_handler(struct pt_regs *regs)
 	case ESR_ELx_EC_SVE:
 		el0_sve_acc(regs, esr);
 		break;
+	case ESR_ELx_EC_SME:
+		el0_sme_acc(regs, esr);
+		break;
 	case ESR_ELx_EC_FP_EXC64:
 		el0_fpsimd_exc(regs, esr);
 		break;
arch/arm64/kernel/fpsimd.c +163 -17

256 lines not on this page · raw message

arch/arm64/kernel/process.c +7 -5
index f2d32a29641c..f7fcc625ea0e 100644
@@ -299,17 +299,19 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
 	BUILD_BUG_ON(!IS_ENABLED(CONFIG_THREAD_INFO_IN_TASK));
 
 	/*
-	 * Detach src's sve_state (if any) from dst so that it does not
-	 * get erroneously used or freed prematurely.  dst's sve_state
-	 * will be allocated on demand later on if dst uses SVE.
-	 * For consistency, also clear TIF_SVE here: this could be done
+	 * Detach src's sve/za_state (if any) from dst so that it does not
+	 * get erroneously used or freed prematurely.  dst's copies
+	 * will be allocated on demand later on if dst uses SVE/SME.
+	 * For consistency, also clear TIF_SVE/SME here: this could be done
 	 * later in copy_process(), but to avoid tripping up future
-	 * maintainers it is best not to leave TIF_SVE and sve_state in
+	 * maintainers it is best not to leave TIF flags and buffers in
 	 * an inconsistent state, even temporarily.
 	 */
 	dst->thread.sve_state = NULL;
 	clear_tsk_thread_flag(dst, TIF_SVE);
 
+	dst->thread.za_state = NULL;
+	clear_tsk_thread_flag(dst, TIF_SME);
 	dst->thread.svcr = 0;
 
 	/* clear any pending asynchronous tag fault raised by the parent */
arch/arm64/kernel/syscall.c +32 -2
index c938603b3ba0..958b2d926354 100644
@@ -158,11 +158,41 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr,
 	syscall_trace_exit(regs);
 }
 
-static inline void sve_user_discard(void)
+/*
+ * As per the ABI exit SME streaming mode and clear the SVE state not
+ * shared with FPSIMD on syscall entry.
+ */
+static inline void fp_user_discard(void)
 {
+	/*
+	 * If SME is active then exit streaming mode.  If ZA is active
+	 * then flush the SVE registers but leave userspace access to
+	 * both SVE and SME enabled, otherwise disable SME for the
+	 * task and fall through to disabling SVE too.  This means
+	 * that after a syscall we never have any SME register state
+	 * to track, if this changes the KVM code will need updating.
+	 */
+	if (system_supports_sme() && test_thread_flag(TIF_SME)) {
+		u64 svcr = read_sysreg_s(SYS_SVCR_EL0);
+
+		if (svcr & SYS_SVCR_EL0_SM_MASK)
+			sme_smstop_sm();
+
+		if (!(svcr & SYS_SVCR_EL0_ZA_MASK)) {
+			clear_thread_flag(TIF_SME);
+			sme_user_disable();
+		}
+	}
+
+
 	if (!system_supports_sve())
 		return;
 
+	/*
+	 * If SME is not active then disable SVE, the registers will
+	 * be cleared when userspace next attempts to access them and
+	 * we do not need to track the SVE register state until then.
+	 */
 	clear_thread_flag(TIF_SVE);
 
 	/*
@@ -177,7 +207,7 @@ static inline void sve_user_discard(void)
 
 void do_el0_svc(struct pt_regs *regs)
 {
-	sve_user_discard();
+	fp_user_discard();
 	el0_svc_common(regs, regs->regs[8], __NR_syscalls, sys_call_table);
 }
 
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#68 lore raw

PATCH v11 19/40 arm64/sme: Disable ZA and streaming mode when handling signals

In reply to Mark Brown

The ABI requires that streaming mode and ZA are disabled when invoking signal handlers, do this in setup_return() when we prepare the task state for the signal handler.

---
 arch/arm64/kernel/signal.c | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm64/kernel/signal.c +7 -0
index d8aaf4b6f432..cda04fd73333 100644
@@ -758,6 +758,13 @@ static void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
 	/* TCO (Tag Check Override) always cleared for signal handlers */
 	regs->pstate &= ~PSR_TCO_BIT;
 
+	/* Signal handlers are invoked with ZA and streaming mode disabled */
+	if (system_supports_sme()) {
+		current->thread.svcr &= ~(SYS_SVCR_EL0_ZA_MASK |
+					  SYS_SVCR_EL0_SM_MASK);
+		sme_smstop();
+	}
+
 	if (ka->sa.sa_flags & SA_RESTORER)
 		sigtramp = ka->sa.sa_restorer;
 	else
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#70 lore raw

PATCH v11 20/40 arm64/sme: Implement streaming SVE signal handling

In reply to Mark Brown

When in streaming mode we have the same set of SVE registers as we do in regular SVE mode with the exception of FFR and the use of the SME vector length. Provide signal handling for these registers by taking one of the reserved words in the SVE signal context as a flags field and defining a flag with a flag which is set for streaming mode. When the flag is set the vector length is set to the streaming mode vector length and we save and restore streaming mode data. We support entering or leaving streaming mode based on the value of the flag but do not support changing the vector length, this is not currently supported SVE signal handling.

We could instead allocate a separate record in the signal frame for the streaming mode SVE context but this inflates the size of the maximal signal frame required and adds complication when validating signal frames from userspace, especially given the current structure of the code.

Any implementation of support for streaming mode vectors in signals will have some potential for causing issues for applications that attempt to handle SVE vectors in signals, use streaming mode but do not understand streaming mode in their signal handling code, it is hard to identify a case that is clearly better than any other - they all have cases where they could cause unexpected register corruption or faults.

---
 arch/arm64/include/uapi/asm/sigcontext.h | 16 ++++++--
 arch/arm64/kernel/signal.c               | 48 ++++++++++++++++++------
 2 files changed, 50 insertions(+), 14 deletions(-)
arch/arm64/include/uapi/asm/sigcontext.h +13 -3
index 0c796c795dbe..3a3366d4fbc2 100644
@@ -134,9 +134,12 @@ struct extra_context {
 struct sve_context {
 	struct _aarch64_ctx head;
 	__u16 vl;
-	__u16 __reserved[3];
+	__u16 flags;
+	__u16 __reserved[2];
 };
 
+#define SVE_SIG_FLAG_SM	0x1	/* Context describes streaming mode */
+
 #endif /* !__ASSEMBLY__ */
 
 #include <asm/sve_context.h>
@@ -186,9 +189,16 @@ struct sve_context {
  * sve_context.vl must equal the thread's current vector length when
  * doing a sigreturn.
  *
+ * On systems with support for SME the SVE register state may reflect either
+ * streaming or non-streaming mode.  In streaming mode the streaming mode
+ * vector length will be used and the flag SVE_SIG_FLAG_SM will be set in
+ * the flags field. It is permitted to enter or leave streaming mode in
+ * a signal return, applications should take care to ensure that any difference
+ * in vector length between the two modes is handled, including any resixing
+ * and movement of context blocks.
  *
- * Note: for all these macros, the "vq" argument denotes the SVE
- * vector length in quadwords (i.e., units of 128 bits).
+ * Note: for all these macros, the "vq" argument denotes the vector length
+ * in quadwords (i.e., units of 128 bits).
  *
  * The correct way to obtain vq is to use sve_vq_from_vl(vl).  The
  * result is valid if and only if sve_vl_valid(vl) is true.  This is
arch/arm64/kernel/signal.c +37 -11

105 lines not on this page · raw message

Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#72 lore raw

PATCH v11 21/40 arm64/sme: Implement ZA signal handling

In reply to Mark Brown

Implement support for ZA in signal handling in a very similar way to how we implement support for SVE registers, using a signal context structure with optional register state after it. Where present this register state stores the ZA matrix as a series of horizontal vectors numbered from 0 to VL/8 in the endinanness independent format used for vectors.

As with SVE we do not allow changes in the vector length during signal return but we do allow ZA to be enabled or disabled.

---
 arch/arm64/include/uapi/asm/sigcontext.h |  41 +++++++
 arch/arm64/kernel/fpsimd.c               |   3 -
 arch/arm64/kernel/signal.c               | 139 +++++++++++++++++++++++
 3 files changed, 180 insertions(+), 3 deletions(-)
arch/arm64/include/uapi/asm/sigcontext.h +41 -0
index 3a3366d4fbc2..d45bdf2c8b26 100644
@@ -140,6 +140,14 @@ struct sve_context {
 
 #define SVE_SIG_FLAG_SM	0x1	/* Context describes streaming mode */
 
+#define ZA_MAGIC	0x54366345
+
+struct za_context {
+	struct _aarch64_ctx head;
+	__u16 vl;
+	__u16 __reserved[3];
+};
+
 #endif /* !__ASSEMBLY__ */
 
 #include <asm/sve_context.h>
@@ -259,4 +267,37 @@ struct sve_context {
 #define SVE_SIG_CONTEXT_SIZE(vq) \
 		(SVE_SIG_REGS_OFFSET + SVE_SIG_REGS_SIZE(vq))
 
+/*
+ * If the ZA register is enabled for the thread at signal delivery then,
+ * za_context.head.size >= ZA_SIG_CONTEXT_SIZE(sve_vq_from_vl(za_context.vl))
+ * and the register data may be accessed using the ZA_SIG_*() macros.
+ *
+ * If za_context.head.size < ZA_SIG_CONTEXT_SIZE(sve_vq_from_vl(za_context.vl))
+ * then ZA was not enabled and no register data was included in which case
+ * ZA register was not enabled for the thread and no register data
+ * the ZA_SIG_*() macros should not be used except for this check.
+ *
+ * The same convention applies when returning from a signal: a caller
+ * will need to remove or resize the za_context block if it wants to
+ * enable the ZA register when it was previously non-live or vice-versa.
+ * This may require the caller to allocate fresh memory and/or move other
+ * context blocks in the signal frame.
+ *
+ * Changing the vector length during signal return is not permitted:
+ * za_context.vl must equal the thread's current SME vector length when
+ * doing a sigreturn.
+ */
+
+#define ZA_SIG_REGS_OFFSET					\
+	((sizeof(struct za_context) + (__SVE_VQ_BYTES - 1))	\
+		/ __SVE_VQ_BYTES * __SVE_VQ_BYTES)
+
+#define ZA_SIG_REGS_SIZE(vq) ((vq * __SVE_VQ_BYTES) * (vq * __SVE_VQ_BYTES))
+
+#define ZA_SIG_ZAV_OFFSET(vq, n) (ZA_SIG_REGS_OFFSET + \
+				  (SVE_SIG_ZREG_SIZE(vq) * n))
+
+#define ZA_SIG_CONTEXT_SIZE(vq) \
+		(ZA_SIG_REGS_OFFSET + ZA_SIG_REGS_SIZE(vq))
+
 #endif /* _UAPI__ASM_SIGCONTEXT_H */
arch/arm64/kernel/fpsimd.c +0 -3
index 33f80512753d..2242c14a5a05 100644
@@ -1190,9 +1190,6 @@ void fpsimd_release_task(struct task_struct *dead_task)
 
 #ifdef CONFIG_ARM64_SME
 
-/* This will move to uapi/asm/sigcontext.h when signals are implemented */
-#define ZA_SIG_REGS_SIZE(vq) ((vq * __SVE_VQ_BYTES) * (vq * __SVE_VQ_BYTES))
-
 /*
  * Ensure that task->thread.za_state is allocated and sufficiently large.
  *
arch/arm64/kernel/signal.c +139 -0

187 lines not on this page · raw message

Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#74 lore raw

PATCH v11 22/40 arm64/sme: Implement ptrace support for streaming mode SVE registers

In reply to Mark Brown

The streaming mode SVE registers are represented using the same data structures as for SVE but since the vector lengths supported and in use may not be the same as SVE we represent them with a new type NT_ARM_SSVE. Unfortunately we only have a single 16 bit reserved field available in the header so there is no space to fit the current and maximum vector length for both standard and streaming SVE mode without redefining the structure in a way the creates a complicatd and fragile ABI. Since FFR is not present in streaming mode it is read and written as zero.

Setting NT_ARM_SSVE registers will put the task into streaming mode, similarly setting NT_ARM_SVE registers will exit it. Reads that do not correspond to the current mode of the task will return the header with no register data. For compatibility reasons on write setting no flag for the register type will be interpreted as setting SVE registers, though users can provide no register data as an alternative mechanism for doing so.

---
 arch/arm64/include/uapi/asm/ptrace.h |  13 +-
 arch/arm64/kernel/fpsimd.c           |  21 ++-
 arch/arm64/kernel/ptrace.c           | 212 +++++++++++++++++++++------
 include/uapi/linux/elf.h             |   1 +
 4 files changed, 190 insertions(+), 57 deletions(-)
arch/arm64/include/uapi/asm/ptrace.h +8 -5
index 758ae984ff97..522b925a78c1 100644
@@ -109,7 +109,7 @@ struct user_hwdebug_state {
 	}		dbg_regs[16];
 };
 
-/* SVE/FP/SIMD state (NT_ARM_SVE) */
+/* SVE/FP/SIMD state (NT_ARM_SVE & NT_ARM_SSVE) */
 
 struct user_sve_header {
 	__u32 size; /* total meaningful regset content in bytes */
@@ -220,6 +220,7 @@ struct user_sve_header {
 	(SVE_PT_SVE_PREG_OFFSET(vq, __SVE_NUM_PREGS) - \
 		SVE_PT_SVE_PREGS_OFFSET(vq))
 
+/* For streaming mode SVE (SSVE) FFR must be read and written as zero */
 #define SVE_PT_SVE_FFR_OFFSET(vq) \
 	(SVE_PT_REGS_OFFSET + __SVE_FFR_OFFSET(vq))
 
@@ -240,10 +241,12 @@ struct user_sve_header {
 			- SVE_PT_SVE_OFFSET + (__SVE_VQ_BYTES - 1))	\
 		/ __SVE_VQ_BYTES * __SVE_VQ_BYTES)
 
-#define SVE_PT_SIZE(vq, flags)						\
-	 (((flags) & SVE_PT_REGS_MASK) == SVE_PT_REGS_SVE ?		\
-		  SVE_PT_SVE_OFFSET + SVE_PT_SVE_SIZE(vq, flags)	\
-		: SVE_PT_FPSIMD_OFFSET + SVE_PT_FPSIMD_SIZE(vq, flags))
+#define SVE_PT_SIZE(vq, flags)						  \
+	 (((flags) & SVE_PT_REGS_MASK) == SVE_PT_REGS_SVE ?		  \
+		  SVE_PT_SVE_OFFSET + SVE_PT_SVE_SIZE(vq, flags)	  \
+		: ((((flags) & SVE_PT_REGS_MASK) == SVE_PT_REGS_FPSIMD ?  \
+		    SVE_PT_FPSIMD_OFFSET + SVE_PT_FPSIMD_SIZE(vq, flags) \
+		  : SVE_PT_REGS_OFFSET)))
 
 /* pointer authentication masks (NT_ARM_PAC_MASK) */
 
arch/arm64/kernel/fpsimd.c +15 -6
index 2242c14a5a05..8b111b7f2006 100644
@@ -645,14 +645,19 @@ static void __fpsimd_to_sve(void *sst, struct user_fpsimd_state const *fst,
  */
 static void fpsimd_to_sve(struct task_struct *task)
 {
-	unsigned int vq;
+	unsigned int vq, vl;
 	void *sst = task->thread.sve_state;
 	struct user_fpsimd_state const *fst = &task->thread.uw.fpsimd_state;
 
 	if (!system_supports_sve())
 		return;
 
-	vq = sve_vq_from_vl(task_get_sve_vl(task));
+	if (thread_sm_enabled(&task->thread))
+		vl = task_get_sme_vl(task);
+	else
+		vl = task_get_sve_vl(task);
+
+	vq = sve_vq_from_vl(vl);
 	__fpsimd_to_sve(sst, fst, vq);
 }
 
@@ -669,7 +674,7 @@ static void fpsimd_to_sve(struct task_struct *task)
  */
 static void sve_to_fpsimd(struct task_struct *task)
 {
-	unsigned int vq;
+	unsigned int vq, vl;
 	void const *sst = task->thread.sve_state;
 	struct user_fpsimd_state *fst = &task->thread.uw.fpsimd_state;
 	unsigned int i;
@@ -678,7 +683,12 @@ static void sve_to_fpsimd(struct task_struct *task)
 	if (!system_supports_sve())
 		return;
 
-	vq = sve_vq_from_vl(task_get_sve_vl(task));
+	if (thread_sm_enabled(&task->thread))
+		vl = task_get_sme_vl(task);
+	else
+		vl = task_get_sve_vl(task);
+
+	vq = sve_vq_from_vl(vl);
 	for (i = 0; i < SVE_NUM_ZREGS; ++i) {
 		p = (__uint128_t const *)ZREG(sst, vq, i);
 		fst->vregs[i] = arm64_le128_to_cpu(*p);
@@ -819,8 +829,7 @@ int vec_set_vector_length(struct task_struct *task, enum vec_type type,
 	/*
 	 * To ensure the FPSIMD bits of the SVE vector registers are preserved,
 	 * write any live register state back to task_struct, and convert to a
-	 * regular FPSIMD thread.  Since the vector length can only be changed
-	 * with a syscall we can't be in streaming mode while reconfiguring.
+	 * regular FPSIMD thread.
 	 */
 	if (task == current) {
 		get_cpu_fpsimd_context();
arch/arm64/kernel/ptrace.c +166 -46

303 lines not on this page · raw message

include/uapi/linux/elf.h +1 -0
index 61bf4774b8f2..61502388683f 100644
@@ -427,6 +427,7 @@ typedef struct elf64_shdr {
 #define NT_ARM_PACG_KEYS	0x408	/* ARM pointer authentication generic key */
 #define NT_ARM_TAGGED_ADDR_CTRL	0x409	/* arm64 tagged address control (prctl()) */
 #define NT_ARM_PAC_ENABLED_KEYS	0x40a	/* arm64 ptr auth enabled keys (prctl()) */
+#define NT_ARM_SSVE	0x40b		/* ARM Streaming SVE registers */
 #define NT_ARC_V2	0x600		/* ARCv2 accumulator/extra registers */
 #define NT_VMCOREDD	0x700		/* Vmcore Device Dump Note */
 #define NT_MIPS_DSP	0x800		/* MIPS DSP ASE registers */
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#76 lore raw

PATCH v11 23/40 arm64/sme: Add ptrace support for ZA

In reply to Mark Brown

The ZA array can be read and written with the NT_ARM_ZA. Similarly to our interface for the SVE vector registers the regset consists of a header with information on the current vector length followed by an optional register data payload, represented as for signals as a series of horizontal vectors from 0 to VL/8 in the endianness independent format used for vectors.

On get if ZA is enabled then register data will be provided, otherwise it will be omitted. On set if register data is provided then ZA is enabled and initialized using the provided data, otherwise it is disabled.

---
 arch/arm64/include/uapi/asm/ptrace.h |  56 +++++++++++
 arch/arm64/kernel/ptrace.c           | 144 +++++++++++++++++++++++++++
 include/uapi/linux/elf.h             |   1 +
 3 files changed, 201 insertions(+)
arch/arm64/include/uapi/asm/ptrace.h +56 -0
index 522b925a78c1..7fa2f7036aa7 100644
@@ -268,6 +268,62 @@ struct user_pac_generic_keys {
 	__uint128_t	apgakey;
 };
 
+/* ZA state (NT_ARM_ZA) */
+
+struct user_za_header {
+	__u32 size; /* total meaningful regset content in bytes */
+	__u32 max_size; /* maxmium possible size for this thread */
+	__u16 vl; /* current vector length */
+	__u16 max_vl; /* maximum possible vector length */
+	__u16 flags;
+	__u16 __reserved;
+};
+
+/*
+ * Common ZA_PT_* flags:
+ * These must be kept in sync with prctl interface in <linux/prctl.h>
+ */
+#define ZA_PT_VL_INHERIT		((1 << 17) /* PR_SME_VL_INHERIT */ >> 16)
+#define ZA_PT_VL_ONEXEC			((1 << 18) /* PR_SME_SET_VL_ONEXEC */ >> 16)
+
+
+/*
+ * The remainder of the ZA state follows struct user_za_header.  The
+ * total size of the ZA state (including header) depends on the
+ * metadata in the header:  ZA_PT_SIZE(vq, flags) gives the total size
+ * of the state in bytes, including the header.
+ *
+ * Refer to <asm/sigcontext.h> for details of how to pass the correct
+ * "vq" argument to these macros.
+ */
+
+/* Offset from the start of struct user_za_header to the register data */
+#define ZA_PT_ZA_OFFSET						\
+	((sizeof(struct user_za_header) + (__SVE_VQ_BYTES - 1))	\
+		/ __SVE_VQ_BYTES * __SVE_VQ_BYTES)
+
+/*
+ * The payload starts at offset ZA_PT_ZA_OFFSET, and is of size
+ * ZA_PT_ZA_SIZE(vq, flags).
+ *
+ * The ZA array is stored as a sequence of horizontal vectors ZAV of SVL/8
+ * bytes each, starting from vector 0.
+ *
+ * Additional data might be appended in the future.
+ *
+ * The ZA matrix is represented in memory in an endianness-invariant layout
+ * which differs from the layout used for the FPSIMD V-registers on big-endian
+ * systems: see sigcontext.h for more explanation.
+ */
+
+#define ZA_PT_ZAV_OFFSET(vq, n) \
+	(ZA_PT_ZA_OFFSET + ((vq * __SVE_VQ_BYTES) * n))
+
+#define ZA_PT_ZA_SIZE(vq) ((vq * __SVE_VQ_BYTES) * (vq * __SVE_VQ_BYTES))
+
+#define ZA_PT_SIZE(vq)						\
+	(ZA_PT_ZA_OFFSET + ZA_PT_ZA_SIZE(vq))
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* _UAPI__ASM_PTRACE_H */
arch/arm64/kernel/ptrace.c +144 -0

162 lines not on this page · raw message

include/uapi/linux/elf.h +1 -0
index 61502388683f..7ef574f3256a 100644
@@ -428,6 +428,7 @@ typedef struct elf64_shdr {
 #define NT_ARM_TAGGED_ADDR_CTRL	0x409	/* arm64 tagged address control (prctl()) */
 #define NT_ARM_PAC_ENABLED_KEYS	0x40a	/* arm64 ptr auth enabled keys (prctl()) */
 #define NT_ARM_SSVE	0x40b		/* ARM Streaming SVE registers */
+#define NT_ARM_ZA	0x40c		/* ARM SME ZA registers */
 #define NT_ARC_V2	0x600		/* ARCv2 accumulator/extra registers */
 #define NT_VMCOREDD	0x700		/* Vmcore Device Dump Note */
 #define NT_MIPS_DSP	0x800		/* MIPS DSP ASE registers */
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#78 lore raw

PATCH v11 24/40 arm64/sme: Disable streaming mode and ZA when flushing CPU state

In reply to Mark Brown

Both streaming mode and ZA may increase power consumption when they are enabled and streaming mode makes many FPSIMD and SVE instructions undefined which will cause problems for any kernel mode floating point so disable both when we flush the CPU state. This covers both kernel_neon_begin() and idle and after flushing the state a reload is always required anyway.

---
 arch/arm64/kernel/fpsimd.c | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm64/kernel/fpsimd.c +9 -0
index 8b111b7f2006..e00d3a9e919c 100644
@@ -1762,6 +1762,15 @@ static void fpsimd_flush_cpu_state(void)
 {
 	WARN_ON(!system_supports_fpsimd());
 	__this_cpu_write(fpsimd_last_state.st, NULL);
+
+	/*
+	 * Leaving streaming mode enabled will cause issues for any kernel
+	 * NEON and leaving streaming mode or ZA enabled may increase power
+	 * consumption.
+	 */
+	if (system_supports_sme())
+		sme_smstop();
+
 	set_thread_flag(TIF_FOREIGN_FPSTATE);
 }
 
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#80 lore raw

PATCH v11 25/40 arm64/sme: Save and restore streaming mode over EFI runtime calls

In reply to Mark Brown

When saving and restoring the floating point state over an EFI runtime call ensure that we handle streaming mode, only handling FFR if we are not in streaming mode and ensuring that we are in normal mode over the call into runtime services.

We currently assume that ZA will not be modified by runtime services, the specification is not yet finalised so this may need updating if that changes.

---
 arch/arm64/kernel/fpsimd.c | 47 +++++++++++++++++++++++++++++++++-----
 1 file changed, 41 insertions(+), 6 deletions(-)
arch/arm64/kernel/fpsimd.c +41 -6
index e00d3a9e919c..a7077a5d1ed2 100644
@@ -1059,21 +1059,25 @@ int vec_verify_vq_map(enum vec_type type)
 
 static void __init sve_efi_setup(void)
 {
-	struct vl_info *info = &vl_info[ARM64_VEC_SVE];
+	int max_vl = 0;
+	int i;
 
 	if (!IS_ENABLED(CONFIG_EFI))
 		return;
 
+	for (i = 0; i < ARRAY_SIZE(vl_info); i++)
+		max_vl = max(vl_info[i].max_vl, max_vl);
+
 	/*
 	 * alloc_percpu() warns and prints a backtrace if this goes wrong.
 	 * This is evidence of a crippled system and we are returning void,
 	 * so no attempt is made to handle this situation here.
 	 */
-	if (!sve_vl_valid(info->max_vl))
+	if (!sve_vl_valid(max_vl))
 		goto fail;
 
 	efi_sve_state = __alloc_percpu(
-		SVE_SIG_REGS_SIZE(sve_vq_from_vl(info->max_vl)), SVE_VQ_BYTES);
+		SVE_SIG_REGS_SIZE(sve_vq_from_vl(max_vl)), SVE_VQ_BYTES);
 	if (!efi_sve_state)
 		goto fail;
 
@@ -1848,6 +1852,7 @@ EXPORT_SYMBOL(kernel_neon_end);
 static DEFINE_PER_CPU(struct user_fpsimd_state, efi_fpsimd_state);
 static DEFINE_PER_CPU(bool, efi_fpsimd_state_used);
 static DEFINE_PER_CPU(bool, efi_sve_state_used);
+static DEFINE_PER_CPU(bool, efi_sm_state);
 
 /*
  * EFI runtime services support functions
@@ -1882,12 +1887,28 @@ void __efi_fpsimd_begin(void)
 		 */
 		if (system_supports_sve() && likely(efi_sve_state)) {
 			char *sve_state = this_cpu_ptr(efi_sve_state);
+			bool ffr = true;
+			u64 svcr;
 
 			__this_cpu_write(efi_sve_state_used, true);
 
+			/* If we are in streaming mode don't touch FFR */
+			if (system_supports_sme()) {
+				svcr = read_sysreg_s(SYS_SVCR_EL0);
+
+				ffr = svcr & SYS_SVCR_EL0_SM_MASK;
+
+				__this_cpu_write(efi_sm_state, ffr);
+			}
+
 			sve_save_state(sve_state + sve_ffr_offset(sve_max_vl()),
 				       &this_cpu_ptr(&efi_fpsimd_state)->fpsr,
-				       true);
+				       ffr);
+
+			if (system_supports_sme())
+				sysreg_clear_set_s(SYS_SVCR_EL0,
+						   SYS_SVCR_EL0_SM_MASK, 0);
+
 		} else {
 			fpsimd_save_state(this_cpu_ptr(&efi_fpsimd_state));
 		}
@@ -1910,11 +1931,25 @@ void __efi_fpsimd_end(void)
 		if (system_supports_sve() &&
 		    likely(__this_cpu_read(efi_sve_state_used))) {
 			char const *sve_state = this_cpu_ptr(efi_sve_state);
+			bool ffr = true;
+
+			/*
+			 * Restore streaming mode; EFI calls are
+			 * normal function calls so should not return in
+			 * streaming mode.
+			 */
+			if (system_supports_sme()) {
+				if (__this_cpu_read(efi_sm_state)) {
+					sysreg_clear_set_s(SYS_SVCR_EL0,
+							   0,
+							   SYS_SVCR_EL0_SM_MASK);
+					ffr = false;
+				}
+			}
 
-			sve_set_vq(sve_vq_from_vl(sve_get_vl()) - 1);
 			sve_load_state(sve_state + sve_ffr_offset(sve_max_vl()),
 				       &this_cpu_ptr(&efi_fpsimd_state)->fpsr,
-				       true);
+				       ffr);
 
 			__this_cpu_write(efi_sve_state_used, false);
 		} else {
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#82 lore raw

PATCH v11 26/40 KVM: arm64: Hide SME system registers from guests

In reply to Mark Brown

For the time being we do not support use of SME by KVM guests, support for this will be enabled in future. In order to prevent any side effects or side channels via the new system registers, including the EL0 read/write register TPIDR2, explicitly undefine all the system registers added by SME and mask out the SME bitfield in SYS_ID_AA64PFR1.

---
 arch/arm64/kvm/sys_regs.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
arch/arm64/kvm/sys_regs.c +8 -1
index 4dc2fba316ff..43516eda9143 100644
@@ -1089,6 +1089,8 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,
 	case SYS_ID_AA64PFR1_EL1:
 		if (!kvm_has_mte(vcpu->kvm))
 			val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_MTE);
+
+		val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_SME);
 		break;
 	case SYS_ID_AA64ISAR1_EL1:
 		if (!vcpu_has_ptrauth(vcpu))
@@ -1508,7 +1510,7 @@ static const struct sys_reg_desc sys_reg_descs[] = {
 	ID_UNALLOCATED(4,2),
 	ID_UNALLOCATED(4,3),
 	ID_SANITISED(ID_AA64ZFR0_EL1),
-	ID_UNALLOCATED(4,5),
+	ID_HIDDEN(ID_AA64SMFR0_EL1),
 	ID_UNALLOCATED(4,6),
 	ID_UNALLOCATED(4,7),
 
@@ -1551,6 +1553,8 @@ static const struct sys_reg_desc sys_reg_descs[] = {
 
 	{ SYS_DESC(SYS_ZCR_EL1), NULL, reset_val, ZCR_EL1, 0, .visibility = sve_visibility },
 	{ SYS_DESC(SYS_TRFCR_EL1), undef_access },
+	{ SYS_DESC(SYS_SMPRI_EL1), undef_access },
+	{ SYS_DESC(SYS_SMCR_EL1), undef_access },
 	{ SYS_DESC(SYS_TTBR0_EL1), access_vm_reg, reset_unknown, TTBR0_EL1 },
 	{ SYS_DESC(SYS_TTBR1_EL1), access_vm_reg, reset_unknown, TTBR1_EL1 },
 	{ SYS_DESC(SYS_TCR_EL1), access_vm_reg, reset_val, TCR_EL1, 0 },
@@ -1633,8 +1637,10 @@ static const struct sys_reg_desc sys_reg_descs[] = {
 
 	{ SYS_DESC(SYS_CCSIDR_EL1), access_ccsidr },
 	{ SYS_DESC(SYS_CLIDR_EL1), access_clidr },
+	{ SYS_DESC(SYS_SMIDR_EL1), undef_access },
 	{ SYS_DESC(SYS_CSSELR_EL1), access_csselr, reset_unknown, CSSELR_EL1 },
 	{ SYS_DESC(SYS_CTR_EL0), access_ctr },
+	{ SYS_DESC(SYS_SVCR_EL0), undef_access },
 
 	{ PMU_SYS_REG(SYS_PMCR_EL0), .access = access_pmcr,
 	  .reset = reset_pmcr, .reg = PMCR_EL0 },
@@ -1674,6 +1680,7 @@ static const struct sys_reg_desc sys_reg_descs[] = {
 
 	{ SYS_DESC(SYS_TPIDR_EL0), NULL, reset_unknown, TPIDR_EL0 },
 	{ SYS_DESC(SYS_TPIDRRO_EL0), NULL, reset_unknown, TPIDRRO_EL0 },
+	{ SYS_DESC(SYS_TPIDR2_EL0), undef_access },
 
 	{ SYS_DESC(SYS_SCXTNUM_EL0), undef_access },
 
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#84 lore raw

PATCH v11 27/40 KVM: arm64: Trap SME usage in guest

In reply to Mark Brown

SME defines two new traps which need to be enabled for guests to ensure that they can't use SME, one for the main SME operations which mirrors the traps for SVE and another for access to TPIDR2 in SCTLR_EL2.

For VHE manage SMEN along with ZEN in activate_traps() and the FP state management callbacks, along with SCTLR_EL2.EnTPIDR2. There is no existing dynamic management of SCTLR_EL2.

For nVHE manage TSM in activate_traps() along with the fine grained traps for TPIDR2 and SMPRI. There is no existing dynamic management of fine grained traps.

---
 arch/arm64/kvm/hyp/nvhe/switch.c | 30 ++++++++++++++++++++++++++++++
 arch/arm64/kvm/hyp/vhe/switch.c  | 11 ++++++++++-
 2 files changed, 40 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/switch.c +30 -0
index 6410d21d8695..caace61ea459 100644
@@ -47,10 +47,24 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
 		val |= CPTR_EL2_TFP | CPTR_EL2_TZ;
 		__activate_traps_fpsimd32(vcpu);
 	}
+	if (cpus_have_final_cap(ARM64_SME))
+		val |= CPTR_EL2_TSM;
 
 	write_sysreg(val, cptr_el2);
 	write_sysreg(__this_cpu_read(kvm_hyp_vector), vbar_el2);
 
+	if (cpus_have_final_cap(ARM64_SME)) {
+		val = read_sysreg_s(SYS_HFGRTR_EL2);
+		val &= ~(HFGxTR_EL2_nTPIDR2_EL0_MASK |
+			 HFGxTR_EL2_nSMPRI_EL1_MASK);
+		write_sysreg_s(val, SYS_HFGRTR_EL2);
+
+		val = read_sysreg_s(SYS_HFGWTR_EL2);
+		val &= ~(HFGxTR_EL2_nTPIDR2_EL0_MASK |
+			 HFGxTR_EL2_nSMPRI_EL1_MASK);
+		write_sysreg_s(val, SYS_HFGWTR_EL2);
+	}
+
 	if (cpus_have_final_cap(ARM64_WORKAROUND_SPECULATIVE_AT)) {
 		struct kvm_cpu_context *ctxt = &vcpu->arch.ctxt;
 
@@ -94,9 +108,25 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu)
 
 	write_sysreg(this_cpu_ptr(&kvm_init_params)->hcr_el2, hcr_el2);
 
+	if (cpus_have_final_cap(ARM64_SME)) {
+		u64 val;
+
+		val = read_sysreg_s(SYS_HFGRTR_EL2);
+		val |= HFGxTR_EL2_nTPIDR2_EL0_MASK |
+			HFGxTR_EL2_nSMPRI_EL1_MASK;
+		write_sysreg_s(val, SYS_HFGRTR_EL2);
+
+		val = read_sysreg_s(SYS_HFGWTR_EL2);
+		val |= HFGxTR_EL2_nTPIDR2_EL0_MASK |
+			HFGxTR_EL2_nSMPRI_EL1_MASK;
+		write_sysreg_s(val, SYS_HFGWTR_EL2);
+	}
+
 	cptr = CPTR_EL2_DEFAULT;
 	if (vcpu_has_sve(vcpu) && (vcpu->arch.flags & KVM_ARM64_FP_ENABLED))
 		cptr |= CPTR_EL2_TZ;
+	if (cpus_have_final_cap(ARM64_SME))
+		cptr &= ~CPTR_EL2_TSM;
 
 	write_sysreg(cptr, cptr_el2);
 	write_sysreg(__kvm_hyp_host_vector, vbar_el2);
arch/arm64/kvm/hyp/vhe/switch.c +10 -1
index 619353b06e38..a4d2fb5c9710 100644
@@ -38,7 +38,8 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
 
 	val = read_sysreg(cpacr_el1);
 	val |= CPACR_EL1_TTA;
-	val &= ~(CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN);
+	val &= ~(CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN |
+		 CPACR_EL1_SMEN_EL0EN | CPACR_EL1_SMEN_EL1EN);
 
 	/*
 	 * With VHE (HCR.E2H == 1), accesses to CPACR_EL1 are routed to
@@ -59,6 +60,10 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
 		__activate_traps_fpsimd32(vcpu);
 	}
 
+	if (cpus_have_final_cap(ARM64_SME))
+		write_sysreg(read_sysreg(sctlr_el2) & ~SCTLR_ELx_ENTP2,
+			     sctlr_el2);
+
 	write_sysreg(val, cpacr_el1);
 
 	write_sysreg(__this_cpu_read(kvm_hyp_vector), vbar_el1);
@@ -80,6 +85,10 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu)
 	 */
 	asm(ALTERNATIVE("nop", "isb", ARM64_WORKAROUND_SPECULATIVE_AT));
 
+	if (cpus_have_final_cap(ARM64_SME))
+		write_sysreg(read_sysreg(sctlr_el2) | SCTLR_ELx_ENTP2,
+			     sctlr_el2);
+
 	write_sysreg(CPACR_EL1_DEFAULT, cpacr_el1);
 	write_sysreg(vectors, vbar_el1);
 }
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#86 lore raw

PATCH v11 28/40 KVM: arm64: Handle SME host state when running guests

In reply to Mark Brown

While we don't currently support SME in guests we do currently support it for the host system so we need to take care of SME's impact, including the floating point register state, when running guests. Simiarly to SVE we need to manage the traps in CPACR_RL1, what is new is the handling of streaming mode and ZA.

Normally we defer any handling of the floating point register state until the guest first uses it however if the system is in streaming mode FPSIMD and SVE operations may generate SME traps which we would need to distinguish from actual attempts by the guest to use SME. Rather than do this for the time being if we are in streaming mode when entering the guest we force the floating point state to be saved immediately and exit streaming mode, meaning that the guest won't generate SME traps for supported operations.

We could handle ZA in the access trap similarly to the FPSIMD/SVE state without the disruption caused by streaming mode but for simplicity handle it the same way as streaming mode for now.

This will be revisited when we support SME for guests (hopefully before SME hardware becomes available), for now it will only incur additional cost on systems with SME and even there only if streaming mode or ZA are enabled.

---
 arch/arm64/include/asm/kvm_host.h |  1 +
 arch/arm64/kvm/fpsimd.c           | 36 +++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)
arch/arm64/include/asm/kvm_host.h +1 -0
index 7dc85d5a6552..404b7358ba96 100644
@@ -438,6 +438,7 @@ struct kvm_vcpu_arch {
 #define KVM_ARM64_DEBUG_STATE_SAVE_SPE	(1 << 12) /* Save SPE context if active  */
 #define KVM_ARM64_DEBUG_STATE_SAVE_TRBE	(1 << 13) /* Save TRBE context if active  */
 #define KVM_ARM64_FP_FOREIGN_FPSTATE	(1 << 14)
+#define KVM_ARM64_HOST_SME_ENABLED	(1 << 15) /* SME enabled for EL0 */
 
 #define KVM_GUESTDBG_VALID_MASK (KVM_GUESTDBG_ENABLE | \
 				 KVM_GUESTDBG_USE_SW_BP | \
arch/arm64/kvm/fpsimd.c +36 -0
index 338733ac63f8..1c585553d74f 100644
@@ -82,6 +82,26 @@ void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu)
 
 	if (read_sysreg(cpacr_el1) & CPACR_EL1_ZEN_EL0EN)
 		vcpu->arch.flags |= KVM_ARM64_HOST_SVE_ENABLED;
+
+	/*
+	 * We don't currently support SME guests but if we leave
+	 * things in streaming mode then when the guest starts running
+	 * FPSIMD or SVE code it may generate SME traps so as a
+	 * special case if we are in streaming mode we force the host
+	 * state to be saved now and exit streaming mode so that we
+	 * don't have to handle any SME traps for valid guest
+	 * operations. Do this for ZA as well for now for simplicity.
+	 */
+	if (system_supports_sme()) {
+		if (read_sysreg(cpacr_el1) & CPACR_EL1_SMEN_EL0EN)
+			vcpu->arch.flags |= KVM_ARM64_HOST_SME_ENABLED;
+
+		if (read_sysreg_s(SYS_SVCR_EL0) &
+		    (SYS_SVCR_EL0_SM_MASK | SYS_SVCR_EL0_ZA_MASK)) {
+			vcpu->arch.flags &= ~KVM_ARM64_FP_HOST;
+			fpsimd_save_and_flush_cpu_state();
+		}
+	}
 }
 
 void kvm_arch_vcpu_ctxflush_fp(struct kvm_vcpu *vcpu)
@@ -129,6 +149,22 @@ void kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu)
 
 	local_irq_save(flags);
 
+	/*
+	 * If we have VHE then the Hyp code will reset CPACR_EL1 to
+	 * CPACR_EL1_DEFAULT and we need to reenable SME.
+	 */
+	if (has_vhe() && system_supports_sme()) {
+		/* Also restore EL0 state seen on entry */
+		if (vcpu->arch.flags & KVM_ARM64_HOST_SME_ENABLED)
+			sysreg_clear_set(CPACR_EL1, 0,
+					 CPACR_EL1_SMEN_EL0EN |
+					 CPACR_EL1_SMEN_EL1EN);
+		else
+			sysreg_clear_set(CPACR_EL1,
+					 CPACR_EL1_SMEN_EL0EN,
+					 CPACR_EL1_SMEN_EL1EN);
+	}
+
 	if (vcpu->arch.flags & KVM_ARM64_FP_ENABLED) {
 		if (vcpu_has_sve(vcpu)) {
 			__vcpu_sys_reg(vcpu, ZCR_EL1) = read_sysreg_el1(SYS_ZCR);
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#88 lore raw

PATCH v11 29/40 arm64/sme: Provide Kconfig for SME

In reply to Mark Brown

Now that basline support for the Scalable Matrix Extension (SME) is present introduce the Kconfig option allowing it to be built. While the feature registers don't impose a strong requirement for a system with SME to support SVE at runtime the support for streaming mode SVE is mostly shared with normal SVE so depend on SVE.

---
 arch/arm64/Kconfig | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm64/Kconfig +11 -0
index cbcd42decb2a..4fd7574866cc 100644
@@ -1924,6 +1924,17 @@ config ARM64_SVE
 	  booting the kernel.  If unsure and you are not observing these
 	  symptoms, you should assume that it is safe to say Y.
 
+config ARM64_SME
+	bool "ARM Scalable Matrix Extension support"
+	default y
+	depends on ARM64_SVE
+	help
+	  The Scalable Matrix Extension (SME) is an extension to the AArch64
+	  execution state which utilises a substantial subset of the SVE
+	  instruction set, together with the addition of new architectural
+	  register state capable of holding two dimensional matrix tiles to
+	  enable various matrix operations.
+
 config ARM64_MODULE_PLTS
 	bool "Use PLTs to allow module memory to spill over into vmalloc area"
 	depends on MODULES
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#94 lore raw

PATCH v11 30/40 kselftest/arm64: Add manual encodings for SME instructions

In reply to Mark Brown

As for the kernel so that we don't have ambitious toolchain requirements to build the tests manually encode some of the SVE instructions.

---
 tools/testing/selftests/arm64/fp/sme-inst.h | 51 +++++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 tools/testing/selftests/arm64/fp/sme-inst.h
tools/testing/selftests/arm64/fp/sme-inst.h new file +51 -0
new file mode 100644
index 000000000000..7191e53ca1c0
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// Copyright (C) 2021-2 ARM Limited.
+// Original author: Mark Brown <[email protected]>
+
+#ifndef SME_INST_H
+#define SME_INST_H
+
+/*
+ * RDSVL X\nx, #\imm
+ */
+.macro rdsvl nx, imm
+	.inst	0x4bf5800			\
+		| (\imm << 5)			\
+		| (\nx)
+.endm
+
+.macro smstop
+	msr	S0_3_C4_C6_3, xzr
+.endm
+
+.macro smstart_za
+	msr	S0_3_C4_C5_3, xzr
+.endm
+
+.macro smstart_sm
+	msr	S0_3_C4_C3_3, xzr
+.endm
+
+/*
+ * LDR (vector to ZA array):
+ *	LDR ZA[\nw, #\offset], [X\nxbase, #\offset, MUL VL]
+ */
+.macro _ldr_za nw, nxbase, offset=0
+	.inst	0xe1000000			\
+		| (((\nw) & 3) << 13)		\
+		| ((\nxbase) << 5)		\
+		| ((\offset) & 7)
+.endm
+
+/*
+ * STR (vector from ZA array):
+ *	STR ZA[\nw, #\offset], [X\nxbase, #\offset, MUL VL]
+ */
+.macro _str_za nw, nxbase, offset=0
+	.inst	0xe1200000			\
+		| (((\nw) & 3) << 13)		\
+		| ((\nxbase) << 5)		\
+		| ((\offset) & 7)
+.endm
+
+#endif
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#97 lore raw

PATCH v11 31/40 kselftest/arm64: sme: Add SME support to vlset

In reply to Mark Brown

The Scalable Matrix Extenions (SME) introduces additional register state with configurable vector lengths, similar to SVE but configured separately. Extend vlset to support configuring this state with a --sme or -s command line option.

---
 tools/testing/selftests/arm64/fp/vlset.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tools/testing/selftests/arm64/fp/vlset.c +8 -2
index 308d27a68226..76912a581a95 100644
@@ -22,12 +22,15 @@ static int inherit = 0;
 static int no_inherit = 0;
 static int force = 0;
 static unsigned long vl;
+static int set_ctl = PR_SVE_SET_VL;
+static int get_ctl = PR_SVE_GET_VL;
 
 static const struct option options[] = {
 	{ "force",	no_argument, NULL, 'f' },
 	{ "inherit",	no_argument, NULL, 'i' },
 	{ "max",	no_argument, NULL, 'M' },
 	{ "no-inherit",	no_argument, &no_inherit, 1 },
+	{ "sme",	no_argument, NULL, 's' },
 	{ "help",	no_argument, NULL, '?' },
 	{}
 };
@@ -50,6 +53,9 @@ static int parse_options(int argc, char **argv)
 		case 'M':	vl = SVE_VL_MAX; break;
 		case 'f':	force = 1; break;
 		case 'i':	inherit = 1; break;
+		case 's':	set_ctl = PR_SME_SET_VL;
+				get_ctl = PR_SME_GET_VL;
+				break;
 		case 0:		break;
 		default:	goto error;
 		}
@@ -125,14 +131,14 @@ int main(int argc, char **argv)
 	if (inherit)
 		flags |= PR_SVE_VL_INHERIT;
 
-	t = prctl(PR_SVE_SET_VL, vl | flags);
+	t = prctl(set_ctl, vl | flags);
 	if (t < 0) {
 		fprintf(stderr, "%s: PR_SVE_SET_VL: %s\n",
 			program_name, strerror(errno));
 		goto error;
 	}
 
-	t = prctl(PR_SVE_GET_VL);
+	t = prctl(get_ctl);
 	if (t == -1) {
 		fprintf(stderr, "%s: PR_SVE_GET_VL: %s\n",
 			program_name, strerror(errno));
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#101 lore raw

PATCH v11 32/40 kselftest/arm64: Add tests for TPIDR2

In reply to Mark Brown

The Scalable Matrix Extension adds a new system register TPIDR2 intended to be used by libc for its own thread specific use, add some kselftests which exercise the ABI for it.

Since this test should with some adjustment work for TPIDR and any other similar registers added in future add tests for it in a separate directory rather than placing it with the other floating point tests, nothing existing looked suitable so I created a new test directory called "abi".

Since this feature is intended to be used by libc the test is built as freestanding code using nolibc so we don't end up with the test program and libc both trying to manage the register simultaneously and distrupting each other. As a result of being written using nolibc rather than using hwcaps to identify if SME is available in the system we check for the default SME vector length configuration in proc, adding hwcap support to nolibc seems like disproportionate effort and didn't feel entirely idiomatic for what nolibc is trying to do.

---
 tools/testing/selftests/arm64/abi/.gitignore |   1 +
 tools/testing/selftests/arm64/abi/Makefile   |   9 +-
 tools/testing/selftests/arm64/abi/tpidr2.c   | 298 +++++++++++++++++++
 3 files changed, 307 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/arm64/abi/tpidr2.c
tools/testing/selftests/arm64/abi/.gitignore +1 -0
index b79cf5814c23..b9e54417250d 100644
@@ -1 +1,2 @@
 syscall-abi
+tpidr2
tools/testing/selftests/arm64/abi/Makefile +8 -1
index 96eba974ac8d..c8d7f2495eb2 100644
@@ -1,8 +1,15 @@
 # SPDX-License-Identifier: GPL-2.0
 # Copyright (C) 2021 ARM Limited
 
-TEST_GEN_PROGS := syscall-abi
+TEST_GEN_PROGS := syscall-abi tpidr2
 
 include ../../lib.mk
 
 $(OUTPUT)/syscall-abi: syscall-abi.c syscall-abi-asm.S
+
+# Build with nolibc since TPIDR2 is intended to be actively managed by
+# libc and we're trying to test the functionality that it depends on here.
+$(OUTPUT)/tpidr2: tpidr2.c
+	$(CC) -fno-asynchronous-unwind-tables -fno-ident -s -Os -nostdlib \
+		-static -include ../../../../include/nolibc/nolibc.h \
+		-ffreestanding -Wall $^ -o $@ -lgcc
tools/testing/selftests/arm64/abi/tpidr2.c new file +298 -0

298 lines not on this page · raw message

Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#105 lore raw

PATCH v11 33/40 kselftest/arm64: Extend vector configuration API tests to cover SME

In reply to Mark Brown

Provide RDVL helpers for SME and extend the main vector configuration tests to cover SME.

---
 tools/testing/selftests/arm64/fp/.gitignore   |  1 +
 tools/testing/selftests/arm64/fp/Makefile     |  3 ++-
 tools/testing/selftests/arm64/fp/rdvl-sme.c   | 14 ++++++++++++++
 tools/testing/selftests/arm64/fp/rdvl.S       | 10 ++++++++++
 tools/testing/selftests/arm64/fp/rdvl.h       |  1 +
 tools/testing/selftests/arm64/fp/vec-syscfg.c | 10 ++++++++++
 6 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/arm64/fp/rdvl-sme.c
tools/testing/selftests/arm64/fp/.gitignore +1 -0
index c50d86331ed2..6e9a610c5e5d 100644
@@ -1,5 +1,6 @@
 fp-pidbench
 fpsimd-test
+rdvl-sme
 rdvl-sve
 sve-probe-vls
 sve-ptrace
tools/testing/selftests/arm64/fp/Makefile +2 -1
index 95f0b877a060..a224fff8082b 100644
@@ -3,7 +3,7 @@
 CFLAGS += -I../../../../../usr/include/
 TEST_GEN_PROGS := sve-ptrace sve-probe-vls vec-syscfg
 TEST_PROGS_EXTENDED := fp-pidbench fpsimd-test fpsimd-stress \
-	rdvl-sve \
+	rdvl-sme rdvl-sve \
 	sve-test sve-stress \
 	vlset
 
@@ -13,6 +13,7 @@ fp-pidbench: fp-pidbench.S asm-utils.o
 	$(CC) -nostdlib $^ -o $@
 fpsimd-test: fpsimd-test.o asm-utils.o
 	$(CC) -nostdlib $^ -o $@
+rdvl-sme: rdvl-sme.o rdvl.o
 rdvl-sve: rdvl-sve.o rdvl.o
 sve-ptrace: sve-ptrace.o
 sve-probe-vls: sve-probe-vls.o rdvl.o
tools/testing/selftests/arm64/fp/rdvl-sme.c new file +14 -0
new file mode 100644
index 000000000000..49b0b2e08bac
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <stdio.h>
+
+#include "rdvl.h"
+
+int main(void)
+{
+	int vl = rdvl_sme();
+
+	printf("%d\n", vl);
+
+	return 0;
+}
tools/testing/selftests/arm64/fp/rdvl.S +10 -0
index c916c1c9defd..20dc29996dc6 100644
@@ -1,6 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0-only
 // Copyright (C) 2021 ARM Limited.
 
+#include "sme-inst.h"
+
 .arch_extension sve
 
 .globl rdvl_sve
@@ -8,3 +10,11 @@ rdvl_sve:
 	hint	34			// BTI C
 	rdvl	x0, #1
 	ret
+
+.globl rdvl_sme
+rdvl_sme:
+	hint	34			// BTI C
+
+	rdsvl	0, 1
+
+	ret
tools/testing/selftests/arm64/fp/rdvl.h +1 -0
index 7c9d953fc9e7..5d323679fbc9 100644
@@ -3,6 +3,7 @@
 #ifndef RDVL_H
 #define RDVL_H
 
+int rdvl_sme(void);
 int rdvl_sve(void);
 
 #endif
tools/testing/selftests/arm64/fp/vec-syscfg.c +10 -0
index c90658811a83..9bcfcdc34ee9 100644
@@ -51,6 +51,16 @@ static struct vec_data vec_data[] = {
 		.prctl_set = PR_SVE_SET_VL,
 		.default_vl_file = "/proc/sys/abi/sve_default_vector_length",
 	},
+	{
+		.name = "SME",
+		.hwcap_type = AT_HWCAP2,
+		.hwcap = HWCAP2_SME,
+		.rdvl = rdvl_sme,
+		.rdvl_binary = "./rdvl-sme",
+		.prctl_get = PR_SME_GET_VL,
+		.prctl_set = PR_SME_SET_VL,
+		.default_vl_file = "/proc/sys/abi/sme_default_vector_length",
+	},
 };
 
 static int stdio_read_integer(FILE *f, const char *what, int *val)
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#108 lore raw

PATCH v11 34/40 kselftest/arm64: sme: Provide streaming mode SVE stress test

In reply to Mark Brown

One of the features of SME is the addition of streaming mode, in which we have access to a set of streaming mode SVE registers at the SME vector length. Since these are accessed using the SVE instructions let's reuse the existing SVE stress test for testing with a compile time option for controlling the few small differences needed:

- Enter streaming mode immediately on starting the program.
- In streaming mode FFR is removed so skip reading and writing FFR.

In order to avoid requiring a cutting edge toolchain with SME support use the op/CR form for specifying SVCR.

---
 tools/testing/selftests/arm64/fp/.gitignore  |  1 +
 tools/testing/selftests/arm64/fp/Makefile    |  3 +
 tools/testing/selftests/arm64/fp/ssve-stress | 59 ++++++++++++++++++++
 tools/testing/selftests/arm64/fp/sve-test.S  | 20 +++++++
 4 files changed, 83 insertions(+)
 create mode 100644 tools/testing/selftests/arm64/fp/ssve-stress
tools/testing/selftests/arm64/fp/.gitignore +1 -0
index 6e9a610c5e5d..5729a5b1adfc 100644
@@ -5,5 +5,6 @@ rdvl-sve
 sve-probe-vls
 sve-ptrace
 sve-test
+ssve-test
 vec-syscfg
 vlset
tools/testing/selftests/arm64/fp/Makefile +3 -0
index a224fff8082b..e6643c9b0474 100644
@@ -5,6 +5,7 @@ TEST_GEN_PROGS := sve-ptrace sve-probe-vls vec-syscfg
 TEST_PROGS_EXTENDED := fp-pidbench fpsimd-test fpsimd-stress \
 	rdvl-sme rdvl-sve \
 	sve-test sve-stress \
+	ssve-test ssve-stress \
 	vlset
 
 all: $(TEST_GEN_PROGS) $(TEST_PROGS_EXTENDED)
@@ -19,6 +20,8 @@ sve-ptrace: sve-ptrace.o
 sve-probe-vls: sve-probe-vls.o rdvl.o
 sve-test: sve-test.o asm-utils.o
 	$(CC) -nostdlib $^ -o $@
+ssve-test: sve-test.S asm-utils.o
+	$(CC) -DSSVE -nostdlib $^ -o $@
 vec-syscfg: vec-syscfg.o rdvl.o
 vlset: vlset.o
 
tools/testing/selftests/arm64/fp/ssve-stress new file +59 -0

59 lines not on this page · raw message

tools/testing/selftests/arm64/fp/sve-test.S +20 -0
index f5b1b48ffff2..589264231a2d 100644
@@ -13,6 +13,7 @@
 #include <asm/unistd.h>
 #include "assembler.h"
 #include "asm-offsets.h"
+#include "sme-inst.h"
 
 #define NZR	32
 #define NPR	16
@@ -156,6 +157,7 @@ endfunction
 // We fill the upper lanes of FFR with zeros.
 // Beware: corrupts P0.
 function setup_ffr
+#ifndef SSVE
 	mov	x4, x30
 
 	and	w0, w0, #0x3
@@ -178,6 +180,9 @@ function setup_ffr
 	wrffr	p0.b
 
 	ret	x4
+#else
+	ret
+#endif
 endfunction
 
 // Trivial memory compare: compare x2 bytes starting at address x0 with
@@ -260,6 +265,7 @@ endfunction
 // Beware -- corrupts P0.
 // Clobbers x0-x5.
 function check_ffr
+#ifndef SSVE
 	mov	x3, x30
 
 	ldr	x4, =scratch
@@ -280,6 +286,9 @@ function check_ffr
 	mov	x2, x5
 	mov	x30, x3
 	b	memcmp
+#else
+	ret
+#endif
 endfunction
 
 // Any SVE register modified here can cause corruption in the main
@@ -295,10 +304,12 @@ function irritator_handler
 	movi	v0.8b, #1
 	movi	v9.16b, #2
 	movi	v31.8b, #3
+#ifndef SSVE
 	// And P0
 	rdffr	p0.b
 	// And FFR
 	wrffr	p15.b
+#endif
 
 	ret
 endfunction
@@ -359,6 +370,11 @@ endfunction
 .globl _start
 function _start
 _start:
+#ifdef SSVE
+	puts	"Streaming mode "
+	smstart_sm
+#endif
+
 	// Sanity-check and report the vector length
 
 	rdvl	x19, #8
@@ -407,6 +423,10 @@ _start:
 	orr	w2, w2, #SA_NODEFER
 	bl	setsignal
 
+#ifdef SSVE
+	smstart_sm		// syscalls will have exited streaming mode
+#endif
+
 	mov	x22, #0		// generation number, increments per iteration
 .Ltest_loop:
 	rdvl	x0, #8
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#112 lore raw

PATCH v11 35/40 kselftest/arm64: signal: Handle ZA signal context in core code

In reply to Mark Brown

As part of the generic code for signal handling test cases we parse all signal frames to make sure they have at least the basic form we expect and that there are no unexpected frames present in the signal context. Add coverage of the ZA signal frame to this code.

---
 .../arm64/signal/testcases/testcases.c        | 36 +++++++++++++++++++
 .../arm64/signal/testcases/testcases.h        |  3 +-
 2 files changed, 38 insertions(+), 1 deletion(-)
tools/testing/selftests/arm64/signal/testcases/testcases.c +36 -0
index 8c2a57fc2f9c..84c36bee4d82 100644
@@ -75,6 +75,31 @@ bool validate_sve_context(struct sve_context *sve, char **err)
 	return true;
 }
 
+bool validate_za_context(struct za_context *za, char **err)
+{
+	/* Size will be rounded up to a multiple of 16 bytes */
+	size_t regs_size
+		= ((ZA_SIG_CONTEXT_SIZE(sve_vq_from_vl(za->vl)) + 15) / 16) * 16;
+
+	if (!za || !err)
+		return false;
+
+	/* Either a bare za_context or a za_context followed by regs data */
+	if ((za->head.size != sizeof(struct za_context)) &&
+	    (za->head.size != regs_size)) {
+		*err = "bad size for ZA context";
+		return false;
+	}
+
+	if (!sve_vl_valid(za->vl)) {
+		*err = "SME VL in ZA context invalid";
+
+		return false;
+	}
+
+	return true;
+}
+
 bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err)
 {
 	bool terminated = false;
@@ -82,6 +107,7 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err)
 	int flags = 0;
 	struct extra_context *extra = NULL;
 	struct sve_context *sve = NULL;
+	struct za_context *za = NULL;
 	struct _aarch64_ctx *head =
 		(struct _aarch64_ctx *)uc->uc_mcontext.__reserved;
 
@@ -120,6 +146,13 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err)
 			sve = (struct sve_context *)head;
 			flags |= SVE_CTX;
 			break;
+		case ZA_MAGIC:
+			if (flags & ZA_CTX)
+				*err = "Multiple ZA_MAGIC";
+			/* Size is validated in validate_za_context() */
+			za = (struct za_context *)head;
+			flags |= ZA_CTX;
+			break;
 		case EXTRA_MAGIC:
 			if (flags & EXTRA_CTX)
 				*err = "Multiple EXTRA_MAGIC";
@@ -165,6 +198,9 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err)
 		if (flags & SVE_CTX)
 			if (!validate_sve_context(sve, err))
 				return false;
+		if (flags & ZA_CTX)
+			if (!validate_za_context(za, err))
+				return false;
 
 		head = GET_RESV_NEXT_HEAD(head);
 	}
tools/testing/selftests/arm64/signal/testcases/testcases.h +2 -1
index ad884c135314..49f1d5de7b5b 100644
@@ -16,7 +16,8 @@
 
 #define FPSIMD_CTX	(1 << 0)
 #define SVE_CTX		(1 << 1)
-#define EXTRA_CTX	(1 << 2)
+#define ZA_CTX		(1 << 2)
+#define EXTRA_CTX	(1 << 3)
 
 #define KSFT_BAD_MAGIC	0xdeadbeef
 
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#116 lore raw

PATCH v11 36/40 kselftest/arm64: Add stress test for SME ZA context switching

In reply to Mark Brown

Add a stress test for context switching of the ZA register state based on the similar tests Dave Martin wrote for FPSIMD and SVE registers. The test loops indefinitely writing a data pattern to ZA then reading it back and verifying that it's what was expected.

Unlike the other tests we manually assemble the SME instructions since at present no released toolchain has SME support integrated.

---
 tools/testing/selftests/arm64/fp/.gitignore |   1 +
 tools/testing/selftests/arm64/fp/Makefile   |   3 +
 tools/testing/selftests/arm64/fp/za-stress  |  59 +++
 tools/testing/selftests/arm64/fp/za-test.S  | 388 ++++++++++++++++++++
 4 files changed, 451 insertions(+)
 create mode 100644 tools/testing/selftests/arm64/fp/za-stress
 create mode 100644 tools/testing/selftests/arm64/fp/za-test.S
tools/testing/selftests/arm64/fp/.gitignore +1 -0
index 5729a5b1adfc..ead3197e720b 100644
@@ -8,3 +8,4 @@ sve-test
 ssve-test
 vec-syscfg
 vlset
+za-test
tools/testing/selftests/arm64/fp/Makefile +3 -0
index e6643c9b0474..38d2d0d5a0eb 100644
@@ -6,6 +6,7 @@ TEST_PROGS_EXTENDED := fp-pidbench fpsimd-test fpsimd-stress \
 	rdvl-sme rdvl-sve \
 	sve-test sve-stress \
 	ssve-test ssve-stress \
+	za-test za-stress \
 	vlset
 
 all: $(TEST_GEN_PROGS) $(TEST_PROGS_EXTENDED)
@@ -24,5 +25,7 @@ ssve-test: sve-test.S asm-utils.o
 	$(CC) -DSSVE -nostdlib $^ -o $@
 vec-syscfg: vec-syscfg.o rdvl.o
 vlset: vlset.o
+za-test: za-test.o asm-utils.o
+	$(CC) -nostdlib $^ -o $@
 
 include ../../lib.mk
tools/testing/selftests/arm64/fp/za-stress new file +59 -0

59 lines not on this page · raw message

tools/testing/selftests/arm64/fp/za-test.S new file +388 -0

388 lines not on this page · raw message

Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#118 lore raw

PATCH v11 37/40 kselftest/arm64: signal: Add SME signal handling tests

In reply to Mark Brown

Add test cases for the SME signal handing ABI patterned off the SVE tests. Due to the small size of the tests and the differences in ABI (especially around needing to account for both streaming SVE and ZA) there is some code duplication here.

We currently cover:
- Reporting of the vector length.
- Lack of support for changing vector length.
- Presence and size of register state for streaming SVE and ZA.

As with the SVE tests we do not yet have any validation of register contents.

---
 .../testing/selftests/arm64/signal/.gitignore |   2 +
 .../selftests/arm64/signal/test_signals.h     |   4 +
 .../arm64/signal/test_signals_utils.c         |   6 +
 .../testcases/fake_sigreturn_sme_change_vl.c  |  92 +++++++++++++
 .../arm64/signal/testcases/sme_trap_no_sm.c   |  38 ++++++
 .../signal/testcases/sme_trap_non_streaming.c |  45 ++++++
 .../arm64/signal/testcases/sme_trap_za.c      |  36 +++++
 .../selftests/arm64/signal/testcases/sme_vl.c |  68 +++++++++
 .../arm64/signal/testcases/ssve_regs.c        | 129 ++++++++++++++++++
 9 files changed, 420 insertions(+)
 create mode 100644 tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_sme_change_vl.c
 create mode 100644 tools/testing/selftests/arm64/signal/testcases/sme_trap_no_sm.c
 create mode 100644 tools/testing/selftests/arm64/signal/testcases/sme_trap_non_streaming.c
 create mode 100644 tools/testing/selftests/arm64/signal/testcases/sme_trap_za.c
 create mode 100644 tools/testing/selftests/arm64/signal/testcases/sme_vl.c
 create mode 100644 tools/testing/selftests/arm64/signal/testcases/ssve_regs.c
tools/testing/selftests/arm64/signal/.gitignore +2 -0
index c1742755abb9..4de8eb26d4de 100644
@@ -1,5 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 mangle_*
 fake_sigreturn_*
+sme_*
+ssve_*
 sve_*
 !*.[ch]
tools/testing/selftests/arm64/signal/test_signals.h +4 -0
index f909b70d9e98..c70fdec7d7c4 100644
@@ -34,11 +34,15 @@
 enum {
 	FSSBS_BIT,
 	FSVE_BIT,
+	FSME_BIT,
+	FSME_FA64_BIT,
 	FMAX_END
 };
 
 #define FEAT_SSBS		(1UL << FSSBS_BIT)
 #define FEAT_SVE		(1UL << FSVE_BIT)
+#define FEAT_SME		(1UL << FSME_BIT)
+#define FEAT_SME_FA64		(1UL << FSME_FA64_BIT)
 
 /*
  * A descriptor used to describe and configure a test case.
tools/testing/selftests/arm64/signal/test_signals_utils.c +6 -0
index 5743897984b0..b588d10afd5b 100644
@@ -27,6 +27,8 @@ static int sig_copyctx = SIGTRAP;
 static char const *const feats_names[FMAX_END] = {
 	" SSBS ",
 	" SVE ",
+	" SME ",
+	" FA64 ",
 };
 
 #define MAX_FEATS_SZ	128
@@ -268,6 +270,10 @@ int test_init(struct tdescr *td)
 			td->feats_supported |= FEAT_SSBS;
 		if (getauxval(AT_HWCAP) & HWCAP_SVE)
 			td->feats_supported |= FEAT_SVE;
+		if (getauxval(AT_HWCAP2) & HWCAP2_SME)
+			td->feats_supported |= FEAT_SME;
+		if (getauxval(AT_HWCAP2) & HWCAP2_SME_FA64)
+			td->feats_supported |= FEAT_SME_FA64;
 		if (feats_ok(td)) {
 			if (td->feats_required & td->feats_supported)
 				fprintf(stderr,
tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_sme_change_vl.c new file +92 -0

92 lines not on this page · raw message

tools/testing/selftests/arm64/signal/testcases/sme_trap_no_sm.c new file +38 -0
new file mode 100644
index 000000000000..f9d76ae32bba
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021 ARM Limited
+ *
+ * Verify that using a streaming mode instruction without enabling it
+ * generates a SIGILL.
+ */
+
+#include <signal.h>
+#include <ucontext.h>
+#include <sys/prctl.h>
+
+#include "test_signals_utils.h"
+#include "testcases.h"
+
+int sme_trap_no_sm_trigger(struct tdescr *td)
+{
+	/* SMSTART ZA ; ADDHA ZA0.S, P0/M, P0/M, Z0.S */
+	asm volatile(".inst 0xd503457f ; .inst 0xc0900000");
+
+	return 0;
+}
+
+int sme_trap_no_sm_run(struct tdescr *td, siginfo_t *si, ucontext_t *uc)
+{
+	return 1;
+}
+
+struct tdescr tde = {
+	.name = "SME trap without SM",
+	.descr = "Check that we get a SIGILL if we use streaming mode without enabling it",
+	.timeout = 3,
+	.feats_required = FEAT_SME,   /* We need a SMSTART ZA */
+	.sanity_disabled = true,
+	.trigger = sme_trap_no_sm_trigger,
+	.run = sme_trap_no_sm_run,
+	.sig_ok = SIGILL,
+};
tools/testing/selftests/arm64/signal/testcases/sme_trap_non_streaming.c new file +45 -0

45 lines not on this page · raw message

tools/testing/selftests/arm64/signal/testcases/sme_trap_za.c new file +36 -0
new file mode 100644
index 000000000000..3a7747af4715
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021 ARM Limited
+ *
+ * Verify that accessing ZA without enabling it generates a SIGILL.
+ */
+
+#include <signal.h>
+#include <ucontext.h>
+#include <sys/prctl.h>
+
+#include "test_signals_utils.h"
+#include "testcases.h"
+
+int sme_trap_za_trigger(struct tdescr *td)
+{
+	/* ZERO ZA */
+	asm volatile(".inst 0xc00800ff");
+
+	return 0;
+}
+
+int sme_trap_za_run(struct tdescr *td, siginfo_t *si, ucontext_t *uc)
+{
+	return 1;
+}
+
+struct tdescr tde = {
+	.name = "SME ZA trap",
+	.descr = "Check that we get a SIGILL if we access ZA without enabling",
+	.timeout = 3,
+	.sanity_disabled = true,
+	.trigger = sme_trap_za_trigger,
+	.run = sme_trap_za_run,
+	.sig_ok = SIGILL,
+};
tools/testing/selftests/arm64/signal/testcases/sme_vl.c new file +68 -0

68 lines not on this page · raw message

tools/testing/selftests/arm64/signal/testcases/ssve_regs.c new file +129 -0

129 lines not on this page · raw message

Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#122 lore raw

PATCH v11 38/40 kselftest/arm64: Add streaming SVE to SVE ptrace tests

In reply to Mark Brown

In order to allow ptrace of streaming mode SVE registers we have added a new regset for streaming mode which in isolation offers the same ABI as regular SVE with a different vector type. Add this to the array of regsets we handle, together with additional tests for the interoperation of the two regsets.

---
 tools/testing/selftests/arm64/fp/sve-ptrace.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
tools/testing/selftests/arm64/fp/sve-ptrace.c +11 -0
index 4bd333768cc4..509b875cb7bb 100644
@@ -26,6 +26,10 @@
 #define NT_ARM_SVE 0x405
 #endif
 
+#ifndef NT_ARM_SSVE
+#define NT_ARM_SSVE 0x40b
+#endif
+
 struct vec_type {
 	const char *name;
 	unsigned long hwcap_type;
@@ -42,6 +46,13 @@ static const struct vec_type vec_types[] = {
 		.regset = NT_ARM_SVE,
 		.prctl_set = PR_SVE_SET_VL,
 	},
+	{
+		.name = "Streaming SVE",
+		.hwcap_type = AT_HWCAP2,
+		.hwcap = HWCAP2_SME,
+		.regset = NT_ARM_SSVE,
+		.prctl_set = PR_SME_SET_VL,
+	},
 };
 
 #define VL_TESTS (((SVE_VQ_MAX - SVE_VQ_MIN) + 1) * 3)
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#125 lore raw

PATCH v11 39/40 kselftest/arm64: Add coverage for the ZA ptrace interface

In reply to Mark Brown

Add some basic coverage for the ZA ptrace interface, including walking through all the vector lengths supported in the system. Unlike SVE doing syscalls does not discard the ZA state so when we set data in ZA we run the child process briefly, having it add one to each byte in ZA in order to validate that both the vector size and data are being read and written as expected when the process runs.

---
 tools/testing/selftests/arm64/fp/.gitignore  |   1 +
 tools/testing/selftests/arm64/fp/Makefile    |   3 +-
 tools/testing/selftests/arm64/fp/za-ptrace.c | 354 +++++++++++++++++++
 3 files changed, 357 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/arm64/fp/za-ptrace.c
tools/testing/selftests/arm64/fp/.gitignore +1 -0
index ead3197e720b..d98d3d48b504 100644
@@ -8,4 +8,5 @@ sve-test
 ssve-test
 vec-syscfg
 vlset
+za-ptrace
 za-test
tools/testing/selftests/arm64/fp/Makefile +2 -1
index 38d2d0d5a0eb..807a8faf8d57 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
 CFLAGS += -I../../../../../usr/include/
-TEST_GEN_PROGS := sve-ptrace sve-probe-vls vec-syscfg
+TEST_GEN_PROGS := sve-ptrace sve-probe-vls vec-syscfg za-ptrace
 TEST_PROGS_EXTENDED := fp-pidbench fpsimd-test fpsimd-stress \
 	rdvl-sme rdvl-sve \
 	sve-test sve-stress \
@@ -27,5 +27,6 @@ vec-syscfg: vec-syscfg.o rdvl.o
 vlset: vlset.o
 za-test: za-test.o asm-utils.o
 	$(CC) -nostdlib $^ -o $@
+za-ptrace: za-ptrace.o
 
 include ../../lib.mk
tools/testing/selftests/arm64/fp/za-ptrace.c new file +354 -0

354 lines not on this page · raw message

Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#128 lore raw

PATCH v11 40/40 kselftest/arm64: Add SME support to syscall ABI test

In reply to Mark Brown

For every possible combination of SVE and SME vector length verify that for each possible value of SVCR after a syscall we leave streaming mode and ZA is preserved. We don't need to take account of any streaming/non streaming SVE vector length changes in the assembler code since the store instructions will handle the vector length for us. We log if the system supports FA64 and only try to set FFR in streaming mode if it does.

---
 .../selftests/arm64/abi/syscall-abi-asm.S     |  69 +++++-
 .../testing/selftests/arm64/abi/syscall-abi.c | 204 ++++++++++++++++--
 .../testing/selftests/arm64/abi/syscall-abi.h |  15 ++
 3 files changed, 265 insertions(+), 23 deletions(-)
 create mode 100644 tools/testing/selftests/arm64/abi/syscall-abi.h
tools/testing/selftests/arm64/abi/syscall-abi-asm.S +68 -1
index 983467cfcee0..bc70e04224bf 100644
@@ -9,15 +9,42 @@
 // invoked is configured in x8 of the input GPR data.
 //
 // x0:	SVE VL, 0 for FP only
+// x1:	SME VL
 //
 //	GPRs:	gpr_in, gpr_out
 //	FPRs:	fpr_in, fpr_out
 //	Zn:	z_in, z_out
 //	Pn:	p_in, p_out
 //	FFR:	ffr_in, ffr_out
+//	ZA:	za_in, za_out
+//	SVCR:	svcr_in, svcr_out
+
+#include "syscall-abi.h"
 
 .arch_extension sve
 
+/*
+ * LDR (vector to ZA array):
+ *	LDR ZA[\nw, #\offset], [X\nxbase, #\offset, MUL VL]
+ */
+.macro _ldr_za nw, nxbase, offset=0
+	.inst	0xe1000000			\
+		| (((\nw) & 3) << 13)		\
+		| ((\nxbase) << 5)		\
+		| ((\offset) & 7)
+.endm
+
+/*
+ * STR (vector from ZA array):
+ *	STR ZA[\nw, #\offset], [X\nxbase, #\offset, MUL VL]
+ */
+.macro _str_za nw, nxbase, offset=0
+	.inst	0xe1200000			\
+		| (((\nw) & 3) << 13)		\
+		| ((\nxbase) << 5)		\
+		| ((\offset) & 7)
+.endm
+
 .globl do_syscall
 do_syscall:
 	// Store callee saved registers x19-x29 (80 bytes) plus x0 and x1
@@ -30,6 +57,24 @@ do_syscall:
 	stp	x25, x26, [sp, #80]
 	stp	x27, x28, [sp, #96]
 
+	// Set SVCR if we're doing SME
+	cbz	x1, 1f
+	adrp	x2, svcr_in
+	ldr	x2, [x2, :lo12:svcr_in]
+	msr	S3_3_C4_C2_2, x2
+1:
+
+	// Load ZA if it's enabled - uses x12 as scratch due to SME LDR
+	tbz	x2, #SVCR_ZA_SHIFT, 1f
+	mov	w12, #0
+	ldr	x2, =za_in
+2:	_ldr_za 12, 2
+	add	x2, x2, x1
+	add	x12, x12, #1
+	cmp	x1, x12
+	bne	2b
+1:
+
 	// Load GPRs x8-x28, and save our SP/FP for later comparison
 	ldr	x2, =gpr_in
 	add	x2, x2, #64
@@ -68,7 +113,7 @@ do_syscall:
 	ldp	q30, q31, [x2, #16 * 30]
 1:
 
-	// Load the SVE registers if we're doing SVE
+	// Load the SVE registers if we're doing SVE/SME
 	cbz	x0, 1f
 
 	ldr	x2, =z_in
@@ -105,9 +150,13 @@ do_syscall:
 	ldr	z30, [x2, #30, MUL VL]
 	ldr	z31, [x2, #31, MUL VL]
 
+	// Only set a non-zero FFR, test patterns must be zero since the
+	// syscall should clear it - this lets us handle FA64.
 	ldr	x2, =ffr_in
+	cbz	x2, 2f
 	ldr	p0, [x2, #0]
 	wrffr	p0.b
+2:
 
 	ldr	x2, =p_in
 	ldr	p0, [x2, #0, MUL VL]
@@ -169,6 +218,24 @@ do_syscall:
 	stp	q28, q29, [x2, #16 * 28]
 	stp	q30, q31, [x2, #16 * 30]
 
+	// Save SVCR if we're doing SME
+	cbz	x1, 1f
+	mrs	x2, S3_3_C4_C2_2
+	adrp	x3, svcr_out
+	str	x2, [x3, :lo12:svcr_out]
+1:
+
+	// Save ZA if it's enabled - uses x12 as scratch due to SME STR
+	tbz	x2, #SVCR_ZA_SHIFT, 1f
+	mov	w12, #0
+	ldr	x2, =za_out
+2:	_str_za 12, 2
+	add	x2, x2, x1
+	add	x12, x12, #1
+	cmp	x1, x12
+	bne	2b
+1:
+
 	// Save the SVE state if we have some
 	cbz	x0, 1f
 
tools/testing/selftests/arm64/abi/syscall-abi.c +182 -22

337 lines not on this page · raw message

tools/testing/selftests/arm64/abi/syscall-abi.h new file +15 -0
new file mode 100644
index 000000000000..bda5a87ad381
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2021 ARM Limited.
+ */
+
+#ifndef SYSCALL_ABI_H
+#define SYSCALL_ABI_H
+
+#define SVCR_ZA_MASK		2
+#define SVCR_SM_MASK		1
+
+#define SVCR_ZA_SHIFT		1
+#define SVCR_SM_SHIFT		0
+
+#endif
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
#89 lore raw

Re: [PATCH v11 29/40] arm64/sme: Provide Kconfig for SME

In reply to Mark Brown
I love your patch! Perhaps something to improve:

Hi Mark,

I love your patch! Perhaps something to improve:

[auto build test WARNING on dfd42facf1e4ada021b939b4e19c935dcdd55566]

url:    https://github.com/0day-ci/linux/commits/Mark-Brown/arm64-sme-Initial-support-for-the-Scalable-Matrix-Extension/20220207-233825
base:   dfd42facf1e4ada021b939b4e19c935dcdd55566
config: arm64-randconfig-s032-20220207 (https://download.01.org/0day-ci/archive/20220208/202202080624.bZPyvbcL-lkp(a)intel.com/config)
compiler: aarch64-linux-gcc (GCC) 11.2.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.4-dirty
# https://github.com/0day-ci/linux/commit/3c145e627affeb9240ccaebb147235e09b229b34
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mark-Brown/arm64-sme-Initial-support-for-the-Scalable-Matrix-Extension/20220207-233825
git checkout 3c145e627affeb9240ccaebb147235e09b229b34
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=arm64 SHELL=/bin/bash arch/arm64/kernel/ block/ drivers/nvme/host/ drivers/nvme/target/

If you fix the issue, kindly add following tag as appropriate

sparse warnings: (new ones prefixed by >>)

>> arch/arm64/kernel/signal.c:664:43: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected struct user_ctxs [noderef] __user *user @@     got struct user_ctxs * @@
   arch/arm64/kernel/signal.c:664:43: sparse:     expected struct user_ctxs [noderef] __user *user
   arch/arm64/kernel/signal.c:664:43: sparse:     got struct user_ctxs *
   arch/arm64/kernel/signal.c:936:26: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected void ( [noderef] [usertype] __user *[assigned] [usertype] sigtramp )( ... ) @@     got void * @@
   arch/arm64/kernel/signal.c:936:26: sparse:     expected void ( [noderef] [usertype] __user *[assigned] [usertype] sigtramp )( ... )
   arch/arm64/kernel/signal.c:936:26: sparse:     got void *
>> arch/arm64/kernel/signal.c:395:35: sparse: sparse: dereference of noderef expression
>> arch/arm64/kernel/signal.c:395:35: sparse: sparse: dereference of noderef expression

arch/arm64/kernel/signal.c:429:53: sparse: sparse: dereference of noderef expression arch/arm64/kernel/signal.c:429:53: sparse: sparse: dereference of noderef expression

vim +664 arch/arm64/kernel/signal.c

47ccb02868cead Dave Martin      2017-06-15  621  
2c020ed8d148f7 Catalin Marinas  2012-03-05  622  static int restore_sigframe(struct pt_regs *regs,
2c020ed8d148f7 Catalin Marinas  2012-03-05  623  			    struct rt_sigframe __user *sf)
2c020ed8d148f7 Catalin Marinas  2012-03-05  624  {
2c020ed8d148f7 Catalin Marinas  2012-03-05  625  	sigset_t set;
2c020ed8d148f7 Catalin Marinas  2012-03-05  626  	int i, err;
47ccb02868cead Dave Martin      2017-06-15  627  	struct user_ctxs user;
2c020ed8d148f7 Catalin Marinas  2012-03-05  628  
2c020ed8d148f7 Catalin Marinas  2012-03-05  629  	err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set));
2c020ed8d148f7 Catalin Marinas  2012-03-05  630  	if (err == 0)
2c020ed8d148f7 Catalin Marinas  2012-03-05  631  		set_current_blocked(&set);
2c020ed8d148f7 Catalin Marinas  2012-03-05  632  
2c020ed8d148f7 Catalin Marinas  2012-03-05  633  	for (i = 0; i < 31; i++)
2c020ed8d148f7 Catalin Marinas  2012-03-05  634  		__get_user_error(regs->regs[i], &sf->uc.uc_mcontext.regs[i],
2c020ed8d148f7 Catalin Marinas  2012-03-05  635  				 err);
2c020ed8d148f7 Catalin Marinas  2012-03-05  636  	__get_user_error(regs->sp, &sf->uc.uc_mcontext.sp, err);
2c020ed8d148f7 Catalin Marinas  2012-03-05  637  	__get_user_error(regs->pc, &sf->uc.uc_mcontext.pc, err);
2c020ed8d148f7 Catalin Marinas  2012-03-05  638  	__get_user_error(regs->pstate, &sf->uc.uc_mcontext.pstate, err);
2c020ed8d148f7 Catalin Marinas  2012-03-05  639  
2c020ed8d148f7 Catalin Marinas  2012-03-05  640  	/*
2c020ed8d148f7 Catalin Marinas  2012-03-05  641  	 * Avoid sys_rt_sigreturn() restarting.
2c020ed8d148f7 Catalin Marinas  2012-03-05  642  	 */
17c28958600928 Dave Martin      2017-08-01  643  	forget_syscall(regs);
2c020ed8d148f7 Catalin Marinas  2012-03-05  644  
dbd4d7ca563fd0 Mark Rutland     2016-03-01  645  	err |= !valid_user_regs(&regs->user_regs, current);
47ccb02868cead Dave Martin      2017-06-15  646  	if (err == 0)
47ccb02868cead Dave Martin      2017-06-15  647  		err = parse_user_sigframe(&user, sf);
2c020ed8d148f7 Catalin Marinas  2012-03-05  648  
6d502b6ba1b267 Suzuki K Poulose 2020-01-13  649  	if (err == 0 && system_supports_fpsimd()) {
8cd969d28fd284 Dave Martin      2017-10-31  650  		if (!user.fpsimd)
8cd969d28fd284 Dave Martin      2017-10-31  651  			return -EINVAL;
8cd969d28fd284 Dave Martin      2017-10-31  652  
8cd969d28fd284 Dave Martin      2017-10-31  653  		if (user.sve) {
8cd969d28fd284 Dave Martin      2017-10-31  654  			if (!system_supports_sve())
8cd969d28fd284 Dave Martin      2017-10-31  655  				return -EINVAL;
8cd969d28fd284 Dave Martin      2017-10-31  656  
8cd969d28fd284 Dave Martin      2017-10-31  657  			err = restore_sve_fpsimd_context(&user);
8cd969d28fd284 Dave Martin      2017-10-31  658  		} else {
47ccb02868cead Dave Martin      2017-06-15  659  			err = restore_fpsimd_context(user.fpsimd);
8cd969d28fd284 Dave Martin      2017-10-31  660  		}
8cd969d28fd284 Dave Martin      2017-10-31  661  	}
2c020ed8d148f7 Catalin Marinas  2012-03-05  662  
a884c063c23007 Mark Brown       2022-02-07  663  	if (err == 0 && system_supports_sme() && user.za)
a884c063c23007 Mark Brown       2022-02-07 @664  		err = restore_za_context(&user);
a884c063c23007 Mark Brown       2022-02-07  665  
2c020ed8d148f7 Catalin Marinas  2012-03-05  666  	return err;
2c020ed8d148f7 Catalin Marinas  2012-03-05  667  }
2c020ed8d148f7 Catalin Marinas  2012-03-05  668  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

maintainer Reviewed-by on v11 4/40
#14 lore raw

Re: [PATCH v11 04/40] kselftest/arm64: Remove local ARRAY_SIZE() definitions

In reply to Mark Brown
Quoted 27 lines · Mark Brown

An ARRAY_SIZE() has been added to kselftest.h so remove the local versions in some of the arm64 selftests.

---
  tools/testing/selftests/arm64/abi/syscall-abi.c | 1 -
  tools/testing/selftests/arm64/fp/sve-ptrace.c   | 2 --
  2 files changed, 3 deletions(-)
tools/testing/selftests/arm64/abi/syscall-abi.c +0 -1
index d8eeeafb50dc..1e13b7523918 100644
@@ -18,7 +18,6 @@
 
  #include "../../kselftest.h"
 
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
  #define NUM_VL ((SVE_VQ_MAX - SVE_VQ_MIN) + 1)
 
  extern void do_syscall(int sve_vl);
tools/testing/selftests/arm64/fp/sve-ptrace.c +0 -0
index a3c1e67441f9..4bd333768cc4 100644

tools/testing/selftests/arm64/fp/sve-ptrace.c line 26

Quoted 8 lines
tools/testing/selftests/arm64/fp/sve-ptrace.c +0 -2
@@ -21,8 +21,6 @@
 
  #include "../../kselftest.h"
 
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
-
  /* <linux/elf.h> and <sys/auxv.h> don't like each other, so: */
  #ifndef NT_ARM_SVE
  #define NT_ARM_SVE 0x405

Thank you for cleaning this up.

thanks,
-- Shuah

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer Reviewed-by on v11 5/40
#17 lore raw

Re: [PATCH v11 05/40] kselftest/arm64: signal: Allow tests to be incompatible with features

In reply to Mark Brown
Quoted 90 lines · Mark Brown

Some features may invalidate some tests, for example by supporting an operation which would trap otherwise. Allow tests to list features that they are incompatible with so we can cover the case where a signal will be generated without disruption on systems where that won't happen.

---
  .../selftests/arm64/signal/test_signals.h     |  1 +
  .../arm64/signal/test_signals_utils.c         | 34 ++++++++++++++-----
  .../arm64/signal/test_signals_utils.h         |  2 ++
  3 files changed, 28 insertions(+), 9 deletions(-)
tools/testing/selftests/arm64/signal/test_signals.h +1 -0
index ebe8694dbef0..f909b70d9e98 100644
@@ -53,6 +53,7 @@ struct tdescr {
  	char			*name;
  	char			*descr;
  	unsigned long		feats_required;
+	unsigned long		feats_incompatible;
  	/* bitmask of effectively supported feats: populated at run-time */
  	unsigned long		feats_supported;
  	bool			initialized;
tools/testing/selftests/arm64/signal/test_signals_utils.c +25 -9
index 2f8c23af3b5e..5743897984b0 100644
@@ -36,6 +36,8 @@ static inline char *feats_to_string(unsigned long feats)
  {
  	size_t flen = MAX_FEATS_SZ - 1;
 
+	feats_string[0] = '\0';
+
  	for (int i = 0; i < FMAX_END; i++) {
  		if (feats & (1UL << i)) {
  			size_t tlen = strlen(feats_names[i]);
@@ -256,7 +258,7 @@ int test_init(struct tdescr *td)
  		td->minsigstksz = MINSIGSTKSZ;
  	fprintf(stderr, "Detected MINSTKSIGSZ:%d\n", td->minsigstksz);
 
-	if (td->feats_required) {
+	if (td->feats_required || td->feats_incompatible) {
  		td->feats_supported = 0;
  		/*
  		 * Checking for CPU required features using both the
@@ -267,15 +269,29 @@ int test_init(struct tdescr *td)
  		if (getauxval(AT_HWCAP) & HWCAP_SVE)
  			td->feats_supported |= FEAT_SVE;
  		if (feats_ok(td)) {
-			fprintf(stderr,
-				"Required Features: [%s] supported\n",
-				feats_to_string(td->feats_required &
-						td->feats_supported));
+			if (td->feats_required & td->feats_supported)
+				fprintf(stderr,
+					"Required Features: [%s] supported\n",
+					feats_to_string(td->feats_required &
+							td->feats_supported));
+			if (!(td->feats_incompatible & td->feats_supported))
+				fprintf(stderr,
+					"Incompatible Features: [%s] absent\n",
+					feats_to_string(td->feats_incompatible));
  		} else {
-			fprintf(stderr,
-				"Required Features: [%s] NOT supported\n",
-				feats_to_string(td->feats_required &
-						~td->feats_supported));
+			if ((td->feats_required & td->feats_supported) !=
+			    td->feats_supported)
+				fprintf(stderr,
+					"Required Features: [%s] NOT supported\n",
+					feats_to_string(td->feats_required &
+							~td->feats_supported));
+			if (td->feats_incompatible & td->feats_supported)
+				fprintf(stderr,
+					"Incompatible Features: [%s] supported\n",
+					feats_to_string(td->feats_incompatible &
+							~td->feats_supported));
+
+
  			td->result = KSFT_SKIP;
  			return 0;
  		}
tools/testing/selftests/arm64/signal/test_signals_utils.h +0 -0
index 6772b5c8d274..f3aa99ba67bb 100644

tools/testing/selftests/arm64/signal/test_signals_utils.h void test_result(struct tdescr *td); · line 25

Quoted 8 lines
tools/testing/selftests/arm64/signal/test_signals_utils.h +2 -0
@@ -18,6 +18,8 @@ void test_result(struct tdescr *td);
 
  static inline bool feats_ok(struct tdescr *td)
  {
+	if (td->feats_incompatible & td->feats_supported)
+		return false;
  	return (td->feats_required & td->feats_supported) == td->feats_required;
  }
 

Assuming default_handler() will skip test and return skip test when feature is unsupported?

Looks good to me.

thanks,
-- Shuah

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer Reviewed-by on v11 30/40
#95 lore raw

Re: [PATCH v11 30/40] kselftest/arm64: Add manual encodings for SME instructions

In reply to Mark Brown
Quoted 3 lines · Mark Brown

As for the kernel so that we don't have ambitious toolchain requirements to build the tests manually encode some of the SVE instructions.

Thank you for thinking about toolchain requirements. Please add a bit more information on how these defines are used here in this commit log.

Quoted 2 lines

---

Rest looks good to me.

thanks,
-- Shuah

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer Reviewed-by on v11 6/40
#21 lore raw

Re: [PATCH v11 06/40] arm64/sme: Provide ABI documentation for SME

In reply to Mark Brown

Hi Mark,

Quoted 6 lines · Mark Brown

Provide ABI documentation for SME similar to that for SVE. Due to the very large overlap around streaming SVE mode in both implementation and interfaces documentation for streaming mode SVE is added to the SVE document rather than the SME one.

A few typos and missing SPDX comments below.

Documentation/arm64/sme.rst

Quoted 25 lines
---
  Documentation/arm64/index.rst |   1 +
  Documentation/arm64/sme.rst   | 432 ++++++++++++++++++++++++++++++++++
  Documentation/arm64/sve.rst   |  70 +++++-
  3 files changed, 493 insertions(+), 10 deletions(-)

create mode 100644 Documentation/arm64/sme.rst

Documentation/arm64/index.rst +1 -0
index 4f840bac083e..ae21f8118830 100644
@@ -21,6 +21,7 @@ ARM64 Architecture
      perf
      pointer-authentication
      silicon-errata
+    sme
      sve
      tagged-address-abi
      tagged-pointers
Documentation/arm64/sme.rst new file +0 -0
new file mode 100644
index 000000000000..15df3157c592
@@ -0,0 +1,432 @@

Missing SPDX here?

Documentation/arm64/sme.rst

Quoted 11 lines
Documentation/arm64/sme.rst new file +9 -0
+===================================================
+Scalable Matrix Extension support for AArch64 Linux
+===================================================
+
 
 
+
+When returning from a signal handler:
+
+* If there is no za_context record in the signal frame, or if the record is
+  present but contains no register data as desribed in the previous section,

described

Documentation/arm64/sme.rst line 180

Quoted 9 lines
Documentation/arm64/sme.rst new file +8 -0
+  then ZA is disabled.
+
 
+	PR_SME_SET_VL_ONEXEC
+
+	    Defer the requested vector length change until the next execve()
+	    performed by this thread.
+
+	    The effect is equivalent to implicit exceution of the following

execution

Quoted 15 lines
Documentation/arm64/sme.rst new file +9 -0
+	    call immediately after the next execve() (if any) by the thread:
+
 
+
+[3] Documentation/arm64/cpu-feature-registers.rst
+
+[4] ARM IHI0055C
+    http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055c/IHI0055C_beta_aapcs64.pdf
+    http://infocenter.arm.com/help/topic/com.arm.doc.subset.swdev.abi/index.html
+    Procedure Call Standard for the ARM 64-bit Architecture (AArch64)
Documentation/arm64/sve.rst +0 -0
index 9d9a4de5bc34..93c2c2990584 100644

Documentation/arm64/sve.rst Author: Dave Martin <[email protected]> · line 8

Quoted 2 lines
Documentation/arm64/sve.rst +0 -0
@@ -7,7 +7,9 @@ Author: Dave Martin <[email protected]>
  Date:   4 August 2017
 

Missing SPDX perhaps?

Documentation/arm64/sve.rst Author: Dave Martin <[email protected]> · line 13

Quoted 6 lines
Documentation/arm64/sve.rst +3 -1
  This document outlines briefly the interface provided to userspace by Linux in
-order to support use of the ARM Scalable Vector Extension (SVE).
+order to support use of the ARM Scalable Vector Extension (SVE), including
+interactions with Streaming SVE mode added by the Scalable Matrix Extension
+(SME).
 

Looks good otherwise.

thanks,
-- Shuah

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer Reviewed-by on v11 31/40
#98 lore raw

Re: [PATCH v11 31/40] kselftest/arm64: sme: Add SME support to vlset

In reply to Mark Brown
Quoted 4 lines · Mark Brown

The Scalable Matrix Extenions (SME) introduces additional register state with configurable vector lengths, similar to SVE but configured separately. Extend vlset to support configuring this state with a --sme or -s command line option.

It would be useful to add a -g command to get the current value. -g would just do PR_SVE_GET_VL and print the value perhaps?

Quoted 44 lines
---
  tools/testing/selftests/arm64/fp/vlset.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
tools/testing/selftests/arm64/fp/vlset.c +7 -1
index 308d27a68226..76912a581a95 100644
@@ -22,12 +22,15 @@ static int inherit = 0;
  static int no_inherit = 0;
  static int force = 0;
  static unsigned long vl;
+static int set_ctl = PR_SVE_SET_VL;
+static int get_ctl = PR_SVE_GET_VL;
 
  static const struct option options[] = {
  	{ "force",	no_argument, NULL, 'f' },
  	{ "inherit",	no_argument, NULL, 'i' },
  	{ "max",	no_argument, NULL, 'M' },
  	{ "no-inherit",	no_argument, &no_inherit, 1 },
+	{ "sme",	no_argument, NULL, 's' },
  	{ "help",	no_argument, NULL, '?' },
  	{}
  };
@@ -50,6 +53,9 @@ static int parse_options(int argc, char **argv)
  		case 'M':	vl = SVE_VL_MAX; break;
  		case 'f':	force = 1; break;
  		case 'i':	inherit = 1; break;
+		case 's':	set_ctl = PR_SME_SET_VL;
+				get_ctl = PR_SME_GET_VL;
+				break;
  		case 0:		break;
  		default:	goto error;
  		}
@@ -125,14 +131,14 @@ int main(int argc, char **argv)
  	if (inherit)
  		flags |= PR_SVE_VL_INHERIT;
 
-	t = prctl(PR_SVE_SET_VL, vl | flags);
+	t = prctl(set_ctl, vl | flags);
  	if (t < 0) {

tools/testing/selftests/arm64/fp/vlset.c int main(int argc, char **argv) · line 144

Quoted 10 lines
tools/testing/selftests/arm64/fp/vlset.c +1 -1
  		fprintf(stderr, "%s: PR_SVE_SET_VL: %s\n",
  			program_name, strerror(errno));
  		goto error;
  	}
 
-	t = prctl(PR_SVE_GET_VL);
+	t = prctl(get_ctl);
  	if (t == -1) {
  		fprintf(stderr, "%s: PR_SVE_GET_VL: %s\n",
  			program_name, strerror(errno));

With the above comment addressed or explained:

thanks,
-- Shuah

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer Reviewed-by on v11 32/40
#102 lore raw

Re: [PATCH v11 32/40] kselftest/arm64: Add tests for TPIDR2

In reply to Mark Brown
Quoted 170 lines · Mark Brown

The Scalable Matrix Extension adds a new system register TPIDR2 intended to be used by libc for its own thread specific use, add some kselftests which exercise the ABI for it.

Since this test should with some adjustment work for TPIDR and any other similar registers added in future add tests for it in a separate directory rather than placing it with the other floating point tests, nothing existing looked suitable so I created a new test directory called "abi".

Since this feature is intended to be used by libc the test is built as freestanding code using nolibc so we don't end up with the test program and libc both trying to manage the register simultaneously and distrupting each other. As a result of being written using nolibc rather than using hwcaps to identify if SME is available in the system we check for the default SME vector length configuration in proc, adding hwcap support to nolibc seems like disproportionate effort and didn't feel entirely idiomatic for what nolibc is trying to do.

---
  tools/testing/selftests/arm64/abi/.gitignore |   1 +
  tools/testing/selftests/arm64/abi/Makefile   |   9 +-
  tools/testing/selftests/arm64/abi/tpidr2.c   | 298 +++++++++++++++++++
  3 files changed, 307 insertions(+), 1 deletion(-)

create mode 100644 tools/testing/selftests/arm64/abi/tpidr2.c

tools/testing/selftests/arm64/abi/.gitignore +1 -0
index b79cf5814c23..b9e54417250d 100644
@@ -1 +1,2 @@
  syscall-abi
+tpidr2
tools/testing/selftests/arm64/abi/Makefile +8 -1
index 96eba974ac8d..c8d7f2495eb2 100644
@@ -1,8 +1,15 @@
  # SPDX-License-Identifier: GPL-2.0
  # Copyright (C) 2021 ARM Limited
 
-TEST_GEN_PROGS := syscall-abi
+TEST_GEN_PROGS := syscall-abi tpidr2
 
  include ../../lib.mk
 
  $(OUTPUT)/syscall-abi: syscall-abi.c syscall-abi-asm.S
+
+# Build with nolibc since TPIDR2 is intended to be actively managed by
+# libc and we're trying to test the functionality that it depends on here.
+$(OUTPUT)/tpidr2: tpidr2.c
+	$(CC) -fno-asynchronous-unwind-tables -fno-ident -s -Os -nostdlib \
+		-static -include ../../../../include/nolibc/nolibc.h \
+		-ffreestanding -Wall $^ -o $@ -lgcc
tools/testing/selftests/arm64/abi/tpidr2.c new file +109 -0
new file mode 100644
index 000000000000..351a098b503a
@@ -0,0 +1,298 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/sched.h>
+#include <linux/wait.h>
+
+#define SYS_TPIDR2 "S3_3_C13_C0_5"
+
+#define EXPECTED_TESTS 5
+
+static void putstr(const char *str)
+{
+	write(1, str, strlen(str));
+}
+
+static void putnum(unsigned int num)
+{
+	char c;
+
+	if (num / 10)
+		putnum(num / 10);
+
+	c = '0' + (num % 10);
+	write(1, &c, 1);
+}
+
+static int tests_run;
+static int tests_passed;
+static int tests_failed;
+static int tests_skipped;
+
+static void set_tpidr2(uint64_t val)
+{
+	asm volatile (
+		"msr	" SYS_TPIDR2 ", %0\n"
+		:
+		: "r"(val)
+		: "cc");
+}
+
+static uint64_t get_tpidr2(void)
+{
+	uint64_t val;
+
+	asm volatile (
+		"mrs	%0, " SYS_TPIDR2 "\n"
+		: "=r"(val)
+		:
+		: "cc");
+
+	return val;
+}
+
+static void print_summary(void)
+{
+	if (tests_passed + tests_failed + tests_skipped != EXPECTED_TESTS)
+		putstr("# UNEXPECTED TEST COUNT: ");
+
+	putstr("# Totals: pass:");
+	putnum(tests_passed);
+	putstr(" fail:");
+	putnum(tests_failed);
+	putstr(" xfail:0 xpass:0 skip:");
+	putnum(tests_skipped);
+	putstr(" error:0\n");
+}
+
+/* Processes should start with TPIDR2 == 0 */
+static int default_value(void)
+{
+	return get_tpidr2() == 0;
+}
+
+/* If we set TPIDR2 we should read that value */
+static int write_read(void)
+{
+	set_tpidr2(getpid());
+
+	return getpid() == get_tpidr2();
+}
+
+/* If we set a value we should read the same value after scheduling out */
+static int write_sleep_read(void)
+{
+	set_tpidr2(getpid());
+
+	msleep(100);
+
+	return getpid() == get_tpidr2();
+}
+
+/*
+ * If we fork the value in the parent should be unchanged and the
+ * child should start with the same value and be able to set its own
+ * value.
+ */
+static int write_fork_read(void)
+{
+	pid_t newpid, waiting, oldpid;
+	int status;
+
+	set_tpidr2(getpid());
+
+	oldpid = getpid();
+	newpid = fork();
+	if (newpid == 0) {
+		/* In child */
+		if (get_tpidr2() != oldpid) {
+			putstr("# TPIDR2 changed in child: ");
+			putnum(get_tpidr2());

tools/testing/selftests/arm64/abi/tpidr2.c line 119

Quoted 10 lines
tools/testing/selftests/arm64/abi/tpidr2.c new file +10 -0
+			putstr("\n");
+			exit(0);
+		}
+
+		set_tpidr2(getpid());
+		if (get_tpidr2() == getpid()) {
+			exit(1);
+		} else {
+			putstr("# Failed to set TPIDR2 in child\n");
+			exit(0);

Is this test expected to fail? Is that why it exits with 0 status?

tools/testing/selftests/arm64/abi/tpidr2.c line 126

Quoted 7 lines
tools/testing/selftests/arm64/abi/tpidr2.c new file +7 -0
+		}
+	}
+	if (newpid < 0) {
+		putstr("# fork() failed: -");
+		putnum(-newpid);
+		putstr("\n");
+		return 0;

Same here - returning 0 indicates test passing which could mean a false positive.

Quoted 55 lines
tools/testing/selftests/arm64/abi/tpidr2.c new file +55 -0
+	}
+
+	for (;;) {
+		waiting = waitpid(newpid, &status, 0);
+
+		if (waiting < 0) {
+			if (errno == EINTR)
+				continue;
+			putstr("# waitpid() failed: ");
+			putnum(errno);
+			putstr("\n");
+			return 0;
+		}
+		if (waiting != newpid) {
+			putstr("# waitpid() returned wrong PID\n");
+			return 0;
+		}
+
+		if (!WIFEXITED(status)) {
+			putstr("# child did not exit\n");
+			return 0;
+		}
+
+		if (getpid() != get_tpidr2()) {
+			putstr("# TPIDR2 corrupted in parent\n");
+			return 0;
+		}
+
+		return WEXITSTATUS(status);
+	}
+}
+
+/*
+ * sys_clone() has a lot of per architecture variation so just define
+ * it here rather than adding it to nolibc, plus the raw API is a
+ * little more convenient for this test.
+ */
+static int sys_clone(unsigned long clone_flags, unsigned long newsp,
+		     int *parent_tidptr, unsigned long tls,
+		     int *child_tidptr)
+{
+	return my_syscall5(__NR_clone, clone_flags, newsp, parent_tidptr, tls,
+			   child_tidptr);
+}
+
+/*
+ * If we clone with CLONE_SETTLS then the value in the parent should
+ * be unchanged and the child should start with zero and be able to
+ * set its own value.
+ */
+static int write_clone_read(void)
+{
+	int parent_tid, child_tid;
+	pid_t parent, waiting;
+	int ret, status;

tools/testing/selftests/arm64/abi/tpidr2.c line 191

Quoted 10 lines
tools/testing/selftests/arm64/abi/tpidr2.c new file +10 -0
+
+	parent = getpid();
+	set_tpidr2(parent);
+
+	ret = sys_clone(CLONE_SETTLS, 0, &parent_tid, 0, &child_tid);
+	if (ret == -1) {
+		putstr("# clone() failed\n");
+		putnum(errno);
+		putstr("\n");
+		return 0;

Same commnet here - just making sure there are no false positives

Quoted 98 lines
tools/testing/selftests/arm64/abi/tpidr2.c new file +97 -0
+	}
+
+	if (ret == 0) {
+		/* In child */
+		if (get_tpidr2() != 0) {
+			putstr("# TPIDR2 non-zero in child: ");
+			putnum(get_tpidr2());
+			putstr("\n");
+			exit(0);
+		}
+
+		if (gettid() == 0)
+			putstr("# Child TID==0\n");
+		set_tpidr2(gettid());
+		if (get_tpidr2() == gettid()) {
+			exit(1);
+		} else {
+			putstr("# Failed to set TPIDR2 in child\n");
+			exit(0);
+		}
+	}
+
+	for (;;) {
+		waiting = wait4(ret, &status, __WCLONE, NULL);
+
+		if (waiting < 0) {
+			if (errno == EINTR)
+				continue;
+			putstr("# wait4() failed: ");
+			putnum(errno);
+			putstr("\n");
+			return 0;
+		}
+		if (waiting != ret) {
+			putstr("# wait4() returned wrong PID ");
+			putnum(waiting);
+			putstr("\n");
+			return 0;
+		}
+
+		if (!WIFEXITED(status)) {
+			putstr("# child did not exit\n");
+			return 0;
+		}
+
+		if (parent != get_tpidr2()) {
+			putstr("# TPIDR2 corrupted in parent\n");
+			return 0;
+		}
+
+		return WEXITSTATUS(status);
+	}
+}
+
+#define run_test(name)			     \
+	if (name()) {			     \
+		tests_passed++;		     \
+	} else {			     \
+		tests_failed++;		     \
+		putstr("not ");		     \
+	}				     \
+	putstr("ok ");			     \
+	putnum(++tests_run);		     \
+	putstr(" " #name "\n");
+
+int main(int argc, char **argv)
+{
+	int ret, i;
+
+	putstr("TAP version 13\n");
+	putstr("1..");
+	putnum(EXPECTED_TESTS);
+	putstr("\n");
+
+	putstr("# PID: ");
+	putnum(getpid());
+	putstr("\n");
+
+	/*
+	 * This test is run with nolibc which doesn't support hwcap and
+	 * it's probably disproportionate to implement so instead check
+	 * for the default vector length configuration in /proc.
+	 */
+	ret = open("/proc/sys/abi/sme_default_vector_length", O_RDONLY, 0);
+	if (ret >= 0) {
+		run_test(default_value);
+		run_test(write_read);
+		run_test(write_sleep_read);
+		run_test(write_fork_read);
+		run_test(write_clone_read);
+
+	} else {
+		putstr("# SME support not present\n");
+
+		for (i = 0; i < EXPECTED_TESTS; i++) {
+			putstr("ok ");
+			putnum(i);

tools/testing/selftests/arm64/abi/tpidr2.c line 298

Quoted 10 lines
tools/testing/selftests/arm64/abi/tpidr2.c new file +10 -0
+			putstr(" skipped, TPIDR2 not supported\n");
+		}
+
+		tests_skipped += EXPECTED_TESTS;
+	}
+
+	print_summary();
+
+	return 0;
+}

With the comments explained or addressed:

thanks,
-- Shuah

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer Reviewed-by on v11 33/40
#106 lore raw

Re: [PATCH v11 33/40] kselftest/arm64: Extend vector configuration API tests to cover SME

In reply to Mark Brown
Quoted 115 lines · Mark Brown

Provide RDVL helpers for SME and extend the main vector configuration tests to cover SME.

---
  tools/testing/selftests/arm64/fp/.gitignore   |  1 +
  tools/testing/selftests/arm64/fp/Makefile     |  3 ++-
  tools/testing/selftests/arm64/fp/rdvl-sme.c   | 14 ++++++++++++++
  tools/testing/selftests/arm64/fp/rdvl.S       | 10 ++++++++++
  tools/testing/selftests/arm64/fp/rdvl.h       |  1 +
  tools/testing/selftests/arm64/fp/vec-syscfg.c | 10 ++++++++++
  6 files changed, 38 insertions(+), 1 deletion(-)

create mode 100644 tools/testing/selftests/arm64/fp/rdvl-sme.c

tools/testing/selftests/arm64/fp/.gitignore +1 -0
index c50d86331ed2..6e9a610c5e5d 100644
@@ -1,5 +1,6 @@
  fp-pidbench
  fpsimd-test
+rdvl-sme
  rdvl-sve
  sve-probe-vls
  sve-ptrace
tools/testing/selftests/arm64/fp/Makefile +2 -1
index 95f0b877a060..a224fff8082b 100644
@@ -3,7 +3,7 @@
  CFLAGS += -I../../../../../usr/include/
  TEST_GEN_PROGS := sve-ptrace sve-probe-vls vec-syscfg
  TEST_PROGS_EXTENDED := fp-pidbench fpsimd-test fpsimd-stress \
-	rdvl-sve \
+	rdvl-sme rdvl-sve \
  	sve-test sve-stress \
  	vlset
 
@@ -13,6 +13,7 @@ fp-pidbench: fp-pidbench.S asm-utils.o
  	$(CC) -nostdlib $^ -o $@
  fpsimd-test: fpsimd-test.o asm-utils.o
  	$(CC) -nostdlib $^ -o $@
+rdvl-sme: rdvl-sme.o rdvl.o
  rdvl-sve: rdvl-sve.o rdvl.o
  sve-ptrace: sve-ptrace.o
  sve-probe-vls: sve-probe-vls.o rdvl.o
tools/testing/selftests/arm64/fp/rdvl-sme.c new file +14 -0
new file mode 100644
index 000000000000..49b0b2e08bac
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <stdio.h>
+
+#include "rdvl.h"
+
+int main(void)
+{
+	int vl = rdvl_sme();
+
+	printf("%d\n", vl);
+
+	return 0;
+}
tools/testing/selftests/arm64/fp/rdvl.S +10 -0
index c916c1c9defd..20dc29996dc6 100644
@@ -1,6 +1,8 @@
  // SPDX-License-Identifier: GPL-2.0-only
  // Copyright (C) 2021 ARM Limited.
 
+#include "sme-inst.h"
+
  .arch_extension sve
 
  .globl rdvl_sve
@@ -8,3 +10,11 @@ rdvl_sve:
  	hint	34			// BTI C
  	rdvl	x0, #1
  	ret
+
+.globl rdvl_sme
+rdvl_sme:
+	hint	34			// BTI C
+
+	rdsvl	0, 1
+
+	ret
tools/testing/selftests/arm64/fp/rdvl.h +1 -0
index 7c9d953fc9e7..5d323679fbc9 100644
@@ -3,6 +3,7 @@
  #ifndef RDVL_H
  #define RDVL_H
 
+int rdvl_sme(void);
  int rdvl_sve(void);
 
  #endif
tools/testing/selftests/arm64/fp/vec-syscfg.c +3 -0
index c90658811a83..9bcfcdc34ee9 100644
@@ -51,6 +51,16 @@ static struct vec_data vec_data[] = {
  		.prctl_set = PR_SVE_SET_VL,
  		.default_vl_file = "/proc/sys/abi/sve_default_vector_length",
  	},
+	{
+		.name = "SME",
+		.hwcap_type = AT_HWCAP2,

tools/testing/selftests/arm64/fp/vec-syscfg.c static struct vec_data vec_data[] = { · line 66

Quoted 10 lines
tools/testing/selftests/arm64/fp/vec-syscfg.c +7 -0
+		.hwcap = HWCAP2_SME,
+		.rdvl = rdvl_sme,
+		.rdvl_binary = "./rdvl-sme",
+		.prctl_get = PR_SME_GET_VL,
+		.prctl_set = PR_SME_SET_VL,
+		.default_vl_file = "/proc/sys/abi/sme_default_vector_length",
+	},
  };
 
  static int stdio_read_integer(FILE *f, const char *what, int *val)

Looks good to me.

thanks,
-- Shuah

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer Reviewed-by on v11 34/40
#109 lore raw

Re: [PATCH v11 34/40] kselftest/arm64: sme: Provide streaming mode SVE stress test

In reply to Mark Brown
Quoted 11 lines · Mark Brown

One of the features of SME is the addition of streaming mode, in which we have access to a set of streaming mode SVE registers at the SME vector length. Since these are accessed using the SVE instructions let's reuse the existing SVE stress test for testing with a compile time option for controlling the few small differences needed:

- Enter streaming mode immediately on starting the program.
- In streaming mode FFR is removed so skip reading and writing FFR.

In order to avoid requiring a cutting edge toolchain with SME support use the op/CR form for specifying SVCR.

A few words or pointer to op/CR form would help as education for people that aren't familiar with the form (self included).

Quoted 75 lines
---
  tools/testing/selftests/arm64/fp/.gitignore  |  1 +
  tools/testing/selftests/arm64/fp/Makefile    |  3 +
  tools/testing/selftests/arm64/fp/ssve-stress | 59 ++++++++++++++++++++
  tools/testing/selftests/arm64/fp/sve-test.S  | 20 +++++++
  4 files changed, 83 insertions(+)

create mode 100644 tools/testing/selftests/arm64/fp/ssve-stress

tools/testing/selftests/arm64/fp/.gitignore +1 -0
index 6e9a610c5e5d..5729a5b1adfc 100644
@@ -5,5 +5,6 @@ rdvl-sve
  sve-probe-vls
  sve-ptrace
  sve-test
+ssve-test
  vec-syscfg
  vlset
tools/testing/selftests/arm64/fp/Makefile +3 -0
index a224fff8082b..e6643c9b0474 100644
@@ -5,6 +5,7 @@ TEST_GEN_PROGS := sve-ptrace sve-probe-vls vec-syscfg
  TEST_PROGS_EXTENDED := fp-pidbench fpsimd-test fpsimd-stress \
  	rdvl-sme rdvl-sve \
  	sve-test sve-stress \
+	ssve-test ssve-stress \
  	vlset
 
  all: $(TEST_GEN_PROGS) $(TEST_PROGS_EXTENDED)
@@ -19,6 +20,8 @@ sve-ptrace: sve-ptrace.o
  sve-probe-vls: sve-probe-vls.o rdvl.o
  sve-test: sve-test.o asm-utils.o
  	$(CC) -nostdlib $^ -o $@
+ssve-test: sve-test.S asm-utils.o
+	$(CC) -DSSVE -nostdlib $^ -o $@
  vec-syscfg: vec-syscfg.o rdvl.o
  vlset: vlset.o
 
tools/testing/selftests/arm64/fp/ssve-stress new file +27 -0
new file mode 100644
index 000000000000..e2bd2cc184ad
@@ -0,0 +1,59 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+# Copyright (C) 2015-2019 ARM Limited.
+# Original author: Dave Martin <[email protected]>
+
+set -ue
+
+NR_CPUS=`nproc`
+
+pids=
+logs=
+
+cleanup () {
+	trap - INT TERM CHLD
+	set +e
+
+	if [ -n "$pids" ]; then
+		kill $pids
+		wait $pids
+		pids=
+	fi
+
+	if [ -n "$logs" ]; then
+		cat $logs
+		rm $logs
+		logs=
+	fi

tools/testing/selftests/arm64/fp/ssve-stress line 37

Quoted 10 lines
tools/testing/selftests/arm64/fp/ssve-stress new file +10 -0
+}
+
+interrupt () {
+	cleanup
+	exit 0
+}
+
+child_died () {
+	cleanup
+	exit 1

Is this a failure condition?

tools/testing/selftests/arm64/fp/ssve-stress line 39

Quoted 2 lines
tools/testing/selftests/arm64/fp/ssve-stress new file +2 -0
+}
+

With the comments explained or addressed:

thanks,
-- Shuah

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer Reviewed-by on v11 35/40
#113 lore raw

Re: [PATCH v11 35/40] kselftest/arm64: signal: Handle ZA signal context in core code

In reply to Mark Brown
Quoted 56 lines · Mark Brown

As part of the generic code for signal handling test cases we parse all signal frames to make sure they have at least the basic form we expect and that there are no unexpected frames present in the signal context. Add coverage of the ZA signal frame to this code.

---
  .../arm64/signal/testcases/testcases.c        | 36 +++++++++++++++++++
  .../arm64/signal/testcases/testcases.h        |  3 +-
  2 files changed, 38 insertions(+), 1 deletion(-)
tools/testing/selftests/arm64/signal/testcases/testcases.c +26 -0
index 8c2a57fc2f9c..84c36bee4d82 100644
@@ -75,6 +75,31 @@ bool validate_sve_context(struct sve_context *sve, char **err)
  	return true;
  }
 
+bool validate_za_context(struct za_context *za, char **err)
+{
+	/* Size will be rounded up to a multiple of 16 bytes */
+	size_t regs_size
+		= ((ZA_SIG_CONTEXT_SIZE(sve_vq_from_vl(za->vl)) + 15) / 16) * 16;
+
+	if (!za || !err)
+		return false;
+
+	/* Either a bare za_context or a za_context followed by regs data */
+	if ((za->head.size != sizeof(struct za_context)) &&
+	    (za->head.size != regs_size)) {
+		*err = "bad size for ZA context";
+		return false;
+	}
+
+	if (!sve_vl_valid(za->vl)) {
+		*err = "SME VL in ZA context invalid";
+
+		return false;
+	}
+
+	return true;
+}
+
  bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err)
  {
  	bool terminated = false;
@@ -82,6 +107,7 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err)
  	int flags = 0;
  	struct extra_context *extra = NULL;
  	struct sve_context *sve = NULL;
+	struct za_context *za = NULL;
  	struct _aarch64_ctx *head =
  		(struct _aarch64_ctx *)uc->uc_mcontext.__reserved;
 

tools/testing/selftests/arm64/signal/testcases/testcases.c bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err) · line 151

Quoted 6 lines
tools/testing/selftests/arm64/signal/testcases/testcases.c +3 -0
@@ -120,6 +146,13 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err)
  			sve = (struct sve_context *)head;
  			flags |= SVE_CTX;
  			break;
+		case ZA_MAGIC:
+			if (flags & ZA_CTX)
+				*err = "Multiple ZA_MAGIC";

Is this considered an error?

tools/testing/selftests/arm64/signal/testcases/testcases.c bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err) · line 202

Quoted 13 lines
tools/testing/selftests/arm64/signal/testcases/testcases.c +6 -0
+			/* Size is validated in validate_za_context() */
+			za = (struct za_context *)head;
+			flags |= ZA_CTX;
+			break;
  		case EXTRA_MAGIC:
  			if (flags & EXTRA_CTX)
  				*err = "Multiple EXTRA_MAGIC";
@@ -165,6 +198,9 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err)
  		if (flags & SVE_CTX)
  			if (!validate_sve_context(sve, err))
  				return false;
+		if (flags & ZA_CTX)
+			if (!validate_za_context(za, err))

If validate_za_context() finds an error, the above "Multiple ZA_MAGIC" will be overwritten? Is that the intent?

Quoted 10 lines
tools/testing/selftests/arm64/signal/testcases/testcases.c +1 -0
+				return false;
 
  		head = GET_RESV_NEXT_HEAD(head);
  	}
tools/testing/selftests/arm64/signal/testcases/testcases.h +0 -0
index ad884c135314..49f1d5de7b5b 100644

tools/testing/selftests/arm64/signal/testcases/testcases.h line 23

Quoted 9 lines
tools/testing/selftests/arm64/signal/testcases/testcases.h +2 -1
@@ -16,7 +16,8 @@
 
  #define FPSIMD_CTX	(1 << 0)
  #define SVE_CTX		(1 << 1)
-#define EXTRA_CTX	(1 << 2)
+#define ZA_CTX		(1 << 2)
+#define EXTRA_CTX	(1 << 3)
 
  #define KSFT_BAD_MAGIC	0xdeadbeef
 

With these explained or fixed:

thanks,
-- Shuah
thanks,
-- Shuah

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer Reviewed-by on v11 37/40
#119 lore raw

Re: [PATCH v11 37/40] kselftest/arm64: signal: Add SME signal handling tests

In reply to Mark Brown
Quoted 504 lines · Mark Brown

Add test cases for the SME signal handing ABI patterned off the SVE tests. Due to the small size of the tests and the differences in ABI (especially around needing to account for both streaming SVE and ZA) there is some code duplication here.

We currently cover:
- Reporting of the vector length.
- Lack of support for changing vector length.
- Presence and size of register state for streaming SVE and ZA.

As with the SVE tests we do not yet have any validation of register contents.

---
  .../testing/selftests/arm64/signal/.gitignore |   2 +
  .../selftests/arm64/signal/test_signals.h     |   4 +
  .../arm64/signal/test_signals_utils.c         |   6 +
  .../testcases/fake_sigreturn_sme_change_vl.c  |  92 +++++++++++++
  .../arm64/signal/testcases/sme_trap_no_sm.c   |  38 ++++++
  .../signal/testcases/sme_trap_non_streaming.c |  45 ++++++
  .../arm64/signal/testcases/sme_trap_za.c      |  36 +++++
  .../selftests/arm64/signal/testcases/sme_vl.c |  68 +++++++++
  .../arm64/signal/testcases/ssve_regs.c        | 129 ++++++++++++++++++
  9 files changed, 420 insertions(+)

create mode 100644 tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_sme_change_vl.c create mode 100644 tools/testing/selftests/arm64/signal/testcases/sme_trap_no_sm.c create mode 100644 tools/testing/selftests/arm64/signal/testcases/sme_trap_non_streaming.c create mode 100644 tools/testing/selftests/arm64/signal/testcases/sme_trap_za.c create mode 100644 tools/testing/selftests/arm64/signal/testcases/sme_vl.c create mode 100644 tools/testing/selftests/arm64/signal/testcases/ssve_regs.c

tools/testing/selftests/arm64/signal/.gitignore +2 -0
index c1742755abb9..4de8eb26d4de 100644
@@ -1,5 +1,7 @@
  # SPDX-License-Identifier: GPL-2.0-only
  mangle_*
  fake_sigreturn_*
+sme_*
+ssve_*
  sve_*
  !*.[ch]
tools/testing/selftests/arm64/signal/test_signals.h +4 -0
index f909b70d9e98..c70fdec7d7c4 100644
@@ -34,11 +34,15 @@
  enum {
  	FSSBS_BIT,
  	FSVE_BIT,
+	FSME_BIT,
+	FSME_FA64_BIT,
  	FMAX_END
  };
 
  #define FEAT_SSBS		(1UL << FSSBS_BIT)
  #define FEAT_SVE		(1UL << FSVE_BIT)
+#define FEAT_SME		(1UL << FSME_BIT)
+#define FEAT_SME_FA64		(1UL << FSME_FA64_BIT)
 
  /*
   * A descriptor used to describe and configure a test case.
tools/testing/selftests/arm64/signal/test_signals_utils.c +6 -0
index 5743897984b0..b588d10afd5b 100644
@@ -27,6 +27,8 @@ static int sig_copyctx = SIGTRAP;
  static char const *const feats_names[FMAX_END] = {
  	" SSBS ",
  	" SVE ",
+	" SME ",
+	" FA64 ",
  };
 
  #define MAX_FEATS_SZ	128
@@ -268,6 +270,10 @@ int test_init(struct tdescr *td)
  			td->feats_supported |= FEAT_SSBS;
  		if (getauxval(AT_HWCAP) & HWCAP_SVE)
  			td->feats_supported |= FEAT_SVE;
+		if (getauxval(AT_HWCAP2) & HWCAP2_SME)
+			td->feats_supported |= FEAT_SME;
+		if (getauxval(AT_HWCAP2) & HWCAP2_SME_FA64)
+			td->feats_supported |= FEAT_SME_FA64;
  		if (feats_ok(td)) {
  			if (td->feats_required & td->feats_supported)
  				fprintf(stderr,
tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_sme_change_vl.c new file +92 -0
new file mode 100644
index 000000000000..7ed762b7202f
@@ -0,0 +1,92 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021 ARM Limited
+ *
+ * Attempt to change the streaming SVE vector length in a signal
+ * handler, this is not supported and is expected to segfault.
+ */
+
+#include <signal.h>
+#include <ucontext.h>
+#include <sys/prctl.h>
+
+#include "test_signals_utils.h"
+#include "testcases.h"
+
+struct fake_sigframe sf;
+static unsigned int vls[SVE_VQ_MAX];
+unsigned int nvls = 0;
+
+static bool sme_get_vls(struct tdescr *td)
+{
+	int vq, vl;
+
+	/*
+	 * Enumerate up to SVE_VQ_MAX vector lengths
+	 */
+	for (vq = SVE_VQ_MAX; vq > 0; --vq) {
+		vl = prctl(PR_SVE_SET_VL, vq * 16);
+		if (vl == -1)
+			return false;
+
+		vl &= PR_SME_VL_LEN_MASK;
+
+		/* Skip missing VLs */
+		vq = sve_vq_from_vl(vl);
+
+		vls[nvls++] = vl;
+	}
+
+	/* We need at least two VLs */
+	if (nvls < 2) {
+		fprintf(stderr, "Only %d VL supported\n", nvls);
+		return false;
+	}
+
+	return true;
+}
+
+static int fake_sigreturn_ssve_change_vl(struct tdescr *td,
+					 siginfo_t *si, ucontext_t *uc)
+{
+	size_t resv_sz, offset;
+	struct _aarch64_ctx *head = GET_SF_RESV_HEAD(sf);
+	struct sve_context *sve;
+
+	/* Get a signal context with a SME ZA frame in it */
+	if (!get_current_context(td, &sf.uc))
+		return 1;
+
+	resv_sz = GET_SF_RESV_SIZE(sf);
+	head = get_header(head, SVE_MAGIC, resv_sz, &offset);
+	if (!head) {
+		fprintf(stderr, "No SVE context\n");
+		return 1;
+	}
+
+	if (head->size != sizeof(struct sve_context)) {
+		fprintf(stderr, "Register data present, aborting\n");
+		return 1;
+	}
+
+	sve = (struct sve_context *)head;
+
+	/* No changes are supported; init left us at minimum VL so go to max */
+	fprintf(stderr, "Attempting to change VL from %d to %d\n",
+		sve->vl, vls[0]);
+	sve->vl = vls[0];
+
+	fake_sigreturn(&sf, sizeof(sf), 0);
+
+	return 1;
+}
+
+struct tdescr tde = {
+	.name = "FAKE_SIGRETURN_SSVE_CHANGE",
+	.descr = "Attempt to change Streaming SVE VL",
+	.feats_required = FEAT_SME,
+	.sig_ok = SIGSEGV,
+	.timeout = 3,
+	.init = sme_get_vls,
+	.run = fake_sigreturn_ssve_change_vl,
+};
tools/testing/selftests/arm64/signal/testcases/sme_trap_no_sm.c new file +38 -0
new file mode 100644
index 000000000000..f9d76ae32bba
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021 ARM Limited
+ *
+ * Verify that using a streaming mode instruction without enabling it
+ * generates a SIGILL.
+ */
+
+#include <signal.h>
+#include <ucontext.h>
+#include <sys/prctl.h>
+
+#include "test_signals_utils.h"
+#include "testcases.h"
+
+int sme_trap_no_sm_trigger(struct tdescr *td)
+{
+	/* SMSTART ZA ; ADDHA ZA0.S, P0/M, P0/M, Z0.S */
+	asm volatile(".inst 0xd503457f ; .inst 0xc0900000");
+
+	return 0;
+}
+
+int sme_trap_no_sm_run(struct tdescr *td, siginfo_t *si, ucontext_t *uc)
+{
+	return 1;
+}
+
+struct tdescr tde = {
+	.name = "SME trap without SM",
+	.descr = "Check that we get a SIGILL if we use streaming mode without enabling it",
+	.timeout = 3,
+	.feats_required = FEAT_SME,   /* We need a SMSTART ZA */
+	.sanity_disabled = true,
+	.trigger = sme_trap_no_sm_trigger,
+	.run = sme_trap_no_sm_run,
+	.sig_ok = SIGILL,
+};
tools/testing/selftests/arm64/signal/testcases/sme_trap_non_streaming.c new file +45 -0
new file mode 100644
index 000000000000..e469ae5348e3
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021 ARM Limited
+ *
+ * Verify that using an instruction not supported in streaming mode
+ * traps when in streaming mode.
+ */
+
+#include <signal.h>
+#include <ucontext.h>
+#include <sys/prctl.h>
+
+#include "test_signals_utils.h"
+#include "testcases.h"
+
+int sme_trap_non_streaming_trigger(struct tdescr *td)
+{
+	/*
+	 * The framework will handle SIGILL so we need to exit SM to
+	 * stop any other code triggering a further SIGILL down the
+	 * line from using a streaming-illegal instruction.
+	 */
+	asm volatile(".inst 0xd503437f; /* SMSTART ZA */ \
+		      cnt v0.16b, v0.16b; \
+                      .inst 0xd503447f  /* SMSTOP ZA */");
+
+	return 0;
+}
+
+int sme_trap_non_streaming_run(struct tdescr *td, siginfo_t *si, ucontext_t *uc)
+{
+	return 1;
+}
+
+struct tdescr tde = {
+	.name = "SME SM trap unsupported instruction",
+	.descr = "Check that we get a SIGILL if we use an unsupported instruction in streaming mode",
+	.feats_required = FEAT_SME,
+	.feats_incompatible = FEAT_SME_FA64,
+	.timeout = 3,
+	.sanity_disabled = true,
+	.trigger = sme_trap_non_streaming_trigger,
+	.run = sme_trap_non_streaming_run,
+	.sig_ok = SIGILL,
+};
tools/testing/selftests/arm64/signal/testcases/sme_trap_za.c new file +36 -0
new file mode 100644
index 000000000000..3a7747af4715
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021 ARM Limited
+ *
+ * Verify that accessing ZA without enabling it generates a SIGILL.
+ */
+
+#include <signal.h>
+#include <ucontext.h>
+#include <sys/prctl.h>
+
+#include "test_signals_utils.h"
+#include "testcases.h"
+
+int sme_trap_za_trigger(struct tdescr *td)
+{
+	/* ZERO ZA */
+	asm volatile(".inst 0xc00800ff");
+
+	return 0;
+}
+
+int sme_trap_za_run(struct tdescr *td, siginfo_t *si, ucontext_t *uc)
+{
+	return 1;
+}
+
+struct tdescr tde = {
+	.name = "SME ZA trap",
+	.descr = "Check that we get a SIGILL if we access ZA without enabling",
+	.timeout = 3,
+	.sanity_disabled = true,
+	.trigger = sme_trap_za_trigger,
+	.run = sme_trap_za_run,
+	.sig_ok = SIGILL,
+};
tools/testing/selftests/arm64/signal/testcases/sme_vl.c new file +68 -0
new file mode 100644
index 000000000000..13ff3b35cbaf
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021 ARM Limited
+ *
+ * Check that the SME vector length reported in signal contexts is the
+ * expected one.
+ */
+
+#include <signal.h>
+#include <ucontext.h>
+#include <sys/prctl.h>
+
+#include "test_signals_utils.h"
+#include "testcases.h"
+
+struct fake_sigframe sf;
+unsigned int vl;
+
+static bool get_sme_vl(struct tdescr *td)
+{
+	int ret = prctl(PR_SME_GET_VL);
+	if (ret == -1)
+		return false;
+
+	vl = ret;
+
+	return true;
+}
+
+static int sme_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc)
+{
+	size_t resv_sz, offset;
+	struct _aarch64_ctx *head = GET_SF_RESV_HEAD(sf);
+	struct za_context *za;
+
+	/* Get a signal context which should have a ZA frame in it */
+	if (!get_current_context(td, &sf.uc))
+		return 1;
+
+	resv_sz = GET_SF_RESV_SIZE(sf);
+	head = get_header(head, ZA_MAGIC, resv_sz, &offset);
+	if (!head) {
+		fprintf(stderr, "No ZA context\n");
+		return 1;
+	}
+	za = (struct za_context *)head;
+
+	if (za->vl != vl) {
+		fprintf(stderr, "ZA sigframe VL %u, expected %u\n",
+			za->vl, vl);
+		return 1;
+	} else {
+		fprintf(stderr, "got expected VL %u\n", vl);
+	}
+
+	td->pass = 1;
+
+	return 0;
+}
+
+struct tdescr tde = {
+	.name = "SME VL",
+	.descr = "Check that we get the right SME VL reported",
+	.feats_required = FEAT_SME,
+	.timeout = 3,
+	.init = get_sme_vl,
+	.run = sme_vl,
+};
tools/testing/selftests/arm64/signal/testcases/ssve_regs.c new file +101 -0
new file mode 100644
index 000000000000..6150862a9cde
@@ -0,0 +1,129 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021 ARM Limited
+ *
+ * Verify that the streaming SVE register context in signal frames is
+ * set up as expected.
+ */
+
+#include <signal.h>
+#include <ucontext.h>
+#include <sys/prctl.h>
+
+#include "test_signals_utils.h"
+#include "testcases.h"
+
+struct fake_sigframe sf;
+static unsigned int vls[SVE_VQ_MAX];
+unsigned int nvls = 0;
+
+static bool sme_get_vls(struct tdescr *td)
+{
+	int vq, vl;
+
+	/*
+	 * Enumerate up to SVE_VQ_MAX vector lengths
+	 */
+	for (vq = SVE_VQ_MAX; vq > 0; --vq) {
+		vl = prctl(PR_SVE_SET_VL, vq * 16);
+		if (vl == -1)
+			return false;
+
+		vl &= PR_SME_VL_LEN_MASK;
+
+		/* Skip missing VLs */
+		vq = sve_vq_from_vl(vl);
+
+		vls[nvls++] = vl;
+	}
+
+	/* We need at least one VL */
+	if (nvls < 1) {
+		fprintf(stderr, "Only %d VL supported\n", nvls);
+		return false;
+	}
+
+	return true;
+}
+
+static void setup_ssve_regs(void)
+{
+	/* SMSTART SM */
+	asm volatile(".inst 0x7f4303d5");
+
+	/* RDVL x16, #1 so we should have SVE regs; real data is TODO */
+	asm volatile(".inst 0x04bf5030" : : : "x16" );
+}
+
+static int do_one_sme_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc,
+			 unsigned int vl)
+{
+	size_t resv_sz, offset;
+	struct _aarch64_ctx *head = GET_SF_RESV_HEAD(sf);
+	struct sve_context *ssve;
+
+	fprintf(stderr, "Testing VL %d\n", vl);
+
+	if (prctl(PR_SME_SET_VL, vl) == -1) {
+		fprintf(stderr, "Failed to set VL\n");
+		return 1;
+	}
+
+	/*
+	 * Get a signal context which should have a SVE frame and registers
+	 * in it.
+	 */
+	setup_ssve_regs();
+	if (!get_current_context(td, &sf.uc))
+		return 1;
+
+	resv_sz = GET_SF_RESV_SIZE(sf);
+	head = get_header(head, SVE_MAGIC, resv_sz, &offset);
+	if (!head) {
+		fprintf(stderr, "No SVE context\n");
+		return 1;
+	}
+
+	ssve = (struct sve_context *)head;
+	if (ssve->vl != vl) {
+		fprintf(stderr, "Got VL %d, expected %d\n", ssve->vl, vl);
+		return 1;
+	}
+
+	/* The actual size validation is done in get_current_context() */
+	fprintf(stderr, "Got expected size %u and VL %d\n",
+		head->size, ssve->vl);
+
+	return 0;
+}
+
+static int sme_regs(struct tdescr *td, siginfo_t *si, ucontext_t *uc)
+{

tools/testing/selftests/arm64/signal/testcases/ssve_regs.c line 111

Quoted 10 lines
tools/testing/selftests/arm64/signal/testcases/ssve_regs.c new file +10 -0
+	int i;
+
+	for (i = 0; i < nvls; i++) {
+		/*
+		 * TODO: the signal test helpers can't currently cope
+		 * with signal frames bigger than struct sigcontext,
+		 * skip VLs that will trigger that.
+		 */
+		if (vls[i] > 64)
+			continue;

Count the skipped VLs and print counts - helps see how many are skipped.

Quoted 9 lines
tools/testing/selftests/arm64/signal/testcases/ssve_regs.c new file +8 -0
+
+		if (do_one_sme_vl(td, si, uc, vls[i]))
+			return 1;
+	}
+
+	td->pass = 1;
+
+	return 0;

tools/testing/selftests/arm64/signal/testcases/ssve_regs.c line 129

Quoted 10 lines
tools/testing/selftests/arm64/signal/testcases/ssve_regs.c new file +10 -0
+}
+
+struct tdescr tde = {
+	.name = "Streaming SVE registers",
+	.descr = "Check that we get the right Streaming SVE registers reported",
+	.feats_required = FEAT_SME,
+	.timeout = 3,
+	.init = sme_get_vls,
+	.run = sme_regs,
+};

With these explained or fixed:

thanks,
-- Shuah

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer Reviewed-by on v11 38/40
#123 lore raw

Re: [PATCH v11 38/40] kselftest/arm64: Add streaming SVE to SVE ptrace tests

In reply to Mark Brown
Quoted 31 lines · Mark Brown

In order to allow ptrace of streaming mode SVE registers we have added a new regset for streaming mode which in isolation offers the same ABI as regular SVE with a different vector type. Add this to the array of regsets we handle, together with additional tests for the interoperation of the two regsets.

---
  tools/testing/selftests/arm64/fp/sve-ptrace.c | 11 +++++++++++
  1 file changed, 11 insertions(+)
tools/testing/selftests/arm64/fp/sve-ptrace.c +4 -0
index 4bd333768cc4..509b875cb7bb 100644
@@ -26,6 +26,10 @@
  #define NT_ARM_SVE 0x405
  #endif
 
+#ifndef NT_ARM_SSVE
+#define NT_ARM_SSVE 0x40b
+#endif
+
  struct vec_type {
  	const char *name;
  	unsigned long hwcap_type;
@@ -42,6 +46,13 @@ static const struct vec_type vec_types[] = {
  		.regset = NT_ARM_SVE,
  		.prctl_set = PR_SVE_SET_VL,
  	},

tools/testing/selftests/arm64/fp/sve-ptrace.c static const struct vec_type vec_types[] = { · line 58

Quoted 10 lines
tools/testing/selftests/arm64/fp/sve-ptrace.c +7 -0
+	{
+		.name = "Streaming SVE",
+		.hwcap_type = AT_HWCAP2,
+		.hwcap = HWCAP2_SME,
+		.regset = NT_ARM_SSVE,
+		.prctl_set = PR_SME_SET_VL,
+	},
  };
 
  #define VL_TESTS (((SVE_VQ_MAX - SVE_VQ_MIN) + 1) * 3)

Looks good to me.

thanks,
-- Shuah

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer Reviewed-by on v11 39/40
#126 lore raw

Re: [PATCH v11 39/40] kselftest/arm64: Add coverage for the ZA ptrace interface

In reply to Mark Brown
Quoted 102 lines · Mark Brown

Add some basic coverage for the ZA ptrace interface, including walking through all the vector lengths supported in the system. Unlike SVE doing syscalls does not discard the ZA state so when we set data in ZA we run the child process briefly, having it add one to each byte in ZA in order to validate that both the vector size and data are being read and written as expected when the process runs.

---
  tools/testing/selftests/arm64/fp/.gitignore  |   1 +
  tools/testing/selftests/arm64/fp/Makefile    |   3 +-
  tools/testing/selftests/arm64/fp/za-ptrace.c | 354 +++++++++++++++++++
  3 files changed, 357 insertions(+), 1 deletion(-)

create mode 100644 tools/testing/selftests/arm64/fp/za-ptrace.c

tools/testing/selftests/arm64/fp/.gitignore +1 -0
index ead3197e720b..d98d3d48b504 100644
@@ -8,4 +8,5 @@ sve-test
  ssve-test
  vec-syscfg
  vlset
+za-ptrace
  za-test
tools/testing/selftests/arm64/fp/Makefile +2 -1
index 38d2d0d5a0eb..807a8faf8d57 100644
@@ -1,7 +1,7 @@
  # SPDX-License-Identifier: GPL-2.0
 
  CFLAGS += -I../../../../../usr/include/
-TEST_GEN_PROGS := sve-ptrace sve-probe-vls vec-syscfg
+TEST_GEN_PROGS := sve-ptrace sve-probe-vls vec-syscfg za-ptrace
  TEST_PROGS_EXTENDED := fp-pidbench fpsimd-test fpsimd-stress \
  	rdvl-sme rdvl-sve \
  	sve-test sve-stress \
@@ -27,5 +27,6 @@ vec-syscfg: vec-syscfg.o rdvl.o
  vlset: vlset.o
  za-test: za-test.o asm-utils.o
  	$(CC) -nostdlib $^ -o $@
+za-ptrace: za-ptrace.o
 
  include ../../lib.mk
tools/testing/selftests/arm64/fp/za-ptrace.c new file +51 -0
new file mode 100644
index 000000000000..692c82624855
@@ -0,0 +1,354 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2021 ARM Limited.
+ */
+#include <errno.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/auxv.h>
+#include <sys/prctl.h>
+#include <sys/ptrace.h>
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <sys/wait.h>
+#include <asm/sigcontext.h>
+#include <asm/ptrace.h>
+
+#include "../../kselftest.h"
+
+/* <linux/elf.h> and <sys/auxv.h> don't like each other, so: */
+#ifndef NT_ARM_ZA
+#define NT_ARM_ZA 0x40c
+#endif
+
+#define EXPECTED_TESTS (((SVE_VQ_MAX - SVE_VQ_MIN) + 1) * 3)
+
+static void fill_buf(char *buf, size_t size)
+{
+	int i;
+
+	for (i = 0; i < size; i++)
+		buf[i] = random();
+}
+
+static int do_child(void)
+{
+	if (ptrace(PTRACE_TRACEME, -1, NULL, NULL))
+		ksft_exit_fail_msg("PTRACE_TRACEME", strerror(errno));
+
+	if (raise(SIGSTOP))
+		ksft_exit_fail_msg("raise(SIGSTOP)", strerror(errno));
+
+	return EXIT_SUCCESS;
+}
+
+static struct user_za_header *get_za(pid_t pid, void **buf, size_t *size)
+{
+	struct user_za_header *za;

tools/testing/selftests/arm64/fp/za-ptrace.c line 61

Quoted 10 lines
tools/testing/selftests/arm64/fp/za-ptrace.c new file +10 -0
+	void *p;
+	size_t sz = sizeof(*za);
+	struct iovec iov;
+
+	while (1) {
+		if (*size < sz) {
+			p = realloc(*buf, sz);
+			if (!p) {
+				errno = ENOMEM;
+				goto error;

Do we free buf in error path? Didn't see it in error handling below.

Quoted 11 lines
tools/testing/selftests/arm64/fp/za-ptrace.c new file +11 -0
+			}
+
+			*buf = p;
+			*size = sz;
+		}
+
+		iov.iov_base = *buf;
+		iov.iov_len = sz;
+		if (ptrace(PTRACE_GETREGSET, pid, NT_ARM_ZA, &iov))
+			goto error;
+

tools/testing/selftests/arm64/fp/za-ptrace.c line 82

Quoted 10 lines
tools/testing/selftests/arm64/fp/za-ptrace.c new file +10 -0
+		za = *buf;
+		if (za->size <= sz)
+			break;
+
+		sz = za->size;
+	}
+
+	return za;
+
+error:

Free buf?

tools/testing/selftests/arm64/fp/za-ptrace.c line 85

Quoted 3 lines
tools/testing/selftests/arm64/fp/za-ptrace.c new file +3 -0
+	return NULL;
+}
+

Rest looked okay.

thanks,
-- Shuah

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer Reviewed-by on v11 40/40
#129 lore raw

Re: [PATCH v11 40/40] kselftest/arm64: Add SME support to syscall ABI test

In reply to Mark Brown
Quoted 207 lines · Mark Brown

For every possible combination of SVE and SME vector length verify that for each possible value of SVCR after a syscall we leave streaming mode and ZA is preserved. We don't need to take account of any streaming/non streaming SVE vector length changes in the assembler code since the store instructions will handle the vector length for us. We log if the system supports FA64 and only try to set FFR in streaming mode if it does.

---
  .../selftests/arm64/abi/syscall-abi-asm.S     |  69 +++++-
  .../testing/selftests/arm64/abi/syscall-abi.c | 204 ++++++++++++++++--
  .../testing/selftests/arm64/abi/syscall-abi.h |  15 ++
  3 files changed, 265 insertions(+), 23 deletions(-)

create mode 100644 tools/testing/selftests/arm64/abi/syscall-abi.h

tools/testing/selftests/arm64/abi/syscall-abi.c +76 -15
index 1e13b7523918..b632bfe9e022 100644
@@ -18,9 +18,13 @@
 
  #include "../../kselftest.h"
 
+#include "syscall-abi.h"
+
  #define NUM_VL ((SVE_VQ_MAX - SVE_VQ_MIN) + 1)
 
-extern void do_syscall(int sve_vl);
+static int default_sme_vl;
+
+extern void do_syscall(int sve_vl, int sme_vl);
 
  static void fill_random(void *buf, size_t size)
  {
@@ -48,14 +52,15 @@ static struct syscall_cfg {
  uint64_t gpr_in[NUM_GPR];
  uint64_t gpr_out[NUM_GPR];
 
-static void setup_gpr(struct syscall_cfg *cfg, int sve_vl)
+static void setup_gpr(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
+		      uint64_t svcr)
  {
  	fill_random(gpr_in, sizeof(gpr_in));
  	gpr_in[8] = cfg->syscall_nr;
  	memset(gpr_out, 0, sizeof(gpr_out));
  }
 
-static int check_gpr(struct syscall_cfg *cfg, int sve_vl)
+static int check_gpr(struct syscall_cfg *cfg, int sve_vl, int sme_vl, uint64_t svcr)
  {
  	int errors = 0;
  	int i;
@@ -79,13 +84,15 @@ static int check_gpr(struct syscall_cfg *cfg, int sve_vl)
  uint64_t fpr_in[NUM_FPR * 2];
  uint64_t fpr_out[NUM_FPR * 2];
 
-static void setup_fpr(struct syscall_cfg *cfg, int sve_vl)
+static void setup_fpr(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
+		      uint64_t svcr)
  {
  	fill_random(fpr_in, sizeof(fpr_in));
  	memset(fpr_out, 0, sizeof(fpr_out));
  }
 
-static int check_fpr(struct syscall_cfg *cfg, int sve_vl)
+static int check_fpr(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
+		     uint64_t svcr)
  {
  	int errors = 0;
  	int i;
@@ -109,13 +116,15 @@ static uint8_t z_zero[__SVE_ZREG_SIZE(SVE_VQ_MAX)];
  uint8_t z_in[SVE_NUM_PREGS * __SVE_ZREG_SIZE(SVE_VQ_MAX)];
  uint8_t z_out[SVE_NUM_PREGS * __SVE_ZREG_SIZE(SVE_VQ_MAX)];
 
-static void setup_z(struct syscall_cfg *cfg, int sve_vl)
+static void setup_z(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
+		    uint64_t svcr)
  {
  	fill_random(z_in, sizeof(z_in));
  	fill_random(z_out, sizeof(z_out));
  }
 
-static int check_z(struct syscall_cfg *cfg, int sve_vl)
+static int check_z(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
+		   uint64_t svcr)
  {
  	size_t reg_size = sve_vl;
  	int errors = 0;
@@ -126,13 +135,17 @@ static int check_z(struct syscall_cfg *cfg, int sve_vl)
 
  	/*
  	 * After a syscall the low 128 bits of the Z registers should
-	 * be preserved and the rest be zeroed or preserved.
+	 * be preserved and the rest be zeroed or preserved, except if
+	 * we were in streaming mode in which case the low 128 bits may
+	 * also be cleared by the transition out of streaming mode.
  	 */
  	for (i = 0; i < SVE_NUM_ZREGS; i++) {
  		void *in = &z_in[reg_size * i];
  		void *out = &z_out[reg_size * i];
 
-		if (memcmp(in, out, SVE_VQ_BYTES) != 0) {
+		if ((memcmp(in, out, SVE_VQ_BYTES) != 0) &&
+		    !((svcr & SVCR_SM_MASK) &&
+		      memcmp(z_zero, out, SVE_VQ_BYTES) == 0)) {
  			ksft_print_msg("%s SVE VL %d Z%d low 128 bits changed\n",
  				       cfg->name, sve_vl, i);
  			errors++;
@@ -145,13 +158,15 @@ static int check_z(struct syscall_cfg *cfg, int sve_vl)
  uint8_t p_in[SVE_NUM_PREGS * __SVE_PREG_SIZE(SVE_VQ_MAX)];
  uint8_t p_out[SVE_NUM_PREGS * __SVE_PREG_SIZE(SVE_VQ_MAX)];
 
-static void setup_p(struct syscall_cfg *cfg, int sve_vl)
+static void setup_p(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
+		    uint64_t svcr)
  {
  	fill_random(p_in, sizeof(p_in));
  	fill_random(p_out, sizeof(p_out));
  }
 
-static int check_p(struct syscall_cfg *cfg, int sve_vl)
+static int check_p(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
+		   uint64_t svcr)
  {
  	size_t reg_size = sve_vq_from_vl(sve_vl) * 2; /* 1 bit per VL byte */
 
@@ -175,8 +190,19 @@ static int check_p(struct syscall_cfg *cfg, int sve_vl)
  uint8_t ffr_in[__SVE_PREG_SIZE(SVE_VQ_MAX)];
  uint8_t ffr_out[__SVE_PREG_SIZE(SVE_VQ_MAX)];
 
-static void setup_ffr(struct syscall_cfg *cfg, int sve_vl)
+static void setup_ffr(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
+		      uint64_t svcr)
  {
+	/*
+	 * If we are in streaming mode and do not have FA64 then FFR
+	 * is unavailable.
+	 */
+	if ((svcr & SVCR_SM_MASK) &&
+	    !(getauxval(AT_HWCAP2) & HWCAP2_SME_FA64)) {
+		memset(&ffr_in, 0, sizeof(ffr_in));
+		return;
+	}
+
  	/*
  	 * It is only valid to set a contiguous set of bits starting
  	 * at 0.  For now since we're expecting this to be cleared by
@@ -186,7 +212,8 @@ static void setup_ffr(struct syscall_cfg *cfg, int sve_vl)
  	fill_random(ffr_out, sizeof(ffr_out));
  }
 
-static int check_ffr(struct syscall_cfg *cfg, int sve_vl)
+static int check_ffr(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
+		     uint64_t svcr)
  {
  	size_t reg_size = sve_vq_from_vl(sve_vl) * 2;  /* 1 bit per VL byte */
  	int errors = 0;
@@ -195,6 +222,10 @@ static int check_ffr(struct syscall_cfg *cfg, int sve_vl)
  	if (!sve_vl)
  		return 0;
 
+	if ((svcr & SVCR_SM_MASK) &&
+	    !(getauxval(AT_HWCAP2) & HWCAP2_SME_FA64))
+		return 0;
+
  	/* After a syscall the P registers should be preserved or zeroed */
  	for (i = 0; i < reg_size; i++)
  		if (ffr_out[i] && (ffr_in[i] != ffr_out[i]))
@@ -206,8 +237,65 @@ static int check_ffr(struct syscall_cfg *cfg, int sve_vl)
  	return errors;
  }
 
-typedef void (*setup_fn)(struct syscall_cfg *cfg, int sve_vl);
-typedef int (*check_fn)(struct syscall_cfg *cfg, int sve_vl);
+uint64_t svcr_in, svcr_out;
+
+static void setup_svcr(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
+		    uint64_t svcr)
+{
+	svcr_in = svcr;
+}
+
+static int check_svcr(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
+		      uint64_t svcr)
+{
+	int errors = 0;
+
+	if (svcr_out & SVCR_SM_MASK) {
+		ksft_print_msg("%s Still in SM, SVCR %llx\n",
+			       cfg->name, svcr_out);
+		errors++;
+	}
+
+	if ((svcr_in & SVCR_ZA_MASK) != (svcr_out & SVCR_ZA_MASK)) {
+		ksft_print_msg("%s PSTATE.ZA changed, SVCR %llx != %llx\n",
+			       cfg->name, svcr_in, svcr_out);
+		errors++;
+	}
+
+	return errors;
+}
+
+uint8_t za_in[SVE_NUM_PREGS * __SVE_ZREG_SIZE(SVE_VQ_MAX)];
+uint8_t za_out[SVE_NUM_PREGS * __SVE_ZREG_SIZE(SVE_VQ_MAX)];
+
+static void setup_za(struct syscall_cfg *cfg, int sve_vl, int sme_vl,

tools/testing/selftests/arm64/abi/syscall-abi.c static int check_ffr(struct syscall_cfg *cfg, int sve_vl) · line 281

Quoted 10 lines
tools/testing/selftests/arm64/abi/syscall-abi.c +10 -0
+		     uint64_t svcr)
+{
+	fill_random(za_in, sizeof(za_in));
+	memset(za_out, 0, sizeof(za_out));
+}
+
+static int check_za(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
+		    uint64_t svcr)
+{
+	size_t reg_size = sme_vl * sme_vl;

Is there possibilty of size_t overfolow here?

tools/testing/selftests/arm64/abi/syscall-abi.c static int check_ffr(struct syscall_cfg *cfg, int sve_vl) · line 288

Quoted 7 lines
tools/testing/selftests/arm64/abi/syscall-abi.c +7 -0
+	int errors = 0;
+
+	if (!(svcr & SVCR_ZA_MASK))
+		return 0;
+
+	if (memcmp(za_in, za_out, reg_size) != 0) {
+		ksft_print_msg("SME VL %d ZA does not match\n", sme_vl);

Print the expected value in addition to the sme_val.

Quoted 54 lines
tools/testing/selftests/arm64/abi/syscall-abi.c +19 -5
+		errors++;
+	}
+
+	return errors;
+}
+
+typedef void (*setup_fn)(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
+			 uint64_t svcr);
+typedef int (*check_fn)(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
+			uint64_t svcr);
 
  /*
   * Each set of registers has a setup function which is called before
@@ -225,20 +313,23 @@ static struct {
  	{ setup_z, check_z },
  	{ setup_p, check_p },
  	{ setup_ffr, check_ffr },
+	{ setup_svcr, check_svcr },
+	{ setup_za, check_za },
  };
 
-static bool do_test(struct syscall_cfg *cfg, int sve_vl)
+static bool do_test(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
+		    uint64_t svcr)
  {
  	int errors = 0;
  	int i;
 
  	for (i = 0; i < ARRAY_SIZE(regset); i++)
-		regset[i].setup(cfg, sve_vl);
+		regset[i].setup(cfg, sve_vl, sme_vl, svcr);
 
-	do_syscall(sve_vl);
+	do_syscall(sve_vl, sme_vl);
 
  	for (i = 0; i < ARRAY_SIZE(regset); i++)
-		errors += regset[i].check(cfg, sve_vl);
+		errors += regset[i].check(cfg, sve_vl, sme_vl, svcr);
 
  	return errors == 0;
  }
@@ -246,9 +337,10 @@ static bool do_test(struct syscall_cfg *cfg, int sve_vl)
  static void test_one_syscall(struct syscall_cfg *cfg)
  {
  	int sve_vq, sve_vl;
+	int sme_vq, sme_vl;
 
  	/* FPSIMD only case */
-	ksft_test_result(do_test(cfg, 0),
+	ksft_test_result(do_test(cfg, 0, default_sme_vl, 0),
  			 "%s FPSIMD\n", cfg->name);
 
  	if (!(getauxval(AT_HWCAP) & HWCAP_SVE))

tools/testing/selftests/arm64/abi/syscall-abi.c static void test_one_syscall(struct syscall_cfg *cfg) · line 361

Quoted 6 lines
tools/testing/selftests/arm64/abi/syscall-abi.c +1 -1
@@ -265,8 +357,36 @@ static void test_one_syscall(struct syscall_cfg *cfg)
  		if (sve_vq != sve_vq_from_vl(sve_vl))
  			sve_vq = sve_vq_from_vl(sve_vl);
 
-		ksft_test_result(do_test(cfg, sve_vl),
+		ksft_test_result(do_test(cfg, sve_vl, default_sme_vl, 0),
  				 "%s SVE VL %d\n", cfg->name, sve_vl);

Print default_sme_vl as well.

Quoted 99 lines
tools/testing/selftests/arm64/abi/syscall-abi.c +69 -1
+
+		if (!(getauxval(AT_HWCAP2) & HWCAP2_SME))
+			continue;
+
+		for (sme_vq = SVE_VQ_MAX; sme_vq > 0; --sme_vq) {
+			sme_vl = prctl(PR_SME_SET_VL, sme_vq * 16);
+			if (sme_vl == -1)
+				ksft_exit_fail_msg("PR_SME_SET_VL failed: %s (%d)\n",
+						   strerror(errno), errno);
+
+			sme_vl &= PR_SME_VL_LEN_MASK;
+
+			if (sme_vq != sve_vq_from_vl(sme_vl))
+				sme_vq = sve_vq_from_vl(sme_vl);
+
+			ksft_test_result(do_test(cfg, sve_vl, sme_vl,
+						 SVCR_ZA_MASK | SVCR_SM_MASK),
+					 "%s SVE VL %d/SME VL %d SM+ZA\n",
+					 cfg->name, sve_vl, sme_vl);
+			ksft_test_result(do_test(cfg, sve_vl, sme_vl,
+						 SVCR_SM_MASK),
+					 "%s SVE VL %d/SME VL %d SM\n",
+					 cfg->name, sve_vl, sme_vl);
+			ksft_test_result(do_test(cfg, sve_vl, sme_vl,
+						 SVCR_ZA_MASK),
+					 "%s SVE VL %d/SME VL %d ZA\n",
+					 cfg->name, sve_vl, sme_vl);
+		}
  	}
  }
 
@@ -299,14 +419,54 @@ int sve_count_vls(void)
  	return vl_count;
  }
 
+int sme_count_vls(void)
+{
+	unsigned int vq;
+	int vl_count = 0;
+	int vl;
+
+	if (!(getauxval(AT_HWCAP2) & HWCAP2_SME))
+		return 0;
+
+	/* Ensure we configure a SME VL, used to flag if SVCR is set */
+	default_sme_vl = 16;
+
+	/*
+	 * Enumerate up to SVE_VQ_MAX vector lengths
+	 */
+	for (vq = SVE_VQ_MAX; vq > 0; --vq) {
+		vl = prctl(PR_SME_SET_VL, vq * 16);
+		if (vl == -1)
+			ksft_exit_fail_msg("PR_SME_SET_VL failed: %s (%d)\n",
+					   strerror(errno), errno);
+
+		vl &= PR_SME_VL_LEN_MASK;
+
+		if (vq != sve_vq_from_vl(vl))
+			vq = sve_vq_from_vl(vl);
+
+		vl_count++;
+	}
+
+	return vl_count;
+}
+
  int main(void)
  {
  	int i;
+	int tests = 1;  /* FPSIMD */
 
  	srandom(getpid());
 
  	ksft_print_header();
-	ksft_set_plan(ARRAY_SIZE(syscalls) * (sve_count_vls() + 1));
+	tests += sve_count_vls();
+	tests += (sve_count_vls() * sme_count_vls()) * 3;
+	ksft_set_plan(ARRAY_SIZE(syscalls) * tests);
+
+	if (getauxval(AT_HWCAP2) & HWCAP2_SME_FA64)
+		ksft_print_msg("SME with FA64\n");
+	else if (getauxval(AT_HWCAP2) & HWCAP2_SME)
+		ksft_print_msg("SME without FA64\n");
 
  	for (i = 0; i < ARRAY_SIZE(syscalls); i++)
  		test_one_syscall(&syscalls[i]);
tools/testing/selftests/arm64/abi/syscall-abi.h new file +5 -0
new file mode 100644
index 000000000000..bda5a87ad381
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2021 ARM Limited.
+ */
+

tools/testing/selftests/arm64/abi/syscall-abi.h line 15

Quoted 10 lines
tools/testing/selftests/arm64/abi/syscall-abi.h new file +10 -0
+#ifndef SYSCALL_ABI_H
+#define SYSCALL_ABI_H
+
+#define SVCR_ZA_MASK		2
+#define SVCR_SM_MASK		1
+
+#define SVCR_ZA_SHIFT		1
+#define SVCR_SM_SHIFT		0
+
+#endif

With these fixed or explained

thanks,
-- Shuah

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#90 lore raw

Re: [PATCH v11 29/40] arm64/sme: Provide Kconfig for SME

In reply to kernel test robot
Quoted 4 lines · kernel test robot
Quoted 2 lines
Quoted 2 lines

arch/arm64/kernel/signal.c:395:35: sparse: sparse: dereference of noderef expression arch/arm64/kernel/signal.c:395:35: sparse: sparse: dereference of noderef expression

arch/arm64/kernel/signal.c:429:53: sparse: sparse: dereference of noderef expression arch/arm64/kernel/signal.c:429:53: sparse: sparse: dereference of noderef expression

This is a replication of an existing pattern in the signal code adding a fixed offset to a userspace pointer to read a variably sized buffer after reading the header that prefixes it rather than actually dereferencing the pointer.

#91 lore raw

Re: [PATCH v11 29/40] arm64/sme: Provide Kconfig for SME

In reply to Mark Brown
I love your patch! Perhaps something to improve:

Hi Mark,

I love your patch! Perhaps something to improve:

[auto build test WARNING on dfd42facf1e4ada021b939b4e19c935dcdd55566]

url:    https://github.com/0day-ci/linux/commits/Mark-Brown/arm64-sme-Initial-support-for-the-Scalable-Matrix-Extension/20220207-233825
base:   dfd42facf1e4ada021b939b4e19c935dcdd55566
config: arm64-randconfig-s032-20220207 (https://download.01.org/0day-ci/archive/20220208/202202082237.RC01lAqd-lkp(a)intel.com/config)
compiler: aarch64-linux-gcc (GCC) 11.2.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.4-dirty
# https://github.com/0day-ci/linux/commit/3c145e627affeb9240ccaebb147235e09b229b34
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mark-Brown/arm64-sme-Initial-support-for-the-Scalable-Matrix-Extension/20220207-233825
git checkout 3c145e627affeb9240ccaebb147235e09b229b34
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=arm64 SHELL=/bin/bash arch/arm64/kernel/ block/ drivers/nvme/host/ drivers/nvme/target/

If you fix the issue, kindly add following tag as appropriate

sparse warnings: (new ones prefixed by >>)

>> arch/arm64/kernel/signal.c:664:43: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected struct user_ctxs [noderef] __user *user @@     got struct user_ctxs * @@
   arch/arm64/kernel/signal.c:664:43: sparse:     expected struct user_ctxs [noderef] __user *user
   arch/arm64/kernel/signal.c:664:43: sparse:     got struct user_ctxs *
   arch/arm64/kernel/signal.c:936:26: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected void ( [noderef] [usertype] __user *[assigned] [usertype] sigtramp )( ... ) @@     got void * @@
   arch/arm64/kernel/signal.c:936:26: sparse:     expected void ( [noderef] [usertype] __user *[assigned] [usertype] sigtramp )( ... )
   arch/arm64/kernel/signal.c:936:26: sparse:     got void *
>> arch/arm64/kernel/signal.c:395:35: sparse: sparse: dereference of noderef expression
>> arch/arm64/kernel/signal.c:395:35: sparse: sparse: dereference of noderef expression

arch/arm64/kernel/signal.c:429:53: sparse: sparse: dereference of noderef expression arch/arm64/kernel/signal.c:429:53: sparse: sparse: dereference of noderef expression

vim +664 arch/arm64/kernel/signal.c

47ccb02868cead Dave Martin      2017-06-15  621  
2c020ed8d148f7 Catalin Marinas  2012-03-05  622  static int restore_sigframe(struct pt_regs *regs,
2c020ed8d148f7 Catalin Marinas  2012-03-05  623  			    struct rt_sigframe __user *sf)
2c020ed8d148f7 Catalin Marinas  2012-03-05  624  {
2c020ed8d148f7 Catalin Marinas  2012-03-05  625  	sigset_t set;
2c020ed8d148f7 Catalin Marinas  2012-03-05  626  	int i, err;
47ccb02868cead Dave Martin      2017-06-15  627  	struct user_ctxs user;
2c020ed8d148f7 Catalin Marinas  2012-03-05  628  
2c020ed8d148f7 Catalin Marinas  2012-03-05  629  	err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set));
2c020ed8d148f7 Catalin Marinas  2012-03-05  630  	if (err == 0)
2c020ed8d148f7 Catalin Marinas  2012-03-05  631  		set_current_blocked(&set);
2c020ed8d148f7 Catalin Marinas  2012-03-05  632  
2c020ed8d148f7 Catalin Marinas  2012-03-05  633  	for (i = 0; i < 31; i++)
2c020ed8d148f7 Catalin Marinas  2012-03-05  634  		__get_user_error(regs->regs[i], &sf->uc.uc_mcontext.regs[i],
2c020ed8d148f7 Catalin Marinas  2012-03-05  635  				 err);
2c020ed8d148f7 Catalin Marinas  2012-03-05  636  	__get_user_error(regs->sp, &sf->uc.uc_mcontext.sp, err);
2c020ed8d148f7 Catalin Marinas  2012-03-05  637  	__get_user_error(regs->pc, &sf->uc.uc_mcontext.pc, err);
2c020ed8d148f7 Catalin Marinas  2012-03-05  638  	__get_user_error(regs->pstate, &sf->uc.uc_mcontext.pstate, err);
2c020ed8d148f7 Catalin Marinas  2012-03-05  639  
2c020ed8d148f7 Catalin Marinas  2012-03-05  640  	/*
2c020ed8d148f7 Catalin Marinas  2012-03-05  641  	 * Avoid sys_rt_sigreturn() restarting.
2c020ed8d148f7 Catalin Marinas  2012-03-05  642  	 */
17c28958600928 Dave Martin      2017-08-01  643  	forget_syscall(regs);
2c020ed8d148f7 Catalin Marinas  2012-03-05  644  
dbd4d7ca563fd0 Mark Rutland     2016-03-01  645  	err |= !valid_user_regs(&regs->user_regs, current);
47ccb02868cead Dave Martin      2017-06-15  646  	if (err == 0)
47ccb02868cead Dave Martin      2017-06-15  647  		err = parse_user_sigframe(&user, sf);
2c020ed8d148f7 Catalin Marinas  2012-03-05  648  
6d502b6ba1b267 Suzuki K Poulose 2020-01-13  649  	if (err == 0 && system_supports_fpsimd()) {
8cd969d28fd284 Dave Martin      2017-10-31  650  		if (!user.fpsimd)
8cd969d28fd284 Dave Martin      2017-10-31  651  			return -EINVAL;
8cd969d28fd284 Dave Martin      2017-10-31  652  
8cd969d28fd284 Dave Martin      2017-10-31  653  		if (user.sve) {
8cd969d28fd284 Dave Martin      2017-10-31  654  			if (!system_supports_sve())
8cd969d28fd284 Dave Martin      2017-10-31  655  				return -EINVAL;
8cd969d28fd284 Dave Martin      2017-10-31  656  
8cd969d28fd284 Dave Martin      2017-10-31  657  			err = restore_sve_fpsimd_context(&user);
8cd969d28fd284 Dave Martin      2017-10-31  658  		} else {
47ccb02868cead Dave Martin      2017-06-15  659  			err = restore_fpsimd_context(user.fpsimd);
8cd969d28fd284 Dave Martin      2017-10-31  660  		}
8cd969d28fd284 Dave Martin      2017-10-31  661  	}
2c020ed8d148f7 Catalin Marinas  2012-03-05  662  
a884c063c23007 Mark Brown       2022-02-07  663  	if (err == 0 && system_supports_sme() && user.za)
a884c063c23007 Mark Brown       2022-02-07 @664  		err = restore_za_context(&user);
a884c063c23007 Mark Brown       2022-02-07  665  
2c020ed8d148f7 Catalin Marinas  2012-03-05  666  	return err;
2c020ed8d148f7 Catalin Marinas  2012-03-05  667  }
2c020ed8d148f7 Catalin Marinas  2012-03-05  668  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

author
#18 lore raw

Re: [PATCH v11 05/40] kselftest/arm64: signal: Allow tests to be incompatible with features

In reply to Shuah Khan
Quoted 2 lines · Shuah Khan

Assuming default_handler() will skip test and return skip test when feature is unsupported?

Yes.

author
#22 lore raw

Re: [PATCH v11 06/40] arm64/sme: Provide ABI documentation for SME

In reply to Shuah Khan
Quoted 4 lines · Shuah Khan

Review

Quoted 2 lines

+++ b/Documentation/arm64/sme.rst

(quoted diff) +0 -0
@@ -0,0 +1,432 @@

Missing SPDX here?

Only a couple of rst files have SPDX documentation here, I guess the SPDX people aren't worrying about documentation?

author
#99 lore raw

Re: [PATCH v11 31/40] kselftest/arm64: sme: Add SME support to vlset

In reply to Shuah Khan
Quoted 8 lines · Shuah Khan
Quoted 4 lines · Mark Brown

The Scalable Matrix Extenions (SME) introduces additional register state with configurable vector lengths, similar to SVE but configured separately. Extend vlset to support configuring this state with a --sme or -s command line option.

It would be useful to add a -g command to get the current value. -g would just do PR_SVE_GET_VL and print the value perhaps?

We already have the rdvl helper programs which can be used to read the actual vector length from a shell command. I'm not sure there's a particular use case for adding something to to this program, and I'm not sure the complexity is worth it especially given that we've got both the actual and to be inherited vector lengths to be considered in the UI. This program exists to allow you to configure vector lengths for the stress tests without having to write UI code in assembler.

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

author
#103 lore raw

Re: [PATCH v11 32/40] kselftest/arm64: Add tests for TPIDR2

In reply to Shuah Khan
Quoted 10 lines · Shuah Khan

tools/testing/selftests/arm64/abi/tpidr2.c line 119

Quoted 6 lines · Mark Brown
tools/testing/selftests/arm64/abi/tpidr2.c new file +6 -0
+		set_tpidr2(getpid());
+		if (get_tpidr2() == getpid()) {
+			exit(1);
+		} else {
+			putstr("# Failed to set TPIDR2 in child\n");
+			exit(0);

Is this test expected to fail? Is that why it exits with 0 status?

This is so that we can use the exit code as a boolean value in the parent without having to invert it. Given that this is just a fork() of the program itself it didn't seem useful to invert the value purely to pass it back to the parent, it seemed better to consistently use natural true/false rather than 0 on success rather than mixing the two.

author
#110 lore raw

Re: [PATCH v11 34/40] kselftest/arm64: sme: Provide streaming mode SVE stress test

In reply to Shuah Khan
Quoted 5 lines · Shuah Khan

tools/testing/selftests/arm64/fp/ssve-stress line 37

Quoted 3 lines
tools/testing/selftests/arm64/fp/ssve-stress new file +3 -0
+child_died () {
+	cleanup
+	exit 1

Is this a failure condition?

Yes.

author
#114 lore raw

Re: [PATCH v11 35/40] kselftest/arm64: signal: Handle ZA signal context in core code

In reply to Shuah Khan
Quoted 7 lines · Shuah Khan

tools/testing/selftests/arm64/signal/testcases/testcases.c bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err) · line 151

Quoted 3 lines · Mark Brown
tools/testing/selftests/arm64/signal/testcases/testcases.c +3 -0
+		case ZA_MAGIC:
+			if (flags & ZA_CTX)
+				*err = "Multiple ZA_MAGIC";

Is this considered an error?

Yes.

Quoted 9 lines

tools/testing/selftests/arm64/signal/testcases/testcases.c bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err) · line 202

Quoted 6 lines
tools/testing/selftests/arm64/signal/testcases/testcases.c +2 -0
@@ -165,6 +198,9 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err)
  		if (flags & SVE_CTX)
  			if (!validate_sve_context(sve, err))
  				return false;
+		if (flags & ZA_CTX)
+			if (!validate_za_context(za, err))

If validate_za_context() finds an error, the above "Multiple ZA_MAGIC" will be overwritten? Is that the intent?

Both are errors.

author
#120 lore raw

Re: [PATCH v11 37/40] kselftest/arm64: signal: Add SME signal handling tests

In reply to Shuah Khan
Quoted 17 lines · Shuah Khan

tools/testing/selftests/arm64/signal/testcases/ssve_regs.c line 111

Quoted 12 lines · Mark Brown
tools/testing/selftests/arm64/signal/testcases/ssve_regs.c new file +12 -0
+static int sme_regs(struct tdescr *td, siginfo_t *si, ucontext_t *uc)
+{
+	int i;
+
+	for (i = 0; i < nvls; i++) {
+		/*
+		 * TODO: the signal test helpers can't currently cope
+		 * with signal frames bigger than struct sigcontext,
+		 * skip VLs that will trigger that.
+		 */
+		if (vls[i] > 64)
+			continue;

Count the skipped VLs and print counts - helps see how many are skipped.

I'll print a message when we skip an individual VL for this reason. Note that it is hardware dependent what vector lengths exist in a system and that it is expected that many possible vector lengths will be skipped - the enumeration algorithm means that we don't explicitly step through most vector lengths but rather have the enumeration done for us.

Please delete unneeded context from mails when replying. Doing this makes it much easier to find your reply in the message, helping ensure it won't be missed by people scrolling through the irrelevant quoted material.

author
#130 lore raw

Re: [PATCH v11 40/40] kselftest/arm64: Add SME support to syscall ABI test

In reply to Shuah Khan
Quoted 8 lines · Shuah Khan

tools/testing/selftests/arm64/abi/syscall-abi.c static int check_ffr(struct syscall_cfg *cfg, int sve_vl) · line 281

Quoted 4 lines · Mark Brown
tools/testing/selftests/arm64/abi/syscall-abi.c +4 -0
+static int check_za(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
+		    uint64_t svcr)
+{
+	size_t reg_size = sme_vl * sme_vl;

Is there possibilty of size_t overfolow here?

No, if the size of a vector were anywhere near to being able to being able to do that I think we'd have serious design issues with the ABI - the size being calculated here is the size of a single register. The current architectural maximum vector length is 2048 bits, which would give a size of 64K for ZA if implemented.

Quoted 4 lines

tools/testing/selftests/arm64/abi/syscall-abi.c static int check_ffr(struct syscall_cfg *cfg, int sve_vl) · line 288

Quoted 2 lines
tools/testing/selftests/arm64/abi/syscall-abi.c +2 -0
+	if (memcmp(za_in, za_out, reg_size) != 0) {
+		ksft_print_msg("SME VL %d ZA does not match\n", sme_vl);

Print the expected value in addition to the sme_val.

This is not comparing the vector length, this is comparing the contents of the ZA register which may be up to 64K in size. There are serious presentational issues with displaying any errors in a useful fashion for such a large register which IME needs custom display code adding by whoever is debugging the issue that takes account of what the pattern being observed is.

Quoted 8 lines

tools/testing/selftests/arm64/abi/syscall-abi.c static void test_one_syscall(struct syscall_cfg *cfg) · line 360

Quoted 6 lines
tools/testing/selftests/arm64/abi/syscall-abi.c +1 -1
@@ -265,8 +357,36 @@ static void test_one_syscall(struct syscall_cfg *cfg)
  		if (sve_vq != sve_vq_from_vl(sve_vl))
  			sve_vq = sve_vq_from_vl(sve_vl);
-		ksft_test_result(do_test(cfg, sve_vl),
+		ksft_test_result(do_test(cfg, sve_vl, default_sme_vl, 0),
  				 "%s SVE VL %d\n", cfg->name, sve_vl);

Print default_sme_vl as well.

default_sme_vl is just being passed in as a dummy value here since the function takes a fixed number of arguments, this is testing the case where SME is not used or enabled and will be run on systems which do not have SME at all so there won't be any defined vector length for SME. I fear that it would cause confusion to display a SME VL here, and do_test() won't actually pay any attention to that argument in this case. We will individually step through all possible combinations of SVE and SME vector lengths in separate tests.

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

author
#23 lore raw

Re: [PATCH v11 06/40] arm64/sme: Provide ABI documentation for SME

In reply to Mark Brown
Quoted 9 lines · Mark Brown
Quoted 4 lines · Shuah Khan

Review

Quoted 2 lines

+++ b/Documentation/arm64/sme.rst

(quoted diff) +0 -0
@@ -0,0 +1,432 @@

Missing SPDX here?

Only a couple of rst files have SPDX documentation here, I guess the SPDX people aren't worrying about documentation?

I can't find any free format plain text files with SPDX in them, even really prominent stuff like README. The process documentation is silent on what's supposed to be done here too, it says you should use the comment style for whatever format you're writing in but that's not a thing for free format text. Dealing with this feels out of scope for this series, probably something for whenever someone gets round to doing a conversion to .rst or some other format.

maintainer
#24 lore raw

Re: [PATCH v11 06/40] arm64/sme: Provide ABI documentation for SME

Quoted 11 lines · Mark Brown
Quoted 9 lines · Mark Brown
Quoted 4 lines · Shuah Khan

Review

Quoted 2 lines

+++ b/Documentation/arm64/sme.rst

(quoted diff) +0 -0
@@ -0,0 +1,432 @@

Missing SPDX here?

Only a couple of rst files have SPDX documentation here, I guess the SPDX people aren't worrying about documentation?

Quoted 8 lines

I can't find any free format plain text files with SPDX in them, even really prominent stuff like README. The process documentation is silent on what's supposed to be done here too, it says you should use the comment style for whatever format you're writing in but that's not a thing for free format text. Dealing with this feels out of scope for this series, probably something for whenever someone gets round to doing a conversion to .rst or some other format.

There are about 570+ files under Documentation directory that have SPDX including Documentation/index.rst

Based on a recent doc patch I did, I have seen warns during doc build about the missing SPDX.

Let's add it now so it doesn't need fixing later.

thanks,
-- Shuah

maintainer
#131 lore raw

Re: [PATCH v11 40/40] kselftest/arm64: Add SME support to syscall ABI test

In reply to Mark Brown
Quoted 37 lines · Mark Brown
Quoted 8 lines · Shuah Khan

tools/testing/selftests/arm64/abi/syscall-abi.c static int check_ffr(struct syscall_cfg *cfg, int sve_vl) · line 281

Quoted 4 lines · Mark Brown
tools/testing/selftests/arm64/abi/syscall-abi.c +4 -0
+static int check_za(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
+		    uint64_t svcr)
+{
+	size_t reg_size = sme_vl * sme_vl;

Is there possibilty of size_t overfolow here?

No, if the size of a vector were anywhere near to being able to being able to do that I think we'd have serious design issues with the ABI - the size being calculated here is the size of a single register. The current architectural maximum vector length is 2048 bits, which would give a size of 64K for ZA if implemented.

Quoted 4 lines

tools/testing/selftests/arm64/abi/syscall-abi.c static int check_ffr(struct syscall_cfg *cfg, int sve_vl) · line 288

Quoted 2 lines
tools/testing/selftests/arm64/abi/syscall-abi.c +2 -0
+	if (memcmp(za_in, za_out, reg_size) != 0) {
+		ksft_print_msg("SME VL %d ZA does not match\n", sme_vl);

Print the expected value in addition to the sme_val.

This is not comparing the vector length, this is comparing the contents of the ZA register which may be up to 64K in size. There are serious presentational issues with displaying any errors in a useful fashion for such a large register which IME needs custom display code adding by whoever is debugging the issue that takes account of what the pattern being observed is.

Quoted 8 lines

tools/testing/selftests/arm64/abi/syscall-abi.c static void test_one_syscall(struct syscall_cfg *cfg) · line 360

Quoted 6 lines
tools/testing/selftests/arm64/abi/syscall-abi.c +1 -1
@@ -265,8 +357,36 @@ static void test_one_syscall(struct syscall_cfg *cfg)
   		if (sve_vq != sve_vq_from_vl(sve_vl))
   			sve_vq = sve_vq_from_vl(sve_vl);
-		ksft_test_result(do_test(cfg, sve_vl),
+		ksft_test_result(do_test(cfg, sve_vl, default_sme_vl, 0),
   				 "%s SVE VL %d\n", cfg->name, sve_vl);

Print default_sme_vl as well.

Quoted 9 lines

default_sme_vl is just being passed in as a dummy value here since the function takes a fixed number of arguments, this is testing the case where SME is not used or enabled and will be run on systems which do not have SME at all so there won't be any defined vector length for SME. I fear that it would cause confusion to display a SME VL here, and do_test() won't actually pay any attention to that argument in this case. We will individually step through all possible combinations of SVE and SME vector lengths in separate tests.

Sounds good.

thanks,
-- Shuah

maintainer
#133 lore raw
In reply to Mark Brown
Quoted 282 lines · Mark Brown

This series provides initial support for the ARMv9 Scalable Matrix Extension (SME). SME takes the approach used for vectors in SVE and extends this to provide architectural support for matrix operations. A more detailed overview can be found in [1].

For the kernel SME can be thought of as a series of features which are intended to be used together by applications but operate mostly orthogonally:

- The ZA matrix register.
- Streaming mode, in which ZA can be accessed and a subset of SVE features are available.
- A second vector length, used for streaming mode SVE and ZA and controlled using a similar interface to that for SVE.
- TPIDR2, a new userspace controllable system register intended for use by the C library for storing context related to the ZA ABI.

A substantial part of the series is dedicated to refactoring the existing SVE support so that we don't need to duplicate code for handling vector lengths and the SVE registers, this involves creating an array of vector types and making the users take the vector type as a parameter. I'm not 100% happy with this but wasn't able to come up with anything better, duplicating code definitely felt like a bad idea so this felt like the least bad thing. If this approach makes sense to people it might make sense to split this off into a separate series and/or merge it while the rest is pending review to try to make things a little more digestable, the series is very large so it'd probably make things easier to digest if some of the preparatory refactoring could be merged before the rest is ready.

One feature of the architecture of particular note is that switching to and from streaming mode may change the size of and invalidate the contents of the SVE registers, and when in streaming mode the FFR is not accessible. This complicates aspects of the ABI like signal handling and ptrace.

This initial implementation is mainly intended to get the ABI in place, there are several areas which will be worked on going forwards - some of these will be blockers, others could be handled in followup serieses:

- SME is currently not supported for KVM guests, this will be done as a followup series. A host system can use SME and run KVM guests but SME is not available in the guests.
- The KVM host support is done in a very simplistic way, were anyone to attempt to use it in production there would be performance impacts on hosts with SME support. As part of this we also add enumeration of fine grained traps.
- There is not currently ptrace or signal support TPIDR2, this will be done as a followup series.
- No support is currently provided for scheduler control of SME or SME applications, given the size of the SME register state the context switch overhead may be noticable so this may be needed especially for real time applications. Similar concerns already exist for larger SVE vector lengths but are amplified for SME, particularly as the vector length increases.
- There has been no work on optimising the performance of anything the kernel does.

It is not expected that any systems will be encountered that support SME but not SVE, SME is an ARMv9 feature and SVE is mandatory for ARMv9. The code attempts to handle any such systems that are encountered but this hasn't been tested extensively.

v11:
- Rebase onto v5.17-rc3.
- Provide a sme-inst.h to collect manual encodings in kselftest.
v10:
- Actually do the rebase of fixups from the previous version into relevant patches.
v9:
- Remove defensive programming around IS_ENABLED() and FGT in KVM code.
- Fix naming of TPIDR2 FGT register bit.
- Add patches making handling of floating point register bits more consistent (also sent as separate series).
- Drop now unused enumeration of fine grained traps.
v8:
- Rebase onto v5.17-rc1.
- Support interoperation with KVM, SME is disabled for KVM guests with minimal handling for cleaning up SME state when entering and leaving the guest.
- Document and implement that signal handlers are invoked with ZA and streaming mode disabled.
- Use the RDSVL instruction introduced in EAC2 of the architecture to obtain the streaming mode vector length during enumeration, ZA state loading/saving and in test programs.
- Store a pointer to SVCR in fpsimd_last_state and use it in fpsimd_save() for interoperation with KVM.
- Add a test case sme_trap_no_sm checking that we generate a SIGILL when using an instruction that requires streaming mode without enabling it.
- Add basic ZA context form validation to testcases helper library.
- Move signal tests over to validating streaming VL from ZA information.
- Pulled in patch removing ARRAY_SIZE() so that kselftest builds cleanly and to avoid trivial conflicts.
v7:
- Rebase onto v5.16-rc3.
- Reduce indentation when supporting custom triggers for signal tests as suggested by Catalin.
- Change to specifying a width for all CPU features rather than adding single bit specific infrastructure.
- Don't require zeroing of non-shared SVE state during syscalls.
v6:
- Rebase onto v5.16-rc1.
- Return to disabling TIF_SVE on kernel entry even if we have SME state, this avoids the need for KVM to handle the case where TIF_SVE is set on guest entry.
- Add syscall-abi.h to SME updates to syscall-abi, mistakenly omitted from commit.
v5:
- Rebase onto currently merged SVE and kselftest patches.
- Add support for the FA64 option, introduced in the recently published EAC1 update to the specification.
- Pull in test program for the syscall ABI previously sent separately with some revisions and add coverage for the SME ABI.
- Fix checking for options with 1 bit fields in ID_AA64SMFR0_EL1.
- Minor fixes and clarifications to the ABI documentation.
v4:
- Rebase onto merged patches.
- Remove an uneeded NULL check in vec_proc_do_default_vl().
- Include patch to factor out utility routines in kselftests written in assembler.
- Specify -ffreestanding when building TPIDR2 test.
v3:
- Skip FFR rather than predicate registers in sve_flush_live().
- Don't assume a bool is all zeros in sve_flush_live() as per AAPCS.
- Don't redundantly specify a zero index when clearing FFR.
v2:
- Fix several issues with !SME and !SVE configurations.
- Preserve TPIDR2 when creating a new thread/process unless CLONE_SETTLS is set.
- Report traps due to using features in an invalid mode as SIGILL.
- Spell out streaming mode behaviour in SVE ABI documentation more directly.
- Document TPIDR2 in the ABI document.
- Use SMSTART and SMSTOP rather than read/modify/write sequences.
- Rework logic for exiting streaming mode on syscall.
- Don't needlessly initialise SVCR on access trap.
- Always restore SME VL for userspace if SME traps are disabled.
- Only yield to encourage preemption every 128 iterations in za-test, otherwise do a getpid(), and validate SVCR after syscall.
- Leave streaming mode disabled except when reading the vector length in za-test, and disable ZA after detecting a mismatch.
- Add SME support to vlset.
- Clarifications and typo fixes in comments.
- Move sme_alloc() forward declaration back a patch.

[1] https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/scalable-matrix-extension-armv9-a-architecture

Mark Brown (40):
arm64: Define CPACR_EL1_FPEN similarly to other floating point
controls
arm64: Always use individual bits in CPACR floating point enables
arm64: cpufeature: Always specify and use a field width for
capabilities
kselftest/arm64: Remove local ARRAY_SIZE() definitions kselftest/arm64: signal: Allow tests to be incompatible with features arm64/sme: Provide ABI documentation for SME
arm64/sme: System register and exception syndrome definitions arm64/sme: Manually encode SME instructions
arm64/sme: Early CPU setup for SME
arm64/sme: Basic enumeration support
arm64/sme: Identify supported SME vector lengths at boot arm64/sme: Implement sysctl to set the default vector length arm64/sme: Implement vector length configuration prctl()s arm64/sme: Implement support for TPIDR2
arm64/sme: Implement SVCR context switching
arm64/sme: Implement streaming SVE context switching arm64/sme: Implement ZA context switching
arm64/sme: Implement traps and syscall handling for SME arm64/sme: Disable ZA and streaming mode when handling signals arm64/sme: Implement streaming SVE signal handling arm64/sme: Implement ZA signal handling
arm64/sme: Implement ptrace support for streaming mode SVE registers arm64/sme: Add ptrace support for ZA
arm64/sme: Disable streaming mode and ZA when flushing CPU state arm64/sme: Save and restore streaming mode over EFI runtime calls
KVM: arm64: Hide SME system registers from guests
KVM: arm64: Trap SME usage in guest
KVM: arm64: Handle SME host state when running guests arm64/sme: Provide Kconfig for SME
kselftest/arm64: Add manual encodings for SME instructions kselftest/arm64: sme: Add SME support to vlset kselftest/arm64: Add tests for TPIDR2
kselftest/arm64: Extend vector configuration API tests to cover SME kselftest/arm64: sme: Provide streaming mode SVE stress test kselftest/arm64: signal: Handle ZA signal context in core code kselftest/arm64: Add stress test for SME ZA context switching kselftest/arm64: signal: Add SME signal handling tests kselftest/arm64: Add streaming SVE to SVE ptrace tests kselftest/arm64: Add coverage for the ZA ptrace interface kselftest/arm64: Add SME support to syscall ABI test

  Documentation/arm64/elf_hwcaps.rst            |  33 +
  Documentation/arm64/index.rst                 |   1 +
  Documentation/arm64/sme.rst                   | 432 +++++++++++++
  Documentation/arm64/sve.rst                   |  70 ++-
  arch/arm64/Kconfig                            |  11 +
  arch/arm64/include/asm/cpu.h                  |   4 +
  arch/arm64/include/asm/cpufeature.h           |  25 +
  arch/arm64/include/asm/el2_setup.h            |  64 +-
  arch/arm64/include/asm/esr.h                  |  13 +-
  arch/arm64/include/asm/exception.h            |   1 +
  arch/arm64/include/asm/fpsimd.h               | 110 +++-
  arch/arm64/include/asm/fpsimdmacros.h         |  86 +++
  arch/arm64/include/asm/hwcap.h                |   8 +
  arch/arm64/include/asm/kvm_arm.h              |   5 +-
  arch/arm64/include/asm/kvm_host.h             |   4 +
  arch/arm64/include/asm/processor.h            |  18 +-
  arch/arm64/include/asm/sysreg.h               |  67 +-
  arch/arm64/include/asm/thread_info.h          |   2 +
  arch/arm64/include/uapi/asm/hwcap.h           |   8 +
  arch/arm64/include/uapi/asm/ptrace.h          |  69 ++-
  arch/arm64/include/uapi/asm/sigcontext.h      |  55 +-
  arch/arm64/kernel/cpufeature.c                | 273 ++++++--
  arch/arm64/kernel/cpuinfo.c                   |  13 +
  arch/arm64/kernel/entry-common.c              |  11 +
  arch/arm64/kernel/entry-fpsimd.S              |  36 ++
  arch/arm64/kernel/fpsimd.c                    | 585 ++++++++++++++++--
  arch/arm64/kernel/process.c                   |  28 +-
  arch/arm64/kernel/ptrace.c                    | 356 +++++++++--
  arch/arm64/kernel/signal.c                    | 194 +++++-
  arch/arm64/kernel/syscall.c                   |  34 +-
  arch/arm64/kernel/traps.c                     |   1 +
  arch/arm64/kvm/fpsimd.c                       |  43 +-
  arch/arm64/kvm/hyp/include/hyp/switch.h       |   4 +-
  arch/arm64/kvm/hyp/nvhe/switch.c              |  30 +
  arch/arm64/kvm/hyp/vhe/switch.c               |  15 +-
  arch/arm64/kvm/sys_regs.c                     |   9 +-
  arch/arm64/tools/cpucaps                      |   2 +
  include/uapi/linux/elf.h                      |   2 +
  include/uapi/linux/prctl.h                    |   9 +
  kernel/sys.c                                  |  12 +
  tools/testing/selftests/arm64/abi/.gitignore  |   1 +
  tools/testing/selftests/arm64/abi/Makefile    |   9 +-
  .../selftests/arm64/abi/syscall-abi-asm.S     |  69 ++-
  .../testing/selftests/arm64/abi/syscall-abi.c | 205 +++++-
  .../testing/selftests/arm64/abi/syscall-abi.h |  15 +
  tools/testing/selftests/arm64/abi/tpidr2.c    | 298 +++++++++
  tools/testing/selftests/arm64/fp/.gitignore   |   4 +
  tools/testing/selftests/arm64/fp/Makefile     |  12 +-
  tools/testing/selftests/arm64/fp/rdvl-sme.c   |  14 +
  tools/testing/selftests/arm64/fp/rdvl.S       |  10 +
  tools/testing/selftests/arm64/fp/rdvl.h       |   1 +
  tools/testing/selftests/arm64/fp/sme-inst.h   |  51 ++
  tools/testing/selftests/arm64/fp/ssve-stress  |  59 ++
  tools/testing/selftests/arm64/fp/sve-ptrace.c |  13 +-
  tools/testing/selftests/arm64/fp/sve-test.S   |  20 +
  tools/testing/selftests/arm64/fp/vec-syscfg.c |  10 +
  tools/testing/selftests/arm64/fp/vlset.c      |  10 +-
  tools/testing/selftests/arm64/fp/za-ptrace.c  | 354 +++++++++++
  tools/testing/selftests/arm64/fp/za-stress    |  59 ++
  tools/testing/selftests/arm64/fp/za-test.S    | 388 ++++++++++++
  .../testing/selftests/arm64/signal/.gitignore |   2 +
  .../selftests/arm64/signal/test_signals.h     |   5 +
  .../arm64/signal/test_signals_utils.c         |  40 +-
  .../arm64/signal/test_signals_utils.h         |   2 +
  .../testcases/fake_sigreturn_sme_change_vl.c  |  92 +++
  .../arm64/signal/testcases/sme_trap_no_sm.c   |  38 ++
  .../signal/testcases/sme_trap_non_streaming.c |  45 ++
  .../arm64/signal/testcases/sme_trap_za.c      |  36 ++
  .../selftests/arm64/signal/testcases/sme_vl.c |  68 ++
  .../arm64/signal/testcases/ssve_regs.c        | 129 ++++
  .../arm64/signal/testcases/testcases.c        |  36 ++
  .../arm64/signal/testcases/testcases.h        |   3 +-
  72 files changed, 4590 insertions(+), 251 deletions(-)

create mode 100644 Documentation/arm64/sme.rst
create mode 100644 tools/testing/selftests/arm64/abi/syscall-abi.h
create mode 100644 tools/testing/selftests/arm64/abi/tpidr2.c
create mode 100644 tools/testing/selftests/arm64/fp/rdvl-sme.c
create mode 100644 tools/testing/selftests/arm64/fp/sme-inst.h
create mode 100644 tools/testing/selftests/arm64/fp/ssve-stress
create mode 100644 tools/testing/selftests/arm64/fp/za-ptrace.c
create mode 100644 tools/testing/selftests/arm64/fp/za-stress
create mode 100644 tools/testing/selftests/arm64/fp/za-test.S
create mode 100644 tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_sme_change_vl.c create mode 100644 tools/testing/selftests/arm64/signal/testcases/sme_trap_no_sm.c create mode 100644 tools/testing/selftests/arm64/signal/testcases/sme_trap_non_streaming.c create mode 100644 tools/testing/selftests/arm64/signal/testcases/sme_trap_za.c create mode 100644 tools/testing/selftests/arm64/signal/testcases/sme_vl.c create mode 100644 tools/testing/selftests/arm64/signal/testcases/ssve_regs.c

Quoted 2 lines

base-commit: dfd42facf1e4ada021b939b4e19c935dcdd55566

Mark,

Kselftest patches look good to me with your responses to my comments on individual patches. In the interest of not generating more email traffic - responding to all here. I already added Reviewed-by to the patches.

Just the doc patch - SPDX needs addressing.

thanks,
-- Shuah

author
#25 lore raw

Re: [PATCH v11 06/40] arm64/sme: Provide ABI documentation for SME

In reply to Shuah Khan
Quoted 5 lines · Shuah Khan
Quoted 2 lines · Mark Brown

I can't find any free format plain text files with SPDX in them, even really prominent stuff like README. The process documentation is silent

Quoted 7 lines

There are about 570+ files under Documentation directory that have SPDX including Documentation/index.rst

Based on a recent doc patch I did, I have seen warns during doc build about the missing SPDX.

Let's add it now so it doesn't need fixing later.

Sure, there are lots of structured files in there like .rst ones which have SPDX headers but this is just a free format text file so it's not clear what if any format to use.

#92 lore raw

Re: [PATCH v11 29/40] arm64/sme: Provide Kconfig for SME

In reply to Mark Brown
I love your patch! Perhaps something to improve:

Hi Mark,

I love your patch! Perhaps something to improve:

[auto build test WARNING on dfd42facf1e4ada021b939b4e19c935dcdd55566]

url:    https://github.com/0day-ci/linux/commits/Mark-Brown/arm64-sme-Initial-support-for-the-Scalable-Matrix-Extension/20220207-233825
base:   dfd42facf1e4ada021b939b4e19c935dcdd55566
config: arm64-randconfig-s032-20220207 (https://download.01.org/0day-ci/archive/20220209/202202091343.QUFckK7O-lkp(a)intel.com/config)
compiler: aarch64-linux-gcc (GCC) 11.2.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.4-dirty
# https://github.com/0day-ci/linux/commit/3c145e627affeb9240ccaebb147235e09b229b34
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mark-Brown/arm64-sme-Initial-support-for-the-Scalable-Matrix-Extension/20220207-233825
git checkout 3c145e627affeb9240ccaebb147235e09b229b34
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=arm64 SHELL=/bin/bash arch/arm64/kernel/ block/ drivers/nvme/host/ drivers/nvme/target/

If you fix the issue, kindly add following tag as appropriate

sparse warnings: (new ones prefixed by >>)

>> arch/arm64/kernel/signal.c:664:43: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected struct user_ctxs [noderef] __user *user @@     got struct user_ctxs * @@
   arch/arm64/kernel/signal.c:664:43: sparse:     expected struct user_ctxs [noderef] __user *user
   arch/arm64/kernel/signal.c:664:43: sparse:     got struct user_ctxs *
   arch/arm64/kernel/signal.c:936:26: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected void ( [noderef] [usertype] __user *[assigned] [usertype] sigtramp )( ... ) @@     got void * @@
   arch/arm64/kernel/signal.c:936:26: sparse:     expected void ( [noderef] [usertype] __user *[assigned] [usertype] sigtramp )( ... )
   arch/arm64/kernel/signal.c:936:26: sparse:     got void *
>> arch/arm64/kernel/signal.c:395:35: sparse: sparse: dereference of noderef expression
>> arch/arm64/kernel/signal.c:395:35: sparse: sparse: dereference of noderef expression

arch/arm64/kernel/signal.c:429:53: sparse: sparse: dereference of noderef expression arch/arm64/kernel/signal.c:429:53: sparse: sparse: dereference of noderef expression

vim +664 arch/arm64/kernel/signal.c

47ccb02868cead3 Dave Martin      2017-06-15  621  
2c020ed8d148f75 Catalin Marinas  2012-03-05  622  static int restore_sigframe(struct pt_regs *regs,
2c020ed8d148f75 Catalin Marinas  2012-03-05  623  			    struct rt_sigframe __user *sf)
2c020ed8d148f75 Catalin Marinas  2012-03-05  624  {
2c020ed8d148f75 Catalin Marinas  2012-03-05  625  	sigset_t set;
2c020ed8d148f75 Catalin Marinas  2012-03-05  626  	int i, err;
47ccb02868cead3 Dave Martin      2017-06-15  627  	struct user_ctxs user;
2c020ed8d148f75 Catalin Marinas  2012-03-05  628  
2c020ed8d148f75 Catalin Marinas  2012-03-05  629  	err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set));
2c020ed8d148f75 Catalin Marinas  2012-03-05  630  	if (err == 0)
2c020ed8d148f75 Catalin Marinas  2012-03-05  631  		set_current_blocked(&set);
2c020ed8d148f75 Catalin Marinas  2012-03-05  632  
2c020ed8d148f75 Catalin Marinas  2012-03-05  633  	for (i = 0; i < 31; i++)
2c020ed8d148f75 Catalin Marinas  2012-03-05  634  		__get_user_error(regs->regs[i], &sf->uc.uc_mcontext.regs[i],
2c020ed8d148f75 Catalin Marinas  2012-03-05  635  				 err);
2c020ed8d148f75 Catalin Marinas  2012-03-05  636  	__get_user_error(regs->sp, &sf->uc.uc_mcontext.sp, err);
2c020ed8d148f75 Catalin Marinas  2012-03-05  637  	__get_user_error(regs->pc, &sf->uc.uc_mcontext.pc, err);
2c020ed8d148f75 Catalin Marinas  2012-03-05  638  	__get_user_error(regs->pstate, &sf->uc.uc_mcontext.pstate, err);
2c020ed8d148f75 Catalin Marinas  2012-03-05  639  
2c020ed8d148f75 Catalin Marinas  2012-03-05  640  	/*
2c020ed8d148f75 Catalin Marinas  2012-03-05  641  	 * Avoid sys_rt_sigreturn() restarting.
2c020ed8d148f75 Catalin Marinas  2012-03-05  642  	 */
17c289586009281 Dave Martin      2017-08-01  643  	forget_syscall(regs);
2c020ed8d148f75 Catalin Marinas  2012-03-05  644  
dbd4d7ca563fd0a Mark Rutland     2016-03-01  645  	err |= !valid_user_regs(&regs->user_regs, current);
47ccb02868cead3 Dave Martin      2017-06-15  646  	if (err == 0)
47ccb02868cead3 Dave Martin      2017-06-15  647  		err = parse_user_sigframe(&user, sf);
2c020ed8d148f75 Catalin Marinas  2012-03-05  648  
6d502b6ba1b267b Suzuki K Poulose 2020-01-13  649  	if (err == 0 && system_supports_fpsimd()) {
8cd969d28fd2848 Dave Martin      2017-10-31  650  		if (!user.fpsimd)
8cd969d28fd2848 Dave Martin      2017-10-31  651  			return -EINVAL;
8cd969d28fd2848 Dave Martin      2017-10-31  652  
8cd969d28fd2848 Dave Martin      2017-10-31  653  		if (user.sve) {
8cd969d28fd2848 Dave Martin      2017-10-31  654  			if (!system_supports_sve())
8cd969d28fd2848 Dave Martin      2017-10-31  655  				return -EINVAL;
8cd969d28fd2848 Dave Martin      2017-10-31  656  
8cd969d28fd2848 Dave Martin      2017-10-31  657  			err = restore_sve_fpsimd_context(&user);
8cd969d28fd2848 Dave Martin      2017-10-31  658  		} else {
47ccb02868cead3 Dave Martin      2017-06-15  659  			err = restore_fpsimd_context(user.fpsimd);
8cd969d28fd2848 Dave Martin      2017-10-31  660  		}
8cd969d28fd2848 Dave Martin      2017-10-31  661  	}
2c020ed8d148f75 Catalin Marinas  2012-03-05  662  
a884c063c230076 Mark Brown       2022-02-07  663  	if (err == 0 && system_supports_sme() && user.za)
a884c063c230076 Mark Brown       2022-02-07 @664  		err = restore_za_context(&user);
a884c063c230076 Mark Brown       2022-02-07  665  
2c020ed8d148f75 Catalin Marinas  2012-03-05  666  	return err;
2c020ed8d148f75 Catalin Marinas  2012-03-05  667  }
2c020ed8d148f75 Catalin Marinas  2012-03-05  668  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

maintainer Acked-by on v11 1/40
#2 lore raw

Re: [PATCH v11 01/40] arm64: Define CPACR_EL1_FPEN similarly to other floating point controls

In reply to Mark Brown
Quoted 8 lines · Mark Brown

The base floating point, SVE and SME all have enable controls for EL0 and EL1 in CPACR_EL1 which have a similar layout and function. Currently the basic floating point enable FPEN is defined differently to the SVE control, specified as a single define in kvm_arm.h rather than in sysreg.h. Move the define to sysreg.h and provide separate EL0 and EL1 control bits so code managing the different floating point enables can look consistent.

maintainer Acked-by on v11 2/40
#4 lore raw

Re: [PATCH v11 02/40] arm64: Always use individual bits in CPACR floating point enables

In reply to Mark Brown
Quoted 11 lines · Mark Brown

CPACR_EL1 has several bitfields for controlling traps for floating point features to EL1, each of which has a separate bits for EL0 and EL1. Marc Zyngier noted that we are not consistent in our use of defines to manipulate these, sometimes using a define covering the whole field and sometimes using defines for the individual bits. Make this consistent by expanding the whole field defines where they are used (currently only in the KVM code) and deleting them so that no further uses can be introduced.

maintainer Reviewed-by on v11 3/40
#6 lore raw

Re: [PATCH v11 03/40] arm64: cpufeature: Always specify and use a field width for capabilities

In reply to Mark Brown
Quoted 8 lines · Mark Brown

Since all the fields in the main ID registers are 4 bits wide we have up until now not bothered specifying the width in the code. Since we now wish to use this mechanism to enumerate features from the floating point feature registers which do not follow this pattern add a width to the table. This means updating all the existing table entries but makes it less likely that we run into issues in future due to implicitly assuming a 4 bit width.

Quoted 6 lines
Cc Suzuki K Poulose <[email protected]>
---
 arch/arm64/include/asm/cpufeature.h |   1 +
 arch/arm64/kernel/cpufeature.c      | 167 +++++++++++++++++-----------
 2 files changed, 102 insertions(+), 66 deletions(-)

I know it's a positive diffstat but I prefer being explicit with the field width. So:

reviewer Reviewed-by on v11 3/40
#7 lore raw

Re: [PATCH v11 03/40] arm64: cpufeature: Always specify and use a field width for capabilities

In reply to Mark Brown
Quoted 10 lines · Mark Brown

Since all the fields in the main ID registers are 4 bits wide we have up until now not bothered specifying the width in the code. Since we now wish to use this mechanism to enumerate features from the floating point feature registers which do not follow this pattern add a width to the table. This means updating all the existing table entries but makes it less likely that we run into issues in future due to implicitly assuming a 4 bit width.

Cc Suzuki K Poulose <[email protected]>
maintainer Acked-by on v11 5/40
#19 lore raw

Re: [PATCH v11 05/40] kselftest/arm64: signal: Allow tests to be incompatible with features

In reply to Mark Brown
Quoted 6 lines · Mark Brown

Some features may invalidate some tests, for example by supporting an operation which would trap otherwise. Allow tests to list features that they are incompatible with so we can cover the case where a signal will be generated without disruption on systems where that won't happen.

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

maintainer
#26 lore raw

Re: [PATCH v11 06/40] arm64/sme: Provide ABI documentation for SME

In reply to Mark Brown
Quoted 9 lines · Mark Brown
Quoted 7 lines · Shuah Khan
Quoted 2 lines · Mark Brown

I can't find any free format plain text files with SPDX in them, even really prominent stuff like README. The process documentation is silent

There are about 570+ files under Documentation directory that have SPDX including Documentation/index.rst

Quoted 9 lines
Quoted 4 lines

Based on a recent doc patch I did, I have seen warns during doc build about the missing SPDX.

Let's add it now so it doesn't need fixing later.

Sure, there are lots of structured files in there like .rst ones which have SPDX headers but this is just a free format text file so it's not clear what if any format to use.

I think SPDX is applicable to all files free format or not. Are you seeing any build warns during doc build on this?

thanks,
-- Shuah

author
#27 lore raw

Re: [PATCH v11 06/40] arm64/sme: Provide ABI documentation for SME

Quoted 8 lines · Shuah Khan
Quoted 3 lines · Mark Brown

Sure, there are lots of structured files in there like .rst ones which have SPDX headers but this is just a free format text file so it's not clear what if any format to use.

I think SPDX is applicable to all files free format or not. Are you seeing any build warns during doc build on this?

No, but I'm not exactly going out of my way to do anything with them. As far as I know these files don't get touched during builds, they just exist in the kernel tree. If there is some way of generating warnings from them there are quite a lot of other such files already there and doing so. Like I say I can't find any evidence that anyone has looked at adding SPDX to these files, as far as I know the long term plan such as it is is to convert to other formats and I can't immediately think how one would do it otherwise in a way that works well.

I'm sure the license compliance people would find adding annotations useful but working out how to do that sensibly for these files seems beyond the scope of this series.

maintainer
#28 lore raw

Re: [PATCH v11 06/40] arm64/sme: Provide ABI documentation for SME

Quoted 10 lines · Mark Brown
Quoted 8 lines · Shuah Khan
Quoted 3 lines · Mark Brown

Sure, there are lots of structured files in there like .rst ones which have SPDX headers but this is just a free format text file so it's not clear what if any format to use.

I think SPDX is applicable to all files free format or not. Are you seeing any build warns during doc build on this?

Quoted 9 lines

No, but I'm not exactly going out of my way to do anything with them. As far as I know these files don't get touched during builds, they just exist in the kernel tree. If there is some way of generating warnings from them there are quite a lot of other such files already there and doing so. Like I say I can't find any evidence that anyone has looked at adding SPDX to these files, as far as I know the long term plan such as it is is to convert to other formats and I can't immediately think how one would do it otherwise in a way that works well.

If build isn't saying anything, we can move on from SPDX comment. :)

thanks,
-- Shuah

maintainer
#29 lore raw

Re: [PATCH v11 06/40] arm64/sme: Provide ABI documentation for SME

In reply to Mark Brown
Quoted 5 lines · Mark Brown
Documentation/arm64/sme.rst new file +0 -0
new file mode 100644
index 000000000000..15df3157c592

[...]

Documentation/arm64/sme.rst line 84

Quoted 8 lines

+3. Sharing of streaming and non-streaming mode SVE state
+---------------------------------------------------------

Documentation/arm64/sme.rst new file +6 -0
+
+It is implementation defined which if any parts of the SVE state are shared
+between streaming and non-streaming modes.  When switching between modes
+via software interfaces such as ptrace if no register content is provided as
+part of switching no state will be assumed to be shared and everything will
+be zeroed.

Is there anything other than ptrace() here? I read the sigreturn() case below but did not say anything about changing PSTATE.SM via the sigcontext. I guess it's similar to ptrace().

Documentation/arm64/sme.rst line 91

Quoted 5 lines

+4. System call behaviour
+-------------------------

Documentation/arm64/sme.rst new file +3 -0
+
+* On syscall PSTATE.ZA is preserved, if PSTATE.ZA==1 then the contents of the
+  ZA matrix are preserved.

Sorry if this was discussed. What is the rationale for preserving the ZA registers on syscall? We don't do this for the top part of the Z registers.

Documentation/arm64/sme.rst line 94

Quoted 2 lines
Documentation/arm64/sme.rst new file +2 -0
+* On syscall PSTATE.SM will be cleared and the SVE registers will be handled
+  as normal.

What does that mean? Is this as per the sve.rst doc (unspecified but zeroed in practice)?

Documentation/arm64/sme.rst line 100

Quoted 5 lines
Documentation/arm64/sme.rst new file +5 -0
+* Neither the SVE registers nor ZA are used to pass arguments to or receive
+  results from any syscall.
+
+* On creation fork() or clone() the newly created process will have PSTATE.SM
+  and PSTATE.ZA cleared.

This looks slightly inconsistent with the first bullet point on ZA being preserved on syscalls. Why do these differ?

[...]

Quoted 5 lines
Documentation/arm64/sme.rst new file +5 -0
+References
+==========
+
+[1] arch/arm64/include/uapi/asm/sigcontext.h
+    AArch64 Linux signal ABI definitions

Documentation/arm64/sme.rst line 432

Quoted 10 lines
Documentation/arm64/sme.rst new file +10 -0
+
+[2] arch/arm64/include/uapi/asm/ptrace.h
+    AArch64 Linux ptrace ABI definitions
+
+[3] Documentation/arm64/cpu-feature-registers.rst
+
+[4] ARM IHI0055C
+    http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055c/IHI0055C_beta_aapcs64.pdf
+    http://infocenter.arm.com/help/topic/com.arm.doc.subset.swdev.abi/index.html
+    Procedure Call Standard for the ARM 64-bit Architecture (AArch64)

The second link no longer works. I also couldn't find any reference to
[4] but there's a lot of text to scan, so I may have missed it.

Signature · 5 lines
Catalin
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
maintainer Acked-by on v11 7/40
#36 lore raw

Re: [PATCH v11 07/40] arm64/sme: System register and exception syndrome definitions

In reply to Mark Brown
Quoted 9 lines · Mark Brown

The arm64 Scalable Matrix Extension (SME) adds some new system registers, fields in existing system registers and exception syndromes. This patch adds definitions for these for use in future patches implementing support for this extension.

Since SME will be the first user of FEAT_HCX in the kernel also include the definitions for enumerating it and the HCRX system register it adds.

I can't claim I verified that the new definitions match the bits in the spec. I trust you on this, so:

maintainer
#38 lore raw

Re: [PATCH v11 08/40] arm64/sme: Manually encode SME instructions

In reply to Mark Brown
Quoted 34 lines · Mark Brown

As with SVE rather than impose ambitious toolchain requirements for SME we manually encode the few instructions which we require in order to perform the work the kernel needs to do. The instructions used to save and restore context are provided as assembler macros while those for entering and leaving streaming mode are done in asm volatile blocks since they are expected to be used from C.

We could do the SMSTART and SMSTOP operations with read/modify/write cycles on SVCR but using the aliases provided for individual field accesses should be slightly faster. These instructions are aliases for MSR but since our minimum toolchain requirements are old enough to mean that we can't use the sX_X_cX_cX_X form and they always use xzr rather than taking a value like write_sysreg_s() wants we just use .inst.

---
 arch/arm64/include/asm/fpsimd.h       | 25 +++++++++++++
 arch/arm64/include/asm/fpsimdmacros.h | 53 +++++++++++++++++++++++++++
 2 files changed, 78 insertions(+)
arch/arm64/include/asm/fpsimd.h +6 -0
index cb24385e3632..c90f7f99a768 100644
@@ -249,6 +249,31 @@ static inline void sve_setup(void) { }
 
 #endif /* ! CONFIG_ARM64_SVE */
 
+#ifdef CONFIG_ARM64_SME
+
+static inline void sme_smstart_sm(void)
+{
+	asm volatile(".inst 0xd503437f");
+}

arch/arm64/include/asm/fpsimd.h static inline void sve_setup(void) { } · line 267

Quoted 10 lines
arch/arm64/include/asm/fpsimd.h +10 -0
+
+static inline void sme_smstop_sm(void)
+{
+	asm volatile(".inst 0xd503427f");
+}
+
+static inline void sme_smstop(void)
+{
+	asm volatile(".inst 0xd503467f");
+}

I think you can use xzr with __msr_s. It would be more consistent if we had some sysregs defined to be used with __msr_s.

Signature · 1 line
Catalin
author
#30 lore raw

Re: [PATCH v11 06/40] arm64/sme: Provide ABI documentation for SME

In reply to Catalin Marinas
Quoted 11 lines · Catalin Marinas

Documentation/arm64/sme.rst line 84

Quoted 5 lines · Mark Brown
Documentation/arm64/sme.rst new file +5 -0
+It is implementation defined which if any parts of the SVE state are shared
+between streaming and non-streaming modes.  When switching between modes
+via software interfaces such as ptrace if no register content is provided as
+part of switching no state will be assumed to be shared and everything will
+be zeroed.

Is there anything other than ptrace() here? I read the sigreturn() case below but did not say anything about changing PSTATE.SM via the sigcontext. I guess it's similar to ptrace().

The signal handling code requires that register data be provided to restore with either form of SVE data, this falls out of the existing requirement that register data be provided for SVE.

Quoted 9 lines

Documentation/arm64/sme.rst line 91

Quoted 5 lines

+4. System call behaviour
+-------------------------

Documentation/arm64/sme.rst new file +2 -0
+* On syscall PSTATE.ZA is preserved, if PSTATE.ZA==1 then the contents of the
+  ZA matrix are preserved.

Sorry if this was discussed. What is the rationale for preserving the ZA registers on syscall? We don't do this for the top part of the Z registers.

In both cases it's mirroring the expected PCS which is that for normal functions they must be called with streaming mode disabled, the high bits of Z may be changed and there is a lazy saving scheme for ZA. The handling of the Z registers falls out of a combination of the fact that the low bits are shared with the V registers and a desire to interoperate with binaries that are only aware of FPSIMD.

See:

https://github.com/rsandifo-arm/abi-aa/blob/sme-aapcs64/aapcs64/aapcs64.rst

for the PCS (it's an open pull request on the AAPCS), if we disable ZA we should really cooperate with the lazy save scheme for ZA in section 6.5 which would involve writing to userspace buffers. Given that we need to support preserving ZA for cases where userspace is preempted it's not really much effort to do that, if userspace doesn't want the cost it can disable ZA before doing a syscall and it means that syscalls don't push userspace code that would otherwise not do anything with ZA to have problems interoperating with the lazy saving scheme.

If we don't preserve ZA then userspace will be forced to save it when enabled which increases overall costs, if we do preserve ZA then it's no more expensive for the kernel to save it than userspace, we avoid the cost of restoring in the case where return directly to userspace without context switching and if we do future work to save more lazily then we may be able to avoid some of the saves.

Quoted 4 lines
Quoted 1 line

+ as normal.

What does that mean? Is this as per the sve.rst doc (unspecified but zeroed in practice)?

Yes, we will exit streaming mode and proceed as per sve.rst and the rest of the ABI.

Quoted 8 lines

Documentation/arm64/sme.rst line 100

Quoted 5 lines
Documentation/arm64/sme.rst new file +5 -0
+* Neither the SVE registers nor ZA are used to pass arguments to or receive
+  results from any syscall.
+
+* On creation fork() or clone() the newly created process will have PSTATE.SM
+  and PSTATE.ZA cleared.

This looks slightly inconsistent with the first bullet point on ZA being preserved on syscalls. Why do these differ?

Largely just because it's more complicated to implement copying the ZA backing store for this and it seemed more likely that someone would be surprised by a new process getting stuck carrying a potentially large copy of ZA around that it was unaware of than that someone would actually want that to happen. It's not a particularly strongly held opinon.

Quoted 7 lines

Documentation/arm64/sme.rst line 432

Quoted 4 lines

+[4] ARM IHI0055C

Documentation/arm64/sme.rst new file +3 -0
+    http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055c/IHI0055C_beta_aapcs64.pdf
+    http://infocenter.arm.com/help/topic/com.arm.doc.subset.swdev.abi/index.html
+    Procedure Call Standard for the ARM 64-bit Architecture (AArch64)

The second link no longer works. I also couldn't find any reference to
[4] but there's a lot of text to scan, so I may have missed it.

We don't referenced it, it's just carried over from SVE.

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

maintainer
#31 lore raw

Re: [PATCH v11 06/40] arm64/sme: Provide ABI documentation for SME

Quoted 32 lines · Mark Brown
Quoted 10 lines · Catalin Marinas

Documentation/arm64/sme.rst line 91

Quoted 5 lines · Mark Brown

+4. System call behaviour
+-------------------------

Documentation/arm64/sme.rst new file +2 -0
+* On syscall PSTATE.ZA is preserved, if PSTATE.ZA==1 then the contents of the
+  ZA matrix are preserved.

Sorry if this was discussed. What is the rationale for preserving the ZA registers on syscall? We don't do this for the top part of the Z registers.

In both cases it's mirroring the expected PCS which is that for normal functions they must be called with streaming mode disabled, the high bits of Z may be changed and there is a lazy saving scheme for ZA. The handling of the Z registers falls out of a combination of the fact that the low bits are shared with the V registers and a desire to interoperate with binaries that are only aware of FPSIMD.

See:

https://github.com/rsandifo-arm/abi-aa/blob/sme-aapcs64/aapcs64/aapcs64.rst

for the PCS (it's an open pull request on the AAPCS), if we disable ZA we should really cooperate with the lazy save scheme for ZA in section 6.5 which would involve writing to userspace buffers. Given that we need to support preserving ZA for cases where userspace is preempted it's not really much effort to do that, if userspace doesn't want the cost it can disable ZA before doing a syscall and it means that syscalls don't push userspace code that would otherwise not do anything with ZA to have problems interoperating with the lazy saving scheme.

Quoted 6 lines

If we don't preserve ZA then userspace will be forced to save it when enabled which increases overall costs, if we do preserve ZA then it's no more expensive for the kernel to save it than userspace, we avoid the cost of restoring in the case where return directly to userspace without context switching and if we do future work to save more lazily then we may be able to avoid some of the saves.

Thanks for the explanation and the PCS pointer. I guess doing the lazy saving scheme in the syscall handler is a lot more painful (faults etc.) and it's a user-only ABI/PCS, so we shouldn't tie the kernel into it.

Given that Linux doesn't plan to use the ZA registers itself, in most cases it won't need to restore anything. But we still need to save the ZA registers on context switch in case the thread wakes up on a different CPU. How often do you reckon would the user do a syscall with active ZA?

Anyway, I'll go through the other patches and get back to the ABI doc later, once I understand the kernel implementation better.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

+ as normal.

What does that mean? Is this as per the sve.rst doc (unspecified but zeroed in practice)?

Yes, we will exit streaming mode and proceed as per sve.rst and the rest of the ABI.

So in this case we consider the syscall interface as non-streaming (as per the PCS terminology). Should we require that the PSTATE.SM is cleared by the user as well? Alternatively, we could make it streaming-compatible and just preserve it. Are there any drawbacks? kernel_neon_begin() could clear SM if needed.

Quoted 9 lines
Quoted 8 lines

Documentation/arm64/sme.rst line 100

Quoted 5 lines
Documentation/arm64/sme.rst new file +5 -0
+* Neither the SVE registers nor ZA are used to pass arguments to or receive
+  results from any syscall.
+
+* On creation fork() or clone() the newly created process will have PSTATE.SM
+  and PSTATE.ZA cleared.

This looks slightly inconsistent with the first bullet point on ZA being preserved on syscalls. Why do these differ?

Quoted 6 lines

Largely just because it's more complicated to implement copying the ZA backing store for this and it seemed more likely that someone would be surprised by a new process getting stuck carrying a potentially large copy of ZA around that it was unaware of than that someone would actually want that to happen. It's not a particularly strongly held opinon.

If PSTATE.ZA is valid and the user does a fork() (well, implemented as clone()), normally it expects a nearly identical state in the child. With clone() if a new thread is created, we likely don't need the additional ZA state. We got away with having to think about this for SVE as the state is lost on syscall. Here we risk having a vaguely defined ABI - fork() is disabled on arm64 for example but we do have clone() and clone3().

Still thinking about this but maybe we could do something like always copy the ZA state unless CLONE_VM is passed for example. It is marginally more precise.

Quoted 9 lines
Quoted 7 lines

Documentation/arm64/sme.rst line 432

Quoted 4 lines

+[4] ARM IHI0055C

Documentation/arm64/sme.rst new file +3 -0
+    http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055c/IHI0055C_beta_aapcs64.pdf
+    http://infocenter.arm.com/help/topic/com.arm.doc.subset.swdev.abi/index.html
+    Procedure Call Standard for the ARM 64-bit Architecture (AArch64)

The second link no longer works. I also couldn't find any reference to
[4] but there's a lot of text to scan, so I may have missed it.

We don't referenced it, it's just carried over from SVE.

So I guess we can drop them from this doc.

Signature · 1 line
Catalin
author
#32 lore raw

Re: [PATCH v11 06/40] arm64/sme: Provide ABI documentation for SME

Quoted 9 lines · Catalin Marinas
Quoted 6 lines · Mark Brown

If we don't preserve ZA then userspace will be forced to save it when enabled which increases overall costs, if we do preserve ZA then it's no more expensive for the kernel to save it than userspace, we avoid the cost of restoring in the case where return directly to userspace without context switching and if we do future work to save more lazily then we may be able to avoid some of the saves.

Quoted 3 lines

Thanks for the explanation and the PCS pointer. I guess doing the lazy saving scheme in the syscall handler is a lot more painful (faults etc.) and it's a user-only ABI/PCS, so we shouldn't tie the kernel into it.

Yes, other than the considerations around clone() it's clearly more complicated to engage with.

Quoted 5 lines

Given that Linux doesn't plan to use the ZA registers itself, in most cases it won't need to restore anything. But we still need to save the ZA registers on context switch in case the thread wakes up on a different CPU. How often do you reckon would the user do a syscall with active ZA?

I would expect it to be very rare that userspace would want to do a syscall with ZA enabled, though obviously there's not a huge body of real world SME code to validate that against yet. The expected usage pattern is that both ZA and SM are only enabled for fairly brief bursts of intense computation and disabled when not actively used. It's possible that you will see things like logging during computation, or perhaps streaming data to/from a running algorithm incrementally during operation, generating syscalls so I wouldn't be surprised to see it happen but it for most systems it should be a very small percentage of system calls.

Quoted 11 lines
Quoted 5 lines
Quoted 2 lines

What does that mean? Is this as per the sve.rst doc (unspecified but zeroed in practice)?

Yes, we will exit streaming mode and proceed as per sve.rst and the rest of the ABI.

So in this case we consider the syscall interface as non-streaming (as per the PCS terminology). Should we require that the PSTATE.SM is cleared by the user as well? Alternatively, we could make it streaming-compatible and just preserve it. Are there any drawbacks? kernel_neon_begin() could clear SM if needed.

In fact kernel_neon_begin() already disables PSTATE.SM since we need to account for the case where userspace was preempted rather than issued a syscall. We could require that PSTATE.SM is disabled by the user, though it's questionable what we could usefully and helpfully do about it if they forget other than disable it anyway or generate a signal.

We could preserve PSTATE.SM, though since all the other register state for streaming mode is shared with SVE I would expect that we should be applying the SVE discard rules to it and there is therefore no other state that should be retained. As things stand this would either result in more overhead or complicate the register save and restore a bit since if we're in streaming mode we currently assume that we should save and restore the full SVE register contents but normally in a syscall we only need to save and restore the FPSIMD subset. The overhead might go away anyway as a result of general work on syscall optimisation for SVE, though that work isn't done yet and may not end up working out that way.

Having said that as with ZA userspace can just exit streaming mode to avoid any overhead having it enabled introduces and the common case is expected to be that it will have done so due to the PCS, it should be an extremely rare case - unlike keeping ZA active there doesn't seem to be any case where it would be sensible to want to do this and the PCS means you'd have to actively try to do so.

Quoted 15 lines
Quoted 6 lines

Largely just because it's more complicated to implement copying the ZA backing store for this and it seemed more likely that someone would be surprised by a new process getting stuck carrying a potentially large copy of ZA around that it was unaware of than that someone would actually want that to happen. It's not a particularly strongly held opinon.

If PSTATE.ZA is valid and the user does a fork() (well, implemented as clone()), normally it expects a nearly identical state in the child. With clone() if a new thread is created, we likely don't need the additional ZA state. We got away with having to think about this for SVE as the state is lost on syscall. Here we risk having a vaguely defined ABI - fork() is disabled on arm64 for example but we do have clone() and clone3().

Quoted 3 lines

Still thinking about this but maybe we could do something like always copy the ZA state unless CLONE_VM is passed for example. It is marginally more precise.

We should definitely write this up a bit more explictly whatever we do, like I say I don't really have strong opinions here.

There's also the interaction with the lazy save state to consider - TPIDR2 is cleared if CLONE_SETTLS is specified which would interfere with any lazy state saving that had already happened, though hopefully userspace is taking care of that as part of setting up the new thread so I think it's fine.

maintainer
#33 lore raw

Re: [PATCH v11 06/40] arm64/sme: Provide ABI documentation for SME

Quoted 13 lines · Mark Brown
Quoted 5 lines · Catalin Marinas

So in this case we consider the syscall interface as non-streaming (as per the PCS terminology). Should we require that the PSTATE.SM is cleared by the user as well? Alternatively, we could make it streaming-compatible and just preserve it. Are there any drawbacks? kernel_neon_begin() could clear SM if needed.

In fact kernel_neon_begin() already disables PSTATE.SM since we need to account for the case where userspace was preempted rather than issued a syscall. We could require that PSTATE.SM is disabled by the user, though it's questionable what we could usefully and helpfully do about it if they forget other than disable it anyway or generate a signal.

Quoted 4 lines

We could preserve PSTATE.SM, though since all the other register state for streaming mode is shared with SVE I would expect that we should be applying the SVE discard rules to it and there is therefore no other state that should be retained.

So when clearing PSTATE.SM, the streaming SVE regs become unknown (well, the wording is a bit more verbose). I think this fits well with the proposal to drop the streaming SVE state entirely on syscalls.

The ZA state I think is not affected by the PSTATE.SM change (early internal SME specs were listing this as unknown after SM clearing but I can't find it in the latest spec). However, after the syscall, the user won't be able to execute SME instruction until turning on PSTATE.SM again.

Would the libc wrappers preserve PSTATE.SM? What I find a bit confusing is that we only partially preserve some state while in streaming mode - the ZA registers but not the SVE ones. Is the user more likely to turn PSTATE.SM on for ZA processing or for SVE? If the former, we don't want to unnecessarily save/restore some SVE state that the user doesn't care about (can we even trap SVE instructions independently of SME while in streaming mode?).

I'd find it clearer if we preserved PSTATE.SM and, w.r.t. the streaming SVE state, we somewhat follow the PCS and not restore the regs (input from the libc people welcomed).

Quoted 8 lines

As things stand this would either result
in more overhead or complicate the register save and restore a bit since if we're in streaming mode we currently assume that we should save and restore the full SVE register contents but normally in a syscall we only need to save and restore the FPSIMD subset. The overhead might go away anyway as a result of general work on syscall optimisation for SVE, though that work isn't done yet and may not end up working out that way.

Quoted 6 lines

Having said that as with ZA userspace can just exit streaming mode to avoid any overhead having it enabled introduces and the common case is expected to be that it will have done so due to the PCS, it should be an extremely rare case - unlike keeping ZA active there doesn't seem to be any case where it would be sensible to want to do this and the PCS means you'd have to actively try to do so.

IIUC, the PCS introduced the notion of streaming-compatible functions that preserve the SM bit. If they are non-streaming, SM should be 0 on entry. It would be nice if we put the syscalls in one of these categories, so either mandate SM == 0 on entry or preserve (the latter being easier, I think, I haven't looked at what it takes to save/restore the streaming SVE state; I may change my mind after reviewing at the other patches).

Quoted 12 lines
Quoted 11 lines

If PSTATE.ZA is valid and the user does a fork() (well, implemented as clone()), normally it expects a nearly identical state in the child. With clone() if a new thread is created, we likely don't need the additional ZA state. We got away with having to think about this for SVE as the state is lost on syscall. Here we risk having a vaguely defined ABI - fork() is disabled on arm64 for example but we do have clone() and clone3().

Still thinking about this but maybe we could do something like always copy the ZA state unless CLONE_VM is passed for example. It is marginally more precise.

Quoted 8 lines

We should definitely write this up a bit more explictly whatever we do, like I say I don't really have strong opinions here.

There's also the interaction with the lazy save state to consider - TPIDR2 is cleared if CLONE_SETTLS is specified which would interfere with any lazy state saving that had already happened, though hopefully userspace is taking care of that as part of setting up the new thread so I think it's fine.

TPIDR2_EL0 should indeed be cleared in the child, it doesn't make sense to start a thread with this reg pointing to a buffer in another thread (not sure whether it needs to be tied to SETTLS but that works as well).

In fork()+execve() cases, it doesn't make sense to preserve ZA in the child but we can't tell at fork/clone3() time. OTOH, it probably doesn't make much sense to call clone3() with PSTATE.ZA set either, so such copy would rarely/never happen in the kernel. We'd just carry some code for the classic fork() case.

(few hours later) I think instead of singling out fork() (clone3() actually), we can just say that new tasks (process/thread) always start with PSTATE.ZA == 0, PSTATE.SM == 0 (tbd for this) and TPIDR2_EL0 == 0 irrespective of any clone3() flags (even CLONE_SETTLS). The C library will have to implement the lazy ZA saving in the parent before the syscall and the child will automatically recover the state if it follows the PCS.

Signature · 1 line
Catalin
author
#34 lore raw

Re: [PATCH v11 06/40] arm64/sme: Provide ABI documentation for SME

Quoted 10 lines · Catalin Marinas
Quoted 4 lines · Mark Brown

We could preserve PSTATE.SM, though since all the other register state for streaming mode is shared with SVE I would expect that we should be applying the SVE discard rules to it and there is therefore no other state that should be retained.

So when clearing PSTATE.SM, the streaming SVE regs become unknown (well, the wording is a bit more verbose). I think this fits well with the proposal to drop the streaming SVE state entirely on syscalls.

They're preserved or zeroed, yes.

Quoted 5 lines

The ZA state I think is not affected by the PSTATE.SM change (early internal SME specs were listing this as unknown after SM clearing but I can't find it in the latest spec). However, after the syscall, the user won't be able to execute SME instruction until turning on PSTATE.SM again.

Yes, ZA is preserved unless PSTATE.ZA is disabled. There are some instructions that can be used to interact with it outside of streaming mode, a subset of the instructions for loading and storing values in ZA.

Quoted 3 lines

Would the libc wrappers preserve PSTATE.SM? What I find a bit confusing is that we only partially preserve some state while in streaming mode - the ZA registers but not the SVE ones.

I would expect that libc wrappers would expect to be called with streaming mode already disabled - that's what default functions in the PCS expect, and since without FA64 enabled a huge proportion of FPSIMD instructions and some SVE instructions become undefined standard code could easily generate traps if it uses those instructions for anything. I wouldn't expect that libc would explicitly disable SME itself in standard configurations.

Quoted 3 lines

Is the user more likely to turn
PSTATE.SM on for ZA processing or for SVE? If the former, we don't want to unnecessarily save/restore some SVE state that the user doesn't care

It's expected that any active work with ZA will require enabling streaming mode, you can't do any actual computation with it without doing so and most of the work with ZA will involve using the streaming mode SVE registers as part of the computation (eg, collecting results in a Z register, or doing an operation to a ZA tile using the contents of a Z register as an operand).

It is also expected that some applications may prefer to execute what is mainly a SVE workload in streaming mode, as well as any performance relevant differences in the implementation choices the hardware makes it is likely that some systems will have vector lengths available in streaming mode that are otherwise unavailable (eg, you might have PEs with 128 bit FPSIMD/SVE units and a 512 bit SMCU).

I don't have a good handle on which sort of usage is going to be more common, and I expect that the answer is going to be very system dependent varying based on both the mix of applications running on the system at any given moment and the capabilities of the standard and streaming mode floating point implementations that the system has.

However the existing syscall ABI for the Z and P registers (which is all the SVE register state, FFR is a magic P register) means that unless we treat streaming mode differently to non-streaming mode we'll be discarding whatever state is there anyway so userspace by definition shouldn't have anything in there it expects to be preserved when it does a syscall. I'd rather not introduce an ABI that guarantees that we preserve the streaming mode SVE register state in cases where we discard (or can discard) the non-streaming SVE register state, that's both going to be more complicated to implement and more likely to cause unexpected differences that trip userspace up.

Quoted 2 lines

about (can we even trap SVE instructions independently of SME while in streaming mode?).

I'd need to check through but I don't believe so.

Quoted 3 lines

I'd find it clearer if we preserved PSTATE.SM and, w.r.t. the streaming SVE state, we somewhat follow the PCS and not restore the regs (input from the libc people welcomed).

Like I say we can do that easily enough, it's not something I expect to ever come up in practical usage though.

Quoted 9 lines
Quoted 6 lines

Having said that as with ZA userspace can just exit streaming mode to avoid any overhead having it enabled introduces and the common case is expected to be that it will have done so due to the PCS, it should be an extremely rare case - unlike keeping ZA active there doesn't seem to be any case where it would be sensible to want to do this and the PCS means you'd have to actively try to do so.

IIUC, the PCS introduced the notion of streaming-compatible functions that preserve the SM bit. If they are non-streaming, SM should be 0 on

Yes, it isn't the default though.

Quoted 5 lines

entry. It would be nice if we put the syscalls in one of these categories, so either mandate SM == 0 on entry or preserve (the latter being easier, I think, I haven't looked at what it takes to save/restore the streaming SVE state; I may change my mind after reviewing at the other patches).

The streaming SVE state is identical to the SVE state with the exception of the FFR predicate register which is not present unless FA64 is available in the system and enabled and the separatly configured vector length.

It's sounding like we may as well just preserve SM, it shouldn't come up that often anyway and if it causes performance problems we can probably optimise it, and/or userspace can simply just not do that. Like I say I don't have particularly strong feelings, the current behaviour was just the easiest thing to implement and it doesn't seem like there is a use case. This is fine by me, I can do that for the next version.

[fork()/clone() behaviour]

Quoted 7 lines

(few hours later) I think instead of singling out fork() (clone3() actually), we can just say that new tasks (process/thread) always start with PSTATE.ZA == 0, PSTATE.SM == 0 (tbd for this) and TPIDR2_EL0 == 0 irrespective of any clone3() flags (even CLONE_SETTLS). The C library will have to implement the lazy ZA saving in the parent before the syscall and the child will automatically recover the state if it follows the PCS.

Works for me, I think forcing the userspace to consider this is going to work out more robust.

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

maintainer Reviewed-by on v11 9/40
#40 lore raw

Re: [PATCH v11 09/40] arm64/sme: Early CPU setup for SME

In reply to Mark Brown
Quoted 4 lines · Mark Brown

SME requires similar setup to that for SVE: disable traps to EL2 and make sure that the maximum vector length is available to EL1, for SME we have two traps - one for SME itself and one for TPIDR2.

Quoted 8 lines

In addition since we currently make no active use of priority control for SCMUs we map all SME priorities lower ELs may configure to 0, the architecture specified minimum priority, to ensure that nothing we manage is able to configure itself to consume excessive resources. This will need to be revisited should there be a need to manage SME priorities at runtime.

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

maintainer
#42 lore raw

Re: [PATCH v11 10/40] arm64/sme: Basic enumeration support

In reply to Mark Brown
Quoted 30 lines · Mark Brown
Documentation/arm64/elf_hwcaps.rst +22 -0
index b72ff17d600a..5626cf208000 100644
@@ -259,6 +259,39 @@ HWCAP2_RPRES
 
     Functionality implied by ID_AA64ISAR2_EL1.RPRES == 0b0001.
 
+HWCAP2_SME
+
+    Functionality implied by ID_AA64PFR1_EL1.SME == 0b0001, as described
+    by Documentation/arm64/sme.rst.
+
+HWCAP2_SME_I16I64
+
+    Functionality implied by ID_AA64SMFR0_EL1.I16I64 == 0b1111.
+
+HWCAP2_SME_F64F64
+
+    Functionality implied by ID_AA64SMFR0_EL1.F64F64 == 0b1.
+
+HWCAP2_SME_I8I32
+
+    Functionality implied by ID_AA64SMFR0_EL1.I8I32 == 0b1111.
+
+HWCAP2_SME_F16F32
+
+    Functionality implied by ID_AA64SMFR0_EL1.F16F32 == 0b1.
+
+HWCAP2_SME_B16F32

Documentation/arm64/elf_hwcaps.rst HWCAP2_RPRES · line 293

Quoted 10 lines
Documentation/arm64/elf_hwcaps.rst +10 -0
+
+    Functionality implied by ID_AA64SMFR0_EL1.B16F32 == 0b1.
+
+HWCAP2_SME_F32F32
+
+    Functionality implied by ID_AA64SMFR0_EL1.F32F32 == 0b1.
+
+HWCAP2_SME_FA64
+
+    Functionality implied by ID_AA64SMFR0_EL1.FA64 == 0b1.

More of a question for the libc people: should we drop the fine-grained HWCAP corresponding to the new ID_AA64SMFR0_EL1 register (only keep HWCAP2_SME) and get the user space to use the MRS emulation? Would any ifunc resolver be affected?

arch/arm64/kernel/cpufeature.c static const struct arm64_ftr_bits ftr_id_aa64pfr0[] = { · line 254

Quoted 9 lines
arch/arm64/kernel/cpufeature.c +1 -0
index 64a748c2b351..2634e32bbfb9 100644
@@ -251,6 +251,7 @@ static const struct arm64_ftr_bits ftr_id_aa64pfr0[] = {
 };
 
 static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = {
+	ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_SME_SHIFT, 4, 0),

Shouldn't this field also be visible (if SME is enabled)?

Quoted 23 lines
arch/arm64/kernel/fpsimd.c +15 -0
index 5280e098cfb5..576490be3c2b 100644
@@ -987,6 +987,32 @@ void fpsimd_release_task(struct task_struct *dead_task)
 
 #endif /* CONFIG_ARM64_SVE */
 
+#ifdef CONFIG_ARM64_SME
+
+void sme_kernel_enable(const struct arm64_cpu_capabilities *__always_unused p)
+{
+	/* Set priority for all PEs to architecturally defined minimum */
+	write_sysreg_s(read_sysreg_s(SYS_SMPRI_EL1) & ~SMPRI_EL1_PRIORITY_MASK,
+		       SYS_SMPRI_EL1);
+
+	/* Allow SME in kernel */
+	write_sysreg(read_sysreg(CPACR_EL1) | CPACR_EL1_SMEN_EL1EN, CPACR_EL1);
+	isb();
+}
+
+/*
+ * This must be called after sme_kernel_enable(), we rely on the

arch/arm64/kernel/fpsimd.c void fpsimd_release_task(struct task_struct *dead_task) · line 1014

Quoted 10 lines
arch/arm64/kernel/fpsimd.c +10 -0
+ * feature table being sorted to ensure this.
+ */
+void fa64_kernel_enable(const struct arm64_cpu_capabilities *__always_unused p)
+{
+	/* Allow use of FA64 */
+	write_sysreg_s(read_sysreg_s(SYS_SMCR_EL1) | SMCR_ELx_FA64_MASK,
+		       SYS_SMCR_EL1);
+}
+
+#endif /* CONFIG_ARM64_SVE */

I think instead of worrying about the order, we could check the sanitised register value in sme_kernel_enable() and set the FA64 bit. Also to me 'fa64_kernel_enable' somehow implies that the kernel cares about FA64 for itself but AFAICT we never run the kernel in streaming mode.

Signature · 5 lines
Catalin
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#43 lore raw

Re: [PATCH v11 10/40] arm64/sme: Basic enumeration support

Quoted 6 lines · Catalin Marinas

arch/arm64/kernel/cpufeature.c static const struct arm64_ftr_bits ftr_id_aa64pfr0[] = { · line 254

Quoted 2 lines · Mark Brown

static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = {

arch/arm64/kernel/cpufeature.c +1 -0
+	ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_SME_SHIFT, 4, 0),

Shouldn't this field also be visible (if SME is enabled)?

Yes.

Quoted 7 lines
Quoted 7 lines
arch/arm64/kernel/fpsimd.c +7 -0
+/*
+ * This must be called after sme_kernel_enable(), we rely on the
+ * feature table being sorted to ensure this.
+ */
+void fa64_kernel_enable(const struct arm64_cpu_capabilities *__always_unused p)
+{
+	/* Allow use of FA64 */
Quoted 8 lines

arch/arm64/kernel/fpsimd.c void fpsimd_release_task(struct task_struct *dead_task) · line 1014

Quoted 5 lines
arch/arm64/kernel/fpsimd.c +5 -0
+	write_sysreg_s(read_sysreg_s(SYS_SMCR_EL1) | SMCR_ELx_FA64_MASK,
+		       SYS_SMCR_EL1);
+}
+
+#endif /* CONFIG_ARM64_SVE */

I think instead of worrying about the order, we could check the sanitised register value in sme_kernel_enable() and set the FA64 bit.

There's going to be a ordering/clarity issue whatever way round we do it
- the FA64 feature bit is in a different feature register to the main SME feature bitfield and it's not as abundantly clear as might be ideal that it will have been sanitised when we're getting callbacks for the main SME feature, there's an awful lot of sharp edges with this code. Having things this way round felt more idiomatic to me.

Quoted 3 lines

Also to me 'fa64_kernel_enable' somehow implies that the kernel cares about FA64 for itself but AFAICT we never run the kernel in streaming mode.

We do run the kernel in streaming mode - entering the kernel through a syscall or preemption will not change the streaming mode state, and we need to be in streaming mode in order to save or restore the register state for streaming mode. In particular we need FA64 enabled for EL1 in order to context switch FFR when in streaming mode, without it we'll generate an exception when we execute the rdffr or wrffr. We don't do any real floating point work in streaming mode but we absolutely need to run in streaming mode and only exit streaming mode when restoring a context where it is disabled, when using floating point in the kernel or when idling the CPU.

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

maintainer
#50 lore raw

Re: [PATCH v11 11/40] arm64/sme: Identify supported SME vector lengths at boot

In reply to Mark Brown

arch/arm64/kernel/cpufeature.c void __init init_cpu_features(struct cpuinfo_arm64 *info) · line 993

Quoted 11 lines · Mark Brown
arch/arm64/kernel/cpufeature.c +7 -0
@@ -977,6 +984,14 @@ void __init init_cpu_features(struct cpuinfo_arm64 *info)
 		vec_init_vq_map(ARM64_VEC_SVE);
 	}
 
+	if (id_aa64pfr1_sme(info->reg_id_aa64pfr1)) {
+		init_cpu_ftr_reg(SYS_SMCR_EL1, info->reg_smcr);
+		if (IS_ENABLED(CONFIG_ARM64_SME)) {
+			sme_kernel_enable(NULL);
+			vec_init_vq_map(ARM64_VEC_SME);
+		}
+	}

Why do we need to call sme_kernel_enable() here? It's called again later via the cpufeature framework. I guess you need the CPACR_EL1 setup but we don't seem to do this for SVE.

Signature · 1 line
Catalin
#47 lore raw

Re: [PATCH v11 10/40] arm64/sme: Basic enumeration support

In reply to Catalin Marinas
Quoted 38 lines · Catalin Marinas
Quoted 37 lines · Mark Brown
Documentation/arm64/elf_hwcaps.rst +29 -0
index b72ff17d600a..5626cf208000 100644
@@ -259,6 +259,39 @@ HWCAP2_RPRES
 
     Functionality implied by ID_AA64ISAR2_EL1.RPRES == 0b0001.
 
+HWCAP2_SME
+
+    Functionality implied by ID_AA64PFR1_EL1.SME == 0b0001, as described
+    by Documentation/arm64/sme.rst.
+
+HWCAP2_SME_I16I64
+
+    Functionality implied by ID_AA64SMFR0_EL1.I16I64 == 0b1111.
+
+HWCAP2_SME_F64F64
+
+    Functionality implied by ID_AA64SMFR0_EL1.F64F64 == 0b1.
+
+HWCAP2_SME_I8I32
+
+    Functionality implied by ID_AA64SMFR0_EL1.I8I32 == 0b1111.
+
+HWCAP2_SME_F16F32
+
+    Functionality implied by ID_AA64SMFR0_EL1.F16F32 == 0b1.
+
+HWCAP2_SME_B16F32
+
+    Functionality implied by ID_AA64SMFR0_EL1.B16F32 == 0b1.
+
+HWCAP2_SME_F32F32
+
+    Functionality implied by ID_AA64SMFR0_EL1.F32F32 == 0b1.
+
Quoted 9 lines

Documentation/arm64/elf_hwcaps.rst HWCAP2_RPRES · line 293

Quoted 3 lines
Documentation/arm64/elf_hwcaps.rst +3 -0
+HWCAP2_SME_FA64
+
+    Functionality implied by ID_AA64SMFR0_EL1.FA64 == 0b1.

More of a question for the libc people: should we drop the fine-grained HWCAP corresponding to the new ID_AA64SMFR0_EL1 register (only keep HWCAP2_SME) and get the user space to use the MRS emulation? Would any ifunc resolver be affected?

good question.

within glibc HWCAP2_SME is enough (to decide if we need to deal with additional register state and the lazy ZA save scheme) but i guess user code that actually uses sme would need the details (including in ifunc resolvers in principle).

since we have mrs, there is no strict need for hwcaps. if ifunc resolvers using this info are not widespread then the mrs emulation overhead is acceptable, but i suspect hwcaps are nicer to use.

do we have a plan after hwcap2 bits run out? :)

maintainer Reviewed-by on v11 12/40
#53 lore raw

Re: [PATCH v11 12/40] arm64/sme: Implement sysctl to set the default vector length

In reply to Mark Brown
Quoted 4 lines · Mark Brown

As for SVE provide a sysctl which allows the default SME vector length to be configured.

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

maintainer Reviewed-by on v11 14/40
#57 lore raw

Re: [PATCH v11 14/40] arm64/sme: Implement support for TPIDR2

In reply to Mark Brown
Quoted 11 lines · Mark Brown

The Scalable Matrix Extension introduces support for a new thread specific data register TPIDR2 intended for use by libc. The kernel must save the value of TPIDR2 on context switch and should ensure that all new threads start off with a default value of 0. Add a field to the thread_struct to store TPIDR2 and context switch it with the other thread specific data.

In case there are future extensions which also use TPIDR2 we introduce system_supports_tpidr2() and use that rather than system_supports_sme() for TPIDR2 handling.

I think this matches the ABI per the documentation (and the subsequent discussion we had).

maintainer Reviewed-by on v11 15/40
#59 lore raw

Re: [PATCH v11 15/40] arm64/sme: Implement SVCR context switching

In reply to Mark Brown
Quoted 6 lines · Mark Brown

In SME the use of both streaming SVE mode and ZA are tracked through PSTATE.SM and PSTATE.ZA, visible through the system register SVCR. In order to context switch the floating point state for SME we need to context switch the contents of this register as part of context switching the floating point state.

Quoted 6 lines

Since changing the vector length exits streaming SVE mode and disables ZA we also make sure we update SVCR appropriately when setting vector length, and similarly ensure that new threads have streaming SVE mode and ZA disabled.

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

maintainer
#48 lore raw

Re: [PATCH v11 10/40] arm64/sme: Basic enumeration support

In reply to Szabolcs Nagy
Quoted 55 lines · Szabolcs Nagy
Quoted 38 lines · Catalin Marinas
Quoted 37 lines · Mark Brown
Documentation/arm64/elf_hwcaps.rst +29 -0
index b72ff17d600a..5626cf208000 100644
@@ -259,6 +259,39 @@ HWCAP2_RPRES
 
     Functionality implied by ID_AA64ISAR2_EL1.RPRES == 0b0001.
 
+HWCAP2_SME
+
+    Functionality implied by ID_AA64PFR1_EL1.SME == 0b0001, as described
+    by Documentation/arm64/sme.rst.
+
+HWCAP2_SME_I16I64
+
+    Functionality implied by ID_AA64SMFR0_EL1.I16I64 == 0b1111.
+
+HWCAP2_SME_F64F64
+
+    Functionality implied by ID_AA64SMFR0_EL1.F64F64 == 0b1.
+
+HWCAP2_SME_I8I32
+
+    Functionality implied by ID_AA64SMFR0_EL1.I8I32 == 0b1111.
+
+HWCAP2_SME_F16F32
+
+    Functionality implied by ID_AA64SMFR0_EL1.F16F32 == 0b1.
+
+HWCAP2_SME_B16F32
+
+    Functionality implied by ID_AA64SMFR0_EL1.B16F32 == 0b1.
+
+HWCAP2_SME_F32F32
+
+    Functionality implied by ID_AA64SMFR0_EL1.F32F32 == 0b1.
+
Quoted 8 lines

Documentation/arm64/elf_hwcaps.rst HWCAP2_RPRES · line 293

Quoted 3 lines
Documentation/arm64/elf_hwcaps.rst +3 -0
+HWCAP2_SME_FA64
+
+    Functionality implied by ID_AA64SMFR0_EL1.FA64 == 0b1.

More of a question for the libc people: should we drop the fine-grained HWCAP corresponding to the new ID_AA64SMFR0_EL1 register (only keep HWCAP2_SME) and get the user space to use the MRS emulation? Would any ifunc resolver be affected?

good question.

within glibc HWCAP2_SME is enough (to decide if we need to deal with additional register state and the lazy ZA save scheme) but i guess user code that actually uses sme would need the details (including in ifunc resolvers in principle).

Quoted 4 lines

since we have mrs, there is no strict need for hwcaps. if ifunc resolvers using this info are not widespread then the mrs emulation overhead is acceptable, but i suspect hwcaps are nicer to use.

I presume the ifunc resolvers only run once, so the overhead won't be noticed. Anyway, happy to keep the new HWCAP2 if they are useful.

Quoted 1 line

do we have a plan after hwcap2 bits run out? :)

HWCAP3 or we free up the top 32-bit in both HWCAP and HWCAP2 ranges. We did not extend into those upper bits because of the ILP32 discussions at the time.

Signature · 1 line
Catalin
maintainer
#44 lore raw

Re: [PATCH v11 10/40] arm64/sme: Basic enumeration support

In reply to Mark Brown
Quoted 18 lines · Mark Brown
Quoted 16 lines · Catalin Marinas

arch/arm64/kernel/fpsimd.c void fpsimd_release_task(struct task_struct *dead_task) · line 1014

Quoted 12 lines · Mark Brown
arch/arm64/kernel/fpsimd.c +12 -0
+/*
+ * This must be called after sme_kernel_enable(), we rely on the
+ * feature table being sorted to ensure this.
+ */
+void fa64_kernel_enable(const struct arm64_cpu_capabilities *__always_unused p)
+{
+	/* Allow use of FA64 */
+	write_sysreg_s(read_sysreg_s(SYS_SMCR_EL1) | SMCR_ELx_FA64_MASK,
+		       SYS_SMCR_EL1);
+}
+
+#endif /* CONFIG_ARM64_SVE */

I think instead of worrying about the order, we could check the sanitised register value in sme_kernel_enable() and set the FA64 bit.

Quoted 6 lines

There's going to be a ordering/clarity issue whatever way round we do it
- the FA64 feature bit is in a different feature register to the main SME feature bitfield and it's not as abundantly clear as might be ideal that it will have been sanitised when we're getting callbacks for the main SME feature, there's an awful lot of sharp edges with this code. Having things this way round felt more idiomatic to me.

You may want to add a comment in the cpu_feature[] array that it should be placed after SME.

Quoted 4 lines
Quoted 3 lines

Also to me 'fa64_kernel_enable' somehow implies that the kernel cares about FA64 for itself but AFAICT we never run the kernel in streaming mode.

Quoted 10 lines

We do run the kernel in streaming mode - entering the kernel through a syscall or preemption will not change the streaming mode state, and we need to be in streaming mode in order to save or restore the register state for streaming mode. In particular we need FA64 enabled for EL1 in order to context switch FFR when in streaming mode, without it we'll generate an exception when we execute the rdffr or wrffr. We don't do any real floating point work in streaming mode but we absolutely need to run in streaming mode and only exit streaming mode when restoring a context where it is disabled, when using floating point in the kernel or when idling the CPU.

So, IIUC, for Linux it is mandatory that FEAT_SME_FA64 is supported, otherwise we won't be able to enable SME. Does the architecture say this feature as optional? Which A64 instructions are not available if FA64 is disabled? I hope it's only the SVE ones but I thought we can still do load/store of the state even with FA64 disabled.

Anyway, if we can't even context switch without FA64 while in streaming mode, I think we should move the check in the main SME .matches function and enable it in sme_kernel_enable(), no need for an additional feature.

I think we should also update booting.rst to require that the FA64 is enabled at EL2 and EL3.

Signature · 1 line
Catalin
author
#45 lore raw

Re: [PATCH v11 10/40] arm64/sme: Basic enumeration support

Quoted 11 lines · Catalin Marinas
Quoted 6 lines · Mark Brown

There's going to be a ordering/clarity issue whatever way round we do it
- the FA64 feature bit is in a different feature register to the main SME feature bitfield and it's not as abundantly clear as might be ideal that it will have been sanitised when we're getting callbacks for the main SME feature, there's an awful lot of sharp edges with this code. Having things this way round felt more idiomatic to me.

You may want to add a comment in the cpu_feature[] array that it should be placed after SME.

Sure.

Quoted 11 lines
Quoted 10 lines

We do run the kernel in streaming mode - entering the kernel through a syscall or preemption will not change the streaming mode state, and we need to be in streaming mode in order to save or restore the register state for streaming mode. In particular we need FA64 enabled for EL1 in order to context switch FFR when in streaming mode, without it we'll generate an exception when we execute the rdffr or wrffr. We don't do any real floating point work in streaming mode but we absolutely need to run in streaming mode and only exit streaming mode when restoring a context where it is disabled, when using floating point in the kernel or when idling the CPU.

Quoted 2 lines

So, IIUC, for Linux it is mandatory that FEAT_SME_FA64 is supported, otherwise we won't be able to enable SME. Does the architecture say

The feature is not mandatory and we do not require it for Linux. It is expected that many implementations will choose to not support FA64.

The only impact it has on the kernel is that if it's present then we need to enable it for each EL and then context switch FFR in streaming mode, the code is there to do that conditionally already. We'd also have to take it into account if we were to run streaming mode algorithms in the kernel but if we ever do so that's just an additional feature check when choosing to run such code.

Quoted 3 lines

this feature as optional? Which A64 instructions are not available if FA64 is disabled? I hope it's only the SVE ones but I thought we can still do load/store of the state even with FA64 disabled.

There's a rather large subset of mostly FPSIMD and some SVE instructions (including those for accessing FFR which is why we don't need to context switch it in streaming mode), you can see a full list in appendix F1 of the SME specification.

This is actually a bit awkward for not disabling streaming mode when we do a syscall since the disabled instructions include the FPSMID mov vector, vector instruction which we currently use to zero the high bits of the Z registers. That issue goes away if the optimisations I've got for relaxed flushing of the non-shared SVE state that we discussed in relation to syscall-abi get merged, though it'd still be there if we add a sysctl to force flushing. This is a solvable problem though, even if we have to use a less efficient sequence to flush in streaming mode.

Quoted 3 lines

Anyway, if we can't even context switch without FA64 while in streaming mode, I think we should move the check in the main SME .matches function and enable it in sme_kernel_enable(), no need for an additional feature.

Given that it's optional and we need to check for it at runtime in order to context switch it seems sensible to use the cpufeature infrastructure for the detection.

Quoted 2 lines

I think we should also update booting.rst to require that the FA64 is enabled at EL2 and EL3.

That's there already since d198c77b7fab13d4 ("arm64: Document boot requirements for FEAT_SME_FA64").

author
#51 lore raw

Re: [PATCH v11 11/40] arm64/sme: Identify supported SME vector lengths at boot

In reply to Catalin Marinas
Quoted 9 lines · Catalin Marinas

arch/arm64/kernel/cpufeature.c void __init init_cpu_features(struct cpuinfo_arm64 *info) · line 991

Quoted 3 lines · Mark Brown
arch/arm64/kernel/cpufeature.c +3 -0
+		if (IS_ENABLED(CONFIG_ARM64_SME)) {
+			sme_kernel_enable(NULL);
+			vec_init_vq_map(ARM64_VEC_SME);

Why do we need to call sme_kernel_enable() here? It's called again later via the cpufeature framework. I guess you need the CPACR_EL1 setup but we don't seem to do this for SVE.

It's not needed any more, it's bit rot.

maintainer
#46 lore raw

Re: [PATCH v11 10/40] arm64/sme: Basic enumeration support

In reply to Mark Brown
Quoted 16 lines · Mark Brown
Quoted 12 lines · Catalin Marinas
Quoted 10 lines · Mark Brown

We do run the kernel in streaming mode - entering the kernel through a syscall or preemption will not change the streaming mode state, and we need to be in streaming mode in order to save or restore the register state for streaming mode. In particular we need FA64 enabled for EL1 in order to context switch FFR when in streaming mode, without it we'll generate an exception when we execute the rdffr or wrffr. We don't do any real floating point work in streaming mode but we absolutely need to run in streaming mode and only exit streaming mode when restoring a context where it is disabled, when using floating point in the kernel or when idling the CPU.

Quoted 2 lines

So, IIUC, for Linux it is mandatory that FEAT_SME_FA64 is supported, otherwise we won't be able to enable SME. Does the architecture say

Quoted 6 lines

The feature is not mandatory and we do not require it for Linux. It is expected that many implementations will choose to not support FA64.

The only impact it has on the kernel is that if it's present then we need to enable it for each EL and then context switch FFR in streaming mode, the code is there to do that conditionally already.

OK, I get it. So FFR is only present if FA64 is supported.

Quoted 8 lines

This is actually a bit awkward for not disabling streaming mode when we do a syscall since the disabled instructions include the FPSMID mov vector, vector instruction which we currently use to zero the high bits of the Z registers. That issue goes away if the optimisations I've got for relaxed flushing of the non-shared SVE state that we discussed in relation to syscall-abi get merged, though it'd still be there if we add a sysctl to force flushing. This is a solvable problem though, even if we have to use a less efficient sequence to flush in streaming mode.

I guess the simplest is to just disable streaming mode on syscall. The C library would mark the syscall wrappers as not streaming compatible, so whoever is calling them might disable SM anyway.

So I think your original proposal in the ABI doc is fine (I just need the libc people to confirm ;)).

Signature · 1 line
Catalin
maintainer Reviewed-by on v11 16/40
#61 lore raw

Re: [PATCH v11 16/40] arm64/sme: Implement streaming SVE context switching

In reply to Mark Brown
Quoted 8 lines · Mark Brown

When in streaming mode we need to save and restore the streaming mode SVE register state rather than the regular SVE register state. This uses the streaming mode vector length and omits FFR but is otherwise identical, if TIF_SVE is enabled when we are in streaming mode then streaming mode takes precedence.

This does not handle use of streaming SVE state with KVM, ptrace or signals. This will be updated in further patches.

I think I get this but a state diagram somewhere would help ;).

IIUC you don't disable SM on a context switch, you just leave it in place until a task_fpsimd_load(). It shouldn't be a problem as kernel_neon_begin() disables it anyway.

maintainer Reviewed-by on v11 17/40
#64 lore raw

Re: [PATCH v11 17/40] arm64/sme: Implement ZA context switching

In reply to Mark Brown
Quoted 11 lines · Mark Brown

Allocate space for storing ZA on first access to SME and use that to save and restore ZA state when context switching. We do this by using the vector form of the LDR and STR ZA instructions, these do not require streaming mode and have implementation recommendations that they avoid contention issues in shared SMCU implementations.

Since ZA is architecturally guaranteed to be zeroed when enabled we do not need to explicitly zero ZA, either we will be restoring from a saved copy or trapping on first use of SME so we know that ZA must be disabled.

author
#62 lore raw

Re: [PATCH v11 16/40] arm64/sme: Implement streaming SVE context switching

In reply to Catalin Marinas
Quoted 5 lines · Catalin Marinas

I think I get this but a state diagram somewhere would help ;).

IIUC you don't disable SM on a context switch, you just leave it in place until a task_fpsimd_load(). It shouldn't be a problem as kernel_neon_begin() disables it anyway.

Yes, streaming mode is part of the floating point state and this is how we handle floating point in general - it's part of what's tracked with TIF_FOREIGN_FPSTATE. Unless we want to do something with floating point we don't touch it.

maintainer
#66 lore raw

Re: [PATCH v11 18/40] arm64/sme: Implement traps and syscall handling for SME

In reply to Mark Brown
Quoted 10 lines · Mark Brown

By default all SME operations in userspace will trap. When this happens we allocate storage space for the SME register state, set up the SVE registers and disable traps. We do not need to initialize ZA since the architecture guarantees that it will be zeroed when enabled and when we trap ZA is disabled.

On syscall we exit streaming mode if we were previously in it and ensure that all but the lower 128 bits of the registers are zeroed while preserving the state of ZA. This follows the aarch64 PCS for SME, ZA state is preserved over a function call and streaming mode is exited.

I'm not sure this is entirely correct about the PCS. The caller must disable SM if the function it calls is not compatible. But it's fine for the kernel to impose this at the ABI level.

Quoted 9 lines
arch/arm64/kernel/fpsimd.c +5 -0
@@ -409,6 +415,21 @@ static void task_fpsimd_load(void)
 			       restore_ffr);
 	else
 		fpsimd_load_state(&current->thread.uw.fpsimd_state);
+
+	/*
+	 * If we didn't set up any SVE registers but we do have SME
+	 * enabled for userspace then ensure the SVE registers are
+	 * flushed since userspace can switch to streaming mode and

arch/arm64/kernel/fpsimd.c static void task_fpsimd_load(void) · line 432

Quoted 10 lines
arch/arm64/kernel/fpsimd.c +10 -0
+	 * view the register state without trapping.
+	 */
+	if (system_supports_sme() && test_thread_flag(TIF_SME) &&
+	    !restore_sve_regs) {
+		int sve_vq_minus_one;
+
+		sve_vq_minus_one = sve_vq_from_vl(task_get_sve_vl(current)) - 1;
+		sve_set_vq(sve_vq_minus_one);
+		sve_flush_live(true, sve_vq_minus_one);
+	}

Shouldn't the SVE state be flushed by the hardware when switching to streaming mode?

Quoted 4 lines
arch/arm64/kernel/syscall.c +4 -0
+/*
+ * As per the ABI exit SME streaming mode and clear the SVE state not
+ * shared with FPSIMD on syscall entry.
+ */

arch/arm64/kernel/syscall.c static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr, · line 174

Quoted 10 lines
arch/arm64/kernel/syscall.c +9 -0
+static inline void fp_user_discard(void)
 {
+	/*
+	 * If SME is active then exit streaming mode.  If ZA is active
+	 * then flush the SVE registers but leave userspace access to
+	 * both SVE and SME enabled, otherwise disable SME for the
+	 * task and fall through to disabling SVE too.  This means
+	 * that after a syscall we never have any SME register state
+	 * to track, if this changes the KVM code will need updating.
+	 */

By "we never have any SME register state to track" I understand that we drop the ZA state as well which AFAICT is not the case.

Quoted 11 lines
arch/arm64/kernel/syscall.c +11 -0
+	if (system_supports_sme() && test_thread_flag(TIF_SME)) {
+		u64 svcr = read_sysreg_s(SYS_SVCR_EL0);
+
+		if (svcr & SYS_SVCR_EL0_SM_MASK)
+			sme_smstop_sm();
+
+		if (!(svcr & SYS_SVCR_EL0_ZA_MASK)) {
+			clear_thread_flag(TIF_SME);
+			sme_user_disable();
+		}
+	}
Signature · 1 line
Catalin
author
#67 lore raw

Re: [PATCH v11 18/40] arm64/sme: Implement traps and syscall handling for SME

Quoted 10 lines · Catalin Marinas
Quoted 4 lines · Mark Brown

On syscall we exit streaming mode if we were previously in it and ensure that all but the lower 128 bits of the registers are zeroed while preserving the state of ZA. This follows the aarch64 PCS for SME, ZA state is preserved over a function call and streaming mode is exited.

I'm not sure this is entirely correct about the PCS. The caller must disable SM if the function it calls is not compatible. But it's fine for the kernel to impose this at the ABI level.

Yeah, I was thinking of it as being constructive error handling for being a normal function - if this were within userspace then the risk for the caller would be a SIGILL when the called function tries to do something that's invalid in streaming mode. I'll tweak the text.

Quoted 11 lines

arch/arm64/kernel/fpsimd.c static void task_fpsimd_load(void) · line 432

Quoted 8 lines
arch/arm64/kernel/fpsimd.c +8 -0
+	if (system_supports_sme() && test_thread_flag(TIF_SME) &&
+	    !restore_sve_regs) {
+		int sve_vq_minus_one;
+
+		sve_vq_minus_one = sve_vq_from_vl(task_get_sve_vl(current)) - 1;
+		sve_set_vq(sve_vq_minus_one);
+		sve_flush_live(true, sve_vq_minus_one);
+	}

Shouldn't the SVE state be flushed by the hardware when switching to streaming mode?

Ah, yes - this is now the case. In earlier revisions of the specification it was implementation defined if the state was zeroed or preserved so we had to clear but with the current version the state will always be zeroed so the flush is redundant and can be deleted.

Quoted 11 lines

arch/arm64/kernel/syscall.c static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr, · line 174

Quoted 8 lines
arch/arm64/kernel/syscall.c +8 -0
+	/*
+	 * If SME is active then exit streaming mode.  If ZA is active
+	 * then flush the SVE registers but leave userspace access to
+	 * both SVE and SME enabled, otherwise disable SME for the
+	 * task and fall through to disabling SVE too.  This means
+	 * that after a syscall we never have any SME register state
+	 * to track, if this changes the KVM code will need updating.
+	 */

By "we never have any SME register state to track" I understand that we drop the ZA state as well which AFAICT is not the case.

s/SME/streaming SVE/

maintainer Reviewed-by on v11 20/40
#71 lore raw

Re: [PATCH v11 20/40] arm64/sme: Implement streaming SVE signal handling

In reply to Mark Brown
Quoted 5 lines · Mark Brown

When in streaming mode we have the same set of SVE registers as we do in regular SVE mode with the exception of FFR and the use of the SME vector length. Provide signal handling for these registers by taking one of the reserved words in the SVE signal context as a flags field and defining a flag with a flag which is set for streaming mode. When the flag is set the

Too many "flag" words.

Quoted 10 lines
arch/arm64/kernel/signal.c +3 -2
@@ -593,11 +613,16 @@ static int setup_sigframe_layout(struct rt_sigframe_user_layout *user,
 	if (system_supports_sve()) {
 		unsigned int vq = 0;
 
-		if (add_all || test_thread_flag(TIF_SVE)) {
-			int vl = sve_max_vl();
+		if (add_all || test_thread_flag(TIF_SVE) ||
+		    thread_sm_enabled(&current->thread)) {
+			int vl = max(sve_max_vl(), sme_max_vl());
 

arch/arm64/kernel/signal.c static int setup_sigframe_layout(struct rt_sigframe_user_layout *user, · line 627

Quoted 10 lines
arch/arm64/kernel/signal.c +6 -2
-			if (!add_all)
-				vl = task_get_sve_vl(current);
+			if (!add_all) {
+				if (thread_sm_enabled(&current->thread))
+					vl = task_get_sme_vl(current);
+				else
+					vl = task_get_sve_vl(current);
+			}
 
 			vq = sve_vq_from_vl(vl);

Nitpick: this looks a bit too complicated, maybe split it in three separate if/else blocks.

Either way,

maintainer Reviewed-by on v11 21/40
#73 lore raw

Re: [PATCH v11 21/40] arm64/sme: Implement ZA signal handling

In reply to Mark Brown
Quoted 10 lines · Mark Brown

Implement support for ZA in signal handling in a very similar way to how we implement support for SVE registers, using a signal context structure with optional register state after it. Where present this register state stores the ZA matrix as a series of horizontal vectors numbered from 0 to VL/8 in the endinanness independent format used for vectors.

As with SVE we do not allow changes in the vector length during signal return but we do allow ZA to be enabled or disabled.

This follows the SVE implementation closely. It looks fine to me:

maintainer Reviewed-by on v11 22/40
#75 lore raw

Re: [PATCH v11 22/40] arm64/sme: Implement ptrace support for streaming mode SVE registers

In reply to Mark Brown
Quoted 11 lines · Mark Brown
arch/arm64/kernel/fpsimd.c +1 -1
index 2242c14a5a05..8b111b7f2006 100644
@@ -645,14 +645,19 @@ static void __fpsimd_to_sve(void *sst, struct user_fpsimd_state const *fst,
  */
 static void fpsimd_to_sve(struct task_struct *task)
 {
-	unsigned int vq;
+	unsigned int vq, vl;
 	void *sst = task->thread.sve_state;

arch/arm64/kernel/fpsimd.c static void __fpsimd_to_sve(void *sst, struct user_fpsimd_state const *fst, · line 658

Quoted 10 lines
arch/arm64/kernel/fpsimd.c +4 -1
 	struct user_fpsimd_state const *fst = &task->thread.uw.fpsimd_state;
 
 	if (!system_supports_sve())
 		return;
 
-	vq = sve_vq_from_vl(task_get_sve_vl(task));
+	if (thread_sm_enabled(&task->thread))
+		vl = task_get_sme_vl(task);
+	else
+		vl = task_get_sve_vl(task);

I saw this construct in the signal patches as well. Can we have a function/macro that checks the SM enabled and returns the proper vl?

Otherwise,

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

maintainer Reviewed-by on v11 23/40
#77 lore raw

Re: [PATCH v11 23/40] arm64/sme: Add ptrace support for ZA

In reply to Mark Brown
Quoted 7 lines · Mark Brown

The ZA array can be read and written with the NT_ARM_ZA. Similarly to our interface for the SVE vector registers the regset consists of a header with information on the current vector length followed by an optional register data payload, represented as for signals as a series of horizontal vectors from 0 to VL/8 in the endianness independent format used for vectors.

Quoted 6 lines

On get if ZA is enabled then register data will be provided, otherwise it will be omitted. On set if register data is provided then ZA is enabled and initialized using the provided data, otherwise it is disabled.

The patch looks fine to be but I'd like Luis to look at the ptrace ABI in this series.

maintainer Reviewed-by on v11 24/40
#79 lore raw

Re: [PATCH v11 24/40] arm64/sme: Disable streaming mode and ZA when flushing CPU state

In reply to Mark Brown
Quoted 7 lines · Mark Brown

Both streaming mode and ZA may increase power consumption when they are enabled and streaming mode makes many FPSIMD and SVE instructions undefined which will cause problems for any kernel mode floating point so disable both when we flush the CPU state. This covers both kernel_neon_begin() and idle and after flushing the state a reload is always required anyway.

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

maintainer Reviewed-by on v11 25/40
#81 lore raw

Re: [PATCH v11 25/40] arm64/sme: Save and restore streaming mode over EFI runtime calls

In reply to Mark Brown
Quoted 10 lines · Mark Brown

When saving and restoring the floating point state over an EFI runtime call ensure that we handle streaming mode, only handling FFR if we are not in streaming mode and ensuring that we are in normal mode over the call into runtime services.

We currently assume that ZA will not be modified by runtime services, the specification is not yet finalised so this may need updating if that changes.

maintainer Reviewed-by on v11 26/40
#83 lore raw

Re: [PATCH v11 26/40] KVM: arm64: Hide SME system registers from guests

In reply to Mark Brown
Quoted 7 lines · Mark Brown

For the time being we do not support use of SME by KVM guests, support for this will be enabled in future. In order to prevent any side effects or side channels via the new system registers, including the EL0 read/write register TPIDR2, explicitly undefine all the system registers added by SME and mask out the SME bitfield in SYS_ID_AA64PFR1.

maintainer Reviewed-by on v11 27/40
#85 lore raw

Re: [PATCH v11 27/40] KVM: arm64: Trap SME usage in guest

In reply to Mark Brown
Quoted 8 lines · Mark Brown

SME defines two new traps which need to be enabled for guests to ensure that they can't use SME, one for the main SME operations which mirrors the traps for SVE and another for access to TPIDR2 in SCTLR_EL2.

For VHE manage SMEN along with ZEN in activate_traps() and the FP state management callbacks, along with SCTLR_EL2.EnTPIDR2. There is no existing dynamic management of SCTLR_EL2.

Quoted 5 lines

For nVHE manage TSM in activate_traps() along with the fine grained traps for TPIDR2 and SMPRI. There is no existing dynamic management of fine grained traps.

This looks alright to me but I'm not a kvm expert. FWIW:

maintainer Reviewed-by on v11 28/40
#87 lore raw

Re: [PATCH v11 28/40] KVM: arm64: Handle SME host state when running guests

In reply to Mark Brown
Quoted 18 lines · Mark Brown

While we don't currently support SME in guests we do currently support it for the host system so we need to take care of SME's impact, including the floating point register state, when running guests. Simiarly to SVE we need to manage the traps in CPACR_RL1, what is new is the handling of streaming mode and ZA.

Normally we defer any handling of the floating point register state until the guest first uses it however if the system is in streaming mode FPSIMD and SVE operations may generate SME traps which we would need to distinguish from actual attempts by the guest to use SME. Rather than do this for the time being if we are in streaming mode when entering the guest we force the floating point state to be saved immediately and exit streaming mode, meaning that the guest won't generate SME traps for supported operations.

We could handle ZA in the access trap similarly to the FPSIMD/SVE state without the disruption caused by streaming mode but for simplicity handle it the same way as streaming mode for now.

Quoted 5 lines

This will be revisited when we support SME for guests (hopefully before SME hardware becomes available), for now it will only incur additional cost on systems with SME and even there only if streaming mode or ZA are enabled.

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

maintainer Reviewed-by on v11 29/40
#93 lore raw

Re: [PATCH v11 29/40] arm64/sme: Provide Kconfig for SME

In reply to Mark Brown
Quoted 7 lines · Mark Brown

Now that basline support for the Scalable Matrix Extension (SME) is present introduce the Kconfig option allowing it to be built. While the feature registers don't impose a strong requirement for a system with SME to support SVE at runtime the support for streaming mode SVE is mostly shared with normal SVE so depend on SVE.

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

maintainer Acked-by on v11 31/40
#100 lore raw

Re: [PATCH v11 31/40] kselftest/arm64: sme: Add SME support to vlset

In reply to Mark Brown
Quoted 6 lines · Mark Brown

The Scalable Matrix Extenions (SME) introduces additional register state with configurable vector lengths, similar to SVE but configured separately. Extend vlset to support configuring this state with a --sme or -s command line option.

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

maintainer Acked-by on v11 32/40
#104 lore raw

Re: [PATCH v11 32/40] kselftest/arm64: Add tests for TPIDR2

In reply to Mark Brown
Quoted 19 lines · Mark Brown

The Scalable Matrix Extension adds a new system register TPIDR2 intended to be used by libc for its own thread specific use, add some kselftests which exercise the ABI for it.

Since this test should with some adjustment work for TPIDR and any other similar registers added in future add tests for it in a separate directory rather than placing it with the other floating point tests, nothing existing looked suitable so I created a new test directory called "abi".

Since this feature is intended to be used by libc the test is built as freestanding code using nolibc so we don't end up with the test program and libc both trying to manage the register simultaneously and distrupting each other. As a result of being written using nolibc rather than using hwcaps to identify if SME is available in the system we check for the default SME vector length configuration in proc, adding hwcap support to nolibc seems like disproportionate effort and didn't feel entirely idiomatic for what nolibc is trying to do.

Quoted 1 line
maintainer Acked-by on v11 34/40
#111 lore raw

Re: [PATCH v11 34/40] kselftest/arm64: sme: Provide streaming mode SVE stress test

In reply to Mark Brown
Quoted 6 lines · Mark Brown

One of the features of SME is the addition of streaming mode, in which we have access to a set of streaming mode SVE registers at the SME vector length. Since these are accessed using the SVE instructions let's reuse the existing SVE stress test for testing with a compile time option for controlling the few small differences needed:

Quoted 7 lines

- Enter streaming mode immediately on starting the program.
- In streaming mode FFR is removed so skip reading and writing FFR.

In order to avoid requiring a cutting edge toolchain with SME support use the op/CR form for specifying SVCR.

maintainer Acked-by on v11 35/40
#115 lore raw

Re: [PATCH v11 35/40] kselftest/arm64: signal: Handle ZA signal context in core code

In reply to Mark Brown
Quoted 6 lines · Mark Brown

As part of the generic code for signal handling test cases we parse all signal frames to make sure they have at least the basic form we expect and that there are no unexpected frames present in the signal context. Add coverage of the ZA signal frame to this code.

maintainer Acked-by on v11 36/40
#117 lore raw

Re: [PATCH v11 36/40] kselftest/arm64: Add stress test for SME ZA context switching

In reply to Mark Brown
Quoted 9 lines · Mark Brown

Add a stress test for context switching of the ZA register state based on the similar tests Dave Martin wrote for FPSIMD and SVE registers. The test loops indefinitely writing a data pattern to ZA then reading it back and verifying that it's what was expected.

Unlike the other tests we manually assemble the SME instructions since at present no released toolchain has SME support integrated.

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

maintainer Acked-by on v11 37/40
#121 lore raw

Re: [PATCH v11 37/40] kselftest/arm64: signal: Add SME signal handling tests

In reply to Mark Brown
Quoted 10 lines · Mark Brown

Add test cases for the SME signal handing ABI patterned off the SVE tests. Due to the small size of the tests and the differences in ABI (especially around needing to account for both streaming SVE and ZA) there is some code duplication here.

We currently cover:
- Reporting of the vector length.
- Lack of support for changing vector length.
- Presence and size of register state for streaming SVE and ZA.

Quoted 4 lines

As with the SVE tests we do not yet have any validation of register contents.

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

maintainer Acked-by on v11 38/40
#124 lore raw

Re: [PATCH v11 38/40] kselftest/arm64: Add streaming SVE to SVE ptrace tests

In reply to Mark Brown
Quoted 7 lines · Mark Brown

In order to allow ptrace of streaming mode SVE registers we have added a new regset for streaming mode which in isolation offers the same ABI as regular SVE with a different vector type. Add this to the array of regsets we handle, together with additional tests for the interoperation of the two regsets.

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

maintainer Acked-by on v11 39/40
#127 lore raw

Re: [PATCH v11 39/40] kselftest/arm64: Add coverage for the ZA ptrace interface

In reply to Mark Brown
Quoted 8 lines · Mark Brown

Add some basic coverage for the ZA ptrace interface, including walking through all the vector lengths supported in the system. Unlike SVE doing syscalls does not discard the ZA state so when we set data in ZA we run the child process briefly, having it add one to each byte in ZA in order to validate that both the vector size and data are being read and written as expected when the process runs.

maintainer Acked-by on v11 40/40
#132 lore raw

Re: [PATCH v11 40/40] kselftest/arm64: Add SME support to syscall ABI test

In reply to Mark Brown
Quoted 8 lines · Mark Brown

For every possible combination of SVE and SME vector length verify that for each possible value of SVCR after a syscall we leave streaming mode and ZA is preserved. We don't need to take account of any streaming/non streaming SVE vector length changes in the assembler code since the store instructions will handle the vector length for us. We log if the system supports FA64 and only try to set FFR in streaming mode if it does.

maintainer
#134 lore raw
In reply to Mark Brown
Quoted 10 lines · Mark Brown

This series provides initial support for the ARMv9 Scalable Matrix Extension (SME). SME takes the approach used for vectors in SVE and extends this to provide architectural support for matrix operations. A more detailed overview can be found in [1].

For the kernel SME can be thought of as a series of features which are intended to be used together by applications but operate mostly orthogonally:

[...]

Applied patch 5 to arm64 (for-next/kselftest), thanks!

[05/40] kselftest/arm64: signal: Allow tests to be incompatible with features

        https://git.kernel.org/arm64/c/32de73e89099

Cheers,

Signature · 5 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
maintainer
#135 lore raw
Quoted 10 lines · Will Deacon
Quoted 9 lines · Mark Brown

This series provides initial support for the ARMv9 Scalable Matrix Extension (SME). SME takes the approach used for vectors in SVE and extends this to provide architectural support for matrix operations. A more detailed overview can be found in [1].

For the kernel SME can be thought of as a series of features which are intended to be used together by applications but operate mostly orthogonally:

Quoted 6 lines
Quoted 1 line

[...]

Applied patch 5 to arm64 (for-next/kselftest), thanks!

[05/40] kselftest/arm64: signal: Allow tests to be incompatible with features

        https://git.kernel.org/arm64/c/32de73e89099

I also applied 1-3 to for-next/fpsimd, but the 'thanks' file got overwritten before I sent it!

Will
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

#8 lore raw

Re: [PATCH v11 03/40] arm64: cpufeature: Always specify and use a field width for capabilities

In reply to Mark Brown
Quoted 9 lines · Mark Brown

Since all the fields in the main ID registers are 4 bits wide we have up until now not bothered specifying the width in the code. Since we now wish to use this mechanism to enumerate features from the floating point feature registers which do not follow this pattern add a width to the table. This means updating all the existing table entries but makes it less likely that we run into issues in future due to implicitly assuming a 4 bit width.

Do we leave this one alone on purpose?

.desc = "GIC system register CPU interface", .capability = ARM64_HAS_SYSREG_GIC_CPUIF, .type = ARM64_CPUCAP_STRICT_BOOT_CPU_FEATURE, .matches = has_useable_gicv3_cpuif, .sys_reg = SYS_ID_AA64PFR0_EL1, .field_pos = ID_AA64PFR0_GIC_SHIFT, .sign = FTR_UNSIGNED, .min_field_value = 1,

Since width == 0, it will generate an undefined behavior.

UBSAN: shift-out-of-bounds in ./arch/arm64/include/asm/cpufeature.h:535:49
 shift exponent 64 is too large for 64-bit type 'long long unsigned int'
 CPU: 0 PID: 0 Comm: swapper Not tainted 5.17.0-rc6-next-20220301 #1
 Call trace:
  dump_backtrace
  show_stack
  dump_stack_lvl
  dump_stack
  ubsan_epilogue
  __ubsan_handle_shift_out_of_bounds
  has_cpuid_feature
  cpuid_feature_extract_unsigned_field_width at arch/arm64/include/asm/cpufeature.h:535
  (inlined by) cpuid_feature_extract_field_width at arch/arm64/include/asm/cpufeature.h:582
  (inlined by) cpuid_feature_extract_field_width at arch/arm64/include/asm/cpufeature.h:578
  (inlined by) feature_matches at arch/arm64/kernel/cpufeature.c:1317
  (inlined by) has_cpuid_feature at arch/arm64/kernel/cpufeature.c:1335
  has_useable_gicv3_cpuif
  has_useable_gicv3_cpuif at arch/arm64/kernel/cpufeature.c:1389
  update_cpu_capabilities
  init_cpu_features
  cpuinfo_store_boot_cpu
  smp_prepare_boot_cpu
  start_kernel
  __primary_switched
maintainer
#9 lore raw

Re: [PATCH v11 03/40] arm64: cpufeature: Always specify and use a field width for capabilities

Quoted 23 lines · Qian Cai
Quoted 9 lines · Mark Brown

Since all the fields in the main ID registers are 4 bits wide we have up until now not bothered specifying the width in the code. Since we now wish to use this mechanism to enumerate features from the floating point feature registers which do not follow this pattern add a width to the table. This means updating all the existing table entries but makes it less likely that we run into issues in future due to implicitly assuming a 4 bit width.

Do we leave this one alone on purpose?

.desc = "GIC system register CPU interface", .capability = ARM64_HAS_SYSREG_GIC_CPUIF, .type = ARM64_CPUCAP_STRICT_BOOT_CPU_FEATURE, .matches = has_useable_gicv3_cpuif, .sys_reg = SYS_ID_AA64PFR0_EL1, .field_pos = ID_AA64PFR0_GIC_SHIFT, .sign = FTR_UNSIGNED, .min_field_value = 1,

Quoted 1 line

Since width == 0, it will generate an undefined behavior.

I don't think that's on purpose, and we should definitely address this. Maybe we should have a warning if we spot an occurrence of .width being 0.

Thanks,

	M.
Signature · 5 lines
Without deviation from the norm, progress is not possible.
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
maintainer
#10 lore raw

Re: [PATCH v11 03/40] arm64: cpufeature: Always specify and use a field width for capabilities

Quoted 25 lines · Marc Zyngier
Quoted 23 lines · Qian Cai
Quoted 9 lines · Mark Brown

Since all the fields in the main ID registers are 4 bits wide we have up until now not bothered specifying the width in the code. Since we now wish to use this mechanism to enumerate features from the floating point feature registers which do not follow this pattern add a width to the table. This means updating all the existing table entries but makes it less likely that we run into issues in future due to implicitly assuming a 4 bit width.

Do we leave this one alone on purpose?

.desc = "GIC system register CPU interface", .capability = ARM64_HAS_SYSREG_GIC_CPUIF, .type = ARM64_CPUCAP_STRICT_BOOT_CPU_FEATURE, .matches = has_useable_gicv3_cpuif, .sys_reg = SYS_ID_AA64PFR0_EL1, .field_pos = ID_AA64PFR0_GIC_SHIFT, .sign = FTR_UNSIGNED, .min_field_value = 1,

Quoted 5 lines
Quoted 1 line

Since width == 0, it will generate an undefined behavior.

I don't think that's on purpose, and we should definitely address this. Maybe we should have a warning if we spot an occurrence of .width being 0.

We should indeed have a check. Alternatively, assume the default to be 4 and convert all 0s to 4 during boot (less patch churn).

Signature · 1 line
Catalin
author
#12 lore raw

Re: [PATCH v11 03/40] arm64: cpufeature: Always specify and use a field width for capabilities

In reply to Qian Cai
Quoted 6 lines · Qian Cai
Quoted 2 lines · Mark Brown

Since all the fields in the main ID registers are 4 bits wide we have up until now not bothered specifying the width in the code. Since we now

Do we leave this one alone on purpose?

Quoted 8 lines

.desc = "GIC system register CPU interface", .capability = ARM64_HAS_SYSREG_GIC_CPUIF, .type = ARM64_CPUCAP_STRICT_BOOT_CPU_FEATURE, .matches = has_useable_gicv3_cpuif, .sys_reg = SYS_ID_AA64PFR0_EL1, .field_pos = ID_AA64PFR0_GIC_SHIFT, .sign = FTR_UNSIGNED, .min_field_value = 1,

No, that's just an oversight.

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

author
#11 lore raw

Re: [PATCH v11 03/40] arm64: cpufeature: Always specify and use a field width for capabilities

In reply to Catalin Marinas
Quoted 8 lines · Catalin Marinas
Quoted 3 lines · Marc Zyngier

I don't think that's on purpose, and we should definitely address this. Maybe we should have a warning if we spot an occurrence of .width being 0.

We should indeed have a check. Alternatively, assume the default to be 4 and convert all 0s to 4 during boot (less patch churn).

That's got the issue that it becomes very easy to end up defaulting to a width of 4 in the case where the field is narrower which isn't going to be easily visible in testing until it encounters a system where it misfires in a way that breaks things.