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

Re: [PATCH] [RFC] xen/vpci: modify pci_get_pdev_by_domain() & pci_get_pdev()


  • To: Rahul Singh <Rahul.Singh@xxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 9 Aug 2022 17:13:16 +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=oKh30c55EpI/STGxmfeUdUzT9z+6VgDDJLq4DGKo834=; b=QMG6iYDpSMn7OLbLeEe6QBHreY+rqTMClDn757FN88Bfj5op31CVe44aMha+IDyXrJ81FRaiRptMJq7crg5eK7DlbajbdDiMwfmqFxi9qoT4ir0YTGvNFIHkKyQ/dsMwV531BchrRmtwJvuAlMiqBcokN2Q2sICaZouVMbH7AEjAv7z9O0k4AImGC4VZngD5VQ0Wg2eXvVdU/T9fcvFqRnZ/1KK6KTMBNuf/KOTfG0WH6EVj0agyj0YkbXywvsWC4OaIoThEHSwOQMlCXq1CSupl2sOqN3ppSky7qD8QXc+8QEFP5206GniZG+tIM8kkx/ux2WcqbsMkLgUWDDaWbQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YxrGtPS3DScUKvVpMc98LjcUFWRknmzjfyc77SBUcspWuWkMCbbO5D5TkOUZIgIKY50M24rr7X4DVHnhtodlFseoJoNAfKW10htcyVuzgQ7JADQh6cuqgrT/d6/oUYOTVYNLnDd4Vsk83W+lWQ77IsdgPezW3BYAvWonBwc/OARTh/UhnZGXYLDrn+/7d51p+PZyt7+axSHWW90V1OXHrHQ1t7nv8gtSiuc86VNdHvzhWCdJ+9ZQe5XcxcWu+zrI7r1wXCzqNnEPZh2rdsomluHn5fuY8dvdYUU62mhZDZWsT/uXYjMMshlCMhKYl0BTiCCrmy1VHlbbRCe6sV/uqg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Paul Durrant <paul@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 09 Aug 2022 15:13:27 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 09.08.2022 17:06, Rahul Singh wrote:
>> On 9 Aug 2022, at 11:02 am, Jan Beulich <jbeulich@xxxxxxxx> wrote:
>> On 05.08.2022 17:43, Rahul Singh wrote:
>>> --- a/xen/drivers/passthrough/pci.c
>>> +++ b/xen/drivers/passthrough/pci.c
>>> @@ -593,13 +593,10 @@ struct pci_dev *pci_get_pdev(int seg, int bus, int 
>>> devfn)
>>>             return NULL;
>>>     }
>>>
>>> -    do {
>>> -        list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list )
>>> -            if ( (pdev->bus == bus || bus == -1) &&
>>> -                 (pdev->devfn == devfn || devfn == -1) )
>>> -                return pdev;
>>> -    } while ( radix_tree_gang_lookup(&pci_segments, (void **)&pseg,
>>> -                                     pseg->nr + 1, 1) );
>>> +    list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list )
>>> +        if ( (pdev->bus == bus || bus == -1) &&
>>> +             (pdev->devfn == devfn || devfn == -1) )
>>> +            return pdev;
>>>
>>>     return NULL;
>>> }
>>> @@ -642,14 +639,11 @@ struct pci_dev *pci_get_pdev_by_domain(const struct 
>>> domain *d, int seg,
>>>             return NULL;
>>>     }
>>>
>>> -    do {
>>> -        list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list )
>>> -            if ( (pdev->bus == bus || bus == -1) &&
>>> -                 (pdev->devfn == devfn || devfn == -1) &&
>>> -                 (pdev->domain == d) )
>>> -                return pdev;
>>> -    } while ( radix_tree_gang_lookup(&pci_segments, (void **)&pseg,
>>> -                                     pseg->nr + 1, 1) );
>>> +    list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list )
>>> +        if ( (pdev->bus == bus || bus == -1) &&
>>> +             (pdev->devfn == devfn || devfn == -1) &&
>>> +             (pdev->domain == d) )
>>> +            return pdev;
>>>
>>>     return NULL;
>>> }
>>
>> Indeed present behavior is wrong - thanks for spotting. However in
>> both cases you're moving us from one wrongness to another: The
>> lookup of further segments _is_ necessary when the incoming "seg"
>> is -1 (and apparently when this logic was introduced that was the
>> only case considered).
> 
> If I understand correctly then fixed code should be like this:                
>                         
>    
> —snip— 
> ….                                                                  
>     if ( !pseg )                                                              
>   
>     {                                                                         
>   
>         if ( seg == -1 )                                                      
>   
>             radix_tree_gang_lookup(&pci_segments, (void **)&pseg, 0, 1);      
>   
>         if ( !pseg )                                                          
>   
>             return NULL;                                                      
>   
>                                                                               
>   
>         do {                                                                  
>   
>         list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list )       
>   
>             if ( (pdev->bus == bus || bus == -1) &&                           
>   
>                  (pdev->devfn == devfn || devfn == -1) )                      
>   
>                 return pdev;                                                  
>   
>         } while ( radix_tree_gang_lookup(&pci_segments, (void **)&pseg,       
>   
>                                      pseg->nr + 1, 1) );                      
>   
>         return NULL;                                                          
>   
>     }                                                                         
>   
>                                                                               
>   
>     list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list )           
>   
>         if ( (pdev->bus == bus || bus == -1) &&                               
>   
>              (pdev->devfn == devfn || devfn == -1) )                          
>   
>             return pdev;                                                      
>   
>                                                                               
>   
>     return NULL;                                                              
>   
> }  

That would about double the code in the functions. Imo all it takes
is to alter the while() conditions, prefixing what is there with
"seg == -1 &&".

Actually while looking there I've noticed the get_pseg() uses in
both functions aren't quite right for the "seg == -1" case either.
I'll make a patch there, which I think shouldn't collide with yours.

Jan



 


Rackspace

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