Commit 30aec6e1 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'vfio-v6.10-rc1' of https://github.com/awilliam/linux-vfio

Pull vfio updates from Alex Williamson:

 - The vfio fsl-mc bus driver has become orphaned. We'll consider
   removing it in future releases if a new maintainer isn't found (Alex
   Williamson)

 - Improved usage of opaque data in vfio-pci INTx handling, avoiding
   lookups of the eventfd through the interrupt and irqfd runtime paths
   (Alex Williamson)

 - Resolve an error path memory leak introduced in vfio-pci interrupt
   code (Ye Bin)

 - Addition of interrupt support for vfio devices exposed on the CDX
   bus, including a new MSI allocation helper and export of existing
   helpers for MSI alloc and free (Nipun Gupta)

 - A new vfio-pci variant driver supporting migration of Intel QAT VF
   devices for the GEN4 PFs (Xin Zeng & Yahui Cao)

 - Resolve a possibly circular locking dependency in vfio-pci by
   avoiding copy_to_user() from a PCI bus walk callback (Alex
   Williamson)

 - Trivial docs update to remove a duplicate semicolon (Foryun Ma)

* tag 'vfio-v6.10-rc1' of https://github.com/awilliam/linux-vfio:
  vfio/pci: Restore zero affected bus reset devices warning
  vfio: remove an extra semicolon
  vfio/pci: Collect hot-reset devices to local buffer
  vfio/qat: Add vfio_pci driver for Intel QAT SR-IOV VF devices
  vfio/cdx: add interrupt support
  genirq/msi: Add MSI allocation helper and export MSI functions
  vfio/pci: fix potential memory leak in vfio_intx_enable()
  vfio/pci: Pass eventfd context object through irqfd
  vfio/pci: Pass eventfd context to IRQ handler
  MAINTAINERS: Orphan vfio fsl-mc bus driver
