From patchwork Wed Oct 4 13:14:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9984637 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 D4BCF60237 for ; Wed, 4 Oct 2017 13:19:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5603287C2 for ; Wed, 4 Oct 2017 13:19:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA28628961; Wed, 4 Oct 2017 13:19:15 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI 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 2C1BA287C2 for ; Wed, 4 Oct 2017 13:19:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752714AbdJDNSt (ORCPT ); Wed, 4 Oct 2017 09:18:49 -0400 Received: from mail-cys01nam02on0075.outbound.protection.outlook.com ([104.47.37.75]:59363 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752250AbdJDNPY (ORCPT ); Wed, 4 Oct 2017 09:15:24 -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=dpPNBfkek2Z1zNEcNARPJ4hFoROf04OsjRQxWJvvZX4=; b=A7+vQulEfdFmvgn97CaRxIziVK6bWEUDnzj5MwbmwhX7zVP1LHd/COG6nc/kLa8mBiTAu+O1/DVKz9TzaxsEpBZDmdEH+QinCP8t7Aw6w6w0CrSjaGioWu8iB/on+CPs1dBxkwfe/JKSBUTczArY8b9b/5uf4ySZLAbZoHBdsbw= Received: from ubuntu-010236106000.amd.com (165.204.78.1) by SN1PR12MB0160.namprd12.prod.outlook.com (10.162.3.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Wed, 4 Oct 2017 13:15:16 +0000 From: Brijesh Singh To: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Brijesh Singh , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Joerg Roedel , Borislav Petkov , Tom Lendacky Subject: [Part2 PATCH v5 21/31] KVM: SVM: Add support for KVM_SEV_LAUNCH_MEASURE command Date: Wed, 4 Oct 2017 08:14:02 -0500 Message-Id: <20171004131412.13038-22-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171004131412.13038-1-brijesh.singh@amd.com> References: <20171004131412.13038-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: MWHPR2201CA0056.namprd22.prod.outlook.com (10.172.59.30) To SN1PR12MB0160.namprd12.prod.outlook.com (10.162.3.147) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 50829e86-71ce-4679-29bd-08d50b29f5a7 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(48565401081)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:SN1PR12MB0160; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0160; 3:bxbcLj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1VY/MlQBXQfclxN31YSrVK6bdU7rlSc1Azx5oRcAMCXL50M0NZBsbHHm5Vhe5JKaRUglSZLdGyjWV3UxPOT/6mPQzsZf+pvmPpwKxZ3jftEfGsi4h37eGgmJ1tzFbfZoQZvRGc8fb+O9L0PPCw0g/oYTMxwU+DWqxc2XLawp7TFrbBtx4wDqjSSYUWvHlfohsRmRStRhbFzpupH+iAii7mQ2CACDyw50KtrZ9RRrLhkahfPVHqg6lZaETE4VKXOY/K5z+gNbrW1GH1WBmm/MLm7uF9IcJL/EHHNDJClWnnmqA2gLP+vn1A85F3MtBw6FJegAi2l15Q1DceQtp5opFEAv0; 4:b2chFnV/TpyKwVtqfjMz1WUswP/2cmTGEC17oLt0ZKYkVnCLmJXfbedJc/Q1F6E24GAUozcB+qrQz/UF4/Iyk3EjD5QpPpjAF6+SC1yiDVA4mRrbNdKv/Z00PwZOeo3BdaexpibnL2XKwpJbn3pWT/YxTOp1m0GGXEX7c8/RVmbEzyqOwIuZwBiKT0VMn19zMbpkj1gB5Z8mmsoezQmRgor6FVbWZ0MU4fh5w+yddL9AFE3nikNkHzrX8ThTgg4bvACj4ifmKk5ZeantbRxbH2SvCqCS1M9u+/v6oQpbenzgOKpTXHb4iP9eI8Tj7fC65if2/PiG+wc7JFc1lIREVg== X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(767451399110); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(3002001)(93006095)(93001095)(10201501046)(6055026)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123562025)(20161123555025)(20161123560025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:SN1PR12MB0160; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:SN1PR12MB0160; X-Forefront-PRVS: 0450A714CB X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(346002)(376002)(199003)(189002)(97736004)(86362001)(23676002)(76176999)(53936002)(50986999)(1076002)(6116002)(3846002)(478600001)(36756003)(47776003)(101416001)(33646002)(6486002)(66066001)(189998001)(68736007)(105586002)(53416004)(50466002)(4326008)(54906003)(8936002)(305945005)(6666003)(2870700001)(81166006)(5660300001)(81156014)(25786009)(2906002)(8676002)(7736002)(2950100002)(7416002)(50226002)(106356001)(316002)(16526018); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0160; H:ubuntu-010236106000.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtTTjFQUjEyTUIwMTYwOzIzOnpKZEZyZ0ZPcmY1RzlCYVFISU1ucWVWKzBS?= =?utf-8?B?Q3VReGhMTWY5RVd5MFRNeDN6VzhOQUpzSXl4RkZRREtRV2o1b0tFSCt3MGYr?= =?utf-8?B?NHhEYzI4L2FTWE1IU1A5bE1qN09rNXhTY2tZT1pNN2pUNFpDZFo0dHBxd2th?= =?utf-8?B?eUJpbUZQNDNicTk5QnNMUlFyK1hFS3dRaVBSdnZLcmQ4T0pPbDhIUGJySG5Z?= =?utf-8?B?eEFBN2hOV1B3MWNkeGxIMXhYOWxpTzZZZmNnKzlaU0txZ3Nsa1VOdU1FRjl4?= =?utf-8?B?U3BGem5GQ29QZ1o3TXRvdnRXMmVEdVU5OVUyNHFBUExZeWs3ZXREa0lKUVdM?= =?utf-8?B?eGFIdlJlSFVCY0EzL3NtVldDWWRzUm4vdUkxdm9SZ1E2T1dUOGlIS0F3SFB0?= =?ut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CYc8O7FdaieA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0160; 20:lbyxHZ00kbAQJBrT0Im6bdOs34UNqoCYJxthf45/J68bMMQwF9I5wgU0W8UQEQ8AQEVIlNbd6mscXI9EXYVdHcrGZETvwOjqsgLaS8ZUNbS/iKvskh1qnuBFKPjCNEABDslsfbPQ0gzWYZ3DSg9XVx/gkIsxRbmgE3x2+rf5ifZ0xp6ouV2c8TVNsKLOgCvI2ELqRs1mRYpFW65cSGVjv1mhYE9gv3CTSvHom4nHYK9xXOUCl1gROlosi9apPrgT X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2017 13:15:16.9950 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0160 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 to retrieve the measurement of contents encrypted through the KVM_SEV_LAUNCH_UPDATE_DATA command. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: "Radim Krčmář" Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Brijesh Singh --- arch/x86/kvm/svm.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 0871d3ab9e6c..25bb3cd9b66a 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -6000,6 +6000,68 @@ static int sev_launch_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static int sev_launch_measure(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &kvm->arch.sev_info; + struct sev_data_launch_measure *data; + struct kvm_sev_launch_measure params; + void *blob; + int ret; + + if (!sev_guest(kvm)) + return -ENOTTY; + + if (copy_from_user(¶ms, (void __user *)(uintptr_t)argp->data, + sizeof(struct kvm_sev_launch_measure))) + return -EFAULT; + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + blob = NULL; + if (params.uaddr) { + if (params.len > SEV_FW_BLOB_MAX_SIZE) { + ret = -EINVAL; + goto e_free; + } + + if (!access_ok(VERIFY_WRITE, params.uaddr, params.len)) { + ret = -EFAULT; + goto e_free; + } + + ret = -ENOMEM; + blob = kmalloc(params.len, GFP_KERNEL); + if (!blob) + goto e_free; + + data->address = __psp_pa(blob); + data->len = params.len; + } + + data->handle = sev->handle; + ret = sev_issue_cmd(kvm, SEV_CMD_LAUNCH_MEASURE, data, &argp->error); + + /* copy the measurement to userspace */ + if (blob && + copy_to_user((void __user *)(uintptr_t)params.uaddr, blob, params.len)) { + ret = -EFAULT; + goto e_free_blob; + } + + params.len = data->len; + if (copy_to_user((void __user *)(uintptr_t)argp->data, ¶ms, + sizeof(struct kvm_sev_launch_measure))) + ret = -EFAULT; + +e_free_blob: + kfree(blob); +e_free: + kfree(data); + return ret; +} + static int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -6026,6 +6088,10 @@ static int svm_mem_enc_op(struct kvm *kvm, void __user *argp) r = sev_launch_update_data(kvm, &sev_cmd); break; } + case KVM_SEV_LAUNCH_MEASURE: { + r = sev_launch_measure(kvm, &sev_cmd); + break; + } default: break; }