[PATCH v2] drivers: xen: unmap Enlighten page before jumping to Linux

Oleksandr olekstysh at gmail.com
Thu Jul 21 17:11:30 CEST 2022


On 19.07.22 17:55, Dmytro Firsov wrote:

Hello Dmytro


First of all, thanks for fixing this issue.

Patch looks good, just a nit below.

> This commit fixes issue with usage of Xen hypervisor shared info page.
> Previously U-boot did not unmap it at the end of OS boot process. Xen
> did not prevent guest from this. So, it worked, but caused wierd
> issues - one memory page, that was returned by memalign in U-boot
> for Enlighten mapping was not unmaped by Xen (shared_info values was
> not removed from there) and returned to allocator. During the Linux
> boot, it uses shared_info page as regular RAM page, which leads to
> hypervisor shared info corruption.
>
> So, to fix this issue, as discussed on the xen-devel mailing list, the
> code should:
>     1) Unmap the page
>     2) Populate the area with memory using XENMEM_populate_physmap
>
> This patch adds page unmapping via XENMEM_remove_from_physmap, fills
> hole in address space where page was mapped via XENMEM_populate_physmap
> and return this address to memory allocator for freeing.
>
> Signed-off-by: Dmytro Firsov <dmytro_firsov at epam.com>
> ---
>
> Changes in v2:
> - Reword commit message to be more clear with purpose of the patch
> - Change BUG() helper to panic() and add error messages
> - Add struct zeroing during initialization
> - Fix typo in comment
> ---
>   drivers/xen/hypervisor.c | 31 +++++++++++++++++++++++++++++++
>   1 file changed, 31 insertions(+)
>
> diff --git a/drivers/xen/hypervisor.c b/drivers/xen/hypervisor.c
> index 2560894832..16c7c96c94 100644
> --- a/drivers/xen/hypervisor.c
> +++ b/drivers/xen/hypervisor.c
> @@ -144,6 +144,36 @@ struct shared_info *map_shared_info(void *p)
>   	return HYPERVISOR_shared_info;
>   }
>   
> +void unmap_shared_info(void)
> +{
> +	xen_pfn_t shared_info_pfn = virt_to_pfn(HYPERVISOR_shared_info);
> +	struct xen_remove_from_physmap xrfp = {0};
> +	struct xen_memory_reservation reservation = {0};
> +	xen_ulong_t nr_exts = 1;
> +
> +	xrfp.domid = DOMID_SELF;
> +	xrfp.gpfn = shared_info_pfn;
> +	if (HYPERVISOR_memory_op(XENMEM_remove_from_physmap, &xrfp) != 0)
> +		panic("Failed to unmap HYPERVISOR_shared_info\n");
> +
> +	/*
> +	 * After removing from physmap there will be a hole in address space on
> +	 * HYPERVISOR_shared_info address, so to free memory allocated with
> +	 * memalign and prevent exceptions during access to this page we need to
> +	 * fill this 4KB hole with XENMEM_populate_physmap before jumping to Linux.
> +	 */
> +	reservation.domid = DOMID_SELF;
> +	reservation.extent_order = 0;
> +	reservation.address_bits = 0;

I think the explicit field's zeroing could be dropped now.


[snip]

-- 
Regards,

Oleksandr Tyshchenko



More information about the U-Boot mailing list