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, Ian Campbell <ian.campbell@citrix.com>,
	Wei Liu <wei.liu2@citrix.com>,
	Christoph Egger <chegger@amazon.de>,
	Jan Beulich <jbeulich@suse.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Liu Jinsong <jinsong.liu@alibaba-inc.com>,
	Keir Fraser <keir@xen.org>,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	Haozhong Zhang <haozhong.zhang@intel.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH v2 3/4] x86/mce: Translate passed-in GPA to host machine address
Date: Wed, 16 Sep 2015 13:35:14 +0800	[thread overview]
Message-ID: <1442381715-30893-4-git-send-email-haozhong.zhang@intel.com> (raw)
In-Reply-To: <1442381715-30893-1-git-send-email-haozhong.zhang@intel.com>

This patch adds a new flag MC_MSRINJ_F_GPADDR to
xen_mc_msrinject.mcinj_flags, and makes do_mca() to translate the
guest physical address passed-in through
xen_mc_msrinject.mcinj_msr[i].value to the host machine address if
this flag is present.

Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
---
 xen/arch/x86/cpu/mcheck/mce.c         | 56 ++++++++++++++++++++++++++++++-----
 xen/include/public/arch-x86/xen-mca.h |  5 +++-
 2 files changed, 52 insertions(+), 9 deletions(-)

diff --git a/xen/arch/x86/cpu/mcheck/mce.c b/xen/arch/x86/cpu/mcheck/mce.c
index 561257d..08cd3f2 100644
--- a/xen/arch/x86/cpu/mcheck/mce.c
+++ b/xen/arch/x86/cpu/mcheck/mce.c
@@ -21,6 +21,7 @@
 #include <asm/processor.h>
 #include <asm/system.h>
 #include <asm/msr.h>
+#include <asm/p2m.h>
 
 #include "mce.h"
 #include "barrier.h"
@@ -48,14 +49,15 @@ struct mca_banks *mca_allbanks;
 #define _MC_MSRINJ_F_REQ_HWCR_WREN (1 << 16)
 
 #if 0
-static int x86_mcerr(const char *msg, int err)
-{
-    gdprintk(XENLOG_WARNING, "x86_mcerr: %s, returning %d\n",
-             msg != NULL ? msg : "", err);
-    return err;
-}
+#define x86_mcerr(fmt, err, args...)                                    \
+    ({                                                                  \
+        int _err = (err);                                               \
+        gdprintk(XENLOG_WARNING, "x86_mcerr: " fmt ", returning %d\n",  \
+                 ## args, _err);                                        \
+        _err;                                                           \
+    })
 #else
-#define x86_mcerr(msg, err) (err)
+#define x86_mcerr(fmt, err, args...) (err)
 #endif
 
 int mce_verbosity;
@@ -1307,7 +1309,7 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
 
     ret = xsm_do_mca(XSM_PRIV);
     if ( ret )
-        return x86_mcerr(NULL, ret);
+        return x86_mcerr("", ret);
 
     if ( copy_from_guest(op, u_xen_mc, 1) )
         return x86_mcerr("do_mca: failed copyin of xen_mc_t", -EFAULT);
@@ -1422,6 +1424,44 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
         if (mc_msrinject->mcinj_count == 0)
             return 0;
 
+        if ( mc_msrinject->mcinj_flags & MC_MSRINJ_F_GPADDR )
+        {
+            struct domain *d;
+            struct mcinfo_msr *msr;
+            unsigned int i;
+            paddr_t gaddr;
+            unsigned long gfn, mfn;
+            p2m_type_t t;
+
+            d = get_domain_by_id(mc_msrinject->mcinj_domid);
+            if ( d == NULL )
+                return x86_mcerr("do_mca inject: bad domain id %d",
+                                 -EINVAL, mc_msrinject->mcinj_domid);
+
+            for ( i = 0, msr = &mc_msrinject->mcinj_msr[0];
+                  i < mc_msrinject->mcinj_count;
+                  i++, msr++ )
+            {
+                gaddr = msr->value;
+                gfn = PFN_DOWN(gaddr);
+                mfn = mfn_x(get_gfn(d, gfn, &t));
+
+                if ( mfn == INVALID_MFN )
+                {
+                    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);
+                }
+
+                msr->value = pfn_to_paddr(mfn) | (gaddr & (PAGE_SIZE - 1));
+
+                put_gfn(d, gfn);
+            }
+
+            put_domain(d);
+        }
+
         if (!x86_mc_msrinject_verify(mc_msrinject))
             return x86_mcerr("do_mca inject: illegal MSR", -EINVAL);
 
diff --git a/xen/include/public/arch-x86/xen-mca.h b/xen/include/public/arch-x86/xen-mca.h
index ec1237a..a97e821 100644
--- a/xen/include/public/arch-x86/xen-mca.h
+++ b/xen/include/public/arch-x86/xen-mca.h
@@ -392,12 +392,15 @@ struct xen_mc_msrinject {
     uint32_t mcinj_cpunr;           /* target processor id */
     uint32_t mcinj_flags;           /* see MC_MSRINJ_F_* below */
     uint32_t mcinj_count;           /* 0 .. count-1 in array are valid */
-    uint32_t _pad0;
+    domid_t  mcinj_domid;           /* valid only if MC_MSRINJ_F_GPADDR is
+                                       present in mcinj_flags */
+    uint16_t _pad0;
     struct mcinfo_msr mcinj_msr[MC_MSRINJ_MAXMSRS];
 };
 
 /* Flags for mcinj_flags above; bits 16-31 are reserved */
 #define MC_MSRINJ_F_INTERPOSE   0x1
+#define MC_MSRINJ_F_GPADDR      0x2
 
 #define XEN_MC_mceinject    5
 struct xen_mc_mceinject {
-- 
2.4.8

  parent reply	other threads:[~2015-09-16  5:35 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-16  5:35 [PATCH v2 0/4] Fix tools/xen-mceinj to handle >=4GB guest memory Haozhong Zhang
2015-09-16  5:35 ` [PATCH v2 1/4] x86/mce: Fix code style Haozhong Zhang
2015-09-16  8:28   ` Egger, Christoph
2015-09-16  5:35 ` [PATCH v2 2/4] tools/xen-mceinj: " Haozhong Zhang
2015-09-16  7:45   ` Wei Liu
2015-09-16  7:52     ` Haozhong Zhang
2015-09-16  7:56       ` Wei Liu
2015-09-16  7:58       ` Wei Liu
2015-09-16  8:02         ` Haozhong Zhang
2015-09-16  8:42   ` Egger, Christoph
2015-09-16  5:35 ` Haozhong Zhang [this message]
2015-09-16  8:27   ` [PATCH v2 3/4] x86/mce: Translate passed-in GPA to host machine address Egger, Christoph
2015-09-16  5:35 ` [PATCH v2 4/4] tools/xen-mceinj: Pass in GPA when injecting through MSR_MCI_ADDR Haozhong Zhang
2015-09-16  8:18   ` Egger, Christoph
2015-09-16  9:42   ` Jan Beulich
2015-09-16 10:40   ` Wei Liu
2015-09-16 10:54 ` [PATCH v2 0/4] Fix tools/xen-mceinj to handle >=4GB guest memory Ian Jackson

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=1442381715-30893-4-git-send-email-haozhong.zhang@intel.com \
    --to=haozhong.zhang@intel.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=chegger@amazon.de \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=jinsong.liu@alibaba-inc.com \
    --cc=keir@xen.org \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /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).