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

Re: [PATCH] xen/arm: skip holes in physical address space when setting up frametable


  • To: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • From: "Orzel, Michal" <michal.orzel@xxxxxxx>
  • Date: Tue, 21 Apr 2026 12:33:46 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=arm.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VxmIw3KmI0vcN0/yo8LF+iFhya3BDpRME4P4eJ4t2CA=; b=rQ2V5px5ucAxiMVF3mX7IOf5IM+8710M+DERFhCW+4v3wBDvHUpLO+S4N5uM3s8TSwFk4ukl0VOtRgR6aYVRuVLpPowWSesC/XHLb4D7pNzsmfT50ufLp+J1nOJz34yqvX36Qt29QgGh4UAKZa3DO+0bPrfKMguufq+rXPbYgF8dI6pca+5xCtTKgsNC/v8WKeBijXFKqjt+3ZqmiBzUf0Oa7D59SY8eTymrGyL/7LvVtgXxqLaLFkX7kU1coBpjY3jFFYcHm9sxOcHl7HybKRrQ1EEbPVlfkxr2bq101A/kquo4uHCFtraJTa+KdW6zWEBv18yA10+v/znlEmQLwg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NbeTWD0poOGL/jD6lJmAGOstYfXbpo9LYns9Nt8SuoW0gVD9TuOZ5H4+Tk0zTZjbhvX2OHI2aGUrg0kbTybemDEQnahRuECKRns0q63PI96e/2CiyolBilDBPw15dVCWpyQheFNnJ1NPd6OV7WdFLXTU8ZyjLDuRBRzv/SWueQDWhFxVdLloZwv2VXogcc+U6joaPFrErI9Ztb2fWQB3/bWSIBnX4VIMuhc/5Qj8O9AwWKo+zR+xKH+qCx8ix0ALOaEQvMYyyCjjkn+OdmvGQazeRTXGSZi6zp9PlBZEXzi9xoQ+/4Kjkf0e7vucjOrfmNWjbSG3drsOEXKB2o6mRQ==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=amd.com header.i="@amd.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "Stefano Stabellini" <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, "Bertrand Marquis" <Bertrand.Marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Tue, 21 Apr 2026 10:34:04 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 20/04/2026 16:06, Luca Fancellu wrote:
> HI Michal,
> 
>>>> +void __init init_frametable(paddr_t ram_start)
>>>> +{
>>>> +    unsigned int sidx, nidx, max_idx;
>>>>
>>>>    /*
>>>>     * The size of paddr_t should be sufficient for the complete range of
>>>> @@ -26,24 +47,34 @@ void __init setup_frametable_mappings(paddr_t ps, 
>>>> paddr_t pe)
>>>>    BUILD_BUG_ON((sizeof(paddr_t) * BITS_PER_BYTE) < PADDR_BITS);
>>>>    BUILD_BUG_ON(sizeof(struct page_info) != PAGE_INFO_SIZE);
>>>>
>>>> -    if ( frametable_size > FRAMETABLE_SIZE )
>>>> -        panic("The frametable cannot cover the physical region 
>>>> %#"PRIpaddr" - %#"PRIpaddr"\n",
>>>> -              ps, pe);
>>>> +    max_idx = DIV_ROUND_UP(max_pdx, PDX_GROUP_COUNT);
>>>> +    frametable_base_pdx = mfn_to_pdx(maddr_to_mfn(ram_start));
>>>>
>>>> -    frametable_base_pdx = mfn_to_pdx(maddr_to_mfn(ps));
>>>> -    /* Round up to 2M or 32M boundary, as appropriate. */
>>>> -    frametable_size = ROUNDUP(frametable_size, mapping_size);
>>>> -    base_mfn = alloc_boot_pages(frametable_size >> PAGE_SHIFT, 
>>>> 32<<(20-12));
>>>> +    /*
>>>> +     * pdx_to_page(pdx_s) in init_frametable_chunk must be page-aligned
>>>> +     * for map_pages_to_xen(). Aligning to PDX_GROUP_COUNT guarantees this
>>>> +     * because PDX_GROUP_COUNT * sizeof(page_info) is always a multiple of
>>>> +     * PAGE_SIZE by construction.
>>>> +     */
>>>> +    frametable_base_pdx = ROUNDDOWN(frametable_base_pdx, PDX_GROUP_COUNT);
>>>
>>> We are now rounding down frametable_base_pdx which before this patch it was 
>>> the start of the ram,
>>> but in xen/xen/arch/arm/include/asm/mm.h, mfn_valid(mfn) is using 
>>> frametable_base_pdx to check for
>>> mfn validity, this means that we could pass an mfn before the start of the 
>>> ram and if __mfn_valid is happy,
>>> we are getting a regression.
>>>
>>> Can this happen or am I missing something?
>> mfn_valid() can indeed return true for an MFN below ram_start that falls
>> in the same PDX group, but this is safe. init_frametable_chunk() maps
>> and zeroes the frametable for that range, so mfn_to_page() won't fault.
>> The zeroed page_info has count_info == 0 and no owner, so any get_page()
>> call on it will fail — the page is effectively inert.
> 
> Yes, I’ve checked and many path relying on mfn_valid() go also through 
> mfn_to_page()
> and/or get_page(), there is only one in process_shm() that potentially could 
> add a shared memory page
> given that we are relaxing mfn_valid now.
We are not relaxing mfn_valid now. It has never meant to mean RAM. It means the
MFN has a corresponding frame table entry with struct page_info. This is what
it's comment says.

Static shmem is safe for ghost MFN. In prepare_staticmem_pages() we have a check
for count_info that for ghost MFN is 0.

> 
> I’m trying also to follow is_iomem_page(), to check if subsequent 
> mfn_to_page() fail safely, but I think that depending
> on that (mfn_valid) the page will be only treated differently, not sure if 
> it’s a latent bug to leave mfn_valid() as it is.\
On Arm, is_iomem_page() is just !mfn_valid(), so yes, ghost MFNs
would be classified as not IOMEM. But this is harmless because is_iomem_page()
on ARM is only called from grant table paths that operate on pages obrtained by
get_page(), so no Arm code can reach is_iomem_page with a ghost MFN.

> 
> Would it be valid to have something like mfn_to_page() != 0 to be part of 
> mfn_valid() to ensure it’s a real host ram page?
> I’m truly asking here because I didn’t check if it’s doable.
As already said, mfn_valid was never supposed to mean RAM page. It is just that
on ARM the two happened to coincide until this patch.

> 
> Otherwise we could split the round down and the frametable_base_pdx in this 
> way maybe?
I don't think we need this extra complexity for something that is safe and has
always been in use. We've never had mfn_valid == RAM guarantee.

~Michal




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.