History

vdpa: Enable user to set mac and mtu of vdpa device

$ vdpa dev add name bar mgmtdev vdpasim_net mac 00:11:22:33:44:55 mtu 9000 $ vdpa dev config show bar: mac 00:11:22:33:44:55 link up link_announce false mtu 9000 $ vdpa dev config show -jp { "config": { "bar": { "mac": "00:11:22:33:44:55", "link ": "up", "link_announce ": false, "mtu": 9000, } } } Signed-off-by: Parav Pandit <parav@nvidia.com> Reviewed-by: Eli Cohen <elic@nvidia.com> Acked-by: Jason Wang <jasowang@redhat.com>

Parav Pandit committed 5 years ago

Commit d8ca2fa1 parent 960deb37 files · +62 −8Browse files

Unified · Split

7 files
  1. drivers/vdpa/ifcvf/ifcvf_main.c +2 −1
  2. drivers/vdpa/mlx5/net/mlx5_vnet.c +2 −1
  3. drivers/vdpa/vdpa.c +36 −2
  4. drivers/vdpa/vdpa_sim/vdpa_sim_blk.c +2 −1
  5. drivers/vdpa/vdpa_sim/vdpa_sim_net.c +2 −1
  6. drivers/vdpa/vdpa_user/vduse_dev.c +2 −1
  7. include/linux/vdpa.h +16 −1
