Skip to contentSkip to conversation

KVM: arm64: FEAT_RASv1p1 support and RAS selection

PATCH Superseded Marc Zyngier 4 participants 13 messages Aug 6, 2025 – Aug 12, 2025

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Marc Zyngier

author maintainer
#0 lore raw

v2 cover KVM: arm64: FEAT_RASv1p1 support and RAS selection

This is the next iteration of this series trying to plug some of our RAS holes (no pun intended...). See [1] for the original series.

Patches on top of kvmarm-6.17.

* From v1 [1]:

- Bunch of patches picked by Oliver (thanks!)

- Added missing SYS_ERXMISC{2,3}_EL1 from the list of handled RAS registers

- Added some rationale about the advertising of RASv1p1 (Cornelia)

- Picked AB from Catalin (thanks!)

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

Marc Zyngier (5):
arm64: Add capability denoting FEAT_RASv1p1
KVM: arm64: Handle RASv1p1 registers
KVM: arm64: Ignore HCR_EL2.FIEN set by L1 guest's EL2
KVM: arm64: Expose FEAT_RASv1p1 in a canonical manner
KVM: arm64: Make ID_AA64PFR0_EL1.RAS writable

 arch/arm64/kernel/cpufeature.c  | 24 ++++++++++++++++++++++++
 arch/arm64/kvm/hyp/vhe/switch.c |  5 ++++-
 arch/arm64/kvm/sys_regs.c       | 30 +++++++++++++++++++++++++++++-
 arch/arm64/tools/cpucaps        |  1 +
 4 files changed, 58 insertions(+), 2 deletions(-)
Signature · 1 line
2.39.2
author maintainer
#1 lore raw

PATCH v2 1/5 arm64: Add capability denoting FEAT_RASv1p1

Detecting FEAT_RASv1p1 is rather complicated, as there are two ways for the architecture to advertise the same thing (always a delight...).

Add a capability that will advertise this in a synthetic way to the rest of the kernel.

---
 arch/arm64/kernel/cpufeature.c | 24 ++++++++++++++++++++++++
 arch/arm64/tools/cpucaps       |  1 +
 2 files changed, 25 insertions(+)
arch/arm64/kernel/cpufeature.c +24 -0
index 4dece9ca68bc6..22a94e548362d 100644
@@ -2235,6 +2235,24 @@ static void cpu_clear_disr(const struct arm64_cpu_capabilities *__unused)
 	/* Firmware may have left a deferred SError in this register. */
 	write_sysreg_s(0, SYS_DISR_EL1);
 }
+static bool has_rasv1p1(const struct arm64_cpu_capabilities *__unused, int scope)
+{
+	const struct arm64_cpu_capabilities rasv1p1_caps[] = {
+		{
+			ARM64_CPUID_FIELDS(ID_AA64PFR0_EL1, RAS, V1P1)
+		},
+		{
+			ARM64_CPUID_FIELDS(ID_AA64PFR0_EL1, RAS, IMP)
+		},
+		{
+			ARM64_CPUID_FIELDS(ID_AA64PFR1_EL1, RAS_frac, RASv1p1)
+		},
+	};
+
+	return (has_cpuid_feature(&rasv1p1_caps[0], scope) ||
+		(has_cpuid_feature(&rasv1p1_caps[1], scope) &&
+		 has_cpuid_feature(&rasv1p1_caps[2], scope)));
+}
 #endif /* CONFIG_ARM64_RAS_EXTN */
 
 #ifdef CONFIG_ARM64_PTR_AUTH
@@ -2653,6 +2671,12 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
 		.cpu_enable = cpu_clear_disr,
 		ARM64_CPUID_FIELDS(ID_AA64PFR0_EL1, RAS, IMP)
 	},
