mirror of
https://github.com/torvalds/linux.git
synced 2024-11-23 12:42:02 +00:00
785d21ba2f
- Replace deprecated git://github.com link in MAINTAINERS. (Palmer Dabbelt) - Simplify vfio/mlx5 with module_pci_driver() helper. (Shang XiaoJing) - Drop unnecessary buffer from ACPI call. (Rafael Mendonca) - Correct latent missing include issue in iova-bitmap and fix support for unaligned bitmaps. Follow-up with better fix through refactor. (Joao Martins) - Rework ccw mdev driver to split private data from parent structure, better aligning with the mdev lifecycle and allowing us to remove a temporary workaround. (Eric Farman) - Add an interface to get an estimated migration data size for a device, allowing userspace to make informed decisions, ex. more accurately predicting VM downtime. (Yishai Hadas) - Fix minor typo in vfio/mlx5 array declaration. (Yishai Hadas) - Simplify module and Kconfig through consolidating SPAPR/EEH code and config options and folding virqfd module into main vfio module. (Jason Gunthorpe) - Fix error path from device_register() across all vfio mdev and sample drivers. (Alex Williamson) - Define migration pre-copy interface and implement for vfio/mlx5 devices, allowing portions of the device state to be saved while the device continues operation, towards reducing the stop-copy state size. (Jason Gunthorpe, Yishai Hadas, Shay Drory) - Implement pre-copy for hisi_acc devices. (Shameer Kolothum) - Fixes to mdpy mdev driver remove path and error path on probe. (Shang XiaoJing) - vfio/mlx5 fixes for incorrect return after copy_to_user() fault and incorrect buffer freeing. (Dan Carpenter) -----BEGIN PGP SIGNATURE----- iQJPBAABCAA5FiEEQvbATlQL0amee4qQI5ubbjuwiyIFAmObfPgbHGFsZXgud2ls bGlhbXNvbkByZWRoYXQuY29tAAoJECObm247sIsiDogP/i9GuBKposvZpnfxXWwo oNpKBZSOVMW8wgavNEuryMb+9WoouIghce8XU49MmONoP26kIh5TA14Zpi3XWkLK K+NlpwicESvLeZVHU7f3R8meVqmPtlxIi59jE+CfEHB8BW2HIAsEdwdhkxMwus9C nuiiK/2YYyQWOXYc4LAIkspMzjtGPy6Im5P6AED+dI+TFCEqJAM5qgOLJZFlk4a/ WwZY2xjVKOl6xf5VZXGw+v7fDgz2Ju+j4Bm3X5lx1HgiDrEH83MjXY5h67neAIVb bXrfNLN++MiuO5niGTFMbUjGVUIFxsfmJzBnL9QrLsuj0JrGEKsu/1JEO78g0Km0 ZCChoJ6UyUOgxt6evEymUAZAAkbcKaaht2gdbAXW71tv9p1TripAbBKwVeah1bQp SiHPqy9InKJlhaf+GbXL9eux1WVMfQ6FZccU16bNt7VaV2I8js85z/2gqVD0a5Mw +gnwp5XMUFWNKlJrnc7uVCD0bDExwQhr75OP4rWjMNvvLi9hPXJ2cI2Sg+9OLzQw vm/I+Df+FfXCuGAgX4Lxq76pqWlYGJH0Qxc14Ds6YoXqygBPz9yvTtuBv8mTHJzE KdAl/6DmZZxZ/JFD9lPF80KRiAsJ6iNf6tPTWES7hfDBfIdgQ/DZbXridLWJPNoi xLfaW19yrLTXWKSmR7G2Lsz4 =q9xs -----END PGP SIGNATURE----- Merge tag 'vfio-v6.2-rc1' of https://github.com/awilliam/linux-vfio Pull VFIO updates from Alex Williamson: - Replace deprecated git://github.com link in MAINTAINERS (Palmer Dabbelt) - Simplify vfio/mlx5 with module_pci_driver() helper (Shang XiaoJing) - Drop unnecessary buffer from ACPI call (Rafael Mendonca) - Correct latent missing include issue in iova-bitmap and fix support for unaligned bitmaps. Follow-up with better fix through refactor (Joao Martins) - Rework ccw mdev driver to split private data from parent structure, better aligning with the mdev lifecycle and allowing us to remove a temporary workaround (Eric Farman) - Add an interface to get an estimated migration data size for a device, allowing userspace to make informed decisions, ex. more accurately predicting VM downtime (Yishai Hadas) - Fix minor typo in vfio/mlx5 array declaration (Yishai Hadas) - Simplify module and Kconfig through consolidating SPAPR/EEH code and config options and folding virqfd module into main vfio module (Jason Gunthorpe) - Fix error path from device_register() across all vfio mdev and sample drivers (Alex Williamson) - Define migration pre-copy interface and implement for vfio/mlx5 devices, allowing portions of the device state to be saved while the device continues operation, towards reducing the stop-copy state size (Jason Gunthorpe, Yishai Hadas, Shay Drory) - Implement pre-copy for hisi_acc devices (Shameer Kolothum) - Fixes to mdpy mdev driver remove path and error path on probe (Shang XiaoJing) - vfio/mlx5 fixes for incorrect return after copy_to_user() fault and incorrect buffer freeing (Dan Carpenter) * tag 'vfio-v6.2-rc1' of https://github.com/awilliam/linux-vfio: (42 commits) vfio/mlx5: error pointer dereference in error handling vfio/mlx5: fix error code in mlx5vf_precopy_ioctl() samples: vfio-mdev: Fix missing pci_disable_device() in mdpy_fb_probe() hisi_acc_vfio_pci: Enable PRE_COPY flag hisi_acc_vfio_pci: Move the dev compatibility tests for early check hisi_acc_vfio_pci: Introduce support for PRE_COPY state transitions hisi_acc_vfio_pci: Add support for precopy IOCTL vfio/mlx5: Enable MIGRATION_PRE_COPY flag vfio/mlx5: Fallback to STOP_COPY upon specific PRE_COPY error vfio/mlx5: Introduce multiple loads vfio/mlx5: Consider temporary end of stream as part of PRE_COPY vfio/mlx5: Introduce vfio precopy ioctl implementation vfio/mlx5: Introduce SW headers for migration states vfio/mlx5: Introduce device transitions of PRE_COPY vfio/mlx5: Refactor to use queue based data chunks vfio/mlx5: Refactor migration file state vfio/mlx5: Refactor MKEY usage vfio/mlx5: Refactor PD usage vfio/mlx5: Enforce a single SAVE command at a time vfio: Extend the device migration protocol with PRE_COPY ...
255 lines
7.1 KiB
C
255 lines
7.1 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/*
|
|
* Copyright (C) 2012 Red Hat, Inc. All rights reserved.
|
|
* Author: Alex Williamson <alex.williamson@redhat.com>
|
|
*/
|
|
#ifndef __VFIO_VFIO_H__
|
|
#define __VFIO_VFIO_H__
|
|
|
|
#include <linux/file.h>
|
|
#include <linux/device.h>
|
|
#include <linux/cdev.h>
|
|
#include <linux/module.h>
|
|
|
|
struct iommufd_ctx;
|
|
struct iommu_group;
|
|
struct vfio_device;
|
|
struct vfio_container;
|
|
|
|
void vfio_device_put_registration(struct vfio_device *device);
|
|
bool vfio_device_try_get_registration(struct vfio_device *device);
|
|
int vfio_device_open(struct vfio_device *device,
|
|
struct iommufd_ctx *iommufd, struct kvm *kvm);
|
|
void vfio_device_close(struct vfio_device *device,
|
|
struct iommufd_ctx *iommufd);
|
|
|
|
extern const struct file_operations vfio_device_fops;
|
|
|
|
enum vfio_group_type {
|
|
/*
|
|
* Physical device with IOMMU backing.
|
|
*/
|
|
VFIO_IOMMU,
|
|
|
|
/*
|
|
* Virtual device without IOMMU backing. The VFIO core fakes up an
|
|
* iommu_group as the iommu_group sysfs interface is part of the
|
|
* userspace ABI. The user of these devices must not be able to
|
|
* directly trigger unmediated DMA.
|
|
*/
|
|
VFIO_EMULATED_IOMMU,
|
|
|
|
/*
|
|
* Physical device without IOMMU backing. The VFIO core fakes up an
|
|
* iommu_group as the iommu_group sysfs interface is part of the
|
|
* userspace ABI. Users can trigger unmediated DMA by the device,
|
|
* usage is highly dangerous, requires an explicit opt-in and will
|
|
* taint the kernel.
|
|
*/
|
|
VFIO_NO_IOMMU,
|
|
};
|
|
|
|
struct vfio_group {
|
|
struct device dev;
|
|
struct cdev cdev;
|
|
/*
|
|
* When drivers is non-zero a driver is attached to the struct device
|
|
* that provided the iommu_group and thus the iommu_group is a valid
|
|
* pointer. When drivers is 0 the driver is being detached. Once users
|
|
* reaches 0 then the iommu_group is invalid.
|
|
*/
|
|
refcount_t drivers;
|
|
unsigned int container_users;
|
|
struct iommu_group *iommu_group;
|
|
struct vfio_container *container;
|
|
struct list_head device_list;
|
|
struct mutex device_lock;
|
|
struct list_head vfio_next;
|
|
#if IS_ENABLED(CONFIG_VFIO_CONTAINER)
|
|
struct list_head container_next;
|
|
#endif
|
|
enum vfio_group_type type;
|
|
struct mutex group_lock;
|
|
struct kvm *kvm;
|
|
struct file *opened_file;
|
|
struct blocking_notifier_head notifier;
|
|
struct iommufd_ctx *iommufd;
|
|
};
|
|
|
|
int vfio_device_set_group(struct vfio_device *device,
|
|
enum vfio_group_type type);
|
|
void vfio_device_remove_group(struct vfio_device *device);
|
|
void vfio_device_group_register(struct vfio_device *device);
|
|
void vfio_device_group_unregister(struct vfio_device *device);
|
|
int vfio_device_group_use_iommu(struct vfio_device *device);
|
|
void vfio_device_group_unuse_iommu(struct vfio_device *device);
|
|
void vfio_device_group_close(struct vfio_device *device);
|
|
bool vfio_device_has_container(struct vfio_device *device);
|
|
int __init vfio_group_init(void);
|
|
void vfio_group_cleanup(void);
|
|
|
|
#if IS_ENABLED(CONFIG_VFIO_CONTAINER)
|
|
/* events for the backend driver notify callback */
|
|
enum vfio_iommu_notify_type {
|
|
VFIO_IOMMU_CONTAINER_CLOSE = 0,
|
|
};
|
|
|
|
/**
|
|
* struct vfio_iommu_driver_ops - VFIO IOMMU driver callbacks
|
|
*/
|
|
struct vfio_iommu_driver_ops {
|
|
char *name;
|
|
struct module *owner;
|
|
void *(*open)(unsigned long arg);
|
|
void (*release)(void *iommu_data);
|
|
long (*ioctl)(void *iommu_data, unsigned int cmd,
|
|
unsigned long arg);
|
|
int (*attach_group)(void *iommu_data,
|
|
struct iommu_group *group,
|
|
enum vfio_group_type);
|
|
void (*detach_group)(void *iommu_data,
|
|
struct iommu_group *group);
|
|
int (*pin_pages)(void *iommu_data,
|
|
struct iommu_group *group,
|
|
dma_addr_t user_iova,
|
|
int npage, int prot,
|
|
struct page **pages);
|
|
void (*unpin_pages)(void *iommu_data,
|
|
dma_addr_t user_iova, int npage);
|
|
void (*register_device)(void *iommu_data,
|
|
struct vfio_device *vdev);
|
|
void (*unregister_device)(void *iommu_data,
|
|
struct vfio_device *vdev);
|
|
int (*dma_rw)(void *iommu_data, dma_addr_t user_iova,
|
|
void *data, size_t count, bool write);
|
|
struct iommu_domain *(*group_iommu_domain)(void *iommu_data,
|
|
struct iommu_group *group);
|
|
void (*notify)(void *iommu_data,
|
|
enum vfio_iommu_notify_type event);
|
|
};
|
|
|
|
struct vfio_iommu_driver {
|
|
const struct vfio_iommu_driver_ops *ops;
|
|
struct list_head vfio_next;
|
|
};
|
|
|
|
int vfio_register_iommu_driver(const struct vfio_iommu_driver_ops *ops);
|
|
void vfio_unregister_iommu_driver(const struct vfio_iommu_driver_ops *ops);
|
|
|
|
struct vfio_container *vfio_container_from_file(struct file *filep);
|
|
int vfio_group_use_container(struct vfio_group *group);
|
|
void vfio_group_unuse_container(struct vfio_group *group);
|
|
int vfio_container_attach_group(struct vfio_container *container,
|
|
struct vfio_group *group);
|
|
void vfio_group_detach_container(struct vfio_group *group);
|
|
void vfio_device_container_register(struct vfio_device *device);
|
|
void vfio_device_container_unregister(struct vfio_device *device);
|
|
int vfio_device_container_pin_pages(struct vfio_device *device,
|
|
dma_addr_t iova, int npage,
|
|
int prot, struct page **pages);
|
|
void vfio_device_container_unpin_pages(struct vfio_device *device,
|
|
dma_addr_t iova, int npage);
|
|
int vfio_device_container_dma_rw(struct vfio_device *device,
|
|
dma_addr_t iova, void *data,
|
|
size_t len, bool write);
|
|
|
|
int __init vfio_container_init(void);
|
|
void vfio_container_cleanup(void);
|
|
#else
|
|
static inline struct vfio_container *
|
|
vfio_container_from_file(struct file *filep)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static inline int vfio_group_use_container(struct vfio_group *group)
|
|
{
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
static inline void vfio_group_unuse_container(struct vfio_group *group)
|
|
{
|
|
}
|
|
|
|
static inline int vfio_container_attach_group(struct vfio_container *container,
|
|
struct vfio_group *group)
|
|
{
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
static inline void vfio_group_detach_container(struct vfio_group *group)
|
|
{
|
|
}
|
|
|
|
static inline void vfio_device_container_register(struct vfio_device *device)
|
|
{
|
|
}
|
|
|
|
static inline void vfio_device_container_unregister(struct vfio_device *device)
|
|
{
|
|
}
|
|
|
|
static inline int vfio_device_container_pin_pages(struct vfio_device *device,
|
|
dma_addr_t iova, int npage,
|
|
int prot, struct page **pages)
|
|
{
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
static inline void vfio_device_container_unpin_pages(struct vfio_device *device,
|
|
dma_addr_t iova, int npage)
|
|
{
|
|
}
|
|
|
|
static inline int vfio_device_container_dma_rw(struct vfio_device *device,
|
|
dma_addr_t iova, void *data,
|
|
size_t len, bool write)
|
|
{
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
static inline int vfio_container_init(void)
|
|
{
|
|
return 0;
|
|
}
|
|
static inline void vfio_container_cleanup(void)
|
|
{
|
|
}
|
|
#endif
|
|
|
|
#if IS_ENABLED(CONFIG_IOMMUFD)
|
|
int vfio_iommufd_bind(struct vfio_device *device, struct iommufd_ctx *ictx);
|
|
void vfio_iommufd_unbind(struct vfio_device *device);
|
|
#else
|
|
static inline int vfio_iommufd_bind(struct vfio_device *device,
|
|
struct iommufd_ctx *ictx)
|
|
{
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
static inline void vfio_iommufd_unbind(struct vfio_device *device)
|
|
{
|
|
}
|
|
#endif
|
|
|
|
#if IS_ENABLED(CONFIG_VFIO_VIRQFD)
|
|
int __init vfio_virqfd_init(void);
|
|
void vfio_virqfd_exit(void);
|
|
#else
|
|
static inline int __init vfio_virqfd_init(void)
|
|
{
|
|
return 0;
|
|
}
|
|
static inline void vfio_virqfd_exit(void)
|
|
{
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_VFIO_NOIOMMU
|
|
extern bool vfio_noiommu __read_mostly;
|
|
#else
|
|
enum { vfio_noiommu = false };
|
|
#endif
|
|
|
|
#endif
|