Skip to contentSkip to conversation

KVM: arm64: Fix FEAT_MOPS in pKVM

PATCH In review Vladimir Murzin 3 participants 4 messages Jan 6, 2025 – Jan 7, 2025

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

PATCH 1/1 KVM: arm64: Fix FEAT_MOPS in pKVM

Flush HCRX_EL2 when switching between the host and the guests.

Fixes 84de212d739e ("KVM: arm64: Make FEAT_MOPS UNDEF if not advertised to the guest")
---
 arch/arm64/kvm/hyp/nvhe/hyp-main.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/kvm/hyp/nvhe/hyp-main.c +1 -0
index 6aa0b13d86..d9a41ddc63 100644
@@ -109,6 +109,7 @@ static void flush_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu)
 	hyp_vcpu->vcpu.arch.hcr_el2 &= ~(HCR_TWI | HCR_TWE);
 	hyp_vcpu->vcpu.arch.hcr_el2 |= READ_ONCE(host_vcpu->arch.hcr_el2) &
 						 (HCR_TWI | HCR_TWE);
+	hyp_vcpu->vcpu.arch.hcrx_el2    = host_vcpu->arch.hcrx_el2;
 
 	hyp_vcpu->vcpu.arch.iflags	= host_vcpu->arch.iflags;
 
Signature · 1 line
2.24.0
#1 lore raw

+cc Fuad

Quoted 4 lines · Vladimir Murzin

Flush HCRX_EL2 when switching between the host and the guests.

Fixes 84de212d739e ("KVM: arm64: Make FEAT_MOPS UNDEF if not advertised to the guest")

We shouldn't be trusting the host's hcrx_el2 in this case and should instead calculate it for the pVM similar to the other trap registers (see pkvm_vcpu_init_traps() and friends).

It is apparent, though, that we erroneously exposed MOPS before commit 3d7ff00700d1 ("KVM: arm64: Rework specifying restricted features for protected VMs").

Signature · 2 lines
Thanks,
Oliver 
#2 lore raw
Quoted 9 lines · Oliver Upton

+cc Fuad

Quoted 4 lines · Vladimir Murzin

Flush HCRX_EL2 when switching between the host and the guests.

Fixes 84de212d739e ("KVM: arm64: Make FEAT_MOPS UNDEF if not advertised to the guest")
Quoted 6 lines

We shouldn't be trusting the host's hcrx_el2 in this case and should instead calculate it for the pVM similar to the other trap registers (see pkvm_vcpu_init_traps() and friends).

It is apparent, though, that we erroneously exposed MOPS before commit 3d7ff00700d1 ("KVM: arm64: Rework specifying restricted features for protected VMs").

Yeah, actually FEAT_MOPS needs a bit more work for it to work with pKVM. I have patches (downstream, Android) that add MOPS support for pKVM. If there's interest I can post them now, but since protected VMs aren't completely done upstream I thought I'd wait a bit.

Cheers,
/fuad

Quoted 4 lines

--
Thanks,
Oliver

#3 lore raw
Quoted 12 lines · Fuad Tabba
Quoted 11 lines · Oliver Upton

+cc Fuad

Quoted 4 lines · Vladimir Murzin

Flush HCRX_EL2 when switching between the host and the guests.

Fixes 84de212d739e ("KVM: arm64: Make FEAT_MOPS UNDEF if not advertised to the guest")

We shouldn't be trusting the host's hcrx_el2 in this case and should instead calculate it for the pVM similar to the other trap registers (see pkvm_vcpu_init_traps() and friends).

Quoted 6 lines
Quoted 2 lines

It is apparent, though, that we erroneously exposed MOPS before commit 3d7ff00700d1 ("KVM: arm64: Rework specifying restricted features for protected VMs").

Yeah, actually FEAT_MOPS needs a bit more work for it to work with pKVM. I have patches (downstream, Android) that add MOPS support for pKVM. If there's interest I can post them now, but since protected VMs aren't completely done upstream I thought I'd wait a bit.

Fair enough.

Vladimir

Quoted 7 lines

Cheers,
/fuad

Quoted 3 lines

--
Thanks,
Oliver