From: "Jan Beulich" Subject: Re: [PATCH v11 6/8] xen/arm: introduce GNTTABOP_cache_flush Date: Thu, 23 Oct 2014 09:34:48 +0100 Message-ID: <5448D9C80200007800041573@mail.emea.novell.com> References: <1413996037-2747-6-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.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XhDr8-00062H-La for xen-devel@lists.xenproject.org; Thu, 23 Oct 2014 08:34:50 +0000 In-Reply-To: <1413996037-2747-6-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 22.10.14 at 18:40, wrote: > Introduce a new hypercall to perform cache maintenance operation on > behalf of the guest. The argument is a machine address and a size. The > implementation checks that the memory range is owned by the guest or the > guest has been granted access to it by another domain. > > Introduce grant_map_exists: an internal grant table function to check > whether an mfn has been granted to a given domain on a target grant > table. Check hypercall_preempt_check() every 4096 iterations in the > implementation of grant_map_exists. > Use the top 20 bits of the GNTTABOP cmd encoding to save the last ref > across the hypercall continuation. > > Signed-off-by: Stefano Stabellini Reviewed-by: Jan Beulich albeit the subject still says "arm" while there isn't anything ARM-specific in here and ... > +static int __gnttab_cache_flush(gnttab_cache_flush_t *cflush, > + unsigned int *ref_count) > +{ > + struct domain *d, *owner; > + struct page_info *page; > + unsigned long mfn; > + void *v; > + int ret; > + > + if ( (cflush->offset >= PAGE_SIZE) || > + (cflush->length > PAGE_SIZE) || > + (cflush->offset + cflush->length > PAGE_SIZE) ) > + return -EINVAL; > + > + if ( cflush->length == 0 || cflush->op == 0 ) > + return 0; > + > + /* currently unimplemented */ > + if ( cflush->op & GNTTAB_CACHE_SOURCE_GREF ) > + return -EOPNOTSUPP; > + > + if ( !(cflush->op & (GNTTAB_CACHE_INVAL|GNTTAB_CACHE_CLEAN)) || ... I think we should drop this because ... > + (cflush->op & ~(GNTTAB_CACHE_INVAL|GNTTAB_CACHE_CLEAN)) ) > + return -EINVAL; > + > + 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); > + > + ret = grant_map_exists(d, owner->grant_table, mfn, ref_count); > + if ( ret != 0 ) > + { > + spin_unlock(&owner->grant_table->lock); > + rcu_unlock_domain(d); > + put_page(page); > + return ret; > + } > + } > + > + v = map_domain_page(mfn); > + v += cflush->offset; > + > + if ( (cflush->op & GNTTAB_CACHE_INVAL) && (cflush->op & GNTTAB_CACHE_CLEAN) ) > + ret = clean_and_invalidate_dcache_va_range(v, cflush->length); > + else if ( cflush->op & GNTTAB_CACHE_INVAL ) > + ret = invalidate_dcache_va_range(v, cflush->length); > + else if ( cflush->op & GNTTAB_CACHE_CLEAN ) > + ret = clean_dcache_va_range(v, cflush->length); > + else > + BUG(); ... now that I think about it again it was a bad suggestion to BUG() here - there's nothing wrong with the caller requesting an expensive NOP. Both could be fixed up while committing. Jan