From mboxrd@z Thu Jan 1 00:00:00 1970 From: Arianna Avanzini Subject: [PATCH RESEND v9 04/14] arch/arm: unmap partially-mapped I/O-memory regions Date: Mon, 14 Jul 2014 02:50:25 +0200 Message-ID: <1405299035-2988-5-git-send-email-avanzini.arianna@gmail.com> References: <53BFEBFB.1090602@linaro.org> <1405299035-2988-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: <1405299035-2988-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 This commit changes the function apply_p2m_changes() to unwind changes performed while mapping an I/O-memory region, if errors are seen during the operation. This is useful to avoid that I/O-memory areas are partially accessible to guests. 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 --- v9: - Let apply_p2m_ranges() unwind its own progress instead of relying on the caller to unmap partially-mapped I/O-memory regions. - Adapt to rework of p2m-related functions for ARM. --- xen/arch/arm/p2m.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 1e6579f..e9f7c96 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -694,7 +694,7 @@ static int apply_p2m_changes(struct domain *d, unsigned long cur_first_page = ~0, cur_first_offset = ~0, cur_second_offset = ~0; - unsigned long count = 0; + unsigned long count = 0, inserted = 0; bool_t flush = false; bool_t flush_pt; @@ -706,6 +706,7 @@ static int apply_p2m_changes(struct domain *d, spin_lock(&p2m->lock); +unwind: addr = start_gpaddr; while ( addr < end_gpaddr ) { @@ -749,7 +750,15 @@ static int apply_p2m_changes(struct domain *d, start_gpaddr, end_gpaddr, &addr, &maddr, &flush, mattr, t); - if ( ret < 0 ) { rc = ret ; goto out; } + if ( ret < 0 ) + { + rc = ret ; + if ( op != INSERT ) goto out; + end_gpaddr = start_gpaddr + inserted * PAGE_SIZE; + op = REMOVE; + goto unwind; + } + if ( op == INSERT ) inserted++; count += ret; if ( ret != P2M_ONE_DESCEND ) continue; @@ -768,7 +777,15 @@ static int apply_p2m_changes(struct domain *d, start_gpaddr, end_gpaddr, &addr, &maddr, &flush, mattr, t); - if ( ret < 0 ) { rc = ret ; goto out; } + if ( ret < 0 ) + { + rc = ret ; + if ( op != INSERT ) goto out; + end_gpaddr = start_gpaddr + inserted * PAGE_SIZE; + op = REMOVE; + goto unwind; + } + if ( op == INSERT ) inserted++; count += ret; if ( ret != P2M_ONE_DESCEND ) continue; @@ -787,9 +804,17 @@ static int apply_p2m_changes(struct domain *d, start_gpaddr, end_gpaddr, &addr, &maddr, &flush, mattr, t); - if ( ret < 0 ) { rc = ret ; goto out; } + if ( ret < 0 ) + { + rc = ret ; + if ( op != INSERT ) goto out; + end_gpaddr = start_gpaddr + inserted * PAGE_SIZE; + op = REMOVE; + goto unwind; + } /* L3 had better have done something! We cannot descend any further */ BUG_ON(ret == P2M_ONE_DESCEND); + if ( op == INSERT ) inserted++; count += ret; } -- 1.9.3