Skip to contentSkip to conversation

xen/x86: clear per cpu stub page information in cpu_smpboot_free()

PATCH In review Juergen Gross 3 participants 5 messages Jan 8, 2020 – Jan 9, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xen/x86: clear per cpu stub page information in cpu_smpboot_free()

cpu_smpboot_free() removes the stubs for the cpu going offline, but it isn't clearing the related percpu variables. This will result in crashes when a stub page is released due to all related cpus gone offline and one of those cpus going online later.

Fix that by clearing stubs.addr and stubs.mfn in order to allocate a new stub page when needed.

Fixes 2e6c8f182c9c50 ("x86: distinguish CPU offlining from CPU removal")
---
 xen/arch/x86/smpboot.c | 2 ++
 1 file changed, 2 insertions(+)
xen/arch/x86/smpboot.c +2 -0
index 7e29704080..46c0729214 100644
@@ -945,6 +945,8 @@ static void cpu_smpboot_free(unsigned int cpu, bool remove)
                              (per_cpu(stubs.addr, cpu) | ~PAGE_MASK) + 1);
         if ( i == STUBS_PER_PAGE )
             free_domheap_page(mfn_to_page(mfn));
+        per_cpu(stubs.addr, cpu) = 0;
+        per_cpu(stubs.mfn, cpu) = 0;
     }
 
     FREE_XENHEAP_PAGE(per_cpu(compat_gdt, cpu));
Signature · 7 lines
2.16.4


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

cpu_smpboot_free() removes the stubs for the cpu going offline, but it isn't clearing the related percpu variables. This will result in crashes when a stub page is released due to all related cpus gone offline and one of those cpus going online later.

Fix that by clearing stubs.addr and stubs.mfn in order to allocate a new stub page when needed.

I was really hoping for you to mention CPU parking here. How about

"Fix that by clearing stubs.mfn (and also stubs.addr just to be on
the safe side) in order to allocate a new stub page when needed, irrespective of whether the CPU gets parked or removed."

xen/arch/x86/smpboot.c static void cpu_smpboot_free(unsigned int cpu, bool remove) · line 949

Quoted 8 lines
xen/arch/x86/smpboot.c +2 -0
@@ -945,6 +945,8 @@ static void cpu_smpboot_free(unsigned int cpu, bool remove)
                              (per_cpu(stubs.addr, cpu) | ~PAGE_MASK) + 1);
         if ( i == STUBS_PER_PAGE )
             free_domheap_page(mfn_to_page(mfn));
+        per_cpu(stubs.addr, cpu) = 0;
+        per_cpu(stubs.mfn, cpu) = 0;

Looking more closely, I think I'd prefer these two lines (of which the addr one isn't strictly needed anyway) to move ahead of the if().

If you agree, I'll be happy to do both while committing.

Jan

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

#2 lore raw
Quoted 28 lines · Jan Beulich
Quoted 7 lines · Juergen Gross

cpu_smpboot_free() removes the stubs for the cpu going offline, but it isn't clearing the related percpu variables. This will result in crashes when a stub page is released due to all related cpus gone offline and one of those cpus going online later.

Fix that by clearing stubs.addr and stubs.mfn in order to allocate a new stub page when needed.

I was really hoping for you to mention CPU parking here. How about

"Fix that by clearing stubs.mfn (and also stubs.addr just to be on
the safe side) in order to allocate a new stub page when needed, irrespective of whether the CPU gets parked or removed."

xen/arch/x86/smpboot.c static void cpu_smpboot_free(unsigned int cpu, bool remove) · line 949

Quoted 8 lines
xen/arch/x86/smpboot.c +2 -0
@@ -945,6 +945,8 @@ static void cpu_smpboot_free(unsigned int cpu, bool remove)
                               (per_cpu(stubs.addr, cpu) | ~PAGE_MASK) + 1);
          if ( i == STUBS_PER_PAGE )
              free_domheap_page(mfn_to_page(mfn));
