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>,
	Ian Campbell <ian.campbell@citrix.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
	Liu Jinsong <jinsong.liu@alibaba-inc.com>,
	Christoph Egger <chegger@amazon.de>,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	Jan Beulich <jbeulich@suse.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Keir Fraser <keir@xen.org>
Subject: [PATCH 4/4] tools/xen-mceinj: Pass in GPA when injecting through MSR_MCI_ADDR
Date: Tue, 15 Sep 2015 16:29:40 +0800	[thread overview]
Message-ID: <1442305780-12790-5-git-send-email-haozhong.zhang@intel.com> (raw)
In-Reply-To: <1442305780-12790-1-git-send-email-haozhong.zhang@intel.com>

This patch removes the address translation in xen-mceinj which
translates the guest physical address passed-in through the argument
of '-p' to the host machine address.

Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
---
 tools/tests/mce-test/tools/xen-mceinj.c | 135 +++++---------------------------
 1 file changed, 19 insertions(+), 116 deletions(-)

diff --git a/tools/tests/mce-test/tools/xen-mceinj.c b/tools/tests/mce-test/tools/xen-mceinj.c
index 0c2b640..7b9dd13 100644
--- a/tools/tests/mce-test/tools/xen-mceinj.c
+++ b/tools/tests/mce-test/tools/xen-mceinj.c
@@ -238,7 +238,8 @@ static int add_msr_intpose(xc_interface *xc_handle,
                            uint32_t cpu_nr,
                            uint32_t flags,
                            uint64_t msr,
-                           uint64_t val)
+                           uint64_t val,
+                           domid_t domid)
 {
     uint32_t count;
 
@@ -256,6 +257,8 @@ static int add_msr_intpose(xc_interface *xc_handle,
         msr_inj.mcinj_cpunr = cpu_nr;
         msr_inj.mcinj_flags = flags;
     }
+    if ( flags & MC_MSRINJ_F_GPADDR )
+        msr_inj.mcinj_domid = domid;
     msr_inj.mcinj_msr[count].reg = msr;
     msr_inj.mcinj_msr[count].value = val;
     msr_inj.mcinj_count++;
@@ -268,105 +271,15 @@ static int add_msr_bank_intpose(xc_interface *xc_handle,
                                 uint32_t flags,
                                 uint32_t type,
                                 uint32_t bank,
-                                uint64_t val)
+                                uint64_t val,
+                                domid_t domid)
 {
     uint64_t msr;
 
     msr = bank_addr(bank, type);
     if ( msr == INVALID_MSR )
         return -1;
-    return add_msr_intpose(xc_handle, cpu_nr, flags, msr, val);
-}
-
-#define MCE_INVALID_MFN ~0UL
-#define mfn_valid(_mfn) (_mfn != MCE_INVALID_MFN)
-#define mfn_to_pfn(_mfn) (live_m2p[(_mfn)])
-static uint64_t guest_mfn(xc_interface *xc_handle,
-                               uint32_t domain,
-                               uint64_t gpfn)
-{
-    xen_pfn_t *live_m2p = NULL;
-    int ret;
-    unsigned long hvirt_start;
-    unsigned int pt_levels;
-    uint64_t * pfn_buf = NULL;
-    unsigned long max_mfn = 0; /* max mfn of the whole machine */
-    unsigned long m2p_mfn0;
-    unsigned int guest_width;
-    long max_gpfn,i;
-    uint64_t mfn = MCE_INVALID_MFN;
-
-    if ( domain > DOMID_FIRST_RESERVED )
-        return MCE_INVALID_MFN;
-
-    /* Get max gpfn */
-    max_gpfn = do_memory_op(xc_handle, XENMEM_maximum_gpfn, &domain,
-                               sizeof(domain)) + 1;
-    if ( max_gpfn <= 0 )
-        err(xc_handle, "Failed to get max_gpfn 0x%lx", max_gpfn);
-
-    Lprintf("Maxium gpfn for dom %d is 0x%lx", domain, max_gpfn);
-
-    /* Get max mfn */
-    if ( !get_platform_info(xc_handle, domain,
-                            &max_mfn, &hvirt_start,
-                            &pt_levels, &guest_width) )
-        err(xc_handle, "Failed to get platform information");
-
-    /* Get guest's pfn list */
-    pfn_buf = calloc(max_gpfn, sizeof(uint64_t));
-    if ( !pfn_buf )
-        err(xc_handle, "Failed to alloc pfn buf");
-
-    ret = xc_get_pfn_list(xc_handle, domain, pfn_buf, max_gpfn);
-    if ( ret < 0 ) {
-        free(pfn_buf);
-        err(xc_handle, "Failed to get pfn list %x", ret);
-    }
-
-    /* Now get the m2p table */
-    live_m2p = xc_map_m2p(xc_handle, max_mfn, PROT_READ, &m2p_mfn0);
-    if ( !live_m2p )
-        err(xc_handle, "Failed to map live M2P table");
-
-    /* match the mapping */
-    for ( i = 0; i < max_gpfn; i++ )
-    {
-        uint64_t tmp;
-        tmp = pfn_buf[i];
-
-        if (mfn_valid(tmp) &&  (mfn_to_pfn(tmp) == gpfn))
-        {
-            mfn = tmp;
-            Lprintf("We get the mfn 0x%lx for this injection", mfn);
-            break;
-        }
-    }
-
-    munmap(live_m2p, M2P_SIZE(max_mfn));
-
-    free(pfn_buf);
-    return mfn;
-}
-
-static uint64_t mca_gpfn_to_mfn(xc_interface *xc_handle,
-                                uint32_t domain,
-                                uint64_t gfn)
-{
-    uint64_t index;
-    long max_gpfn;
-
-    /* If domain is xen, means we want pass index directly */
-    if ( domain == DOMID_XEN )
-        return gfn;
-
-    max_gpfn = do_memory_op(xc_handle, XENMEM_maximum_gpfn, &domain,
-                               sizeof(domain)) + 1;
-    if ( max_gpfn <= 0 )
-        err(xc_handle, "Failed to get max_gpfn 0x%lx", max_gpfn);
-    index = gfn % max_gpfn;
-
-    return guest_mfn(xc_handle, domain, index);
+    return add_msr_intpose(xc_handle, cpu_nr, flags, msr, val, domid);
 }
 
 static int inject_mcg_status(xc_interface *xc_handle,
@@ -374,7 +287,7 @@ static int inject_mcg_status(xc_interface *xc_handle,
                              uint64_t val)
 {
     return add_msr_intpose(xc_handle, cpu_nr, MC_MSRINJ_F_INTERPOSE,
-                               MSR_IA32_MCG_STATUS, val);
+                               MSR_IA32_MCG_STATUS, val, 0);
 }
 
 static int inject_mci_status(xc_interface *xc_handle,
@@ -383,7 +296,7 @@ static int inject_mci_status(xc_interface *xc_handle,
                              uint64_t val)
 {
     return add_msr_bank_intpose(xc_handle, cpu_nr, MC_MSRINJ_F_INTERPOSE,
-                                    MCi_type_STATUS, bank, val);
+                                    MCi_type_STATUS, bank, val, 0);
 }
 
 static int inject_mci_misc(xc_interface *xc_handle,
@@ -392,22 +305,23 @@ static int inject_mci_misc(xc_interface *xc_handle,
                              uint64_t val)
 {
     return add_msr_bank_intpose(xc_handle, cpu_nr, MC_MSRINJ_F_INTERPOSE,
-                                    MCi_type_MISC, bank, val);
+                                    MCi_type_MISC, bank, val, 0);
 }
 
 static int inject_mci_addr(xc_interface *xc_handle,
                              uint32_t cpu_nr,
                              uint64_t bank,
-                             uint64_t val)
+                             uint64_t val,
+                             domid_t domid)
 {
-    return add_msr_bank_intpose(xc_handle, cpu_nr, MC_MSRINJ_F_INTERPOSE,
-                                    MCi_type_ADDR, bank, val);
+    return add_msr_bank_intpose(xc_handle, cpu_nr,
+                                    MC_MSRINJ_F_INTERPOSE | MC_MSRINJ_F_GPADDR,
+                                    MCi_type_ADDR, bank, val, domid);
 }
 
 static int inject(xc_interface *xc_handle, struct mce_info *mce,
                   uint32_t cpu_nr, uint32_t domain, uint64_t gaddr)
 {
-    uint64_t gpfn, mfn, haddr;
     int ret = 0;
 
     ret = inject_mcg_status(xc_handle, cpu_nr, mce->mcg_stat);
@@ -424,12 +338,7 @@ static int inject(xc_interface *xc_handle, struct mce_info *mce,
     if ( ret )
         err(xc_handle, "Failed to inject MCi_MISC MSR");
 
-    gpfn = gaddr >> PAGE_SHIFT;
-    mfn = mca_gpfn_to_mfn(xc_handle, domain, gpfn);
-    if (!mfn_valid(mfn))
-        err(xc_handle, "The MFN is not valid");
-    haddr = (mfn << PAGE_SHIFT) | (gaddr & (PAGE_SIZE - 1));
-    ret = inject_mci_addr(xc_handle, cpu_nr, mce->bank, haddr);
+    ret = inject_mci_addr(xc_handle, cpu_nr, mce->bank, gaddr, domain);
     if ( ret )
         err(xc_handle, "Failed to inject MCi_ADDR MSR");
 
@@ -507,7 +416,7 @@ int main(int argc, char *argv[])
     uint32_t domid;
     xc_interface *xc_handle;
     int cpu_nr;
-    int64_t gaddr, gpfn, mfn, haddr, max_gpa;
+    uint64_t gaddr, max_gpa;
 
     /* Default Value */
     domid = DOMID_XEN;
@@ -563,16 +472,10 @@ int main(int argc, char *argv[])
     Lprintf("get gaddr of error inject is: 0x%lx", gaddr);
 
     if ( dump ) {
-        gpfn = gaddr >> PAGE_SHIFT;
-        mfn = mca_gpfn_to_mfn(xc_handle, domid, gpfn);
-        if (!mfn_valid(mfn))
-            err(xc_handle, "The MFN is not valid");
-        haddr = (mfn << PAGE_SHIFT) | (gaddr & (PAGE_SIZE - 1));
         if ( domid == DOMID_XEN )
-            Lprintf("Xen: mfn=0x%lx, haddr=0x%lx", mfn, haddr);
+            Lprintf("Xen: gaddr=0x%lx", gaddr);
         else
-            Lprintf("Dom%d: gaddr=0x%lx, gpfn=0x%lx, mfn=0x%lx, haddr=0x%lx",
-                    domid, gaddr, gpfn, mfn, haddr);
+            Lprintf("Dom%d: gaddr=0x%lx", domid, gaddr);
         goto out;
     }
 
-- 
2.4.8

  parent reply	other threads:[~2015-09-15  8:29 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-15  8:29 [PATCH 0/4] Fix tools/xen-mceinj to handle >=4GB guest memory Haozhong Zhang
2015-09-15  8:29 ` [PATCH 1/4] x86/mce: Fix code style Haozhong Zhang
2015-09-15  8:47   ` Egger, Christoph
2015-09-15 13:13   ` Jan Beulich
2015-09-15 13:19     ` Haozhong Zhang
2015-09-15  8:29 ` [PATCH 2/4] tools/mceinject: " Haozhong Zhang
2015-09-15  8:48   ` Egger, Christoph
2015-09-15 10:15     ` Ian Campbell
2015-09-15 13:11   ` Wei Liu
2015-09-15  8:29 ` [PATCH 3/4] x86/mce: Translate passed-in GPA to host machine address Haozhong Zhang
2015-09-15  9:14   ` Egger, Christoph
2015-09-15  9:48     ` Haozhong Zhang
2015-09-15 13:24   ` Jan Beulich
2015-09-15 13:42     ` Haozhong Zhang
2015-09-15 13:47       ` Jan Beulich
2015-09-15 13:51         ` Haozhong Zhang
2015-09-15 13:50       ` Andrew Cooper
2015-09-16  0:38         ` Haozhong Zhang
2015-09-15  8:29 ` Haozhong Zhang [this message]
2015-09-15 10:02   ` [PATCH 4/4] tools/xen-mceinj: Pass in GPA when injecting through MSR_MCI_ADDR Wei Liu
2015-09-15 10:08     ` Egger, Christoph
2015-09-15 10:16       ` Wei Liu
2015-09-15 10:17   ` Egger, Christoph
2015-09-15 10:28     ` Haozhong Zhang
2015-09-15 10:34       ` Egger, Christoph
2015-09-15 10:20   ` Ian Campbell
2015-09-15 10:38     ` Haozhong Zhang

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=1442305780-12790-5-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).