Skip to contentSkip to conversation

KVM: arm64: Support debug, SVE, MOPS, PIE/POE, FPMR and more in protected VMs

PATCH In review Fuad Tabba 2 participants 25 messages Nov 25

Subsystems (4)
lore
Share & tools
lore

Fuad Tabba

author reviewer
#0 lore raw

v2 cover KVM: arm64: Support debug, SVE, MOPS, PIE/POE, FPMR and more in protected VMs

Hi folks,

Changes since v1 [1]:
- Replaced the #ifdef around the feature map check with a WARN_ON(). (Oliver)
- Added two fixes, for ptrauth and MTE_frac.
- Added a patch advertising GICv3 to protected VMs on GICv5 hosts with legacy support.
- Small fixes and tidying up.
- Rebased on 7.4-rc3.

With most of the groundwork merged, it's time to bring protected VMs up to the features we support for them in Android.

  01-02:  Fixes for ptrauth and MTE_frac.
  03:     Self-hosted debug.
  04-07:  SVE, with EL2 owning a protected vCPU's SVE state.
  08-11:  Compute a protected vCPU's fine-grained traps at EL2.
  12-20:  Advertise TCR2, SCTLR2, S1PIE, S1POE, MOPS, FPMR and the

features EL2 already handles for non-protected guests.

Tested on QEMU, in hVHE and nVHE, and on FVP for S1POE, GICv5 in legacy mode and the fields QEMU doesn't model (CLRBHB, RPRFM, ECBHB, LSFE, LSUI, HAFT, ETS3 and F16MM). v2 of the pKVM selftests series [2] covers debug, SVE, MOPS, PIE, POE and FPMR.

Based on Linux 7.4-rc3 (aebb727447640).

Cheers,
/fuad

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

Fuad Tabba (20):
KVM: arm64: Only allow ptrauth for a pVM on a system with full ptrauth
KVM: arm64: Don't advertise the host's MTE_frac to protected VMs
KVM: arm64: Add support for self-hosted debug in protected guests
KVM: arm64: Remove redundant kern_hyp_va() calls from the pKVM FP sync
KVM: arm64: Allocate a protected vCPU's SVE state at EL2
KVM: arm64: Advertise ID_AA64ZFR0_EL1 to protected VMs
KVM: arm64: Allow protected VMs to use SVE
KVM: arm64: Move the VM's FGU initialisation into config.c
KVM: arm64: Report an incomplete feature map with WARN_ON()
KVM: arm64: Advertise the GICv3 CPU interface to protected VMs on
GICv5
KVM: arm64: Compute a protected vCPU's fine-grained traps at EL2
KVM: arm64: Advertise TCR2, SCTLR2, S1PIE and S1POE to protected VMs
KVM: arm64: Advertise MOPS to protected VMs
KVM: arm64: Advertise FPMR to protected VMs
KVM: arm64: Advertise HBC, CLRBHB, RPRFM, CSSC and LUT to protected
VMs
KVM: arm64: Advertise FAMINMAX, LSFE, LSUI and FPRCVT to protected VMs
KVM: arm64: Advertise AFP and RPRES to protected VMs
KVM: arm64: Advertise ECBHB, TIDCP1, TTST and LVA to protected VMs
KVM: arm64: Advertise FP8 and F16MM to protected VMs
KVM: arm64: Advertise ECV, HAFT and ETS3 to protected VMs

 Documentation/virt/kvm/arm/pkvm.rst     |  13 +-
 arch/arm64/include/asm/kvm_host.h       |   2 +-
 arch/arm64/include/asm/kvm_hyp.h        |   6 +
 arch/arm64/include/asm/kvm_pkvm.h       |  12 +-
 arch/arm64/kvm/arm.c                    |  11 +
 arch/arm64/kvm/config.c                 |  24 +-
 arch/arm64/kvm/hyp/include/hyp/switch.h |   2 +-
 arch/arm64/kvm/hyp/include/nvhe/pkvm.h  |   1 +
 arch/arm64/kvm/hyp/nvhe/Makefile        |   4 +-
 arch/arm64/kvm/hyp/nvhe/hyp-main.c      |   6 +-
 arch/arm64/kvm/hyp/nvhe/pkvm.c          |  51 ++--
 arch/arm64/kvm/hyp/nvhe/switch.c        |   1 +
 arch/arm64/kvm/hyp/nvhe/sys_regs.c      | 350 ++++++++++++++++++++++--
 arch/arm64/kvm/reset.c                  |   2 +
 arch/arm64/kvm/sys_regs.c               |  17 +-
 15 files changed, 423 insertions(+), 79 deletions(-)

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3

Signature · 1 line
2.47.3
author reviewer
#1 lore raw

PATCH v2 1/20 KVM: arm64: Only allow ptrauth for a pVM on a system with full ptrauth

EL2 allows a protected VM both ptrauth features whatever the system supports. An id_aa64isar1 override can leave a system with generic but not address auth. EL2 then doesn't trap the guest's key accesses, but it doesn't switch the keys either, since the switch is gated on ARM64_HAS_ADDRESS_AUTH. The host can read and write the guest's APGAKey.

Only allow the ptrauth features when the system has full ptrauth, as the host does.

Fixes b56680de9c648 ("KVM: arm64: Initialize trap register values in hyp in pKVM")
---
 arch/arm64/include/asm/kvm_pkvm.h | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
arch/arm64/include/asm/kvm_pkvm.h +7 -4
index fd042d2b54624..155ac35069245 100644
@@ -76,11 +76,14 @@ static inline void kvm_pkvm_vcpu_allowed_features(struct kvm *kvm,
 	if (kvm_pkvm_ext_allowed(kvm, KVM_CAP_ARM_PMU_V3))
 		set_bit(KVM_ARM_VCPU_PMU_V3, allowed);
 
-	if (kvm_pkvm_ext_allowed(kvm, KVM_CAP_ARM_PTRAUTH_ADDRESS))
-		set_bit(KVM_ARM_VCPU_PTRAUTH_ADDRESS, allowed);
+	/* Without address auth, EL2 doesn't switch the guest's keys. */
+	if (system_has_full_ptr_auth()) {
+		if (kvm_pkvm_ext_allowed(kvm, KVM_CAP_ARM_PTRAUTH_ADDRESS))
+			set_bit(KVM_ARM_VCPU_PTRAUTH_ADDRESS, allowed);
 
-	if (kvm_pkvm_ext_allowed(kvm, KVM_CAP_ARM_PTRAUTH_GENERIC))
-		set_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, allowed);
+		if (kvm_pkvm_ext_allowed(kvm, KVM_CAP_ARM_PTRAUTH_GENERIC))
+			set_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, allowed);
+	}
 
 	if (kvm_pkvm_ext_allowed(kvm, KVM_CAP_ARM_SVE))
 		set_bit(KVM_ARM_VCPU_SVE, allowed);
Signature · 1 line
2.47.3
author reviewer
#2 lore raw

PATCH v2 2/20 KVM: arm64: Don't advertise the host's MTE_frac to protected VMs

In reply to Fuad Tabba

Protected VMs don't support MTE, so MTE_frac in their ID_AA64PFR1_EL1 doesn't apply and is RES0, as it is for a non-protected VM without MTE.

Commit 3d7ff00700d1a ("KVM: arm64: Rework specifying restricted features for protected VMs") caps the field at NI in the pVM restriction table. However, NI is 0xF and the clamp is unsigned, so the cap does nothing and a protected guest sees the host's value. On a CPU with MTE2 but without FEAT_MTE_ASYNC, that value is 0xF.

Drop the entry so that the field reads as 0 again. It was the only entry capping an unsigned field at an NI other than 0.

---
 arch/arm64/kvm/hyp/nvhe/sys_regs.c | 1 -
 1 file changed, 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/sys_regs.c +0 -1
index 32e82653ebf7e..e1749138f7507 100644
@@ -105,7 +105,6 @@ static const struct pvm_ftr_bits pvmid_aa64pfr0[] = {
 static const struct pvm_ftr_bits pvmid_aa64pfr1[] = {
 	MAX_FEAT(ID_AA64PFR1_EL1, BT, IMP),
 	MAX_FEAT(ID_AA64PFR1_EL1, SSBS, SSBS2),
-	MAX_FEAT_ENUM(ID_AA64PFR1_EL1, MTE_frac, NI),
 	FEAT_END
 };
 
Signature · 1 line
2.47.3
#3 lore raw

Re: [PATCH v2 02/20] KVM: arm64: Don't advertise the host's MTE_frac to protected VMs

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] KVM: arm64: missing Fixes trailer for commit 3d7ff00700d1 --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] KVM: arm64: missing Fixes trailer for commit 3d7ff00700d1 --

commit f7eced7525b14181f745f704977ce69bbe4690ce
Author: Fuad Tabba <[email protected]>

Quoted 11 lines

KVM: arm64: Don't advertise the host's MTE_frac to protected VMs

Protected VMs don't support MTE, so MTE_frac in their ID_AA64PFR1_EL1 doesn't apply and is RES0, as it is for a non-protected VM without MTE.

Commit 3d7ff00700d1a ("KVM: arm64: Rework specifying restricted features for protected VMs") caps the field at NI in the pVM restriction table. However, NI is 0xF and the clamp is unsigned, so the cap does nothing and a protected guest sees the host's value. On a CPU with MTE2 but without FEAT_MTE_ASYNC, that value is 0xF.

Quoted 4 lines

Drop the entry so that the field reads as 0 again. It was the only entry capping an unsigned field at an NI other than 0.

