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

Re: [PATCH] vpci: introduce per-domain lock to protect vpci structure


  • To: Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 14 Feb 2022 15:31:18 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=9bX+Bm6Kq+UGImw8PzonFban3IJbCKjlxzEsURkdbNU=; b=WB2ahwc/jOwxo37OlT4Q0T4bOVq/ScBN0m5+hCFDSK3/8lluugCc0JyGSNveGLI22JK/nkCF08UILsDRefJW6k5wJps6Wh/tIXG9k8DDPJapjOE5RGLsqkzII2p5Mnvh987l5lNH0qnbxGkKJpempJdMJV3n5baB303N+jhNeNY0to1ukdbBfxApcJVCZQHIqe1qj68RQjgYEp8YW/sBegHI3Fi/9MqCNPN2EIVZqkjeDUDvisFyngtMi+s/5RcKqxk6wu06ebm9odfrAJ5rWRKZY5PFU/cjDLNp3REE9a5IvhomB3UaOW6u9LqQorRhD+HgsTKATB1mvHw9dD1wIQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K/xUSclmp4gqg1inHyyZSSxRQ3C/mfSwAsPt8MVNj48ZR78HHpy8aiy6CRHICsP6rZ176saKbTsw7tVljGnCpbkJIGrtCZeqLq0Lj6+QoTvoqPmN2gIK3Dxh8pF3GJE8qSXGe86mWDKEAe/pWf0i66kXjXfGeZlTVYI8CvCh2R+Rr16w3vXlN4br1eLhPaGeUItcWTzht/hEjE2+VoaFhORQPNcubEFc88xqd4Ol29R1zqc+kusTGXlEAmJuQ/ortYz45AszfZFFky8YofTP0r3vY2idf+hsdYRdYnTvlgdgOAYOjzgoppAkhj8JmsyJXdWzo4HlGaTq8cHOQOV+Ug==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: "roger.pau@xxxxxxxxxx" <roger.pau@xxxxxxxxxx>, "julien@xxxxxxx" <julien@xxxxxxx>, "sstabellini@xxxxxxxxxx" <sstabellini@xxxxxxxxxx>, Oleksandr Tyshchenko <Oleksandr_Tyshchenko@xxxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Artem Mygaiev <Artem_Mygaiev@xxxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Rahul Singh <rahul.singh@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 14 Feb 2022 14:31:33 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 14.02.2022 15:26, Oleksandr Andrushchenko wrote:
> 
> 
> On 14.02.22 16:19, Jan Beulich wrote:
>> On 09.02.2022 14:36, Oleksandr Andrushchenko wrote:
>>> @@ -410,14 +428,37 @@ static void vpci_write_helper(const struct pci_dev 
>>> *pdev,
>>>                r->private);
>>>   }
>>>   
>>> +static bool vpci_header_write_lock(const struct pci_dev *pdev,
>>> +                                   unsigned int start, unsigned int size)
>>> +{
>>> +    /*
>>> +     * Writing the command register and ROM BAR register may trigger
>>> +     * modify_bars to run which in turn may access multiple pdevs while
>>> +     * checking for the existing BAR's overlap. The overlapping check, if 
>>> done
>>> +     * under the read lock, requires vpci->lock to be acquired on both 
>>> devices
>>> +     * being compared, which may produce a deadlock. It is not possible to
>>> +     * upgrade read lock to write lock in such a case. So, in order to 
>>> prevent
>>> +     * the deadlock, check which registers are going to be written and 
>>> acquire
>>> +     * the lock in the appropriate mode from the beginning.
>>> +     */
>>> +    if ( !vpci_offset_cmp(start, size, PCI_COMMAND, 2) )
>>> +        return true;
>>> +
>>> +    if ( !vpci_offset_cmp(start, size, pdev->vpci->header.rom_reg, 4) )
>>> +        return true;
>>> +
>>> +    return false;
>>> +}
>> A function of this name gives (especially at the call site(s)) the
>> impression of acquiring a lock. Considering that of the prefixes
>> neither "vpci" nor "header" are really relevant here, may I suggest
>> to use need_write_lock()?
>>
>> May I further suggest that you either split the comment or combine
>> the two if()-s (perhaps even straight into single return statement)?
>> Personally I'd prefer the single return statement approach here ...
> That was already questioned by Roger and now it looks like:
> 
> static bool overlap(unsigned int r1_offset, unsigned int r1_size,
>                      unsigned int r2_offset, unsigned int r2_size)
> {
>      /* Return true if there is an overlap. */
>      return r1_offset < r2_offset + r2_size && r2_offset < r1_offset + 
> r1_size;
> }
> 
> bool vpci_header_write_lock(const struct pci_dev *pdev,
>                              unsigned int start, unsigned int size)
> {
>      /*
>       * Writing the command register and ROM BAR register may trigger
>       * modify_bars to run which in turn may access multiple pdevs while
>       * checking for the existing BAR's overlap. The overlapping check, if 
> done
>       * under the read lock, requires vpci->lock to be acquired on both 
> devices
>       * being compared, which may produce a deadlock. It is not possible to
>       * upgrade read lock to write lock in such a case. So, in order to 
> prevent
>       * the deadlock, check which registers are going to be written and 
> acquire
>       * the lock in the appropriate mode from the beginning.
>       */
>      if ( overlap(start, size, PCI_COMMAND, 2) ||
>           (pdev->vpci->header.rom_reg &&
>            overlap(start, size, pdev->vpci->header.rom_reg, 4)) )
>          return true;
> 
>      return false;
> }
> 
> vpci_header_write_lock moved to header.c and is not static anymore.
> So, sitting in header.c, the name seems to be appropriate now

The prefix of the name - yes. But as said, a function of this name looks
as if it would acquire a lock. Imo you want to insert "need" or some
such.

Jan




 


Rackspace

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