Introduce vfio_pci_core subsystem
Subsystems (10)
v2 cover Introduce vfio_pci_core subsystem
Prologue:
This is the second series of three to send the "mlx5_vfio_pci" driver that has been discussed on the list for a while now. It comes on top of the first series (i.e. Reorganize reflck to support splitting vfio_pci) that was merged already.
- Split vfio_pci into vfio_pci/vfio_pci_core and provide infrastructure for non-generic VFIO PCI drivers.
- The new driver mlx5_vfio_pci that is a full implementation of suspend/resume functionality for mlx5 devices.
A preview of the third series for mlx5_vfio_pci can be seen here:
https://github.com/jgunthorpe/linux/commits/mlx5_vfio_pci
=====================
From Max Gurtovoy:
====================
This series splits the vfio_pci driver into two parts, a PCI driver and a subsystem driver that will also be library of code. The main PCI driver, vfio_pci.ko, will remain as before and it will use the library module vfio_pci_core.ko to help create the vfio_device.
This series is intended to solve the issues that were raised in the previous attempts for extending vfio-pci for device specific functionality:
1.
https://lore.kernel.org/kvm/[email protected]
by Yan Zhao
2.
https://lore.kernel.org/kvm/[email protected]
by Longfang Liu
Also to support proposed future changes to virtio and other common protocols to support migration:
https://lists.oasis-open.org/archives/virtio-comment/202106/msg00044.html
This subsystem framework will also ease adding new device specific functionality to VFIO devices in the future by allowing another module to provide the pci_driver that can setup a number of details before registering to the VFIO subsystem, such as injecting its own operations.
This series also extends the "driver_override" mechanism. A flag is added for PCI drivers that will declare themselves as "driver_override" capable which sends their match table to the modules.alias file but otherwise leaves them outside of the normal driver core auto-binding world, like vfio_pci.
In order to get the best match for "driver_override" drivers, one can create a userspace program to inspect the modules.alias, an example can be found at:
https://github.com/maxgurtovoy/linux_tools/blob/main/vfio/bind_vfio_pci_driver.py
Which finds the 'best match' according to a simple algorithm: "the driver with the fewest '*' matches wins."
For example, the vfio-pci driver will match to any pci device. So it will have the maximal '*' matches.
In case we are looking for a match to a mlx5 based device, we'll have a match to vfio-pci.ko and mlx5-vfio-pci.ko. We'll prefer mlx5-vfio-pci.ko since it will have less '*' matches (probably vendor and device IDs will match). This will work in the future for NVMe/Virtio devices that can match according to a class code or other criteria.
v2:
Patch #6:
- Drop DRIVER_VERSION as it's useless and not required any more.
Patch #9:
- Follow Bjorn Helgaas suggestion to enable having "vfio_" prefix in modules.alias file without the unnecessary VFIO connection in pci_match_device.
- Add the sequence of commands/algorithm that is required by userspace to discover the matching driver to the commit message to let the patch documentation be self-contained.
Patch #12:
- Save compatibility with Kconfig as was asked in the mailing list.
- Drop DRIVER_VERSION as it's useless and not required any more.
Yishai
Jason Gunthorpe (2):
vfio: Use select for eventfd
vfio: Use kconfig if XX/endif blocks instead of repeating 'depends on'
Max Gurtovoy (9):
vfio/pci: Rename vfio_pci.c to vfio_pci_core.c vfio/pci: Rename vfio_pci_private.h to vfio_pci_core.h vfio/pci: Rename vfio_pci_device to vfio_pci_core_device vfio/pci: Rename ops functions to fit core namings vfio/pci: Include vfio header in vfio_pci_core.h vfio/pci: Split the pci_driver code out of vfio_pci_core.c vfio/pci: Move igd initialization to vfio_pci.c
PCI: Add 'override_only' bitmap to struct pci_device_id vfio/pci: Introduce vfio_pci_core.ko
Yishai Hadas (1):
vfio/pci: Move module parameters to vfio_pci.c
Documentation/PCI/pci.rst | 1 + drivers/pci/pci-driver.c | 27 +- drivers/vfio/Kconfig | 29 +- drivers/vfio/fsl-mc/Kconfig | 3 +- drivers/vfio/mdev/Kconfig | 1 - drivers/vfio/pci/Kconfig | 40 +- drivers/vfio/pci/Makefile | 8 +- drivers/vfio/pci/vfio_pci.c | 2262 +---------------- drivers/vfio/pci/vfio_pci_config.c | 70 +- drivers/vfio/pci/vfio_pci_core.c | 2159 ++++++++++++++++ drivers/vfio/pci/vfio_pci_igd.c | 19 +- drivers/vfio/pci/vfio_pci_intrs.c | 42 +- drivers/vfio/pci/vfio_pci_rdwr.c | 18 +- drivers/vfio/pci/vfio_pci_zdev.c | 4 +- drivers/vfio/platform/Kconfig | 6 +- drivers/vfio/platform/reset/Kconfig | 4 +- include/linux/mod_devicetable.h | 6 + include/linux/pci.h | 28 + .../linux/vfio_pci_core.h | 89 +- scripts/mod/devicetable-offsets.c | 1 + scripts/mod/file2alias.c | 8 +- 21 files changed, 2515 insertions(+), 2310 deletions(-) create mode 100644 drivers/vfio/pci/vfio_pci_core.c rename drivers/vfio/pci/vfio_pci_private.h => include/linux/vfio_pci_core.h (56%)
Signature · 1 line
2.18.1
PATCH v2 1/12 vfio/pci: Rename vfio_pci.c to vfio_pci_core.c
From: Max Gurtovoy <[email protected]>
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.
---
drivers/vfio/pci/Makefile | 2 +-
drivers/vfio/pci/{vfio_pci.c => vfio_pci_core.c} | 0
2 files changed, 1 insertion(+), 1 deletion(-)
rename drivers/vfio/pci/{vfio_pci.c => vfio_pci_core.c} (100%)drivers/vfio/pci/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only -vfio-pci-y := vfio_pci.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o +vfio-pci-y := vfio_pci_core.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o vfio-pci-$(CONFIG_VFIO_PCI_IGD) += vfio_pci_igd.o vfio-pci-$(CONFIG_S390) += vfio_pci_zdev.o
drivers/vfio/pci/vfio_pci_core.c renamed from drivers/vfio/pci/vfio_pci.c +0 -0
Signature · 1 line
2.18.1
PATCH v2 2/12 vfio/pci: Rename vfio_pci_private.h to vfio_pci_core.h
In reply to Yishai HadasFrom: Max Gurtovoy <[email protected]>
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.
---
drivers/vfio/pci/vfio_pci_config.c | 2 +-
drivers/vfio/pci/vfio_pci_core.c | 2 +-
drivers/vfio/pci/{vfio_pci_private.h => vfio_pci_core.h} | 6 +++---
drivers/vfio/pci/vfio_pci_igd.c | 2 +-
drivers/vfio/pci/vfio_pci_intrs.c | 2 +-
drivers/vfio/pci/vfio_pci_rdwr.c | 2 +-
drivers/vfio/pci/vfio_pci_zdev.c | 2 +-
7 files changed, 9 insertions(+), 9 deletions(-)
rename drivers/vfio/pci/{vfio_pci_private.h => vfio_pci_core.h} (98%)drivers/vfio/pci/vfio_pci_config.c +1 -1
@@ -26,7 +26,7 @@#include <linux/vfio.h> #include <linux/slab.h> -#include "vfio_pci_private.h" +#include "vfio_pci_core.h" /* Fake capability ID for standard config space */ #define PCI_CAP_ID_BASIC 0
drivers/vfio/pci/vfio_pci_core.c +1 -1
@@ -28,7 +28,7 @@#include <linux/nospec.h> #include <linux/sched/mm.h> -#include "vfio_pci_private.h" +#include "vfio_pci_core.h" #define DRIVER_VERSION "0.2"#define DRIVER_AUTHOR "Alex Williamson <[email protected]>"
drivers/vfio/pci/vfio_pci_core.h renamed from drivers/vfio/pci/vfio_pci_private.h +3 -3
@@ -15,8 +15,8 @@#include <linux/uuid.h> #include <linux/notifier.h> -#ifndef VFIO_PCI_PRIVATE_H -#define VFIO_PCI_PRIVATE_H +#ifndef VFIO_PCI_CORE_H +#define VFIO_PCI_CORE_H #define VFIO_PCI_OFFSET_SHIFT 40
@@ -205,4 +205,4 @@ static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_device *vdev, }#endif -#endif /* VFIO_PCI_PRIVATE_H */ +#endif /* VFIO_PCI_CORE_H */
drivers/vfio/pci/vfio_pci_igd.c +1 -1
@@ -15,7 +15,7 @@#include <linux/uaccess.h> #include <linux/vfio.h> -#include "vfio_pci_private.h" +#include "vfio_pci_core.h" #define OPREGION_SIGNATURE "IntelGraphicsMem"#define OPREGION_SIZE (8 * 1024)
drivers/vfio/pci/vfio_pci_intrs.c +1 -1
@@ -20,7 +20,7 @@#include <linux/wait.h> #include <linux/slab.h> -#include "vfio_pci_private.h" +#include "vfio_pci_core.h" /* * INTx
drivers/vfio/pci/vfio_pci_rdwr.c +1 -1
@@ -17,7 +17,7 @@#include <linux/vfio.h> #include <linux/vgaarb.h> -#include "vfio_pci_private.h" +#include "vfio_pci_core.h" #ifdef __LITTLE_ENDIAN#define vfio_ioread64 ioread64
drivers/vfio/pci/vfio_pci_zdev.c +1 -1
@@ -19,7 +19,7 @@#include <asm/pci_clp.h> #include <asm/pci_io.h> -#include "vfio_pci_private.h" +#include "vfio_pci_core.h" /* * Add the Base PCI Function information to the device info region.
Signature · 1 line
2.18.1
PATCH v2 3/12 vfio/pci: Rename vfio_pci_device to vfio_pci_core_device
In reply to Yishai HadasFrom: Max Gurtovoy <[email protected]>
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.
--- drivers/vfio/pci/vfio_pci_config.c | 68 ++++++++--------- drivers/vfio/pci/vfio_pci_core.c | 118 +++++++++++++++-------------- drivers/vfio/pci/vfio_pci_core.h | 52 ++++++------- drivers/vfio/pci/vfio_pci_igd.c | 17 +++-- drivers/vfio/pci/vfio_pci_intrs.c | 40 +++++----- drivers/vfio/pci/vfio_pci_rdwr.c | 16 ++-- drivers/vfio/pci/vfio_pci_zdev.c | 2 +- 7 files changed, 158 insertions(+), 155 deletions(-)
drivers/vfio/pci/vfio_pci_config.c +34 -34
@@ -108,9 +108,9 @@ static const u16 pci_ext_cap_length[PCI_EXT_CAP_ID_MAX + 1] = {struct perm_bits {u8 *virt;/* read/write virtual data, not hw */ u8 *write;/* writeable bits */ -int (*readfn)(struct vfio_pci_device *vdev,int pos,int count, +int (*readfn)(struct vfio_pci_core_device *vdev,int pos,int count,struct perm_bits *perm,int offset,__le32 *val); -int (*writefn)(struct vfio_pci_device *vdev,int pos,int count, +int (*writefn)(struct vfio_pci_core_device *vdev,int pos,int count,struct perm_bits *perm,int offset,__le32 val); };
@@ -171,7 +171,7 @@ static int vfio_user_config_write(struct pci_dev *pdev, int offset,return ret; } -static int vfio_default_config_read (struct vfio_pci_device *vdev,int pos, +static int vfio_default_config_read (struct vfio_pci_core_device *vdev,int pos,int count,struct perm_bits *perm,int offset,__le32 *val) {
@@ -197,7 +197,7 @@ static int vfio_default_config_read(struct vfio_pci_device *vdev, int pos,return count; } -static int vfio_default_config_write (struct vfio_pci_device *vdev,int pos, +static int vfio_default_config_write (struct vfio_pci_core_device *vdev,int pos,int count,struct perm_bits *perm,int offset,__le32 val) {
@@ -244,7 +244,7 @@ static int vfio_default_config_write(struct vfio_pci_device *vdev, int pos, }/* Allow direct read from hardware, except for capability next pointer */ -static int vfio_direct_config_read (struct vfio_pci_device *vdev,int pos, +static int vfio_direct_config_read (struct vfio_pci_core_device *vdev,int pos,int count,struct perm_bits *perm,int offset,__le32 *val) {
@@ -269,7 +269,7 @@ static int vfio_direct_config_read(struct vfio_pci_device *vdev, int pos, }/* Raw access skips any kind of virtualization */ -static int vfio_raw_config_write (struct vfio_pci_device *vdev,int pos, +static int vfio_raw_config_write (struct vfio_pci_core_device *vdev,int pos,int count,struct perm_bits *perm,int offset,__le32 val) {
@@ -282,7 +282,7 @@ static int vfio_raw_config_write(struct vfio_pci_device *vdev, int pos,return count; } -static int vfio_raw_config_read (struct vfio_pci_device *vdev,int pos, +static int vfio_raw_config_read (struct vfio_pci_core_device *vdev,int pos,int count,struct perm_bits *perm,int offset,__le32 *val) {
@@ -296,7 +296,7 @@ static int vfio_raw_config_read(struct vfio_pci_device *vdev, int pos, }/* Virt access uses only virtualization */ -static int vfio_virt_config_write (struct vfio_pci_device *vdev,int pos, +static int vfio_virt_config_write (struct vfio_pci_core_device *vdev,int pos,int count,struct perm_bits *perm,int offset,__le32 val) {
@@ -304,7 +304,7 @@ static int vfio_virt_config_write(struct vfio_pci_device *vdev, int pos,return count; } -static int vfio_virt_config_read (struct vfio_pci_device *vdev,int pos, +static int vfio_virt_config_read (struct vfio_pci_core_device *vdev,int pos,int count,struct perm_bits *perm,int offset,__le32 *val) {
@@ -396,7 +396,7 @@ static inline void p_setd(struct perm_bits *p, int off, u32 virt, u32 write) }/* Caller should hold memory_lock semaphore */ -bool __vfio_pci_memory_enabled (struct vfio_pci_device *vdev) +bool __vfio_pci_memory_enabled (struct vfio_pci_core_device *vdev) {struct pci_dev *pdev = vdev->pdev;u16 cmd =le16_to_cpu (*(__le16 *)&vdev->vconfig[PCI_COMMAND ]);
@@ -413,7 +413,7 @@ bool __vfio_pci_memory_enabled(struct vfio_pci_device *vdev)* Restore the *real* BARs after we detect a FLR or backdoor reset. * (backdoor = some device specific technique that we didn't catch) */ -static void vfio_bar_restore (struct vfio_pci_device *vdev) +static void vfio_bar_restore (struct vfio_pci_core_device *vdev) {struct pci_dev *pdev = vdev->pdev;u32 *rbar = vdev->rbar;
@@ -460,7 +460,7 @@ static __le32 vfio_generate_bar_flags(struct pci_dev *pdev, int bar)* Pretend we're hardware and tweak the values of the *virtual* PCI BARs * to reflect the hardware capabilities. This implements BAR sizing. */ -static void vfio_bar_fixup (struct vfio_pci_device *vdev) +static void vfio_bar_fixup (struct vfio_pci_core_device *vdev) {struct pci_dev *pdev = vdev->pdev;int i;
@@ -514,7 +514,7 @@ static void vfio_bar_fixup(struct vfio_pci_device *vdev) vdev->bardirty = false; } -static int vfio_basic_config_read (struct vfio_pci_device *vdev,int pos, +static int vfio_basic_config_read (struct vfio_pci_core_device *vdev,int pos,int count,struct perm_bits *perm,int offset,__le32 *val) {
@@ -536,7 +536,7 @@ static int vfio_basic_config_read(struct vfio_pci_device *vdev, int pos, }/* Test whether BARs match the value we think they should contain */ -static bool vfio_need_bar_restore (struct vfio_pci_device *vdev) +static bool vfio_need_bar_restore (struct vfio_pci_core_device *vdev) {int i =0 , pos =PCI_BASE_ADDRESS_0 , ret;u32 bar;
@@ -552,7 +552,7 @@ static bool vfio_need_bar_restore(struct vfio_pci_device *vdev)return false; } -static int vfio_basic_config_write (struct vfio_pci_device *vdev,int pos, +static int vfio_basic_config_write (struct vfio_pci_core_device *vdev,int pos,int count,struct perm_bits *perm,int offset,__le32 val) {
@@ -692,7 +692,7 @@ static int __init init_pci_cap_basic_perm(struct perm_bits *perm)return 0 ; } -static int vfio_pm_config_write (struct vfio_pci_device *vdev,int pos, +static int vfio_pm_config_write (struct vfio_pci_core_device *vdev,int pos,int count,struct perm_bits *perm,int offset,__le32 val) {
@@ -747,7 +747,7 @@ static int __init init_pci_cap_pm_perm(struct perm_bits *perm)return 0 ; } -static int vfio_vpd_config_write (struct vfio_pci_device *vdev,int pos, +static int vfio_vpd_config_write (struct vfio_pci_core_device *vdev,int pos,int count,struct perm_bits *perm,int offset,__le32 val) {
@@ -829,7 +829,7 @@ static int __init init_pci_cap_pcix_perm(struct perm_bits *perm)return 0 ; } -static int vfio_exp_config_write (struct vfio_pci_device *vdev,int pos, +static int vfio_exp_config_write (struct vfio_pci_core_device *vdev,int pos,int count,struct perm_bits *perm,int offset,__le32 val) {
@@ -913,7 +913,7 @@ static int __init init_pci_cap_exp_perm(struct perm_bits *perm)return 0 ; } -static int vfio_af_config_write (struct vfio_pci_device *vdev,int pos, +static int vfio_af_config_write (struct vfio_pci_core_device *vdev,int pos,int count,struct perm_bits *perm,int offset,__le32 val) {
@@ -1072,7 +1072,7 @@ int __init vfio_pci_init_perm_bits(void)return ret; } -static int vfio_find_cap_start (struct vfio_pci_device *vdev,int pos) +static int vfio_find_cap_start (struct vfio_pci_core_device *vdev,int pos) {u8 cap; int base = (pos >= PCI_CFG_SPACE_SIZE) ? PCI_CFG_SPACE_SIZE :
@@ -1089,7 +1089,7 @@ static int vfio_find_cap_start(struct vfio_pci_device *vdev, int pos)return pos; } -static int vfio_msi_config_read (struct vfio_pci_device *vdev,int pos, +static int vfio_msi_config_read (struct vfio_pci_core_device *vdev,int pos,int count,struct perm_bits *perm,int offset,__le32 *val) {
@@ -1109,7 +1109,7 @@ static int vfio_msi_config_read(struct vfio_pci_device *vdev, int pos,return vfio_default_config_read (vdev, pos, count, perm, offset, val); } -static int vfio_msi_config_write (struct vfio_pci_device *vdev,int pos, +static int vfio_msi_config_write (struct vfio_pci_core_device *vdev,int pos,int count,struct perm_bits *perm,int offset,__le32 val) {
@@ -1189,7 +1189,7 @@ static int init_pci_cap_msi_perm(struct perm_bits *perm, int len, u16 flags) }/* Determine MSI CAP field length; initialize msi_perms on 1st call per vdev */ -static int vfio_msi_cap_len (struct vfio_pci_device *vdev,u8 pos) +static int vfio_msi_cap_len (struct vfio_pci_core_device *vdev,u8 pos) {struct pci_dev *pdev = vdev->pdev;int len, ret;
@@ -1222,7 +1222,7 @@ static int vfio_msi_cap_len(struct vfio_pci_device *vdev, u8 pos) }/* Determine extended capability length for VC (2 & 9) and MFVC */ -static int vfio_vc_cap_len (struct vfio_pci_device *vdev,u16 pos) +static int vfio_vc_cap_len (struct vfio_pci_core_device *vdev,u16 pos) {struct pci_dev *pdev = vdev->pdev;u32 tmp;
@@ -1263,7 +1263,7 @@ static int vfio_vc_cap_len(struct vfio_pci_device *vdev, u16 pos)return len; } -static int vfio_cap_len (struct vfio_pci_device *vdev,u8 cap,u8 pos) +static int vfio_cap_len (struct vfio_pci_core_device *vdev,u8 cap,u8 pos) {struct pci_dev *pdev = vdev->pdev;u32 dword;
@@ -1338,7 +1338,7 @@ static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos)return 0 ; } -static int vfio_ext_cap_len (struct vfio_pci_device *vdev,u16 ecap,u16 epos) +static int vfio_ext_cap_len (struct vfio_pci_core_device *vdev,u16 ecap,u16 epos) {struct pci_dev *pdev = vdev->pdev;u8 byte;
@@ -1412,7 +1412,7 @@ static int vfio_ext_cap_len(struct vfio_pci_device *vdev, u16 ecap, u16 epos)return 0 ; } -static int vfio_fill_vconfig_bytes (struct vfio_pci_device *vdev, +static int vfio_fill_vconfig_bytes (struct vfio_pci_core_device *vdev,int offset,int size) {struct pci_dev *pdev = vdev->pdev;
@@ -1459,7 +1459,7 @@ static int vfio_fill_vconfig_bytes(struct vfio_pci_device *vdev,return ret; } -static int vfio_cap_init (struct vfio_pci_device *vdev) +static int vfio_cap_init (struct vfio_pci_core_device *vdev) {struct pci_dev *pdev = vdev->pdev;u8 *map = vdev->pci_config_map;
@@ -1549,7 +1549,7 @@ static int vfio_cap_init(struct vfio_pci_device *vdev)return 0 ; } -static int vfio_ecap_init (struct vfio_pci_device *vdev) +static int vfio_ecap_init (struct vfio_pci_core_device *vdev) {struct pci_dev *pdev = vdev->pdev;u8 *map = vdev->pci_config_map;
@@ -1669,7 +1669,7 @@ static const struct pci_device_id known_bogus_vf_intx_pin[] = {* for each area requiring emulated bits, but the array of pointers * would be comparable in size (at least for standard config space). */ -int vfio_config_init (struct vfio_pci_device *vdev) +int vfio_config_init (struct vfio_pci_core_device *vdev) {struct pci_dev *pdev = vdev->pdev;u8 *map, *vconfig;
@@ -1773,7 +1773,7 @@ int vfio_config_init(struct vfio_pci_device *vdev)return pcibios_err_to_errno (ret); } -void vfio_config_free (struct vfio_pci_device *vdev) +void vfio_config_free (struct vfio_pci_core_device *vdev) {kfree (vdev->vconfig); vdev->vconfig =NULL ;
@@ -1790,7 +1790,7 @@ void vfio_config_free(struct vfio_pci_device *vdev)* Find the remaining number of bytes in a dword that match the given * position. Stop at either the end of the capability or the dword boundary. */ -static size_t vfio_pci_cap_remaining_dword (struct vfio_pci_device *vdev, +static size_t vfio_pci_cap_remaining_dword (struct vfio_pci_core_device *vdev,loff_t pos) {u8 cap = vdev->pci_config_map[pos];
@@ -1802,7 +1802,7 @@ static size_t vfio_pci_cap_remaining_dword(struct vfio_pci_device *vdev,return i; } -static ssize_t vfio_config_do_rw (struct vfio_pci_device *vdev,char __user *buf, +static ssize_t vfio_config_do_rw (struct vfio_pci_core_device *vdev,char __user *buf,size_t count,loff_t *ppos,bool iswrite) {struct pci_dev *pdev = vdev->pdev;
@@ -1885,7 +1885,7 @@ static ssize_t vfio_config_do_rw(struct vfio_pci_device *vdev, char __user *buf,return ret; } -ssize_t vfio_pci_config_rw (struct vfio_pci_device *vdev,char __user *buf, +ssize_t vfio_pci_config_rw (struct vfio_pci_core_device *vdev,char __user *buf,size_t count,loff_t *ppos,bool iswrite) {size_t done =0 ;
drivers/vfio/pci/vfio_pci_core.c +60 -58
391 lines not on this page · raw message
drivers/vfio/pci/vfio_pci_core.h +26 -26
119 lines not on this page · raw message
drivers/vfio/pci/vfio_pci_igd.c +9 -8
@@ -25,8 +25,9 @@#define OPREGION_RVDS 0x3c2#define OPREGION_VERSION 0x16 -static ssize_t vfio_pci_igd_rw (struct vfio_pci_device *vdev,char __user *buf, -size_t count,loff_t *ppos,bool iswrite) +static ssize_t vfio_pci_igd_rw (struct vfio_pci_core_device *vdev, +char __user *buf,size_t count,loff_t *ppos, +bool iswrite) {unsigned int i =VFIO_PCI_OFFSET_TO_INDEX (*ppos) -VFIO_PCI_NUM_REGIONS ;void *base = vdev->region[i].data;
@@ -45,7 +46,7 @@ static ssize_t vfio_pci_igd_rw(struct vfio_pci_device *vdev, char __user *buf,return count; } -static void vfio_pci_igd_release (struct vfio_pci_device *vdev, +static void vfio_pci_igd_release (struct vfio_pci_core_device *vdev,struct vfio_pci_region *region) {memunmap (region->data);
@@ -56,7 +57,7 @@ static const struct vfio_pci_regops vfio_pci_igd_regops = { .release = vfio_pci_igd_release, }; -static int vfio_pci_igd_opregion_init (struct vfio_pci_device *vdev) +static int vfio_pci_igd_opregion_init (struct vfio_pci_core_device *vdev) {__le32 *dwordp = (__le32 *)(vdev->vconfig +OPREGION_PCI_ADDR );u32 addr, size;
@@ -160,7 +161,7 @@ static int vfio_pci_igd_opregion_init(struct vfio_pci_device *vdev)return ret; } -static ssize_t vfio_pci_igd_cfg_rw (struct vfio_pci_device *vdev, +static ssize_t vfio_pci_igd_cfg_rw (struct vfio_pci_core_device *vdev,char __user *buf,size_t count,loff_t *ppos,bool iswrite) {
@@ -253,7 +254,7 @@ static ssize_t vfio_pci_igd_cfg_rw(struct vfio_pci_device *vdev,return count; } -static void vfio_pci_igd_cfg_release (struct vfio_pci_device *vdev, +static void vfio_pci_igd_cfg_release (struct vfio_pci_core_device *vdev,struct vfio_pci_region *region) {struct pci_dev *pdev = region->data;
@@ -266,7 +267,7 @@ static const struct vfio_pci_regops vfio_pci_igd_cfg_regops = { .release = vfio_pci_igd_cfg_release, }; -static int vfio_pci_igd_cfg_init (struct vfio_pci_device *vdev) +static int vfio_pci_igd_cfg_init (struct vfio_pci_core_device *vdev) {struct pci_dev *host_bridge, *lpc_bridge;int ret;
@@ -314,7 +315,7 @@ static int vfio_pci_igd_cfg_init(struct vfio_pci_device *vdev)return 0 ; } -int vfio_pci_igd_init (struct vfio_pci_device *vdev) +int vfio_pci_igd_init (struct vfio_pci_core_device *vdev) {int ret;
drivers/vfio/pci/vfio_pci_intrs.c +20 -20
@@ -27,13 +27,13 @@*/ static void vfio_send_intx_eventfd (void *opaque,void *unused) { -struct vfio_pci_device *vdev = opaque; +struct vfio_pci_core_device *vdev = opaque;if (likely (is_intx (vdev) && !vdev->virq_disabled))eventfd_signal (vdev->ctx[0 ].trigger,1 ); } -void vfio_pci_intx_mask (struct vfio_pci_device *vdev) +void vfio_pci_intx_mask (struct vfio_pci_core_device *vdev) {struct pci_dev *pdev = vdev->pdev;unsigned long flags;
@@ -73,7 +73,7 @@ void vfio_pci_intx_mask(struct vfio_pci_device *vdev)*/ static int vfio_pci_intx_unmask_handler (void *opaque,void *unused) { -struct vfio_pci_device *vdev = opaque; +struct vfio_pci_core_device *vdev = opaque;struct pci_dev *pdev = vdev->pdev;unsigned long flags;int ret =0 ;
@@ -107,7 +107,7 @@ static int vfio_pci_intx_unmask_handler(void *opaque, void *unused)return ret; } -void vfio_pci_intx_unmask (struct vfio_pci_device *vdev) +void vfio_pci_intx_unmask (struct vfio_pci_core_device *vdev) {if (vfio_pci_intx_unmask_handler (vdev,NULL ) >0 )vfio_send_intx_eventfd (vdev,NULL );
@@ -115,7 +115,7 @@ void vfio_pci_intx_unmask(struct vfio_pci_device *vdev)static irqreturn_t vfio_intx_handler (int irq,void *dev_id) { -struct vfio_pci_device *vdev = dev_id; +struct vfio_pci_core_device *vdev = dev_id;unsigned long flags;int ret =IRQ_NONE ;
@@ -139,7 +139,7 @@ static irqreturn_t vfio_intx_handler(int irq, void *dev_id)return ret; } -static int vfio_intx_enable (struct vfio_pci_device *vdev) +static int vfio_intx_enable (struct vfio_pci_core_device *vdev) {if (!is_irq_none (vdev))return -EINVAL ;
@@ -168,7 +168,7 @@ static int vfio_intx_enable(struct vfio_pci_device *vdev)return 0 ; } -static int vfio_intx_set_signal (struct vfio_pci_device *vdev,int fd) +static int vfio_intx_set_signal (struct vfio_pci_core_device *vdev,int fd) {struct pci_dev *pdev = vdev->pdev;unsigned long irqflags =IRQF_SHARED ;
@@ -223,7 +223,7 @@ static int vfio_intx_set_signal(struct vfio_pci_device *vdev, int fd)return 0 ; } -static void vfio_intx_disable (struct vfio_pci_device *vdev) +static void vfio_intx_disable (struct vfio_pci_core_device *vdev) {vfio_virqfd_disable (&vdev->ctx[0 ].unmask);vfio_virqfd_disable (&vdev->ctx[0 ].mask);
@@ -244,7 +244,7 @@ static irqreturn_t vfio_msihandler(int irq, void *arg)return IRQ_HANDLED ; } -static int vfio_msi_enable (struct vfio_pci_device *vdev,int nvec,bool msix) +static int vfio_msi_enable (struct vfio_pci_core_device *vdev,int nvec,bool msix) {struct pci_dev *pdev = vdev->pdev;unsigned int flag = msix ?PCI_IRQ_MSIX :PCI_IRQ_MSI ;
@@ -285,7 +285,7 @@ static int vfio_msi_enable(struct vfio_pci_device *vdev, int nvec, bool msix)return 0 ; } -static int vfio_msi_set_vector_signal (struct vfio_pci_device *vdev, +static int vfio_msi_set_vector_signal (struct vfio_pci_core_device *vdev,int vector,int fd,bool msix) {struct pci_dev *pdev = vdev->pdev;
@@ -364,7 +364,7 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev,return 0 ; } -static int vfio_msi_set_block (struct vfio_pci_device *vdev,unsigned start, +static int vfio_msi_set_block (struct vfio_pci_core_device *vdev,unsigned start,unsigned count,int32_t *fds,bool msix) {int i, j, ret =0 ;
@@ -385,7 +385,7 @@ static int vfio_msi_set_block(struct vfio_pci_device *vdev, unsigned start,return ret; } -static void vfio_msi_disable (struct vfio_pci_device *vdev,bool msix) +static void vfio_msi_disable (struct vfio_pci_core_device *vdev,bool msix) {struct pci_dev *pdev = vdev->pdev;int i;
@@ -417,7 +417,7 @@ static void vfio_msi_disable(struct vfio_pci_device *vdev, bool msix)/* * IOCTL support */ -static int vfio_pci_set_intx_unmask (struct vfio_pci_device *vdev, +static int vfio_pci_set_intx_unmask (struct vfio_pci_core_device *vdev,unsigned index,unsigned start,unsigned count,uint32_t flags,void *data) {
@@ -444,7 +444,7 @@ static int vfio_pci_set_intx_unmask(struct vfio_pci_device *vdev,return 0 ; } -static int vfio_pci_set_intx_mask (struct vfio_pci_device *vdev, +static int vfio_pci_set_intx_mask (struct vfio_pci_core_device *vdev,unsigned index,unsigned start,unsigned count,uint32_t flags,void *data) {
@@ -464,7 +464,7 @@ static int vfio_pci_set_intx_mask(struct vfio_pci_device *vdev,return 0 ; } -static int vfio_pci_set_intx_trigger (struct vfio_pci_device *vdev, +static int vfio_pci_set_intx_trigger (struct vfio_pci_core_device *vdev,unsigned index,unsigned start,unsigned count,uint32_t flags,void *data) {
@@ -507,7 +507,7 @@ static int vfio_pci_set_intx_trigger(struct vfio_pci_device *vdev,return 0 ; } -static int vfio_pci_set_msi_trigger (struct vfio_pci_device *vdev, +static int vfio_pci_set_msi_trigger (struct vfio_pci_core_device *vdev,unsigned index,unsigned start,unsigned count,uint32_t flags,void *data) {
@@ -613,7 +613,7 @@ static int vfio_pci_set_ctx_trigger_single(struct eventfd_ctx **ctx,return -EINVAL ; } -static int vfio_pci_set_err_trigger (struct vfio_pci_device *vdev, +static int vfio_pci_set_err_trigger (struct vfio_pci_core_device *vdev,unsigned index,unsigned start,unsigned count,uint32_t flags,void *data) {
@@ -624,7 +624,7 @@ static int vfio_pci_set_err_trigger(struct vfio_pci_device *vdev, count, flags, data); } -static int vfio_pci_set_req_trigger (struct vfio_pci_device *vdev, +static int vfio_pci_set_req_trigger (struct vfio_pci_core_device *vdev,unsigned index,unsigned start,unsigned count,uint32_t flags,void *data) {
@@ -635,11 +635,11 @@ static int vfio_pci_set_req_trigger(struct vfio_pci_device *vdev, count, flags, data); } -int vfio_pci_set_irqs_ioctl (struct vfio_pci_device *vdev,uint32_t flags, +int vfio_pci_set_irqs_ioctl (struct vfio_pci_core_device *vdev,uint32_t flags,unsigned index,unsigned start,unsigned count,void *data) { -int (*func)(struct vfio_pci_device *vdev,unsigned index, +int (*func)(struct vfio_pci_core_device *vdev,unsigned index,unsigned start,unsigned count,uint32_t flags,void *data) =NULL ;
drivers/vfio/pci/vfio_pci_rdwr.c +8 -8
@@ -38,7 +38,7 @@#define vfio_iowrite8 iowrite8#define VFIO_IOWRITE (size) \ -static int vfio_pci_iowrite##size(struct vfio_pci_device *vdev, \ +static int vfio_pci_iowrite##size(struct vfio_pci_core_device *vdev, \ bool test_mem, u##size val, void __iomem *io) \ { \ if (test_mem) { \
@@ -65,7 +65,7 @@ VFIO_IOWRITE(64)#endif #define VFIO_IOREAD (size) \ -static int vfio_pci_ioread##size(struct vfio_pci_device *vdev, \ +static int vfio_pci_ioread##size(struct vfio_pci_core_device *vdev, \ bool test_mem, u##size *val, void __iomem *io) \ { \ if (test_mem) { \
@@ -94,7 +94,7 @@ VFIO_IOREAD(32)* reads with -1. This is intended for handling MSI-X vector tables and * leftover space for ROM BARs. */ -static ssize_t do_io_rw (struct vfio_pci_device *vdev,bool test_mem, +static ssize_t do_io_rw (struct vfio_pci_core_device *vdev,bool test_mem,void __iomem *io,char __user *buf,loff_t off,size_t count,size_t x_start,size_t x_end,bool iswrite)
@@ -200,7 +200,7 @@ static ssize_t do_io_rw(struct vfio_pci_device *vdev, bool test_mem,return done; } -static int vfio_pci_setup_barmap (struct vfio_pci_device *vdev,int bar) +static int vfio_pci_setup_barmap (struct vfio_pci_core_device *vdev,int bar) {struct pci_dev *pdev = vdev->pdev;int ret;
@@ -224,7 +224,7 @@ static int vfio_pci_setup_barmap(struct vfio_pci_device *vdev, int bar)return 0 ; } -ssize_t vfio_pci_bar_rw (struct vfio_pci_device *vdev,char __user *buf, +ssize_t vfio_pci_bar_rw (struct vfio_pci_core_device *vdev,char __user *buf,size_t count,loff_t *ppos,bool iswrite) {struct pci_dev *pdev = vdev->pdev;
@@ -288,7 +288,7 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf,return done; } -ssize_t vfio_pci_vga_rw (struct vfio_pci_device *vdev,char __user *buf, +ssize_t vfio_pci_vga_rw (struct vfio_pci_core_device *vdev,char __user *buf,size_t count,loff_t *ppos,bool iswrite) {int ret;
@@ -384,7 +384,7 @@ static void vfio_pci_ioeventfd_do_write(struct vfio_pci_ioeventfd *ioeventfd,static int vfio_pci_ioeventfd_handler (void *opaque,void *unused) {struct vfio_pci_ioeventfd *ioeventfd = opaque; -struct vfio_pci_device *vdev = ioeventfd->vdev; +struct vfio_pci_core_device *vdev = ioeventfd->vdev;if (ioeventfd->test_mem) {if (!down_read_trylock (&vdev->memory_lock))
@@ -410,7 +410,7 @@ static void vfio_pci_ioeventfd_thread(void *opaque, void *unused)vfio_pci_ioeventfd_do_write (ioeventfd, ioeventfd->test_mem); } -long vfio_pci_ioeventfd (struct vfio_pci_device *vdev,loff_t offset, +long vfio_pci_ioeventfd (struct vfio_pci_core_device *vdev,loff_t offset,uint64_t data,int count,int fd) {struct pci_dev *pdev = vdev->pdev;
drivers/vfio/pci/vfio_pci_zdev.c +1 -1
@@ -114,7 +114,7 @@ static int zpci_pfip_cap(struct zpci_dev *zdev, struct vfio_info_cap *caps)/* * Add all supported capabilities to the VFIO_DEVICE_GET_INFO capability chain. */ -int vfio_pci_info_zdev_add_caps (struct vfio_pci_device *vdev, +int vfio_pci_info_zdev_add_caps (struct vfio_pci_core_device *vdev,struct vfio_info_cap *caps) {struct zpci_dev *zdev =to_zpci (vdev->pdev);
Signature · 1 line
2.18.1
PATCH v2 4/12 vfio/pci: Rename ops functions to fit core namings
In reply to Yishai HadasFrom: Max Gurtovoy <[email protected]>
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.
--- drivers/vfio/pci/vfio_pci_core.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
drivers/vfio/pci/vfio_pci_core.c +16 -16
@@ -533,7 +533,7 @@ static void vfio_pci_vf_token_user_add(struct vfio_pci_core_device *vdev, int vavfio_device_put (&pf_vdev->vdev); } -static void vfio_pci_close_device (struct vfio_device *core_vdev) +static void vfio_pci_core_close_device (struct vfio_device *core_vdev) {struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev);
@@ -554,7 +554,7 @@ static void vfio_pci_close_device(struct vfio_device *core_vdev)mutex_unlock (&vdev->igate); } -static int vfio_pci_open_device (struct vfio_device *core_vdev) +static int vfio_pci_core_open_device (struct vfio_device *core_vdev) {struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev);
@@ -727,7 +727,7 @@ int vfio_pci_register_dev_region(struct vfio_pci_core_device *vdev,return 0 ; } -static long vfio_pci_ioctl (struct vfio_device *core_vdev, +static long vfio_pci_core_ioctl (struct vfio_device *core_vdev,unsigned int cmd,unsigned long arg) { struct vfio_pci_core_device *vdev =
@@ -1302,7 +1302,7 @@ static ssize_t vfio_pci_rw(struct vfio_pci_core_device *vdev, char __user *buf,return -EINVAL ; } -static ssize_t vfio_pci_read (struct vfio_device *core_vdev,char __user *buf, +static ssize_t vfio_pci_core_read (struct vfio_device *core_vdev,char __user *buf,size_t count,loff_t *ppos) { struct vfio_pci_core_device *vdev =
@@ -1314,7 +1314,7 @@ static ssize_t vfio_pci_read(struct vfio_device *core_vdev, char __user *buf,return vfio_pci_rw (vdev, buf, count, ppos, false); } -static ssize_t vfio_pci_write (struct vfio_device *core_vdev,const char __user *buf, +static ssize_t vfio_pci_core_write (struct vfio_device *core_vdev,const char __user *buf,size_t count,loff_t *ppos) { struct vfio_pci_core_device *vdev =
@@ -1533,7 +1533,7 @@ static const struct vm_operations_struct vfio_pci_mmap_ops = { .fault = vfio_pci_mmap_fault, }; -static int vfio_pci_mmap (struct vfio_device *core_vdev,struct vm_area_struct *vma) +static int vfio_pci_core_mmap (struct vfio_device *core_vdev,struct vm_area_struct *vma) {struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev);
@@ -1604,7 +1604,7 @@ static int vfio_pci_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vreturn 0 ; } -static void vfio_pci_request (struct vfio_device *core_vdev,unsigned int count) +static void vfio_pci_core_request (struct vfio_device *core_vdev,unsigned int count) {struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev);
@@ -1720,7 +1720,7 @@ static int vfio_pci_validate_vf_token(struct vfio_pci_core_device *vdev,#define VF_TOKEN_ARG "vf_token=" -static int vfio_pci_match (struct vfio_device *core_vdev,char *buf) +static int vfio_pci_core_match (struct vfio_device *core_vdev,char *buf) {struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev);
@@ -1772,14 +1772,14 @@ static int vfio_pci_match(struct vfio_device *core_vdev, char *buf)static const struct vfio_device_ops vfio_pci_ops = { .name ="vfio-pci" , - .open_device = vfio_pci_open_device, - .close_device = vfio_pci_close_device, - .ioctl = vfio_pci_ioctl, - .read = vfio_pci_read, - .write = vfio_pci_write, - .mmap = vfio_pci_mmap, - .request = vfio_pci_request, - .match = vfio_pci_match, + .open_device = vfio_pci_core_open_device, + .close_device = vfio_pci_core_close_device, + .ioctl = vfio_pci_core_ioctl, + .read = vfio_pci_core_read, + .write = vfio_pci_core_write, + .mmap = vfio_pci_core_mmap, + .request = vfio_pci_core_request, + .match = vfio_pci_core_match, }; static int vfio_pci_bus_notifier(struct notifier_block *nb,
Signature · 1 line
2.18.1
PATCH v2 5/12 vfio/pci: Include vfio header in vfio_pci_core.h
In reply to Yishai HadasFrom: Max Gurtovoy <[email protected]>
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.
--- drivers/vfio/pci/vfio_pci_core.c | 1 - drivers/vfio/pci/vfio_pci_core.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/pci/vfio_pci_core.c +0 -1
@@ -23,7 +23,6 @@#include <linux/slab.h> #include <linux/types.h> #include <linux/uaccess.h> -#include <linux/vfio.h> #include <linux/vgaarb.h> #include <linux/nospec.h> #include <linux/sched/mm.h>
drivers/vfio/pci/vfio_pci_core.h +1 -0
@@ -10,6 +10,7 @@#include <linux/mutex.h> #include <linux/pci.h> +#include <linux/vfio.h> #include <linux/irqbypass.h> #include <linux/types.h> #include <linux/uuid.h>
Signature · 1 line
2.18.1
PATCH v2 6/12 vfio/pci: Split the pci_driver code out of vfio_pci_core.c
In reply to Yishai HadasFrom: Max Gurtovoy <[email protected]>
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.
--- drivers/vfio/pci/Makefile | 2 +- drivers/vfio/pci/vfio_pci.c | 225 ++++++++++++++++++++++++++ drivers/vfio/pci/vfio_pci_core.c | 264 +++++++------------------------ drivers/vfio/pci/vfio_pci_core.h | 23 +++ 4 files changed, 303 insertions(+), 211 deletions(-) create mode 100644 drivers/vfio/pci/vfio_pci.c
drivers/vfio/pci/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only -vfio-pci-y := vfio_pci_core.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o +vfio-pci-y := vfio_pci.o vfio_pci_core.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o vfio-pci-$(CONFIG_VFIO_PCI_IGD) += vfio_pci_igd.o vfio-pci-$(CONFIG_S390) += vfio_pci_zdev.o
drivers/vfio/pci/vfio_pci.c new file +225 -0
225 lines not on this page · raw message
drivers/vfio/pci/vfio_pci_core.c +54 -210
443 lines not on this page · raw message
drivers/vfio/pci/vfio_pci_core.h +23 -0
@@ -206,4 +206,27 @@ static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev, }#endif +/* Will be exported for vfio pci drivers usage */ +void vfio_pci_core_cleanup (void ); +int vfio_pci_core_init (void ); +void vfio_pci_core_close_device (struct vfio_device *core_vdev); +int vfio_pci_core_open_device (struct vfio_device *core_vdev); +void vfio_pci_core_init_device (struct vfio_pci_core_device *vdev, +struct pci_dev *pdev, +const struct vfio_device_ops *vfio_pci_ops); +int vfio_pci_core_register_device (struct vfio_pci_core_device *vdev); +void vfio_pci_core_uninit_device (struct vfio_pci_core_device *vdev); +void vfio_pci_core_unregister_device (struct vfio_pci_core_device *vdev); +int vfio_pci_core_sriov_configure (struct pci_dev *pdev,int nr_virtfn); +extern const struct pci_error_handlers vfio_pci_core_err_handlers; +long vfio_pci_core_ioctl (struct vfio_device *core_vdev,unsigned int cmd, +unsigned long arg); +ssize_t vfio_pci_core_read (struct vfio_device *core_vdev,char __user *buf, +size_t count,loff_t *ppos); +ssize_t vfio_pci_core_write (struct vfio_device *core_vdev,const char __user *buf, +size_t count,loff_t *ppos); +int vfio_pci_core_mmap (struct vfio_device *core_vdev,struct vm_area_struct *vma); +void vfio_pci_core_request (struct vfio_device *core_vdev,unsigned int count); +int vfio_pci_core_match (struct vfio_device *core_vdev,char *buf); +#endif /* VFIO_PCI_CORE_H */
Signature · 1 line
2.18.1
Re: [PATCH V2 06/12] vfio/pci: Split the pci_driver code out of vfio_pci_core.c
drivers/vfio/pci/vfio_pci.c line 132
Quoted 4 lines · On Wed, 18 Aug 2021 18:16:00 +0300 Yishai Hadas <[email protected]> wrote:
drivers/vfio/pci/vfio_pci.c new file +4
-0+ +static int vfio_pci_sriov_configure (struct pci_dev *pdev,int nr_virtfn) +{ +might_sleep ();
vfio_pci_core_sriov_configure() retained the might_sleep(), it shouldn't be needed here.
Quoted 6 lines
drivers/vfio/pci/vfio_pci.c new file +6
-0+ +if (!enable_sriov) +return -ENOENT ; + +return vfio_pci_core_sriov_configure (pdev, nr_virtfn); +}
...
drivers/vfio/pci/vfio_pci_core.c static struct vfio_pci_core_device *get_pf_vdev(struct vfio_pci_core_device *vde · line 452
Quoted 6 lines
drivers/vfio/pci/vfio_pci_core.c +1
-1@@ -509,7 +449,7 @@ static struct vfio_pci_core_device *get_pf_vdev(struct vfio_pci_core_device *vdeif (!pf_dev)return NULL ; -if (pci_dev_driver (physfn) != &vfio_pci_driver) { +if (pci_dev_driver (physfn) !=pci_dev_driver (vdev->pdev)) {
I think this means that the PF and VF must use the same vfio-pci "variant" driver, it's too bad we're not enabling vfio-pci to own the PF while vfio-vendor-foo-pci owns the VF since our SR-IOV security model remains in the core. We can work on that later though, no loss of functionality here.
...
Quoted 4 lines
drivers/vfio/pci/vfio_pci_core.c +0
-0@@ -1795,12 +1723,12 @@ static int vfio_pci_bus_notifier(struct notifier_block *nb,pci_info (vdev->pdev,"Captured SR-IOV VF %s driver_override\n" ,pci_name (pdev)); pdev->driver_override = kasprintf(GFP_KERNEL, "%s",
drivers/vfio/pci/vfio_pci_core.c static int vfio_pci_bus_notifier(struct notifier_block *nb, · line 1733
Quoted 10 lines
drivers/vfio/pci/vfio_pci_core.c +2
-2- vfio_pci_ops.name); + vdev->vdev.ops->name); }else if (action ==BUS_NOTIFY_BOUND_DRIVER && pdev->is_virtfn && physfn == vdev->pdev) {struct pci_driver *drv =pci_dev_driver (pdev); -if (drv && drv != &vfio_pci_driver) +if (drv && drv !=pci_dev_driver (vdev->pdev)) pci_warn(vdev->pdev, "VF %s bound to driver %s while PF bound to vfio-pci\n",
"vfio-pci" is hardcoded in this comment. There are a few other user visible instances of this in vfio-pci-core.c as well:
MODULE_PARM_DESC(disable_vga, "Disable VGA resource access through vfio-pci");
ret = pci_request_selected_regions(pdev,
1 << index, "vfio-pci");
pci_info_ratelimited(vdev->pdev,
"VF token incorrectly provided, PF not bound to vfio-pci\n");We should try to fix or reword as many of these as we reasonably can. Thanks,
Alex
Re: [PATCH V2 06/12] vfio/pci: Split the pci_driver code out of vfio_pci_core.c
Quoted 49 lines · On Thu, 19 Aug 2021 15:12:35 -0600 Alex Williamson…
drivers/vfio/pci/vfio_pci.c line 132
Quoted 4 lines · On Wed, 18 Aug 2021 18:16:00 +0300 Yishai Hadas <[email protected]> wrote:
drivers/vfio/pci/vfio_pci.c new file +4
-0+ +static int vfio_pci_sriov_configure (struct pci_dev *pdev,int nr_virtfn) +{ +might_sleep ();
vfio_pci_core_sriov_configure()retained themight_sleep(), it shouldn't be needed here.Quoted 6 lines
drivers/vfio/pci/vfio_pci.c new file +6
-0+ +if (!enable_sriov) +return -ENOENT ; + +return vfio_pci_core_sriov_configure (pdev, nr_virtfn); +}...
drivers/vfio/pci/vfio_pci_core.c static struct vfio_pci_core_device *get_pf_vdev(struct vfio_pci_core_device *vde · line 452
Quoted 6 lines
drivers/vfio/pci/vfio_pci_core.c +1
-1@@ -509,7 +449,7 @@ static struct vfio_pci_core_device *get_pf_vdev(struct vfio_pci_core_device *vdeif (!pf_dev)return NULL ; -if (pci_dev_driver (physfn) != &vfio_pci_driver) { +if (pci_dev_driver (physfn) !=pci_dev_driver (vdev->pdev)) {I think this means that the PF and VF must use the same vfio-pci "variant" driver, it's too bad we're not enabling vfio-pci to own the PF while vfio-vendor-foo-pci owns the VF since our SR-IOV security model remains in the core. We can work on that later though, no loss of functionality here.
...
Quoted 4 lines
drivers/vfio/pci/vfio_pci_core.c +0
-0@@ -1795,12 +1723,12 @@ static int vfio_pci_bus_notifier(struct notifier_block *nb,pci_info (vdev->pdev,"Captured SR-IOV VF %s driver_override\n" ,pci_name (pdev)); pdev->driver_override = kasprintf(GFP_KERNEL, "%s",drivers/vfio/pci/vfio_pci_core.c static int vfio_pci_bus_notifier(struct notifier_block *nb, · line 1733
Quoted 10 lines
drivers/vfio/pci/vfio_pci_core.c +2
-2- vfio_pci_ops.name); + vdev->vdev.ops->name); }else if (action ==BUS_NOTIFY_BOUND_DRIVER && pdev->is_virtfn && physfn == vdev->pdev) {struct pci_driver *drv =pci_dev_driver (pdev); -if (drv && drv != &vfio_pci_driver) +if (drv && drv !=pci_dev_driver (vdev->pdev)) pci_warn(vdev->pdev, "VF %s bound to driver %s while PF bound to vfio-pci\n","vfio-pci" is hardcoded in this comment. There are a few other user visible instances of this in
vfio-pci-core.cas well:
Quoted 1 line
MODULE_PARM_DESC(disable_vga, "Disable VGA resource access through vfio-pci");
I see this one is resolved in a later patch. Thanks,
Alex
Quoted 11 lines
ret = pci_request_selected_regions(pdev, 1 << index, "vfio-pci"); pci_info_ratelimited(vdev->pdev, "VF token incorrectly provided, PF not bound to vfio-pci\n");We should try to fix or reword as many of these as we reasonably can. Thanks,
Alex
Re: [PATCH V2 06/12] vfio/pci: Split the pci_driver code out of vfio_pci_core.c
In reply to Alex WilliamsonQuoted 21 lines · Alex Williamson
drivers/vfio/pci/vfio_pci.c line 132
Quoted 4 lines · On Wed, 18 Aug 2021 18:16:00 +0300 Yishai Hadas <[email protected]> wrote:
drivers/vfio/pci/vfio_pci.c new file +4
-0+ +static int vfio_pci_sriov_configure (struct pci_dev *pdev,int nr_virtfn) +{ +might_sleep ();
vfio_pci_core_sriov_configure()retained themight_sleep(), it shouldn't be needed here.Quoted 6 lines
drivers/vfio/pci/vfio_pci.c new file +6
-0+ +if (!enable_sriov) +return -ENOENT ; + +return vfio_pci_core_sriov_configure (pdev, nr_virtfn); +}...
Quoted 4 lines
drivers/vfio/pci/vfio_pci_core.c +0
-0@@ -509,7 +449,7 @@ static struct vfio_pci_core_device *get_pf_vdev(struct vfio_pci_core_device *vdeif (!pf_dev)return NULL ;
Quoted 8 lines
drivers/vfio/pci/vfio_pci_core.c static struct vfio_pci_core_device *get_pf_vdev(struct vfio_pci_core_device *vde · line 452
Quoted 2 lines
drivers/vfio/pci/vfio_pci_core.c +1
-1-if (pci_dev_driver (physfn) != &vfio_pci_driver) { +if (pci_dev_driver (physfn) !=pci_dev_driver (vdev->pdev)) {I think this means that the PF and VF must use the same vfio-pci "variant" driver, it's too bad we're not enabling vfio-pci to own the PF while vfio-vendor-foo-pci owns the VF since our SR-IOV security model remains in the core. We can work on that later though, no loss of functionality here.
Yes, there are still a few of these references that want to go away..
For this one we probably need to introduce a 'class' notion to the vfio_device_ops to confirm that the container_of cast is OK.
It was something on my list to look at after this is settled since it is pretty minor
Quoted 4 lines
"vfio-pci" is hardcoded in this comment. There are a few other user visible instances of this in
vfio-pci-core.cas well:
MODULE_PARM_DESC(disable_vga, "Disable VGA resource access through vfio-pci");
This module_param is on vfio_pci - ideally we'd lift the the VGA code out of vfio_pci_core into vfio_pci since it really shouldn't apply to device specific drivers anyhow.
Jason
PATCH v2 7/12 vfio/pci: Move igd initialization to vfio_pci.c
In reply to Yishai HadasFrom: Max Gurtovoy <[email protected]>
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.
--- drivers/vfio/pci/vfio_pci.c | 29 +++++++++++++++++++++++- drivers/vfio/pci/vfio_pci_core.c | 39 ++++---------------------------- drivers/vfio/pci/vfio_pci_core.h | 9 +++++++- 3 files changed, 41 insertions(+), 36 deletions(-)
drivers/vfio/pci/vfio_pci.c +28 -1
@@ -82,9 +82,36 @@ static bool vfio_pci_is_denylisted(struct pci_dev *pdev)return true; } +static int vfio_pci_open_device (struct vfio_device *core_vdev) +{ +struct vfio_pci_core_device *vdev = + container_of(core_vdev, struct vfio_pci_core_device, vdev); +struct pci_dev *pdev = vdev->pdev; +int ret; + + ret =vfio_pci_core_enable (vdev); +if (ret) +return ret; + +if (vfio_pci_is_vga (pdev) && + pdev->vendor ==PCI_VENDOR_ID_INTEL && +IS_ENABLED (CONFIG_VFIO_PCI_IGD )) { + ret =vfio_pci_igd_init (vdev); +if (ret && ret != -ENODEV ) { +pci_warn (pdev,"Failed to setup Intel IGD regions\n" ); +vfio_pci_core_disable (vdev); +return ret; + } + } + +vfio_pci_core_finish_enable (vdev); + +return 0 ; +} +static const struct vfio_device_ops vfio_pci_ops = { .name ="vfio-pci" , - .open_device = vfio_pci_core_open_device, + .open_device = vfio_pci_open_device, .close_device = vfio_pci_core_close_device, .ioctl = vfio_pci_core_ioctl, .read = vfio_pci_core_read,
drivers/vfio/pci/vfio_pci_core.c +5 -34
@@ -91,11 +91,6 @@ static unsigned int vfio_pci_set_vga_decode(void *opaque, bool single_vga)return decodes; } -static inline bool vfio_pci_is_vga (struct pci_dev *pdev) -{ -return (pdev->class >>8 ) ==PCI_CLASS_DISPLAY_VGA ; -} -static void vfio_pci_probe_mmaps (struct vfio_pci_core_device *vdev) {struct resource *res;
@@ -166,7 +161,6 @@ static void vfio_pci_probe_mmaps(struct vfio_pci_core_device *vdev)struct vfio_pci_group_info ;static bool vfio_pci_dev_set_try_reset (struct vfio_device_set *dev_set); -static void vfio_pci_disable (struct vfio_pci_core_device *vdev);static int vfio_pci_dev_set_hot_reset (struct vfio_device_set *dev_set,struct vfio_pci_group_info *groups);
@@ -252,7 +246,7 @@ int vfio_pci_set_power_state(struct vfio_pci_core_device *vdev, pci_power_t statreturn ret; } -static int vfio_pci_enable (struct vfio_pci_core_device *vdev) +int vfio_pci_core_enable (struct vfio_pci_core_device *vdev) {struct pci_dev *pdev = vdev->pdev;int ret;
@@ -321,26 +315,11 @@ static int vfio_pci_enable(struct vfio_pci_core_device *vdev)if (!vfio_vga_disabled () &&vfio_pci_is_vga (pdev)) vdev->has_vga = true; -if (vfio_pci_is_vga (pdev) && - pdev->vendor ==PCI_VENDOR_ID_INTEL && -IS_ENABLED (CONFIG_VFIO_PCI_IGD )) { - ret =vfio_pci_igd_init (vdev); -if (ret && ret != -ENODEV ) { -pci_warn (pdev,"Failed to setup Intel IGD regions\n" ); - goto disable_exit; - } - } - -vfio_pci_probe_mmaps (vdev);return 0 ; - -disable_exit: -vfio_pci_disable (vdev); -return ret; } -static void vfio_pci_disable (struct vfio_pci_core_device *vdev) +void vfio_pci_core_disable (struct vfio_pci_core_device *vdev) {struct pci_dev *pdev = vdev->pdev;struct vfio_pci_dummy_resource *dummy_res, *tmp;
@@ -479,7 +458,7 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev)vfio_pci_vf_token_user_add (vdev,-1 );vfio_spapr_pci_eeh_release (vdev->pdev); -vfio_pci_disable (vdev); +vfio_pci_core_disable (vdev);mutex_lock (&vdev->igate);if (vdev->err_trigger) {
@@ -493,19 +472,11 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev)mutex_unlock (&vdev->igate); } -int vfio_pci_core_open_device (struct vfio_device *core_vdev) +void vfio_pci_core_finish_enable (struct vfio_pci_core_device *vdev) { -struct vfio_pci_core_device *vdev = - container_of(core_vdev, struct vfio_pci_core_device, vdev); -int ret =0 ; - - ret =vfio_pci_enable (vdev); -if (ret) -return ret; - +vfio_pci_probe_mmaps (vdev);vfio_spapr_pci_eeh_open (vdev->pdev);vfio_pci_vf_token_user_add (vdev,1 ); -return 0 ; }static int vfio_pci_get_irq_count (struct vfio_pci_core_device *vdev,int irq_type)
drivers/vfio/pci/vfio_pci_core.h +8 -1
@@ -210,7 +210,6 @@ static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,void vfio_pci_core_cleanup (void );int vfio_pci_core_init (void );void vfio_pci_core_close_device (struct vfio_device *core_vdev); -int vfio_pci_core_open_device (struct vfio_device *core_vdev);void vfio_pci_core_init_device (struct vfio_pci_core_device *vdev,struct pci_dev *pdev,const struct vfio_device_ops *vfio_pci_ops);
@@ -228,5 +227,13 @@ ssize_t vfio_pci_core_write(struct vfio_device *core_vdev, const char __user *buint vfio_pci_core_mmap (struct vfio_device *core_vdev,struct vm_area_struct *vma);void vfio_pci_core_request (struct vfio_device *core_vdev,unsigned int count);int vfio_pci_core_match (struct vfio_device *core_vdev,char *buf); +int vfio_pci_core_enable (struct vfio_pci_core_device *vdev); +void vfio_pci_core_disable (struct vfio_pci_core_device *vdev); +void vfio_pci_core_finish_enable (struct vfio_pci_core_device *vdev); + +static inline bool vfio_pci_is_vga (struct pci_dev *pdev) +{ +return (pdev->class >>8 ) ==PCI_CLASS_DISPLAY_VGA ; +}#endif /* VFIO_PCI_CORE_H */
Signature · 1 line
2.18.1
PATCH v2 8/12 vfio/pci: Move module parameters to vfio_pci.c
In reply to Yishai HadasThis 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
--- drivers/vfio/pci/vfio_pci.c | 23 +++++++++++++++++++++++ drivers/vfio/pci/vfio_pci_core.c | 20 ++++++++------------ drivers/vfio/pci/vfio_pci_core.h | 2 ++ 3 files changed, 33 insertions(+), 12 deletions(-)
drivers/vfio/pci/vfio_pci.c +23 -0
@@ -34,6 +34,22 @@ static char ids[1024] __initdata;module_param_string (ids, ids,sizeof (ids),0 );MODULE_PARM_DESC (ids,"Initial PCI IDs to add to the vfio driver, format is \"vendor:device[:subvendor[:subdevice[:class[:class_mask]]]]\" and multiple comma separated entries can be specified" ); +static bool nointxmask; +module_param_named (nointxmask, nointxmask, bool,S_IRUGO |S_IWUSR ); +MODULE_PARM_DESC (nointxmask, +"Disable support for PCI 2.3 style INTx masking. If this resolves problems for specific devices, report lspci -vvvxxx to [email protected] so the device can be fixed automatically via the broken_intx_masking flag." ); + +#ifdef CONFIG_VFIO_PCI_VGA +static bool disable_vga; +module_param (disable_vga, bool,S_IRUGO ); +MODULE_PARM_DESC (disable_vga,"Disable VGA resource access through vfio-pci" ); +#endif + +static bool disable_idle_d3; +module_param (disable_idle_d3, bool,S_IRUGO |S_IWUSR ); +MODULE_PARM_DESC (disable_idle_d3, +"Disable using the PCI D3 low power state for idle, unused devices" ); +static bool enable_sriov;#ifdef CONFIG_PCI_IOV module_param (enable_sriov, bool,0644 );
@@ -217,6 +233,13 @@ static void __init vfio_pci_fill_ids(void)static int __init vfio_pci_init (void ) {int ret; +bool is_disable_vga = true; + +#ifdef CONFIG_VFIO_PCI_VGA + is_disable_vga = disable_vga; +#endif + +vfio_pci_core_set_params (nointxmask, is_disable_vga, disable_idle_d3); ret =vfio_pci_core_init ();if (ret)
drivers/vfio/pci/vfio_pci_core.c +8 -12
@@ -28,20 +28,8 @@#include "vfio_pci_core.h" static bool nointxmask; -module_param_named (nointxmask, nointxmask, bool,S_IRUGO |S_IWUSR ); -MODULE_PARM_DESC (nointxmask, -"Disable support for PCI 2.3 style INTx masking. If this resolves problems for specific devices, report lspci -vvvxxx to [email protected] so the device can be fixed automatically via the broken_intx_masking flag." ); - -#ifdef CONFIG_VFIO_PCI_VGA static bool disable_vga; -module_param (disable_vga, bool,S_IRUGO ); -MODULE_PARM_DESC (disable_vga,"Disable VGA resource access through vfio-pci" ); -#endif -static bool disable_idle_d3; -module_param (disable_idle_d3, bool,S_IRUGO |S_IWUSR ); -MODULE_PARM_DESC (disable_idle_d3, -"Disable using the PCI D3 low power state for idle, unused devices" );static inline bool vfio_vga_disabled (void ) {
@@ -2122,6 +2110,14 @@ static bool vfio_pci_dev_set_try_reset(struct vfio_device_set *dev_set)return true; } +void vfio_pci_core_set_params (bool is_nointxmask,bool is_disable_vga, +bool is_disable_idle_d3) +{ + nointxmask = is_nointxmask; + disable_vga = is_disable_vga; + disable_idle_d3 = is_disable_idle_d3; +} +/* This will become the __exit function of vfio_pci_core.ko */ void vfio_pci_core_cleanup (void ) {
drivers/vfio/pci/vfio_pci_core.h +2 -0
@@ -209,6 +209,8 @@ static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,/* Will be exported for vfio pci drivers usage */ void vfio_pci_core_cleanup (void );int vfio_pci_core_init (void ); +void vfio_pci_core_set_params (bool nointxmask,bool is_disable_vga, +bool is_disable_idle_d3);void vfio_pci_core_close_device (struct vfio_device *core_vdev); void vfio_pci_core_init_device(struct vfio_pci_core_device *vdev, struct pci_dev *pdev,
Signature · 1 line
2.18.1
PATCH v2 9/12 PCI: Add 'override_only' bitmap to struct pci_device_id
In reply to Yishai HadasFrom: Max Gurtovoy <[email protected]>
Allow 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.
To achieve it, we add the 'override_only' bitmap to struct pci_device_id and a helper macro named 'PCI_DEVICE_DRIVER_OVERRIDE' to enable setting specific bits on it.
The first bit (i.e. 'PCI_ID_F_VFIO_DRIVER_OVERRIDE') indicates that the match entry is for the VFIO subsystem, it can be set by another helper macro named 'PCI_DRIVER_OVERRIDE_DEVICE_VFIO'.
These match entries are prefixed with "vfio_" in the modules.alias.
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 userspace 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's 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.
--- Documentation/PCI/pci.rst | 1 + drivers/pci/pci-driver.c | 27 ++++++++++++++++++++------- drivers/vfio/pci/vfio_pci.c | 9 ++++++++- include/linux/mod_devicetable.h | 6 ++++++ include/linux/pci.h | 28 ++++++++++++++++++++++++++++ scripts/mod/devicetable-offsets.c | 1 + scripts/mod/file2alias.c | 8 ++++++-- 7 files changed, 70 insertions(+), 10 deletions(-)
Documentation/PCI/pci.rst +1 -0
@@ -103,6 +103,7 @@ need pass only as many optional fields as necessary: - subvendor and subdevice fields default to PCI_ANY_ID (FFFFFFFF) - class and classmask fields default to 0 - driver_data defaults to 0UL. + - override_only field defaults to 0. Note that driver_data must match the value used by any of the pci_device_id entries defined in the driver. This makes the driver_data field mandatory
drivers/pci/pci-driver.c +20 -7
@@ -136,7 +136,7 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv, struct pci_dev *dev) {struct pci_dynid *dynid; -const struct pci_device_id *found_id =NULL ; +const struct pci_device_id *found_id =NULL , *ids;/* When driver_override is set, only bind to the matching driver */ if (dev->driver_override &&strcmp (dev->driver_override, drv->name))
@@ -152,14 +152,27 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv, }spin_unlock (&drv->dynids.lock); -if (!found_id) - found_id =pci_match_id (drv->id_table, dev); +if (found_id) +return found_id; -/* driver_override will always match, send a dummy id */ -if (!found_id && dev->driver_override) - found_id = &pci_device_id_any; +for (ids = drv->id_table; (found_id =pci_match_id (ids, dev)); + ids = found_id +1 ) { +/* +* The match table is split based on driver_override. Check the +* override_only as well so that any matching entry is +* returned. +*/ +if (!found_id->override_only || dev->driver_override) +return found_id; + } -return found_id; +/* +* if no static match, driver_override will always match, send a dummy +* id. +*/ +if (dev->driver_override) +return &pci_device_id_any; +return NULL ; }/**
drivers/vfio/pci/vfio_pci.c +8 -1
@@ -180,9 +180,16 @@ static int vfio_pci_sriov_configure(struct pci_dev *pdev, int nr_virtfn)return vfio_pci_core_sriov_configure (pdev, nr_virtfn); } +static const struct pci_device_id vfio_pci_table[] = { + {PCI_DRIVER_OVERRIDE_DEVICE_VFIO (PCI_ANY_ID ,PCI_ANY_ID ) },/* match all by default */ + {} +}; + +MODULE_DEVICE_TABLE (pci, vfio_pci_table); +static struct pci_driver vfio_pci_driver = { .name ="vfio-pci" , - .id_table =NULL ,/* only dynamic ids */ + .id_table = vfio_pci_table, .probe = vfio_pci_probe, .remove = vfio_pci_remove, .sriov_configure = vfio_pci_sriov_configure,
include/linux/mod_devicetable.h +6 -0
@@ -16,6 +16,10 @@ typedef unsigned long kernel_ulong_t;#define PCI_ANY_ID (~0) +enum { +PCI_ID_F_VFIO_DRIVER_OVERRIDE =1 <<0 , +}; +/** * struct pci_device_id - PCI device ID structure * @vendor: Vendor ID to match (or PCI_ANY_ID)
@@ -34,12 +38,14 @@ typedef unsigned long kernel_ulong_t;* Best practice is to use driver_data as an index * into a static list of equivalent device types, * instead of using it as a pointer. +* @override_only: Bitmap for override_only PCI drivers. */ struct pci_device_id {__u32 vendor, device;/* Vendor and device ID or PCI_ANY_ID*/ __u32 subvendor, subdevice;/* Subsystem ID's or PCI_ANY_ID */ __u32 class, class_mask;/* (class,subclass,prog-if) triplet */ kernel_ulong_t driver_data;/* Data private to the driver */ +__u32 override_only; };
include/linux/pci.h +28 -0
@@ -901,6 +901,34 @@ struct pci_driver { .vendor = (vend), .device = (dev), \ .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID +/** +* PCI_DEVICE_DRIVER_OVERRIDE - macro used to describe a PCI device with +* override_only flags. +* @vend: the 16 bit PCI Vendor ID +* @dev: the 16 bit PCI Device ID +* @driver_override: PCI Device override_only bitmap +* +* This macro is used to create a struct pci_device_id that matches a +* specific device. The subvendor and subdevice fields will be set to +* PCI_ANY_ID. + */ +#define PCI_DEVICE_DRIVER_OVERRIDE (vend, dev, driver_override) \ + .vendor = (vend), .device = (dev), .subvendor = PCI_ANY_ID, \ + .subdevice = PCI_ANY_ID, .override_only = (driver_override) + +/** +* PCI_DRIVER_OVERRIDE_DEVICE_VFIO - macro used to describe a VFIO +* "driver_override" PCI device. +* @vend: the 16 bit PCI Vendor ID +* @dev: the 16 bit PCI Device ID +* +* This macro is used to create a struct pci_device_id that matches a +* specific device. The subvendor and subdevice fields will be set to +* PCI_ANY_ID and the flags will be set to PCI_ID_F_VFIO_DRIVER_OVERRIDE. +*/ +#define PCI_DRIVER_OVERRIDE_DEVICE_VFIO (vend, dev) \ + PCI_DEVICE_DRIVER_OVERRIDE(vend, dev, PCI_ID_F_VFIO_DRIVER_OVERRIDE) +/** * PCI_DEVICE_SUB - macro used to describe a specific PCI device with subsystem * @vend: the 16 bit PCI Vendor ID
scripts/mod/devicetable-offsets.c +1 -0
@@ -42,6 +42,7 @@ int main(void)DEVID_FIELD (pci_device_id, subdevice);DEVID_FIELD (pci_device_id, class);DEVID_FIELD (pci_device_id, class_mask); +DEVID_FIELD (pci_device_id, override_only);DEVID (ccw_device_id);DEVID_FIELD (ccw_device_id, match_flags);
scripts/mod/file2alias.c +6 -2
@@ -426,7 +426,7 @@ static int do_ieee1394_entry(const char *filename,return 1 ; } -/* Looks like: pci:vNdNsvNsdNbcNscNiN. */ +/* Looks like: pci:vNdNsvNsdNbcNscNiN or <prefix>_pci:vNdNsvNsdNbcNscNiN. */ static int do_pci_entry (const char *filename,void *symval,char *alias) {
@@ -440,8 +440,12 @@ static int do_pci_entry(const char *filename,DEF_FIELD (symval, pci_device_id, subdevice);DEF_FIELD (symval, pci_device_id, class);DEF_FIELD (symval, pci_device_id, class_mask); +DEF_FIELD (symval, pci_device_id, override_only); -strcpy (alias,"pci:" ); +if (override_only &PCI_ID_F_VFIO_DRIVER_OVERRIDE ) +strcpy (alias,"vfio_pci:" ); +else +strcpy (alias,"pci:" );ADD (alias,"v" , vendor !=PCI_ANY_ID , vendor);ADD (alias,"d" , device !=PCI_ANY_ID , device);ADD (alias,"sv" , subvendor !=PCI_ANY_ID , subvendor);
Signature · 1 line
2.18.1
Re: [PATCH V2 09/12] PCI: Add 'override_only' bitmap to struct pci_device_id
Quoted 51 lines · Yishai Hadas
From: Max Gurtovoy <[email protected]>
Allow 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_overridesysfs.To achieve it, we add the '
override_only' bitmap to structpci_device_idand a helper macro named 'PCI_DEVICE_DRIVER_OVERRIDE' to enable setting specific bits on it.The first bit (i.e. '
PCI_ID_F_VFIO_DRIVER_OVERRIDE') indicates that the match entry is for the VFIO subsystem, it can be set by another helper macro named 'PCI_DRIVER_OVERRIDE_DEVICE_VFIO'.These match entries are prefixed with "
vfio_" in the modules.alias.For example the resulting modules.alias may have:
alias pci:v000015B3d00001021sv*sd*bc*sc*i*
mlx5_corealias vfio_pci:v000015B3d00001021sv*sd*bc*sc*i*mlx5_vfio_pcialias vfio_pci:v*d*sv*sd*bc*sc*i*vfio_pciIn this example
mlx5_coreandmlx5_vfio_pcimatch to the same PCI device. The kernel will autoload and autobind tomlx5_corebut the kernel and udev mechanisms will ignoremlx5_vfio_pci.When userspace wants to change a device to the VFIO subsystem userspace can implement a generic algorithm:
1) Identify the sysfs path to the device:
/sys/devices/pci0000:00/0000:00:01.0/0000:01:00.02) Get the modalias string from the kernel:
$ cat /sys/bus/pci/devices/0000:01:00.0/modalias pci:v000015B3d00001021sv000015B3sd00000001bc02sc00i003) Prefix it with
vfio_:vfio_pci:v000015B3d00001021sv000015B3sd00000001bc02sc00i004) 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_pci5) modprobe the matched module name:
$ modprobe mlx5_vfio_pci6) cat the matched module name to
driver_override:echo mlx5_vfio_pci > /sys/bus/pci/devices/0000:01:00.0/driver_override
Quoted 7 lines
7) unbind device from original module
echo 0000:01:00.0 > /sys/bus/pci/devices/0000:01:00.0/driver/unbind8) probe PCI drivers (or explicitly bind to
mlx5_vfio_pci)echo 0000:01:00.0 > /sys/bus/pci/drivers_probeThe algorithm is independent of bus type. In future the other buses's with
s/buses's/buses/
Quoted 61 lines
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_driverwhich results in one new line in the modules.alias:alias vfio_pci:v*d*sv*sd*bc*sc*i*
vfio_pciLater series introduce additional HW specific VFIO PCI drivers, such as
mlx5_vfio_pci.Signed-off-by Max Gurtovoy <[email protected]>Signed-off-by Jason Gunthorpe <[email protected]>Signed-off-by Yishai Hadas <[email protected]>--- Documentation/PCI/pci.rst | 1 + drivers/pci/pci-driver.c | 27 ++++++++++++++++++++------- drivers/vfio/pci/vfio_pci.c | 9 ++++++++- include/linux/mod_devicetable.h | 6 ++++++ include/linux/pci.h | 28 ++++++++++++++++++++++++++++ scripts/mod/devicetable-offsets.c | 1 + scripts/mod/file2alias.c | 8 ++++++-- 7 files changed, 70 insertions(+), 10 deletions(-)Documentation/PCI/pci.rst +1
-0@@ -103,6 +103,7 @@ need pass only as many optional fields as necessary: - subvendor and subdevice fields default to PCI_ANY_ID (FFFFFFFF) - class and classmask fields default to 0 - driver_data defaults to 0UL. + - override_only field defaults to 0. Note that driver_data must match the value used by any of the pci_device_id entries defined in the driver. This makes the driver_data field mandatorydrivers/pci/pci-driver.c +3
-5@@ -136,7 +136,7 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv, struct pci_dev *dev) {struct pci_dynid *dynid; -const struct pci_device_id *found_id =NULL ; +const struct pci_device_id *found_id =NULL , *ids;/* When driver_override is set, only bind to the matching driver */ if (dev->driver_override &&strcmp (dev->driver_override, drv->name))@@ -152,14 +152,27 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv, }spin_unlock (&drv->dynids.lock); -if (!found_id) - found_id =pci_match_id (drv->id_table, dev); +if (found_id) +return found_id; -/* driver_override will always match, send a dummy id */ -if (!found_id && dev->driver_override)
drivers/pci/pci-driver.c static const struct pci_device_id *pci_match_device(struct pci_driver *drv, · line 166
Quoted 10 lines
drivers/pci/pci-driver.c +9
-1- found_id = &pci_device_id_any; +for (ids = drv->id_table; (found_id =pci_match_id (ids, dev)); + ids = found_id +1 ) { +/* +* The match table is split based on driver_override. Check the +* override_only as well so that any matching entry is +* returned. +*/ +if (!found_id->override_only || dev->driver_override) +return found_id;
The negation makes this short, but IMO, makes this harder to read. I'd rather test for the special case directly instead of testing for the *absence* of the special case, e.g.,
if (found_id->override_only) {
if (dev->driver_override)
return found_id;
} else
return found_id;drivers/pci/pci-driver.c static const struct pci_device_id *pci_match_device(struct pci_driver *drv, · line 171
Quoted 6 lines
drivers/pci/pci-driver.c +4
-1+ } -return found_id; +/* +* if no static match, driver_override will always match, send a dummy +* id.
I think the original comment was better. This comment implies that we only checked for static matches above, but we actually checked for *both* dynamic IDs and static IDs.
Quoted 45 lines
drivers/pci/pci-driver.c +4
-0+*/ +if (dev->driver_override) +return &pci_device_id_any; +return NULL ; }/** drivers/vfio/pci/vfio_pci.c +8
-1@@ -180,9 +180,16 @@ static int vfio_pci_sriov_configure(struct pci_dev *pdev, int nr_virtfn)return vfio_pci_core_sriov_configure (pdev, nr_virtfn); } +static const struct pci_device_id vfio_pci_table[] = { + {PCI_DRIVER_OVERRIDE_DEVICE_VFIO (PCI_ANY_ID ,PCI_ANY_ID ) },/* match all by default */ + {} +}; + +MODULE_DEVICE_TABLE (pci, vfio_pci_table); +static struct pci_driver vfio_pci_driver = { .name ="vfio-pci" , - .id_table =NULL ,/* only dynamic ids */ + .id_table = vfio_pci_table, .probe = vfio_pci_probe, .remove = vfio_pci_remove, .sriov_configure = vfio_pci_sriov_configure,include/linux/mod_devicetable.h +4
-0@@ -16,6 +16,10 @@ typedef unsigned long kernel_ulong_t;#define PCI_ANY_ID (~0) +enum { +PCI_ID_F_VFIO_DRIVER_OVERRIDE =1 <<0 , +}; +/** * struct pci_device_id - PCI device ID structure * @vendor: Vendor ID to match (or PCI_ANY_ID)
include/linux/mod_devicetable.h typedef unsigned long kernel_ulong_t; · line 41
Quoted 4 lines
include/linux/mod_devicetable.h +1
-0@@ -34,12 +38,14 @@ typedef unsigned long kernel_ulong_t;* Best practice is to use driver_data as an index * into a static list of equivalent device types, * instead of using it as a pointer. +* @override_only: Bitmap for override_only PCI drivers.
"Match only when dev->driver_override is this driver"?
As far as PCI core is concerned there's no need for this to be a bitmap.
I think this would make more sense if split into two patches. The first would add override_only and change pci_match_device(). Then there's no confusion about whether this is specific to VFIO.
The second can add PCI_ID_F_VFIO_DRIVER_OVERRIDE and make the file2alias.c changes. Most of the commit log applies to this part.
Quoted 91 lines
include/linux/mod_devicetable.h +1
-0*/ struct pci_device_id {__u32 vendor, device;/* Vendor and device ID or PCI_ANY_ID*/ __u32 subvendor, subdevice;/* Subsystem ID's or PCI_ANY_ID */ __u32 class, class_mask;/* (class,subclass,prog-if) triplet */ kernel_ulong_t driver_data;/* Data private to the driver */ +__u32 override_only; };include/linux/pci.h +28
-0@@ -901,6 +901,34 @@ struct pci_driver { .vendor = (vend), .device = (dev), \ .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID +/** +* PCI_DEVICE_DRIVER_OVERRIDE - macro used to describe a PCI device with +* override_only flags. +* @vend: the 16 bit PCI Vendor ID +* @dev: the 16 bit PCI Device ID +* @driver_override: PCI Device override_only bitmap +* +* This macro is used to create a struct pci_device_id that matches a +* specific device. The subvendor and subdevice fields will be set to +* PCI_ANY_ID. + */ +#define PCI_DEVICE_DRIVER_OVERRIDE (vend, dev, driver_override) \ + .vendor = (vend), .device = (dev), .subvendor = PCI_ANY_ID, \ + .subdevice = PCI_ANY_ID, .override_only = (driver_override) + +/** +* PCI_DRIVER_OVERRIDE_DEVICE_VFIO - macro used to describe a VFIO +* "driver_override" PCI device. +* @vend: the 16 bit PCI Vendor ID +* @dev: the 16 bit PCI Device ID +* +* This macro is used to create a struct pci_device_id that matches a +* specific device. The subvendor and subdevice fields will be set to +* PCI_ANY_ID and the flags will be set to PCI_ID_F_VFIO_DRIVER_OVERRIDE. +*/ +#define PCI_DRIVER_OVERRIDE_DEVICE_VFIO (vend, dev) \ + PCI_DEVICE_DRIVER_OVERRIDE(vend, dev, PCI_ID_F_VFIO_DRIVER_OVERRIDE) +/** * PCI_DEVICE_SUB - macro used to describe a specific PCI device with subsystem * @vend: the 16 bit PCI Vendor ID scripts/mod/devicetable-offsets.c +1
-0@@ -42,6 +42,7 @@ int main(void)DEVID_FIELD (pci_device_id, subdevice);DEVID_FIELD (pci_device_id, class);DEVID_FIELD (pci_device_id, class_mask); +DEVID_FIELD (pci_device_id, override_only);DEVID (ccw_device_id);DEVID_FIELD (ccw_device_id, match_flags);scripts/mod/file2alias.c +6
-2@@ -426,7 +426,7 @@ static int do_ieee1394_entry(const char *filename,return 1 ; } -/* Looks like: pci:vNdNsvNsdNbcNscNiN. */ +/* Looks like: pci:vNdNsvNsdNbcNscNiN or <prefix>_pci:vNdNsvNsdNbcNscNiN. */ static int do_pci_entry (const char *filename,void *symval,char *alias) {@@ -440,8 +440,12 @@ static int do_pci_entry(const char *filename,DEF_FIELD (symval, pci_device_id, subdevice);DEF_FIELD (symval, pci_device_id, class);DEF_FIELD (symval, pci_device_id, class_mask); +DEF_FIELD (symval, pci_device_id, override_only); -strcpy (alias,"pci:" ); +if (override_only &PCI_ID_F_VFIO_DRIVER_OVERRIDE ) +strcpy (alias,"vfio_pci:" ); +else +strcpy (alias,"pci:" );ADD (alias,"v" , vendor !=PCI_ANY_ID , vendor);ADD (alias,"d" , device !=PCI_ANY_ID , device);ADD (alias,"sv" , subvendor !=PCI_ANY_ID , subvendor);Signature · 1 line
2.18.1
Re: [PATCH V2 09/12] PCI: Add 'override_only' bitmap to struct pci_device_id
Quoted 52 lines · Bjorn Helgaas
Quoted 51 lines · Yishai Hadas
From: Max Gurtovoy <[email protected]>
Allow 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_overridesysfs.To achieve it, we add the '
override_only' bitmap to structpci_device_idand a helper macro named 'PCI_DEVICE_DRIVER_OVERRIDE' to enable setting specific bits on it.The first bit (i.e. '
PCI_ID_F_VFIO_DRIVER_OVERRIDE') indicates that the match entry is for the VFIO subsystem, it can be set by another helper macro named 'PCI_DRIVER_OVERRIDE_DEVICE_VFIO'.These match entries are prefixed with "
vfio_" in the modules.alias.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_pciIn this example
mlx5_coreandmlx5_vfio_pcimatch to the same PCI device. The kernel will autoload and autobind tomlx5_corebut the kernel and udev mechanisms will ignoremlx5_vfio_pci.When userspace wants to change a device to the VFIO subsystem userspace can implement a generic algorithm:
1) Identify the sysfs path to the device:
/sys/devices/pci0000:00/0000:00:01.0/0000:01:00.02) Get the modalias string from the kernel:
$ cat /sys/bus/pci/devices/0000:01:00.0/modalias pci:v000015B3d00001021sv000015B3sd00000001bc02sc00i003) Prefix it with
vfio_:
vfio_pci:v000015B3d00001021sv000015B3sd00000001bc02sc00i004) 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_pci5) modprobe the matched module name:
$ modprobemlx5_vfio_pci6) cat the matched module name to
driver_override:
echomlx5_vfio_pci> /sys/bus/pci/devices/0000:01:00.0/driver_override
Quoted 8 lines
Quoted 7 lines
7) unbind device from original module
echo 0000:01:00.0 > /sys/bus/pci/devices/0000:01:00.0/driver/unbind8) probe PCI drivers (or explicitly bind to
mlx5_vfio_pci) echo 0000:01:00.0 >/sys/bus/pci/drivers_probeThe algorithm is independent of bus type. In future the other buses's with
s/buses's/buses/
OK
Quoted 75 lines
Quoted 61 lines
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_driverwhich results in one new line in the modules.alias:alias vfio_pci:v*d*sv*sd*bc*sc*i*
vfio_pciLater series introduce additional HW specific VFIO PCI drivers, such as
mlx5_vfio_pci.Signed-off-by Max Gurtovoy <[email protected]>Signed-off-by Jason Gunthorpe <[email protected]>Signed-off-by Yishai Hadas <[email protected]>--- Documentation/PCI/pci.rst | 1 + drivers/pci/pci-driver.c | 27 ++++++++++++++++++++------- drivers/vfio/pci/vfio_pci.c | 9 ++++++++- include/linux/mod_devicetable.h | 6 ++++++ include/linux/pci.h | 28 ++++++++++++++++++++++++++++ scripts/mod/devicetable-offsets.c | 1 + scripts/mod/file2alias.c | 8 ++++++-- 7 files changed, 70 insertions(+), 10 deletions(-)Documentation/PCI/pci.rst +1
-0@@ -103,6 +103,7 @@ need pass only as many optional fields as necessary: - subvendor and subdevice fields default to PCI_ANY_ID (FFFFFFFF) - class and classmask fields default to 0 - driver_data defaults to 0UL. + - override_only field defaults to 0. Note that driver_data must match the value used by any of the pci_device_id entries defined in the driver. This makes the driver_data field mandatorydrivers/pci/pci-driver.c +3
-5@@ -136,7 +136,7 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv, struct pci_dev *dev) {struct pci_dynid *dynid; -const struct pci_device_id *found_id =NULL ; +const struct pci_device_id *found_id =NULL , *ids;/* When driver_override is set, only bind to the matching driver */ if (dev->driver_override &&strcmp (dev->driver_override, drv->name))@@ -152,14 +152,27 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv, }spin_unlock (&drv->dynids.lock); -if (!found_id) - found_id =pci_match_id (drv->id_table, dev); +if (found_id) +return found_id; -/* driver_override will always match, send a dummy id */ -if (!found_id && dev->driver_override)drivers/pci/pci-driver.c static const struct pci_device_id *pci_match_device(struct pci_driver *drv, · line 166
Quoted 10 lines
drivers/pci/pci-driver.c +9
-1- found_id = &pci_device_id_any; +for (ids = drv->id_table; (found_id =pci_match_id (ids, dev)); + ids = found_id +1 ) { +/* +* The match table is split based on driver_override. Check the +* override_only as well so that any matching entry is +* returned. +*/ +if (!found_id->override_only || dev->driver_override) +return found_id;The negation makes this short, but IMO, makes this harder to read. I'd rather test for the special case directly instead of testing for the *absence* of the special case, e.g.,
Quoted 5 lines
if (found_id->override_only) {
if (dev->driver_override)
return found_id;
} else
return found_id;This can be fine as well.
Quoted 9 lines
drivers/pci/pci-driver.c static const struct pci_device_id *pci_match_device(struct pci_driver *drv, · line 171
Quoted 6 lines
drivers/pci/pci-driver.c +4
-1+ } -return found_id; +/* +* if no static match, driver_override will always match, send a dummy +* id. I think the original comment was better. This comment implies that we only checked for static matches above, but we actually checked for *both* dynamic IDs and static IDs.
OK
Quoted 37 lines
Quoted 37 lines
drivers/pci/pci-driver.c +4
-0+*/ +if (dev->driver_override) +return &pci_device_id_any; +return NULL ; }/** drivers/vfio/pci/vfio_pci.c +8
-1@@ -180,9 +180,16 @@ static int vfio_pci_sriov_configure(struct pci_dev *pdev, int nr_virtfn)return vfio_pci_core_sriov_configure (pdev, nr_virtfn); } +static const struct pci_device_id vfio_pci_table[] = { + {PCI_DRIVER_OVERRIDE_DEVICE_VFIO (PCI_ANY_ID ,PCI_ANY_ID ) },/* match all by default */ + {} +}; + +MODULE_DEVICE_TABLE (pci, vfio_pci_table); +static struct pci_driver vfio_pci_driver = { .name ="vfio-pci" , - .id_table =NULL ,/* only dynamic ids */ + .id_table = vfio_pci_table, .probe = vfio_pci_probe, .remove = vfio_pci_remove, .sriov_configure = vfio_pci_sriov_configure,include/linux/mod_devicetable.h +0
-0@@ -16,6 +16,10 @@ typedef unsigned long kernel_ulong_t;#define PCI_ANY_ID (~0)
Quoted 13 lines
include/linux/mod_devicetable.h typedef unsigned long kernel_ulong_t; · line 41
Quoted 12 lines
include/linux/mod_devicetable.h +5
-0+enum { +PCI_ID_F_VFIO_DRIVER_OVERRIDE =1 <<0 , +}; +/** * struct pci_device_id - PCI device ID structure * @vendor: Vendor ID to match (or PCI_ANY_ID) @@ -34,12 +38,14 @@ typedef unsigned long kernel_ulong_t;* Best practice is to use driver_data as an index * into a static list of equivalent device types, * instead of using it as a pointer. +* @override_only: Bitmap for override_only PCI drivers. "Match only when
dev->driver_overrideis this driver"?
Just to be aligned here,
This field will stay __u32 and may hold at the most 1 bit value set to represent the actual subsystem/driver.
This is required to later on set the correct prefix in the modules.alias file, and you just suggested to change the comment as of above, right ?
Quoted 6 lines
As far as PCI core is concerned there's no need for this to be a bitmap.
I think this would make more sense if split into two patches. The first would add
override_onlyand changepci_match_device(). Then there's no confusion about whether this is specific to VFIO.
Splitting may end-up the first patch with a dead-code on below, as found_id->override_only will be always 0.
If you still believe that this is better we can do it.
if (found_id->override_only) {
if (dev->driver_override)
return found_id;
} else
return found_id;Quoted 94 lines
The second can add
PCI_ID_F_VFIO_DRIVER_OVERRIDEand make thefile2alias.cchanges. Most of the commit log applies to this part.Quoted 91 lines
include/linux/mod_devicetable.h +1
-0*/ struct pci_device_id {__u32 vendor, device;/* Vendor and device ID or PCI_ANY_ID*/ __u32 subvendor, subdevice;/* Subsystem ID's or PCI_ANY_ID */ __u32 class, class_mask;/* (class,subclass,prog-if) triplet */ kernel_ulong_t driver_data;/* Data private to the driver */ +__u32 override_only; };include/linux/pci.h +28
-0@@ -901,6 +901,34 @@ struct pci_driver { .vendor = (vend), .device = (dev), \ .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID +/** +* PCI_DEVICE_DRIVER_OVERRIDE - macro used to describe a PCI device with +* override_only flags. +* @vend: the 16 bit PCI Vendor ID +* @dev: the 16 bit PCI Device ID +* @driver_override: PCI Device override_only bitmap +* +* This macro is used to create a struct pci_device_id that matches a +* specific device. The subvendor and subdevice fields will be set to +* PCI_ANY_ID. + */ +#define PCI_DEVICE_DRIVER_OVERRIDE (vend, dev, driver_override) \ + .vendor = (vend), .device = (dev), .subvendor = PCI_ANY_ID, \ + .subdevice = PCI_ANY_ID, .override_only = (driver_override) + +/** +* PCI_DRIVER_OVERRIDE_DEVICE_VFIO - macro used to describe a VFIO +* "driver_override" PCI device. +* @vend: the 16 bit PCI Vendor ID +* @dev: the 16 bit PCI Device ID +* +* This macro is used to create a struct pci_device_id that matches a +* specific device. The subvendor and subdevice fields will be set to +* PCI_ANY_ID and the flags will be set to PCI_ID_F_VFIO_DRIVER_OVERRIDE. +*/ +#define PCI_DRIVER_OVERRIDE_DEVICE_VFIO (vend, dev) \ + PCI_DEVICE_DRIVER_OVERRIDE(vend, dev, PCI_ID_F_VFIO_DRIVER_OVERRIDE) +/** * PCI_DEVICE_SUB - macro used to describe a specific PCI device with subsystem * @vend: the 16 bit PCI Vendor ID scripts/mod/devicetable-offsets.c +1
-0@@ -42,6 +42,7 @@ int main(void)DEVID_FIELD (pci_device_id, subdevice);DEVID_FIELD (pci_device_id, class);DEVID_FIELD (pci_device_id, class_mask); +DEVID_FIELD (pci_device_id, override_only);DEVID (ccw_device_id);DEVID_FIELD (ccw_device_id, match_flags);scripts/mod/file2alias.c +6
-2@@ -426,7 +426,7 @@ static int do_ieee1394_entry(const char *filename,return 1 ; } -/* Looks like: pci:vNdNsvNsdNbcNscNiN. */ +/* Looks like: pci:vNdNsvNsdNbcNscNiN or <prefix>_pci:vNdNsvNsdNbcNscNiN. */ static int do_pci_entry (const char *filename,void *symval,char *alias) {@@ -440,8 +440,12 @@ static int do_pci_entry(const char *filename,DEF_FIELD (symval, pci_device_id, subdevice);DEF_FIELD (symval, pci_device_id, class);DEF_FIELD (symval, pci_device_id, class_mask); +DEF_FIELD (symval, pci_device_id, override_only); -strcpy (alias,"pci:" ); +if (override_only &PCI_ID_F_VFIO_DRIVER_OVERRIDE ) +strcpy (alias,"vfio_pci:" ); +else +strcpy (alias,"pci:" );ADD (alias,"v" , vendor !=PCI_ANY_ID , vendor);ADD (alias,"d" , device !=PCI_ANY_ID , device);ADD (alias,"sv" , subvendor !=PCI_ANY_ID , subvendor);Signature · 1 line
2.18.1
Re: [PATCH V2 09/12] PCI: Add 'override_only' bitmap to struct pci_device_id
Quoted 14 lines · Yishai Hadas
Quoted 12 lines · Bjorn Helgaas
include/linux/mod_devicetable.h typedef unsigned long kernel_ulong_t; · line 41
Quoted 10 lines · Yishai Hadas
From: Max Gurtovoy <[email protected]>
/**
* structpci_device_id- PCI device ID structure
* @vendor: Vendor ID to match (orPCI_ANY_ID)include/linux/mod_devicetable.h +1
-0@@ -34,12 +38,14 @@ typedef unsigned long kernel_ulong_t;* Best practice is to use driver_data as an index * into a static list of equivalent device types, * instead of using it as a pointer. +* @override_only: Bitmap for override_only PCI drivers. "Match only when
dev->driver_overrideis this driver"?
Quoted 4 lines
Just to be aligned here,
This field will stay
__u32and may hold at the most 1 bit value set to represent the actual subsystem/driver.
The PCI core does not require "at most 1 bit is set."
Actually, I don't think even the file2alias code requires that. If you set two bits, you can generate two aliases.
Quoted 2 lines
This is required to later on set the correct prefix in the modules.alias file, and you just suggested to change the comment as of above, right ?
Yes, __u32 is fine and I'm only suggesting a comment change here.
Quoted 11 lines
Quoted 6 lines
As far as PCI core is concerned there's no need for this to be a bitmap.
I think this would make more sense if split into two patches. The first would add
override_onlyand changepci_match_device(). Then there's no confusion about whether this is specific to VFIO.Splitting may end-up the first patch with a dead-code on below, as
found_id->override_onlywill be always 0.If you still believe that this is better we can do it.
I think it's fine to add the functionality in one patch and use it in the next if it makes the commit clearer. I wouldn't want to add functionality that's not used at all in the series, but it's OK when they're both posted together.
Quoted 8 lines
if (found_id->override_only) { if (dev->driver_override) return found_id; } else return found_id;Quoted 2 lines
The second can add
PCI_ID_F_VFIO_DRIVER_OVERRIDEand make thefile2alias.cchanges. Most of the commit log applies to this part.
Re: [PATCH V2 09/12] PCI: Add 'override_only' bitmap to struct pci_device_id
Quoted 17 lines · Bjorn Helgaas
Quoted 12 lines · Yishai Hadas
Quoted 11 lines · Bjorn Helgaas
include/linux/mod_devicetable.h typedef unsigned long kernel_ulong_t; · line 41
Quoted 9 lines · Yishai Hadas
From: Max Gurtovoy <[email protected]>
/**
* structpci_device_id- PCI device ID structure
* @vendor: Vendor ID to match (orPCI_ANY_ID)include/linux/mod_devicetable.h +1
-0@@ -34,12 +38,14 @@ typedef unsigned long kernel_ulong_t;* Best practice is to use driver_data as an index * into a static list of equivalent device types, * instead of using it as a pointer. +* @override_only: Bitmap for override_only PCI drivers. "Match only when
dev->driver_overrideis this driver"?Quoted 4 lines
Just to be aligned here,
This field will stay
__u32and may hold at the most 1 bit value set to represent the actual subsystem/driver.
Quoted 8 lines
The PCI core does not require "at most 1 bit is set."
Actually, I don't think even the file2alias code requires that. If you set two bits, you can generate two aliases.
Quoted 2 lines
This is required to later on set the correct prefix in the modules.alias file, and you just suggested to change the comment as of above, right ?
Yes,
__u32is fine and I'm only suggesting a comment change here.
great.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
As far as PCI core is concerned there's no need for this to be a bitmap.
I think this would make more sense if split into two patches. The first would add
override_onlyand changepci_match_device(). Then there's no confusion about whether this is specific to VFIO.
Quoted 8 lines
Quoted 4 lines
Splitting may end-up the first patch with a dead-code on below, as
found_id->override_onlywill be always 0.If you still believe that this is better we can do it.
I think it's fine to add the functionality in one patch and use it in the next if it makes the commit clearer. I wouldn't want to add functionality that's not used at all in the series, but it's OK when they're both posted together.
Ok. We can do the separation if all agree that the first commit is have a dead section.
Alex,
we would like to get few more reviewed-by signatures and we'll send the V3 series in a couple of days to make it to 5.15 merge window as we planned.
Are you ok with the series after we got the green light for this patch ?
do you think we need another pair of eyes to review the other patches ?
-Max.
Quoted 9 lines
Quoted 9 lines
if (found_id->override_only) { if (dev->driver_override) return found_id; } else return found_id;Quoted 2 lines
The second can add
PCI_ID_F_VFIO_DRIVER_OVERRIDEand make thefile2alias.cchanges. Most of the commit log applies to this part.
Re: [PATCH V2 09/12] PCI: Add 'override_only' bitmap to struct pci_device_id
Quoted 49 lines · On Thu, 19 Aug 2021 22:57:30 +0300 Max Gurtovoy <[email protected]> wrote:
Quoted 17 lines · Bjorn Helgaas
Quoted 12 lines · Yishai Hadas
Quoted 11 lines · Bjorn Helgaas
include/linux/mod_devicetable.h typedef unsigned long kernel_ulong_t; · line 41
Quoted 9 lines · Yishai Hadas
From: Max Gurtovoy <[email protected]>
/**
* structpci_device_id- PCI device ID structure
* @vendor: Vendor ID to match (orPCI_ANY_ID)include/linux/mod_devicetable.h +1
-0@@ -34,12 +38,14 @@ typedef unsigned long kernel_ulong_t;* Best practice is to use driver_data as an index * into a static list of equivalent device types, * instead of using it as a pointer. +* @override_only: Bitmap for override_only PCI drivers. "Match only when
dev->driver_overrideis this driver"?Quoted 4 lines
Just to be aligned here,
This field will stay
__u32and may hold at the most 1 bit value set to represent the actual subsystem/driver.Quoted 8 lines
The PCI core does not require "at most 1 bit is set."
Actually, I don't think even the file2alias code requires that. If you set two bits, you can generate two aliases.
Quoted 2 lines
This is required to later on set the correct prefix in the modules.alias file, and you just suggested to change the comment as of above, right ?
Yes,
__u32is fine and I'm only suggesting a comment change here.great.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
As far as PCI core is concerned there's no need for this to be a bitmap.
I think this would make more sense if split into two patches. The first would add
override_onlyand changepci_match_device(). Then there's no confusion about whether this is specific to VFIO.Quoted 8 lines
Quoted 4 lines
Splitting may end-up the first patch with a dead-code on below, as
found_id->override_onlywill be always 0.If you still believe that this is better we can do it.
I think it's fine to add the functionality in one patch and use it in the next if it makes the commit clearer. I wouldn't want to add functionality that's not used at all in the series, but it's OK when they're both posted together.
Ok. We can do the separation if all agree that the first commit is have a dead section.
Quoted 8 lines
Alex,
we would like to get few more reviewed-by signatures and we'll send the V3 series in a couple of days to make it to 5.15 merge window as we planned.
Are you ok with the series after we got the green light for this patch ?
do you think we need another pair of eyes to review the other patches ?
More eyes is always better, but I'm not finding much to complain about in this series. This patch was probably the most pivotal for agreement, the rest is largely mechanical at this point.
In addition to Bjorn for the PCI parts of this, I'd also like to see an ack from Yamada-san or Michal for scripts/mod/, who are already cc'd
I also notice include/linux/vfio_pci_core.h doesn't get added to MAINTAINERS in the series. Please fix in patch 12/
It seems plausible that this could be ready for v5.15. Thanks,
Alex
PATCH v2 10/12 vfio: Use select for eventfd
In reply to Yishai HadasFrom: Jason Gunthorpe <[email protected]>
If VFIO_VIRQFD is required then turn on eventfd automatically. The majority of kconfig users of the EVENTFD use select not depends on.
--- drivers/vfio/Kconfig | 3 ++- drivers/vfio/fsl-mc/Kconfig | 3 ++- drivers/vfio/pci/Kconfig | 2 +- drivers/vfio/platform/Kconfig | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-)
drivers/vfio/Kconfig +2 -1
@@ -16,7 +16,8 @@ config VFIO_SPAPR_EEH config VFIO_VIRQFD tristate - depends on VFIO && EVENTFD + depends on VFIO + select EVENTFD default n menuconfig VFIO
drivers/vfio/fsl-mc/Kconfig +2 -1
@@ -1,6 +1,7 @@ config VFIO_FSL_MC tristate "VFIO support for QorIQ DPAA2 fsl-mc bus devices" - depends on VFIO && FSL_MC_BUS && EVENTFD + depends on VFIO && FSL_MC_BUS + select EVENTFD help Driver to enable support for the VFIO QorIQ DPAA2 fsl-mc (Management Complex) devices. This is required to passthrough
drivers/vfio/pci/Kconfig +1 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config VFIO_PCI tristate "VFIO support for PCI devices" - depends on VFIO && PCI && EVENTFD + depends on VFIO && PCI depends on MMU select VFIO_VIRQFD select IRQ_BYPASS_MANAGER
drivers/vfio/platform/Kconfig +1 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config VFIO_PLATFORM tristate "VFIO support for platform devices" - depends on VFIO && EVENTFD && (ARM || ARM64 || COMPILE_TEST) + depends on VFIO && (ARM || ARM64 || COMPILE_TEST) select VFIO_VIRQFD help Support for platform devices with VFIO. This is required to make
Signature · 1 line
2.18.1
PATCH v2 11/12 vfio: Use kconfig if XX/endif blocks instead of repeating 'depends on'
In reply to Yishai HadasFrom: Jason Gunthorpe <[email protected]>
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.
--- drivers/vfio/Kconfig | 28 ++++++++++++++-------------- drivers/vfio/fsl-mc/Kconfig | 2 +- drivers/vfio/mdev/Kconfig | 1 - drivers/vfio/pci/Kconfig | 11 ++++++----- drivers/vfio/platform/Kconfig | 6 ++++-- drivers/vfio/platform/reset/Kconfig | 4 +--- 6 files changed, 26 insertions(+), 26 deletions(-)
drivers/vfio/Kconfig +14 -14
@@ -1,12 +1,22 @@ # SPDX-License-Identifier: GPL-2.0-only +menuconfig VFIO + tristate "VFIO Non-Privileged userspace driver framework" + select IOMMU_API + select VFIO_IOMMU_TYPE1 if MMU && (X86 || S390 || ARM || ARM64) + help + VFIO provides a framework for secure userspace device drivers. + See Documentation/driver-api/vfio.rst for more details. + + If you don't know what to do here, say N. + +if VFIO config VFIO_IOMMU_TYPE1 tristate - depends on VFIO default n config VFIO_IOMMU_SPAPR_TCE tristate - depends on VFIO && SPAPR_TCE_IOMMU + depends on SPAPR_TCE_IOMMU default VFIO config VFIO_SPAPR_EEH
@@ -16,23 +26,11 @@ config VFIO_SPAPR_EEH config VFIO_VIRQFD tristate - depends on VFIO select EVENTFD default n -menuconfig VFIO - tristate "VFIO Non-Privileged userspace driver framework" - select IOMMU_API - select VFIO_IOMMU_TYPE1 if MMU && (X86 || S390 || ARM || ARM64) - help - VFIO provides a framework for secure userspace device drivers. - See Documentation/driver-api/vfio.rst for more details. - - If you don't know what to do here, say N. - config VFIO_NOIOMMU bool "VFIO No-IOMMU support" - depends on VFIO help VFIO is built on the ability to isolate devices using the IOMMU. Only with an IOMMU can userspace access to DMA capable devices be
@@ -49,4 +47,6 @@ source "drivers/vfio/pci/Kconfig" source "drivers/vfio/platform/Kconfig" source "drivers/vfio/mdev/Kconfig" source "drivers/vfio/fsl-mc/Kconfig" +endif + source "virt/lib/Kconfig"
drivers/vfio/fsl-mc/Kconfig +1 -1
@@ -1,6 +1,6 @@ config VFIO_FSL_MC tristate "VFIO support for QorIQ DPAA2 fsl-mc bus devices" - depends on VFIO && FSL_MC_BUS + depends on FSL_MC_BUS select EVENTFD help Driver to enable support for the VFIO QorIQ DPAA2 fsl-mc
drivers/vfio/mdev/Kconfig +0 -1
@@ -2,7 +2,6 @@ config VFIO_MDEV tristate "Mediated device driver framework" - depends on VFIO default n help Provides a framework to virtualize devices.
drivers/vfio/pci/Kconfig +6 -5
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config VFIO_PCI tristate "VFIO support for PCI devices" - depends on VFIO && PCI + depends on PCI depends on MMU select VFIO_VIRQFD select IRQ_BYPASS_MANAGER
@@ -11,9 +11,10 @@ config VFIO_PCI If you don't know what to do here, say N. +if VFIO_PCI config VFIO_PCI_VGA bool "VFIO PCI support for VGA devices" - depends on VFIO_PCI && X86 && VGA_ARB + depends on X86 && VGA_ARB help Support for VGA extension to VFIO PCI. This exposes an additional region on VGA devices for accessing legacy VGA addresses used by
@@ -22,16 +23,14 @@ config VFIO_PCI_VGA If you don't know what to do here, say N. config VFIO_PCI_MMAP - depends on VFIO_PCI def_bool y if !S390 config VFIO_PCI_INTX - depends on VFIO_PCI def_bool y if !S390 config VFIO_PCI_IGD bool "VFIO PCI extensions for Intel graphics (GVT-d)" - depends on VFIO_PCI && X86 + depends on X86 default y help Support for Intel IGD specific extensions to enable direct
@@ -40,3 +39,5 @@ config VFIO_PCI_IGD and LPC bridge config space. To enable Intel IGD assignment through vfio-pci, say Y. + +endif
drivers/vfio/platform/Kconfig +4 -2
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config VFIO_PLATFORM tristate "VFIO support for platform devices" - depends on VFIO && (ARM || ARM64 || COMPILE_TEST) + depends on ARM || ARM64 || COMPILE_TEST select VFIO_VIRQFD help Support for platform devices with VFIO. This is required to make
@@ -10,9 +10,10 @@ config VFIO_PLATFORM If you don't know what to do here, say N. +if VFIO_PLATFORM config VFIO_AMBA tristate "VFIO support for AMBA devices" - depends on VFIO_PLATFORM && (ARM_AMBA || COMPILE_TEST) + depends on ARM_AMBA || COMPILE_TEST help Support for ARM AMBA devices with VFIO. This is required to make use of ARM AMBA devices present on the system using the VFIO
@@ -21,3 +22,4 @@ config VFIO_AMBA If you don't know what to do here, say N. source "drivers/vfio/platform/reset/Kconfig" +endif
drivers/vfio/platform/reset/Kconfig +1 -3
@@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only config VFIO_PLATFORM_CALXEDAXGMAC_RESET tristate "VFIO support for calxeda xgmac reset" - depends on VFIO_PLATFORM help Enables the VFIO platform driver to handle reset for Calxeda xgmac
@@ -9,7 +8,6 @@ config VFIO_PLATFORM_CALXEDAXGMAC_RESET config VFIO_PLATFORM_AMDXGBE_RESET tristate "VFIO support for AMD XGBE reset" - depends on VFIO_PLATFORM help Enables the VFIO platform driver to handle reset for AMD XGBE
@@ -17,7 +15,7 @@ config VFIO_PLATFORM_AMDXGBE_RESET config VFIO_PLATFORM_BCMFLEXRM_RESET tristate "VFIO support for Broadcom FlexRM reset" - depends on VFIO_PLATFORM && (ARCH_BCM_IPROC || COMPILE_TEST) + depends on ARCH_BCM_IPROC || COMPILE_TEST default ARCH_BCM_IPROC help Enables the VFIO platform driver to handle reset for Broadcom FlexRM
Signature · 1 line
2.18.1
PATCH v2 12/12 vfio/pci: Introduce vfio_pci_core.ko
In reply to Yishai HadasFrom: Max Gurtovoy <[email protected]>
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.
---
drivers/vfio/pci/Kconfig | 33 +++++++++-------
drivers/vfio/pci/Makefile | 8 ++--
drivers/vfio/pci/vfio_pci.c | 14 ++-----
drivers/vfio/pci/vfio_pci_config.c | 2 +-
drivers/vfio/pci/vfio_pci_core.c | 39 ++++++++++++++++---
drivers/vfio/pci/vfio_pci_igd.c | 2 +-
drivers/vfio/pci/vfio_pci_intrs.c | 2 +-
drivers/vfio/pci/vfio_pci_rdwr.c | 2 +-
drivers/vfio/pci/vfio_pci_zdev.c | 2 +-
.../pci => include/linux}/vfio_pci_core.h | 2 -
10 files changed, 64 insertions(+), 42 deletions(-)
rename {drivers/vfio/pci => include/linux}/vfio_pci_core.h (99%)drivers/vfio/pci/Kconfig +18 -15
@@ -1,19 +1,28 @@ # SPDX-License-Identifier: GPL-2.0-only -config VFIO_PCI - tristate "VFIO support for PCI devices" - depends on PCI - depends on MMU +if PCI && MMU +config VFIO_PCI_CORE + tristate select VFIO_VIRQFD select IRQ_BYPASS_MANAGER + +config VFIO_PCI_MMAP + def_bool y if !S390 + +config VFIO_PCI_INTX + def_bool y if !S390 + +config VFIO_PCI + tristate "Generic VFIO support for any PCI device" + select VFIO_PCI_CORE help - Support for the PCI VFIO bus driver. This is required to make - use of PCI drivers using the VFIO framework. + Support for the generic PCI VFIO bus driver which can connect any + PCI device to the VFIO framework. If you don't know what to do here, say N. if VFIO_PCI config VFIO_PCI_VGA - bool "VFIO PCI support for VGA devices" + bool "Generic VFIO PCI support for VGA devices" depends on X86 && VGA_ARB help Support for VGA extension to VFIO PCI. This exposes an additional
@@ -22,14 +31,8 @@ config VFIO_PCI_VGA If you don't know what to do here, say N. -config VFIO_PCI_MMAP - def_bool y if !S390 - -config VFIO_PCI_INTX - def_bool y if !S390 - config VFIO_PCI_IGD - bool "VFIO PCI extensions for Intel graphics (GVT-d)" + bool "Generic VFIO PCI extensions for Intel graphics (GVT-d)" depends on X86 default y help
@@ -39,5 +42,5 @@ config VFIO_PCI_IGD and LPC bridge config space. To enable Intel IGD assignment through vfio-pci, say Y. - +endif endif
drivers/vfio/pci/Makefile +5 -3
@@ -1,7 +1,9 @@ # SPDX-License-Identifier: GPL-2.0-only -vfio-pci-y := vfio_pci.o vfio_pci_core.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o -vfio-pci-$(CONFIG_VFIO_PCI_IGD) += vfio_pci_igd.o -vfio-pci-$(CONFIG_S390) += vfio_pci_zdev.o +vfio-pci-core-y := vfio_pci_core.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o +vfio-pci-core-$(CONFIG_S390) += vfio_pci_zdev.o +obj-$(CONFIG_VFIO_PCI_CORE) += vfio-pci-core.o +vfio-pci-y := vfio_pci.o +vfio-pci-$(CONFIG_VFIO_PCI_IGD) += vfio_pci_igd.o obj-$(CONFIG_VFIO_PCI) += vfio-pci.o
drivers/vfio/pci/vfio_pci.c +3 -11
@@ -25,7 +25,7 @@#include <linux/types.h> #include <linux/uaccess.h> -#include "vfio_pci_core.h" +#include <linux/vfio_pci_core.h> #define DRIVER_AUTHOR "Alex Williamson <[email protected]>"#define DRIVER_DESC "VFIO PCI - User Level meta-driver"
@@ -153,6 +153,7 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) ret =vfio_pci_core_register_device (vdev);if (ret) goto out_free; +dev_set_drvdata (&pdev->dev, vdev);return 0 ; out_free:
@@ -248,14 +249,10 @@ static int __init vfio_pci_init(void)vfio_pci_core_set_params (nointxmask, is_disable_vga, disable_idle_d3); - ret =vfio_pci_core_init (); -if (ret) -return ret; -/* Register and scan for devices */ ret =pci_register_driver (&vfio_pci_driver);if (ret) - goto out; +return ret;vfio_pci_fill_ids ();
@@ -263,17 +260,12 @@ static int __init vfio_pci_init(void)pr_warn ("device denylist disabled.\n" );return 0 ; - -out: -vfio_pci_core_cleanup (); -return ret; }module_init (vfio_pci_init); static void __exit vfio_pci_cleanup(void) {pci_unregister_driver (&vfio_pci_driver); -vfio_pci_core_cleanup (); }module_exit (vfio_pci_cleanup);
drivers/vfio/pci/vfio_pci_config.c +1 -1
@@ -26,7 +26,7 @@#include <linux/vfio.h> #include <linux/slab.h> -#include "vfio_pci_core.h" +#include <linux/vfio_pci_core.h> /* Fake capability ID for standard config space */ #define PCI_CAP_ID_BASIC 0
drivers/vfio/pci/vfio_pci_core.c +33 -6
@@ -8,6 +8,8 @@* Author: Tom Lyon, [email protected] */ +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/device.h> #include <linux/eventfd.h> #include <linux/file.h>
@@ -25,7 +27,10 @@#include <linux/nospec.h> #include <linux/sched/mm.h> -#include "vfio_pci_core.h" +#include <linux/vfio_pci_core.h> + +#define DRIVER_AUTHOR "Alex Williamson <[email protected]>" +#define DRIVER_DESC "core driver for VFIO based PCI devices"static bool nointxmask;static bool disable_vga;
@@ -306,6 +311,7 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)return 0 ; } +EXPORT_SYMBOL_GPL (vfio_pci_core_enable);void vfio_pci_core_disable (struct vfio_pci_core_device *vdev) {
@@ -403,6 +409,7 @@ void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)if (!vfio_pci_dev_set_try_reset (vdev->vdev.dev_set) && !disable_idle_d3)vfio_pci_set_power_state (vdev, PCI_D3hot); } +EXPORT_SYMBOL_GPL (vfio_pci_core_disable);static struct vfio_pci_core_device *get_pf_vdev (struct vfio_pci_core_device *vdev) {
@@ -459,6 +466,7 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev) }mutex_unlock (&vdev->igate); } +EXPORT_SYMBOL_GPL (vfio_pci_core_close_device);void vfio_pci_core_finish_enable (struct vfio_pci_core_device *vdev) {
@@ -466,6 +474,7 @@ void vfio_pci_core_finish_enable(struct vfio_pci_core_device *vdev)vfio_spapr_pci_eeh_open (vdev->pdev);vfio_pci_vf_token_user_add (vdev,1 ); } +EXPORT_SYMBOL_GPL (vfio_pci_core_finish_enable);static int vfio_pci_get_irq_count (struct vfio_pci_core_device *vdev,int irq_type) {
@@ -624,6 +633,7 @@ int vfio_pci_register_dev_region(struct vfio_pci_core_device *vdev,return 0 ; } +EXPORT_SYMBOL_GPL (vfio_pci_register_dev_region);long vfio_pci_core_ioctl (struct vfio_device *core_vdev,unsigned int cmd,unsigned long arg)
@@ -1168,6 +1178,7 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,return -ENOTTY ; } +EXPORT_SYMBOL_GPL (vfio_pci_core_ioctl);static ssize_t vfio_pci_rw (struct vfio_pci_core_device *vdev,char __user *buf,size_t count,loff_t *ppos,bool iswrite)
@@ -1211,6 +1222,7 @@ ssize_t vfio_pci_core_read(struct vfio_device *core_vdev, char __user *buf,return vfio_pci_rw (vdev, buf, count, ppos, false); } +EXPORT_SYMBOL_GPL (vfio_pci_core_read);ssize_t vfio_pci_core_write (struct vfio_device *core_vdev,const char __user *buf,size_t count,loff_t *ppos)
@@ -1223,6 +1235,7 @@ ssize_t vfio_pci_core_write(struct vfio_device *core_vdev, const char __user *bureturn vfio_pci_rw (vdev, (char __user *)buf, count, ppos, true); } +EXPORT_SYMBOL_GPL (vfio_pci_core_write);/* Return 1 on zap and vma_lock acquired, 0 on contention (only with @try) */ static int vfio_pci_zap_and_vma_lock (struct vfio_pci_core_device *vdev,bool try)
@@ -1501,6 +1514,7 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vmareturn 0 ; } +EXPORT_SYMBOL_GPL (vfio_pci_core_mmap);void vfio_pci_core_request (struct vfio_device *core_vdev,unsigned int count) {
@@ -1523,6 +1537,7 @@ void vfio_pci_core_request(struct vfio_device *core_vdev, unsigned int count)mutex_unlock (&vdev->igate); } +EXPORT_SYMBOL_GPL (vfio_pci_core_request);static int vfio_pci_validate_vf_token (struct vfio_pci_core_device *vdev,bool vf_token,uuid_t *uuid)
@@ -1667,6 +1682,7 @@ int vfio_pci_core_match(struct vfio_device *core_vdev, char *buf)return 1 ;/* Match */ } +EXPORT_SYMBOL_GPL (vfio_pci_core_match);static int vfio_pci_bus_notifier (struct notifier_block *nb,unsigned long action,void *data)
@@ -1774,6 +1790,7 @@ void vfio_pci_core_init_device(struct vfio_pci_core_device *vdev,INIT_LIST_HEAD (&vdev->vma_list);init_rwsem (&vdev->memory_lock); } +EXPORT_SYMBOL_GPL (vfio_pci_core_init_device);void vfio_pci_core_uninit_device (struct vfio_pci_core_device *vdev) {
@@ -1784,6 +1801,7 @@ void vfio_pci_core_uninit_device(struct vfio_pci_core_device *vdev)kfree (vdev->region);kfree (vdev->pm_save); } +EXPORT_SYMBOL_GPL (vfio_pci_core_uninit_device);int vfio_pci_core_register_device (struct vfio_pci_core_device *vdev) {
@@ -1851,7 +1869,6 @@ int vfio_pci_core_register_device(struct vfio_pci_core_device *vdev) ret =vfio_register_group_dev (&vdev->vdev);if (ret) goto out_power; -dev_set_drvdata (&pdev->dev, vdev);return 0 ; out_power:
@@ -1863,6 +1880,7 @@ int vfio_pci_core_register_device(struct vfio_pci_core_device *vdev)vfio_iommu_group_put (group, &pdev->dev);return ret; } +EXPORT_SYMBOL_GPL (vfio_pci_core_register_device);void vfio_pci_core_unregister_device (struct vfio_pci_core_device *vdev) {
@@ -1880,6 +1898,7 @@ void vfio_pci_core_unregister_device(struct vfio_pci_core_device *vdev)if (!disable_idle_d3)vfio_pci_set_power_state (vdev,PCI_D0 ); } +EXPORT_SYMBOL_GPL (vfio_pci_core_unregister_device);static pci_ers_result_t vfio_pci_aer_err_detected (struct pci_dev *pdev,pci_channel_state_t state)
@@ -1925,10 +1944,12 @@ int vfio_pci_core_sriov_configure(struct pci_dev *pdev, int nr_virtfn)return ret <0 ? ret : nr_virtfn; } +EXPORT_SYMBOL_GPL (vfio_pci_core_sriov_configure);const struct pci_error_handlers vfio_pci_core_err_handlers = { .error_detected = vfio_pci_aer_err_detected, }; +EXPORT_SYMBOL_GPL (vfio_pci_core_err_handlers);static bool vfio_dev_in_groups (struct vfio_pci_core_device *vdev,struct vfio_pci_group_info *groups)
@@ -2117,16 +2138,22 @@ void vfio_pci_core_set_params(bool is_nointxmask, bool is_disable_vga, disable_vga = is_disable_vga; disable_idle_d3 = is_disable_idle_d3; } +EXPORT_SYMBOL_GPL (vfio_pci_core_set_params); -/* This will become the __exit function of vfio_pci_core.ko */ -void vfio_pci_core_cleanup (void ) +static void vfio_pci_core_cleanup (void ) {vfio_pci_uninit_perm_bits (); } -/* This will become the __init function of vfio_pci_core.ko */ -int __init vfio_pci_core_init (void ) +static int __init vfio_pci_core_init (void ) {/* Allocate shared config space permission data used by all devices */ return vfio_pci_init_perm_bits (); } + +module_init (vfio_pci_core_init); +module_exit (vfio_pci_core_cleanup); + +MODULE_LICENSE ("GPL v2" ); +MODULE_AUTHOR (DRIVER_AUTHOR ); +MODULE_DESCRIPTION (DRIVER_DESC );
drivers/vfio/pci/vfio_pci_igd.c +1 -1
@@ -15,7 +15,7 @@#include <linux/uaccess.h> #include <linux/vfio.h> -#include "vfio_pci_core.h" +#include <linux/vfio_pci_core.h> #define OPREGION_SIGNATURE "IntelGraphicsMem"#define OPREGION_SIZE (8 * 1024)
drivers/vfio/pci/vfio_pci_intrs.c +1 -1
@@ -20,7 +20,7 @@#include <linux/wait.h> #include <linux/slab.h> -#include "vfio_pci_core.h" +#include <linux/vfio_pci_core.h> /* * INTx
drivers/vfio/pci/vfio_pci_rdwr.c +1 -1
@@ -17,7 +17,7 @@#include <linux/vfio.h> #include <linux/vgaarb.h> -#include "vfio_pci_core.h" +#include <linux/vfio_pci_core.h> #ifdef __LITTLE_ENDIAN#define vfio_ioread64 ioread64
drivers/vfio/pci/vfio_pci_zdev.c +1 -1
@@ -19,7 +19,7 @@#include <asm/pci_clp.h> #include <asm/pci_io.h> -#include "vfio_pci_core.h" +#include <linux/vfio_pci_core.h> /* * Add the Base PCI Function information to the device info region.
include/linux/vfio_pci_core.h renamed from drivers/vfio/pci/vfio_pci_core.h +0 -2
@@ -207,8 +207,6 @@ static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,#endif /* Will be exported for vfio pci drivers usage */ -void vfio_pci_core_cleanup (void ); -int vfio_pci_core_init (void );void vfio_pci_core_set_params (bool nointxmask,bool is_disable_vga,bool is_disable_idle_d3);void vfio_pci_core_close_device (struct vfio_device *core_vdev);
Signature · 1 line
2.18.1