From mboxrd@z Thu Jan 1 00:00:00 1970 From: Arianna Avanzini Subject: [PATCH v7 05/10] arch/x86: check if mapping exists before memory_mapping removes it Date: Mon, 5 May 2014 17:54:09 +0200 Message-ID: <1399305254-3695-6-git-send-email-avanzini.arianna@gmail.com> References: <1399305254-3695-1-git-send-email-avanzini.arianna@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1399305254-3695-1-git-send-email-avanzini.arianna@gmail.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: xen-devel@lists.xen.org Cc: Ian.Campbell@eu.citrix.com, paolo.valente@unimore.it, keir@xen.org, stefano.stabellini@eu.citrix.com, Ian.Jackson@eu.citrix.com, dario.faggioli@citrix.com, tim@xen.org, julien.grall@citrix.com, etrudeau@broadcom.com, andrew.cooper3@citrix.com, JBeulich@suse.com, avanzini.arianna@gmail.com, viktor.kleinik@globallogic.com List-Id: xen-devel@lists.xenproject.org Currently, when a memory mapping is removed with the memory_mapping DOMCTL, no check is performed on the existence of such a mapping. This commit attempts to add such a consistency check to the code performing the unmap, emitting a warning message if the check fails. Signed-off-by: Arianna Avanzini Cc: Dario Faggioli Cc: Paolo Valente Cc: Stefano Stabellini Cc: Julien Grall Cc: Ian Campbell Cc: Jan Beulich Cc: Keir Fraser Cc: Tim Deegan Cc: Ian Jackson Cc: Andrew Cooper Cc: Eric Trudeau Cc: Viktor Kleinik --- v7: - Do not fail with an error when attempting to remove a non-existent mapping: just emit a warning. --- xen/arch/x86/domctl.c | 4 ++-- xen/arch/x86/mm/p2m.c | 12 ++++++++---- xen/include/asm-x86/p2m.h | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index ae29a56..c466063 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -679,7 +679,7 @@ long arch_do_domctl( "memory_map:fail: dom%d gfn=%lx mfn=%lx ret:%ld\n", d->domain_id, gfn + i, mfn + i, ret); while ( i-- ) - clear_mmio_p2m_entry(d, gfn + i); + clear_mmio_p2m_entry(d, gfn + i, _mfn(mfn + i)); if ( iomem_deny_access(d, mfn, mfn + nr_mfns - 1) && is_hardware_domain(current->domain) ) printk(XENLOG_ERR @@ -699,7 +699,7 @@ long arch_do_domctl( if ( paging_mode_translate(d) ) for ( i = 0; i < nr_mfns; i++ ) { - ret = clear_mmio_p2m_entry(d, gfn + i); + ret = clear_mmio_p2m_entry(d, gfn + i, _mfn(mfn + i)); if ( ret ) tmp_rc = ret; } diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 1d0528b..a99e222 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -801,10 +801,10 @@ int set_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn) } /* Returns: 0 for success, -errno for failure */ -int clear_mmio_p2m_entry(struct domain *d, unsigned long gfn) +int clear_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn) { int rc = -EINVAL; - mfn_t mfn; + mfn_t actual_mfn; p2m_access_t a; p2m_type_t t; struct p2m_domain *p2m = p2m_get_hostp2m(d); @@ -813,15 +813,19 @@ int clear_mmio_p2m_entry(struct domain *d, unsigned long gfn) return -EIO; gfn_lock(p2m, gfn, 0); - mfn = p2m->get_entry(p2m, gfn, &t, &a, 0, NULL); + actual_mfn = p2m->get_entry(p2m, gfn, &t, &a, 0, NULL); /* Do not use mfn_valid() here as it will usually fail for MMIO pages. */ - if ( (INVALID_MFN == mfn_x(mfn)) || (t != p2m_mmio_direct) ) + if ( (INVALID_MFN == mfn_x(actual_mfn)) || (t != p2m_mmio_direct) ) { gdprintk(XENLOG_ERR, "gfn_to_mfn failed! gfn=%08lx type:%d\n", gfn, t); goto out; } + if ( mfn_x(mfn) != mfn_x(actual_mfn) ) + gdprintk(XENLOG_WARNING, + "no mapping between mfn %08lx and gfn %08lx\n", + mfn_x(mfn), gfn); rc = p2m_set_entry(p2m, gfn, _mfn(INVALID_MFN), PAGE_ORDER_4K, p2m_invalid, p2m->default_access); diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 86847e9..e901085 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -513,7 +513,7 @@ void p2m_memory_type_changed(struct domain *d); /* Set mmio addresses in the p2m table (for pass-through) */ 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); +int clear_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn); /* -- 1.9.2