Skip to content

Commit aba21af

Browse files
elic307imstsirkin
authored andcommitted
vdpa: Allow to configure max data virtqueues
Add netlink support to configure the max virtqueue pairs for a device. At least one pair is required. The maximum is dictated by the device. Example: $ vdpa dev add name vdpa-a mgmtdev auxiliary/mlx5_core.sf.1 max_vqp 4 Signed-off-by: Eli Cohen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 30ef7a8 commit aba21af

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

drivers/vdpa/vdpa.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ static void vdpa_get_config_unlocked(struct vdpa_device *vdev,
404404
* If it does happen we assume a legacy guest.
405405
*/
406406
if (!vdev->features_valid)
407-
vdpa_set_features(vdev, 0);
407+
vdpa_set_features(vdev, 0, true);
408408
ops->get_config(vdev, offset, buf, len);
409409
}
410410

@@ -581,7 +581,8 @@ vdpa_nl_cmd_mgmtdev_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb)
581581
}
582582

583583
#define VDPA_DEV_NET_ATTRS_MASK ((1 << VDPA_ATTR_DEV_NET_CFG_MACADDR) | \
584-
(1 << VDPA_ATTR_DEV_NET_CFG_MTU))
584+
(1 << VDPA_ATTR_DEV_NET_CFG_MTU) | \
585+
(1 << VDPA_ATTR_DEV_NET_CFG_MAX_VQP))
585586

586587
static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *info)
587588
{
@@ -607,6 +608,16 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i
607608
nla_get_u16(nl_attrs[VDPA_ATTR_DEV_NET_CFG_MTU]);
608609
config.mask |= (1 << VDPA_ATTR_DEV_NET_CFG_MTU);
609610
}
611+
if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MAX_VQP]) {
612+
config.net.max_vq_pairs =
613+
nla_get_u16(nl_attrs[VDPA_ATTR_DEV_NET_CFG_MAX_VQP]);
614+
if (!config.net.max_vq_pairs) {
615+
NL_SET_ERR_MSG_MOD(info->extack,
616+
"At least one pair of VQs is required");
617+
return -EINVAL;
618+
}
619+
config.mask |= BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP);
620+
}
610621

611622
/* Skip checking capability if user didn't prefer to configure any
612623
* device networking attributes. It is likely that user might have used

drivers/vhost/vdpa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static long vhost_vdpa_set_features(struct vhost_vdpa *v, u64 __user *featurep)
285285
if (copy_from_user(&features, featurep, sizeof(features)))
286286
return -EFAULT;
287287

288-
if (vdpa_set_features(vdpa, features))
288+
if (vdpa_set_features(vdpa, features, false))
289289
return -EINVAL;
290290

291291
return 0;

drivers/virtio/virtio_vdpa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ static int virtio_vdpa_finalize_features(struct virtio_device *vdev)
317317
/* Give virtio_ring a chance to accept features. */
318318
vring_transport_features(vdev);
319319

320-
return vdpa_set_features(vdpa, vdev->features);
320+
return vdpa_set_features(vdpa, vdev->features, false);
321321
}
322322

323323
static const char *virtio_vdpa_bus_name(struct virtio_device *vdev)

include/linux/vdpa.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ struct vdpa_dev_set_config {
101101
struct {
102102
u8 mac[ETH_ALEN];
103103
u16 mtu;
104+
u16 max_vq_pairs;
104105
} net;
105106
u64 mask;
106107
};
@@ -391,17 +392,29 @@ static inline struct device *vdpa_get_dma_dev(struct vdpa_device *vdev)
391392
static inline int vdpa_reset(struct vdpa_device *vdev)
392393
{
393394
const struct vdpa_config_ops *ops = vdev->config;
395+
int ret;
394396

397+
mutex_lock(&vdev->cf_mutex);
395398
vdev->features_valid = false;
396-
return ops->reset(vdev);
399+
ret = ops->reset(vdev);
400+
mutex_unlock(&vdev->cf_mutex);
401+
return ret;
397402
}
398403

399-
static inline int vdpa_set_features(struct vdpa_device *vdev, u64 features)
404+
static inline int vdpa_set_features(struct vdpa_device *vdev, u64 features, bool locked)
400405
{
401406
const struct vdpa_config_ops *ops = vdev->config;
407+
int ret;
408+
409+
if (!locked)
410+
mutex_lock(&vdev->cf_mutex);
402411

403412
vdev->features_valid = true;
404-
return ops->set_driver_features(vdev, features);
413+
ret = ops->set_driver_features(vdev, features);
414+
if (!locked)
415+
mutex_unlock(&vdev->cf_mutex);
416+
417+
return ret;
405418
}
406419

407420
void vdpa_get_config(struct vdpa_device *vdev, unsigned int offset,

0 commit comments

Comments
 (0)