Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost

Pull virtio updates from Michael Tsirkin:
 "Just a bunch of fixes and cleanups, mostly very simple. Several
  features were merged through net-next this time around"

* tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost:
  virtio_pci: drop kernel.h
  vhost: switch to arrays of feature bits
  vhost/test: add test specific macro for features
  virtio: clean up features qword/dword terms
  vduse: add WQ_PERCPU to alloc_workqueue users
  virtio_balloon: add WQ_PERCPU to alloc_workqueue users
  vdpa/pds: use %pe for ERR_PTR() in event handler registration
  vhost: Fix kthread worker cgroup failure handling
  virtio: vdpa: Fix reference count leak in octep_sriov_enable()
  vdpa/mlx5: Fix incorrect error code reporting in query_virtqueues
  virtio: fix map ops comment
  virtio: fix virtqueue_set_affinity() docs
  virtio: standardize Returns documentation style
  virtio: fix grammar in virtio_map_ops docs
  virtio: fix grammar in virtio_queue_info docs
  virtio: fix whitespace in virtio_config_ops
  virtio: fix typo in virtio_device_ready() comment
  virtio: fix kernel-doc for mapping/free_coherent functions
  virtio_vdpa: fix misleading return in void function
This commit is contained in:
Linus Torvalds
2025-12-04 18:59:21 -08:00
21 changed files with 131 additions and 86 deletions

View File

