From patchwork Wed Mar 8 20:53:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9612021 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8245460414 for ; Wed, 8 Mar 2017 21:39:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7465F2862A for ; Wed, 8 Mar 2017 21:39:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6905028635; Wed, 8 Mar 2017 21:39:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3A90F2862E for ; Wed, 8 Mar 2017 21:39:27 +0000 (UTC) Received: from localhost ([::1]:58583 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cljIs-0000Ll-4u for patchwork-qemu-devel@patchwork.kernel.org; Wed, 08 Mar 2017 16:39:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52518) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clj7J-0007Fi-DO for qemu-devel@nongnu.org; Wed, 08 Mar 2017 16:27:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clj7G-0005r6-7j for qemu-devel@nongnu.org; Wed, 08 Mar 2017 16:27:29 -0500 Received: from mail-by2nam03on0072.outbound.protection.outlook.com ([104.47.42.72]:32926 helo=NAM03-BY2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clj7F-0005qp-Sf for qemu-devel@nongnu.org; Wed, 08 Mar 2017 16:27:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=DCzyZFXt/zbBI32ryHXrKLLl8j9Tfudu4yv0lLhr4Ic=; b=5S1rQtj2gMPr66w57RXRhjP6HeOaKnhC86SQsd6/2fac9L0ufvasdUWJWorwc/2rNRm4Sy0RmCusuqSwlJVB83WQT4Si7deQ6MI/T3swEJrZJqwJwUi+yreM0MQ0tWB/TF1uFsxxCx1kA4ilidUZ3XJtY10QrIrS3jaV6YLO2cI= Authentication-Results: amd.com; dkim=none (message not signed) header.d=none;amd.com; dmarc=none action=none header.from=amd.com; Received: from [127.0.1.1] (165.204.77.1) by DM5PR12MB1609.namprd12.prod.outlook.com (10.172.40.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.947.12; Wed, 8 Mar 2017 20:53:52 +0000 From: Brijesh Singh To: , , , , , , , , Date: Wed, 8 Mar 2017 15:53:49 -0500 Message-ID: <148900642968.27090.13322958747245445508.stgit@brijesh-build-machine> In-Reply-To: <148900626714.27090.1616990932333159904.stgit@brijesh-build-machine> References: <148900626714.27090.1616990932333159904.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR17CA0029.namprd17.prod.outlook.com (10.175.189.15) To DM5PR12MB1609.namprd12.prod.outlook.com (10.172.40.15) X-MS-Office365-Filtering-Correlation-Id: d9117859-bbee-4012-ab27-08d466653b34 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:DM5PR12MB1609; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1609; 3:P23zCkIBldgsZRyWVLvezdLSGT8f2uYMFUSWYKSJdNHX3rAHAfdT61IobWTWAqk5+0yh962nHsKmKocJI9PxWgRKATztFRL89/V5L67+86dtIRK7nzJMD0YNdOKmczabDyrV17Ty65gaAMEwVmaLtoYPKdhVRCxfe7Eg7I/MSyr1X12WkPmmSN/k76JfjFUri9uUIjRqvS63JT+nrreF6FlkHrHonJjiz5ooTO45dOcYp2H3f9GeHOnPamrEw6oNX4YZjZ9zBAG8cVZoQ1R0ii9ve3OnjBKBlDmXqUgKwgM=; 25:u3XZnv7RGl1gmrWF6F18wnua5tcaPKKrH8e8fjE2pbpdLxzthM3LjHnxJSh6IF/CMan0NTuJSiG7psAjvOGEvIOdf0acLD0cNVk3JDCXKE/YtzEJicfRwc2XhG9hygofftna3Y6VAJWZk3IQHFSgiznBSffYtCR60MYncZmY/xt/ofJs44JH9zx99XncEiNrmo0q1UrUwEKvJbDs1lBQUFmgNvYNWmjIP0up0XrkBirS92v2Fjm5nPfbtZwDcjv7UjjZ6iwtuVjEByqfalKWDabnPrtUEU00jSIOEseO7sCcGKmi6NfV60XbQZb3iUrgjmegvH5EKIux/mUzF7LqRDUhMFexuxiNFGQHWl40tJUfzrAdwJo2dIvRb1tNfrmJbF4tTBLKsP4vl8vKhJEa4nutD21SUPb6tVlGjGhUoYDdumwFP0PVZI/y6b/d84dq/gEnSj1fOAqF5IFlTnc+mQ== X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1609; 31:edysrPv38XjlOZ2g0ySWPTOYddoIrAkSW32A5oUpGOWFWCk5gJuZicoSdtx11xo6PYRovX8QK6dfeepT5Pq3uru8Is4vYF0U5L0uw/Ui5d6Ub6sisoRwRH9jqQfr+Ydn48AWLmdbioiTq22SEV/PNECggdGs7T7Yoq9hoKogcUx5goESKJ8KdmFlQbOt6gjZ+ghnAhyhcstTh6PQnLB2FliTaC3N9jqoXA8cjWK2U3M=; 20:txVtmm2Og4arxf0vWoZW2QCyVIPe+Hka0QSaBdMSGjKLbxy03xx03/WyTtCM75vGNzU6BZ7bNUy6qBLvfLMLEvir/SWfqKGpTWfh7Cq0wubp02T+jWaJ+cTJ3EHdeVrDZSGDj3mZ7n/Yzu/zq62rW/Uk3yVlaeJbHkB6vBj767MwhBS7ySrsfk1Ck1IDtE8uUtv5dEDcMm0BD0H7v75DD/5M0578Z3INeaTgxC/Nr7dRKSsRyDYkV8IB+N8pTflzPp3blpLAceK2CVJxOsaHbMdrCuFIHyzM71EzYwLyWleKx3uwFtYkwOxVG+s3IMem4tUwWKC1WK//diScwdivDDq8rR3Um+uuv4P2ql9YxZ8DaTGgSy8UjXwUqxoOwxNbSsH+snKWia1+vnwfZd0lO5+suUeC7/+F7weLxGzTqBBluVz0glu/5iNjv9pdfXwcBK6zw/rqeNvceAjh5RbiRJBH0GBJpka4RLpbXgFoQlUI8oDFn9416EdI0W5DL8b1 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026)(6041248)(20161123555025)(20161123560025)(20161123558025)(20161123562025)(20161123564025)(6072148); SRVR:DM5PR12MB1609; BCL:0; PCL:0; RULEID:; SRVR:DM5PR12MB1609; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1609; 4:RjCDlAuViut91ngrd8Vqd7PdTaQkBKZzW1B7DohgtkvNfZsMucwFNOsaAISwK60ae2d+O4ATobuKU/7yk1YUOOWJQKX6UZQ9lQxUPP0nGG1i6vHw6lR4uk9H21nvuiikxeY6au25+TsIu4Pppk/LTpAwy2IfdOrnOB4ErYKguKMYqqGEBjW2HrZ9p8OFxtA78P7Y6lhzENJRvYBogSpMcOhhB6/dPaLpK9n5+rn91GdeQ8i2P0NQSgwtCuRpeiRWSX6/NobtUSHLE594OLZ8oUkJSLb5dpjp+jc3EeVtQT13nUOvl1PyZ8NtfEYTyJpbUr0wnXoJBzlfJK5XTO+gPtbiEERPWpzS0npTRso3gQUAP6IjwWADdJXYpqfHmateY05zGtMco3cY3dVTwIq2dwVwPucwBp+xWFCmTGeleioG5J2+4sRXIYDc7dpQZrsTTjMQIdvcH/2rv0gdybGW6BefIob5LfI57atWb+XQo8YGiH906uCIqQ2UTdSzeMZrEfHNMr3iFFx5uVARcgXob0irwKcpamc/hCCv8sjfpzdTs7wS+R+jw0tZpM4jPAjIFJFWkmkdYxdhIa7fM+MtDXVPfqc6C1DAxyLkOETcm5fqIvMzGV3MoBG2oR1gVzVbILqjQrsa6zVCdNe1GoPuCkX7XE9naWaCmC4fDgRYdss= X-Forefront-PRVS: 02408926C4 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6049001)(6009001)(39840400002)(39450400003)(39850400002)(39860400002)(39410400002)(189998001)(230700001)(9686003)(33646002)(6486002)(66066001)(83506001)(2950100002)(90366009)(3846002)(6666003)(4326008)(42186005)(38730400002)(33716001)(23676002)(54356999)(8676002)(76176999)(6116002)(54906002)(2201001)(103116003)(7736002)(50986999)(53936002)(86362001)(305945005)(81166006)(77096006)(25786008)(50466002)(2906002)(47776003)(5660300001)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB1609; H:[127.0.1.1]; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTVQUjEyTUIxNjA5OzIzOm1rUlAvcVd2MThJUGI5THM5TnRNRjVQejFB?= =?utf-8?B?SkdlTytQbmVFdDI0cytwYWh0MlY3NitDd0tta0tBK29ROEdqNldoS25qSVNX?= =?utf-8?B?Vm5RMTk5cW1CMzFJcm9ybDNDZkJORld6K1hSV1RKbm5JZzhlW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QLAq0SoyhWD3d6A5hxOyWaHNCliC0rSgeCi4UZyewgxPVdyvCHn6PWEnndVwx2lv5fY4jIKq3DCpQfddKW7mI+tuYYUwI+h+8eGYioQCBCOiMe4Yj/GjHs6Di79sK7fM6W8BjWk=; 24:t2Jpsm8wFc9dlTLkZth14lBfKh38hPUagGftyQU8bnzkV4Ixp7TSMqre4Li0O2qSPCWcjS4/EBmzzGV6u4rHyzqtBFMqpsm+tHtKQVZP+U8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1609; 7:hvt5bno9Q9TCigi26e/WScgruN5khKNv824Zbfvw9NC+mbToWBENwpCFDjTqP2plHm269FrF//aj86TH/8aiTuIv7KlyznhDxMoOJc6WHxOqsxs9FSEA2MzQhEZP9AS9yDjaqHvtBHAZYdeFrGm2nsJ5+7FLk2uhai53won6FGtvgBXPEiv6rIGt3aPqXkBwuymbjSiYcw56pfZy+WzS9EXpa6I/FrVECNs70jUsTOJJHxrYrGqKCUlildHkBxmKpc33GuXsKkDgUUbwBrMFrgBuAiZb8yJRoJJ0lwK+tmSEaMqd9jsvdODvQCP3hx61WPDN7mf/JUCOSXqo+7Vn+w==; 20:xct4F4gXFwJQDrNxCgRsJj/muLteF4u7ah02lJ7kmprStp5mimhP8i1NjcoKiX68QElz3pzzefWW7mcw9BDxalmf9XQkNu/dCGSO/BjRxV+vBvur4+R6+YTmUa7XphAVUvVc5OIUopuKhm6g/f0LpxDrs6fI0B5u6tLDeN2fHxPiDmcBDqpJ/Gh0zQIlPUROWKXgs958vknJjTk+f8P2NhAyrXNPDAN2kM73SqaoV/m+LaVrMzgAGc89QgPwcUKl X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2017 20:53:52.7276 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1609 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.42.72 Subject: [Qemu-devel] [RFC PATCH v4 15/20] sev: add DEBUG_DECRYPT command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas.Lendacky@amd.com, brijesh.singh@amd.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The command is used to decrypt a page of guest memory for debug. The command will be used by qemu monitor dump and gdbserver to access the guest memory for debug purposes. A typical usage look like: cpu_physical_memory_rw_debug cpu_physical_memory_rw_debug_internal sev_debug_decrypt Signed-off-by: Brijesh Singh --- sev.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/sev.c b/sev.c index d32391e..f8d822d 100644 --- a/sev.c +++ b/sev.c @@ -320,6 +320,36 @@ err_1: } static int +sev_debug_decrypt(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_DECRYPT, dbg, &error); + if (ret) { + fprintf(stderr, "failed DBG_DECRYPT %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(); @@ -335,7 +365,11 @@ sev_mem_write(uint8_t *dst, const uint8_t *src, uint32_t len, MemTxAttrs attrs) static int sev_mem_read(uint8_t *dst, const uint8_t *src, uint32_t len, MemTxAttrs attrs) { - return 0; + SEVState *s = kvm_memcrypt_get_handle(); + + assert(attrs.debug); + + return sev_debug_decrypt(s, dst, src, len); } void *