|
|
4841a6 |
From 688c9f386635544dbc468171a32fbc84f0c9224e Mon Sep 17 00:00:00 2001
|
|
|
4841a6 |
From: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
4841a6 |
Date: Fri, 18 Mar 2022 16:23:47 +0100
|
|
|
4841a6 |
Subject: [PATCH 12/24] target/i386: kvm: do not access uninitialized variable
|
|
|
4841a6 |
on older kernels
|
|
|
4841a6 |
|
|
|
4841a6 |
RH-Author: Paul Lai <plai@redhat.com>
|
|
|
4841a6 |
RH-MergeRequest: 176: Enable KVM AMX support
|
|
|
4841a6 |
RH-Commit: [12/13] 776fac1e7d1aa16ec5f4d99ddad3039eab8212af
|
|
|
4841a6 |
RH-Bugzilla: 1916415
|
|
|
4841a6 |
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
|
|
|
4841a6 |
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
|
|
|
4841a6 |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
4841a6 |
|
|
|
4841a6 |
KVM support for AMX includes a new system attribute, KVM_X86_XCOMP_GUEST_SUPP.
|
|
|
4841a6 |
Commit 19db68ca68 ("x86: Grant AMX permission for guest", 2022-03-15) however
|
|
|
4841a6 |
did not fully consider the behavior on older kernels. First, it warns
|
|
|
4841a6 |
too aggressively. Second, it invokes the KVM_GET_DEVICE_ATTR ioctl
|
|
|
4841a6 |
unconditionally and then uses the "bitmask" variable, which remains
|
|
|
4841a6 |
uninitialized if the ioctl fails. Third, kvm_ioctl returns -errno rather
|
|
|
4841a6 |
than -1 on errors.
|
|
|
4841a6 |
|
|
|
4841a6 |
While at it, explain why the ioctl is needed and KVM_GET_SUPPORTED_CPUID
|
|
|
4841a6 |
is not enough.
|
|
|
4841a6 |
|
|
|
4841a6 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
4841a6 |
(cherry picked from commit 3ec5ad40081b14af28496198b4d08dbe13386790)
|
|
|
4841a6 |
Signed-off-by: Paul Lai <plai@redhat.com>
|
|
|
4841a6 |
---
|
|
|
4841a6 |
target/i386/kvm/kvm.c | 17 +++++++++++++----
|
|
|
4841a6 |
1 file changed, 13 insertions(+), 4 deletions(-)
|
|
|
4841a6 |
|
|
|
4841a6 |
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
|
|
|
4841a6 |
index b1128b0e07..bd439e56ad 100644
|
|
|
4841a6 |
--- a/target/i386/kvm/kvm.c
|
|
|
4841a6 |
+++ b/target/i386/kvm/kvm.c
|
|
|
4841a6 |
@@ -409,6 +409,12 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,
|
|
|
4841a6 |
}
|
|
|
4841a6 |
} else if (function == 0xd && index == 0 &&
|
|
|
4841a6 |
(reg == R_EAX || reg == R_EDX)) {
|
|
|
4841a6 |
+ /*
|
|
|
4841a6 |
+ * The value returned by KVM_GET_SUPPORTED_CPUID does not include
|
|
|
4841a6 |
+ * features that still have to be enabled with the arch_prctl
|
|
|
4841a6 |
+ * system call. QEMU needs the full value, which is retrieved
|
|
|
4841a6 |
+ * with KVM_GET_DEVICE_ATTR.
|
|
|
4841a6 |
+ */
|
|
|
4841a6 |
struct kvm_device_attr attr = {
|
|
|
4841a6 |
.group = 0,
|
|
|
4841a6 |
.attr = KVM_X86_XCOMP_GUEST_SUPP,
|
|
|
4841a6 |
@@ -417,13 +423,16 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,
|
|
|
4841a6 |
|
|
|
4841a6 |
bool sys_attr = kvm_check_extension(s, KVM_CAP_SYS_ATTRIBUTES);
|
|
|
4841a6 |
if (!sys_attr) {
|
|
|
4841a6 |
- warn_report("cannot get sys attribute capabilities %d", sys_attr);
|
|
|
4841a6 |
+ return ret;
|
|
|
4841a6 |
}
|
|
|
4841a6 |
|
|
|
4841a6 |
int rc = kvm_ioctl(s, KVM_GET_DEVICE_ATTR, &attr);
|
|
|
4841a6 |
- if (rc == -1 && (errno == ENXIO || errno == EINVAL)) {
|
|
|
4841a6 |
- warn_report("KVM_GET_DEVICE_ATTR(0, KVM_X86_XCOMP_GUEST_SUPP) "
|
|
|
4841a6 |
- "error: %d", rc);
|
|
|
4841a6 |
+ if (rc < 0) {
|
|
|
4841a6 |
+ if (rc != -ENXIO) {
|
|
|
4841a6 |
+ warn_report("KVM_GET_DEVICE_ATTR(0, KVM_X86_XCOMP_GUEST_SUPP) "
|
|
|
4841a6 |
+ "error: %d", rc);
|
|
|
4841a6 |
+ }
|
|
|
4841a6 |
+ return ret;
|
|
|
4841a6 |
}
|
|
|
4841a6 |
ret = (reg == R_EAX) ? bitmask : bitmask >> 32;
|
|
|
4841a6 |
} else if (function == 0x80000001 && reg == R_ECX) {
|
|
|
4841a6 |
--
|
|
|
4841a6 |
2.35.3
|
|
|
4841a6 |
|