Skip to contentSkip to conversation

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

PATCH Superseded Juergen Gross 4 participants 11 messages Jan 8, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

---
 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 18 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.

---
 xen/arch/x86/smpboot.c | 2 ++
 1 file changed, 2 insertions(+)
xen/arch/x86/smpboot.c +0 -0
index 7e29704080..46c0729214 100644

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

Quoted 5 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;

Shouldn't the mfn be set to INVALID_MFN instead?

Wei.

Quoted 6 lines
xen/arch/x86/smpboot.c +0 -0
     }
 
     FREE_XENHEAP_PAGE(per_cpu(compat_gdt, cpu));
Signature · 1 line
2.16.4

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

#2 lore raw
Quoted 14 lines · Wei Liu
Quoted 13 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.

---
  xen/arch/x86/smpboot.c | 2 ++
  1 file changed, 2 insertions(+)
Quoted 12 lines

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

Quoted 10 lines
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;

Shouldn't the mfn be set to INVALID_MFN instead?

This would require modifying alloc_stub_page():

    if ( *mfn )
        pg = mfn_to_page(_mfn(*mfn));
    else

Juergen

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

#3 lore raw
Quoted 30 lines · Jürgen Groß
Quoted 14 lines · Wei Liu
Quoted 13 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.

---
  xen/arch/x86/smpboot.c | 2 ++

  1 file changed, 2 insertions(+)
Quoted 14 lines
Quoted 6 lines
xen/arch/x86/smpboot.c +0 -0
index 7e29704080..46c0729214 100644
@@ -945,6 +945,8 @@ static void cpu_smpboot_free(unsigned int cpu,
 bool remove)
Quoted 6 lines

                               (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;

Shouldn't the mfn be set to INVALID_MFN instead?

Quoted 5 lines

This would require modifying alloc_stub_page():

    if ( *mfn )
        pg = mfn_to_page(_mfn(*mfn));
    else

Correct.  per-cpu data is initialised to 0, not to a custom default, so using INVALID_MFN is more complicated.

~Andrew

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

#4 lore raw
In reply to Jürgen Groß
Quoted 28 lines · Jürgen Groß
Quoted 14 lines · Wei Liu
Quoted 13 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.

---
  xen/arch/x86/smpboot.c | 2 ++
  1 file changed, 2 insertions(+)
Quoted 12 lines

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

Quoted 10 lines
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;

Shouldn't the mfn be set to INVALID_MFN instead?

Quoted 5 lines

This would require modifying alloc_stub_page():

    if ( *mfn )
        pg = mfn_to_page(_mfn(*mfn));
    else

OK. I think the chance of allocating mfn 0 from the allocator is exceedingly low, so I certainly have no objection to reset it to 0.

Wei.

Quoted 3 lines

Juergen

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

#5 lore raw
Quoted 29 lines · Wei Liu
Quoted 28 lines · Jürgen Groß
Quoted 26 lines · Wei Liu
Quoted 18 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.

---
   xen/arch/x86/smpboot.c | 2 ++
   1 file changed, 2 insertions(+)
xen/arch/x86/smpboot.c +0 -0
index 7e29704080..46c0729214 100644

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

Quoted 5 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;

Shouldn't the mfn be set to INVALID_MFN instead?

Quoted 8 lines
Quoted 5 lines

This would require modifying alloc_stub_page():

     if ( *mfn )
         pg = mfn_to_page(_mfn(*mfn));
     else

OK. I think the chance of allocating mfn 0 from the allocator is exceedingly low, so I certainly have no objection to reset it to 0.

The chance should be exactly zero. Otherwise we'd have a big problem due to L1TF...

Juergen

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

Reviewed-by
#6 lore raw
Quoted 36 lines · Jürgen Groß
Quoted 35 lines · Wei Liu
Quoted 33 lines · Jürgen Groß
Quoted 14 lines · Wei Liu
Quoted 13 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.

---
   xen/arch/x86/smpboot.c | 2 ++
   1 file changed, 2 insertions(+)
Quoted 12 lines

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

Quoted 10 lines
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;

Shouldn't the mfn be set to INVALID_MFN instead?

This would require modifying alloc_stub_page():

     if ( *mfn )
         pg = mfn_to_page(_mfn(*mfn));
     else
Quoted 5 lines
Quoted 2 lines

OK. I think the chance of allocating mfn 0 from the allocator is exceedingly low, so I certainly have no objection to reset it to 0.

The chance should be exactly zero. Otherwise we'd have a big problem due to L1TF...

Heh...

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

#7 lore raw
In reply to Jürgen Groß
Quoted 39 lines · Jürgen Groß
Quoted 38 lines · Wei Liu
Quoted 36 lines · Jürgen Groß
Quoted 15 lines · Wei Liu
Quoted 14 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.

---
   xen/arch/x86/smpboot.c | 2 ++

   1 file changed, 2 insertions(+)
Quoted 14 lines
Quoted 6 lines
xen/arch/x86/smpboot.c +0 -0
index 7e29704080..46c0729214 100644
@@ -945,6 +945,8 @@ static void cpu_smpboot_free(unsigned int cpu,
 bool remove)
Quoted 6 lines

                                (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;

Shouldn't the mfn be set to INVALID_MFN instead?

This would require modifying alloc_stub_page():

     if ( *mfn )
         pg = mfn_to_page(_mfn(*mfn));
     else

Quoted 5 lines
Quoted 2 lines

OK. I think the chance of allocating mfn 0 from the allocator is exceedingly low, so I certainly have no objection to reset it to 0.

The chance should be exactly zero. Otherwise we'd have a big problem due to L1TF...

Also MFN 0 contains the IVT and BDA.

The IVT at least must remain valid at all times (even on EFI systems), because AP boot needs to have at least a no-op NMI handler.  A base of 0 and limit of 0xffff is the architectural INIT/RESET state for IDTR. (Also for the other system data structures, but they have to be moved elsewhere before they can be used).

~Andrew

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

#8 lore raw
In reply to Juergen Gross

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

Quoted 9 lines · Juergen Gross
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;
     }

Afaict this was a regression from the introduction of CPU parking:
Prior to that, per-CPU data would have been zeroed in all cases before a new CPU was unleashed. I think it would be helpful it this was mentioned in the description (possibly by way of a Fixes:
tag).

Jan

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

#9 lore raw
Quoted 16 lines · Jan Beulich

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

Quoted 9 lines · Juergen Gross
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;
      }

Afaict this was a regression from the introduction of CPU parking:
Prior to that, per-CPU data would have been zeroed in all cases before a new CPU was unleashed. I think it would be helpful it this was mentioned in the description (possibly by way of a Fixes:
tag).

Okay, will do. Just to be sure - you are thinking of commit 2e6c8f182?

Juergen

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

#10 lore raw
Quoted 18 lines · Jürgen Groß
Quoted 16 lines · Jan Beulich

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

Quoted 9 lines · Juergen Gross
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;
      }

Afaict this was a regression from the introduction of CPU parking:
Prior to that, per-CPU data would have been zeroed in all cases before a new CPU was unleashed. I think it would be helpful it this was mentioned in the description (possibly by way of a Fixes:
tag).

Quoted 1 line

Okay, will do. Just to be sure - you are thinking of commit 2e6c8f182?

Yes, this looks to be the one.

Jan

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