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

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