[Qemu-devel] [PATCH 3/3] sev: Change SEV to use EncryptedRAMBlock Notifier

Natarajan, Janakarajan posted 3 patches 6 years, 9 months ago
[Qemu-devel] [PATCH 3/3] sev: Change SEV to use EncryptedRAMBlock Notifier
Posted by Natarajan, Janakarajan 6 years, 9 months ago
The EncryptedRAMBlock Notifier lets SEV know which guest RAM pages
will contain encrypted guest data.

Using this notifier lets SEV skip pinning pages that do not contain
encrypted data.

Signed-off-by: Janakarajan Natarajan <Janakarajan.Natarajan@amd.com>
---
 target/i386/sev.c | 25 ++++++++-----------------
 1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/target/i386/sev.c b/target/i386/sev.c
index cd77f6b5d4..610e992e64 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -127,21 +127,11 @@ sev_set_guest_state(SevState new_state)
 }
 
 static void
-sev_ram_block_added(RAMBlockNotifier *n, void *host, size_t size)
+sev_ram_block_encrypted_added(RAMBlockEncryptedNotifier *n,
+                              void *host, size_t size)
 {
     int r;
     struct kvm_enc_region range;
-    ram_addr_t offset;
-    MemoryRegion *mr;
-
-    /*
-     * The RAM device presents a memory region that should be treated
-     * as IO region and should not be pinned.
-     */
-    mr = memory_region_from_host(host, &offset);
-    if (mr && memory_region_is_ram_device(mr)) {
-        return;
-    }
 
     range.addr = (__u64)(unsigned long)host;
     range.size = size;
@@ -156,7 +146,8 @@ sev_ram_block_added(RAMBlockNotifier *n, void *host, size_t size)
 }
 
 static void
-sev_ram_block_removed(RAMBlockNotifier *n, void *host, size_t size)
+sev_ram_block_encrypted_removed(RAMBlockEncryptedNotifier *n,
+                                void *host, size_t size)
 {
     int r;
     struct kvm_enc_region range;
@@ -172,9 +163,9 @@ sev_ram_block_removed(RAMBlockNotifier *n, void *host, size_t size)
     }
 }
 
-static struct RAMBlockNotifier sev_ram_notifier = {
-    .ram_block_added = sev_ram_block_added,
-    .ram_block_removed = sev_ram_block_removed,
+static struct RAMBlockEncryptedNotifier sev_ram_encrypted_notifier = {
+    .ram_block_encrypted_added = sev_ram_block_encrypted_added,
+    .ram_block_encrypted_removed = sev_ram_block_encrypted_removed,
 };
 
 static void
@@ -794,7 +785,7 @@ sev_guest_init(const char *id)
         goto err;
     }
 
-    ram_block_notifier_add(&sev_ram_notifier);
+    ram_block_encrypted_notifier_add(&sev_ram_encrypted_notifier);
     qemu_add_machine_init_done_notifier(&sev_machine_done_notify);
     qemu_add_vm_change_state_handler(sev_vm_state_change, s);
 
-- 
2.20.1