49812da5a8
- Add AMD SEV (Secure Encrypted Virtualization) support by taking the v7 series of the patches posted to qemu ml. (fate#322124) - Update python3 related patches now that they are upstream OBS-URL: https://build.opensuse.org/request/show/574394 OBS-URL: https://build.opensuse.org/package/show/Virtualization/qemu?expand=0&rev=390
95 lines
3.0 KiB
Diff
95 lines
3.0 KiB
Diff
From 127890da09ac0ebb4945f52b0e23e582d93fc698 Mon Sep 17 00:00:00 2001
|
|
From: Brijesh Singh <brijesh.singh@amd.com>
|
|
Date: Tue, 6 Feb 2018 19:08:09 -0600
|
|
Subject: [PATCH] sev: register the guest memory range which may contain
|
|
encrypted data
|
|
|
|
When SEV is enabled, the hardware encryption engine uses a tweak such
|
|
that the two identical plaintext at different location will have a
|
|
different ciphertexts. So swapping or moving a ciphertexts of two guest
|
|
pages will not result in plaintexts being swapped. Hence relocating
|
|
a physical backing pages of the SEV guest will require some additional
|
|
steps in KVM driver. The KVM_MEMORY_ENCRYPT_{UN,}REG_REGION ioctl can be
|
|
used to register/unregister the guest memory region which may contain the
|
|
encrypted data. KVM driver will internally handle the relocating physical
|
|
backing pages of registered memory regions.
|
|
|
|
Cc: Paolo Bonzini <pbonzini@redhat.com>
|
|
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
|
|
[BR: FATE#322124]
|
|
Signed-off-by: Bruce Rogers <brogers@suse.com>
|
|
---
|
|
accel/kvm/sev.c | 41 +++++++++++++++++++++++++++++++++++++++++
|
|
accel/kvm/trace-events | 2 ++
|
|
2 files changed, 43 insertions(+)
|
|
|
|
diff --git a/accel/kvm/sev.c b/accel/kvm/sev.c
|
|
index d5fd975792..2c4bbba3c3 100644
|
|
--- a/accel/kvm/sev.c
|
|
+++ b/accel/kvm/sev.c
|
|
@@ -86,6 +86,45 @@ fw_error_to_str(int code)
|
|
return sev_fw_errlist[code];
|
|
}
|
|
|
|
+static void
|
|
+sev_ram_block_added(RAMBlockNotifier *n, void *host, size_t size)
|
|
+{
|
|
+ int r;
|
|
+ struct kvm_enc_region range;
|
|
+
|
|
+ range.addr = (__u64)host;
|
|
+ range.size = size;
|
|
+
|
|
+ trace_kvm_memcrypt_register_region(host, size);
|
|
+ r = kvm_vm_ioctl(kvm_state, KVM_MEMORY_ENCRYPT_REG_REGION, &range);
|
|
+ if (r) {
|
|
+ error_report("%s: failed to register region (%p+%#lx)",
|
|
+ __func__, host, size);
|
|
+ }
|
|
+}
|
|
+
|
|
+static void
|
|
+sev_ram_block_removed(RAMBlockNotifier *n, void *host, size_t size)
|
|
+{
|
|
+ int r;
|
|
+ struct kvm_enc_region range;
|
|
+
|
|
+ range.addr = (__u64)host;
|
|
+ range.size = size;
|
|
+
|
|
+ trace_kvm_memcrypt_unregister_region(host, size);
|
|
+ r = kvm_vm_ioctl(kvm_state, KVM_MEMORY_ENCRYPT_UNREG_REGION, &range);
|
|
+ if (r) {
|
|
+ error_report("%s: failed to unregister region (%p+%#lx)",
|
|
+ __func__, host, size);
|
|
+ }
|
|
+}
|
|
+
|
|
+static struct RAMBlockNotifier sev_ram_notifier = {
|
|
+ .ram_block_added = sev_ram_block_added,
|
|
+ .ram_block_removed = sev_ram_block_removed,
|
|
+};
|
|
+
|
|
static void
|
|
qsev_guest_finalize(Object *obj)
|
|
{
|
|
@@ -360,6 +399,8 @@ sev_guest_init(const char *id)
|
|
}
|
|
|
|
sev_active = true;
|
|
+ ram_block_notifier_add(&sev_ram_notifier);
|
|
+
|
|
return s;
|
|
err:
|
|
g_free(s);
|
|
diff --git a/accel/kvm/trace-events b/accel/kvm/trace-events
|
|
index ea487e5a59..364c84bd7a 100644
|
|
--- a/accel/kvm/trace-events
|
|
+++ b/accel/kvm/trace-events
|
|
@@ -15,3 +15,5 @@ kvm_irqchip_release_virq(int virq) "virq %d"
|
|
|
|
# sev.c
|
|
kvm_sev_init(void) ""
|
|
+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"
|