[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v7 12/26] kvm: introduce memory encryption APIs
From: |
Brijesh Singh |
Subject: |
[Qemu-devel] [PATCH v7 12/26] kvm: introduce memory encryption APIs |
Date: |
Wed, 7 Feb 2018 10:06:24 -0600 |
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>
---
accel/kvm/kvm-all.c | 30 ++++++++++++++++++++++++++++++
accel/stubs/kvm-stub.c | 14 ++++++++++++++
include/sysemu/kvm.h | 25 +++++++++++++++++++++++++
3 files changed, 69 insertions(+)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 6e5f3fd65066..f1fb826f0648 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -107,6 +107,8 @@ struct KVMState
/* memory encryption */
void *memcrypt_handle;
+ int (*memcrypt_encrypt_data)(void *handle, uint8_t *ptr, uint64_t len);
+ void (*memcrypt_debug_ops)(void *handle, MemoryRegion *mr);
};
KVMState *kvm_state;
@@ -142,6 +144,34 @@ 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;
+}
+
+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;
+}
+
+void kvm_memcrypt_set_debug_ops(MemoryRegion *mr)
+{
+ if (kvm_state->memcrypt_handle &&
+ kvm_state->memcrypt_debug_ops) {
+ kvm_state->memcrypt_debug_ops(kvm_state->memcrypt_handle, mr);
+ }
+}
+
static KVMSlot *kvm_get_free_slot(KVMMemoryListener *kml)
{
KVMState *s = kvm_state;
diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c
index bb78a1f1b950..e7d579e3e54f 100644
--- a/accel/stubs/kvm-stub.c
+++ b/accel/stubs/kvm-stub.c
@@ -133,6 +133,20 @@ void sev_get_policy(uint32_t *policy)
{
}
+bool kvm_memcrypt_enabled(void)
+{
+ return false;
+}
+
+int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len)
+{
+ return 1;
+}
+
+void kvm_memcrypt_set_debug_ops(MemoryRegion *mr)
+{
+}
+
#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 bbf12a172339..4a5db5dde390 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -231,6 +231,31 @@ 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);
+
+/**
+ * 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);
+
+/**
+ * kvm_memcrypt_set_debug_ram_ops: set debug_ram_ops callback
+ *
+ * When debug_ram_ops is set, debug access to this memory region will use
+ * memory encryption APIs.
+ */
+void kvm_memcrypt_set_debug_ops(MemoryRegion *mr);
+
+
#ifdef NEED_CPU_H
#include "cpu.h"
--
2.14.3
- Re: [Qemu-devel] [PATCH v7 13/26] qmp: add query-sev command, (continued)
- [Qemu-devel] [PATCH v7 14/26] hmp: add 'info sev' command, Brijesh Singh, 2018/02/07
- [Qemu-devel] [PATCH v7 17/26] target/i386: encrypt bios rom, Brijesh Singh, 2018/02/07
- [Qemu-devel] [PATCH v7 19/26] sev: Finalize the SEV guest launch flow, Brijesh Singh, 2018/02/07
- [Qemu-devel] [PATCH v7 22/26] target/i386: clear C-bit when walking SEV guest page table, Brijesh Singh, 2018/02/07
- [Qemu-devel] [PATCH v7 16/26] sev: add command to encrypt guest memory region, Brijesh Singh, 2018/02/07
- [Qemu-devel] [PATCH v7 15/26] sev: add command to create launch memory encryption context, Brijesh Singh, 2018/02/07
- [Qemu-devel] [PATCH v7 18/26] sev: add support to LAUNCH_MEASURE command, Brijesh Singh, 2018/02/07
- [Qemu-devel] [PATCH v7 20/26] hw: i386: set ram_debug_ops when memory encryption is enabled, Brijesh Singh, 2018/02/07
- [Qemu-devel] [PATCH v7 12/26] kvm: introduce memory encryption APIs,
Brijesh Singh <=
- [Qemu-devel] [PATCH v7 21/26] sev: add debug encrypt and decrypt commands, Brijesh Singh, 2018/02/07
- [Qemu-devel] [PATCH v7 23/26] include: add psp-sev.h header file, Brijesh Singh, 2018/02/07
- [Qemu-devel] [PATCH v7 25/26] sev: add support to KVM_SEV_GUEST_STATUS, Brijesh Singh, 2018/02/07
- [Qemu-devel] [PATCH v7 26/26] qmp: add query-sev-launch-measure command, Brijesh Singh, 2018/02/07