From patchwork Mon Aug 22 23:28:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9294651 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 17D61607F0 for ; Mon, 22 Aug 2016 23:30:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07ED628899 for ; Mon, 22 Aug 2016 23:30:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F022028A87; 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=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 970C328899 for ; Mon, 22 Aug 2016 23:29:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756514AbcHVX3B (ORCPT ); Mon, 22 Aug 2016 19:29:01 -0400 Received: from mail-co1nam03on0064.outbound.protection.outlook.com ([104.47.40.64]:43139 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753111AbcHVX25 (ORCPT ); Mon, 22 Aug 2016 19:28:57 -0400 X-Greylist: delayed 314 seconds by postgrey-1.27 at vger.kernel.org; Mon, 22 Aug 2016 19:28:56 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=t0XE+4SaygAsDNoWvavro+4qbijPceoP0qeIWoHcgkk=; b=p5JoijgreA89La9QDyNTaJNrvJvqwLuEzvNIAeOpGJonpTRrQUZlCPjk/8byMHnh4iOfdC00cmZAh2AeWAt5eV8OlM214/k+sjWwArIam5Yc35yHWyzlRsRL+HM8BI3MNzVimRAD83/0jekTD9q0EZiTUzShZKYHJwhMVdYXwEE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from [127.0.1.1] (165.204.77.1) by BLUPR12MB0657.namprd12.prod.outlook.com (10.163.217.27) 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:28:46 +0000 Subject: [RFC PATCH v1 23/28] KVM: SVM: add SEV launch update command From: Brijesh Singh To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Date: Mon, 22 Aug 2016 19:28:44 -0400 Message-ID: <147190852423.9523.11936794196855765674.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: BY2PR21CA0020.namprd21.prod.outlook.com (10.162.74.158) To BLUPR12MB0657.namprd12.prod.outlook.com (10.163.217.27) X-MS-Office365-Filtering-Correlation-Id: d09e58b5-a93d-4851-4021-08d3cae413be X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0657; 2:6DBG1LiK49iiRrFYH++T5pFFUmrFX0hUAjUwiVdj/2UVdT+2cspkRpze3XU3pZ7+X3frqJSKvDPem1Nk3X05lWg1IuoRZzSdRkdFPAODDt7NIu95GVgbx1qWN3O4Z/ppvjig94faXEbBRt13YqQ+3CaccM10ntYyvfXhmrCulXI9M996WWhQRF5JFM+JFw5d; 3:/aEfI8NzAY90mvKQvpApbjYBsGD3BZfsECi8GoTpOO17TFI62yW5TykjFIneZg2+umap02RyOOgMnKn6/guogMBHNQ9s45lC3SStpM2OmIiiDicltdxwdIpMd2NGB9mn X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR12MB0657; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0657; 25:lTemeFC8RKSRs/tbr/xxxdDWMpEK6wiFcsp7A2FwbKQwBJn04EMfDXRMjvF0mZLkyDzq+ksYUZFdSK/w4VOHgwmmZHU84yyl1/skEiZsiNu1bt4s1KsHJ+AnC6BKX0ijTqyR/eUEf7b/Rg7l1+O0q3eHulOqN0RMVfqCFUbrDnx0FUDy3n5l6sX14P3d/4Zy+DICveWjIa+EOcE3I55zxKRM08rcIcCrSrQP9czsECN/aE5AIWGCzXip8pUlPntIesN6vkZriygKi4x8pHYTdjVNvRLpKXrlEG0MghL2i1pFfxjuqqoEJy4hZxjAcPK/Z0ocbkXtvUUfE63XF05YUfAgE4CZDSal1GXA13+iO/ygzy1KvA44N+QOrtYs/sDjrzDIhg648UIV/Fevp5hXcthgeudLwGjI+jt9wUK82UN94tPbbPb4+GMq+41pt+VdmkdPNm9DRof4xWza81h0AiWOc8f9dNB8MZzCD19Bgy+gcMqon4rI1UjxEQ4yVHqaUOsEOmr+mO5HIN06adIWVP3hjPRhJcz3NH8XxtIMT4MiLjYObkt7Wu400I7QPgpm9g6bj0lkO7ufsxUhPz242PZKJZK6va2qGBwClZKLl2qPhSGcyc80cQr+pPWpD4lHGfEpVC0u7cQyDfwt/jDdt5hv939eg1p/KZex4OnMvmYdLZq+X7cjbZu4loBYsCtOgIeTkcNOcpdv0OqPwyV+fnVFHeLKGO+p2kmhRe7BeWXY8R1ypp4V/7BLb02qv1fchfvmRaH1POJvRoBxpfOczFNIwl6o6hf/Z4H804DCyPQ= X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0657; 31:EliG2N0tLY1kqfkbDoNfQWfwHrMSPdzOgcHsjXOlKrIddAYBKKHuGKr0EIR/DyIJNG5LQGRZD+bzz8I9LWN3kF7f0ovClHWFBoel1JXdd5DMWvjuMAfi7fCu2vXhDTjSap1gYRZ8F84/hIRJ623NwTwo/dVs4iiC+BsvEFzsQ445hkiuNeKHRY2k3mkhc0P+bGcU+9hi8wSt7WZGo+tF2Fc/jI2Bjkyggq7KazOrZYA=; 20:Lg2KEjsa8zdKBL8qSht1NtUFCPA29bT4tZmHZvWT7cEc0oYkmSF7Tk1+SoayaqOeZxkMEjssXYygI8GpwOKe8v34olBNB9LYKp4eQIKejP4vk/Q+NPm1eaVa6V8ySkagg403wXx/9e8l108vX2HPU/wl3Crm0s5oMB4qONRUv9/j+JtTOcyPEG6Bh/tPgVxF3C60kwfZ0QZcKyaOqRTIanGygFXotclHZPyfcf0LDdDdLo6QpAilmW2Iy6Gsp1bECVkajo0ODlON0kkjFW+/Kww2Y7A1eplnNruFU9DQqtHHCLN70hfmqZ7W32FNWxirJcpi2MYBVovPzHRj8QjTcqCwCjcqDouCXe7dJcqjLWdUKpSCMeimbnY4K1E322fI1BiCQhoCSvV4VGSz3A6L2o6gN6Cj08AHSVLOYbLxGKYUlwYMOrrDF6HTV0GXC1/gQcD14yT/dSretVd5FKCgqC3FKissTpohYYOJFKK1ORED8AjxUAeswdyi7pdpFAwN 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:BLUPR12MB0657; BCL:0; PCL:0; RULEID:; SRVR:BLUPR12MB0657; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0657; 4:79+TIIqWpvssPfmEXiSyNRsX7sWrdtzc2UEAYxzgkV9g70TdncOnk2Kf3NZPTRmpyqMFigAURpnTpjppSx5HfGKF1CEDpbHQe3z6jzWQUkL7CPaRKgWdtY7ou8j/U043gzoTibJD4vbq/nCAX9sBvKddajjWxEsGnVy2c9pvDkaNVNz4b8iJSQWjTM2ssOQVafR0FZV1GuK2nujLIH3OBoS67Qg2SE56r17njTX3ZT4TfmJueCqNOAiH/ZBkiyiCqp+4MZiLdyDqrGljdpvvdckOL5+kUK6aJvTLXK48uRGMRRswiNRkuLNWp/kE7KdyozJH1Aq0fNQb1RiqlgI9P1q3Lbih8e1uvni7IO9qt76fhMgH9F4BQWhNrsHqaYUSdDkRpyURZYrE7t/1s9oaIancq9PMIi7MrGn3lzceaBBY2VQzBFh4DY1hyoYtIV0I X-Forefront-PRVS: 00429279BA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6049001)(7916002)(199003)(189002)(105586002)(76176999)(229853001)(83506001)(54356999)(42186005)(189998001)(15650500001)(305945005)(7416002)(4001350100001)(5001770100001)(23676002)(107886002)(7736002)(97736004)(19580395003)(5660300001)(2420400007)(7846002)(2201001)(19580405001)(33716001)(68736007)(50986999)(33646002)(7406005)(8676002)(103116003)(3846002)(15975445007)(586003)(230700001)(50466002)(77096005)(2950100001)(6116002)(47776003)(86362001)(7110500001)(92566002)(101416001)(10710500007)(2906002)(66066001)(106356001)(9686002)(81156014)(81166006)(921003)(1121003)(217873001)(2101003)(83996005); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR12MB0657; H:[127.0.1.1]; 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) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTFVQUjEyTUIwNjU3OzIzOjRscnNNaWJFcGZnTnYvS3BqU3BiNWZ6eG5V?= =?utf-8?B?TGZyb01tcTBvMncrdzhvV1E0TlIza0h5MG9pcVhkNWV4UVNmdTN4WWRiM2tp?= =?utf-8?B?TE1oeDNvUG5aeVN0SVlSVVRleVRoRjFGb2ozeWFZK1A2RUFVa1UzVHp3K0x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l0o6itCteImdRHyCiGIiXLlFUagoc0x+SAkEzlP6SyXcSLGEgRQBV9YpisP46CuAnePeJYyZqqJ/9uJt9zURIK+VNLxh7gLkkxerfz2jPj2wB3hmnF9PD4y1wDVhoAmtiGo3iKc+R70Nl/rDmI+YIRZ4/a0R/kpTJ4AdQ76wcG3/DBPYo4/lJZpCsULPdG3bP6XjzCiaLJDnBELTU/ZN9q3IKi+Ya6IFdMetekeyQ/fpAb2qbBLzSAyeeO X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2016 23:28:46.9699 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0657 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 encrypting guest memory region. For more information see [1], section 6.2 [1] http://support.amd.com/TechDocs/55766_SEV-KM%20API_Spec.pdf Signed-off-by: Brijesh Singh --- arch/x86/kvm/svm.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 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 0b6da4a..c78bdc6 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -35,6 +35,8 @@ #include #include #include +#include +#include #include #include @@ -263,6 +265,8 @@ static unsigned long *sev_asid_bitmap; #define svm_sev_guest() (svm->vcpu.kvm->arch.sev_info.handle) #define svm_sev_ref_count() (svm->vcpu.kvm->arch.sev_info.ref_count) +#define __sev_page_pa(x) ((page_to_pfn(x) << PAGE_SHIFT) | sme_me_mask) + static int sev_asid_new(void); static void sev_asid_free(int asid); static void sev_deactivate_handle(unsigned int handle); @@ -5376,6 +5380,123 @@ err_1: return ret; } +static int sev_pre_update(struct page **pages, unsigned long uaddr, int npages) +{ + int pinned; + + /* pin the user virtual address */ + down_read(¤t->mm->mmap_sem); + pinned = get_user_pages(uaddr, npages, 1, 0, pages, NULL); + up_read(¤t->mm->mmap_sem); + if (pinned != npages) { + printk(KERN_ERR "SEV: failed to pin %d pages (got %d)\n", + npages, pinned); + goto err; + } + + return 0; +err: + if (pinned > 0) + release_pages(pages, pinned, 0); + return 1; +} + +static int sev_launch_update(struct kvm *kvm, + struct kvm_sev_launch_update __user *arg, + int *psp_ret) +{ + int first, last; + struct page **inpages; + int ret, nr_pages; + unsigned long uaddr, ulen; + int i, buffer_len, len, offset; + struct kvm_sev_launch_update params; + struct psp_data_launch_update *update; + + /* Get the parameters from the user */ + if (copy_from_user(¶ms, arg, sizeof(*arg))) + return -EFAULT; + + uaddr = params.address; + ulen = params.length; + + /* Get number of pages */ + first = (uaddr & PAGE_MASK) >> PAGE_SHIFT; + last = ((uaddr + ulen - 1) & PAGE_MASK) >> PAGE_SHIFT; + nr_pages = (last - first + 1); + + /* allocate the buffers */ + buffer_len = sizeof(*update); + update = kzalloc(buffer_len, GFP_KERNEL); + if (!update) + return -ENOMEM; + + ret = -ENOMEM; + inpages = kzalloc(nr_pages * sizeof(struct page *), GFP_KERNEL); + if (!inpages) + goto err_1; + + ret = sev_pre_update(inpages, uaddr, nr_pages); + if (ret) + goto err_2; + + /* 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 + */ + update->hdr.buffer_len = buffer_len; + update->handle = kvm_sev_handle(); + update->length = len; + update->address = __sev_page_pa(inpages[0]) + offset; + clflush_cache_range(page_address(inpages[0]), PAGE_SIZE); + ret = psp_guest_launch_update(update, 5, psp_ret); + if (ret) { + printk(KERN_ERR "SEV: LAUNCH_UPDATE addr %#llx len %d " + "ret=%d (%#010x)\n", update->address, + update->length, ret, *psp_ret); + goto err_3; + } + + /* update remaining pages */ + for (i = 1; i < nr_pages; i++) { + + len = min_t(size_t, PAGE_SIZE, ulen); + ulen -= len; + update->length = len; + update->address = __sev_page_pa(inpages[i]); + clflush_cache_range(page_address(inpages[i]), PAGE_SIZE); + + ret = psp_guest_launch_update(update, 5, psp_ret); + if (ret) { + printk(KERN_ERR "SEV: LAUNCH_UPDATE addr %#llx len %d " + "ret=%d (%#010x)\n", update->address, + update->length, ret, *psp_ret); + goto err_3; + } + } + +err_3: + /* mark pages dirty */ + for (i = 0; i < nr_pages; i++) { + set_page_dirty_lock(inpages[i]); + mark_page_accessed(inpages[i]); + } + release_pages(inpages, nr_pages, 0); +err_2: + kfree(inpages); +err_1: + kfree(update); + return ret; +} + static int amd_sev_issue_cmd(struct kvm *kvm, struct kvm_sev_issue_cmd __user *user_data) { @@ -5391,6 +5512,11 @@ static int amd_sev_issue_cmd(struct kvm *kvm, &arg.ret_code); break; } + case KVM_SEV_LAUNCH_UPDATE: { + r = sev_launch_update(kvm, (void *)arg.opaque, + &arg.ret_code); + break; + } default: break; }