From: "Jan Beulich" Subject: Re: [PATCHv8 2/3] gnttab: per-active entry locking Date: Tue, 19 May 2015 09:27:19 +0100 Message-ID: <555B1007020000780007B772@mail.emea.novell.com> References: <1431440115-27936-1-git-send-email-david.vrabel@citrix.com> <1431440115-27936-3-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Yucs0-0002FD-Fh for xen-devel@lists.xenproject.org; Tue, 19 May 2015 08:27:24 +0000 In-Reply-To: <1431440115-27936-3-git-send-email-david.vrabel@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: David Vrabel Cc: Keir Fraser , Ian Campbell , Christoph Egger , Tim Deegan , Matt Wilson , xen-devel@lists.xenproject.org, Malcolm Crossley List-Id: xen-devel@lists.xenproject.org >>> On 12.05.15 at 16:15, wrote: > +static inline struct active_grant_entry * > +active_entry_acquire(struct grant_table *t, grant_ref_t e) > +{ > + struct active_grant_entry *act; > + > + /* > + * not perfect, but better than nothing for a debug build > + * sanity check > + */ Comment style. > @@ -546,15 +554,28 @@ static void mapcount( > > *wrc = *rdc = 0; > > + /* > + * N.B.: while taking the local maptrack spinlock prevents any > + * mapping changes, the remote active entries could be changing > + * while we are counting. The caller has to hold the grant table > + * write lock, or some other mechanism should be used to prevent > + * concurrent changes during this operation. This is tricky > + * because we can't promote a read lock into a write lock. > + */ > + ASSERT(rw_is_locked(&rd->grant_table->lock)); So both callers only hold the read lock - what is this "other mechanism" that they employ? > @@ -2602,9 +2629,17 @@ __gnttab_swap_grant_ref(grant_ref_t ref_a, grant_ref_t ref_b) > { > struct domain *d = rcu_lock_current_domain(); > struct grant_table *gt = d->grant_table; > - struct active_grant_entry *act; > + struct active_grant_entry *act_a = NULL; > + struct active_grant_entry *act_b = NULL; > s16 rc = GNTST_okay; > > + if ( ref_a == ref_b ) > + /* > + * noop, so avoid acquiring the same active entry > + * twice which would case a deadlock. cause Jan