From patchwork Mon Jun 26 09:16:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9808919 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 072E960209 for ; Mon, 26 Jun 2017 09:19:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DCDD2847C for ; Mon, 26 Jun 2017 09:19:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02DDA2847D; Mon, 26 Jun 2017 09:19:45 +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 8F28128161 for ; Mon, 26 Jun 2017 09:19:45 +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 1dPQ8t-0002pn-1x; Mon, 26 Jun 2017 09:17:11 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPQ8s-0002or-3G for xen-devel@lists.xen.org; Mon, 26 Jun 2017 09:17:10 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id 9C/23-03058-511D0595; Mon, 26 Jun 2017 09:17:09 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJLMWRWlGSWpSXmKPExsVywNwkVlfkYkC kwdt7BhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bZ3afZCpoUKzb/2MfewDhFoouRk0NIYBqj xO1lRiC2hACvxJFlM1ghbH+JvpUv2LsYuYBqehklPk/fxQaSYBPQl1jx+CBYkYiAtMS1z5cZQ WxmgXKJJ/P6wOLCAp4Sr97OBIpzcLAIqEpMeScMEuYVsJP4/aoDar68xK62i2A2J1D8xd8D7B D32EpM+LWCcQIj7wJGhlWMGsWpRWWpRbqGFnpJRZnpGSW5iZk5uoYGZnq5qcXFiempOYlJxXr J+bmbGIHBwAAEOxhvbgw4xCjJwaQkytvo7x8pxJeUn1KZkVicEV9UmpNafIhRhoNDSYL33PmA SCHBotT01Iq0zBxgWMKkJTh4lER4L5wFSvMWFyTmFmemQ6ROMepybFi9/guTEEtefl6qlDjvL JAZAiBFGaV5cCNgMXKJUVZKmJcR6CghnoLUotzMElT5V4ziHIxKwrztIFN4MvNK4Da9AjqCCe gIlnlgR5QkIqSkGhg5RdZtu3LV+cdfBUOmW4y5Macm//meLbRJbqk+r9Pzjb8b9/ZfdxJhafl 58cZxS34H2/dC1lf3P5BZdn2+wMQ3Hb5ewrNePjj4Pmwuc9o8lR2Bf6Y3OsQuuZHhNCOHfe06 BpEGnhdHb2soO6dPenf/0MXVtpWHVkR/qXig2zml9jyX+Nud1oWsSizFGYmGWsxFxYkAem9io 4wCAAA= X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-9.tower-21.messagelabs.com!1498468609!75505562!11 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.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3028 invoked from network); 26 Jun 2017 09:17:08 -0000 Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by server-9.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 26 Jun 2017 09:17:08 -0000 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jun 2017 02:17:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,395,1493708400"; d="scan'208";a="985230055" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by orsmga003.jf.intel.com with ESMTP; 26 Jun 2017 02:17:06 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Mon, 26 Jun 2017 17:16:25 +0800 Message-Id: <20170626091625.19655-12-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170626091625.19655-1-haozhong.zhang@intel.com> References: <20170626091625.19655-1-haozhong.zhang@intel.com> Cc: Haozhong Zhang , Ian Jackson , Wei Liu Subject: [Xen-devel] [PATCH v4 11/11] 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();