From patchwork Mon Aug 22 23:28:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9294643 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 73836607F0 for ; Mon, 22 Aug 2016 23:29:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6470528B01 for ; Mon, 22 Aug 2016 23:29:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57F7C28B07; Mon, 22 Aug 2016 23:29:44 +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=unavailable 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 5942D28B01 for ; Mon, 22 Aug 2016 23:29:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932525AbcHVX3M (ORCPT ); Mon, 22 Aug 2016 19:29:12 -0400 Received: from mail-bl2nam02on0064.outbound.protection.outlook.com ([104.47.38.64]:22364 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753111AbcHVX3I (ORCPT ); Mon, 22 Aug 2016 19:29:08 -0400 X-Greylist: delayed 316 seconds by postgrey-1.27 at vger.kernel.org; Mon, 22 Aug 2016 19:29:07 EDT 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=BkhE2AO4AKiHHZ7if8DSPOZfq86BpCPTi6qmDDVZRfU=; b=K7ruzZmBvDIic2/Q8++ndXujIBvCC/OjT8SLs79Y2DATdyE6A0vbbqmMxeZ/YAeKPymkYHvrCDNc7HEqjyHvL4GhYpwPgCPYj2aT3jRxhOjGOym8GzCfbuQvaSpnW7n5SWzGhWfmn89TxhhwnNFnRf4zJHpHTrk4Xe8AoeFdIts= 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:01 +0000 Subject: [RFC PATCH v1 24/28] KVM: SVM: add SEV_LAUNCH_FINISH command From: Brijesh Singh To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Date: Mon, 22 Aug 2016 19:28:59 -0400 Message-ID: <147190853894.9523.16890031242057232592.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: SN1PR15CA0034.namprd15.prod.outlook.com (10.163.200.44) To BLUPR12MB0660.namprd12.prod.outlook.com (10.163.217.30) X-MS-Office365-Filtering-Correlation-Id: 46b73fe5-1284-4181-0c96-08d3cae41aa6 X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0660; 2:JAvDTkFyZXDFZki/HnCIJyQVFIMMEHBHDH/X1b50A4dhoBENQOcctO+eLABICUCBMzoRBAP9bOwxGifuVgoGntNSXcNJtTunYiW9bfJGk/5TjscK4lPRPa0VKA3dfx+7NZV6OeVtiB0WYMu1ViYUGZIgsirJ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4= X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0660; 31:uMJ0ihIjB4e5YoDix2YIGebSzj1w/jRd7mSLRDblERohUE4IQSOx56hDKiSNt79583n5pkRuun9xfGvqbiMt6O/+ZT4v2dJ2XfKl4l01phse6OQbXzuZvPSkZlYoxRwizPshXEqbYpchA/hOm1LIH9cJH4w/5sOWRbKJhFsY0kAb62MA6ow7Tn7iUJHFvuYQrH4EJbqBE8A7Cr81VK1keuttt+4fvFg6pERrrO3GeHE=; 20:e8lK8z3+s0cT5koriO2vn4YaUAWnKuhRHYZNAbII1qORsifwyZofvPyRbeVhvgL5gMBVWGk2sQUZKU7jYlMDs2KOIj3zE711Z+wuywm91WRgNwQX2ou7ybQyhY0ShA8/1WIRdvZZFr8FQP72wWVAyd/TMI5jCHSV4e7nc8r5rfwAc+xSDLIsXDDGwMX8xro+1jw9Q7WDMn4GhL1ZXNhWskxhvr1bO7YOkjJbaXlAgy6mH9uqXLDLPt+VPQPLUzpdr6O/HeKDU+VFI3TJLI9E+UJNDxjriCszKG0FvCL/NEWLdua0YonT5kNNDVZ6W9JNyvPaFO/dTP4ge3Lg1ID7oqR1mpf1AOzfrIz0LG+/iubFpTB1y/sptBA/eSqMJtRYdIuJihEmxIOmZUkAci+yvkJhT2X5P60X+nkNAlblgRRhwyFFBBehIDwHCjrc1VkgTgybdiGKMsuWBdQbPlIn0FFGEC9PAw2YmUgN9lRGQuJ9R/Cuhk6pYioKWsFWd4/9 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:HibFcZYljiqElnrcyrv8ic7z8YC0mKqrHFWGNzoZ8fNKe669ccH/zpq2D4k2sp5oQfmcstxT2Vdf6scnlAJMcD2Dy11NicR+PgLTv83mOoW8elrbQqjrVfU2SxmBIwGa7tTHWbCWi0b9zyO4g03Jl31omAusavetswPCji/chmrMAsqg/9VJoyCEWWbu+U64pqdJ5orF+ukizcuy8K2f/T+PncXjHxekyPOjpJCS2KpiYJDI9rCsc6VDvfP6/ahkeqep0RJsgjcdXyuezhwO7H4ddVWyISAwDQhbcRrF5+5MkTt+S4RY9uyr9mj5xW74LYEd5oDDI7pOxdfjeu5hV3zWzuFWe9epkrqoLxlV/S3STq9qSsatO6+357eylJjA/hNZhK5t+p81FubzY1ZH30jlrjFzshpG3lKGu+WF82jEpKxYYBdkoSNqH99WGece 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)(575784001)(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?MTtCTFVQUjEyTUIwNjYwOzIzOlNZMDY5YXBNRGVyVUgyTFBZYW5ETjkzYk0v?= =?utf-8?B?eCt4dGhlQWpOY2NqQkFlcUtzY1hlL0lRMDRWSWtrY1llemZ0aHA4OFVBbFVu?= =?utf-8?B?bk9ELzJpU08yeXQyUGNyNGNBQ2o2MnB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+VQ8ASEFo5V+yxXCGrjQb+DZ7clAjv7QR4gZTvXOVOAEJPD7+GCU+lWqGhc0YxuWlFLPMv2GAtaWAnN5Cx539tK8Kfk9tnQ7LmNZhl9qSJqlmdJWALv7tovfSsbsQzYd+Fxv9mbfYwDzrXrV6K X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2016 23:29:01.6476 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0660 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The command is used for finializing the guest launch into SEV mode. For more information see [1], section 6.3 [1] http://support.amd.com/TechDocs/55766_SEV-KM%20API_Spec.pdf Signed-off-by: Brijesh Singh --- arch/x86/kvm/svm.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe kvm" 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 c78bdc6..60cc0f7 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -5497,6 +5497,79 @@ err_1: return ret; } +static int sev_launch_finish(struct kvm *kvm, + struct kvm_sev_launch_finish __user *argp, + int *psp_ret) +{ + int i, ret; + void *mask = NULL; + int buffer_len, len; + struct kvm_vcpu *vcpu; + struct psp_data_launch_finish *finish; + struct kvm_sev_launch_finish params; + + if (!kvm_sev_guest()) + return -EINVAL; + + /* Get the parameters from the user */ + if (copy_from_user(¶ms, argp, sizeof(*argp))) + return -EFAULT; + + buffer_len = sizeof(*finish) + (sizeof(u64) * params.vcpu_count); + finish = kzalloc(buffer_len, GFP_KERNEL); + if (!finish) + return -ENOMEM; + + /* copy the vcpu mask from user */ + if (params.vcpu_mask_length && params.vcpu_mask_addr) { + ret = -ENOMEM; + mask = (void *) get_zeroed_page(GFP_KERNEL); + if (!mask) + goto err_1; + + len = min_t(size_t, PAGE_SIZE, params.vcpu_mask_length); + ret = -EFAULT; + if (copy_from_user(mask, (uint8_t*)params.vcpu_mask_addr, len)) + goto err_2; + finish->vcpus.state_mask_addr = __psp_pa(mask); + } + + finish->handle = kvm_sev_handle(); + finish->hdr.buffer_len = buffer_len; + finish->vcpus.state_count = params.vcpu_count; + finish->vcpus.state_length = params.vcpu_length; + kvm_for_each_vcpu(i, vcpu, kvm) { + finish->vcpus.state_addr[i] = + to_svm(vcpu)->vmcb_pa | sme_me_mask; + if (i == params.vcpu_count) + break; + } + + /* launch finish */ + ret = psp_guest_launch_finish(finish, psp_ret); + if (ret) { + printk(KERN_ERR "SEV: LAUNCH_FINISH ret=%d (%#010x)\n", + ret, *psp_ret); + goto err_2; + } + + /* Iterate through each vcpus and set SEV KVM_SEV_FEATURE bit in + * KVM_CPUID_FEATURE to indicate that SEV is enabled on this vcpu + */ + kvm_for_each_vcpu(i, vcpu, kvm) + svm_cpuid_update(vcpu); + + /* copy the measurement for user */ + if (copy_to_user(argp->measurement, finish->measurement, 32)) + ret = -EFAULT; + +err_2: + free_page((unsigned long)mask); +err_1: + kfree(finish); + return ret; +} + static int amd_sev_issue_cmd(struct kvm *kvm, struct kvm_sev_issue_cmd __user *user_data) { @@ -5517,6 +5590,11 @@ static int amd_sev_issue_cmd(struct kvm *kvm, &arg.ret_code); break; } + case KVM_SEV_LAUNCH_FINISH: { + r = sev_launch_finish(kvm, (void *)arg.opaque, + &arg.ret_code); + break; + } default: break; }