[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 06/22] kvm: introduce memory encryption APIs
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 06/22] kvm: introduce memory encryption APIs |
Date: |
Tue, 13 Mar 2018 13:56:22 +0100 |
From: Brijesh Singh <address@hidden>
Inorder to integerate the Secure Encryption Virtualization (SEV) support
add few high-level memory encryption APIs which can be used for encrypting
the guest memory region.
Cc: Paolo Bonzini <address@hidden>
Cc: address@hidden
Signed-off-by: Brijesh Singh <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
accel/kvm/kvm-all.c | 14 ++++++++++++++
accel/kvm/sev-stub.c | 5 +++++
accel/stubs/kvm-stub.c | 5 +++++
include/sysemu/kvm.h | 8 ++++++++
include/sysemu/sev.h | 1 +
5 files changed, 33 insertions(+)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index e0e43fd..ffee68e 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -107,6 +107,7 @@ struct KVMState
/* memory encryption */
void *memcrypt_handle;
+ int (*memcrypt_encrypt_data)(void *handle, uint8_t *ptr, uint64_t len);
};
KVMState *kvm_state;
@@ -151,6 +152,17 @@ bool kvm_memcrypt_enabled(void)
return false;
}
+int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len)
+{
+ if (kvm_state->memcrypt_handle &&
+ kvm_state->memcrypt_encrypt_data) {
+ return kvm_state->memcrypt_encrypt_data(kvm_state->memcrypt_handle,
+ ptr, len);
+ }
+
+ return 1;
+}
+
static KVMSlot *kvm_get_free_slot(KVMMemoryListener *kml)
{
KVMState *s = kvm_state;
@@ -1659,6 +1671,8 @@ static int kvm_init(MachineState *ms)
ret = -1;
goto err;
}
+
+ kvm_state->memcrypt_encrypt_data = sev_encrypt_data;
}
ret = kvm_arch_init(ms, s);
diff --git a/accel/kvm/sev-stub.c b/accel/kvm/sev-stub.c
index 4a5cc55..4f97452 100644
--- a/accel/kvm/sev-stub.c
+++ b/accel/kvm/sev-stub.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)
+{
+ abort();
+}
+
void *sev_guest_init(const char *id)
{
return NULL;
diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c
index f83192d..02d5170 100644
--- a/accel/stubs/kvm-stub.c
+++ b/accel/stubs/kvm-stub.c
@@ -110,6 +110,11 @@ bool kvm_memcrypt_enabled(void)
return false;
}
+int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len)
+{
+ return 1;
+}
+
#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 84017a0..23669c4 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -239,6 +239,14 @@ bool kvm_arm_supports_user_irq(void);
*/
bool kvm_memcrypt_enabled(void);
+/**
+ * kvm_memcrypt_encrypt_data: encrypt the memory range
+ *
+ * Return: 1 failed to encrypt the range
+ * 0 succesfully encrypted memory region
+ */
+int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len);
+
#ifdef NEED_CPU_H
#include "cpu.h"
diff --git a/include/sysemu/sev.h b/include/sysemu/sev.h
index f7a6057..98c1ec8 100644
--- a/include/sysemu/sev.h
+++ b/include/sysemu/sev.h
@@ -17,4 +17,5 @@
#include "sysemu/kvm.h"
void *sev_guest_init(const char *id);
+int sev_encrypt_data(void *handle, uint8_t *ptr, uint64_t len);
#endif
--
1.8.3.1
- [Qemu-devel] [PULL 00/22] KVM patches for QEMU 2.12 soft freeze, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 03/22] machine: add memory-encryption option, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 02/22] KVM: x86: Add support for save/load MSR_SMI_COUNT, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 04/22] docs: add AMD Secure Encrypted Virtualization (SEV), Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 05/22] kvm: add memory encryption context, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 06/22] kvm: introduce memory encryption APIs,
Paolo Bonzini <=
- [Qemu-devel] [PULL 01/22] update Linux headers to 4.16-rc5, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 09/22] include: add psp-sev.h header file, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 07/22] target/i386: add Secure Encrypted Virtualization (SEV) object, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 13/22] sev/i386: add command to encrypt guest memory region, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 11/22] sev/i386: register the guest memory range which may contain encrypted data, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 08/22] sev/i386: qmp: add query-sev command, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 12/22] sev/i386: add command to create launch memory encryption context, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 10/22] sev/i386: add command to initialize the memory encryption context, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 14/22] target/i386: encrypt bios rom, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 15/22] sev/i386: add support to LAUNCH_MEASURE command, Paolo Bonzini, 2018/03/13