[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5fb4d24c-f070-cc22-7a47-fb55ba430011@amd.com>
Date: Thu, 16 Mar 2017 13:20:06 -0500
From: Brijesh Singh <brijesh.singh@....com>
To: Paolo Bonzini <pbonzini@...hat.com>, <simon.guinot@...uanux.org>,
<linux-efi@...r.kernel.org>, <kvm@...r.kernel.org>,
<rkrcmar@...hat.com>, <matt@...eblueprint.co.uk>,
<linux-pci@...r.kernel.org>, <linus.walleij@...aro.org>,
<gary.hook@....com>, <linux-mm@...ck.org>,
<paul.gortmaker@...driver.com>, <hpa@...or.com>, <cl@...ux.com>,
<dan.j.williams@...el.com>, <aarcange@...hat.com>,
<sfr@...b.auug.org.au>, <andriy.shevchenko@...ux.intel.com>,
<herbert@...dor.apana.org.au>, <bhe@...hat.com>,
<xemul@...allels.com>, <joro@...tes.org>, <x86@...nel.org>,
<peterz@...radead.org>, <piotr.luc@...el.com>, <mingo@...hat.com>,
<msalter@...hat.com>, <ross.zwisler@...ux.intel.com>, <bp@...e.de>,
<dyoung@...hat.com>, <thomas.lendacky@....com>, <jroedel@...e.de>,
<keescook@...omium.org>, <arnd@...db.de>, <toshi.kani@....com>,
<mathieu.desnoyers@...icios.com>, <luto@...nel.org>,
<devel@...uxdriverproject.org>, <bhelgaas@...gle.com>,
<tglx@...utronix.de>, <mchehab@...nel.org>,
<iamjoonsoo.kim@....com>, <labbott@...oraproject.org>,
<tony.luck@...el.com>, <alexandre.bounine@....com>,
<kuleshovmail@...il.com>, <linux-kernel@...r.kernel.org>,
<mcgrof@...nel.org>, <mst@...hat.com>,
<linux-crypto@...r.kernel.org>, <tj@...nel.org>,
<akpm@...ux-foundation.org>, <davem@...emloft.net>
CC: <brijesh.singh@....com>
Subject: Re: [RFC PATCH v2 26/32] kvm: svm: Add support for SEV
LAUNCH_UPDATE_DATA command
On 03/16/2017 05:48 AM, Paolo Bonzini wrote:
>
>
> On 02/03/2017 16:17, Brijesh Singh wrote:
>> +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);
>
> get_user_pages_fast, like get_user_pages_unlocked, must be called
> without mmap_sem held.
Sure.
>
>> + 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;
>> +}
>>
>> + /* 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
>> + */
>
> No need to special case the first page; just set "offset = 0" inside the
> loop after the first iteration.
>
Will do.
-Brijesh
Powered by blists - more mailing lists