27 Sep, 2022

1 commit

  • This is the 5.15.70 stable release

    * tag 'v5.15.70': (2444 commits)
    Linux 5.15.70
    ALSA: hda/sigmatel: Fix unused variable warning for beep power change
    cgroup: Add missing cpus_read_lock() to cgroup_attach_task_all()
    ...

    Signed-off-by: Jason Liu

    Conflicts:
    arch/arm/boot/dts/imx6ul.dtsi
    arch/arm/mm/mmu.c
    arch/arm64/boot/dts/freescale/imx8mp-evk.dts
    drivers/gpu/drm/imx/dcss/dcss-kms.c
    drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c
    drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h
    drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
    drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
    drivers/soc/fsl/Kconfig
    drivers/soc/imx/gpcv2.c
    drivers/usb/dwc3/host.c
    net/dsa/slave.c
    sound/soc/fsl/imx-card.c

    Jason Liu
     

15 Sep, 2022

1 commit

  • commit 873aefb376bbc0ed1dd2381ea1d6ec88106fdbd4 upstream.

    There's currently a reference count leak on the zero page. We increment
    the reference via pin_user_pages_remote(), but the page is later handled
    as an invalid/reserved page, therefore it's not accounted against the
    user and not unpinned by our put_pfn().

    Introducing special zero page handling in put_pfn() would resolve the
    leak, but without accounting of the zero page, a single user could
    still create enough mappings to generate a reference count overflow.

    The zero page is always resident, so for our purposes there's no reason
    to keep it pinned. Therefore, add a loop to walk pages returned from
    pin_user_pages_remote() and unpin any zero pages.

    Cc: stable@vger.kernel.org
    Reported-by: Luboslav Pivarc
    Reviewed-by: David Hildenbrand
    Link: https://lore.kernel.org/r/166182871735.3518559.8884121293045337358.stgit@omen
    Signed-off-by: Alex Williamson
    Signed-off-by: Greg Kroah-Hartman

    Alex Williamson
     

25 Aug, 2022

1 commit

  • [ Upstream commit 6641085e8d7b3f061911517f79a2a15a0a21b97b ]

    On buffer resize failure, vfio_info_cap_add() will free the buffer,
    report zero for the size, and return -ENOMEM. As additional
    hardening, also clear the buffer pointer to prevent any chance of a
    double free.

    Signed-off-by: Schspa Shi
    Reviewed-by: Cornelia Huck
    Link: https://lore.kernel.org/r/20220629022948.55608-1-schspa@gmail.com
    Signed-off-by: Alex Williamson
    Signed-off-by: Sasha Levin

    Schspa Shi
     

30 Jun, 2022

1 commit

  • This is the 5.15.41 stable release

    * tag 'v5.15.41': (1977 commits)
    Linux 5.15.41
    usb: gadget: uvc: allow for application to cleanly shutdown
    usb: gadget: uvc: rename function to be more consistent
    ...

    Signed-off-by: Jason Liu

    Conflicts:
    arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi
    arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi
    arch/arm64/configs/defconfig
    drivers/clk/imx/clk-imx8qxp-lpcg.c
    drivers/dma/imx-sdma.c
    drivers/gpu/drm/bridge/nwl-dsi.c
    drivers/mailbox/imx-mailbox.c
    drivers/net/phy/at803x.c
    drivers/tty/serial/fsl_lpuart.c
    security/keys/trusted-keys/trusted_core.c

    Jason Liu
     

20 Apr, 2022

