Re: [PATCH v11 22/45] x86/sev: Use SEV-SNP AP creation to start secondary CPUs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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);



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux