Commit 9b0971ca authored by Paolo Bonzini's avatar Paolo Bonzini

KVM: SEV-ES: fix another issue with string I/O VMGEXITs

If the guest requests string I/O from the hypervisor via VMGEXIT,
SW_EXITINFO2 will contain the REP count.  However, sev_es_string_io
was incorrectly treating it as the size of the GHCB buffer in
bytes.

This fixes the "outsw" test in the experimental SEV tests of
kvm-unit-tests.

Cc: stable@vger.kernel.org
Fixes: 7ed9abfe ("KVM: SVM: Support string IO operations for an SEV-ES guest")
Reported-by: default avatarMarc Orr <marcorr@google.com>
Tested-by: default avatarMarc Orr <marcorr@google.com>
Reviewed-by: default avatarMarc Orr <marcorr@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 0985dba8
...@@ -2579,11 +2579,20 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu) ...@@ -2579,11 +2579,20 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu)
int sev_es_string_io(struct vcpu_svm *svm, int size, unsigned int port, int in) int sev_es_string_io(struct vcpu_svm *svm, int size, unsigned int port, int in)
{ {
if (!setup_vmgexit_scratch(svm, in, svm->vmcb->control.exit_info_2)) int count;
int bytes;
if (svm->vmcb->control.exit_info_2 > INT_MAX)
return -EINVAL;
count = svm->vmcb->control.exit_info_2;
if (unlikely(check_mul_overflow(count, size, &bytes)))
return -EINVAL;
if (!setup_vmgexit_scratch(svm, in, bytes))
return -EINVAL; return -EINVAL;
return kvm_sev_es_string_io(&svm->vcpu, size, port, return kvm_sev_es_string_io(&svm->vcpu, size, port, svm->ghcb_sa, count, in);
svm->ghcb_sa, svm->ghcb_sa_len / size, in);
} }
void sev_es_init_vmcb(struct vcpu_svm *svm) void sev_es_init_vmcb(struct vcpu_svm *svm)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment