Message ID | 20250218112253.3136505-3-grygorii_strashko@epam.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | xen/arm: fix iomem_ranges cfg in map_range_to_domain() | expand |
Hi Grygorii, On 18/02/2025 11:22, Grygorii Strashko wrote: > Now the following code in map_range_to_domain() > > res = rangeset_add_range(mr_data->iomem_ranges, > paddr_to_pfn(addr), > paddr_to_pfn_aligned(addr + len - 1)); > where > paddr_to_pfn_aligned(paddr) defined as paddr_to_pfn(PAGE_ALIGN(paddr)) > > calculates the iomem range end address by rounding it up to the next Xen > page with incorrect assumption that iomem range end address passed to > rangeset_add_range() is exclusive, while it is expected to be inclusive. > > For example, if requested range is [00e6140000:00e6141004] then it expected > to add [e6140:e6141] range (num_pages=2) to the mr_data->iomem_ranges > rangeset, but will add [e6140:e6142] (num_pages=3) instead. > > To fix it, drop PAGE_ALIGN() from the iomem range end address calculation > formula and just use paddr_to_pfn(addr + len - 1). > > Fixes: 57d4d7d4e8f3b (arm/asm/setup.h: Update struct map_range_data to add > rangeset.") > Signed-off-by: Grygorii Strashko <grygorii_strashko@epam.com> Reviewed-by: Julien Grall <jgrall@amazon.com> Cheers,
diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c index 97e613e06afa..5e1c1cc326ac 100644 --- a/xen/arch/arm/device.c +++ b/xen/arch/arm/device.c @@ -107,7 +107,7 @@ int map_range_to_domain(const struct dt_device_node *dev, { res = rangeset_add_range(mr_data->iomem_ranges, paddr_to_pfn(addr), - paddr_to_pfn_aligned(addr + len - 1)); + paddr_to_pfn(addr + len - 1)); if ( res ) return res; }
Now the following code in map_range_to_domain() res = rangeset_add_range(mr_data->iomem_ranges, paddr_to_pfn(addr), paddr_to_pfn_aligned(addr + len - 1)); where paddr_to_pfn_aligned(paddr) defined as paddr_to_pfn(PAGE_ALIGN(paddr)) calculates the iomem range end address by rounding it up to the next Xen page with incorrect assumption that iomem range end address passed to rangeset_add_range() is exclusive, while it is expected to be inclusive. For example, if requested range is [00e6140000:00e6141004] then it expected to add [e6140:e6141] range (num_pages=2) to the mr_data->iomem_ranges rangeset, but will add [e6140:e6142] (num_pages=3) instead. To fix it, drop PAGE_ALIGN() from the iomem range end address calculation formula and just use paddr_to_pfn(addr + len - 1). Fixes: 57d4d7d4e8f3b (arm/asm/setup.h: Update struct map_range_data to add rangeset.") Signed-off-by: Grygorii Strashko <grygorii_strashko@epam.com> --- xen/arch/arm/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)