1 commit

  • [ Upstream commit 1ef3342a934e235aca72b4bcc0d6854d80a65077 ]

    get_pf_vdev() tries to check if a PF is a VFIO PF by looking at the driver:

    if (pci_dev_driver(physfn) != pci_dev_driver(vdev->pdev)) {

    However now that we have multiple VF and PF drivers this is no longer
    reliable.

    This means that security tests realted to vf_token can be skipped by
    mixing and matching different VFIO PCI drivers.

    Instead of trying to use the driver core to find the PF devices maintain a
    linked list of all PF vfio_pci_core_device's that we have called
    pci_enable_sriov() on.

    When registering a VF just search the list to see if the PF is present and
    record the match permanently in the struct. PCI core locking prevents a PF
    from passing pci_disable_sriov() while VF drivers are attached so the VFIO
    owned PF becomes a static property of the VF.

    In common cases where vfio does not own the PF the global list remains
    empty and the VF's pointer is statically NULL.

    This also fixes a lockdep splat from recursive locking of the
    vfio_group::device_lock between vfio_device_get_from_name() and
    vfio_device_get_from_dev(). If the VF and PF share the same group this
    would deadlock.

    Fixes: ff53edf6d6ab ("vfio/pci: Split the pci_driver code out of vfio_pci_core.c")
    Signed-off-by: Jason Gunthorpe
    Link: https://lore.kernel.org/r/0-v3-876570980634+f2e8-vfio_vf_token_jgg@nvidia.com
    Signed-off-by: Alex Williamson
    Signed-off-by: Sasha Levin

    Jason Gunthorpe
     

14 Apr, 2022

1 commit

  • [ Upstream commit 6e031ec0e5a2dda53e12e0d2a7e9b15b47a3c502 ]

    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: Geert Uytterhoeven
    Link: https://lore.kernel.org/r/20220123125737.2658758-1-geert@linux-m68k.org
    Link: https://lore.kernel.org/r/164306582968.3758255.15192949639574660648.stgit@omen
    Signed-off-by: Alex Williamson
    Signed-off-by: Sasha Levin

    Alex Williamson
     

08 Apr, 2022

2 commits

  • [ Upstream commit 26a17b12d7f3dd8a7aa45a290e5b46e9cc775ddf ]

    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: 51ef3a004b1e ("vfio/pci: Restore device state on PM transition")
    Signed-off-by: Abhishek Sahu
    Link: https://lore.kernel.org/r/20220217122107.22434-3-abhsahu@nvidia.com
    Signed-off-by: Alex Williamson
    Signed-off-by: Sasha Levin

    Abhishek Sahu
     
  • [ Upstream commit eadf88ecf6ac7d6a9f47a76c6055d9a1987a8991 ]

    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: 51ef3a004b1e ("vfio/pci: Restore device state on PM transition")
    Signed-off-by: Abhishek Sahu
    Link: https://lore.kernel.org/r/20220217122107.22434-2-abhsahu@nvidia.com
    Signed-off-by: Alex Williamson
    Signed-off-by: Sasha Levin

    Abhishek Sahu
     

02 Nov, 2021

2 commits


24 Sep, 2021

1 commit


03 Sep, 2021

1 commit

  • Pull VFIO updates from Alex Williamson:

    - Fix dma-valid return WAITED implementation (Anthony Yznaga)

    - SPDX license cleanups (Cai Huoqing)

    - Split vfio-pci-core from vfio-pci and enhance PCI driver matching to
    support future vendor provided vfio-pci variants (Yishai Hadas, Max
    Gurtovoy, Jason Gunthorpe)

    - Replace duplicated reflck with core support for managing first open,
    last close, and device sets (Jason Gunthorpe, Max Gurtovoy, Yishai
    Hadas)

    - Fix non-modular mdev support and don't nag about request callback
    support (Christoph Hellwig)

    - Add semaphore to protect instruction intercept handler and replace
    open-coded locks in vfio-ap driver (Tony Krowiak)

    - Convert vfio-ap to vfio_register_group_dev() API (Jason Gunthorpe)

    * tag 'vfio-v5.15-rc1' of git://github.com/awilliam/linux-vfio: (37 commits)
    vfio/pci: Introduce vfio_pci_core.ko
    vfio: Use kconfig if XX/endif blocks instead of repeating 'depends on'
    vfio: Use select for eventfd
    PCI / VFIO: Add 'override_only' support for VFIO PCI sub system
    PCI: Add 'override_only' field to struct pci_device_id
    vfio/pci: Move module parameters to vfio_pci.c
    vfio/pci: Move igd initialization to vfio_pci.c
    vfio/pci: Split the pci_driver code out of vfio_pci_core.c
    vfio/pci: Include vfio header in vfio_pci_core.h
    vfio/pci: Rename ops functions to fit core namings
    vfio/pci: Rename vfio_pci_device to vfio_pci_core_device
    vfio/pci: Rename vfio_pci_private.h to vfio_pci_core.h
    vfio/pci: Rename vfio_pci.c to vfio_pci_core.c
    vfio/ap_ops: Convert to use vfio_register_group_dev()
    s390/vfio-ap: replace open coded locks for VFIO_GROUP_NOTIFY_SET_KVM notification
    s390/vfio-ap: r/w lock for PQAP interception handler function pointer
    vfio/type1: Fix vfio_find_dma_valid return
    vfio-pci/zdev: Remove repeated verbose license text
    vfio: platform: reset: Convert to SPDX identifier
    vfio: Remove struct vfio_device_ops open/release
    ...

    Linus Torvalds
     

27 Aug, 2021

13 commits

  • …v3', 'v5.15/vfio/vfio-pci-core-v5' and 'v5.15/vfio/vfio-ap' into v5.15/vfio/next

    Alex Williamson
     
  • Now that vfio_pci has been split into two source modules, one focusing on
    the "struct pci_driver" (vfio_pci.c) and a toolbox library of code
    (vfio_pci_core.c), complete the split and move them into two different
    kernel modules.

    As before vfio_pci.ko continues to present the same interface under sysfs
    and this change will have no functional impact.

    Splitting into another module and adding exports allows creating new HW
    specific VFIO PCI drivers that can implement device specific
    functionality, such as VFIO migration interfaces or specialized device
    requirements.

    Signed-off-by: Max Gurtovoy
    Signed-off-by: Jason Gunthorpe
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Yishai Hadas
    Link: https://lore.kernel.org/r/20210826103912.128972-14-yishaih@nvidia.com
    Signed-off-by: Alex Williamson

    Max Gurtovoy
     
  • This results in less kconfig wordage and a simpler understanding of the
    required "depends on" to create the menu structure.

    The next patch increases the nesting level a lot so this is a nice
    preparatory simplification.

    Signed-off-by: Jason Gunthorpe
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Yishai Hadas
    Link: https://lore.kernel.org/r/20210826103912.128972-13-yishaih@nvidia.com
    Signed-off-by: Alex Williamson

    Jason Gunthorpe
     
  • If VFIO_VIRQFD is required then turn on eventfd automatically.
    The majority of kconfig users of the EVENTFD use select not depends on.

    Signed-off-by: Jason Gunthorpe
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Yishai Hadas
    Link: https://lore.kernel.org/r/20210826103912.128972-12-yishaih@nvidia.com
    Signed-off-by: Alex Williamson

    Jason Gunthorpe
     
  • Expose an 'override_only' helper macro (i.e.
    PCI_DRIVER_OVERRIDE_DEVICE_VFIO) for VFIO PCI sub system and add the
    required code to prefix its matching entries with "vfio_" in
    modules.alias file.

    It allows VFIO device drivers to include match entries in the
    modules.alias file produced by kbuild that are not used for normal
    driver autoprobing and module autoloading. Drivers using these match
    entries can be connected to the PCI device manually, by userspace, using
    the existing driver_override sysfs.

    For example the resulting modules.alias may have:

    alias pci:v000015B3d00001021sv*sd*bc*sc*i* mlx5_core
    alias vfio_pci:v000015B3d00001021sv*sd*bc*sc*i* mlx5_vfio_pci
    alias vfio_pci:v*d*sv*sd*bc*sc*i* vfio_pci

    In this example mlx5_core and mlx5_vfio_pci match to the same PCI
    device. The kernel will autoload and autobind to mlx5_core but the
    kernel and udev mechanisms will ignore mlx5_vfio_pci.

    When userspace wants to change a device to the VFIO subsystem it can
    implement a generic algorithm:

    1) Identify the sysfs path to the device:
    /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0

    2) Get the modalias string from the kernel:
    $ cat /sys/bus/pci/devices/0000:01:00.0/modalias
    pci:v000015B3d00001021sv000015B3sd00000001bc02sc00i00

    3) Prefix it with vfio_:
    vfio_pci:v000015B3d00001021sv000015B3sd00000001bc02sc00i00

    4) Search modules.alias for the above string and select the entry that
    has the fewest *'s:
    alias vfio_pci:v000015B3d00001021sv*sd*bc*sc*i* mlx5_vfio_pci

    5) modprobe the matched module name:
    $ modprobe mlx5_vfio_pci

    6) cat the matched module name to driver_override:
    echo mlx5_vfio_pci > /sys/bus/pci/devices/0000:01:00.0/driver_override

    7) unbind device from original module
    echo 0000:01:00.0 > /sys/bus/pci/devices/0000:01:00.0/driver/unbind

    8) probe PCI drivers (or explicitly bind to mlx5_vfio_pci)
    echo 0000:01:00.0 > /sys/bus/pci/drivers_probe

    The algorithm is independent of bus type. In future the other buses with
    VFIO device drivers, like platform and ACPI, can use this algorithm as
    well.

    This patch is the infrastructure to provide the information in the
    modules.alias to userspace. Convert the only VFIO pci_driver which results
    in one new line in the modules.alias:

    alias vfio_pci:v*d*sv*sd*bc*sc*i* vfio_pci

    Later series introduce additional HW specific VFIO PCI drivers, such as
    mlx5_vfio_pci.

    Signed-off-by: Max Gurtovoy
    Signed-off-by: Jason Gunthorpe
    Acked-by: Bjorn Helgaas # for pci.h
    Signed-off-by: Yishai Hadas
    Link: https://lore.kernel.org/r/20210826103912.128972-11-yishaih@nvidia.com
    Signed-off-by: Alex Williamson

    Max Gurtovoy
     
  • This is a preparation before splitting vfio_pci.ko to 2 modules.

    As module parameters are a kind of uAPI they need to stay on vfio_pci.ko
    to avoid a user visible impact.

    For now continue to keep the implementation of these options in
    vfio_pci_core.c. Arguably they are vfio_pci functionality, but further
    splitting of vfio_pci_core.c will be better done in another series

    Signed-off-by: Yishai Hadas
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Jason Gunthorpe
    Link: https://lore.kernel.org/r/20210826103912.128972-9-yishaih@nvidia.com
    Signed-off-by: Alex Williamson

    Yishai Hadas
     
  • igd is related to the vfio_pci pci_driver implementation, move it out of
    vfio_pci_core.c.

    This is preparation for splitting vfio_pci.ko into 2 drivers.

    Signed-off-by: Max Gurtovoy
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Yishai Hadas
    Link: https://lore.kernel.org/r/20210826103912.128972-8-yishaih@nvidia.com
    Signed-off-by: Alex Williamson

    Max Gurtovoy
     
  • Split the vfio_pci driver into two logical parts, the 'struct
    pci_driver' (vfio_pci.c) which implements "Generic VFIO support for any
    PCI device" and a library of code (vfio_pci_core.c) that helps
    implementing a struct vfio_device on top of a PCI device.

    vfio_pci.ko continues to present the same interface under sysfs and this
    change should have no functional impact.

    Following patches will turn vfio_pci and vfio_pci_core into a separate
    module.

    This is a preparation for allowing another module to provide the
    pci_driver and allow that module to customize how VFIO is setup, inject
    its own operations, and easily extend vendor specific functionality.

    At this point the vfio_pci_core still contains a lot of vfio_pci
    functionality mixed into it. Following patches will move more of the
    large scale items out, but another cleanup series will be needed to get
    everything.

    Signed-off-by: Max Gurtovoy
    Signed-off-by: Jason Gunthorpe
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Yishai Hadas
    Link: https://lore.kernel.org/r/20210826103912.128972-7-yishaih@nvidia.com
    Signed-off-by: Alex Williamson

    Max Gurtovoy
     
  • The vfio_device structure is embedded into the vfio_pci_core_device
    structure, so there is no reason for not including the header file in
    the vfio_pci_core header as well.

    Signed-off-by: Max Gurtovoy
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Yishai Hadas
    Link: https://lore.kernel.org/r/20210826103912.128972-6-yishaih@nvidia.com
    Signed-off-by: Alex Williamson

    Max Gurtovoy
     
  • This is another preparation patch for separating the vfio_pci driver to
    a subsystem driver and a generic pci driver. This patch doesn't change
    any logic.

    Signed-off-by: Max Gurtovoy
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Yishai Hadas
    Link: https://lore.kernel.org/r/20210826103912.128972-5-yishaih@nvidia.com
    Signed-off-by: Alex Williamson

    Max Gurtovoy
     
  • This is a preparation patch for separating the vfio_pci driver to a
    subsystem driver and a generic pci driver. This patch doesn't change any
    logic.

    The new vfio_pci_core_device structure will be the main structure of the
    core driver and later on vfio_pci_device structure will be the main
    structure of the generic vfio_pci driver.

    Signed-off-by: Max Gurtovoy
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Yishai Hadas
    Link: https://lore.kernel.org/r/20210826103912.128972-4-yishaih@nvidia.com
    Signed-off-by: Alex Williamson

    Max Gurtovoy
     
  • This is a preparation patch for separating the vfio_pci driver to a
    subsystem driver and a generic pci driver. This patch doesn't change any
    logic.

    Signed-off-by: Max Gurtovoy
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Yishai Hadas
    Link: https://lore.kernel.org/r/20210826103912.128972-3-yishaih@nvidia.com
    Signed-off-by: Alex Williamson

    Max Gurtovoy
     
  • This is a preparation patch for separating the vfio_pci driver to a
    subsystem driver and a generic pci driver. This patch doesn't change any
    logic.

    Signed-off-by: Max Gurtovoy
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Yishai Hadas
    Link: https://lore.kernel.org/r/20210826103912.128972-2-yishaih@nvidia.com
    Signed-off-by: Alex Williamson

    Max Gurtovoy
     

