Skip to contentSkip to conversation

xen/mce: fix file-scoped static variables in mce.c

PATCH Superseded Haozhong Zhang 2 participants 12 messages Apr 6, 2017 – Apr 7, 2017

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover xen/mce: fix file-scoped static variables in mce.c

Changes in v2:
* (Patch 4) Move v1 patch 1 to the last one in this series, so as to avoid blocking others in case it's too late for 4.9.
* (Patch 1) Make static mce barriers private to their users.
* (Patch 2&3) Separate v1 patch 2 into two patches, as they fix different bugs.

Haozhong Zhang (4):
xen/mce: make mce barriers private to their users
xen/mce: make 'severity_cpu' private to its users
xen/mce: always re-initialize 'severity_cpu' in mcheck_cmn_handler() xen/mce: make 'found_error' and 'mce_fatal_cpus' private to mcheck_cmn_handler()

 xen/arch/x86/cpu/mcheck/barrier.h |  7 +++++++
 xen/arch/x86/cpu/mcheck/mce.c     | 30 +++++++++++++++++++-----------
 2 files changed, 26 insertions(+), 11 deletions(-)
Signature · 7 lines
2.10.1


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

PATCH v2 1/4 xen/mce: make mce barriers private to their users

Each of current mce barriers is actually used by only one function, so move their definitions into their users. A static mce barrier initializer is introduced so we can move the initialization of above mce barriers to their definitions.

---
 xen/arch/x86/cpu/mcheck/barrier.h |  7 +++++++
 xen/arch/x86/cpu/mcheck/mce.c     | 10 +++-------
 2 files changed, 10 insertions(+), 7 deletions(-)
xen/arch/x86/cpu/mcheck/barrier.h +7 -0
index 87f7550..c22321c 100644
@@ -10,6 +10,13 @@ struct mce_softirq_barrier {
     atomic_t outgen;
 };
 
+#define DEFINE_MCE_BARRIER(barrier)        \
+    struct mce_softirq_barrier barrier = { \
+        .val    = ATOMIC_INIT(0),          \
+        .ingen  = ATOMIC_INIT(0),          \
+        .outgen = ATOMIC_INIT(0),          \
+    }
+
 /*
  * Initialize a barrier. Just set it to 0.
  */
xen/arch/x86/cpu/mcheck/mce.c +3 -7
index 11d0e23..437d155 100644
@@ -174,10 +174,6 @@ void mce_need_clearbank_register(mce_need_clearbank_t cbfunc)
     mc_need_clearbank_scan = cbfunc;
 }
 
