From patchwork Wed Jul 12 02:04:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9835801 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 A2354602BD for ; Wed, 12 Jul 2017 02:07:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7423A283BB for ; Wed, 12 Jul 2017 02:07:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 671452845C; Wed, 12 Jul 2017 02:07:11 +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 03F2C283BB for ; Wed, 12 Jul 2017 02:07:11 +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 1dV71V-0004Qb-N0; Wed, 12 Jul 2017 02:05:05 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dV71U-0004LD-1b for xen-devel@lists.xen.org; Wed, 12 Jul 2017 02:05:04 +0000 Received: from [193.109.254.147] by server-4.bemta-6.messagelabs.com id 22/09-02962-FC385695; Wed, 12 Jul 2017 02:05:03 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpgkeJIrShJLcpLzFFi42Jpa+uQ0D3fnBp pcHIJn8WSj4tZHBg9ju7+zRTAGMWamZeUX5HAmnF292m2gibFis0/9rE3ME6R6GLk4hASmM4o ceb4bMYuRk4OCQFeiSPLZrB2MXIA2f4Su2/HQNT0Mkp0dmxhA6lhE9CXWPH4ICuILSIgLXHt8 2WwXmaBcokn8/rA4sIC7hLLP14Bs1kEVCWuTp7PDGLzClhLrLq0nwlil7zErraLYDWcAjYS/0 +vArOFgGoWXO9gnsDIu4CRYRWjRnFqUVlqka6hgV5SUWZ6RkluYmYOkGeml5taXJyYnpqTmFS sl5yfu4kRGA4MQLCD8d6ygEOMkhxMSqK8O/JTI4X4kvJTKjMSizPii0pzUosPMcpwcChJ8Ho0 AeUEi1LTUyvSMnOAgQmTluDgURLh9Y4GSvMWFyTmFmemQ6ROMRpzbFi9/gsTx6sJ/78xCbHk5 eelSonzuoFMEgApzSjNgxsEi5hLjLJSwryMQKcJ8RSkFuVmlqDKv2IU52BUEuYNAJnCk5lXAr fvFdApTECnrMlOATmlJBEhJdXAOCtnZ1F6G2PhnYSN+henpuflydpPPL1Ob/LVuau32P79xR4 7N8/poOZUizc1K3ddfrowloPF5UzvYQ/OWv2Z+tzP2BVf/ls7L92l3WFy6oS2j8t8t990f/hJ ZrLdYsWVMftnnX8ZendlgzlT1Pkp2wP0rLucy8UWPV4U6PlY8+SkXq310kVzJiqxFGckGmoxF xUnAgBi8t8ckwIAAA== X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-15.tower-27.messagelabs.com!1499825100!53842236!1 X-Originating-IP: [134.134.136.24] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjQgPT4gMzkwOTcx\n X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 45474 invoked from network); 12 Jul 2017 02:05:02 -0000 Received: from mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by server-15.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 12 Jul 2017 02:05:02 -0000 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Jul 2017 19:05:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,347,1496127600"; d="scan'208";a="877806815" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by FMSMGA003.fm.intel.com with ESMTP; 11 Jul 2017 19:05:01 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Wed, 12 Jul 2017 10:04:40 +0800 Message-Id: <20170712020440.777-8-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170712020440.777-1-haozhong.zhang@intel.com> References: <20170712020440.777-1-haozhong.zhang@intel.com> Cc: Haozhong Zhang , Ian Jackson , Wei Liu Subject: [Xen-devel] [PATCH v9 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();