[Severity: Low]
Should this include a Fixes tag for the commit that added the MTE_frac entry to pvmid_aa64pfr1[]?

Fixes 3d7ff00700d1 ("KVM: arm64: Rework specifying restricted features for protected VMs")
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
author reviewer
#4 lore raw

Re: [PATCH v2 02/20] KVM: arm64: Don't advertise the host's MTE_frac to protected VMs

Quoted 4 lines · On Wed, 25 Nov 2026 at 15:49, <[email protected]> wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] KVM: arm64: missing Fixes trailer for commit 3d7ff00700d1

[...]

Quoted 5 lines

[Severity: Low]
Should this include a Fixes tag for the commit that added the MTE_frac entry to pvmid_aa64pfr1[]?

Fixes 3d7ff00700d1 ("KVM: arm64: Rework specifying restricted features for protected VMs")

No. A protected VM doesn't have MTE, so the field isn't read, and the wrong value doesn't cause a failure. The commit that added the entry is in the commit message.

/fuad

author reviewer
#5 lore raw

PATCH v2 3/20 KVM: arm64: Add support for self-hosted debug in protected guests

In reply to Fuad Tabba

pKVM hides DebugVer from protected guests and makes their debug registers RAZ/WI or UNDEFINED, so they don't have breakpoints, watchpoints or single-step. For a non-protected guest, the host sets the owner of the debug registers at vcpu load, from the guest's MDSCR_EL1 and OS Lock, and EL2 copies the owner and the registers in at each entry. However, the host can't see a protected guest's registers.

Set the owner at EL2 for a protected vCPU instead, by the rules the host uses for a non-protected guest, but keep MDCR_EL2.TDA set when the guest is the owner. A trap handler returns to the guest without going back through the world switch, so a handler that changes the owner switches the debug registers itself. The PSCI CPU_ON reset runs after the vcpu load, so it sets the owner again.

Advertise DebugVer, capped at V8P8 as for a non-protected guest, and the breakpoint, watchpoint and context-aware breakpoint counts. The other debug registers that took an UNDEF behave as they do for a non-protected guest that doesn't own its debug registers.

---
 Documentation/virt/kvm/arm/pkvm.rst    |   7 +-
 arch/arm64/include/asm/kvm_hyp.h       |   1 +
 arch/arm64/kvm/arm.c                   |   1 +
 arch/arm64/kvm/hyp/include/nvhe/pkvm.h |   1 +
 arch/arm64/kvm/hyp/nvhe/hyp-main.c     |   2 +
 arch/arm64/kvm/hyp/nvhe/pkvm.c         |   8 +-
 arch/arm64/kvm/hyp/nvhe/sys_regs.c     | 253 +++++++++++++++++++++++--
 7 files changed, 248 insertions(+), 25 deletions(-)
Documentation/virt/kvm/arm/pkvm.rst +3 -4
index b75bb8ad6f26d..b8c8c94cba534 100644
@@ -241,10 +241,9 @@ Other interface differences
 Debug
 -----
 
-Hardware-assisted debugging is not available to protected guests.
-``MDSCR_EL1``, ``OSLAR_EL1``, ``OSLSR_EL1``, ``OSDLR_EL1``, and breakpoint
-and watchpoint 0 are RAZ/WI; any other debug register access takes an
-undefined instruction exception.
+A protected guest can use self-hosted debug (breakpoints, watchpoints and
+single-step) as a non-protected guest can. ``KVM_SET_GUEST_DEBUG`` returns
+``-EPERM`` for a protected VM.
 
 Resources
 =========
arch/arm64/include/asm/kvm_hyp.h +1 -0
index b0e42be3d9eef..9a785a341090e 100644
@@ -151,6 +151,7 @@ extern u64 kvm_nvhe_sym(id_aa64mmfr0_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64mmfr1_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64mmfr2_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64smfr0_el1_sys_val);
+extern u64 kvm_nvhe_sym(id_aa64dfr0_el1_sys_val);
 
 extern unsigned long kvm_nvhe_sym(__icache_flags);
 extern unsigned int kvm_nvhe_sym(kvm_arm_vmid_bits);
arch/arm64/kvm/arm.c +1 -0
index 157bf4b812020..ec90a580e82a4 100644
@@ -2834,6 +2834,7 @@ static void kvm_hyp_init_symbols(void)
 	kvm_nvhe_sym(id_aa64mmfr1_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1);
 	kvm_nvhe_sym(id_aa64mmfr2_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64MMFR2_EL1);
 	kvm_nvhe_sym(id_aa64smfr0_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64SMFR0_EL1);
+	kvm_nvhe_sym(id_aa64dfr0_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1);
 	kvm_nvhe_sym(__icache_flags) = __icache_flags;
 	kvm_nvhe_sym(kvm_arm_vmid_bits) = kvm_arm_vmid_bits;
 
arch/arm64/kvm/hyp/include/nvhe/pkvm.h +1 -0
index 0261b2bc681f7..993d54ce44408 100644
@@ -130,6 +130,7 @@ void put_pkvm_hyp_vm(struct pkvm_hyp_vm *hyp_vm);
 bool kvm_handle_pvm_hvc64(struct kvm_vcpu *vcpu, u64 *exit_code);
 bool kvm_handle_pvm_sysreg(struct kvm_vcpu *vcpu, u64 *exit_code);
 bool kvm_handle_pvm_restricted(struct kvm_vcpu *vcpu, u64 *exit_code);
+void kvm_load_pvm_debug(struct kvm_vcpu *vcpu);
 void kvm_init_pvm_id_regs(struct kvm_vcpu *vcpu);
 void kvm_reset_pvm_sys_regs(struct kvm_vcpu *vcpu);
 int kvm_check_pvm_sysreg_table(void);
arch/arm64/kvm/hyp/nvhe/hyp-main.c +2 -0
index 179d7c8277b88..9958ca6d7b0a2 100644
@@ -837,6 +837,8 @@ DEFINE_KVM_HOST_HCALL(void, __pkvm_vcpu_load,
 		hyp_vcpu->vcpu.arch.hcr_el2 &= ~(HCR_EL2_TWE | HCR_EL2_TWI);
 		hyp_vcpu->vcpu.arch.hcr_el2 |= hcr_el2 & (HCR_EL2_TWE | HCR_EL2_TWI);
 
+		kvm_load_pvm_debug(&hyp_vcpu->vcpu);
+
 		/* HPMN == 0 is reserved without FEAT_HPMN0. */
 		if (pmuv3_implemented(SYS_FIELD_GET(ID_AA64DFR0_EL1, PMUVer, dfr0)))
 			u64p_replace_bits(&hyp_vcpu->vcpu.arch.mdcr_el2,
arch/arm64/kvm/hyp/nvhe/pkvm.c +6 -2
index fc0475f0877d1..1d484da274c0e 100644
@@ -123,8 +123,11 @@ static void pvm_init_traps_mdcr(struct kvm_vcpu *vcpu)
 		val &= ~(MDCR_EL2_HPME | MDCR_EL2_MTPME);
 	}
 
-	if (!kvm_has_feat(kvm, ID_AA64DFR0_EL1, DebugVer, IMP))
-		val |= MDCR_EL2_TDRA | MDCR_EL2_TDA;
+	/*
+	 * Keep TDA set even when the guest owns debug: it also traps the DCC
+	 * and the claim tags, which the world switch doesn't switch.
+	 */
+	val |= MDCR_EL2_TDRA | MDCR_EL2_TDA;
 
 	if (!kvm_has_feat(kvm, ID_AA64DFR0_EL1, DoubleLock, IMP))
 		val |= MDCR_EL2_TDOSA;
@@ -1245,6 +1248,7 @@ int pkvm_reset_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu)
 
 	kvm_reset_vcpu_core(&hyp_vcpu->vcpu);
 	kvm_reset_pvm_sys_regs(&hyp_vcpu->vcpu);
+	kvm_load_pvm_debug(&hyp_vcpu->vcpu);
 
 	/* Must be done after resetting sys registers. */
 	kvm_reset_vcpu_psci(&hyp_vcpu->vcpu, reset_state);
arch/arm64/kvm/hyp/nvhe/sys_regs.c +234 -19

315 lines not on this page · raw message

Signature · 1 line
2.47.3
author reviewer
#6 lore raw

PATCH v2 4/20 KVM: arm64: Remove redundant kern_hyp_va() calls from the pKVM FP sync

In reply to Fuad Tabba

With pKVM, EL2 saves FP and SVE state through the hyp vCPU, whose kvm is the hyp VM's and whose sve_state is already a hyp address. kern_hyp_va() returns both unchanged.

Remove the calls in fpsimd_sve_sync() and __hyp_sve_save_guest(), and the one in kvm_hyp_save_fpsimd_host(), which only pKVM reaches. The ones in __hyp_sve_restore_guest() and kvm_hyp_handle_fpsimd() stay, as nVHE without pKVM reaches them with the host's pointers.

No functional change intended.

---
 arch/arm64/kvm/hyp/include/hyp/switch.h | 2 +-
 arch/arm64/kvm/hyp/nvhe/hyp-main.c      | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
arch/arm64/kvm/hyp/include/hyp/switch.h +1 -1
index e0c55644224cb..ee85a8bc4d798 100644
@@ -594,7 +594,7 @@ static void kvm_hyp_save_fpsimd_host(struct kvm_vcpu *vcpu)
 		fpsimd_save_state(&hctxt->fp_regs);
 	}
 
