From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Vrabel Subject: Re: [PATCHv6 5/5] gnttab: use per-VCPU maptrack free lists Date: Thu, 23 Apr 2015 17:29:20 +0100 Message-ID: <55391DE0.7080401@citrix.com> References: <1429718436-9782-1-git-send-email-david.vrabel@citrix.com> <1429718436-9782-6-git-send-email-david.vrabel@citrix.com> <553935E402000078000755B7@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YlK19-0007Wh-Ss for xen-devel@lists.xenproject.org; Thu, 23 Apr 2015 16:30:24 +0000 In-Reply-To: <553935E402000078000755B7@mail.emea.novell.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: Jan Beulich , 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 23/04/15 17:11, Jan Beulich wrote: >>>> On 22.04.15 at 18:00, wrote: >> >> + v->maptrack_head = lgt->maptrack_pages * MAPTRACK_PER_PAGE; >> + if (v->maptrack_tail == MAPTRACK_TAIL) >> + { >> + v->maptrack_tail = (lgt->maptrack_pages * MAPTRACK_PER_PAGE) >> + + MAPTRACK_PER_PAGE - 1; >> + new_mt[i - 1].ref = MAPTRACK_TAIL; >> } >> >> + spin_lock(&lgt->maptrack_lock); >> + lgt->maptrack[lgt->maptrack_pages++] = new_mt; >> spin_unlock(&lgt->maptrack_lock); > > The uses of ->maptrack_pages ahead of taking the lock can race > with updates inside the lock. And with locking elsewhere dropped > by the previous patch it looks like you can't update ->maptrack[] > like you do (you'd need a barrier between the pointer store and > the increment, and with that I think the lock would become > superfluous if it was needed only for this update). This was my mistake. Malcolm's original patch had correct locking here. > Also note the coding style issues in the changes above^(and also > in code further down). > >> - return handle; >> + v->maptrack_limit = new_mt_limit; >> + >> + return __get_maptrack_handle(lgt, v); > > With the lock dropped, nothing guarantees this to succeed, which it > ought to unless the table size reached its allowed maximum. We've just added a new page of handles for this VCPU. This will succeed. David