Re: [PATCH v2 4/6] KVM: SVM: Handle MMIO during vectroing error

Sean Christopherson
2024-12-11T18:16:06Z

On Mon, Nov 11, 2024, Ivan Orlov wrote:
> Handle MMIO during vectoring error in check_emulate_instruction to
> prevent infinite loop on SVM and eliminate the difference in how the
> situation when the guest accesses MMIO during vectoring is handled on
> SVM and VMX.
>
> Signed-off-by: Ivan Orlov <iorlov@amazon.com>
> ---
> V1 -> V2:
> - Detect the unhandleable vectoring error in svm_check_emulate_instruction
> instead of handling it in the common MMU code (which is specific for
> cached MMIO)
>
> arch/x86/kvm/svm/svm.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index c1e29307826b..b69f0f98c576 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -4797,9 +4797,16 @@ static void svm_enable_smi_window(struct kvm_vcpu *vcpu)
> static int svm_check_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
> void *insn, int insn_len)
> {
> - bool smep, smap, is_user;
> + bool smep, smap, is_user, is_vect;
> u64 error_code;
>
> + is_vect = to_svm(vcpu)->vmcb->control.exit_int_info &
> + SVM_EXITINTINFO_TYPE_MASK;
> +
> + /* Emulation is not possible when MMIO happens during event vectoring. */
> + if (kvm_is_emul_type_mmio(emul_type) && is_vect)

Same nit here, omit the local variable.

> + return X86EMUL_UNHANDLEABLE_VECTORING_IO;
> +
> /* Emulation is always possible when KVM has access to all guest state. */
> if (!sev_guest(vcpu->kvm))
> return X86EMUL_CONTINUE;
> --
> 2.43.0
>