+	{
+		.desc = "RASv1p1 Extension Support",
+		.capability = ARM64_HAS_RASV1P1_EXTN,
+		.type = ARM64_CPUCAP_SYSTEM_FEATURE,
+		.matches = has_rasv1p1,
+	},
 #endif /* CONFIG_ARM64_RAS_EXTN */
 #ifdef CONFIG_ARM64_AMU_EXTN
 	{
arch/arm64/tools/cpucaps +1 -0
index 115161dd9a24d..eb7f1f5622a8f 100644
@@ -52,6 +52,7 @@ HAS_S1PIE
 HAS_S1POE
 HAS_SCTLR2
 HAS_RAS_EXTN
+HAS_RASV1P1_EXTN
 HAS_RNG
 HAS_SB
 HAS_STAGE2_FWB
Signature · 1 line
2.39.2
author maintainer
#2 lore raw

PATCH v2 2/5 KVM: arm64: Handle RASv1p1 registers

In reply to Marc Zyngier

FEAT_RASv1p1 system registeres are not handled at all so far. KVM will give an embarassed warning on the console and inject an UNDEF, despite RASv1p1 being exposed to the guest on suitable HW.

Handle these registers similarly to FEAT_RAS, with the added fun that there are *two* way to indicate the presence of FEAT_RASv1p1.

---
 arch/arm64/kvm/sys_regs.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
arch/arm64/kvm/sys_regs.c +17 -0
index ad25484772574..1b4114790024e 100644
@@ -2695,6 +2695,18 @@ static bool access_ras(struct kvm_vcpu *vcpu,
 	struct kvm *kvm = vcpu->kvm;
 
 	switch(reg_to_encoding(r)) {
+	case SYS_ERXPFGCDN_EL1:
+	case SYS_ERXPFGCTL_EL1:
+	case SYS_ERXPFGF_EL1:
+	case SYS_ERXMISC2_EL1:
+	case SYS_ERXMISC3_EL1:
+		if (!(kvm_has_feat(kvm, ID_AA64PFR0_EL1, RAS, V1P1) ||
+		      (kvm_has_feat_enum(kvm, ID_AA64PFR0_EL1, RAS, IMP) &&
+		       kvm_has_feat(kvm, ID_AA64PFR1_EL1, RAS_frac, RASv1p1)))) {
+			kvm_inject_undefined(vcpu);
+			return false;
+		}
+		break;
 	default:
 		if (!kvm_has_feat(kvm, ID_AA64PFR0_EL1, RAS, IMP)) {
 			kvm_inject_undefined(vcpu);
@@ -3058,8 +3070,13 @@ static const struct sys_reg_desc sys_reg_descs[] = {
 	{ SYS_DESC(SYS_ERXCTLR_EL1), access_ras },
 	{ SYS_DESC(SYS_ERXSTATUS_EL1), access_ras },
 	{ SYS_DESC(SYS_ERXADDR_EL1), access_ras },
+	{ SYS_DESC(SYS_ERXPFGF_EL1), access_ras },
+	{ SYS_DESC(SYS_ERXPFGCTL_EL1), access_ras },
+	{ SYS_DESC(SYS_ERXPFGCDN_EL1), access_ras },
 	{ SYS_DESC(SYS_ERXMISC0_EL1), access_ras },
 	{ SYS_DESC(SYS_ERXMISC1_EL1), access_ras },
+	{ SYS_DESC(SYS_ERXMISC2_EL1), access_ras },
+	{ SYS_DESC(SYS_ERXMISC3_EL1), access_ras },
 
 	MTE_REG(TFSR_EL1),
 	MTE_REG(TFSRE0_EL1),
Signature · 1 line
2.39.2
reviewer Reviewed-by on v2 2/5
#3 lore raw

Re: [PATCH v2 2/5] KVM: arm64: Handle RASv1p1 registers

Hi!

Quoted 1 line · Marc Zyngier

FEAT_RASv1p1 system registeres are not handled at all so far.

*registers

Quoted 1 line

KVM will give an embarassed warning on the console and inject

*embarrassed

Quoted 6 lines

an UNDEF, despite RASv1p1 being exposed to the guest on suitable HW.

Handle these registers similarly to FEAT_RAS, with the added fun that there are *two* way to indicate the presence of FEAT_RASv1p1.

Quoted 44 lines
---
 arch/arm64/kvm/sys_regs.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
arch/arm64/kvm/sys_regs.c +17 -0
index ad25484772574..1b4114790024e 100644
@@ -2695,6 +2695,18 @@ static bool access_ras(struct kvm_vcpu *vcpu,
 	struct kvm *kvm = vcpu->kvm;
 
 	switch(reg_to_encoding(r)) {
+	case SYS_ERXPFGCDN_EL1:
+	case SYS_ERXPFGCTL_EL1:
+	case SYS_ERXPFGF_EL1:
+	case SYS_ERXMISC2_EL1:
+	case SYS_ERXMISC3_EL1:
+		if (!(kvm_has_feat(kvm, ID_AA64PFR0_EL1, RAS, V1P1) ||
+		      (kvm_has_feat_enum(kvm, ID_AA64PFR0_EL1, RAS, IMP) &&
+		       kvm_has_feat(kvm, ID_AA64PFR1_EL1, RAS_frac, RASv1p1)))) {
+			kvm_inject_undefined(vcpu);
+			return false;
+		}
+		break;
 	default:
 		if (!kvm_has_feat(kvm, ID_AA64PFR0_EL1, RAS, IMP)) {
 			kvm_inject_undefined(vcpu);
@@ -3058,8 +3070,13 @@ static const struct sys_reg_desc sys_reg_descs[] = {
 	{ SYS_DESC(SYS_ERXCTLR_EL1), access_ras },
 	{ SYS_DESC(SYS_ERXSTATUS_EL1), access_ras },
 	{ SYS_DESC(SYS_ERXADDR_EL1), access_ras },
+	{ SYS_DESC(SYS_ERXPFGF_EL1), access_ras },
+	{ SYS_DESC(SYS_ERXPFGCTL_EL1), access_ras },
+	{ SYS_DESC(SYS_ERXPFGCDN_EL1), access_ras },
 	{ SYS_DESC(SYS_ERXMISC0_EL1), access_ras },
 	{ SYS_DESC(SYS_ERXMISC1_EL1), access_ras },
+	{ SYS_DESC(SYS_ERXMISC2_EL1), access_ras },
+	{ SYS_DESC(SYS_ERXMISC3_EL1), access_ras },
 
 	MTE_REG(TFSR_EL1),
 	MTE_REG(TFSRE0_EL1),
Signature · 1 line
2.39.2
author maintainer
#4 lore raw

PATCH v2 3/5 KVM: arm64: Ignore HCR_EL2.FIEN set by L1 guest's EL2

In reply to Marc Zyngier

An EL2 guest can set HCR_EL2.FIEN, which gives access to the RASv1p1 fault injection mechanism. This would allow an EL1 guest to inject error records into the system, which does sound like a terrible idea.

Prevent this situation by added FIEN to the list of bits we silently exclude from being inserted into the host configuration.

---
 arch/arm64/kvm/hyp/vhe/switch.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/vhe/switch.c +4 -1
index e482181c66322..0998ad4a25524 100644
@@ -43,8 +43,11 @@ DEFINE_PER_CPU(unsigned long, kvm_hyp_vector);
  *
  * - API/APK: they are already accounted for by vcpu_load(), and can
  *   only take effect across a load/put cycle (such as ERET)
+ *
+ * - FIEN: no way we let a guest have access to the RAS "Common Fault
+ *   Injection" thing, whatever that does
  */
-#define NV_HCR_GUEST_EXCLUDE	(HCR_TGE | HCR_API | HCR_APK)
+#define NV_HCR_GUEST_EXCLUDE	(HCR_TGE | HCR_API | HCR_APK | HCR_FIEN)
 
 static u64 __compute_hcr(struct kvm_vcpu *vcpu)
 {
Signature · 1 line
2.39.2
author maintainer
#5 lore raw

PATCH v2 4/5 KVM: arm64: Expose FEAT_RASv1p1 in a canonical manner

In reply to Marc Zyngier

If we have RASv1p1 on the host, advertise it to the guest in the "canonical way", by setting ID_AA64PFR0_EL1 to V1P1, rather than the convoluted RAS+RAS_frac method.

Note that this also advertises FEAT_DoubleFault, which doesn't affect the guest at all, as only EL3 is concerned by this.

---
 arch/arm64/kvm/sys_regs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/arm64/kvm/sys_regs.c +12 -0
index 1b4114790024e..66e5a733e9628 100644
@@ -1800,6 +1800,18 @@ static u64 sanitise_id_aa64pfr0_el1(const struct kvm_vcpu *vcpu, u64 val)
 	if (!vcpu_has_sve(vcpu))
 		val &= ~ID_AA64PFR0_EL1_SVE_MASK;
 
+	/*
+	 * Describe RASv1p1 in a canonical way -- ID_AA64PFR1_EL1.RAS_frac
+	 * is cleared separately. Note that by advertising RASv1p1 here, we
+	 * implicitly advertise FEAT_DoubleFault. However, since that last
+	 * feature is a pure EL3 feature, this is not relevant for the
+	 * guest, and we save on the complexity.
+	 */
+	if (cpus_have_final_cap(ARM64_HAS_RASV1P1_EXTN)) {
+		val &= ~ID_AA64PFR0_EL1_RAS;
+		val |= SYS_FIELD_PREP_ENUM(ID_AA64PFR0_EL1, RAS, V1P1);
+	}
+
 	/*
 	 * The default is to expose CSV2 == 1 if the HW isn't affected.
 	 * Although this is a per-CPU feature, we make it global because
Signature · 1 line
2.39.2
reviewer
#6 lore raw

Re: [PATCH v2 4/5] KVM: arm64: Expose FEAT_RASv1p1 in a canonical manner

Quoted 17 lines · Marc Zyngier

If we have RASv1p1 on the host, advertise it to the guest in the "canonical way", by setting ID_AA64PFR0_EL1 to V1P1, rather than the convoluted RAS+RAS_frac method.

Note that this also advertises FEAT_DoubleFault, which doesn't affect the guest at all, as only EL3 is concerned by this.

---
 arch/arm64/kvm/sys_regs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/arm64/kvm/sys_regs.c +0 -0
index 1b4114790024e..66e5a733e9628 100644

arch/arm64/kvm/sys_regs.c static u64 sanitise_id_aa64pfr0_el1(const struct kvm_vcpu *vcpu, u64 val) · line 1805

Quoted 6 lines
arch/arm64/kvm/sys_regs.c +3 -0
@@ -1800,6 +1800,18 @@ static u64 sanitise_id_aa64pfr0_el1(const struct kvm_vcpu *vcpu, u64 val)
 	if (!vcpu_has_sve(vcpu))
 		val &= ~ID_AA64PFR0_EL1_SVE_MASK;
 
+	/*
+	 * Describe RASv1p1 in a canonical way -- ID_AA64PFR1_EL1.RAS_frac
+	 * is cleared separately. Note that by advertising RASv1p1 here, we

Where is it cleared? __kvm_read_sanitised_id_reg() is where I would have expected to see it:

    case SYS_ID_AA64PFR1_EL1:                                                                                                                                                                  
        if (!kvm_has_mte(vcpu->kvm)) {                                                                                                                                                         
            val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_MTE);                                                                                                                                   
            val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_MTE_frac);                                                                                                                              
        }                                                                                                                                                                                      
                                                                                                                                                                                               
        val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_SME);                                                                                                                                       
        val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_RNDR_trap);                                                                                                                                 
        val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_NMI);                                                                                                                                       
        val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_GCS);                                                                                                                                       
        val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_THE);                                                                                                                                       
        val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_MTEX);                                                                                                                                      
        val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_PFAR);                                                                                                                                      
        val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_MPAM_frac);                                                                                                                                 
        break;                                                                  
Quoted 15 lines
arch/arm64/kvm/sys_regs.c +9 -0
+	 * implicitly advertise FEAT_DoubleFault. However, since that last
+	 * feature is a pure EL3 feature, this is not relevant for the
+	 * guest, and we save on the complexity.
+	 */
+	if (cpus_have_final_cap(ARM64_HAS_RASV1P1_EXTN)) {
+		val &= ~ID_AA64PFR0_EL1_RAS;
+		val |= SYS_FIELD_PREP_ENUM(ID_AA64PFR0_EL1, RAS, V1P1);
+	}
+
 	/*
 	 * The default is to expose CSV2 == 1 if the HW isn't affected.
 	 * Although this is a per-CPU feature, we make it global because
Signature · 1 line
2.39.2
#7 lore raw

Re: [PATCH v2 4/5] KVM: arm64: Expose FEAT_RASv1p1 in a canonical manner

Quoted 21 lines · Joey Gouly
Quoted 20 lines · Marc Zyngier

If we have RASv1p1 on the host, advertise it to the guest in the "canonical way", by setting ID_AA64PFR0_EL1 to V1P1, rather than the convoluted RAS+RAS_frac method.

Note that this also advertises FEAT_DoubleFault, which doesn't affect the guest at all, as only EL3 is concerned by this.

---
 arch/arm64/kvm/sys_regs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/arm64/kvm/sys_regs.c +0 -0
index 1b4114790024e..66e5a733e9628 100644
@@ -1800,6 +1800,18 @@ static u64 sanitise_id_aa64pfr0_el1(const struct kvm_vcpu *vcpu, u64 val)
 	if (!vcpu_has_sve(vcpu))
 		val &= ~ID_AA64PFR0_EL1_SVE_MASK;
 
Quoted 6 lines

arch/arm64/kvm/sys_regs.c static u64 sanitise_id_aa64pfr0_el1(const struct kvm_vcpu *vcpu, u64 val) · line 1805

Quoted 3 lines
arch/arm64/kvm/sys_regs.c +3 -0
+	/*
+	 * Describe RASv1p1 in a canonical way -- ID_AA64PFR1_EL1.RAS_frac
+	 * is cleared separately. Note that by advertising RASv1p1 here, we

Where is it cleared? __kvm_read_sanitised_id_reg() is where I would have expected to see it:

Actually, I'm a bit worried this change doesn't give us very much value since Marc already does the exhaustive RASv1p1 check in the sysreg emulation.

There's potential for breakage when migrating VMs between new/old kernels on systems w/ FEAT_RASv1p1 && !FEAT_DoubleFault.

Marc, WDYT about dropping this patch and instead opening up RAS_frac to writes?

Thanks,
Oliver

author maintainer
#8 lore raw

Re: [PATCH v2 4/5] KVM: arm64: Expose FEAT_RASv1p1 in a canonical manner

Quoted 34 lines · Oliver Upton
Quoted 21 lines · Joey Gouly
Quoted 20 lines · Marc Zyngier

If we have RASv1p1 on the host, advertise it to the guest in the "canonical way", by setting ID_AA64PFR0_EL1 to V1P1, rather than the convoluted RAS+RAS_frac method.

Note that this also advertises FEAT_DoubleFault, which doesn't affect the guest at all, as only EL3 is concerned by this.

---
 arch/arm64/kvm/sys_regs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/arm64/kvm/sys_regs.c +0 -0
index 1b4114790024e..66e5a733e9628 100644
@@ -1800,6 +1800,18 @@ static u64 sanitise_id_aa64pfr0_el1(const struct kvm_vcpu *vcpu, u64 val)
 	if (!vcpu_has_sve(vcpu))
 		val &= ~ID_AA64PFR0_EL1_SVE_MASK;
 
Quoted 6 lines

arch/arm64/kvm/sys_regs.c static u64 sanitise_id_aa64pfr0_el1(const struct kvm_vcpu *vcpu, u64 val) · line 1805

Quoted 3 lines
arch/arm64/kvm/sys_regs.c +3 -0
+	/*
+	 * Describe RASv1p1 in a canonical way -- ID_AA64PFR1_EL1.RAS_frac
+	 * is cleared separately. Note that by advertising RASv1p1 here, we

Where is it cleared? __kvm_read_sanitised_id_reg() is where I would have expected to see it:

Actually, I'm a bit worried this change doesn't give us very much value since Marc already does the exhaustive RASv1p1 check in the sysreg emulation.

Quoted 5 lines

There's potential for breakage when migrating VMs between new/old kernels on systems w/ FEAT_RASv1p1 && !FEAT_DoubleFault.

Marc, WDYT about dropping this patch and instead opening up RAS_frac to writes?

That's indeed probably best. But the question I can't manage to answer right now is how we migrate RASv1p1 between the two versions? It means cross-idreg dependencies, ordering and all that, and I'm a bit reluctant to do so.

Thoughts?

	M.
Signature · 1 line
Jazz isn't dead. It just smells funny.
#9 lore raw

Re: [PATCH v2 4/5] KVM: arm64: Expose FEAT_RASv1p1 in a canonical manner

Quoted 39 lines · Marc Zyngier
Quoted 37 lines · Oliver Upton
Quoted 21 lines · Joey Gouly
Quoted 20 lines · Marc Zyngier

If we have RASv1p1 on the host, advertise it to the guest in the "canonical way", by setting ID_AA64PFR0_EL1 to V1P1, rather than the convoluted RAS+RAS_frac method.

Note that this also advertises FEAT_DoubleFault, which doesn't affect the guest at all, as only EL3 is concerned by this.

---
 arch/arm64/kvm/sys_regs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/arm64/kvm/sys_regs.c +0 -0
index 1b4114790024e..66e5a733e9628 100644
@@ -1800,6 +1800,18 @@ static u64 sanitise_id_aa64pfr0_el1(const struct kvm_vcpu *vcpu, u64 val)
 	if (!vcpu_has_sve(vcpu))
 		val &= ~ID_AA64PFR0_EL1_SVE_MASK;
 
Quoted 6 lines

arch/arm64/kvm/sys_regs.c static u64 sanitise_id_aa64pfr0_el1(const struct kvm_vcpu *vcpu, u64 val) · line 1805

Quoted 3 lines
arch/arm64/kvm/sys_regs.c +3 -0
+	/*
+	 * Describe RASv1p1 in a canonical way -- ID_AA64PFR1_EL1.RAS_frac
+	 * is cleared separately. Note that by advertising RASv1p1 here, we

Where is it cleared? __kvm_read_sanitised_id_reg() is where I would have expected to see it:

Actually, I'm a bit worried this change doesn't give us very much value since Marc already does the exhaustive RASv1p1 check in the sysreg emulation.

There's potential for breakage when migrating VMs between new/old kernels on systems w/ FEAT_RASv1p1 && !FEAT_DoubleFault.

Quoted 7 lines
Quoted 2 lines

Marc, WDYT about dropping this patch and instead opening up RAS_frac to writes?

That's indeed probably best. But the question I can't manage to answer right now is how we migrate RASv1p1 between the two versions? It means cross-idreg dependencies, ordering and all that, and I'm a bit reluctant to do so.

Adding our offline conversation to the list in case folks have any concerns.

Next steps here are to allow the RAS_frac mechanism for RASv1p1 only on RASv1p1 machines (to protect against turds like a potential RASv2p1) and allow the user to de-feature the RAS_frac field.

A VMM that wants to migrate cross-implementation (with mixed support for FEAT_DoubleFault) will need to compute the intersection of CPU features and decide it needs to de-feature FEAT_RASv1p1 anyway (RAS = 0x1, RAS_frac = 0x0) so the canonicalization isn't that big of a deal.

Thanks,
Oliver

author maintainer
#10 lore raw

Re: [PATCH v2 4/5] KVM: arm64: Expose FEAT_RASv1p1 in a canonical manner

In reply to Joey Gouly
Quoted 22 lines · Joey Gouly
Quoted 20 lines · Marc Zyngier

If we have RASv1p1 on the host, advertise it to the guest in the "canonical way", by setting ID_AA64PFR0_EL1 to V1P1, rather than the convoluted RAS+RAS_frac method.

Note that this also advertises FEAT_DoubleFault, which doesn't affect the guest at all, as only EL3 is concerned by this.

---
 arch/arm64/kvm/sys_regs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/arm64/kvm/sys_regs.c +0 -0
index 1b4114790024e..66e5a733e9628 100644
@@ -1800,6 +1800,18 @@ static u64 sanitise_id_aa64pfr0_el1(const struct kvm_vcpu *vcpu, u64 val)
 	if (!vcpu_has_sve(vcpu))
 		val &= ~ID_AA64PFR0_EL1_SVE_MASK;
 
Quoted 8 lines

arch/arm64/kvm/sys_regs.c static u64 sanitise_id_aa64pfr0_el1(const struct kvm_vcpu *vcpu, u64 val) · line 1805

Quoted 3 lines
arch/arm64/kvm/sys_regs.c +3 -0
+	/*
+	 * Describe RASv1p1 in a canonical way -- ID_AA64PFR1_EL1.RAS_frac
+	 * is cleared separately. Note that by advertising RASv1p1 here, we

Where is it cleared? __kvm_read_sanitised_id_reg() is where I would have expected to see it:

    case SYS_ID_AA64PFR1_EL1:

[...]

Ah crap, it is the nested code that we get rid of it, nowhere else. Which means that non-nested VMs have already observed RAS_frac. What a mess. Then RAS_frac must be exposed as writable.

The question is whether we want to allow migration between one flavour of RASv1p1 and the other.

	M.
Signature · 1 line
Jazz isn't dead. It just smells funny.
#11 lore raw

Re: [PATCH v2 4/5] KVM: arm64: Expose FEAT_RASv1p1 in a canonical manner

Quoted 33 lines · Marc Zyngier
Quoted 22 lines · Joey Gouly
Quoted 20 lines · Marc Zyngier

If we have RASv1p1 on the host, advertise it to the guest in the "canonical way", by setting ID_AA64PFR0_EL1 to V1P1, rather than the convoluted RAS+RAS_frac method.

Note that this also advertises FEAT_DoubleFault, which doesn't affect the guest at all, as only EL3 is concerned by this.

---
 arch/arm64/kvm/sys_regs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/arm64/kvm/sys_regs.c +0 -0
index 1b4114790024e..66e5a733e9628 100644
@@ -1800,6 +1800,18 @@ static u64 sanitise_id_aa64pfr0_el1(const struct kvm_vcpu *vcpu, u64 val)
 	if (!vcpu_has_sve(vcpu))
 		val &= ~ID_AA64PFR0_EL1_SVE_MASK;
 
Quoted 8 lines

arch/arm64/kvm/sys_regs.c static u64 sanitise_id_aa64pfr0_el1(const struct kvm_vcpu *vcpu, u64 val) · line 1805

Quoted 3 lines
arch/arm64/kvm/sys_regs.c +3 -0
+	/*
+	 * Describe RASv1p1 in a canonical way -- ID_AA64PFR1_EL1.RAS_frac
+	 * is cleared separately. Note that by advertising RASv1p1 here, we

Where is it cleared? __kvm_read_sanitised_id_reg() is where I would have expected to see it:

    case SYS_ID_AA64PFR1_EL1:
Quoted 8 lines

[...]

Ah crap, it is the nested code that we get rid of it, nowhere else. Which means that non-nested VMs have already observed RAS_frac. What a mess. Then RAS_frac must be exposed as writable.

The question is whether we want to allow migration between one flavour of RASv1p1 and the other.

I guess that boils down to which kind of observable changes we want to
allow: bit-for-bit register contents, or only features? If only feature stability is needed, then a cross-flavour migration would be fine; OTOH, we do not know how a guest deduces feature availability, and it might check for one flavour, but not the other (which is mostly a problem if it re-checks during the lifetime.)

Only looking at strictly matching register contents would probably be easier to implement for the VMM (well, it looks easier for QEMU :)

author maintainer
#12 lore raw

PATCH v2 5/5 KVM: arm64: Make ID_AA64PFR0_EL1.RAS writable

In reply to Marc Zyngier

Make ID_AA64PFR0_EL1.RAS writable so that we can restore a VM from a system without RAS to a RAS-equipped machine (or disable RAS in the guest).

---
 arch/arm64/kvm/sys_regs.c | 1 -
 1 file changed, 1 deletion(-)
arch/arm64/kvm/sys_regs.c +0 -1
index 66e5a733e9628..3a50ade091491 100644
@@ -2951,7 +2951,6 @@ static const struct sys_reg_desc sys_reg_descs[] = {
 		    ~(ID_AA64PFR0_EL1_AMU |
 		      ID_AA64PFR0_EL1_MPAM |
 		      ID_AA64PFR0_EL1_SVE |
-		      ID_AA64PFR0_EL1_RAS |
 		      ID_AA64PFR0_EL1_AdvSIMD |
 		      ID_AA64PFR0_EL1_FP)),
 	ID_FILTERED(ID_AA64PFR1_EL1, id_aa64pfr1_el1,
Signature · 1 line
2.39.2