qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH v4 16/20] sev: add DEBUG_ENCRYPT command


From: Brijesh Singh
Subject: [Qemu-devel] [RFC PATCH v4 16/20] sev: add DEBUG_ENCRYPT command
Date: Wed, 8 Mar 2017 15:53:59 -0500
User-agent: StGit/0.17.1-dirty

The command is used to encrypt a region of guest memory for debug.

The command will be used by gdbserver when writing the data into guest
memory for debug purposes (e.g setting breakpoint)

A typical usage looks like:
 cpu_memory_rw_debug
   cpu_physical_memory_rw_debug_internal
     sev_debug_encrypt

Signed-off-by: Brijesh Singh <address@hidden>
---
 sev.c |   39 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)

diff --git a/sev.c b/sev.c
index f8d822d..52b75e3 100644
--- a/sev.c
+++ b/sev.c
@@ -350,16 +350,49 @@ err:
 }
 
 static int
+sev_debug_encrypt(SEVState *s, uint8_t *dst, const uint8_t *src, uint32_t len)
+{
+    int ret, error;
+    struct kvm_sev_dbg *dbg;
+
+    if (!s) {
+        return 1;
+    }
+
+    dbg = g_malloc0(sizeof(*dbg));
+    if (!dbg) {
+        return 1;
+    }
+
+    dbg->src_addr = (unsigned long)src;
+    dbg->dst_addr = (unsigned long)dst;
+    dbg->length = len;
+
+    ret = sev_ioctl(KVM_SEV_DBG_ENCRYPT, dbg, &error);
+    if (ret) {
+        fprintf(stderr, "failed DBG_ENCRYPT %d (%#x)\n", ret, error);
+        goto err;
+    }
+
+err:
+    g_free(dbg);
+
+    return ret;
+}
+
+static int
 sev_mem_write(uint8_t *dst, const uint8_t *src, uint32_t len, MemTxAttrs attrs)
 {
     SEVState *s = kvm_memcrypt_get_handle();
 
-    if (sev_get_current_state(s) == SEV_STATE_LAUNCHING) {
+    if (attrs.debug) {
+        return sev_debug_encrypt(s, dst, src, len);
+    } else if (sev_get_current_state(s) == SEV_STATE_LAUNCHING) {
         memcpy(dst, src, len);
         return sev_launch_update_data(s, dst, len);
+    } else {
+        return 1;
     }
-
-    return 1;
 }
 
 static int




reply via email to

[Prev in Thread] Current Thread [Next in Thread]