-	if (kvm_has_fpmr(kern_hyp_va(vcpu->kvm)))
+	if (kvm_has_fpmr(vcpu->kvm))
 		ctxt_sys_reg(hctxt, FPMR) = read_sysreg_s(SYS_FPMR);
 }
 
arch/arm64/kvm/hyp/nvhe/hyp-main.c +2 -2
index 9958ca6d7b0a2..57c3f7a2d4b14 100644
@@ -482,7 +482,7 @@ static void __hyp_sve_save_guest(struct kvm_vcpu *vcpu)
 	 * on the VL, so use a consistent (i.e., the maximum) guest VL.
 	 */
 	sve_cond_update_zcr_vq(vcpu_sve_max_vq(vcpu) - 1, SYS_ZCR_EL2);
-	sve_save_state(kern_hyp_va(vcpu->arch.sve_state), true);
+	sve_save_state(vcpu->arch.sve_state, true);
 	fpsimd_save_common(&vcpu->arch.ctxt.fp_regs);
 	write_sysreg_s(sve_vq_from_vl(kvm_host_sve_max_vl) - 1, SYS_ZCR_EL2);
 }
@@ -531,7 +531,7 @@ static void fpsimd_sve_sync(struct kvm_vcpu *vcpu)
 	else
 		fpsimd_save_state(&vcpu->arch.ctxt.fp_regs);
 
-	has_fpmr = kvm_has_fpmr(kern_hyp_va(vcpu->kvm));
+	has_fpmr = kvm_has_fpmr(vcpu->kvm);
 	if (has_fpmr)
 		__vcpu_assign_sys_reg(vcpu, FPMR, read_sysreg_s(SYS_FPMR));
 
Signature · 1 line
2.47.3
author reviewer
#7 lore raw

PATCH v2 5/20 KVM: arm64: Allocate a protected vCPU's SVE state at EL2

In reply to Fuad Tabba

For a vCPU with SVE, EL2 pins the buffer the host allocated at KVM_ARM_VCPU_FINALIZE and saves the guest's SVE registers there. The host can still read and write that buffer, so it can't hold a protected vCPU's state.

Allocate a protected vCPU's SVE state from the hyp heap instead, and free it with the vCPU. When EL2 resets a protected vCPU, zero its SVE state and ZCR_EL1, as KVM does for a non-protected one. The host still allocates its own buffer, which KVM_{GET,SET}_ONE_REG access before the first run, but EL2 doesn't use it.

For a protected vCPU, the host's sve_max_vl now sizes an EL2 allocation and is the guest's maximum vector length on every CPU. Give EL2 a copy of kvm_sve_max_vl, the largest length all CPUs can give a guest, and check every vCPU's sve_max_vl against it rather than clamping it to the host's own maximum. set_sve_vls() already keeps the host's value within that bound.

---
 arch/arm64/include/asm/kvm_hyp.h   |  1 +
 arch/arm64/kvm/hyp/nvhe/pkvm.c     | 41 ++++++++++++++++++++----------
 arch/arm64/kvm/hyp/nvhe/sys_regs.c |  1 +
 arch/arm64/kvm/reset.c             |  2 ++
 4 files changed, 31 insertions(+), 14 deletions(-)
arch/arm64/include/asm/kvm_hyp.h +1 -0
index 9a785a341090e..22601a4e36f4e 100644
@@ -158,6 +158,7 @@ extern unsigned int kvm_nvhe_sym(kvm_arm_vmid_bits);
 extern enum mitigation_state kvm_nvhe_sym(spectre_v2_state);
 extern enum mitigation_state kvm_nvhe_sym(spectre_v4_state);
 extern enum mitigation_state kvm_nvhe_sym(spectre_bhb_state);
+extern unsigned int kvm_nvhe_sym(kvm_sve_max_vl);
 extern unsigned int kvm_nvhe_sym(kvm_host_sve_max_vl);
 extern unsigned long kvm_nvhe_sym(hyp_nr_cpus);
 extern unsigned int kvm_nvhe_sym(hyp_gicv3_nr_lr);
arch/arm64/kvm/hyp/nvhe/pkvm.c +27 -14

93 lines not on this page · raw message

