From patchwork Mon Aug 22 23:29:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9294647 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 86606607F0 for ; Mon, 22 Aug 2016 23:30:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7513F289A5 for ; Mon, 22 Aug 2016 23:30:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64AD328B07; Mon, 22 Aug 2016 23:30:00 +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 vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE5DD289A5 for ; Mon, 22 Aug 2016 23:29:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932796AbcHVX3t (ORCPT ); Mon, 22 Aug 2016 19:29:49 -0400 Received: from mail-bl2nam02on0078.outbound.protection.outlook.com ([104.47.38.78]:32289 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932578AbcHVX3o (ORCPT ); Mon, 22 Aug 2016 19:29:44 -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=sgTI6v+j0+eICsAowL7lCcWn8sosFiRNdypK0p4JtU0=; b=itJhvo0rY0/KZ3xrSsLc9n3P/uclYv/WEb0nZ2vgxmGcJtORQDqvcV+8UJz/0si4vz/2DuMzk3VYyx0SMOWbKS42bkDcRk6meYOrudLvgjUcEaB+6IKbfL2AISpP+Q8WSKX0JoGb+jmNqwTls9J3plyhdLLuEtZiGnF5AgAC/00= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from [127.0.1.1] (165.204.77.1) by BLUPR12MB0660.namprd12.prod.outlook.com (10.163.217.30) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.9; Mon, 22 Aug 2016 23:29:38 +0000 Subject: [RFC PATCH v1 27/28] KVM: SVM: add KVM_SEV_DEBUG_ENCRYPT command From: Brijesh Singh To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Date: Mon, 22 Aug 2016 19:29:35 -0400 Message-ID: <147190857531.9523.10196506226671736370.stgit@brijesh-build-machine> In-Reply-To: <147190820782.9523.4967724730957229273.stgit@brijesh-build-machine> References: <147190820782.9523.4967724730957229273.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BLUPR05CA0068.namprd05.prod.outlook.com (10.141.20.38) To BLUPR12MB0660.namprd12.prod.outlook.com (10.163.217.30) X-MS-Office365-Filtering-Correlation-Id: c270e3ec-0a69-4aa3-8150-08d3cae4308d X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0660; 2:iK2W77Yx2wP+3mhF/S5YIzHQL44xc6Eqmqw0VDQMKxDz+F8uIaN1B75I3qxMpCj1okxwIAZpgLtxz2Tt7yZqm0rWSvnrtksDwvcwW3xDK+XTr8deFiFrQn9wvbgPwnxuJmEW5CM6KbbL9gYIqsncZdB+M+oMdlALimKvJDtil10d2D2YMOSmNs4RgU5M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0YWIHs9Jp4ACGb7xtVwHei8ohrSYX6oxLa6wKlh0V/RscqyuhvvKSQBiX/foNxgXfsW0kKWR3zXb3eVfuKwlIDdqsgC6MP6sWdwqE5hq0fYYmZPXHvLcEOq/KLSK39Q5kPOtwwsqzxj2+hpr4yjtZZSXMPXpTpMrXEIKbZ+EufbY7ivDeUAPl0cEvDhvi7IKVZt94nllMzzIzlLjaSDJtD/1fEFc9iVvAT4Ec0OCgQsFJABSvCZictQNen+szGYadB/4UZqfsKS/wo6XCl1A6rMyIaj5LS9EAUBEAFOYQ5mH815dLrJbKHIGwI/ngxf4fFtJcqQntC4UIufZu4We 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:BLUPR12MB0660; BCL:0; PCL:0; RULEID:; SRVR:BLUPR12MB0660; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0660; 4:jceEBLWgPDQcWzcm13v2ewkBVZxXViO4aHYDOgdx0fm2S1kDnOLNJKXGtn3gunigfc9+5N2GOW3kALX53xRqtT7wJu+IPAijOzOEspwNIYqBRmqV+3wXhPBx1kdOjkJC+aZgsonzC/qYwQfoKURXrDvVI3iF/pDDWRSPQ1BM8UE/W9qf36LMlNvg+Nl9Fdbnhp8onLzuhKe0fQMw3PzPP7MXu81qDoGubacFVUpKwXxE+xwWHFv8t+nwNrzmZOiH3dWUV0MF+/u31VTzeY+WXp+hMwpDGIcank0xqYYJhZhrbXoHZWLXhYKE0XDos9k6YRD930Ky5a5fM+JXO1a6BJO9eliPZKvvJbzCkEL5X4ig19BetcfE2KJuNLZC70c02hsm6SH1QuLOwS6aXJjvgmGLiO0z4x8y6BxRL7qiaswv4/RfOijo0YqbNq2KRZJn X-Forefront-PRVS: 00429279BA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6049001)(6009001)(7916002)(189002)(199003)(54356999)(6116002)(105586002)(7736002)(101416001)(230700001)(76176999)(3846002)(2906002)(9686002)(66066001)(5660300001)(7846002)(103116003)(33716001)(50986999)(305945005)(4001350100001)(92566002)(2950100001)(23676002)(33646002)(8676002)(81156014)(77096005)(7416002)(7406005)(15975445007)(97736004)(19580395003)(5001770100001)(42186005)(47776003)(106356001)(19580405001)(86362001)(189998001)(50466002)(107886002)(229853001)(81166006)(2201001)(68736007)(586003)(83506001)(921003)(1121003)(83996005)(2101003)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR12MB0660; 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?MTtCTFVQUjEyTUIwNjYwOzIzOlJHcDFFRjh3TWdCemlRMjVpeXp5RFlTRHRB?= =?utf-8?B?M2NuQWVheE11MDR4Q2Q3cGFlbWovZGIzbEgyMVlCdm9uSHlUeWdlUXdNaFo0?= =?utf-8?B?eUV2UmNBNGVPN1duL3JuS0VYeXFkZlJXRWtDYUMwR2p1Yk9HVlUyMVNCZkhW?= =?utf-8?B?VVl6Vyt5WHVrTEcvZEhiSkRzbVBvQUVFbzZjQVRyQURpT1VjT2VNMy90ajNu?= =?utf-8?B?b0pkaEtBaERWMkdrRmMwajMvMXBFb3JrQ28vUmpuN2FidE8rOGk0MHZsdi9p?= =?utf-8?B?UGF5ejlZNVFWZUtHUFVXT2RRNmorbEw3SUNMSURLMHBBQ1ZTckR2ZElSY2kv?= =?utf-8?B?RERwazZodUpVSEgrNCtWYlo3ZTRKT2IwWURnUVYybzd0TWIwR2lnMUFreGxT?= =?utf-8?B?NkVxbWsyOUdUKy9zS2Ewbnl5a2UvKzBuSmNERldUMDk1ZVFVZmVBcXNQMGFB?= =?utf-8?B?Kzh5VER0a1dqL2diNU5ocXVGNm5sSkkxUWFRVlVU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YR+mvEyWSwx/CQKQpXBTFxNeOrxeJLcpSvU7JLKlvlGP+YmiANcRMfA==; 24:A6vNnd9y2TWE+0o+b+j4d3WCKSn7yER9XsITHx4VfQHCEZcwT4/PI9RTx0kKpHXvCC53TPcmbwVEE2JfwpH2fSeJ8ez0GPK71Yw7veycg8A=; 7:BKANH2SWO5w8qNInSSrUVICi7ejO6UeAv4GfK2xGivSHELIbkCD3V4tOj9iV7oQvpcokqPtT90GDiV5aRr/vqBvaE+PaEzOzimv4tqxS+B/uE9EebWB8BSn3KSwclCVoPD04lpBxoYYNRw7Ex/KUx2j03yuv5iwTEwL5WPGM7cjU+16g9K4RAtsgoyo0k640Lh4yOlEfPRJ19PsLnnHU+dmy8krYddZDiL82oyRYgVQMWq03sZ+OwVO8EQ8MUkW6 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0660; 20:6vWGfwLdD8pGXorA22ensKGs96gM5jVdEKEcxwyHE274j+z/wx0LGyyIxskOkV6WOi/ad5umVYLhsOMRz/uAF65T31hXHGyQ8KWdkmRtHmG1vuebSj91z5Xd1rns8MHAmSxK7H9/ieRf8tMOVSMG6lVRQ7f76CjAN2OgR0YTtlFSkfmvrO9JZkrWS/Oc2QkYGLqAF85tgfe+uEAX+sTjI9qUuk1y6srivcIxpjDAie2yZds0NOtJRUOl//8MxQFN X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2016 23:29:38.5738 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0660 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The command encrypts a region of guest memory for debugging purposes. For more information see [1], section 7.2 [1] http://support.amd.com/TechDocs/55766_SEV-KM%20API_Spec.pdf Signed-off-by: Brijesh Singh --- arch/x86/kvm/svm.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index b383bc7..4af195d 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -5684,6 +5684,101 @@ err_1: return ret; } +static int sev_dbg_encrypt(struct kvm *kvm, + struct kvm_sev_dbg_encrypt __user *argp, + int *psp_ret) +{ + void *data; + int len, ret, d_off; + struct page **inpages; + struct psp_data_dbg *encrypt; + struct kvm_sev_dbg_encrypt debug; + unsigned long src_addr, dst_addr; + + if (!kvm_sev_guest()) + return -ENOTTY; + + if (copy_from_user(&debug, argp, sizeof(*argp))) + return -EFAULT; + + if (debug.length > PAGE_SIZE) + return -EINVAL; + + len = debug.length; + src_addr = debug.src_addr; + dst_addr = debug.dst_addr; + + inpages = kzalloc(1 * sizeof(struct page *), GFP_KERNEL); + if (!inpages) + return -ENOMEM; + + /* pin the guest destination virtual address */ + down_read(¤t->mm->mmap_sem); + ret = get_user_pages(dst_addr, 1, 1, 0, inpages, NULL); + up_read(¤t->mm->mmap_sem); + if (ret < 0) + goto err_1; + + encrypt = kzalloc(sizeof(*encrypt), GFP_KERNEL); + if (!encrypt) + goto err_2; + + data = (void *) get_zeroed_page(GFP_KERNEL); + if (!data) + goto err_3; + + encrypt->hdr.buffer_len = sizeof(*encrypt); + encrypt->handle = kvm_sev_handle(); + + if ((len & 15) || (dst_addr & 15)) { + /* if destination address and length are not 16-byte + * aligned then: + * a) decrypt destination page into temporary buffer + * b) copy source data into temporary buffer at correct offset + * c) encrypt temporary buffer + */ + ret = __sev_dbg_decrypt_page(kvm, dst_addr, data, psp_ret); + if (ret) + goto err_4; + + d_off = dst_addr & (PAGE_SIZE - 1); + ret = -EFAULT; + if (copy_from_user(data + d_off, + (uint8_t *)debug.src_addr, len)) + goto err_4; + + encrypt->length = PAGE_SIZE; + encrypt->src_addr = __pa(data) | sme_me_mask; + encrypt->dst_addr = __sev_page_pa(inpages[0]); + } else { + if (copy_from_user(data, (uint8_t *)debug.src_addr, len)) + goto err_4; + + d_off = dst_addr & (PAGE_SIZE - 1); + encrypt->length = len; + encrypt->src_addr = __pa(data) | sme_me_mask; + encrypt->dst_addr = __sev_page_pa(inpages[0]); + encrypt->dst_addr += d_off; + } + + ret = psp_dbg_encrypt(encrypt, psp_ret); + if (ret) + printk(KERN_ERR "SEV: DEBUG_ENCRYPT: [%#lx=>%#lx+%#x] " + "%d (%#010x)\n",src_addr, dst_addr, len, + ret, *psp_ret); + +err_4: + free_page((unsigned long)data); +err_3: + kfree(encrypt); +err_2: + release_pages(inpages, 1, 0); +err_1: + kfree(inpages); + + return ret; +} + static int amd_sev_issue_cmd(struct kvm *kvm, struct kvm_sev_issue_cmd __user *user_data) { @@ -5719,6 +5814,11 @@ static int amd_sev_issue_cmd(struct kvm *kvm, &arg.ret_code); break; } + case KVM_SEV_DBG_ENCRYPT: { + r = sev_dbg_encrypt(kvm, (void *)arg.opaque, + &arg.ret_code); + break; + } default: break; }