From patchwork Fri May 27 13:30:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9138375 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 5DD4160467 for ; Fri, 27 May 2016 13:34:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E46827CB1 for ; Fri, 27 May 2016 13:34:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 42BF928159; Fri, 27 May 2016 13:34:26 +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 C4C3227CB1 for ; Fri, 27 May 2016 13:34:25 +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 1b6Hs8-0005SP-P2; Fri, 27 May 2016 13:32:16 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b6Hs7-0005SJ-Up for xen-devel@lists.xen.org; Fri, 27 May 2016 13:32:16 +0000 Received: from [85.158.137.68] by server-5.bemta-3.messagelabs.com id F9/B0-08326-F5C48475; Fri, 27 May 2016 13:32:15 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrCLMWRWlGSWpSXmKPExsXS1tYhohvn4xF usKXB0GLJx8UsDoweR3f/ZgpgjGLNzEvKr0hgzZgybzt7wUOZirbF3xgbGJtFuhg5OYQEKiVm Xt7GBmJLCPBKHFk2gxXC9pc49qYByOYCqulhlOhv+gqWYBPQl1jx+CCYLSIgLXHt82VGEJtZY D6TRPNjIRBbWMBLYvPzOywgNouAqsSPG81ANgcHr4CNxI4fxhDz5SQmL77EOIGRewEjwypG9e LUorLUIl0TvaSizPSMktzEzBxdQwNjvdzU4uLE9NScxKRiveT83E2MQN8yAMEOxsYvTocYJTm YlER5iz09woX4kvJTKjMSizPii0pzUosPMcpwcChJ8O70AsoJFqWmp1akZeYAgwwmLcHBoyTC exskzVtckJhbnJkOkTrFqCglzrsLJCEAksgozYNrgwX2JUZZKWFeRqBDhHgKUotyM0tQ5V8xi nMwKgnzbgeZwpOZVwI3/RXQYiagxQtYwBaXJCKkpBoYlxaZrTM6WGcw/aLZa+mKUyyTl0RO0G j0LfKVusdxhWGDqOziPI0wz0ztaS/FwiU2W4ft2/3urVBRSM4BnnMSHcLqL7ZGzGac1hDy7tQ s15dXN047q6E4+YWH46dKNoHWL3Pafm9ik5T5cOTqg/r5OQfty38Vv2AtDlo171ZoLM/ddfnP z9noKLEUZyQaajEXFScCAHdhF+xnAgAA X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-5.tower-31.messagelabs.com!1464355933!39330691!1 X-Originating-IP: [134.134.136.20] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjAgPT4gMzU1MzU4\n X-StarScan-Received: X-StarScan-Version: 8.34; banners=-,-,- X-VirusChecked: Checked Received: (qmail 7699 invoked from network); 27 May 2016 13:32:14 -0000 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by server-5.tower-31.messagelabs.com with SMTP; 27 May 2016 13:32:14 -0000 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP; 27 May 2016 06:32:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,374,1459839600"; d="scan'208";a="111580576" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.13.126]) by fmsmga004.fm.intel.com with ESMTP; 27 May 2016 06:32:10 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Fri, 27 May 2016 21:30:33 +0800 Message-Id: <20160527133033.7412-1-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.8.3 Cc: Haozhong Zhang , Wei Liu , pengtaox.zhang@intel.com, Liu Jinsong , Christoph Egger , xudong.hao@intel.com, Jan Beulich , Andrew Cooper Subject: [Xen-devel] [PATCH v3] x86/mce: handle reserved domain ID in XEN_MC_msrinject 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 Commit 26646f3 "x86/mce: translate passed-in GPA to host machine address" and commit 4ddf474 "tools/xen-mceinj: Pass in GPA when injecting through MSR_MCI_ADDR" forgot to consider reserved domain ID and mistakenly add MC_MSRINJ_F_GPADDR flag for them, which in turn causes bug reported by http://lists.xenproject.org/archives/html/xen-devel/2016-05/msg02640.html. This patch removes MC_MSRINK_F_GPADDR flag and checks this when injecting to reserved domain IDs except DOMID_SELF, and treats the passed-in address as host machine address. Signed-off-by: Haozhong Zhang Reviewed-by: Jan Beulich Acked-by: Christoph Egger --- Changes in v3: * Refine check condition of domid. Changes in v2: * Consider all reserved domain IDs rather than just DOMID_XEN. v1 can be found at http://lists.xenproject.org/archives/html/xen-devel/2016-05/msg02534.html. --- tools/tests/mce-test/tools/xen-mceinj.c | 5 ++++- xen/arch/x86/cpu/mcheck/mce.c | 14 +++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tools/tests/mce-test/tools/xen-mceinj.c b/tools/tests/mce-test/tools/xen-mceinj.c index 061ec7c..51abc8a 100644 --- a/tools/tests/mce-test/tools/xen-mceinj.c +++ b/tools/tests/mce-test/tools/xen-mceinj.c @@ -317,7 +317,10 @@ static int inject_mci_addr(xc_interface *xc_handle, domid_t domid) { return add_msr_bank_intpose(xc_handle, cpu_nr, - MC_MSRINJ_F_INTERPOSE | MC_MSRINJ_F_GPADDR, + MC_MSRINJ_F_INTERPOSE | + ((domid >= DOMID_FIRST_RESERVED && + domid != DOMID_SELF) ? + 0 : MC_MSRINJ_F_GPADDR), MCi_type_ADDR, bank, val, domid); } diff --git a/xen/arch/x86/cpu/mcheck/mce.c b/xen/arch/x86/cpu/mcheck/mce.c index cc446eb..0244553 100644 --- a/xen/arch/x86/cpu/mcheck/mce.c +++ b/xen/arch/x86/cpu/mcheck/mce.c @@ -1427,6 +1427,7 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc) if ( mc_msrinject->mcinj_flags & MC_MSRINJ_F_GPADDR ) { + domid_t domid; struct domain *d; struct mcinfo_msr *msr; unsigned int i; @@ -1434,10 +1435,17 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc) unsigned long gfn, mfn; p2m_type_t t; - d = get_domain_by_id(mc_msrinject->mcinj_domid); + domid = (mc_msrinject->mcinj_domid == DOMID_SELF) ? + current->domain->domain_id : mc_msrinject->mcinj_domid; + if ( domid >= DOMID_FIRST_RESERVED ) + return x86_mcerr("do_mca inject: incompatible flag " + "MC_MSRINJ_F_GPADDR with domain %d", + -EINVAL, domid); + + d = get_domain_by_id(domid); if ( d == NULL ) return x86_mcerr("do_mca inject: bad domain id %d", - -EINVAL, mc_msrinject->mcinj_domid); + -EINVAL, domid); for ( i = 0, msr = &mc_msrinject->mcinj_msr[0]; i < mc_msrinject->mcinj_count; @@ -1452,7 +1460,7 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc) put_gfn(d, gfn); put_domain(d); return x86_mcerr("do_mca inject: bad gfn %#lx of domain %d", - -EINVAL, gfn, mc_msrinject->mcinj_domid); + -EINVAL, gfn, domid); } msr->value = pfn_to_paddr(mfn) | (gaddr & (PAGE_SIZE - 1));