-
-static struct mce_softirq_barrier mce_inside_bar, mce_severity_bar;
-static struct mce_softirq_barrier mce_trap_bar;
-
 /*
  * mce_logout_lock should only be used in the trap handler,
  * while MCIP has not been cleared yet in the global status
@@ -453,6 +449,7 @@ static int mce_urgent_action(const struct cpu_user_regs *regs,
 /* Shared #MC handler. */
 void mcheck_cmn_handler(const struct cpu_user_regs *regs)
 {
+    static DEFINE_MCE_BARRIER(mce_trap_bar);
     struct mca_banks *bankmask = mca_allbanks;
     struct mca_banks *clear_bank = __get_cpu_var(mce_clear_banks);
     uint64_t gstatus;
@@ -1698,6 +1695,8 @@ static int mce_delayed_action(mctelem_cookie_t mctc)
 /* Softirq Handler for this MCE# processing */
 static void mce_softirq(void)
 {
+    static DEFINE_MCE_BARRIER(mce_inside_bar);
+    static DEFINE_MCE_BARRIER(mce_severity_bar);
     int cpu = smp_processor_id();
     unsigned int workcpu;
 
@@ -1764,9 +1763,6 @@ void mce_handler_init(void)
 
     /* callback register, do we really need so many callback? */
     /* mce handler data initialization */
-    mce_barrier_init(&mce_inside_bar);
-    mce_barrier_init(&mce_severity_bar);
-    mce_barrier_init(&mce_trap_bar);
     spin_lock_init(&mce_logout_lock);
     open_softirq(MACHINE_CHECK_SOFTIRQ, mce_softirq);
 }
Signature · 7 lines
2.10.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v2 1/4
#2 lore raw

Re: [PATCH v2 1/4] xen/mce: make mce barriers private to their users

xen/arch/x86/cpu/mcheck/barrier.h struct mce_softirq_barrier { · line 13

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 06.04.17 at 14:33, <[email protected]> wrote:
xen/arch/x86/cpu/mcheck/barrier.h +1 -0
@@ -10,6 +10,13 @@ struct mce_softirq_barrier {
     atomic_t outgen;
 };
 
+#define DEFINE_MCE_BARRIER(barrier)        \

With the parameter name changed to "name" or "sym" or some such

Jan

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

#3 lore raw

PATCH v2 2/4 xen/mce: make 'severity_cpu' private to its users

In reply to Haozhong Zhang

The current 'severity_cpu' is used by both mcheck_cmn_handler() and mce_softirq(). If MC# happens during mce_softirq(), the values set in mcheck_cmn_handler() and mce_softirq() may interfere with each other. Use private 'severity_cpu' for each function to fix this issue.

---
 xen/arch/x86/cpu/mcheck/mce.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/x86/cpu/mcheck/mce.c +2 -1
index 437d155..a2e9668 100644
@@ -182,7 +182,6 @@ void mce_need_clearbank_register(mce_need_clearbank_t cbfunc)
  */
 static DEFINE_SPINLOCK(mce_logout_lock);
 
-static atomic_t severity_cpu = ATOMIC_INIT(-1);
 static atomic_t found_error = ATOMIC_INIT(0);
 static cpumask_t mce_fatal_cpus;
 
@@ -450,6 +449,7 @@ static int mce_urgent_action(const struct cpu_user_regs *regs,
 void mcheck_cmn_handler(const struct cpu_user_regs *regs)
 {
     static DEFINE_MCE_BARRIER(mce_trap_bar);
+    static atomic_t severity_cpu = ATOMIC_INIT(-1);
     struct mca_banks *bankmask = mca_allbanks;
     struct mca_banks *clear_bank = __get_cpu_var(mce_clear_banks);
     uint64_t gstatus;
@@ -1697,6 +1697,7 @@ static void mce_softirq(void)
 {
     static DEFINE_MCE_BARRIER(mce_inside_bar);
     static DEFINE_MCE_BARRIER(mce_severity_bar);
+    static atomic_t severity_cpu;
     int cpu = smp_processor_id();
     unsigned int workcpu;
 
Signature · 7 lines
2.10.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v2 2/4
#4 lore raw

Re: [PATCH v2 2/4] xen/mce: make 'severity_cpu' private to its users

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 06.04.17 at 14:33, <[email protected]> wrote:

The current 'severity_cpu' is used by both mcheck_cmn_handler() and mce_softirq(). If MC# happens during mce_softirq(), the values set in mcheck_cmn_handler() and mce_softirq() may interfere with each other. Use private 'severity_cpu' for each function to fix this issue.

Other than patch 1 I think this qualifies for 4.9.

Jan

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

#5 lore raw

Re: [PATCH v2 2/4] xen/mce: make 'severity_cpu' private to its users

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines · On 07.04.17 at 15:48, <[email protected]> wrote:
Quoted 1 line · On 06.04.17 at 14:33, <[email protected]> wrote:

The current 'severity_cpu' is used by both mcheck_cmn_handler() and mce_softirq(). If MC# happens during mce_softirq(), the values set in mcheck_cmn_handler() and mce_softirq() may interfere with each other. Use private 'severity_cpu' for each function to fix this issue.

Quoted 5 lines
Quoted 1 line

Other than patch 1 I think this qualifies for 4.9.

And for that reason it is generally better to put bug fixes first in your series, and pure cleanup last. This patch will now need re-basing and the committed patch 2 (which I did adjust as necessary to apply on its own).

Jan

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

#6 lore raw

PATCH v2 3/4 xen/mce: always re-initialize 'severity_cpu' in mcheck_cmn_handler()

In reply to Haozhong Zhang

mcheck_cmn_handler() does not always set 'severity_cpu' to override its value taken from previous rounds of MC handling, which will interfere the current round of MC handling. Always re-initialize it to clear the historical value.

---
 xen/arch/x86/cpu/mcheck/mce.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
xen/arch/x86/cpu/mcheck/mce.c +13 -1
index a2e9668..d1bc642 100644
@@ -449,13 +449,25 @@ static int mce_urgent_action(const struct cpu_user_regs *regs,
 void mcheck_cmn_handler(const struct cpu_user_regs *regs)
 {
     static DEFINE_MCE_BARRIER(mce_trap_bar);
-    static atomic_t severity_cpu = ATOMIC_INIT(-1);
+    static DEFINE_MCE_BARRIER(mce_handler_init_bar);
+    static atomic_t severity_cpu;
     struct mca_banks *bankmask = mca_allbanks;
     struct mca_banks *clear_bank = __get_cpu_var(mce_clear_banks);
     uint64_t gstatus;
     mctelem_cookie_t mctc = NULL;
     struct mca_summary bs;
 
+    /*
+     * Re-initialize severity_cpu to clear historical information
+     * taken from previous rounds of MC handling. Besides this
+     * initialization, severity_cpu is not always set below to
+     * override the previous value, so the re-initialization is
+     * necessary.
+     */
+    mce_barrier_enter(&mce_handler_init_bar);
+    atomic_set(&severity_cpu, -1);
+    mce_barrier_exit(&mce_handler_init_bar);
+
     mce_spin_lock(&mce_logout_lock);
 
     if (clear_bank != NULL) {
Signature · 7 lines
2.10.1


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

PATCH RESEND v2 3/4 xen/mce: always re-initialize 'severity_cpu' in mcheck_cmn_handler()

mcheck_cmn_handler() does not always set 'severity_cpu' to override its value taken from previous rounds of MC handling, which will interfere the current round of MC handling. Always re-initialize it to clear the historical value.

---
Reason for resend:
* Move the re-initialization after its last use, so that we can avoid introducing a new mce barrier.

---
 xen/arch/x86/cpu/mcheck/mce.c | 1 +
 1 file changed, 1 insertion(+)
xen/arch/x86/cpu/mcheck/mce.c +1 -0
index a2e9668..0d9d5b0 100644
@@ -523,6 +523,7 @@ void mcheck_cmn_handler(const struct cpu_user_regs *regs)
             mc_panic(ebuf);
         }
         atomic_set(&found_error, 0);
+        atomic_set(&severity_cpu, -1);
     }
     mce_barrier_exit(&mce_trap_bar);
 
Signature · 7 lines
2.10.1


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

PATCH RESEND v2 4/4 xen/mce: make 'found_error' and 'mce_fatal_cpus' private to mcheck_cmn_handler()

mcheck_cmn_handler() is the only user of 'found_error' and 'mce_fatal_cpus'.

---
Reason for resend:
* Adapt for resent patch 3.

---
 xen/arch/x86/cpu/mcheck/mce.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
xen/arch/x86/cpu/mcheck/mce.c +2 -3
index 0d9d5b0..54fd000 100644
@@ -182,9 +182,6 @@ void mce_need_clearbank_register(mce_need_clearbank_t cbfunc)
  */
 static DEFINE_SPINLOCK(mce_logout_lock);
 
-static atomic_t found_error = ATOMIC_INIT(0);
-static cpumask_t mce_fatal_cpus;
-
 const struct mca_error_handler *__read_mostly mce_dhandlers;
 const struct mca_error_handler *__read_mostly mce_uhandlers;
 unsigned int __read_mostly mce_dhandler_num;
@@ -450,6 +447,8 @@ void mcheck_cmn_handler(const struct cpu_user_regs *regs)
 {
     static DEFINE_MCE_BARRIER(mce_trap_bar);
     static atomic_t severity_cpu = ATOMIC_INIT(-1);
+    static atomic_t found_error = ATOMIC_INIT(0);
+    static cpumask_t mce_fatal_cpus;
     struct mca_banks *bankmask = mca_allbanks;
     struct mca_banks *clear_bank = __get_cpu_var(mce_clear_banks);
     uint64_t gstatus;
Signature · 7 lines
2.10.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v2 4/4
#9 lore raw

Re: [RESEND PATCH v2 4/4] xen/mce: make 'found_error' and 'mce_fatal_cpus' private to mcheck_cmn_handler()

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 07.04.17 at 09:52, <[email protected]> wrote:

mcheck_cmn_handler() is the only user of 'found_error' and 'mce_fatal_cpus'.

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

Reviewed-by on v2 3/4
#10 lore raw

Re: [RESEND PATCH v2 3/4] xen/mce: always re-initialize 'severity_cpu' in mcheck_cmn_handler()

In reply to Haozhong Zhang
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 07.04.17 at 09:52, <[email protected]> wrote:

mcheck_cmn_handler() does not always set 'severity_cpu' to override its value taken from previous rounds of MC handling, which will interfere the current round of MC handling. Always re-initialize it to clear the historical value.

Same here as to 4.9.

Quoted 4 lines

---
Reason for resend:
* Move the re-initialization after its last use, so that we can avoid introducing a new mce barrier.

In the future please don't call this a "resend" - it is a new version if you make a change.

Jan

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

#11 lore raw

PATCH v2 4/4 xen/mce: make 'found_error' and 'mce_fatal_cpus' private to mcheck_cmn_handler()

In reply to Haozhong Zhang

mcheck_cmn_handler() is the only user of 'found_error' and 'mce_fatal_cpus'.

---
 xen/arch/x86/cpu/mcheck/mce.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
xen/arch/x86/cpu/mcheck/mce.c +2 -3
index d1bc642..39d19a3 100644
@@ -182,9 +182,6 @@ void mce_need_clearbank_register(mce_need_clearbank_t cbfunc)
  */
 static DEFINE_SPINLOCK(mce_logout_lock);
 
-static atomic_t found_error = ATOMIC_INIT(0);
-static cpumask_t mce_fatal_cpus;
-
 const struct mca_error_handler *__read_mostly mce_dhandlers;
 const struct mca_error_handler *__read_mostly mce_uhandlers;
 unsigned int __read_mostly mce_dhandler_num;
@@ -451,6 +448,8 @@ void mcheck_cmn_handler(const struct cpu_user_regs *regs)
     static DEFINE_MCE_BARRIER(mce_trap_bar);
     static DEFINE_MCE_BARRIER(mce_handler_init_bar);
     static atomic_t severity_cpu;
+    static atomic_t found_error = ATOMIC_INIT(0);
+    static cpumask_t mce_fatal_cpus;
     struct mca_banks *bankmask = mca_allbanks;
     struct mca_banks *clear_bank = __get_cpu_var(mce_clear_banks);
     uint64_t gstatus;
Signature · 7 lines
2.10.1


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