All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Tom Lendacky <thomas.lendacky@amd.com>,
	Eduardo Habkost <ehabkost@redhat.com>,
	Richard Henderson <richard.henderson@linaro.org>,
	"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
	Venu Busireddy <venu.busireddy@oracle.com>,
	Jiri Slaby <jslaby@suse.cz>
Subject: [PULL 03/19] sev/i386: Add initial support for SEV-ES
Date: Mon, 15 Feb 2021 14:16:10 +0100	[thread overview]
Message-ID: <20210215131626.65640-4-pbonzini@redhat.com> (raw)
In-Reply-To: <20210215131626.65640-1-pbonzini@redhat.com>

From: Tom Lendacky <thomas.lendacky@amd.com>

Provide initial support for SEV-ES. This includes creating a function to
indicate the guest is an SEV-ES guest (which will return false until all
support is in place), performing the proper SEV initialization and
ensuring that the guest CPU state is measured as part of the launch.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Richard Henderson <richard.henderson@linaro.org>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Co-developed-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Reviewed-by: Venu Busireddy <venu.busireddy@oracle.com>
Message-Id: <2e6386cbc1ddeaf701547dd5677adf5ddab2b6bd.1611682609.git.thomas.lendacky@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/cpu.c      |  1 +
 target/i386/sev-stub.c |  6 ++++++
 target/i386/sev.c      | 44 ++++++++++++++++++++++++++++++++++++++++--
 target/i386/sev_i386.h |  1 +
 4 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 9c3d2d60b7..20c3a5af3f 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -5984,6 +5984,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
         break;
     case 0x8000001F:
         *eax = sev_enabled() ? 0x2 : 0;
+        *eax |= sev_es_enabled() ? 0x8 : 0;
         *ebx = sev_get_cbit_position();
         *ebx |= sev_get_reduced_phys_bits() << 6;
         *ecx = 0;
diff --git a/target/i386/sev-stub.c b/target/i386/sev-stub.c
index 1ac1fd5b94..edf6c519d7 100644
--- a/target/i386/sev-stub.c
+++ b/target/i386/sev-stub.c
@@ -49,6 +49,7 @@ SevCapability *sev_get_capabilities(Error **errp)
     error_setg(errp, "SEV is not available in this QEMU");
     return NULL;
 }
+
 int sev_inject_launch_secret(const char *hdr, const char *secret,
                              uint64_t gpa, Error **errp)
 {
@@ -59,3 +60,8 @@ int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp)
 {
     return 0;
 }
+
+bool sev_es_enabled(void)
+{
+    return false;
+}
diff --git a/target/i386/sev.c b/target/i386/sev.c
index 11c9a3cc21..dc0e53019b 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -341,6 +341,12 @@ sev_enabled(void)
     return !!sev_guest;
 }
 
+bool
+sev_es_enabled(void)
+{
+    return false;
+}
+
 uint64_t
 sev_get_me_mask(void)
 {
@@ -561,6 +567,20 @@ sev_launch_update_data(SevGuestState *sev, uint8_t *addr, uint64_t len)
     return ret;
 }
 
+static int
+sev_launch_update_vmsa(SevGuestState *sev)
+{
+    int ret, fw_error;
+
+    ret = sev_ioctl(sev->sev_fd, KVM_SEV_LAUNCH_UPDATE_VMSA, NULL, &fw_error);
+    if (ret) {
+        error_report("%s: LAUNCH_UPDATE_VMSA ret=%d fw_error=%d '%s'",
+                __func__, ret, fw_error, fw_error_to_str(fw_error));
+    }
+
+    return ret;
+}
+
 static void
 sev_launch_get_measure(Notifier *notifier, void *unused)
 {
@@ -573,6 +593,14 @@ sev_launch_get_measure(Notifier *notifier, void *unused)
         return;
     }
 
+    if (sev_es_enabled()) {
+        /* measure all the VM save areas before getting launch_measure */
+        ret = sev_launch_update_vmsa(sev);
+        if (ret) {
+            exit(1);
+        }
+    }
+
     measurement = g_new0(struct kvm_sev_launch_measure, 1);
 
     /* query the measurement blob length */
@@ -667,7 +695,7 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
     SevGuestState *sev
         = (SevGuestState *)object_dynamic_cast(OBJECT(cgs), TYPE_SEV_GUEST);
     char *devname;
-    int ret, fw_error;
+    int ret, fw_error, cmd;
     uint32_t ebx;
     uint32_t host_cbitpos;
     struct sev_user_data_status status = {};
@@ -724,8 +752,20 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
     sev->api_major = status.api_major;
     sev->api_minor = status.api_minor;
 
