All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
	Stewart Hildebrand <stewart.hildebrand@amd.com>
Subject: Re: [PATCH v5 5/5] vPCI: re-init extended-capabilities when MMCFG availability changed
Date: Thu, 5 Mar 2026 10:19:38 +0100	[thread overview]
Message-ID: <aalKqq0ioTcU9Mdh@macbook.local> (raw)
In-Reply-To: <5a16e95b-25a5-477d-8445-4843d2fba576@suse.com>

On Thu, Mar 05, 2026 at 09:40:32AM +0100, Jan Beulich wrote:
> 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.

OK, so that one is (possibly) sorted then.

> >>>> +
> >>>> +    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?

In this context the caller is already holding the pcidevs lock, so
there's no risk of the device being de-assigned.

My reasoning for taking the d->pci_lock in write mode was to prevent
any concurrent access to vPCI while the changes to the emulated config
space is taken place, but you are right that the vPCI lock if used
properly should prevent races.

Thanks, Roger.


  reply	other threads:[~2026-03-05  9:20 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-25 11:41 [PATCH v5 0/5] vPCI: extended capability handling Jan Beulich
2026-02-25 11:43 ` [PATCH v5 1/5] vPCI: introduce private header Jan Beulich
2026-02-26  3:33   ` Stewart Hildebrand
2026-03-03 16:44   ` Roger Pau Monné
2026-03-03 16:48     ` Jan Beulich
2026-02-25 11:43 ` [PATCH v5 2/5] vPCI: move vpci_init_capabilities() to a separate file Jan Beulich
2026-02-25 11:43 ` [PATCH v5 3/5] vPCI: move capability-list init Jan Beulich
2026-02-25 11:44 ` [PATCH v5 4/5] vPCI/ReBAR: improve cleanup Jan Beulich
2026-03-04 13:46   ` Roger Pau Monné
2026-02-25 11:44 ` [PATCH v5 5/5] vPCI: re-init extended-capabilities when MMCFG availability changed Jan Beulich
2026-03-04 15:06   ` Roger Pau Monné
2026-03-04 15:39     ` Jan Beulich
2026-03-04 16:53       ` Roger Pau Monné
2026-03-05  8:40         ` Jan Beulich
2026-03-05  9:19           ` Roger Pau Monné [this message]
2026-03-05  9:00     ` Jan Beulich
2026-03-05  9:22       ` Roger Pau Monné
2026-03-05  9:45         ` Jan Beulich
2026-03-05 10:20           ` Roger Pau Monné

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aalKqq0ioTcU9Mdh@macbook.local \
    --to=roger.pau@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=stewart.hildebrand@amd.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.