xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Haozhong Zhang <haozhong.zhang@intel.com>
To: xen-devel@lists.xen.org
Cc: Haozhong Zhang <haozhong.zhang@intel.com>,
	Wei Liu <wei.liu2@citrix.com>,
	pengtaox.zhang@intel.com,
	Liu Jinsong <jinsong.liu@alibaba-inc.com>,
	Christoph Egger <chegger@amazon.de>,
	xudong.hao@intel.com, Jan Beulich <jbeulich@suse.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>
Subject: [PATCH v3] x86/mce: handle reserved domain ID in XEN_MC_msrinject
Date: Fri, 27 May 2016 21:30:33 +0800	[thread overview]
Message-ID: <20160527133033.7412-1-haozhong.zhang@intel.com> (raw)

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 <haozhong.zhang@intel.com>
---
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));
-- 
2.8.3


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

             reply	other threads:[~2016-05-27 13:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-27 13:30 Haozhong Zhang [this message]
2016-05-27 14:03 ` [PATCH v3] x86/mce: handle reserved domain ID in XEN_MC_msrinject Jan Beulich
2016-05-27 14:06   ` Wei Liu
2016-05-27 15:31     ` Wei Liu
2016-05-27 16:06       ` Jan Beulich
2016-05-27 16:14         ` Wei Liu
2016-05-27 16:16           ` Wei Liu
2016-06-01  6:38             ` Haozhong Zhang
2016-06-06 13:08               ` Wei Liu
2016-06-06 13:40 ` Egger, Christoph
2016-06-06 13:47   ` Wei Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160527133033.7412-1-haozhong.zhang@intel.com \
    --to=haozhong.zhang@intel.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=chegger@amazon.de \
    --cc=jbeulich@suse.com \
    --cc=jinsong.liu@alibaba-inc.com \
    --cc=pengtaox.zhang@intel.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    --cc=xudong.hao@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).