OSDN Git Service

target/i386: kvm: do not access uninitialized variable on older kernels
authorPaolo Bonzini <pbonzini@redhat.com>
Fri, 18 Mar 2022 15:23:47 +0000 (16:23 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Sun, 20 Mar 2022 19:38:52 +0000 (20:38 +0100)
commit3ec5ad40081b14af28496198b4d08dbe13386790
tree316f10a515bdc38709a65fd0b0a08e182abb718c
parente2fb7d8aa218256793df99571d16f92074258447
target/i386: kvm: do not access uninitialized variable on older kernels

KVM support for AMX includes a new system attribute, KVM_X86_XCOMP_GUEST_SUPP.
Commit 19db68ca68 ("x86: Grant AMX permission for guest", 2022-03-15) however
did not fully consider the behavior on older kernels.  First, it warns
too aggressively.  Second, it invokes the KVM_GET_DEVICE_ATTR ioctl
unconditionally and then uses the "bitmask" variable, which remains
uninitialized if the ioctl fails.  Third, kvm_ioctl returns -errno rather
than -1 on errors.

While at it, explain why the ioctl is needed and KVM_GET_SUPPORTED_CPUID
is not enough.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
target/i386/kvm/kvm.c