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

Re: [PATCH] xen/arm: Fix under-mapping in map_range_to_domain()


  • To: Julien Grall <julien@xxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: "Orzel, Michal" <michal.orzel@xxxxxxx>
  • Date: Mon, 12 Oct 2026 09:32:00 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=xen.org 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=/MxTUYpqdo3ktSYxb0sZm0A+NJ1qRXX6YhLwnGe9o7Y=; b=bwYd2ZqsiN4D3+gLKCA0nYie1zA8dLXielZ0yRQjkIpZz5+ii1WqfSbepIiCeKeR+5XWPLXF3z7nQ8ITf9KUcVLe6ATEXRFGc2Jb6sC3NK8riJAPG+VuwC3cC6EtrwLPP/RaE59nn/f8bLMy8gz7uGR4AIMdljX0NGgh8on/zk1QJn7bQl0YTZlEn72Ny5/ytl4FRLxtHPNIJ1EJIKLGl4Q95/5gHcfoSAvZCjDfE0ty/Q8yZW3fAGbr2ffeC0oUJwzCtmAwpYDWNTWN5PIX2q1YKGVgFozgl1/pcMBJ+KKjVKEkNXM6XbkKfanwmTyO1749Qqi2S94tiVcJMNTK7g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=p2PULSOcAM9VJIi9Z2/rjbDb2ZQ6GCjBEOXgxVeQwfB//VwXk8Rcu1Yh8lN4eb/QuORTsZWQY5kuWJm2V7v1on0hJw6k1TVAY8OM8blB6IWbAEsiLRShw6poyEkz7ARhNzkzYqfyrDQ4VqYyfhX9rAPIMsugEyhDs8CX5LJSvNSUvHHKMyF26nHQKP26mzxS8x6A3c7KMbijE01XoMGWT5JBkcCX+BMDbPDQTLvGvFJU2mqmHkwUfH7DBkgwkdILyCDTK5xdpYznprIoJ0K1tV9CQaOMgq5fYftRb8iqT89mYvEuYk3z4Cc+NmS+ED/AlzBu9rJr1m9XFC6Y7sP1Xg==
  • 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: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Mon, 12 Oct 2026 07:32:25 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 10-Oct-26 12:38, Julien Grall wrote:
> Hi Michal,
> 
> On 08/10/2026 11:50, Orzel, Michal wrote:
>>
>>
>> On 07-Oct-26 22:20, Grall, Julien wrote:
>>> Hi Michal,
>>>
>>> On 07/10/2026 15:58, Michal Orzel wrote:
>>>> If the memory region to be mapped does not start at the page boundary
>>>> and its end spans over the page boundary, map_range_to_domain() passes
>>>> a number of pages that is short by one to map_regions_p2mt(). Domain's
>>>> attempt to access memory within that page will fail. Fix it by calculating
>>>> the number of pages to be mapped taking into account the start offset.
>>>
>>> Can you provide an example where the caller doesn't suitably align?
>> Sure. Example is handle_device() being called on the hwdom DTB creation time 
>> for
>> a node whose address is not page aligned i.e. /reserved-memory node or 
>> basically
>> any node, given that DT spec does not mention anything about memory region
>> alignment and there are existing DTs like that. With reg = <0x0 0x800 0x0
>> 0x1000>, today we only map 0x0-0xfff and an access to 0x1000-0x17ff faults.
> 
> Thanks!
>>
>>>
>>>>
>>>> Fixes: 88c10b0d6eee ("arch/arm: let map_mmio_regions() use start and 
>>>> count")
>>>> Signed-off-by: Michal Orzel <michal.orzel@xxxxxxx>
>>>
>>> The fix LGTM in the current context. However given map_range_to_domain()
>>> is now used in more places (e.g. overlay), I wonder whether this is the
>>> right decision to allow map_range_to_domain() with non-aligned region.
>>>
>>> Imagine a user say "I want to map 0x400 - 0x1000 to domain A and map
>>> domain B "0x0 - 0x400". This could result to interesting behavior if the
>>> user is not aware of the alignment (this would become even more
>>> problematic if we decide to ever support different page granularity on Arm).
>> I agree this is not great, but this is not something introduced here:
>> iomem_permit_access() and the iomem_ranges rangeset already cover whole pages
>> and we already map the full first page.This patch only makes the p2m mapping
>> match what we already allow.
> 
> I am possibly misinterpreting what you wrote, but I disagree with such 
> statement. The fact existing code may be wrong doesn't mean we should 
> continue with the wrongness.
It was just to clarify that this patch does not change who can access the page.

> 
>>
>> I don't think we can reject unaligned regions in map_range_to_domain()
>> though, as the host DT is not under our control and hwdom would fail to
>> boot on platforms with sub-page devices. I asked AI to look at the Linux 
>> boards
>> for Arm and Arm64 (140 boards in total with unaligned regions) and even the
>> boards we claim to support have nodes that would fail:
>> - RPI4: hdmi@7ef00700, <0x7ef01f00 0x400>
>> - IMX8QXP: clock-controller@5b290004, <0x5b290004 0x10000>
> 
> I am not suggesting to reject unaligned regions when mapped into the 
> hardware domain. I am suggesting to reject it when we want to 
> passthrough to another domain. So we don't end up in a situation two 
> different devices on the same page are passthrough to two different 
> domains (or between Xen and a domain).
> 
> Codewise, it would mean map_range_to_domain() would enforce the 
> alignment and the caller will be left to decide what to do. We could 
> also decide about the alignment base don whether this is the HW domain 
> or not within the function.
For passthrough this is already the case. map_range_to_domain() does
not map anything for nodes with xen,passthrough and the domU mapping is done by
handle_passthrough_prop(), which rejects mstart, gstart and size that are not
page aligned.

The remaining case is the overlay which can be attached to any 1:1 domain and
this goes through handle_device() -> map_range_to_domain() without any alignment
check. All the other callers operate on hwdom, so I think we could reject a
region that is not page aligned if d is not the hardware domain, before granting
the iomem permission in map_range_to_domain().

Shouldn't we accept this patch as is so that we can backport (overlay is not
supported) it as a fix and then add a second one with a rejection mentioned
above that will help the overlay (and any future) case?

~Michal




 


Rackspace

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