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
499 return dev_type;499 return dev_type;
500}500}
501 501
502static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name)502static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
503 const struct vdpa_dev_set_config *config)
503{504{
504 struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev;505 struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev;
505 struct ifcvf_adapter *adapter;506 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
2482 return ret;2482 return ret;
2483}2483}
2484 2484
2485static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name)2485static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
2486 const struct vdpa_dev_set_config *add_config)
2486{2487{
2487 struct mlx5_vdpa_mgmtdev *mgtdev = container_of(v_mdev, struct mlx5_vdpa_mgmtdev, mgtdev);2488 struct mlx5_vdpa_mgmtdev *mgtdev = container_of(v_mdev, struct mlx5_vdpa_mgmtdev, mgtdev);
2488 struct virtio_net_config *config;2489 struct virtio_net_config *config;
drivers/vdpa/vdpa.c+36−2
@@ -14,7 +14,6 @@ · 13 unmodified lines
14#include <uapi/linux/vdpa.h>14#include <uapi/linux/vdpa.h>
15#include <net/genetlink.h>15#include <net/genetlink.h>
16#include <linux/mod_devicetable.h>16#include <linux/mod_devicetable.h>
17#include <linux/virtio_net.h>
18#include <linux/virtio_ids.h>17#include <linux/virtio_ids.h>
19 18
20static LIST_HEAD(mdev_head);19static LIST_HEAD(mdev_head);
@@ -480,9 +479,15 @@ out: · 459 unmodified lines
480 return msg->len;479 return msg->len;
481}480}
482 481
482#define VDPA_DEV_NET_ATTRS_MASK ((1 << VDPA_ATTR_DEV_NET_CFG_MACADDR) | \
483 (1 << VDPA_ATTR_DEV_NET_CFG_MTU))
484
483static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *info)485static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *info)
484{486{
487 struct vdpa_dev_set_config config = {};
488 struct nlattr **nl_attrs = info->attrs;
485 struct vdpa_mgmt_dev *mdev;489 struct vdpa_mgmt_dev *mdev;
490 const u8 *macaddr;
486 const char *name;491 const char *name;
487 int err = 0;492 int err = 0;
488 493
@@ -491,6 +496,26 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i · 2 unmodified lines
491 496
492 name = nla_data(info->attrs[VDPA_ATTR_DEV_NAME]);497 name = nla_data(info->attrs[VDPA_ATTR_DEV_NAME]);
493 498
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
494 mutex_lock(&vdpa_dev_mutex);519 mutex_lock(&vdpa_dev_mutex);
495 mdev = vdpa_mgmtdev_get_from_attr(info->attrs);520 mdev = vdpa_mgmtdev_get_from_attr(info->attrs);
496 if (IS_ERR(mdev)) {521 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
498 err = PTR_ERR(mdev);523 err = PTR_ERR(mdev);
499 goto err;524 goto err;
500 }525 }
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 }
501 532
502 err = mdev->ops->dev_add(mdev, name);533 err = mdev->ops->dev_add(mdev, name, &config);
503err:534err:
504 mutex_unlock(&vdpa_dev_mutex);535 mutex_unlock(&vdpa_dev_mutex);
505 return err;536 return err;
@@ -835,6 +866,9 @@ static const struct nla_policy vdpa_nl_policy[VDPA_ATTR_MAX + 1] = { · 329 unmodified lines
835 [VDPA_ATTR_MGMTDEV_BUS_NAME] = { .type = NLA_NUL_STRING },866 [VDPA_ATTR_MGMTDEV_BUS_NAME] = { .type = NLA_NUL_STRING },
836 [VDPA_ATTR_MGMTDEV_DEV_NAME] = { .type = NLA_STRING },867 [VDPA_ATTR_MGMTDEV_DEV_NAME] = { .type = NLA_STRING },
837 [VDPA_ATTR_DEV_NAME] = { .type = NLA_STRING },868 [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),
838};872};
839 873
840static const struct genl_ops vdpa_nl_ops[] = {874static 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
248 .release = vdpasim_blk_mgmtdev_release,248 .release = vdpasim_blk_mgmtdev_release,
249};249};
250 250
251static int vdpasim_blk_dev_add(struct vdpa_mgmt_dev *mdev, const char *name)251static int vdpasim_blk_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
252 const struct vdpa_dev_set_config *config)
252{253{
253 struct vdpasim_dev_attr dev_attr = {};254 struct vdpasim_dev_attr dev_attr = {};
254 struct vdpasim *simdev;255 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
126 .release = vdpasim_net_mgmtdev_release,126 .release = vdpasim_net_mgmtdev_release,
127};127};
128 128
129static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name)129static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
130 const struct vdpa_dev_set_config *config)
130{131{
131 struct vdpasim_dev_attr dev_attr = {};132 struct vdpasim_dev_attr dev_attr = {};
132 struct vdpasim *simdev;133 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
1503 return 0;1503 return 0;
1504}1504}
1505 1505
1506static int vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name)1506static int vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
1507 const struct vdpa_dev_set_config *config)
1507{1508{
1508 struct vduse_dev *dev;1509 struct vduse_dev *dev;
1509 int ret;1510 int ret;
include/linux/vdpa.h+16−1
@@ -6,6 +6,8 @@ · 5 unmodified lines
6#include <linux/device.h>6#include <linux/device.h>
7#include <linux/interrupt.h>7#include <linux/interrupt.h>
8#include <linux/vhost_iotlb.h>8#include <linux/vhost_iotlb.h>
9#include <linux/virtio_net.h>
10#include <linux/if_ether.h>
9 11
10/**12/**
11 * struct vdpa_calllback - vDPA callback definition.13 * struct vdpa_calllback - vDPA callback definition.
@@ -93,6 +95,14 @@ struct vdpa_iova_range { · 81 unmodified lines
93 u64 last;95 u64 last;
94};96};
95 97
98struct vdpa_dev_set_config {
99 struct {
100 u8 mac[ETH_ALEN];
101 u16 mtu;
102 } net;
103 u64 mask;
104};
105
96/**106/**
97 * Corresponding file area for device memory mapping107 * Corresponding file area for device memory mapping
98 * @file: vma->vm_file for the mapping108 * @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
397 * @dev_add: Add a vdpa device using alloc and register407 * @dev_add: Add a vdpa device using alloc and register
398 * @mdev: parent device to use for device addition408 * @mdev: parent device to use for device addition
399 * @name: name of the new vdpa device409 * @name: name of the new vdpa device
410 * @config: config attributes to apply to the device under creation
400 * Driver need to add a new device using _vdpa_register_device()411 * Driver need to add a new device using _vdpa_register_device()
401 * after fully initializing the vdpa device. Driver must return 0412 * after fully initializing the vdpa device. Driver must return 0
402 * on success or appropriate error code.413 * on success or appropriate error code.
@@ -407,7 +418,8 @@ void vdpa_set_config(struct vdpa_device *dev, unsigned int offset, · 4 unmodified lines
407 * _vdpa_unregister_device().418 * _vdpa_unregister_device().
408 */419 */
409struct vdpa_mgmtdev_ops {420struct 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);
411 void (*dev_del)(struct vdpa_mgmt_dev *mdev, struct vdpa_device *dev);423 void (*dev_del)(struct vdpa_mgmt_dev *mdev, struct vdpa_device *dev);
412};424};
413 425
@@ -416,12 +428,15 @@ struct vdpa_mgmtdev_ops { · 2 unmodified lines
416 * @device: Management parent device428 * @device: Management parent device
417 * @ops: operations supported by management device429 * @ops: operations supported by management device
418 * @id_table: Pointer to device id table of supported ids430 * @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
419 * @list: list entry433 * @list: list entry
420 */434 */
421struct vdpa_mgmt_dev {435struct vdpa_mgmt_dev {
422 struct device *device;436 struct device *device;
423 const struct vdpa_mgmtdev_ops *ops;437 const struct vdpa_mgmtdev_ops *ops;
424 const struct virtio_device_id *id_table;438 const struct virtio_device_id *id_table;
439 u64 config_attr_mask;
425 struct list_head list;440 struct list_head list;
426};441};
427 442

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