yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-target-i386-sev-fail-query-sev-capabilities-if-QEMU-.patch

8fced6
From 9adf5e57df32df464e7465b1df72c993d0ed4ed4 Mon Sep 17 00:00:00 2001
8fced6
From: Paolo Bonzini <pbonzini@redhat.com>
8fced6
Date: Fri, 31 Jul 2020 18:08:35 -0400
8fced6
Subject: [PATCH 3/4] target/i386: sev: fail query-sev-capabilities if QEMU
8fced6
 cannot use SEV
8fced6
MIME-Version: 1.0
8fced6
Content-Type: text/plain; charset=UTF-8
8fced6
Content-Transfer-Encoding: 8bit
8fced6
8fced6
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
8fced6
Message-id: <20200731180835.86786-3-pbonzini@redhat.com>
8fced6
Patchwork-id: 98124
8fced6
O-Subject: [RHEL-8.3.0 qemu-kvm PATCH 2/2] target/i386: sev: fail query-sev-capabilities if QEMU cannot use SEV
8fced6
Bugzilla: 1689341
8fced6
RH-Acked-by: Danilo de Paula <ddepaula@redhat.com>
8fced6
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8fced6
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
8fced6
8fced6
In some cases, such as if the kvm-amd "sev" module parameter is set
8fced6
to 0, SEV will be unavailable but query-sev-capabilities will still
8fced6
return all the information.  This tricks libvirt into erroneously
8fced6
reporting that SEV is available.  Check the actual usability of the
8fced6
feature and return the appropriate error if QEMU cannot use KVM
8fced6
or KVM cannot use SEV.
8fced6
8fced6
Reviewed-by: Eric Blake <eblake@redhat.com>
8fced6
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8fced6
cherry picked from commit 1b38750c40281dd0d068f8536b2ea95d7b9bd585
8fced6
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
8fced6
---
8fced6
 target/i386/sev.c | 9 +++++++++
8fced6
 1 file changed, 9 insertions(+)
8fced6
8fced6
diff --git a/target/i386/sev.c b/target/i386/sev.c
8fced6
index 054f2d846a..a47f0d3880 100644
8fced6
--- a/target/i386/sev.c
8fced6
+++ b/target/i386/sev.c
8fced6
@@ -504,6 +504,15 @@ sev_get_capabilities(Error **errp)
8fced6
     uint32_t ebx;
8fced6
     int fd;
8fced6
 
8fced6
+    if (!kvm_enabled()) {
8fced6
+        error_setg(errp, "KVM not enabled");
8fced6
+        return NULL;
8fced6
+    }
8fced6
+    if (kvm_vm_ioctl(kvm_state, KVM_MEMORY_ENCRYPT_OP, NULL) < 0) {
8fced6
+        error_setg(errp, "SEV is not enabled in KVM");
8fced6
+        return NULL;
8fced6
+    }
8fced6
+
8fced6
     fd = open(DEFAULT_SEV_DEVICE, O_RDWR);
8fced6
     if (fd < 0) {
8fced6
         error_setg_errno(errp, errno, "Failed to open %s",
8fced6
-- 
8fced6
2.27.0
8fced6