[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v10 16/28] sev/i386: add command to encrypt guest me
From: |
Brijesh Singh |
Subject: |
[Qemu-devel] [PATCH v10 16/28] sev/i386: add command to encrypt guest memory region |
Date: |
Wed, 28 Feb 2018 15:10:16 -0600 |
The KVM_SEV_LAUNCH_UPDATE_DATA command is used to encrypt a guest memory
region using the VM Encryption Key created using LAUNCH_START.
Cc: Paolo Bonzini <address@hidden>
Cc: Richard Henderson <address@hidden>
Cc: Eduardo Habkost <address@hidden>
Signed-off-by: Brijesh Singh <address@hidden>
---
accel/kvm/kvm-all.c | 2 ++
stubs/sev.c | 5 +++++
target/i386/sev.c | 43 +++++++++++++++++++++++++++++++++++++++++++
target/i386/trace-events | 1 +
4 files changed, 51 insertions(+)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 4468c8fe002c..4974c00c46fb 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -1679,6 +1679,8 @@ static int kvm_init(MachineState *ms)
if (!kvm_state->memcrypt_handle) {
goto err;
}
+
+ kvm_state->memcrypt_encrypt_data = sev_encrypt_data;
}
ret = kvm_arch_init(ms, s);
diff --git a/stubs/sev.c b/stubs/sev.c
index 4a5cc5569e5f..2e20f3b73a5b 100644
--- a/stubs/sev.c
+++ b/stubs/sev.c
@@ -15,6 +15,11 @@
#include "qemu-common.h"
#include "sysemu/sev.h"
+int sev_encrypt_data(void *handle, uint8_t *ptr, uint64_t len)
+{
+ return 1;
+}
+
void *sev_guest_init(const char *id)
{
return NULL;
diff --git a/target/i386/sev.c b/target/i386/sev.c
index b867ffbc0eae..a25722bdb934 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -100,6 +100,13 @@ fw_error_to_str(int code)
return sev_fw_errlist[code];
}
+static bool
+sev_check_state(SevState state)
+{
+ assert(sev_state);
+ return sev_state->state == state ? true : false;
+}
+
static void
sev_set_guest_state(SevState new_state)
{
@@ -480,6 +487,29 @@ sev_launch_start(SEVState *s)
return 0;
}
+static int
+sev_launch_update_data(uint8_t *addr, uint64_t len)
+{
+ int ret, fw_error;
+ struct kvm_sev_launch_update_data update;
+
+ if (!addr || !len) {
+ return 1;
+ }
+
+ update.uaddr = (__u64)addr;
+ update.len = len;
+ trace_kvm_sev_launch_update_data(addr, len);
+ ret = sev_ioctl(sev_state->sev_fd, KVM_SEV_LAUNCH_UPDATE_DATA,
+ &update, &fw_error);
+ if (ret) {
+ error_report("%s: LAUNCH_UPDATE ret=%d fw_error=%d '%s'",
+ __func__, ret, fw_error, fw_error_to_str(fw_error));
+ }
+
+ return ret;
+}
+
void *
sev_guest_init(const char *id)
{
@@ -568,6 +598,19 @@ err:
return NULL;
}
+int
+sev_encrypt_data(void *handle, uint8_t *ptr, uint64_t len)
+{
+ assert(handle);
+
+ /* if SEV is in update state then encrypt the data else do nothing */
+ if (sev_check_state(SEV_STATE_LUPDATE)) {
+ return sev_launch_update_data(ptr, len);
+ }
+
+ return 0;
+}
+
static void
sev_register_types(void)
{
diff --git a/target/i386/trace-events b/target/i386/trace-events
index 9402251e9991..c0cd8e93217f 100644
--- a/target/i386/trace-events
+++ b/target/i386/trace-events
@@ -12,3 +12,4 @@ kvm_memcrypt_register_region(void *addr, size_t len) "addr %p
len 0x%lu"
kvm_memcrypt_unregister_region(void *addr, size_t len) "addr %p len 0x%lu"
kvm_sev_change_state(const char *old, const char *new) "%s -> %s"
kvm_sev_launch_start(int policy, void *session, void *pdh) "policy 0x%x
session %p pdh %p"
+kvm_sev_launch_update_data(void *addr, uint64_t len) "addr %p len 0x%" PRIu64
--
2.14.3
- [Qemu-devel] [PATCH v10 09/28] qmp: add query-sev command, (continued)
- [Qemu-devel] [PATCH v10 09/28] qmp: add query-sev command, Brijesh Singh, 2018/02/28
- [Qemu-devel] [PATCH v10 10/28] include: add psp-sev.h header file, Brijesh Singh, 2018/02/28
- [Qemu-devel] [PATCH v10 08/28] target/i386: add Secure Encrypted Virtulization (SEV) object, Brijesh Singh, 2018/02/28
- [Qemu-devel] [PATCH v10 07/28] docs: add AMD Secure Encrypted Virtualization (SEV), Brijesh Singh, 2018/02/28
- [Qemu-devel] [PATCH v10 13/28] kvm: introduce memory encryption APIs, Brijesh Singh, 2018/02/28
- [Qemu-devel] [PATCH v10 17/28] target/i386: encrypt bios rom, Brijesh Singh, 2018/02/28
- [Qemu-devel] [PATCH v10 19/28] sev/i386: finalize the SEV guest launch flow, Brijesh Singh, 2018/02/28
- [Qemu-devel] [PATCH v10 12/28] sev/i386: register the guest memory range which may contain encrypted data, Brijesh Singh, 2018/02/28
- [Qemu-devel] [PATCH v10 11/28] sev/i386: add command to initialize the memory encryption context, Brijesh Singh, 2018/02/28
- [Qemu-devel] [PATCH v10 14/28] hmp: add 'info sev' command, Brijesh Singh, 2018/02/28
- [Qemu-devel] [PATCH v10 16/28] sev/i386: add command to encrypt guest memory region,
Brijesh Singh <=
- [Qemu-devel] [PATCH v10 24/28] sev/i386: add migration blocker, Brijesh Singh, 2018/02/28
- [Qemu-devel] [PATCH v10 21/28] sev/i386: add debug encrypt and decrypt commands, Brijesh Singh, 2018/02/28
- [Qemu-devel] [PATCH v10 15/28] sev/i386: add command to create launch memory encryption context, Brijesh Singh, 2018/02/28
- [Qemu-devel] [PATCH v10 22/28] target/i386: clear C-bit when walking SEV guest page table, Brijesh Singh, 2018/02/28
- [Qemu-devel] [PATCH v10 18/28] sev/i386: add support to LAUNCH_MEASURE command, Brijesh Singh, 2018/02/28
- [Qemu-devel] [PATCH v10 20/28] hw/i386: set ram_debug_ops when memory encryption is enabled, Brijesh Singh, 2018/02/28
- [Qemu-devel] [PATCH v10 23/28] qmp: add query-sev-launch-measure command, Brijesh Singh, 2018/02/28
- [Qemu-devel] [PATCH v10 25/28] cpu/i386: populate CPUID 0x8000_001F when SEV is active, Brijesh Singh, 2018/02/28
- [Qemu-devel] [PATCH v10 26/28] qmp: add query-sev-capabilities command, Brijesh Singh, 2018/02/28
- [Qemu-devel] [PATCH v10 28/28] tests/qmp-test: blacklist sev specific qmp commands, Brijesh Singh, 2018/02/28