Skip to contentSkip to conversation

x86: fix kexec crash regression

PATCH In review David Vrabel 4 participants 9 messages Jan 8, 2014

lore
Share & tools
lore
#0 lore raw

A recent commit causes Xen to crash if a kexec crash images is loaded into a crash area below 5 TiB (and a non-debug Xen is used).

This series reverts the bad commit and then re-implements the part of the original fix that does cause a regression.

This is an important bug fix necessary for 4.4.

David

#1 lore raw

PATCH 1/2 Revert "kexec/x86: do not map crash kernel area"

From: David Vrabel <[email protected]>

This reverts commit 7113a45451a9f656deeff070e47672043ed83664.

The kexec code uses map_domain_page() on pages within the crash region, so this mapping is required if the crash region is within the direct map area.

Wthout this revert, loading a crash kernel may cause a fatal page fault when trying to zero the first control page allocated from the crash area. The fault will occur on non-debug builds of Xen when the crash area is below 5 TiB (which will be most systems).

---
 xen/arch/x86/setup.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
xen/arch/x86/setup.c +3 -1
index 4833ca3..f07ee2b 100644
@@ -1097,7 +1097,9 @@ void __init __start_xen(unsigned long mbi_p)
                          mod[i].mod_start,
                          PFN_UP(mod[i].mod_end), PAGE_HYPERVISOR);
     }
-
+    map_pages_to_xen((unsigned long)__va(kexec_crash_area.start),
+                     kexec_crash_area.start >> PAGE_SHIFT,
+                     PFN_UP(kexec_crash_area.size), 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
#5 lore raw

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

In reply to David Vrabel

From: David Vrabel <[email protected]>

map_domain_page() is used to temporarily map the crash area when loading a kexec crash image.

If some or all of the crash area is within the direct map area then this portion must have a direct mapping, otherwise map_domain_page() (on non-debug builds) will return a direct map VA that is not actually mapped.

Parts of the crash area outside the direct map area (i.e., above 5 TiB) do not need and should not have such a mapping.

---
 xen/arch/x86/setup.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)
xen/arch/x86/setup.c +11 -3
index f07ee2b..8e10bdf 100644
@@ -1097,9 +1097,17 @@ void __init __start_xen(unsigned long mbi_p)
                          mod[i].mod_start,
                          PFN_UP(mod[i].mod_end), PAGE_HYPERVISOR);
     }
-    map_pages_to_xen((unsigned long)__va(kexec_crash_area.start),
-                     kexec_crash_area.start >> PAGE_SHIFT,
-                     PFN_UP(kexec_crash_area.size), 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)));
+
+        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
#8 lore raw
In reply to David Vrabel
Quoted 9 lines · David Vrabel

A recent commit causes Xen to crash if a kexec crash images is loaded into a crash area below 5 TiB (and a non-debug Xen is used).

This series reverts the bad commit and then re-implements the part of the original fix that does cause a regression.

This is an important bug fix necessary for 4.4.

David

Both Reviewed-by: Andrew Cooper <[email protected]>

~Andrew

Quoted 5 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw

Re: [PATCH 1/2] Revert "kexec/x86: do not map crash kernel area"

In reply to David Vrabel
Quoted 4 lines
Quoted 1 line
Quoted 1 line · David Vrabel

From: David Vrabel <[email protected]>

This reverts commit 7113a45451a9f656deeff070e47672043ed83664.

As indicated before - I don't think reverting is the right thing here. Just add the necessary code in the same (or another, if more suitable) place.

Jan

Quoted 39 lines

The kexec code uses map_domain_page() on pages within the crash region, so this mapping is required if the crash region is within the direct map area.

Wthout this revert, loading a crash kernel may cause a fatal page fault when trying to zero the first control page allocated from the crash area. The fault will occur on non-debug builds of Xen when the crash area is below 5 TiB (which will be most systems).

---
 xen/arch/x86/setup.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
