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

Re: [PATCH v1 3/3] xen/vpci: header: filter PCI capabilities


  • To: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 15 Aug 2023 08:03:06 +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=/GRX0qUU4uTsh392m0DTImSMXbkGdK6Xq9xTe8sb/fo=; b=M8wihcxzSqW1PJo9u6vqLKJJgOIItMVl1P0mzXvtzf+uXE6BE68mOPyuy0w/YQQ5kaYujyk4tpZmgvITuvHNhhsuP9zbIVBTXK7m4g/ZeZgzfqDOUV5nFX2ABgLf9IqavT1Zu4rCDHHOHFERM1PPkmAyh8EqasvG4m8lsNUFGtlah8e4NgpHTpW8k7VNUApv7+jH5gInRuaN1kXY3gtFsGb7dPfgcaCpNRjN8oYkZkFeSFXGmOMRAciaIx+TuO0qj7Su0rvnceLAfYMd+peazvgO+gu/vXNes29ydRibnOE7RHf11hB4dJRE/qZLO3JJ2JQqN8Py/9fVxy7g6zSMFg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jBVrIs/LnpcoKd1IEpP7pZ+oUgmH3rmChfBl0+Aq2OrH+Cl02vjKIIBxqNUcdMYj8POqXWWr5i9LTFSzxu00V67/3eg3XdUANukDXs2SEnW5Dq0EUunDFmfrTa2w9JGuIJADgYJsJr9U4Q5xek2Nu84U1D00zlXKjgEGhjirOX3FjbF41y8BTH50ncMg9mpfd0AxCIfTdhNu3BqpQB6b9NzAH9kUL6insVKSXLA11p+SkX2tL2kXegLJVMHkRUqS8QHTeTByDx1kopyRkX3S/j4mnzjlmHaBzdghcqnduqlXsFjw0l3jncZTVJHQT2+KkXnl8juEKbwCKZhCPKxzBg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Roger Pau Monné <roger.pau@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 15 Aug 2023 06:03:44 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 14.08.2023 23:11, Stewart Hildebrand wrote:
> On 8/14/23 10:58, Jan Beulich wrote:
>> On 10.08.2023 21:12, Stewart Hildebrand wrote:
>>> --- a/xen/drivers/vpci/header.c
>>> +++ b/xen/drivers/vpci/header.c
>>> @@ -513,6 +513,36 @@ static void cf_check rom_write(
>>>          rom->addr = val & PCI_ROM_ADDRESS_MASK;
>>>  }
>>>
>>> +static uint8_t vpci_find_next_cap(pci_sbdf_t sbdf, uint8_t pos)
>>> +{
>>> +    uint8_t id;
>>> +    int ttl;
>>> +
>>> +    if ( pos < 0x40 )
>>> +        pos = pci_conf_read8(sbdf, PCI_CAPABILITY_LIST);
>>> +    else
>>> +        pos = pci_conf_read8(sbdf, pos + PCI_CAP_LIST_NEXT);
>>
>> How about avoiding the if/else by having the caller pass in a useful
>> value, rather than PCI_CAPABILITY_LIST? I.e.
>>
>> #define PCI_CAP_LIST_FIRST (PCI_CAPABILITY_LIST - PCI_CAP_LIST_NEXT)
> 
> OK, yes, I will eliminate the if/else.
> 
>>
>>> +    for ( ttl = 48; ttl > 0; ttl-- )
>>> +    {
>>> +        if ( pos < 0x40 )
>>> +            break;
>>> +
>>> +        pos &= ~3;
>>> +        id = pci_conf_read8(sbdf, pos + PCI_CAP_LIST_ID);
>>> +
>>> +        if ( id == 0xff )
>>> +            break;
>>> +
>>> +        if ( id == PCI_CAP_ID_MSI ||
>>> +             id == PCI_CAP_ID_MSIX )
>>> +            return pos;
>>
>> Can this please start out as switch() right away?
> 
> Yes, certainly.
> 
>>> +        pos = pci_conf_read8(sbdf, pos + PCI_CAP_LIST_NEXT);
>>> +    }
>>> +    return 0;
>>> +}
>>
>> Nit: Blank line please ahead of main function return point.
>>
>> I also notice that the function isn't really vPCI-specific in any way
>> (except for the specific PCI_CAP_ID_* compared against). Would it
>> perhaps make sense to have it be a general utility function, living in
>> xen/drivers/pci/pci.c next to its relatives?
> 
> Yes. The the PCI_CAP_ID_* comparisons were the only reason I initially 
> decided not to use the existing pci_find_next_cap() function, which performs 
> an almost identical task. I just noticed that the existing 
> pci_find_next_cap() doesn't appear to have any callers. Given this, I'd 
> prefer to modify the existing pci_find_next_cap() to suit our needs.

Please modify the function only if it then remains (easily) usable for
its original purpose. Even if right now without callers, it exists for
a reason. (How to deal with the Misra unreachable code aspect in such
cases remains to be decided.)

Jan



 


Rackspace

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