25 Aug, 2021

3 commits

  • vfio_find_dma_valid is defined to return WAITED on success if it was
    necessary to wait. However, the loop forgets the WAITED value returned
    by vfio_wait() and returns 0 in a later iteration. Fix it.

    Signed-off-by: Anthony Yznaga
    Reviewed-by: Steve Sistare
    Link: https://lore.kernel.org/r/1629736550-2388-1-git-send-email-anthony.yznaga@oracle.com
    Signed-off-by: Alex Williamson

    Anthony Yznaga
     
  • The SPDX and verbose license text are redundant, however in this case
    the verbose license indicates a GPL v2 only while SPDX specifies v2+.
    Remove the verbose license and correct SPDX to the more restricted
    version.

    Signed-off-by: Cai Huoqing
    Reviewed-by: Matthew Rosato
    Link: https://lore.kernel.org/r/20210824003749.1039-1-caihuoqing@baidu.com
    [aw: commit log]
    Signed-off-by: Alex Williamson

    Cai Huoqing
     
  • use SPDX-License-Identifier instead of a verbose license text

    Signed-off-by: Cai Huoqing
    Link: https://lore.kernel.org/r/20210822043643.2040-1-caihuoqing@baidu.com
    Signed-off-by: Alex Williamson

    Cai Huoqing
     

