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

Re: [PATCH v12.2 01/15] vpci: use per-domain PCI lock to protect vpci structure


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
  • Date: Wed, 24 Jan 2024 15:21:04 -0500
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=citrix.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • 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=V0JA7FoHuWcbjJZsa8jjyQSeGIximf/CWa4nHoAsF54=; b=TKSQijbEGCV1VZzykcGVR3MldpSun9E56vCS+KtVt41rr+JrdJl/ihzdWs4nGhiIkQlQ0iiWDXQyVIE1HTmUjhqsWFPFQSZRKgAAghyBYmzkNnaO72WF0LTjveIZcIa9ZQMDpULw1L6vhxwyUEWeGh+Oq+B0qbVAdVx4LvsZlExf3ykOyVuJNF7+NAvFO3jwQvqHXv8S6RH1itPKeM+PnmO65lotp8eC3irsCt9Mm2plNsh8R37YJ1ktLXvBIqAgAXDQR36ml3huDN1MQ8t96eQZY55qt7YGj1EfTTMb5G/0feiJJoU+Ek3seS2qEAM2JNOKV/W5bPCnAHZx4ThRDw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A7yRXSmYIwUk8mLZCCFbFTDA7+h4ryxav2QBzkBdYldA5h2nz+pLQFelr0rYSRQoHL1g/QXwk5/lupr1jA5RYwfdNdWpm0JAUIGVqY4g8SlXG/b6yYi3Yt17Vam9AoNEPgPgT52cZJgXjXRe8w3om5RSdTO77+Wel7bhX/WiCLy+rnrnH/k0es0DeHkjkcCNKzGRHniEOGmCHOQdVDPSE6V7TTGntd0nrIF0YYidjoiTqohMQVdgQf1Up6ZG7X2F05RY6Ao4QGU3Yl38AuKxW7IvNs2cksuL7Qu41qlWQQ8rIbPw9ckNfeDmuoacYUo33ccZx+Pajz0vXJ+EKORITw==
  • Cc: Jan Beulich <jbeulich@xxxxxxxx>, Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Jun Nakajima <jun.nakajima@xxxxxxxxx>, Kevin Tian <kevin.tian@xxxxxxxxx>, Paul Durrant <paul@xxxxxxx>, Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 24 Jan 2024 20:21:26 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 1/24/24 03:21, Roger Pau Monné wrote:
> On Wed, Jan 24, 2024 at 12:07:28AM -0500, Stewart Hildebrand wrote:
>> On 1/23/24 09:29, Jan Beulich wrote:
>>> On 15.01.2024 20:43, Stewart Hildebrand wrote:
>>>> @@ -1043,11 +1043,11 @@ static int __pci_enable_msix(struct pci_dev *pdev, 
>>>> struct msi_info *msi,
>>>>  {
>>>>      struct msi_desc *old_desc;
>>>>  
>>>> -    ASSERT(pcidevs_locked());
>>>> -
>>>>      if ( !pdev || !pdev->msix )
>>>>          return -ENODEV;
>>>>  
>>>> +    ASSERT(pcidevs_locked() || rw_is_locked(&pdev->domain->pci_lock));
>>>> +
>>>>      if ( msi->entry_nr >= pdev->msix->nr_entries )
>>>>          return -EINVAL;
>>>
>>> Further looking at this - is dereferencing pdev actually safe without 
>>> holding
>>> the global lock?
> 
> It is safe because either the global pcidevs lock or the per-domain
> pci_lock will be held, which should prevent the device from being
> removed.
> 
>> Are you referring to the new placement of the ASSERT, which opens up the 
>> possibility that pdev could be dereferenced and the function return before 
>> the ASSERT? If that is what you mean, I see your point. The ASSERT was 
>> placed there simply because we wanted to check that pdev != NULL first. See 
>> prior discussion at [1]. Hmm.. How about splitting the pdev-checking 
>> condition? E.g.:
>>
>>     if ( !pdev )
>>         return -ENODEV;
>>
>>     ASSERT(pcidevs_locked() || rw_is_locked(&pdev->domain->pci_lock));
>>
>>     if ( !pdev->msix )
>>         return -ENODEV;
> 
> I'm not specially worried about the position of the assert, those are
> just debug messages at the end.
> 
> One worry I have after further looking at the code, when called from
> ns16550_init_postirq(), does the device have pdev->domain set?
> 
> That case would satisfy the first condition of the assert, so won't
> attempt to dereference pdev->domain, but still would be good to ensure
> consistency here wrt the state of pdev->domain.

Indeed. How about this?

    if ( !pdev )
        return -ENODEV;

    ASSERT(pcidevs_locked() ||
           (pdev->domain && rw_is_locked(&pdev->domain->pci_lock)));

    if ( !pdev->msix )
        return -ENODEV;

And similarly in __pci_enable_msi(), without the !pdev->msix check. And 
similarly in pci_enable_msi(), which then should also gain its own if ( !pdev ) 
return -ENODEV; check.



 


Rackspace

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