xen/arch/x86/setup.c +3 -1
index 4833ca3..f07ee2b 100644
@@ -1097,7 +1097,9 @@ void __init __start_xen(unsigned long mbi_p)
                          mod[i].mod_start,
                          PFN_UP(mod[i].mod_end), PAGE_HYPERVISOR);
     }
-
+    map_pages_to_xen((unsigned long)__va(kexec_crash_area.start),
+                     kexec_crash_area.start >> PAGE_SHIFT,
+                     PFN_UP(kexec_crash_area.size), 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 · 7 lines
1.7.2.5


_______________________________________________
Xen-devel mailing list
[email protected] 
http://lists.xen.org/xen-devel 
#3 lore raw

Re: [PATCH 1/2] Revert "kexec/x86: do not map crash kernel area"

Quoted 8 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · David Vrabel

From: David Vrabel <[email protected]>

This reverts commit 7113a45451a9f656deeff070e47672043ed83664.

As indicated before - I don't think reverting is the right thing here. Just add the necessary code in the same (or another, if more suitable) place.

Isn't that what the second patch does? Perhaps this would be better structured as a single fix rather than a revert + do it properly, but the latter approach seems reasonable enough...

Ian.

#6 lore raw

Re: [PATCH 2/2] x86: map portion of kexec crash area that is within the direct map area

In reply to David Vrabel
Quoted 2 lines
Quoted 1 line
Quoted 1 line · David Vrabel

+ if ( kexec_crash_area.size )

Wouldn't this better also include a kexec_crash_area.start range check?

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

Quoted 7 lines
xen/arch/x86/setup.c +7 -0
+    {
+        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)));
+
+        map_pages_to_xen((unsigned long)__va(kexec_crash_area.start),
+                         s, e - s, PAGE_HYPERVISOR);

map_pages_to_xen() doesn't tolerate a huge count resulting when e < s (which is possible due to the min() above).

Furthermore, with PFN compression and a badly specified address range (overlapping a hole) this would likely crash during boot. While that mistake might later also lead to problems, I think it would be better if booting nevertheless succeeded.

And of course the whole thing will break the moment we allow RAM to fall into PFN compression holes (either by not using some small amount of memory in order to be able to cover a larger total amount, like would be desirable in cases where we need to chop off a large piece at the top, but could do with not using a couple of gigabytes relocated from the range below 4Gb, or via command line option), which is why I told you that using map_domain_page() for the kexec crash area is a bad thing in the first place.

Jan

Quoted 1 line

+ }

#4 lore raw

Re: [PATCH 1/2] Revert "kexec/x86: do not map crash kernel area"

In reply to Ian Campbell
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · David Vrabel

From: David Vrabel <[email protected]>

This reverts commit 7113a45451a9f656deeff070e47672043ed83664.

Quoted 7 lines
Quoted 3 lines

As indicated before - I don't think reverting is the right thing here. Just add the necessary code in the same (or another, if more suitable) place.

Isn't that what the second patch does? Perhaps this would be better structured as a single fix rather than a revert + do it properly, but the latter approach seems reasonable enough...

Right - that's what I'm asking for: Do this as a single patch.

Jan

#7 lore raw

Re: [PATCH 2/2] x86: map portion of kexec crash area that is within the direct map area

In reply to Jan Beulich
Quoted 5 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · David Vrabel

+ if ( kexec_crash_area.size )

Wouldn't this better also include a kexec_crash_area.start range check?

It's a "if there is a crash area" check. It seems fine as-is to me.

Quoted 10 lines

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

Quoted 7 lines
xen/arch/x86/setup.c +7 -0
+    {
+        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)));
+
+        map_pages_to_xen((unsigned long)__va(kexec_crash_area.start),
+                         s, e - s, PAGE_HYPERVISOR);

map_pages_to_xen() doesn't tolerate a huge count resulting when e < s (which is possible due to the min() above).

Yes, you're right. This needs to be:

if ( e > s )

       map_pages_to_xen(...)

David