• Abhishek Sahu's avatar
    vfio/pci: Change the PF power state to D0 before enabling VFs · f4162eb1
    Abhishek Sahu authored
    According to [PCIe v5 9.6.2] for PF Device Power Management States
    
     "The PF's power management state (D-state) has global impact on its
      associated VFs. If a VF does not implement the Power Management
      Capability, then it behaves as if it is in an equivalent
      power state of its associated PF.
    
      If a VF implements the Power Management Capability, the Device behavior
      is undefined if the PF is placed in a lower power state than the VF.
      Software should avoid this situation by placing all VFs in lower power
      state before lowering their associated PF's power state."
    
    From the vfio driver side, user can enable SR-IOV when the PF is in D3hot
    state. If VF does not implement the Power Management Capability, then
    the VF will be actually in D3hot state and then the VF BAR access will
    fail. If VF implements the Power Management Capability, then VF will
    assume that its current power state is D0 when the PF is D3hot and
    in this case, the behavior is undefined.
    
    To support PF power management, we need to create power management
    dependency between PF and its VF's. The runtime power management support
    may help with this where power management dependencies are supported
    through device links. But till we have such support in place, we can
    disallow the PF to go into low power state, if PF has VF enabled.
    There can be a case, where user first enables the VF's and then
    disables the VF's. If there is no user of PF, then the PF can put into
    D3hot state again. But with this patch, the PF will still be in D0
    state after disabling VF's since detecting this case inside
    vfio_pci_core_sriov_configure() requires access to
    struct vfio_device::open_count along with its locks. But the subsequent
    patches related to runtime PM will handle this case since runtime PM
    maintains its own usage count.
    
    Also, vfio_pci_core_sriov_configure() can be called at any time
    (with and without vfio pci device user), so the power state change
    and SR-IOV enablement need to be protected with the required locks.
    Signed-off-by: default avatarAbhishek Sahu <abhsahu@nvidia.com>
    Link: https://lore.kernel.org/r/20220518111612.16985-3-abhsahu@nvidia.comSigned-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
    f4162eb1
vfio_pci_core.c 58.4 KB