Skip to contentSkip to conversation

x86/boot: Drop incorrect mapping at l2_xenmap[0]

PATCH In review Andrew Cooper 3 participants 4 messages Nov 29, 2021 – Nov 30, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/boot: Drop incorrect mapping at l2_xenmap[0]

It has been 4 years since the default load address changed from 1M to 2M, and _stext ceased residing in l2_xenmap[0]. We should not be inserting an unused mapping.

To ensure we don't create/remove mappings accidentally, loop from 0 and obey _PAGE_PRESENT on all entries.

Fixes 7ed93f3a0dff ("x86: change default load address from 1 MiB to 2 MiB")

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

I ought to have spotted this in c/s 52975142d154 ("x86/boot: Create the l2_xenmap[] mappings dynamically") too.

---
 xen/arch/x86/setup.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
xen/arch/x86/setup.c +3 -7
index da47cdea14a1..6f241048425c 100644
@@ -1279,16 +1279,12 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
             /* The only data mappings to be relocated are in the Xen area. */
             pl2e = __va(__pa(l2_xenmap));
-            /*
-             * Undo the temporary-hooking of the l1_directmap.  __2M_text_start
-             * is contained in this PTE.
-             */
+
             BUG_ON(using_2M_mapping() &&
                    l2_table_offset((unsigned long)_erodata) ==
                    l2_table_offset((unsigned long)_stext));
-            *pl2e++ = l2e_from_pfn(xen_phys_start >> PAGE_SHIFT,
-                                   PAGE_HYPERVISOR_RX | _PAGE_PSE);
-            for ( i = 1; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ )
+
+            for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ )
             {
                 unsigned int flags;
 
Signature · 1 line
2.11.0
#1 lore raw
Quoted 34 lines · Andrew Cooper

It has been 4 years since the default load address changed from 1M to 2M, and _stext ceased residing in l2_xenmap[0]. We should not be inserting an unused mapping.

To ensure we don't create/remove mappings accidentally, loop from 0 and obey _PAGE_PRESENT on all entries.

Fixes 7ed93f3a0dff ("x86: change default load address from 1 MiB to 2 MiB")

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

I ought to have spotted this in c/s 52975142d154 ("x86/boot: Create the l2_xenmap[] mappings dynamically") too.

---
 xen/arch/x86/setup.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
xen/arch/x86/setup.c +1 -4
index da47cdea14a1..6f241048425c 100644
@@ -1279,16 +1279,12 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
             /* The only data mappings to be relocated are in the Xen area. */
             pl2e = __va(__pa(l2_xenmap));
-            /*
-             * Undo the temporary-hooking of the l1_directmap.  __2M_text_start
-             * is contained in this PTE.
-             */
+
             BUG_ON(using_2M_mapping() &&

xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 1290

Quoted 10 lines
xen/arch/x86/setup.c +2 -3
                    l2_table_offset((unsigned long)_erodata) ==
                    l2_table_offset((unsigned long)_stext));
-            *pl2e++ = l2e_from_pfn(xen_phys_start >> PAGE_SHIFT,
-                                   PAGE_HYPERVISOR_RX | _PAGE_PSE);
-            for ( i = 1; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ )
+
+            for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ )
             {
                 unsigned int flags;
 

Actually, on further consideration, this hunk should be included too, to cross-check that we don't zap any of the dynamically created mappings.

~Andrew

xen/arch/x86/setup.c +0 -0
index 6f241048425c..5c8026b30e3e 100644
@@ -1320,7 +1320,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)

                 }
                 else
                 {
-                    *pl2e = l2e_empty();
+                    ASSERT_UNREACHABLE();
                     continue;
                 }

#2 lore raw
Quoted 40 lines · Andrew Cooper
Quoted 39 lines · Andrew Cooper

It has been 4 years since the default load address changed from 1M to 2M, and _stext ceased residing in l2_xenmap[0]. We should not be inserting an unused mapping.

To ensure we don't create/remove mappings accidentally, loop from 0 and obey _PAGE_PRESENT on all entries.

Fixes 7ed93f3a0dff ("x86: change default load address from 1 MiB to 2 MiB")

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

