From patchwork Fri Jul 7 03:53: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: 9829537 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 823A0602CA for ; Fri, 7 Jul 2017 03:56:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B14E25F3E for ; Fri, 7 Jul 2017 03:56:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5FEB6283DA; Fri, 7 Jul 2017 03:56:40 +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 F2F6C25F3E for ; Fri, 7 Jul 2017 03:56:39 +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 1dTKL6-0002H3-47; Fri, 07 Jul 2017 03:53: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 1dTKL5-0002FH-1W for xen-devel@lists.xen.org; Fri, 07 Jul 2017 03:53:55 +0000 Received: from [85.158.137.68] by server-13.bemta-3.messagelabs.com id AA/1D-01862-2D50F595; Fri, 07 Jul 2017 03:53:54 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpgkeJIrShJLcpLzFFi42I5YG5SoXuRNT7 S4OJUTYslHxezODB6HN39mymAMYo1My8pvyKBNePs7tNsBU2KFZt/7GNvYJwi0cXIxSEkMJ1R YtWt5yxdjJwcEgK8EkeWzWCFsP0lek7vZ4Qo6mWUmPxiBTNIgk1AX2LF44NgRSIC0hLXPl9mB LGZBcolnszrA4sLC7hLzF67kwnEZhFQlbjd0g9WwytgK9F8upUdYoG8xK62i2D1nAJ2Eu0Xt4 LNFwKqebBqLcsERt4FjAyrGNWLU4vKUot0jfSSijLTM0pyEzNzdA0NjPVyU4uLE9NTcxKTivW S83M3MQLDoZ6BgXEH46lm50OMkhxMSqK8Z27GRQrxJeWnVGYkFmfEF5XmpBYfYpTh4FCS4F3L Eh8pJFiUmp5akZaZAwxMmLQEB4+SCO8+kFbe4oLE3OLMdIjUKUZjjg2r139h4ng14f83JiGWv Py8VClx3lUgkwRASjNK8+AGwSLmEqOslDAvIwMDgxBPQWpRbmYJqvwrRnEORiVh3m0gU3gy80 rg9r0COoUJ6BTFxhiQU0oSEVJSDYyzfY94cQfaTT2vx/din9/uTQfnbGXauqHkstynLWvbik4 eXOvS3npB/8X/krQTzf91Xjo/kFFfnn/24nTrOxuvuJlJ5yodKjE7lbYw/UPWhki9a3c8SufN UUzMrFzuzaQd3Gfly7qhvW5i097AQx4dER25CVpJ3nvn7gyMOfqesWSCguncVaeVWIozEg21m IuKEwFSy5/5kwIAAA== X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-14.tower-31.messagelabs.com!1499399618!104177186!7 X-Originating-IP: [192.55.52.120] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 55274 invoked from network); 7 Jul 2017 03:53:53 -0000 Received: from mga04.intel.com (HELO mga04.intel.com) (192.55.52.120) by server-14.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 7 Jul 2017 03:53:53 -0000 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jul 2017 20:53:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,320,1496127600"; d="scan'208";a="123632557" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga005.fm.intel.com with ESMTP; 06 Jul 2017 20:53:51 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Fri, 7 Jul 2017 11:53:14 +0800 Message-Id: <20170707035314.15659-8-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170707035314.15659-1-haozhong.zhang@intel.com> References: <20170707035314.15659-1-haozhong.zhang@intel.com> Cc: Haozhong Zhang , Ian Jackson , Wei Liu Subject: [Xen-devel] [PATCH v7 7/7] 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 --- 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 bae5a46eb5..380e42190c 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();