arch/arm64/kvm/hyp/nvhe/sys_regs.c +1 -0
index 13209786d0a71..3b468ef619ed2 100644
@@ -782,6 +782,7 @@ static const struct sys_reg_desc_reset pvm_sys_reg_reset_vals[] = {
 	RESET_UNKNOWN(MAIR_EL1),
 	RESET_ZERO(AMAIR_EL1),
 	RESET_ZERO(MDSCR_EL1),
+	RESET_ZERO(ZCR_EL1),
 	RESET_ZERO(CNTV_CTL_EL0),
 	RESET_UNKNOWN(TTBR0_EL1),
 	RESET_UNKNOWN(TTBR1_EL1),
arch/arm64/kvm/reset.c +2 -0
index 10eb7249aa9e8..aaaa1b8634ba4 100644
@@ -52,6 +52,8 @@ int __init kvm_arm_init_sve(void)
 		if (WARN_ON(kvm_sve_max_vl > VL_ARCH_MAX))
 			kvm_sve_max_vl = VL_ARCH_MAX;
 
+		kvm_nvhe_sym(kvm_sve_max_vl) = kvm_sve_max_vl;
+
 		/*
 		 * Don't even try to make use of vector lengths that
 		 * aren't available on all CPUs, for now:
Signature · 1 line
2.47.3
author reviewer
#8 lore raw

PATCH v2 6/20 KVM: arm64: Advertise ID_AA64ZFR0_EL1 to protected VMs

In reply to Fuad Tabba

EL2 builds a protected guest's ID registers from the host's sanitised values, most of them capped per field. It has no case for ID_AA64ZFR0_EL1, so the register reads as 0, and a protected guest with SVE wouldn't see any of the SVE extensions the CPUs implement.

Keep a copy of the host's sanitised ID_AA64ZFR0_EL1 at EL2, and advertise it when the guest has SVE, as KVM does for a non-protected guest. Cap each field at the highest value the sysreg file defines.

---
 arch/arm64/include/asm/kvm_hyp.h   |  1 +
 arch/arm64/kvm/arm.c               |  1 +
 arch/arm64/kvm/hyp/nvhe/sys_regs.c | 19 +++++++++++++++++++
 3 files changed, 21 insertions(+)
arch/arm64/include/asm/kvm_hyp.h +1 -0
index 22601a4e36f4e..920c1d8d45b1a 100644
@@ -144,6 +144,7 @@ void __noreturn __host_enter(struct kvm_cpu_context *host_ctxt);
 extern u64 kvm_nvhe_sym(id_aa64pfr0_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64pfr1_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64pfr2_el1_sys_val);
+extern u64 kvm_nvhe_sym(id_aa64zfr0_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64isar0_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64isar1_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64isar2_el1_sys_val);
arch/arm64/kvm/arm.c +1 -0
index ec90a580e82a4..2753686982f0b 100644
@@ -2827,6 +2827,7 @@ static void kvm_hyp_init_symbols(void)
 	kvm_nvhe_sym(id_aa64pfr0_el1_sys_val) = get_hyp_id_aa64pfr0_el1();
 	kvm_nvhe_sym(id_aa64pfr1_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64PFR1_EL1);
 	kvm_nvhe_sym(id_aa64pfr2_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64PFR2_EL1);
+	kvm_nvhe_sym(id_aa64zfr0_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64ZFR0_EL1);
 	kvm_nvhe_sym(id_aa64isar0_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64ISAR0_EL1);
 	kvm_nvhe_sym(id_aa64isar1_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64ISAR1_EL1);
 	kvm_nvhe_sym(id_aa64isar2_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64ISAR2_EL1);
arch/arm64/kvm/hyp/nvhe/sys_regs.c +19 -0
index 3b468ef619ed2..352998a07512a 100644
@@ -23,6 +23,7 @@
 u64 id_aa64pfr0_el1_sys_val;
 u64 id_aa64pfr1_el1_sys_val;
 u64 id_aa64pfr2_el1_sys_val;
+u64 id_aa64zfr0_el1_sys_val;
 u64 id_aa64isar0_el1_sys_val;
 u64 id_aa64isar1_el1_sys_val;
 u64 id_aa64isar2_el1_sys_val;
@@ -123,6 +124,22 @@ static const struct pvm_ftr_bits pvmid_aa64pfr2[] = {
 	FEAT_END
 };
 
+static const struct pvm_ftr_bits pvmid_aa64zfr0[] = {
+	MAX_FEAT_FUNC(ID_AA64ZFR0_EL1, SVEver, SVE2p3, vm_has_sve),
+	MAX_FEAT_FUNC(ID_AA64ZFR0_EL1, AES, AES2, vm_has_sve),
+	MAX_FEAT_FUNC(ID_AA64ZFR0_EL1, EltPerm, IMP, vm_has_sve),
+	MAX_FEAT_FUNC(ID_AA64ZFR0_EL1, BitPerm, IMP, vm_has_sve),
+	MAX_FEAT_FUNC(ID_AA64ZFR0_EL1, BF16, EBF16, vm_has_sve),
+	MAX_FEAT_FUNC(ID_AA64ZFR0_EL1, B16B16, B16MM, vm_has_sve),
+	MAX_FEAT_FUNC(ID_AA64ZFR0_EL1, SHA3, IMP, vm_has_sve),
+	MAX_FEAT_FUNC(ID_AA64ZFR0_EL1, SM4, IMP, vm_has_sve),
+	MAX_FEAT_FUNC(ID_AA64ZFR0_EL1, I8MM, IMP, vm_has_sve),
+	MAX_FEAT_FUNC(ID_AA64ZFR0_EL1, F16MM, IMP, vm_has_sve),
+	MAX_FEAT_FUNC(ID_AA64ZFR0_EL1, F32MM, IMP, vm_has_sve),
+	MAX_FEAT_FUNC(ID_AA64ZFR0_EL1, F64MM, IMP, vm_has_sve),
+	FEAT_END
+};
+
 static const struct pvm_ftr_bits pvmid_aa64mmfr0[] = {
 	MAX_FEAT_ENUM(ID_AA64MMFR0_EL1, PARANGE, 40),
 	MAX_FEAT_ENUM(ID_AA64MMFR0_EL1, ASIDBITS, 16),
@@ -242,6 +259,8 @@ static u64 pvm_calc_id_reg(const struct kvm_vcpu *vcpu, u32 id)
 		return get_restricted_features(vcpu, id_aa64pfr1_el1_sys_val, pvmid_aa64pfr1);
 	case SYS_ID_AA64PFR2_EL1:
 		return get_restricted_features(vcpu, id_aa64pfr2_el1_sys_val, pvmid_aa64pfr2);
+	case SYS_ID_AA64ZFR0_EL1:
+		return get_restricted_features(vcpu, id_aa64zfr0_el1_sys_val, pvmid_aa64zfr0);
 	case SYS_ID_AA64ISAR0_EL1:
 		return id_aa64isar0_el1_sys_val;
 	case SYS_ID_AA64ISAR1_EL1:
Signature · 1 line
2.47.3
author reviewer
#9 lore raw

PATCH v2 7/20 KVM: arm64: Allow protected VMs to use SVE

In reply to Fuad Tabba

Now that EL2 owns a protected vCPU's SVE state and advertises ID_AA64ZFR0_EL1, allow KVM_CAP_ARM_SVE for a protected VM, which lets KVM_ARM_VCPU_INIT take KVM_ARM_VCPU_SVE.

A protected guest's SVE access trap injects an UNDEF. An SVE instruction takes the SVE trap rather than the FP one, so a guest whose first vector instruction is an SVE one would get an UNDEF instead of the lazy FP switch. Handle the SVE trap as the FP trap is:
kvm_handle_pvm_fpsimd() switches the state for a vCPU with SVE and still injects the UNDEF for one without.

Update the documentation to match.

---
 Documentation/virt/kvm/arm/pkvm.rst | 6 +++---
 arch/arm64/include/asm/kvm_pkvm.h   | 1 +
 arch/arm64/kvm/hyp/nvhe/switch.c    | 1 +
 arch/arm64/kvm/hyp/nvhe/sys_regs.c  | 2 --
 4 files changed, 5 insertions(+), 5 deletions(-)
Documentation/virt/kvm/arm/pkvm.rst +3 -3
index b8c8c94cba534..c59e598645b1b 100644
@@ -134,9 +134,9 @@ A protected VM boots from a single primary vCPU. Before the first
 * Set the primary vCPU's boot state with ``KVM_SET_ONE_REG``: the kernel
   entry address in ``PC`` and the DTB pointer in ``x0``.
 
-``PC`` and ``x0`` are the only registers EL2 takes from the host. Other
-pre-run writes are accepted, but the guest starts from the state the
-hypervisor resets it to.
+``PC``, ``x0`` and the SVE vector lengths (``KVM_REG_ARM64_SVE_VLS``) are
+the only registers EL2 takes from the host. Other pre-run writes are
+accepted, but the guest starts from the state the hypervisor resets it to.
 
 Secondary vCPUs are started by the guest itself through PSCI ``CPU_ON``
 (see `Power state`_), which supplies their entry point and context ID.
arch/arm64/include/asm/kvm_pkvm.h +1 -0
index 155ac35069245..9350caed1e8e7 100644
@@ -40,6 +40,7 @@ static inline bool kvm_pkvm_ext_allowed(struct kvm *kvm, long ext)
 	case KVM_CAP_MAX_VCPU_ID:
 	case KVM_CAP_MSI_DEVID:
 	case KVM_CAP_ARM_VM_IPA_SIZE:
+	case KVM_CAP_ARM_SVE:
 	case KVM_CAP_ARM_PTRAUTH_ADDRESS:
 	case KVM_CAP_ARM_PTRAUTH_GENERIC:
 	case KVM_CAP_ONE_REG:
arch/arm64/kvm/hyp/nvhe/switch.c +1 -0
index 89fb9dd351ad5..0626f4203ba6d 100644
@@ -230,6 +230,7 @@ static const exit_handler_fn pvm_exit_handlers[] = {
 	[ESR_ELx_EC_WFx]		= kvm_handle_pvm_wfx,
 	[ESR_ELx_EC_HVC64]		= kvm_handle_pvm_hvc64,
 	[ESR_ELx_EC_SYS64]		= kvm_handle_pvm_sys64,
+	[ESR_ELx_EC_SVE]		= kvm_handle_pvm_fpsimd,
 	[ESR_ELx_EC_FP_ASIMD]		= kvm_handle_pvm_fpsimd,
 	[ESR_ELx_EC_IABT_LOW]		= kvm_hyp_handle_iabt_low,
 	[ESR_ELx_EC_DABT_LOW]		= kvm_hyp_handle_dabt_low,
arch/arm64/kvm/hyp/nvhe/sys_regs.c +0 -2
index 352998a07512a..0a536b237a7c9 100644
@@ -712,8 +712,6 @@ static const struct sys_reg_desc pvm_sys_reg_descs[] = {
 	ID_UNALLOCATED(7,6),
 	ID_UNALLOCATED(7,7),
 
-	/* Scalable Vector Registers are restricted. */
-
 	HOST_HANDLED(SYS_ICC_PMR_EL1),
 
 	RAZ_WI(SYS_ERRIDR_EL1),
Signature · 1 line
2.47.3
author reviewer
#10 lore raw

PATCH v2 8/20 KVM: arm64: Move the VM's FGU initialisation into config.c

In reply to Fuad Tabba

The first time one of a VM's vCPUs runs, kvm_calculate_traps() computes the VM's fine-grained UNDEF masks from its ID registers, one compute_fgu() call per FGT group, and sets KVM_ARCH_FLAG_FGU_INITIALIZED so that it computes them once. The next patch computes the same masks for protected VMs at EL2.

Move the calls and the flag into kvm_init_fgu() in config.c, so that a group added later is computed at EL2 too. compute_fgu() then has no caller outside config.c, so make it static.

No functional change intended.

---
 arch/arm64/include/asm/kvm_host.h |  2 +-
 arch/arm64/kvm/config.c           | 20 +++++++++++++++++++-
 arch/arm64/kvm/sys_regs.c         | 17 +----------------
 3 files changed, 21 insertions(+), 18 deletions(-)
arch/arm64/include/asm/kvm_host.h +1 -1
index 97332ffcb1300..82ba4bb9573f1 100644
@@ -1748,7 +1748,7 @@ static inline bool kvm_arch_has_irq_bypass(void)
 }
 
 void kvm_idregs_enforce_dependencies(struct kvm *kvm);
-void compute_fgu(struct kvm *kvm, enum fgt_group_id fgt);
+void kvm_init_fgu(struct kvm *kvm);
 struct resx get_reg_fixed_bits(struct kvm *kvm, enum vcpu_sysreg reg);
 void check_feature_map(void);
 void kvm_vcpu_load_fgt(struct kvm_vcpu *vcpu);
arch/arm64/kvm/config.c +19 -1
index adaf26ab93b85..c65cf1dd27330 100644
@@ -1586,7 +1586,7 @@ static u64 compute_fgu_bits(struct kvm *kvm, const struct reg_feat_map_desc *r)
 	return resx.res0 | resx.res1;
 }
 
-void compute_fgu(struct kvm *kvm, enum fgt_group_id fgt)
+static void compute_fgu(struct kvm *kvm, enum fgt_group_id fgt)
 {
 	u64 val = 0;
 
@@ -1630,6 +1630,24 @@ void compute_fgu(struct kvm *kvm, enum fgt_group_id fgt)
 	kvm->arch.fgu[fgt] = val;
 }
 
+void kvm_init_fgu(struct kvm *kvm)
+{
+	if (test_bit(KVM_ARCH_FLAG_FGU_INITIALIZED, &kvm->arch.flags))
+		return;
+
+	compute_fgu(kvm, HFGRTR_GROUP);
+	compute_fgu(kvm, HFGITR_GROUP);
+	compute_fgu(kvm, HDFGRTR_GROUP);
+	compute_fgu(kvm, HAFGRTR_GROUP);
+	compute_fgu(kvm, HFGRTR2_GROUP);
+	compute_fgu(kvm, HFGITR2_GROUP);
+	compute_fgu(kvm, HDFGRTR2_GROUP);
+	compute_fgu(kvm, ICH_HFGRTR_GROUP);
+	compute_fgu(kvm, ICH_HFGITR_GROUP);
+
+	set_bit(KVM_ARCH_FLAG_FGU_INITIALIZED, &kvm->arch.flags);
+}
+
 struct resx get_reg_fixed_bits(struct kvm *kvm, enum vcpu_sysreg reg)
 {
 	struct resx resx;
arch/arm64/kvm/sys_regs.c +1 -16
index c7d91138a6d49..2cbbae81c07c4 100644
@@ -5841,22 +5841,7 @@ void kvm_calculate_traps(struct kvm_vcpu *vcpu)
 	vcpu_set_hcr(vcpu);
 	vcpu_set_ich_hcr(vcpu);
 	vcpu_set_hcrx(vcpu);
-
-	if (test_bit(KVM_ARCH_FLAG_FGU_INITIALIZED, &kvm->arch.flags))
-		goto out;
-
-	compute_fgu(kvm, HFGRTR_GROUP);
-	compute_fgu(kvm, HFGITR_GROUP);
-	compute_fgu(kvm, HDFGRTR_GROUP);
-	compute_fgu(kvm, HAFGRTR_GROUP);
-	compute_fgu(kvm, HFGRTR2_GROUP);
-	compute_fgu(kvm, HFGITR2_GROUP);
-	compute_fgu(kvm, HDFGRTR2_GROUP);
-	compute_fgu(kvm, ICH_HFGRTR_GROUP);
-	compute_fgu(kvm, ICH_HFGITR_GROUP);
-
-	set_bit(KVM_ARCH_FLAG_FGU_INITIALIZED, &kvm->arch.flags);
-out:
+	kvm_init_fgu(kvm);
 	mutex_unlock(&kvm->arch.config_lock);
 }
 
