From patchwork Tue Sep 13 14:48:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9329347 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 AA7AF6077F for ; Tue, 13 Sep 2016 15:52:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B2E3290FC for ; Tue, 13 Sep 2016 15:52:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8FE1229105; Tue, 13 Sep 2016 15:52:29 +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 5187D290FC for ; Tue, 13 Sep 2016 15:52:28 +0000 (UTC) Received: from localhost ([::1]:49764 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjq0Z-0004Na-EF for patchwork-qemu-devel@patchwork.kernel.org; Tue, 13 Sep 2016 11:52:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54834) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjpX1-00042v-MK for qemu-devel@nongnu.org; Tue, 13 Sep 2016 11:21:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bjpWw-00018q-JM for qemu-devel@nongnu.org; Tue, 13 Sep 2016 11:21:55 -0400 Received: from mail-co1nam03on0088.outbound.protection.outlook.com ([104.47.40.88]:46080 helo=NAM03-CO1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjpWw-00016e-8C for qemu-devel@nongnu.org; Tue, 13 Sep 2016 11:21:50 -0400 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=rF0FD0nl+1YB4wq9s+utjdDtcWDXlIW2GmXtkvvMLbw=; b=WmV4UpIv2G76NX35eQDVtOu17z3r9dZd4oIhoDMEKpMpwS7LJJrWRVqR2I4GS73o5tEabGsvaf8bxlsJk0VHxy93A3ZTaOeqYGMHDafp8P0HbtNTSmKhpCkQS00GuQ2VI7kOoqG9s3RfPmuDfu6a0t3/5mHOH7krcClxuaqyorc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from [127.0.1.1] (165.204.77.1) by SN1PR12MB0671.namprd12.prod.outlook.com (10.163.208.29) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.609.9; Tue, 13 Sep 2016 14:48:13 +0000 From: Brijesh Singh To: , , , , , , , , Date: Tue, 13 Sep 2016 10:48:09 -0400 Message-ID: <147377808948.11859.12953757350056951214.stgit@brijesh-build-machine> In-Reply-To: <147377800565.11859.4411044563640180545.stgit@brijesh-build-machine> References: <147377800565.11859.4411044563640180545.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN1PR17CA0001.namprd17.prod.outlook.com (10.169.33.139) To SN1PR12MB0671.namprd12.prod.outlook.com (10.163.208.29) X-MS-Office365-Filtering-Correlation-Id: 87d2b816-636b-47eb-ee0c-08d3dbe4fd4b X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0671; 2:IIfVi4fcsjhj35l4z6YMylDcpWspzy4qF0R+H5TM9AajduPRslOy2H1UcEslC9v/jQs6Xw3iMt/D8t7b7tF3VJyGs5IzrO0dLct5t8ERa77rRsQtJmbIk1XfPTRmoBFzza69nJjOWHdrs/zykeYVsHYYmBNluNq9D7n48khJQdgZcOfaRez/TXSwLr63Po8z; 3:gj7HAndyazjFv+i2xWsJrd8iXjYPqYX3GdgtkXFQ20o3Xc3xqjFtL4kUj6UviPnzLaTHachSFKh0lY/QIBOxDRi70RHmEGt/tkf8pPMLEjfLUXRXhQePl6clRF62vbA7 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN1PR12MB0671; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0671; 25:uGxq/Yd5DhE0mryTHHbmb9HXwf50lG/4uruq07VwAPMiofxNe29HGxUcNfgbP0QjBaSzvoypHUkJbOvRK45wvqmlg5WoJbKtwAlnWMU9jjaS77uXZTclzdS6FljGKGlFtAFettcKSOe/KbrDtwg66uMOC0Oan2a+oNEJspdrDCw+B73Bh8zH6EJWuldJbNwF9jFsHpHKhymI+ca4qQx/AkZZx+4n82gWFmuGahEmEv0Kongpm7lFJ/OcLE6HtWRPXOmsV3y9c+dtPcT9YsoB3kW5NlWy6rbZklpRnbZ6Lnbhl09Moyr+YleaooyV6gjWzwJIHcbMapUZD6vDCdcAeKU5W7nq7Veq6ikWGY06JkCzW5lb5I2HeToxi0845I7FQKnPnzQcJnuDmF7beHF/nBAxVUyLmELBowVcVCiQgHx16ZtX1UyMlQ85f1pN1eCnH27SpezFL0btSN0vgmUI9jJ065x0KfH9Ae07IXQrUYzVsp+QAwh5EY+fxlr+aRKmmjArE+xK81qgtyPuormMpSCqVRyyMqg9nIXqMiNZGvFqxyGz3f3Je0hLg7pVQDOsRaABBdrpzt/aZyPi6pQzOpdORsFwtO8zPKKx1KwUqYVAFSXZVoNLrumo4t+Of04fYxbP1zh3cjsq4QqTI1eR1vnZtvAFrJuuxZbWRd9abyN7GQ1PtgVmPru72rzNVGGbeU46cUaLVoowyw5juA+zdhlGocqAoalnMFigWpfvLD1AoBa/Gnj9qZ8H23MnwIzwd3lT8jhbD/odlEoVC9sNdpgK/MY8NLbYhIbIgKS82Oo= X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0671; 31:DD+sO1QcIZoRdLN/PzhYAdJVCfmqjgH7Ubo6xMCCArEa2TvPn2nZQLHgqwxgI/HonyBsrR5k5x63k0SahARw3e/Hr9AOBNCDULDzL96Y1KcFLUqJmENirfcmdQlw2ZgHweEZlBQogG7pRWOjd2sbkEqREmxkq70Tid1LFYLDRYEQoml0jviTdqlJY3yMmjEwK22MVNz8FfTibIwMT2Umx8951yxP45Ti9XReahv5XPc=; 20:jgWKpDxGyf0XtXDR+Iv2sxOgS9AeFmVtNtq0WdbEe3AgFEsu1aRj5raaff5onuYgBh/qOnhTiW9iUZOQKJjFLKgLFjBdPWEwQgsWuZclH1Qzty+YbYt0r814vFL4rhAaYkDOdRJV9sGZCN9RrH+gnbnsXFRKs3fuI7pmq/Ktj5v3U2GE5uV88nQ4vnkpY7asaCIYY3AlO7JBnaRyyzgEAW7b7cyQ+mH+P4fWHUDKbDSzH53Jz7Jvh20ajZZ4nd0QnDYV0VNPtzHx4aCsHfN0RgOb+lQ5I15vSH8jgc+I0BbLIbfdY1yUEYbGdT0d/Lmw2c/r2x6xqVGqq8EzOhmpldQwYlNR8GUFScIW9O4PZMIcZJkCHdhAqj9LyrkjTqwtHyW0/YeupeJj6kQ2VsxXrc2fD5WNV59+l7pOs8SqZVAY9iSmsIeT7fDVmA4P+FhqH2Nq40BPzeLgN2YgbO9J6tUWQHiDD8GKFNKvkevpD5iTFOsFoL0lw4QOYCESa3V6 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:SN1PR12MB0671; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0671; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0671; 4:XBM3lJ+WgCrr7LpIhm7x8UPWQeDXkZyI3kNCEjGjj5t/cioJtuCE47ENmRf56wqKSRWUuOWmfFHj9wIcN1VphAadUBp3wDU5ilJaW+nkrj4Q21OT52lFBAKerSn/rAvfd1omuyZUpFOEf+4gBEVpxbX80NkXY4YfYb5BuyuD/lPemd1nRb5NKnupxFquc0OKgNJD3mB1nIizlXPlBSOIoOlQ1Tb4GnkTML+MKIo2MB4k4u/1TzMDzjleRem9b1cdzeU2oGG2nCamzIVNHVUYYQaZd5z8Vs3HT6bChbxZEX5x6B2c+RKbvdFu79qPoWagT6vtUP0KwopdArZYvFk9NydCkwqjnrgtEJAjWz/KZJfLT7Ee2uzU1UmN6VnqREHoLz8MkGiqg9wBq0cUPn+7LnX4RxGcyYnnPcMRsB0r43oBp/oeYMPVS32kRPwWolm7 X-Forefront-PRVS: 0064B3273C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6049001)(6009001)(7916002)(209900001)(189002)(199003)(15975445007)(92566002)(97736004)(50466002)(66066001)(4001350100001)(5001770100001)(9686002)(47776003)(101416001)(2950100001)(5660300001)(19580395003)(19580405001)(54356999)(50986999)(76176999)(3846002)(229853001)(7736002)(230700001)(42186005)(103116003)(6116002)(586003)(106356001)(86362001)(105586002)(2201001)(305945005)(23676002)(15650500001)(8676002)(83506001)(81156014)(77096005)(33716001)(2420400007)(81166006)(107886002)(33646002)(15395725005)(7846002)(7110500001)(2906002)(10710500007)(68736007)(189998001)(217873001)(6606295002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0671; H:[127.0.1.1]; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: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ZzNd4b0C4Y/0dVtJlB30HkgTnifwiWBDTWrM8GAfSKQsEMnIuBiA9yDc SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0671; 20:4WefiIZxxX6ddEpJyvKcPa6sItJVqiiwPHvr03QiC2166sk9IKooskvT7W58sSXnIIIy+uolzTly7Img1XxzY5pSapG4c5vZu9PRU/SMZwHMWz3GZnWV67cbr24TUO1POq+aPLtSy4tjjg0BWOH3sE7Hx6pVKDe9EnqpbVrAoWQnzPLRtdDtCciKP6oyiRatTh1ZVww7luQzuH+kZLntguPoeDiMerQdmuinF1Oo6jbXPQwXQZDaUuwtYNWxJaYo X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2016 14:48:13.6128 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0671 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.40.88 X-Mailman-Approved-At: Tue, 13 Sep 2016 11:45:47 -0400 Subject: [Qemu-devel] [RFC PATCH v1 08/22] sev: add SEV launch update 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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The SEV LAUNCH_UPDATE command is used to encrypt the guest memory region. For more information see [1], section 6.2 [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=147190859023996&w=2 Signed-off-by: Brijesh Singh --- include/sysemu/sev.h | 9 +++++++++ sev.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/sysemu/sev.h b/include/sysemu/sev.h index b8a7afa..b58a9d7 100644 --- a/include/sysemu/sev.h +++ b/include/sysemu/sev.h @@ -30,5 +30,14 @@ int sev_init(KVMState *kvm_state); */ int kvm_sev_guest_start(void); +/** + * kvm_sev_guest_update - encrypt the memory region. + * @address: host virtual address of memory region (must be 16-byte aligned) + * @len: length of memory region (must be 16-byte aligned). + * + * Returns: 0 on success, or 1 on failure. + */ +int kvm_sev_guest_update(uint8_t *address, uint32_t len); + #endif diff --git a/sev.c b/sev.c index 40a126a..a451dc0 100644 --- a/sev.c +++ b/sev.c @@ -304,6 +304,28 @@ static int sev_launch_start(void) return 0; } +static int sev_launch_update(uint8_t *addr, uint32_t len) +{ + int ret; + SEVInfo *s = sev_info; + struct kvm_sev_issue_cmd input; + struct kvm_sev_launch_update *update = s->launch_update; + + update->address = (uint64_t) addr; + update->length = len; + input.cmd = KVM_SEV_LAUNCH_UPDATE; + input.opaque = (unsigned long)update; + ret = kvm_vm_ioctl(kvm_state, KVM_SEV_ISSUE_CMD, &input); + if (ret) { + fprintf(stderr, "SEV: launch_update failed ret=%d (%#010x)\n", + ret, input.ret_code); + exit(EXIT_FAILURE); + } + + DPRINTF("SEV: LAUNCH update [%#lx+0x%x]\n", (uint64_t)addr, len); + return 0; +} + int kvm_sev_guest_start(void) { SEVInfo *s = sev_info; @@ -335,3 +357,17 @@ int kvm_sev_guest_start(void) return 1; } +int kvm_sev_guest_update(uint8_t *addr, uint32_t len) +{ + SEVInfo *s = sev_info; + + if (!s) { + return 1; + } + + if (s->state == SEV_LAUNCH_START) { + return sev_launch_update(addr, len); + } + + return 1; +}