From patchwork Tue Sep 13 14:48:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9329335 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 C298560231 for ; Tue, 13 Sep 2016 15:46:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4D6F289BE for ; Tue, 13 Sep 2016 15:46:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A99F928D62; Tue, 13 Sep 2016 15:46:27 +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 5AA5E289BE for ; Tue, 13 Sep 2016 15:46:26 +0000 (UTC) Received: from localhost ([::1]:49738 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjpuj-0007fW-DO for patchwork-qemu-devel@patchwork.kernel.org; Tue, 13 Sep 2016 11:46:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjpW2-0003Ig-FO for qemu-devel@nongnu.org; Tue, 13 Sep 2016 11:20:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bjpVx-0007eJ-N5 for qemu-devel@nongnu.org; Tue, 13 Sep 2016 11:20:54 -0400 Received: from mail-bn3nam01on0044.outbound.protection.outlook.com ([104.47.33.44]:24096 helo=NAM01-BN3-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjpVx-0007ct-IO for qemu-devel@nongnu.org; Tue, 13 Sep 2016 11:20:49 -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=9owoPyZcFstNd18DqPjBk0aAHj5l2OMmq+P2TXuClRU=; b=bTjB6i6GF924kStOGyG9OrMfMMVr67JJbgpPncfDQDvaQYHnT7SaWdW+V39NRPVInD4Kd/7awH+2XVL7wTp4vP1hU6phuDsv6kA4RvhCGzH0ku9yKWKxYFze3la4Dzsch7F3xeBXDLmdpMXUX4GjZlqtcinYSiT0haLKtFlBMBY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from [127.0.1.1] (165.204.77.1) by BLUPR12MB0657.namprd12.prod.outlook.com (10.163.217.27) 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:45 +0000 From: Brijesh Singh To: , , , , , , , , Date: Tue, 13 Sep 2016 10:48:38 -0400 Message-ID: <147377811888.11859.2777245831487772253.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: CY1PR08CA0003.namprd08.prod.outlook.com (10.163.94.141) To BLUPR12MB0657.namprd12.prod.outlook.com (10.163.217.27) X-MS-Office365-Filtering-Correlation-Id: 8bd5c234-b6f4-430c-1db7-08d3dbe510bd X-Microsoft-Exchange-Diagnostics: 1; B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6xHiiTtRBCtVSS3T610P4ZFrAMDLNs=; 20:u0DiZ8nAQrSxxBo+ESEFPEcvq8O7xXAxLirw5GqkfRjrtWZ3q+bDKJwZAJPl7PjQoBZh1X4ADyK0zHPkQeHvNTraLPJLlS8yGYP9EmFj4PFj6FPODyaISZsO7m+gLRpkk4OIrJ8eIbqw8FgP/C+oBMUrWlZOtlmbKWVrU6jbRyx7w0thLQZzvGJd2xV424vEFoL9pGPBTWN4HqoOxXE9BOfdx/HzV/IM+xjFZ43zwk46OteWoqwY2iN9NbTUsHd+pSp3uT0tBjc8ZLXbwAdbESg4oIHvO/WJrauqFfS22/xKU5VUfxXmSJFNi7Y7vyf9KNhutY/O4kj2TMT5RwtJEmCTAOMlsKDakYN464I+O8SSxK1F7+WNo7SCV269LnIxtOGiYuQ2w+vcDGTOqGqG9FnrM3A8iAS4P8fK/EiXDxBl14DEh9ozuhED6hgsQDPdf6AipB4n7HMF9YlgAm5ptSVsWy0kh//Tv2d5I1C/fRymku7i01jenlqU6tJTvfva 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)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:BLUPR12MB0657; BCL:0; PCL:0; RULEID:; SRVR:BLUPR12MB0657; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0657; 4:0/SwMLTadzUTx2AZf39yLdcuEYlRLxONC6WxhJJbFVGEEb+tKntbZhJ9c5hUnlFAD5hq7JNuuFSbUZbvFaxKDxbh5831dEfZ31hmyaXQsx8BiyDkZjbzvwiS2O2z+qz9J6e3ZxZ8n+OvnzNANEYAC6r0AeQZKPvF8tyKnNRiK+M98kQ8S4pRoSEcUQejAEwZ2xzeD+u8Ardq2Iii+kYUypI05vm7Y5t/ADSO8dRJdPaeqkbi9ZkxyF1eC8MASlVOYni00fV+c5jlT2lhSceldQTB5Br2/P1fZYO32+F3ZnWX7uyoJXIimyHrrvkEgRadrTL+T+WeuIw8DY8tsinMsxFl/MlEbJ0gl4DJLLzrp1GN6DrNg6PrpxCAAtWzNgGDEUJxFRy34oZQWBkf1UewNzJZF88RSaXAZIUCTAQVkUbUe637kQdwRHrVdzo12n+p X-Forefront-PRVS: 0064B3273C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6049001)(6009001)(7916002)(209900001)(189002)(199003)(33716001)(229853001)(50986999)(101416001)(15395725005)(23676002)(42186005)(76176999)(77096005)(105586002)(106356001)(5660300001)(54356999)(103116003)(83506001)(50466002)(15975445007)(81156014)(8676002)(92566002)(97736004)(86362001)(5001770100001)(230700001)(4001350100001)(19580395003)(2906002)(2950100001)(68736007)(7736002)(9686002)(2201001)(81166006)(47776003)(3846002)(107886002)(19580405001)(66066001)(305945005)(6116002)(586003)(7846002)(189998001)(33646002)(217873001)(6606295002); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR12MB0657; 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: =?utf-8?B?MTtCTFVQUjEyTUIwNjU3OzIzOlJTSjRaYS9hTUl5SnhBNzNHamhrWkh1aGFE?= =?utf-8?B?emJ6Z2FZZ2F2MW9DSVBNbFAyOWJxOWh6Q3FEYkRwT0pKV2FGeDlLNjIrajNL?= =?utf-8?B?b0pLSDJTWElsR0hkQzcyam1IZlZPbGlFcjlDVnA0d1JROHhSSFlDVHZpb0xV?= =?utf-8?B?SmJ4S3VsNlJxc3hrRzFndXc0dzFWWTNNTmN5K245MThxREVzeXNNODY0eUpi?= =?utf-8?B?amppWWpGT29IOG95VFJkY3IxbGd2YjhxM3VVSW9FOEY0YmdWUFNaUHpPdUVw?= =?utf-8?B?d2ZEZkJqQmNyQkxPTCtmTnBBeXR0ZXFoejFVYW84Yk5Ga0gxcnMwQ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PHKTaNPcqVc5nru+GHyBkWYWw4FBGz/jMR1cxbuik6rikllMbadNhTSooc9JTd6IudDd4JgMps1obk96AqFPweMZHbDBVlDKdX1fZJkuJD5d+VXTgqW51RTw1ZRLa0zo7WIwRof31eYgNcqf3jRjPQ==; 24:NHCR36ivbMP361oqECu9F7FUTGFiwGouGAiVeRFk4Wq++Fd+JUqAYOxx+NvzRJqxVjr4fx3d1+jUg0mQ0c79JZq/W9swAdjxWxS34E1YWcc=; 7:YMktpnq5vS5hV+NX2+yf17/UN3rob/t7g4Gy1fPWpO4o6oEw7F6uKbKdC/gDfcOP9I9Ta58aroroTH+1TIxvojZkzMPSNtxtfrvSVIdr4+cFVeYyfCN7C9oiqKO90g+85xhn7ETwMTpFdtwwF/WSpInAHrh4w5ba8lweHUAnrms74MC2HNuEa+pzNPu9DPkyJ86DRvXvIl2PR1f12UfUkwXh9/FJUBTCeUJ8khKG+sxeva3QlfKY7CHGFGUmfHLP SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0657; 20:tEJLAFC1g3Atct8ueld/DWoWs9Mxk78L3P/iT6TAaksSZXNSFbke8l5BCujeqWMHBgUsfiIktBduE0YFmOj5wLOwY/euo40srYmTzUd58f3b3AIFq7pKUe88Pw0UHRBUsRNjCUHdq7mEQi2ddMJY8ZmHuirYkoXmubTxCHMVG0W8BUQXLW8k71XrvVXvqNAi49QMyPiJJJynbgOMJoQqYO23ylvJUyOs+7tkq4i+Pm/MboFukvQ2MEO5BQx27X8K X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2016 14:48:45.5637 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0657 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.33.44 X-Mailman-Approved-At: Tue, 13 Sep 2016 11:45:46 -0400 Subject: [Qemu-devel] [RFC PATCH v1 11/22] sev: add SEV debug encrypt 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 DEBUG_ENCRYPT command is used for injecting a code into SEV-enabled guest memory For more information see [1], section 7.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=147190861124032&w=2 http://marc.info/?l=kvm&m=147190861124032&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 5872c3e..a505d75 100644 --- a/include/sysemu/sev.h +++ b/include/sysemu/sev.h @@ -65,4 +65,14 @@ int kvm_sev_guest_measurement(uint8_t *measurement); */ int kvm_sev_dbg_decrypt(uint8_t *dest, const uint8_t *src, uint32_t len); +/** + * kvm_sev_dbg_encrypt - encrypt the guest memory in SEV mode. + * @src - guest memory address + * @dest - host memory address where the encrypted data should be copied + * @length - length of memory region + * + * Returns: 0 on success and dest will contains the encrypted data + */ +int kvm_sev_dbg_encrypt(uint8_t *dest, const uint8_t *src, uint32_t len); + #endif diff --git a/sev.c b/sev.c index c7031d3..4e5da84 100644 --- a/sev.c +++ b/sev.c @@ -455,3 +455,26 @@ int kvm_sev_dbg_decrypt(uint8_t *dst, const uint8_t *src, uint32_t len) DPRINTF("SEV: DBG_DECRYPT dst %p src %p sz %d\n", dst, src, len); return 0; } + +int kvm_sev_dbg_encrypt(uint8_t *dst, const uint8_t *src, uint32_t len) +{ + int ret; + struct kvm_sev_dbg_encrypt encrypt; + struct kvm_sev_issue_cmd input; + + encrypt.src_addr = (unsigned long)src; + encrypt.dst_addr = (unsigned long)dst; + encrypt.length = len; + + input.cmd = KVM_SEV_DBG_ENCRYPT; + input.opaque = (unsigned long)&encrypt; + ret = kvm_vm_ioctl(kvm_state, KVM_SEV_ISSUE_CMD, &input); + if (ret) { + fprintf(stderr, "SEV: dbg_encrypt failed ret=%d(%#010x)\n", + ret, input.ret_code); + return 1; + } + + DPRINTF("SEV: DBG_ENCRYPT dst %p src %p sz %d\n", dst, src, len); + return 0; +}