Introduce vendor ops in vfio-pci
Subsystems (4)
v2 cover Introduce vendor ops in vfio-pci
When using module vfio-pci to pass through devices, though for the most of time, it is desired to use default implementations in vfio-pci, vendors sometimes may want to do certain kind of customization.
For example, vendors may want to add a vendor device region or may want to intercept writes to a BAR region.
So, in this patch set, we introduce a way to allow vendors to focus on handling of regions of their interest and call default vfio-pci ops to handle the reset ones.
It goes like this:
(1) macros are provided to let vendor drivers register/unregister vfio_pci_vendor_driver_ops to vfio_pci in their module_init() and module_exit().vfio_pci_vendor_driver_ops contains callbacks probe() and remove() and a pointer to vfio_device_ops.
(2) vendor drivers define their module aliases as "vfio-pci:$vendor_id-$device_id".
E.g. A vendor module for VF devices of Intel(R) Ethernet Controller XL710 family can define its module alias as MODULE_ALIAS("vfio-pci:8086-154c").
(3) when module vfio_pci is bound to a device, it would call modprobe in user space for modules of alias "vfio-pci:$vendor_id-$device_id", which would trigger unloaded vendor drivers to register their vfio_pci_vendor_driver_ops to vfio_pci.
Then it searches registered ops list and calls probe() to test whether this vendor driver supports this physical device.
A success probe() would make vfio_pci to use vfio_device_ops provided vendor driver as the ops of the vfio device. So vfio_pci_ops are not to be called for this device any more. Instead, they are exported to be called from vendor drivers as a default implementation.
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
__________ (un)register vendor ops | ___________ ___________ |
| |<----------------------------| VF | | |
| vfio-pci | | | vendor | | PF driver | |
|__________|---------------------------->| driver | |___________|
| probe/remove() | ----------- | |
| |
| |_ _ _ _ _ _ _ _ _ _ _ _|_ _ _ _|
\|/ \|/
----------- ------------
| VF | | PF |
----------- ------------a typical usage in SRIOV
Ref counts:
(1) vendor drivers must be a module and compiled to depend on module vfio_pci.
(2) In vfio_pci, a successful register would add refs of itself, and a successful unregister would derefs of itself.
(3) In vfio_pci, a successful probe() of a vendor driver would add ref of the vendor module. It derefs of the vendor module after calling remove().
(4) macro provided to make sure vendor module always unregister itself in its module_exit
Those are to prevent below conditions:
a. vfio_pci is unloaded after a successful register from vendor driver.
Though vfio_pci would later call modprobe to ask the vendor module to register again, it cannot help if vendor driver remain as loaded across unloading-loading of vfio_pci.
b. vendor driver unregisters itself after successfully probed by vfio_pci. c. circular dependency between vfio_pci and the vendor driver.
if vfio_pci adds refs to both vfio_pci and vendor driver on a successful register and if vendor driver only do the unregister in its module_exit, then it would have no chance to do the unregister.
Patch Overview
patches 1-2 makes vfio_pci inheritable by vendor modules
by making part of struct vfio_pci_device public and functions in struct vfio_pci_ops exported
patches 3-4 provide register/unregister interfaces for vendor drivers patches 5-6 some more enhancements
patch 7 provides an sample to pass through IGD devices patches 8-9 implement VF live migration on Intel's 710 SRIOV devices.
Some dirty page tracking functions are intentionally commented out and would send out later in future.
Changelog:
RFC v1- RFC v2:
- renamed mediate ops to vendor ops
- use of request_module and module alias to manage vendor driver load (Alex)
- changed from vfio_pci_ops calling vendor ops
to vendor ops calling default vfio_pci_ops (Alex)
- dropped patches for dynamic traps of BARs. will submit them later.
Links:
Previous version (RFC v1):
kernel part: https://www.spinics.net/lists/kernel/msg3337337.html.
qemu part: https://www.spinics.net/lists/kernel/msg3337337.html.
VFIO live migration v8:
https://lists.gnu.org/archive/html/qemu-devel/2019-08/msg05542.html.
Yan Zhao (9):
vfio/pci: split vfio_pci_device into public and private parts vfio/pci: export functions in vfio_pci_ops
vfio/pci: register/unregister vfio_pci_vendor_driver_ops vfio/pci: macros to generate module_init and module_exit for vendor
modules
vfio/pci: let vfio_pci know how many vendor regions are registered vfio/pci: export vfio_pci_setup_barmap
samples/vfio-pci: add a sample vendor module of vfio-pci for IGD
devices
vfio: header for vfio live migration region. i40e/vf_migration: vfio-pci vendor driver for VF live migration
drivers/net/ethernet/intel/Kconfig | 10 + drivers/net/ethernet/intel/i40e/Makefile | 2 + drivers/net/ethernet/intel/i40e/i40e.h | 2 + .../ethernet/intel/i40e/i40e_vf_migration.c | 590 ++++++++++++++++++ .../ethernet/intel/i40e/i40e_vf_migration.h | 92 +++ drivers/vfio/pci/vfio_pci.c | 337 ++++++---- drivers/vfio/pci/vfio_pci_config.c | 157 ++--- drivers/vfio/pci/vfio_pci_igd.c | 16 +- drivers/vfio/pci/vfio_pci_intrs.c | 171 ++--- drivers/vfio/pci/vfio_pci_nvlink2.c | 16 +- drivers/vfio/pci/vfio_pci_private.h | 11 +- drivers/vfio/pci/vfio_pci_rdwr.c | 60 +- include/linux/vfio.h | 61 ++ include/uapi/linux/vfio.h | 149 +++++ samples/Kconfig | 6 + samples/Makefile | 1 + samples/vfio-pci/Makefile | 2 + samples/vfio-pci/igd_pt.c | 153 +++++ 18 files changed, 1518 insertions(+), 318 deletions(-) create mode 100644 drivers/net/ethernet/intel/i40e/i40e_vf_migration.c create mode 100644 drivers/net/ethernet/intel/i40e/i40e_vf_migration.h create mode 100644 samples/vfio-pci/Makefile create mode 100644 samples/vfio-pci/igd_pt.c
Signature · 1 line
2.17.1
RFC PATCH v2 1/9 vfio/pci: split vfio_pci_device into public and private parts
split vfio_pci_device into two parts:
(1) a public part,
including pdev, num_region, irq_type which are accessible from outside of vfio.
(2) a private part,
a pointer to vfio_pci_device_private, only accessible within vfio
--- drivers/vfio/pci/vfio_pci.c | 209 +++++++++++++++------------- drivers/vfio/pci/vfio_pci_config.c | 157 +++++++++++---------- drivers/vfio/pci/vfio_pci_igd.c | 16 +-- drivers/vfio/pci/vfio_pci_intrs.c | 171 ++++++++++++----------- drivers/vfio/pci/vfio_pci_nvlink2.c | 16 +-- drivers/vfio/pci/vfio_pci_private.h | 5 +- drivers/vfio/pci/vfio_pci_rdwr.c | 36 ++--- include/linux/vfio.h | 7 + 8 files changed, 321 insertions(+), 296 deletions(-)
drivers/vfio/pci/vfio_pci.c +110 -99
@@ -113,7 +113,7 @@ static void vfio_pci_probe_mmaps(struct vfio_pci_device *vdev)int bar;struct vfio_pci_dummy_resource *dummy_res; -INIT_LIST_HEAD (&vdev->dummy_resources_list); +INIT_LIST_HEAD (&vdev->priv->dummy_resources_list);for (bar =PCI_STD_RESOURCES ; bar <=PCI_STD_RESOURCE_END ; bar++) { res = vdev->pdev->resource + bar;
@@ -133,7 +133,7 @@ static void vfio_pci_probe_mmaps(struct vfio_pci_device *vdev) goto no_mmap;if (resource_size (res) >=PAGE_SIZE ) { - vdev->bar_mmap_supported[bar] = true; + vdev->priv->bar_mmap_supported[bar] = true;continue ; }
@@ -158,8 +158,8 @@ static void vfio_pci_probe_mmaps(struct vfio_pci_device *vdev) } dummy_res->index = bar;list_add (&dummy_res->res_next, - &vdev->dummy_resources_list); - vdev->bar_mmap_supported[bar] = true; + &vdev->priv->dummy_resources_list); + vdev->priv->bar_mmap_supported[bar] = true;continue ; }/*
@@ -171,7 +171,7 @@ static void vfio_pci_probe_mmaps(struct vfio_pci_device *vdev)* the BAR's location in a page. */ no_mmap: - vdev->bar_mmap_supported[bar] = false; + vdev->priv->bar_mmap_supported[bar] = false; } }
@@ -217,7 +217,7 @@ static void vfio_pci_probe_power_state(struct vfio_pci_device *vdev)pci_read_config_word (pdev, pdev->pm_cap +PCI_PM_CTRL , &pmcsr); - vdev->needs_pm_restore = !(pmcsr &PCI_PM_CTRL_NO_SOFT_RESET ); + vdev->priv->needs_pm_restore = !(pmcsr &PCI_PM_CTRL_NO_SOFT_RESET ); }/*
@@ -233,7 +233,7 @@ int vfio_pci_set_power_state(struct vfio_pci_device *vdev, pci_power_t state)bool needs_restore = false, needs_save = false;int ret; -if (vdev->needs_pm_restore) { +if (vdev->priv->needs_pm_restore) {if (pdev->current_state < PCI_D3hot && state >= PCI_D3hot) {pci_save_state (pdev); needs_save = true;
@@ -248,9 +248,10 @@ int vfio_pci_set_power_state(struct vfio_pci_device *vdev, pci_power_t state)if (!ret) {/* D3 might be unsupported via quirk, skip unless in D3 */ if (needs_save && pdev->current_state >= PCI_D3hot) { - vdev->pm_save =pci_store_saved_state (pdev); + vdev->priv->pm_save =pci_store_saved_state (pdev); }else if (needs_restore) { -pci_load_and_free_saved_state (pdev, &vdev->pm_save); +pci_load_and_free_saved_state (pdev, + &vdev->priv->pm_save);pci_restore_state (pdev); } }
@@ -281,31 +282,31 @@ static int vfio_pci_enable(struct vfio_pci_device *vdev)return ret; } - vdev->reset_works = !ret; + vdev->priv->reset_works = !ret;pci_save_state (pdev); - vdev->pci_saved_state =pci_store_saved_state (pdev); -if (!vdev->pci_saved_state) + vdev->priv->pci_saved_state =pci_store_saved_state (pdev); +if (!vdev->priv->pci_saved_state)pci_dbg (pdev,"%s: Couldn't store saved state\n" , __func__);if (likely (!nointxmask)) {if (vfio_pci_nointx (pdev)) {pci_info (pdev,"Masking broken INTx support\n" ); - vdev->nointx = true; + vdev->priv->nointx = true;pci_intx (pdev,0 ); }else - vdev->pci_2_3 =pci_intx_mask_supported (pdev); + vdev->priv->pci_2_3 =pci_intx_mask_supported (pdev); }pci_read_config_word (pdev,PCI_COMMAND , &cmd); -if (vdev->pci_2_3 && (cmd &PCI_COMMAND_INTX_DISABLE )) { +if (vdev->priv->pci_2_3 && (cmd &PCI_COMMAND_INTX_DISABLE )) { cmd &= ~PCI_COMMAND_INTX_DISABLE ;pci_write_config_word (pdev,PCI_COMMAND , cmd); } ret =vfio_config_init (vdev);if (ret) { -kfree (vdev->pci_saved_state); - vdev->pci_saved_state =NULL ; +kfree (vdev->priv->pci_saved_state); + vdev->priv->pci_saved_state =NULL ;pci_disable_device (pdev);return ret; }
@@ -318,14 +319,15 @@ static int vfio_pci_enable(struct vfio_pci_device *vdev)pci_read_config_word (pdev, msix_pos +PCI_MSIX_FLAGS , &flags);pci_read_config_dword (pdev, msix_pos +PCI_MSIX_TABLE , &table); - vdev->msix_bar = table &PCI_MSIX_TABLE_BIR ; - vdev->msix_offset = table &PCI_MSIX_TABLE_OFFSET ; - vdev->msix_size = ((flags &PCI_MSIX_FLAGS_QSIZE ) +1 ) *16 ; + vdev->priv->msix_bar = table &PCI_MSIX_TABLE_BIR ; + vdev->priv->msix_offset = table &PCI_MSIX_TABLE_OFFSET ; + vdev->priv->msix_size = + ((flags &PCI_MSIX_FLAGS_QSIZE ) +1 ) *16 ; }else - vdev->msix_bar =0xFF ; + vdev->priv->msix_bar =0xFF ;if (!vfio_vga_disabled () &&vfio_pci_is_vga (pdev)) - vdev->has_vga = true; + vdev->priv->has_vga = true; if (vfio_pci_is_vga(pdev) &&
@@ -381,40 +383,41 @@ static void vfio_pci_disable(struct vfio_pci_device *vdev)/* Device closed, don't need mutex here */ list_for_each_entry_safe (ioeventfd, ioeventfd_tmp, - &vdev->ioeventfds_list, next) { + &vdev->priv->ioeventfds_list, next) {vfio_virqfd_disable (&ioeventfd->virqfd);list_del (&ioeventfd->next);kfree (ioeventfd); } - vdev->ioeventfds_nr =0 ; + vdev->priv->ioeventfds_nr =0 ; - vdev->virq_disabled = false; + vdev->priv->virq_disabled = false;for (i =0 ; i < vdev->num_regions; i++) - vdev->region[i].ops->release (vdev, &vdev->region[i]); + vdev->priv->region[i].ops->release (vdev, + &vdev->priv->region[i]); vdev->num_regions =0 ; -kfree (vdev->region); - vdev->region =NULL ;/* don't krealloc a freed pointer */ +kfree (vdev->priv->region); + vdev->priv->region =NULL ;/* don't krealloc a freed pointer */ vfio_config_free (vdev);for (bar =PCI_STD_RESOURCES ; bar <=PCI_STD_RESOURCE_END ; bar++) { -if (!vdev->barmap[bar]) +if (!vdev->priv->barmap[bar])continue ; -pci_iounmap (pdev, vdev->barmap[bar]); +pci_iounmap (pdev, vdev->priv->barmap[bar]);pci_release_selected_regions (pdev,1 << bar); - vdev->barmap[bar] =NULL ; + vdev->priv->barmap[bar] =NULL ; }list_for_each_entry_safe (dummy_res, tmp, - &vdev->dummy_resources_list, res_next) { + &vdev->priv->dummy_resources_list, res_next) {list_del (&dummy_res->res_next);release_resource (&dummy_res->resource);kfree (dummy_res); } - vdev->needs_reset = true; + vdev->priv->needs_reset = true;/* * If we have saved state, restore it. If we can reset the device,
@@ -422,10 +425,10 @@ static void vfio_pci_disable(struct vfio_pci_device *vdev)* nothing, but saving and restoring current state without reset * is just busy work. */ -if (pci_load_and_free_saved_state (pdev, &vdev->pci_saved_state)) { +if (pci_load_and_free_saved_state (pdev, &vdev->priv->pci_saved_state)) {pci_info (pdev,"%s: Couldn't reload saved state\n" , __func__); -if (!vdev->reset_works) +if (!vdev->priv->reset_works) goto out;pci_save_state (pdev);
@@ -444,10 +447,10 @@ static void vfio_pci_disable(struct vfio_pci_device *vdev)* We can not use the "try" reset interface here, which will * overwrite the previously restored configuration information. */ -if (vdev->reset_works &&pci_cfg_access_trylock (pdev)) { +if (vdev->priv->reset_works &&pci_cfg_access_trylock (pdev)) {if (device_trylock (&pdev->dev)) {if (!__pci_reset_function_locked (pdev)) - vdev->needs_reset = false; + vdev->priv->needs_reset = false;device_unlock (&pdev->dev); }pci_cfg_access_unlock (pdev);
@@ -467,14 +470,14 @@ static void vfio_pci_release(void *device_data) {struct vfio_pci_device *vdev = device_data; -mutex_lock (&vdev->reflck->lock); +mutex_lock (&vdev->priv->reflck->lock); -if (!(--vdev->refcnt)) { +if (!(--vdev->priv->refcnt)) {vfio_spapr_pci_eeh_release (vdev->pdev);vfio_pci_disable (vdev); } -mutex_unlock (&vdev->reflck->lock); +mutex_unlock (&vdev->priv->reflck->lock);module_put (THIS_MODULE ); }
@@ -487,18 +490,18 @@ static int vfio_pci_open(void *device_data)if (!try_module_get (THIS_MODULE ))return -ENODEV ; -mutex_lock (&vdev->reflck->lock); +mutex_lock (&vdev->priv->reflck->lock); -if (!vdev->refcnt) { +if (!vdev->priv->refcnt) { ret =vfio_pci_enable (vdev);if (ret) goto error;vfio_spapr_pci_eeh_open (vdev->pdev); } - vdev->refcnt++; + vdev->priv->refcnt++; error: -mutex_unlock (&vdev->reflck->lock); +mutex_unlock (&vdev->priv->reflck->lock);if (ret)module_put (THIS_MODULE );return ret;
@@ -510,7 +513,7 @@ static int vfio_pci_get_irq_count(struct vfio_pci_device *vdev, int irq_type)u8 pin;if (!IS_ENABLED (CONFIG_VFIO_PCI_INTX ) || - vdev->nointx || vdev->pdev->is_virtfn) + vdev->priv->nointx || vdev->pdev->is_virtfn)return 0 ;pci_read_config_byte (vdev->pdev,PCI_INTERRUPT_PIN , &pin);
@@ -669,19 +672,19 @@ int vfio_pci_register_dev_region(struct vfio_pci_device *vdev, {struct vfio_pci_region *region; - region =krealloc (vdev->region, + region =krealloc (vdev->priv->region, (vdev->num_regions +1 ) *sizeof (*region),GFP_KERNEL );if (!region)return -ENOMEM ; - vdev->region = region; - vdev->region[vdev->num_regions].type = type; - vdev->region[vdev->num_regions].subtype = subtype; - vdev->region[vdev->num_regions].ops = ops; - vdev->region[vdev->num_regions].size = size; - vdev->region[vdev->num_regions].flags = flags; - vdev->region[vdev->num_regions].data = data; + vdev->priv->region = region; + vdev->priv->region[vdev->num_regions].type = type; + vdev->priv->region[vdev->num_regions].subtype = subtype; + vdev->priv->region[vdev->num_regions].ops = ops; + vdev->priv->region[vdev->num_regions].size = size; + vdev->priv->region[vdev->num_regions].flags = flags; + vdev->priv->region[vdev->num_regions].data = data; vdev->num_regions++;
@@ -707,7 +710,7 @@ static long vfio_pci_ioctl(void *device_data, info.flags =VFIO_DEVICE_FLAGS_PCI ; -if (vdev->reset_works) +if (vdev->priv->reset_works) info.flags |=VFIO_DEVICE_FLAGS_RESET ; info.num_regions =VFIO_PCI_NUM_REGIONS + vdev->num_regions;
@@ -747,9 +750,9 @@ static long vfio_pci_ioctl(void *device_data, info.flags =VFIO_REGION_INFO_FLAG_READ |VFIO_REGION_INFO_FLAG_WRITE ; -if (vdev->bar_mmap_supported[info.index]) { +if (vdev->priv->bar_mmap_supported[info.index]) { info.flags |=VFIO_REGION_INFO_FLAG_MMAP ; -if (info.index == vdev->msix_bar) { +if (info.index == vdev->priv->msix_bar) { ret =msix_mmappable_cap (vdev, &caps);if (ret)return ret;
@@ -797,7 +800,7 @@ static long vfio_pci_ioctl(void *device_data,break ; }case VFIO_PCI_VGA_REGION_INDEX : -if (!vdev->has_vga) +if (!vdev->priv->has_vga)return -EINVAL ; info.offset =VFIO_PCI_INDEX_TO_OFFSET (info.index);
@@ -811,6 +814,7 @@ static long vfio_pci_ioctl(void *device_data,struct vfio_region_info_cap_type cap_type = { .header.id =VFIO_REGION_INFO_CAP_TYPE , .header.version =1 }; +struct vfio_pci_region *region;if (info.index >=VFIO_PCI_NUM_REGIONS + vdev->num_regions)
@@ -821,21 +825,22 @@ static long vfio_pci_ioctl(void *device_data, i = info.index -VFIO_PCI_NUM_REGIONS ; + region = vdev->priv->region; info.offset =VFIO_PCI_INDEX_TO_OFFSET (info.index); - info.size = vdev->region[i].size; - info.flags = vdev->region[i].flags; + info.size = region[i].size; + info.flags = region[i].flags; - cap_type.type = vdev->region[i].type; - cap_type.subtype = vdev->region[i].subtype; + cap_type.type = region[i].type; + cap_type.subtype = region[i].subtype; ret =vfio_info_add_capability (&caps, &cap_type.header,sizeof (cap_type));if (ret)return ret; -if (vdev->region[i].ops->add_capability) { - ret = vdev->region[i].ops->add_capability (vdev, - &vdev->region[i], &caps); +if (region[i].ops->add_capability) { + ret = region[i].ops->add_capability (vdev, + ®ion[i], &caps);if (ret)return ret; }
@@ -925,18 +930,18 @@ static long vfio_pci_ioctl(void *device_data,return PTR_ERR (data); } -mutex_lock (&vdev->igate); +mutex_lock (&vdev->priv->igate); ret =vfio_pci_set_irqs_ioctl (vdev, hdr.flags, hdr.index, hdr.start, hdr.count, data); -mutex_unlock (&vdev->igate); +mutex_unlock (&vdev->priv->igate);kfree (data);return ret; }else if (cmd ==VFIO_DEVICE_RESET ) { -return vdev->reset_works ? +return vdev->priv->reset_works ?pci_try_reset_function (vdev->pdev) : -EINVAL ; }else if (cmd ==VFIO_DEVICE_GET_PCI_HOT_RESET_INFO ) {
@@ -1167,7 +1172,7 @@ static ssize_t vfio_pci_rw(void *device_data, char __user *buf,return vfio_pci_vga_rw (vdev, buf, count, ppos, iswrite);default : index -=VFIO_PCI_NUM_REGIONS ; -return vdev->region[index].ops->rw (vdev, buf, +return vdev->priv->region[index].ops->rw (vdev, buf, count, ppos, iswrite); }
@@ -1208,7 +1213,7 @@ static int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma)return -EINVAL ;if (index >=VFIO_PCI_NUM_REGIONS ) {int regnum = index -VFIO_PCI_NUM_REGIONS ; -struct vfio_pci_region *region = vdev->region + regnum; +struct vfio_pci_region *region = vdev->priv->region + regnum;if (region && region->ops && region->ops->mmap && (region->flags &VFIO_REGION_INFO_FLAG_MMAP ))
@@ -1217,7 +1222,7 @@ static int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma) }if (index >=VFIO_PCI_ROM_REGION_INDEX )return -EINVAL ; -if (!vdev->bar_mmap_supported[index]) +if (!vdev->priv->bar_mmap_supported[index])return -EINVAL ; phys_len =PAGE_ALIGN (pci_resource_len (pdev, index));
@@ -1233,14 +1238,14 @@ static int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma)* Even though we don't make use of the barmap for the mmap, * we need to request the region and the barmap tracks that. */ -if (!vdev->barmap[index]) { +if (!vdev->priv->barmap[index]) { ret =pci_request_selected_regions (pdev,1 << index,"vfio-pci" );if (ret)return ret; - vdev->barmap[index] =pci_iomap (pdev, index,0 ); -if (!vdev->barmap[index]) { + vdev->priv->barmap[index] =pci_iomap (pdev, index,0 ); +if (!vdev->priv->barmap[index]) {pci_release_selected_regions (pdev,1 << index);return -ENOMEM ; }
@@ -1259,20 +1264,20 @@ static void vfio_pci_request(void *device_data, unsigned int count)struct vfio_pci_device *vdev = device_data;struct pci_dev *pdev = vdev->pdev; -mutex_lock (&vdev->igate); +mutex_lock (&vdev->priv->igate); -if (vdev->req_trigger) { +if (vdev->priv->req_trigger) {if (!(count %10 ))pci_notice_ratelimited (pdev,"Relaying device request to user (#%u)\n" , count); -eventfd_signal (vdev->req_trigger,1 ); +eventfd_signal (vdev->priv->req_trigger,1 ); }else if (count ==0 ) {pci_warn (pdev,"No device request channel registered, blocked until released by user\n" ); } -mutex_unlock (&vdev->igate); +mutex_unlock (&vdev->priv->igate); }static const struct vfio_device_ops vfio_pci_ops = {
@@ -1321,12 +1326,18 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)return -ENOMEM ; } + vdev->priv =kzalloc (sizeof (*vdev->priv),GFP_KERNEL ); +if (!vdev->priv) { +vfio_iommu_group_put (group, &pdev->dev); +return -ENOMEM ; + } + vdev->pdev = pdev; vdev->irq_type =VFIO_PCI_NUM_IRQS ; -mutex_init (&vdev->igate); -spin_lock_init (&vdev->irqlock); -mutex_init (&vdev->ioeventfds_lock); -INIT_LIST_HEAD (&vdev->ioeventfds_list); +mutex_init (&vdev->priv->igate); +spin_lock_init (&vdev->priv->irqlock); +mutex_init (&vdev->priv->ioeventfds_lock); +INIT_LIST_HEAD (&vdev->priv->ioeventfds_list); ret =vfio_add_group_dev (&pdev->dev, &vfio_pci_ops, vdev);if (ret) {
@@ -1376,16 +1387,16 @@ static void vfio_pci_remove(struct pci_dev *pdev)if (!vdev)return ; -vfio_pci_reflck_put (vdev->reflck); +vfio_pci_reflck_put (vdev->priv->reflck);vfio_iommu_group_put (pdev->dev.iommu_group, &pdev->dev); -kfree (vdev->region); -mutex_destroy (&vdev->ioeventfds_lock); +kfree (vdev->priv->region); +mutex_destroy (&vdev->priv->ioeventfds_lock);if (!disable_idle_d3)vfio_pci_set_power_state (vdev,PCI_D0 ); -kfree (vdev->pm_save); +kfree (vdev->priv->pm_save);kfree (vdev);if (vfio_pci_is_vga (pdev)) {
@@ -1412,12 +1423,12 @@ static pci_ers_result_t vfio_pci_aer_err_detected(struct pci_dev *pdev,return PCI_ERS_RESULT_DISCONNECT ; } -mutex_lock (&vdev->igate); +mutex_lock (&vdev->priv->igate); -if (vdev->err_trigger) -eventfd_signal (vdev->err_trigger,1 ); +if (vdev->priv->err_trigger) +eventfd_signal (vdev->priv->err_trigger,1 ); -mutex_unlock (&vdev->igate); +mutex_unlock (&vdev->priv->igate);vfio_device_put (device);
@@ -1474,9 +1485,9 @@ static int vfio_pci_reflck_find(struct pci_dev *pdev, void *data) vdev =vfio_device_data (device); -if (vdev->reflck) { -vfio_pci_reflck_get (vdev->reflck); - *preflck = vdev->reflck; +if (vdev->priv->reflck) { +vfio_pci_reflck_get (vdev->priv->reflck); + *preflck = vdev->priv->reflck;vfio_device_put (device);return 1 ; }
@@ -1493,12 +1504,12 @@ static int vfio_pci_reflck_attach(struct vfio_pci_device *vdev)if (pci_is_root_bus (vdev->pdev->bus) || vfio_pci_for_each_slot_or_bus(vdev->pdev, vfio_pci_reflck_find, - &vdev->reflck, slot) <=0 ) - vdev->reflck =vfio_pci_reflck_alloc (); + &vdev->priv->reflck, slot) <=0 ) + vdev->priv->reflck =vfio_pci_reflck_alloc ();mutex_unlock (&reflck_lock); -return PTR_ERR_OR_ZERO (vdev->reflck); +return PTR_ERR_OR_ZERO (vdev->priv->reflck); }static void vfio_pci_reflck_release (struct kref *kref)
@@ -1543,7 +1554,7 @@ static int vfio_pci_get_unused_devs(struct pci_dev *pdev, void *data) vdev =vfio_device_data (device);/* Fault if the device is not unused */ -if (vdev->refcnt) { +if (vdev->priv->refcnt) {vfio_device_put (device);return -EBUSY ; }
@@ -1559,7 +1570,7 @@ static int vfio_pci_get_unused_devs(struct pci_dev *pdev, void *data)* - At least one of the affected devices is marked dirty via * needs_reset (such as by lack of FLR support) * Then attempt to perform that bus or slot reset. Callers are required -* to hold vdev->reflck->lock, protecting the bus/slot reset group from +* to hold vdev->priv->reflck->lock, protecting the bus/slot reset group from * concurrent opens. A vfio_device reference is acquired for each device * to prevent unbinds during the reset operation. *
@@ -1597,7 +1608,7 @@ static void vfio_pci_try_bus_reset(struct vfio_pci_device *vdev)/* Does at least one need a reset? */ for (i =0 ; i < devs.cur_index; i++) { tmp =vfio_device_data (devs.devices[i]); -if (tmp->needs_reset) { +if (tmp->priv->needs_reset) { ret =pci_reset_bus (vdev->pdev);break ; }
@@ -1615,7 +1626,7 @@ static void vfio_pci_try_bus_reset(struct vfio_pci_device *vdev)* the power state. */ if (!ret) { - tmp->needs_reset = false; + tmp->priv->needs_reset = false;if (tmp != vdev && !disable_idle_d3)vfio_pci_set_power_state (tmp, PCI_D3hot);
drivers/vfio/pci/vfio_pci_config.c +82 -75
459 lines not on this page · raw message
drivers/vfio/pci/vfio_pci_igd.c +8 -8
@@ -25,13 +25,13 @@ static size_t vfio_pci_igd_rw(struct vfio_pci_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; +void *base = vdev->priv->region[i].data;loff_t pos = *ppos &VFIO_PCI_OFFSET_MASK ; -if (pos >= vdev->region[i].size || iswrite) +if (pos >= vdev->priv->region[i].size || iswrite)return -EINVAL ; - count =min (count, (size_t )(vdev->region[i].size - pos)); + count =min (count, (size_t )(vdev->priv->region[i].size - pos));if (copy_to_user (buf, base + pos, count))return -EFAULT ;
@@ -54,7 +54,7 @@ static const struct vfio_pci_regops vfio_pci_igd_regops = {static int vfio_pci_igd_opregion_init (struct vfio_pci_device *vdev) { -__le32 *dwordp = (__le32 *)(vdev->vconfig +OPREGION_PCI_ADDR ); +__le32 *dwordp = (__le32 *)(vdev->priv->vconfig +OPREGION_PCI_ADDR );u32 addr, size;void *base;int ret;
@@ -101,7 +101,7 @@ static int vfio_pci_igd_opregion_init(struct vfio_pci_device *vdev)/* Fill vconfig with the hw value and virtualize register */ *dwordp =cpu_to_le32 (addr); -memset (vdev->pci_config_map +OPREGION_PCI_ADDR , +memset (vdev->priv->pci_config_map +OPREGION_PCI_ADDR ,PCI_CAP_ID_INVALID_VIRT ,4 );return ret;
@@ -112,15 +112,15 @@ static size_t vfio_pci_igd_cfg_rw(struct vfio_pci_device *vdev, bool iswrite) {unsigned int i =VFIO_PCI_OFFSET_TO_INDEX (*ppos) -VFIO_PCI_NUM_REGIONS ; -struct pci_dev *pdev = vdev->region[i].data; +struct pci_dev *pdev = vdev->priv->region[i].data;loff_t pos = *ppos &VFIO_PCI_OFFSET_MASK ;size_t size;int ret; -if (pos >= vdev->region[i].size || iswrite) +if (pos >= vdev->priv->region[i].size || iswrite)return -EINVAL ; - size = count =min (count, (size_t )(vdev->region[i].size - pos)); + size = count =min (count, (size_t )(vdev->priv->region[i].size - pos));if ((pos &1 ) && size) {u8 val;
drivers/vfio/pci/vfio_pci_intrs.c +87 -84
406 lines not on this page · raw message
drivers/vfio/pci/vfio_pci_nvlink2.c +8 -8
@@ -43,16 +43,16 @@ static size_t vfio_pci_nvgpu_rw(struct vfio_pci_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; -struct vfio_pci_nvgpu_data *data = vdev->region[i].data; +struct vfio_pci_nvgpu_data *data = vdev->priv->region[i].data;loff_t pos = *ppos &VFIO_PCI_OFFSET_MASK ;loff_t posaligned = pos &PAGE_MASK , posoff = pos & ~PAGE_MASK ;size_t sizealigned;void __iomem *ptr; -if (pos >= vdev->region[i].size) +if (pos >= vdev->priv->region[i].size)return -EINVAL ; - count =min (count, (size_t )(vdev->region[i].size - pos)); + count =min (count, (size_t )(vdev->priv->region[i].size - pos));/* * We map only a bit of GPU RAM for a short time instead of mapping it
@@ -115,7 +115,7 @@ static vm_fault_t vfio_pci_nvgpu_mmap_fault(struct vm_fault *vmf) {vm_fault_t ret;struct vm_area_struct *vma = vmf->vma; -struct vfio_pci_region *region = vma->vm_private_data; +struct vfio_pci_region *region = vma->vm_priv_data;struct vfio_pci_nvgpu_data *data = region->data;unsigned long vmf_off = (vmf->address - vma->vm_start) >>PAGE_SHIFT ;unsigned long nv2pg = data->gpu_hpa >>PAGE_SHIFT ;
@@ -146,7 +146,7 @@ static int vfio_pci_nvgpu_mmap(struct vfio_pci_device *vdev,if (vma->vm_end - vma->vm_start > data->size)return -EINVAL ; - vma->vm_private_data = region; + vma->vm_priv_data = region; vma->vm_flags |=VM_PFNMAP ; vma->vm_ops = &vfio_pci_nvgpu_mmap_vmops;
@@ -306,13 +306,13 @@ static size_t vfio_pci_npu2_rw(struct vfio_pci_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; -struct vfio_pci_npu2_data *data = vdev->region[i].data; +struct vfio_pci_npu2_data *data = vdev->priv->region[i].data;loff_t pos = *ppos &VFIO_PCI_OFFSET_MASK ; -if (pos >= vdev->region[i].size) +if (pos >= vdev->priv->region[i].size)return -EINVAL ; - count =min (count, (size_t )(vdev->region[i].size - pos)); + count =min (count, (size_t )(vdev->priv->region[i].size - pos));if (iswrite) {if (copy_from_user (data->base + pos, buf, count))
drivers/vfio/pci/vfio_pci_private.h +1 -4
@@ -84,8 +84,7 @@ struct vfio_pci_reflck {struct mutex lock; }; -struct vfio_pci_device { -struct pci_dev *pdev; +struct vfio_pci_device_private {void __iomem *barmap[PCI_STD_RESOURCE_END +1 ];bool bar_mmap_supported[PCI_STD_RESOURCE_END +1 ];u8 *pci_config_map;
@@ -95,8 +94,6 @@ struct vfio_pci_device {struct mutex igate;struct vfio_pci_irq_ctx *ctx;int num_ctx; -int irq_type; -int num_regions;struct vfio_pci_region *region;u8 msi_qmax;u8 msix_bar;
drivers/vfio/pci/vfio_pci_rdwr.c +18 -18
@@ -135,7 +135,7 @@ static int vfio_pci_setup_barmap(struct vfio_pci_device *vdev, int bar)int ret;void __iomem *io; -if (vdev->barmap[bar]) +if (vdev->priv->barmap[bar])return 0 ; ret =pci_request_selected_regions (pdev,1 << bar,"vfio" );
@@ -148,7 +148,7 @@ static int vfio_pci_setup_barmap(struct vfio_pci_device *vdev, int bar)return -ENOMEM ; } - vdev->barmap[bar] = io; + vdev->priv->barmap[bar] = io;return 0 ; }
@@ -192,12 +192,12 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf,if (ret)return ret; - io = vdev->barmap[bar]; + io = vdev->priv->barmap[bar]; } -if (bar == vdev->msix_bar) { - x_start = vdev->msix_offset; - x_end = vdev->msix_offset + vdev->msix_size; +if (bar == vdev->priv->msix_bar) { + x_start = vdev->priv->msix_offset; + x_end = vdev->priv->msix_offset + vdev->priv->msix_size; } done =do_io_rw (io, buf, pos, count, x_start, x_end, iswrite);
@@ -221,7 +221,7 @@ ssize_t vfio_pci_vga_rw(struct vfio_pci_device *vdev, char __user *buf,bool is_ioport;ssize_t done; -if (!vdev->has_vga) +if (!vdev->priv->has_vga)return -EINVAL ;if (pos >0xbfffful )
@@ -314,9 +314,9 @@ long vfio_pci_ioeventfd(struct vfio_pci_device *vdev, loff_t offset,return -EINVAL ;/* Disallow ioeventfds working around MSI-X table writes */ -if (bar == vdev->msix_bar && - !(pos + count <= vdev->msix_offset || - pos >= vdev->msix_offset + vdev->msix_size)) +if (bar == vdev->priv->msix_bar && + !(pos + count <= vdev->priv->msix_offset || + pos >= vdev->priv->msix_offset + vdev->priv->msix_size))return -EINVAL ;#ifndef iowrite64
@@ -328,15 +328,15 @@ long vfio_pci_ioeventfd(struct vfio_pci_device *vdev, loff_t offset,if (ret)return ret; -mutex_lock (&vdev->ioeventfds_lock); +mutex_lock (&vdev->priv->ioeventfds_lock); -list_for_each_entry (ioeventfd, &vdev->ioeventfds_list, next) { +list_for_each_entry (ioeventfd, &vdev->priv->ioeventfds_list, next) {if (ioeventfd->pos == pos && ioeventfd->bar == bar && ioeventfd->data == data && ioeventfd->count == count) {if (fd ==-1 ) {vfio_virqfd_disable (&ioeventfd->virqfd);list_del (&ioeventfd->next); - vdev->ioeventfds_nr--; + vdev->priv->ioeventfds_nr--;kfree (ioeventfd); ret =0 ; }else
@@ -351,7 +351,7 @@ long vfio_pci_ioeventfd(struct vfio_pci_device *vdev, loff_t offset, goto out_unlock; } -if (vdev->ioeventfds_nr >=VFIO_PCI_IOEVENTFD_MAX ) { +if (vdev->priv->ioeventfds_nr >=VFIO_PCI_IOEVENTFD_MAX ) { ret = -ENOSPC ; goto out_unlock; }
@@ -362,7 +362,7 @@ long vfio_pci_ioeventfd(struct vfio_pci_device *vdev, loff_t offset, goto out_unlock; } - ioeventfd->addr = vdev->barmap[bar] + pos; + ioeventfd->addr = vdev->priv->barmap[bar] + pos; ioeventfd->data = data; ioeventfd->pos = pos; ioeventfd->bar = bar;
@@ -375,11 +375,11 @@ long vfio_pci_ioeventfd(struct vfio_pci_device *vdev, loff_t offset, goto out_unlock; } -list_add (&ioeventfd->next, &vdev->ioeventfds_list); - vdev->ioeventfds_nr++; +list_add (&ioeventfd->next, &vdev->priv->ioeventfds_list); + vdev->priv->ioeventfds_nr++; out_unlock: -mutex_unlock (&vdev->ioeventfds_lock); +mutex_unlock (&vdev->priv->ioeventfds_lock);return ret; }
include/linux/vfio.h +7 -0
@@ -195,4 +195,11 @@ extern int vfio_virqfd_enable(void *opaque, void *data, struct virqfd **pvirqfd, int fd);extern void vfio_virqfd_disable (struct virqfd **pvirqfd); +struct vfio_pci_device_private ; +struct vfio_pci_device { +struct pci_dev *pdev; +int num_regions; +int irq_type; +struct vfio_pci_device_private *priv; +};#endif /* VFIO_H */
Signature · 1 line
2.17.1
Re: [RFC PATCH v2 1/9] vfio/pci: split vfio_pci_device into public and private parts
Quoted 9 lines · On Thu, 30 Jan 2020 21:09:56 -0500 Yan Zhao <[email protected]> wrote:
split
vfio_pci_deviceinto two parts:
(1) a public part,
including pdev,num_region,irq_typewhich are accessible from outside of vfio.
(2) a private part,
a pointer tovfio_pci_device_private, only accessible within vfioCc Kevin Tian <[email protected]>Signed-off-by Yan Zhao <[email protected]>
Quoted 10 lines
--- drivers/vfio/pci/vfio_pci.c | 209 +++++++++++++++------------- drivers/vfio/pci/vfio_pci_config.c | 157 +++++++++++---------- drivers/vfio/pci/vfio_pci_igd.c | 16 +-- drivers/vfio/pci/vfio_pci_intrs.c | 171 ++++++++++++----------- drivers/vfio/pci/vfio_pci_nvlink2.c | 16 +-- drivers/vfio/pci/vfio_pci_private.h | 5 +- drivers/vfio/pci/vfio_pci_rdwr.c | 36 ++--- include/linux/vfio.h | 7 + 8 files changed, 321 insertions(+), 296 deletions(-)
I think the typical solution to something like this would be...
struct vfio_pci_device {
...
};struct vfio_pci_device_private {
struct vfio_pci_device vdev;
...
};External code would be able to work with the vfio_pci_device and internal code would do a container_of() to get access to the private fields. What's done here is pretty ugly and not very cache friendly. Thanks,
Alex
Re: [RFC PATCH v2 1/9] vfio/pci: split vfio_pci_device into public and private parts
Quoted 34 lines · Alex Williamson
Quoted 9 lines · On Thu, 30 Jan 2020 21:09:56 -0500 Yan Zhao <[email protected]> wrote:
split
vfio_pci_deviceinto two parts:
(1) a public part,
including pdev,num_region,irq_typewhich are accessible from outside of vfio.
(2) a private part,
a pointer tovfio_pci_device_private, only accessible within vfioCc Kevin Tian <[email protected]>Signed-off-by Yan Zhao <[email protected]>Quoted 10 lines
--- drivers/vfio/pci/vfio_pci.c | 209 +++++++++++++++------------- drivers/vfio/pci/vfio_pci_config.c | 157 +++++++++++---------- drivers/vfio/pci/vfio_pci_igd.c | 16 +-- drivers/vfio/pci/vfio_pci_intrs.c | 171 ++++++++++++----------- drivers/vfio/pci/vfio_pci_nvlink2.c | 16 +-- drivers/vfio/pci/vfio_pci_private.h | 5 +- drivers/vfio/pci/vfio_pci_rdwr.c | 36 ++--- include/linux/vfio.h | 7 + 8 files changed, 321 insertions(+), 296 deletions(-)I think the typical solution to something like this would be...
struct vfio_pci_device { ... };struct vfio_pci_device_private { struct vfio_pci_device vdev; ... };
Quoted 5 lines
External code would be able to work with the
vfio_pci_deviceand internal code would do acontainer_of()to get access to the private fields. What's done here is pretty ugly and not very cache friendly. Thanks,
got it, it's much better!
will change it. Thanks!
Yan
RFC PATCH v2 2/9 vfio/pci: export functions in vfio_pci_ops
In reply to Yan Zhaoexport functions in vfio_pci_ops,
including
vfio_pci_open,
vfio_pci_release,
vfio_pci_ioctl,
vfio_pci_read,
vfio_pci_write,
vfio_pci_mmap,
vfio_pci_request,
--- drivers/vfio/pci/vfio_pci.c | 21 ++++++++++++++------- include/linux/vfio.h | 11 +++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-)
drivers/vfio/pci/vfio_pci.c +14 -7
@@ -466,7 +466,7 @@ static void vfio_pci_disable(struct vfio_pci_device *vdev)vfio_pci_set_power_state (vdev, PCI_D3hot); } -static void vfio_pci_release (void *device_data) +void vfio_pci_release (void *device_data) {struct vfio_pci_device *vdev = device_data;
@@ -481,8 +481,9 @@ static void vfio_pci_release(void *device_data)module_put (THIS_MODULE ); } +EXPORT_SYMBOL_GPL (vfio_pci_release); -static int vfio_pci_open (void *device_data) +int vfio_pci_open (void *device_data) {struct vfio_pci_device *vdev = device_data;int ret =0 ;
@@ -506,6 +507,7 @@ static int vfio_pci_open(void *device_data)module_put (THIS_MODULE );return ret; } +EXPORT_SYMBOL_GPL (vfio_pci_open);static int vfio_pci_get_irq_count (struct vfio_pci_device *vdev,int irq_type) {
@@ -691,7 +693,7 @@ int vfio_pci_register_dev_region(struct vfio_pci_device *vdev,return 0 ; } -static long vfio_pci_ioctl (void *device_data, +long vfio_pci_ioctl (void *device_data,unsigned int cmd,unsigned long arg) {struct vfio_pci_device *vdev = device_data;
@@ -1146,6 +1148,7 @@ static long vfio_pci_ioctl(void *device_data,return -ENOTTY ; } +EXPORT_SYMBOL_GPL (vfio_pci_ioctl);static ssize_t vfio_pci_rw (void *device_data,char __user *buf,size_t count,loff_t *ppos,bool iswrite)
@@ -1179,7 +1182,7 @@ static ssize_t vfio_pci_rw(void *device_data, char __user *buf,return -EINVAL ; } -static ssize_t vfio_pci_read (void *device_data,char __user *buf, +ssize_t vfio_pci_read (void *device_data,char __user *buf,size_t count,loff_t *ppos) {if (!count)
@@ -1187,8 +1190,9 @@ static ssize_t vfio_pci_read(void *device_data, char __user *buf,return vfio_pci_rw (device_data, buf, count, ppos, false); } +EXPORT_SYMBOL_GPL (vfio_pci_read); -static ssize_t vfio_pci_write (void *device_data,const char __user *buf, +ssize_t vfio_pci_write (void *device_data,const char __user *buf,size_t count,loff_t *ppos) {if (!count)
@@ -1196,8 +1200,9 @@ static ssize_t vfio_pci_write(void *device_data, const char __user *buf,return vfio_pci_rw (device_data, (char __user *)buf, count, ppos, true); } +EXPORT_SYMBOL_GPL (vfio_pci_write); -static int vfio_pci_mmap (void *device_data,struct vm_area_struct *vma) +int vfio_pci_mmap (void *device_data,struct vm_area_struct *vma) {struct vfio_pci_device *vdev = device_data;struct pci_dev *pdev = vdev->pdev;
@@ -1258,8 +1263,9 @@ static int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma)return remap_pfn_range (vma, vma->vm_start, vma->vm_pgoff, req_len, vma->vm_page_prot); } +EXPORT_SYMBOL_GPL (vfio_pci_mmap); -static void vfio_pci_request (void *device_data,unsigned int count) +void vfio_pci_request (void *device_data,unsigned int count) {struct vfio_pci_device *vdev = device_data;struct pci_dev *pdev = vdev->pdev;
@@ -1279,6 +1285,7 @@ static void vfio_pci_request(void *device_data, unsigned int count)mutex_unlock (&vdev->priv->igate); } +EXPORT_SYMBOL_GPL (vfio_pci_request);static const struct vfio_device_ops vfio_pci_ops = { .name ="vfio-pci" ,
include/linux/vfio.h +11 -0
@@ -202,4 +202,15 @@ struct vfio_pci_device {int irq_type; struct vfio_pci_device_private *priv; }; + +extern long vfio_pci_ioctl (void *device_data, +unsigned int cmd,unsigned long arg); +extern ssize_t vfio_pci_read (void *device_data,char __user *buf, +size_t count,loff_t *ppos); +extern ssize_t vfio_pci_write (void *device_data,const char __user *buf, +size_t count,loff_t *ppos); +extern int vfio_pci_mmap (void *device_data,struct vm_area_struct *vma); +extern void vfio_pci_request (void *device_data,unsigned int count); +extern int vfio_pci_open (void *device_data); +extern void vfio_pci_release (void *device_data);#endif /* VFIO_H */
Signature · 1 line
2.17.1
RFC PATCH v2 3/9 vfio/pci: register/unregister vfio_pci_vendor_driver_ops
In reply to Yan Zhaovfio_pci_vendor_driver_ops includes two parts:
(1) .probe() and .remove() interfaces to be called by vfio_pci_probe() and vfio_pci_remove().
(2) pointer to struct vfio_device_ops. It will be registered as vfio device ops if .probe() succeeds.
--- drivers/vfio/pci/vfio_pci.c | 102 +++++++++++++++++++++++++++- drivers/vfio/pci/vfio_pci_private.h | 6 ++ include/linux/vfio.h | 13 ++++ 3 files changed, 120 insertions(+), 1 deletion(-)
drivers/vfio/pci/vfio_pci.c +101 -1
@@ -62,6 +62,10 @@ static inline bool vfio_vga_disabled(void)return true;#endif } +static struct vfio_pci { +struct mutex vendor_drivers_lock; +struct list_head vendor_drivers_list; +} vfio_pci;/* * Our VGA arbiter participation is limited since we don't know anything
@@ -1301,6 +1305,36 @@ static const struct vfio_device_ops vfio_pci_ops = {static int vfio_pci_reflck_attach (struct vfio_pci_device *vdev);static void vfio_pci_reflck_put (struct vfio_pci_reflck *reflck); +static int probe_vendor_drivers (struct vfio_pci_device *vdev) +{ + +struct vfio_pci_vendor_driver *driver; +int ret = -ENODEV ; + +request_module ("vfio-pci:%x-%x" , vdev->pdev->vendor, + vdev->pdev->device); + +mutex_lock (&vfio_pci.vendor_drivers_lock); +list_for_each_entry (driver, &vfio_pci.vendor_drivers_list, next) { +void *data; + +if (!try_module_get (driver->ops->owner)) +continue ; + + data = driver->ops->probe (vdev->pdev); +if (IS_ERR (data)) { +module_put (driver->ops->owner); +continue ; + } + vdev->vendor_driver = driver; + vdev->vendor_data = data; + ret =0 ; +break ; + } +mutex_unlock (&vfio_pci.vendor_drivers_lock); +return ret; +} +static int vfio_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) {struct vfio_pci_device *vdev;
@@ -1346,7 +1380,11 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)mutex_init (&vdev->priv->ioeventfds_lock);INIT_LIST_HEAD (&vdev->priv->ioeventfds_list); - ret =vfio_add_group_dev (&pdev->dev, &vfio_pci_ops, vdev); +if (probe_vendor_drivers (vdev)) + ret =vfio_add_group_dev (&pdev->dev, &vfio_pci_ops, vdev); +else + ret =vfio_add_group_dev (&pdev->dev, + vdev->vendor_driver->ops->device_ops, vdev);if (ret) {vfio_iommu_group_put (group, &pdev->dev);kfree (vdev);
@@ -1383,6 +1421,7 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)vfio_pci_set_power_state (vdev, PCI_D3hot); } +return ret; }
@@ -1403,6 +1442,11 @@ static void vfio_pci_remove(struct pci_dev *pdev)if (!disable_idle_d3)vfio_pci_set_power_state (vdev,PCI_D0 ); +if (vdev->vendor_driver) { + vdev->vendor_driver->ops->remove (vdev->vendor_data); +module_put (vdev->vendor_driver->ops->owner); + } +kfree (vdev->priv->pm_save);kfree (vdev);
@@ -1708,6 +1752,8 @@ static int __init vfio_pci_init(void)vfio_pci_fill_ids (); +mutex_init (&vfio_pci.vendor_drivers_lock); +INIT_LIST_HEAD (&vfio_pci.vendor_drivers_list);return 0 ; out_driver:
@@ -1715,6 +1761,60 @@ static int __init vfio_pci_init(void)return ret; } +int __vfio_pci_register_vendor_driver (struct vfio_pci_vendor_driver_ops *ops) +{ +struct vfio_pci_vendor_driver *driver, *tmp; + +if (!ops || !ops->device_ops) +return -EINVAL ; + + driver =kzalloc (sizeof (*driver),GFP_KERNEL ); +if (!driver) +return -ENOMEM ; + + driver->ops = ops; + +mutex_lock (&vfio_pci.vendor_drivers_lock); + +/* Check for duplicates */ +list_for_each_entry (tmp, &vfio_pci.vendor_drivers_list, next) { +if (tmp->ops->device_ops == ops->device_ops) { +mutex_unlock (&vfio_pci.vendor_drivers_lock); +kfree (driver); +return -EINVAL ; + } + } + +list_add (&driver->next, &vfio_pci.vendor_drivers_list); + +mutex_unlock (&vfio_pci.vendor_drivers_lock); + +if (!try_module_get (THIS_MODULE )) +return -ENODEV ; + +return 0 ; +} +EXPORT_SYMBOL_GPL (__vfio_pci_register_vendor_driver); + +void vfio_pci_unregister_vendor_driver (struct vfio_device_ops *device_ops) +{ +struct vfio_pci_vendor_driver *driver, *tmp; + +mutex_lock (&vfio_pci.vendor_drivers_lock); +list_for_each_entry_safe (driver, tmp, + &vfio_pci.vendor_drivers_list, next) { +if (driver->ops->device_ops == device_ops) { +list_del (&driver->next); +mutex_unlock (&vfio_pci.vendor_drivers_lock); +kfree (driver); +module_put (THIS_MODULE ); +return ; + } + } +mutex_unlock (&vfio_pci.vendor_drivers_lock); +} +EXPORT_SYMBOL_GPL (vfio_pci_unregister_vendor_driver); +module_init (vfio_pci_init);module_exit (vfio_pci_cleanup);
drivers/vfio/pci/vfio_pci_private.h +6 -0
@@ -84,6 +84,11 @@ struct vfio_pci_reflck {struct mutex lock; }; +struct vfio_pci_vendor_driver { +const struct vfio_pci_vendor_driver_ops *ops; +struct list_head next; +}; +struct vfio_pci_device_private {void __iomem *barmap[PCI_STD_RESOURCE_END +1 ];bool bar_mmap_supported[PCI_STD_RESOURCE_END +1 ];
@@ -119,6 +124,7 @@ struct vfio_pci_device_private {struct list_head dummy_resources_list;struct mutex ioeventfds_lock;struct list_head ioeventfds_list; + };#define is_intx (vdev) (vdev->irq_type == VFIO_PCI_INTX_IRQ_INDEX)
include/linux/vfio.h +13 -0
@@ -195,12 +195,25 @@ extern int vfio_virqfd_enable(void *opaque, void *data, struct virqfd **pvirqfd, int fd);extern void vfio_virqfd_disable (struct virqfd **pvirqfd); + +struct vfio_pci_vendor_driver_ops { +char *name; +struct module *owner; +void *(*probe)(struct pci_dev *pdev); +void (*remove)(void *vendor_data); +struct vfio_device_ops *device_ops; +}; +int __vfio_pci_register_vendor_driver (struct vfio_pci_vendor_driver_ops *ops); +void vfio_pci_unregister_vendor_driver (struct vfio_device_ops *device_ops); +struct vfio_pci_device_private ;struct vfio_pci_device {struct pci_dev *pdev;int num_regions;int irq_type;struct vfio_pci_device_private *priv; +struct vfio_pci_vendor_driver *vendor_driver; +void *vendor_data; }; extern long vfio_pci_ioctl(void *device_data,
Signature · 1 line
2.17.1
RFC PATCH v2 4/9 vfio/pci: macros to generate module_init and module_exit for vendor modules
In reply to Yan Zhaovendor modules call macro module_vfio_pci_register_vendor_handler to generate module_init and module_exit.
It is a must to ensure that vendor modules always call vfio_pci_register_vendor_driver() on driver loading and vfio_pci_unregister_vendor_driver on driver unloading,
because
(1) at compiling time, there's only a dependency of vendor modules on vfio_pci.
(2) at runtime,
- vendor modules trigger module ref inc of vfio_pci when vfio_pci_register_vendor_driver() succeeds and module ref dec of vfio_pci when vfio_pci_unregister_vendor_driver() succeeds.
- vfio_pci adds refs of vendor module on a successful probe of vendor driver.
vfio_pci derefs vendor module when unbinding from a device.
After vfio_pci is unbound from a device, the vendor module to that device is free to get unloaded. However, if that vendor module does not call vfio_pci_unregister_vendor_driver() before its module_exit, vfio_pc may hold a stale pointer to vendor module and would be able to get unloaded for the ref increased in vfio_pci_register_vendor_driver();
That's how module_vfio_pci_register_vendor_handler helps.
--- include/linux/vfio.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
include/linux/vfio.h +27 -0
@@ -226,4 +226,31 @@ extern int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma);extern void vfio_pci_request (void *device_data,unsigned int count);extern int vfio_pci_open (void *device_data);extern void vfio_pci_release (void *device_data); + +#define vfio_pci_register_vendor_driver (__name, __probe, __remove, \ + __device_ops) \ +static struct vfio_pci_vendor_driver_ops __ops ## _node = { \ + .owner = THIS_MODULE, \ + .name = __name, \ + .probe = __probe, \ + .remove = __remove, \ + .device_ops = __device_ops, \ +}; \ +__vfio_pci_register_vendor_driver(&__ops ## _node) + +#define module_vfio_pci_register_vendor_handler (name, probe, remove, \ + device_ops) \ +static int __init device_ops ## _module_init(void) \ +{ \ + vfio_pci_register_vendor_driver(name, probe, remove, \ + device_ops); \ + return 0; \ +}; \ +static void __exit device_ops ## _module_exit(void) \ +{ \ + vfio_pci_unregister_vendor_driver(device_ops); \ +}; \ +module_init(device_ops ## _module_init); \ +module_exit(device_ops ## _module_exit) +#endif /* VFIO_H */
Signature · 1 line
2.17.1
RFC PATCH v2 5/9 vfio/pci: let vfio_pci know how many vendor regions are registered
In reply to Yan ZhaoThis allows a simpler VFIO_DEVICE_GET_INFO ioctl in vendor driver
--- drivers/vfio/pci/vfio_pci.c | 3 ++- include/linux/vfio.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/vfio/pci/vfio_pci.c +2 -1
@@ -719,7 +719,8 @@ long vfio_pci_ioctl(void *device_data,if (vdev->priv->reset_works) info.flags |=VFIO_DEVICE_FLAGS_RESET ; - info.num_regions =VFIO_PCI_NUM_REGIONS + vdev->num_regions; + info.num_regions =VFIO_PCI_NUM_REGIONS + vdev->num_regions + + vdev->num_vendor_regions; info.num_irqs =VFIO_PCI_NUM_IRQS ; return copy_to_user((void __user *)arg, &info, minsz) ?
include/linux/vfio.h +1 -0
@@ -210,6 +210,7 @@ struct vfio_pci_device_private;struct vfio_pci_device {struct pci_dev *pdev;int num_regions; +int num_vendor_regions;int irq_type;struct vfio_pci_device_private *priv;struct vfio_pci_vendor_driver *vendor_driver;
Signature · 1 line
2.17.1
RFC PATCH v2 6/9 vfio/pci: export vfio_pci_setup_barmap
In reply to Yan ZhaoThis allows vendor driver to read/write to bars directly, which is useful in security checking condition.
E.g. if a value is invalid, vendor driver can modify the value before writing to hardware; if a value is valid, vendor driver calls default vfio_pci_write().
--- drivers/vfio/pci/vfio_pci_rdwr.c | 26 +++++++++++++------------- include/linux/vfio.h | 2 ++ 2 files changed, 15 insertions(+), 13 deletions(-)
drivers/vfio/pci/vfio_pci_rdwr.c +13 -13
@@ -129,29 +129,30 @@ static ssize_t do_io_rw(void __iomem *io, char __user *buf,return done; } -static int vfio_pci_setup_barmap (struct vfio_pci_device *vdev,int bar) +void __iomem *vfio_pci_setup_barmap (struct vfio_pci_device *vdev,int bar) {struct pci_dev *pdev = vdev->pdev;int ret;void __iomem *io;if (vdev->priv->barmap[bar]) -return 0 ; +return vdev->priv->barmap[bar]; ret =pci_request_selected_regions (pdev,1 << bar,"vfio" );if (ret) -return ret; +return NULL ; io =pci_iomap (pdev, bar,0 );if (!io) {pci_release_selected_regions (pdev,1 << bar); -return -ENOMEM ; +return NULL ; } vdev->priv->barmap[bar] = io; -return 0 ; +return io; } +EXPORT_SYMBOL_GPL (vfio_pci_setup_barmap);ssize_t vfio_pci_bar_rw (struct vfio_pci_device *vdev,char __user *buf,size_t count,loff_t *ppos,bool iswrite)
@@ -188,11 +189,9 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf,return -ENOMEM ; x_end = end; }else { -int ret =vfio_pci_setup_barmap (vdev, bar); -if (ret) -return ret; - - io = vdev->priv->barmap[bar]; + io =vfio_pci_setup_barmap (vdev, bar); +if (!io) +return -EFAULT ; }if (bar == vdev->priv->msix_bar) {
@@ -305,6 +304,7 @@ long vfio_pci_ioeventfd(struct vfio_pci_device *vdev, loff_t offset,loff_t pos = offset &VFIO_PCI_OFFSET_MASK ;int ret, bar =VFIO_PCI_OFFSET_TO_INDEX (offset);struct vfio_pci_ioeventfd *ioeventfd; +void __iomem *io;/* Only support ioeventfds into BARs */ if (bar >VFIO_PCI_BAR5_REGION_INDEX )
@@ -324,9 +324,9 @@ long vfio_pci_ioeventfd(struct vfio_pci_device *vdev, loff_t offset,return -EINVAL ;#endif - ret =vfio_pci_setup_barmap (vdev, bar); -if (ret) -return ret; + io =vfio_pci_setup_barmap (vdev, bar); +if (!io) +return -EFAULT ;mutex_lock (&vdev->priv->ioeventfds_lock);
include/linux/vfio.h +2 -0
@@ -227,6 +227,8 @@ extern int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma);extern void vfio_pci_request (void *device_data,unsigned int count);extern int vfio_pci_open (void *device_data);extern void vfio_pci_release (void *device_data); +extern void __iomem *vfio_pci_setup_barmap (struct vfio_pci_device *vdev, +int bar);#define vfio_pci_register_vendor_driver (__name, __probe, __remove, \ __device_ops) \
Signature · 1 line
2.17.1
RFC PATCH v2 7/9 samples/vfio-pci: add a sample vendor module of vfio-pci for IGD devices
In reply to Yan ZhaoThis sample driver does nothing but calls default device ops of vfio-pci to pass through IGD devices.
--- samples/Kconfig | 6 ++ samples/Makefile | 1 + samples/vfio-pci/Makefile | 2 + samples/vfio-pci/igd_pt.c | 153 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 162 insertions(+) create mode 100644 samples/vfio-pci/Makefile create mode 100644 samples/vfio-pci/igd_pt.c
samples/Kconfig +6 -0
@@ -169,4 +169,10 @@ config SAMPLE_VFS as mount API and statx(). Note that this is restricted to the x86 arch whilst it accesses system calls that aren't yet in all arches. +config SAMPLE_VFIO_PCI_IGD_PT + tristate "Build VFIO sample vendor driver to pass through IGD devices -- loadable modules only" + depends on VFIO_PCI && m + help + Build a sample driver to pass through IGD devices as a vendor driver + of VFIO PCI. endif # SAMPLES
samples/Makefile +1 -0
@@ -19,4 +19,5 @@ obj-$(CONFIG_SAMPLE_TRACE_EVENTS) += trace_events/ obj-$(CONFIG_SAMPLE_TRACE_PRINTK) += trace_printk/ obj-$(CONFIG_VIDEO_PCI_SKELETON) += v4l/ obj-y += vfio-mdev/ +obj-y += vfio-pci/ subdir-$(CONFIG_SAMPLE_VFS) += vfs
samples/vfio-pci/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_SAMPLE_VFIO_PCI_IGD_PT) += igd_pt.o
samples/vfio-pci/igd_pt.c new file +153 -0
153 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC PATCH v2 8/9 vfio: header for vfio live migration region.
In reply to Yan ZhaoHeader file copied from vfio live migration patch series v8. [1].
[1] https://lists.gnu.org/archive/html/qemu-devel/2019-08/msg05542.html
--- include/uapi/linux/vfio.h | 149 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+)
include/uapi/linux/vfio.h +149 -0
@@ -306,6 +306,155 @@ struct vfio_region_info_cap_type {#define VFIO_REGION_TYPE_GFX (1)#define VFIO_REGION_TYPE_CCW (2) +/* Migration region type and sub-type */ +#define VFIO_REGION_TYPE_MIGRATION (3) +#define VFIO_REGION_SUBTYPE_MIGRATION (1) + +/** +* Structure vfio_device_migration_info is placed at 0th offset of +* VFIO_REGION_SUBTYPE_MIGRATION region to get/set VFIO device related migration +* information. Field accesses from this structure are only supported at their +* native width and alignment, otherwise the result is undefined and vendor +* drivers should return an error. +* +* device_state: (read/write) +* To indicate vendor driver the state VFIO device should be transitioned +* to. If device state transition fails, write on this field return error. +* It consists of 3 bits: +* - If bit 0 set, indicates _RUNNING state. When its reset, that indicates +* _STOPPED state. When device is changed to _STOPPED, driver should stop +* device before write() returns. +* - If bit 1 set, indicates _SAVING state. +* - If bit 2 set, indicates _RESUMING state. +* Bits 3 - 31 are reserved for future use. User should perform +* read-modify-write operation on this field. +* _SAVING and _RESUMING bits set at the same time is invalid state. +* +* pending bytes: (read only) +* Number of pending bytes yet to be migrated from vendor driver +* +* data_offset: (read only) +* User application should read data_offset in migration region from where +* user application should read device data during _SAVING state or write +* device data during _RESUMING state or read dirty pages bitmap. See below +* for detail of sequence to be followed. +* +* data_size: (read/write) +* User application should read data_size to get size of data copied in +* migration region during _SAVING state and write size of data copied in +* migration region during _RESUMING state. +* +* start_pfn: (write only) +* Start address pfn to get bitmap of dirty pages from vendor driver duing +* _SAVING state. +* +* page_size: (write only) +* User application should write the page_size of pfn. +* +* total_pfns: (write only) +* Total pfn count from start_pfn for which dirty bitmap is requested. +* +* copied_pfns: (read only) +* pfn count for which dirty bitmap is copied to migration region. +* Vendor driver should copy the bitmap with bits set only for pages to be +* marked dirty in migration region. +* - Vendor driver should return VFIO_DEVICE_DIRTY_PFNS_NONE if none of the +* pages are dirty in requested range or rest of the range. +* - Vendor driver should return VFIO_DEVICE_DIRTY_PFNS_ALL to mark all +* pages dirty in the given range or rest of the range. +* - Vendor driver should return pfn count for which bitmap is written in +* the region. +* +* Migration region looks like: +* ------------------------------------------------------------------ +* |vfio_device_migration_info| data section | +* | | /////////////////////////////// | +* ------------------------------------------------------------------ +* ^ ^ ^ +* offset 0-trapped part data_offset data_size +* +* Data section is always followed by vfio_device_migration_info structure +* in the region, so data_offset will always be non-0. Offset from where data +* is copied is decided by kernel driver, data section can be trapped or +* mapped or partitioned, depending on how kernel driver defines data section. +* Data section partition can be defined as mapped by sparse mmap capability. +* If mmapped, then data_offset should be page aligned, where as initial section +* which contain vfio_device_migration_info structure might not end at offset +* which is page aligned. +* Data_offset can be same or different for device data and dirty pages bitmap. +* Vendor driver should decide whether to partition data section and how to +* partition the data section. Vendor driver should return data_offset +* accordingly. +* +* Sequence to be followed for _SAVING|_RUNNING device state or pre-copy phase +* and for _SAVING device state or stop-and-copy phase: +* a. read pending_bytes. If pending_bytes > 0, go through below steps. +* b. read data_offset, indicates kernel driver to write data to staging buffer. +* c. read data_size, amount of data in bytes written by vendor driver in +* migration region. +* d. read data_size bytes of data from data_offset in the migration region. +* e. process data. +* f. Loop through a to e. +* +* To copy system memory content during migration, vendor driver should be able +* to report system memory pages which are dirtied by that driver. For such +* dirty page reporting, user application should query for a range of GFNs +* relative to device address space (IOVA), then vendor driver should provide +* the bitmap of pages from this range which are dirtied by him through +* migration region where each bit represents a page and bit set to 1 represents +* that the page is dirty. +* User space application should take care of copying content of system memory +* for those pages. +* +* Steps to get dirty page bitmap: +* a. write start_pfn, page_size and total_pfns. +* b. read copied_pfns. Vendor driver should take one of the below action: +* - Vendor driver should return VFIO_DEVICE_DIRTY_PFNS_NONE if driver +* doesn't have any page to report dirty in given range or rest of the +* range. Exit the loop. +* - Vendor driver should return VFIO_DEVICE_DIRTY_PFNS_ALL to mark all +* pages dirty for given range or rest of the range. User space +* application mark all pages in the range as dirty and exit the loop. +* - Vendor driver should return copied_pfns and provide bitmap for +* copied_pfn in migration region. +* c. read data_offset, where vendor driver has written bitmap. +* d. read bitmap from the migration region from data_offset. +* e. Iterate through steps a to d while (total copied_pfns < total_pfns) +* +* Sequence to be followed while _RESUMING device state: +* While data for this device is available, repeat below steps: +* a. read data_offset from where user application should write data. +* b. write data of data_size to migration region from data_offset. +* c. write data_size which indicates vendor driver that data is written in +* staging buffer. +* +* For user application, data is opaque. User should write data in the same +* order as received. +*/ + +struct vfio_device_migration_info { +__u32 device_state;/* VFIO device state */ +#define VFIO_DEVICE_STATE_RUNNING (1 << 0) +#define VFIO_DEVICE_STATE_SAVING (1 << 1) +#define VFIO_DEVICE_STATE_RESUMING (1 << 2) +#define VFIO_DEVICE_STATE_MASK (VFIO_DEVICE_STATE_RUNNING | \ + VFIO_DEVICE_STATE_SAVING | \ + VFIO_DEVICE_STATE_RESUMING) +#define VFIO_DEVICE_STATE_INVALID (VFIO_DEVICE_STATE_SAVING | \ + VFIO_DEVICE_STATE_RESUMING) +__u32 reserved; +__u64 pending_bytes; +__u64 data_offset; +__u64 data_size; +__u64 start_pfn; +__u64 page_size; +__u64 total_pfns; +__u64 copied_pfns; +#define VFIO_DEVICE_DIRTY_PFNS_NONE (0) +#define VFIO_DEVICE_DIRTY_PFNS_ALL (~0ULL) +} __attribute__((packed)); + +/* sub-types for VFIO_REGION_TYPE_PCI_* */ /* 8086 vendor PCI sub-types */
Signature · 1 line
2.17.1
RFC PATCH v2 9/9 i40e/vf_migration: vfio-pci vendor driver for VF live migration
In reply to Yan Zhaovfio pci operates on regions
(1) 0 ~ VFIO_PCI_NUM_REGIONS - 1
(2) VFIO_PCI_NUM_REGIONS ~ VFIO_PCI_NUM_REGIONS + vdev->num_regions -1
vf_migration operates on regionsVFIO_PCI_NUM_REGIONS + vdev->num_regions ~ VFIO_PCI_NUM_REGIONS + vdev->num_regions + vdev->num_vendor_regions
vf_migration also intercept BAR0 write operation.
--- drivers/net/ethernet/intel/Kconfig | 10 + drivers/net/ethernet/intel/i40e/Makefile | 2 + drivers/net/ethernet/intel/i40e/i40e.h | 2 + .../ethernet/intel/i40e/i40e_vf_migration.c | 590 ++++++++++++++++++ .../ethernet/intel/i40e/i40e_vf_migration.h | 92 +++ 5 files changed, 696 insertions(+) create mode 100644 drivers/net/ethernet/intel/i40e/i40e_vf_migration.c create mode 100644 drivers/net/ethernet/intel/i40e/i40e_vf_migration.h
drivers/net/ethernet/intel/Kconfig +10 -0
@@ -264,6 +264,16 @@ config I40E_DCB If unsure, say N. +config I40E_VF_MIGRATION + tristate "XL710 Family VF live migration support -- loadable modules only" + depends on I40E && VFIO_PCI && m + help + Say m if you want to enable live migration of + Virtual Functions of Intel(R) Ethernet Controller XL710 + Family of devices. It must be a module. + This module serves as vendor module of module vfio_pci. + VFs bind to module vfio_pci directly. + # this is here to allow seamless migration from I40EVF --> IAVF name # so that CONFIG_IAVF symbol will always mirror the state of CONFIG_I40EVF config IAVF
drivers/net/ethernet/intel/i40e/Makefile +2 -0
@@ -27,3 +27,5 @@ i40e-objs := i40e_main.o \ i40e_xsk.o i40e-$(CONFIG_I40E_DCB) += i40e_dcb.o i40e_dcb_nl.o + +obj-$(CONFIG_I40E_VF_MIGRATION) += i40e_vf_migration.o
drivers/net/ethernet/intel/i40e/i40e.h +2 -0
@@ -1162,4 +1162,6 @@ int i40e_add_del_cloud_filter(struct i40e_vsi *vsi,int i40e_add_del_cloud_filter_big_buf (struct i40e_vsi *vsi,struct i40e_cloud_filter *filter,bool add); +int i40e_vf_migration_register (void ); +void i40e_vf_migration_unregister (void );#endif /* _I40E_H_ */
drivers/net/ethernet/intel/i40e/i40e_vf_migration.c new file +590 -0
590 lines not on this page · raw message
drivers/net/ethernet/intel/i40e/i40e_vf_migration.h new file +92 -0
92 lines not on this page · raw message
Signature · 1 line
2.17.1