From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54837) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjpX1-000438-T7 for qemu-devel@nongnu.org; Tue, 13 Sep 2016 11:22:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bjpWw-00019I-UX for qemu-devel@nongnu.org; Tue, 13 Sep 2016 11:21:55 -0400 Received: from mail-cys01nam02on0087.outbound.protection.outlook.com ([104.47.37.87]:4928 helo=NAM02-CY1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjpWw-00017w-Kh for qemu-devel@nongnu.org; Tue, 13 Sep 2016 11:21:50 -0400 From: Brijesh Singh Date: Tue, 13 Sep 2016 10:48:27 -0400 Message-ID: <147377810767.11859.4668503556528840901.stgit@brijesh-build-machine> In-Reply-To: <147377800565.11859.4411044563640180545.stgit@brijesh-build-machine> References: <147377800565.11859.4411044563640180545.stgit@brijesh-build-machine> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [RFC PATCH v1 10/22] sev: add SEV debug decrypt command List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: ehabkost@redhat.com, crosthwaite.peter@gmail.com, armbru@redhat.com, mst@redhat.com, p.fedin@samsung.com, qemu-devel@nongnu.org, lcapitulino@redhat.com, pbonzini@redhat.com, rth@twiddle.net The SEV DEBUG_DECRYPT command is used for decrypting a guest memory for the debugging purposes. Note that debugging is permitting only when guest policy allows it. For more information see [1], section 7.1 [1] http://support.amd.com/TechDocs/55766_SEV-KM%20API_Spec.pdf The following KVM RFC patches defines and implements this command http://marc.info/?l=kvm&m=147190852423972&w=2 http://marc.info/?l=kvm&m=147191068524579&w=2 Signed-off-by: Brijesh Singh --- include/sysemu/sev.h | 10 ++++++++++ sev.c | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/sysemu/sev.h b/include/sysemu/sev.h index ab03c5d..5872c3e 100644 --- a/include/sysemu/sev.h +++ b/include/sysemu/sev.h @@ -55,4 +55,14 @@ int kvm_sev_guest_finish(void); */ int kvm_sev_guest_measurement(uint8_t *measurement); +/** + * kvm_sev_dbg_decrypt - decrypt the guest memory for debugging purposes + * @src - guest memory address + * @dest - host memory address where the decrypted data should be copied + * @length - length of memory region + * + * Returns: 0 on success and dest will contains the decrypted data + */ +int kvm_sev_dbg_decrypt(uint8_t *dest, const uint8_t *src, uint32_t len); + #endif diff --git a/sev.c b/sev.c index 055ed83..c7031d3 100644 --- a/sev.c +++ b/sev.c @@ -432,3 +432,26 @@ int kvm_sev_guest_measurement(uint8_t *out) return 0; } + +int kvm_sev_dbg_decrypt(uint8_t *dst, const uint8_t *src, uint32_t len) +{ + int ret; + struct kvm_sev_dbg_decrypt decrypt; + struct kvm_sev_issue_cmd input; + + decrypt.src_addr = (unsigned long)src; + decrypt.dst_addr = (unsigned long)dst; + decrypt.length = len; + + input.cmd = KVM_SEV_DBG_DECRYPT; + input.opaque = (unsigned long)&decrypt; + ret = kvm_vm_ioctl(kvm_state, KVM_SEV_ISSUE_CMD, &input); + if (ret) { + fprintf(stderr, "SEV: dbg_decrypt failed ret=%d(%#010x)\n", + ret, input.ret_code); + return 1; + } + + DPRINTF("SEV: DBG_DECRYPT dst %p src %p sz %d\n", dst, src, len); + return 0; +}