[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 16:00:01 +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=1KpjXxok5CH/DHk54ul3iEJBpe4C3OhxMRY1cptw8V8=; b=Zz+F5NQ5C5ijteYC90qhyWPrqw9YhhxPkZd4vycTrYiVYdfZV/rxiFPiK6MSK5/cE/TSlOFznf/3H7+FINfJWHslNYpeRgGJek4u4uDlNwPagt6BXM/wTZrFaSntkI293laRYuvjB4I+dgKIog8Glgy2kBMmq1m5JRvBi6u45Xv993WHP94R1UE/2nB/wkWIK/bghSv1njScj2BgKKiVynOJTlSOv7yT/VR0SbVhNqJWZqYJ5sZa0YG1Hu0brZ3/Z1XFHOn1bwmEpKcu/hG7RpGvhRSsC6UQsyLi9MzlCcwnH9pNI9t5J0GhJGhJkRJb8fFttbefwKeadgvQEotsXQ==
- 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=1KpjXxok5CH/DHk54ul3iEJBpe4C3OhxMRY1cptw8V8=; b=mjHiCuR/U2imriXVd8Rfte4znWQ7yo7/vaaoMkkMuO6eI9cSb9JNvN1GMHUFgb4mAM/DbSMmVnKqUEznBtvzGewU43iPyPiKZQba20mEctqh3gddHd549iW3BSQ/09pMJCri59oLyY/cDlQduR+Dd3DlfNMIK0eVPFD+rWH0gaagvmhIYxUPbmbjTk1B3n9xsG5d4T07fZLrSo0H6suzQoYFM9UgYlZs36MQFQSx2BD2/2/3FeBDsRRcKq+EODrFrqOn/yjfJtxmxibZ4CsMNlPd0GvAe7uo3QCZz1tkfqby0RTTaLiz48k1Kku0XGTqmuyMORKfo/Q6LkSyLTwA0A==
- Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=a1J1KAJ8N392GvQRdBtGJ4ye4iBm6Y+yjopbsYk/SQEGDnkhlf9EeSPQ89Z0xU5pWJDCEGgR3HY0aUqn9Ybq6oXcGW6Dvsz7+KXB+S2pAINuEHr//fNU5PNuYcRDVYw82dV85NWCzXDUBX7xR2gAl3aXSHcDlUz0I/DLEhInL2AGuRzCfzzVQNGQdssFVutz0t/C5rhO+UjRDyVgiNRSvEY1vzhP52/tCwnxwaEhh2X+6TwkX2v14MjdSx6G3HijLxLN0Dw2bSrBz/ZnEYqJMCamTz5WxsuLm5G9/Va/jFXzKru++80TOsg5U9jhz5C/z43HRQndQ7okSAhOxbEZmA==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BuNLPP2HXPRyZ6SbGLvW30FjUapSfSdfs5vw/qRuMTcji32RjBwHuWf2wiuBOmYrUN43fkPdlfdUz7zQAuBTCGMm6XnYl0YjijEV3btMZ/1bFPafpuhLz84yPcpYOya3vOyzpZQSjJu4OMwRyeh2BBCKuxzFaYduPYweYg8keysoOBBg8cisQ8e2ksKMLzSVL55KQP0CcpUH7YQSzIiUSUjr7Zmk+9RFAxJvUyT28MQ0m1jBlzkeXsvm9FW+zr5jxodKYEARGq7cx/HBy/RbEG+cNSjNBqL1uyPRZGMz5WuTOaoTlrdX5xrkWDZYXfuxXPXFCH+6fx7d978ke1aV0w==
- 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 16:00:16 +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: AQHYqOI28IdG0PHJfUiTCQKz3s6xa62mXF0AgABVF4CAAAHhAIAADQ4A
- Thread-topic: [PATCH] [RFC] xen/vpci: modify pci_get_pdev_by_domain() & pci_get_pdev()
Hi Jan,
> On 9 Aug 2022, at 4:13 pm, Jan Beulich <jbeulich@xxxxxxxx> wrote:
>
> 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 &&".
I agree with you this will avoid duplication of the code.
>
> 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.
Ok. I will test the patch once you sent it..
Regards,
Rahul
|