From: Haozhong Zhang Subject: Re: [PATCH 3/4] x86/mce: Translate passed-in GPA to host machine address Date: Tue, 15 Sep 2015 17:48:33 +0800 Message-ID: <20150915094833.GA26047@hzzhang-OptiPlex-9020.sh.intel.com> References: <1442305780-12790-1-git-send-email-haozhong.zhang@intel.com> <1442305780-12790-4-git-send-email-haozhong.zhang@intel.com> <55F7E172.6080904@amazon.de> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <55F7E172.6080904@amazon.de> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: "Egger, Christoph" Cc: Wei Liu , Ian Campbell , Stefano Stabellini , Liu Jinsong , Ian Jackson , xen-devel@lists.xen.org, Jan Beulich , Andrew Cooper , Keir Fraser List-Id: xen-devel@lists.xenproject.org On Tue, Sep 15, 2015 at 11:14:26AM +0200, Egger, Christoph wrote: > On 2015/09/15 10:29, Haozhong Zhang wrote: > > 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 > > Comments inline. > > > --- > > xen/arch/x86/cpu/mcheck/mce.c | 33 +++++++++++++++++++++++++++++++++ > > xen/include/public/arch-x86/xen-mca.h | 5 ++++- > > 2 files changed, 37 insertions(+), 1 deletion(-) > > > > diff --git a/xen/arch/x86/cpu/mcheck/mce.c b/xen/arch/x86/cpu/mcheck/mce.c > > index 561257d..343d9d2 100644 > > --- a/xen/arch/x86/cpu/mcheck/mce.c > > +++ b/xen/arch/x86/cpu/mcheck/mce.c > > @@ -21,6 +21,7 @@ > > #include > > #include > > #include > > +#include > > > > #include "mce.h" > > #include "barrier.h" > > @@ -1422,6 +1423,38 @@ 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; > > + int i; > > + uint64_t gaddr, gpfn, mfn, haddr; > > + p2m_type_t t; > > + > > + d = get_domain_by_id(mc_msrinject->mcinj_domid); > > + if (d == NULL) > > + return x86_mcerr("do_mca inject: illegal domain id", -EINVAL); > > + > > + for (i = 0, msr = &mc_msrinject->mcinj_msr[0]; > > + i < mc_msrinject->mcinj_count; i++, msr++) { > > + gaddr = msr->value; > > + gpfn = gaddr >> PAGE_SHIFT; > > + mfn = mfn_x(get_gfn(d, gpfn, &t)); > > + > > + if (mfn == INVALID_MFN) { > > put_gfn(d, gpfn); Oh, I forgot it in this path and will add in next version. > > > + put_domain(d); > > + return x86_mcerr("do_mca inject: illegal MSR value", > > + -EINVAL); > > + } > > + > > + haddr = (mfn << PAGE_SHIFT) | (gaddr & (PAGE_SIZE - 1)); > > + msr->value = haddr; > > + > > + put_gfn(d, gpfn); > > + } > > + > > + 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 2422b76..33c1a84 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 presents > > + in mcinj_flags */ > > wording. I prefer "s/presents/is present/" > I will fix it in the next version. > > + 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 { > > > > Amazon Development Center Germany GmbH > Krausenstr. 38 > 10117 Berlin > Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger > Ust-ID: DE289237879 > Eingetragen am Amtsgericht Charlottenburg HRB 149173 B >