From: "Jan Beulich" Subject: Re: [PATCH v3 4/5] xen/arm: introduce GNTTABOP_cache_flush Date: Fri, 10 Oct 2014 08:56:03 +0100 Message-ID: <5437AD33020000780003D86B@mail.emea.novell.com> References: <1412773221-15150-4-git-send-email-stefano.stabellini@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XcV3U-0007jL-Sb for xen-devel@lists.xenproject.org; Fri, 10 Oct 2014 07:56:04 +0000 In-Reply-To: <1412773221-15150-4-git-send-email-stefano.stabellini@eu.citrix.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Stefano Stabellini Cc: julien.grall@citrix.com, xen-devel , Ian.Campbell@citrix.com List-Id: xen-devel@lists.xenproject.org >>> On 08.10.14 at 15:00, wrote: > @@ -2498,6 +2528,97 @@ gnttab_swap_grant_ref(XEN_GUEST_HANDLE_PARAM(gnttab_swap_grant_ref_t) uop, > return 0; > } > > +static int __gnttab_cache_flush(gnttab_cache_flush_t cflush) > +{ > + struct domain *d, *owner; > + struct page_info *page; > + uint64_t mfn; > + void *v; > + > + if ( cflush.offset > PAGE_SIZE || >= ? > + cflush.length > PAGE_SIZE || > + cflush.offset + cflush.length > PAGE_SIZE ) Indentation. > + return -EINVAL; > + > + if ( cflush.length == 0 || cflush.op == 0 ) > + return 0; > + > + /* currently unimplemented */ > + if ( cflush.op & GNTTAB_CACHE_SOURCE_GREF ) > + return -EOPNOTSUPP; > + > + d = rcu_lock_current_domain(); > + mfn = cflush.a.dev_bus_addr >> PAGE_SHIFT; > + > + if ( !mfn_valid(mfn) ) > + { > + rcu_unlock_domain(d); > + return -EINVAL; > + } > + > + page = mfn_to_page(mfn); > + owner = page_get_owner_and_reference(page); > + if ( !owner ) > + { > + rcu_unlock_domain(d); > + return -EPERM; > + } > + > + if ( d != owner ) > + { > + spin_lock(&owner->grant_table->lock); > + > + if ( !grant_map_exists(d, owner->grant_table, mfn) ) > + { > + spin_unlock(&owner->grant_table->lock); > + rcu_unlock_domain(d); > + put_page(page); > + gdprintk(XENLOG_G_ERR, "mfn %"PRIx64" hasn't been granted by d%d to d%d\n", > + mfn, owner->domain_id, d->domain_id); > + return -EINVAL; > + } > + } > + > + v = map_domain_page(mfn); > + v += cflush.offset; > + > + if ( (cflush.op & GNTTAB_CACHE_INVAL) && (cflush.op & GNTTAB_CACHE_CLEAN) ) > + clean_and_invalidate_xen_dcache_va_range(v, cflush.length); > + else if ( cflush.op & GNTTAB_CACHE_INVAL ) > + invalidate_xen_dcache_va_range(v, cflush.length); > + else if ( cflush.op & GNTTAB_CACHE_CLEAN ) > + clean_xen_dcache_va_range(v, cflush.length); > + > + if ( d != owner ) > + spin_unlock(&owner->grant_table->lock); > + unmap_domain_page(v); > + put_page(page); > + > + return 0; > +} > + > +static long > +gnttab_cache_flush(XEN_GUEST_HANDLE_PARAM(gnttab_cache_flush_t) uop, > + unsigned int count) > +{ > + int i, ret; > + gnttab_cache_flush_t op; > + > + for ( i = 0; i < count; i++ ) > + { > + if ( i && hypercall_preempt_check() ) > + return i; > + if ( unlikely(__copy_from_guest(&op, uop, 1)) ) > + return -EFAULT; > + ret = __gnttab_cache_flush(op); > + if ( ret < 0 ) > + return -ret; Why "-ret"? Especially with ... > @@ -2627,6 +2748,20 @@ do_grant_table_op( > } > break; > } > + case GNTTABOP_cache_flush: > + { > + XEN_GUEST_HANDLE_PARAM(gnttab_cache_flush_t) cflush = > + guest_handle_cast(uop, gnttab_cache_flush_t); > + if ( unlikely(!guest_handle_okay(cflush, count)) ) > + goto out; > + rc = gnttab_cache_flush(cflush, count); > + if ( rc > 0 ) > + { > + guest_handle_add_offset(cflush, rc); > + uop = guest_handle_cast(cflush, void); > + } > + break; > + } ... a positive value here meaning "continuation needed". Jan