xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Haozhong Zhang <haozhong.zhang@intel.com>
To: xen-devel@lists.xen.org
Cc: Haozhong Zhang <haozhong.zhang@intel.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	Wei Liu <wei.liu2@citrix.com>
Subject: [PATCH 19/19] tools/xen-mceinj: support injecting LMCE
Date: Fri, 17 Feb 2017 14:39:36 +0800	[thread overview]
Message-ID: <20170217063936.13208-20-haozhong.zhang@intel.com> (raw)
In-Reply-To: <20170217063936.13208-1-haozhong.zhang@intel.com>

If option '-l' or '--lmce' is specified and the host supports LMCE,
xen-mceinj will inject LMCE to CPU specified by '-c' (or CPU0 if '-c'
is not present).

Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
---
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
---
 tools/libxc/include/xenctrl.h           |  1 +
 tools/libxc/xc_misc.c                   | 25 +++++++++++++++
 tools/tests/mce-test/tools/xen-mceinj.c | 57 +++++++++++++++++++++++++++++++--
 3 files changed, 81 insertions(+), 2 deletions(-)

diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index 85d7fe5..2598952 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -1968,6 +1968,7 @@ int xc_cpuid_apply_policy(xc_interface *xch,
 void xc_cpuid_to_str(const unsigned int *regs,
                      char **strs); /* some strs[] may be NULL if ENOMEM */
 int xc_mca_op(xc_interface *xch, struct xen_mc *mc);
+int xc_mca_op_cpumap(xc_interface *xch, struct xen_mc *mc, xc_cpumap_t cpumap);
 #endif
 
 struct xc_px_val {
diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c
index 0fc6c22..24f7fdf 100644
--- a/tools/libxc/xc_misc.c
+++ b/tools/libxc/xc_misc.c
@@ -341,6 +341,31 @@ int xc_mca_op(xc_interface *xch, struct xen_mc *mc)
     xc_hypercall_bounce_post(xch, mc);
     return ret;
 }
+
+int xc_mca_op_cpumap(xc_interface *xch, struct xen_mc *mc, xc_cpumap_t cpumap)
+{
+    int ret;
+    DECLARE_HYPERCALL_BOUNCE(cpumap, 0, XC_HYPERCALL_BUFFER_BOUNCE_IN);
+
+    if ( cpumap )
+    {
+        HYPERCALL_BOUNCE_SET_SIZE(cpumap,
+                                  (mc->u.mc_inject_v2.cpumap.nr_bits + 7) / 8);
+        if ( xc_hypercall_bounce_pre(xch, cpumap) )
+        {
+            PERROR("Could not bouce cpumap memory buffer");
+            return -1;
+        }
+        set_xen_guest_handle(mc->u.mc_inject_v2.cpumap.bitmap, cpumap);
+    }
+
+    ret = xc_mca_op(xch, mc);
+
+    if ( cpumap )
+        xc_hypercall_bounce_post(xch, cpumap);
+
+    return ret;
+}
 #endif
 
 int xc_perfc_reset(xc_interface *xch)
diff --git a/tools/tests/mce-test/tools/xen-mceinj.c b/tools/tests/mce-test/tools/xen-mceinj.c
index 5f70a61..b2eb7d3 100644
--- a/tools/tests/mce-test/tools/xen-mceinj.c
+++ b/tools/tests/mce-test/tools/xen-mceinj.c
@@ -56,6 +56,8 @@
 #define MSR_IA32_MC0_MISC        0x00000403
 #define MSR_IA32_MC0_CTL2        0x00000280
 
+#define MCG_STATUS_LMCE          0x8
+
 struct mce_info {
     const char *description;
     uint8_t mcg_stat;
@@ -113,6 +115,7 @@ static struct mce_info mce_table[] = {
 #define LOGFILE stdout
 
 int dump;
+int lmce;
 struct xen_mc_msrinject msr_inj;
 
 static void Lprintf(const char *fmt, ...)
@@ -213,6 +216,42 @@ static int inject_mce(xc_interface *xc_handle, int cpu_nr)
     return xc_mca_op(xc_handle, &mc);
 }
 
+static int inject_lmce(xc_interface *xc_handle, uint32_t cpu_nr)
+{
+    struct xen_mc mc;
+    uint8_t *cpumap = NULL;
+    size_t cpumap_size, line, shift;
+    uint32_t nr_cpus;
+    int ret;
+
+    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 %"PRIu32" is larger than %"PRIu32,
+            cpu_nr, nr_cpus - 1);
+
+    memset(&mc, 0, sizeof(struct xen_mc));
+    mc.cmd = XEN_MC_inject_v2;
+    mc.interface_version = XEN_MCA_INTERFACE_VERSION;
+    mc.u.mc_inject_v2.flags |= XEN_MC_INJECT_TYPE_LMCE;
+
+    cpumap_size = (nr_cpus + 7) / 8;
+    cpumap = malloc(cpumap_size);
+    if ( !cpumap )
+        err(xc_handle, "Failed to allocate cpumap\n");
+    memset(cpumap, 0, cpumap_size);
+    line = cpu_nr / 8;
+    shift = cpu_nr % 8;
+    memset(cpumap + line, 1 << shift, 1);
+
+    mc.u.mc_inject_v2.cpumap.nr_bits = cpumap_size * 8;
+    ret = xc_mca_op_cpumap(xc_handle, &mc, cpumap);
+
+    free(cpumap);
+    return ret;
+}
+
 static uint64_t bank_addr(int bank, int type)
 {
     uint64_t addr;
@@ -331,8 +370,15 @@ static int inject(xc_interface *xc_handle, struct mce_info *mce,
                   uint32_t cpu_nr, uint32_t domain, uint64_t gaddr)
 {
     int ret = 0;
+    uint8_t mcg_status = mce->mcg_stat;
 
-    ret = inject_mcg_status(xc_handle, cpu_nr, mce->mcg_stat, domain);
+    if ( lmce )
+    {
+        if ( mce->cmci )
+            err(xc_handle, "No support to inject CMCI as LMCE");
+        mcg_status |= MCG_STATUS_LMCE;
+    }
+    ret = inject_mcg_status(xc_handle, cpu_nr, mcg_status, domain);
     if ( ret )
         err(xc_handle, "Failed to inject MCG_STATUS MSR");
 
@@ -355,6 +401,8 @@ static int inject(xc_interface *xc_handle, struct mce_info *mce,
         err(xc_handle, "Failed to inject MSR");
     if ( mce->cmci )
         ret = inject_cmci(xc_handle, cpu_nr);
+    else if ( lmce )
+        ret = inject_lmce(xc_handle, cpu_nr);
     else
         ret = inject_mce(xc_handle, cpu_nr);
     if ( ret )
@@ -394,6 +442,7 @@ static struct option opts[] = {
     {"dump", 0, 0, 'D'},
     {"help", 0, 0, 'h'},
     {"page", 0, 0, 'p'},
+    {"lmce", 0, 0, 'l'},
     {"", 0, 0, '\0'}
 };
 
@@ -410,6 +459,7 @@ static void help(void)
            "  -d, --domain=DOMID   target domain, the default is Xen itself\n"
            "  -h, --help           print this page\n"
            "  -p, --page=ADDR      physical address to report\n"
+           "  -l, --lmce           inject as LMCE (Intel only)\n"
            "  -t, --type=ERROR     error type\n");
 
     for ( i = 0; i < MCE_TABLE_SIZE; i++ )
@@ -439,7 +489,7 @@ int main(int argc, char *argv[])
     }
 
     while ( 1 ) {
-        c = getopt_long(argc, argv, "c:Dd:t:hp:", opts, &opt_index);
+        c = getopt_long(argc, argv, "c:Dd:t:hp:l", opts, &opt_index);
         if ( c == -1 )
             break;
         switch ( c ) {
@@ -464,6 +514,9 @@ int main(int argc, char *argv[])
         case 't':
             type = strtol(optarg, NULL, 0);
             break;
+        case 'l':
+            lmce = 1;
+            break;
         case 'h':
         default:
             help();
-- 
2.10.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2017-02-17  6:39 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-17  6:39 [PATCH 00/19] MCE code cleanup and add LMCE support Haozhong Zhang
2017-02-17  6:39 ` [PATCH 01/19] x86/mce: fix indentation style in xen-mca.h and mce.h Haozhong Zhang
2017-02-17  9:49   ` Jan Beulich
2017-02-17  6:39 ` [PATCH 02/19] x86/mce: remove declarations of non-existing functions in mce.h Haozhong Zhang
2017-02-17  9:50   ` Jan Beulich
2017-02-17  6:39 ` [PATCH 03/19] x86/mce: remove unnecessary braces around intel_get_extended_msrs() Haozhong Zhang
2017-02-17  9:51   ` Jan Beulich
2017-02-17  6:39 ` [PATCH 04/19] xen/mce: remove unused x86_mcinfo_add() Haozhong Zhang
2017-02-17  9:55   ` Jan Beulich
2017-02-20  1:52     ` Haozhong Zhang
2017-02-20  9:00       ` Jan Beulich
2017-02-20  9:10         ` Haozhong Zhang
2017-02-17  6:39 ` [PATCH 05/19] x86/mce: merge loops to get Intel extended MC MSR Haozhong Zhang
2017-02-17  9:58   ` Jan Beulich
2017-02-20  1:11     ` Haozhong Zhang
2017-02-17  6:39 ` [PATCH 06/19] x86/mce: merge intel_default_mce_dhandler/uhandler() Haozhong Zhang
2017-02-17 10:01   ` Jan Beulich
2017-02-20  2:40     ` Haozhong Zhang
2017-02-17  6:39 ` [PATCH 07/19] x86/vmce: include domain/vcpu id in debug messages Haozhong Zhang
2017-02-17 10:03   ` Jan Beulich
2017-02-17  6:39 ` [PATCH 08/19] x86/mce: set mcinfo_comm.type and .size in x86_mcinfo_reserve() Haozhong Zhang
2017-02-17 10:07   ` Jan Beulich
2017-02-20  2:48     ` Haozhong Zhang
2017-02-20  9:02       ` Jan Beulich
2017-02-20  9:11         ` Haozhong Zhang
2017-02-17  6:39 ` [PATCH 09/19] x86/vmce: fill MSR_IA32_MCG_STATUS on all vcpus in broadcast case Haozhong Zhang
2017-02-17 10:21   ` Jan Beulich
2017-02-20  4:36     ` Haozhong Zhang
2017-02-20  9:04       ` Jan Beulich
2017-02-20  9:12         ` Haozhong Zhang
2017-02-17  6:39 ` [PATCH 10/19] x86/mce: always write 0 to MSR_IA32_MCG_STATUS on Intel CPU Haozhong Zhang
2017-02-17 10:26   ` Jan Beulich
2017-02-17 15:01     ` Boris Ostrovsky
2017-02-17 15:13       ` Jan Beulich
2017-02-17 15:38         ` Boris Ostrovsky
2017-02-17  6:39 ` [PATCH 11/19] tools/xen-mceinj: fix the type of cpu number Haozhong Zhang
2017-02-17 10:08   ` Jan Beulich
2017-02-20  2:49     ` Haozhong Zhang
2017-02-20 12:29     ` Wei Liu
2017-02-17  6:39 ` [PATCH 12/19] x86/mce: handle LMCE locally Haozhong Zhang
2017-02-22 13:53   ` Jan Beulich
2017-02-23  3:06     ` Haozhong Zhang
2017-02-23  7:42       ` Jan Beulich
2017-02-23  8:38         ` Haozhong Zhang
2017-02-17  6:39 ` [PATCH 13/19] x86/mce_intel: detect and enable LMCE on Intel host Haozhong Zhang
2017-02-22 15:10   ` Jan Beulich
2017-02-23  3:16     ` Haozhong Zhang
2017-02-23  7:45       ` Jan Beulich
2017-02-17  6:39 ` [PATCH 14/19] x86/vmx: expose LMCE feature via guest MSR_IA32_FEATURE_CONTROL Haozhong Zhang
2017-02-22 15:20   ` Jan Beulich
2017-02-23  4:10     ` Haozhong Zhang
2017-02-17  6:39 ` [PATCH 15/19] x86/vmce: emulate MSR_IA32_MCG_EXT_CTL Haozhong Zhang
2017-02-22 15:36   ` Jan Beulich
2017-02-23  4:26     ` Haozhong Zhang
2017-02-23  7:53       ` Jan Beulich
2017-02-23  8:54         ` Haozhong Zhang
2017-02-23  9:04           ` Jan Beulich
2017-02-17  6:39 ` [PATCH 16/19] x86/vmce: enable injecting LMCE to guest on Intel host Haozhong Zhang
2017-02-22 15:48   ` Jan Beulich
2017-02-23  4:48     ` Haozhong Zhang
2017-02-23  8:21       ` Jan Beulich
2017-02-17  6:39 ` [PATCH 17/19] x86/vmce, tools/libxl: expose LMCE capability in guest MSR_IA32_MCG_CAP Haozhong Zhang
2017-02-20 12:32   ` Wei Liu
2017-02-20 12:38     ` Jan Beulich
2017-02-20 14:12       ` Wei Liu
2017-02-20 23:55     ` Haozhong Zhang
2017-02-22 15:55   ` Jan Beulich
2017-02-23  5:07     ` Haozhong Zhang
2017-02-17  6:39 ` [PATCH 18/19] xen/mce: add support of vLMCE injection to XEN_MC_inject_v2 Haozhong Zhang
2017-02-22 15:59   ` Jan Beulich
2017-02-23  5:14     ` Haozhong Zhang
2017-02-23  8:26       ` Jan Beulich
2017-02-23  9:14         ` Haozhong Zhang
2017-02-23  9:22           ` Jan Beulich
2017-02-17  6:39 ` Haozhong Zhang [this message]
2017-02-20 12:53   ` [PATCH 19/19] tools/xen-mceinj: support injecting LMCE Wei Liu
2017-02-20 23:50     ` Haozhong Zhang
2017-02-21  9:18       ` Wei Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170217063936.13208-20-haozhong.zhang@intel.com \
    --to=haozhong.zhang@intel.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).