Skip to contentSkip to conversation

MCE code cleanup and bugfix

PATCH In review Haozhong Zhang 3 participants 12 messages Feb 27, 2017 – Mar 8, 2017

lore
Share & tools
lore
#0 lore raw

v2 cover MCE code cleanup and bugfix

Changes in v2:
* Only patch 6 is changed, which removes ASSERT's rather than modifying them.
* Take R-b in patch 2 - 5, and A-b in patch 7.
* Patch 1 in v1 (it only adjusts the code comment) hasn't got any R-b or A-b.

This patch series separates the uncommitted code cleanup and bugfix
patches from my previous patch series "[PATCH 00/19] MCE code cleanup and add LMCE support" with other new fixes.

* This patch series is based on Jan's patch "x86/MCE: sanitize domain/vcpu ID handling".
* Patch 1 & 6 are new ones.
* Patch 2 is the previous patch 4 w/ the same title.
* Patch 3 - 5 are the previous patch 8 - 10 w/ the last one renamed.
* Patch 7 is the previous patch 11 w/ the same title.
* Individual changes are logged in each patch.

Haozhong Zhang (7):
1/7 xen/mce: adjust comment of callback register functions 2/7 xen/mce: remove unused x86_mcinfo_add()
3/7 x86/mce: set mcinfo_comm.type and .size in x86_mcinfo_reserve() 4/7 x86/vmce: fill MSR_IA32_MCG_STATUS on all vcpus in broadcast case 5/7 x86/mce: clear MSR_IA32_MCG_STATUS by writing 0
6/7 xen/mce: remove ASSERT's about mce_dhandler_num in mce_action() 7/7 tools/xen-mceinj: fix the type of cpu number

 tools/tests/mce-test/tools/xen-mceinj.c | 12 +++---
 xen/arch/x86/cpu/mcheck/mcaction.c      | 20 ++++-----
 xen/arch/x86/cpu/mcheck/mce.c           | 37 ++++-------------
 xen/arch/x86/cpu/mcheck/mce.h           | 24 +++++------
 xen/arch/x86/cpu/mcheck/mce_amd.c       |  4 +-
 xen/arch/x86/cpu/mcheck/mce_intel.c     |  6 +--
 xen/arch/x86/cpu/mcheck/vmce.c          | 74 +++++++++++++++++++++++----------
 xen/arch/x86/cpu/mcheck/vmce.h          |  2 +-
 8 files changed, 91 insertions(+), 88 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/7 xen/mce: adjust comment of callback register functions

c/s e966818264908e842e2847f579ca4d94e586eaac added mce_need_clearbank_register below the comment of x86_mce_callback_register(). This commit (1) adjusts the first paragraph of comment to be a general statement of all callback register functions, and (2) moves the second paragraph to the front of x86_mce_callback_register().

---
Cc: Christoph Egger <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

---
 xen/arch/x86/cpu/mcheck/mce.h | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
xen/arch/x86/cpu/mcheck/mce.h +10 -10
index e83d431..42bb782 100644
@@ -128,24 +128,24 @@ extern void mcheck_mca_clearbanks(struct mca_banks *);
 extern mctelem_cookie_t mcheck_mca_logout(enum mca_source, struct mca_banks *,
     struct mca_summary *, struct mca_banks *);
 
-/* Register a callback to be made during bank telemetry logout.
- * This callback is only available to those machine check handlers
+/* Register callbacks to be made during bank telemetry logout.
+ * Those callbacks are only available to those machine check handlers
  * that call to the common mcheck_cmn_handler or who use the common
  * telemetry logout function mcheck_mca_logout in error polling.
- *
- * This can be used to collect additional information (typically non-
- * architectural) provided by newer CPU families/models without the need
- * to duplicate the whole handler resulting in various handlers each with
- * its own tweaks and bugs.  The callback receives an struct mc_info pointer
- * which it can use with x86_mcinfo_add to add additional telemetry,
- * the current MCA bank number we are reading telemetry from, and the
- * MCi_STATUS value for that bank.
  */
 
 /* Register a handler for judging whether the bank need to be cleared */
 typedef int (*mce_need_clearbank_t)(enum mca_source who, u64 status);
 extern void mce_need_clearbank_register(mce_need_clearbank_t);
 
