qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Brijesh Singh <brijesh.singh@amd.com>
Subject: [Qemu-devel] [PULL 05/22] kvm: add memory encryption context
Date: Tue, 13 Mar 2018 13:56:21 +0100	[thread overview]
Message-ID: <1520945798-50640-6-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1520945798-50640-1-git-send-email-pbonzini@redhat.com>

From: Brijesh Singh <brijesh.singh@amd.com>

Split from a patch by Brijesh Singh (brijesh.singh@amd.com).

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
---
 accel/Makefile.objs     |  2 +-
 accel/kvm/Makefile.objs |  3 ++-
 accel/kvm/kvm-all.c     | 25 +++++++++++++++++++++++++
 accel/kvm/sev-stub.c    | 21 +++++++++++++++++++++
 accel/stubs/kvm-stub.c  |  5 +++++
 include/sysemu/kvm.h    |  9 +++++++++
 include/sysemu/sev.h    | 20 ++++++++++++++++++++
 7 files changed, 83 insertions(+), 2 deletions(-)
 create mode 100644 accel/kvm/sev-stub.c
 create mode 100644 include/sysemu/sev.h

diff --git a/accel/Makefile.objs b/accel/Makefile.objs
index 10666ed..c3718a1 100644
--- a/accel/Makefile.objs
+++ b/accel/Makefile.objs
@@ -1,4 +1,4 @@
 obj-$(CONFIG_SOFTMMU) += accel.o
-obj-y += kvm/
+obj-$(CONFIG_KVM) += kvm/
 obj-$(CONFIG_TCG) += tcg/
 obj-y += stubs/
diff --git a/accel/kvm/Makefile.objs b/accel/kvm/Makefile.objs
index 85351e7..fdfa481 100644
--- a/accel/kvm/Makefile.objs
+++ b/accel/kvm/Makefile.objs
@@ -1 +1,2 @@
-obj-$(CONFIG_KVM) += kvm-all.o
+obj-y += kvm-all.o
+obj-$(call lnot,$(CONFIG_SEV)) += sev-stub.o
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index b91fcb7..e0e43fd 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -38,6 +38,7 @@
 #include "qemu/event_notifier.h"
 #include "trace.h"
 #include "hw/irq.h"
+#include "sysemu/sev.h"
 
 #include "hw/boards.h"
 
@@ -103,6 +104,9 @@ struct KVMState
 #endif
     KVMMemoryListener memory_listener;
     QLIST_HEAD(, KVMParkedVcpu) kvm_parked_vcpus;
+
+    /* memory encryption */
+    void *memcrypt_handle;
 };
 
 KVMState *kvm_state;
@@ -138,6 +142,15 @@ int kvm_get_max_memslots(void)
     return s->nr_slots;
 }
 
