[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 3/4] vpci: use pcidevs locking to protect MMIO handlers


  • To: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 10 Aug 2022 08:46:34 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XjwzMdFj6Fblo4bsU0dvsEvVxOff1AXLAp9EZTC9wvU=; b=VjT0JP4aQYRAOMfsRmG+2K6UgDhxupiAZs4Fl1NnnSHNs1jVqEMbIIrZQgZW0UMNd/z04cALRiCbDz5dodCNbtJ0YAtB6vM5JsImMjsYovzO7URK8V/Y8Hbu+wfvbSaA62gTbzH433NPzR8kBLVtJ0/9TGHKA6qtpio21ASWNtVKH8CrT+y9QQ/fXodm/eyLua/3HJdI1IFBNwuhS5tjq2EKTTnk1u3u5vOPUBsZ7XNYphkq66puHeT2CiK57OGnE/OUjLEIuomedGMXEwg+pLIkGyfTkOvvI1ZqVN+gBqmpYHB4tIXa2LQd8mNIwkIaKbkRA67Zs/UcFpGqcIH76A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WBahJLMvGqk6inw1rRai79RttdYwZoeMAGgMToHKXllZlToZ56qVUecHQUONbUMRk+iBCzO3INqIG218Zy0PMnPGXfsijWzy0NW3q2Unp01q7yVX/d3VRuQ8kK8WvERA740anMA2wx/YW6qy3lGOhCTjtKUuvqvxfDv1e1OEzJKTGZbrMtpuAMk0lW9C1011zqVrhWbcXMl5yTk8AcFNsRZOkx/O6OJ/easmBVrsGhnTIm+9UPp0tybPTCzD+y0jNlTyhd2mI2e3b6LSEdD4vuKGyGPwdR1T821+xCU97XCF66Iv0y/Qq410hm32RLyrxIxNIRUSimq9/u5trBTsiQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 10 Aug 2022 06:46:58 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 09.08.2022 22:33, Volodymyr Babchuk wrote:
> Jan Beulich <jbeulich@xxxxxxxx> writes:
>> On 18.07.2022 23:15, Volodymyr Babchuk wrote:
>>> -            if ( !pdev->vpci || !spin_trylock(&pdev->vpci->lock) )
>>> +
>>> +            if ( !pcidevs_read_trylock() )
>>> +                return -EBUSY;
>>> +            pdev = pci_get_pdev_by_domain(d, sbdf.seg, sbdf.bus, 
>>> sbdf.devfn);
>>> +            /*
>>> +             * FIXME: we may find a re-allocated pdev's copy here.
>>> +             * Even occupying the same address as before. Do our best.
>>> +             */
>>> +            if ( !pdev || (pdev != msix->pdev) || !pdev->vpci ||
>>
>> Despite the comment: What guarantees that msix isn't a dangling pointer
>> at this point? At the very least I think you need to check !pdev->vpci
>> first. And I'm afraid I don't view "do our best" as good enough here
>> (considering the patch doesn't carry an RFC tag). And no, I don't have
>> any good suggestion other than "our PCI device locking needs a complete
>> overhaul". Quite likely what we need is a refcounter per device, which
>> - as long as non-zero - prevents removal.
> 
> Refcounter itself is a good idea, but I'm not liking where all this
> goes. We already are reworking locking by adding rw-locks with counters,
> adding refcounter on top of this will complicate things even further.

I'm of quite the opposite opinion: A lot of the places will no longer
need to hold the pcidevs lock when instead they hold a reference; the
lock will only be needed to acquire a reference. Therefore refcounting
is likely to simplify things, presumably to the point where at least
recursive locking (and probably also converting to some r/w locking
scheme) won't be necessary. The main complicating factor is that all
places where a reference is needed will have to be located, and (quite
obviously I'm inclined to say) in particular all involved error paths
will need to be covered when it comes to dropping references no longer
needed.

> I'm starting to think that complete PCI device locking rework may be
> simpler solution, actually. By any chance, were there any prior
> discussion on how proper locking should look like? 

Well, there were prior discussions (you'd need to search the list, as
I have no pointers to hand), but I'm not sure a clear picture had
surfaced how "proper locking" would look like. I guess that's part of
the reason why the currently proposed locking model actually makes
things quite a bit more complicated.

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.