From patchwork Fri Mar 17 06:46:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9629907 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 6B57F60245 for ; Fri, 17 Mar 2017 06:49:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BBB22869B for ; Fri, 17 Mar 2017 06:49:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F2CA28698; Fri, 17 Mar 2017 06:49:02 +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 DF74D28698 for ; Fri, 17 Mar 2017 06:49:01 +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 1colf6-0000kd-9q; Fri, 17 Mar 2017 06:46:56 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1colf5-0000j1-5P for xen-devel@lists.xen.org; Fri, 17 Mar 2017 06:46:55 +0000 Received: from [85.158.137.68] by server-3.bemta-3.messagelabs.com id AB/AF-14551-E568BC85; Fri, 17 Mar 2017 06:46:54 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrBLMWRWlGSWpSXmKPExsVywNxEWze27XS EwYS1BhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8ac439ZC5YqVjzpvMnewLhKoouRg0NIoELi 2XXbLkZODgkBXokjy2awQtgBEk93T2fuYuQCKulllHi1vZURJMEmoC+x4vFBsCIRAWmJa58vg 8WZBcolnszrA4sLC3hKnHzdDWazCKhKvHpwAqyGV8BO4s+85YwQC+QlLlw9xQJicwLFPzbeAr OFBGwlGhtuM01g5F3AyLCKUb04tagstUjXVC+pKDM9oyQ3MTNH19DAWC83tbg4MT01JzGpWC8 5P3cTIzAU6hkYGHcwXv7qdIhRkoNJSZRXRfBEhBBfUn5KZUZicUZ8UWlOavEhRhkODiUJXvH5 QDnBotT01Iq0zBxgUMKkJTh4lER4bUHSvMUFibnFmekQqVOMuhxzZu9+wyTEkpeflyolznt1H lCRAEhRRmke3AhYhFxilJUS5mVkYGAQ4ilILcrNLEGVf8UozsGoJMzrDLKKJzOvBG7TK6AjmI COSPx5BOSIkkSElFQD47JVUUnV/1kutk9jUO/t3p/88LHte97pm5de38/z2aBYcmXJvGOqRwx u7LRgWP7k/73kApZ535TXr1QJCTggv+CP11XGn2kMcxmtgk9y9WdbTmTat/Wa+VoXqdos49cT ZP8f6nCv01ZumTv/k+eBoC2rdB+lNoR/kGx6mXK8dvmbSfrXRTLD5ZVYijMSDbWYi4oTAT8P7 qWLAgAA X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-11.tower-31.messagelabs.com!1489733199!59832828!7 X-Originating-IP: [192.55.52.43] 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 12977 invoked from network); 17 Mar 2017 06:46:53 -0000 Received: from mga05.intel.com (HELO mga05.intel.com) (192.55.52.43) by server-11.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 17 Mar 2017 06:46:53 -0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP; 16 Mar 2017 23:46:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.36,175,1486454400"; d="scan'208"; a="1109452688" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.153]) by orsmga001.jf.intel.com with ESMTP; 16 Mar 2017 23:46:51 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Fri, 17 Mar 2017 14:46:14 +0800 Message-Id: <20170317064614.23539-13-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170317064614.23539-1-haozhong.zhang@intel.com> References: <20170317064614.23539-1-haozhong.zhang@intel.com> Cc: Haozhong Zhang , Ian Jackson , Wei Liu Subject: [Xen-devel] [PATCH v2 12/12] tools/xen-mceinj: add support of 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 Acked-by: Wei Liu --- Cc: Ian Jackson Cc: Wei Liu Changes in v2: * Separate the xen-mceinj changes from v1 patch 19 to this one. --- tools/tests/mce-test/tools/xen-mceinj.c | 50 +++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/tools/tests/mce-test/tools/xen-mceinj.c b/tools/tests/mce-test/tools/xen-mceinj.c index bae5a46..380e421 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, ...) @@ -212,6 +215,35 @@ 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, unsigned int cpu) +{ + uint8_t *cpumap = NULL; + size_t cpumap_size, line, shift; + unsigned int nr_cpus; + int ret; + + nr_cpus = mca_cpuinfo(xc_handle); + if ( !nr_cpus ) + err(xc_handle, "Failed to get mca_cpuinfo"); + if ( cpu >= nr_cpus ) + err(xc_handle, "-c %u is larger than %u", cpu, nr_cpus - 1); + + 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 / 8; + shift = cpu % 8; + memset(cpumap + line, 1 << shift, 1); + + ret = xc_mca_op_inject_v2(xc_handle, XEN_MC_INJECT_TYPE_LMCE, + cpumap, cpumap_size * 8); + + free(cpumap); + return ret; +} + static uint64_t bank_addr(int bank, int type) { uint64_t addr; @@ -330,8 +362,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"); @@ -354,6 +393,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 ) @@ -393,6 +434,7 @@ static struct option opts[] = { {"dump", 0, 0, 'D'}, {"help", 0, 0, 'h'}, {"page", 0, 0, 'p'}, + {"lmce", 0, 0, 'l'}, {"", 0, 0, '\0'} }; @@ -409,6 +451,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++ ) @@ -438,7 +481,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 ) { @@ -463,6 +506,9 @@ int main(int argc, char *argv[]) case 't': type = strtol(optarg, NULL, 0); break; + case 'l': + lmce = 1; + break; case 'h': default: help();