+/* Register a callback to collect additional information (typically non-
+ * architectural) provided by newer CPU families/models without the need
+ * to duplicate the whole handler resulting in various handlers each with
+ * its own tweaks and bugs. The callback receives an struct mc_info pointer
+ * which it can use with x86_mcinfo_add to add additional telemetry,
+ * the current MCA bank number we are reading telemetry from, and the
+ * MCi_STATUS value for that bank.
+ */
 typedef struct mcinfo_extended *(*x86_mce_callback_t)
     (struct mc_info *, uint16_t, uint64_t);
 extern void x86_mce_callback_register(x86_mce_callback_t);
Signature · 7 lines
2.10.1


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

Re: [PATCH v2 1/7] xen/mce: adjust comment of callback register functions

Quoted 8 lines · Haozhong Zhang

c/s e966818264908e842e2847f579ca4d94e586eaac added mce_need_clearbank_register below the comment of x86_mce_callback_register(). This commit (1) adjusts the first paragraph of comment to be a general statement of all callback register functions, and (2) moves the second paragraph to the front of x86_mce_callback_register().

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

#3 lore raw

PATCH v2 2/7 xen/mce: remove unused x86_mcinfo_add()

In reply to Haozhong Zhang

c/s 9d13fd9fd320a7740c6446c048ff6a2990095966 turned to update the mcinfo buffer in-place instead of using x86_mcinfo_add(). The last uses of x86_mcinfo_add() were removed by that commit as well. Therefore, x86_mcinfo_add() was deprecated in fact.

---
Cc: Christoph Egger <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

---
 xen/arch/x86/cpu/mcheck/mce.c | 16 ----------------
 xen/arch/x86/cpu/mcheck/mce.h |  3 +--
 2 files changed, 1 insertion(+), 18 deletions(-)
xen/arch/x86/cpu/mcheck/mce.c +0 -16
index e41989d..aa9304f 100644
@@ -835,22 +835,6 @@ void *x86_mcinfo_reserve(struct mc_info *mi, int size)
     return memset(mic_index, 0, size);
 }
 
-void *x86_mcinfo_add(struct mc_info *mi, void *mcinfo)
-{
-    struct mcinfo_common *mic, *buf;
-
-    mic = (struct mcinfo_common *)mcinfo;
-    buf = x86_mcinfo_reserve(mi, mic->size);
-
-    if ( !buf )
-        mce_printk(MCE_CRITICAL,
-                   "mcinfo_add: No space left in mc_info\n");
-    else
-        memcpy(buf, mic, mic->size);
-
-    return buf;
-}
-
 static void x86_mcinfo_apei_save(
     struct mcinfo_global *mc_global, struct mcinfo_bank *mc_bank)
 {
xen/arch/x86/cpu/mcheck/mce.h +1 -2
index 42bb782..a28e862 100644
@@ -142,7 +142,7 @@ extern void mce_need_clearbank_register(mce_need_clearbank_t);
  * architectural) provided by newer CPU families/models without the need
  * to duplicate the whole handler resulting in various handlers each with
  * its own tweaks and bugs. The callback receives an struct mc_info pointer
- * which it can use with x86_mcinfo_add to add additional telemetry,
+ * which it can use with x86_mcinfo_reserve to add additional telemetry,
  * the current MCA bank number we are reading telemetry from, and the
  * MCi_STATUS value for that bank.
  */
@@ -150,7 +150,6 @@ typedef struct mcinfo_extended *(*x86_mce_callback_t)
     (struct mc_info *, uint16_t, uint64_t);
 extern void x86_mce_callback_register(x86_mce_callback_t);
 
-void *x86_mcinfo_add(struct mc_info *mi, void *mcinfo);
 void *x86_mcinfo_reserve(struct mc_info *mi, int size);
 void x86_mcinfo_dump(struct mc_info *mi);
 
Signature · 7 lines
2.10.1


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

PATCH v2 3/7 x86/mce: set mcinfo_comm.type and .size in x86_mcinfo_reserve()

In reply to Haozhong Zhang

All existing calls to x86_mcinfo_reserve() are followed by statements that set the size and the type of the reserved space, so move them into x86_mcinfo_reserve() to simplify the code.

---
Cc: Christoph Egger <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

---
 xen/arch/x86/cpu/mcheck/mcaction.c  |  4 +---
 xen/arch/x86/cpu/mcheck/mce.c       | 17 +++++++++--------
 xen/arch/x86/cpu/mcheck/mce.h       |  3 ++-
 xen/arch/x86/cpu/mcheck/mce_amd.c   |  4 +---
 xen/arch/x86/cpu/mcheck/mce_intel.c |  6 +-----
 5 files changed, 14 insertions(+), 20 deletions(-)
