From patchwork Tue Dec 5 01:06:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 10091825 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 9947B60327 for ; Tue, 5 Dec 2017 01:06:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D6E829426 for ; Tue, 5 Dec 2017 01:06:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82132294D9; Tue, 5 Dec 2017 01:06:59 +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=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 F0AFB29426 for ; Tue, 5 Dec 2017 01:06:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752387AbdLEBG4 (ORCPT ); Mon, 4 Dec 2017 20:06:56 -0500 Received: from mail-by2nam01on0087.outbound.protection.outlook.com ([104.47.34.87]:63748 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752042AbdLEBGo (ORCPT ); Mon, 4 Dec 2017 20:06:44 -0500 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=bQExDQzEWVnq8CxJMsjaKr89e8hlo91LBIkuJnVtI1A=; b=LUg6P7s2L7n1GzVaCxiyxZa4syWOxoaOsZJPg/uieP/jQ7+t0hU4rwlZ+7fs7uAgVJnghPGlLThI8Lmxzzq2uWpiSo+pw/zJZkUv35Jz4yAZyqk1iO23Aex+oJGO+qwzkHDYXja2XWjV6SMNS2CnDTxM9V/EeoON7iS8lYMBkRI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from wsp141597wss.amd.com (165.204.78.1) by DM2PR12MB0156.namprd12.prod.outlook.com (2a01:111:e400:50ce::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.282.5; Tue, 5 Dec 2017 01:06:38 +0000 From: Brijesh Singh To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: bp@alien8.de, 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 v9 34/38] KVM: SVM: Add support for SEV LAUNCH_SECRET command Date: Mon, 4 Dec 2017 19:06:12 -0600 Message-Id: <20171205010616.5958-5-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171205010616.5958-1-brijesh.singh@amd.com> References: <20171205010616.5958-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: BN6PR04CA0055.namprd04.prod.outlook.com (2603:10b6:405:3b::44) To DM2PR12MB0156.namprd12.prod.outlook.com (2a01:111:e400:50ce::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 84b100a4-1374-4013-79d6-08d53b7c70d6 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(2017052603286); SRVR:DM2PR12MB0156; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0156; 3:o4EyFGZ/dgKt0ZSLvLl5AYW4PBGlEgGseQUMpCTY7y+MIG0ZLx1e/zz2UevMc0akgbkcKNe9uMEX84G0imj6YZJl6OfbtfrJRf0yjJE+d8MBYMfHDc/LRTwgFXw61Jl6WU6utQq61XA5qsXF8bbafz+e05Vj/7+WeEr2PZKOZ/lmhpGY1NH8j2hQG4AHT3IyNjxOgk2u7F/FL6Qf9estbRre1qqDoWul7QDuh11JWujbbE/dTjJ/olBjbyTRrNw4; 25:/fzJbm8jYDmZKZc0QYENyApobq1b2CukF3ZYwlak/DNrjjHvV6GkHHsRRVgGQL7FwCt3LlBNWKCyggnXrGAxcM3dnwPIUTGc6OvEsHoAFfFytNoFWGyANLsoy5ZGWbaxqr2TAX6hH829bWSUq2d/twtNtR49nm5rCZOgdEq02/1zgP8QlUc9Q4vM5d+7QWve/YcDlLcgSzJrLtzM6E+S34bRk/tk8mhMgqaK6a2rQeEz4VbF5atf7KVNwyMNP87nqJpnrK0mEY2adKfZ3cGsaAbjCDVPlMe4IuB3EwytCMLzKQ/CfS9M9j5+R3qxTA15EN68LDrHvZlZL56DI9GLoA==; 31:tGdhC75SmnMTJDYXjsgutwQSRGnHRVrofnmY9xB+inYFnlMJhwL23wxoA+Qq+jyXizzyz2VCNPGd4nuMfKDQYlEtiNCLYnCxSrQUCuSqi5XFtxY+JqZNJ1RZyju2UaxZHNfrCUHX0OZpEDh463DYZGjL+5s6vo/q10hb/+9AyjWK8It1bFrM8HLuwl/KMEi94me6hoxqBEnmZFpvlKZlBvLfhnDIFb6a9A3wWfprNMM= X-MS-TrafficTypeDiagnostic: DM2PR12MB0156: X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0156; 20:1R4u2AeHSr1zpwDuMkzJkblIAk8Bc0B34itEBO98r0jY+ga74SsUv1ZKKYwHXMxrMPtWC0vt+1ysQPJUwLpaxTS9SwqGQR9Lfi6YZsFSh1FRpN+FcBUnNvjSx2ZPRLbkrARVxYrL3P13paKgG6eglCwKjiVAiAXPPC20pZRTQlTwI1d6NYpOTDzvsxdDXLv+cuyE9jfCJfHsdigIvrQ5oYtGGxTnqaZDau84V0TC2fmbgfHzM3QMTCQ5YDNU367kgM4hvMO5e3weKdFoZPmPT8JJfrNL0ZCvTj5PVdQmfr9F6YacYVFyD2tr1qC5KtYwJbdoTv77g7OB68xpHYix0+K6fVoMqaI3z6HTaNk7tDQaRuYh9yzm3pBwExxBfgqmreeaVHru1xg97r8jPBuCCSzDWqAFk1GncrWo0TdyZAR8zPWNRiNdhcYa3LOuzFRR0sCYL8W2BLHfoiX5UXHAYvWsVXBVNJikoeEeXWbIwHp+uCdoJqin4QpugwL7uVyx; 4:RPQncsCsmE69tnx1CdUlBH21cB6N2NO6zY7+TaWH7oJkltx4mm6hIlEHoIMnuancPMuO61Ek5mz9AAD9O/467gfvfug8p2194HNwJT97wHHhDAROIktlOWcpkVPGjh0QTQvWLGdL8tU+S77rP6FYsjYjbW/xgtbDF/hGhVm6iZk4/SZeELNwr544yOBcWVGfZfuaWzaqSDJAmKyBuku7PM1fUYtANcaPGUx/QWB0LMADxu4jFDXoAvu8Eg+D4GDnyW+JOZZVN5wjtnrbrvYqxXvcinfi9tpZNh41AkEjhyNKb8Y6iCdJSjyvzIizYF5cujTJn+XYfjPFePPE0XCRtQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(3002001)(3231022)(6055026)(6041248)(20161123562025)(20161123560025)(20161123558100)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(6072148)(201708071742011); SRVR:DM2PR12MB0156; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:DM2PR12MB0156; X-Forefront-PRVS: 0512CC5201 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(376002)(346002)(39860400002)(366004)(189002)(199003)(316002)(66066001)(50466002)(23676004)(47776003)(25786009)(54906003)(86362001)(53416004)(7696005)(76176011)(16526018)(36756003)(8936002)(81166006)(6486002)(81156014)(305945005)(50226002)(7736002)(53936002)(5660300001)(52116002)(2950100002)(6666003)(33646002)(4326008)(101416001)(8676002)(478600001)(2906002)(7416002)(2870700001)(1076002)(189998001)(106356001)(6116002)(3846002)(68736007)(97736004)(105586002)(219293001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR12MB0156; H:wsp141597wss.amd.com; 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?MTtETTJQUjEyTUIwMTU2OzIzOkFaSUxBWFJUdk5QTGxKSUZEUVBlNWc4VnhZ?= =?utf-8?B?UEZlSitqU1pHdVhBWjE0M0hTUDcyUEZKSWF5Q3VxUGQ3ZGdHRWk5SXYxUHly?= =?utf-8?B?TkdIbWtqS2pJZVlIUmQ5WEovd1lDKzdvYXJDdVpPQjR2eWpZYmZQN3ZlMW5p?= =?utf-8?B?MkEwUnZkbmw3V2xrVWNVS1JhdFJVUWprZms4ZmMva2Z6N0x6VUlabXlBKzFt?= =?utf-8?B?bzd1Tk1GTWZ0bjBtaUVETkVwMDFrQVIwRXArSklxWHIzelNzcytqSXVvbTR1?= =?utf-8?B?dll1Ynl1a3FiRysxNjY4OXpyZy9lU3l0bktpb25EeloyMVF0Nm1taTUxU0F3?= =?utf-8?B?alNnVWlUY0tNaG5kLzY3aENUWk1EcVNINmdtYlZWVVVSTm0zZlEzTWdtYXY3?= =?utf-8?B?R3A3N0Q2Q0MxQUVLS2NLZ3BKYXBIeEVjQVdUMDlLT0RTVFByNDlxblRBUlZE?= =?utf-8?B?MEdzR2ZtaXpCSEJzZ0dseVZ5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O8MoNp0PlMUwpKMfAloVPBofBfwLTeaW0lqmPVaew4hqmqSowqe6ukjvziWwWaELK SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0156; 20:wb+a0hCkPDPv+6qr38HOPvByJx0aANnWuaWTtjnHp3ruqjRSePjr7hlQj4KqAYdHONxY1I3RK+FsBNlUbCLn6t3LKEb250u8VyQQEgM/9RUDq5Q6OrSaljM3Qe2IoiHy9bWJ/Plf8ToABZQM1zLL7gWv0fnqEN4z6ei5/yxcVD537gI1YNex12tOtFiG2iJDKrmfIFY0r9OYStMDMEWpKUhEGmp+v+hsBCaRyRfk9+8TZotBBr3uxPZQ/dL6FBPF X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Dec 2017 01:06:38.6005 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 84b100a4-1374-4013-79d6-08d53b7c70d6 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0156 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 injecting a secret into the guest memory region. 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 Reviewed-by: Borislav Petkov --- arch/x86/kvm/svm.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 11d4860997d9..8a499425bf7e 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -6397,6 +6397,71 @@ static int sev_dbg_crypt(struct kvm *kvm, struct kvm_sev_cmd *argp, bool dec) return ret; } +static int sev_launch_secret(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &kvm->arch.sev_info; + struct sev_data_launch_secret *data; + struct kvm_sev_launch_secret params; + struct page **pages; + void *blob, *hdr; + unsigned long n; + int ret; + + if (!sev_guest(kvm)) + return -ENOTTY; + + if (copy_from_user(¶ms, (void __user *)(uintptr_t)argp->data, sizeof(params))) + return -EFAULT; + + pages = sev_pin_memory(kvm, params.guest_uaddr, params.guest_len, &n, 1); + if (!pages) + return -ENOMEM; + + /* + * The secret must be copied into contiguous memory region, lets verify + * that userspace memory pages are contiguous before we issue command. + */ + if (get_num_contig_pages(0, pages, n) != n) { + ret = -EINVAL; + goto e_unpin_memory; + } + + ret = -ENOMEM; + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + goto e_unpin_memory; + + blob = psp_copy_user_blob(params.trans_uaddr, params.trans_len); + if (IS_ERR(blob)) { + ret = PTR_ERR(blob); + goto e_free; + } + + data->trans_address = __psp_pa(blob); + data->trans_len = params.trans_len; + + hdr = psp_copy_user_blob(params.hdr_uaddr, params.hdr_len); + if (IS_ERR(hdr)) { + ret = PTR_ERR(hdr); + goto e_free_blob; + } + data->trans_address = __psp_pa(blob); + data->trans_len = params.trans_len; + + data->handle = sev->handle; + ret = sev_issue_cmd(kvm, SEV_CMD_LAUNCH_UPDATE_SECRET, data, &argp->error); + + kfree(hdr); + +e_free_blob: + kfree(blob); +e_free: + kfree(data); +e_unpin_memory: + sev_unpin_memory(kvm, pages, n); + return ret; +} + static int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -6435,6 +6500,9 @@ static int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_DBG_ENCRYPT: r = sev_dbg_crypt(kvm, &sev_cmd, false); break; + case KVM_SEV_LAUNCH_SECRET: + r = sev_launch_secret(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out;