11 Aug, 2021

9 commits

  • Nothing uses this anymore, delete it.

    Signed-off-by: Yishai Hadas
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Jason Gunthorpe
    Reviewed-by: Cornelia Huck
    Link: https://lore.kernel.org/r/14-v4-9ea22c5e6afb+1adf-vfio_reflck_jgg@nvidia.com
    Signed-off-by: Alex Williamson

    Jason Gunthorpe
     
  • Like vfio_pci_dev_set_try_reset() this code wants to reset all of the
    devices in the "reset group" which is the same membership as the device
    set.

    Instead of trying to reconstruct the device set from the PCI list go
    directly from the device set's device list to execute the reset.

    The same basic structure as vfio_pci_dev_set_try_reset() is used. The
    'vfio_devices' struct is replaced with the device set linked list and we
    simply sweep it multiple times under the lock.

    This eliminates a memory allocation and get/put traffic and another
    improperly locked test of pci_dev_driver().

    Reviewed-off-by: Christoph Hellwig
    Signed-off-by: Jason Gunthorpe
    Reviewed-by: Cornelia Huck
    Link: https://lore.kernel.org/r/10-v4-9ea22c5e6afb+1adf-vfio_reflck_jgg@nvidia.com
    Signed-off-by: Alex Williamson

    Jason Gunthorpe
     
  • vfio_pci_try_bus_reset() is triggering a reset of the entire_dev set if
    any device within it has accumulated a needs_reset. This reset can only be
    done once all of the drivers operating the PCI devices to be reset are in
    a known safe state.

    Make this clearer by directly operating on the dev_set instead of the
    vfio_pci_device. Rename the function to vfio_pci_dev_set_try_reset().

    Use the device list inside the dev_set to check that all drivers are in a
    safe state instead of working backwards from the pci_device.

    The dev_set->lock directly prevents devices from joining/leaving the set,
    or changing their state, which further implies the pci_device cannot
    change drivers or that the vfio_device be freed, eliminating the need for
    get/put's.

    If a pci_device to be reset is not in the dev_set then the reset cannot be
    used as we can't know what the state of that driver is. Directly measure
    this by checking that every pci_device is in the dev_set - which
    effectively proves that VFIO drivers are attached to everything.

    Remove the odd interaction around vfio_pci_set_power_state() - have the
    only caller avoid its redundant vfio_pci_set_power_state() instead of
    avoiding it inside vfio_pci_dev_set_try_reset().

    This restructuring corrects a call to pci_dev_driver() without holding the
    device_lock() and removes a hard wiring to &vfio_pci_driver.

    Signed-off-by: Jason Gunthorpe
    Reviewed-by: Christoph Hellwig
    Reviewed-by: Cornelia Huck
    Link: https://lore.kernel.org/r/9-v4-9ea22c5e6afb+1adf-vfio_reflck_jgg@nvidia.com
    Signed-off-by: Alex Williamson

    Jason Gunthorpe
     
  • PCI wants to have the usual open/close_device() logic with the slight
    twist that the open/close_device() must be done under a singelton lock
    shared by all of the vfio_devices that are in the PCI "reset group".

    The reset group, and thus the device set, is determined by what devices
    pci_reset_bus() touches, which is either the entire bus or only the slot.

    Rely on the core code to do everything reflck was doing and delete reflck
    entirely.

    Signed-off-by: Yishai Hadas
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Jason Gunthorpe
    Reviewed-by: Cornelia Huck
    Link: https://lore.kernel.org/r/8-v4-9ea22c5e6afb+1adf-vfio_reflck_jgg@nvidia.com
    Signed-off-by: Alex Williamson

    Yishai Hadas
     
  • Platform simply wants to run some code when the device is first
    opened/last closed. Use the core framework and locking for this. Aside
    from removing a bit of code this narrows the locking scope from a global
    lock.

    Reviewed-by: Cornelia Huck
    Reviewed-by: Eric Auger
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Jason Gunthorpe
    Signed-off-by: Yishai Hadas
    Link: https://lore.kernel.org/r/7-v4-9ea22c5e6afb+1adf-vfio_reflck_jgg@nvidia.com
    Signed-off-by: Alex Williamson

    Jason Gunthorpe
     
  • FSL uses the internal reflck to implement the open_device() functionality,
    conversion to the core code is straightforward.

    The decision on which set to be part of is trivially based on the
    is_fsl_mc_bus_dprc() and we use a 'struct device *' pointer as the set_id.

    The dev_set lock is protecting the interrupts setup. The FSL MC devices
    are using MSIs and only the DPRC device is allocating the MSIs from the
    MSI domain. The other devices just take interrupts from a pool. The lock
    is protecting the access to this pool.

    Signed-off-by: Yishai Hadas
    Tested-by: Diana Craciun OSS
    Signed-off-by: Jason Gunthorpe
    Link: https://lore.kernel.org/r/6-v4-9ea22c5e6afb+1adf-vfio_reflck_jgg@nvidia.com
    Signed-off-by: Alex Williamson

    Jason Gunthorpe
     
  • Currently the driver ops have an open/release pair that is called once
    each time a device FD is opened or closed. Add an additional set of
    open/close_device() ops which are called when the device FD is opened for
    the first time and closed for the last time.

    An analysis shows that all of the drivers require this semantic. Some are
    open coding it as part of their reflck implementation, and some are just
    buggy and miss it completely.

    To retain the current semantics PCI and FSL depend on, introduce the idea
    of a "device set" which is a grouping of vfio_device's that share the same
    lock around opening.

    The device set is established by providing a 'set_id' pointer. All
    vfio_device's that provide the same pointer will be joined to the same
    singleton memory and lock across the whole set. This effectively replaces
    the oddly named reflck.

    After conversion the set_id will be sourced from:
    - A struct device from a fsl_mc_device (fsl)
    - A struct pci_slot (pci)
    - A struct pci_bus (pci)
    - The struct vfio_device (everything)

    The design ensures that the above pointers are live as long as the
    vfio_device is registered, so they form reliable unique keys to group
    vfio_devices into sets.

    This implementation uses xarray instead of searching through the driver
    core structures, which simplifies the somewhat tricky locking in this
    area.

    Following patches convert all the drivers.

    Signed-off-by: Yishai Hadas
    Reviewed-by: Cornelia Huck
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Jason Gunthorpe
    Link: https://lore.kernel.org/r/4-v4-9ea22c5e6afb+1adf-vfio_reflck_jgg@nvidia.com
    Signed-off-by: Alex Williamson

    Jason Gunthorpe
     
  • This pairs with vfio_init_group_dev() and allows undoing any state that is
    stored in the vfio_device unrelated to registration. Add appropriately
    placed calls to all the drivers.

    The following patch will use this to add pre-registration state for the
    device set.

    Signed-off-by: Max Gurtovoy
    Reviewed-by: Cornelia Huck
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Jason Gunthorpe
    Link: https://lore.kernel.org/r/3-v4-9ea22c5e6afb+1adf-vfio_reflck_jgg@nvidia.com
    Signed-off-by: Alex Williamson

    Max Gurtovoy
     
  • …rnel/git/gregkh/driver-core into drm-next

    Bus: Make remove callback return void tag

    Tag for other trees/branches to pull from in order to have a stable
    place to build off of if they want to add new busses for 5.15.

    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

    [airlied: fixed up merge conflict in drm]
    From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Link: https://patchwork.freedesktop.org/patch/msgid/YPkwQwf0dUKnGA7L@kroah.com

    Dave Airlie
     

