Add support for FEAT_{LS64, LS64_V} and related tests
Subsystems (4)
v2 cover Add support for FEAT_{LS64, LS64_V} and related tests
From: Yicong Yang <[email protected]>
Armv8.7 introduces single-copy atomic 64-byte loads and stores instructions and its variants named under FEAT_{LS64, LS64_V}. Add support for Armv8.7 FEAT_{LS64, LS64_V}:
- Add identifying and enabling in the cpufeature list
- Expose the support of these features to userspace through HWCAP3 and cpuinfo
- Add related hwcap test
- Handle the trap of unsupported memory (normal/uncacheable) access in a VM
A real scenario for this feature is that the userspace driver can make use of this to implement direct WQE (workqueue entry) - a mechanism to fill WQE directly into the hardware.
This patchset also complement with Marc's patchset v2[1] for handling LS64* trapped if not advertised for a VM.
[1] https://lore.kernel.org/linux-arm-kernel/[email protected]/
Tested with updated hwcap test:
On host:
root@localhost:/tmp# dmesg | grep "All CPU(s) started" [ 0.504846] CPU: All CPU(s) started at EL2 root@localhost:/tmp# ./hwcap [...] # LS64 present ok 217 cpuinfo_match_LS64 ok 218 sigill_LS64 ok 219 # SKIP sigbus_LS64 # LS64_V present ok 220 cpuinfo_match_LS64_V ok 221 sigill_LS64_V ok 222 # SKIP sigbus_LS64_V # 115 skipped test(s) detected. Consider enabling relevant config options to improve coverage. # Totals: pass:107 fail:0 xfail:0 xpass:0 skip:115 error:0
On guest:
root@localhost:/# dmesg | grep "All CPU(s) started" [ 0.205580] CPU: All CPU(s) started at EL1 root@localhost:/mnt# ./hwcap [...] # LS64 present ok 217 cpuinfo_match_LS64 ok 218 sigill_LS64 ok 219 # SKIP sigbus_LS64 # LS64_V present ok 220 cpuinfo_match_LS64_V ok 221 sigill_LS64_V ok 222 # SKIP sigbus_LS64_V # 115 skipped test(s) detected. Consider enabling relevant config options to improve coverage. # Totals: pass:107 fail:0 xfail:0 xpass:0 skip:115 error:0
Change since v1:
- Drop the suppport for LS64_ACCDATA
- handle the DABT of unsupported memory type after checking the memory attributes
Yicong Yang (6):
arm64: Provide basic EL2 setup for FEAT_{LS64, LS64_V} usage at EL0/1
arm64: Add support for FEAT_{LS64, LS64_V}
KVM: arm64: Enable FEAT_{LS64, LS64_V} in the supported guest kselftest/arm64: Add HWCAP test for FEAT_{LS64, LS64_V}
arm64: Add ESR.DFSC definition of unsupported exclusive or atomic
access
KVM: arm64: Handle DABT caused by LS64* instructions on unsupported
memory
Documentation/arch/arm64/booting.rst | 12 +++ Documentation/arch/arm64/elf_hwcaps.rst | 6 ++ arch/arm64/include/asm/el2_setup.h | 12 ++- arch/arm64/include/asm/esr.h | 8 ++ arch/arm64/include/asm/hwcap.h | 2 + arch/arm64/include/asm/kvm_emulate.h | 7 ++ arch/arm64/include/uapi/asm/hwcap.h | 2 + arch/arm64/kernel/cpufeature.c | 51 +++++++++++++ arch/arm64/kernel/cpuinfo.c | 2 + arch/arm64/kvm/inject_fault.c | 35 +++++++++ arch/arm64/kvm/mmu.c | 37 +++++++++- arch/arm64/tools/cpucaps | 2 + tools/testing/selftests/arm64/abi/hwcap.c | 90 +++++++++++++++++++++++ 13 files changed, 264 insertions(+), 2 deletions(-)
Signature · 1 line
2.24.0
PATCH v2 1/6 arm64: Provide basic EL2 setup for FEAT_{LS64, LS64_V} usage at EL0/1
From: Yicong Yang <[email protected]>
Instructions introduced by FEAT_{LS64, LS64_V} is controlled by HCRX_EL2.{EnALS, EnASR}. Configure all of these to allow usage at EL0/1.
This doesn't mean these instructions are always available in EL0/1 if provided. The hypervisor still have the control at runtime.
--- arch/arm64/include/asm/el2_setup.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
arch/arm64/include/asm/el2_setup.h +11 -1
@@ -57,9 +57,19 @@/* Enable GCS if supported */ mrs_s x1,SYS_ID_AA64PFR1_EL1 ubfx x1, x1, #ID_AA64PFR1_EL1_GCS_SHIFT, #4 - cbz x1, .Lset_hcrx_\@ + cbz x1, .Lskip_gcs_hcrx_\@ orr x0, x0, #HCRX_EL2_GCSEn +.Lskip_gcs_hcrx_\@: +/* Enable LS64, LS64_V if supported */ + mrs_s x1, SYS_ID_AA64ISAR1_EL1 + ubfx x1, x1, #ID_AA64ISAR1_EL1_LS64_SHIFT, #4 + cbz x1, .Lset_hcrx_\@ + orr x0, x0, #HCRX_EL2_EnALS + cmp x1, #ID_AA64ISAR1_EL1_LS64_LS64_V + b.lt .Lset_hcrx_\@ + orr x0, x0, #HCRX_EL2_EnASR + .Lset_hcrx_\@: msr_s SYS_HCRX_EL2, x0 .Lskip_hcrx_\@:
Signature · 1 line
2.24.0
Suzuki K Poulose
reviewerRe: [PATCH v2 1/6] arm64: Provide basic EL2 setup for FEAT_{LS64, LS64_V} usage at EL0/1
Quoted 20 lines · Yicong Yang
From: Yicong Yang <[email protected]>
Instructions introduced by FEAT_{LS64,
LS64_V} is controlled by HCRX_EL2.{EnALS, EnASR}. Configure all of these to allow usage at EL0/1.This doesn't mean these instructions are always available in EL0/1 if provided. The hypervisor still have the control at runtime.
Signed-off-by Yicong Yang <[email protected]>--- arch/arm64/include/asm/el2_setup.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)arch/arm64/include/asm/el2_setup.h +0
-0
arch/arm64/include/asm/el2_setup.h line 63
Quoted 8 lines
arch/arm64/include/asm/el2_setup.h +2
-1@@ -57,9 +57,19 @@/* Enable GCS if supported */ mrs_s x1,SYS_ID_AA64PFR1_EL1 ubfx x1, x1, #ID_AA64PFR1_EL1_GCS_SHIFT, #4 - cbz x1, .Lset_hcrx_\@ + cbz x1, .Lskip_gcs_hcrx_\@ orr x0, x0, #HCRX_EL2_GCSEn +.Lskip_gcs_hcrx_\@:
minor nit: For consistency, could we rename this "set_ls64", similar to "set_hcrx" ?
arch/arm64/include/asm/el2_setup.h line 75
Quoted 12 lines
arch/arm64/include/asm/el2_setup.h +9
-0+/* Enable LS64, LS64_V if supported */ +mrs_s x1,SYS_ID_AA64ISAR1_EL1 + ubfx x1, x1, #ID_AA64ISAR1_EL1_LS64_SHIFT, #4 + cbz x1, .Lset_hcrx_\@ + orr x0, x0, #HCRX_EL2_EnALS + cmp x1, #ID_AA64ISAR1_EL1_LS64_LS64_V + b.lt .Lset_hcrx_\@ + orr x0, x0, #HCRX_EL2_EnASR + .Lset_hcrx_\@: msr_s SYS_HCRX_EL2, x0 .Lskip_hcrx_\@:
Suzuki
Re: [PATCH v2 1/6] arm64: Provide basic EL2 setup for FEAT_{LS64, LS64_V} usage at EL0/1
Quoted 16 lines · Suzuki K Poulose
Quoted 15 lines · Yicong Yang
From: Yicong Yang <[email protected]>
Instructions introduced by FEAT_{LS64,
LS64_V} is controlled by HCRX_EL2.{EnALS, EnASR}. Configure all of these to allow usage at EL0/1.This doesn't mean these instructions are always available in EL0/1 if provided. The hypervisor still have the control at runtime.
Signed-off-by Yicong Yang <[email protected]>---
arch/arm64/include/asm/el2_setup.h| 12 +++++++++++-1 file changed, 11 insertions(+), 1 deletion(-)
Quoted 15 lines
Quoted 6 lines
arch/arm64/include/asm/el2_setup.h +0
-0@@ -57,9 +57,19 @@ /* Enable GCS if supported */Quoted 6 lines
mrs_s x1,
SYS_ID_AA64PFR1_EL1
ubfx x1, x1, #ID_AA64PFR1_EL1_GCS_SHIFT, #4 - cbz x1, .Lset_hcrx_\@
+ cbz x1, .Lskip_gcs_hcrx_\@
orr x0, x0, #HCRX_EL2_GCSEn +.Lskip_gcs_hcrx_\@:minor nit: For consistency, could we rename this "
set_ls64", similar to "set_hcrx" ?
IIUC, set_xxx really touches the registers and skip_xxx should just check and prepare the feature bits. so here using .Lskip_gcs_hrcx_\@ should be more proper and consistent with other places in el2_setup.h, like __init_el2_debug/__init_el2_fgt which also use .Lskip_xxx for skipping an unsupported feature?
Thanks.
Quoted 16 lines
Quoted 4 lines
+ /* Enable LS64,
LS64_Vif supported */
+ mrs_s x1,SYS_ID_AA64ISAR1_EL1
+ ubfx x1, x1, #ID_AA64ISAR1_EL1_LS64_SHIFT, #4 + cbz x1, .Lset_hcrx_\@Quoted 8 lines
+ orr x0, x0, #HCRX_EL2_EnALS
+ cmp x1, #ID_AA64ISAR1_EL1_LS64_LS64_V
+ b.lt .Lset_hcrx_\@
+ orr x0, x0, #HCRX_EL2_EnASR
+
.Lset_hcrx_\@:
msr_sSYS_HCRX_EL2, x0
.Lskip_hcrx_\@:Suzuki
.
Will Deacon
maintainerRe: [PATCH v2 1/6] arm64: Provide basic EL2 setup for FEAT_{LS64, LS64_V} usage at EL0/1
Quoted 33 lines · Yicong Yang
Quoted 16 lines · Suzuki K Poulose
Quoted 15 lines · Yicong Yang
From: Yicong Yang <[email protected]>
Instructions introduced by FEAT_{LS64,
LS64_V} is controlled by HCRX_EL2.{EnALS, EnASR}. Configure all of these to allow usage at EL0/1.This doesn't mean these instructions are always available in EL0/1 if provided. The hypervisor still have the control at runtime.
Signed-off-by Yicong Yang <[email protected]>---
arch/arm64/include/asm/el2_setup.h| 12 +++++++++++-1 file changed, 11 insertions(+), 1 deletion(-)Quoted 15 lines
Quoted 6 lines
arch/arm64/include/asm/el2_setup.h +0
-0@@ -57,9 +57,19 @@ /* Enable GCS if supported */Quoted 6 lines
mrs_s x1,
SYS_ID_AA64PFR1_EL1
ubfx x1, x1, #ID_AA64PFR1_EL1_GCS_SHIFT, #4 - cbz x1, .Lset_hcrx_\@
+ cbz x1, .Lskip_gcs_hcrx_\@
orr x0, x0, #HCRX_EL2_GCSEn +.Lskip_gcs_hcrx_\@:minor nit: For consistency, could we rename this "
set_ls64", similar to "set_hcrx" ?
Quoted 4 lines
IIUC,
set_xxxreally touches the registers andskip_xxxshould just check and prepare the feature bits. so here using .Lskip_gcs_hrcx_\@ should be more proper and consistent with other places inel2_setup.h, like __init_el2_debug/__init_el2_fgt which also use .Lskip_xxx for skipping an unsupported feature?
fwiw, I think the label names are fine as you have them.
Will
Will Deacon
maintainerRe: [PATCH v2 1/6] arm64: Provide basic EL2 setup for FEAT_{LS64, LS64_V} usage at EL0/1
In reply to Yicong YangQuoted 26 lines · Yicong Yang
From: Yicong Yang <[email protected]>
Instructions introduced by FEAT_{LS64,
LS64_V} is controlled by HCRX_EL2.{EnALS, EnASR}. Configure all of these to allow usage at EL0/1.This doesn't mean these instructions are always available in EL0/1 if provided. The hypervisor still have the control at runtime.
Signed-off-by Yicong Yang <[email protected]>--- arch/arm64/include/asm/el2_setup.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)arch/arm64/include/asm/el2_setup.h +1
-1@@ -57,9 +57,19 @@/* Enable GCS if supported */ mrs_s x1,SYS_ID_AA64PFR1_EL1 ubfx x1, x1, #ID_AA64PFR1_EL1_GCS_SHIFT, #4 - cbz x1, .Lset_hcrx_\@ + cbz x1, .Lskip_gcs_hcrx_\@ orr x0, x0, #HCRX_EL2_GCSEn
arch/arm64/include/asm/el2_setup.h line 71
Quoted 10 lines
arch/arm64/include/asm/el2_setup.h +9
-0+.Lskip_gcs_hcrx_\@: +/* Enable LS64, LS64_V if supported */ +mrs_s x1,SYS_ID_AA64ISAR1_EL1 + ubfx x1, x1, #ID_AA64ISAR1_EL1_LS64_SHIFT, #4 + cbz x1, .Lset_hcrx_\@ + orr x0, x0, #HCRX_EL2_EnALS + cmp x1, #ID_AA64ISAR1_EL1_LS64_LS64_V + b.lt .Lset_hcrx_\@ + orr x0, x0, #HCRX_EL2_EnASR
How do these HCRX settings survive a world-switch to and from a KVM guest? AFAICT, the trap deactivation path there restores HCRX_HOST_FLAGS when returning to the host. That would mean that the GCS code is broken too, unless I'm missing something :/
Will
PATCH v2 2/6 arm64: Add support for FEAT_{LS64, LS64_V}
In reply to Yicong YangFrom: Yicong Yang <[email protected]>
Armv8.7 introduces single-copy atomic 64-byte loads and stores instructions and its variants named under FEAT_{LS64, LS64_V}. These features are identified by ID_AA64ISAR1_EL1.LS64 and the use of such instructions in userspace (EL0) can be trapped. In order to support the use of corresponding instructions in userspace:
- Make ID_AA64ISAR1_EL1.LS64 visbile to userspace
- Add identifying and enabling in the cpufeature list
- Expose these support of these features to userspace through HWCAP3 and cpuinfo
--- Documentation/arch/arm64/booting.rst | 12 ++++++ Documentation/arch/arm64/elf_hwcaps.rst | 6 +++ arch/arm64/include/asm/hwcap.h | 2 + arch/arm64/include/uapi/asm/hwcap.h | 2 + arch/arm64/kernel/cpufeature.c | 51 +++++++++++++++++++++++++ arch/arm64/kernel/cpuinfo.c | 2 + arch/arm64/tools/cpucaps | 2 + 7 files changed, 77 insertions(+)
Documentation/arch/arm64/booting.rst +12 -0
@@ -483,6 +483,18 @@ Before jumping into the kernel, the following conditions must be met: - MDCR_EL3.TPM (bit 6) must be initialized to 0b0 + For CPUs support for 64-byte loads and stores without status (FEAT_LS64): + + - If the kernel is entered at EL1 and EL2 is present: + + - HCRX_EL2.EnALS (bit 1) must be initialised to 0b1. + + For CPUs support for 64-byte loads and stores with status (FEAT_LS64_V): + + - If the kernel is entered at EL1 and EL2 is present: + + - HCRX_EL2.EnASR (bit 2) must be initialised to 0b1. + The requirements described above for CPU mode, caches, MMUs, architected timers, coherency and system registers apply to all CPUs. All CPUs must enter the kernel in the same exception level. Where the values documented
Documentation/arch/arm64/elf_hwcaps.rst +6 -0
@@ -435,6 +435,12 @@ HWCAP2_SME_SF8DP4 HWCAP2_POE Functionality implied by ID_AA64MMFR3_EL1.S1POE == 0b0001. +HWCAP3_LS64 + Functionality implied by ID_AA64ISAR1_EL1.LS64 == 0b0001. + +HWCAP3_LS64_V + Functionality implied by ID_AA64ISAR1_EL1.LS64 == 0b0010. + 4. Unused AT_HWCAP bits -----------------------
arch/arm64/include/asm/hwcap.h +2 -0
@@ -176,6 +176,8 @@#define KERNEL_HWCAP_POE __khwcap2_feature(POE)#define __khwcap3_feature (x) (const_ilog2(HWCAP3_ ## x) + 128) +#define KERNEL_HWCAP_LS64 __khwcap3_feature(LS64) +#define KERNEL_HWCAP_LS64_V __khwcap3_feature(LS64_V)/* * This yields a mask that user programs can use to figure out what
arch/arm64/include/uapi/asm/hwcap.h +2 -0
@@ -143,5 +143,7 @@/* * HWCAP3 flags - for AT_HWCAP3 */ +#define HWCAP3_LS64 (1UL << 0) +#define HWCAP3_LS64_V (1UL << 1)#endif /* _UAPI__ASM_HWCAP_H */
arch/arm64/kernel/cpufeature.c +51 -0
75 lines not on this page · raw message
arch/arm64/kernel/cpuinfo.c +2 -0
@@ -81,6 +81,8 @@ static const char *const hwcap_str[] = { [KERNEL_HWCAP_PACA] = "paca", [KERNEL_HWCAP_PACG] = "pacg", [KERNEL_HWCAP_GCS] = "gcs", + [KERNEL_HWCAP_LS64] = "ls64", + [KERNEL_HWCAP_LS64_V] = "ls64_v", [KERNEL_HWCAP_DCPODP] = "dcpodp", [KERNEL_HWCAP_SVE2] = "sve2", [KERNEL_HWCAP_SVEAES] = "sveaes",
arch/arm64/tools/cpucaps +2 -0
@@ -42,6 +42,8 @@ HAS_HCX HAS_LDAPR HAS_LPA2 HAS_LSE_ATOMICS +HAS_LS64 +HAS_LS64_V HAS_MOPS HAS_NESTED_VIRT HAS_PAN
Signature · 1 line
2.24.0
PATCH v2 3/6 KVM: arm64: Enable FEAT_{LS64, LS64_V} in the supported guest
In reply to Yicong YangFrom: Yicong Yang <[email protected]>
Using FEAT_{LS64, LS64_V} instructions in a guest is also controlled by HCRX_EL2.{EnALS, EnASR}. Enable it if guest has related feature.
--- arch/arm64/include/asm/kvm_emulate.h | 6 ++++++ 1 file changed, 6 insertions(+)
arch/arm64/include/asm/kvm_emulate.h +6 -0
@@ -684,6 +684,12 @@ static inline void vcpu_set_hcrx(struct kvm_vcpu *vcpu)if (kvm_has_fpmr (kvm)) vcpu->arch.hcrx_el2 |= HCRX_EL2_EnFPM; + +if (kvm_has_feat (kvm,ID_AA64ISAR1_EL1 ,LS64 ,LS64 )) + vcpu->arch.hcrx_el2 |= HCRX_EL2_EnALS; + +if (kvm_has_feat (kvm,ID_AA64ISAR1_EL1 ,LS64 ,LS64_V )) + vcpu->arch.hcrx_el2 |= HCRX_EL2_EnASR; } }#endif /* __ARM64_KVM_EMULATE_H__ */
Signature · 1 line
2.24.0
PATCH v2 4/6 kselftest/arm64: Add HWCAP test for FEAT_{LS64, LS64_V}
In reply to Yicong YangFrom: Yicong Yang <[email protected]>
Add tests for FEAT_{LS64, LS64_V}. Issue related instructions if feature presents, no SIGILL should be received. When such instructions operate on Device memory or non-cacheable memory, we may received a SIGBUS during the test (w/o FEAT_LS64WB). Just ignore it since we only tested whether the instruction itself can be issued as expected on platforms declaring the support of such features.
--- tools/testing/selftests/arm64/abi/hwcap.c | 90 +++++++++++++++++++++++ 1 file changed, 90 insertions(+)
tools/testing/selftests/arm64/abi/hwcap.c +90 -0
@@ -11,6 +11,8 @@#include <stdlib.h> #include <string.h> #include <unistd.h> +#include <linux/auxvec.h> +#include <linux/compiler.h> #include <sys/auxv.h> #include <sys/prctl.h> #include <asm/hwcap.h>
@@ -578,6 +580,78 @@ static void lrcpc3_sigill(void) : "=r" (data0), "=r" (data1) : "r" (src) :); } +static void ignore_signal (int sig,siginfo_t *info,void *context) +{ +ucontext_t *uc = context; + + uc->uc_mcontext.pc +=4 ; +} + +static void ls64_sigill (void ) +{ +struct sigaction ign, old; +char src[64 ]__aligned(64) = {1 }; + +/* +* LS64, LS64_V require target memory to be Device/Non-cacheable (if +* FEAT_LS64WB not supported) and the completer supports these +* instructions, otherwise we'll receive a SIGBUS. Since we are only +* testing the ABI here, so just ignore the SIGBUS and see if we can +* execute the instructions without receiving a SIGILL. Restore the +* handler of SIGBUS after this test. +*/ + ign.sa_sigaction = ignore_signal; + ign.sa_flags =SA_SIGINFO |SA_RESTART ; +sigemptyset (&ign.sa_mask); +sigaction (SIGBUS , &ign, &old); + + register void *xn asm ("x8") = src; + registeru64 xt_1 asm ("x0" ); + registeru64 __maybe_unused xt_2 asm ("x1" ); + registeru64 __maybe_unused xt_3 asm ("x2" ); + registeru64 __maybe_unused xt_4 asm ("x3" ); + registeru64 __maybe_unused xt_5 asm ("x4" ); + registeru64 __maybe_unused xt_6 asm ("x5" ); + registeru64 __maybe_unused xt_7 asm ("x6" ); + registeru64 __maybe_unused xt_8 asm ("x7" ); + +/* LD64B x0, [x8] */ + asmvolatile (".inst 0xf83fd100" :"=r" (xt_1) :"r" (xn)); + +/* ST64B x0, [x8] */ + asmvolatile (".inst 0xf83f9100" : :"r" (xt_1),"r" (xn)); + +sigaction (SIGBUS , &old,NULL ); +} + +static void ls64_v_sigill (void ) +{ +struct sigaction ign, old; +char dst[64 ]__aligned(64) ; + +/* See comment in ls64_sigill() */ + ign.sa_sigaction = ignore_signal; + ign.sa_flags =SA_SIGINFO |SA_RESTART ; +sigemptyset (&ign.sa_mask); +sigaction (SIGBUS , &ign, &old); + + register void *xn asm ("x8") = dst; + register u64 xt_1 asm ("x0") = 1; + register u64 __maybe_unused xt_2 asm ("x1") = 2; + register u64 __maybe_unused xt_3 asm ("x2") = 3; + register u64 __maybe_unused xt_4 asm ("x3") = 4; + register u64 __maybe_unused xt_5 asm ("x4") = 5; + register u64 __maybe_unused xt_6 asm ("x5") = 6; + register u64 __maybe_unused xt_7 asm ("x6") = 7; + register u64 __maybe_unused xt_8 asm ("x7") = 8; + registeru64 st asm ("x9" ); + +/* ST64BV x9, x0, [x8] */ + asmvolatile (".inst 0xf829b100" :"=r" (st) :"r" (xt_1),"r" (xn)); + +sigaction (SIGBUS , &old,NULL ); +} + static const struct hwcap_data { const char *name; unsigned long at_hwcap;
@@ -1098,6 +1172,22 @@ static const struct hwcap_data { .sigill_fn = hbc_sigill, .sigill_reliable = true, }, + { + .name = "LS64", + .at_hwcap = AT_HWCAP3, + .hwcap_bit = HWCAP3_LS64, + .cpuinfo = "ls64", + .sigill_fn = ls64_sigill, + .sigill_reliable = true, + }, + { + .name = "LS64_V", + .at_hwcap = AT_HWCAP3, + .hwcap_bit = HWCAP3_LS64_V, + .cpuinfo = "ls64_v", + .sigill_fn = ls64_v_sigill, + .sigill_reliable = true, + }, };typedef void (*sighandler_fn )(int ,siginfo_t *,void *);
Signature · 1 line
2.24.0
PATCH v2 5/6 arm64: Add ESR.DFSC definition of unsupported exclusive or atomic access
In reply to Yicong YangFrom: Yicong Yang <[email protected]>
0x35 indicates IMPLEMENTATION DEFINED fault for Unsupported Exclusive or Atomic access. Add ESR_ELx_FSC definition and corresponding wrapper.
--- arch/arm64/include/asm/esr.h | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/arm64/include/asm/esr.h +8 -0
@@ -121,6 +121,7 @@#define ESR_ELx_FSC_SEA_TTW (n) (0x14 + (n))#define ESR_ELx_FSC_SECC (0x18)#define ESR_ELx_FSC_SECC_TTW (n) (0x1c + (n)) +#define ESR_ELx_FSC_EXCL_ATOMIC (0x35)/* Status codes for individual page table levels */ #define ESR_ELx_FSC_ACCESS_L (n) (ESR_ELx_FSC_ACCESS + (n))
@@ -464,6 +465,13 @@ static inline bool esr_fsc_is_access_flag_fault(unsigned long esr) (esr ==ESR_ELx_FSC_ACCESS_L (0 )); } +static inline bool esr_fsc_is_excl_atomic_fault (unsigned long esr) +{ + esr = esr & ESR_ELx_FSC; + +return esr == ESR_ELx_FSC_EXCL_ATOMIC; +} +/* Indicate whether ESR.EC==0x1A is for an ERETAx instruction */ static inline bool esr_iss_is_eretax (unsigned long esr) {
Signature · 1 line
2.24.0
Re: [PATCH v2 5/6] arm64: Add ESR.DFSC definition of unsupported exclusive or atomic access
Quoted 6 lines · Yicong Yang
From: Yicong Yang <[email protected]>
0x35indicates IMPLEMENTATION DEFINED fault for Unsupported Exclusive or Atomic access. AddESR_ELx_FSCdefinition and corresponding wrapper.Signed-off-by Yicong Yang <[email protected]>
Just squash this into the next patch. Adding a helper w/o any user usually isn't a good idea.
Thanks,
Oliver
Re: [PATCH v2 5/6] arm64: Add ESR.DFSC definition of unsupported exclusive or atomic access
Quoted 11 lines · Oliver Upton
Quoted 6 lines · Yicong Yang
From: Yicong Yang <[email protected]>
0x35indicates IMPLEMENTATION DEFINED fault for Unsupported Exclusive or Atomic access. AddESR_ELx_FSCdefinition and corresponding wrapper.Signed-off-by Yicong Yang <[email protected]>Just squash this into the next patch. Adding a helper w/o any user usually isn't a good idea.
sure, will squash this into the next patch.
Thanks.
PATCH v2 6/6 KVM: arm64: Handle DABT caused by LS64* instructions on unsupported memory
In reply to Yicong YangFrom: Yicong Yang <[email protected]>
If FEAT_LS64WB not supported, FEAT_LS64* instructions only support to access Device/Uncacheable memory, otherwise a data abort for unsupported Exclusive or atomic access (0x35) is generated per spec. It's implementation defined whether the target exception level is routed and is possible to implemented as route to EL2 on a VHE VM. Per DDI0487K.a Section C3.2.12.2 Single-copy atomic 64-byte load/store:
The check is performed against the resulting memory type after all enabled stages of translation. In this case the fault is reported at the final enabled stage of translation.
If it's implemented as generate the DABT to the final enabled stage (stage-2), inject a DABT to the guest to handle it.
--- arch/arm64/include/asm/kvm_emulate.h | 1 + arch/arm64/kvm/inject_fault.c | 35 ++++++++++++++++++++++++++ arch/arm64/kvm/mmu.c | 37 +++++++++++++++++++++++++++- 3 files changed, 72 insertions(+), 1 deletion(-)
arch/arm64/include/asm/kvm_emulate.h +1 -0
@@ -47,6 +47,7 @@ void kvm_skip_instr32(struct kvm_vcpu *vcpu);void kvm_inject_undefined (struct kvm_vcpu *vcpu);void kvm_inject_vabt (struct kvm_vcpu *vcpu);void kvm_inject_dabt (struct kvm_vcpu *vcpu,unsigned long addr); +void kvm_inject_dabt_excl_atomic (struct kvm_vcpu *vcpu,unsigned long addr);void kvm_inject_pabt (struct kvm_vcpu *vcpu,unsigned long addr);void kvm_inject_size_fault (struct kvm_vcpu *vcpu);
arch/arm64/kvm/inject_fault.c +35 -0
@@ -171,6 +171,41 @@ void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr)inject_abt64 (vcpu, false, addr); } +/** +* kvm_inject_dabt_excl_atomic - inject a data abort for unsupported exclusive +* or atomic access +* @vcpu: The VCPU to receive the data abort +* @addr: The address to report in the DFAR +* +* It is assumed that this code is called from the VCPU thread and that the +* VCPU therefore is not currently executing guest code. +*/ +void kvm_inject_dabt_excl_atomic (struct kvm_vcpu *vcpu,unsigned long addr) +{ +unsigned long cpsr = *vcpu_cpsr (vcpu); +u64 esr =0 ; + +pend_sync_exception (vcpu); + +if (kvm_vcpu_trap_il_is32bit (vcpu)) + esr |= ESR_ELx_IL; + +if ((cpsr &PSR_MODE_MASK ) == PSR_MODE_EL0t) + esr |= ESR_ELx_EC_DABT_LOW << ESR_ELx_EC_SHIFT; +else + esr |= ESR_ELx_EC_DABT_CUR << ESR_ELx_EC_SHIFT; + + esr |= ESR_ELx_FSC_EXCL_ATOMIC; + +if (match_target_el (vcpu,unpack_vcpu_flag (EXCEPT_AA64_EL1_SYNC ))) { +vcpu_write_sys_reg (vcpu, addr,FAR_EL1 ); +vcpu_write_sys_reg (vcpu, esr,ESR_EL1 ); + }else { +vcpu_write_sys_reg (vcpu, addr,FAR_EL2 ); +vcpu_write_sys_reg (vcpu, esr,ESR_EL2 ); + } +} +/** * kvm_inject_pabt - inject a prefetch abort into the guest * @vcpu: The VCPU to receive the prefetch abort
arch/arm64/kvm/mmu.c +36 -1
@@ -1658,6 +1658,25 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,if (exec_fault && device)return -ENOEXEC ; +if (esr_fsc_is_excl_atomic_fault (kvm_vcpu_get_esr (vcpu))) { +/* +* Target address is normal memory on the Host. We come here +* because: +* 1) Guest map it as device memory and perform LS64 operations +* 2) VMM report it as device memory mistakenly +* Warn the VMM and inject the DABT back to the guest. +*/ +if (!device) +kvm_err ("memory attributes maybe incorrect for hva 0x%lx\n" , hva); + +/* +* Otherwise it's a piece of device memory on the Host. +* Inject the DABT back to the guest since the mapping +* is wrong. +*/ +kvm_inject_dabt_excl_atomic (vcpu,kvm_vcpu_get_hfar (vcpu)); + } +/* * Potentially reduce shadow S2 permissions to match the guest's own * S2. For exec faults, we'd only reach this point if the guest
@@ -1836,7 +1855,8 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)/* Check the stage-2 fault is trans. fault or write fault */ if (!esr_fsc_is_translation_fault (esr) && !esr_fsc_is_permission_fault (esr) && - !esr_fsc_is_access_flag_fault (esr)) { + !esr_fsc_is_access_flag_fault (esr) && + !esr_fsc_is_excl_atomic_fault (esr)) { kvm_err("Unsupported FSC: EC=%#x xFSC=%#lx ESR_EL2=%#lx\n", kvm_vcpu_trap_get_class(vcpu), (unsigned long)kvm_vcpu_trap_get_fault(vcpu),
@@ -1919,6 +1939,21 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) goto out_unlock; } +/* +* If instructions of FEAT_{LS64, LS64_V} operated on +* unsupported memory regions, a DABT for unsupported +* Exclusive or atomic access is generated. It's +* implementation defined whether the exception will +* be taken to, a stage-1 DABT or the final enabled +* stage of translation (stage-2 in this case as we +* hit here). Inject a DABT to the guest to handle it +* if it's implemented as a stage-2 DABT. +*/ +if (esr_fsc_is_excl_atomic_fault (esr)) { +kvm_inject_dabt_excl_atomic (vcpu,kvm_vcpu_get_hfar (vcpu)); +return 1 ; + } +/* * The IPA is reported as [MAX:12], so we need to * complement it with the bottom 12 bits from the
Signature · 1 line
2.24.0
Re: [PATCH v2 6/6] KVM: arm64: Handle DABT caused by LS64* instructions on unsupported memory
Hi Yicong,
Quoted 9 lines · Yicong Yang
From: Yicong Yang <[email protected]>
If
FEAT_LS64WBnot supported, FEAT_LS64* instructions only support to access Device/Uncacheable memory, otherwise a data abort for unsupported Exclusive or atomic access (0x35) is generated per spec. It's implementation defined whether the target exception level is routed and is possible to implemented as route to EL2 on a VHE VM. Per DDI0487K.a Section C3.2.12.2 Single-copy atomic 64-byte load/store:
Quoted 3 lines
The check is performed against the resulting memory type after all enabled stages of translation. In this case the fault is reported at the final enabled stage of translation.
Just use section citations, this quote isn't very useful since it doesn't adequately describe the different IMPLEMENTATION DEFINED behavior.
Quoted 2 lines
If it's implemented as generate the DABT to the final enabled stage (stage-2), inject a DABT to the guest to handle it.
This should be ordered _before_ the patch that exposes FEAT_LS64* to the VM.
Quoted 4 lines
arch/arm64/kvm/mmu.c +0
-0@@ -1658,6 +1658,25 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,if (exec_fault && device)return -ENOEXEC ;
arch/arm64/kvm/mmu.c static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, · line 1670
Quoted 10 lines
arch/arm64/kvm/mmu.c +10
-0+if (esr_fsc_is_excl_atomic_fault (kvm_vcpu_get_esr (vcpu))) { +/* +* Target address is normal memory on the Host. We come here +* because: +* 1) Guest map it as device memory and perform LS64 operations +* 2) VMM report it as device memory mistakenly +* Warn the VMM and inject the DABT back to the guest. +*/ +if (!device) +kvm_err ("memory attributes maybe incorrect for hva 0x%lx\n" , hva);
No, kvm_err() doesn't warn the VMM at all. KVM should never log anything for a situation that can be caused by the guest, e.g. option #1 in your comment.
Keep in mind that data aborts with DFSC == 0x35 can happen for a lot more than LS64 instructions, e.g. an atomic on a Device-* mapping.
Quoted 9 lines
arch/arm64/kvm/mmu.c +5
-0@@ -1919,6 +1939,21 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) goto out_unlock; } +/* +* If instructions of FEAT_{LS64, LS64_V} operated on +* unsupported memory regions, a DABT for unsupported +* Exclusive or atomic access is generated. It's +* implementation defined whether the exception will
arch/arm64/kvm/mmu.c int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) · line 1956
Quoted 10 lines
arch/arm64/kvm/mmu.c +10
-0+* be taken to, a stage-1 DABT or the final enabled +* stage of translation (stage-2 in this case as we +* hit here). Inject a DABT to the guest to handle it +* if it's implemented as a stage-2 DABT. +*/ +if (esr_fsc_is_excl_atomic_fault (esr)) { +kvm_inject_dabt_excl_atomic (vcpu,kvm_vcpu_get_hfar (vcpu)); +return 1 ; + } +
A precondition of taking such a data abort is having a valid mapping at stage-2. If KVM can't resolve the HVA of the fault then there couldn't have been a stage-2 mapping.
Thanks,
Oliver
Re: [PATCH v2 6/6] KVM: arm64: Handle DABT caused by LS64* instructions on unsupported memory
Quoted 12 lines · Oliver Upton
Hi Yicong,
Quoted 9 lines · Yicong Yang
From: Yicong Yang <[email protected]>
If
FEAT_LS64WBnot supported, FEAT_LS64* instructions only support to access Device/Uncacheable memory, otherwise a data abort for unsupported Exclusive or atomic access (0x35) is generated per spec. It's implementation defined whether the target exception level is routed and is possible to implemented as route to EL2 on a VHE VM. Per DDI0487K.a Section C3.2.12.2 Single-copy atomic 64-byte load/store:
Quoted 8 lines
Quoted 3 lines
The check is performed against the resulting memory type after all enabled stages of translation. In this case the fault is reported at the final enabled stage of translation.
Just use section citations, this quote isn't very useful since it doesn't adequately describe the different IMPLEMENTATION DEFINED behavior.
will drop the quote here.
Quoted 5 lines
Quoted 2 lines
If it's implemented as generate the DABT to the final enabled stage (stage-2), inject a DABT to the guest to handle it.
This should be ordered _before_ the patch that exposes FEAT_LS64* to the VM.
will make this patch ahead.
Quoted 5 lines
Quoted 5 lines
arch/arm64/kvm/mmu.c +0
-0@@ -1658,6 +1658,25 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,if (exec_fault && device)return -ENOEXEC ;
Quoted 15 lines
arch/arm64/kvm/mmu.c static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, · line 1670
Quoted 10 lines
arch/arm64/kvm/mmu.c +10
-0+if (esr_fsc_is_excl_atomic_fault (kvm_vcpu_get_esr (vcpu))) { +/* +* Target address is normal memory on the Host. We come here +* because: +* 1) Guest map it as device memory and perform LS64 operations +* 2) VMM report it as device memory mistakenly +* Warn the VMM and inject the DABT back to the guest. +*/ +if (!device) +kvm_err ("memory attributes maybe incorrect for hva 0x%lx\n" , hva);No,
kvm_err()doesn't warn the VMM at all. KVM should never log anything for a situation that can be caused by the guest, e.g. option #1 in your comment.
ok will drop the log here and only inject a DABT back.
Quoted 3 lines
Keep in mind that data aborts with DFSC ==
0x35can happen for a lot more than LS64 instructions, e.g. an atomic on a Device-* mapping.
got it. 0x35 should be caused by LS64* or IMPLEMENTATION DEFINED fault, but no further hint to distinguish between these two faults. hope it's also the right behaviour to inject a DABT back for the latter case.
Quoted 15 lines
Quoted 15 lines
arch/arm64/kvm/mmu.c +11
-0@@ -1919,6 +1939,21 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) goto out_unlock; } +/* +* If instructions of FEAT_{LS64, LS64_V} operated on +* unsupported memory regions, a DABT for unsupported +* Exclusive or atomic access is generated. It's +* implementation defined whether the exception will +* be taken to, a stage-1 DABT or the final enabled +* stage of translation (stage-2 in this case as we +* hit here). Inject a DABT to the guest to handle it +* if it's implemented as a stage-2 DABT. +*/ +if (esr_fsc_is_excl_atomic_fault (esr)) {
Quoted 9 lines
arch/arm64/kvm/mmu.c int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) · line 1956
Quoted 4 lines
arch/arm64/kvm/mmu.c +4
-0+kvm_inject_dabt_excl_atomic (vcpu,kvm_vcpu_get_hfar (vcpu)); +return 1 ; + } +A precondition of taking such a data abort is having a valid mapping at stage-2. If KVM can't resolve the HVA of the fault then there couldn't have been a stage-2 mapping.
Here's handling the case for emulated mmio, I thought there's no valid stage-2 mapping for the emulated MMIO? so this check is put just before entering io_mem_abort(). should it be put into io_mem_abort() or we just don't handle the emulated case?
For the case where's a valid stage-2 mapping, the LS64 DABT is handled in user_mem_abort().
Thanks.
Re: [PATCH v2 6/6] KVM: arm64: Handle DABT caused by LS64* instructions on unsupported memory
Quoted 10 lines · Yicong Yang
Quoted 5 lines · Oliver Upton
Review static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
Quoted 1 line · Yicong Yang
(quoted diff) +0
-0@@ -1658,6 +1658,25 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,Keep in mind that data aborts with DFSC ==
0x35can happen for a lot more than LS64 instructions, e.g. an atomic on a Device-* mapping.got it.
0x35should be caused by LS64* or IMPLEMENTATION DEFINED fault, but no further hint to distinguish between these two faults. hope it's also the right behaviour to inject a DABT back for the latter case.
There isn't exactly a 'right' behavior here. The abort could either be due to a bug in the guest (doing an access on something knows it can't) or the VMM creating / describing the IPA memory map incorrectly.
Since KVM can't really work out who's to blame in this situation we should probably exit to userspace + provide a way to reinject the abort.
Quoted 25 lines
Quoted 15 lines
Quoted 15 lines
arch/arm64/kvm/mmu.c +11
-0@@ -1919,6 +1939,21 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) goto out_unlock; } +/* +* If instructions of FEAT_{LS64, LS64_V} operated on +* unsupported memory regions, a DABT for unsupported +* Exclusive or atomic access is generated. It's +* implementation defined whether the exception will +* be taken to, a stage-1 DABT or the final enabled +* stage of translation (stage-2 in this case as we +* hit here). Inject a DABT to the guest to handle it +* if it's implemented as a stage-2 DABT. +*/ +if (esr_fsc_is_excl_atomic_fault (esr)) {Quoted 9 lines
arch/arm64/kvm/mmu.c int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) · line 1956
Quoted 4 lines
arch/arm64/kvm/mmu.c +4
-0+kvm_inject_dabt_excl_atomic (vcpu,kvm_vcpu_get_hfar (vcpu)); +return 1 ; + } +A precondition of taking such a data abort is having a valid mapping at stage-2. If KVM can't resolve the HVA of the fault then there couldn't have been a stage-2 mapping.
Quoted 3 lines
Here's handling the case for emulated mmio, I thought there's no valid stage-2 mapping for the emulated MMIO? so this check is put just before entering
io_mem_abort(). should it be put intoio_mem_abort()or we just don't handle the emulated case?
Right -- there's no valid stage-2 translation for _most_ MMIO. If KVM cannot find an HVA for the fault (look at the condition that gets us here) then we know there isn't a stage-2 mapping. How would we know what to map?
In that case I would expect to take a Translation fault with instruction syndrome that can can be used to construct an exit to the VMM. Marc had some patches on list to do exactly that [*].
However, after reading this again there's a rather ugly catch. The KVM ABI has it that writes to a RO memlot generate an MMIO exit, so it *is* possible to get here w/ a stage-2 mapping. Unfortunately there's no instruction syndrome with DFSC = 0x35 so no way to decode the access.
This is starting to sound similar an nISV MMIO abort...
[*]: https://lore.kernel.org/kvmarm/[email protected]/
Thanks,
Oliver
Re: [PATCH v2 6/6] KVM: arm64: Handle DABT caused by LS64* instructions on unsupported memory
Quoted 12 lines · Oliver Upton
Quoted 10 lines · Yicong Yang
Quoted 5 lines · Oliver Upton
Review static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
Quoted 1 line · Yicong Yang
(quoted diff) +0
-0@@ -1658,6 +1658,25 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,Keep in mind that data aborts with DFSC ==
0x35can happen for a lot more than LS64 instructions, e.g. an atomic on a Device-* mapping.got it.
0x35should be caused by LS64* or IMPLEMENTATION DEFINED fault, but no further hint to distinguish between these two faults. hope it's also the right behaviour to inject a DABT back for the latter case.
Quoted 7 lines
There isn't exactly a 'right' behavior here. The abort could either be due to a bug in the guest (doing an access on something knows it can't) or the VMM creating / describing the IPA memory map incorrectly.
Since KVM can't really work out who's to blame in this situation we should probably exit to userspace + provide a way to reinject the abort.
as mentioned below, maybe the proper way is to handle it like KVM_EXIT_ARM_NISV. In this case exit to userspace with KVM_EXIT_ARM_LDST64B, if it's due to the wrong mapping of the guestOS then reinject the DABT back to the guest, otherwise the userspace need to check whether it's reporting the memory region correctly and handle in its own way.
Quoted 29 lines
Quoted 25 lines
Quoted 15 lines
Quoted 15 lines
arch/arm64/kvm/mmu.c +11
-0@@ -1919,6 +1939,21 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) goto out_unlock; } +/* +* If instructions of FEAT_{LS64, LS64_V} operated on +* unsupported memory regions, a DABT for unsupported +* Exclusive or atomic access is generated. It's +* implementation defined whether the exception will +* be taken to, a stage-1 DABT or the final enabled +* stage of translation (stage-2 in this case as we +* hit here). Inject a DABT to the guest to handle it +* if it's implemented as a stage-2 DABT. +*/ +if (esr_fsc_is_excl_atomic_fault (esr)) {Quoted 9 lines
arch/arm64/kvm/mmu.c int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) · line 1956
Quoted 4 lines
arch/arm64/kvm/mmu.c +4
-0+kvm_inject_dabt_excl_atomic (vcpu,kvm_vcpu_get_hfar (vcpu)); +return 1 ; + } +A precondition of taking such a data abort is having a valid mapping at stage-2. If KVM can't resolve the HVA of the fault then there couldn't have been a stage-2 mapping.
Quoted 3 lines
Here's handling the case for emulated mmio, I thought there's no valid stage-2 mapping for the emulated MMIO? so this check is put just before entering
io_mem_abort(). should it be put intoio_mem_abort()or we just don't handle the emulated case?
Quoted 7 lines
Right -- there's no valid stage-2 translation for _most_ MMIO. If KVM cannot find an HVA for the fault (look at the condition that gets us here) then we know there isn't a stage-2 mapping. How would we know what to map?
In that case I would expect to take a Translation fault with instruction syndrome that can can be used to construct an exit to the VMM.
you're right, I misunderstand here. If there's no stage-2 mapping we'll have a translation fault here rather than an unsupported exclusive or atomic access fault. So no need to check and handle it here since we won't have such a fault in this case.
Quoted 10 lines
Marc had
some patches on list to do exactly that [*].However, after reading this again there's a rather ugly catch. The KVM ABI has it that writes to a RO memlot generate an MMIO exit, so it *is* possible to get here w/ a stage-2 mapping. Unfortunately there's no instruction syndrome with DFSC =
0x35so no way to decode the access.This is starting to sound similar an nISV MMIO abort...
yes similiar to nISV MMIO and no ISV as well. Per-spec DABT caused by LS64* has ISV==1 if it's a Translation fault, Access flag fault, or Permission fault, but not for unsupported exclusive or atomic access fault..
Quoted 2 lines
Thanks.