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

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


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>
  • Date: Tue, 15 Feb 2022 10:57:18 +0000
  • Accept-language: en-US
  • 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=cFK5m9+VxwITfMlXzjygmB9ipTvuiWJCSP5a1hzhxvM=; b=D0wYGoYrx5T/3e3QNrAyLDflcUQ0RbhY0FfKZsS6govbQWqITYfQ2HNSWpyakygNWNEOZp9TtZGT7sZEf4fID4RfOvtMueGbnSm0wErlzLLY7Ffsa8ByXKW15Ap+8jRt8MY2COKhJ1WpfTzgO2vthCXEzzz/hc9zSrQZG/nSxgJ+ulhH8j7JY0KhiMRarUEHNcbfaiT68GaFJUvui2wN2Q9SxJI+mXnZQVog12P1BkgnMJbbYoKaMogvjj2Q/m8W8IQke3ZEWZLzaS1bE0+p4+8Mw9ZekUJlfWyQvtMGbmvX4ktP1fQZ+Ozz40n9G/zZDh56GjHZroZprokjVsc3nw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a8FBanfp5qEurTvx3l3qX/3WTsVDKAHl60YTTT9ZiX6wjFYQ+iJSSlr8Ndmv0W5q6hJ7gxX03rCkX+ZF8OlDhIcUddDL1w2VdaUHCLmY5nzEMsDMyGJNj5VG1YBYLjm3gsuhq6facJaqmxQfFngsTOat46Ub27jSKhc2gwfc+bSaVeQoqU60CDWBydPGo3eNw9YnU+5caxTPaHPxRAXDoOOk+jtxwta1Fq0AM7F27iLZWQEbxbmagjN4lDYLwtB+SIjtFO2PYjegoLDV/xkLO4mW5W04nvllPYeimyBmpitjdz8fl1/IZaTyvTVtm4XBUi7Gc6ZWIZfxfkuR+Gi7jg==
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "jbeulich@xxxxxxxx" <jbeulich@xxxxxxxx>, "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>, Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>
  • Delivery-date: Tue, 15 Feb 2022 10:57:32 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHYIkOs9pmsZb0l5kefj1m3qdTVCayUboeAgAACiYA=
  • Thread-topic: [PATCH v2] vpci: introduce per-domain lock to protect vpci structure


On 15.02.22 12:48, Roger Pau Monné wrote:
> On Tue, Feb 15, 2022 at 10:11:35AM +0200, Oleksandr Andrushchenko wrote:
> @@ -911,7 +914,11 @@ int vpci_msix_arch_print(const struct vpci_msix *msix)
>>               struct pci_dev *pdev = msix->pdev;
>>   
>>               spin_unlock(&msix->pdev->vpci->lock);
>> +            pcidevs_unlock();
>> +            read_unlock(&pdev->domain->vpci_rwlock);
>>               process_pending_softirqs();
>> +            read_lock(&pdev->domain->vpci_rwlock);
>> +            pcidevs_lock();
> This is again an ABBA situation: vpci_add_handlers will get called
> with pci_devs locked, and it will try to acquire the per-domain vpci
> lock (so pcidevs -> vpci_rwlock) while here and in other places in the
> patch to you have inverse locking order (vpci_rwlock -> pcidevs).
Indeed, I need to always lock in this order: pcidevs -> vpci_rwlock
to prevent ABBA, good catch
>
>>               /* NB: we assume that pdev cannot go away for an alive domain. 
>> */
>>               if ( !pdev->vpci || !spin_trylock(&pdev->vpci->lock) )
>>                   return -EBUSY;
>> @@ -323,10 +334,18 @@ uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, 
>> unsigned int size)
>>       }
>>   
>>       /* Find the PCI dev matching the address. */
>> +    pcidevs_lock();
>>       pdev = pci_get_pdev_by_domain(d, sbdf.seg, sbdf.bus, sbdf.devfn);
>> +    pcidevs_unlock();
>>       if ( !pdev )
>>           return vpci_read_hw(sbdf, reg, size);
> There's a window here (between dropping the pcidevs lock and acquiring
> the vpci_rwlock where either the pdev or pdev->vpci could be removed
> or recreated.
Yes, I know that. But this is the best I came up with...
>
> Thanks, Roger.
Thank you,
Oleksandr

 


Rackspace

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