[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: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Rahul Singh <Rahul.Singh@xxxxxxx>
  • Date: Tue, 9 Aug 2022 15:06:33 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; 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=vK5HQKrElDf0iUkqMtc+bm6/H6U2KoyEA3OrM1FR6Xk=; b=KzGincdycrvzwyF5LdN1S6mN494Nz1bir2Vk5Yk7UgC7XibWh7a85HFxkMsf2J0ir4kknFsZX9Zb+TyKL9BHJHw+iBEZcdPK6CI8W8+atwh6nOCklYownhafbVFMNFqX9QJg88uSk4qtlLsPkfTtgTR/fDCR60UiTPVtv0eKf5YGW9QMhrKz1Y7tyMHwsMiRdTZHJa3Kw5HJthgJYkM+Yov+Z6kPDKyo92hZwPOIbpP3vNEshFGHdLW/NhfrZPvJHkKZK855mHL64kjHUAjm9Cq+9/99TX/firgMUHAm+UEut0oUFpAu5kpf8zRc8EWrTTIzpFz3r9E0P97yoMt36w==
  • 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=vK5HQKrElDf0iUkqMtc+bm6/H6U2KoyEA3OrM1FR6Xk=; b=J8u6mCzCPPJ7/oBDeNAUk7+FiUx6GTUWbpBJsgFO4dWGCSDlwm2e0YeidSWGAi43/9FLkXjBk9UBPHk/M8ujTui6QXHrbt+gQqw5/C7byFFdquoaBNvPFvJnT7EJ9F80kvV2FtA/9zfDdlvjY6jdN6Oy6WaSRxUrkMzVz4YOpuE6aIPBnBxiKgm/H7nos0lQIEnrgcnLh+tFiphDkwLZhoEJednL7iYvZIVZbXqaduZAnmvko9fhaLQlE/0TC32aOnnB8U/KlG7RO+tGozI8jT5oC8PKPJyYkP8oDK4ylMJ5ZrY9waDjnyLnKEp8HffAgqQt2X+dC2Jk3EelSPHjRw==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=Mmg29+2AipvE1d/pFXAI3ZvHMEQRCNRmKU5am/t+EaiQQxaqOClsgB72Q5OayI4AEvZqtZsAaRL8H5/1Gpu08iiyDvrCRSCS+7yJysr6YZ9sPrnfuKd5osIZUewoZxFHSbcCaIQSKp7iMuc0U/4m6d2VU9EWiFK+28r5fREOvVxTI63dSrhP1f46anTh54r+S0ZHA5cemhMBG+06kRjuIzHQiK/48zGFpkKppDgsNfNX7IttMQboP0xIuxopFTptxVQtN7sxiGsG+FdGUqw7JCp1b+/n6wEzS30oxfzHcbawbImXHsQ3RF1LfX7/lN+fhUpX6qvj62lMgwZ0G5KcXA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qa0CG0Bn4BpL4azJ+juDiAfGPlBQfmhyU3yr/R+EN3J5pRtOcDfeoJqf7qfoSg3riehyt9QS/RpnVQpQc5BmV7XunkNuz0NhjpuBH0LCYKMp+l9Q4g6tPZkO4TsCAizQAUvxfabZkfdC5B4O47rLnqOhSMmMaRqrzkuXl+jmkF7fjbOxQvS9V7FjHyxJZa8+HFBkk5bfC9efV9QH0r3v92oEa6JhbMGn+Jfj2SaJ4wZ6+oQL7F4EAU7HD/RftvZ8fRB99lFM4lWmpamOTlZy15NL3NOOdQLet30qIUobzSfalBJlWzH/1kqJaLjPd7rAggrrWfDxu9tSonuiXUhRKw==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.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:07:08 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHYqOI28IdG0PHJfUiTCQKz3s6xa62mXF0AgABVF4A=
  • Thread-topic: [PATCH] [RFC] xen/vpci: modify pci_get_pdev_by_domain() & pci_get_pdev()

Hi Jan,

> On 9 Aug 2022, at 11:02 am, Jan Beulich <jbeulich@xxxxxxxx> wrote:
> 
> On 05.08.2022 17:43, Rahul Singh wrote:
>> pci_get_pdev_by_domain() and pci_get_pdev() functions find the pdev in
>> the pseg list. If pdev is not in the pseg list, the functions will try
>> to find the pdev in the next segment. It is not right to find the pdev
>> in the next segment as this will result in the corruption of another
>> device in a different segment with the same BDF.
>> 
>> An issue that was observed when implementing the PCI passthrough on ARM.
>> When we deassign the device from domU guest, the device is assigned
>> to dom_io and not to dom0, but the tool stack that runs in dom0 will try
>> to configure the device from dom0. vpci will find the device based on
>> conversion of GPA to SBDF and will try to find the device in dom0, but
>> because device is assigned to dom_io, pci_get_pdev_by_domain() will
>> return pdev with same BDF from next segment.
>> 
>> Signed-off-by: Rahul Singh <rahul.singh@xxxxxxx>
> 
> This wants a Fixes: tag.

Ack. 
> 
>> --- 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;                                                                
}  


> 
> As an aside - my mail UI shows me unexpected threading between
> this patch and two subsequent ones. If they were actually meant
> to be a series, can they please be marked n/3?

Sorry for the confusion all the patches are independent of each other.
Maybe this is because I send them via a single git send-mail command.
I will fix that in the next version. 

Regards,
Rahul

 


Rackspace

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