Skip to contentSkip to conversation

KVM: arm64: Minor pKVM cleanups

PATCH Applied Oliver Upton 3 participants 6 messages May 9, 2022 – May 10, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover KVM: arm64: Minor pKVM cleanups

I was reading through some of the pKVM stuff to get an idea of how it handles feature registers and spotted a few minor nits.

Applies cleanly to 5.18-rc5.

Oliver Upton (2):
KVM: arm64: pkvm: Drop unnecessary FP/SIMD trap handler
KVM: arm64: pkvm: Don't mask already zeroed FEAT_SVE

 arch/arm64/kvm/hyp/nvhe/switch.c   | 19 +------------------
 arch/arm64/kvm/hyp/nvhe/sys_regs.c |  3 ---
 2 files changed, 1 insertion(+), 21 deletions(-)
Signature · 6 lines
2.36.0.512.ge40c2bad7a-goog

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

PATCH 1/2 KVM: arm64: pkvm: Drop unnecessary FP/SIMD trap handler

The pVM-specific FP/SIMD trap handler just calls straight into the generic trap handler. Avoid the indirection and just call the hyp handler directly.

Note that the BUILD_BUG_ON() pattern is repeated in pvm_init_traps_aa64pfr0(), which is likely a better home for it.

No functional change intended.

---
 arch/arm64/kvm/hyp/nvhe/switch.c | 19 +------------------
 1 file changed, 1 insertion(+), 18 deletions(-)
arch/arm64/kvm/hyp/nvhe/switch.c +1 -18
index 6410d21d8695..3dee2ad96e10 100644
@@ -175,23 +175,6 @@ static bool kvm_handle_pvm_sys64(struct kvm_vcpu *vcpu, u64 *exit_code)
 		kvm_handle_pvm_sysreg(vcpu, exit_code));
 }
 
-/**
- * Handler for protected floating-point and Advanced SIMD accesses.
- *
- * Returns true if the hypervisor has handled the exit, and control should go
- * back to the guest, or false if it hasn't.
- */
-static bool kvm_handle_pvm_fpsimd(struct kvm_vcpu *vcpu, u64 *exit_code)
-{
-	/* Linux guests assume support for floating-point and Advanced SIMD. */
-	BUILD_BUG_ON(!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_FP),
-				PVM_ID_AA64PFR0_ALLOW));
-	BUILD_BUG_ON(!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_ASIMD),
-				PVM_ID_AA64PFR0_ALLOW));
-
-	return kvm_hyp_handle_fpsimd(vcpu, exit_code);
-}
-
 static const exit_handler_fn hyp_exit_handlers[] = {
 	[0 ... ESR_ELx_EC_MAX]		= NULL,
 	[ESR_ELx_EC_CP15_32]		= kvm_hyp_handle_cp15_32,
@@ -207,7 +190,7 @@ static const exit_handler_fn pvm_exit_handlers[] = {
 	[0 ... ESR_ELx_EC_MAX]		= NULL,
 	[ESR_ELx_EC_SYS64]		= kvm_handle_pvm_sys64,
 	[ESR_ELx_EC_SVE]		= kvm_handle_pvm_restricted,
-	[ESR_ELx_EC_FP_ASIMD]		= kvm_handle_pvm_fpsimd,
+	[ESR_ELx_EC_FP_ASIMD]		= kvm_hyp_handle_fpsimd,
 	[ESR_ELx_EC_IABT_LOW]		= kvm_hyp_handle_iabt_low,
 	[ESR_ELx_EC_DABT_LOW]		= kvm_hyp_handle_dabt_low,
 	[ESR_ELx_EC_PAC]		= kvm_hyp_handle_ptrauth,
Signature · 6 lines
2.36.0.512.ge40c2bad7a-goog

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] KVM: arm64: pkvm: Drop unnecessary FP/SIMD trap handler

Hi Oliver,

Quoted 9 lines · Oliver Upton

The pVM-specific FP/SIMD trap handler just calls straight into the generic trap handler. Avoid the indirection and just call the hyp handler directly.

Note that the BUILD_BUG_ON() pattern is repeated in pvm_init_traps_aa64pfr0(), which is likely a better home for it.

No functional change intended.

Cheers,
/fuad

Quoted 46 lines
---
 arch/arm64/kvm/hyp/nvhe/switch.c | 19 +------------------
 1 file changed, 1 insertion(+), 18 deletions(-)
arch/arm64/kvm/hyp/nvhe/switch.c +1 -19
index 6410d21d8695..3dee2ad96e10 100644
@@ -175,23 +175,6 @@ static bool kvm_handle_pvm_sys64(struct kvm_vcpu *vcpu, u64 *exit_code)
                kvm_handle_pvm_sysreg(vcpu, exit_code));
 }
 
