Skip to content

Commit bc69ed9

Browse files
committed
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
2 parents 55aa394 + 205dd7a commit bc69ed9

21 files changed

Lines changed: 131 additions & 86 deletions

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ static int query_virtqueues(struct mlx5_vdpa_net *ndev,
12561256
int vq_idx = start_vq + i;
12571257

12581258
if (cmd->err) {
1259-
mlx5_vdpa_err(mvdev, "query vq %d failed, err: %d\n", vq_idx, err);
1259+
mlx5_vdpa_err(mvdev, "query vq %d failed, err: %d\n", vq_idx, cmd->err);
12601260
if (!err)
12611261
err = cmd->err;
12621262
continue;

drivers/vdpa/octeon_ep/octep_vdpa_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ static int octep_sriov_enable(struct pci_dev *pdev, int num_vfs)
736736
octep_vdpa_assign_barspace(vf_pdev, pdev, index);
737737
if (++index == num_vfs) {
738738
done = true;
739+
pci_dev_put(vf_pdev);
739740
break;
740741
}
741742
}

drivers/vdpa/pds/vdpa_dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static int pds_vdpa_register_event_handler(struct pds_vdpa_device *pdsv)
5151
err = pdsc_register_notify(nb);
5252
if (err) {
5353
nb->notifier_call = NULL;
54-
dev_err(dev, "failed to register pds event handler: %ps\n",
54+
dev_err(dev, "failed to register pds event handler: %pe\n",
5555
ERR_PTR(err));
5656
return -EINVAL;
5757
}

drivers/vdpa/vdpa_user/vduse_dev.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2173,7 +2173,8 @@ static int vduse_init(void)
21732173
if (!vduse_irq_wq)
21742174
goto err_wq;
21752175

2176-
vduse_irq_bound_wq = alloc_workqueue("vduse-irq-bound", WQ_HIGHPRI, 0);
2176+
vduse_irq_bound_wq = alloc_workqueue("vduse-irq-bound",
2177+
WQ_HIGHPRI | WQ_PERCPU, 0);
21772178
if (!vduse_irq_bound_wq)
21782179
goto err_bound_wq;
21792180

drivers/vhost/net.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ MODULE_PARM_DESC(experimental_zcopytx, "Enable Zero Copy TX;"
6969

7070
#define VHOST_DMA_IS_DONE(len) ((__force u32)(len) >= (__force u32)VHOST_DMA_DONE_LEN)
7171

72-
static const u64 vhost_net_features[VIRTIO_FEATURES_DWORDS] = {
73-
VHOST_FEATURES |
74-
(1ULL << VHOST_NET_F_VIRTIO_NET_HDR) |
75-
(1ULL << VIRTIO_NET_F_MRG_RXBUF) |
76-
(1ULL << VIRTIO_F_ACCESS_PLATFORM) |
77-
(1ULL << VIRTIO_F_RING_RESET) |
78-
(1ULL << VIRTIO_F_IN_ORDER),
79-
VIRTIO_BIT(VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO) |
80-
VIRTIO_BIT(VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO),
72+
static const int vhost_net_bits[] = {
73+
VHOST_FEATURES,
74+
VHOST_NET_F_VIRTIO_NET_HDR,
75+
VIRTIO_NET_F_MRG_RXBUF,
76+
VIRTIO_F_ACCESS_PLATFORM,
77+
VIRTIO_F_RING_RESET,
78+
VIRTIO_F_IN_ORDER,
79+
VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO,
80+
VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO
8181
};
8282

8383
enum {
@@ -1731,7 +1731,8 @@ static long vhost_net_set_owner(struct vhost_net *n)
17311731
static long vhost_net_ioctl(struct file *f, unsigned int ioctl,
17321732
unsigned long arg)
17331733
{
1734-
u64 all_features[VIRTIO_FEATURES_DWORDS];
1734+
const DEFINE_VHOST_FEATURES_ARRAY(vhost_net_features, vhost_net_bits);
1735+
u64 all_features[VIRTIO_FEATURES_U64S];
17351736
struct vhost_net *n = f->private_data;
17361737
void __user *argp = (void __user *)arg;
17371738
u64 __user *featurep = argp;
@@ -1763,7 +1764,7 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl,
17631764

17641765
/* Copy the net features, up to the user-provided buffer size */
17651766
argp += sizeof(u64);
1766-
copied = min(count, VIRTIO_FEATURES_DWORDS);
1767+
copied = min(count, (u64)VIRTIO_FEATURES_U64S);
17671768
if (copy_to_user(argp, vhost_net_features,
17681769
copied * sizeof(u64)))
17691770
return -EFAULT;
@@ -1778,13 +1779,13 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl,
17781779

17791780
virtio_features_zero(all_features);
17801781
argp += sizeof(u64);
1781-
copied = min(count, VIRTIO_FEATURES_DWORDS);
1782+
copied = min(count, (u64)VIRTIO_FEATURES_U64S);
17821783
if (copy_from_user(all_features, argp, copied * sizeof(u64)))
17831784
return -EFAULT;
17841785

17851786
/*
17861787
* Any feature specified by user-space above
1787-
* VIRTIO_FEATURES_MAX is not supported by definition.
1788+
* VIRTIO_FEATURES_BITS is not supported by definition.
17881789
*/
17891790
for (i = copied; i < count; ++i) {
17901791
if (copy_from_user(&features, featurep + 1 + i,
@@ -1794,7 +1795,7 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl,
17941795
return -EOPNOTSUPP;
17951796
}
17961797

1797-
for (i = 0; i < VIRTIO_FEATURES_DWORDS; i++)
1798+
for (i = 0; i < VIRTIO_FEATURES_U64S; i++)
17981799
if (all_features[i] & ~vhost_net_features[i])
17991800
return -EOPNOTSUPP;
18001801

drivers/vhost/scsi.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,14 @@ enum {
197197
};
198198

199199
/* Note: can't set VIRTIO_F_VERSION_1 yet, since that implies ANY_LAYOUT. */
200-
enum {
201-
VHOST_SCSI_FEATURES = VHOST_FEATURES | (1ULL << VIRTIO_SCSI_F_HOTPLUG) |
202-
(1ULL << VIRTIO_SCSI_F_T10_PI)
200+
static const int vhost_scsi_bits[] = {
201+
VHOST_FEATURES,
202+
VIRTIO_SCSI_F_HOTPLUG,
203+
VIRTIO_SCSI_F_T10_PI
203204
};
204205

206+
#define VHOST_SCSI_FEATURES VHOST_FEATURES_U64(vhost_scsi_bits, 0)
207+
205208
#define VHOST_SCSI_MAX_TARGET 256
206209
#define VHOST_SCSI_MAX_IO_VQ 1024
207210
#define VHOST_SCSI_MAX_EVENT 128

drivers/vhost/test.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
*/
2929
#define VHOST_TEST_PKT_WEIGHT 256
3030

31+
static const int vhost_test_bits[] = {
32+
VHOST_FEATURES
33+
};
34+
35+
#define VHOST_TEST_FEATURES VHOST_FEATURES_U64(vhost_test_bits, 0)
36+
3137
enum {
3238
VHOST_TEST_VQ = 0,
3339
VHOST_TEST_VQ_MAX = 1,
@@ -328,14 +334,14 @@ static long vhost_test_ioctl(struct file *f, unsigned int ioctl,
328334
return -EFAULT;
329335
return vhost_test_set_backend(n, backend.index, backend.fd);
330336
case VHOST_GET_FEATURES:
331-
features = VHOST_FEATURES;
337+
features = VHOST_TEST_FEATURES;
332338
if (copy_to_user(featurep, &features, sizeof features))
333339
return -EFAULT;
334340
return 0;
335341
case VHOST_SET_FEATURES:
336342
if (copy_from_user(&features, featurep, sizeof features))
337343
return -EFAULT;
338-
if (features & ~VHOST_FEATURES)
344+
if (features & ~VHOST_TEST_FEATURES)
339345
return -EOPNOTSUPP;
340346
return vhost_test_set_features(n, features);
341347
case VHOST_RESET_OWNER:

drivers/vhost/vhost.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,11 +804,13 @@ static int vhost_kthread_worker_create(struct vhost_worker *worker,
804804

805805
ret = vhost_attach_task_to_cgroups(worker);
806806
if (ret)
807-
goto stop_worker;
807+
goto free_id;
808808

809809
worker->id = id;
810810
return 0;
811811

812+
free_id:
813+
xa_erase(&dev->worker_xa, id);
812814
stop_worker:
813815
vhost_kthread_do_stop(worker);
814816
return ret;

drivers/vhost/vhost.h

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/atomic.h>
1515
#include <linux/vhost_iotlb.h>
1616
#include <linux/irqbypass.h>
17+
#include <linux/unroll.h>
1718

1819
struct vhost_work;
1920
struct vhost_task;
@@ -287,14 +288,39 @@ void vhost_iotlb_map_free(struct vhost_iotlb *iotlb,
287288
eventfd_signal((vq)->error_ctx);\
288289
} while (0)
289290

290-
enum {
291-
VHOST_FEATURES = (1ULL << VIRTIO_F_NOTIFY_ON_EMPTY) |
292-
(1ULL << VIRTIO_RING_F_INDIRECT_DESC) |
293-
(1ULL << VIRTIO_RING_F_EVENT_IDX) |
294-
(1ULL << VHOST_F_LOG_ALL) |
295-
(1ULL << VIRTIO_F_ANY_LAYOUT) |
296-
(1ULL << VIRTIO_F_VERSION_1)
297-
};
291+
#define VHOST_FEATURES \
292+
VIRTIO_F_NOTIFY_ON_EMPTY, \
293+
VIRTIO_RING_F_INDIRECT_DESC, \
294+
VIRTIO_RING_F_EVENT_IDX, \
295+
VHOST_F_LOG_ALL, \
296+
VIRTIO_F_ANY_LAYOUT, \
297+
VIRTIO_F_VERSION_1
298+
299+
static inline u64 vhost_features_u64(const int *features, int size, int idx)
300+
{
301+
u64 res = 0;
302+
303+
unrolled_count(VIRTIO_FEATURES_BITS)
304+
for (int i = 0; i < size; ++i) {
305+
int bit = features[i];
306+
307+
if (virtio_features_chk_bit(bit) && VIRTIO_U64(bit) == idx)
308+
res |= VIRTIO_BIT(bit);
309+
}
310+
return res;
311+
}
312+
313+
#define VHOST_FEATURES_U64(features, idx) \
314+
vhost_features_u64(features, ARRAY_SIZE(features), idx)
315+
316+
#define DEFINE_VHOST_FEATURES_ARRAY_ENTRY(idx, features) \
317+
[idx] = VHOST_FEATURES_U64(features, idx),
318+
319+
#define DEFINE_VHOST_FEATURES_ARRAY(array, features) \
320+
u64 array[VIRTIO_FEATURES_U64S] = { \
321+
UNROLL(VIRTIO_FEATURES_U64S, \
322+
DEFINE_VHOST_FEATURES_ARRAY_ENTRY, features) \
323+
}
298324

299325
/**
300326
* vhost_vq_set_backend - Set backend.

drivers/vhost/vsock.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@
2929
*/
3030
#define VHOST_VSOCK_PKT_WEIGHT 256
3131

32-
enum {
33-
VHOST_VSOCK_FEATURES = VHOST_FEATURES |
34-
(1ULL << VIRTIO_F_ACCESS_PLATFORM) |
35-
(1ULL << VIRTIO_VSOCK_F_SEQPACKET)
32+
static const int vhost_vsock_bits[] = {
33+
VHOST_FEATURES,
34+
VIRTIO_F_ACCESS_PLATFORM,
35+
VIRTIO_VSOCK_F_SEQPACKET
3636
};
3737

38+
#define VHOST_VSOCK_FEATURES VHOST_FEATURES_U64(vhost_vsock_bits, 0)
39+
3840
enum {
3941
VHOST_VSOCK_BACKEND_FEATURES = (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2)
4042
};

0 commit comments

Comments
 (0)