From patchwork Thu Mar 2 15:17:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9600833 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 E1D0760414 for ; Thu, 2 Mar 2017 16:08:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0ABE2858C for ; Thu, 2 Mar 2017 16:08:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4C8D285A3; Thu, 2 Mar 2017 16:08:47 +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 2DDEC2858C for ; Thu, 2 Mar 2017 16:08:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751648AbdCBQGI (ORCPT ); Thu, 2 Mar 2017 11:06:08 -0500 Received: from mail-by2nam03on0042.outbound.protection.outlook.com ([104.47.42.42]:30518 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751930AbdCBPfA (ORCPT ); Thu, 2 Mar 2017 10:35:00 -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=fQAM99yjonB28ZQUcgHNQnnsFaC4BgeGg8uH7X6yeiQ=; b=SrCoe2wexbhM2ynLAG0h0k5dDmcLGUzoCooPKz7R7U9Qogo32RKMet/J1iU43HVRuBdq3FKeaSbcRVBpeSZ/MjmKLaNW15d9F8+8aZkY7n0X7Jk/RYmRkxb4ziWV2YMp7fLqQWJiejpfAU9aEu+YnowkQtavgNu/pQNRrexKCGo= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=amd.com; Received: from [127.0.1.1] (165.204.77.1) by CY4PR12MB1606.namprd12.prod.outlook.com (10.172.72.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.933.12; Thu, 2 Mar 2017 15:17:49 +0000 Subject: [RFC PATCH v2 26/32] kvm: svm: Add support for SEV LAUNCH_UPDATE_DATA command From: Brijesh Singh To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Date: Thu, 2 Mar 2017 10:17:47 -0500 Message-ID: <148846786714.2349.17724971671841396908.stgit@brijesh-build-machine> In-Reply-To: <148846752022.2349.13667498174822419498.stgit@brijesh-build-machine> References: <148846752022.2349.13667498174822419498.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: CY4PR19CA0036.namprd19.prod.outlook.com (10.172.173.150) To CY4PR12MB1606.namprd12.prod.outlook.com (10.172.72.15) X-MS-Office365-Filtering-Correlation-Id: 2d037c2c-6aae-44e5-993e-08d4617f4ab4 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:CY4PR12MB1606; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1606; 3:SznpmNhuBd/QtD41q8TeHPAwRYtLMEgYRllfKvhddVkTVgawkrQSOYGLzjnl/lUhbBG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pDxSwX2Mb3ydz/CofA4Nh0Mv6F630XrfLnY0ZQdXSO/0E8bV3VE5wKEgHjp447qdagv2hQ2QVM1yhxxWaDZONbdNSJ7d/hVGSfQiIsFQC8t9TI5tRlma4MhuTCDnepN4Qsb+7hThm00+xxaPKH5R5J02mM1HIY2T5cAHeV834KVX5WxV54YRoIbaD9LILSAeu0e/0gBoyq5uNeQqHD0ZsRr89jwHpXaAQ3NzF0OyqCIa3c+5xT0WLgrBCEoTRkZmFevGD142iz/A5gPk4QMUENWDdH8f9j8YARGXWy5g+ptxmAwFRNG/4Qm0wvRv7q2yw3wCd4lL6wihDwNM9ePXfuksKW0NNGb1fDlp6KxnlJxGqGR1evoVZJY4a0F+Islq/L89lccU8ai/v7MgiBGXB1Sv0wvfVCSadkqBH X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6055026)(6041248)(20161123560025)(20161123555025)(20161123562025)(20161123564025)(20161123558025)(6072148); SRVR:CY4PR12MB1606; BCL:0; PCL:0; RULEID:; SRVR:CY4PR12MB1606; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1606; 4:ksiXK4a0eSlEu6xqQbcW6ySCf1SEuu9cEbfDa8RdDxWOmXFW3QleW6H0AbFG0OngNcDPZsJ7ZY71Lcrqmi7bQ/xo3BY8Uml9glCIDoXPVjtaSHgzsA59sTC3hXDenIb7nXYfqwOhjCF0Qk1aaprd3SfZXdd0D/dJc3Ldvyx9yI7WQAUy/jgMw684/Q+TlzYdEnmg0mFlBNLpaSqwMon1kKK/pzDF+pk3ID8TbyVJGDafkLcPSMqfbayB7vgcEmoNlUiwRy0mz1h/GI+obPNEa5cMSFTLf0QadfO5AE6LeluenQj2hJs0bL0lXEuURj6DuLrTWOE259nLZx75Jlih2gk90YDiZj3N3GEO+a5OgaXU4jiMvoon9xJVVR5qOxIrNnOw3DeIND6je3jpNOt31UBJ+Vf/Z70YmUj1qLJob03ecthe9bumNCN4XJ/A2x+q0knvTCy4Q/zTPvmY2pZ/WVmwsKOfQbj/ks4Yidp4FTZGYL4f0T08lp9QdwY/pQxAwjYB7usNJ5sLPk8khjPgwdVtwKmt7Xqg6pI5uMK2pcBv+3LxIpnZGqeFvpyfvmOD+guV/XSgNjDKEOKKl1WsvskWvjxr/fmXLlHeeLJcps6SL2NHnC/G9cNI/b5707UTzN/f3FSgay8h6syYb61lgChn391pro12LPg3dmmFeUg= X-Forefront-PRVS: 023495660C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6049001)(6009001)(7916002)(39410400002)(39450400003)(39860400002)(39840400002)(39850400002)(77096006)(6486002)(8676002)(81166006)(7736002)(1191002)(90366009)(9686003)(54356999)(76176999)(25786008)(92566002)(103116003)(6116002)(50986999)(50466002)(3846002)(2950100002)(7366002)(42186005)(189998001)(5660300001)(305945005)(7416002)(230700001)(33646002)(7406005)(38730400002)(33716001)(83506001)(23676002)(66066001)(2201001)(86362001)(2906002)(47776003)(53936002)(921003)(1121003)(217873001)(84006005)(83996005)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR12MB1606; H:[127.0.1.1]; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTRQUjEyTUIxNjA2OzIzOnc2RHNGd2xnb0o3M0JWQ1JEalh1TGJpcXJM?= =?utf-8?B?YndOYm9TRzRnQ0F6Q3VlOFQyNlRKS0hlTC9mOWZrVTBBNVBEVDZaRE9aTHA1?= =?utf-8?B?aWt6QUxYcC9RT3JnNGdiWkYyQkh6Z1dOankvUVlpVnpRamhOTE1tWCtoRERC?= =?utf-8?B?NUJYTVVtUzRQTnhNdGRuNGU0RkZ0SVBhRm9pUEJxd3J3WmZzN3VFWFgwcjNk?= =?utf-8?B?V0phRUtndUNYUmVVRmpoWWRjc3Jadlc1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IHYGpYJFeDkmMZVfS8EgD5nuY8qvSN7FINLTx3sY9xc1kcI+yH9DIlx81j90Bogo0=; 5:7X5xK6Wt6HUlItJiZWQlAP/zjebWQAPJwVmagFM1Sy1ERfulbri0y6uAp/RX0lOJ6NZ5r1AeYUNlZP3LNdvl9YFz1ifuCY6gGF8PtP+omcAQn47MTgcnJOBK+mFlAwZjag0jrUJf8483lodrmSdCKQ==; 24:a0CHVbJcTDtveetrsXGbarPhKPnDa+/IjIuCqRo2+ZF/kDyX8jpS7a9l27NSxTyJqhkHestld5CObu3RjgVcqmutaqq8MabPibfHnxGRoew= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1606; 7:nMHoVh4D4niqiYyhLKyagl/B94EoNg6fR+ChOjjGVSXHCjqoS08D+gesdPd7jrA3pLUKMWB7UzOMAr47KRORpFsXp5gmKk91H0/4saEU39nIJdlOLb2cuyh6yBDtCYRq9gPQ1cjsVvr5hBzBuScB3Q8DyCXwlgs2RU34HPuulNxHOVHaHHd4G8ZbobKU/Jy6Ed9CfhL32qH76YcwMZ/vKl7PP3auRgjkRbLrEitQcDjq/fTgsweh7S10ZjbkHwWHc/5j6EpugxJyhRxvqK0j2ed099J3wjDv2IXpS0zLjIUON3zUcWDloHgSwwHxOgqxxD+9gHdLhxdlITxDa0uzVg==; 20:9afRTphBAe0YndZjEEYcjua5b2keoUIZG2eYQ7ehJY3tt0s/DS3HITNtwlCbzvqnsdxqN55jr/GMoDgOZ3b/0ZIs8Fd3sPHhXcBDRF9pn8/o0ytPVCTBup7TMAzz2HJxaHRSl9oUX5ZkXGVjcp316kbYZv+25ecUVygqWR2NkaCFywJS3Udy0zN+i81eysgY8tVOV0VXM/VUffl3xvlskRJbuYSyjA7giT4v8KmPsI0OE9e9au96LBIr/WAw0Tha X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2017 15:17:49.1454 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 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 is used for encrypting the guest memory region using the VM encryption key (VEK) created from LAUNCH_START. Signed-off-by: Brijesh Singh --- arch/x86/kvm/svm.c | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index b5fa8c0..62c2b22 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -38,6 +38,8 @@ #include #include #include +#include +#include #include #include @@ -502,6 +504,7 @@ static void sev_deactivate_handle(struct kvm *kvm); static void sev_decommission_handle(struct kvm *kvm); static int sev_asid_new(void); static void sev_asid_free(int asid); +#define __sev_page_pa(x) ((page_to_pfn(x) << PAGE_SHIFT) | sme_me_mask) static bool kvm_sev_enabled(void) { @@ -5775,6 +5778,149 @@ static int sev_launch_start(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static struct page **sev_pin_memory(unsigned long uaddr, unsigned long ulen, + unsigned long *n) +{ + struct page **pages; + int first, last; + unsigned long npages, pinned; + + /* Get number of pages */ + first = (uaddr & PAGE_MASK) >> PAGE_SHIFT; + last = ((uaddr + ulen - 1) & PAGE_MASK) >> PAGE_SHIFT; + npages = (last - first + 1); + + pages = kzalloc(npages * sizeof(struct page *), GFP_KERNEL); + if (!pages) + return NULL; + + /* pin the user virtual address */ + down_read(¤t->mm->mmap_sem); + pinned = get_user_pages_fast(uaddr, npages, 1, pages); + up_read(¤t->mm->mmap_sem); + if (pinned != npages) { + printk(KERN_ERR "SEV: failed to pin %ld pages (got %ld)\n", + npages, pinned); + goto err; + } + + *n = npages; + return pages; +err: + if (pinned > 0) + release_pages(pages, pinned, 0); + kfree(pages); + + return NULL; +} + +static void sev_unpin_memory(struct page **pages, unsigned long npages) +{ + release_pages(pages, npages, 0); + kfree(pages); +} + +static void sev_clflush_pages(struct page *pages[], int num_pages) +{ + unsigned long i; + uint8_t *page_virtual; + + if (num_pages == 0 || pages == NULL) + return; + + for (i = 0; i < num_pages; i++) { + page_virtual = kmap_atomic(pages[i]); + clflush_cache_range(page_virtual, PAGE_SIZE); + kunmap_atomic(page_virtual); + } +} + +static int sev_launch_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct page **inpages; + unsigned long uaddr, ulen; + int i, len, ret, offset; + unsigned long nr_pages; + struct kvm_sev_launch_update_data params; + struct sev_data_launch_update_data *data; + + if (!sev_guest(kvm)) + return -EINVAL; + + /* Get the parameters from the user */ + ret = -EFAULT; + if (copy_from_user(¶ms, (void *)argp->data, + sizeof(struct kvm_sev_launch_update_data))) + goto err_1; + + uaddr = params.address; + ulen = params.length; + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) { + ret = -ENOMEM; + goto err_1; + } + + /* pin user pages */ + inpages = sev_pin_memory(params.address, params.length, &nr_pages); + if (!inpages) { + ret = -ENOMEM; + goto err_2; + } + + /* invalidate the cache line for these pages to ensure that DRAM + * has recent content before calling the SEV commands to perform + * the encryption. + */ + sev_clflush_pages(inpages, nr_pages); + + /* the array of pages returned by get_user_pages() is a page-aligned + * memory. Since the user buffer is probably not page-aligned, we need + * to calculate the offset within a page for first update entry. + */ + offset = uaddr & (PAGE_SIZE - 1); + len = min_t(size_t, (PAGE_SIZE - offset), ulen); + ulen -= len; + + /* update first page - + * special care need to be taken for the first page because we might + * be dealing with offset within the page + */ + data->handle = sev_get_handle(kvm); + data->length = len; + data->address = __sev_page_pa(inpages[0]) + offset; + ret = sev_issue_cmd(kvm, SEV_CMD_LAUNCH_UPDATE_DATA, + data, &argp->error); + if (ret) + goto err_3; + + /* update remaining pages */ + for (i = 1; i < nr_pages; i++) { + + len = min_t(size_t, PAGE_SIZE, ulen); + ulen -= len; + data->length = len; + data->address = __sev_page_pa(inpages[i]); + ret = sev_issue_cmd(kvm, SEV_CMD_LAUNCH_UPDATE_DATA, + data, &argp->error); + if (ret) + goto err_3; + } + + /* mark pages dirty */ + for (i = 0; i < nr_pages; i++) { + set_page_dirty_lock(inpages[i]); + mark_page_accessed(inpages[i]); + } +err_3: + sev_unpin_memory(inpages, nr_pages); +err_2: + kfree(data); +err_1: + return ret; +} + static int amd_memory_encryption_cmd(struct kvm *kvm, void __user *argp) { int r = -ENOTTY; @@ -5790,6 +5936,10 @@ static int amd_memory_encryption_cmd(struct kvm *kvm, void __user *argp) r = sev_launch_start(kvm, &sev_cmd); break; } + case KVM_SEV_LAUNCH_UPDATE_DATA: { + r = sev_launch_update_data(kvm, &sev_cmd); + break; + } default: break; }