Signature · 1 line
2.47.3
author reviewer
#11 lore raw

PATCH v2 9/20 KVM: arm64: Report an incomplete feature map with WARN_ON()

In reply to Fuad Tabba

At init, check_feature_map() reports with kvm_err() any feature map that doesn't account for every bit of its register. The next patch builds config.c into nVHE hyp, which has no printk(), so the check would need an #ifdef to keep it out of hyp.

Use WARN_ON() instead, which doesn't need printk().

---
 arch/arm64/kvm/config.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/arm64/kvm/config.c +1 -3
index c65cf1dd27330..eef5ca50fc382 100644
@@ -1409,9 +1409,7 @@ static void __init check_feat_map(const struct reg_bits_to_feat_map *map,
 		if (!((map[i].flags & FORCE_RESx) && (map[i].bits & resx)))
 			mask |= map[i].bits;
 
-	if (mask != ~resx)
-		kvm_err("Undefined %s behaviour, bits %016llx\n",
-			str, mask ^ ~resx);
+	WARN_ON(mask != ~resx);
 }
 
 static u64 reg_feat_map_bits(const struct reg_bits_to_feat_map *map)
Signature · 1 line
2.47.3
#12 lore raw

Re: [PATCH v2 09/20] KVM: arm64: Report an incomplete feature map with WARN_ON()

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] KVM: arm64: unused str parameter and name field in check_feat_map() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] KVM: arm64: unused str parameter and name field in check_feat_map()
--

commit ef16fb792e699aa85734a7167ff79fe6521ee780
Author: Fuad Tabba <[email protected]>

KVM: arm64: Report an incomplete feature map with WARN_ON()

This commit replaces the kvm_err() call in check_feat_map() with WARN_ON() so that arch/arm64/kvm/config.c can be built into the nVHE hypervisor without depending on printk().

arch/arm64/kvm/config.c static void __init check_feat_map(const struct reg_bits_to_feat_map *map, · line 1413

Quoted 13 lines
arch/arm64/kvm/config.c +1 -3
index c65cf1dd27330..eef5ca50fc382 100644
@@ -1409,9 +1409,7 @@ static void __init check_feat_map(const struct reg_bits_to_feat_map *map,
 		if (!((map[i].flags & FORCE_RESx) && (map[i].bits & resx)))
 			mask |= map[i].bits;
 
-	if (mask != ~resx)
-		kvm_err("Undefined %s behaviour, bits %016llx\n",
-			str, mask ^ ~resx);
+	WARN_ON(mask != ~resx);
 }

[Severity: Low]
Does replacing kvm_err() with WARN_ON() leave the str parameter of check_feat_map() and struct reg_feat_map_desc::name unused?

check_reg_desc() passing r->name to check_feat_map() was the only reader of struct reg_feat_map_desc::name. Leaving str and name in place triggers an unused-parameter warning under W=3 and, once config.c is built into nVHE hyp, keeps unused string literals and relocation entries in .hyp.rodata and .hyp.reloc, while the bare WARN_ON() across the 23 check_reg_desc() calls in check_feature_map() no longer reports which register or bits failed. Either str and struct reg_feat_map_desc::name should be removed, or check_feat_map(), check_reg_desc() and check_feature_map() could be guarded with #ifndef __KVM_NVHE_HYPERVISOR__ so the host init check keeps logging the register name and mismatched bits.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
author reviewer
#13 lore raw

Re: [PATCH v2 09/20] KVM: arm64: Report an incomplete feature map with WARN_ON()

Quoted 5 lines · On Wed, 25 Nov 2026 at 15:55, <[email protected]> wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] KVM: arm64: unused str parameter and name field in check_feat_map()

[...]

Quoted 3 lines

[Severity: Low]
Does replacing kvm_err() with WARN_ON() leave the str parameter of check_feat_map() and struct reg_feat_map_desc::name unused?

Deliberate. The #ifdef was removed at Oliver's request [1], and the warning doesn't print the register's name or the bits, as discussed there. The str parameter and the name field are kept so that this patch only changes how the check reports an incomplete feature map.

/fuad

[1] https://lore.kernel.org/all/[email protected]/

author reviewer
#14 lore raw

PATCH v2 10/20 KVM: arm64: Advertise the GICv3 CPU interface to protected VMs on GICv5

In reply to Fuad Tabba

A GICv5 host with FEAT_GCIE_LEGACY runs GICv3 guests, but its own ID_AA64PFR0_EL1.GIC is 0. KVM sets the field to IMP for non-protected VMs on such a host, but not for protected VMs, which read it from EL2's copy of the register. The next patch computes a protected vCPU's fine-grained traps from its ID registers, and with GIC at 0, EL2 would then inject an UNDEF for the guest's ICC_IGRPEN<n>_EL1 accesses.

Set the field to IMP in EL2's copy as well. The vgic isn't probed yet when the copy is made, so test the capability the vgic itself tests.

---
 arch/arm64/kvm/arm.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm64/kvm/arm.c +6 -0
index 2753686982f0b..3b4bc646d894a 100644
@@ -2819,6 +2819,12 @@ static u64 get_hyp_id_aa64pfr0_el1(void)
 	val |= FIELD_PREP(ID_AA64PFR0_EL1_CSV3,
 			  arm64_get_meltdown_state() == SPECTRE_UNAFFECTED);
 
+	/* A GICv5 host with legacy support gives its guests a GICv3. */
+	if (cpus_have_final_cap(ARM64_HAS_GICV5_LEGACY)) {
+		val &= ~ID_AA64PFR0_EL1_GIC;
+		val |= SYS_FIELD_PREP_ENUM(ID_AA64PFR0_EL1, GIC, IMP);
+	}
+
 	return val;
 }
 
Signature · 1 line
2.47.3
author reviewer
#15 lore raw

PATCH v2 11/20 KVM: arm64: Compute a protected vCPU's fine-grained traps at EL2

In reply to Fuad Tabba

pKVM sets a protected vCPU's HCR_EL2, MDCR_EL2 and HCRX_EL2 at EL2 from the VM's ID registers, but never computes its fine-grained traps, which stay 0. That traps every register with a negative-polarity trap bit, so a feature such as S1PIE can't be advertised to a protected VM.

Link config.c into nVHE hyp and compute the VM's FGU masks and the vCPU's fine-grained traps there, under vm_table_lock, once the ID registers are set. Build hyp without the latent_entropy plugin, which adds a reference to config.c's __init functions that hyp can't resolve.

This also restores the AmpereOne AC03_CPU_38 masking of a protected vCPU's TCR_EL1 writes, which was lost when the erratum's trap moved into the per-vCPU fine-grained traps.

Fixes fb10ddf35c1cc ("KVM: arm64: Compute per-vCPU FGTs at vcpu_load()")
---
 arch/arm64/kvm/hyp/nvhe/Makefile | 4 +++-
 arch/arm64/kvm/hyp/nvhe/pkvm.c   | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/Makefile +3 -1
index 56a7e2c05f73a..2980f1af90166 100644
@@ -12,7 +12,8 @@ asflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS
 ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS -D__DISABLE_TRACE_MMIO__
 ccflags-y += -fno-stack-protector	\
 	     -DDISABLE_BRANCH_PROFILING	\
-	     $(DISABLE_KSTACK_ERASE)
+	     $(DISABLE_KSTACK_ERASE)	\
+	     $(DISABLE_LATENT_ENTROPY_PLUGIN)
 
 hostprogs := gen-hyprel
 HOST_EXTRACFLAGS += -I$(objtree)/include
@@ -27,6 +28,7 @@ hyp-obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o
 	 cache.o setup.o mm.o mem_protect.o sys_regs.o pkvm.o stacktrace.o ffa.o
 hyp-obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \
 	 ../hyp-entry.o ../exception.o ../pgtable.o ../vgic-v5-sr.o
+hyp-obj-y += ../../config.o
 hyp-obj-y += ../../../kernel/smccc-call.o
 hyp-obj-$(CONFIG_LIST_HARDENED) += list_debug.o
 hyp-obj-$(CONFIG_NVHE_EL2_TRACING) += clock.o trace.o events.o
arch/arm64/kvm/hyp/nvhe/pkvm.c +2 -0
index fba8dfe6389d6..465d963d6ff57 100644
@@ -206,6 +206,8 @@ static int pkvm_vcpu_init_traps(struct pkvm_hyp_vcpu *hyp_vcpu)
 	pvm_init_traps_hcr(vcpu);
 	pvm_init_traps_mdcr(vcpu);
 	vcpu_set_hcrx(vcpu);