+bool kvm_memcrypt_enabled(void)
+{
+    if (kvm_state && kvm_state->memcrypt_handle) {
+        return true;
+    }
+
+    return false;
+}
+
 static KVMSlot *kvm_get_free_slot(KVMMemoryListener *kml)
 {
     KVMState *s = kvm_state;
@@ -1636,6 +1649,18 @@ static int kvm_init(MachineState *ms)
 
     kvm_state = s;
 
+    /*
+     * if memory encryption object is specified then initialize the memory
+     * encryption context.
+     */
+    if (ms->memory_encryption) {
+        kvm_state->memcrypt_handle = sev_guest_init(ms->memory_encryption);
+        if (!kvm_state->memcrypt_handle) {
+            ret = -1;
+            goto err;
+        }
+    }
+
     ret = kvm_arch_init(ms, s);
     if (ret < 0) {
         goto err;
diff --git a/accel/kvm/sev-stub.c b/accel/kvm/sev-stub.c
new file mode 100644
index 0000000..4a5cc55
--- /dev/null
+++ b/accel/kvm/sev-stub.c
@@ -0,0 +1,21 @@
+/*
+ * QEMU SEV stub
+ *
+ * Copyright Advanced Micro Devices 2018
+ *
+ * Authors:
+ *      Brijesh Singh <brijesh.singh@amd.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "sysemu/sev.h"
+
+void *sev_guest_init(const char *id)
+{
+    return NULL;
+}
diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c
index c964af3..f83192d 100644
--- a/accel/stubs/kvm-stub.c
+++ b/accel/stubs/kvm-stub.c
@@ -105,6 +105,11 @@ int kvm_on_sigbus(int code, void *addr)
     return 1;
 }
 
+bool kvm_memcrypt_enabled(void)
+{
+    return false;
+}
+
 #ifndef CONFIG_USER_ONLY
 int kvm_irqchip_add_msi_route(KVMState *s, int vector, PCIDevice *dev)
 {
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 85002ac..84017a0 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -231,6 +231,15 @@ int kvm_destroy_vcpu(CPUState *cpu);
  */
 bool kvm_arm_supports_user_irq(void);
 
+/**
+ * kvm_memcrypt_enabled - return boolean indicating whether memory encryption
+ *                        is enabled
+ * Returns: 1 memory encryption is enabled
+ *          0 memory encryption is disabled
+ */
+bool kvm_memcrypt_enabled(void);
+
+
 #ifdef NEED_CPU_H
 #include "cpu.h"
 
diff --git a/include/sysemu/sev.h b/include/sysemu/sev.h
new file mode 100644
index 0000000..f7a6057
--- /dev/null
+++ b/include/sysemu/sev.h
@@ -0,0 +1,20 @@
+/*
+ * QEMU Secure Encrypted Virutualization (SEV) support
+ *
+ * Copyright: Advanced Micro Devices, 2016-2018
+ *
+ * Authors:
+ *  Brijesh Singh <brijesh.singh@amd.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef QEMU_SEV_H
+#define QEMU_SEV_H
+
+#include "sysemu/kvm.h"
+
+void *sev_guest_init(const char *id);
+#endif
-- 
1.8.3.1

  parent reply	other threads:[~2018-03-13 12:57 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-13 12:56 [Qemu-devel] [PULL 00/22] KVM patches for QEMU 2.12 soft freeze Paolo Bonzini
2018-03-13 12:56 ` [Qemu-devel] [PULL 01/22] update Linux headers to 4.16-rc5 Paolo Bonzini
2018-03-13 12:56 ` [Qemu-devel] [PULL 02/22] KVM: x86: Add support for save/load MSR_SMI_COUNT Paolo Bonzini
2018-03-13 12:56 ` [Qemu-devel] [PULL 03/22] machine: add memory-encryption option Paolo Bonzini
2018-03-13 12:56 ` [Qemu-devel] [PULL 04/22] docs: add AMD Secure Encrypted Virtualization (SEV) Paolo Bonzini
2018-03-13 12:56 ` Paolo Bonzini [this message]
2018-03-13 12:56 ` [Qemu-devel] [PULL 06/22] kvm: introduce memory encryption APIs Paolo Bonzini
2018-03-13 12:56 ` [Qemu-devel] [PULL 07/22] target/i386: add Secure Encrypted Virtualization (SEV) object Paolo Bonzini
2018-03-13 12:56 ` [Qemu-devel] [PULL 08/22] sev/i386: qmp: add query-sev command Paolo Bonzini
2018-03-13 12:56 ` [Qemu-devel] [PULL 09/22] include: add psp-sev.h header file Paolo Bonzini
2018-03-13 12:56 ` [Qemu-devel] [PULL 10/22] sev/i386: add command to initialize the memory encryption context Paolo Bonzini
2018-04-27 13:01   ` Peter Maydell
2018-03-13 12:56 ` [Qemu-devel] [PULL 11/22] sev/i386: register the guest memory range which may contain encrypted data Paolo Bonzini
2018-03-13 12:56 ` [Qemu-devel] [PULL 12/22] sev/i386: add command to create launch memory encryption context Paolo Bonzini
2018-04-27 13:04   ` Peter Maydell
2018-03-13 12:56 ` [Qemu-devel] [PULL 13/22] sev/i386: add command to encrypt guest memory region Paolo Bonzini
2018-03-13 12:56 ` [Qemu-devel] [PULL 14/22] target/i386: encrypt bios rom Paolo Bonzini
2018-03-13 12:56 ` [Qemu-devel] [PULL 15/22] sev/i386: add support to LAUNCH_MEASURE command Paolo Bonzini
2018-03-13 12:56 ` [Qemu-devel] [PULL 16/22] sev/i386: finalize the SEV guest launch flow Paolo Bonzini
2018-03-13 12:56 ` [Qemu-devel] [PULL 17/22] sev/i386: add migration blocker Paolo Bonzini
2018-03-13 12:56 ` [Qemu-devel] [PULL 18/22] cpu/i386: populate CPUID 0x8000_001F when SEV is active Paolo Bonzini
2018-03-13 12:56 ` [Qemu-devel] [PULL 19/22] sev/i386: hmp: add 'info sev' command Paolo Bonzini
2018-03-13 12:56 ` [Qemu-devel] [PULL 20/22] sev/i386: qmp: add query-sev-launch-measure command Paolo Bonzini
2018-03-13 12:56 ` [Qemu-devel] [PULL 21/22] sev/i386: qmp: add query-sev-capabilities command Paolo Bonzini
2018-03-13 12:56 ` [Qemu-devel] [PULL 22/22] sev/i386: add sev_get_capabilities() Paolo Bonzini
2018-04-27 12:53   ` Peter Maydell
2018-03-13 16:29 ` [Qemu-devel] [PULL 00/22] KVM patches for QEMU 2.12 soft freeze Alex Williamson

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=1520945798-50640-6-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=brijesh.singh@amd.com \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).