Skip to contentSkip to conversation

x86: map portion of kexec crash area that is within the direct map area

PATCH In review David Vrabel 4 participants 6 messages Jan 8, 2014 – Jan 10, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86: map portion of kexec crash area that is within the direct map area

From: David Vrabel <[email protected]>

Commit 7113a45451a9f656deeff070e47672043ed83664 (kexec/x86: do not map crash kernel area) causes fatal page faults when loading a crash image. The attempt to zero the first control page allocated from the crash region will fault as the VA return by map_domain_page() has no mapping.

The fault will occur on non-debug builds of Xen when the crash area is below 5 TiB (which will be most systems).

The assumption that the crash area mapping was not used is incorrect. map_domain_page() is used when loading an image and building the image's page tables to temporarily map the crash area, thus the mapping is required if the crash area is in the direct map area.

Reintroduce the mapping, but only the portions of the crash area that are within the direct map area.

---
This fixes a Xen crash so is an important fix for the 4.4 release..

Changes in v2:
- merge patches into one
- add check for e > s before mapping

---
 xen/arch/x86/setup.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
xen/arch/x86/setup.c +11 -0
index 4833ca3..b49256d 100644
@@ -1098,6 +1098,17 @@ void __init __start_xen(unsigned long mbi_p)
                          PFN_UP(mod[i].mod_end), PAGE_HYPERVISOR);
     }
 
+    if ( kexec_crash_area.size )
+    {
+        unsigned long s = PFN_DOWN(kexec_crash_area.start);
+        unsigned long e = min(s + PFN_UP(kexec_crash_area.size),
+                              PFN_UP(__pa(HYPERVISOR_VIRT_END - 1)));
+
+        if ( e > s ) 
+            map_pages_to_xen((unsigned long)__va(kexec_crash_area.start),
+                             s, e - s, PAGE_HYPERVISOR);
+    }
+
     xen_virt_end = ((unsigned long)_end + (1UL << L2_PAGETABLE_SHIFT) - 1) &
                    ~((1UL << L2_PAGETABLE_SHIFT) - 1);
     destroy_xen_mappings(xen_virt_end, XEN_VIRT_START + BOOTSTRAP_MAP_BASE);
Signature · 1 line
1.7.2.5
#1 lore raw
Quoted 16 lines · David Vrabel

From: David Vrabel <[email protected]>

Commit 7113a45451a9f656deeff070e47672043ed83664 (kexec/x86: do not map crash kernel area) causes fatal page faults when loading a crash image. The attempt to zero the first control page allocated from the crash region will fault as the VA return by map_domain_page() has no mapping.

The fault will occur on non-debug builds of Xen when the crash area is below 5 TiB (which will be most systems).

The assumption that the crash area mapping was not used is incorrect. map_domain_page() is used when loading an image and building the image's page tables to temporarily map the crash area, thus the mapping is required if the crash area is in the direct map area.

Quoted 8 lines

Reintroduce the mapping, but only the portions of the crash area that are within the direct map area.

---
This fixes a Xen crash so is an important fix for the 4.4 release..

Thanks. It looks quite good for me but I would like to do some tests. I will send you results by the end of this week.

Daniel

Tested-by on v2 1/1
#2 lore raw
In reply to David Vrabel
Quoted 44 lines · David Vrabel

From: David Vrabel <[email protected]>

Commit 7113a45451a9f656deeff070e47672043ed83664 (kexec/x86: do not map crash kernel area) causes fatal page faults when loading a crash image. The attempt to zero the first control page allocated from the crash region will fault as the VA return by map_domain_page() has no mapping.

The fault will occur on non-debug builds of Xen when the crash area is below 5 TiB (which will be most systems).

The assumption that the crash area mapping was not used is incorrect. map_domain_page() is used when loading an image and building the image's page tables to temporarily map the crash area, thus the mapping is required if the crash area is in the direct map area.

Reintroduce the mapping, but only the portions of the crash area that are within the direct map area.

---
This fixes a Xen crash so is an important fix for the 4.4 release..

Changes in v2:
- merge patches into one
- add check for e > s before mapping

---
  xen/arch/x86/setup.c |   11 +++++++++++
  1 files changed, 11 insertions(+), 0 deletions(-)
