diff mbox series

[v6,42/64] KVM: arm64: nv: Fold guest's HCR_EL2 configuration into the host's

Message ID 20220128121912.509006-43-maz@kernel.org (mailing list archive)
State New, archived
Headers show
Series KVM: arm64: ARMv8.3/8.4 Nested Virtualization support | expand

Commit Message

Marc Zyngier Jan. 28, 2022, 12:18 p.m. UTC
When entering a L2 guest (nested virt enabled, but not in hypervisor
context), we need to honor the traps the L1 guest has asked enabled.

For now, just OR the guest's HCR_EL2 into the host's. We may have to do
some filtering in the future though.

Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 arch/arm64/kvm/hyp/vhe/switch.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Alexandru Elisei Feb. 25, 2022, 1:45 p.m. UTC | #1
Hi,

On Fri, Jan 28, 2022 at 12:18:50PM +0000, Marc Zyngier wrote:
> When entering a L2 guest (nested virt enabled, but not in hypervisor
> context), we need to honor the traps the L1 guest has asked enabled.
> 
> For now, just OR the guest's HCR_EL2 into the host's. We may have to do
> some filtering in the future though.

Hmm... looks to me like the filtering is already implemented via the
HCR_GUEST_NV_FILTER_FLAGS. Or am I misunderstanding something?

> 
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> ---
>  arch/arm64/kvm/hyp/vhe/switch.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c
> index 0e164cc8e913..5e8eafac27c6 100644
> --- a/arch/arm64/kvm/hyp/vhe/switch.c
> +++ b/arch/arm64/kvm/hyp/vhe/switch.c
> @@ -78,6 +78,11 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
>  			if (!vcpu_el2_tge_is_set(vcpu))
>  				hcr |= HCR_AT | HCR_TTLB;
>  		}
> +	} else if (vcpu_has_nv(vcpu)) {
> +		u64 vhcr_el2 = __vcpu_sys_reg(vcpu, HCR_EL2);
> +
> +		vhcr_el2 &= ~HCR_GUEST_NV_FILTER_FLAGS;


> +		hcr |= vhcr_el2;

This makes sense, we only the guest to add extra traps on top of what KVM
already traps, not remove traps from what KVM has configured.

However, HCR_EL2.FIEN (bit 47) disables traps when the bit is 1. Shouldn't
it be part of the HCR_GUEST_NV_FILTER_FLAGS?

Thanks,
Alex

>  	}
>  
>  	___activate_traps(vcpu, hcr);
> -- 
> 2.30.2
>
diff mbox series

Patch

diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c
index 0e164cc8e913..5e8eafac27c6 100644
--- a/arch/arm64/kvm/hyp/vhe/switch.c
+++ b/arch/arm64/kvm/hyp/vhe/switch.c
@@ -78,6 +78,11 @@  static void __activate_traps(struct kvm_vcpu *vcpu)
 			if (!vcpu_el2_tge_is_set(vcpu))
 				hcr |= HCR_AT | HCR_TTLB;
 		}
+	} else if (vcpu_has_nv(vcpu)) {
+		u64 vhcr_el2 = __vcpu_sys_reg(vcpu, HCR_EL2);
+
+		vhcr_el2 &= ~HCR_GUEST_NV_FILTER_FLAGS;
+		hcr |= vhcr_el2;
 	}
 
 	___activate_traps(vcpu, hcr);