-/**
- * Handler for protected floating-point and Advanced SIMD accesses.
- *
- * Returns true if the hypervisor has handled the exit, and control should go
- * back to the guest, or false if it hasn't.
- */
-static bool kvm_handle_pvm_fpsimd(struct kvm_vcpu *vcpu, u64 *exit_code)
-{
-       /* Linux guests assume support for floating-point and Advanced SIMD. */
-       BUILD_BUG_ON(!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_FP),
-                               PVM_ID_AA64PFR0_ALLOW));
-       BUILD_BUG_ON(!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_ASIMD),
-                               PVM_ID_AA64PFR0_ALLOW));
-
-       return kvm_hyp_handle_fpsimd(vcpu, exit_code);
-}
-
 static const exit_handler_fn hyp_exit_handlers[] = {
        [0 ... ESR_ELx_EC_MAX]          = NULL,
        [ESR_ELx_EC_CP15_32]            = kvm_hyp_handle_cp15_32,
@@ -207,7 +190,7 @@ static const exit_handler_fn pvm_exit_handlers[] = {
        [0 ... ESR_ELx_EC_MAX]          = NULL,
        [ESR_ELx_EC_SYS64]              = kvm_handle_pvm_sys64,
        [ESR_ELx_EC_SVE]                = kvm_handle_pvm_restricted,
-       [ESR_ELx_EC_FP_ASIMD]           = kvm_handle_pvm_fpsimd,
+       [ESR_ELx_EC_FP_ASIMD]           = kvm_hyp_handle_fpsimd,
        [ESR_ELx_EC_IABT_LOW]           = kvm_hyp_handle_iabt_low,
        [ESR_ELx_EC_DABT_LOW]           = kvm_hyp_handle_dabt_low,
        [ESR_ELx_EC_PAC]                = kvm_hyp_handle_ptrauth,
--

2.36.0.512.ge40c2bad7a-goog

#3 lore raw

PATCH 2/2 KVM: arm64: pkvm: Don't mask already zeroed FEAT_SVE

In reply to Oliver Upton

FEAT_SVE is already masked by the fixed configuration for ID_AA64PFR0_EL1; don't try and mask it at runtime.

No functional change intended.

---
 arch/arm64/kvm/hyp/nvhe/sys_regs.c | 3 ---
 1 file changed, 3 deletions(-)
arch/arm64/kvm/hyp/nvhe/sys_regs.c +0 -3
index 33f5181af330..3f5d7bd171c5 100644
@@ -90,9 +90,6 @@ static u64 get_pvm_id_aa64pfr0(const struct kvm_vcpu *vcpu)
 	u64 set_mask = 0;
 	u64 allow_mask = PVM_ID_AA64PFR0_ALLOW;
 
-	if (!vcpu_has_sve(vcpu))
-		allow_mask &= ~ARM64_FEATURE_MASK(ID_AA64PFR0_SVE);
-
 	set_mask |= get_restricted_features_unsigned(id_aa64pfr0_el1_sys_val,
 		PVM_ID_AA64PFR0_RESTRICT_UNSIGNED);
 
Signature · 6 lines
2.36.0.512.ge40c2bad7a-goog

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] KVM: arm64: pkvm: Don't mask already zeroed FEAT_SVE

Hi Oliver,

Quoted 8 lines · Oliver Upton

FEAT_SVE is already masked by the fixed configuration for ID_AA64PFR0_EL1; don't try and mask it at runtime.

No functional change intended.

---

Cheers,
/fuad

Quoted 20 lines
 arch/arm64/kvm/hyp/nvhe/sys_regs.c | 3 ---
 1 file changed, 3 deletions(-)
arch/arm64/kvm/hyp/nvhe/sys_regs.c +0 -4
index 33f5181af330..3f5d7bd171c5 100644
@@ -90,9 +90,6 @@ static u64 get_pvm_id_aa64pfr0(const struct kvm_vcpu *vcpu)
        u64 set_mask = 0;
        u64 allow_mask = PVM_ID_AA64PFR0_ALLOW;
 
-       if (!vcpu_has_sve(vcpu))
-               allow_mask &= ~ARM64_FEATURE_MASK(ID_AA64PFR0_SVE);
-
        set_mask |= get_restricted_features_unsigned(id_aa64pfr0_el1_sys_val,
                PVM_ID_AA64PFR0_RESTRICT_UNSIGNED);
 
--

2.36.0.512.ge40c2bad7a-goog

maintainer Applied
#5 lore raw
In reply to Oliver Upton
Quoted 10 lines · Oliver Upton

I was reading through some of the pKVM stuff to get an idea of how it handles feature registers and spotted a few minor nits.

Applies cleanly to 5.18-rc5.

Oliver Upton (2):
KVM: arm64: pkvm: Drop unnecessary FP/SIMD trap handler
KVM: arm64: pkvm: Don't mask already zeroed FEAT_SVE

[...]

Applied to next, thanks!

[1/2] KVM: arm64: pkvm: Drop unnecessary FP/SIMD trap handler

      commit: 4d2e469e163ec79340b2f42c2a07838b5ff30686
[2/2] KVM: arm64: pkvm: Don't mask already zeroed FEAT_SVE
      commit: 249838b7660ac04a67bfb017364a7f01029370a0

Cheers,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.