On 2025/6/18 22:27, Jan Beulich wrote:
> On 12.06.2025 11:29, Jiqian Chen wrote:
>> +static int vpci_ext_capability_hide(struct pci_dev *pdev, unsigned int cap)
>> +{
>> + const unsigned int offset = pci_find_ext_capability(pdev->sbdf, cap);
>> + struct vpci_register *r, *prev_r;
>> + struct vpci *vpci = pdev->vpci;
>> + uint32_t header, pre_header;
>> +
>> + if ( offset < PCI_CFG_SPACE_SIZE )
>> + {
>> + ASSERT_UNREACHABLE();
>> + return 0;
>> + }
>> +
>> + spin_lock(&vpci->lock);
>> + r = vpci_get_register(vpci, offset, 4);
>> + if ( !r )
>> + {
>> + spin_unlock(&vpci->lock);
>> + return -ENODEV;
>> + }
>> +
>> + header = (uint32_t)(uintptr_t)r->private;
>> + if ( offset == PCI_CFG_SPACE_SIZE )
>> + {
>> + if ( PCI_EXT_CAP_NEXT(header) <= PCI_CFG_SPACE_SIZE )
>> + r->private = (void *)(uintptr_t)0;
>> + else
>> + /*
>> + * The first extended capability (0x100) can not be removed from
>> + * the linked list, so instead mask its capability ID to return >> 0
>> + * and force OSes to skip it.
>> + */
>> + r->private = (void *)(uintptr_t)(header &
>> ~PCI_EXT_CAP_ID(header));
>
> Can we rely on OSes recognizing ID 0 as "just skip"? Since the size isn't
> encoded
> in the header, there might be issues lurking here.
I was not very confident about how to handle this situation.
This version was modified according to Roger's suggestions.
Maybe Roger can give you more explanation.
>
> Jan
--
Best regards,
Jiqian Chen.