+    if (sev_es_enabled()) {
+        if (!(status.flags & SEV_STATUS_FLAGS_CONFIG_ES)) {
+            error_report("%s: guest policy requires SEV-ES, but "
+                         "host SEV-ES support unavailable",
+                         __func__);
+            goto err;
+        }
+        cmd = KVM_SEV_ES_INIT;
+    } else {
+        cmd = KVM_SEV_INIT;
+    }
+
     trace_kvm_sev_init();
-    ret = sev_ioctl(sev->sev_fd, KVM_SEV_INIT, NULL, &fw_error);
+    ret = sev_ioctl(sev->sev_fd, cmd, NULL, &fw_error);
     if (ret) {
         error_setg(errp, "%s: failed to initialize ret=%d fw_error=%d '%s'",
                    __func__, ret, fw_error, fw_error_to_str(fw_error));
diff --git a/target/i386/sev_i386.h b/target/i386/sev_i386.h
index bd9f00a908..ae221d4c72 100644
--- a/target/i386/sev_i386.h
+++ b/target/i386/sev_i386.h
@@ -28,6 +28,7 @@
 #define SEV_POLICY_DOMAIN       0x10
 #define SEV_POLICY_SEV          0x20
 
+extern bool sev_es_enabled(void);
 extern uint64_t sev_get_me_mask(void);
 extern SevInfo *sev_get_info(void);
 extern uint32_t sev_get_cbit_position(void);
-- 
2.29.2




  parent reply	other threads:[~2021-02-15 13:23 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-15 13:16 [PULL 00/19] i386, qgraph patches for 2020-02-15 Paolo Bonzini
2021-02-15 13:16 ` [PULL 01/19] pc: add parser for OVMF reset block Paolo Bonzini
2021-02-15 13:16 ` [PULL 02/19] sev: update sev-inject-launch-secret to make gpa optional Paolo Bonzini
2021-05-20 21:36   ` Philippe Mathieu-Daudé
2021-05-20 22:19     ` James Bottomley
2021-05-21 11:34       ` Philippe Mathieu-Daudé
2021-02-15 13:16 ` Paolo Bonzini [this message]
2021-02-15 13:16 ` [PULL 04/19] sev/i386: Require in-kernel irqchip support for SEV-ES guests Paolo Bonzini
2021-02-15 13:16 ` [PULL 05/19] sev/i386: Allow AP booting under SEV-ES Paolo Bonzini
2021-02-15 13:16 ` [PULL 06/19] sev/i386: Don't allow a system reset under an SEV-ES guest Paolo Bonzini
2021-02-15 13:16 ` [PULL 07/19] kvm/i386: Use a per-VM check for SMM capability Paolo Bonzini
2021-02-15 13:16 ` [PULL 08/19] sev/i386: Enable an SEV-ES guest based on SEV policy Paolo Bonzini
2021-02-15 13:16 ` [PULL 09/19] libqos/qgraph: add qos_node_create_driver_named() Paolo Bonzini
2021-02-15 14:06   ` Christian Schoenebeck
2021-02-18  9:10     ` Christian Schoenebeck
2021-02-18  9:14       ` Paolo Bonzini
2021-02-18  9:23         ` Christian Schoenebeck
2021-02-15 13:16 ` [PULL 10/19] libqos/qgraph_internal: add qos_printf() and qos_printf_literal() Paolo Bonzini
2021-02-15 13:16 ` [PULL 11/19] tests/qtest/qos-test: dump qos graph if verbose Paolo Bonzini
2021-02-15 13:16 ` [PULL 12/19] tests/qtest/qos-test: dump environment variables " Paolo Bonzini
2021-02-15 13:16 ` [PULL 13/19] tests/qtest/qos-test: dump QEMU command " Paolo Bonzini
2021-02-15 13:16 ` [PULL 14/19] util/cutils: Skip "." when looking for next directory component Paolo Bonzini
2021-02-15 13:16 ` [PULL 15/19] hvf: Guard xgetbv call Paolo Bonzini
2021-02-15 13:16 ` [PULL 16/19] target/i386/hvf: add vmware-cpuid-freq cpu feature Paolo Bonzini
2021-02-15 13:16 ` [PULL 17/19] hvf: x86: Remove unused definitions Paolo Bonzini
2021-02-15 13:16 ` [PULL 18/19] target/i386/hvf: add rdmsr 35H MSR_CORE_THREAD_COUNT Paolo Bonzini
2021-02-15 13:16 ` [PULL 19/19] hvf: Fetch cr4 before evaluating CPUID(1) Paolo Bonzini
2021-02-15 13:29 ` [PULL 00/19] i386, qgraph patches for 2020-02-15 Thomas Huth
2021-02-15 13:30 ` Philippe Mathieu-Daudé
2021-02-15 13:43 ` no-reply
2021-02-15 21:13 ` Eric Blake
2021-02-16 14:13   ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210215131626.65640-4-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=jslaby@suse.cz \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=thomas.lendacky@amd.com \
    --cc=venu.busireddy@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.