KVM: arm64: nv: Forward hvc traps if originated from nested VM
PATCH 1/1 KVM: arm64: nv: Forward hvc traps if originated from nested VM
It was discovered while trying selftest(smccc_filter) that the hvc trap is getting forwarded to guest hypervisor even if it is originated from itself.
HVC traps from guest hypervisor should be handled by the host hypervisor and traps originating from nested VM should be forwarded. Adding check to forward only if the hvc is trapped from the nested VM.
--- arch/arm64/kvm/handle_exit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kvm/handle_exit.c +2 -2
@@ -40,8 +40,8 @@ static int handle_hvc(struct kvm_vcpu *vcpu) kvm_vcpu_hvc_get_imm(vcpu)); vcpu->stat.hvc_exit_stat++; -/* Forward hvc instructions to the virtual EL2 if the guest has EL2. */ -if (vcpu_has_nv (vcpu)) { +/* Forward hvc instructions to the virtual EL2, if it is from nested VM. */ +if (vcpu_has_nv (vcpu) && !is_hyp_ctxt (vcpu)) {if (vcpu_read_sys_reg (vcpu,HCR_EL2 ) &HCR_HCD )kvm_inject_undefined (vcpu);else
Signature · 1 line
2.48.1
Marc Zyngier
maintainerQuoted 9 lines · Ganapatrao Kulkarni
It was discovered while trying
selftest(smccc_filter)that the hvc trap is getting forwarded to guest hypervisor even if it is originated from itself.HVC traps from guest hypervisor should be handled by the host hypervisor and traps originating from nested VM should be forwarded. Adding check to forward only if the hvc is trapped from the nested VM.
I disagree. HVC from EL2 must be routed to the same EL2. HVC from EL1 must be routed to the EL2 controlling EL1.
In no circumstances should HVC from a NV guest be directly handled by the host hypervisor. That's what SMC is for.
Please read the pseudocode for HVC.
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Quoted 7 lines · Marc Zyngier
Quoted 5 lines · Ganapatrao Kulkarni
It was discovered while trying
selftest(smccc_filter)that the hvc trap is getting forwarded to guest hypervisor even if it is originated from itself.
Quoted 7 lines
Quoted 4 lines
HVC traps from guest hypervisor should be handled by the host hypervisor and traps originating from nested VM should be forwarded. Adding check to forward only if the hvc is trapped from the nested VM.
I disagree. HVC from EL2 must be routed to the same EL2. HVC from EL1 must be routed to the EL2 controlling EL1.
Thanks, Understood, In NV case, hvc has to be forwarded to L1 irrespective of it origin (L1 or L2). Need to add hvc handler in the smccc_filter.c for the vm (when run as L1), so that it is handled and returns with required args set.
Signature · 2 lines
Thanks, Ganapat/GK
Marc Zyngier
maintainerQuoted 16 lines · Ganapatrao Kulkarni
Quoted 12 lines · Marc Zyngier
Quoted 9 lines · Ganapatrao Kulkarni
It was discovered while trying
selftest(smccc_filter)that the hvc trap is getting forwarded to guest hypervisor even if it is originated from itself.HVC traps from guest hypervisor should be handled by the host hypervisor and traps originating from nested VM should be forwarded. Adding check to forward only if the hvc is trapped from the nested VM.
Quoted 7 lines
Quoted 2 lines
I disagree. HVC from EL2 must be routed to the same EL2. HVC from EL1 must be routed to the EL2 controlling EL1.
Thanks, Understood, In NV case, hvc has to be forwarded to L1 irrespective of it origin (L1 or L2). Need to add hvc handler in the
smccc_filter.cfor the vm (when run as L1), so that it is handled and returns with required args set.
Why? This test checks under which conditions an HVC/SMC gets routed to userspace. What does it even mean to test HVC if it doesn't make it outside of the guest itself?
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Quoted 21 lines · Marc Zyngier
Quoted 19 lines · Ganapatrao Kulkarni
Quoted 14 lines · Marc Zyngier
Quoted 9 lines · Ganapatrao Kulkarni
It was discovered while trying
selftest(smccc_filter)that the hvc trap is getting forwarded to guest hypervisor even if it is originated from itself.HVC traps from guest hypervisor should be handled by the host hypervisor and traps originating from nested VM should be forwarded. Adding check to forward only if the hvc is trapped from the nested VM.
I disagree. HVC from EL2 must be routed to the same EL2. HVC from EL1 must be routed to the EL2 controlling EL1.
Quoted 8 lines
Quoted 4 lines
Thanks, Understood, In NV case, hvc has to be forwarded to L1 irrespective of it origin (L1 or L2). Need to add hvc handler in the
smccc_filter.cfor the vm (when run as L1), so that it is handled and returns with required args set.Why? This test checks under which conditions an HVC/SMC gets routed to userspace. What does it even mean to test HVC if it doesn't make it outside of the guest itself?
smccc_filter.c has 2 tests (test_filter_denied and test_filter_fwd_to_user), which runs the vm(guest_code).
I was trying to modify test_filter_denied to run in vEL2, which led to this patch/discussion. I agree, it does not makes sense to run this test for vEL2.
test_filter_fwd_to_user is not feasible to run in vEL2. Thanks for the feedback.
BTW, I could add hvc handler and run test_filter_denied in vEL2.
Signature · 2 lines
Thanks, Ganapat/GK
Quoted 36 lines · Ganapatrao Kulkarni
Quoted 21 lines · Marc Zyngier
Quoted 19 lines · Ganapatrao Kulkarni
Quoted 14 lines · Marc Zyngier
Quoted 9 lines · Ganapatrao Kulkarni
It was discovered while trying
selftest(smccc_filter)that the hvc trap is getting forwarded to guest hypervisor even if it is originated from itself.HVC traps from guest hypervisor should be handled by the host hypervisor and traps originating from nested VM should be forwarded. Adding check to forward only if the hvc is trapped from the nested VM.
I disagree. HVC from EL2 must be routed to the same EL2. HVC from EL1 must be routed to the EL2 controlling EL1.
Quoted 8 lines
Quoted 4 lines
Thanks, Understood, In NV case, hvc has to be forwarded to L1 irrespective of it origin (L1 or L2). Need to add hvc handler in the
smccc_filter.cfor the vm (when run as L1), so that it is handled and returns with required args set.Why? This test checks under which conditions an HVC/SMC gets routed to userspace. What does it even mean to test HVC if it doesn't make it outside of the guest itself?
smccc_filter.chas 2 tests (test_filter_deniedandtest_filter_fwd_to_user), which runs thevm(guest_code).
Quoted 8 lines
I was trying to modify
test_filter_deniedto run in vEL2, which led to this patch/discussion. I agree, it does not makes sense to run this test for vEL2.
test_filter_fwd_to_useris not feasible to run in vEL2. Thanks for the feedback.BTW, I could add hvc handler and run
test_filter_deniedin vEL2.
I would much prefer that the entire test be adapted to consider the EL of the guest, only testing the behavior of SMCs for EL2.
Thanks,
Oliver