From: Alex Williamson <alex@shazbot.org>
To: Samiullah Khawaja <skhawaja@google.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>,
bhelgaas@google.com, Kevin Tian <kevin.tian@intel.com>,
Leon Romanovsky <leon@kernel.org>,
dmatlack@google.com, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, alex@shazbot.org
Subject: Re: [RFC PATCH 1/1] vfio/pci: Disable sriov on PF device close
Date: Wed, 12 Aug 2026 11:19:43 -0600 [thread overview]
Message-ID: <20260812111943.31cf9cea@shazbot.org> (raw)
In-Reply-To: <anpJrnR6Lbmgqad-@google.com>
On Tue, 11 Aug 2026 20:31:49 +0000
Samiullah Khawaja <skhawaja@google.com> wrote:
> On Mon, Aug 10, 2026 at 09:32:23AM -0600, Alex Williamson wrote:
> >On Thu, 6 Aug 2026 16:47:39 -0300
> >Jason Gunthorpe <jgg@ziepe.ca> wrote:
> >> On Wed, Aug 05, 2026 at 09:03:23AM -0600, Alex Williamson wrote:
> >> > It's possible there are gaps that closing the PF can interrupt the VFs
> >> > and we need to defer a reset until the VFs are closed,
> >>
> >> Oh definately, when running in a SRIOV mode it is really problematic
> >> for the PF to reset while there are any active VFs. The PF controls a
> >> number of shared items (MMIO, ATS, etc) and when it blips everyone is
> >> at risk of unexpected fairly catastrophic system crashing errors
> >> related to the shared items going away.
> >>
> >> So resetting the PF device unconditionally when vfio closes is
> >> definately wrong in principal. I can see it maybe working for simple
> >> systems, especially ones that don't MCE..
> >>
> >> I don't think we can skip the PF reset on close because of dev_set
> >> reasons and leave a rouge device for the next user, so the thing looks
> >> somewhat troubled?
> >
> >This is what our vf_token model would handle, if we could use it.
> >Re-open with VFs in use through vfio-pci requires the vf_token
> >proof/opt-in. Re-open with no VFs in use could reset the PF, but we
> >can't account for VFs bound to in-kernel drivers.
>
> I think even with this a PF reset blip can be catastrophic for the VFs
> in some usecases or devices. Maybe we need an opt-in where the PF driver
> can specify that keeping the SRIOV enabled during PF reset is
> catastrophic for it and so the reopen is not preferred by it?
AFAICT, there's really no case where a VF can be operating
independently from the PF that a PF reset is not catastrophic. Per the
PCI spec, the default SR-IOV capability state is disabled, so
post-reset the PF is effectively bringing up fresh, scrubbed VFs.
> >> Adding the sriov disable here at least makes it defensibly safe, that
> >> we do still clear the PF on close, and we don't take risks that the
> >> active VFs will crash the system during the FLR blip.
> >>
> >> Though I understand it was not the original intention, I feel we have
> >> ended up in a strange place with the SRIOV PF feature ..
> >
> >I think we have 3 potential options for PF reset:
> >
> > a) All resets are blocked or deferred while SR-IOV is active.
> >
> > b) VF mappings are zapped/invalidated at PF reset and require
> > coordination to be reinstated.
> >
> > c) VFs are torn down on all PF resets.
> >
> >Option (a) is complex and doesn't look like stable material. A deferred
> >reset on .close needs to materialize on .remove or .sriov_configure
> >(and of course .open), but to allow in-kernel VF drivers we can't rely
> >on vfio usage counts, or even our vf-token trust boundaries, which is
> >what leads to the .sriov_configure hook since we need to take advantage
> >of every opportunity to issue a deferred reset when SR-IOV is not
> >active when we can only rely on the PF state.
>
> In my cover letter I pointed out that this problem probably exists in
> the in-kernel drivers (or PCI core) level also. For example an SRIOV PF
> driverA can reset the PF while VFs are bound to driverB. This makes me
> wonder whether we should fix this at PCI core level to maintain the same
> policy for all drivers when it comes to PF/VF lifecycle? Basically,
>
> option1) On PF reset when there is SRIOV enabled, PCI core returns
> -EBUSY from the reset API.
>
> option2) On PF reset, PCI core disables SRIOV. This might be tricky as
> some drivers might block this waiting for VF driver tear down and
> remove.
>
> We probably cannot do this as default policy as it will break the
> vfio-pci model where the PF can be reopened as you mentioned above. I
> think if we go down this route, we would need some way of establishing
> trust and lifecycle rules?
The PCI-core level change is the same conclusion I came to and posted
in the RFC[1]. I think our only practical option is (1), function
scoped resets must be rejected on PFs with SR-IOV enabled. This is
compatible with the re-open scenario, but leans on the fact that resets
are best effort.
The vf_token continues to form the boundary of trust for VFs operating
within the vfio framework. The adversarial device support Kevin
referenced could influence the security posture of the driver taking on
an untrusted device like this, but I don't currently see much
opportunity to introduce coordination between vfio and non-vfio drivers.
[1]https://lore.kernel.org/all/20260812045325.2733631-1-alex.williamson@nvidia.com/
> >Option (b) is potentially more simple, it implements the blocking of
> >access on reset in the kernel for enforcement, but defers the
> >coordination of reinstantiating mappings to userspace, which is really
> >how the vf_token model is intended to work. This is incompatible with
> >in-kernel VF drivers, which I think means tainting on VF unbind from
> >vfio-pci and those working outside the model would tread carefully.
>
> While this might solve the issue for scenarios where the MMIO of these
> VFs is mapped or exported (dmabufs), this might not be enough as the
> software still remains out of sync as compared to the state of the
> device.
This is the same problem as the .reset_prepare/.reset_done hooks,
invalidating the dma-buf only prevents the machine check, it doesn't
necessarily allow for ongoing operation. This gets back to the point
that all PF resets are catastrophic for the VF driver.
> >Option (c) is the more heavy handed approach, it means that a PF driver
> >cannot fail or exit and re-attach. We have existing logic that handles
> >a PF driver re-opening the PF device with active VFs and authenticating
> >the vf_token (logic also broken by in-kernel VF drivers that bypass the
> >vf_token mechanics). There also appears to be significant locking
> >challenges in this approach, ex. the inversion of getting the device
> >lock for SR-IOV teardown from the ioctl, config space, and .close
> >contexts.
>
> I think this can be a reasonable opt-in option that the PF drivers can
> use to indicate that on PF reset keeping the VFs alive is catastrophic
> for it and it does not want to reconnect to the VFs. If we want to go
> for this one, I can maybe try figure out a way to break the locking
> issues.
My exploration of this space suggests the locking issues run pretty
deep with this approach.
> Or we could certainly do this in a deferred way that is somewhat similar
> to the option (a). Basically PF openers can opt-in to not reset the PF
> on close if the VFs are enabled, and teardown the VFs on subsequent
> .open or .remove. This at least gives the system administrator (or
> scripts) opportunity to teardown the VFs in a proper way.
But VFs can be enabled before the PF is opened. If we're strictly
within the vfio-pci model of using VFs, VFs cannot be opened until the
vf_token is known, which requires a PF driver to set the token.
However, binding VFs to in-kernel drivers entirely removes them from
that ordering and coordination. The disposition of the VFs is changed
without PF driver involvement.
I don't see how we really have an opportunity to create an opt-in
beyond a module level global opt-in, but even then it's not clear
what the opt-in can realistically choose. Thanks,
Alex
prev parent reply other threads:[~2026-08-12 17:19 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 0:33 [RFC PATCH 0/1] vfio/pci: Disable sriov on PF device close Samiullah Khawaja
2026-08-05 0:33 ` [RFC PATCH 1/1] " Samiullah Khawaja
2026-08-05 1:03 ` sashiko-bot
2026-08-05 9:34 ` Tian, Kevin
2026-08-10 21:47 ` Samiullah Khawaja
2026-08-05 15:03 ` Alex Williamson
2026-08-06 19:47 ` Jason Gunthorpe
2026-08-10 15:32 ` Alex Williamson
2026-08-11 9:52 ` Tian, Kevin
2026-08-11 13:59 ` Jason Gunthorpe
2026-08-12 16:00 ` Alex Williamson
2026-08-11 20:31 ` Samiullah Khawaja
2026-08-12 17:19 ` Alex Williamson [this message]
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=20260812111943.31cf9cea@shazbot.org \
--to=alex@shazbot.org \
--cc=bhelgaas@google.com \
--cc=dmatlack@google.com \
--cc=jgg@ziepe.ca \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=skhawaja@google.com \
/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.