From patchwork Fri Feb 17 06:39:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9578877 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9BF47600C5 for ; Fri, 17 Feb 2017 06:43:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CCEB2869B for ; Fri, 17 Feb 2017 06:43:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81B20286A4; Fri, 17 Feb 2017 06:43:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 148662869B for ; Fri, 17 Feb 2017 06:43:19 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cecEH-0002z9-JQ; Fri, 17 Feb 2017 06:41:17 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cecEG-0002x0-CZ for xen-devel@lists.xen.org; Fri, 17 Feb 2017 06:41:16 +0000 Received: from [193.109.254.147] by server-8.bemta-6.messagelabs.com id 81/FB-21675-B0B96A85; Fri, 17 Feb 2017 06:41:15 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrOLMWRWlGSWpSXmKPExsVywNykWJdj9rI Ig2nTLSyWfFzM4sDocXT3b6YAxijWzLyk/IoE1owZj7kKtulXbPm8gLmB8ZRyFyMXh5DANEaJ FX9usHcxcnJICPBKHFk2gxXC9pNYuu0nC4gtJNDLKDFhcTmIzSagL7Hi8UGwGhEBaYlrny8zg tjMAuUST+b1gcWFBewlrjW9ZgOxWQRUJZZtmsjcxcjBwStgJ3GzE2qVvMSFq6fAxnMChf88/M AOscpW4v2ne8wTGHkXMDKsYlQvTi0qSy3SNdFLKspMzyjJTczM0TU0MNPLTS0uTkxPzUlMKtZ Lzs/dxAgMBAYg2MHYfdn/EKMkB5OSKO+iacsihPiS8lMqMxKLM+KLSnNSiw8xynBwKEnwcs8C ygkWpaanVqRl5gBDEiYtwcGjJMLLAZLmLS5IzC3OTIdInWLU5Th14/RLJiGWvPy8VClx3hszg YoEQIoySvPgRsDi4xKjrJQwLyPQUUI8BalFuZklqPKvGMU5GJWEeS+ATOHJzCuB2/QK6AgmoC M6I5aCHFGSiJCSamCUkbJ4FLZmx3TN838UOMxvfy/+bl234pZG+W52ta9Lv8g/15N2MfZkKg3 rTcx/v+y6mLJD3f6G72ZBh3kO7w1W2XV1ib7Kwm+HdAzvTI8oulR4qFVpioPlE5EQllN/1E3U u/4eEIw1KN7ekJSW5HH/3NIrV82XHt+zqOvXI86Ky1npfF0n3X2UWIozEg21mIuKEwESrV4bi gIAAA== X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-15.tower-27.messagelabs.com!1487313633!34675007!19 X-Originating-IP: [192.55.52.115] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 34956 invoked from network); 17 Feb 2017 06:41:12 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by server-15.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 17 Feb 2017 06:41:12 -0000 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Feb 2017 22:41:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,171,1484035200"; d="scan'208";a="65781641" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.133]) by orsmga005.jf.intel.com with ESMTP; 16 Feb 2017 22:41:10 -0800 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Fri, 17 Feb 2017 14:39:36 +0800 Message-Id: <20170217063936.13208-20-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170217063936.13208-1-haozhong.zhang@intel.com> References: <20170217063936.13208-1-haozhong.zhang@intel.com> Cc: Haozhong Zhang , Ian Jackson , Wei Liu Subject: [Xen-devel] [PATCH 19/19] tools/xen-mceinj: support injecting LMCE X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- Cc: Ian Jackson Cc: Wei Liu --- 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();