[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] x86/boot: Force error checking for reserve_e820_ram()
- To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- From: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
- Date: Mon, 20 Apr 2026 08:57:20 +0100
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
- 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=1U3C+MeKhh6Xwgw3INE79vNzEqtjx6GNUx+rMjSJ9DY=; b=Yhmj/208JT7VYDvIL08Cv+bAkHfQZ2UaO7136mHQWG7U3Pxn4lOG1DoyuT80eR/SymmamG71dueqANS90h+l+Z/SgbsIoyJ8pJlNC8OXfOijmna71Qy/wXV8e0epBSsEfpg6JeZjOtewTygrki5pSPl9TSnGy5kI12Dy4opg903PTPY6NGv5CXz5wEk9s8ad+uHUSvc6sS4/duhPg8NKMqc0/KamGzZQTQj0pg2sqjg8B/RopCU0kHVHeb0rdY+3seHYNTHoviDWdFT7/Gt0vOEtAG4I7KlMc3fV+LOWrkg/WUm7bhjXrlhZ/k1NA7aS4y7CcLe0eXKqJvTzormE5g==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=l9t4++CW42blXUCmvYluEzOxzBNvApAg/9+vTg4O5HmquPbJ952jnAnf6qKFqEksUMyuwMqL4JiF/cRoxDE8fD2usr15gp7BrLffMTOnzqCBUoX3Td8p1sVOMGIIevCkdb7b5bwGpHtq659YZ4BOW6X2PDE1eDrsNLm8EIxqcvvVD6wG7SigLbocnxvcfyNluwn1H5Vf8J3VJ1VOzpq6n28aZPyFyl10LTyPuQZEney0U0TU0SCUnVAkc1n2yS/R6I+QPZOEN5FJIi5Dl+JFYqNXUg1DOi8Rijd6m31ne1qkMLJQ7S0rpPkuNNYDmWcg2ojhTBBJaLeI92OFjNhWGA==
- Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
- Cc: Jan Beulich <jbeulich@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>
- Delivery-date: Mon, 20 Apr 2026 07:57:32 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 4/17/26 6:05 PM, Andrew Cooper wrote:
On 17/04/2026 5:27 pm, Ross Lagerwall wrote:
On 4/17/26 5:08 PM, Andrew Cooper wrote:
Failing to mark Xen as Reserved in the E820 is catastrophic; RAM
regions get
handed to the physical memory allocator for general use. Similarly,
failure
to mark the boot modules as reserved is not going to result in a working
system.
Mark reserve_e820_ram() as __must_check, and panic() on failure. To
avoid
opencoding the range in every caller, print a general failure message in
reserve_e820_ram().
Reported-by: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Jan Beulich <jbeulich@xxxxxxxx>
CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
CC: Teddy Astie <teddy.astie@xxxxxxxxxx>
Slightly RFC; only compile tested so far.
There's no obvious fixes tag. This has been many variations of
broken since
forever.
---
xen/arch/x86/e820.c | 8 +++++++-
xen/arch/x86/include/asm/e820.h | 2 +-
xen/arch/x86/setup.c | 11 +++++++----
3 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/xen/arch/x86/e820.c b/xen/arch/x86/e820.c
index 872208ab3722..f09a01f0c50a 100644
--- a/xen/arch/x86/e820.c
+++ b/xen/arch/x86/e820.c
@@ -670,7 +670,13 @@ int __init e820_change_range_type(
/* Set E820_RAM area (@s,@e) as RESERVED in specified e820 map. */
int __init reserve_e820_ram(struct e820map *map, uint64_t s,
uint64_t e)
{
- return e820_change_range_type(map, s, e, E820_RAM, E820_RESERVED);
+ int res = e820_change_range_type(map, s, e, E820_RAM,
E820_RESERVED);
+
+ if ( !res )
+ printk("Failed to convert E820 RAM %"PRIx64"-%"PRIx64" to
RESERVED\n",
+ s, e);
+
+ return res;
}
unsigned long __init init_e820(const char *str, struct e820map *raw)
diff --git a/xen/arch/x86/include/asm/e820.h
b/xen/arch/x86/include/asm/e820.h
index 8e7644f8870b..a86d60ce3e77 100644
--- a/xen/arch/x86/include/asm/e820.h
+++ b/xen/arch/x86/include/asm/e820.h
@@ -25,7 +25,7 @@ struct e820map {
extern int sanitize_e820_map(struct e820entry *biosmap, unsigned
int *pnr_map);
extern int e820_all_mapped(u64 start, u64 end, unsigned type);
-extern int reserve_e820_ram(struct e820map *map, uint64_t s,
uint64_t e);
+extern int __must_check reserve_e820_ram(struct e820map *map,
uint64_t s, uint64_t e);
extern int e820_change_range_type(
struct e820map *map, uint64_t s, uint64_t e,
uint32_t orig_type, uint32_t new_type);
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index d041cbd5f6f1..9c1f1eafa0d7 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -1639,7 +1639,8 @@ void asmlinkage __init noreturn __start_xen(void)
{
uint64_t s = bi->mods[i].start, l = bi->mods[i].size;
- reserve_e820_ram(&boot_e820, s, s + PAGE_ALIGN(l));
+ if ( !reserve_e820_ram(&boot_e820, s, s + PAGE_ALIGN(l)) )
+ panic("Failed to reserve boot module %u in E820\n", i);
i is an int, so it should be %d.
}
if ( !xen_phys_start )
@@ -1652,11 +1653,13 @@ void asmlinkage __init noreturn
__start_xen(void)
/* This needs to remain in sync with remove_xen_ranges(). */
if ( efi_boot_mem_unused(&eb_start, &eb_end) )
{
- reserve_e820_ram(&boot_e820, __pa(_stext), __pa(eb_start));
- reserve_e820_ram(&boot_e820, __pa(eb_end),
__pa(__2M_rwdata_end));
+ if ( !reserve_e820_ram(&boot_e820, __pa(_stext),
__pa(eb_start)) ||
+ !reserve_e820_ram(&boot_e820, __pa(eb_end),
__pa(__2M_rwdata_end)) )
+ panic("Failed to reserve Xen in E820\n");
}
else
- reserve_e820_ram(&boot_e820, __pa(_stext),
__pa(__2M_rwdata_end));
+ if ( reserve_e820_ram(&boot_e820, __pa(_stext),
__pa(__2M_rwdata_end)) )
+ panic("Failed to reserve Xen in E820\n");
This condition is inverted.
Otherwise this looks like a sensible change.
Oops, yes. Fixed.
With those changes,
Reviewed-by: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
|