03 Aug, 2021

3 commits

  • Only a single driver actually sets the ->request method, so don't print
    a scary warning if it isn't.

    Signed-off-by: Christoph Hellwig
    Reviewed-by: Cornelia Huck
    Reviewed-by: Jason Gunthorpe
    Link: https://lore.kernel.org/r/20210726143524.155779-3-hch@lst.de
    Signed-off-by: Alex Williamson

    Christoph Hellwig
     
  • Without this setups with buіlt-in mdev and mdev-drivers fail to
    register like this:

    [1.903149] Driver 'intel_vgpu_mdev' was unable to register with bus_type 'mdev' because the bus was not initialized.

    Signed-off-by: Christoph Hellwig
    Reviewed-by: Cornelia Huck
    Reviewed-by: Jason Gunthorpe
    Link: https://lore.kernel.org/r/20210726143524.155779-2-hch@lst.de
    Signed-off-by: Alex Williamson

    Christoph Hellwig
     
  • The only implementation of this in IGD returns a -ERRNO which is
    implicitly cast through a size_t and then casted again and returned as a
    ssize_t in vfio_pci_rw().

    Fix the vfio_pci_regops->rw() return type to be ssize_t so all is
    consistent.

    Fixes: 28541d41c9e0 ("vfio/pci: Add infrastructure for additional device specific regions")
    Signed-off-by: Yishai Hadas
    Signed-off-by: Jason Gunthorpe
    Reviewed-by: Cornelia Huck
    Reviewed-by: Max Gurtovoy
    Link: https://lore.kernel.org/r/0-v3-5db12d1bf576+c910-vfio_rw_jgg@nvidia.com
    Signed-off-by: Alex Williamson

    Yishai Hadas