xen/arch/x86/setup.c +4 -0
index 4833ca3..b49256d 100644
@@ -1098,6 +1098,17 @@ void __init __start_xen(unsigned long mbi_p)
                           PFN_UP(mod[i].mod_end), PAGE_HYPERVISOR);
      }
 
+    if ( kexec_crash_area.size )
+    {
+        unsigned long s = PFN_DOWN(kexec_crash_area.start);
+        unsigned long e = min(s + PFN_UP(kexec_crash_area.size),

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

Quoted 10 lines
xen/arch/x86/setup.c +7 -0
+                              PFN_UP(__pa(HYPERVISOR_VIRT_END - 1)));
+
+        if ( e > s )
+            map_pages_to_xen((unsigned long)__va(kexec_crash_area.start),
+                             s, e - s, PAGE_HYPERVISOR);
+    }
+
      xen_virt_end = ((unsigned long)_end + (1UL << L2_PAGETABLE_SHIFT) - 1) &
                     ~((1UL << L2_PAGETABLE_SHIFT) - 1);
      destroy_xen_mappings(xen_virt_end, XEN_VIRT_START + BOOTSTRAP_MAP_BASE);

4.4.0-rc1 + this patch works for me. So you can add:

-Don Slutz

Reviewed-by Tested-by on v2 1/1
#3 lore raw
In reply to David Vrabel
Quoted 16 lines · David Vrabel

From: David Vrabel <[email protected]>

Commit 7113a45451a9f656deeff070e47672043ed83664 (kexec/x86: do not map crash kernel area) causes fatal page faults when loading a crash image. The attempt to zero the first control page allocated from the crash region will fault as the VA return by map_domain_page() has no mapping.

The fault will occur on non-debug builds of Xen when the crash area is below 5 TiB (which will be most systems).

The assumption that the crash area mapping was not used is incorrect. map_domain_page() is used when loading an image and building the image's page tables to temporarily map the crash area, thus the mapping is required if the crash area is in the direct map area.

Quoted 8 lines

Reintroduce the mapping, but only the portions of the crash area that are within the direct map area.

---
This fixes a Xen crash so is an important fix for the 4.4 release..

This really fixes page fault found by Don. After deeper testing I can confirm that issue introduced by commit 7113a45451a9f656deeff070e47672043ed83664 is revealed only when Xen is compiled with debug option disabled.

By the way, why map_domain_page() behavior depends on debug option? It is not nice because we could be trapped by this in the future in more serious places. Could map_domain_page() work in the same way with or without debug option?

Anyway...

Daniel

#4 lore raw
Quoted 4 lines · Daniel Kiper

By the way, why map_domain_page() behavior depends on debug option? It is not nice because we could be trapped by this in the future in more serious places. Could map_domain_page() work in the same way with or without debug option?

With a debug build of Xen, map_domain_page() always mutates the pagetables and hands out virtual addresses from the mapcache region. This is to test map_domain_page() itself, as well as making domain mapping leaks more obvious (as the mapcache is under heavier load).

For a non-debug build of Xen, any map_domain_page() calls which can be satisfied by returning a virtual address from the direct map region (i.e. for pages below the 5TiB boundary which is basically all of them unless you have more money than sense) are, which avoided excessive use of the mapcache, and avoids a TLB shootdown/flush on unmap.

~Andrew

#5 lore raw
Quoted 11 lines · Andrew Cooper
Quoted 4 lines · Daniel Kiper

By the way, why map_domain_page() behavior depends on debug option? It is not nice because we could be trapped by this in the future in more serious places. Could map_domain_page() work in the same way with or without debug option?

With a debug build of Xen, map_domain_page() always mutates the pagetables and hands out virtual addresses from the mapcache region. This is to test map_domain_page() itself, as well as making domain mapping leaks more obvious (as the mapcache is under heavier load).

Quoted 5 lines

For a non-debug build of Xen, any map_domain_page() calls which can be satisfied by returning a virtual address from the direct map region (i.e. for pages below the 5TiB boundary which is basically all of them unless you have more money than sense) are, which avoided excessive use of the mapcache, and avoids a TLB shootdown/flush on unmap.

Make sens. Thanks for explanation.

Daniel