Add Mediated device support
Subsystems (5)
Kirti Wankhede
maintainerv14 cover Add Mediated device support
This series adds Mediated device support to Linux host kernel. Purpose of this series is to provide a common interface for mediated device management that can be used by different devices. This series introduces Mdev core module that creates and manages mediated devices, VFIO based driver for mediated devices that are created by mdev core module and update VFIO type1 IOMMU module to support pinning & unpinning for mediated devices.
What changed v13-> v14?
- Added retries to notify DMA_UNMAP, if pfn_list is not empty.
- Added BUG_ON if pages are not unpined during DMA_UNMAP after 10 retries.
- Removed unpinning from detach_group() and release() and added WARN_ON if pfn_list is not empty.
- Updated page accounting logic.
Tested by assigning below combinations of devices to a single VM:
- GPU pass through only
- vGPU device only
- One GPU pass through and one vGPU device
- Linux VM hot plug and unplug vGPU device while GPU pass through device exist
- Linux VM hot plug and unplug GPU pass through device while vGPU device exist
Tested with Linux-next upto commit e76d21c40bd6.
Kirti Wankhede (22):
vfio: Mediated device Core driver
vfio: VFIO based driver for Mediated devices
vfio: Rearrange functions to get vfio_group from dev
vfio: Common function to increment container_users
vfio iommu: Added pin and unpin callback functions to
vfio_iommu_driver_ops
vfio iommu type1: Update arguments of vfio_lock_acct vfio iommu type1: Update argument of vaddr_get_pfn() vfio iommu type1: Add find_iommu_group() function
vfio iommu type1: Add task structure to vfio_dma
vfio iommu type1: Add support for mediated devices
vfio iommu: Add blocking notifier to notify DMA_UNMAP
vfio: Add notifier callback to parent's ops structure of mdev
vfio: Introduce common function to add capabilities
vfio_pci: Update vfio_pci to use vfio_info_add_capability()
vfio: Introduce vfio_set_irqs_validate_and_prepare()
vfio_pci: Updated to use vfio_set_irqs_validate_and_prepare()
vfio_platform: Updated to use vfio_set_irqs_validate_and_prepare()
vfio: Define device_api strings
docs: Add Documentation for Mediated devices
docs: Sysfs ABI for mediated device framework
docs: Sample driver to demonstrate how to use Mediated device
framework.
MAINTAINERS: Add entry VFIO based Mediated device drivers
Documentation/ABI/testing/sysfs-bus-vfio-mdev | 111 ++ Documentation/vfio-mediated-device.txt | 399 +++++++ MAINTAINERS | 9 + drivers/vfio/Kconfig | 1 + drivers/vfio/Makefile | 1 + drivers/vfio/mdev/Kconfig | 17 + drivers/vfio/mdev/Makefile | 5 + drivers/vfio/mdev/mdev_core.c | 385 +++++++ drivers/vfio/mdev/mdev_driver.c | 119 ++ drivers/vfio/mdev/mdev_private.h | 41 + drivers/vfio/mdev/mdev_sysfs.c | 286 +++++ drivers/vfio/mdev/vfio_mdev.c | 180 +++ drivers/vfio/pci/vfio_pci.c | 83 +- drivers/vfio/platform/vfio_platform_common.c | 31 +- drivers/vfio/vfio.c | 340 +++++- drivers/vfio/vfio_iommu_type1.c | 872 +++++++++++--- include/linux/mdev.h | 177 +++ include/linux/vfio.h | 32 +- include/uapi/linux/vfio.h | 10 + samples/vfio-mdev/Makefile | 13 + samples/vfio-mdev/mtty.c | 1503 +++++++++++++++++++++++++ 21 files changed, 4358 insertions(+), 257 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-vfio-mdev create mode 100644 Documentation/vfio-mediated-device.txt create mode 100644 drivers/vfio/mdev/Kconfig create mode 100644 drivers/vfio/mdev/Makefile create mode 100644 drivers/vfio/mdev/mdev_core.c create mode 100644 drivers/vfio/mdev/mdev_driver.c create mode 100644 drivers/vfio/mdev/mdev_private.h create mode 100644 drivers/vfio/mdev/mdev_sysfs.c create mode 100644 drivers/vfio/mdev/vfio_mdev.c create mode 100644 include/linux/mdev.h create mode 100644 samples/vfio-mdev/Makefile create mode 100644 samples/vfio-mdev/mtty.c
Signature · 1 line
2.7.0
Kirti Wankhede
maintainerPATCH v14 1/22 vfio: Mediated device Core driver
Design for Mediated Device Driver:
Main purpose of this driver is to provide a common interface for mediated device management that can be used by different drivers of different devices.
This module provides a generic interface to create the device, add it to mediated bus, add device to IOMMU group and then add it to vfio group.
Below is the high Level block diagram, with Nvidia, Intel and IBM devices as example, since these are the devices which are going to actively use this module as of now.
+---------------+ | | | +-----------+ | mdev_register_driver() +--------------+ | | | +<------------------------+ __init() | | | mdev | | | | | | bus | +------------------------>+ |<-> VFIO user | | driver | | probe()/remove() | vfio_mdev.ko | APIs | | | | | | | +-----------+ | +--------------+ | | | MDEV CORE | | MODULE | | mdev.ko | | +-----------+ | mdev_register_device() +--------------+ | | | +<------------------------+ | | | | | | nvidia.ko |<-> physical | | | +------------------------>+ | device | | | | callback +--------------+ | | Physical | | | | device | | mdev_register_device() +--------------+ | | interface | |<------------------------+ | | | | | | i915.ko |<-> physical | | | +------------------------>+ | device | | | | callback +--------------+ | | | | | | | | mdev_register_device() +--------------+ | | | +<------------------------+ | | | | | | ccw_device.ko|<-> physical | | | +------------------------>+ | device | | | | callback +--------------+ | +-----------+ | +---------------+
Core driver provides two types of registration interfaces:
1. Registration interface for mediated bus driver:
/**
* struct mdev_driver - Mediated device's driver
* @name: driver name
* @probe: called when new device created
* @remove:called when device removed
* @driver:device driver structure
*
**/
struct mdev_driver {
const char *name;
int (*probe) (struct device *dev);
void (*remove) (struct device *dev);
struct device_driver driver;
};Mediated bus driver for mdev device should use this interface to register and unregister with core driver respectively:
int mdev_register_driver(struct mdev_driver *drv, struct module *owner); void mdev_unregister_driver(struct mdev_driver *drv);
Mediated bus driver is responsible to add/delete mediated devices to/from VFIO group when devices are bound and unbound to the driver.
2. Physical device driver interface
This interface provides vendor driver the set APIs to manage physical device related work in its driver. APIs are :
* dev_attr_groups: attributes of the parent device.
* mdev_attr_groups: attributes of the mediated device.
* supported_type_groups: attributes to define supported type. This is mandatory field.
* create: to allocate basic resources in vendor driver for a mediated device. This is mandatory to be provided by vendor driver.
* remove: to free resources in vendor driver when mediated device is destroyed. This is mandatory to be provided by vendor driver.
* open: open callback of mediated device
* release: release callback of mediated device
* read : read emulation callback.
* write: write emulation callback.
* ioctl: ioctl callback.
* mmap: mmap emulation callback.
Drivers should use these interfaces to register and unregister device to mdev core driver respectively:
extern int mdev_register_device(struct device *dev,
const struct parent_ops *ops);
extern void mdev_unregister_device(struct device *dev);
There are no locks to serialize above callbacks in mdev driver and vfio_mdev driver. If required, vendor driver can have locks to serialize above APIs in their driver.
Change-Id: I73a5084574270b14541c529461ea2f03c292d510
--- drivers/vfio/Kconfig | 1 + drivers/vfio/Makefile | 1 + drivers/vfio/mdev/Kconfig | 9 + drivers/vfio/mdev/Makefile | 4 + drivers/vfio/mdev/mdev_core.c | 374 +++++++++++++++++++++++++++++++++++++++ drivers/vfio/mdev/mdev_driver.c | 119 +++++++++++++ drivers/vfio/mdev/mdev_private.h | 41 +++++ drivers/vfio/mdev/mdev_sysfs.c | 286 ++++++++++++++++++++++++++++++ include/linux/mdev.h | 168 ++++++++++++++++++ 9 files changed, 1003 insertions(+) create mode 100644 drivers/vfio/mdev/Kconfig create mode 100644 drivers/vfio/mdev/Makefile create mode 100644 drivers/vfio/mdev/mdev_core.c create mode 100644 drivers/vfio/mdev/mdev_driver.c create mode 100644 drivers/vfio/mdev/mdev_private.h create mode 100644 drivers/vfio/mdev/mdev_sysfs.c create mode 100644 include/linux/mdev.h
drivers/vfio/Kconfig +1 -0
@@ -48,4 +48,5 @@ menuconfig VFIO_NOIOMMU source "drivers/vfio/pci/Kconfig" source "drivers/vfio/platform/Kconfig" +source "drivers/vfio/mdev/Kconfig" source "virt/lib/Kconfig"
drivers/vfio/Makefile +1 -0
@@ -7,3 +7,4 @@ obj-$(CONFIG_VFIO_IOMMU_SPAPR_TCE) += vfio_iommu_spapr_tce.o obj-$(CONFIG_VFIO_SPAPR_EEH) += vfio_spapr_eeh.o obj-$(CONFIG_VFIO_PCI) += pci/ obj-$(CONFIG_VFIO_PLATFORM) += platform/ +obj-$(CONFIG_VFIO_MDEV) += mdev/
drivers/vfio/mdev/Kconfig new file +9 -0
@@ -0,0 +1,9 @@ + +config VFIO_MDEV + tristate "Mediated device driver framework" + depends on VFIO + default n + help + Provides a framework to virtualize devices. + + If you don't know what do here, say N.
drivers/vfio/mdev/Makefile new file +4 -0
@@ -0,0 +1,4 @@ + +mdev-y := mdev_core.o mdev_sysfs.o mdev_driver.o + +obj-$(CONFIG_VFIO_MDEV) += mdev.o
drivers/vfio/mdev/mdev_core.c new file +374 -0
374 lines not on this page · raw message
drivers/vfio/mdev/mdev_driver.c new file +119 -0
119 lines not on this page · raw message
drivers/vfio/mdev/mdev_private.h new file +41 -0
41 lines not on this page · raw message
drivers/vfio/mdev/mdev_sysfs.c new file +286 -0
286 lines not on this page · raw message
include/linux/mdev.h new file +168 -0
168 lines not on this page · raw message
Signature · 1 line
2.7.0
Kirti Wankhede
maintainerPATCH v14 2/22 vfio: VFIO based driver for Mediated devices
In reply to Kirti Wankhedevfio_mdev driver registers with mdev core driver.
mdev core driver creates mediated device and calls probe routine of vfio_mdev driver for each device.
Probe routine of vfio_mdev driver adds mediated device to VFIO core module
This driver forms a shim layer that pass through VFIO devices operations to vendor driver for mediated devices.
Change-Id: I583f4734752971d3d112324d69e2508c88f359ec
--- drivers/vfio/mdev/Kconfig | 7 ++ drivers/vfio/mdev/Makefile | 1 + drivers/vfio/mdev/mdev_core.c | 13 +++- drivers/vfio/mdev/vfio_mdev.c | 148 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 drivers/vfio/mdev/vfio_mdev.c
drivers/vfio/mdev/Kconfig +7 -0
@@ -7,3 +7,10 @@ config VFIO_MDEV Provides a framework to virtualize devices. If you don't know what do here, say N. + +config VFIO_MDEV_DEVICE + tristate "VFIO driver for Mediated devices" + depends on VFIO && VFIO_MDEV + default n + help + VFIO based driver for Mediated devices.
drivers/vfio/mdev/Makefile +1 -0
@@ -2,3 +2,4 @@ mdev-y := mdev_core.o mdev_sysfs.o mdev_driver.o obj-$(CONFIG_VFIO_MDEV) += mdev.o +obj-$(CONFIG_VFIO_MDEV_DEVICE) += vfio_mdev.o
drivers/vfio/mdev/mdev_core.c +12 -1
@@ -354,7 +354,18 @@ int mdev_device_remove(struct device *dev, bool force_remove)static int __init mdev_init (void ) { -return mdev_bus_register (); +int ret; + + ret =mdev_bus_register (); + +/* +* Attempt to load known vfio_mdev. This gives us a working environment +* without the user needing to explicitly load vfio_mdev driver. +*/ +if (!ret) +request_module_nowait ("vfio_mdev" ); + +return ret; } static void __exit mdev_exit(void)
drivers/vfio/mdev/vfio_mdev.c new file +148 -0
148 lines not on this page · raw message
Signature · 1 line
2.7.0
Kirti Wankhede
maintainerPATCH v14 3/22 vfio: Rearrange functions to get vfio_group from dev
In reply to Kirti WankhedeThis patch rearranges functions to get vfio_group from device
Change-Id: I1f93262bdbab75094bc24b087b29da35ba70c4c6
--- drivers/vfio/vfio.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
drivers/vfio/vfio.c +16 -7
@@ -480,6 +480,21 @@ static struct vfio_group *vfio_group_get_from_minor(int minor)return group; } +static struct vfio_group *vfio_group_get_from_dev (struct device *dev) +{ +struct iommu_group *iommu_group; +struct vfio_group *group; + + iommu_group =iommu_group_get (dev); +if (!iommu_group) +return NULL ; + + group =vfio_group_get_from_iommu (iommu_group); +iommu_group_put (iommu_group); + +return group; +} +/** * Device objects - create, release, get, put, search */
@@ -811,16 +826,10 @@ EXPORT_SYMBOL_GPL(vfio_add_group_dev);*/ struct vfio_device *vfio_device_get_from_dev (struct device *dev) { -struct iommu_group *iommu_group;struct vfio_group *group;struct vfio_device *device; - iommu_group =iommu_group_get (dev); -if (!iommu_group) -return NULL ; - - group =vfio_group_get_from_iommu (iommu_group); -iommu_group_put (iommu_group); + group =vfio_group_get_from_dev (dev);if (!group)return NULL ;
Signature · 1 line
2.7.0
Kirti Wankhede
maintainerPATCH v14 4/22 vfio: Common function to increment container_users
In reply to Kirti WankhedeThis change rearrange functions to have common function to increment container_users
Change-Id: I8bdeb352bc8439b107ffd519480fd4dc238677f2
--- drivers/vfio/vfio.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-)
drivers/vfio/vfio.c +21 -13
@@ -1385,6 +1385,23 @@ static bool vfio_group_viable(struct vfio_group *group) group, vfio_dev_viable) == 0); } +static int vfio_group_add_container_user (struct vfio_group *group) +{ +if (!atomic_inc_not_zero (&group->container_users)) +return -EINVAL ; + +if (group->noiommu) { +atomic_dec (&group->container_users); +return -EPERM ; + } +if (!group->container->iommu_driver || !vfio_group_viable (group)) { +atomic_dec (&group->container_users); +return -EINVAL ; + } + +return 0 ; +} +static const struct file_operations vfio_device_fops;static int vfio_group_get_device_fd (struct vfio_group *group,char *buf)
@@ -1694,23 +1711,14 @@ static const struct file_operations vfio_device_fops = {struct vfio_group *vfio_group_get_external_user (struct file *filep) {struct vfio_group *group = filep->private_data; +int ret;if (filep->f_op != &vfio_group_fops)return ERR_PTR (-EINVAL ); -if (!atomic_inc_not_zero (&group->container_users)) -return ERR_PTR (-EINVAL ); - -if (group->noiommu) { -atomic_dec (&group->container_users); -return ERR_PTR (-EPERM ); - } - -if (!group->container->iommu_driver || - !vfio_group_viable (group)) { -atomic_dec (&group->container_users); -return ERR_PTR (-EINVAL ); - } + ret =vfio_group_add_container_user (group); +if (ret) +return ERR_PTR (ret);vfio_group_get (group);
Signature · 1 line
2.7.0
Kirti Wankhede
maintainerPATCH v14 5/22 vfio iommu: Added pin and unpin callback functions to vfio_iommu_driver_ops
In reply to Kirti WankhedeAdded APIs for pining and unpining set of pages. These call back into backend iommu module to actually pin and unpin pages.
Added two new callback functions to struct vfio_iommu_driver_ops. Backend IOMMU module that supports pining and unpinning pages for mdev devices should provide these functions.
Renamed static functions in vfio_type1_iommu.c to resolve conflicts
Change-Id: Ia7417723aaae86bec2959ad9ae6c2915ddd340e0
--- drivers/vfio/vfio.c | 102 ++++++++++++++++++++++++++++++++++++++++ drivers/vfio/vfio_iommu_type1.c | 20 ++++---- include/linux/vfio.h | 13 ++++- 3 files changed, 124 insertions(+), 11 deletions(-)
drivers/vfio/vfio.c +102 -0
@@ -1799,6 +1799,108 @@ void vfio_info_cap_shift(struct vfio_info_cap *caps, size_t offset) }EXPORT_SYMBOL_GPL (vfio_info_cap_shift); + +/* +* Pin a set of guest PFNs and return their associated host PFNs for local +* domain only. +* @dev [in] : device +* @user_pfn [in]: array of user/guest PFNs to be unpinned. +* @npage [in] : count of elements in user_pfn array. This count should not +* be greater VFIO_PIN_PAGES_MAX_ENTRIES. +* @prot [in] : protection flags +* @phys_pfn[out]: array of host PFNs +* Return error or number of pages pinned. +*/ +int vfio_pin_pages (struct device *dev,unsigned long *user_pfn,int npage, +int prot,unsigned long *phys_pfn) +{ +struct vfio_container *container; +struct vfio_group *group; +struct vfio_iommu_driver *driver; +int ret; + +if (!dev || !user_pfn || !phys_pfn || !npage) +return -EINVAL ; + +if (npage >VFIO_PIN_PAGES_MAX_ENTRIES ) +return -E2BIG ; + + group =vfio_group_get_from_dev (dev); +if (IS_ERR (group)) +return PTR_ERR (group); + + ret =vfio_group_add_container_user (group); +if (ret) + goto err_pin_pages; + + container = group->container; +down_read (&container->group_lock); + + driver = container->iommu_driver; +if (likely (driver && driver->ops->pin_pages)) + ret = driver->ops->pin_pages (container->iommu_data, user_pfn, + npage, prot, phys_pfn); +else + ret = -ENOTTY ; + +up_read (&container->group_lock); +vfio_group_try_dissolve_container (group); + +err_pin_pages: +vfio_group_put (group); +return ret; +} +EXPORT_SYMBOL (vfio_pin_pages); + +/* +* Unpin set of host PFNs for local domain only. +* @dev [in] : device +* @user_pfn [in]: array of user/guest PFNs to be unpinned. Number of user/guest +* PFNs should not be greater than VFIO_PIN_PAGES_MAX_ENTRIES. +* @npage [in] : count of elements in user_pfn array. This count should not +* be greater than VFIO_PIN_PAGES_MAX_ENTRIES. +* Return error or number of pages unpinned. +*/ +int vfio_unpin_pages (struct device *dev,unsigned long *user_pfn,int npage) +{ +struct vfio_container *container; +struct vfio_group *group; +struct vfio_iommu_driver *driver; +int ret; + +if (!dev || !user_pfn || !npage) +return -EINVAL ; + +if (npage >VFIO_PIN_PAGES_MAX_ENTRIES ) +return -E2BIG ; + + group =vfio_group_get_from_dev (dev); +if (IS_ERR (group)) +return PTR_ERR (group); + + ret =vfio_group_add_container_user (group); +if (ret) + goto err_unpin_pages; + + container = group->container; +down_read (&container->group_lock); + + driver = container->iommu_driver; +if (likely (driver && driver->ops->unpin_pages)) + ret = driver->ops->unpin_pages (container->iommu_data, user_pfn, + npage); +else + ret = -ENOTTY ; + +up_read (&container->group_lock); +vfio_group_try_dissolve_container (group); + +err_unpin_pages: +vfio_group_put (group); +return ret; +} +EXPORT_SYMBOL (vfio_unpin_pages); +/** * Module/class support */
drivers/vfio/vfio_iommu_type1.c +10 -10
@@ -259,8 +259,8 @@ static int vaddr_get_pfn(unsigned long vaddr, int prot, unsigned long *pfn)* the iommu can only map chunks of consecutive pfns anyway, so get the * first page and all consecutive pages with the same locking. */ -static long vfio_pin_pages (unsigned long vaddr,long npage, -int prot,unsigned long *pfn_base) +static long vfio_pin_pages_remote (unsigned long vaddr,long npage, +int prot,unsigned long *pfn_base) {unsigned long limit =rlimit (RLIMIT_MEMLOCK ) >>PAGE_SHIFT ;bool lock_cap =capable (CAP_IPC_LOCK );
@@ -318,8 +318,8 @@ static long vfio_pin_pages(unsigned long vaddr, long npage,return i; } -static long vfio_unpin_pages (unsigned long pfn,long npage, -int prot,bool do_accounting) +static long vfio_unpin_pages_remote (unsigned long pfn,long npage, +int prot,bool do_accounting) {unsigned long unlocked =0 ;long i;
@@ -382,9 +382,9 @@ static void vfio_unmap_unpin(struct vfio_iommu *iommu, struct vfio_dma *dma)if (WARN_ON (!unmapped))break ; - unlocked +=vfio_unpin_pages (phys >>PAGE_SHIFT , - unmapped >>PAGE_SHIFT , - dma->prot, false); + unlocked +=vfio_unpin_pages_remote (phys >>PAGE_SHIFT , + unmapped >>PAGE_SHIFT , + dma->prot, false); iova += unmapped;cond_resched ();
@@ -613,8 +613,8 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu,while (size) {/* Pin a contiguous chunk of memory */ - npage =vfio_pin_pages (vaddr + dma->size, - size >>PAGE_SHIFT , prot, &pfn); + npage =vfio_pin_pages_remote (vaddr + dma->size, + size >>PAGE_SHIFT , prot, &pfn);if (npage <=0 ) {WARN_ON (!npage); ret = (int )npage;
@@ -624,7 +624,7 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu,/* Map it! */ ret =vfio_iommu_map (iommu, iova + dma->size, pfn, npage, prot);if (ret) { -vfio_unpin_pages (pfn, npage, prot, true); +vfio_unpin_pages_remote (pfn, npage, prot, true);break ; }
include/linux/vfio.h +12 -1
@@ -75,7 +75,11 @@ struct vfio_iommu_driver_ops { struct iommu_group *group);void (*detach_group)(void *iommu_data,struct iommu_group *group); - +int (*pin_pages)(void *iommu_data,unsigned long *user_pfn, +int npage,int prot, +unsigned long *phys_pfn); +int (*unpin_pages)(void *iommu_data, +unsigned long *user_pfn,int npage); };extern int vfio_register_iommu_driver (const struct vfio_iommu_driver_ops *ops);
@@ -92,6 +96,13 @@ extern int vfio_external_user_iommu_id(struct vfio_group *group);extern long vfio_external_check_extension (struct vfio_group *group,unsigned long arg); +#define VFIO_PIN_PAGES_MAX_ENTRIES (PAGE_SIZE/sizeof(unsigned long)) + +extern int vfio_pin_pages (struct device *dev,unsigned long *user_pfn, +int npage,int prot,unsigned long *phys_pfn); +extern int vfio_unpin_pages (struct device *dev,unsigned long *user_pfn, +int npage); +/* * Sub-module helpers */
Signature · 1 line
2.7.0
Kirti Wankhede
maintainerPATCH v14 6/22 vfio iommu type1: Update arguments of vfio_lock_acct
In reply to Kirti WankhedeAdded task structure as input argument to vfio_lock_acct() function.
--- drivers/vfio/vfio_iommu_type1.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-)
drivers/vfio/vfio_iommu_type1.c +16 -14
@@ -150,17 +150,22 @@ static void vfio_lock_acct_bg(struct work_struct *work)kfree (vwork); } -static void vfio_lock_acct (long npage) +static void vfio_lock_acct (struct task_struct *task,long npage) {struct vwork *vwork;struct mm_struct *mm; -if (!current->mm || !npage) +if (!npage) +return ; + + mm =get_task_mm (task); +if (!mm)return ;/* process exited or nothing to do */ -if (down_write_trylock (¤t->mm->mmap_sem)) { - current->mm->locked_vm += npage; -up_write (¤t->mm->mmap_sem); +if (down_write_trylock (&mm->mmap_sem)) { + mm->locked_vm += npage; +up_write (&mm->mmap_sem); +mmput (mm);return ; }
@@ -170,11 +175,8 @@ static void vfio_lock_acct(long npage)* wouldn't need this silliness */ vwork =kmalloc (sizeof (struct vwork ),GFP_KERNEL ); -if (!vwork) -return ; - mm =get_task_mm (current); -if (!mm) { -kfree (vwork); +if (!vwork) { +mmput (mm);return ; }INIT_WORK (&vwork->work, vfio_lock_acct_bg);
@@ -285,7 +287,7 @@ static long vfio_pin_pages_remote(unsigned long vaddr, long npage,if (unlikely (disable_hugepages)) {if (!rsvd) -vfio_lock_acct (1 ); +vfio_lock_acct (current,1 );return 1 ; }
@@ -313,7 +315,7 @@ static long vfio_pin_pages_remote(unsigned long vaddr, long npage, }if (!rsvd) -vfio_lock_acct (i); +vfio_lock_acct (current, i);return i; }
@@ -328,7 +330,7 @@ static long vfio_unpin_pages_remote(unsigned long pfn, long npage, unlocked +=put_pfn (pfn++, prot);if (do_accounting) -vfio_lock_acct (-unlocked); +vfio_lock_acct (current, -unlocked);return unlocked; }
@@ -390,7 +392,7 @@ static void vfio_unmap_unpin(struct vfio_iommu *iommu, struct vfio_dma *dma)cond_resched (); } -vfio_lock_acct (-unlocked); +vfio_lock_acct (current, -unlocked); }static void vfio_remove_dma (struct vfio_iommu *iommu,struct vfio_dma *dma)
Signature · 1 line
2.7.0
Kirti Wankhede
maintainerPATCH v14 7/22 vfio iommu type1: Update argument of vaddr_get_pfn()
In reply to Kirti WankhedeUpdate arguments of vaddr_get_pfn() to take struct mm_struct *mm as input argument.
--- drivers/vfio/vfio_iommu_type1.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-)
drivers/vfio/vfio_iommu_type1.c +24 -8
@@ -230,20 +230,36 @@ static int put_pfn(unsigned long pfn, int prot)return 0 ; } -static int vaddr_get_pfn (unsigned long vaddr,int prot,unsigned long *pfn) +static int vaddr_get_pfn (struct mm_struct *mm,unsigned long vaddr, +int prot,unsigned long *pfn) {struct page *page[1 ];struct vm_area_struct *vma; -int ret = -EFAULT ; +int ret; + +if (mm == current->mm) { + ret =get_user_pages_fast (vaddr,1 , !!(prot &IOMMU_WRITE ), + page); + }else { +unsigned int flags =0 ; + +if (prot &IOMMU_WRITE ) + flags |=FOLL_WRITE ; + +down_read (&mm->mmap_sem); + ret =get_user_pages_remote (NULL , mm, vaddr,1 , flags, page, +NULL ); +up_read (&mm->mmap_sem); + } -if (get_user_pages_fast (vaddr,1 , !!(prot &IOMMU_WRITE ), page) ==1 ) { +if (ret ==1 ) { *pfn =page_to_pfn (page[0 ]);return 0 ; } -down_read (¤t->mm->mmap_sem); +down_read (&mm->mmap_sem); - vma =find_vma_intersection (current->mm, vaddr, vaddr +1 ); + vma =find_vma_intersection (mm, vaddr, vaddr +1 );if (vma && vma->vm_flags &VM_PFNMAP ) { *pfn = ((vaddr - vma->vm_start) >>PAGE_SHIFT ) + vma->vm_pgoff;
@@ -251,7 +267,7 @@ static int vaddr_get_pfn(unsigned long vaddr, int prot, unsigned long *pfn) ret =0 ; } -up_read (¤t->mm->mmap_sem); +up_read (&mm->mmap_sem);return ret; }
@@ -272,7 +288,7 @@ static long vfio_pin_pages_remote(unsigned long vaddr, long npage,if (!current->mm)return -ENODEV ; - ret =vaddr_get_pfn (vaddr, prot, pfn_base); + ret =vaddr_get_pfn (current->mm, vaddr, prot, pfn_base);if (ret)return ret;
@@ -295,7 +311,7 @@ static long vfio_pin_pages_remote(unsigned long vaddr, long npage,for (i =1 , vaddr +=PAGE_SIZE ; i < npage; i++, vaddr +=PAGE_SIZE ) {unsigned long pfn =0 ; - ret =vaddr_get_pfn (vaddr, prot, &pfn); + ret =vaddr_get_pfn (current->mm, vaddr, prot, &pfn);if (ret)break ;
Signature · 1 line
2.7.0
Kirti Wankhede
maintainerPATCH v14 8/22 vfio iommu type1: Add find_iommu_group() function
In reply to Kirti WankhedeAdd find_iommu_group()
Change-Id: I9d372f1ebe9eb01a5a21374b8a2b03f7df73601f
--- drivers/vfio/vfio_iommu_type1.c | 57 ++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 24 deletions(-)
drivers/vfio/vfio_iommu_type1.c +33 -24
@@ -752,11 +752,24 @@ static void vfio_test_domain_fgsp(struct vfio_domain *domain)__free_pages (pages, order); } +static struct vfio_group *find_iommu_group (struct vfio_domain *domain, +struct iommu_group *iommu_group) +{ +struct vfio_group *g; + +list_for_each_entry (g, &domain->group_list, next) { +if (g->iommu_group == iommu_group) +return g; + } + +return NULL ; +} +static int vfio_iommu_type1_attach_group (void *iommu_data,struct iommu_group *iommu_group) {struct vfio_iommu *iommu = iommu_data; -struct vfio_group *group, *g; +struct vfio_group *group;struct vfio_domain *domain, *d;struct bus_type *bus =NULL ;int ret;
@@ -764,10 +777,7 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,mutex_lock (&iommu->lock);list_for_each_entry (d, &iommu->domain_list, next) { -list_for_each_entry (g, &d->group_list, next) { -if (g->iommu_group != iommu_group) -continue ; - +if (find_iommu_group (d, iommu_group)) {mutex_unlock (&iommu->lock);return -EINVAL ; }
@@ -887,27 +897,26 @@ static void vfio_iommu_type1_detach_group(void *iommu_data,mutex_lock (&iommu->lock);list_for_each_entry (domain, &iommu->domain_list, next) { -list_for_each_entry (group, &domain->group_list, next) { -if (group->iommu_group != iommu_group) -continue ; + group =find_iommu_group (domain, iommu_group); +if (!group) +continue ; -iommu_detach_group (domain->domain, iommu_group); -list_del (&group->next); -kfree (group); -/* -* Group ownership provides privilege, if the group -* list is empty, the domain goes away. If it's the -* last domain, then all the mappings go away too. -*/ -if (list_empty (&domain->group_list)) { -if (list_is_singular (&iommu->domain_list)) -vfio_iommu_unmap_unpin_all (iommu); -iommu_domain_free (domain->domain); -list_del (&domain->next); -kfree (domain); - } - goto done; +iommu_detach_group (domain->domain, iommu_group); +list_del (&group->next); +kfree (group); +/* +* Group ownership provides privilege, if the group +* list is empty, the domain goes away. If it's the +* last domain, then all the mappings go away too. +*/ +if (list_empty (&domain->group_list)) { +if (list_is_singular (&iommu->domain_list)) +vfio_iommu_unmap_unpin_all (iommu); +iommu_domain_free (domain->domain); +list_del (&domain->next); +kfree (domain); } + goto done; } done:
Signature · 1 line
2.7.0
Re: [PATCH v14 08/22] vfio iommu type1: Add find_iommu_group() function
Hi,
Quoted 91 lines · Kirti Wankhede
Add
find_iommu_group()Signed-off-by Kirti Wankhede <[email protected]>Signed-off-by Neo Jia <[email protected]>Reviewed-by Jike Song <[email protected]>Reviewed-by Dong Jia Shi <[email protected]>Change-Id: I9d372f1ebe9eb01a5a21374b8a2b03f7df73601f
--- drivers/vfio/vfio_iommu_type1.c | 57 ++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 24 deletions(-)drivers/vfio/vfio_iommu_type1.c +27
-24@@ -752,11 +752,24 @@ static void vfio_test_domain_fgsp(struct vfio_domain *domain)__free_pages (pages, order); } +static struct vfio_group *find_iommu_group (struct vfio_domain *domain, +struct iommu_group *iommu_group) +{ +struct vfio_group *g; + +list_for_each_entry (g, &domain->group_list, next) { +if (g->iommu_group == iommu_group) +return g; + } + +return NULL ; +} +static int vfio_iommu_type1_attach_group (void *iommu_data,struct iommu_group *iommu_group) {struct vfio_iommu *iommu = iommu_data; -struct vfio_group *group, *g; +struct vfio_group *group;struct vfio_domain *domain, *d;struct bus_type *bus =NULL ;int ret;@@ -764,10 +777,7 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,mutex_lock (&iommu->lock);list_for_each_entry (d, &iommu->domain_list, next) { -list_for_each_entry (g, &d->group_list, next) { -if (g->iommu_group != iommu_group) -continue ; - +if (find_iommu_group (d, iommu_group)) {mutex_unlock (&iommu->lock);return -EINVAL ; }@@ -887,27 +897,26 @@ static void vfio_iommu_type1_detach_group(void *iommu_data,mutex_lock (&iommu->lock);list_for_each_entry (domain, &iommu->domain_list, next) { -list_for_each_entry (group, &domain->group_list, next) { -if (group->iommu_group != iommu_group) -continue ; + group =find_iommu_group (domain, iommu_group); +if (!group) +continue ; -iommu_detach_group (domain->domain, iommu_group); -list_del (&group->next); -kfree (group); -/* -* Group ownership provides privilege, if the group -* list is empty, the domain goes away. If it's the -* last domain, then all the mappings go away too. -*/ -if (list_empty (&domain->group_list)) { -if (list_is_singular (&iommu->domain_list)) -vfio_iommu_unmap_unpin_all (iommu); -iommu_domain_free (domain->domain); -list_del (&domain->next); -kfree (domain); - } - goto done; +iommu_detach_group (domain->domain, iommu_group); +list_del (&group->next); +kfree (group); +/* +* Group ownership provides privilege, if the group +* list is empty, the domain goes away. If it's the +* last domain, then all the mappings go away too. +*/ +if (list_empty (&domain->group_list)) {
drivers/vfio/vfio_iommu_type1.c static void vfio_iommu_type1_detach_group(void *iommu_data, · line 922
Quoted 10 lines
drivers/vfio/vfio_iommu_type1.c +6
-0+if (list_is_singular (&iommu->domain_list)) +vfio_iommu_unmap_unpin_all (iommu); +iommu_domain_free (domain->domain); +list_del (&domain->next); +kfree (domain); } + goto done; } done:
Eric
Kirti Wankhede
maintainerRe: [PATCH v14 08/22] vfio iommu type1: Add find_iommu_group() function
Hi Eric,
Thanks for your reviews.
Alex had already pulled this series into his next branch for v4.10.
http://www.mail-archive.com/[email protected]/msg1274745.html
Thanks,
Kirti
Quoted 107 lines · Auger Eric
Hi,
Quoted 91 lines · Kirti Wankhede
Add
find_iommu_group()Signed-off-by Kirti Wankhede <[email protected]>Signed-off-by Neo Jia <[email protected]>Reviewed-by Jike Song <[email protected]>Reviewed-by Dong Jia Shi <[email protected]>Change-Id: I9d372f1ebe9eb01a5a21374b8a2b03f7df73601f
--- drivers/vfio/vfio_iommu_type1.c | 57 ++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 24 deletions(-)drivers/vfio/vfio_iommu_type1.c +27
-24@@ -752,11 +752,24 @@ static void vfio_test_domain_fgsp(struct vfio_domain *domain)__free_pages (pages, order); } +static struct vfio_group *find_iommu_group (struct vfio_domain *domain, +struct iommu_group *iommu_group) +{ +struct vfio_group *g; + +list_for_each_entry (g, &domain->group_list, next) { +if (g->iommu_group == iommu_group) +return g; + } + +return NULL ; +} +static int vfio_iommu_type1_attach_group (void *iommu_data,struct iommu_group *iommu_group) {struct vfio_iommu *iommu = iommu_data; -struct vfio_group *group, *g; +struct vfio_group *group;struct vfio_domain *domain, *d;struct bus_type *bus =NULL ;int ret;@@ -764,10 +777,7 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,mutex_lock (&iommu->lock);list_for_each_entry (d, &iommu->domain_list, next) { -list_for_each_entry (g, &d->group_list, next) { -if (g->iommu_group != iommu_group) -continue ; - +if (find_iommu_group (d, iommu_group)) {mutex_unlock (&iommu->lock);return -EINVAL ; }@@ -887,27 +897,26 @@ static void vfio_iommu_type1_detach_group(void *iommu_data,mutex_lock (&iommu->lock);list_for_each_entry (domain, &iommu->domain_list, next) { -list_for_each_entry (group, &domain->group_list, next) { -if (group->iommu_group != iommu_group) -continue ; + group =find_iommu_group (domain, iommu_group); +if (!group) +continue ; -iommu_detach_group (domain->domain, iommu_group); -list_del (&group->next); -kfree (group); -/* -* Group ownership provides privilege, if the group -* list is empty, the domain goes away. If it's the -* last domain, then all the mappings go away too. -*/ -if (list_empty (&domain->group_list)) { -if (list_is_singular (&iommu->domain_list)) -vfio_iommu_unmap_unpin_all (iommu); -iommu_domain_free (domain->domain); -list_del (&domain->next); -kfree (domain); - } - goto done; +iommu_detach_group (domain->domain, iommu_group); +list_del (&group->next); +kfree (group); +/* +* Group ownership provides privilege, if the group +* list is empty, the domain goes away. If it's the +* last domain, then all the mappings go away too. +*/ +if (list_empty (&domain->group_list)) {drivers/vfio/vfio_iommu_type1.c static void vfio_iommu_type1_detach_group(void *iommu_data, · line 922
Quoted 10 lines
drivers/vfio/vfio_iommu_type1.c +6
-0+if (list_is_singular (&iommu->domain_list)) +vfio_iommu_unmap_unpin_all (iommu); +iommu_domain_free (domain->domain); +list_del (&domain->next); +kfree (domain); } + goto done; } done:Reviewed-by Eric Auger <[email protected]>Eric
Auger Eric
maintainerRe: [PATCH v14 08/22] vfio iommu type1: Add find_iommu_group() function
Hi Kirti,
Quoted 7 lines · Kirti Wankhede
Hi Eric,
Thanks for your reviews.
Alex had already pulled this series into his next branch for v4.10.http://www.mail-archive.com/[email protected]/msg1274745.html
Yes I am showing up too late and noticed that later :-(
Anyway I needed (and still need) to look at it.
Thanks
Eric
Quoted 112 lines
Thanks,
KirtiQuoted 107 lines · Auger Eric
Hi,
Quoted 91 lines · Kirti Wankhede
Add
find_iommu_group()Signed-off-by Kirti Wankhede <[email protected]>Signed-off-by Neo Jia <[email protected]>Reviewed-by Jike Song <[email protected]>Reviewed-by Dong Jia Shi <[email protected]>Change-Id: I9d372f1ebe9eb01a5a21374b8a2b03f7df73601f
--- drivers/vfio/vfio_iommu_type1.c | 57 ++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 24 deletions(-)drivers/vfio/vfio_iommu_type1.c +27
-24@@ -752,11 +752,24 @@ static void vfio_test_domain_fgsp(struct vfio_domain *domain)__free_pages (pages, order); } +static struct vfio_group *find_iommu_group (struct vfio_domain *domain, +struct iommu_group *iommu_group) +{ +struct vfio_group *g; + +list_for_each_entry (g, &domain->group_list, next) { +if (g->iommu_group == iommu_group) +return g; + } + +return NULL ; +} +static int vfio_iommu_type1_attach_group (void *iommu_data,struct iommu_group *iommu_group) {struct vfio_iommu *iommu = iommu_data; -struct vfio_group *group, *g; +struct vfio_group *group;struct vfio_domain *domain, *d;struct bus_type *bus =NULL ;int ret;@@ -764,10 +777,7 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,mutex_lock (&iommu->lock);list_for_each_entry (d, &iommu->domain_list, next) { -list_for_each_entry (g, &d->group_list, next) { -if (g->iommu_group != iommu_group) -continue ; - +if (find_iommu_group (d, iommu_group)) {mutex_unlock (&iommu->lock);return -EINVAL ; }@@ -887,27 +897,26 @@ static void vfio_iommu_type1_detach_group(void *iommu_data,mutex_lock (&iommu->lock);list_for_each_entry (domain, &iommu->domain_list, next) { -list_for_each_entry (group, &domain->group_list, next) { -if (group->iommu_group != iommu_group) -continue ; + group =find_iommu_group (domain, iommu_group); +if (!group) +continue ; -iommu_detach_group (domain->domain, iommu_group); -list_del (&group->next); -kfree (group); -/* -* Group ownership provides privilege, if the group -* list is empty, the domain goes away. If it's the -* last domain, then all the mappings go away too. -*/ -if (list_empty (&domain->group_list)) { -if (list_is_singular (&iommu->domain_list)) -vfio_iommu_unmap_unpin_all (iommu); -iommu_domain_free (domain->domain); -list_del (&domain->next); -kfree (domain); - } - goto done; +iommu_detach_group (domain->domain, iommu_group); +list_del (&group->next); +kfree (group); +/* +* Group ownership provides privilege, if the group +* list is empty, the domain goes away. If it's the +* last domain, then all the mappings go away too. +*/ +if (list_empty (&domain->group_list)) {drivers/vfio/vfio_iommu_type1.c static void vfio_iommu_type1_detach_group(void *iommu_data, · line 922
Quoted 10 lines
drivers/vfio/vfio_iommu_type1.c +6
-0+if (list_is_singular (&iommu->domain_list)) +vfio_iommu_unmap_unpin_all (iommu); +iommu_domain_free (domain->domain); +list_del (&domain->next); +kfree (domain); } + goto done; } done:Reviewed-by Eric Auger <[email protected]>Eric
Kirti Wankhede
maintainerPATCH v14 9/22 vfio iommu type1: Add task structure to vfio_dma
In reply to Kirti WankhedeAdd task structure to vfio_dma structure. Task structure is used for:
- During DMA_UNMAP, same task who mapped it or other task who shares same address space is allowed to unmap, otherwise unmap fails. QEMU maps few iova ranges initially, then fork threads and from the child thread calls DMA_UNMAP on previously mapped iova. Since child shares same address space, DMA_UNMAP is successful.
- Avoid accessing struct mm while process is exiting by acquiring reference of task's mm during page accounting.
- It is also used to get task mlock capability and rlimit for mlock.
Change-Id: I7600f1bea6b384fd589fa72421ccf031bcfd9ac5
--- drivers/vfio/vfio_iommu_type1.c | 137 +++++++++++++++++++++++++--------------- 1 file changed, 86 insertions(+), 51 deletions(-)
drivers/vfio/vfio_iommu_type1.c +86 -51
@@ -36,6 +36,7 @@#include <linux/uaccess.h> #include <linux/vfio.h> #include <linux/workqueue.h> +#include <linux/pid_namespace.h> #define DRIVER_VERSION "0.2"#define DRIVER_AUTHOR "Alex Williamson <[email protected]>"
@@ -75,6 +76,7 @@ struct vfio_dma {unsigned long vaddr;/* Process virtual addr */ size_t size;/* Map size (bytes) */ int prot;/* IOMMU_READ/WRITE */ +struct task_struct *task; };struct vfio_group {
@@ -277,41 +279,47 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr,* the iommu can only map chunks of consecutive pfns anyway, so get the * first page and all consecutive pages with the same locking. */ -static long vfio_pin_pages_remote (unsigned long vaddr,long npage, -int prot,unsigned long *pfn_base) +static long vfio_pin_pages_remote (struct vfio_dma *dma,unsigned long vaddr, +long npage,int prot,unsigned long *pfn_base) { -unsigned long limit =rlimit (RLIMIT_MEMLOCK ) >>PAGE_SHIFT ; -bool lock_cap =capable (CAP_IPC_LOCK ); +unsigned long limit; +bool lock_cap =ns_capable (task_active_pid_ns (dma->task)->user_ns, +CAP_IPC_LOCK ); +struct mm_struct *mm;long ret, i;bool rsvd; -if (!current->mm) + mm =get_task_mm (dma->task); +if (!mm)return -ENODEV ; - ret =vaddr_get_pfn (current->mm, vaddr, prot, pfn_base); + ret =vaddr_get_pfn (mm, vaddr, prot, pfn_base);if (ret) -return ret; + goto pin_pg_remote_exit; rsvd =is_invalid_reserved_pfn (*pfn_base); + limit =task_rlimit (dma->task,RLIMIT_MEMLOCK ) >>PAGE_SHIFT ; -if (!rsvd && !lock_cap && current->mm->locked_vm +1 > limit) { +if (!rsvd && !lock_cap && mm->locked_vm +1 > limit) {put_pfn (*pfn_base, prot);pr_warn ("%s: RLIMIT_MEMLOCK (%ld) exceeded\n" , __func__, limit <<PAGE_SHIFT ); -return -ENOMEM ; + ret = -ENOMEM ; + goto pin_pg_remote_exit; }if (unlikely (disable_hugepages)) {if (!rsvd) -vfio_lock_acct (current,1 ); -return 1 ; +vfio_lock_acct (dma->task,1 ); + ret =1 ; + goto pin_pg_remote_exit; }/* Lock all the consecutive pages from pfn_base */ for (i =1 , vaddr +=PAGE_SIZE ; i < npage; i++, vaddr +=PAGE_SIZE ) {unsigned long pfn =0 ; - ret =vaddr_get_pfn (current->mm, vaddr, prot, &pfn); + ret =vaddr_get_pfn (mm, vaddr, prot, &pfn);if (ret)break ;
@@ -321,8 +329,7 @@ static long vfio_pin_pages_remote(unsigned long vaddr, long npage,break ; } -if (!rsvd && !lock_cap && - current->mm->locked_vm + i +1 > limit) { +if (!rsvd && !lock_cap && mm->locked_vm + i +1 > limit) {put_pfn (pfn, prot);pr_warn ("%s: RLIMIT_MEMLOCK (%ld) exceeded\n" , __func__, limit <<PAGE_SHIFT );
@@ -331,13 +338,16 @@ static long vfio_pin_pages_remote(unsigned long vaddr, long npage, }if (!rsvd) -vfio_lock_acct (current, i); +vfio_lock_acct (dma->task, i); + ret = i; -return i; +pin_pg_remote_exit: +mmput (mm); +return ret; } -static long vfio_unpin_pages_remote (unsigned long pfn,long npage, -int prot,bool do_accounting) +static long vfio_unpin_pages_remote (struct vfio_dma *dma,unsigned long pfn, +long npage,int prot,bool do_accounting) {unsigned long unlocked =0 ;long i;
@@ -346,7 +356,7 @@ static long vfio_unpin_pages_remote(unsigned long pfn, long npage, unlocked +=put_pfn (pfn++, prot);if (do_accounting) -vfio_lock_acct (current, -unlocked); +vfio_lock_acct (dma->task, -unlocked);return unlocked; }
@@ -400,7 +410,7 @@ static void vfio_unmap_unpin(struct vfio_iommu *iommu, struct vfio_dma *dma)if (WARN_ON (!unmapped))break ; - unlocked +=vfio_unpin_pages_remote (phys >>PAGE_SHIFT , + unlocked +=vfio_unpin_pages_remote (dma, phys >>PAGE_SHIFT , unmapped >>PAGE_SHIFT , dma->prot, false); iova += unmapped;
@@ -408,13 +418,14 @@ static void vfio_unmap_unpin(struct vfio_iommu *iommu, struct vfio_dma *dma)cond_resched (); } -vfio_lock_acct (current, -unlocked); +vfio_lock_acct (dma->task, -unlocked); }static void vfio_remove_dma (struct vfio_iommu *iommu,struct vfio_dma *dma) {vfio_unmap_unpin (iommu, dma);vfio_unlink_dma (iommu, dma); +put_task_struct (dma->task);kfree (dma); }
@@ -510,6 +521,12 @@ static int vfio_dma_do_unmap(struct vfio_iommu *iommu,while ((dma =vfio_find_dma (iommu, unmap->iova, unmap->size))) {if (!iommu->v2 && unmap->iova > dma->iova)break ; +/* +* Task with same address space who mapped this iova range is +* allowed to unmap the iova range. +*/ +if (dma->task->mm != current->mm) +break ; unmapped += dma->size;vfio_remove_dma (iommu, dma); }
@@ -576,17 +593,55 @@ unwind:return ret; } +static int vfio_pin_map_dma (struct vfio_iommu *iommu,struct vfio_dma *dma, +size_t map_size) +{ +dma_addr_t iova = dma->iova; +unsigned long vaddr = dma->vaddr; +size_t size = map_size; +long npage; +unsigned long pfn; +int ret =0 ; + +while (size) { +/* Pin a contiguous chunk of memory */ + npage =vfio_pin_pages_remote (dma, vaddr + dma->size, + size >>PAGE_SHIFT , dma->prot, + &pfn); +if (npage <=0 ) { +WARN_ON (!npage); + ret = (int )npage; +break ; + } + +/* Map it! */ + ret =vfio_iommu_map (iommu, iova + dma->size, pfn, npage, + dma->prot); +if (ret) { +vfio_unpin_pages_remote (dma, pfn, npage, + dma->prot, true); +break ; + } + + size -= npage <<PAGE_SHIFT ; + dma->size += npage <<PAGE_SHIFT ; + } + +if (ret) +vfio_remove_dma (iommu, dma); + +return ret; +} +static int vfio_dma_do_map (struct vfio_iommu *iommu,struct vfio_iommu_type1_dma_map *map) {dma_addr_t iova = map->iova;unsigned long vaddr = map->vaddr;size_t size = map->size; -long npage;int ret =0 , prot =0 ;uint64_t mask;struct vfio_dma *dma; -unsigned long pfn;/* Verify that none of our __u64 fields overflow */ if (map->size != size || map->vaddr != vaddr || map->iova != iova)
@@ -612,47 +667,27 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu,mutex_lock (&iommu->lock);if (vfio_find_dma (iommu, iova, size)) { -mutex_unlock (&iommu->lock); -return -EEXIST ; + ret = -EEXIST ; + goto out_unlock; } dma =kzalloc (sizeof (*dma),GFP_KERNEL );if (!dma) { -mutex_unlock (&iommu->lock); -return -ENOMEM ; + ret = -ENOMEM ; + goto out_unlock; } dma->iova = iova; dma->vaddr = vaddr; dma->prot = prot; +get_task_struct (current); + dma->task = current;/* Insert zero-sized and grow as we map chunks of it */ vfio_link_dma (iommu, dma); -while (size) { -/* Pin a contiguous chunk of memory */ - npage =vfio_pin_pages_remote (vaddr + dma->size, - size >>PAGE_SHIFT , prot, &pfn); -if (npage <=0 ) { -WARN_ON (!npage); - ret = (int )npage; -break ; - } - -/* Map it! */ - ret =vfio_iommu_map (iommu, iova + dma->size, pfn, npage, prot); -if (ret) { -vfio_unpin_pages_remote (pfn, npage, prot, true); -break ; - } - - size -= npage <<PAGE_SHIFT ; - dma->size += npage <<PAGE_SHIFT ; - } - -if (ret) -vfio_remove_dma (iommu, dma); - + ret =vfio_pin_map_dma (iommu, dma, size); +out_unlock:mutex_unlock (&iommu->lock);return ret; }
Signature · 1 line
2.7.0
Re: [PATCH v14 09/22] vfio iommu type1: Add task structure to vfio_dma
Quoted 10 lines · Kirti Wankhede
Add task structure to
vfio_dmastructure. Task structure is used for:
- DuringDMA_UNMAP, same task who mapped it or other task who shares same address space is allowed to unmap, otherwise unmap fails. QEMU maps few iova ranges initially, then fork threads and from the child thread callsDMA_UNMAPon previously mapped iova. Since child shares same address space,DMA_UNMAPis successful.
- Avoid accessing struct mm while process is exiting by acquiring reference of task's mm during page accounting.
- It is also used to get task mlock capability and rlimit for mlock.
Quoted 3 lines
Signed-off-by Kirti Wankhede <[email protected]>Signed-off-by Neo Jia <[email protected]>Reviewed-by Dong Jia Shi <[email protected]>
I keep whinging that @mm should be referenced, not @current but you keep referencing @current even if you only need @mm and you are not telling why
- and I am wondering what I am missing here? Something else will be used from @task later, besides just @mm?
Quoted 279 lines
Change-Id: I7600f1bea6b384fd589fa72421ccf031bcfd9ac5
--- drivers/vfio/vfio_iommu_type1.c | 137 +++++++++++++++++++++++++--------------- 1 file changed, 86 insertions(+), 51 deletions(-)drivers/vfio/vfio_iommu_type1.c +86
-51@@ -36,6 +36,7 @@#include <linux/uaccess.h> #include <linux/vfio.h> #include <linux/workqueue.h> +#include <linux/pid_namespace.h> #define DRIVER_VERSION "0.2"#define DRIVER_AUTHOR "Alex Williamson <[email protected]>"@@ -75,6 +76,7 @@ struct vfio_dma {unsigned long vaddr;/* Process virtual addr */ size_t size;/* Map size (bytes) */ int prot;/* IOMMU_READ/WRITE */ +struct task_struct *task; };struct vfio_group {@@ -277,41 +279,47 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr,* the iommu can only map chunks of consecutive pfns anyway, so get the * first page and all consecutive pages with the same locking. */ -static long vfio_pin_pages_remote (unsigned long vaddr,long npage, -int prot,unsigned long *pfn_base) +static long vfio_pin_pages_remote (struct vfio_dma *dma,unsigned long vaddr, +long npage,int prot,unsigned long *pfn_base) { -unsigned long limit =rlimit (RLIMIT_MEMLOCK ) >>PAGE_SHIFT ; -bool lock_cap =capable (CAP_IPC_LOCK ); +unsigned long limit; +bool lock_cap =ns_capable (task_active_pid_ns (dma->task)->user_ns, +CAP_IPC_LOCK ); +struct mm_struct *mm;long ret, i;bool rsvd; -if (!current->mm) + mm =get_task_mm (dma->task); +if (!mm)return -ENODEV ; - ret =vaddr_get_pfn (current->mm, vaddr, prot, pfn_base); + ret =vaddr_get_pfn (mm, vaddr, prot, pfn_base);if (ret) -return ret; + goto pin_pg_remote_exit; rsvd =is_invalid_reserved_pfn (*pfn_base); + limit =task_rlimit (dma->task,RLIMIT_MEMLOCK ) >>PAGE_SHIFT ; -if (!rsvd && !lock_cap && current->mm->locked_vm +1 > limit) { +if (!rsvd && !lock_cap && mm->locked_vm +1 > limit) {put_pfn (*pfn_base, prot);pr_warn ("%s: RLIMIT_MEMLOCK (%ld) exceeded\n" , __func__, limit <<PAGE_SHIFT ); -return -ENOMEM ; + ret = -ENOMEM ; + goto pin_pg_remote_exit; }if (unlikely (disable_hugepages)) {if (!rsvd) -vfio_lock_acct (current,1 ); -return 1 ; +vfio_lock_acct (dma->task,1 ); + ret =1 ; + goto pin_pg_remote_exit; }/* Lock all the consecutive pages from pfn_base */ for (i =1 , vaddr +=PAGE_SIZE ; i < npage; i++, vaddr +=PAGE_SIZE ) {unsigned long pfn =0 ; - ret =vaddr_get_pfn (current->mm, vaddr, prot, &pfn); + ret =vaddr_get_pfn (mm, vaddr, prot, &pfn);if (ret)break ;@@ -321,8 +329,7 @@ static long vfio_pin_pages_remote(unsigned long vaddr, long npage,break ; } -if (!rsvd && !lock_cap && - current->mm->locked_vm + i +1 > limit) { +if (!rsvd && !lock_cap && mm->locked_vm + i +1 > limit) {put_pfn (pfn, prot);pr_warn ("%s: RLIMIT_MEMLOCK (%ld) exceeded\n" , __func__, limit <<PAGE_SHIFT );@@ -331,13 +338,16 @@ static long vfio_pin_pages_remote(unsigned long vaddr, long npage, }if (!rsvd) -vfio_lock_acct (current, i); +vfio_lock_acct (dma->task, i); + ret = i; -return i; +pin_pg_remote_exit: +mmput (mm); +return ret; } -static long vfio_unpin_pages_remote (unsigned long pfn,long npage, -int prot,bool do_accounting) +static long vfio_unpin_pages_remote (struct vfio_dma *dma,unsigned long pfn, +long npage,int prot,bool do_accounting) {unsigned long unlocked =0 ;long i;@@ -346,7 +356,7 @@ static long vfio_unpin_pages_remote(unsigned long pfn, long npage, unlocked +=put_pfn (pfn++, prot);if (do_accounting) -vfio_lock_acct (current, -unlocked); +vfio_lock_acct (dma->task, -unlocked);return unlocked; }@@ -400,7 +410,7 @@ static void vfio_unmap_unpin(struct vfio_iommu *iommu, struct vfio_dma *dma)if (WARN_ON (!unmapped))break ; - unlocked +=vfio_unpin_pages_remote (phys >>PAGE_SHIFT , + unlocked +=vfio_unpin_pages_remote (dma, phys >>PAGE_SHIFT , unmapped >>PAGE_SHIFT , dma->prot, false); iova += unmapped;@@ -408,13 +418,14 @@ static void vfio_unmap_unpin(struct vfio_iommu *iommu, struct vfio_dma *dma)cond_resched (); } -vfio_lock_acct (current, -unlocked); +vfio_lock_acct (dma->task, -unlocked); }static void vfio_remove_dma (struct vfio_iommu *iommu,struct vfio_dma *dma) {vfio_unmap_unpin (iommu, dma);vfio_unlink_dma (iommu, dma); +put_task_struct (dma->task);kfree (dma); }@@ -510,6 +521,12 @@ static int vfio_dma_do_unmap(struct vfio_iommu *iommu,while ((dma =vfio_find_dma (iommu, unmap->iova, unmap->size))) {if (!iommu->v2 && unmap->iova > dma->iova)break ; +/* +* Task with same address space who mapped this iova range is +* allowed to unmap the iova range. +*/ +if (dma->task->mm != current->mm) +break ; unmapped += dma->size;vfio_remove_dma (iommu, dma); }@@ -576,17 +593,55 @@ unwind:return ret; } +static int vfio_pin_map_dma (struct vfio_iommu *iommu,struct vfio_dma *dma, +size_t map_size) +{ +dma_addr_t iova = dma->iova; +unsigned long vaddr = dma->vaddr; +size_t size = map_size; +long npage; +unsigned long pfn; +int ret =0 ; + +while (size) { +/* Pin a contiguous chunk of memory */ + npage =vfio_pin_pages_remote (dma, vaddr + dma->size, + size >>PAGE_SHIFT , dma->prot, + &pfn); +if (npage <=0 ) { +WARN_ON (!npage); + ret = (int )npage; +break ; + } + +/* Map it! */ + ret =vfio_iommu_map (iommu, iova + dma->size, pfn, npage, + dma->prot); +if (ret) { +vfio_unpin_pages_remote (dma, pfn, npage, + dma->prot, true); +break ; + } + + size -= npage <<PAGE_SHIFT ; + dma->size += npage <<PAGE_SHIFT ; + } + +if (ret) +vfio_remove_dma (iommu, dma); + +return ret; +} +static int vfio_dma_do_map (struct vfio_iommu *iommu,struct vfio_iommu_type1_dma_map *map) {dma_addr_t iova = map->iova;unsigned long vaddr = map->vaddr;size_t size = map->size; -long npage;int ret =0 , prot =0 ;uint64_t mask;struct vfio_dma *dma; -unsigned long pfn;/* Verify that none of our __u64 fields overflow */ if (map->size != size || map->vaddr != vaddr || map->iova != iova)@@ -612,47 +667,27 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu,mutex_lock (&iommu->lock);if (vfio_find_dma (iommu, iova, size)) { -mutex_unlock (&iommu->lock); -return -EEXIST ; + ret = -EEXIST ; + goto out_unlock; } dma =kzalloc (sizeof (*dma),GFP_KERNEL );if (!dma) { -mutex_unlock (&iommu->lock); -return -ENOMEM ; + ret = -ENOMEM ; + goto out_unlock; } dma->iova = iova; dma->vaddr = vaddr; dma->prot = prot; +get_task_struct (current); + dma->task = current;/* Insert zero-sized and grow as we map chunks of it */ vfio_link_dma (iommu, dma); -while (size) { -/* Pin a contiguous chunk of memory */ - npage =vfio_pin_pages_remote (vaddr + dma->size, - size >>PAGE_SHIFT , prot, &pfn); -if (npage <=0 ) { -WARN_ON (!npage); - ret = (int )npage; -break ; - } - -/* Map it! */ - ret =vfio_iommu_map (iommu, iova + dma->size, pfn, npage, prot); -if (ret) { -vfio_unpin_pages_remote (pfn, npage, prot, true); -break ; - } - - size -= npage <<PAGE_SHIFT ; - dma->size += npage <<PAGE_SHIFT ; - } - -if (ret) -vfio_remove_dma (iommu, dma); - + ret =vfio_pin_map_dma (iommu, dma, size); +out_unlock:mutex_unlock (&iommu->lock);return ret; }
Signature · 1 line
Alexey
Re: [PATCH v14 09/22] vfio iommu type1: Add task structure to vfio_dma
Quoted 16 lines · On Thu, 17 Nov 2016 16:41:14 +1100 Alexey Kardashevskiy <[email protected]> wrote:
Quoted 10 lines · Kirti Wankhede
Add task structure to
vfio_dmastructure. Task structure is used for:
- DuringDMA_UNMAP, same task who mapped it or other task who shares same address space is allowed to unmap, otherwise unmap fails. QEMU maps few iova ranges initially, then fork threads and from the child thread callsDMA_UNMAPon previously mapped iova. Since child shares same address space,DMA_UNMAPis successful.
- Avoid accessing struct mm while process is exiting by acquiring reference of task's mm during page accounting.
- It is also used to get task mlock capability and rlimit for mlock.Quoted 3 lines
Signed-off-by Kirti Wankhede <[email protected]>Signed-off-by Neo Jia <[email protected]>Reviewed-by Dong Jia Shi <[email protected]>
Quoted 4 lines
I keep whinging that @mm should be referenced, not @current but you keep referencing @current even if you only need @mm and you are not telling why
- and I am wondering what I am missing here? Something else will be used from @task later, besides just @mm?
Yes, we reference @current from vfio_dma_do_map() and this is stored on the struct vfio_dma. A reference to current is held because the external page pinning in vfio_pin_page_external() needs to test the capabilities of the task for CAP_IPC_LOCK to know whether locked memory limits are in effect for the task even when it's not @current (ie. an asynchronous call from the vendor driver regardless of what task is currently running). There are also various get_task_mm() taken temporarily when we're working with the mm of that task. Do you spot any issues with this behavior? Thanks,
Alex
Re: [PATCH v14 09/22] vfio iommu type1: Add task structure to vfio_dma
Quoted 24 lines · Alex Williamson
Quoted 16 lines · On Thu, 17 Nov 2016 16:41:14 +1100 Alexey Kardashevskiy <[email protected]> wrote:
Quoted 10 lines · Kirti Wankhede
Add task structure to
vfio_dmastructure. Task structure is used for:
- DuringDMA_UNMAP, same task who mapped it or other task who shares same address space is allowed to unmap, otherwise unmap fails. QEMU maps few iova ranges initially, then fork threads and from the child thread callsDMA_UNMAPon previously mapped iova. Since child shares same address space,DMA_UNMAPis successful.
- Avoid accessing struct mm while process is exiting by acquiring reference of task's mm during page accounting.
- It is also used to get task mlock capability and rlimit for mlock.Quoted 3 lines
Signed-off-by Kirti Wankhede <[email protected]>Signed-off-by Neo Jia <[email protected]>Reviewed-by Dong Jia Shi <[email protected]>Quoted 4 lines
I keep whinging that @mm should be referenced, not @current but you keep referencing @current even if you only need @mm and you are not telling why
- and I am wondering what I am missing here? Something else will be used from @task later, besides just @mm?
Quoted 4 lines
Yes, we reference @current from
vfio_dma_do_map()and this is stored on the structvfio_dma. A reference to current is held because the external page pinning invfio_pin_page_external()needs to test the capabilities of the task forCAP_IPC_LOCKto know whether locked memory
Ah, that's it - capable(CAP_IPC_LOCK) is checking @current, missed that.
Quoted 5 lines
limits are in effect for the task even when it's not @current (ie. an asynchronous call from the vendor driver regardless of what task is currently running). There are also various
get_task_mm()taken temporarily when we're working with the mm of that task. Do you spot any issues with this behavior? Thanks,
No, now I am fine, thanks!
Signature · 1 line
Alexey
Kirti Wankhede
maintainerRe: [PATCH v14 09/22] vfio iommu type1: Add task structure to vfio_dma
In reply to Alexey KardashevskiyQuoted 16 lines · Alexey Kardashevskiy
Quoted 10 lines · Kirti Wankhede
Add task structure to
vfio_dmastructure. Task structure is used for:
- DuringDMA_UNMAP, same task who mapped it or other task who shares same address space is allowed to unmap, otherwise unmap fails. QEMU maps few iova ranges initially, then fork threads and from the child thread callsDMA_UNMAPon previously mapped iova. Since child shares same address space,DMA_UNMAPis successful.
- Avoid accessing struct mm while process is exiting by acquiring reference of task's mm during page accounting.
- It is also used to get task mlock capability and rlimit for mlock.Quoted 3 lines
Signed-off-by Kirti Wankhede <[email protected]>Signed-off-by Neo Jia <[email protected]>Reviewed-by Dong Jia Shi <[email protected]>
Quoted 6 lines
I keep whinging that @mm should be referenced, not @current but you keep referencing @current even if you only need @mm and you are not telling why
- and I am wondering what I am missing here? Something else will be used from @task later, besides just @mm?
Hey Alexey,
I updated briefly in commit description. Let me try to explain it again in detail.
Its true we need mm, but we also need task structure for 2 reasons:
- Avoid accessing struct mm while process is exiting by acquiring reference of task's mm during page accounting.
If you see vfio_lock_acct(), where reference to mm is taken from task structure, get_task_mm(task), to make sure that mm of this task is still valid and task not in exiting process. If process is exiting, mm would be NULL and we don't have to do page accounting.
This patch is to re-org and prepare the code for next patch, 10/22. vfio_pin_pages()/ vfio_unpin_pages() for mediated devices would get called from vendor driver. Those could be initiated by other process, but for pin/unpin, these APIs should use the mm of the task who mapped it. So in these calls we should check that we get the valid reference of mm, that we would get from task structure.
- It is also used to get task mlock capability and rlimit for mlock. These are again used for page accounting and page accounting should be done with reference to the task who mapped the iova range. We get these from task structure.
Thanks,
Kirti
Kirti Wankhede
maintainerPATCH v14 10/22 vfio iommu type1: Add support for mediated devices
In reply to Kirti WankhedeVFIO IOMMU drivers are designed for the devices which are IOMMU capable. Mediated device only uses IOMMU APIs, the underlying hardware can be managed by an IOMMU domain.
Aim of this change is:
- To use most of the code of TYPE1 IOMMU driver for mediated devices
- To support direct assigned device and mediated device in single module
This change adds pin and unpin support for mediated device to TYPE1 IOMMU backend module. More details:
- Domain for external user is tracked separately in vfio_iommu structure. It is allocated when group for first mdev device is attached.
- Pages pinned for external domain are tracked in each vfio_dma structure for that iova range.
- Page tracking rb-tree in vfio_dma keeps <iova, pfn, ref_count>. Key of rb-tree is iova, but it actually aims to track pfns.
- On external pin request for an iova, page is pinned once, if iova is already pinned and tracked, ref_count is incremented.
- External unpin request unpins pages only when ref_count is 0.
- Pinned pages list is used to find pfn from iova and then unpin it. WARN_ON is added if there are entires in pfn_list while detaching the group and releasing the domain.
- Page accounting is updated to account in its address space where the pages are pinned/unpinned, i.e dma->task
- Accouting for mdev device is only done if there is no iommu capable domain in the container. When there is a direct device assigned to the container and that domain is iommu capable, all pages are already pinned during DMA_MAP.
- Page accouting is updated on hot plug and unplug mdev device and pass through device.
Tested by assigning below combinations of devices to a single VM:
- GPU pass through only
- vGPU device only
- One GPU pass through and one vGPU device
- Linux VM hot plug and unplug vGPU device while GPU pass through device exist
- Linux VM hot plug and unplug GPU pass through device while vGPU device exist
--- drivers/vfio/vfio_iommu_type1.c | 621 ++++++++++++++++++++++++++++++++++------ 1 file changed, 537 insertions(+), 84 deletions(-)
drivers/vfio/vfio_iommu_type1.c +537 -84
@@ -37,6 +37,7 @@#include <linux/vfio.h> #include <linux/workqueue.h> #include <linux/pid_namespace.h> +#include <linux/mdev.h> #define DRIVER_VERSION "0.2"#define DRIVER_AUTHOR "Alex Williamson <[email protected]>"
@@ -56,6 +57,7 @@ MODULE_PARM_DESC(disable_hugepages,struct vfio_iommu {struct list_head domain_list; +struct vfio_domain *external_domain;/* domain for external user */ struct mutex lock;struct rb_root dma_list;bool v2;
@@ -76,7 +78,9 @@ struct vfio_dma {unsigned long vaddr;/* Process virtual addr */ size_t size;/* Map size (bytes) */ int prot;/* IOMMU_READ/WRITE */ +bool iommu_mapped;struct task_struct *task; +struct rb_root pfn_list;/* Ex-user pinned pfn list */ };struct vfio_group {
@@ -85,6 +89,21 @@ struct vfio_group { };/* +* Guest RAM pinning working set or DMA target +*/ +struct vfio_pfn { +struct rb_node node; +dma_addr_t iova;/* Device address */ +unsigned long pfn;/* Host pfn */ +atomic_t ref_count; +}; + +#define IS_IOMMU_CAP_DOMAIN_IN_CONTAINER (iommu) \ + (!list_empty(&iommu->domain_list)) + +static int put_pfn (unsigned long pfn,int prot); + +/* * This code handles mapping and unmapping of user data buffers * into DMA'ble space using the IOMMU */
@@ -132,6 +151,97 @@ static void vfio_unlink_dma(struct vfio_iommu *iommu, struct vfio_dma *old)rb_erase (&old->node, &iommu->dma_list); } +/* +* Helper Functions for host iova-pfn list +*/ +static struct vfio_pfn *vfio_find_vpfn (struct vfio_dma *dma,dma_addr_t iova) +{ +struct vfio_pfn *vpfn; +struct rb_node *node = dma->pfn_list.rb_node; + +while (node) { + vpfn = rb_entry(node, struct vfio_pfn, node); + +if (iova < vpfn->iova) + node = node->rb_left; +else if (iova > vpfn->iova) + node = node->rb_right; +else +return vpfn; + } +return NULL ; +} + +static void vfio_link_pfn (struct vfio_dma *dma, +struct vfio_pfn *new) +{ +struct rb_node **link, *parent =NULL ; +struct vfio_pfn *vpfn; + + link = &dma->pfn_list.rb_node; +while (*link) { + parent = *link; + vpfn = rb_entry(parent, struct vfio_pfn, node); + +if (new->iova < vpfn->iova) + link = &(*link)->rb_left; +else + link = &(*link)->rb_right; + } + +rb_link_node (&new->node, parent, link); +rb_insert_color (&new->node, &dma->pfn_list); +} + +static void vfio_unlink_pfn (struct vfio_dma *dma,struct vfio_pfn *old) +{ +rb_erase (&old->node, &dma->pfn_list); +} + +static int vfio_add_to_pfn_list (struct vfio_dma *dma,dma_addr_t iova, +unsigned long pfn) +{ +struct vfio_pfn *vpfn; + + vpfn =kzalloc (sizeof (*vpfn),GFP_KERNEL ); +if (!vpfn) +return -ENOMEM ; + + vpfn->iova = iova; + vpfn->pfn = pfn; +atomic_set (&vpfn->ref_count,1 ); +vfio_link_pfn (dma, vpfn); +return 0 ; +} + +static void vfio_remove_from_pfn_list (struct vfio_dma *dma, +struct vfio_pfn *vpfn) +{ +vfio_unlink_pfn (dma, vpfn); +kfree (vpfn); +} + +static struct vfio_pfn *vfio_iova_get_vfio_pfn (struct vfio_dma *dma, +unsigned long iova) +{ +struct vfio_pfn *vpfn =vfio_find_vpfn (dma, iova); + +if (vpfn) +atomic_inc (&vpfn->ref_count); +return vpfn; +} + +static int vfio_iova_put_vfio_pfn (struct vfio_dma *dma,struct vfio_pfn *vpfn) +{ +int ret =0 ; + +if (atomic_dec_and_test (&vpfn->ref_count)) { + ret =put_pfn (vpfn->pfn, dma->prot); +vfio_remove_from_pfn_list (dma, vpfn); + } +return ret; +} +struct vwork {struct mm_struct *mm;long npage;
@@ -270,7 +380,6 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr, }up_read (&mm->mmap_sem); -return ret; }
@@ -280,65 +389,74 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr,* first page and all consecutive pages with the same locking. */ static long vfio_pin_pages_remote (struct vfio_dma *dma,unsigned long vaddr, -long npage,int prot,unsigned long *pfn_base) +long npage,unsigned long *pfn_base) {unsigned long limit;bool lock_cap =ns_capable (task_active_pid_ns (dma->task)->user_ns,CAP_IPC_LOCK );struct mm_struct *mm; -long ret, i; +long ret, i =0 , lock_acct =0 ;bool rsvd; +dma_addr_t iova = vaddr - dma->vaddr + dma->iova; mm =get_task_mm (dma->task);if (!mm)return -ENODEV ; - ret =vaddr_get_pfn (mm, vaddr, prot, pfn_base); + ret =vaddr_get_pfn (mm, vaddr, dma->prot, pfn_base);if (ret) goto pin_pg_remote_exit; rsvd =is_invalid_reserved_pfn (*pfn_base); limit =task_rlimit (dma->task,RLIMIT_MEMLOCK ) >>PAGE_SHIFT ; -if (!rsvd && !lock_cap && mm->locked_vm +1 > limit) { -put_pfn (*pfn_base, prot); -pr_warn ("%s: RLIMIT_MEMLOCK (%ld) exceeded\n" , __func__, - limit <<PAGE_SHIFT ); - ret = -ENOMEM ; - goto pin_pg_remote_exit; - } - -if (unlikely (disable_hugepages)) { -if (!rsvd) -vfio_lock_acct (dma->task,1 ); - ret =1 ; - goto pin_pg_remote_exit; +/* +* Reserved pages aren't counted against the user, externally pinned +* pages are already counted against the user. +*/ +if (!rsvd && !vfio_find_vpfn (dma, iova)) { +if (!lock_cap && mm->locked_vm +1 > limit) { +put_pfn (*pfn_base, dma->prot); +pr_warn ("%s: RLIMIT_MEMLOCK (%ld) exceeded\n" , __func__, + limit <<PAGE_SHIFT ); + ret = -ENOMEM ; + goto pin_pg_remote_exit; + } + lock_acct++; } -/* Lock all the consecutive pages from pfn_base */ -for (i =1 , vaddr +=PAGE_SIZE ; i < npage; i++, vaddr +=PAGE_SIZE ) { -unsigned long pfn =0 ; + i++; +if (likely (!disable_hugepages)) { +/* Lock all the consecutive pages from pfn_base */ +for (vaddr +=PAGE_SIZE , iova +=PAGE_SIZE ; i < npage; + i++, vaddr +=PAGE_SIZE , iova +=PAGE_SIZE ) { +unsigned long pfn =0 ; - ret =vaddr_get_pfn (mm, vaddr, prot, &pfn); -if (ret) -break ; + ret =vaddr_get_pfn (mm, vaddr, dma->prot, &pfn); +if (ret) +break ; -if (pfn != *pfn_base + i || - rsvd !=is_invalid_reserved_pfn (pfn)) { -put_pfn (pfn, prot); -break ; - } +if (pfn != *pfn_base + i || + rsvd !=is_invalid_reserved_pfn (pfn)) { +put_pfn (pfn, dma->prot); +break ; + } -if (!rsvd && !lock_cap && mm->locked_vm + i +1 > limit) { -put_pfn (pfn, prot); -pr_warn ("%s: RLIMIT_MEMLOCK (%ld) exceeded\n" , - __func__, limit <<PAGE_SHIFT ); -break ; +if (!rsvd && !vfio_find_vpfn (dma, iova)) { +if (!lock_cap && + mm->locked_vm + lock_acct +1 > limit) { +put_pfn (pfn, dma->prot); +pr_warn ("%s: RLIMIT_MEMLOCK (%ld) " +"exceeded\n" , __func__, + limit <<PAGE_SHIFT ); +break ; + } + lock_acct++; + } } } -if (!rsvd) -vfio_lock_acct (dma->task, i); +vfio_lock_acct (dma->task, lock_acct); ret = i; pin_pg_remote_exit:
@@ -346,14 +464,76 @@ pin_pg_remote_exit:return ret; } -static long vfio_unpin_pages_remote (struct vfio_dma *dma,unsigned long pfn, -long npage,int prot,bool do_accounting) +static long vfio_unpin_pages_remote (struct vfio_dma *dma,dma_addr_t iova, +unsigned long pfn,long npage, +bool do_accounting) { -unsigned long unlocked =0 ; +long unlocked =0 , locked =0 ;long i; -for (i =0 ; i < npage; i++) - unlocked +=put_pfn (pfn++, prot); +for (i =0 ; i < npage; i++) { +if (put_pfn (pfn++, dma->prot)) { + unlocked++; +if (vfio_find_vpfn (dma, iova + (i <<PAGE_SHIFT ))) + locked++; + } + } + +if (do_accounting) +vfio_lock_acct (dma->task, locked - unlocked); + +return unlocked; +} + +static int vfio_pin_page_external (struct vfio_dma *dma,unsigned long vaddr, +unsigned long *pfn_base,bool do_accounting) +{ +unsigned long limit; +bool lock_cap =ns_capable (task_active_pid_ns (dma->task)->user_ns, +CAP_IPC_LOCK ); +struct mm_struct *mm; +int ret; +bool rsvd; + + mm =get_task_mm (dma->task); +if (!mm) +return -ENODEV ; + + ret =vaddr_get_pfn (mm, vaddr, dma->prot, pfn_base); +if (ret) + goto pin_page_exit; + + rsvd =is_invalid_reserved_pfn (*pfn_base); + limit =task_rlimit (dma->task,RLIMIT_MEMLOCK ) >>PAGE_SHIFT ; + +if (!rsvd && !lock_cap && mm->locked_vm +1 > limit) { +put_pfn (*pfn_base, dma->prot); +pr_warn ("%s: Task %s (%d) RLIMIT_MEMLOCK (%ld) exceeded\n" , + __func__, dma->task->comm,task_pid_nr (dma->task), + limit <<PAGE_SHIFT ); + ret = -ENOMEM ; + goto pin_page_exit; + } + +if (!rsvd && do_accounting) +vfio_lock_acct (dma->task,1 ); + ret =1 ; + +pin_page_exit: +mmput (mm); +return ret; +} + +static int vfio_unpin_page_external (struct vfio_dma *dma,dma_addr_t iova, +bool do_accounting) +{ +int unlocked; +struct vfio_pfn *vpfn =vfio_find_vpfn (dma, iova); + +if (!vpfn) +return 0 ; + + unlocked =vfio_iova_put_vfio_pfn (dma, vpfn);if (do_accounting)vfio_lock_acct (dma->task, -unlocked);
@@ -361,14 +541,145 @@ static long vfio_unpin_pages_remote(struct vfio_dma *dma, unsigned long pfn,return unlocked; } -static void vfio_unmap_unpin (struct vfio_iommu *iommu,struct vfio_dma *dma) +static int vfio_iommu_type1_pin_pages (void *iommu_data, +unsigned long *user_pfn, +int npage,int prot, +unsigned long *phys_pfn) +{ +struct vfio_iommu *iommu = iommu_data; +int i, j, ret; +unsigned long remote_vaddr; +struct vfio_dma *dma; +bool do_accounting; + +if (!iommu || !user_pfn || !phys_pfn) +return -EINVAL ; + +/* Supported for v2 version only */ +if (!iommu->v2) +return -EACCES ; + +mutex_lock (&iommu->lock); + +if (!iommu->external_domain) { + ret = -EINVAL ; + goto pin_done; + } + +/* +* If iommu capable domain exist in the container then all pages are +* already pinned and accounted. Accouting should be done if there is no +* iommu capable domain in the container. +*/ + do_accounting = !IS_IOMMU_CAP_DOMAIN_IN_CONTAINER (iommu); + +for (i =0 ; i < npage; i++) { +dma_addr_t iova; +struct vfio_pfn *vpfn; + + iova = user_pfn[i] <<PAGE_SHIFT ; + dma =vfio_find_dma (iommu, iova,0 ); +if (!dma) { + ret = -EINVAL ; + goto pin_unwind; + } + +if ((dma->prot & prot) != prot) { + ret = -EPERM ; + goto pin_unwind; + } + + vpfn =vfio_iova_get_vfio_pfn (dma, iova); +if (vpfn) { + phys_pfn[i] = vpfn->pfn; +continue ; + } + + remote_vaddr = dma->vaddr + iova - dma->iova; + ret =vfio_pin_page_external (dma, remote_vaddr, &phys_pfn[i], + do_accounting); +if (ret <=0 ) { +WARN_ON (!ret); + goto pin_unwind; + } + + ret =vfio_add_to_pfn_list (dma, iova, phys_pfn[i]); +if (ret) { +vfio_unpin_page_external (dma, iova, do_accounting); + goto pin_unwind; + } + } + + ret = i; + goto pin_done; + +pin_unwind: + phys_pfn[i] =0 ; +for (j =0 ; j < i; j++) { +dma_addr_t iova; + + iova = user_pfn[j] <<PAGE_SHIFT ; + dma =vfio_find_dma (iommu, iova,0 ); +vfio_unpin_page_external (dma, iova, do_accounting); + phys_pfn[j] =0 ; + } +pin_done: +mutex_unlock (&iommu->lock); +return ret; +} + +static int vfio_iommu_type1_unpin_pages (void *iommu_data, +unsigned long *user_pfn, +int npage) +{ +struct vfio_iommu *iommu = iommu_data; +bool do_accounting; +int i; + +if (!iommu || !user_pfn) +return -EINVAL ; + +/* Supported for v2 version only */ +if (!iommu->v2) +return -EACCES ; + +mutex_lock (&iommu->lock); + +if (!iommu->external_domain) { +mutex_unlock (&iommu->lock); +return -EINVAL ; + } + + do_accounting = !IS_IOMMU_CAP_DOMAIN_IN_CONTAINER (iommu); +for (i =0 ; i < npage; i++) { +struct vfio_dma *dma; +dma_addr_t iova; + + iova = user_pfn[i] <<PAGE_SHIFT ; + dma =vfio_find_dma (iommu, iova,0 ); +if (!dma) + goto unpin_exit; +vfio_unpin_page_external (dma, iova, do_accounting); + } + +unpin_exit: +mutex_unlock (&iommu->lock); +return i > npage ? npage : (i >0 ? i : -EINVAL ); +} + +static long vfio_unmap_unpin (struct vfio_iommu *iommu,struct vfio_dma *dma, +bool do_accounting) {dma_addr_t iova = dma->iova, end = dma->iova + dma->size;struct vfio_domain *domain, *d;long unlocked =0 ;if (!dma->size) -return ; +return 0 ; + +if (!IS_IOMMU_CAP_DOMAIN_IN_CONTAINER (iommu)) +return 0 ; +/* * We use the IOMMU to track the physical addresses, otherwise we'd * need a much more complicated tracking system. Unfortunately that
@@ -410,20 +721,26 @@ static void vfio_unmap_unpin(struct vfio_iommu *iommu, struct vfio_dma *dma)if (WARN_ON (!unmapped))break ; - unlocked +=vfio_unpin_pages_remote (dma, phys >>PAGE_SHIFT , + unlocked +=vfio_unpin_pages_remote (dma, iova, + phys >>PAGE_SHIFT , unmapped >>PAGE_SHIFT , - dma->prot, false); + false); iova += unmapped;cond_resched (); } -vfio_lock_acct (dma->task, -unlocked); + dma->iommu_mapped = false; +if (do_accounting) { +vfio_lock_acct (dma->task, -unlocked); +return 0 ; + } +return unlocked; }static void vfio_remove_dma (struct vfio_iommu *iommu,struct vfio_dma *dma) { -vfio_unmap_unpin (iommu, dma); +vfio_unmap_unpin (iommu, dma, true);vfio_unlink_dma (iommu, dma);put_task_struct (dma->task);kfree (dma);
@@ -606,8 +923,7 @@ static int vfio_pin_map_dma(struct vfio_iommu *iommu, struct vfio_dma *dma,while (size) {/* Pin a contiguous chunk of memory */ npage =vfio_pin_pages_remote (dma, vaddr + dma->size, - size >>PAGE_SHIFT , dma->prot, - &pfn); + size >>PAGE_SHIFT , &pfn);if (npage <=0 ) {WARN_ON (!npage); ret = (int )npage;
@@ -618,8 +934,8 @@ static int vfio_pin_map_dma(struct vfio_iommu *iommu, struct vfio_dma *dma, ret =vfio_iommu_map (iommu, iova + dma->size, pfn, npage, dma->prot);if (ret) { -vfio_unpin_pages_remote (dma, pfn, npage, - dma->prot, true); +vfio_unpin_pages_remote (dma, iova + dma->size, pfn, + npage, true);break ; }
@@ -627,6 +943,8 @@ static int vfio_pin_map_dma(struct vfio_iommu *iommu, struct vfio_dma *dma, dma->size += npage <<PAGE_SHIFT ; } + dma->iommu_mapped = true; +if (ret)vfio_remove_dma (iommu, dma);
@@ -682,11 +1000,17 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu, dma->prot = prot;get_task_struct (current); dma->task = current; + dma->pfn_list =RB_ROOT ;/* Insert zero-sized and grow as we map chunks of it */ vfio_link_dma (iommu, dma); - ret =vfio_pin_map_dma (iommu, dma, size); +/* Don't pin and map if container doesn't contain IOMMU capable domain*/ +if (!IS_IOMMU_CAP_DOMAIN_IN_CONTAINER (iommu)) + dma->size = size; +else + ret =vfio_pin_map_dma (iommu, dma, size); + out_unlock:mutex_unlock (&iommu->lock);return ret;
@@ -715,10 +1039,6 @@ static int vfio_iommu_replay(struct vfio_iommu *iommu, d = list_first_entry(&iommu->domain_list, struct vfio_domain, next); n =rb_first (&iommu->dma_list); -/* If there's not a domain, there better not be any mappings */ -if (WARN_ON (n && !d)) -return -EINVAL ; -for (; n; n =rb_next (n)) {struct vfio_dma *dma;dma_addr_t iova;
@@ -727,21 +1047,49 @@ static int vfio_iommu_replay(struct vfio_iommu *iommu, iova = dma->iova;while (iova < dma->iova + dma->size) { -phys_addr_t phys =iommu_iova_to_phys (d->domain, iova); +phys_addr_t phys;size_t size; -if (WARN_ON (!phys)) { - iova +=PAGE_SIZE ; -continue ; +if (dma->iommu_mapped) { +phys_addr_t p; +dma_addr_t i; + + phys =iommu_iova_to_phys (d->domain, iova); + +if (WARN_ON (!phys)) { + iova +=PAGE_SIZE ; +continue ; + } + + size =PAGE_SIZE ; + p = phys + size; + i = iova + size; +while (i < dma->iova + dma->size && + p ==iommu_iova_to_phys (d->domain, i)) { + size +=PAGE_SIZE ; + p +=PAGE_SIZE ; + i +=PAGE_SIZE ; + } + }else { +unsigned long pfn; +unsigned long vaddr = dma->vaddr + + (iova - dma->iova); +size_t n = dma->iova + dma->size - iova; +long npage; + + npage =vfio_pin_pages_remote (dma, vaddr, + n >>PAGE_SHIFT , + &pfn); +if (npage <=0 ) { +WARN_ON (!npage); + ret = (int )npage; +return ret; + } + + phys = pfn <<PAGE_SHIFT ; + size = npage <<PAGE_SHIFT ; } - size =PAGE_SIZE ; - -while (iova + size < dma->iova + dma->size && - phys + size ==iommu_iova_to_phys (d->domain, - iova + size)) - size +=PAGE_SIZE ; - ret =iommu_map (domain->domain, iova, phys, size, dma->prot | domain->prot);if (ret)
@@ -749,8 +1097,8 @@ static int vfio_iommu_replay(struct vfio_iommu *iommu, iova += size; } + dma->iommu_mapped = true; } -return 0 ; }
@@ -806,7 +1154,7 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,struct vfio_iommu *iommu = iommu_data;struct vfio_group *group;struct vfio_domain *domain, *d; -struct bus_type *bus =NULL ; +struct bus_type *bus =NULL , *mdev_bus;int ret;mutex_lock (&iommu->lock);
@@ -818,6 +1166,13 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, } } +if (iommu->external_domain) { +if (find_iommu_group (iommu->external_domain, iommu_group)) { +mutex_unlock (&iommu->lock); +return -EINVAL ; + } + } + group =kzalloc (sizeof (*group),GFP_KERNEL ); domain =kzalloc (sizeof (*domain),GFP_KERNEL );if (!group || !domain) {
@@ -832,6 +1187,25 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,if (ret) goto out_free; + mdev_bus =symbol_get (mdev_bus_type); + +if (mdev_bus) { +if ((bus == mdev_bus) && !iommu_present (bus)) { +symbol_put (mdev_bus_type); +if (!iommu->external_domain) { +INIT_LIST_HEAD (&domain->group_list); + iommu->external_domain = domain; + }else +kfree (domain); + +list_add (&group->next, + &iommu->external_domain->group_list); +mutex_unlock (&iommu->lock); +return 0 ; + } +symbol_put (mdev_bus_type); + } + domain->domain =iommu_domain_alloc (bus);if (!domain->domain) { ret = -EIO ;
@@ -922,6 +1296,45 @@ static void vfio_iommu_unmap_unpin_all(struct vfio_iommu *iommu) vfio_remove_dma(iommu, rb_entry(node, struct vfio_dma, node)); } +static void vfio_iommu_unmap_unpin_reaccount (struct vfio_iommu *iommu) +{ +struct rb_node *n, *p; + + n =rb_first (&iommu->dma_list); +for (; n; n =rb_next (n)) { +struct vfio_dma *dma; +long locked =0 , unlocked =0 ; + + dma = rb_entry(n, struct vfio_dma, node); + unlocked +=vfio_unmap_unpin (iommu, dma, false); + p =rb_first (&dma->pfn_list); +for (; p; p =rb_next (p)) { + struct vfio_pfn *vpfn = rb_entry(p, struct vfio_pfn, + node); + +if (!is_invalid_reserved_pfn (vpfn->pfn)) + locked++; + } +vfio_lock_acct (dma->task, locked - unlocked); + } +} + +static void vfio_sanity_check_pfn_list (struct vfio_iommu *iommu) +{ +struct rb_node *n, *p; + + n =rb_first (&iommu->dma_list); +for (; n; n =rb_next (n)) { +struct vfio_dma *dma; +int unlocked =0 ; + + dma = rb_entry(n, struct vfio_dma, node); + +if (WARN_ON (!RB_EMPTY_ROOT (&dma->pfn_list))) +break ; + } +} +static void vfio_iommu_type1_detach_group (void *iommu_data,struct iommu_group *iommu_group) {
@@ -931,6 +1344,24 @@ static void vfio_iommu_type1_detach_group(void *iommu_data,mutex_lock (&iommu->lock); +if (iommu->external_domain) { + group =find_iommu_group (iommu->external_domain, iommu_group); +if (group) { +list_del (&group->next); +kfree (group); + +if (list_empty (&iommu->external_domain->group_list)) { +vfio_sanity_check_pfn_list (iommu); + +if (!IS_IOMMU_CAP_DOMAIN_IN_CONTAINER (iommu)) +vfio_iommu_unmap_unpin_all (iommu); + +kfree (iommu->external_domain); + } + goto detach_group_done; + } + } +list_for_each_entry (domain, &iommu->domain_list, next) { group =find_iommu_group (domain, iommu_group);if (!group)
@@ -940,21 +1371,27 @@ static void vfio_iommu_type1_detach_group(void *iommu_data,list_del (&group->next);kfree (group);/* -* Group ownership provides privilege, if the group -* list is empty, the domain goes away. If it's the -* last domain, then all the mappings go away too. +* Group ownership provides privilege, if the group list is +* empty, the domain goes away. If it's the last domain with +* iommu and external domain doesn't exist, then all the +* mappings go away too. If it's the last domain with iommu and +* external domain exist, update accounting */ if (list_empty (&domain->group_list)) { -if (list_is_singular (&iommu->domain_list)) -vfio_iommu_unmap_unpin_all (iommu); +if (list_is_singular (&iommu->domain_list)) { +if (!iommu->external_domain) +vfio_iommu_unmap_unpin_all (iommu); +else +vfio_iommu_unmap_unpin_reaccount (iommu); + }iommu_domain_free (domain->domain);list_del (&domain->next);kfree (domain); } - goto done; +break ; } -done: +detach_group_done:mutex_unlock (&iommu->lock); }
@@ -986,27 +1423,41 @@ static void *vfio_iommu_type1_open(unsigned long arg)return iommu; } +static void vfio_release_domain (struct vfio_domain *domain,bool external) +{ +struct vfio_group *group, *group_tmp; + +list_for_each_entry_safe (group, group_tmp, + &domain->group_list, next) { +if (!external) +iommu_detach_group (domain->domain, group->iommu_group); +list_del (&group->next); +kfree (group); + } + +if (!external) +iommu_domain_free (domain->domain); +} +static void vfio_iommu_type1_release (void *iommu_data) {struct vfio_iommu *iommu = iommu_data;struct vfio_domain *domain, *domain_tmp; -struct vfio_group *group, *group_tmp; + +if (iommu->external_domain) { +vfio_release_domain (iommu->external_domain, true); +vfio_sanity_check_pfn_list (iommu); +kfree (iommu->external_domain); + }vfio_iommu_unmap_unpin_all (iommu);list_for_each_entry_safe (domain, domain_tmp, &iommu->domain_list, next) { -list_for_each_entry_safe (group, group_tmp, - &domain->group_list, next) { -iommu_detach_group (domain->domain, group->iommu_group); -list_del (&group->next); -kfree (group); - } -iommu_domain_free (domain->domain); +vfio_release_domain (domain, false);list_del (&domain->next);kfree (domain); } -kfree (iommu); }
@@ -1110,6 +1561,8 @@ static const struct vfio_iommu_driver_ops vfio_iommu_driver_ops_type1 = { .ioctl = vfio_iommu_type1_ioctl, .attach_group = vfio_iommu_type1_attach_group, .detach_group = vfio_iommu_type1_detach_group, + .pin_pages = vfio_iommu_type1_pin_pages, + .unpin_pages = vfio_iommu_type1_unpin_pages, };static int __init vfio_iommu_type1_init (void )
Signature · 1 line
2.7.0
Re: [PATCH v14 10/22] vfio iommu type1: Add support for mediated devices
Quoted 7 lines · On Thu, 17 Nov 2016 02:16:22 +0530 Kirti Wankhede <[email protected]> wrote:
drivers/vfio/vfio_iommu_type1.c +3
-0@@ -931,6 +1344,24 @@ static void vfio_iommu_type1_detach_group(void *iommu_data,mutex_lock (&iommu->lock); +if (iommu->external_domain) { + group =find_iommu_group (iommu->external_domain, iommu_group); +if (group) {
drivers/vfio/vfio_iommu_type1.c static void vfio_iommu_type1_detach_group(void *iommu_data, · line 1359
Quoted 10 lines
drivers/vfio/vfio_iommu_type1.c +10
-0+list_del (&group->next); +kfree (group); + +if (list_empty (&iommu->external_domain->group_list)) { +vfio_sanity_check_pfn_list (iommu); + +if (!IS_IOMMU_CAP_DOMAIN_IN_CONTAINER (iommu)) +vfio_iommu_unmap_unpin_all (iommu); + +kfree (iommu->external_domain);
I advised in one place that I didn't understand why we were checking iommu->external_domain before walking the pfn_list, but we do have several checks still in place for if(iommu->external_domain), so I think we better be setting to NULL after we free it.
I haven't finished my review yet, but if this ends up being the only comment and you agree, I can add:
iommu->external_domain = NULL;
here on commit. Thanks,
Alex
Kirti Wankhede
maintainerRe: [PATCH v14 10/22] vfio iommu type1: Add support for mediated devices
Quoted 25 lines · Alex Williamson
Quoted 7 lines · On Thu, 17 Nov 2016 02:16:22 +0530 Kirti Wankhede <[email protected]> wrote:
drivers/vfio/vfio_iommu_type1.c +3
-0@@ -931,6 +1344,24 @@ static void vfio_iommu_type1_detach_group(void *iommu_data,mutex_lock (&iommu->lock); +if (iommu->external_domain) { + group =find_iommu_group (iommu->external_domain, iommu_group); +if (group) {drivers/vfio/vfio_iommu_type1.c static void vfio_iommu_type1_detach_group(void *iommu_data, · line 1359
Quoted 10 lines
drivers/vfio/vfio_iommu_type1.c +10
-0+list_del (&group->next); +kfree (group); + +if (list_empty (&iommu->external_domain->group_list)) { +vfio_sanity_check_pfn_list (iommu); + +if (!IS_IOMMU_CAP_DOMAIN_IN_CONTAINER (iommu)) +vfio_iommu_unmap_unpin_all (iommu); + +kfree (iommu->external_domain);I advised in one place that I didn't understand why we were checking
iommu->external_domainbefore walking thepfn_list, but we do have several checks still in place forif(iommu->external_domain), so I think we better be setting to NULL after we free it.
Quoted 7 lines
I haven't finished my review yet, but if this ends up being the only comment and you agree, I can add:
iommu->external_domain= NULL;here on commit. Thanks,
Thanks Alex.
I'm updating this patch and 11/22 as per your comment here and on 11/22.
Thanks,
Kirti
Kirti Wankhede
maintainerRe: [PATCH v14 10/22] vfio iommu type1: Add support for mediated devices
In reply to Kirti WankhedeVFIO IOMMU drivers are designed for the devices which are IOMMU capable. Mediated device only uses IOMMU APIs, the underlying hardware can be managed by an IOMMU domain.
Aim of this change is:
- To use most of the code of TYPE1 IOMMU driver for mediated devices
- To support direct assigned device and mediated device in single module
This change adds pin and unpin support for mediated device to TYPE1 IOMMU backend module. More details:
- Domain for external user is tracked separately in vfio_iommu structure. It is allocated when group for first mdev device is attached.
- Pages pinned for external domain are tracked in each vfio_dma structure for that iova range.
- Page tracking rb-tree in vfio_dma keeps <iova, pfn, ref_count>. Key of rb-tree is iova, but it actually aims to track pfns.
- On external pin request for an iova, page is pinned once, if iova is already pinned and tracked, ref_count is incremented.
- External unpin request unpins pages only when ref_count is 0.
- Pinned pages list is used to find pfn from iova and then unpin it. WARN_ON is added if there are entires in pfn_list while detaching the group and releasing the domain.
- Page accounting is updated to account in its address space where the pages are pinned/unpinned, i.e dma->task
- Accouting for mdev device is only done if there is no iommu capable domain in the container. When there is a direct device assigned to the container and that domain is iommu capable, all pages are already pinned during DMA_MAP.
- Page accouting is updated on hot plug and unplug mdev device and pass through device.
Tested by assigning below combinations of devices to a single VM:
- GPU pass through only
- vGPU device only
- One GPU pass through and one vGPU device
- Linux VM hot plug and unplug vGPU device while GPU pass through device exist
- Linux VM hot plug and unplug GPU pass through device while vGPU device exist
--- drivers/vfio/vfio_iommu_type1.c | 621 ++++++++++++++++++++++++++++++++++------ 1 file changed, 537 insertions(+), 84 deletions(-)
drivers/vfio/vfio_iommu_type1.c +537 -84
@@ -37,6 +37,7 @@#include <linux/vfio.h> #include <linux/workqueue.h> #include <linux/pid_namespace.h> +#include <linux/mdev.h> #define DRIVER_VERSION "0.2"#define DRIVER_AUTHOR "Alex Williamson <[email protected]>"
@@ -56,6 +57,7 @@ MODULE_PARM_DESC(disable_hugepages,struct vfio_iommu {struct list_head domain_list; +struct vfio_domain *external_domain;/* domain for external user */ struct mutex lock;struct rb_root dma_list;bool v2;
@@ -76,7 +78,9 @@ struct vfio_dma {unsigned long vaddr;/* Process virtual addr */ size_t size;/* Map size (bytes) */ int prot;/* IOMMU_READ/WRITE */ +bool iommu_mapped;struct task_struct *task; +struct rb_root pfn_list;/* Ex-user pinned pfn list */ };struct vfio_group {
@@ -85,6 +89,21 @@ struct vfio_group { };/* +* Guest RAM pinning working set or DMA target +*/ +struct vfio_pfn { +struct rb_node node; +dma_addr_t iova;/* Device address */ +unsigned long pfn;/* Host pfn */ +atomic_t ref_count; +}; + +#define IS_IOMMU_CAP_DOMAIN_IN_CONTAINER (iommu) \ + (!list_empty(&iommu->domain_list)) + +static int put_pfn (unsigned long pfn,int prot); + +/* * This code handles mapping and unmapping of user data buffers * into DMA'ble space using the IOMMU */
@@ -132,6 +151,97 @@ static void vfio_unlink_dma(struct vfio_iommu *iommu, struct vfio_dma *old)rb_erase (&old->node, &iommu->dma_list); } +/* +* Helper Functions for host iova-pfn list +*/ +static struct vfio_pfn *vfio_find_vpfn (struct vfio_dma *dma,dma_addr_t iova) +{ +struct vfio_pfn *vpfn; +struct rb_node *node = dma->pfn_list.rb_node; + +while (node) { + vpfn = rb_entry(node, struct vfio_pfn, node); + +if (iova < vpfn->iova) + node = node->rb_left; +else if (iova > vpfn->iova) + node = node->rb_right; +else +return vpfn; + } +return NULL ; +} + +static void vfio_link_pfn (struct vfio_dma *dma, +struct vfio_pfn *new) +{ +struct rb_node **link, *parent =NULL ; +struct vfio_pfn *vpfn; + + link = &dma->pfn_list.rb_node; +while (*link) { + parent = *link; + vpfn = rb_entry(parent, struct vfio_pfn, node); + +if (new->iova < vpfn->iova) + link = &(*link)->rb_left; +else + link = &(*link)->rb_right; + } + +rb_link_node (&new->node, parent, link); +rb_insert_color (&new->node, &dma->pfn_list); +} + +static void vfio_unlink_pfn (struct vfio_dma *dma,struct vfio_pfn *old) +{ +rb_erase (&old->node, &dma->pfn_list); +} + +static int vfio_add_to_pfn_list (struct vfio_dma *dma,dma_addr_t iova, +unsigned long pfn) +{ +struct vfio_pfn *vpfn; + + vpfn =kzalloc (sizeof (*vpfn),GFP_KERNEL ); +if (!vpfn) +return -ENOMEM ; + + vpfn->iova = iova; + vpfn->pfn = pfn; +atomic_set (&vpfn->ref_count,1 ); +vfio_link_pfn (dma, vpfn); +return 0 ; +} + +static void vfio_remove_from_pfn_list (struct vfio_dma *dma, +struct vfio_pfn *vpfn) +{ +vfio_unlink_pfn (dma, vpfn); +kfree (vpfn); +} + +static struct vfio_pfn *vfio_iova_get_vfio_pfn (struct vfio_dma *dma, +unsigned long iova) +{ +struct vfio_pfn *vpfn =vfio_find_vpfn (dma, iova); + +if (vpfn) +atomic_inc (&vpfn->ref_count); +return vpfn; +} + +static int vfio_iova_put_vfio_pfn (struct vfio_dma *dma,struct vfio_pfn *vpfn) +{ +int ret =0 ; + +if (atomic_dec_and_test (&vpfn->ref_count)) { + ret =put_pfn (vpfn->pfn, dma->prot); +vfio_remove_from_pfn_list (dma, vpfn); + } +return ret; +} +struct vwork {struct mm_struct *mm;long npage;
@@ -270,7 +380,6 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr, }up_read (&mm->mmap_sem); -return ret; }
@@ -280,65 +389,74 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr,* first page and all consecutive pages with the same locking. */ static long vfio_pin_pages_remote (struct vfio_dma *dma,unsigned long vaddr, -long npage,int prot,unsigned long *pfn_base) +long npage,unsigned long *pfn_base) {unsigned long limit;bool lock_cap =ns_capable (task_active_pid_ns (dma->task)->user_ns,CAP_IPC_LOCK );struct mm_struct *mm; -long ret, i; +long ret, i =0 , lock_acct =0 ;bool rsvd; +dma_addr_t iova = vaddr - dma->vaddr + dma->iova; mm =get_task_mm (dma->task);if (!mm)return -ENODEV ; - ret =vaddr_get_pfn (mm, vaddr, prot, pfn_base); + ret =vaddr_get_pfn (mm, vaddr, dma->prot, pfn_base);if (ret) goto pin_pg_remote_exit; rsvd =is_invalid_reserved_pfn (*pfn_base); limit =task_rlimit (dma->task,RLIMIT_MEMLOCK ) >>PAGE_SHIFT ; -if (!rsvd && !lock_cap && mm->locked_vm +1 > limit) { -put_pfn (*pfn_base, prot); -pr_warn ("%s: RLIMIT_MEMLOCK (%ld) exceeded\n" , __func__, - limit <<PAGE_SHIFT ); - ret = -ENOMEM ; - goto pin_pg_remote_exit; - } - -if (unlikely (disable_hugepages)) { -if (!rsvd) -vfio_lock_acct (dma->task,1 ); - ret =1 ; - goto pin_pg_remote_exit; +/* +* Reserved pages aren't counted against the user, externally pinned +* pages are already counted against the user. +*/ +if (!rsvd && !vfio_find_vpfn (dma, iova)) { +if (!lock_cap && mm->locked_vm +1 > limit) { +put_pfn (*pfn_base, dma->prot); +pr_warn ("%s: RLIMIT_MEMLOCK (%ld) exceeded\n" , __func__, + limit <<PAGE_SHIFT ); + ret = -ENOMEM ; + goto pin_pg_remote_exit; + } + lock_acct++; } -/* Lock all the consecutive pages from pfn_base */ -for (i =1 , vaddr +=PAGE_SIZE ; i < npage; i++, vaddr +=PAGE_SIZE ) { -unsigned long pfn =0 ; + i++; +if (likely (!disable_hugepages)) { +/* Lock all the consecutive pages from pfn_base */ +for (vaddr +=PAGE_SIZE , iova +=PAGE_SIZE ; i < npage; + i++, vaddr +=PAGE_SIZE , iova +=PAGE_SIZE ) { +unsigned long pfn =0 ; - ret =vaddr_get_pfn (mm, vaddr, prot, &pfn); -if (ret) -break ; + ret =vaddr_get_pfn (mm, vaddr, dma->prot, &pfn); +if (ret) +break ; -if (pfn != *pfn_base + i || - rsvd !=is_invalid_reserved_pfn (pfn)) { -put_pfn (pfn, prot); -break ; - } +if (pfn != *pfn_base + i || + rsvd !=is_invalid_reserved_pfn (pfn)) { +put_pfn (pfn, dma->prot); +break ; + } -if (!rsvd && !lock_cap && mm->locked_vm + i +1 > limit) { -put_pfn (pfn, prot); -pr_warn ("%s: RLIMIT_MEMLOCK (%ld) exceeded\n" , - __func__, limit <<PAGE_SHIFT ); -break ; +if (!rsvd && !vfio_find_vpfn (dma, iova)) { +if (!lock_cap && + mm->locked_vm + lock_acct +1 > limit) { +put_pfn (pfn, dma->prot); +pr_warn ("%s: RLIMIT_MEMLOCK (%ld) " +"exceeded\n" , __func__, + limit <<PAGE_SHIFT ); +break ; + } + lock_acct++; + } } } -if (!rsvd) -vfio_lock_acct (dma->task, i); +vfio_lock_acct (dma->task, lock_acct); ret = i; pin_pg_remote_exit:
@@ -346,14 +464,76 @@ pin_pg_remote_exit:return ret; } -static long vfio_unpin_pages_remote (struct vfio_dma *dma,unsigned long pfn, -long npage,int prot,bool do_accounting) +static long vfio_unpin_pages_remote (struct vfio_dma *dma,dma_addr_t iova, +unsigned long pfn,long npage, +bool do_accounting) { -unsigned long unlocked =0 ; +long unlocked =0 , locked =0 ;long i; -for (i =0 ; i < npage; i++) - unlocked +=put_pfn (pfn++, prot); +for (i =0 ; i < npage; i++) { +if (put_pfn (pfn++, dma->prot)) { + unlocked++; +if (vfio_find_vpfn (dma, iova + (i <<PAGE_SHIFT ))) + locked++; + } + } + +if (do_accounting) +vfio_lock_acct (dma->task, locked - unlocked); + +return unlocked; +} + +static int vfio_pin_page_external (struct vfio_dma *dma,unsigned long vaddr, +unsigned long *pfn_base,bool do_accounting) +{ +unsigned long limit; +bool lock_cap =ns_capable (task_active_pid_ns (dma->task)->user_ns, +CAP_IPC_LOCK ); +struct mm_struct *mm; +int ret; +bool rsvd; + + mm =get_task_mm (dma->task); +if (!mm) +return -ENODEV ; + + ret =vaddr_get_pfn (mm, vaddr, dma->prot, pfn_base); +if (ret) + goto pin_page_exit; + + rsvd =is_invalid_reserved_pfn (*pfn_base); + limit =task_rlimit (dma->task,RLIMIT_MEMLOCK ) >>PAGE_SHIFT ; + +if (!rsvd && !lock_cap && mm->locked_vm +1 > limit) { +put_pfn (*pfn_base, dma->prot); +pr_warn ("%s: Task %s (%d) RLIMIT_MEMLOCK (%ld) exceeded\n" , + __func__, dma->task->comm,task_pid_nr (dma->task), + limit <<PAGE_SHIFT ); + ret = -ENOMEM ; + goto pin_page_exit; + } + +if (!rsvd && do_accounting) +vfio_lock_acct (dma->task,1 ); + ret =1 ; + +pin_page_exit: +mmput (mm); +return ret; +} + +static int vfio_unpin_page_external (struct vfio_dma *dma,dma_addr_t iova, +bool do_accounting) +{ +int unlocked; +struct vfio_pfn *vpfn =vfio_find_vpfn (dma, iova); + +if (!vpfn) +return 0 ; + + unlocked =vfio_iova_put_vfio_pfn (dma, vpfn);if (do_accounting)vfio_lock_acct (dma->task, -unlocked);
@@ -361,14 +541,145 @@ static long vfio_unpin_pages_remote(struct vfio_dma *dma, unsigned long pfn,return unlocked; } -static void vfio_unmap_unpin (struct vfio_iommu *iommu,struct vfio_dma *dma) +static int vfio_iommu_type1_pin_pages (void *iommu_data, +unsigned long *user_pfn, +int npage,int prot, +unsigned long *phys_pfn) +{ +struct vfio_iommu *iommu = iommu_data; +int i, j, ret; +unsigned long remote_vaddr; +struct vfio_dma *dma; +bool do_accounting; + +if (!iommu || !user_pfn || !phys_pfn) +return -EINVAL ; + +/* Supported for v2 version only */ +if (!iommu->v2) +return -EACCES ; + +mutex_lock (&iommu->lock); + +if (!iommu->external_domain) { + ret = -EINVAL ; + goto pin_done; + } + +/* +* If iommu capable domain exist in the container then all pages are +* already pinned and accounted. Accouting should be done if there is no +* iommu capable domain in the container. +*/ + do_accounting = !IS_IOMMU_CAP_DOMAIN_IN_CONTAINER (iommu); + +for (i =0 ; i < npage; i++) { +dma_addr_t iova; +struct vfio_pfn *vpfn; + + iova = user_pfn[i] <<PAGE_SHIFT ; + dma =vfio_find_dma (iommu, iova,0 ); +if (!dma) { + ret = -EINVAL ; + goto pin_unwind; + } + +if ((dma->prot & prot) != prot) { + ret = -EPERM ; + goto pin_unwind; + } + + vpfn =vfio_iova_get_vfio_pfn (dma, iova); +if (vpfn) { + phys_pfn[i] = vpfn->pfn; +continue ; + } + + remote_vaddr = dma->vaddr + iova - dma->iova; + ret =vfio_pin_page_external (dma, remote_vaddr, &phys_pfn[i], + do_accounting); +if (ret <=0 ) { +WARN_ON (!ret); + goto pin_unwind; + } + + ret =vfio_add_to_pfn_list (dma, iova, phys_pfn[i]); +if (ret) { +vfio_unpin_page_external (dma, iova, do_accounting); + goto pin_unwind; + } + } + + ret = i; + goto pin_done; + +pin_unwind: + phys_pfn[i] =0 ; +for (j =0 ; j < i; j++) { +dma_addr_t iova; + + iova = user_pfn[j] <<PAGE_SHIFT ; + dma =vfio_find_dma (iommu, iova,0 ); +vfio_unpin_page_external (dma, iova, do_accounting); + phys_pfn[j] =0 ; + } +pin_done: +mutex_unlock (&iommu->lock); +return ret; +} + +static int vfio_iommu_type1_unpin_pages (void *iommu_data, +unsigned long *user_pfn, +int npage) +{ +struct vfio_iommu *iommu = iommu_data; +bool do_accounting; +int i; + +if (!iommu || !user_pfn) +return -EINVAL ; + +/* Supported for v2 version only */ +if (!iommu->v2) +return -EACCES ; + +mutex_lock (&iommu->lock); + +if (!iommu->external_domain) { +mutex_unlock (&iommu->lock); +return -EINVAL ; + } + + do_accounting = !IS_IOMMU_CAP_DOMAIN_IN_CONTAINER (iommu); +for (i =0 ; i < npage; i++) { +struct vfio_dma *dma; +dma_addr_t iova; + + iova = user_pfn[i] <<PAGE_SHIFT ; + dma =vfio_find_dma (iommu, iova,0 ); +if (!dma) + goto unpin_exit; +vfio_unpin_page_external (dma, iova, do_accounting); + } + +unpin_exit: +mutex_unlock (&iommu->lock); +return i > npage ? npage : (i >0 ? i : -EINVAL ); +} + +static long vfio_unmap_unpin (struct vfio_iommu *iommu,struct vfio_dma *dma, +bool do_accounting) {dma_addr_t iova = dma->iova, end = dma->iova + dma->size;struct vfio_domain *domain, *d;long unlocked =0 ;if (!dma->size) -return ; +return 0 ; + +if (!IS_IOMMU_CAP_DOMAIN_IN_CONTAINER (iommu)) +return 0 ; +/* * We use the IOMMU to track the physical addresses, otherwise we'd * need a much more complicated tracking system. Unfortunately that
@@ -410,20 +721,26 @@ static void vfio_unmap_unpin(struct vfio_iommu *iommu, struct vfio_dma *dma)if (WARN_ON (!unmapped))break ; - unlocked +=vfio_unpin_pages_remote (dma, phys >>PAGE_SHIFT , + unlocked +=vfio_unpin_pages_remote (dma, iova, + phys >>PAGE_SHIFT , unmapped >>PAGE_SHIFT , - dma->prot, false); + false); iova += unmapped;cond_resched (); } -vfio_lock_acct (dma->task, -unlocked); + dma->iommu_mapped = false; +if (do_accounting) { +vfio_lock_acct (dma->task, -unlocked); +return 0 ; + } +return unlocked; }static void vfio_remove_dma (struct vfio_iommu *iommu,struct vfio_dma *dma) { -vfio_unmap_unpin (iommu, dma); +vfio_unmap_unpin (iommu, dma, true);vfio_unlink_dma (iommu, dma);put_task_struct (dma->task);kfree (dma);
@@ -606,8 +923,7 @@ static int vfio_pin_map_dma(struct vfio_iommu *iommu, struct vfio_dma *dma,while (size) {/* Pin a contiguous chunk of memory */ npage =vfio_pin_pages_remote (dma, vaddr + dma->size, - size >>PAGE_SHIFT , dma->prot, - &pfn); + size >>PAGE_SHIFT , &pfn);if (npage <=0 ) {WARN_ON (!npage); ret = (int )npage;
@@ -618,8 +934,8 @@ static int vfio_pin_map_dma(struct vfio_iommu *iommu, struct vfio_dma *dma, ret =vfio_iommu_map (iommu, iova + dma->size, pfn, npage, dma->prot);if (ret) { -vfio_unpin_pages_remote (dma, pfn, npage, - dma->prot, true); +vfio_unpin_pages_remote (dma, iova + dma->size, pfn, + npage, true);break ; }
@@ -627,6 +943,8 @@ static int vfio_pin_map_dma(struct vfio_iommu *iommu, struct vfio_dma *dma, dma->size += npage <<PAGE_SHIFT ; } + dma->iommu_mapped = true; +if (ret)vfio_remove_dma (iommu, dma);
@@ -682,11 +1000,17 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu, dma->prot = prot;get_task_struct (current); dma->task = current; + dma->pfn_list =RB_ROOT ;/* Insert zero-sized and grow as we map chunks of it */ vfio_link_dma (iommu, dma); - ret =vfio_pin_map_dma (iommu, dma, size); +/* Don't pin and map if container doesn't contain IOMMU capable domain*/ +if (!IS_IOMMU_CAP_DOMAIN_IN_CONTAINER (iommu)) + dma->size = size; +else + ret =vfio_pin_map_dma (iommu, dma, size); + out_unlock:mutex_unlock (&iommu->lock);return ret;
@@ -715,10 +1039,6 @@ static int vfio_iommu_replay(struct vfio_iommu *iommu, d = list_first_entry(&iommu->domain_list, struct vfio_domain, next); n =rb_first (&iommu->dma_list); -/* If there's not a domain, there better not be any mappings */ -if (WARN_ON (n && !d)) -return -EINVAL ; -for (; n; n =rb_next (n)) {struct vfio_dma *dma;dma_addr_t iova;
@@ -727,21 +1047,49 @@ static int vfio_iommu_replay(struct vfio_iommu *iommu, iova = dma->iova;while (iova < dma->iova + dma->size) { -phys_addr_t phys =iommu_iova_to_phys (d->domain, iova); +phys_addr_t phys;size_t size; -if (WARN_ON (!phys)) { - iova +=PAGE_SIZE ; -continue ; +if (dma->iommu_mapped) { +phys_addr_t p; +dma_addr_t i; + + phys =iommu_iova_to_phys (d->domain, iova); + +if (WARN_ON (!phys)) { + iova +=PAGE_SIZE ; +continue ; + } + + size =PAGE_SIZE ; + p = phys + size; + i = iova + size; +while (i < dma->iova + dma->size && + p ==iommu_iova_to_phys (d->domain, i)) { + size +=PAGE_SIZE ; + p +=PAGE_SIZE ; + i +=PAGE_SIZE ; + } + }else { +unsigned long pfn; +unsigned long vaddr = dma->vaddr + + (iova - dma->iova); +size_t n = dma->iova + dma->size - iova; +long npage; + + npage =vfio_pin_pages_remote (dma, vaddr, + n >>PAGE_SHIFT , + &pfn); +if (npage <=0 ) { +WARN_ON (!npage); + ret = (int )npage; +return ret; + } + + phys = pfn <<PAGE_SHIFT ; + size = npage <<PAGE_SHIFT ; } - size =PAGE_SIZE ; - -while (iova + size < dma->iova + dma->size && - phys + size ==iommu_iova_to_phys (d->domain, - iova + size)) - size +=PAGE_SIZE ; - ret =iommu_map (domain->domain, iova, phys, size, dma->prot | domain->prot);if (ret)
@@ -749,8 +1097,8 @@ static int vfio_iommu_replay(struct vfio_iommu *iommu, iova += size; } + dma->iommu_mapped = true; } -return 0 ; }
@@ -806,7 +1154,7 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,struct vfio_iommu *iommu = iommu_data;struct vfio_group *group;struct vfio_domain *domain, *d; -struct bus_type *bus =NULL ; +struct bus_type *bus =NULL , *mdev_bus;int ret;mutex_lock (&iommu->lock);
@@ -818,6 +1166,13 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, } } +if (iommu->external_domain) { +if (find_iommu_group (iommu->external_domain, iommu_group)) { +mutex_unlock (&iommu->lock); +return -EINVAL ; + } + } + group =kzalloc (sizeof (*group),GFP_KERNEL ); domain =kzalloc (sizeof (*domain),GFP_KERNEL );if (!group || !domain) {
@@ -832,6 +1187,25 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,if (ret) goto out_free; + mdev_bus =symbol_get (mdev_bus_type); + +if (mdev_bus) { +if ((bus == mdev_bus) && !iommu_present (bus)) { +symbol_put (mdev_bus_type); +if (!iommu->external_domain) { +INIT_LIST_HEAD (&domain->group_list); + iommu->external_domain = domain; + }else +kfree (domain); + +list_add (&group->next, + &iommu->external_domain->group_list); +mutex_unlock (&iommu->lock); +return 0 ; + } +symbol_put (mdev_bus_type); + } + domain->domain =iommu_domain_alloc (bus);if (!domain->domain) { ret = -EIO ;
@@ -922,6 +1296,44 @@ static void vfio_iommu_unmap_unpin_all(struct vfio_iommu *iommu) vfio_remove_dma(iommu, rb_entry(node, struct vfio_dma, node)); } +static void vfio_iommu_unmap_unpin_reaccount (struct vfio_iommu *iommu) +{ +struct rb_node *n, *p; + + n =rb_first (&iommu->dma_list); +for (; n; n =rb_next (n)) { +struct vfio_dma *dma; +long locked =0 , unlocked =0 ; + + dma = rb_entry(n, struct vfio_dma, node); + unlocked +=vfio_unmap_unpin (iommu, dma, false); + p =rb_first (&dma->pfn_list); +for (; p; p =rb_next (p)) { + struct vfio_pfn *vpfn = rb_entry(p, struct vfio_pfn, + node); + +if (!is_invalid_reserved_pfn (vpfn->pfn)) + locked++; + } +vfio_lock_acct (dma->task, locked - unlocked); + } +} + +static void vfio_sanity_check_pfn_list (struct vfio_iommu *iommu) +{ +struct rb_node *n; + + n =rb_first (&iommu->dma_list); +for (; n; n =rb_next (n)) { +struct vfio_dma *dma; + + dma = rb_entry(n, struct vfio_dma, node); + +if (WARN_ON (!RB_EMPTY_ROOT (&dma->pfn_list))) +break ; + } +} +static void vfio_iommu_type1_detach_group (void *iommu_data,struct iommu_group *iommu_group) {
@@ -931,6 +1343,25 @@ static void vfio_iommu_type1_detach_group(void *iommu_data,mutex_lock (&iommu->lock); +if (iommu->external_domain) { + group =find_iommu_group (iommu->external_domain, iommu_group); +if (group) { +list_del (&group->next); +kfree (group); + +if (list_empty (&iommu->external_domain->group_list)) { +vfio_sanity_check_pfn_list (iommu); + +if (!IS_IOMMU_CAP_DOMAIN_IN_CONTAINER (iommu)) +vfio_iommu_unmap_unpin_all (iommu); + +kfree (iommu->external_domain); + iommu->external_domain =NULL ; + } + goto detach_group_done; + } + } +list_for_each_entry (domain, &iommu->domain_list, next) { group =find_iommu_group (domain, iommu_group);if (!group)
@@ -940,21 +1371,27 @@ static void vfio_iommu_type1_detach_group(void *iommu_data,list_del (&group->next);kfree (group);/* -* Group ownership provides privilege, if the group -* list is empty, the domain goes away. If it's the -* last domain, then all the mappings go away too. +* Group ownership provides privilege, if the group list is +* empty, the domain goes away. If it's the last domain with +* iommu and external domain doesn't exist, then all the +* mappings go away too. If it's the last domain with iommu and +* external domain exist, update accounting */ if (list_empty (&domain->group_list)) { -if (list_is_singular (&iommu->domain_list)) -vfio_iommu_unmap_unpin_all (iommu); +if (list_is_singular (&iommu->domain_list)) { +if (!iommu->external_domain) +vfio_iommu_unmap_unpin_all (iommu); +else +vfio_iommu_unmap_unpin_reaccount (iommu); + }iommu_domain_free (domain->domain);list_del (&domain->next);kfree (domain); } - goto done; +break ; } -done: +detach_group_done:mutex_unlock (&iommu->lock); }
@@ -986,27 +1423,41 @@ static void *vfio_iommu_type1_open(unsigned long arg)return iommu; } +static void vfio_release_domain (struct vfio_domain *domain,bool external) +{ +struct vfio_group *group, *group_tmp; + +list_for_each_entry_safe (group, group_tmp, + &domain->group_list, next) { +if (!external) +iommu_detach_group (domain->domain, group->iommu_group); +list_del (&group->next); +kfree (group); + } + +if (!external) +iommu_domain_free (domain->domain); +} +static void vfio_iommu_type1_release (void *iommu_data) {struct vfio_iommu *iommu = iommu_data;struct vfio_domain *domain, *domain_tmp; -struct vfio_group *group, *group_tmp; + +if (iommu->external_domain) { +vfio_release_domain (iommu->external_domain, true); +vfio_sanity_check_pfn_list (iommu); +kfree (iommu->external_domain); + }vfio_iommu_unmap_unpin_all (iommu);list_for_each_entry_safe (domain, domain_tmp, &iommu->domain_list, next) { -list_for_each_entry_safe (group, group_tmp, - &domain->group_list, next) { -iommu_detach_group (domain->domain, group->iommu_group); -list_del (&group->next); -kfree (group); - } -iommu_domain_free (domain->domain); +vfio_release_domain (domain, false);list_del (&domain->next);kfree (domain); } -kfree (iommu); }
@@ -1110,6 +1561,8 @@ static const struct vfio_iommu_driver_ops vfio_iommu_driver_ops_type1 = { .ioctl = vfio_iommu_type1_ioctl, .attach_group = vfio_iommu_type1_attach_group, .detach_group = vfio_iommu_type1_detach_group, + .pin_pages = vfio_iommu_type1_pin_pages, + .unpin_pages = vfio_iommu_type1_unpin_pages, };static int __init vfio_iommu_type1_init (void )
Signature · 1 line
2.7.0
Kirti Wankhede
maintainerPATCH v14 11/22 vfio iommu: Add blocking notifier to notify DMA_UNMAP
In reply to Kirti WankhedeAdded blocking notifier to IOMMU TYPE1 driver to notify vendor drivers about DMA_UNMAP.
Exported two APIs vfio_register_notifier() and vfio_unregister_notifier(). Notifier should be registered, if external user wants to use vfio_pin_pages()/vfio_unpin_pages() APIs to pin/unpin pages. Vendor driver should use VFIO_IOMMU_NOTIFY_DMA_UNMAP action to invalidate mappings.
--- drivers/vfio/vfio.c | 73 ++++++++++++++++++++++++++++++++++++++ drivers/vfio/vfio_iommu_type1.c | 77 +++++++++++++++++++++++++++++++++-------- include/linux/vfio.h | 12 +++++++ 3 files changed, 147 insertions(+), 15 deletions(-)
drivers/vfio/vfio.c +73 -0
@@ -1901,6 +1901,79 @@ err_unpin_pages: }EXPORT_SYMBOL (vfio_unpin_pages); +int vfio_register_notifier (struct device *dev,struct notifier_block *nb) +{ +struct vfio_container *container; +struct vfio_group *group; +struct vfio_iommu_driver *driver; +ssize_t ret; + +if (!dev || !nb) +return -EINVAL ; + + group =vfio_group_get_from_dev (dev); +if (IS_ERR (group)) +return PTR_ERR (group); + + ret =vfio_group_add_container_user (group); +if (ret) + goto err_register_nb; + + container = group->container; +down_read (&container->group_lock); + + driver = container->iommu_driver; +if (likely (driver && driver->ops->register_notifier)) + ret = driver->ops->register_notifier (container->iommu_data, nb); +else + ret = -ENOTTY ; + +up_read (&container->group_lock); +vfio_group_try_dissolve_container (group); + +err_register_nb: +vfio_group_put (group); +return ret; +} +EXPORT_SYMBOL (vfio_register_notifier); + +int vfio_unregister_notifier (struct device *dev,struct notifier_block *nb) +{ +struct vfio_container *container; +struct vfio_group *group; +struct vfio_iommu_driver *driver; +ssize_t ret; + +if (!dev || !nb) +return -EINVAL ; + + group =vfio_group_get_from_dev (dev); +if (IS_ERR (group)) +return PTR_ERR (group); + + ret =vfio_group_add_container_user (group); +if (ret) + goto err_unregister_nb; + + container = group->container; +down_read (&container->group_lock); + + driver = container->iommu_driver; +if (likely (driver && driver->ops->unregister_notifier)) + ret = driver->ops->unregister_notifier (container->iommu_data, + nb); +else + ret = -ENOTTY ; + +up_read (&container->group_lock); +vfio_group_try_dissolve_container (group); + +err_unregister_nb: +vfio_group_put (group); +return ret; +} +EXPORT_SYMBOL (vfio_unregister_notifier); +/** * Module/class support */
drivers/vfio/vfio_iommu_type1.c +62 -15
137 lines not on this page · raw message
include/linux/vfio.h +12 -0
@@ -80,6 +80,10 @@ struct vfio_iommu_driver_ops { unsigned long *phys_pfn);int (*unpin_pages)(void *iommu_data,unsigned long *user_pfn,int npage); +int (*register_notifier)(void *iommu_data, +struct notifier_block *nb); +int (*unregister_notifier)(void *iommu_data, +struct notifier_block *nb); };extern int vfio_register_iommu_driver (const struct vfio_iommu_driver_ops *ops);
@@ -103,6 +107,14 @@ extern int vfio_pin_pages(struct device *dev, unsigned long *user_pfn,extern int vfio_unpin_pages (struct device *dev,unsigned long *user_pfn,int npage); +#define VFIO_IOMMU_NOTIFY_DMA_UNMAP (1) + +extern int vfio_register_notifier (struct device *dev, +struct notifier_block *nb); + +extern int vfio_unregister_notifier (struct device *dev, +struct notifier_block *nb); +/* * Sub-module helpers */
Signature · 1 line
2.7.0
Re: [PATCH v14 11/22] vfio iommu: Add blocking notifier to notify DMA_UNMAP
Quoted 4 lines · On Thu, 17 Nov 2016 02:16:23 +0530 Kirti Wankhede <[email protected]> wrote:
drivers/vfio/vfio_iommu_type1.c +0
-0@@ -1321,12 +1350,11 @@ static void vfio_iommu_unmap_unpin_reaccount(struct vfio_iommu *iommu)static void vfio_sanity_check_pfn_list (struct vfio_iommu *iommu) {
drivers/vfio/vfio_iommu_type1.c static void vfio_iommu_unmap_unpin_reaccount(struct vfio_iommu *iommu) · line 1360
Quoted 10 lines
drivers/vfio/vfio_iommu_type1.c +1
-2-struct rb_node *n, *p; +struct rb_node *n; n =rb_first (&iommu->dma_list);for (; n; n =rb_next (n)) {struct vfio_dma *dma; -int unlocked =0 ; dma = rb_entry(n, struct vfio_dma, node);
This chunk really should have been part of 10/22 as well.
Re: [PATCH v14 11/22] vfio iommu: Add blocking notifier to notify DMA_UNMAP
In reply to Kirti WankhedeQuoted 22 lines · Kirti Wankhede
Added blocking notifier to IOMMU TYPE1 driver to notify vendor drivers about
DMA_UNMAP.
Exported two APIsvfio_register_notifier()andvfio_unregister_notifier(). Notifier should be registered, if external user wants to use vfio_pin_pages()/vfio_unpin_pages() APIs to pin/unpin pages. Vendor driver should useVFIO_IOMMU_NOTIFY_DMA_UNMAPaction to invalidate mappings.Signed-off-by Kirti Wankhede <[email protected]>Signed-off-by Neo Jia <[email protected]>Change-Id I5910d0024d6be87f3e8d3e0ca0eaeaaa0b17f271--- drivers/vfio/vfio.c | 73 ++++++++++++++++++++++++++++++++++++++ drivers/vfio/vfio_iommu_type1.c | 77 +++++++++++++++++++++++++++++++++-------- include/linux/vfio.h | 12 +++++++ 3 files changed, 147 insertions(+), 15 deletions(-)drivers/vfio/vfio.c +0
-0
drivers/vfio/vfio.c err_unpin_pages: · line 1910
Quoted 10 lines
drivers/vfio/vfio.c +7
-0@@ -1901,6 +1901,79 @@ err_unpin_pages: }EXPORT_SYMBOL (vfio_unpin_pages); +int vfio_register_notifier (struct device *dev,struct notifier_block *nb) +{ +struct vfio_container *container; +struct vfio_group *group; +struct vfio_iommu_driver *driver; +ssize_t ret; +
Any reason being 'ssize_t' here (and unregister)?
--
Thanks,
Jike
Quoted 250 lines
drivers/vfio/vfio.c +66
-0+if (!dev || !nb) +return -EINVAL ; + + group =vfio_group_get_from_dev (dev); +if (IS_ERR (group)) +return PTR_ERR (group); + + ret =vfio_group_add_container_user (group); +if (ret) + goto err_register_nb; + + container = group->container; +down_read (&container->group_lock); + + driver = container->iommu_driver; +if (likely (driver && driver->ops->register_notifier)) + ret = driver->ops->register_notifier (container->iommu_data, nb); +else + ret = -ENOTTY ; + +up_read (&container->group_lock); +vfio_group_try_dissolve_container (group); + +err_register_nb: +vfio_group_put (group); +return ret; +} +EXPORT_SYMBOL (vfio_register_notifier); + +int vfio_unregister_notifier (struct device *dev,struct notifier_block *nb) +{ +struct vfio_container *container; +struct vfio_group *group; +struct vfio_iommu_driver *driver; +ssize_t ret; + +if (!dev || !nb) +return -EINVAL ; + + group =vfio_group_get_from_dev (dev); +if (IS_ERR (group)) +return PTR_ERR (group); + + ret =vfio_group_add_container_user (group); +if (ret) + goto err_unregister_nb; + + container = group->container; +down_read (&container->group_lock); + + driver = container->iommu_driver; +if (likely (driver && driver->ops->unregister_notifier)) + ret = driver->ops->unregister_notifier (container->iommu_data, + nb); +else + ret = -ENOTTY ; + +up_read (&container->group_lock); +vfio_group_try_dissolve_container (group); + +err_unregister_nb: +vfio_group_put (group); +return ret; +} +EXPORT_SYMBOL (vfio_unregister_notifier); +/** * Module/class support */ drivers/vfio/vfio_iommu_type1.c +62
-15@@ -38,6 +38,7 @@#include <linux/workqueue.h> #include <linux/pid_namespace.h> #include <linux/mdev.h> +#include <linux/notifier.h> #define DRIVER_VERSION "0.2"#define DRIVER_AUTHOR "Alex Williamson <[email protected]>"@@ -60,6 +61,7 @@ struct vfio_iommu {struct vfio_domain *external_domain;/* domain for external user */ struct mutex lock;struct rb_root dma_list; +struct blocking_notifier_head notifier;bool v2;bool nesting; };@@ -561,7 +563,8 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data,mutex_lock (&iommu->lock); -if (!iommu->external_domain) { +/* Fail if notifier list is empty */ +if ((!iommu->external_domain) || (!iommu->notifier.head)) { ret = -EINVAL ; goto pin_done; }@@ -776,9 +779,9 @@ static int vfio_dma_do_unmap(struct vfio_iommu *iommu, struct vfio_iommu_type1_dma_unmap *unmap) {uint64_t mask; -struct vfio_dma *dma; +struct vfio_dma *dma, *dma_last =NULL ;size_t unmapped =0 ; -int ret =0 ; +int ret =0 , retries; mask = ((uint64_t )1 <<__ffs (vfio_pgsize_bitmap (iommu))) -1 ;@@ -788,7 +791,7 @@ static int vfio_dma_do_unmap(struct vfio_iommu *iommu,return -EINVAL ;WARN_ON (mask &PAGE_MASK ); - +again:mutex_lock (&iommu->lock);/* @@ -844,6 +847,32 @@ static int vfio_dma_do_unmap(struct vfio_iommu *iommu,*/ if (dma->task->mm != current->mm)break ; + +if (!RB_EMPTY_ROOT (&dma->pfn_list)) { +struct vfio_iommu_type1_dma_unmap nb_unmap; + +if (dma_last == dma) { +BUG_ON (++retries >10 ); + }else { + dma_last = dma; + retries =0 ; + } + + nb_unmap.iova = dma->iova; + nb_unmap.size = dma->size; + +/* +* Notify anyone (mdev vendor drivers) to invalidate and +* unmap iovas within the range we're about to unmap. +* Vendor drivers MUST unpin pages in response to an +* invalidation. +*/ +mutex_unlock (&iommu->lock); +blocking_notifier_call_chain (&iommu->notifier, +VFIO_IOMMU_NOTIFY_DMA_UNMAP , + &nb_unmap); + goto again; + } unmapped += dma->size;vfio_remove_dma (iommu, dma); }@@ -1321,12 +1350,11 @@ static void vfio_iommu_unmap_unpin_reaccount(struct vfio_iommu *iommu)static void vfio_sanity_check_pfn_list (struct vfio_iommu *iommu) { -struct rb_node *n, *p; +struct rb_node *n; n =rb_first (&iommu->dma_list);for (; n; n =rb_next (n)) {struct vfio_dma *dma; -int unlocked =0 ; dma = rb_entry(n, struct vfio_dma, node);@@ -1419,6 +1447,7 @@ static void *vfio_iommu_type1_open(unsigned long arg)INIT_LIST_HEAD (&iommu->domain_list); iommu->dma_list =RB_ROOT ;mutex_init (&iommu->lock); +BLOCKING_INIT_NOTIFIER_HEAD (&iommu->notifier);return iommu; }@@ -1553,16 +1582,34 @@ static long vfio_iommu_type1_ioctl(void *iommu_data,return -ENOTTY ; } +static int vfio_iommu_type1_register_notifier (void *iommu_data, +struct notifier_block *nb) +{ +struct vfio_iommu *iommu = iommu_data; + +return blocking_notifier_chain_register (&iommu->notifier, nb); +} + +static int vfio_iommu_type1_unregister_notifier (void *iommu_data, +struct notifier_block *nb) +{ +struct vfio_iommu *iommu = iommu_data; + +return blocking_notifier_chain_unregister (&iommu->notifier, nb); +} +static const struct vfio_iommu_driver_ops vfio_iommu_driver_ops_type1 = { - .name ="vfio-iommu-type1" , - .owner =THIS_MODULE , - .open = vfio_iommu_type1_open, - .release = vfio_iommu_type1_release, - .ioctl = vfio_iommu_type1_ioctl, - .attach_group = vfio_iommu_type1_attach_group, - .detach_group = vfio_iommu_type1_detach_group, - .pin_pages = vfio_iommu_type1_pin_pages, - .unpin_pages = vfio_iommu_type1_unpin_pages, + .name ="vfio-iommu-type1" , + .owner =THIS_MODULE , + .open = vfio_iommu_type1_open, + .release = vfio_iommu_type1_release, + .ioctl = vfio_iommu_type1_ioctl, + .attach_group = vfio_iommu_type1_attach_group, + .detach_group = vfio_iommu_type1_detach_group, + .pin_pages = vfio_iommu_type1_pin_pages, + .unpin_pages = vfio_iommu_type1_unpin_pages, + .register_notifier = vfio_iommu_type1_register_notifier, + .unregister_notifier = vfio_iommu_type1_unregister_notifier, };static int __init vfio_iommu_type1_init (void )include/linux/vfio.h +12
-0@@ -80,6 +80,10 @@ struct vfio_iommu_driver_ops { unsigned long *phys_pfn);int (*unpin_pages)(void *iommu_data,unsigned long *user_pfn,int npage); +int (*register_notifier)(void *iommu_data, +struct notifier_block *nb); +int (*unregister_notifier)(void *iommu_data, +struct notifier_block *nb); };extern int vfio_register_iommu_driver (const struct vfio_iommu_driver_ops *ops);@@ -103,6 +107,14 @@ extern int vfio_pin_pages(struct device *dev, unsigned long *user_pfn,extern int vfio_unpin_pages (struct device *dev,unsigned long *user_pfn,int npage); +#define VFIO_IOMMU_NOTIFY_DMA_UNMAP (1) + +extern int vfio_register_notifier (struct device *dev, +struct notifier_block *nb); + +extern int vfio_unregister_notifier (struct device *dev, +struct notifier_block *nb); +/* * Sub-module helpers */
Kirti Wankhede
maintainerRe: [PATCH v14 11/22] vfio iommu: Add blocking notifier to notify DMA_UNMAP
In reply to Kirti WankhedeAdded blocking notifier to IOMMU TYPE1 driver to notify vendor drivers about DMA_UNMAP.
Exported two APIs vfio_register_notifier() and vfio_unregister_notifier(). Notifier should be registered, if external user wants to use vfio_pin_pages()/vfio_unpin_pages() APIs to pin/unpin pages. Vendor driver should use VFIO_IOMMU_NOTIFY_DMA_UNMAP action to invalidate mappings.
--- drivers/vfio/vfio.c | 73 ++++++++++++++++++++++++++++++++++++++++ drivers/vfio/vfio_iommu_type1.c | 74 +++++++++++++++++++++++++++++++++-------- include/linux/vfio.h | 12 +++++++ 3 files changed, 146 insertions(+), 13 deletions(-)
drivers/vfio/vfio.c +73 -0
@@ -1901,6 +1901,79 @@ err_unpin_pages: }EXPORT_SYMBOL (vfio_unpin_pages); +int vfio_register_notifier (struct device *dev,struct notifier_block *nb) +{ +struct vfio_container *container; +struct vfio_group *group; +struct vfio_iommu_driver *driver; +int ret; + +if (!dev || !nb) +return -EINVAL ; + + group =vfio_group_get_from_dev (dev); +if (IS_ERR (group)) +return PTR_ERR (group); + + ret =vfio_group_add_container_user (group); +if (ret) + goto err_register_nb; + + container = group->container; +down_read (&container->group_lock); + + driver = container->iommu_driver; +if (likely (driver && driver->ops->register_notifier)) + ret = driver->ops->register_notifier (container->iommu_data, nb); +else + ret = -ENOTTY ; + +up_read (&container->group_lock); +vfio_group_try_dissolve_container (group); + +err_register_nb: +vfio_group_put (group); +return ret; +} +EXPORT_SYMBOL (vfio_register_notifier); + +int vfio_unregister_notifier (struct device *dev,struct notifier_block *nb) +{ +struct vfio_container *container; +struct vfio_group *group; +struct vfio_iommu_driver *driver; +int ret; + +if (!dev || !nb) +return -EINVAL ; + + group =vfio_group_get_from_dev (dev); +if (IS_ERR (group)) +return PTR_ERR (group); + + ret =vfio_group_add_container_user (group); +if (ret) + goto err_unregister_nb; + + container = group->container; +down_read (&container->group_lock); + + driver = container->iommu_driver; +if (likely (driver && driver->ops->unregister_notifier)) + ret = driver->ops->unregister_notifier (container->iommu_data, + nb); +else + ret = -ENOTTY ; + +up_read (&container->group_lock); +vfio_group_try_dissolve_container (group); + +err_unregister_nb: +vfio_group_put (group); +return ret; +} +EXPORT_SYMBOL (vfio_unregister_notifier); +/** * Module/class support */
drivers/vfio/vfio_iommu_type1.c +61 -13
124 lines not on this page · raw message
include/linux/vfio.h +12 -0
@@ -80,6 +80,10 @@ struct vfio_iommu_driver_ops { unsigned long *phys_pfn);int (*unpin_pages)(void *iommu_data,unsigned long *user_pfn,int npage); +int (*register_notifier)(void *iommu_data, +struct notifier_block *nb); +int (*unregister_notifier)(void *iommu_data, +struct notifier_block *nb); };extern int vfio_register_iommu_driver (const struct vfio_iommu_driver_ops *ops);
@@ -103,6 +107,14 @@ extern int vfio_pin_pages(struct device *dev, unsigned long *user_pfn,extern int vfio_unpin_pages (struct device *dev,unsigned long *user_pfn,int npage); +#define VFIO_IOMMU_NOTIFY_DMA_UNMAP (1) + +extern int vfio_register_notifier (struct device *dev, +struct notifier_block *nb); + +extern int vfio_unregister_notifier (struct device *dev, +struct notifier_block *nb); +/* * Sub-module helpers */
Signature · 1 line
2.7.0
Kirti Wankhede
maintainerPATCH v14 12/22 vfio: Add notifier callback to parent's ops structure of mdev
In reply to Kirti WankhedeAdd a notifier calback to parent's ops structure of mdev device so that per device notifer for vfio module is registered through vfio_mdev module.
--- drivers/vfio/mdev/vfio_mdev.c | 34 +++++++++++++++++++++++++++++++++- include/linux/mdev.h | 9 +++++++++ 2 files changed, 42 insertions(+), 1 deletion(-)
drivers/vfio/mdev/vfio_mdev.c +33 -1
@@ -24,6 +24,15 @@#define DRIVER_AUTHOR "NVIDIA Corporation"#define DRIVER_DESC "VFIO based driver for Mediated device" +static int vfio_mdev_notifier (struct notifier_block *nb,unsigned long action, +void *data) +{ + struct mdev_device *mdev = container_of(nb, struct mdev_device, nb); +struct parent_device *parent = mdev->parent; + +return parent->ops->notifier (mdev, action, data); +} +static int vfio_mdev_open (void *device_data) {struct mdev_device *mdev = device_data;
@@ -36,9 +45,27 @@ static int vfio_mdev_open(void *device_data)if (!try_module_get (THIS_MODULE ))return -ENODEV ; +if (likely (parent->ops->notifier)) { + mdev->nb.notifier_call = vfio_mdev_notifier; + ret =vfio_register_notifier (&mdev->dev, &mdev->nb); + +/* +* This should not fail if backend iommu module doesn't support +* register_notifier. +*/ +if (ret && (ret != -ENOTTY )) { +pr_err ("Failed to register notifier for mdev\n" ); +module_put (THIS_MODULE ); +return ret; + } + } + ret = parent->ops->open (mdev); -if (ret) +if (ret) { +if (likely (parent->ops->notifier)) +vfio_unregister_notifier (&mdev->dev, &mdev->nb);module_put (THIS_MODULE ); + }return ret; }
@@ -51,6 +78,11 @@ static void vfio_mdev_release(void *device_data)if (likely (parent->ops->release)) parent->ops->release (mdev); +if (likely (parent->ops->notifier)) { +if (vfio_unregister_notifier (&mdev->dev, &mdev->nb)) +pr_err ("Failed to unregister notifier for mdev\n" ); + } +module_put (THIS_MODULE ); }
include/linux/mdev.h +9 -0
@@ -37,6 +37,7 @@ struct mdev_device {struct kref ref;struct list_head next;struct kobject *type_kobj; +struct notifier_block nb; };/**
@@ -85,6 +86,12 @@ struct mdev_device {* @mmap: mmap callback * @mdev: mediated device structure * @vma: vma structure +* @notifer: Notifier callback, currently only for +* VFIO_IOMMU_NOTIFY_DMA_UNMAP action notified duing +* DMA_UNMAP call on mapped iova range. +* @mdev: mediated device structure +* @action: Action for which notifier is called +* @data: Data associated with the notifier * Parent device that support mediated device should be registered with mdev * module with parent_ops structure. **/
@@ -106,6 +113,8 @@ struct parent_ops {ssize_t (*ioctl)(struct mdev_device *mdev,unsigned int cmd,unsigned long arg);int (*mmap)(struct mdev_device *mdev,struct vm_area_struct *vma); +int (*notifier)(struct mdev_device *mdev,unsigned long action, +void *data); };/* interface for exporting mdev supported type attributes */
Signature · 1 line
2.7.0
Re: [PATCH v14 12/22] vfio: Add notifier callback to parent's ops structure of mdev
* Kirti Wankhede <[email protected]> [2016-11-17 02:16:24 +0530]:
Hi Kirti,
Quoted 1 line
drivers/vfio/mdev/vfio_mdev.c +0
-0
[...]
drivers/vfio/mdev/vfio_mdev.c static void vfio_mdev_release(void *device_data) · line 83
Quoted 7 lines
drivers/vfio/mdev/vfio_mdev.c +3
-0@@ -51,6 +78,11 @@ static void vfio_mdev_release(void *device_data)if (likely (parent->ops->release)) parent->ops->release (mdev); +if (likely (parent->ops->notifier)) { +if (vfio_unregister_notifier (&mdev->dev, &mdev->nb)) +pr_err ("Failed to unregister notifier for mdev\n" );
For the -ENOTTY case, we should not fail here either.
Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +2
-0+ } +module_put (THIS_MODULE ); }
[...]
Signature · 1 line
Dong Jia
Re: [Qemu-devel] [PATCH v14 12/22] vfio: Add notifier callback to parent's ops structure of mdev
In reply to Kirti Wankhede* Kirti Wankhede <[email protected]> [2016-11-17 02:16:24 +0530]:
Hi Kirti,
Quoted 1 line
drivers/vfio/mdev/vfio_mdev.c +0
-0
[...]
drivers/vfio/mdev/vfio_mdev.c static void vfio_mdev_release(void *device_data) · line 83
Quoted 7 lines
drivers/vfio/mdev/vfio_mdev.c +3
-0@@ -51,6 +78,11 @@ static void vfio_mdev_release(void *device_data)if (likely (parent->ops->release)) parent->ops->release (mdev); +if (likely (parent->ops->notifier)) { +if (vfio_unregister_notifier (&mdev->dev, &mdev->nb)) +pr_err ("Failed to unregister notifier for mdev\n" );
For the -ENOTTY case, we should not fail here either.
Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +2
-0+ } +module_put (THIS_MODULE ); }
[...]
Signature · 1 line
Dong Jia
Kirti Wankhede
maintainerRe: [PATCH v14 12/22] vfio: Add notifier callback to parent's ops structure of mdev
Quoted 7 lines · Dong Jia Shi
* Kirti Wankhede <[email protected]> [2016-11-17 02:16:24 +0530]:
Hi Kirti,
Quoted 1 line
drivers/vfio/mdev/vfio_mdev.c +0
-0[...]
Quoted 9 lines
drivers/vfio/mdev/vfio_mdev.c static void vfio_mdev_release(void *device_data) · line 83
Quoted 7 lines
drivers/vfio/mdev/vfio_mdev.c +3
-0@@ -51,6 +78,11 @@ static void vfio_mdev_release(void *device_data)if (likely (parent->ops->release)) parent->ops->release (mdev); +if (likely (parent->ops->notifier)) { +if (vfio_unregister_notifier (&mdev->dev, &mdev->nb)) +pr_err ("Failed to unregister notifier for mdev\n" );For the
-ENOTTYcase, we should not fail here either.
Removing the error print and ignoring return from this unregister call. Updating this patch on this thread.
Quoted 7 lines
Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +2
-0+ } +module_put (THIS_MODULE ); }[...]
Kirti Wankhede
maintainerRe: [PATCH v14 12/22] vfio: Add notifier callback to parent's ops structure of mdev
In reply to Kirti WankhedeAdd a notifier calback to parent's ops structure of mdev device so that per device notifer for vfio module is registered through vfio_mdev module.
--- drivers/vfio/mdev/vfio_mdev.c | 32 +++++++++++++++++++++++++++++++- include/linux/mdev.h | 9 +++++++++ 2 files changed, 40 insertions(+), 1 deletion(-)
drivers/vfio/mdev/vfio_mdev.c +31 -1
@@ -24,6 +24,15 @@#define DRIVER_AUTHOR "NVIDIA Corporation"#define DRIVER_DESC "VFIO based driver for Mediated device" +static int vfio_mdev_notifier (struct notifier_block *nb,unsigned long action, +void *data) +{ + struct mdev_device *mdev = container_of(nb, struct mdev_device, nb); +struct parent_device *parent = mdev->parent; + +return parent->ops->notifier (mdev, action, data); +} +static int vfio_mdev_open (void *device_data) {struct mdev_device *mdev = device_data;
@@ -36,9 +45,27 @@ static int vfio_mdev_open(void *device_data)if (!try_module_get (THIS_MODULE ))return -ENODEV ; +if (likely (parent->ops->notifier)) { + mdev->nb.notifier_call = vfio_mdev_notifier; + ret =vfio_register_notifier (&mdev->dev, &mdev->nb); + +/* +* This should not fail if backend iommu module doesn't support +* register_notifier. +*/ +if (ret && (ret != -ENOTTY )) { +pr_err ("Failed to register notifier for mdev\n" ); +module_put (THIS_MODULE ); +return ret; + } + } + ret = parent->ops->open (mdev); -if (ret) +if (ret) { +if (likely (parent->ops->notifier)) +vfio_unregister_notifier (&mdev->dev, &mdev->nb);module_put (THIS_MODULE ); + }return ret; }
@@ -51,6 +78,9 @@ static void vfio_mdev_release(void *device_data)if (likely (parent->ops->release)) parent->ops->release (mdev); +if (likely (parent->ops->notifier)) +vfio_unregister_notifier (&mdev->dev, &mdev->nb); +module_put (THIS_MODULE ); }
include/linux/mdev.h +9 -0
@@ -37,6 +37,7 @@ struct mdev_device {struct kref ref;struct list_head next;struct kobject *type_kobj; +struct notifier_block nb; };/**
@@ -85,6 +86,12 @@ struct mdev_device {* @mmap: mmap callback * @mdev: mediated device structure * @vma: vma structure +* @notifer: Notifier callback, currently only for +* VFIO_IOMMU_NOTIFY_DMA_UNMAP action notified duing +* DMA_UNMAP call on mapped iova range. +* @mdev: mediated device structure +* @action: Action for which notifier is called +* @data: Data associated with the notifier * Parent device that support mediated device should be registered with mdev * module with parent_ops structure. **/
@@ -106,6 +113,8 @@ struct parent_ops {ssize_t (*ioctl)(struct mdev_device *mdev,unsigned int cmd,unsigned long arg);int (*mmap)(struct mdev_device *mdev,struct vm_area_struct *vma); +int (*notifier)(struct mdev_device *mdev,unsigned long action, +void *data); };/* interface for exporting mdev supported type attributes */
Signature · 1 line
2.7.0
Re: [PATCH v14 12/22] vfio: Add notifier callback to parent's ops structure of mdev
In reply to Kirti WankhedeQuoted 99 lines · Kirti Wankhede
Add a notifier calback to parent's ops structure of mdev device so that per device notifer for vfio module is registered through
vfio_mdevmodule.Signed-off-by Kirti Wankhede <[email protected]>Signed-off-by Neo Jia <[email protected]>Change-Id Iafa6f1721aecdd6e50eb93b153b5621e6d29b637--- drivers/vfio/mdev/vfio_mdev.c | 34 +++++++++++++++++++++++++++++++++- include/linux/mdev.h | 9 +++++++++ 2 files changed, 42 insertions(+), 1 deletion(-)drivers/vfio/mdev/vfio_mdev.c +33
-1@@ -24,6 +24,15 @@#define DRIVER_AUTHOR "NVIDIA Corporation"#define DRIVER_DESC "VFIO based driver for Mediated device" +static int vfio_mdev_notifier (struct notifier_block *nb,unsigned long action, +void *data) +{ + struct mdev_device *mdev = container_of(nb, struct mdev_device, nb); +struct parent_device *parent = mdev->parent; + +return parent->ops->notifier (mdev, action, data); +} +static int vfio_mdev_open (void *device_data) {struct mdev_device *mdev = device_data;@@ -36,9 +45,27 @@ static int vfio_mdev_open(void *device_data)if (!try_module_get (THIS_MODULE ))return -ENODEV ; +if (likely (parent->ops->notifier)) { + mdev->nb.notifier_call = vfio_mdev_notifier; + ret =vfio_register_notifier (&mdev->dev, &mdev->nb); + +/* +* This should not fail if backend iommu module doesn't support +* register_notifier. +*/ +if (ret && (ret != -ENOTTY )) { +pr_err ("Failed to register notifier for mdev\n" ); +module_put (THIS_MODULE ); +return ret; + } + } + ret = parent->ops->open (mdev); -if (ret) +if (ret) { +if (likely (parent->ops->notifier)) +vfio_unregister_notifier (&mdev->dev, &mdev->nb);module_put (THIS_MODULE ); + }return ret; }@@ -51,6 +78,11 @@ static void vfio_mdev_release(void *device_data)if (likely (parent->ops->release)) parent->ops->release (mdev); +if (likely (parent->ops->notifier)) { +if (vfio_unregister_notifier (&mdev->dev, &mdev->nb)) +pr_err ("Failed to unregister notifier for mdev\n" ); + } +module_put (THIS_MODULE ); }include/linux/mdev.h +7
-0@@ -37,6 +37,7 @@ struct mdev_device {struct kref ref;struct list_head next;struct kobject *type_kobj; +struct notifier_block nb; };/** @@ -85,6 +86,12 @@ struct mdev_device {* @mmap: mmap callback * @mdev: mediated device structure * @vma: vma structure +* @notifer: Notifier callback, currently only for +* VFIO_IOMMU_NOTIFY_DMA_UNMAP action notified duing +* DMA_UNMAP call on mapped iova range. +* @mdev: mediated device structure +* @action: Action for which notifier is called +* @data: Data associated with the notifier * Parent device that support mediated device should be registered with mdev * module with parent_ops structure. **/
include/linux/mdev.h struct parent_ops { · line 120
Quoted 8 lines
include/linux/mdev.h +2
-0@@ -106,6 +113,8 @@ struct parent_ops {ssize_t (*ioctl)(struct mdev_device *mdev,unsigned int cmd,unsigned long arg);int (*mmap)(struct mdev_device *mdev,struct vm_area_struct *vma); +int (*notifier)(struct mdev_device *mdev,unsigned long action, +void *data); };/* interface for exporting mdev supported type attributes */
Hi Alex, Kirti,
Since everyone agreed we should let the vendor driver call vfio_register_notifier directly, can you drop this patch from merging? So that I don't need to send a reverse patch.
Thanks :)
--
Thanks,
Jike
Re: [PATCH v14 12/22] vfio: Add notifier callback to parent's ops structure of mdev
Quoted 13 lines · On Thu, 17 Nov 2016 20:35:38 +0800 Jike Song <[email protected]> wrote:
Quoted 11 lines · Kirti Wankhede
Add a notifier calback to parent's ops structure of mdev device so that per device notifer for vfio module is registered through
vfio_mdevmodule.Signed-off-by Kirti Wankhede <[email protected]>Signed-off-by Neo Jia <[email protected]>Change-Id Iafa6f1721aecdd6e50eb93b153b5621e6d29b637--- drivers/vfio/mdev/vfio_mdev.c | 34 +++++++++++++++++++++++++++++++++- include/linux/mdev.h | 9 +++++++++ 2 files changed, 42 insertions(+), 1 deletion(-)
Quoted 5 lines
Hi Alex, Kirti,
Since everyone agreed we should let the vendor driver call
vfio_register_notifierdirectly, can you drop this patch from merging? So that I don't need to send a reverse patch.
This seems like a reasonable request to me, this patch drops cleanly from the series. Any objection Kirti? It seems like it removes a little bit of pre-release churn from the API. Thanks,
Alex
Kirti Wankhede
maintainerRe: [PATCH v14 12/22] vfio: Add notifier callback to parent's ops structure of mdev
Quoted 18 lines · Alex Williamson
Quoted 15 lines · On Thu, 17 Nov 2016 20:35:38 +0800 Jike Song <[email protected]> wrote:
Quoted 11 lines · Kirti Wankhede
Add a notifier calback to parent's ops structure of mdev device so that per device notifer for vfio module is registered through
vfio_mdevmodule.Signed-off-by Kirti Wankhede <[email protected]>Signed-off-by Neo Jia <[email protected]>Change-Id Iafa6f1721aecdd6e50eb93b153b5621e6d29b637--- drivers/vfio/mdev/vfio_mdev.c | 34 +++++++++++++++++++++++++++++++++- include/linux/mdev.h | 9 +++++++++ 2 files changed, 42 insertions(+), 1 deletion(-)Hi Alex, Kirti,
Quoted 8 lines
Quoted 3 lines
Since everyone agreed we should let the vendor driver call
vfio_register_notifierdirectly, can you drop this patch from merging? So that I don't need to send a reverse patch.This seems like a reasonable request to me, this patch drops cleanly from the series. Any objection Kirti? It seems like it removes a little bit of pre-release churn from the API. Thanks,
This is independent patch, I don't have any concern to drop this patch.
Small nit: Since Documentation patch is later in series, its mentioned in the doc. One line need to be removed from vfio-mediated-device.txt.
Documentation/vfio-mediated-device.txt +0 -0
@@ -150,7 +150,6 @@ The callbacks in the parent_ops structure are as
follows:
* read : read emulation callback
* write: write emulation callback
* mmap: mmap emulation callback
-* notifier: notifier callback
Thanks,
Kirti
Re: [PATCH v14 12/22] vfio: Add notifier callback to parent's ops structure of mdev
Quoted 36 lines · On Thu, 17 Nov 2016 21:30:26 +0530 Kirti Wankhede <[email protected]> wrote:
Quoted 18 lines · Alex Williamson
Quoted 15 lines · On Thu, 17 Nov 2016 20:35:38 +0800 Jike Song <[email protected]> wrote:
Quoted 11 lines · Kirti Wankhede
Add a notifier calback to parent's ops structure of mdev device so that per device notifer for vfio module is registered through
vfio_mdevmodule.Signed-off-by Kirti Wankhede <[email protected]>Signed-off-by Neo Jia <[email protected]>Change-Id Iafa6f1721aecdd6e50eb93b153b5621e6d29b637--- drivers/vfio/mdev/vfio_mdev.c | 34 +++++++++++++++++++++++++++++++++- include/linux/mdev.h | 9 +++++++++ 2 files changed, 42 insertions(+), 1 deletion(-)Hi Alex, Kirti,
Quoted 8 lines
Quoted 3 lines
Since everyone agreed we should let the vendor driver call
vfio_register_notifierdirectly, can you drop this patch from merging? So that I don't need to send a reverse patch.This seems like a reasonable request to me, this patch drops cleanly from the series. Any objection Kirti? It seems like it removes a little bit of pre-release churn from the API. Thanks,
This is independent patch, I don't have any concern to drop this patch.
Small nit: Since Documentation patch is later in series, its mentioned in the doc. One line need to be removed from vfio-mediated-device.txt.
Documentation/vfio-mediated-device.txt +0
-0@@ -150,7 +150,6 @@ The callbacks in the parent_ops structure are as
Quoted 5 lines
follows:
* read : read emulation callback
* write: write emulation callback
* mmap: mmap emulation callback
-* notifier: notifier callback
Good catch, I'll remove this line. Thanks,
Alex
Kirti Wankhede
maintainerPATCH v14 13/22 vfio: Introduce common function to add capabilities
In reply to Kirti WankhedeVendor driver using mediated device framework should use vfio_info_add_capability() to add capabilities.
Introduced this function to reduce code duplication in vendor drivers.
vfio_info_cap_shift() manipulated a data buffer to add an offset to each element in a chain. This data buffer is documented in a uapi header. Changing vfio_info_cap_shift symbol to be available to all drivers.
--- drivers/vfio/vfio.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++- include/linux/vfio.h | 3 +++ 2 files changed, 62 insertions(+), 1 deletion(-)
drivers/vfio/vfio.c +59 -1
@@ -1797,8 +1797,66 @@ void vfio_info_cap_shift(struct vfio_info_cap *caps, size_t offset)for (tmp = caps->buf; tmp->next; tmp = (void *)tmp + tmp->next - offset) tmp->next += offset; } -EXPORT_SYMBOL_GPL (vfio_info_cap_shift); +EXPORT_SYMBOL (vfio_info_cap_shift); +static int sparse_mmap_cap (struct vfio_info_cap *caps,void *cap_type) +{ +struct vfio_info_cap_header *header; +struct vfio_region_info_cap_sparse_mmap *sparse_cap, *sparse = cap_type; +size_t size; + + size =sizeof (*sparse) + sparse->nr_areas *sizeof (*sparse->areas); + header =vfio_info_cap_add (caps, size, +VFIO_REGION_INFO_CAP_SPARSE_MMAP ,1 ); +if (IS_ERR (header)) +return PTR_ERR (header); + + sparse_cap =container_of (header, + struct vfio_region_info_cap_sparse_mmap, header); + sparse_cap->nr_areas = sparse->nr_areas; +memcpy (sparse_cap->areas, sparse->areas, + sparse->nr_areas *sizeof (*sparse->areas)); +return 0 ; +} + +static int region_type_cap (struct vfio_info_cap *caps,void *cap_type) +{ +struct vfio_info_cap_header *header; +struct vfio_region_info_cap_type *type_cap, *cap = cap_type; + + header =vfio_info_cap_add (caps,sizeof (*cap), +VFIO_REGION_INFO_CAP_TYPE ,1 ); +if (IS_ERR (header)) +return PTR_ERR (header); + + type_cap = container_of(header, struct vfio_region_info_cap_type, + header); + type_cap->type = cap->type; + type_cap->subtype = cap->subtype; +return 0 ; +} + +int vfio_info_add_capability (struct vfio_info_cap *caps,int cap_type_id, +void *cap_type) +{ +int ret = -EINVAL ; + +if (!cap_type) +return 0 ; + +switch (cap_type_id) { +case VFIO_REGION_INFO_CAP_SPARSE_MMAP : + ret =sparse_mmap_cap (caps, cap_type); +break ; + +case VFIO_REGION_INFO_CAP_TYPE : + ret =region_type_cap (caps, cap_type); +break ; + } + +return ret; +} +EXPORT_SYMBOL (vfio_info_add_capability);/* * Pin a set of guest PFNs and return their associated host PFNs for local
include/linux/vfio.h +3 -0
@@ -126,6 +126,9 @@ extern struct vfio_info_cap_header *vfio_info_cap_add( struct vfio_info_cap *caps, size_t size, u16 id, u16 version);extern void vfio_info_cap_shift (struct vfio_info_cap *caps,size_t offset); +extern int vfio_info_add_capability (struct vfio_info_cap *caps, +int cap_type_id,void *cap_type); +struct pci_dev ;#ifdef CONFIG_EEH extern void vfio_spapr_pci_eeh_open (struct pci_dev *pdev);
Signature · 1 line
2.7.0
Re: [Qemu-devel] [PATCH v14 13/22] vfio: Introduce common function to add capabilities
Hi,
Quoted 94 lines · Kirti Wankhede
Vendor driver using mediated device framework should use
vfio_info_add_capability()to add capabilities.
Introduced this function to reduce code duplication in vendor drivers.
vfio_info_cap_shift()manipulated a data buffer to add an offset to each element in a chain. This data buffer is documented in a uapi header. Changingvfio_info_cap_shiftsymbol to be available to all drivers.Signed-off-by Kirti Wankhede <[email protected]>Signed-off-by Neo Jia <[email protected]>Change-Id I6fca329fa2291f37a2c859d0bc97574d9e2ce1a6--- drivers/vfio/vfio.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++- include/linux/vfio.h | 3 +++ 2 files changed, 62 insertions(+), 1 deletion(-)drivers/vfio/vfio.c +59
-1@@ -1797,8 +1797,66 @@ void vfio_info_cap_shift(struct vfio_info_cap *caps, size_t offset)for (tmp = caps->buf; tmp->next; tmp = (void *)tmp + tmp->next - offset) tmp->next += offset; } -EXPORT_SYMBOL_GPL (vfio_info_cap_shift); +EXPORT_SYMBOL (vfio_info_cap_shift); +static int sparse_mmap_cap (struct vfio_info_cap *caps,void *cap_type) +{ +struct vfio_info_cap_header *header; +struct vfio_region_info_cap_sparse_mmap *sparse_cap, *sparse = cap_type; +size_t size; + + size =sizeof (*sparse) + sparse->nr_areas *sizeof (*sparse->areas); + header =vfio_info_cap_add (caps, size, +VFIO_REGION_INFO_CAP_SPARSE_MMAP ,1 ); +if (IS_ERR (header)) +return PTR_ERR (header); + + sparse_cap =container_of (header, + struct vfio_region_info_cap_sparse_mmap, header); + sparse_cap->nr_areas = sparse->nr_areas; +memcpy (sparse_cap->areas, sparse->areas, + sparse->nr_areas *sizeof (*sparse->areas)); +return 0 ; +} + +static int region_type_cap (struct vfio_info_cap *caps,void *cap_type) +{ +struct vfio_info_cap_header *header; +struct vfio_region_info_cap_type *type_cap, *cap = cap_type; + + header =vfio_info_cap_add (caps,sizeof (*cap), +VFIO_REGION_INFO_CAP_TYPE ,1 ); +if (IS_ERR (header)) +return PTR_ERR (header); + + type_cap = container_of(header, struct vfio_region_info_cap_type, + header); + type_cap->type = cap->type; + type_cap->subtype = cap->subtype; +return 0 ; +} + +int vfio_info_add_capability (struct vfio_info_cap *caps,int cap_type_id, +void *cap_type) +{ +int ret = -EINVAL ; + +if (!cap_type) +return 0 ; + +switch (cap_type_id) { +case VFIO_REGION_INFO_CAP_SPARSE_MMAP : + ret =sparse_mmap_cap (caps, cap_type); +break ; + +case VFIO_REGION_INFO_CAP_TYPE : + ret =region_type_cap (caps, cap_type); +break ; + } + +return ret; +} +EXPORT_SYMBOL (vfio_info_add_capability);/* * Pin a set of guest PFNs and return their associated host PFNs for local include/linux/vfio.h +0
-0
include/linux/vfio.h extern struct vfio_info_cap_header *vfio_info_cap_add( · line 134
Quoted 9 lines
include/linux/vfio.h +3
-0@@ -126,6 +126,9 @@ extern struct vfio_info_cap_header *vfio_info_cap_add( struct vfio_info_cap *caps, size_t size, u16 id, u16 version);extern void vfio_info_cap_shift (struct vfio_info_cap *caps,size_t offset); +extern int vfio_info_add_capability (struct vfio_info_cap *caps, +int cap_type_id,void *cap_type); +struct pci_dev ;#ifdef CONFIG_EEH extern void vfio_spapr_pci_eeh_open (struct pci_dev *pdev);
Eric
Kirti Wankhede
maintainerPATCH v14 14/22 vfio_pci: Update vfio_pci to use vfio_info_add_capability()
In reply to Kirti WankhedeUpdate msix_sparse_mmap_cap() to use vfio_info_add_capability() Update region type capability to use vfio_info_add_capability()
--- drivers/vfio/pci/vfio_pci.c | 49 ++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 30 deletions(-)
drivers/vfio/pci/vfio_pci.c +19 -30
@@ -558,10 +558,9 @@ static int vfio_pci_for_each_slot_or_bus(struct pci_dev *pdev,static int msix_sparse_mmap_cap (struct vfio_pci_device *vdev,struct vfio_info_cap *caps) { -struct vfio_info_cap_header *header;struct vfio_region_info_cap_sparse_mmap *sparse;size_t end, size; -int nr_areas =2 , i =0 ; +int nr_areas =2 , i =0 , ret; end =pci_resource_len (vdev->pdev, vdev->msix_bar);
@@ -572,13 +571,10 @@ static int msix_sparse_mmap_cap(struct vfio_pci_device *vdev, size =sizeof (*sparse) + (nr_areas *sizeof (*sparse->areas)); - header =vfio_info_cap_add (caps, size, -VFIO_REGION_INFO_CAP_SPARSE_MMAP ,1 ); -if (IS_ERR (header)) -return PTR_ERR (header); + sparse =kzalloc (size,GFP_KERNEL ); +if (!sparse) +return -ENOMEM ; - sparse =container_of (header, - struct vfio_region_info_cap_sparse_mmap, header); sparse->nr_areas = nr_areas;if (vdev->msix_offset &PAGE_MASK ) {
@@ -594,26 +590,11 @@ static int msix_sparse_mmap_cap(struct vfio_pci_device *vdev, i++; } -return 0 ; -} - -static int region_type_cap (struct vfio_pci_device *vdev, -struct vfio_info_cap *caps, -unsigned int type,unsigned int subtype) -{ -struct vfio_info_cap_header *header; -struct vfio_region_info_cap_type *cap; - - header =vfio_info_cap_add (caps,sizeof (*cap), -VFIO_REGION_INFO_CAP_TYPE ,1 ); -if (IS_ERR (header)) -return PTR_ERR (header); - - cap = container_of(header, struct vfio_region_info_cap_type, header); - cap->type = type; - cap->subtype = subtype; + ret =vfio_info_add_capability (caps,VFIO_REGION_INFO_CAP_SPARSE_MMAP , + sparse); +kfree (sparse); -return 0 ; +return ret; } int vfio_pci_register_dev_region(struct vfio_pci_device *vdev,
@@ -752,6 +733,9 @@ static long vfio_pci_ioctl(void *device_data,break ;default : + { +struct vfio_region_info_cap_type cap_type; +if (info.index >=VFIO_PCI_NUM_REGIONS + vdev->num_regions)return -EINVAL ;
@@ -762,11 +746,16 @@ static long vfio_pci_ioctl(void *device_data, info.size = vdev->region[i].size; info.flags = vdev->region[i].flags; - ret =region_type_cap (vdev, &caps, - vdev->region[i].type, - vdev->region[i].subtype); + cap_type.type = vdev->region[i].type; + cap_type.subtype = vdev->region[i].subtype; + + ret =vfio_info_add_capability (&caps, +VFIO_REGION_INFO_CAP_TYPE , + &cap_type);if (ret)return ret; + + } }if (caps.size) {
Signature · 1 line
2.7.0
Re: [PATCH v14 14/22] vfio_pci: Update vfio_pci to use vfio_info_add_capability()
Hi,
Quoted 90 lines · Kirti Wankhede
Update
msix_sparse_mmap_cap()to usevfio_info_add_capability()Update region type capability to usevfio_info_add_capability()Signed-off-by Kirti Wankhede <[email protected]>Signed-off-by Neo Jia <[email protected]>Change-Id I52bb28c7875a6da5a79ddad1843e6088aff58a45--- drivers/vfio/pci/vfio_pci.c | 49 ++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 30 deletions(-)drivers/vfio/pci/vfio_pci.c +11
-29@@ -558,10 +558,9 @@ static int vfio_pci_for_each_slot_or_bus(struct pci_dev *pdev,static int msix_sparse_mmap_cap (struct vfio_pci_device *vdev,struct vfio_info_cap *caps) { -struct vfio_info_cap_header *header;struct vfio_region_info_cap_sparse_mmap *sparse;size_t end, size; -int nr_areas =2 , i =0 ; +int nr_areas =2 , i =0 , ret; end =pci_resource_len (vdev->pdev, vdev->msix_bar);@@ -572,13 +571,10 @@ static int msix_sparse_mmap_cap(struct vfio_pci_device *vdev, size =sizeof (*sparse) + (nr_areas *sizeof (*sparse->areas)); - header =vfio_info_cap_add (caps, size, -VFIO_REGION_INFO_CAP_SPARSE_MMAP ,1 ); -if (IS_ERR (header)) -return PTR_ERR (header); + sparse =kzalloc (size,GFP_KERNEL ); +if (!sparse) +return -ENOMEM ; - sparse =container_of (header, - struct vfio_region_info_cap_sparse_mmap, header); sparse->nr_areas = nr_areas;if (vdev->msix_offset &PAGE_MASK ) {@@ -594,26 +590,11 @@ static int msix_sparse_mmap_cap(struct vfio_pci_device *vdev, i++; } -return 0 ; -} - -static int region_type_cap (struct vfio_pci_device *vdev, -struct vfio_info_cap *caps, -unsigned int type,unsigned int subtype) -{ -struct vfio_info_cap_header *header; -struct vfio_region_info_cap_type *cap; - - header =vfio_info_cap_add (caps,sizeof (*cap), -VFIO_REGION_INFO_CAP_TYPE ,1 ); -if (IS_ERR (header)) -return PTR_ERR (header); - - cap = container_of(header, struct vfio_region_info_cap_type, header); - cap->type = type; - cap->subtype = subtype; + ret =vfio_info_add_capability (caps,VFIO_REGION_INFO_CAP_SPARSE_MMAP , + sparse); +kfree (sparse); -return 0 ; +return ret; } int vfio_pci_register_dev_region(struct vfio_pci_device *vdev,@@ -752,6 +733,9 @@ static long vfio_pci_ioctl(void *device_data,break ;default : + { +struct vfio_region_info_cap_type cap_type; +if (info.index >=VFIO_PCI_NUM_REGIONS + vdev->num_regions)return -EINVAL ;@@ -762,11 +746,16 @@ static long vfio_pci_ioctl(void *device_data, info.size = vdev->region[i].size; info.flags = vdev->region[i].flags; - ret = region_type_cap(vdev, &caps, - vdev->region[i].type,
drivers/vfio/pci/vfio_pci.c static long vfio_pci_ioctl(void *device_data, · line 757
Quoted 10 lines
drivers/vfio/pci/vfio_pci.c +7
-1- vdev->region[i].subtype); + cap_type.type = vdev->region[i].type; + cap_type.subtype = vdev->region[i].subtype; + + ret =vfio_info_add_capability (&caps, +VFIO_REGION_INFO_CAP_TYPE , + &cap_type);if (ret)return ret; +
nit: spare empty line
Eric
Quoted 5 lines
drivers/vfio/pci/vfio_pci.c +1
-0+ } }if (caps.size) {
Kirti Wankhede
maintainerPATCH v14 15/22 vfio: Introduce vfio_set_irqs_validate_and_prepare()
In reply to Kirti WankhedeVendor driver using mediated device framework would use same mechnism to validate and prepare IRQs. Introducing this function to reduce code replication in multiple drivers.
--- drivers/vfio/vfio.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/vfio.h | 4 ++++ 2 files changed, 52 insertions(+)
drivers/vfio/vfio.c +48 -0
@@ -1858,6 +1858,54 @@ int vfio_info_add_capability(struct vfio_info_cap *caps, int cap_type_id, }EXPORT_SYMBOL (vfio_info_add_capability); +int vfio_set_irqs_validate_and_prepare (struct vfio_irq_set *hdr,int num_irqs, +int max_irq_type,size_t *data_size) +{ +unsigned long minsz; +size_t size; + + minsz = offsetofend(struct vfio_irq_set, count); + +if ((hdr->argsz < minsz) || (hdr->index >= max_irq_type) || + (hdr->count >= (U32_MAX - hdr->start)) || + (hdr->flags & ~(VFIO_IRQ_SET_DATA_TYPE_MASK | +VFIO_IRQ_SET_ACTION_TYPE_MASK ))) +return -EINVAL ; + +if (data_size) + *data_size =0 ; + +if (hdr->start >= num_irqs || hdr->start + hdr->count > num_irqs) +return -EINVAL ; + +switch (hdr->flags &VFIO_IRQ_SET_DATA_TYPE_MASK ) { +case VFIO_IRQ_SET_DATA_NONE : + size =0 ; +break ; +case VFIO_IRQ_SET_DATA_BOOL : + size =sizeof (uint8_t ); +break ; +case VFIO_IRQ_SET_DATA_EVENTFD : + size =sizeof (int32_t ); +break ; +default : +return -EINVAL ; + } + +if (size) { +if (hdr->argsz - minsz < hdr->count * size) +return -EINVAL ; + +if (!data_size) +return -EINVAL ; + + *data_size = hdr->count * size; + } + +return 0 ; +} +EXPORT_SYMBOL (vfio_set_irqs_validate_and_prepare); +/* * Pin a set of guest PFNs and return their associated host PFNs for local * domain only.
include/linux/vfio.h +4 -0
@@ -129,6 +129,10 @@ extern void vfio_info_cap_shift(struct vfio_info_cap *caps, size_t offset);extern int vfio_info_add_capability (struct vfio_info_cap *caps,int cap_type_id,void *cap_type); +extern int vfio_set_irqs_validate_and_prepare (struct vfio_irq_set *hdr, +int num_irqs,int max_irq_type, +size_t *data_size); +struct pci_dev ;#ifdef CONFIG_EEH extern void vfio_spapr_pci_eeh_open (struct pci_dev *pdev);
Signature · 1 line
2.7.0
Re: [PATCH v14 15/22] vfio: Introduce vfio_set_irqs_validate_and_prepare()
Hi,
Quoted 50 lines · Kirti Wankhede
Vendor driver using mediated device framework would use same mechnism to validate and prepare IRQs. Introducing this function to reduce code replication in multiple drivers.
Signed-off-by Kirti Wankhede <[email protected]>Signed-off-by Neo Jia <[email protected]>Change-Id Ie201f269dda0713ca18a07dc4852500bd8b48309--- drivers/vfio/vfio.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/vfio.h | 4 ++++ 2 files changed, 52 insertions(+)drivers/vfio/vfio.c +30
-0@@ -1858,6 +1858,54 @@ int vfio_info_add_capability(struct vfio_info_cap *caps, int cap_type_id, }EXPORT_SYMBOL (vfio_info_add_capability); +int vfio_set_irqs_validate_and_prepare (struct vfio_irq_set *hdr,int num_irqs, +int max_irq_type,size_t *data_size) +{ +unsigned long minsz; +size_t size; + + minsz = offsetofend(struct vfio_irq_set, count); + +if ((hdr->argsz < minsz) || (hdr->index >= max_irq_type) || + (hdr->count >= (U32_MAX - hdr->start)) || + (hdr->flags & ~(VFIO_IRQ_SET_DATA_TYPE_MASK | +VFIO_IRQ_SET_ACTION_TYPE_MASK ))) +return -EINVAL ; + +if (data_size) + *data_size =0 ; + +if (hdr->start >= num_irqs || hdr->start + hdr->count > num_irqs) +return -EINVAL ; + +switch (hdr->flags &VFIO_IRQ_SET_DATA_TYPE_MASK ) { +case VFIO_IRQ_SET_DATA_NONE : + size =0 ; +break ; +case VFIO_IRQ_SET_DATA_BOOL : + size =sizeof (uint8_t ); +break ; +case VFIO_IRQ_SET_DATA_EVENTFD : + size =sizeof (int32_t ); +break ;
drivers/vfio/vfio.c int vfio_info_add_capability(struct vfio_info_cap *caps, int cap_type_id, · line 1900
Quoted 10 lines
drivers/vfio/vfio.c +10
-0+default : +return -EINVAL ; + } + +if (size) { +if (hdr->argsz - minsz < hdr->count * size) +return -EINVAL ; + +if (!data_size) +return -EINVAL ;
nit: this could have done on the first check above.
Thanks
Eric
Quoted 27 lines
drivers/vfio/vfio.c +8
-0+ + *data_size = hdr->count * size; + } + +return 0 ; +} +EXPORT_SYMBOL (vfio_set_irqs_validate_and_prepare); +/* * Pin a set of guest PFNs and return their associated host PFNs for local * domain only. include/linux/vfio.h +4
-0@@ -129,6 +129,10 @@ extern void vfio_info_cap_shift(struct vfio_info_cap *caps, size_t offset);extern int vfio_info_add_capability (struct vfio_info_cap *caps,int cap_type_id,void *cap_type); +extern int vfio_set_irqs_validate_and_prepare (struct vfio_irq_set *hdr, +int num_irqs,int max_irq_type, +size_t *data_size); +struct pci_dev ;#ifdef CONFIG_EEH extern void vfio_spapr_pci_eeh_open (struct pci_dev *pdev);
Kirti Wankhede
maintainerPATCH v14 16/22 vfio_pci: Updated to use vfio_set_irqs_validate_and_prepare()
In reply to Kirti WankhedeUpdated vfio_pci.c file to use vfio_set_irqs_validate_and_prepare()
--- drivers/vfio/pci/vfio_pci.c | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-)
drivers/vfio/pci/vfio_pci.c +7 -27
@@ -818,45 +818,25 @@ static long vfio_pci_ioctl(void *device_data, }else if (cmd ==VFIO_DEVICE_SET_IRQS ) {struct vfio_irq_set hdr; -size_t size;u8 *data =NULL ;int max, ret =0 ; +size_t data_size =0 ; minsz = offsetofend(struct vfio_irq_set, count);if (copy_from_user (&hdr, (void __user *)arg, minsz))return -EFAULT ; -if (hdr.argsz < minsz || hdr.index >=VFIO_PCI_NUM_IRQS || - hdr.count >= (U32_MAX - hdr.start) || - hdr.flags & ~(VFIO_IRQ_SET_DATA_TYPE_MASK | -VFIO_IRQ_SET_ACTION_TYPE_MASK )) -return -EINVAL ; - max =vfio_pci_get_irq_count (vdev, hdr.index); -if (hdr.start >= max || hdr.start + hdr.count > max) -return -EINVAL ; -switch (hdr.flags &VFIO_IRQ_SET_DATA_TYPE_MASK ) { -case VFIO_IRQ_SET_DATA_NONE : - size =0 ; -break ; -case VFIO_IRQ_SET_DATA_BOOL : - size =sizeof (uint8_t ); -break ; -case VFIO_IRQ_SET_DATA_EVENTFD : - size =sizeof (int32_t ); -break ; -default : -return -EINVAL ; - } - -if (size) { -if (hdr.argsz - minsz < hdr.count * size) -return -EINVAL ; + ret =vfio_set_irqs_validate_and_prepare (&hdr, max, +VFIO_PCI_NUM_IRQS , &data_size); +if (ret) +return ret; +if (data_size) { data =memdup_user ((void __user *)(arg + minsz), - hdr.count * size); + data_size);if (IS_ERR (data))return PTR_ERR (data); }
Signature · 1 line
2.7.0
Re: [PATCH v14 16/22] vfio_pci: Updated to use vfio_set_irqs_validate_and_prepare()
Hi,
Quoted 57 lines · Kirti Wankhede
Updated
vfio_pci.cfile to usevfio_set_irqs_validate_and_prepare()Signed-off-by Kirti Wankhede <[email protected]>Signed-off-by Neo Jia <[email protected]>Change-Id I9f3daba89d8dba5cb5b01a8cff420412f30686c7--- drivers/vfio/pci/vfio_pci.c | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-)drivers/vfio/pci/vfio_pci.c +3
-26@@ -818,45 +818,25 @@ static long vfio_pci_ioctl(void *device_data, }else if (cmd ==VFIO_DEVICE_SET_IRQS ) {struct vfio_irq_set hdr; -size_t size;u8 *data =NULL ;int max, ret =0 ; +size_t data_size =0 ; minsz = offsetofend(struct vfio_irq_set, count);if (copy_from_user (&hdr, (void __user *)arg, minsz))return -EFAULT ; -if (hdr.argsz < minsz || hdr.index >=VFIO_PCI_NUM_IRQS || - hdr.count >= (U32_MAX - hdr.start) || - hdr.flags & ~(VFIO_IRQ_SET_DATA_TYPE_MASK | -VFIO_IRQ_SET_ACTION_TYPE_MASK )) -return -EINVAL ; - max =vfio_pci_get_irq_count (vdev, hdr.index); -if (hdr.start >= max || hdr.start + hdr.count > max) -return -EINVAL ; -switch (hdr.flags &VFIO_IRQ_SET_DATA_TYPE_MASK ) { -case VFIO_IRQ_SET_DATA_NONE : - size =0 ; -break ; -case VFIO_IRQ_SET_DATA_BOOL : - size =sizeof (uint8_t ); -break ; -case VFIO_IRQ_SET_DATA_EVENTFD : - size =sizeof (int32_t ); -break ; -default : -return -EINVAL ; - } - -if (size) { -if (hdr.argsz - minsz < hdr.count * size) -return -EINVAL ; + ret =vfio_set_irqs_validate_and_prepare (&hdr, max, +VFIO_PCI_NUM_IRQS , &data_size);
drivers/vfio/pci/vfio_pci.c static long vfio_pci_ioctl(void *device_data, · line 842
Quoted 10 lines
drivers/vfio/pci/vfio_pci.c +4
-1+if (ret) +return ret; +if (data_size) { data =memdup_user ((void __user *)(arg + minsz), - hdr.count * size); + data_size);if (IS_ERR (data))return PTR_ERR (data); }
Thanks
Eric
Kirti Wankhede
maintainerPATCH v14 17/22 vfio_platform: Updated to use vfio_set_irqs_validate_and_prepare()
In reply to Kirti WankhedeUpdated vfio_platform_common.c file to usevfio_set_irqs_validate_and_prepare()
--- drivers/vfio/platform/vfio_platform_common.c | 31 +++++++--------------------- 1 file changed, 8 insertions(+), 23 deletions(-)
drivers/vfio/platform/vfio_platform_common.c +8 -23
@@ -364,36 +364,21 @@ static long vfio_platform_ioctl(void *device_data,struct vfio_irq_set hdr;u8 *data =NULL ;int ret =0 ; +size_t data_size =0 ; minsz = offsetofend(struct vfio_irq_set, count);if (copy_from_user (&hdr, (void __user *)arg, minsz))return -EFAULT ; -if (hdr.argsz < minsz) -return -EINVAL ; - -if (hdr.index >= vdev->num_irqs) -return -EINVAL ; - -if (hdr.flags & ~(VFIO_IRQ_SET_DATA_TYPE_MASK | -VFIO_IRQ_SET_ACTION_TYPE_MASK )) -return -EINVAL ; - -if (!(hdr.flags &VFIO_IRQ_SET_DATA_NONE )) { -size_t size; - -if (hdr.flags &VFIO_IRQ_SET_DATA_BOOL ) - size =sizeof (uint8_t ); -else if (hdr.flags &VFIO_IRQ_SET_DATA_EVENTFD ) - size =sizeof (int32_t ); -else -return -EINVAL ; - -if (hdr.argsz - minsz < size) -return -EINVAL ; + ret =vfio_set_irqs_validate_and_prepare (&hdr, vdev->num_irqs, + vdev->num_irqs, &data_size); +if (ret) +return ret; - data =memdup_user ((void __user *)(arg + minsz), size); +if (data_size) { + data =memdup_user ((void __user *)(arg + minsz), + data_size);if (IS_ERR (data))return PTR_ERR (data); }
Signature · 1 line
2.7.0
Re: [PATCH v14 17/22] vfio_platform: Updated to use vfio_set_irqs_validate_and_prepare()
Hi,
Quoted 46 lines · Kirti Wankhede
Updated
vfio_platform_common.cfile to usevfio_set_irqs_validate_and_prepare()Signed-off-by Kirti Wankhede <[email protected]>Signed-off-by Neo Jia <[email protected]>Change-Id Id87cd6b78ae901610b39bf957974baa6f40cd7b0--- drivers/vfio/platform/vfio_platform_common.c | 31 +++++++--------------------- 1 file changed, 8 insertions(+), 23 deletions(-)drivers/vfio/platform/vfio_platform_common.c +1
-21@@ -364,36 +364,21 @@ static long vfio_platform_ioctl(void *device_data,struct vfio_irq_set hdr;u8 *data =NULL ;int ret =0 ; +size_t data_size =0 ; minsz = offsetofend(struct vfio_irq_set, count);if (copy_from_user (&hdr, (void __user *)arg, minsz))return -EFAULT ; -if (hdr.argsz < minsz) -return -EINVAL ; - -if (hdr.index >= vdev->num_irqs) -return -EINVAL ; - -if (hdr.flags & ~(VFIO_IRQ_SET_DATA_TYPE_MASK | -VFIO_IRQ_SET_ACTION_TYPE_MASK )) -return -EINVAL ; - -if (!(hdr.flags &VFIO_IRQ_SET_DATA_NONE )) { -size_t size; - -if (hdr.flags &VFIO_IRQ_SET_DATA_BOOL ) - size =sizeof (uint8_t ); -else if (hdr.flags &VFIO_IRQ_SET_DATA_EVENTFD ) - size =sizeof (int32_t ); -else -return -EINVAL ; - -if (hdr.argsz - minsz < size)
drivers/vfio/platform/vfio_platform_common.c static long vfio_platform_ioctl(void *device_data, · line 381
Quoted 10 lines
drivers/vfio/platform/vfio_platform_common.c +7
-2-return -EINVAL ; + ret =vfio_set_irqs_validate_and_prepare (&hdr, vdev->num_irqs, + vdev->num_irqs, &data_size); +if (ret) +return ret; - data =memdup_user ((void __user *)(arg + minsz), size); +if (data_size) { + data =memdup_user ((void __user *)(arg + minsz), + data_size);
Thanks
Eric
Quoted 4 lines
drivers/vfio/platform/vfio_platform_common.c +0
-0if (IS_ERR (data))return PTR_ERR (data); }
Kirti Wankhede
maintainerPATCH v14 18/22 vfio: Define device_api strings
In reply to Kirti WankhedeDefined device API strings. Vendor driver using mediated device framework should use corresponding string for device_api attribute.
--- include/uapi/linux/vfio.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
include/uapi/linux/vfio.h +10 -0
@@ -203,6 +203,16 @@ struct vfio_device_info { };#define VFIO_DEVICE_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 7) +/* +* Vendor driver using Mediated device framework should provide device_api +* attribute in supported type attribute groups. Device API string should be one +* of the following corresponding to device flags in vfio_device_info structure. +*/ + +#define VFIO_DEVICE_API_PCI_STRING "vfio-pci" +#define VFIO_DEVICE_API_PLATFORM_STRING "vfio-platform" +#define VFIO_DEVICE_API_AMBA_STRING "vfio-amba" +/** * VFIO_DEVICE_GET_REGION_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 8, * struct vfio_region_info)
Signature · 1 line
2.7.0
Kirti Wankhede
maintainerPATCH v14 19/22 docs: Add Documentation for Mediated devices
In reply to Kirti WankhedeAdd file Documentation/vfio-mediated-device.txt that include details of mediated device framework.
--- Documentation/vfio-mediated-device.txt | 298 +++++++++++++++++++++++++++++++++ drivers/vfio/mdev/Kconfig | 1 + 2 files changed, 299 insertions(+) create mode 100644 Documentation/vfio-mediated-device.txt
Documentation/vfio-mediated-device.txt new file +298 -0
@@ -0,0 +1,298 @@ +/* + * VFIO Mediated devices + * + * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. + * Author: Neo Jia <[email protected]> + * Kirti Wankhede <[email protected]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +Virtual Function I/O (VFIO) Mediated devices[1] +=============================================== + +The number of use cases for virtualizing DMA devices that do not have built-in +SR_IOV capability is increasing. Previously, to virtualize such devices, +developers had to create their own management interfaces and APIs, and then +integrate them with user space software. To simplify integration with user space +software, we have identified common requirements and a unified management +interface for such devices. + +The VFIO driver framework provides unified APIs for direct device access. It is +an IOMMU/device-agnostic framework for exposing direct device access to user +space in a secure, IOMMU-protected environment. This framework is used for +multiple devices, such as GPUs, network adapters, and compute accelerators. With +direct device access, virtual machines or user space applications have direct +access to the physical device. This framework is reused for mediated devices. + +The mediated core driver provides a common interface for mediated device +management that can be used by drivers of different devices. This module +provides a generic interface to perform these operations: + +* Create and destroy a mediated device +* Add a mediated device to and remove it from a mediated bus driver +* Add a mediated device to and remove it from an IOMMU group + +The mediated core driver also provides an interface to register a bus driver. +For example, the mediated VFIO mdev driver is designed for mediated devices and +supports VFIO APIs. The mediated bus driver adds a mediated device to and +removes it from a VFIO group. + +The following high-level block diagram shows the main components and interfaces +in the VFIO mediated driver framework. The diagram shows NVIDIA, Intel, and IBM +devices as examples, as these devices are the first devices to use this module. + + +---------------+ + | | + | +-----------+ | mdev_register_driver() +--------------+ + | | | +<------------------------+ | + | | mdev | | | | + | | bus | +------------------------>+ vfio_mdev.ko |<-> VFIO user + | | driver | | probe()/remove() | | APIs + | | | | +--------------+ + | +-----------+ | + | | + | MDEV CORE | + | MODULE | + | mdev.ko | + | +-----------+ | mdev_register_device() +--------------+ + | | | +<------------------------+ | + | | | | | nvidia.ko |<-> physical + | | | +------------------------>+ | device + | | | | callbacks +--------------+ + | | Physical | | + | | device | | mdev_register_device() +--------------+ + | | interface | |<------------------------+ | + | | | | | i915.ko |<-> physical + | | | +------------------------>+ | device + | | | | callbacks +--------------+ + | | | | + | | | | mdev_register_device() +--------------+ + | | | +<------------------------+ | + | | | | | ccw_device.ko|<-> physical + | | | +------------------------>+ | device + | | | | callbacks +--------------+ + | +-----------+ | + +---------------+ + + +Registration Interfaces +======================= + +The mediated core driver provides the following types of registration +interfaces: + +* Registration interface for a mediated bus driver +* Physical device driver interface + +Registration Interface for a Mediated Bus Driver +------------------------------------------------ + +The registration interface for a mediated bus driver provides the following +structure to represent a mediated device's driver: + + /* + * struct mdev_driver [2] - Mediated device's driver + * @name: driver name + * @probe: called when new device created + * @remove: called when device removed + * @driver: device driver structure + */ + struct mdev_driver { + const char *name; + int (*probe) (struct device *dev); + void (*remove) (struct device *dev); + struct device_driver driver; + }; + +A mediated bus driver for mdev should use this structure in the function calls +to register and unregister itself with the core driver: + +* Register: + + extern int mdev_register_driver(struct mdev_driver *drv, + struct module *owner); + +* Unregister: + + extern void mdev_unregister_driver(struct mdev_driver *drv); + +The mediated bus driver is responsible for adding mediated devices to the VFIO +group when devices are bound to the driver and removing mediated devices from +the VFIO when devices are unbound from the driver. + + +Physical Device Driver Interface +-------------------------------- + +The physical device driver interface provides the parent_ops[3] structure to +define the APIs to manage work in the mediated core driver that is related to +the physical device. + +The structures in the parent_ops structure are as follows: + +* dev_attr_groups: attributes of the parent device +* mdev_attr_groups: attributes of the mediated device +* supported_config: attributes to define supported configurations + +The functions in the parent_ops structure are as follows: + +* create: allocate basic resources in a driver for a mediated device +* remove: free resources in a driver when a mediated device is destroyed + +The callbacks in the parent_ops structure are as follows: + +* open: open callback of mediated device +* close: close callback of mediated device +* ioctl: ioctl callback of mediated device +* read : read emulation callback +* write: write emulation callback +* mmap: mmap emulation callback +* notifier: notifier callback + +A driver should use the parent_ops structure in the function call to register +itself with the mdev core driver: + +extern int mdev_register_device(struct device *dev, + const struct parent_ops *ops); + +However, the parent_ops structure is not required in the function call that a +driver should use to unregister itself with the mdev core driver: + +extern void mdev_unregister_device(struct device *dev); + + +Mediated Device Management Interface Through sysfs +================================================== + +The management interface through sysfs enables user space software, such as +libvirt, to query and configure mediated devices in a hardware-agnostic fashion. +This management interface provides flexibility to the underlying physical +device's driver to support features such as: + +* Mediated device hot plug +* Multiple mediated devices in a single virtual machine +* Multiple mediated devices from different physical devices + +Links in the mdev_bus Class Directory +------------------------------------- +The /sys/class/mdev_bus/ directory contains links to devices that are registered +with the mdev core driver. + +Directories and files under the sysfs for Each Physical Device +-------------------------------------------------------------- + +|- [parent physical device] +|--- Vendor-specific-attributes [optional] +|--- [mdev_supported_types] +| |--- [<type-id>] +| | |--- create +| | |--- name +| | |--- available_instances +| | |--- device_api +| | |--- description +| | |--- [devices] +| |--- [<type-id>] +| | |--- create +| | |--- name +| | |--- available_instances +| | |--- device_api +| | |--- description +| | |--- [devices] +| |--- [<type-id>] +| |--- create +| |--- name +| |--- available_instances +| |--- device_api +| |--- description +| |--- [devices] + +* [mdev_supported_types] + + The list of currently supported mediated device types and their details. + + [<type-id>], device_api, and available_instances are mandatory attributes + that should be provided by vendor driver. + +* [<type-id>] + + The [<type-id>] name is created by adding the the device driver string as a + prefix to the string provided by the vendor driver. This format of this name + is as follows: + + sprintf(buf, "%s-%s", dev_driver_string(parent->dev), group->name); + +* device_api + + This attribute should show which device API is being created, for example, + "vfio-pci" for a PCI device. + +* available_instances + + This attribute should show the number of devices of type <type-id> that can be + created. + +* [device] + + This directory contains links to the devices of type <type-id> that have been +created. + +* name + + This attribute should show human readable name. This is optional attribute. + +* description + + This attribute should show brief features/description of the type. This is + optional attribute. + +Directories and Files Under the sysfs for Each mdev Device +---------------------------------------------------------- + +|- [parent phy device] +|--- [$MDEV_UUID] + |--- remove + |--- mdev_type {link to its type} + |--- vendor-specific-attributes [optional] + +* remove (write only) +Writing '1' to the 'remove' file destroys the mdev device. The vendor driver can +fail the remove() callback if that device is active and the vendor driver +doesn't support hot unplug. + +Example: + # echo 1 > /sys/bus/mdev/devices/$mdev_UUID/remove + +Mediated device Hot plug: +------------------------ + +Mediated devices can be created and assigned at runtime. The procedure to hot +plug a mediated device is the same as the procedure to hot plug a PCI device. + +Translation APIs for Mediated Devices +===================================== + +The following APIs are provided for translating user pfn to host pfn in a VFIO +driver: + +extern int vfio_pin_pages(struct device *dev, unsigned long *user_pfn, + int npage, int prot, unsigned long *phys_pfn); + +extern int vfio_unpin_pages(struct device *dev, unsigned long *user_pfn, + int npage); + +These functions call back into the back-end IOMMU module by using the pin_pages +and unpin_pages callbacks of the struct vfio_iommu_driver_ops[4]. Currently +these callbacks are supported in the TYPE1 IOMMU module. To enable them for +other IOMMU backend modules, such as PPC64 sPAPR module, they need to provide +these two callback functions. + +References +---------- + +[1] See Documentation/vfio.txt for more information on VFIO. +[2] struct mdev_driver in include/linux/mdev.h +[3] struct parent_ops in include/linux/mdev.h +[4] struct vfio_iommu_driver_ops in include/linux/vfio.h
drivers/vfio/mdev/Kconfig +1 -0
@@ -5,6 +5,7 @@ config VFIO_MDEV default n help Provides a framework to virtualize devices. + See Documentation/vfio-mediated-device.txt for more details. If you don't know what do here, say N.
Signature · 1 line
2.7.0
Kirti Wankhede
maintainerPATCH v14 20/22 docs: Sysfs ABI for mediated device framework
In reply to Kirti WankhedeAdded details of sysfs ABI for mediated device framework
--- Documentation/ABI/testing/sysfs-bus-vfio-mdev | 111 ++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-vfio-mdev
Documentation/ABI/testing/sysfs-bus-vfio-mdev new file +111 -0
@@ -0,0 +1,111 @@ +What: /sys/.../<device>/mdev_supported_types/ +Date: October 2016 +Contact: Kirti Wankhede <[email protected]> +Description: + This directory contains list of directories of currently + supported mediated device types and their details for + <device>. Supported type attributes are defined by the + vendor driver who registers with Mediated device framework. + Each supported type is a directory whose name is created + by adding the device driver string as a prefix to the + string provided by the vendor driver. + +What: /sys/.../<device>/mdev_supported_types/<type-id>/ +Date: October 2016 +Contact: Kirti Wankhede <[email protected]> +Description: + This directory gives details of supported type, like name, + description, available_instances, device_api etc. + 'device_api' and 'available_instances' are mandatory + attributes to be provided by vendor driver. 'name', + 'description' and other vendor driver specific attributes + are optional. + +What: /sys/.../mdev_supported_types/<type-id>/create +Date: October 2016 +Contact: Kirti Wankhede <[email protected]> +Description: + Writing UUID to this file will create mediated device of + type <type-id> for parent device <device>. This is a + write-only file. + For example: + # echo "83b8f4f2-509f-382f-3c1e-e6bfe0fa1001" > \ + /sys/devices/foo/mdev_supported_types/foo-1/create + +What: /sys/.../mdev_supported_types/<type-id>/devices/ +Date: October 2016 +Contact: Kirti Wankhede <[email protected]> +Description: + This directory contains symbolic links pointing to mdev + devices sysfs entries which are created of this <type-id>. + +What: /sys/.../mdev_supported_types/<type-id>/available_instances +Date: October 2016 +Contact: Kirti Wankhede <[email protected]> +Description: + Reading this attribute will show the number of mediated + devices of type <type-id> that can be created. This is a + readonly file. +Users: + Userspace applications interested in creating mediated + device of that type. Userspace application should check + the number of available instances could be created before + creating mediated device of this type. + +What: /sys/.../mdev_supported_types/<type-id>/device_api +Date: October 2016 +Contact: Kirti Wankhede <[email protected]> +Description: + Reading this attribute will show VFIO device API supported + by this type. For example, "vfio-pci" for a PCI device, + "vfio-platform" for platform device. + +What: /sys/.../mdev_supported_types/<type-id>/name +Date: October 2016 +Contact: Kirti Wankhede <[email protected]> +Description: + Reading this attribute will show human readable name of the + mediated device that will get created of type <type-id>. + This is optional attribute. For example: "Grid M60-0Q" +Users: + Userspace applications interested in knowing the name of + a particular <type-id> that can help in understanding the + type of mediated device. + +What: /sys/.../mdev_supported_types/<type-id>/description +Date: October 2016 +Contact: Kirti Wankhede <[email protected]> +Description: + Reading this attribute will show description of the type of + mediated device that will get created of type <type-id>. + This is optional attribute. For example: + "2 heads, 512M FB, 2560x1600 maximum resolution" +Users: + Userspace applications interested in knowing the details of + a particular <type-id> that can help in understanding the + features provided by that type of mediated device. + +What: /sys/.../<device>/<UUID>/ +Date: October 2016 +Contact: Kirti Wankhede <[email protected]> +Description: + This directory represents device directory of mediated + device. It contains all the attributes related to mediated + device. + +What: /sys/.../<device>/<UUID>/mdev_type +Date: October 2016 +Contact: Kirti Wankhede <[email protected]> +Description: + This is symbolic link pointing to supported type, <type-id> + directory of which this mediated device is created. + +What: /sys/.../<device>/<UUID>/remove +Date: October 2016 +Contact: Kirti Wankhede <[email protected]> +Description: + Writing '1' to this file destroys the mediated device. The + vendor driver can fail the remove() callback if that device + is active and the vendor driver doesn't support hot unplug. + Example: + # echo 1 > /sys/bus/mdev/devices/<UUID>/remove
Signature · 1 line
2.7.0
Kirti Wankhede
maintainerPATCH v14 21/22 docs: Sample driver to demonstrate how to use Mediated device framework.
In reply to Kirti WankhedeThe Sample driver creates mdev device that simulates serial port over PCI card.
--- Documentation/vfio-mediated-device.txt | 103 ++- samples/vfio-mdev/Makefile | 13 + samples/vfio-mdev/mtty.c | 1503 ++++++++++++++++++++++++++++++++ 3 files changed, 1618 insertions(+), 1 deletion(-) create mode 100644 samples/vfio-mdev/Makefile create mode 100644 samples/vfio-mdev/mtty.c
Documentation/vfio-mediated-device.txt +102 -1
@@ -289,8 +289,109 @@ these callbacks are supported in the TYPE1 IOMMU module. To enable them for other IOMMU backend modules, such as PPC64 sPAPR module, they need to provide these two callback functions. +Using the Sample Code +===================== + +mtty.c in samples/vfio-mdev/ directory is a sample driver program to +demonstrate how to use the mediated device framework. + +The sample driver creates an mdev device that simulates a serial port over a PCI +card. + +1. Build and load the mtty.ko module. + + This step creates a dummy device, /sys/devices/virtual/mtty/mtty/ + + Files in this device directory in sysfs are similar to the following: + + # tree /sys/devices/virtual/mtty/mtty/ + /sys/devices/virtual/mtty/mtty/ + |-- mdev_supported_types + | |-- mtty-1 + | | |-- available_instances + | | |-- create + | | |-- device_api + | | |-- devices + | | `-- name + | `-- mtty-2 + | |-- available_instances + | |-- create + | |-- device_api + | |-- devices + | `-- name + |-- mtty_dev + | `-- sample_mtty_dev + |-- power + | |-- autosuspend_delay_ms + | |-- control + | |-- runtime_active_time + | |-- runtime_status + | `-- runtime_suspended_time + |-- subsystem -> ../../../../class/mtty + `-- uevent + +2. Create a mediated device by using the dummy device that you created in the + previous step. + + # echo "83b8f4f2-509f-382f-3c1e-e6bfe0fa1001" > \ + /sys/devices/virtual/mtty/mtty/mdev_supported_types/mtty-2/create + +3. Add parameters to qemu-kvm. + + -device vfio-pci,\ + sysfsdev=/sys/bus/mdev/devices/83b8f4f2-509f-382f-3c1e-e6bfe0fa1001 + +4. Boot the VM. + + In the Linux guest VM, with no hardware on the host, the device appears + as follows: + + # lspci -s 00:05.0 -xxvv + 00:05.0 Serial controller: Device 4348:3253 (rev 10) (prog-if 02 [16550]) + Subsystem: Device 4348:3253 + Physical Slot: 5 + Control: I/O+ Mem- BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- + Stepping- SERR- FastB2B- DisINTx- + Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=medium >TAbort- + <TAbort- <MAbort- >SERR- <PERR- INTx- + Interrupt: pin A routed to IRQ 10 + Region 0: I/O ports at c150 [size=8] + Region 1: I/O ports at c158 [size=8] + Kernel driver in use: serial + 00: 48 43 53 32 01 00 00 02 10 02 00 07 00 00 00 00 + 10: 51 c1 00 00 59 c1 00 00 00 00 00 00 00 00 00 00 + 20: 00 00 00 00 00 00 00 00 00 00 00 00 48 43 53 32 + 30: 00 00 00 00 00 00 00 00 00 00 00 00 0a 01 00 00 + + In the Linux guest VM, dmesg output for the device is as follows: + + serial 0000:00:05.0: PCI INT A -> Link[LNKA] -> GSI 10 (level, high) -> IRQ +10 + 0000:00:05.0: ttyS1 at I/O 0xc150 (irq = 10) is a 16550A + 0000:00:05.0: ttyS2 at I/O 0xc158 (irq = 10) is a 16550A + + +5. In the Linux guest VM, check the serial ports. + + # setserial -g /dev/ttyS* + /dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4 + /dev/ttyS1, UART: 16550A, Port: 0xc150, IRQ: 10 + /dev/ttyS2, UART: 16550A, Port: 0xc158, IRQ: 10 + +6. Using a minicom or any terminal enulation program, open port /dev/ttyS1 or + /dev/ttyS2 with hardware flow control disabled. + +7. Type data on the minicom terminal or send data to the terminal emulation + program and read the data. + + Data is loop backed from hosts mtty driver. + +8. Destroy the mediated device that you created. + + # echo 1 > /sys/bus/mdev/devices/83b8f4f2-509f-382f-3c1e-e6bfe0fa1001/remove + References ----------- +========== [1] See Documentation/vfio.txt for more information on VFIO. [2] struct mdev_driver in include/linux/mdev.h
samples/vfio-mdev/Makefile new file +13 -0
@@ -0,0 +1,13 @@ +# +# Makefile for mtty.c file +# +KERNEL_DIR:=/lib/modules/$(shell uname -r)/build + +obj-m:=mtty.o + +modules clean modules_install: + $(MAKE) -C $(KERNEL_DIR) SUBDIRS=$(PWD) $@ + +default: modules + +module: modules
samples/vfio-mdev/mtty.c new file +1503 -0
1,503 lines not on this page · raw message
Signature · 1 line
2.7.0
Kirti Wankhede
maintainerPATCH v14 22/22 MAINTAINERS: Add entry VFIO based Mediated device drivers
In reply to Kirti WankhedeAdding myself as a maintainer of mediated device framework, a sub module of VFIO.
--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
@@ -12754,6 +12754,15 @@ F: drivers/vfio/ F: include/linux/vfio.h F: include/uapi/linux/vfio.h +VFIO MEDIATED DEVICE DRIVERS +M: Kirti Wankhede <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/vfio-mediated-device.txt +F: drivers/vfio/mdev/ +F: include/linux/mdev.h +F: samples/vfio-mdev/ + VFIO PLATFORM DRIVER M: Baptiste Reynal <[email protected]> L: [email protected]
Signature · 1 line
2.7.0
Quoted 27 lines · On Thu, 17 Nov 2016 02:16:12 +0530 Kirti Wankhede <[email protected]> wrote:
Documentation/ABI/testing/sysfs-bus-vfio-mdev | 111 ++ Documentation/vfio-mediated-device.txt | 399 +++++++ MAINTAINERS | 9 + drivers/vfio/Kconfig | 1 + drivers/vfio/Makefile | 1 + drivers/vfio/mdev/Kconfig | 17 + drivers/vfio/mdev/Makefile | 5 + drivers/vfio/mdev/mdev_core.c | 385 +++++++ drivers/vfio/mdev/mdev_driver.c | 119 ++ drivers/vfio/mdev/mdev_private.h | 41 + drivers/vfio/mdev/mdev_sysfs.c | 286 +++++ drivers/vfio/mdev/vfio_mdev.c | 180 +++ drivers/vfio/pci/vfio_pci.c | 83 +- drivers/vfio/platform/vfio_platform_common.c | 31 +- drivers/vfio/vfio.c | 340 +++++- drivers/vfio/vfio_iommu_type1.c | 872 +++++++++++--- include/linux/mdev.h | 177 +++ include/linux/vfio.h | 32 +- include/uapi/linux/vfio.h | 10 + samples/vfio-mdev/Makefile | 13 + samples/vfio-mdev/mtty.c | 1503 +++++++++++++++++++++++++ 21 files changed, 4358 insertions(+), 257 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-vfio-mdev create mode 100644 Documentation/vfio-mediated-device.txt create mode 100644 drivers/vfio/mdev/Kconfig create mode 100644 drivers/vfio/mdev/Makefile
Quoted 8 lines
create mode 100644 drivers/vfio/mdev/mdev_core.c create mode 100644 drivers/vfio/mdev/mdev_driver.c create mode 100644 drivers/vfio/mdev/mdev_private.h create mode 100644 drivers/vfio/mdev/mdev_sysfs.c create mode 100644 drivers/vfio/mdev/vfio_mdev.c create mode 100644 include/linux/mdev.h create mode 100644 samples/vfio-mdev/Makefile create mode 100644 samples/vfio-mdev/mtty.c
As discussed, I dropped patch 12, updated the documentation, and added 'retries' initialization. This is now applied to my next branch for v4.10. Thanks to the reviewers and Kirti and Neo for your hard work! Thanks,
Alex
Quoted 38 lines · Alex Williamson
Quoted 27 lines · On Thu, 17 Nov 2016 02:16:12 +0530 Kirti Wankhede <[email protected]> wrote:
Documentation/ABI/testing/sysfs-bus-vfio-mdev | 111 ++ Documentation/vfio-mediated-device.txt | 399 +++++++ MAINTAINERS | 9 + drivers/vfio/Kconfig | 1 + drivers/vfio/Makefile | 1 + drivers/vfio/mdev/Kconfig | 17 + drivers/vfio/mdev/Makefile | 5 + drivers/vfio/mdev/mdev_core.c | 385 +++++++ drivers/vfio/mdev/mdev_driver.c | 119 ++ drivers/vfio/mdev/mdev_private.h | 41 + drivers/vfio/mdev/mdev_sysfs.c | 286 +++++ drivers/vfio/mdev/vfio_mdev.c | 180 +++ drivers/vfio/pci/vfio_pci.c | 83 +- drivers/vfio/platform/vfio_platform_common.c | 31 +- drivers/vfio/vfio.c | 340 +++++- drivers/vfio/vfio_iommu_type1.c | 872 +++++++++++--- include/linux/mdev.h | 177 +++ include/linux/vfio.h | 32 +- include/uapi/linux/vfio.h | 10 + samples/vfio-mdev/Makefile | 13 + samples/vfio-mdev/mtty.c | 1503 +++++++++++++++++++++++++ 21 files changed, 4358 insertions(+), 257 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-vfio-mdev create mode 100644 Documentation/vfio-mediated-device.txt create mode 100644 drivers/vfio/mdev/Kconfig create mode 100644 drivers/vfio/mdev/MakefileQuoted 8 lines
create mode 100644 drivers/vfio/mdev/mdev_core.c create mode 100644 drivers/vfio/mdev/mdev_driver.c create mode 100644 drivers/vfio/mdev/mdev_private.h create mode 100644 drivers/vfio/mdev/mdev_sysfs.c create mode 100644 drivers/vfio/mdev/vfio_mdev.c create mode 100644 include/linux/mdev.h create mode 100644 samples/vfio-mdev/Makefile create mode 100644 samples/vfio-mdev/mtty.c
Quoted 3 lines
As discussed, I dropped patch 12, updated the documentation, and added 'retries' initialization. This is now applied to my next branch for v4.10. Thanks to the reviewers and Kirti and Neo for your hard work!
Really appreciate your help and reviews to allow us reach here, and thanks to various reviewers for their comments and suggestions!
Thanks,
Neo
Quoted 3 lines
Thanks,
Alex
Kirti Wankhede
maintainerQuoted 39 lines · Neo Jia
Quoted 38 lines · Alex Williamson
Quoted 35 lines · On Thu, 17 Nov 2016 02:16:12 +0530 Kirti Wankhede <[email protected]> wrote:
Documentation/ABI/testing/sysfs-bus-vfio-mdev | 111 ++ Documentation/vfio-mediated-device.txt | 399 +++++++ MAINTAINERS | 9 + drivers/vfio/Kconfig | 1 + drivers/vfio/Makefile | 1 + drivers/vfio/mdev/Kconfig | 17 + drivers/vfio/mdev/Makefile | 5 + drivers/vfio/mdev/mdev_core.c | 385 +++++++ drivers/vfio/mdev/mdev_driver.c | 119 ++ drivers/vfio/mdev/mdev_private.h | 41 + drivers/vfio/mdev/mdev_sysfs.c | 286 +++++ drivers/vfio/mdev/vfio_mdev.c | 180 +++ drivers/vfio/pci/vfio_pci.c | 83 +- drivers/vfio/platform/vfio_platform_common.c | 31 +- drivers/vfio/vfio.c | 340 +++++- drivers/vfio/vfio_iommu_type1.c | 872 +++++++++++--- include/linux/mdev.h | 177 +++ include/linux/vfio.h | 32 +- include/uapi/linux/vfio.h | 10 + samples/vfio-mdev/Makefile | 13 + samples/vfio-mdev/mtty.c | 1503 +++++++++++++++++++++++++ 21 files changed, 4358 insertions(+), 257 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-vfio-mdev create mode 100644 Documentation/vfio-mediated-device.txt create mode 100644 drivers/vfio/mdev/Kconfig create mode 100644 drivers/vfio/mdev/Makefile create mode 100644 drivers/vfio/mdev/mdev_core.c create mode 100644 drivers/vfio/mdev/mdev_driver.c create mode 100644 drivers/vfio/mdev/mdev_private.h create mode 100644 drivers/vfio/mdev/mdev_sysfs.c create mode 100644 drivers/vfio/mdev/vfio_mdev.c create mode 100644 include/linux/mdev.h create mode 100644 samples/vfio-mdev/Makefile create mode 100644 samples/vfio-mdev/mtty.c
Quoted 7 lines
Quoted 3 lines
As discussed, I dropped patch 12, updated the documentation, and added 'retries' initialization. This is now applied to my next branch for v4.10. Thanks to the reviewers and Kirti and Neo for your hard work!
Really appreciate your help and reviews to allow us reach here, and thanks to various reviewers for their comments and suggestions!
Thanks for your constant guidance and reviews. Thanks to all reviewers for reviews and suggestions.
Thanks,
Kirti
Quoted 44 lines · Kirti Wankhede
Quoted 43 lines · Neo Jia
Quoted 41 lines · Alex Williamson
Quoted 27 lines · On Thu, 17 Nov 2016 02:16:12 +0530 Kirti Wankhede <[email protected]> wrote:
Documentation/ABI/testing/sysfs-bus-vfio-mdev | 111 ++ Documentation/vfio-mediated-device.txt | 399 +++++++ MAINTAINERS | 9 + drivers/vfio/Kconfig | 1 + drivers/vfio/Makefile | 1 + drivers/vfio/mdev/Kconfig | 17 + drivers/vfio/mdev/Makefile | 5 + drivers/vfio/mdev/mdev_core.c | 385 +++++++ drivers/vfio/mdev/mdev_driver.c | 119 ++ drivers/vfio/mdev/mdev_private.h | 41 + drivers/vfio/mdev/mdev_sysfs.c | 286 +++++ drivers/vfio/mdev/vfio_mdev.c | 180 +++ drivers/vfio/pci/vfio_pci.c | 83 +- drivers/vfio/platform/vfio_platform_common.c | 31 +- drivers/vfio/vfio.c | 340 +++++- drivers/vfio/vfio_iommu_type1.c | 872 +++++++++++--- include/linux/mdev.h | 177 +++ include/linux/vfio.h | 32 +- include/uapi/linux/vfio.h | 10 + samples/vfio-mdev/Makefile | 13 + samples/vfio-mdev/mtty.c | 1503 +++++++++++++++++++++++++ 21 files changed, 4358 insertions(+), 257 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-vfio-mdev create mode 100644 Documentation/vfio-mediated-device.txt create mode 100644 drivers/vfio/mdev/Kconfig create mode 100644 drivers/vfio/mdev/MakefileQuoted 8 lines
create mode 100644 drivers/vfio/mdev/mdev_core.c create mode 100644 drivers/vfio/mdev/mdev_driver.c create mode 100644 drivers/vfio/mdev/mdev_private.h create mode 100644 drivers/vfio/mdev/mdev_sysfs.c create mode 100644 drivers/vfio/mdev/vfio_mdev.c create mode 100644 include/linux/mdev.h create mode 100644 samples/vfio-mdev/Makefile create mode 100644 samples/vfio-mdev/mtty.cAs discussed, I dropped patch 12, updated the documentation, and added 'retries' initialization. This is now applied to my next branch for v4.10. Thanks to the reviewers and Kirti and Neo for your hard work!
Quoted 6 lines
Quoted 3 lines
Really appreciate your help and reviews to allow us reach here, and thanks to various reviewers for their comments and suggestions!
Thanks for your constant guidance and reviews. Thanks to all reviewers for reviews and suggestions.
Echo Alex: thanks for your great work, congrats! :-)
--
Thanks,
Jike
Quoted 42 lines
From: Alex Williamson [mailto:[email protected]]
Sent: Friday, November 18, 2016 5:25 AMQuoted 14 lines · On Thu, 17 Nov 2016 02:16:12 +0530 Kirti Wankhede <[email protected]> wrote:
Documentation/ABI/testing/sysfs-bus-vfio-mdev | 111 ++ Documentation/vfio-mediated-device.txt | 399 +++++++ MAINTAINERS | 9 + drivers/vfio/Kconfig | 1 + drivers/vfio/Makefile | 1 + drivers/vfio/mdev/Kconfig | 17 + drivers/vfio/mdev/Makefile | 5 + drivers/vfio/mdev/mdev_core.c | 385 +++++++ drivers/vfio/mdev/mdev_driver.c | 119 ++ drivers/vfio/mdev/mdev_private.h | 41 + drivers/vfio/mdev/mdev_sysfs.c | 286 +++++ drivers/vfio/mdev/vfio_mdev.c | 180 +++ drivers/vfio/pci/vfio_pci.c | 83 +-Quoted 8 lines
drivers/vfio/platform/vfio_platform_common.c | 31 +- drivers/vfio/vfio.c | 340 +++++- drivers/vfio/vfio_iommu_type1.c | 872 +++++++++++--- include/linux/mdev.h | 177 +++ include/linux/vfio.h | 32 +- include/uapi/linux/vfio.h | 10 + samples/vfio-mdev/Makefile | 13 + samples/vfio-mdev/mtty.c | 1503+++++++++++++++++++++++++
Quoted 5 lines
21 files changed, 4358 insertions(+), 257 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-vfio-mdev create mode 100644 Documentation/vfio-mediated-device.txt create mode 100644 drivers/vfio/mdev/Kconfig create mode 100644 drivers/vfio/mdev/MakefileQuoted 8 lines
create mode 100644 drivers/vfio/mdev/mdev_core.c create mode 100644 drivers/vfio/mdev/mdev_driver.c create mode 100644 drivers/vfio/mdev/mdev_private.h create mode 100644 drivers/vfio/mdev/mdev_sysfs.c create mode 100644 drivers/vfio/mdev/vfio_mdev.c create mode 100644 include/linux/mdev.h create mode 100644 samples/vfio-mdev/Makefile create mode 100644 samples/vfio-mdev/mtty.c
Quoted 5 lines
As discussed, I dropped patch 12, updated the documentation, and added 'retries' initialization. This is now applied to my next branch for v4.10. Thanks to the reviewers and Kirti and Neo for your hard work! Thanks,
That's a great news! Alex, do you have an idea when this series may hit linux-next? :-)
Thanks
Kevin
Quoted 42 lines · Kevin
Quoted 42 lines
From: Alex Williamson [mailto:[email protected]]
Sent: Friday, November 18, 2016 5:25 AMQuoted 14 lines · On Thu, 17 Nov 2016 02:16:12 +0530 Kirti Wankhede <[email protected]> wrote:
Documentation/ABI/testing/sysfs-bus-vfio-mdev | 111 ++ Documentation/vfio-mediated-device.txt | 399 +++++++ MAINTAINERS | 9 + drivers/vfio/Kconfig | 1 + drivers/vfio/Makefile | 1 + drivers/vfio/mdev/Kconfig | 17 + drivers/vfio/mdev/Makefile | 5 + drivers/vfio/mdev/mdev_core.c | 385 +++++++ drivers/vfio/mdev/mdev_driver.c | 119 ++ drivers/vfio/mdev/mdev_private.h | 41 + drivers/vfio/mdev/mdev_sysfs.c | 286 +++++ drivers/vfio/mdev/vfio_mdev.c | 180 +++ drivers/vfio/pci/vfio_pci.c | 83 +-Quoted 8 lines
drivers/vfio/platform/vfio_platform_common.c | 31 +- drivers/vfio/vfio.c | 340 +++++- drivers/vfio/vfio_iommu_type1.c | 872 +++++++++++--- include/linux/mdev.h | 177 +++ include/linux/vfio.h | 32 +- include/uapi/linux/vfio.h | 10 + samples/vfio-mdev/Makefile | 13 + samples/vfio-mdev/mtty.c | 1503+++++++++++++++++++++++++
Quoted 13 lines
21 files changed, 4358 insertions(+), 257 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-vfio-mdev create mode 100644 Documentation/vfio-mediated-device.txt create mode 100644 drivers/vfio/mdev/Kconfig create mode 100644 drivers/vfio/mdev/Makefile create mode 100644 drivers/vfio/mdev/mdev_core.c create mode 100644 drivers/vfio/mdev/mdev_driver.c create mode 100644 drivers/vfio/mdev/mdev_private.h create mode 100644 drivers/vfio/mdev/mdev_sysfs.c create mode 100644 drivers/vfio/mdev/vfio_mdev.c create mode 100644 include/linux/mdev.h create mode 100644 samples/vfio-mdev/Makefile create mode 100644 samples/vfio-mdev/mtty.c
Quoted 8 lines
Quoted 5 lines
As discussed, I dropped patch 12, updated the documentation, and added 'retries' initialization. This is now applied to my next branch for v4.10. Thanks to the reviewers and Kirti and Neo for your hard work! Thanks,
That's a great news! Alex, do you have an idea when this series may hit linux-next? :-)
Whenever there's a new build, hopefully within the next 24hrs, but I don't really know the schedule. Thanks,
Alex
Quoted 51 lines · Alex Williamson
Quoted 48 lines · Kevin
Quoted 47 lines
From: Alex Williamson [mailto:[email protected]]
Sent: Friday, November 18, 2016 5:25 AMQuoted 14 lines · On Thu, 17 Nov 2016 02:16:12 +0530 Kirti Wankhede <[email protected]> wrote:
Documentation/ABI/testing/sysfs-bus-vfio-mdev | 111 ++ Documentation/vfio-mediated-device.txt | 399 +++++++ MAINTAINERS | 9 + drivers/vfio/Kconfig | 1 + drivers/vfio/Makefile | 1 + drivers/vfio/mdev/Kconfig | 17 + drivers/vfio/mdev/Makefile | 5 + drivers/vfio/mdev/mdev_core.c | 385 +++++++ drivers/vfio/mdev/mdev_driver.c | 119 ++ drivers/vfio/mdev/mdev_private.h | 41 + drivers/vfio/mdev/mdev_sysfs.c | 286 +++++ drivers/vfio/mdev/vfio_mdev.c | 180 +++ drivers/vfio/pci/vfio_pci.c | 83 +-Quoted 8 lines
drivers/vfio/platform/vfio_platform_common.c | 31 +- drivers/vfio/vfio.c | 340 +++++- drivers/vfio/vfio_iommu_type1.c | 872 +++++++++++--- include/linux/mdev.h | 177 +++ include/linux/vfio.h | 32 +- include/uapi/linux/vfio.h | 10 + samples/vfio-mdev/Makefile | 13 + samples/vfio-mdev/mtty.c | 1503+++++++++++++++++++++++++
Quoted 5 lines
21 files changed, 4358 insertions(+), 257 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-vfio-mdev create mode 100644 Documentation/vfio-mediated-device.txt create mode 100644 drivers/vfio/mdev/Kconfig create mode 100644 drivers/vfio/mdev/MakefileQuoted 8 lines
create mode 100644 drivers/vfio/mdev/mdev_core.c create mode 100644 drivers/vfio/mdev/mdev_driver.c create mode 100644 drivers/vfio/mdev/mdev_private.h create mode 100644 drivers/vfio/mdev/mdev_sysfs.c create mode 100644 drivers/vfio/mdev/vfio_mdev.c create mode 100644 include/linux/mdev.h create mode 100644 samples/vfio-mdev/Makefile create mode 100644 samples/vfio-mdev/mtty.cAs discussed, I dropped patch 12, updated the documentation, and added 'retries' initialization. This is now applied to my next branch for v4.10. Thanks to the reviewers and Kirti and Neo for your hard work! Thanks,
Quoted 5 lines
Quoted 2 lines
That's a great news! Alex, do you have an idea when this series may hit linux-next? :-)
Whenever there's a new build, hopefully within the next 24hrs, but I don't really know the schedule. Thanks,
Great news! Can't wait to try the upstream version. :->
Thanks everybody that makes this happen!!
Quoted 3 lines
Alex
Signature · 1 line
Dong Jia
Quoted 51 lines · Alex Williamson
Quoted 48 lines · Kevin
Quoted 47 lines
From: Alex Williamson [mailto:[email protected]]
Sent: Friday, November 18, 2016 5:25 AMQuoted 14 lines · On Thu, 17 Nov 2016 02:16:12 +0530 Kirti Wankhede <[email protected]> wrote:
Documentation/ABI/testing/sysfs-bus-vfio-mdev | 111 ++ Documentation/vfio-mediated-device.txt | 399 +++++++ MAINTAINERS | 9 + drivers/vfio/Kconfig | 1 + drivers/vfio/Makefile | 1 + drivers/vfio/mdev/Kconfig | 17 + drivers/vfio/mdev/Makefile | 5 + drivers/vfio/mdev/mdev_core.c | 385 +++++++ drivers/vfio/mdev/mdev_driver.c | 119 ++ drivers/vfio/mdev/mdev_private.h | 41 + drivers/vfio/mdev/mdev_sysfs.c | 286 +++++ drivers/vfio/mdev/vfio_mdev.c | 180 +++ drivers/vfio/pci/vfio_pci.c | 83 +-Quoted 8 lines
drivers/vfio/platform/vfio_platform_common.c | 31 +- drivers/vfio/vfio.c | 340 +++++- drivers/vfio/vfio_iommu_type1.c | 872 +++++++++++--- include/linux/mdev.h | 177 +++ include/linux/vfio.h | 32 +- include/uapi/linux/vfio.h | 10 + samples/vfio-mdev/Makefile | 13 + samples/vfio-mdev/mtty.c | 1503+++++++++++++++++++++++++
Quoted 5 lines
21 files changed, 4358 insertions(+), 257 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-vfio-mdev create mode 100644 Documentation/vfio-mediated-device.txt create mode 100644 drivers/vfio/mdev/Kconfig create mode 100644 drivers/vfio/mdev/MakefileQuoted 8 lines
create mode 100644 drivers/vfio/mdev/mdev_core.c create mode 100644 drivers/vfio/mdev/mdev_driver.c create mode 100644 drivers/vfio/mdev/mdev_private.h create mode 100644 drivers/vfio/mdev/mdev_sysfs.c create mode 100644 drivers/vfio/mdev/vfio_mdev.c create mode 100644 include/linux/mdev.h create mode 100644 samples/vfio-mdev/Makefile create mode 100644 samples/vfio-mdev/mtty.cAs discussed, I dropped patch 12, updated the documentation, and added 'retries' initialization. This is now applied to my next branch for v4.10. Thanks to the reviewers and Kirti and Neo for your hard work! Thanks,
Quoted 5 lines
Quoted 2 lines
That's a great news! Alex, do you have an idea when this series may hit linux-next? :-)
Whenever there's a new build, hopefully within the next 24hrs, but I don't really know the schedule. Thanks,
Great news! Can't wait to try the upstream version. :->
Thanks everybody that makes this happen!!
Quoted 3 lines
Alex
Signature · 1 line
Dong Jia
Quoted 51 lines · Alex Williamson
Quoted 48 lines · Kevin
Quoted 47 lines
From: Alex Williamson [mailto:[email protected]]
Sent: Friday, November 18, 2016 5:25 AMQuoted 14 lines · On Thu, 17 Nov 2016 02:16:12 +0530 Kirti Wankhede <[email protected]> wrote:
Documentation/ABI/testing/sysfs-bus-vfio-mdev | 111 ++ Documentation/vfio-mediated-device.txt | 399 +++++++ MAINTAINERS | 9 + drivers/vfio/Kconfig | 1 + drivers/vfio/Makefile | 1 + drivers/vfio/mdev/Kconfig | 17 + drivers/vfio/mdev/Makefile | 5 + drivers/vfio/mdev/mdev_core.c | 385 +++++++ drivers/vfio/mdev/mdev_driver.c | 119 ++ drivers/vfio/mdev/mdev_private.h | 41 + drivers/vfio/mdev/mdev_sysfs.c | 286 +++++ drivers/vfio/mdev/vfio_mdev.c | 180 +++ drivers/vfio/pci/vfio_pci.c | 83 +-Quoted 8 lines
drivers/vfio/platform/vfio_platform_common.c | 31 +- drivers/vfio/vfio.c | 340 +++++- drivers/vfio/vfio_iommu_type1.c | 872 +++++++++++--- include/linux/mdev.h | 177 +++ include/linux/vfio.h | 32 +- include/uapi/linux/vfio.h | 10 + samples/vfio-mdev/Makefile | 13 + samples/vfio-mdev/mtty.c | 1503+++++++++++++++++++++++++
Quoted 5 lines
21 files changed, 4358 insertions(+), 257 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-vfio-mdev create mode 100644 Documentation/vfio-mediated-device.txt create mode 100644 drivers/vfio/mdev/Kconfig create mode 100644 drivers/vfio/mdev/MakefileQuoted 8 lines
create mode 100644 drivers/vfio/mdev/mdev_core.c create mode 100644 drivers/vfio/mdev/mdev_driver.c create mode 100644 drivers/vfio/mdev/mdev_private.h create mode 100644 drivers/vfio/mdev/mdev_sysfs.c create mode 100644 drivers/vfio/mdev/vfio_mdev.c create mode 100644 include/linux/mdev.h create mode 100644 samples/vfio-mdev/Makefile create mode 100644 samples/vfio-mdev/mtty.cAs discussed, I dropped patch 12, updated the documentation, and added 'retries' initialization. This is now applied to my next branch for v4.10. Thanks to the reviewers and Kirti and Neo for your hard work! Thanks,
Quoted 6 lines
Quoted 2 lines
That's a great news! Alex, do you have an idea when this series may hit linux-next? :-)
Whenever there's a new build, hopefully within the next 24hrs, but I don't really know the schedule. Thanks,
Alex, could you do a pull request of mdev for Daniel's drm-intel tree? We need to send KVMGT mdev support pull base on that.
Thanks!
Signature · 3 lines
Open Source Technology Center, Intel ltd. $gpg --keyserver wwwkeys.pgp.net --recv-keys 4D781827
Quoted 55 lines · On Fri, 18 Nov 2016 17:16:32 +0800 Zhenyu Wang <[email protected]> wrote:
Quoted 54 lines · Alex Williamson
Quoted 50 lines · Kevin
Quoted 42 lines
From: Alex Williamson [mailto:[email protected]]
Sent: Friday, November 18, 2016 5:25 AMQuoted 14 lines · On Thu, 17 Nov 2016 02:16:12 +0530 Kirti Wankhede <[email protected]> wrote:
Documentation/ABI/testing/sysfs-bus-vfio-mdev | 111 ++ Documentation/vfio-mediated-device.txt | 399 +++++++ MAINTAINERS | 9 + drivers/vfio/Kconfig | 1 + drivers/vfio/Makefile | 1 + drivers/vfio/mdev/Kconfig | 17 + drivers/vfio/mdev/Makefile | 5 + drivers/vfio/mdev/mdev_core.c | 385 +++++++ drivers/vfio/mdev/mdev_driver.c | 119 ++ drivers/vfio/mdev/mdev_private.h | 41 + drivers/vfio/mdev/mdev_sysfs.c | 286 +++++ drivers/vfio/mdev/vfio_mdev.c | 180 +++ drivers/vfio/pci/vfio_pci.c | 83 +-Quoted 8 lines
drivers/vfio/platform/vfio_platform_common.c | 31 +- drivers/vfio/vfio.c | 340 +++++- drivers/vfio/vfio_iommu_type1.c | 872 +++++++++++--- include/linux/mdev.h | 177 +++ include/linux/vfio.h | 32 +- include/uapi/linux/vfio.h | 10 + samples/vfio-mdev/Makefile | 13 + samples/vfio-mdev/mtty.c | 1503+++++++++++++++++++++++++
Quoted 5 lines
21 files changed, 4358 insertions(+), 257 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-vfio-mdev create mode 100644 Documentation/vfio-mediated-device.txt create mode 100644 drivers/vfio/mdev/Kconfig create mode 100644 drivers/vfio/mdev/MakefileQuoted 8 lines
create mode 100644 drivers/vfio/mdev/mdev_core.c create mode 100644 drivers/vfio/mdev/mdev_driver.c create mode 100644 drivers/vfio/mdev/mdev_private.h create mode 100644 drivers/vfio/mdev/mdev_sysfs.c create mode 100644 drivers/vfio/mdev/vfio_mdev.c create mode 100644 include/linux/mdev.h create mode 100644 samples/vfio-mdev/Makefile create mode 100644 samples/vfio-mdev/mtty.cQuoted 5 lines
As discussed, I dropped patch 12, updated the documentation, and added 'retries' initialization. This is now applied to my next branch for v4.10. Thanks to the reviewers and Kirti and Neo for your hard work! Thanks,
That's a great news! Alex, do you have an idea when this series may hit linux-next? :-)
Quoted 6 lines
Quoted 3 lines
Whenever there's a new build, hopefully within the next 24hrs, but I don't really know the schedule. Thanks,
Alex, could you do a pull request of mdev for Daniel's drm-intel tree? We need to send KVMGT mdev support pull base on that.
No, this is not how I intend or prefer to merge this. This is a large change for vfio and it is not exclusive to KVMGT. We have linux-next to facilitate handling dependencies between subsystems during development and a two week merge window to allow managing how these changes enter the mainline tree. If I were to have this pulled into drm-intel it ties my hands as to how I can manage changes within my functional area. I want these two weeks of linux-next exposure for vetting the changes and resolving any remaining issues. I'm not going to compromise my ability to react to such issues. linux-next inclusion should be sufficient for you to coordinate through the drm tree, though Daniel will need to be made aware of the dependency. I will however plan to send my pull request to Linus early in the merge window to accommodate dependent changes also being included for v4.10. Hope you understand, thanks,
Alex
Quoted 17 lines · Alex Williamson
Quoted 2 lines
Alex, could you do a pull request of mdev for Daniel's drm-intel tree? We need to send KVMGT mdev support pull base on that.
No, this is not how I intend or prefer to merge this. This is a large change for vfio and it is not exclusive to KVMGT. We have linux-next to facilitate handling dependencies between subsystems during development and a two week merge window to allow managing how these changes enter the mainline tree. If I were to have this pulled into drm-intel it ties my hands as to how I can manage changes within my functional area. I want these two weeks of linux-next exposure for vetting the changes and resolving any remaining issues. I'm not going to compromise my ability to react to such issues. linux-next inclusion should be sufficient for you to coordinate through the drm tree, though Daniel will need to be made aware of the dependency. I will however plan to send my pull request to Linus early in the merge window to accommodate dependent changes also being included for v4.10. Hope you understand, thanks,
My understanding was that the mdev changes are needed to be able to apply the kvmgt stuff, and otherwise it won't build. For that I need a stable git tag&pull request (can be specific topic branch, which means subsystems can land in any order, or the full subsystem tree, which means depencies need to be tracked correctly). I am not going to resolve that in the merge window, since in drm we want everything lined up _before_ that opens (the feature cutoff is this w/e, but there's some wiggle room ofc).
Sounds like there's just not enough time to line all the things up in time for 4.10, and the i915/kmvgt stuff needs to be postponed to 4.11. -Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 29 lines · On Fri, 18 Nov 2016 17:09:59 +0100 Daniel Vetter <[email protected]> wrote:
Quoted 17 lines · Alex Williamson
Quoted 2 lines
Alex, could you do a pull request of mdev for Daniel's drm-intel tree? We need to send KVMGT mdev support pull base on that.
No, this is not how I intend or prefer to merge this. This is a large change for vfio and it is not exclusive to KVMGT. We have linux-next to facilitate handling dependencies between subsystems during development and a two week merge window to allow managing how these changes enter the mainline tree. If I were to have this pulled into drm-intel it ties my hands as to how I can manage changes within my functional area. I want these two weeks of linux-next exposure for vetting the changes and resolving any remaining issues. I'm not going to compromise my ability to react to such issues. linux-next inclusion should be sufficient for you to coordinate through the drm tree, though Daniel will need to be made aware of the dependency. I will however plan to send my pull request to Linus early in the merge window to accommodate dependent changes also being included for v4.10. Hope you understand, thanks,
My understanding was that the mdev changes are needed to be able to apply the kvmgt stuff, and otherwise it won't build. For that I need a stable git tag&pull request (can be specific topic branch, which means subsystems can land in any order, or the full subsystem tree, which means depencies need to be tracked correctly). I am not going to resolve that in the merge window, since in drm we want everything lined up _before_ that opens (the feature cutoff is this w/e, but there's some wiggle room ofc).
Quoted 2 lines
Sounds like there's just not enough time to line all the things up in time for 4.10, and the i915/kmvgt stuff needs to be postponed to 4.11.
My only alternate suggestion is that perhaps the KVMGT code can be sufficiently partitioned off with #ifdefs that could be removed later, allowing mdev and KVMGT to be merged independently. We have only just added mdev to linux-next, my intention is that the next two weeks are for finding and correcting issues. There are still outstanding API changes, specifically for KVMGT being proposed by Intel included with that. Thanks,
Alex