From: Stefano Stabellini Subject: [PATCH 2/4] xen: introduce grant_map_exists Date: Thu, 2 Oct 2014 11:02:36 +0100 Message-ID: <1412244158-12124-2-git-send-email-stefano.stabellini@eu.citrix.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: 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.xensource.com Cc: julien.grall@citrix.com, tim@xen.org, Ian.Campbell@citrix.com, jbeulich@suse.com, Stefano Stabellini List-Id: xen-devel@lists.xenproject.org Check whether an mfn has been granted to a given domain on a target grant table. Signed-off-by: Stefano Stabellini CC: jbeulich@suse.com CC: tim@xen.org --- xen/common/grant_table.c | 32 ++++++++++++++++++++++++++++++++ xen/include/xen/grant_table.h | 4 ++++ 2 files changed, 36 insertions(+) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 23266c3..e1dc330 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -484,6 +484,38 @@ static int _set_status(unsigned gt_version, return _set_status_v2(domid, readonly, mapflag, shah, act, status); } +bool_t grant_map_exists(struct domain *ld, + struct grant_table *rgt, + unsigned long mfn) +{ + struct active_grant_entry *act; + grant_ref_t ref; + bool_t ret = 0; + + spin_lock(&rgt->lock); + + for ( ref = 0; ref != nr_grant_entries(rgt); ref++ ) + { + act = &active_entry(rgt, ref); + + if ( !act->pin ) + continue; + + if ( act->domid != ld->domain_id ) + continue; + + if ( act->frame != mfn ) + continue; + + ret = 1; + break; + } + + spin_unlock(&rgt->lock); + + return ret; +} + static void mapcount( struct grant_table *lgt, struct domain *rd, unsigned long mfn, unsigned int *wrc, unsigned int *rdc) diff --git a/xen/include/xen/grant_table.h b/xen/include/xen/grant_table.h index 5941191..2df390f 100644 --- a/xen/include/xen/grant_table.h +++ b/xen/include/xen/grant_table.h @@ -97,6 +97,10 @@ int grant_table_create( void grant_table_destroy( struct domain *d); +bool_t grant_map_exists(struct domain *ld, + struct grant_table *rgt, + unsigned long mfn); + /* Domain death release of granted mappings of other domains' memory. */ void gnttab_release_mappings( -- 1.7.10.4