+	kvm_init_fgu(vcpu->kvm);
+	kvm_vcpu_load_fgt(vcpu);
 
 	return 0;
 }
Signature · 1 line
2.47.3
author reviewer
#16 lore raw

PATCH v2 12/20 KVM: arm64: Advertise TCR2, SCTLR2, S1PIE and S1POE to protected VMs

In reply to Fuad Tabba

Advertise FEAT_TCR2, FEAT_SCTLR2, FEAT_S1PIE and FEAT_S1POE to protected VMs, with S1POE only when the kernel supports POE, as EL2 doesn't switch the POE registers otherwise. With the fields set, vcpu_set_hcrx() sets HCRX_EL2.{TCR2En,SCTLR2En} for them, and since the previous patch their PIE and POE registers don't trap.

Reset the new registers as KVM does for a non-protected vCPU.

---
 arch/arm64/include/asm/kvm_hyp.h   |  1 +
 arch/arm64/kvm/arm.c               |  1 +
 arch/arm64/kvm/hyp/nvhe/sys_regs.c | 24 +++++++++++++++++++++++-
 3 files changed, 25 insertions(+), 1 deletion(-)
arch/arm64/include/asm/kvm_hyp.h +1 -0
index 920c1d8d45b1a..ab22b395d0908 100644
@@ -151,6 +151,7 @@ extern u64 kvm_nvhe_sym(id_aa64isar2_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64mmfr0_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64mmfr1_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64mmfr2_el1_sys_val);
+extern u64 kvm_nvhe_sym(id_aa64mmfr3_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64smfr0_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64dfr0_el1_sys_val);
 
arch/arm64/kvm/arm.c +1 -0
index 3b4bc646d894a..71afc5a5c9346 100644
@@ -2840,6 +2840,7 @@ static void kvm_hyp_init_symbols(void)
 	kvm_nvhe_sym(id_aa64mmfr0_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1);
 	kvm_nvhe_sym(id_aa64mmfr1_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1);
 	kvm_nvhe_sym(id_aa64mmfr2_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64MMFR2_EL1);
+	kvm_nvhe_sym(id_aa64mmfr3_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64MMFR3_EL1);
 	kvm_nvhe_sym(id_aa64smfr0_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64SMFR0_EL1);
 	kvm_nvhe_sym(id_aa64dfr0_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1);
 	kvm_nvhe_sym(__icache_flags) = __icache_flags;
arch/arm64/kvm/hyp/nvhe/sys_regs.c +23 -1
index 0a536b237a7c9..4f13b100007fa 100644
@@ -30,6 +30,7 @@ u64 id_aa64isar2_el1_sys_val;
 u64 id_aa64mmfr0_el1_sys_val;
 u64 id_aa64mmfr1_el1_sys_val;
 u64 id_aa64mmfr2_el1_sys_val;
+u64 id_aa64mmfr3_el1_sys_val;
 u64 id_aa64smfr0_el1_sys_val;
 u64 id_aa64dfr0_el1_sys_val;
 
@@ -83,6 +84,11 @@ static bool vm_has_sve(const struct kvm *kvm)
 	return system_supports_sve() && kvm_vcpu_has_feature(kvm, KVM_ARM_VCPU_SVE);
 }
 
