Skip to contentSkip to conversation

x86: assert MBI is large enough in pvh-boot.c

PATCH In review Wei Liu 3 participants 5 messages Sep 26, 2018 – Sep 27, 2018

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH 1/1 x86: assert MBI is large enough in pvh-boot.c

The relocation code in __start_xen requires one extra element in the MBI structure. By the looks of it the temporary MBI array is already large enough. Add an assertion to catch any issue in the future.

---
 xen/arch/x86/guest/pvh-boot.c | 7 +++++++
 1 file changed, 7 insertions(+)
xen/arch/x86/guest/pvh-boot.c +7 -0
index 0e9e5bfdf6..7e13e7604b 100644
@@ -44,6 +44,13 @@ static void __init convert_pvh_info(void)
 
     ASSERT(pvh_info->magic == XEN_HVM_START_MAGIC_VALUE);
 
+    /*
+     * Temporary MBI array needs to be at least one element bigger than
+     * required. The extra element is used to aid relocation. See
+     * arch/x86/setup.c:__start_xen().
+     */
+    ASSERT(ARRAY_SIZE(pvh_mbi_mods) > pvh_info->nr_modules);
+
     /*
      * Turn hvm_start_info into mbi. Luckily all modules are placed under 4GB
      * boundary on x86.
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 5 lines · Wei Liu

The relocation code in __start_xen requires one extra element in the MBI structure. By the looks of it the temporary MBI array is already large enough. Add an assertion to catch any issue in the future.

While this is all well and good, the ASSERT() never actually gets out onto the console.  This is because, when a failure occurs, the console hasn't been configured yet.

For development purposes I use:

xen/drivers/char/console.c +0 -0
index e48039d..64febfa 100644
@@ -91,7 +91,7 @@ static uint32_t conringc, conringp;

 static int __read_mostly sercon_handle = -1;

 #ifdef CONFIG_X86
-static bool __read_mostly opt_console_xen; /* console=xen */ +static bool __read_mostly opt_console_xen = true; /* console=xen */ #endif

 static DEFINE_SPINLOCK(console_lock);

which gets the details out into the L0 log.

As an addendum, might it be worth having opt_console_xen be tristate, and enabled by the start of the PVH path, so log messages before the command line is parsed end up being emitted?

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#2 lore raw
Quoted 27 lines · Andrew Cooper
Quoted 5 lines · Wei Liu

The relocation code in __start_xen requires one extra element in the MBI structure. By the looks of it the temporary MBI array is already large enough. Add an assertion to catch any issue in the future.

While this is all well and good, the ASSERT() never actually gets out onto the console.  This is because, when a failure occurs, the console hasn't been configured yet.

For development purposes I use:

xen/drivers/char/console.c +0 -0
index e48039d..64febfa 100644
@@ -91,7 +91,7 @@ static uint32_t conringc, conringp;
  static int __read_mostly sercon_handle = -1;


 #ifdef CONFIG_X86

xen/drivers/char/console.c +1 -1
-static bool __read_mostly opt_console_xen; /* console=xen */
+static bool __read_mostly opt_console_xen = true; /* console=xen */

 #endif

 static DEFINE_SPINLOCK(console_lock);

Quoted 5 lines

which gets the details out into the L0 log.

As an addendum, might it be worth having opt_console_xen be tristate, and enabled by the start of the PVH path, so log messages before the command line is parsed end up being emitted?

This is fine by me.

Wei.

Quoted 2 lines

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
In reply to Wei Liu

xen/arch/x86/guest/pvh-boot.c static void __init convert_pvh_info(void) · line 52

Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 26.09.18 at 13:00, <[email protected]> wrote:
xen/arch/x86/guest/pvh-boot.c +6 -0
@@ -44,6 +44,13 @@ static void __init convert_pvh_info(void)
 
     ASSERT(pvh_info->magic == XEN_HVM_START_MAGIC_VALUE);
 
+    /*
+     * Temporary MBI array needs to be at least one element bigger than
+     * required. The extra element is used to aid relocation. See
+     * arch/x86/setup.c:__start_xen().
+     */
+    ASSERT(ARRAY_SIZE(pvh_mbi_mods) > pvh_info->nr_modules);

Are ASSERT()s (also the other one in context) actually the right thing here? I think we'd better panic(): That'll also cover release builds and is imo more appropriate for data coming from the outside.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#4 lore raw
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 26.09.18 at 13:00, <[email protected]> wrote:
xen/arch/x86/guest/pvh-boot.c +0 -0
@@ -44,6 +44,13 @@ static void __init convert_pvh_info(void)
 
     ASSERT(pvh_info->magic == XEN_HVM_START_MAGIC_VALUE);
 
Quoted 10 lines

xen/arch/x86/guest/pvh-boot.c static void __init convert_pvh_info(void) · line 52

Quoted 6 lines
xen/arch/x86/guest/pvh-boot.c +6 -0
+    /*
+     * Temporary MBI array needs to be at least one element bigger than
+     * required. The extra element is used to aid relocation. See
+     * arch/x86/setup.c:__start_xen().
+     */
+    ASSERT(ARRAY_SIZE(pvh_mbi_mods) > pvh_info->nr_modules);

Are ASSERT()s (also the other one in context) actually the right thing here? I think we'd better panic(): That'll also cover release builds and is imo more appropriate for data coming from the outside.

Okay.

Wei.

Quoted 4 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel