From patchwork Mon Jul 10 02:52:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9832221 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 342D860318 for ; Mon, 10 Jul 2017 02:55:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AB8826AE3 for ; Mon, 10 Jul 2017 02:55:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 092C7283DA; Mon, 10 Jul 2017 02:55:06 +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 4E6A826AE3 for ; Mon, 10 Jul 2017 02:55:05 +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 1dUOoT-0002rY-LT; Mon, 10 Jul 2017 02:52:41 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUOoS-0002rC-5S for xen-devel@lists.xen.org; Mon, 10 Jul 2017 02:52:40 +0000 Received: from [85.158.139.211] by server-12.bemta-5.messagelabs.com id FB/DC-01731-7FBE2695; Mon, 10 Jul 2017 02:52:39 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpkkeJIrShJLcpLzFFi42I5YG4Sq/vtdVK kweqNxhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bZ3afZCpoUKzb/2MfewDhFoouRi0NIYBqj xPJ/p9m6GDk5JAR4JY4sm8EKYftLLJv5kBmiqJdR4vaLo8wgCTYBfYkVjw+CFYkISEtc+3yZE cRmFiiXeDKvDywuLOAu8WPCRCYQm0VAVWLfy7NgC3gFbCVW9H1lhFggL7Gr7SJYPaeAncSZlx PAaoSAanY2bWKbwMi7gJFhFaNGcWpRWWqRrqGBXlJRZnpGSW5iZg6QZ6qXm1pcnJiempOYVKy XnJ+7iREYEAxAsINxzVTnQ4ySHExKorxivQmRQnxJ+SmVGYnFGfFFpTmpxYcYZTg4lCR4E18l RQoJFqWmp1akZeYAQxMmLcHBoyTCq3cSKM1bXJCYW5yZDpE6xWjMsWH1+i9MHK8m/P/GJMSSl 5+XKiXOKwEMeiEBkNKM0jy4QbCYucQoKyXMywh0mhBPQWpRbmYJqvwrRnEORiVh3uIXQFN4Mv NK4Pa9AjqFCegUtroEkFNKEhFSUg2Mmse675bnn9E7yS3iv4VjOstdpgsX2zelfDwVFaDbZ2W /tWll29sVWle5Mp6Zn91i3GO3M5X7xq2biYnLfyiezzwT7M51ueL98SUL62dGXDPyu7G2JX+t x0epo39yZ2r0K3tnPsjOkCuvmS/LqbfB1lFDcO/0V3vzAqr11p174x0WPvGh6rcCJZbijERDL eai4kQAKjDF85QCAAA= X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-12.tower-206.messagelabs.com!1499655147!65819316!7 X-Originating-IP: [192.55.52.93] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTkyLjU1LjUyLjkzID0+IDMyNDY2NQ==\n X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9016 invoked from network); 10 Jul 2017 02:52:38 -0000 Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by server-12.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 10 Jul 2017 02:52:38 -0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jul 2017 19:52:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,337,1496127600"; d="scan'208";a="109361579" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by orsmga002.jf.intel.com with ESMTP; 09 Jul 2017 19:52:36 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Mon, 10 Jul 2017 10:52:15 +0800 Message-Id: <20170710025215.22143-8-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170710025215.22143-1-haozhong.zhang@intel.com> References: <20170710025215.22143-1-haozhong.zhang@intel.com> Cc: Haozhong Zhang , Ian Jackson , Wei Liu Subject: [Xen-devel] [PATCH v8 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();