+static bool vm_has_s1poe(const struct kvm *kvm)
+{
+	return system_supports_poe();
+}
+
 /*
  * Definitions for features to be allowed or restricted for protected guests.
  *
@@ -176,6 +182,14 @@ static const struct pvm_ftr_bits pvmid_aa64mmfr2[] = {
 	FEAT_END
 };
 
+static const struct pvm_ftr_bits pvmid_aa64mmfr3[] = {
+	MAX_FEAT(ID_AA64MMFR3_EL1, TCRX, IMP),
+	MAX_FEAT(ID_AA64MMFR3_EL1, SCTLRX, IMP),
+	MAX_FEAT(ID_AA64MMFR3_EL1, S1PIE, IMP),
+	MAX_FEAT_FUNC(ID_AA64MMFR3_EL1, S1POE, IMP, vm_has_s1poe),
+	FEAT_END
+};
+
 static const struct pvm_ftr_bits pvmid_aa64isar1[] = {
 	MAX_FEAT(ID_AA64ISAR1_EL1, DPB, DPB2),
 	MAX_FEAT_FUNC(ID_AA64ISAR1_EL1, APA, PAuth, vm_has_ptrauth),
@@ -273,6 +287,8 @@ static u64 pvm_calc_id_reg(const struct kvm_vcpu *vcpu, u32 id)
 		return get_restricted_features(vcpu, id_aa64mmfr1_el1_sys_val, pvmid_aa64mmfr1);
 	case SYS_ID_AA64MMFR2_EL1:
 		return get_restricted_features(vcpu, id_aa64mmfr2_el1_sys_val, pvmid_aa64mmfr2);
+	case SYS_ID_AA64MMFR3_EL1:
+		return get_restricted_features(vcpu, id_aa64mmfr3_el1_sys_val, pvmid_aa64mmfr3);
 	case SYS_ID_AA64DFR0_EL1:
 		return get_restricted_features(vcpu, id_aa64dfr0_el1_sys_val, pvmid_aa64dfr0);
 	case SYS_ID_AA64MMFR4_EL1:
@@ -706,7 +722,7 @@ static const struct sys_reg_desc pvm_sys_reg_descs[] = {
 	AARCH64(SYS_ID_AA64MMFR0_EL1),
 	AARCH64(SYS_ID_AA64MMFR1_EL1),
 	AARCH64(SYS_ID_AA64MMFR2_EL1),
-	ID_UNALLOCATED(7,3),
+	AARCH64(SYS_ID_AA64MMFR3_EL1),
 	ID_UNALLOCATED(7,4),
 	ID_UNALLOCATED(7,5),
 	ID_UNALLOCATED(7,6),
@@ -792,7 +808,13 @@ static const struct sys_reg_desc_reset pvm_sys_reg_reset_vals[] = {
 	RESET_ZERO(CPACR_EL1),
 	RESET_VAL(CONTEXTIDR_EL1, 0x00000000dbadc0deULL),
 	RESET_VAL(SCTLR_EL1, 0x00C50078ULL),
+	RESET_ZERO(SCTLR2_EL1),
 	RESET_ZERO(TCR_EL1),
+	RESET_ZERO(TCR2_EL1),
+	RESET_UNKNOWN(PIR_EL1),
+	RESET_UNKNOWN(PIRE0_EL1),
+	RESET_UNKNOWN(POR_EL1),
+	RESET_UNKNOWN(POR_EL0),
 	RESET_UNKNOWN(AFSR0_EL1),
 	RESET_UNKNOWN(AFSR1_EL1),
 	RESET_UNKNOWN(ESR_EL1),
Signature · 1 line
2.47.3
author reviewer
#17 lore raw

PATCH v2 13/20 KVM: arm64: Advertise MOPS to protected VMs

In reply to Fuad Tabba

Advertise FEAT_MOPS to protected VMs. With the field set, vcpu_set_hcrx() sets HCRX_EL2.{MSCEn,MCE2} for them, and kvm_hyp_handle_mops() already handles their MOPS exceptions.

---
 arch/arm64/kvm/hyp/nvhe/sys_regs.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/kvm/hyp/nvhe/sys_regs.c +1 -0
index 4f13b100007fa..acba7489809f3 100644
@@ -211,6 +211,7 @@ static const struct pvm_ftr_bits pvmid_aa64isar1[] = {
 static const struct pvm_ftr_bits pvmid_aa64isar2[] = {
 	MAX_FEAT_FUNC(ID_AA64ISAR2_EL1, GPA3, IMP, vm_has_ptrauth),
 	MAX_FEAT_FUNC(ID_AA64ISAR2_EL1, APA3, PAuth, vm_has_ptrauth),
+	MAX_FEAT(ID_AA64ISAR2_EL1, MOPS, IMP),
 	MAX_FEAT(ID_AA64ISAR2_EL1, ATS1A, IMP),
 	FEAT_END
 };
Signature · 1 line
2.47.3
author reviewer
#18 lore raw

PATCH v2 14/20 KVM: arm64: Advertise FPMR to protected VMs

In reply to Fuad Tabba

Advertise FEAT_FPMR to protected VMs, and reset FPMR to 0 as KVM does for a non-protected vCPU. With the field set, vcpu_set_hcrx() sets HCRX_EL2.EnFPM for them, and FPMR is switched with the rest of the FP state.

---
 arch/arm64/kvm/hyp/nvhe/sys_regs.c | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/kvm/hyp/nvhe/sys_regs.c +2 -0
index acba7489809f3..4ba947bd3d125 100644
@@ -127,6 +127,7 @@ static const struct pvm_ftr_bits pvmid_aa64pfr1[] = {
 
 static const struct pvm_ftr_bits pvmid_aa64pfr2[] = {
 	MAX_FEAT(ID_AA64PFR2_EL1, GCIE, NI),
+	MAX_FEAT(ID_AA64PFR2_EL1, FPMR, IMP),
 	FEAT_END
 };
 
@@ -828,6 +829,7 @@ static const struct sys_reg_desc_reset pvm_sys_reg_reset_vals[] = {
 	RESET_UNKNOWN(TTBR1_EL1),
 	RESET_UNKNOWN(FAR_EL1),
 	RESET_VAL(VBAR_EL1, 0x1de7ec7edbadc000ULL),
+	RESET_ZERO(FPMR),
 };
 
 void kvm_reset_pvm_sys_regs(struct kvm_vcpu *vcpu)
Signature · 1 line
2.47.3
author reviewer
#19 lore raw

PATCH v2 15/20 KVM: arm64: Advertise HBC, CLRBHB, RPRFM, CSSC and LUT to protected VMs

In reply to Fuad Tabba

Advertise FEAT_HBC, FEAT_CLRBHB, FEAT_RPRFM, FEAT_CSSC and FEAT_LUT to protected VMs, with CSSC up to CMPBR and LUT up to LUT6, as for a non-protected VM.

---
 arch/arm64/kvm/hyp/nvhe/sys_regs.c | 5 +++++
 1 file changed, 5 insertions(+)
arch/arm64/kvm/hyp/nvhe/sys_regs.c +5 -0
index 4ba947bd3d125..2c22317a76a5e 100644
@@ -213,6 +213,11 @@ static const struct pvm_ftr_bits pvmid_aa64isar2[] = {
 	MAX_FEAT_FUNC(ID_AA64ISAR2_EL1, GPA3, IMP, vm_has_ptrauth),
 	MAX_FEAT_FUNC(ID_AA64ISAR2_EL1, APA3, PAuth, vm_has_ptrauth),
 	MAX_FEAT(ID_AA64ISAR2_EL1, MOPS, IMP),
+	MAX_FEAT(ID_AA64ISAR2_EL1, BC, IMP),
+	MAX_FEAT(ID_AA64ISAR2_EL1, CLRBHB, IMP),
+	MAX_FEAT(ID_AA64ISAR2_EL1, RPRFM, IMP),
+	MAX_FEAT(ID_AA64ISAR2_EL1, CSSC, CMPBR),
+	MAX_FEAT(ID_AA64ISAR2_EL1, LUT, LUT6),
 	MAX_FEAT(ID_AA64ISAR2_EL1, ATS1A, IMP),
 	FEAT_END
 };
Signature · 1 line
2.47.3
author reviewer
#20 lore raw

PATCH v2 16/20 KVM: arm64: Advertise FAMINMAX, LSFE, LSUI and FPRCVT to protected VMs

In reply to Fuad Tabba

Advertise FEAT_FAMINMAX, FEAT_LSFE, FEAT_LSUI and FEAT_FPRCVT to protected VMs, the ID_AA64ISAR3_EL1 fields a non-protected VM sees.

---
 arch/arm64/include/asm/kvm_hyp.h   |  1 +
 arch/arm64/kvm/arm.c               |  1 +
 arch/arm64/kvm/hyp/nvhe/sys_regs.c | 13 ++++++++++++-
 3 files changed, 14 insertions(+), 1 deletion(-)
arch/arm64/include/asm/kvm_hyp.h +1 -0
index ab22b395d0908..fa9a99cae32a7 100644
@@ -148,6 +148,7 @@ extern u64 kvm_nvhe_sym(id_aa64zfr0_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64isar0_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64isar1_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64isar2_el1_sys_val);
+extern u64 kvm_nvhe_sym(id_aa64isar3_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64mmfr0_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64mmfr1_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64mmfr2_el1_sys_val);
arch/arm64/kvm/arm.c +1 -0
index 71afc5a5c9346..e363e8b5958fb 100644
@@ -2837,6 +2837,7 @@ static void kvm_hyp_init_symbols(void)
 	kvm_nvhe_sym(id_aa64isar0_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64ISAR0_EL1);
 	kvm_nvhe_sym(id_aa64isar1_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64ISAR1_EL1);
 	kvm_nvhe_sym(id_aa64isar2_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64ISAR2_EL1);
+	kvm_nvhe_sym(id_aa64isar3_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64ISAR3_EL1);
 	kvm_nvhe_sym(id_aa64mmfr0_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1);
 	kvm_nvhe_sym(id_aa64mmfr1_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1);
 	kvm_nvhe_sym(id_aa64mmfr2_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64MMFR2_EL1);
arch/arm64/kvm/hyp/nvhe/sys_regs.c +12 -1
index 2c22317a76a5e..129a6b89a232d 100644
@@ -27,6 +27,7 @@ u64 id_aa64zfr0_el1_sys_val;
 u64 id_aa64isar0_el1_sys_val;
 u64 id_aa64isar1_el1_sys_val;
 u64 id_aa64isar2_el1_sys_val;
+u64 id_aa64isar3_el1_sys_val;
 u64 id_aa64mmfr0_el1_sys_val;
 u64 id_aa64mmfr1_el1_sys_val;
 u64 id_aa64mmfr2_el1_sys_val;
@@ -222,6 +223,14 @@ static const struct pvm_ftr_bits pvmid_aa64isar2[] = {
 	FEAT_END
 };
 
+static const struct pvm_ftr_bits pvmid_aa64isar3[] = {
+	MAX_FEAT(ID_AA64ISAR3_EL1, FAMINMAX, IMP),
+	MAX_FEAT(ID_AA64ISAR3_EL1, LSFE, IMP),
+	MAX_FEAT(ID_AA64ISAR3_EL1, LSUI, IMP),
+	MAX_FEAT(ID_AA64ISAR3_EL1, FPRCVT, IMP),
+	FEAT_END
+};
+
 /* DoubleLock and MTPMU are hidden, but their Not-Implemented values are non-zero. */
 static const struct pvm_ftr_bits pvmid_aa64dfr0[] = {
 	MAX_FEAT(ID_AA64DFR0_EL1, DebugVer, V8P8),
@@ -288,6 +297,8 @@ static u64 pvm_calc_id_reg(const struct kvm_vcpu *vcpu, u32 id)
 		return get_restricted_features(vcpu, id_aa64isar1_el1_sys_val, pvmid_aa64isar1);
 	case SYS_ID_AA64ISAR2_EL1:
 		return get_restricted_features(vcpu, id_aa64isar2_el1_sys_val, pvmid_aa64isar2);
+	case SYS_ID_AA64ISAR3_EL1:
+		return get_restricted_features(vcpu, id_aa64isar3_el1_sys_val, pvmid_aa64isar3);
 	case SYS_ID_AA64MMFR0_EL1:
 		return get_restricted_features(vcpu, id_aa64mmfr0_el1_sys_val, pvmid_aa64mmfr0);
 	case SYS_ID_AA64MMFR1_EL1:
@@ -721,7 +732,7 @@ static const struct sys_reg_desc pvm_sys_reg_descs[] = {
 	AARCH64(SYS_ID_AA64ISAR0_EL1),
 	AARCH64(SYS_ID_AA64ISAR1_EL1),
 	AARCH64(SYS_ID_AA64ISAR2_EL1),
-	ID_UNALLOCATED(6,3),
+	AARCH64(SYS_ID_AA64ISAR3_EL1),
 	ID_UNALLOCATED(6,4),
 	ID_UNALLOCATED(6,5),
 	ID_UNALLOCATED(6,6),
Signature · 1 line
2.47.3
author reviewer
#21 lore raw

PATCH v2 17/20 KVM: arm64: Advertise AFP and RPRES to protected VMs

In reply to Fuad Tabba

Advertise FEAT_AFP and FEAT_RPRES to protected VMs. Both are controlled through FPCR, which EL2 switches with the rest of the FP state.

---
 arch/arm64/kvm/hyp/nvhe/sys_regs.c | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/kvm/hyp/nvhe/sys_regs.c +2 -0
index 129a6b89a232d..fdf405629dfd3 100644
@@ -168,6 +168,7 @@ static const struct pvm_ftr_bits pvmid_aa64mmfr1[] = {
 	MAX_FEAT(ID_AA64MMFR1_EL1, PAN, PAN3),
 	MAX_FEAT(ID_AA64MMFR1_EL1, SpecSEI, IMP),
 	MAX_FEAT(ID_AA64MMFR1_EL1, ETS, IMP),
+	MAX_FEAT(ID_AA64MMFR1_EL1, AFP, IMP),
 	MAX_FEAT(ID_AA64MMFR1_EL1, CMOW, IMP),
 	FEAT_END
 };
@@ -211,6 +212,7 @@ static const struct pvm_ftr_bits pvmid_aa64isar1[] = {
 };
 
 static const struct pvm_ftr_bits pvmid_aa64isar2[] = {
+	MAX_FEAT(ID_AA64ISAR2_EL1, RPRES, IMP),
 	MAX_FEAT_FUNC(ID_AA64ISAR2_EL1, GPA3, IMP, vm_has_ptrauth),
 	MAX_FEAT_FUNC(ID_AA64ISAR2_EL1, APA3, PAuth, vm_has_ptrauth),
 	MAX_FEAT(ID_AA64ISAR2_EL1, MOPS, IMP),
Signature · 1 line
2.47.3
author reviewer
#22 lore raw

PATCH v2 18/20 KVM: arm64: Advertise ECBHB, TIDCP1, TTST and LVA to protected VMs

In reply to Fuad Tabba

Advertise FEAT_ECBHB, FEAT_TIDCP1, FEAT_TTST and FEAT_LVA to protected VMs, capping VARange at LVA, since LVA3 requires FEAT_D128. TIDCP1's control, SCTLR_EL1.TIDCP, is switched with the rest of SCTLR_EL1.

---
 arch/arm64/kvm/hyp/nvhe/sys_regs.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm64/kvm/hyp/nvhe/sys_regs.c +4 -0
index fdf405629dfd3..dc7c70ac46f2a 100644
@@ -169,7 +169,9 @@ static const struct pvm_ftr_bits pvmid_aa64mmfr1[] = {
 	MAX_FEAT(ID_AA64MMFR1_EL1, SpecSEI, IMP),
 	MAX_FEAT(ID_AA64MMFR1_EL1, ETS, IMP),
 	MAX_FEAT(ID_AA64MMFR1_EL1, AFP, IMP),
+	MAX_FEAT(ID_AA64MMFR1_EL1, TIDCP1, IMP),
 	MAX_FEAT(ID_AA64MMFR1_EL1, CMOW, IMP),
+	MAX_FEAT(ID_AA64MMFR1_EL1, ECBHB, IMP),
 	FEAT_END
 };
 
@@ -177,6 +179,8 @@ static const struct pvm_ftr_bits pvmid_aa64mmfr2[] = {
 	MAX_FEAT(ID_AA64MMFR2_EL1, CnP, IMP),
 	MAX_FEAT(ID_AA64MMFR2_EL1, UAO, IMP),
 	MAX_FEAT(ID_AA64MMFR2_EL1, IESB, IMP),
+	MAX_FEAT(ID_AA64MMFR2_EL1, VARange, 52),
+	MAX_FEAT_ENUM(ID_AA64MMFR2_EL1, ST, 48_47),
 	MAX_FEAT(ID_AA64MMFR2_EL1, AT, IMP),
 	MAX_FEAT(ID_AA64MMFR2_EL1, IDS, IMP),
 	MAX_FEAT(ID_AA64MMFR2_EL1, TTL, IMP),
Signature · 1 line
2.47.3
author reviewer
#23 lore raw

PATCH v2 19/20 KVM: arm64: Advertise FP8 and F16MM to protected VMs

In reply to Fuad Tabba

Advertise the FP8 features and FEAT_F16MM to protected VMs, the ID_AA64FPFR0_EL1 fields a non-protected VM sees. Their instructions only use the SIMD&FP registers and FPMR, which EL2 already switches.

---
 arch/arm64/include/asm/kvm_hyp.h   |  1 +
 arch/arm64/kvm/arm.c               |  1 +
 arch/arm64/kvm/hyp/nvhe/sys_regs.c | 18 +++++++++++++++++-
 3 files changed, 19 insertions(+), 1 deletion(-)
arch/arm64/include/asm/kvm_hyp.h +1 -0
index fa9a99cae32a7..09b19f2c3c090 100644
@@ -145,6 +145,7 @@ extern u64 kvm_nvhe_sym(id_aa64pfr0_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64pfr1_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64pfr2_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64zfr0_el1_sys_val);
+extern u64 kvm_nvhe_sym(id_aa64fpfr0_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64isar0_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64isar1_el1_sys_val);
 extern u64 kvm_nvhe_sym(id_aa64isar2_el1_sys_val);
arch/arm64/kvm/arm.c +1 -0
index e363e8b5958fb..5dbe66de4f05e 100644
@@ -2834,6 +2834,7 @@ static void kvm_hyp_init_symbols(void)
 	kvm_nvhe_sym(id_aa64pfr1_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64PFR1_EL1);
 	kvm_nvhe_sym(id_aa64pfr2_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64PFR2_EL1);
 	kvm_nvhe_sym(id_aa64zfr0_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64ZFR0_EL1);
+	kvm_nvhe_sym(id_aa64fpfr0_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64FPFR0_EL1);
 	kvm_nvhe_sym(id_aa64isar0_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64ISAR0_EL1);
 	kvm_nvhe_sym(id_aa64isar1_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64ISAR1_EL1);
 	kvm_nvhe_sym(id_aa64isar2_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64ISAR2_EL1);
arch/arm64/kvm/hyp/nvhe/sys_regs.c +17 -1
index dc7c70ac46f2a..4b95128663aa8 100644
@@ -24,6 +24,7 @@ u64 id_aa64pfr0_el1_sys_val;
 u64 id_aa64pfr1_el1_sys_val;
 u64 id_aa64pfr2_el1_sys_val;
 u64 id_aa64zfr0_el1_sys_val;
+u64 id_aa64fpfr0_el1_sys_val;
 u64 id_aa64isar0_el1_sys_val;
 u64 id_aa64isar1_el1_sys_val;
 u64 id_aa64isar2_el1_sys_val;
@@ -148,6 +149,19 @@ static const struct pvm_ftr_bits pvmid_aa64zfr0[] = {
 	FEAT_END
 };
 
+static const struct pvm_ftr_bits pvmid_aa64fpfr0[] = {
+	MAX_FEAT(ID_AA64FPFR0_EL1, F8E5M2, IMP),
+	MAX_FEAT(ID_AA64FPFR0_EL1, F8E4M3, IMP),
+	MAX_FEAT(ID_AA64FPFR0_EL1, F16MM2, IMP),
+	MAX_FEAT(ID_AA64FPFR0_EL1, F8MM4, IMP),
+	MAX_FEAT(ID_AA64FPFR0_EL1, F8MM8, IMP),
+	MAX_FEAT(ID_AA64FPFR0_EL1, F8DP2, IMP),
+	MAX_FEAT(ID_AA64FPFR0_EL1, F8DP4, IMP),
+	MAX_FEAT(ID_AA64FPFR0_EL1, F8FMA, IMP),
+	MAX_FEAT(ID_AA64FPFR0_EL1, F8CVT, IMP),
+	FEAT_END
+};
+
 static const struct pvm_ftr_bits pvmid_aa64mmfr0[] = {
 	MAX_FEAT_ENUM(ID_AA64MMFR0_EL1, PARANGE, 40),
 	MAX_FEAT_ENUM(ID_AA64MMFR0_EL1, ASIDBITS, 16),
@@ -297,6 +311,8 @@ static u64 pvm_calc_id_reg(const struct kvm_vcpu *vcpu, u32 id)
 		return get_restricted_features(vcpu, id_aa64pfr2_el1_sys_val, pvmid_aa64pfr2);
 	case SYS_ID_AA64ZFR0_EL1:
 		return get_restricted_features(vcpu, id_aa64zfr0_el1_sys_val, pvmid_aa64zfr0);
+	case SYS_ID_AA64FPFR0_EL1:
+		return get_restricted_features(vcpu, id_aa64fpfr0_el1_sys_val, pvmid_aa64fpfr0);
 	case SYS_ID_AA64ISAR0_EL1:
 		return id_aa64isar0_el1_sys_val;
 	case SYS_ID_AA64ISAR1_EL1:
@@ -726,7 +742,7 @@ static const struct sys_reg_desc pvm_sys_reg_descs[] = {
 	AARCH64(SYS_ID_AA64ZFR0_EL1),
 	ID_UNALLOCATED(4,5),
 	ID_UNALLOCATED(4,6),
-	ID_UNALLOCATED(4,7),
+	AARCH64(SYS_ID_AA64FPFR0_EL1),
 	AARCH64(SYS_ID_AA64DFR0_EL1),
 	AARCH64(SYS_ID_AA64DFR1_EL1),
 	ID_UNALLOCATED(5,2),
Signature · 1 line
2.47.3
author reviewer
#24 lore raw

PATCH v2 20/20 KVM: arm64: Advertise ECV, HAFT and ETS3 to protected VMs

In reply to Fuad Tabba

Advertise FEAT_ECV, FEAT_HAFT and FEAT_ETS3 to protected VMs, with ECV capped at IMP and HAFDBS at HAFT, since CNTPOFF and HDBSS only add EL2 and EL3 controls. ECV's self-synchronised counter views trap under the same controls as CNTPCT_EL0 and CNTVCT_EL0, which kvm_handle_cntxct() emulates.

---
 arch/arm64/kvm/hyp/nvhe/sys_regs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/kvm/hyp/nvhe/sys_regs.c +3 -2
index 4b95128663aa8..770ba0bb0a400 100644
@@ -172,16 +172,17 @@ static const struct pvm_ftr_bits pvmid_aa64mmfr0[] = {
 	MAX_FEAT(ID_AA64MMFR0_EL1, TGRAN4, IMP),
 	MAX_FEAT(ID_AA64MMFR0_EL1, TGRAN16, IMP),
 	MAX_FEAT(ID_AA64MMFR0_EL1, TGRAN64, IMP),
+	MAX_FEAT(ID_AA64MMFR0_EL1, ECV, IMP),
 	FEAT_END
 };
 
 static const struct pvm_ftr_bits pvmid_aa64mmfr1[] = {
-	MAX_FEAT(ID_AA64MMFR1_EL1, HAFDBS, DBM),
+	MAX_FEAT(ID_AA64MMFR1_EL1, HAFDBS, HAFT),
 	MAX_FEAT_ENUM(ID_AA64MMFR1_EL1, VMIDBits, 16),
 	MAX_FEAT(ID_AA64MMFR1_EL1, HPDS, HPDS2),
 	MAX_FEAT(ID_AA64MMFR1_EL1, PAN, PAN3),
 	MAX_FEAT(ID_AA64MMFR1_EL1, SpecSEI, IMP),
-	MAX_FEAT(ID_AA64MMFR1_EL1, ETS, IMP),
+	MAX_FEAT(ID_AA64MMFR1_EL1, ETS, ETS3),
 	MAX_FEAT(ID_AA64MMFR1_EL1, AFP, IMP),
 	MAX_FEAT(ID_AA64MMFR1_EL1, TIDCP1, IMP),
 	MAX_FEAT(ID_AA64MMFR1_EL1, CMOW, IMP),
Signature · 1 line
2.47.3