|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH v5 5/5] vPCI: re-init extended-capabilities when MMCFG availability changed
On 04.03.2026 17:53, Roger Pau Monné wrote:
> On Wed, Mar 04, 2026 at 04:39:00PM +0100, Jan Beulich wrote:
>> On 04.03.2026 16:06, Roger Pau Monné wrote:
>>> On Wed, Feb 25, 2026 at 12:44:44PM +0100, Jan Beulich wrote:
>>>> @@ -349,22 +352,23 @@ int vpci_init_capabilities(struct pci_de
>>>> return 0;
>>>> }
>>>>
>>>> -void vpci_cleanup_capabilities(struct pci_dev *pdev)
>>>> +void vpci_cleanup_capabilities(struct pci_dev *pdev, bool ext_only)
>>>> {
>>>
>>> You could short-circuit the function here, ie:
>>>
>>> if ( ext_only && !is_hardware_domain(pdev->domain) )
>>> return;
>>>
>>> But I'm not sure that would simplify the code of the function much?
>>> Likewise for vpci_init_capabilities().
>>
>> Such a short-circuit would need replacing / dropping once DomU support is
>> added. I was hoping the chosen arrangement would make for a little less
>> churn at that time. I'll listen to your advice, though, just that the
>> question gives the impression you're not quite sure either.
>
> Yeah, I wasn't fully sure. IT would be nice if we could add those
> short circuits now, and then once domU support is in place we just
> remove teh shortcuts and it works for domU also. But I fear more
> changes will be needed anyway, at which point the short-circuit is
> not that attractive to use.
As per your other request (calling ->cleanup() even for DomU-s) the use of
is_hardware_domain() would go away anyway, and the function would be ready
for use for DomU-s as well.
>>>> +
>>>> + vpci_cleanup_capabilities(pdev, true);
>>>> +
>>>> + if ( vpci_remove_registers(pdev->vpci, PCI_CFG_SPACE_SIZE,
>>>> + PCI_CFG_SPACE_EXP_SIZE -
>>>> PCI_CFG_SPACE_SIZE) )
>>>> + ASSERT_UNREACHABLE();
>>>
>>> Ideally this would better be done the other way around. We first
>>> remove the handlers, and the cleanup the capabilities. Just to ensure
>>> no stray handler could end up having cached references to data that's
>>> been freed by vpci_cleanup_capabilities().
>>
>> And maybe not just that: For the hwdom case cleanup_rebar() adds new
>> handlers,
>> which we'd wrongly purge again right away. (Because we pass "false" for
>> "hide",
>> this isn't an active issue right now.)
>>
>>> And we should take the write_lock(&pdev->domain->pci_lock).
>>
>> Now this is a request that I'm struggling with some. I can see that callers
>> of vpci_{init,cleanup}_capabilities() assert that the lock is being held, yet
>> it's not quite clear to me why that's needed. Shouldn't vPCI internals all
>> synchronize on the vPCI lock of the domain?
>
> Right, the callers of the handlers already hold the locks, and the
> removal of the handlers should also hold the locks. The point of
> taking the d->pci_lock is to avoid the device from being removed
> while there are vPCI accesses against it being done. The vPCI lock is
> fine for vPCI internals, but functions that deal with addition or
> removal of devices need the d->pci_lock to avoid races with possibly
> freeing pdev->vpci while in use.
>
> I think you are right, and for the usage here (that doesn't add or
> remove pdev->vpci itself), the internal vPCI lock should be enough.
Well, we could take two positions: Either we say that as we're being called
from a context where the PCI device is being operated on anyway, we can
assume it can't go away. Then no further locking would be needed here. Or
we want to explicitly guard against that, in which case (seeing that
nothing is added / removed), d->pci_lock may want read-locking?
Jan
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |