Re: [PATCH 4/8] KVM: SVM: Stuff next_rip on emualted INT3 injection if NRIPS is supported

From: Maxim Levitsky
Date: Mon Apr 04 2022 - 08:00:15 EST


On Sat, 2022-04-02 at 01:08 +0000, Sean Christopherson wrote:
> If NRIPS is supported in hardware but disabled in KVM, set next_rip to
> the next RIP when advancing RIP as part of emulating INT3 injection.
> There is no flag to tell the CPU that KVM isn't using next_rip, and so
> leaving next_rip is left as is will result in the CPU pushing garbage
> onto the stack when vectoring the injected event.
>
> Fixes: 66b7138f9136 ("KVM: SVM: Emulate nRIP feature when reinjecting INT3")
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> ---
> arch/x86/kvm/svm/svm.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index 30cef3b10838..6ea8f16e39ac 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -391,6 +391,10 @@ static void svm_queue_exception(struct kvm_vcpu *vcpu)
> */
> (void)svm_skip_emulated_instruction(vcpu);
> rip = kvm_rip_read(vcpu);
> +
> + if (boot_cpu_has(X86_FEATURE_NRIPS))
> + svm->vmcb->control.next_rip = rip;
> +
> svm->int3_rip = rip + svm->vmcb->save.cs.base;
> svm->int3_injected = rip - old_rip;
> }

Reviewed-by: Maxim Levitsky <mlevitsk@xxxxxxxxxx>

Best regards,
Maxim Levitsky