@@ -1256,7 +1256,7 @@ static int query_virtqueues(struct mlx5_vdpa_net *ndev,
int vq_idx = start_vq + i; int vq_idx = start_vq + i;
if (cmd->err) { if (cmd->err) {
mlx5_vdpa_err(mvdev, "query vq %d failed, err: %d\n", vq_idx, err); mlx5_vdpa_err(mvdev, "query vq %d failed, err: %d\n", vq_idx, cmd->err);
if (!err) if (!err)
err = cmd->err; err = cmd->err;
continue; continue;

View File

@@ -736,6 +736,7 @@ static int octep_sriov_enable(struct pci_dev *pdev, int num_vfs)
octep_vdpa_assign_barspace(vf_pdev, pdev, index); octep_vdpa_assign_barspace(vf_pdev, pdev, index);
if (++index == num_vfs) { if (++index == num_vfs) {
done = true; done = true;
pci_dev_put(vf_pdev);
break; break;
} }
} }

View File

@@ -51,7 +51,7 @@ static int pds_vdpa_register_event_handler(struct pds_vdpa_device *pdsv)
err = pdsc_register_notify(nb); err = pdsc_register_notify(nb);
if (err) { if (err) {
nb->notifier_call = NULL; nb->notifier_call = NULL;
dev_err(dev, "failed to register pds event handler: %ps\n", dev_err(dev, "failed to register pds event handler: %pe\n",
ERR_PTR(err)); ERR_PTR(err));
return -EINVAL; return -EINVAL;
} }

View File

@@ -2173,7 +2173,8 @@ static int vduse_init(void)
if (!vduse_irq_wq) if (!vduse_irq_wq)
goto err_wq; goto err_wq;
vduse_irq_bound_wq = alloc_workqueue("vduse-irq-bound", WQ_HIGHPRI, 0); vduse_irq_bound_wq = alloc_workqueue("vduse-irq-bound",
WQ_HIGHPRI | WQ_PERCPU, 0);
if (!vduse_irq_bound_wq) if (!vduse_irq_bound_wq)
goto err_bound_wq; goto err_bound_wq;

View File

@@ -69,15 +69,15 @@ MODULE_PARM_DESC(experimental_zcopytx, "Enable Zero Copy TX;"
#define VHOST_DMA_IS_DONE(len) ((__force u32)(len) >= (__force u32)VHOST_DMA_DONE_LEN) #define VHOST_DMA_IS_DONE(len) ((__force u32)(len) >= (__force u32)VHOST_DMA_DONE_LEN)
static const u64 vhost_net_features[VIRTIO_FEATURES_DWORDS] = { static const int vhost_net_bits[] = {
VHOST_FEATURES | VHOST_FEATURES,
(1ULL << VHOST_NET_F_VIRTIO_NET_HDR) | VHOST_NET_F_VIRTIO_NET_HDR,
(1ULL << VIRTIO_NET_F_MRG_RXBUF) | VIRTIO_NET_F_MRG_RXBUF,
(1ULL << VIRTIO_F_ACCESS_PLATFORM) | VIRTIO_F_ACCESS_PLATFORM,
(1ULL << VIRTIO_F_RING_RESET) | VIRTIO_F_RING_RESET,
(1ULL << VIRTIO_F_IN_ORDER), VIRTIO_F_IN_ORDER,
VIRTIO_BIT(VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO) | VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO,
VIRTIO_BIT(VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO), VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO
}; };
enum { enum {
@@ -1731,7 +1731,8 @@ out:
static long vhost_net_ioctl(struct file *f, unsigned int ioctl, static long vhost_net_ioctl(struct file *f, unsigned int ioctl,
unsigned long arg) unsigned long arg)
{ {
u64 all_features[VIRTIO_FEATURES_DWORDS]; const DEFINE_VHOST_FEATURES_ARRAY(vhost_net_features, vhost_net_bits);
u64 all_features[VIRTIO_FEATURES_U64S];
struct vhost_net *n = f->private_data; struct vhost_net *n = f->private_data;
void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg;
u64 __user *featurep = argp; u64 __user *featurep = argp;
@@ -1763,7 +1764,7 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl,
/* Copy the net features, up to the user-provided buffer size */ /* Copy the net features, up to the user-provided buffer size */
argp += sizeof(u64); argp += sizeof(u64);
copied = min(count, VIRTIO_FEATURES_DWORDS); copied = min(count, (u64)VIRTIO_FEATURES_U64S);
if (copy_to_user(argp, vhost_net_features, if (copy_to_user(argp, vhost_net_features,
copied * sizeof(u64))) copied * sizeof(u64)))
return -EFAULT; return -EFAULT;
@@ -1778,13 +1779,13 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl,
virtio_features_zero(all_features); virtio_features_zero(all_features);
argp += sizeof(u64); argp += sizeof(u64);
copied = min(count, VIRTIO_FEATURES_DWORDS); copied = min(count, (u64)VIRTIO_FEATURES_U64S);
if (copy_from_user(all_features, argp, copied * sizeof(u64))) if (copy_from_user(all_features, argp, copied * sizeof(u64)))
return -EFAULT; return -EFAULT;
/* /*
* Any feature specified by user-space above * Any feature specified by user-space above
* VIRTIO_FEATURES_MAX is not supported by definition. * VIRTIO_FEATURES_BITS is not supported by definition.
*/ */
for (i = copied; i < count; ++i) { for (i = copied; i < count; ++i) {
if (copy_from_user(&features, featurep + 1 + i, if (copy_from_user(&features, featurep + 1 + i,
@@ -1794,7 +1795,7 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl,
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
for (i = 0; i < VIRTIO_FEATURES_DWORDS; i++) for (i = 0; i < VIRTIO_FEATURES_U64S; i++)
if (all_features[i] & ~vhost_net_features[i]) if (all_features[i] & ~vhost_net_features[i])
return -EOPNOTSUPP; return -EOPNOTSUPP;

View File

@@ -197,11 +197,14 @@ enum {
}; };
/* Note: can't set VIRTIO_F_VERSION_1 yet, since that implies ANY_LAYOUT. */ /* Note: can't set VIRTIO_F_VERSION_1 yet, since that implies ANY_LAYOUT. */
enum { static const int vhost_scsi_bits[] = {
VHOST_SCSI_FEATURES = VHOST_FEATURES | (1ULL << VIRTIO_SCSI_F_HOTPLUG) | VHOST_FEATURES,
(1ULL << VIRTIO_SCSI_F_T10_PI) VIRTIO_SCSI_F_HOTPLUG,
VIRTIO_SCSI_F_T10_PI
}; };
#define VHOST_SCSI_FEATURES VHOST_FEATURES_U64(vhost_scsi_bits, 0)
#define VHOST_SCSI_MAX_TARGET 256 #define VHOST_SCSI_MAX_TARGET 256
#define VHOST_SCSI_MAX_IO_VQ 1024 #define VHOST_SCSI_MAX_IO_VQ 1024
#define VHOST_SCSI_MAX_EVENT 128 #define VHOST_SCSI_MAX_EVENT 128

View File

@@ -28,6 +28,12 @@
*/ */
#define VHOST_TEST_PKT_WEIGHT 256 #define VHOST_TEST_PKT_WEIGHT 256
static const int vhost_test_bits[] = {
VHOST_FEATURES
};
#define VHOST_TEST_FEATURES VHOST_FEATURES_U64(vhost_test_bits, 0)
enum { enum {
VHOST_TEST_VQ = 0, VHOST_TEST_VQ = 0,
VHOST_TEST_VQ_MAX = 1, VHOST_TEST_VQ_MAX = 1,
@@ -328,14 +334,14 @@ static long vhost_test_ioctl(struct file *f, unsigned int ioctl,
return -EFAULT; return -EFAULT;
return vhost_test_set_backend(n, backend.index, backend.fd); return vhost_test_set_backend(n, backend.index, backend.fd);
case VHOST_GET_FEATURES: case VHOST_GET_FEATURES:
features = VHOST_FEATURES; features = VHOST_TEST_FEATURES;
if (copy_to_user(featurep, &features, sizeof features)) if (copy_to_user(featurep, &features, sizeof features))
return -EFAULT; return -EFAULT;
return 0; return 0;
case VHOST_SET_FEATURES: case VHOST_SET_FEATURES:
if (copy_from_user(&features, featurep, sizeof features)) if (copy_from_user(&features, featurep, sizeof features))
return -EFAULT; return -EFAULT;
if (features & ~VHOST_FEATURES) if (features & ~VHOST_TEST_FEATURES)
return -EOPNOTSUPP; return -EOPNOTSUPP;
return vhost_test_set_features(n, features); return vhost_test_set_features(n, features);
case VHOST_RESET_OWNER: case VHOST_RESET_OWNER:

View File

@@ -804,11 +804,13 @@ static int vhost_kthread_worker_create(struct vhost_worker *worker,
ret = vhost_attach_task_to_cgroups(worker); ret = vhost_attach_task_to_cgroups(worker);
if (ret) if (ret)
goto stop_worker; goto free_id;
worker->id = id; worker->id = id;
return 0; return 0;
free_id:
xa_erase(&dev->worker_xa, id);
stop_worker: stop_worker:
vhost_kthread_do_stop(worker); vhost_kthread_do_stop(worker);
return ret; return ret;

View File

@@ -14,6 +14,7 @@
#include <linux/atomic.h> #include <linux/atomic.h>
#include <linux/vhost_iotlb.h> #include <linux/vhost_iotlb.h>
#include <linux/irqbypass.h> #include <linux/irqbypass.h>
#include <linux/unroll.h>
struct vhost_work; struct vhost_work;
struct vhost_task; struct vhost_task;
@@ -287,14 +288,39 @@ void vhost_iotlb_map_free(struct vhost_iotlb *iotlb,
eventfd_signal((vq)->error_ctx);\ eventfd_signal((vq)->error_ctx);\
} while (0) } while (0)
enum { #define VHOST_FEATURES \
VHOST_FEATURES = (1ULL << VIRTIO_F_NOTIFY_ON_EMPTY) | VIRTIO_F_NOTIFY_ON_EMPTY, \
(1ULL << VIRTIO_RING_F_INDIRECT_DESC) | VIRTIO_RING_F_INDIRECT_DESC, \
(1ULL << VIRTIO_RING_F_EVENT_IDX) | VIRTIO_RING_F_EVENT_IDX, \
(1ULL << VHOST_F_LOG_ALL) | VHOST_F_LOG_ALL, \
(1ULL << VIRTIO_F_ANY_LAYOUT) | VIRTIO_F_ANY_LAYOUT, \
(1ULL << VIRTIO_F_VERSION_1) VIRTIO_F_VERSION_1
};
static inline u64 vhost_features_u64(const int *features, int size, int idx)
{
u64 res = 0;
unrolled_count(VIRTIO_FEATURES_BITS)
for (int i = 0; i < size; ++i) {
int bit = features[i];
if (virtio_features_chk_bit(bit) && VIRTIO_U64(bit) == idx)
res |= VIRTIO_BIT(bit);
}
return res;
}
#define VHOST_FEATURES_U64(features, idx) \
vhost_features_u64(features, ARRAY_SIZE(features), idx)
#define DEFINE_VHOST_FEATURES_ARRAY_ENTRY(idx, features) \
[idx] = VHOST_FEATURES_U64(features, idx),
#define DEFINE_VHOST_FEATURES_ARRAY(array, features) \
u64 array[VIRTIO_FEATURES_U64S] = { \
UNROLL(VIRTIO_FEATURES_U64S, \
DEFINE_VHOST_FEATURES_ARRAY_ENTRY, features) \
}
/** /**
* vhost_vq_set_backend - Set backend. * vhost_vq_set_backend - Set backend.

View File

@@ -29,12 +29,14 @@
*/ */
#define VHOST_VSOCK_PKT_WEIGHT 256 #define VHOST_VSOCK_PKT_WEIGHT 256
enum { static const int vhost_vsock_bits[] = {
VHOST_VSOCK_FEATURES = VHOST_FEATURES | VHOST_FEATURES,
(1ULL << VIRTIO_F_ACCESS_PLATFORM) | VIRTIO_F_ACCESS_PLATFORM,
(1ULL << VIRTIO_VSOCK_F_SEQPACKET) VIRTIO_VSOCK_F_SEQPACKET
}; };
#define VHOST_VSOCK_FEATURES VHOST_FEATURES_U64(vhost_vsock_bits, 0)
enum { enum {
VHOST_VSOCK_BACKEND_FEATURES = (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2) VHOST_VSOCK_BACKEND_FEATURES = (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2)
}; };

View File

@@ -53,7 +53,7 @@ static ssize_t features_show(struct device *_d,
/* We actually represent this as a bitstring, as it could be /* We actually represent this as a bitstring, as it could be
* arbitrary length in future. */ * arbitrary length in future. */
for (i = 0; i < VIRTIO_FEATURES_MAX; i++) for (i = 0; i < VIRTIO_FEATURES_BITS; i++)
len += sysfs_emit_at(buf, len, "%c", len += sysfs_emit_at(buf, len, "%c",
__virtio_test_bit(dev, i) ? '1' : '0'); __virtio_test_bit(dev, i) ? '1' : '0');
len += sysfs_emit_at(buf, len, "\n"); len += sysfs_emit_at(buf, len, "\n");
@@ -272,8 +272,8 @@ static int virtio_dev_probe(struct device *_d)
int err, i; int err, i;
struct virtio_device *dev = dev_to_virtio(_d); struct virtio_device *dev = dev_to_virtio(_d);
struct virtio_driver *drv = drv_to_virtio(dev->dev.driver); struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
u64 device_features[VIRTIO_FEATURES_DWORDS]; u64 device_features[VIRTIO_FEATURES_U64S];
u64 driver_features[VIRTIO_FEATURES_DWORDS]; u64 driver_features[VIRTIO_FEATURES_U64S];
u64 driver_features_legacy; u64 driver_features_legacy;
/* We have a driver! */ /* We have a driver! */
@@ -286,7 +286,7 @@ static int virtio_dev_probe(struct device *_d)
virtio_features_zero(driver_features); virtio_features_zero(driver_features);
for (i = 0; i < drv->feature_table_size; i++) { for (i = 0; i < drv->feature_table_size; i++) {
unsigned int f = drv->feature_table[i]; unsigned int f = drv->feature_table[i];
if (!WARN_ON_ONCE(f >= VIRTIO_FEATURES_MAX)) if (!WARN_ON_ONCE(f >= VIRTIO_FEATURES_BITS))
virtio_features_set_bit(driver_features, f); virtio_features_set_bit(driver_features, f);
} }
@@ -303,7 +303,7 @@ static int virtio_dev_probe(struct device *_d)
} }
if (virtio_features_test_bit(device_features, VIRTIO_F_VERSION_1)) { if (virtio_features_test_bit(device_features, VIRTIO_F_VERSION_1)) {
for (i = 0; i < VIRTIO_FEATURES_DWORDS; ++i) for (i = 0; i < VIRTIO_FEATURES_U64S; ++i)
dev->features_array[i] = driver_features[i] & dev->features_array[i] = driver_features[i] &
device_features[i]; device_features[i];
} else { } else {
@@ -325,7 +325,7 @@ static int virtio_dev_probe(struct device *_d)
goto err; goto err;
if (drv->validate) { if (drv->validate) {
u64 features[VIRTIO_FEATURES_DWORDS]; u64 features[VIRTIO_FEATURES_U64S];
virtio_features_copy(features, dev->features_array); virtio_features_copy(features, dev->features_array);
err = drv->validate(dev); err = drv->validate(dev);

View File

@@ -983,7 +983,8 @@ static int virtballoon_probe(struct virtio_device *vdev)
goto out_del_vqs; goto out_del_vqs;
} }
vb->balloon_wq = alloc_workqueue("balloon-wq", vb->balloon_wq = alloc_workqueue("balloon-wq",
WQ_FREEZABLE | WQ_CPU_INTENSIVE, 0); WQ_FREEZABLE | WQ_CPU_INTENSIVE | WQ_PERCPU,
0);
if (!vb->balloon_wq) { if (!vb->balloon_wq) {
err = -ENOMEM; err = -ENOMEM;
goto out_del_vqs; goto out_del_vqs;

View File

@@ -8,12 +8,12 @@ static struct dentry *virtio_debugfs_dir;
static int virtio_debug_device_features_show(struct seq_file *s, void *data) static int virtio_debug_device_features_show(struct seq_file *s, void *data)
{ {
u64 device_features[VIRTIO_FEATURES_DWORDS]; u64 device_features[VIRTIO_FEATURES_U64S];
struct virtio_device *dev = s->private; struct virtio_device *dev = s->private;
unsigned int i; unsigned int i;
virtio_get_features(dev, device_features); virtio_get_features(dev, device_features);
for (i = 0; i < VIRTIO_FEATURES_MAX; i++) { for (i = 0; i < VIRTIO_FEATURES_BITS; i++) {
if (virtio_features_test_bit(device_features, i)) if (virtio_features_test_bit(device_features, i))
seq_printf(s, "%u\n", i); seq_printf(s, "%u\n", i);
} }
@@ -26,7 +26,7 @@ static int virtio_debug_filter_features_show(struct seq_file *s, void *data)
struct virtio_device *dev = s->private; struct virtio_device *dev = s->private;
unsigned int i; unsigned int i;
for (i = 0; i < VIRTIO_FEATURES_MAX; i++) { for (i = 0; i < VIRTIO_FEATURES_BITS; i++) {
if (virtio_features_test_bit(dev->debugfs_filter_features, i)) if (virtio_features_test_bit(dev->debugfs_filter_features, i))
seq_printf(s, "%u\n", i); seq_printf(s, "%u\n", i);
} }
@@ -50,7 +50,7 @@ static int virtio_debug_filter_feature_add(void *data, u64 val)
{ {
struct virtio_device *dev = data; struct virtio_device *dev = data;
if (val >= VIRTIO_FEATURES_MAX) if (val >= VIRTIO_FEATURES_BITS)
return -EINVAL; return -EINVAL;
virtio_features_set_bit(dev->debugfs_filter_features, val); virtio_features_set_bit(dev->debugfs_filter_features, val);
@@ -64,7 +64,7 @@ static int virtio_debug_filter_feature_del(void *data, u64 val)
{ {
struct virtio_device *dev = data; struct virtio_device *dev = data;
if (val >= VIRTIO_FEATURES_MAX) if (val >= VIRTIO_FEATURES_BITS)
return -EINVAL; return -EINVAL;
virtio_features_clear_bit(dev->debugfs_filter_features, val); virtio_features_clear_bit(dev->debugfs_filter_features, val);

View File

@@ -401,7 +401,7 @@ void vp_modern_get_extended_features(struct virtio_pci_modern_device *mdev,
int i; int i;
virtio_features_zero(features); virtio_features_zero(features);
for (i = 0; i < VIRTIO_FEATURES_WORDS; i++) { for (i = 0; i < VIRTIO_FEATURES_BITS / 32; i++) {
u64 cur; u64 cur;
vp_iowrite32(i, &cfg->device_feature_select); vp_iowrite32(i, &cfg->device_feature_select);
@@ -427,7 +427,7 @@ vp_modern_get_driver_extended_features(struct virtio_pci_modern_device *mdev,
int i; int i;
virtio_features_zero(features); virtio_features_zero(features);
for (i = 0; i < VIRTIO_FEATURES_WORDS; i++) { for (i = 0; i < VIRTIO_FEATURES_BITS / 32; i++) {
u64 cur; u64 cur;
vp_iowrite32(i, &cfg->guest_feature_select); vp_iowrite32(i, &cfg->guest_feature_select);
@@ -448,7 +448,7 @@ void vp_modern_set_extended_features(struct virtio_pci_modern_device *mdev,
struct virtio_pci_common_cfg __iomem *cfg = mdev->common; struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
int i; int i;
for (i = 0; i < VIRTIO_FEATURES_WORDS; i++) { for (i = 0; i < VIRTIO_FEATURES_BITS / 32; i++) {
u32 cur = features[i >> 1] >> (32 * (i & 1)); u32 cur = features[i >> 1] >> (32 * (i & 1));
vp_iowrite32(i, &cfg->guest_feature_select); vp_iowrite32(i, &cfg->guest_feature_select);

View File

@@ -3166,6 +3166,7 @@ EXPORT_SYMBOL_GPL(virtqueue_map_alloc_coherent);
* @vdev: the virtio device we are talking to * @vdev: the virtio device we are talking to
* @map: metadata for performing mapping * @map: metadata for performing mapping
* @size: the size of the buffer * @size: the size of the buffer
* @vaddr: the virtual address that needs to be freed
* @map_handle: the mapped address that needs to be freed * @map_handle: the mapped address that needs to be freed
* *
*/ */
@@ -3190,7 +3191,7 @@ EXPORT_SYMBOL_GPL(virtqueue_map_free_coherent);
* @dir: mapping direction * @dir: mapping direction
* @attrs: mapping attributes * @attrs: mapping attributes
* *
* Returns mapped address. Caller should check that by virtqueue_mapping_error(). * Returns mapped address. Caller should check that by virtqueue_map_mapping_error().
*/ */
dma_addr_t virtqueue_map_page_attrs(const struct virtqueue *_vq, dma_addr_t virtqueue_map_page_attrs(const struct virtqueue *_vq,
struct page *page, struct page *page,
@@ -3249,7 +3250,7 @@ EXPORT_SYMBOL_GPL(virtqueue_unmap_page_attrs);
* The caller calls this to do dma mapping in advance. The DMA address can be * The caller calls this to do dma mapping in advance. The DMA address can be
* passed to this _vq when it is in pre-mapped mode. * passed to this _vq when it is in pre-mapped mode.
* *
* return mapped address. Caller should check that by virtqueue_mapping_error(). * return mapped address. Caller should check that by virtqueue_map_mapping_error().
*/ */
dma_addr_t virtqueue_map_single_attrs(const struct virtqueue *_vq, void *ptr, dma_addr_t virtqueue_map_single_attrs(const struct virtqueue *_vq, void *ptr,
size_t size, size_t size,
@@ -3299,7 +3300,7 @@ void virtqueue_unmap_single_attrs(const struct virtqueue *_vq,
EXPORT_SYMBOL_GPL(virtqueue_unmap_single_attrs); EXPORT_SYMBOL_GPL(virtqueue_unmap_single_attrs);
/** /**
* virtqueue_mapping_error - check dma address * virtqueue_map_mapping_error - check dma address
* @_vq: the struct virtqueue we're talking about. * @_vq: the struct virtqueue we're talking about.
* @addr: DMA address * @addr: DMA address
* *

View File

@@ -80,7 +80,7 @@ static void virtio_vdpa_set_status(struct virtio_device *vdev, u8 status)
{ {
struct vdpa_device *vdpa = vd_get_vdpa(vdev); struct vdpa_device *vdpa = vd_get_vdpa(vdev);
return vdpa_set_status(vdpa, status); vdpa_set_status(vdpa, status);
} }
static void virtio_vdpa_reset(struct virtio_device *vdev) static void virtio_vdpa_reset(struct virtio_device *vdev)

View File

@@ -177,7 +177,7 @@ struct virtio_device {
union virtio_map vmap; union virtio_map vmap;
#ifdef CONFIG_VIRTIO_DEBUG #ifdef CONFIG_VIRTIO_DEBUG
struct dentry *debugfs_dir; struct dentry *debugfs_dir;
u64 debugfs_filter_features[VIRTIO_FEATURES_DWORDS]; u64 debugfs_filter_features[VIRTIO_FEATURES_U64S];
#endif #endif
}; };

View File

@@ -24,7 +24,7 @@ typedef void vq_callback_t(struct virtqueue *);
* a virtqueue unused by the driver. * a virtqueue unused by the driver.
* @callback: A callback to invoke on a used buffer notification. * @callback: A callback to invoke on a used buffer notification.
* NULL for a virtqueue that does not need a callback. * NULL for a virtqueue that does not need a callback.
* @ctx: A flag to indicate to maintain an extra context per virtqueue. * @ctx: whether to maintain an extra context per virtqueue.
*/ */
struct virtqueue_info { struct virtqueue_info {
const char *name; const char *name;
@@ -80,7 +80,7 @@ struct virtqueue_info {
* Returns the first 64 feature bits. * Returns the first 64 feature bits.
* @get_extended_features: * @get_extended_features:
* vdev: the virtio_device * vdev: the virtio_device
* Returns the first VIRTIO_FEATURES_MAX feature bits (all we currently * Returns the first VIRTIO_FEATURES_BITS feature bits (all we currently
* need). * need).
* @finalize_features: confirm what device features we'll be using. * @finalize_features: confirm what device features we'll be using.
* vdev: the virtio_device * vdev: the virtio_device
@@ -141,8 +141,8 @@ struct virtio_config_ops {
/** /**
* struct virtio_map_ops - operations for mapping buffer for a virtio device * struct virtio_map_ops - operations for mapping buffer for a virtio device
* Note: For transport that has its own mapping logic it must * Note: For a transport that has its own mapping logic it must
* implements all of the operations * implement all of the operations
* @map_page: map a buffer to the device * @map_page: map a buffer to the device
* map: metadata for performing mapping * map: metadata for performing mapping
* page: the page that will be mapped by the device * page: the page that will be mapped by the device
@@ -150,7 +150,7 @@ struct virtio_config_ops {
* size: the buffer size * size: the buffer size
* dir: mapping direction * dir: mapping direction
* attrs: mapping attributes * attrs: mapping attributes
* Returns: the mapped address * Returns the mapped address
* @unmap_page: unmap a buffer from the device * @unmap_page: unmap a buffer from the device
* map: device specific mapping map * map: device specific mapping map
* map_handle: the mapped address * map_handle: the mapped address
@@ -172,23 +172,23 @@ struct virtio_config_ops {
* size: the size of the buffer * size: the size of the buffer
* map_handle: the mapping address to sync * map_handle: the mapping address to sync
* gfp: allocation flag (GFP_XXX) * gfp: allocation flag (GFP_XXX)
* Returns: virtual address of the allocated buffer * Returns virtual address of the allocated buffer
* @free: free a coherent buffer mapping * @free: free a coherent buffer mapping
* map: metadata for performing mapping * map: metadata for performing mapping
* size: the size of the buffer * size: the size of the buffer
* vaddr: virtual address of the buffer * vaddr: virtual address of the buffer
* map_handle: the mapping address to sync * map_handle: the mapping address that needs to be freed
* attrs: unmapping attributes * attrs: unmapping attributes
* @need_sync: if the buffer needs synchronization * @need_sync: if the buffer needs synchronization
* map: metadata for performing mapping * map: metadata for performing mapping
* map_handle: the mapped address * map_handle: the mapped address
* Returns: whether the buffer needs synchronization * Returns whether the buffer needs synchronization
* @mapping_error: if the mapping address is error * @mapping_error: if the mapping address is error
* map: metadata for performing mapping * map: metadata for performing mapping
* map_handle: the mapped address * map_handle: the mapped address
* @max_mapping_size: get the maximum buffer size that can be mapped * @max_mapping_size: get the maximum buffer size that can be mapped
* map: metadata for performing mapping * map: metadata for performing mapping
* Returns: the maximum buffer size that can be mapped * Returns the maximum buffer size that can be mapped
*/ */
struct virtio_map_ops { struct virtio_map_ops {
dma_addr_t (*map_page)(union virtio_map map, struct page *page, dma_addr_t (*map_page)(union virtio_map map, struct page *page,
@@ -362,7 +362,7 @@ void virtio_device_ready(struct virtio_device *dev)
* specific set_status() method. * specific set_status() method.
* *
* A well behaved device will only notify a virtqueue after * A well behaved device will only notify a virtqueue after
* DRIVER_OK, this means the device should "see" the coherenct * DRIVER_OK, this means the device should "see" the coherent
* memory write that set vq->broken as false which is done by * memory write that set vq->broken as false which is done by
* the driver when it sees DRIVER_OK, then the following * the driver when it sees DRIVER_OK, then the following
* driver's vring_interrupt() will see vq->broken as false so * driver's vring_interrupt() will see vq->broken as false so
@@ -384,7 +384,7 @@ const char *virtio_bus_name(struct virtio_device *vdev)
* @vq: the virtqueue * @vq: the virtqueue
* @cpu_mask: the cpu mask * @cpu_mask: the cpu mask
* *
* Pay attention the function are best-effort: the affinity hint may not be set * Note that this function is best-effort: the affinity hint may not be set
* due to config support, irq type and sharing. * due to config support, irq type and sharing.
* *
*/ */

View File

@@ -4,15 +4,16 @@
#include <linux/bits.h> #include <linux/bits.h>
#define VIRTIO_FEATURES_DWORDS 2 #define VIRTIO_FEATURES_U64S 2
#define VIRTIO_FEATURES_MAX (VIRTIO_FEATURES_DWORDS * 64) #define VIRTIO_FEATURES_BITS (VIRTIO_FEATURES_U64S * 64)
#define VIRTIO_FEATURES_WORDS (VIRTIO_FEATURES_DWORDS * 2)
#define VIRTIO_BIT(b) BIT_ULL((b) & 0x3f) #define VIRTIO_BIT(b) BIT_ULL((b) & 0x3f)
#define VIRTIO_DWORD(b) ((b) >> 6) #define VIRTIO_U64(b) ((b) >> 6)
#define VIRTIO_DECLARE_FEATURES(name) \ #define VIRTIO_DECLARE_FEATURES(name) \
union { \ union { \
u64 name; \ u64 name; \
u64 name##_array[VIRTIO_FEATURES_DWORDS];\ u64 name##_array[VIRTIO_FEATURES_U64S];\
} }
static inline bool virtio_features_chk_bit(unsigned int bit) static inline bool virtio_features_chk_bit(unsigned int bit)
@@ -22,9 +23,9 @@ static inline bool virtio_features_chk_bit(unsigned int bit)
* Don't care returning the correct value: the build * Don't care returning the correct value: the build
* will fail before any bad features access * will fail before any bad features access
*/ */
BUILD_BUG_ON(bit >= VIRTIO_FEATURES_MAX); BUILD_BUG_ON(bit >= VIRTIO_FEATURES_BITS);
} else { } else {
if (WARN_ON_ONCE(bit >= VIRTIO_FEATURES_MAX)) if (WARN_ON_ONCE(bit >= VIRTIO_FEATURES_BITS))
return false; return false;
} }
return true; return true;
@@ -34,26 +35,26 @@ static inline bool virtio_features_test_bit(const u64 *features,
unsigned int bit) unsigned int bit)
{ {
return virtio_features_chk_bit(bit) && return virtio_features_chk_bit(bit) &&
!!(features[VIRTIO_DWORD(bit)] & VIRTIO_BIT(bit)); !!(features[VIRTIO_U64(bit)] & VIRTIO_BIT(bit));
} }
static inline void virtio_features_set_bit(u64 *features, static inline void virtio_features_set_bit(u64 *features,
unsigned int bit) unsigned int bit)
{ {
if (virtio_features_chk_bit(bit)) if (virtio_features_chk_bit(bit))
features[VIRTIO_DWORD(bit)] |= VIRTIO_BIT(bit); features[VIRTIO_U64(bit)] |= VIRTIO_BIT(bit);
} }
static inline void virtio_features_clear_bit(u64 *features, static inline void virtio_features_clear_bit(u64 *features,
unsigned int bit) unsigned int bit)
{ {
if (virtio_features_chk_bit(bit)) if (virtio_features_chk_bit(bit))
features[VIRTIO_DWORD(bit)] &= ~VIRTIO_BIT(bit); features[VIRTIO_U64(bit)] &= ~VIRTIO_BIT(bit);
} }
static inline void virtio_features_zero(u64 *features) static inline void virtio_features_zero(u64 *features)
{ {
memset(features, 0, sizeof(features[0]) * VIRTIO_FEATURES_DWORDS); memset(features, 0, sizeof(features[0]) * VIRTIO_FEATURES_U64S);
} }
static inline void virtio_features_from_u64(u64 *features, u64 from) static inline void virtio_features_from_u64(u64 *features, u64 from)
@@ -66,7 +67,7 @@ static inline bool virtio_features_equal(const u64 *f1, const u64 *f2)
{ {
int i; int i;
for (i = 0; i < VIRTIO_FEATURES_DWORDS; ++i) for (i = 0; i < VIRTIO_FEATURES_U64S; ++i)
if (f1[i] != f2[i]) if (f1[i] != f2[i])
return false; return false;
return true; return true;
@@ -74,14 +75,14 @@ static inline bool virtio_features_equal(const u64 *f1, const u64 *f2)
static inline void virtio_features_copy(u64 *to, const u64 *from) static inline void virtio_features_copy(u64 *to, const u64 *from)
{ {
memcpy(to, from, sizeof(to[0]) * VIRTIO_FEATURES_DWORDS); memcpy(to, from, sizeof(to[0]) * VIRTIO_FEATURES_U64S);
} }
static inline void virtio_features_andnot(u64 *to, const u64 *f1, const u64 *f2) static inline void virtio_features_andnot(u64 *to, const u64 *f1, const u64 *f2)
{ {
int i; int i;
for (i = 0; i < VIRTIO_FEATURES_DWORDS; i++) for (i = 0; i < VIRTIO_FEATURES_U64S; i++)
to[i] = f1[i] & ~f2[i]; to[i] = f1[i] & ~f2[i];
} }

View File

@@ -107,7 +107,7 @@ void vp_modern_set_extended_features(struct virtio_pci_modern_device *mdev,
static inline u64 static inline u64
vp_modern_get_features(struct virtio_pci_modern_device *mdev) vp_modern_get_features(struct virtio_pci_modern_device *mdev)
{ {
u64 features_array[VIRTIO_FEATURES_DWORDS]; u64 features_array[VIRTIO_FEATURES_U64S];
vp_modern_get_extended_features(mdev, features_array); vp_modern_get_extended_features(mdev, features_array);
return features_array[0]; return features_array[0];
@@ -116,11 +116,11 @@ vp_modern_get_features(struct virtio_pci_modern_device *mdev)
static inline u64 static inline u64
vp_modern_get_driver_features(struct virtio_pci_modern_device *mdev) vp_modern_get_driver_features(struct virtio_pci_modern_device *mdev)
{ {
u64 features_array[VIRTIO_FEATURES_DWORDS]; u64 features_array[VIRTIO_FEATURES_U64S];
int i; int i;
vp_modern_get_driver_extended_features(mdev, features_array); vp_modern_get_driver_extended_features(mdev, features_array);
for (i = 1; i < VIRTIO_FEATURES_DWORDS; ++i) for (i = 1; i < VIRTIO_FEATURES_U64S; ++i)
WARN_ON_ONCE(features_array[i]); WARN_ON_ONCE(features_array[i]);
return features_array[0]; return features_array[0];
} }
@@ -128,7 +128,7 @@ vp_modern_get_driver_features(struct virtio_pci_modern_device *mdev)
static inline void static inline void
vp_modern_set_features(struct virtio_pci_modern_device *mdev, u64 features) vp_modern_set_features(struct virtio_pci_modern_device *mdev, u64 features)
{ {
u64 features_array[VIRTIO_FEATURES_DWORDS]; u64 features_array[VIRTIO_FEATURES_U64S];
virtio_features_from_u64(features_array, features); virtio_features_from_u64(features_array, features);
vp_modern_set_extended_features(mdev, features_array); vp_modern_set_extended_features(mdev, features_array);

View File

@@ -40,7 +40,7 @@
#define _LINUX_VIRTIO_PCI_H #define _LINUX_VIRTIO_PCI_H
#include <linux/types.h> #include <linux/types.h>
#include <linux/kernel.h> #include <linux/const.h>
#ifndef VIRTIO_PCI_NO_LEGACY #ifndef VIRTIO_PCI_NO_LEGACY