xen/arch/x86/cpu/mcheck/mcaction.c +1 -3
index 322163a..32056f2 100644
@@ -13,14 +13,12 @@ mci_action_add_pageoffline(int bank, struct mc_info *mi,
     if (!mi)
         return NULL;
 
-    rec = x86_mcinfo_reserve(mi, sizeof(*rec));
+    rec = x86_mcinfo_reserve(mi, sizeof(*rec), MC_TYPE_RECOVERY);
     if (!rec) {
         mi->flags |= MCINFO_FLAGS_UNCOMPLETE;
         return NULL;
     }
 
-    rec->common.type = MC_TYPE_RECOVERY;
-    rec->common.size = sizeof(*rec);
     rec->mc_bank = bank;
     rec->action_types = MC_ACTION_PAGE_OFFLINE;
     rec->action_info.page_retire.mfn = mfn;
xen/arch/x86/cpu/mcheck/mce.c +9 -8
index aa9304f..53ca29c 100644
@@ -205,7 +205,7 @@ static void mca_init_bank(enum mca_source who,
     if (!mi)
         return;
 
-    mib = x86_mcinfo_reserve(mi, sizeof(*mib));
+    mib = x86_mcinfo_reserve(mi, sizeof(*mib), MC_TYPE_BANK);
     if (!mib)
     {
         mi->flags |= MCINFO_FLAGS_UNCOMPLETE;
@@ -214,8 +214,6 @@ static void mca_init_bank(enum mca_source who,
 
     mib->mc_status = mca_rdmsr(MSR_IA32_MCx_STATUS(bank));
 
-    mib->common.type = MC_TYPE_BANK;
-    mib->common.size = sizeof (struct mcinfo_bank);
     mib->mc_bank = bank;
     mib->mc_domid = DOMID_INVALID;
 
@@ -251,8 +249,6 @@ static int mca_init_global(uint32_t flags, struct mcinfo_global *mig)
     const struct vcpu *curr = current;
 
     /* Set global information */
-    mig->common.type = MC_TYPE_GLOBAL;
-    mig->common.size = sizeof (struct mcinfo_global);
     status = mca_rdmsr(MSR_IA32_MCG_STATUS);
     mig->mc_gstatus = status;
     mig->mc_domid = DOMID_INVALID;
@@ -349,7 +345,7 @@ mcheck_mca_logout(enum mca_source who, struct mca_banks *bankmask,
             if ( (mctc = mctelem_reserve(which)) != NULL ) {
                 mci = mctelem_dataptr(mctc);
                 mcinfo_clear(mci);
-                mig = x86_mcinfo_reserve(mci, sizeof(*mig));
+                mig = x86_mcinfo_reserve(mci, sizeof(*mig), MC_TYPE_GLOBAL);
                 /* mc_info should at least hold up the global information */
                 ASSERT(mig);
                 mca_init_global(mc_flags, mig);
@@ -805,7 +801,8 @@ static void mcinfo_clear(struct mc_info *mi)
     x86_mcinfo_nentries(mi) = 0;
 }
 
-void *x86_mcinfo_reserve(struct mc_info *mi, int size)
+void *x86_mcinfo_reserve(struct mc_info *mi,
+                         unsigned int size, unsigned int type)
 {
     int i;
     unsigned long end1, end2;
@@ -832,7 +829,11 @@ void *x86_mcinfo_reserve(struct mc_info *mi, int size)
     /* there's enough space. add entry. */
     x86_mcinfo_nentries(mi)++;
 
-    return memset(mic_index, 0, size);
+    memset(mic_index, 0, size);
+    mic_index->size = size;
+    mic_index->type = type;
+
+    return mic_index;
 }
 
 static void x86_mcinfo_apei_save(
xen/arch/x86/cpu/mcheck/mce.h +2 -1
index a28e862..b479b20 100644
@@ -150,7 +150,8 @@ typedef struct mcinfo_extended *(*x86_mce_callback_t)
     (struct mc_info *, uint16_t, uint64_t);
 extern void x86_mce_callback_register(x86_mce_callback_t);
 
-void *x86_mcinfo_reserve(struct mc_info *mi, int size);
+void *x86_mcinfo_reserve(struct mc_info *mi,
+                         unsigned int size, unsigned int type);
 void x86_mcinfo_dump(struct mc_info *mi);
 
 static inline int mce_vendor_bank_msr(const struct vcpu *v, uint32_t msr)
xen/arch/x86/cpu/mcheck/mce_amd.c +1 -3
index 599e465..fe51be9 100644
@@ -218,15 +218,13 @@ amd_f10_handler(struct mc_info *mi, uint16_t bank, uint64_t status)
     if ( !(status & MCi_STATUS_MISCV) )
         return NULL;
 
-    mc_ext = x86_mcinfo_reserve(mi, sizeof(*mc_ext));
+    mc_ext = x86_mcinfo_reserve(mi, sizeof(*mc_ext), MC_TYPE_EXTENDED);
     if ( !mc_ext )
     {
         mi->flags |= MCINFO_FLAGS_UNCOMPLETE;
         return NULL;
     }
 
-    mc_ext->common.type = MC_TYPE_EXTENDED;
-    mc_ext->common.size = sizeof(*mc_ext);
     mc_ext->mc_msrs = 3;
 
     mc_ext->mc_msr[0].reg = MSR_F10_MC4_MISC1;
xen/arch/x86/cpu/mcheck/mce_intel.c +1 -5
index 005e41d..189c1ed 100644
@@ -200,17 +200,13 @@ intel_get_extended_msrs(struct mcinfo_global *mig, struct mc_info *mi)
             !(mig->mc_gstatus & MCG_STATUS_EIPV))
         return NULL;
 
-    mc_ext = x86_mcinfo_reserve(mi, sizeof(*mc_ext));
+    mc_ext = x86_mcinfo_reserve(mi, sizeof(*mc_ext), MC_TYPE_EXTENDED);
     if (!mc_ext)
     {
         mi->flags |= MCINFO_FLAGS_UNCOMPLETE;
         return NULL;
     }
 
-    /* this function will called when CAP(9).MCG_EXT_P = 1 */
-    mc_ext->common.type = MC_TYPE_EXTENDED;
-    mc_ext->common.size = sizeof(struct mcinfo_extended);
-
     for (i = MSR_IA32_MCG_EAX; i <= MSR_IA32_MCG_MISC; i++)
         intel_get_extended_msr(mc_ext, i);
 
Signature · 7 lines
2.10.1


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

PATCH v2 4/7 x86/vmce: fill MSR_IA32_MCG_STATUS on all vcpus in broadcast case

In reply to Haozhong Zhang

The current implementation only fills MC MSRs on vcpu0 and leaves MC MSRs on other vcpus empty in the broadcast case. When guest reads 0 from MSR_IA32_MCG_STATUS on vcpuN (N > 0), it may think it's not possible to recover the execution on that vcpu and then get panic, although MSR_IA32_MCG_STATUS filled on vcpu0 may imply the injected vMCE is actually recoverable. To avoid such unnecessary guest panic, set MSR_IA32_MCG_STATUS on vcpuN (N > 0) to MCG_STATUS_MCIP|MCG_STATUS_RIPV.

In addition, fill_vmsr_data(mc_bank, ...) is changed to return -EINVAL rather than 0, if an invalid domain ID is contained in mc_bank.

---
Cc: Christoph Egger <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

---
 xen/arch/x86/cpu/mcheck/mcaction.c | 16 ++++-----
 xen/arch/x86/cpu/mcheck/vmce.c     | 74 ++++++++++++++++++++++++++------------
 xen/arch/x86/cpu/mcheck/vmce.h     |  2 +-
 3 files changed, 60 insertions(+), 32 deletions(-)
xen/arch/x86/cpu/mcheck/mcaction.c +8 -8
index 32056f2..dab9eac 100644
@@ -88,22 +88,22 @@ mc_memerr_dhandler(struct mca_binfo *binfo,
                     goto vmce_failed;
                 }
 
+                if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL ||
+                    global->mc_vcpuid == XEN_MC_VCPUID_INVALID)
+                    vmce_vcpuid = VMCE_INJECT_BROADCAST;
+                else
+                    vmce_vcpuid = global->mc_vcpuid;
+
                 bank->mc_addr = gfn << PAGE_SHIFT |
                   (bank->mc_addr & (PAGE_SIZE -1 ));
-                if ( fill_vmsr_data(bank, d,
-                      global->mc_gstatus) == -1 )
+                if (fill_vmsr_data(bank, d, global->mc_gstatus,
+                                   vmce_vcpuid == VMCE_INJECT_BROADCAST))
                 {
                     mce_printk(MCE_QUIET, "Fill vMCE# data for DOM%d "
                       "failed\n", bank->mc_domid);
                     goto vmce_failed;
                 }
 
-                if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL ||
-                    global->mc_vcpuid == XEN_MC_VCPUID_INVALID)
-                    vmce_vcpuid = VMCE_INJECT_BROADCAST;
-                else
-                    vmce_vcpuid = global->mc_vcpuid;
-
                 /* We will inject vMCE to DOMU*/
                 if ( inject_vmce(d, vmce_vcpuid) < 0 )
                 {
xen/arch/x86/cpu/mcheck/vmce.c +51 -23

89 lines not on this page · raw message

xen/arch/x86/cpu/mcheck/vmce.h +1 -1
index 163ce3c..74f6381 100644
@@ -17,7 +17,7 @@ int vmce_amd_rdmsr(const struct vcpu *, uint32_t msr, uint64_t *val);
 int vmce_amd_wrmsr(struct vcpu *, uint32_t msr, uint64_t val);
 
 int fill_vmsr_data(struct mcinfo_bank *mc_bank, struct domain *d,
-    uint64_t gstatus);
+                   uint64_t gstatus, bool broadcast);
 
 #define VMCE_INJECT_BROADCAST (-1)
 int inject_vmce(struct domain *d, int vcpu);
Signature · 7 lines
2.10.1


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

PATCH v2 5/7 x86/mce: clear MSR_IA32_MCG_STATUS by writing 0

In reply to Haozhong Zhang

On Intel CPU, an attemp to write to MSR_IA32_MCG_STATUS with any non-zero value would result in #GP.

This commit writes 0 on AMD CPU as well instead of just clearing MCIP bit, because all non-reserved bits of MSR_IA32_MCG_STATUS have been handled at this point.

---
Cc: Christoph Egger <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Boris Ostrovsky <[email protected]>

---
 xen/arch/x86/cpu/mcheck/mce.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/cpu/mcheck/mce.c +1 -1
index 53ca29c..5a7e2ba 100644
@@ -539,7 +539,7 @@ void mcheck_cmn_handler(const struct cpu_user_regs *regs)
     gstatus = mca_rdmsr(MSR_IA32_MCG_STATUS);
     if ((gstatus & MCG_STATUS_MCIP) != 0) {
         mce_printk(MCE_CRITICAL, "MCE: Clear MCIP@ last step");
-        mca_wrmsr(MSR_IA32_MCG_STATUS, gstatus & ~MCG_STATUS_MCIP);
+        mca_wrmsr(MSR_IA32_MCG_STATUS, 0);
     }
     mce_barrier_exit(&mce_trap_bar);
 
Signature · 7 lines
2.10.1


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

PATCH v2 6/7 xen/mce: remove ASSERT's about mce_dhandler_num in mce_action()

In reply to Haozhong Zhang

The current production build works fine even though those ASSERT's are violated. Remove them to make the debug build work as well.

---
Cc: Christoph Egger <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

Changes since v1:
* Remove those ASSERT's rather than making them Intel-only.

---
 xen/arch/x86/cpu/mcheck/mce.c | 4 ----
 1 file changed, 4 deletions(-)
xen/arch/x86/cpu/mcheck/mce.c +0 -4
index 5a7e2ba..a42cabd 100644
@@ -1621,9 +1621,6 @@ static enum mce_result mce_action(const struct cpu_user_regs *regs,
         handlers = mce_uhandlers;
     }
 
-    /* At least a default handler should be registerd */
-    ASSERT(handler_num);
-
     local_mi = (struct mc_info*)mctelem_dataptr(mctc);
     x86_mcinfo_lookup(mic, local_mi, MC_TYPE_GLOBAL);
     if (mic == NULL) {
@@ -1656,7 +1653,6 @@ static enum mce_result mce_action(const struct cpu_user_regs *regs,
                 break;
             }
         }
-        ASSERT(i != handler_num);
     }
 
     return worst_result;
Signature · 7 lines
2.10.1


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

Re: [PATCH v2 6/7] xen/mce: remove ASSERT's about mce_dhandler_num in mce_action()

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 27.02.17 at 06:09, <[email protected]> wrote:

The current production build works fine even though those ASSERT's are violated.

This - without any evidence - is rather weak an argument. Code inspection, otoh, pretty clearly tells us the ASSERT()s aren't needed, as there is no dependency on the asserted expressions to be true. Therefore, while the change itself is fine, may I ask for a better commit message?

Jan

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

#9 lore raw

PATCH v3 6/7 xen/mce: remove ASSERT's about mce_[u|d]handler_num in mce_action()

In reply to Haozhong Zhang

Those assertions as well as mce_[u|d]handlers[], mce_[u|d]handler_num and mce_action() were intel only and lifted to the common code by c/s 3a91769d6e1. However, MCE handling on AMD does not use mce_[u|d]handlers[] before and after that commit, so assertions in mce_action() about their size do not make sense for AMD. To be worse, they can crash the debug build on AMD. Remove them to make the debug build work on AMD.

---
Cc: Christoph Egger <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

Changes in v3:
* Explain the reason in the commit message.

Because other patches in v2 have got R-b or A-b, I only send v3 patch 6.

---
 xen/arch/x86/cpu/mcheck/mce.c | 4 ----
 1 file changed, 4 deletions(-)
xen/arch/x86/cpu/mcheck/mce.c +0 -4
index 35117f8..cd4f0ee 100644
@@ -1616,9 +1616,6 @@ static enum mce_result mce_action(const struct cpu_user_regs *regs,
         handlers = mce_uhandlers;
     }
 
-    /* At least a default handler should be registerd */
-    ASSERT(handler_num);
-
     local_mi = (struct mc_info*)mctelem_dataptr(mctc);
     x86_mcinfo_lookup(mic, local_mi, MC_TYPE_GLOBAL);
     if (mic == NULL) {
@@ -1651,7 +1648,6 @@ static enum mce_result mce_action(const struct cpu_user_regs *regs,
                 break;
             }
         }
-        ASSERT(i != handler_num);
     }
 
     return worst_result;
Signature · 7 lines
2.10.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v3 6/7
#10 lore raw

Re: [PATCH v3 6/7] xen/mce: remove ASSERT's about mce_[u|d]handler_num in mce_action()

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 08.03.17 at 02:58, <[email protected]> wrote:

Those assertions as well as mce_[u|d]handlers[], mce_[u|d]handler_num and mce_action() were intel only and lifted to the common code by c/s 3a91769d6e1. However, MCE handling on AMD does not use mce_[u|d]handlers[] before and after that commit, so assertions in mce_action() about their size do not make sense for AMD. To be worse, they can crash the debug build on AMD. Remove them to make the debug build work on AMD.

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

#11 lore raw

PATCH v2 7/7 tools/xen-mceinj: fix the type of cpu number

In reply to Haozhong Zhang

Use "unsigned int" rather than "int" to align to the type "uint32_t" of xen_mc_physcpuinfo.ncpus.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

---
 tools/tests/mce-test/tools/xen-mceinj.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
tools/tests/mce-test/tools/xen-mceinj.c +7 -5
index 51abc8a..bae5a46 100644
@@ -161,7 +161,7 @@ static int flush_msr_inj(xc_interface *xc_handle)
     return xc_mca_op(xc_handle, &mc);
 }
 
-static int mca_cpuinfo(xc_interface *xc_handle)
+static unsigned int mca_cpuinfo(xc_interface *xc_handle)
 {
     struct xen_mc mc;
 
@@ -176,16 +176,18 @@ static int mca_cpuinfo(xc_interface *xc_handle)
         return 0;
 }
 
-static int inject_cmci(xc_interface *xc_handle, int cpu_nr)
+static int inject_cmci(xc_interface *xc_handle, unsigned int cpu_nr)
 {
     struct xen_mc mc;
-    int nr_cpus;
+    unsigned int nr_cpus;
 
     memset(&mc, 0, sizeof(struct xen_mc));
 
     nr_cpus = mca_cpuinfo(xc_handle);
     if (!nr_cpus)
         err(xc_handle, "Failed to get mca_cpuinfo");
+    if (cpu_nr >= nr_cpus)
+        err(xc_handle, "-c %u is larger than %u", cpu_nr, nr_cpus - 1);
 
     mc.cmd = XEN_MC_inject_v2;
     mc.interface_version = XEN_MCA_INTERFACE_VERSION;
@@ -420,7 +422,7 @@ int main(int argc, char *argv[])
     int c, opt_index;
     uint32_t domid;
     xc_interface *xc_handle;
-    int cpu_nr;
+    unsigned int cpu_nr;
     uint64_t gaddr, max_gpa;
 
     /* Default Value */
@@ -444,7 +446,7 @@ int main(int argc, char *argv[])
             dump=1;
             break;
         case 'c':
-            cpu_nr = strtol(optarg, &optarg, 10);
+            cpu_nr = strtoul(optarg, &optarg, 10);
             if ( strlen(optarg) != 0 )
                 err(xc_handle, "Please input a digit parameter for CPU");
             break;
Signature · 7 lines
2.10.1


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