Re: [PATCH] vfio/pci: Use a private flag to prevent power state change with VFs

From: Raghavendra Rao Ananta

Date: Thu May 14 2026 - 13:37:37 EST


Hi Alex,

On Thu, May 7, 2026 at 2:09 PM Alex Williamson <alex@xxxxxxxxxxx> wrote:
>
> On Mon, 4 May 2026 22:41:42 +0000
> Raghavendra Rao Ananta <rananta@xxxxxxxxxx> wrote:
>
> > diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
> > index 3f8d093aacf8a..0e4a73e541d3a 100644
> > --- a/drivers/vfio/pci/vfio_pci_core.c
> > +++ b/drivers/vfio/pci/vfio_pci_core.c
> > @@ -271,7 +271,7 @@ int vfio_pci_set_power_state(struct vfio_pci_core_device *vdev, pci_power_t stat
> > int ret;
> >
> > /* Prevent changing power state for PFs with VFs enabled */
> > - if (pci_num_vf(pdev) && state > PCI_D0)
> > + if (vdev->sriov_pwr_active && state > PCI_D0)
> > return -EBUSY;
>
> AIUI, clearing the flag in the out_del: below can be lockless because
> at worst we'll deny a low power transition, but I think the test here
> for any state >PCI_D0 does expect memory_lock, right? Maybe this
> should be something like:
>
> if (state > PCI_D0) {
> lockdep_assert_held_write(&vdev->memory_lock);
> if (vdev->sriov_pwr_active)
> return -EBUSY;
> }
>
Yeah, that makes sense. I've applied this and other suggestions and
sent out a v2: https://lore.kernel.org/all/20260514173449.3282188-1-rananta@xxxxxxxxxx/

Thank you.
Raghavendra