+        per_cpu(stubs.addr, cpu) = 0;
+        per_cpu(stubs.mfn, cpu) = 0;

Looking more closely, I think I'd prefer these two lines (of which the addr one isn't strictly needed anyway) to move ahead of the if().

Quoted 1 line

If you agree, I'll be happy to do both while committing.

I agree.

I'm not sure the addr clearing can be omitted. This might result in problems when during onlining an early error happens in cpu_smpboot_alloc() and thus skipping the call of alloc_stub_page(). The subsequent call of cpu_smpboot_free() will then overwrite mfn 0.

Juergen

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

#3 lore raw
Quoted 29 lines · Jürgen Groß
Quoted 28 lines · Jan Beulich
Quoted 7 lines · Juergen Gross

cpu_smpboot_free() removes the stubs for the cpu going offline, but it isn't clearing the related percpu variables. This will result in crashes when a stub page is released due to all related cpus gone offline and one of those cpus going online later.

Fix that by clearing stubs.addr and stubs.mfn in order to allocate a new stub page when needed.

I was really hoping for you to mention CPU parking here. How about

"Fix that by clearing stubs.mfn (and also stubs.addr just to be on
the safe side) in order to allocate a new stub page when needed, irrespective of whether the CPU gets parked or removed."

xen/arch/x86/smpboot.c static void cpu_smpboot_free(unsigned int cpu, bool remove) · line 949

Quoted 8 lines
xen/arch/x86/smpboot.c +2 -0
@@ -945,6 +945,8 @@ static void cpu_smpboot_free(unsigned int cpu, bool remove)
                               (per_cpu(stubs.addr, cpu) | ~PAGE_MASK) + 1);
          if ( i == STUBS_PER_PAGE )
              free_domheap_page(mfn_to_page(mfn));
+        per_cpu(stubs.addr, cpu) = 0;
+        per_cpu(stubs.mfn, cpu) = 0;

Looking more closely, I think I'd prefer these two lines (of which the addr one isn't strictly needed anyway) to move ahead of the if().

Quoted 8 lines
Quoted 1 line

If you agree, I'll be happy to do both while committing.

I agree.

I'm not sure the addr clearing can be omitted. This might result in problems when during onlining an early error happens in cpu_smpboot_alloc() and thus skipping the call of alloc_stub_page(). The subsequent call of cpu_smpboot_free() will then overwrite mfn 0.

Oh, good point.

Jan

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

Tested-by on v2 1/1
#4 lore raw
In reply to Juergen Gross

Thank you Juergen. This patch fix the issue in

XEN crash and double fault when doing cpu online/offline
https://lists.xenproject.org/archives/html/xen-devel/2020-01/msg00424.html

Quoted 32 lines · Juergen Gross

cpu_smpboot_free() removes the stubs for the cpu going offline, but it isn't clearing the related percpu variables. This will result in crashes when a stub page is released due to all related cpus gone offline and one of those cpus going online later.

Fix that by clearing stubs.addr and stubs.mfn in order to allocate a new stub page when needed.

Fixes 2e6c8f182c9c50 ("x86: distinguish CPU offlining from CPU removal")
---
  xen/arch/x86/smpboot.c | 2 ++
  1 file changed, 2 insertions(+)
xen/arch/x86/smpboot.c +2 -1
index 7e29704080..46c0729214 100644
@@ -945,6 +945,8 @@ static void cpu_smpboot_free(unsigned int cpu, bool remove)
                               (per_cpu(stubs.addr, cpu) | ~PAGE_MASK) + 1);
          if ( i == STUBS_PER_PAGE )
              free_domheap_page(mfn_to_page(mfn));
+        per_cpu(stubs.addr, cpu) = 0;
+        per_cpu(stubs.mfn, cpu) = 0;
      }
 
      FREE_XENHEAP_PAGE(per_cpu(compat_gdt, cpu));
--

2.16.4

Quoted 5 lines

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

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