Skip to content

Commit

Permalink
kvm: add memory encryption context
Browse files Browse the repository at this point in the history
Split from a patch by Brijesh Singh ([email protected]).

Signed-off-by: Paolo Bonzini <[email protected]>
Signed-off-by: Brijesh Singh <[email protected]>
  • Loading branch information
codomania authored and bonzini committed Mar 13, 2018
1 parent 9b02f7b commit b20e378
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 2 deletions.
2 changes: 1 addition & 1 deletion accel/Makefile.objs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
obj-$(CONFIG_SOFTMMU) += accel.o
obj-y += kvm/
obj-$(CONFIG_KVM) += kvm/
obj-$(CONFIG_TCG) += tcg/
obj-y += stubs/
3 changes: 2 additions & 1 deletion accel/kvm/Makefile.objs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
obj-$(CONFIG_KVM) += kvm-all.o
obj-y += kvm-all.o
obj-$(call lnot,$(CONFIG_SEV)) += sev-stub.o
25 changes: 25 additions & 0 deletions accel/kvm/kvm-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "qemu/event_notifier.h"
#include "trace.h"
#include "hw/irq.h"
#include "sysemu/sev.h"

#include "hw/boards.h"

Expand Down Expand Up @@ -103,6 +104,9 @@ struct KVMState
#endif
KVMMemoryListener memory_listener;
QLIST_HEAD(, KVMParkedVcpu) kvm_parked_vcpus;

/* memory encryption */
void *memcrypt_handle;
};

KVMState *kvm_state;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions accel/kvm/sev-stub.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* QEMU SEV stub
*
* Copyright Advanced Micro Devices 2018
*
* Authors:
* Brijesh Singh <[email protected]>
*
* 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;
}
5 changes: 5 additions & 0 deletions accel/stubs/kvm-stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
9 changes: 9 additions & 0 deletions include/sysemu/kvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
20 changes: 20 additions & 0 deletions include/sysemu/sev.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* QEMU Secure Encrypted Virutualization (SEV) support
*
* Copyright: Advanced Micro Devices, 2016-2018
*
* Authors:
* Brijesh Singh <[email protected]>
*
* 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

0 comments on commit b20e378

Please sign in to comment.