parents 70ec81c2 cbb325e7
...@@ -364,7 +364,7 @@ IOMMUFD IOAS/HWPT to enable userspace DMA:: ...@@ -364,7 +364,7 @@ IOMMUFD IOAS/HWPT to enable userspace DMA::
MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
map.iova = 0; /* 1MB starting at 0x0 from device view */ map.iova = 0; /* 1MB starting at 0x0 from device view */
map.length = 1024 * 1024; map.length = 1024 * 1024;
map.ioas_id = alloc_data.out_ioas_id;; map.ioas_id = alloc_data.out_ioas_id;
ioctl(iommufd, IOMMU_IOAS_MAP, &map); ioctl(iommufd, IOMMU_IOAS_MAP, &map);
......
...@@ -23512,9 +23512,8 @@ F: include/linux/vfio_pci_core.h ...@@ -23512,9 +23512,8 @@ F: include/linux/vfio_pci_core.h
F: include/uapi/linux/vfio.h F: include/uapi/linux/vfio.h
VFIO FSL-MC DRIVER VFIO FSL-MC DRIVER
M: Diana Craciun <diana.craciun@oss.nxp.com>
L: kvm@vger.kernel.org L: kvm@vger.kernel.org
S: Maintained S: Orphan
F: drivers/vfio/fsl-mc/ F: drivers/vfio/fsl-mc/
VFIO HISILICON PCI DRIVER VFIO HISILICON PCI DRIVER
...@@ -23568,6 +23567,14 @@ L: kvm@vger.kernel.org ...@@ -23568,6 +23567,14 @@ L: kvm@vger.kernel.org
S: Maintained S: Maintained
F: drivers/vfio/platform/ F: drivers/vfio/platform/
VFIO QAT PCI DRIVER
M: Xin Zeng <xin.zeng@intel.com>
M: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
L: kvm@vger.kernel.org
L: qat-linux@intel.com
S: Supported
F: drivers/vfio/pci/qat/
VFIO VIRTIO PCI DRIVER VFIO VIRTIO PCI DRIVER
M: Yishai Hadas <yishaih@nvidia.com> M: Yishai Hadas <yishaih@nvidia.com>
L: kvm@vger.kernel.org L: kvm@vger.kernel.org
......
...@@ -5,4 +5,4 @@ ...@@ -5,4 +5,4 @@
obj-$(CONFIG_VFIO_CDX) += vfio-cdx.o obj-$(CONFIG_VFIO_CDX) += vfio-cdx.o
vfio-cdx-objs := main.o vfio-cdx-objs := main.o intr.o
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
*/
#include <linux/vfio.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/eventfd.h>
#include <linux/msi.h>
#include <linux/interrupt.h>
#include "linux/cdx/cdx_bus.h"
#include "private.h"
static irqreturn_t vfio_cdx_msihandler(int irq_no, void *arg)
{
struct eventfd_ctx *trigger = arg;
eventfd_signal(trigger);
return IRQ_HANDLED;
}
static int vfio_cdx_msi_enable(struct vfio_cdx_device *vdev, int nvec)
{
struct cdx_device *cdx_dev = to_cdx_device(vdev->vdev.dev);
struct device *dev = vdev->vdev.dev;
int msi_idx, ret;
vdev->cdx_irqs = kcalloc(nvec, sizeof(struct vfio_cdx_irq), GFP_KERNEL);
if (!vdev->cdx_irqs)
return -ENOMEM;
ret = cdx_enable_msi(cdx_dev);
if (ret) {
kfree(vdev->cdx_irqs);
return ret;
}
/* Allocate cdx MSIs */
ret = msi_domain_alloc_irqs(dev, MSI_DEFAULT_DOMAIN, nvec);
if (ret) {
cdx_disable_msi(cdx_dev);
kfree(vdev->cdx_irqs);
return ret;
}
for (msi_idx = 0; msi_idx < nvec; msi_idx++)
vdev->cdx_irqs[msi_idx].irq_no = msi_get_virq(dev, msi_idx);
vdev->msi_count = nvec;
vdev->config_msi = 1;
return 0;
}
static int vfio_cdx_msi_set_vector_signal(struct vfio_cdx_device *vdev,
int vector, int fd)
{
struct eventfd_ctx *trigger;
int irq_no, ret;
if (vector < 0 || vector >= vdev->msi_count)
return -EINVAL;
irq_no = vdev->cdx_irqs[vector].irq_no;
if (vdev->cdx_irqs[vector].trigger) {
free_irq(irq_no, vdev->cdx_irqs[vector].trigger);
kfree(vdev->cdx_irqs[vector].name);
eventfd_ctx_put(vdev->cdx_irqs[vector].trigger);
vdev->cdx_irqs[vector].trigger = NULL;
}
if (fd < 0)
return 0;
vdev->cdx_irqs[vector].name = kasprintf(GFP_KERNEL, "vfio-msi[%d](%s)",
vector, dev_name(vdev->vdev.dev));
if (!vdev->cdx_irqs[vector].name)
return -ENOMEM;
trigger = eventfd_ctx_fdget(fd);
if (IS_ERR(trigger)) {
kfree(vdev->cdx_irqs[vector].name);
return PTR_ERR(trigger);
}
ret = request_irq(irq_no, vfio_cdx_msihandler, 0,
vdev->cdx_irqs[vector].name, trigger);
if (ret) {
kfree(vdev->cdx_irqs[vector].name);
eventfd_ctx_put(trigger);
return ret;
}
vdev->cdx_irqs[vector].trigger = trigger;
return 0;
}
static int vfio_cdx_msi_set_block(struct vfio_cdx_device *vdev,
unsigned int start, unsigned int count,
int32_t *fds)
{
int i, j, ret = 0;
if (start >= vdev->msi_count || start + count > vdev->msi_count)
return -EINVAL;
for (i = 0, j = start; i < count && !ret; i++, j++) {
int fd = fds ? fds[i] : -1;
ret = vfio_cdx_msi_set_vector_signal(vdev, j, fd);
}
if (ret) {
for (--j; j >= (int)start; j--)
vfio_cdx_msi_set_vector_signal(vdev, j, -1);
}
return ret;
}
static void vfio_cdx_msi_disable(struct vfio_cdx_device *vdev)
{
struct cdx_device *cdx_dev = to_cdx_device(vdev->vdev.dev);
struct device *dev = vdev->vdev.dev;
vfio_cdx_msi_set_block(vdev, 0, vdev->msi_count, NULL);
if (!vdev->config_msi)
return;
msi_domain_free_irqs_all(dev, MSI_DEFAULT_DOMAIN);
cdx_disable_msi(cdx_dev);
kfree(vdev->cdx_irqs);
vdev->cdx_irqs = NULL;
vdev->msi_count = 0;
vdev->config_msi = 0;
}
static int vfio_cdx_set_msi_trigger(struct vfio_cdx_device *vdev,
unsigned int index, unsigned int start,
unsigned int count, u32 flags,
void *data)
{
struct cdx_device *cdx_dev = to_cdx_device(vdev->vdev.dev);
int i;
if (start + count > cdx_dev->num_msi)
return -EINVAL;
if (!count && (flags & VFIO_IRQ_SET_DATA_NONE)) {
vfio_cdx_msi_disable(vdev);
return 0;
}
if (flags & VFIO_IRQ_SET_DATA_EVENTFD) {
s32 *fds = data;
int ret;
if (vdev->config_msi)
return vfio_cdx_msi_set_block(vdev, start, count,
fds);
ret = vfio_cdx_msi_enable(vdev, cdx_dev->num_msi);
if (ret)
return ret;
ret = vfio_cdx_msi_set_block(vdev, start, count, fds);
if (ret)
vfio_cdx_msi_disable(vdev);
return ret;
}
for (i = start; i < start + count; i++) {
if (!vdev->cdx_irqs[i].trigger)
continue;
if (flags & VFIO_IRQ_SET_DATA_NONE) {
eventfd_signal(vdev->cdx_irqs[i].trigger);
} else if (flags & VFIO_IRQ_SET_DATA_BOOL) {
u8 *bools = data;
if (bools[i - start])
eventfd_signal(vdev->cdx_irqs[i].trigger);
}
}
return 0;
}
int vfio_cdx_set_irqs_ioctl(struct vfio_cdx_device *vdev,
u32 flags, unsigned int index,
unsigned int start, unsigned int count,
void *data)
{
if (flags & VFIO_IRQ_SET_ACTION_TRIGGER)
return vfio_cdx_set_msi_trigger(vdev, index, start,
count, flags, data);
else
return -EINVAL;
}
/* Free All IRQs for the given device */
void vfio_cdx_irqs_cleanup(struct vfio_cdx_device *vdev)
{
/*
* Device does not support any interrupt or the interrupts
* were not configured
*/
if (!vdev->cdx_irqs)
return;
vfio_cdx_set_msi_trigger(vdev, 0, 0, 0, VFIO_IRQ_SET_DATA_NONE, NULL);
}
...@@ -61,6 +61,7 @@ static void vfio_cdx_close_device(struct vfio_device *core_vdev) ...@@ -61,6 +61,7 @@ static void vfio_cdx_close_device(struct vfio_device *core_vdev)
kfree(vdev->regions); kfree(vdev->regions);
cdx_dev_reset(core_vdev->dev); cdx_dev_reset(core_vdev->dev);
vfio_cdx_irqs_cleanup(vdev);
} }
static int vfio_cdx_bm_ctrl(struct vfio_device *core_vdev, u32 flags, static int vfio_cdx_bm_ctrl(struct vfio_device *core_vdev, u32 flags,
...@@ -123,7 +124,7 @@ static int vfio_cdx_ioctl_get_info(struct vfio_cdx_device *vdev, ...@@ -123,7 +124,7 @@ static int vfio_cdx_ioctl_get_info(struct vfio_cdx_device *vdev,
info.flags |= VFIO_DEVICE_FLAGS_RESET; info.flags |= VFIO_DEVICE_FLAGS_RESET;
info.num_regions = cdx_dev->res_count; info.num_regions = cdx_dev->res_count;
info.num_irqs = 0; info.num_irqs = cdx_dev->num_msi ? 1 : 0;
return copy_to_user(arg, &info, minsz) ? -EFAULT : 0; return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
} }
...@@ -152,6 +153,62 @@ static int vfio_cdx_ioctl_get_region_info(struct vfio_cdx_device *vdev, ...@@ -152,6 +153,62 @@ static int vfio_cdx_ioctl_get_region_info(struct vfio_cdx_device *vdev,
return copy_to_user(arg, &info, minsz) ? -EFAULT : 0; return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
} }
static int vfio_cdx_ioctl_get_irq_info(struct vfio_cdx_device *vdev,
struct vfio_irq_info __user *arg)
{
unsigned long minsz = offsetofend(struct vfio_irq_info, count);
struct cdx_device *cdx_dev = to_cdx_device(vdev->vdev.dev);
struct vfio_irq_info info;
if (copy_from_user(&info, arg, minsz))
return -EFAULT;
if (info.argsz < minsz)
return -EINVAL;
if (info.index >= 1)
return -EINVAL;
if (!cdx_dev->num_msi)
return -EINVAL;
info.flags = VFIO_IRQ_INFO_EVENTFD | VFIO_IRQ_INFO_NORESIZE;
info.count = cdx_dev->num_msi;
return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
}
static int vfio_cdx_ioctl_set_irqs(struct vfio_cdx_device *vdev,
struct vfio_irq_set __user *arg)
{
unsigned long minsz = offsetofend(struct vfio_irq_set, count);
struct cdx_device *cdx_dev = to_cdx_device(vdev->vdev.dev);
struct vfio_irq_set hdr;
size_t data_size = 0;
u8 *data = NULL;
int ret = 0;
if (copy_from_user(&hdr, arg, minsz))
return -EFAULT;
ret = vfio_set_irqs_validate_and_prepare(&hdr, cdx_dev->num_msi,
1, &data_size);
if (ret)
return ret;
if (data_size) {
data = memdup_user(arg->data, data_size);
if (IS_ERR(data))
return PTR_ERR(data);
}
ret = vfio_cdx_set_irqs_ioctl(vdev, hdr.flags, hdr.index,
hdr.start, hdr.count, data);
kfree(data);
return ret;
}
static long vfio_cdx_ioctl(struct vfio_device *core_vdev, static long vfio_cdx_ioctl(struct vfio_device *core_vdev,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
{ {
...@@ -164,6 +221,10 @@ static long vfio_cdx_ioctl(struct vfio_device *core_vdev, ...@@ -164,6 +221,10 @@ static long vfio_cdx_ioctl(struct vfio_device *core_vdev,
return vfio_cdx_ioctl_get_info(vdev, uarg); return vfio_cdx_ioctl_get_info(vdev, uarg);
case VFIO_DEVICE_GET_REGION_INFO: case VFIO_DEVICE_GET_REGION_INFO:
return vfio_cdx_ioctl_get_region_info(vdev, uarg); return vfio_cdx_ioctl_get_region_info(vdev, uarg);
case VFIO_DEVICE_GET_IRQ_INFO:
return vfio_cdx_ioctl_get_irq_info(vdev, uarg);
case VFIO_DEVICE_SET_IRQS:
return vfio_cdx_ioctl_set_irqs(vdev, uarg);
case VFIO_DEVICE_RESET: case VFIO_DEVICE_RESET:
return cdx_dev_reset(core_vdev->dev); return cdx_dev_reset(core_vdev->dev);
default: default:
......
...@@ -13,6 +13,14 @@ static inline u64 vfio_cdx_index_to_offset(u32 index) ...@@ -13,6 +13,14 @@ static inline u64 vfio_cdx_index_to_offset(u32 index)
return ((u64)(index) << VFIO_CDX_OFFSET_SHIFT); return ((u64)(index) << VFIO_CDX_OFFSET_SHIFT);
} }
struct vfio_cdx_irq {
u32 flags;
u32 count;
int irq_no;
struct eventfd_ctx *trigger;
char *name;
};
struct vfio_cdx_region { struct vfio_cdx_region {
u32 flags; u32 flags;
u32 type; u32 type;
...@@ -23,8 +31,18 @@ struct vfio_cdx_region { ...@@ -23,8 +31,18 @@ struct vfio_cdx_region {
struct vfio_cdx_device { struct vfio_cdx_device {
struct vfio_device vdev; struct vfio_device vdev;
struct vfio_cdx_region *regions; struct vfio_cdx_region *regions;
struct vfio_cdx_irq *cdx_irqs;
u32 flags; u32 flags;
#define BME_SUPPORT BIT(0) #define BME_SUPPORT BIT(0)
u32 msi_count;
u8 config_msi;
}; };
int vfio_cdx_set_irqs_ioctl(struct vfio_cdx_device *vdev,
u32 flags, unsigned int index,
unsigned int start, unsigned int count,
void *data);
void vfio_cdx_irqs_cleanup(struct vfio_cdx_device *vdev);
#endif /* VFIO_CDX_PRIVATE_H */ #endif /* VFIO_CDX_PRIVATE_H */
...@@ -69,4 +69,6 @@ source "drivers/vfio/pci/virtio/Kconfig" ...@@ -69,4 +69,6 @@ source "drivers/vfio/pci/virtio/Kconfig"
source "drivers/vfio/pci/nvgrace-gpu/Kconfig" source "drivers/vfio/pci/nvgrace-gpu/Kconfig"
source "drivers/vfio/pci/qat/Kconfig"
endmenu endmenu
...@@ -17,3 +17,5 @@ obj-$(CONFIG_PDS_VFIO_PCI) += pds/ ...@@ -17,3 +17,5 @@ obj-$(CONFIG_PDS_VFIO_PCI) += pds/
obj-$(CONFIG_VIRTIO_VFIO_PCI) += virtio/ obj-$(CONFIG_VIRTIO_VFIO_PCI) += virtio/
obj-$(CONFIG_NVGRACE_GPU_VFIO_PCI) += nvgrace-gpu/ obj-$(CONFIG_NVGRACE_GPU_VFIO_PCI) += nvgrace-gpu/
obj-$(CONFIG_QAT_VFIO_PCI) += qat/
# SPDX-License-Identifier: GPL-2.0-only
config QAT_VFIO_PCI
tristate "VFIO support for QAT VF PCI devices"
select VFIO_PCI_CORE
depends on CRYPTO_DEV_QAT_4XXX
help
This provides migration support for Intel(R) QAT Virtual Function
using the VFIO framework.
To compile this as a module, choose M here: the module
will be called qat_vfio_pci. If you don't know what to do here,
say N.
# SPDX-License-Identifier: GPL-2.0-only
obj-$(CONFIG_QAT_VFIO_PCI) += qat_vfio_pci.o
qat_vfio_pci-y := main.o
This diff is collapsed.
...@@ -778,25 +778,26 @@ static int vfio_pci_count_devs(struct pci_dev *pdev, void *data) ...@@ -778,25 +778,26 @@ static int vfio_pci_count_devs(struct pci_dev *pdev, void *data)
} }
struct vfio_pci_fill_info { struct vfio_pci_fill_info {
struct vfio_pci_dependent_device __user *devices;
struct vfio_pci_dependent_device __user *devices_end;
struct vfio_device *vdev; struct vfio_device *vdev;
struct vfio_pci_dependent_device *devices;
int nr_devices;
u32 count; u32 count;
u32 flags; u32 flags;
}; };
static int vfio_pci_fill_devs(struct pci_dev *pdev, void *data) static int vfio_pci_fill_devs(struct pci_dev *pdev, void *data)
{ {
struct vfio_pci_dependent_device info = { struct vfio_pci_dependent_device *info;
.segment = pci_domain_nr(pdev->bus),
.bus = pdev->bus->number,
.devfn = pdev->devfn,
};
struct vfio_pci_fill_info *fill = data; struct vfio_pci_fill_info *fill = data;
fill->count++; /* The topology changed since we counted devices */
if (fill->devices >= fill->devices_end) if (fill->count >= fill->nr_devices)
return 0; return -EAGAIN;
info = &fill->devices[fill->count++];
info->segment = pci_domain_nr(pdev->bus);
info->bus = pdev->bus->number;
info->devfn = pdev->devfn;
if (fill->flags & VFIO_PCI_HOT_RESET_FLAG_DEV_ID) { if (fill->flags & VFIO_PCI_HOT_RESET_FLAG_DEV_ID) {
struct iommufd_ctx *iommufd = vfio_iommufd_device_ictx(fill->vdev); struct iommufd_ctx *iommufd = vfio_iommufd_device_ictx(fill->vdev);
...@@ -809,19 +810,19 @@ static int vfio_pci_fill_devs(struct pci_dev *pdev, void *data) ...@@ -809,19 +810,19 @@ static int vfio_pci_fill_devs(struct pci_dev *pdev, void *data)
*/ */
vdev = vfio_find_device_in_devset(dev_set, &pdev->dev); vdev = vfio_find_device_in_devset(dev_set, &pdev->dev);
if (!vdev) { if (!vdev) {
info.devid = VFIO_PCI_DEVID_NOT_OWNED; info->devid = VFIO_PCI_DEVID_NOT_OWNED;
} else { } else {
int id = vfio_iommufd_get_dev_id(vdev, iommufd); int id = vfio_iommufd_get_dev_id(vdev, iommufd);
if (id > 0) if (id > 0)
info.devid = id; info->devid = id;
else if (id == -ENOENT) else if (id == -ENOENT)
info.devid = VFIO_PCI_DEVID_OWNED; info->devid = VFIO_PCI_DEVID_OWNED;
else else
info.devid = VFIO_PCI_DEVID_NOT_OWNED; info->devid = VFIO_PCI_DEVID_NOT_OWNED;
} }
/* If devid is VFIO_PCI_DEVID_NOT_OWNED, clear owned flag. */ /* If devid is VFIO_PCI_DEVID_NOT_OWNED, clear owned flag. */
if (info.devid == VFIO_PCI_DEVID_NOT_OWNED) if (info->devid == VFIO_PCI_DEVID_NOT_OWNED)
fill->flags &= ~VFIO_PCI_HOT_RESET_FLAG_DEV_ID_OWNED; fill->flags &= ~VFIO_PCI_HOT_RESET_FLAG_DEV_ID_OWNED;
} else { } else {
struct iommu_group *iommu_group; struct iommu_group *iommu_group;
...@@ -830,13 +831,10 @@ static int vfio_pci_fill_devs(struct pci_dev *pdev, void *data) ...@@ -830,13 +831,10 @@ static int vfio_pci_fill_devs(struct pci_dev *pdev, void *data)
if (!iommu_group) if (!iommu_group)
return -EPERM; /* Cannot reset non-isolated devices */ return -EPERM; /* Cannot reset non-isolated devices */
info.group_id = iommu_group_id(iommu_group); info->group_id = iommu_group_id(iommu_group);
iommu_group_put(iommu_group); iommu_group_put(iommu_group);
} }
if (copy_to_user(fill->devices, &info, sizeof(info)))
return -EFAULT;
fill->devices++;
return 0; return 0;
} }
...@@ -1258,10 +1256,11 @@ static int vfio_pci_ioctl_get_pci_hot_reset_info( ...@@ -1258,10 +1256,11 @@ static int vfio_pci_ioctl_get_pci_hot_reset_info(
{ {
unsigned long minsz = unsigned long minsz =
offsetofend(struct vfio_pci_hot_reset_info, count); offsetofend(struct vfio_pci_hot_reset_info, count);
struct vfio_pci_dependent_device *devices = NULL;
struct vfio_pci_hot_reset_info hdr; struct vfio_pci_hot_reset_info hdr;
struct vfio_pci_fill_info fill = {}; struct vfio_pci_fill_info fill = {};
bool slot = false; bool slot = false;
int ret = 0; int ret, count;
if (copy_from_user(&hdr, arg, minsz)) if (copy_from_user(&hdr, arg, minsz))
return -EFAULT; return -EFAULT;
...@@ -1277,9 +1276,26 @@ static int vfio_pci_ioctl_get_pci_hot_reset_info( ...@@ -1277,9 +1276,26 @@ static int vfio_pci_ioctl_get_pci_hot_reset_info(
else if (pci_probe_reset_bus(vdev->pdev->bus)) else if (pci_probe_reset_bus(vdev->pdev->bus))
return -ENODEV; return -ENODEV;
fill.devices = arg->devices; ret = vfio_pci_for_each_slot_or_bus(vdev->pdev, vfio_pci_count_devs,
fill.devices_end = arg->devices + &count, slot);
(hdr.argsz - sizeof(hdr)) / sizeof(arg->devices[0]); if (ret)
return ret;
if (WARN_ON(!count)) /* Should always be at least one */
return -ERANGE;
if (count > (hdr.argsz - sizeof(hdr)) / sizeof(*devices)) {
hdr.count = count;
ret = -ENOSPC;
goto header;
}
devices = kcalloc(count, sizeof(*devices), GFP_KERNEL);
if (!devices)
return -ENOMEM;
fill.devices = devices;
fill.nr_devices = count;
fill.vdev = &vdev->vdev; fill.vdev = &vdev->vdev;
if (vfio_device_cdev_opened(&vdev->vdev)) if (vfio_device_cdev_opened(&vdev->vdev))
...@@ -1291,16 +1307,23 @@ static int vfio_pci_ioctl_get_pci_hot_reset_info( ...@@ -1291,16 +1307,23 @@ static int vfio_pci_ioctl_get_pci_hot_reset_info(
&fill, slot); &fill, slot);
mutex_unlock(&vdev->vdev.dev_set->lock); mutex_unlock(&vdev->vdev.dev_set->lock);
if (ret) if (ret)
return ret; goto out;
if (copy_to_user(arg->devices, devices,
sizeof(*devices) * fill.count)) {
ret = -EFAULT;
goto out;
}
hdr.count = fill.count; hdr.count = fill.count;
hdr.flags = fill.flags; hdr.flags = fill.flags;
if (copy_to_user(arg, &hdr, minsz))
return -EFAULT;
if (fill.count > fill.devices - arg->devices) header:
return -ENOSPC; if (copy_to_user(arg, &hdr, minsz))
return 0; ret = -EFAULT;
out:
kfree(devices);
return ret;
} }
static int static int
......
...@@ -23,11 +23,12 @@ ...@@ -23,11 +23,12 @@
#include "vfio_pci_priv.h" #include "vfio_pci_priv.h"
struct vfio_pci_irq_ctx { struct vfio_pci_irq_ctx {
struct eventfd_ctx *trigger; struct vfio_pci_core_device *vdev;
struct virqfd *unmask; struct eventfd_ctx *trigger;
struct virqfd *mask; struct virqfd *unmask;
char *name; struct virqfd *mask;
bool masked; char *name;
bool masked;
struct irq_bypass_producer producer; struct irq_bypass_producer producer;
}; };
...@@ -84,19 +85,14 @@ vfio_irq_ctx_alloc(struct vfio_pci_core_device *vdev, unsigned long index) ...@@ -84,19 +85,14 @@ vfio_irq_ctx_alloc(struct vfio_pci_core_device *vdev, unsigned long index)
/* /*
* INTx * INTx
*/ */
static void vfio_send_intx_eventfd(void *opaque, void *unused) static void vfio_send_intx_eventfd(void *opaque, void *data)
{ {
struct vfio_pci_core_device *vdev = opaque; struct vfio_pci_core_device *vdev = opaque;
if (likely(is_intx(vdev) && !vdev->virq_disabled)) { if (likely(is_intx(vdev) && !vdev->virq_disabled)) {
struct vfio_pci_irq_ctx *ctx; struct vfio_pci_irq_ctx *ctx = data;
struct eventfd_ctx *trigger; struct eventfd_ctx *trigger = READ_ONCE(ctx->trigger);
ctx = vfio_irq_ctx_get(vdev, 0);
if (WARN_ON_ONCE(!ctx))
return;
trigger = READ_ONCE(ctx->trigger);
if (likely(trigger)) if (likely(trigger))
eventfd_signal(trigger); eventfd_signal(trigger);
} }
...@@ -166,11 +162,11 @@ bool vfio_pci_intx_mask(struct vfio_pci_core_device *vdev) ...@@ -166,11 +162,11 @@ bool vfio_pci_intx_mask(struct vfio_pci_core_device *vdev)
* a signal is necessary, which can then be handled via a work queue * a signal is necessary, which can then be handled via a work queue
* or directly depending on the caller. * or directly depending on the caller.
*/ */
static int vfio_pci_intx_unmask_handler(void *opaque, void *unused) static int vfio_pci_intx_unmask_handler(void *opaque, void *data)
{ {
struct vfio_pci_core_device *vdev = opaque; struct vfio_pci_core_device *vdev = opaque;
struct pci_dev *pdev = vdev->pdev; struct pci_dev *pdev = vdev->pdev;
struct vfio_pci_irq_ctx *ctx; struct vfio_pci_irq_ctx *ctx = data;
unsigned long flags; unsigned long flags;
int ret = 0; int ret = 0;
...@@ -186,10 +182,6 @@ static int vfio_pci_intx_unmask_handler(void *opaque, void *unused) ...@@ -186,10 +182,6 @@ static int vfio_pci_intx_unmask_handler(void *opaque, void *unused)
goto out_unlock; goto out_unlock;
} }
ctx = vfio_irq_ctx_get(vdev, 0);
if (WARN_ON_ONCE(!ctx))
goto out_unlock;
if (ctx->masked && !vdev->virq_disabled) { if (ctx->masked && !vdev->virq_disabled) {
/* /*
* A pending interrupt here would immediately trigger, * A pending interrupt here would immediately trigger,
...@@ -213,10 +205,12 @@ static int vfio_pci_intx_unmask_handler(void *opaque, void *unused) ...@@ -213,10 +205,12 @@ static int vfio_pci_intx_unmask_handler(void *opaque, void *unused)
static void __vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev) static void __vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev)
{ {
struct vfio_pci_irq_ctx *ctx = vfio_irq_ctx_get(vdev, 0);
lockdep_assert_held(&vdev->igate); lockdep_assert_held(&vdev->igate);
if (vfio_pci_intx_unmask_handler(vdev, NULL) > 0) if (vfio_pci_intx_unmask_handler(vdev, ctx) > 0)
vfio_send_intx_eventfd(vdev, NULL); vfio_send_intx_eventfd(vdev, ctx);
} }
void vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev) void vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev)
...@@ -228,15 +222,11 @@ void vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev) ...@@ -228,15 +222,11 @@ void vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev)
static irqreturn_t vfio_intx_handler(int irq, void *dev_id) static irqreturn_t vfio_intx_handler(int irq, void *dev_id)
{ {
struct vfio_pci_core_device *vdev = dev_id; struct vfio_pci_irq_ctx *ctx = dev_id;
struct vfio_pci_irq_ctx *ctx; struct vfio_pci_core_device *vdev = ctx->vdev;
unsigned long flags; unsigned long flags;
int ret = IRQ_NONE; int ret = IRQ_NONE;
ctx = vfio_irq_ctx_get(vdev, 0);
if (WARN_ON_ONCE(!ctx))
return ret;
spin_lock_irqsave(&vdev->irqlock, flags); spin_lock_irqsave(&vdev->irqlock, flags);
if (!vdev->pci_2_3) { if (!vdev->pci_2_3) {
...@@ -252,7 +242,7 @@ static irqreturn_t vfio_intx_handler(int irq, void *dev_id) ...@@ -252,7 +242,7 @@ static irqreturn_t vfio_intx_handler(int irq, void *dev_id)
spin_unlock_irqrestore(&vdev->irqlock, flags); spin_unlock_irqrestore(&vdev->irqlock, flags);
if (ret == IRQ_HANDLED) if (ret == IRQ_HANDLED)
vfio_send_intx_eventfd(vdev, NULL); vfio_send_intx_eventfd(vdev, ctx);
return ret; return ret;
} }
...@@ -277,11 +267,14 @@ static int vfio_intx_enable(struct vfio_pci_core_device *vdev, ...@@ -277,11 +267,14 @@ static int vfio_intx_enable(struct vfio_pci_core_device *vdev,
return -ENOMEM; return -ENOMEM;
ctx = vfio_irq_ctx_alloc(vdev, 0); ctx = vfio_irq_ctx_alloc(vdev, 0);
if (!ctx) if (!ctx) {
kfree(name);
return -ENOMEM; return -ENOMEM;
}
ctx->name = name; ctx->name = name;
ctx->trigger = trigger; ctx->trigger = trigger;
ctx->vdev = vdev;
/* /*
* Fill the initial masked state based on virq_disabled. After * Fill the initial masked state based on virq_disabled. After
...@@ -312,7 +305,7 @@ static int vfio_intx_enable(struct vfio_pci_core_device *vdev, ...@@ -312,7 +305,7 @@ static int vfio_intx_enable(struct vfio_pci_core_device *vdev,
vdev->irq_type = VFIO_PCI_INTX_IRQ_INDEX; vdev->irq_type = VFIO_PCI_INTX_IRQ_INDEX;
ret = request_irq(pdev->irq, vfio_intx_handler, ret = request_irq(pdev->irq, vfio_intx_handler,
irqflags, ctx->name, vdev); irqflags, ctx->name, ctx);
if (ret) { if (ret) {
vdev->irq_type = VFIO_PCI_NUM_IRQS; vdev->irq_type = VFIO_PCI_NUM_IRQS;
kfree(name); kfree(name);
...@@ -358,7 +351,7 @@ static void vfio_intx_disable(struct vfio_pci_core_device *vdev) ...@@ -358,7 +351,7 @@ static void vfio_intx_disable(struct vfio_pci_core_device *vdev)
if (ctx) { if (ctx) {
vfio_virqfd_disable(&ctx->unmask); vfio_virqfd_disable(&ctx->unmask);
vfio_virqfd_disable(&ctx->mask); vfio_virqfd_disable(&ctx->mask);
free_irq(pdev->irq, vdev); free_irq(pdev->irq, ctx);
if (ctx->trigger) if (ctx->trigger)
eventfd_ctx_put(ctx->trigger); eventfd_ctx_put(ctx->trigger);
kfree(ctx->name); kfree(ctx->name);
...@@ -606,7 +599,7 @@ static int vfio_pci_set_intx_unmask(struct vfio_pci_core_device *vdev, ...@@ -606,7 +599,7 @@ static int vfio_pci_set_intx_unmask(struct vfio_pci_core_device *vdev,
if (fd >= 0) if (fd >= 0)
return vfio_virqfd_enable((void *) vdev, return vfio_virqfd_enable((void *) vdev,
vfio_pci_intx_unmask_handler, vfio_pci_intx_unmask_handler,
vfio_send_intx_eventfd, NULL, vfio_send_intx_eventfd, ctx,
&ctx->unmask, fd); &ctx->unmask, fd);
vfio_virqfd_disable(&ctx->unmask); vfio_virqfd_disable(&ctx->unmask);
...@@ -673,11 +666,11 @@ static int vfio_pci_set_intx_trigger(struct vfio_pci_core_device *vdev, ...@@ -673,11 +666,11 @@ static int vfio_pci_set_intx_trigger(struct vfio_pci_core_device *vdev,
return -EINVAL; return -EINVAL;
if (flags & VFIO_IRQ_SET_DATA_NONE) { if (flags & VFIO_IRQ_SET_DATA_NONE) {
vfio_send_intx_eventfd(vdev, NULL); vfio_send_intx_eventfd(vdev, vfio_irq_ctx_get(vdev, 0));
} else if (flags & VFIO_IRQ_SET_DATA_BOOL) { } else if (flags & VFIO_IRQ_SET_DATA_BOOL) {
uint8_t trigger = *(uint8_t *)data; uint8_t trigger = *(uint8_t *)data;
if (trigger) if (trigger)
vfio_send_intx_eventfd(vdev, NULL); vfio_send_intx_eventfd(vdev, vfio_irq_ctx_get(vdev, 0));
} }
return 0; return 0;
} }
......
...@@ -676,6 +676,12 @@ int platform_device_msi_init_and_alloc_irqs(struct device *dev, unsigned int nve ...@@ -676,6 +676,12 @@ int platform_device_msi_init_and_alloc_irqs(struct device *dev, unsigned int nve
void platform_device_msi_free_irqs_all(struct device *dev); void platform_device_msi_free_irqs_all(struct device *dev);
bool msi_device_has_isolated_msi(struct device *dev); bool msi_device_has_isolated_msi(struct device *dev);
static inline int msi_domain_alloc_irqs(struct device *dev, unsigned int domid, int nirqs)
{
return msi_domain_alloc_irqs_range(dev, domid, 0, nirqs - 1);
}
#else /* CONFIG_GENERIC_MSI_IRQ */ #else /* CONFIG_GENERIC_MSI_IRQ */
static inline bool msi_device_has_isolated_msi(struct device *dev) static inline bool msi_device_has_isolated_msi(struct device *dev)
{ {
......
...@@ -1434,6 +1434,7 @@ int msi_domain_alloc_irqs_range(struct device *dev, unsigned int domid, ...@@ -1434,6 +1434,7 @@ int msi_domain_alloc_irqs_range(struct device *dev, unsigned int domid,
msi_unlock_descs(dev); msi_unlock_descs(dev);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(msi_domain_alloc_irqs_range);
/** /**
* msi_domain_alloc_irqs_all_locked - Allocate all interrupts from a MSI interrupt domain * msi_domain_alloc_irqs_all_locked - Allocate all interrupts from a MSI interrupt domain
...@@ -1680,6 +1681,7 @@ void msi_domain_free_irqs_range(struct device *dev, unsigned int domid, ...@@ -1680,6 +1681,7 @@ void msi_domain_free_irqs_range(struct device *dev, unsigned int domid,
msi_domain_free_irqs_range_locked(dev, domid, first, last); msi_domain_free_irqs_range_locked(dev, domid, first, last);
msi_unlock_descs(dev); msi_unlock_descs(dev);
} }
EXPORT_SYMBOL_GPL(msi_domain_free_irqs_all);
/** /**
* msi_domain_free_irqs_all_locked - Free all interrupts from a MSI interrupt domain * msi_domain_free_irqs_all_locked - Free all interrupts from a MSI interrupt domain
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment