From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tiejun Chen Subject: [v8][PATCH 14/17] xen/x86/p2m: introduce set_identity_p2m_entry Date: Mon, 1 Dec 2014 17:24:32 +0800 Message-ID: <1417425875-9634-15-git-send-email-tiejun.chen@intel.com> References: <1417425875-9634-1-git-send-email-tiejun.chen@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1417425875-9634-1-git-send-email-tiejun.chen@intel.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: jbeulich@suse.com, ian.jackson@eu.citrix.com, stefano.stabellini@eu.citrix.com, ian.campbell@citrix.com, wei.liu2@citrix.com, kevin.tian@intel.com, tim@xen.org, yang.z.zhang@intel.com Cc: xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org We will create RMRR mapping as follows: If gfn space unoccupied, we just set that. If space already occupy by 1:1 RMRR mapping do thing. Others should be failed. Signed-off-by: Tiejun Chen --- xen/arch/x86/mm/p2m.c | 28 ++++++++++++++++++++++++++++ xen/include/asm-x86/p2m.h | 4 ++++ 2 files changed, 32 insertions(+) diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 607ecd0..c415521 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -913,6 +913,34 @@ int set_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn) return set_typed_p2m_entry(d, gfn, mfn, p2m_mmio_direct); } +int set_identity_p2m_entry(struct domain *d, unsigned long gfn, + p2m_access_t p2ma) +{ + p2m_type_t p2mt; + p2m_access_t a; + mfn_t mfn; + struct p2m_domain *p2m = p2m_get_hostp2m(d); + int ret = -EBUSY; + + gfn_lock(p2m, gfn, 0); + + mfn = p2m->get_entry(p2m, gfn, &p2mt, &a, 0, NULL); + + if ( !mfn_valid(mfn) ) + ret = p2m_set_entry(p2m, gfn, _mfn(gfn), PAGE_ORDER_4K, p2m_mmio_direct, + p2ma); + else if ( mfn_x(mfn) == gfn && p2mt == p2m_mmio_direct && a == p2ma ) + ret = 0; + else + printk(XENLOG_G_WARNING + "Cannot identity map d%d:%lx, already mapped to %lx.\n", + d->domain_id, gfn, mfn_x(mfn)); + + gfn_unlock(p2m, gfn, 0); + + return ret; +} + /* Returns: 0 for success, -errno for failure */ int clear_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn) { diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 99f7fb7..26cf0cc 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -509,6 +509,10 @@ int p2m_is_logdirty_range(struct p2m_domain *, unsigned long start, int set_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn); int clear_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn); +/* Set identity addresses in the p2m table (for pass-through) */ +int set_identity_p2m_entry(struct domain *d, unsigned long gfn, + p2m_access_t p2ma); + /* Add foreign mapping to the guest's p2m table. */ int p2m_add_foreign(struct domain *tdom, unsigned long fgfn, unsigned long gpfn, domid_t foreign_domid); -- 1.9.1