drivers/vdpa/ifcvf/ifcvf_main.c+2−1
@@ -499,7 +499,8 @@ static u32 get_dev_type(struct pci_dev *pdev) · 498 unmodified lines
499499 return dev_type;
500500 }
501501
502−static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name)
502+static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
503+ const struct vdpa_dev_set_config *config)
503504 {
504505 struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev;
505506 struct ifcvf_adapter *adapter;
drivers/vdpa/mlx5/net/mlx5_vnet.c+2−1
@@ -2482,7 +2482,8 @@ static int event_handler(struct notifier_block *nb, unsigned long event, void *p · 2481 unmodified lines
24822482 return ret;
24832483 }
24842484
2485−static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name)
2485+static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
2486+ const struct vdpa_dev_set_config *add_config)
24862487 {
24872488 struct mlx5_vdpa_mgmtdev *mgtdev = container_of(v_mdev, struct mlx5_vdpa_mgmtdev, mgtdev);
24882489 struct virtio_net_config *config;
drivers/vdpa/vdpa.c+36−2
@@ -14,7 +14,6 @@ · 13 unmodified lines
1414 #include <uapi/linux/vdpa.h>
1515 #include <net/genetlink.h>
1616 #include <linux/mod_devicetable.h>
17−#include <linux/virtio_net.h>
1817 #include <linux/virtio_ids.h>
1918
2019 static LIST_HEAD(mdev_head);
@@ -480,9 +479,15 @@ out: · 459 unmodified lines
480479 return msg->len;
481480 }
482481
482+#define VDPA_DEV_NET_ATTRS_MASK ((1 << VDPA_ATTR_DEV_NET_CFG_MACADDR) | \
483+ (1 << VDPA_ATTR_DEV_NET_CFG_MTU))
484+
483485 static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *info)
484486 {
487+ struct vdpa_dev_set_config config = {};
488+ struct nlattr **nl_attrs = info->attrs;
485489 struct vdpa_mgmt_dev *mdev;
490+ const u8 *macaddr;
486491 const char *name;
487492 int err = 0;
488493
@@ -491,6 +496,26 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i · 2 unmodified lines
491496
492497 name = nla_data(info->attrs[VDPA_ATTR_DEV_NAME]);
493498
499+ if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MACADDR]) {
500+ macaddr = nla_data(nl_attrs[VDPA_ATTR_DEV_NET_CFG_MACADDR]);
501+ memcpy(config.net.mac, macaddr, sizeof(config.net.mac));
502+ config.mask |= (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR);
503+ }
504+ if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MTU]) {
505+ config.net.mtu =
506+ nla_get_u16(nl_attrs[VDPA_ATTR_DEV_NET_CFG_MTU]);
507+ config.mask |= (1 << VDPA_ATTR_DEV_NET_CFG_MTU);
508+ }
509+
510+ /* Skip checking capability if user didn't prefer to configure any
511+ * device networking attributes. It is likely that user might have used
512+ * a device specific method to configure such attributes or using device
513+ * default attributes.
514+ */
515+ if ((config.mask & VDPA_DEV_NET_ATTRS_MASK) &&
516+ !netlink_capable(skb, CAP_NET_ADMIN))
517+ return -EPERM;
518+
494519 mutex_lock(&vdpa_dev_mutex);
495520 mdev = vdpa_mgmtdev_get_from_attr(info->attrs);
496521 if (IS_ERR(mdev)) {
@@ -498,8 +523,14 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i · 1 unmodified line
498523 err = PTR_ERR(mdev);
499524 goto err;
500525 }
526+ if ((config.mask & mdev->config_attr_mask) != config.mask) {
527+ NL_SET_ERR_MSG_MOD(info->extack,
528+ "All provided attributes are not supported");
529+ err = -EOPNOTSUPP;
530+ goto err;
531+ }
501532
502− err = mdev->ops->dev_add(mdev, name);
533+ err = mdev->ops->dev_add(mdev, name, &config);
503534 err:
504535 mutex_unlock(&vdpa_dev_mutex);
505536 return err;
@@ -835,6 +866,9 @@ static const struct nla_policy vdpa_nl_policy[VDPA_ATTR_MAX + 1] = { · 329 unmodified lines
835866 [VDPA_ATTR_MGMTDEV_BUS_NAME] = { .type = NLA_NUL_STRING },
836867 [VDPA_ATTR_MGMTDEV_DEV_NAME] = { .type = NLA_STRING },
837868 [VDPA_ATTR_DEV_NAME] = { .type = NLA_STRING },
869+ [VDPA_ATTR_DEV_NET_CFG_MACADDR] = NLA_POLICY_ETH_ADDR,
870+ /* virtio spec 1.1 section 5.1.4.1 for valid MTU range */
871+ [VDPA_ATTR_DEV_NET_CFG_MTU] = NLA_POLICY_MIN(NLA_U16, 68),
838872 };
839873
840874 static const struct genl_ops vdpa_nl_ops[] = {
drivers/vdpa/vdpa_sim/vdpa_sim_blk.c+2−1
@@ -248,7 +248,8 @@ static struct device vdpasim_blk_mgmtdev = { · 247 unmodified lines
248248 .release = vdpasim_blk_mgmtdev_release,
249249 };
250250
251−static int vdpasim_blk_dev_add(struct vdpa_mgmt_dev *mdev, const char *name)
251+static int vdpasim_blk_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
252+ const struct vdpa_dev_set_config *config)
252253 {
253254 struct vdpasim_dev_attr dev_attr = {};
254255 struct vdpasim *simdev;
drivers/vdpa/vdpa_sim/vdpa_sim_net.c+2−1
@@ -126,7 +126,8 @@ static struct device vdpasim_net_mgmtdev = { · 125 unmodified lines
126126 .release = vdpasim_net_mgmtdev_release,
127127 };
128128
129−static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name)
129+static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
130+ const struct vdpa_dev_set_config *config)
130131 {
131132 struct vdpasim_dev_attr dev_attr = {};
132133 struct vdpasim *simdev;
drivers/vdpa/vdpa_user/vduse_dev.c+2−1
@@ -1503,7 +1503,8 @@ static int vduse_dev_init_vdpa(struct vduse_dev *dev, const char *name) · 1502 unmodified lines
15031503 return 0;
15041504 }
15051505
1506−static int vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name)
1506+static int vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
1507+ const struct vdpa_dev_set_config *config)
15071508 {
15081509 struct vduse_dev *dev;
15091510 int ret;
include/linux/vdpa.h+16−1
@@ -6,6 +6,8 @@ · 5 unmodified lines
66 #include <linux/device.h>
77 #include <linux/interrupt.h>
88 #include <linux/vhost_iotlb.h>
9+#include <linux/virtio_net.h>
10+#include <linux/if_ether.h>
911
1012 /**
1113 * struct vdpa_calllback - vDPA callback definition.
@@ -93,6 +95,14 @@ struct vdpa_iova_range { · 81 unmodified lines
9395 u64 last;
9496 };
9597
98+struct vdpa_dev_set_config {
99+ struct {
100+ u8 mac[ETH_ALEN];
101+ u16 mtu;
102+ } net;
103+ u64 mask;
104+};
105+
96106 /**
97107 * Corresponding file area for device memory mapping
98108 * @file: vma->vm_file for the mapping
@@ -397,6 +407,7 @@ void vdpa_set_config(struct vdpa_device *dev, unsigned int offset, · 298 unmodified lines
397407 * @dev_add: Add a vdpa device using alloc and register
398408 * @mdev: parent device to use for device addition
399409 * @name: name of the new vdpa device
410+ * @config: config attributes to apply to the device under creation
400411 * Driver need to add a new device using _vdpa_register_device()
401412 * after fully initializing the vdpa device. Driver must return 0
402413 * on success or appropriate error code.
@@ -407,7 +418,8 @@ void vdpa_set_config(struct vdpa_device *dev, unsigned int offset, · 4 unmodified lines
407418 * _vdpa_unregister_device().
408419 */
409420 struct vdpa_mgmtdev_ops {
410− int (*dev_add)(struct vdpa_mgmt_dev *mdev, const char *name);
421+ int (*dev_add)(struct vdpa_mgmt_dev *mdev, const char *name,
422+ const struct vdpa_dev_set_config *config);
411423 void (*dev_del)(struct vdpa_mgmt_dev *mdev, struct vdpa_device *dev);
412424 };
413425
@@ -416,12 +428,15 @@ struct vdpa_mgmtdev_ops { · 2 unmodified lines
416428 * @device: Management parent device
417429 * @ops: operations supported by management device
418430 * @id_table: Pointer to device id table of supported ids
431+ * @config_attr_mask: bit mask of attributes of type enum vdpa_attr that
432+ * management device support during dev_add callback
419433 * @list: list entry
420434 */
421435 struct vdpa_mgmt_dev {
422436 struct device *device;
423437 const struct vdpa_mgmtdev_ops *ops;
424438 const struct virtio_device_id *id_table;
439+ u64 config_attr_mask;
425440 struct list_head list;
426441 };
427442

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t