1. 09 Mar, 2022 1 commit
  2. 07 Mar, 2022 1 commit
  3. 03 Mar, 2022 10 commits
  4. 27 Feb, 2022 7 commits
  5. 22 Feb, 2022 3 commits
    • Abhishek Sahu's avatar
      vfio/pci: wake-up devices around reset functions · 26a17b12
      Abhishek Sahu authored
      If 'vfio_pci_core_device::needs_pm_restore' is set (PCI device does
      not have No_Soft_Reset bit set in its PMCSR config register), then the
      current PCI state will be saved locally in
      'vfio_pci_core_device::pm_save' during D0->D3hot transition and same
      will be restored back during D3hot->D0 transition. For reset-related
      functionalities, vfio driver uses PCI reset API's. These
      API's internally change the PCI power state back to D0 first if
      the device power state is non-D0. This state change to D0 will happen
      without the involvement of vfio driver.
      
      Let's consider the following example:
      
      1. The device is in D3hot.
      2. User invokes VFIO_DEVICE_RESET ioctl.
      3. pci_try_reset_function() will be called which internally
         invokes pci_dev_save_and_disable().
      4. pci_set_power_state(dev, PCI_D0) will be called first.
      5. pci_save_state() will happen then.
      
      Now, for the devices which has NoSoftRst-, the pci_set_power_state()
      can trigger soft reset and the original PCI config state will be lost
      at step (4) and this state cannot be restored again. This original PCI
      state can include any setting which is performed by SBIOS or host
      linux kernel (for example LTR, ASPM L1 substates, etc.). When this
      soft reset will be triggered, then all these settings will be reset,
      and the device state saved at step (5) will also have this setting
      cleared so it cannot be restored. Since the vfio driver only exposes
      limited PCI capabilities to its user, so the vfio driver user also
      won't have the option to save and restore these capabilities state
      either and these original settings will be permanently lost.
      
      For pci_reset_bus() also, we can have the above situation.
      The other functions/devices can be in D3hot and the reset will change
      the power state of all devices to D0 without the involvement of vfio
      driver.
      
      So, before calling any reset-related API's, we need to make sure that
      the device state is D0. This is mainly to preserve the state around
      soft reset.
      
      For vfio_pci_core_disable(), we use __pci_reset_function_locked()
      which internally can use pci_pm_reset() for the function reset.
      pci_pm_reset() requires the device power state to be in D0, otherwise
      it returns error.
      
      This patch changes the device power state to D0 by invoking
      vfio_pci_set_power_state() explicitly before calling any reset related
      API's.
      
      Fixes: 51ef3a00 ("vfio/pci: Restore device state on PM transition")
      Signed-off-by: default avatarAbhishek Sahu <abhsahu@nvidia.com>
      Link: https://lore.kernel.org/r/20220217122107.22434-3-abhsahu@nvidia.comSigned-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
      26a17b12
    • Abhishek Sahu's avatar
      vfio/pci: fix memory leak during D3hot to D0 transition · eadf88ec
      Abhishek Sahu authored
      If 'vfio_pci_core_device::needs_pm_restore' is set (PCI device does
      not have No_Soft_Reset bit set in its PMCSR config register), then
      the current PCI state will be saved locally in
      'vfio_pci_core_device::pm_save' during D0->D3hot transition and same
      will be restored back during D3hot->D0 transition.
      For saving the PCI state locally, pci_store_saved_state() is being
      used and the pci_load_and_free_saved_state() will free the allocated
      memory.
      
      But for reset related IOCTLs, vfio driver calls PCI reset-related
      API's which will internally change the PCI power state back to D0. So,
      when the guest resumes, then it will get the current state as D0 and it
      will skip the call to vfio_pci_set_power_state() for changing the
      power state to D0 explicitly. In this case, the memory pointed by
      'pm_save' will never be freed. In a malicious sequence, the state changing
      to D3hot followed by VFIO_DEVICE_RESET/VFIO_DEVICE_PCI_HOT_RESET can be
      run in a loop and it can cause an OOM situation.
      
      This patch frees the earlier allocated memory first before overwriting
      'pm_save' to prevent the mentioned memory leak.
      
      Fixes: 51ef3a00 ("vfio/pci: Restore device state on PM transition")
      Signed-off-by: default avatarAbhishek Sahu <abhsahu@nvidia.com>
      Link: https://lore.kernel.org/r/20220217122107.22434-2-abhsahu@nvidia.comSigned-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
      eadf88ec
    • Alex Williamson's avatar
      vfio/pci: Stub vfio_pci_vga_rw when !CONFIG_VFIO_PCI_VGA · 6e031ec0
      Alex Williamson authored
      Resolve build errors reported against UML build for undefined
      ioport_map() and ioport_unmap() functions.  Without this config
      option a device cannot have vfio_pci_core_device.has_vga set,
      so the existing function would always return -EINVAL anyway.
      Reported-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
      Link: https://lore.kernel.org/r/20220123125737.2658758-1-geert@linux-m68k.org
      Link: https://lore.kernel.org/r/164306582968.3758255.15192949639574660648.stgit@omenSigned-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
      6e031ec0
  6. 20 Feb, 2022 13 commits
  7. 19 Feb, 2022 5 commits