lkml.org 
[lkml]   [2022]   [Mar]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH v11 22/45] x86/sev: Use SEV-SNP AP creation to start secondary CPUs
From


On 3/3/22 11:09, Dave Hansen wrote:
> On 2/24/22 08:56, Brijesh Singh wrote:
>> + /*
>> + * Allocate VMSA page to work around the SNP erratum where the CPU will
>> + * incorrectly signal an RMP violation #PF if a large page (2MB or 1GB)
>> + * collides with the RMP entry of VMSA page. The recommended workaround
>> + * is to not use a large page.
>> + *
>> + * Allocate one extra page, use a page which is not 2MB-aligned
>> + * and free the other.
>> + */
>> + p = alloc_pages(GFP_KERNEL_ACCOUNT | __GFP_ZERO, 1);
>> + if (!p)
>> + return NULL;
>> +
>> + split_page(p, 1);
>> +
>> + pfn = page_to_pfn(p);
>> + if (IS_ALIGNED(__pfn_to_phys(pfn), PMD_SIZE)) {
>> + pfn++;
>> + __free_page(p);
>> + } else {
>> + __free_page(pfn_to_page(pfn + 1));
>> + }
>> +
>> + return page_address(pfn_to_page(pfn));
>> +}
>
> This can be simplified. There's no need for all the sill pfn_to_page()
> conversions or even an alignment check. The second page (page[1]) of an
> order-1 page is never 2M/1G aligned. Just use that:
>
> // Alloc an 8k page which is also 8k-aligned:
> p = alloc_pages(GFP_KERNEL_ACCOUNT | __GFP_ZERO, 1);
> if (!p)
> return NULL;
>
> split_page(p, 1);
>
> // Free the first 4k. This page _may_
> // be 2M/1G aligned and can not be used:
> __free_page(p);
>
> // Return the unaligned page:
> return page_address(p+1);
>

Ack, I am good with using your version.

-Brijesh

\
 
 \ /
  Last update: 2022-03-03 19:02    [W:0.075 / U:0.104 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site