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

[PATCH] xen/arm: mpu: Fix ioremap_attr region size and return value


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Michal Orzel <michal.orzel@xxxxxxx>
  • Date: Thu, 2 Apr 2026 09:56:45 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.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=NN+Hj3NXD8BbcBpU/hqwCcd8XXUb5DDshpgmWT1oq/I=; b=Zey3PFosMWCxID+zcIo2izhdAjs/nIOV+tR5I/LJjTsqTo+4sA47y7S7nT+WRmspRWHxnDTeocJMwj75/nIUhB7zzDbKZi+rn1vs1Ba2wrUyjF+aHFRx1aJJMM059IKSvW5bxs20eUgprHiYaLH+V/g3kCn+ShshbkPca7OIU7A7f8VnvQZTE8i0nPc4osCQg6G+mcg0dyHRklE4wI2wreGYek5Msmq/MjYBpQgWM3vJ0UhMM1lessWG+3NvXRr5/zgIM7fXFdcMFFstA67SGaI42uRn9s6OhsdGj6tzaSSLGmybLo+xW/9CcnDHh6mdINCy/VgRcIBgTjWyqKj2oQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lbkW3URMXAJXcFq6QnW15PpK2YwbPGg/wGv6FKqq2DeuwUhvjtPkO2JwsMvna0CllQ/8CSK2im2ncPOHBPDa6nrf1/adVViRl4yee1OjGr6lpjwrvwgcBSl6WgJ/B4/hb/oNRqNTen53ej9WsGR46p9Uok0rdUerY+TjQCpE400Q8UVGoqo3+L+ywHy3ZV6cN6l2+QSqhsp7IW92oQSRVKOsoIweLjpi+b8qyw9+YpfryHg5CEYhNaBhb/SuWcS+/QmSFr9dL1Q0uGGwbwYmmmluso8dOwAcf4eXyXVds8id7/TcUDCAhEF1bBSVy8Ce/uZiAZ5XDGpoD7peP5u7gg==
  • 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: Michal Orzel <michal.orzel@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Thu, 02 Apr 2026 07:57:04 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

ioremap_attr() computes end_pg as round_pgup(start_pg + len), but
start_pg has already had the sub-page offset stripped by round_pgdown().
When start is not page-aligned, the sub-page offset is lost and the
resulting MPU protection region can be one page too small, leaving the
tail of the requested range covered by something else.

Additionally, the function returns maddr_to_virt(start_pg) — the
page-aligned base dropping the sub-page offset that callers (e.g. ioremap
of an unaligned MMIO base) depend on to reach the correct register block.

Fix end_pg to use the original start so the sub-page tail is included
in the rounding, and return the original start address to preserve the
offset, matching the behaviour of other ioremap implementations.

Fixes: efeec4c70798 ("arm/mpu: Implement ioremap_attr for MPU")
Signed-off-by: Michal Orzel <michal.orzel@xxxxxxx>
---
 xen/arch/arm/mpu/mm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c
index 6b3b0b06e95d..aff88bd3a9c1 100644
--- a/xen/arch/arm/mpu/mm.c
+++ b/xen/arch/arm/mpu/mm.c
@@ -596,13 +596,13 @@ void free_init_memory(void)
 void __iomem *ioremap_attr(paddr_t start, size_t len, unsigned int flags)
 {
     paddr_t start_pg = round_pgdown(start);
-    paddr_t end_pg = round_pgup(start_pg + len);
+    paddr_t end_pg = round_pgup(start + len);
 
     if ( xen_mpumap_update(start_pg, end_pg, flags) )
         return NULL;
 
     /* Mapped or already mapped */
-    return maddr_to_virt(start_pg);
+    return maddr_to_virt(start);
 }
 
 /*
-- 
2.43.0




 


Rackspace

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