I ought to have spotted this in c/s 52975142d154 ("x86/boot: Create the l2_xenmap[] mappings dynamically") too.

---
 xen/arch/x86/setup.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
xen/arch/x86/setup.c +1 -7
index da47cdea14a1..6f241048425c 100644
@@ -1279,16 +1279,12 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
             /* The only data mappings to be relocated are in the Xen area. */
             pl2e = __va(__pa(l2_xenmap));
-            /*
-             * Undo the temporary-hooking of the l1_directmap.  __2M_text_start
-             * is contained in this PTE.
-             */
+
             BUG_ON(using_2M_mapping() &&
                    l2_table_offset((unsigned long)_erodata) ==
                    l2_table_offset((unsigned long)_stext));
-            *pl2e++ = l2e_from_pfn(xen_phys_start >> PAGE_SHIFT,
-                                   PAGE_HYPERVISOR_RX | _PAGE_PSE);
-            for ( i = 1; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ )
Quoted 8 lines

xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 1290

Quoted 5 lines
xen/arch/x86/setup.c +2 -0
+
+            for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ )
             {
                 unsigned int flags;
 

Actually, on further consideration, this hunk should be included too, to cross-check that we don't zap any of the dynamically created mappings.

I agree in principle, but ...

Quoted 10 lines
xen/arch/x86/setup.c +0 -0
@@ -1320,7 +1320,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
                  }

                 else
                 {
-                    *pl2e = l2e_empty();
+                    ASSERT_UNREACHABLE();
                     continue;
                 }

... this isn't going to help non-debug builds. Dropping the zapping would mean release builds then run with an unadjusted PTE. I can see two options:
Extract the flags from the existing PTE as fallback (i.e. keeping the ASSERT_UNREACHABLE()) or use BUG() instead.

Jan

#3 lore raw
Quoted 50 lines · Jan Beulich
Quoted 39 lines · Andrew Cooper
Quoted 38 lines · Andrew Cooper

It has been 4 years since the default load address changed from 1M to 2M, and _stext ceased residing in l2_xenmap[0]. We should not be inserting an unused mapping.

To ensure we don't create/remove mappings accidentally, loop from 0 and obey _PAGE_PRESENT on all entries.

Fixes 7ed93f3a0dff ("x86: change default load address from 1 MiB to 2 MiB")

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

I ought to have spotted this in c/s 52975142d154 ("x86/boot: Create the l2_xenmap[] mappings dynamically") too.

---
 xen/arch/x86/setup.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
xen/arch/x86/setup.c +1 -6
index da47cdea14a1..6f241048425c 100644
@@ -1279,16 +1279,12 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
             /* The only data mappings to be relocated are in the Xen area. */
             pl2e = __va(__pa(l2_xenmap));
-            /*
-             * Undo the temporary-hooking of the l1_directmap.  __2M_text_start
-             * is contained in this PTE.
-             */
+
             BUG_ON(using_2M_mapping() &&
                    l2_table_offset((unsigned long)_erodata) ==
                    l2_table_offset((unsigned long)_stext));
-            *pl2e++ = l2e_from_pfn(xen_phys_start >> PAGE_SHIFT,
-                                   PAGE_HYPERVISOR_RX | _PAGE_PSE);
Quoted 8 lines

xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 1290

Quoted 6 lines
xen/arch/x86/setup.c +2 -1
-            for ( i = 1; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ )
+
+            for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ )
             {
                 unsigned int flags;
 

Actually, on further consideration, this hunk should be included too, to cross-check that we don't zap any of the dynamically created mappings.

I agree in principle, but ...

Quoted 14 lines
Quoted 10 lines
xen/arch/x86/setup.c +0 -0
@@ -1320,7 +1320,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
                  }

                 else
                 {
-                    *pl2e = l2e_empty();
+                    ASSERT_UNREACHABLE();
                     continue;
                 }

... this isn't going to help non-debug builds. Dropping the zapping would mean release builds then run with an unadjusted PTE. I can see two options:
Extract the flags from the existing PTE as fallback (i.e. keeping the ASSERT_UNREACHABLE()) or use BUG() instead.

I've actually dropped this entire block of code with a later cleanup, so I'll leave this hunk alone and post the whole series.

~Andrew