Skip to contentSkip to conversation

vdpa: Enable user to set mac address,

PATCH Superseded Parav Pandit 4 participants 39 messages Feb 24, 2021 – Mar 3, 2021 5 messages not in the archive

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover vdpa: Enable user to set mac address,

Currently user cannot set the mac address and mtu of the vdpa device. This patchset enables users to set the mac address and mtu of the vdpa device once the device is created.
If a vendor driver supports such configuration user can set it otherwise user gets unsupported error.

vdpa mac address and mtu are device configuration layout fields. To keep interface generic enough for multiple types of vdpa devices, mac address and mtu setting is implemented as configuration layout config knobs.
This enables to use similar config layout for other virtio devices.

An example of query & set of config layout fields for vdpa_sim_net driver:

Configuration layout fields are set after device is created.
This enables user to change such fields at later point without destroying and recreating the device for new config.

$ vdpa mgmtdev show
vdpasim_net:
  supported_classes net

Add the device:

$ vdpa dev add name bar mgmtdev vdpasim_net

Configure mac address and mtu:

$ vdpa dev config set bar mac 00:11:22:33:44:55 mtu 9000

In above command only mac address or only mtu can also be set.

View the config after setting:

$ vdpa dev config show
bar: mac 00:11:22:33:44:55 link up link_announce false mtu 9000 speed 0 duplex 0

Patch summary:
Patch-1 uses read only features bit to detect endianness Patch-2 implements new config layout query command
Patch-3 implements callback for setting vdpa net config fields Patch-4 extends vdpa_sim_net driver to implement mac, mtu setting Patch-5 removed redundant get_config callback
Patch-6 mlx5 vdpa driver migrates to user created vdpa device Patch-7 mlx5 vdpa driver uses random mac address when not configured Patch-8 mlx5 vdpa driver supports user provided mac config Patch-9 mlx5 vdpa driver uses user provided mac during rx flow steering

Eli Cohen (4):
vdpa/mlx5: Enable user to add/delete vdpa device vdpa/mlx5: Provide device generated random MAC address vdpa/mlx5: Support configuration of MAC vdpa/mlx5: Forward only packets with allowed MAC address

Parav Pandit (5):
vdpa_sim: Consider read only supported features instead of current
vdpa: Introduce query of device config layout
vdpa: Enable user to set mac and mtu of vdpa device
vdpa_sim_net: Enable user to set mac address and mtu
vdpa_sim_net: Remove redundant get_config callback

 drivers/vdpa/mlx5/net/mlx5_vnet.c    | 185 ++++++++++++++----
 drivers/vdpa/vdpa.c                  | 270 +++++++++++++++++++++++++++
 drivers/vdpa/vdpa_sim/vdpa_sim.h     |   4 +-
 drivers/vdpa/vdpa_sim/vdpa_sim_net.c |  49 +++--
 include/linux/vdpa.h                 |  16 ++
 include/uapi/linux/vdpa.h            |  12 ++
 6 files changed, 476 insertions(+), 60 deletions(-)
Signature · 6 lines
2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#1 lore raw

PATCH 1/9 vdpa_sim: Consider read only supported features instead of current

To honor VIRTIO_F_VERSION_1 feature bit, during endianness detection, consider the read only supported features bit instead of current features bit which can be modified by the driver.

This enables vdpa_sim_net driver to invoke cpu_to_vdpasim16() early enough just after vdpasim device creation in subsequent patch.

---
 drivers/vdpa/vdpa_sim/vdpa_sim.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa_sim/vdpa_sim.h +3 -1
index 6d75444f9948..176d641a0939 100644
@@ -11,6 +11,7 @@
 #include <linux/virtio_byteorder.h>
 #include <linux/vhost_iotlb.h>
 #include <uapi/linux/virtio_config.h>
+#include <linux/bits.h>
 
 #define VDPASIM_FEATURES	((1ULL << VIRTIO_F_ANY_LAYOUT) | \
 				 (1ULL << VIRTIO_F_VERSION_1)  | \
@@ -71,7 +72,8 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *attr);
 static inline bool vdpasim_is_little_endian(struct vdpasim *vdpasim)
 {
 	return virtio_legacy_is_little_endian() ||
-		(vdpasim->features & (1ULL << VIRTIO_F_VERSION_1));
+		(vdpasim->dev_attr.supported_features &
+		 BIT_ULL(VIRTIO_F_VERSION_1));
 }
 
 static inline u16 vdpasim16_to_cpu(struct vdpasim *vdpasim, __virtio16 val)
Signature · 6 lines
2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#2 lore raw

Re: [PATCH linux-next 1/9] vdpa_sim: Consider read only supported features instead of current

Quoted 9 lines · Parav Pandit

To honor VIRTIO_F_VERSION_1 feature bit, during endianness detection, consider the read only supported features bit instead of current features bit which can be modified by the driver.

This enables vdpa_sim_net driver to invoke cpu_to_vdpasim16() early enough just after vdpasim device creation in subsequent patch.

Well that works for legacy and modern devices but not for transitional ones. Without transitional device support vendors are reluctant to add modern features since that will break old guests ... I suspect we need to either add a new ioctl enabling modern mode, or abuse SET_FEATURES and call it from qemu on first config space access.

Quoted 28 lines
---
 drivers/vdpa/vdpa_sim/vdpa_sim.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa_sim/vdpa_sim.h +3 -1
index 6d75444f9948..176d641a0939 100644
@@ -11,6 +11,7 @@
 #include <linux/virtio_byteorder.h>
 #include <linux/vhost_iotlb.h>
 #include <uapi/linux/virtio_config.h>
+#include <linux/bits.h>
 
 #define VDPASIM_FEATURES	((1ULL << VIRTIO_F_ANY_LAYOUT) | \
 				 (1ULL << VIRTIO_F_VERSION_1)  | \
@@ -71,7 +72,8 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *attr);
 static inline bool vdpasim_is_little_endian(struct vdpasim *vdpasim)
 {
 	return virtio_legacy_is_little_endian() ||
-		(vdpasim->features & (1ULL << VIRTIO_F_VERSION_1));
+		(vdpasim->dev_attr.supported_features &
+		 BIT_ULL(VIRTIO_F_VERSION_1));
 }
 
 static inline u16 vdpasim16_to_cpu(struct vdpasim *vdpasim, __virtio16 val)
Signature · 1 line
2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#3 lore raw

RE: [PATCH linux-next 1/9] vdpa_sim: Consider read only supported features instead of current

Hi Michael, Jason,

Quoted 11 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, February 24, 2021 12:40 PM

Quoted 7 lines · Parav Pandit

To honor VIRTIO_F_VERSION_1 feature bit, during endianness detection, consider the read only supported features bit instead of current features bit which can be modified by the driver.

This enables vdpa_sim_net driver to invoke cpu_to_vdpasim16() early enough just after vdpasim device creation in subsequent patch.

Quoted 9 lines
Quoted 2 lines

Well that works for legacy and modern devices but not for transitional ones. Without transitional device support vendors are reluctant to add modern features since that will break old guests ... I suspect we need to either add a new ioctl enabling modern mode, or abuse SET_FEATURES and call it from qemu on first config space access.

From mgmt tool kernel point of view,
(a) config space decoding depends on current feature version bit
(b) feature get/set and config read are not atomic callbacks

Mgmt. tool kernel code need to read them in single call from the vendor driver.
I need to add mgmt_dev->ops->get_features_config(struct virtio_features_config*) calllback that returns value of both atomically in structure like below.

struct virtio_features_config {
	u64 features;
	union {
		struct virtio_net_config net;
		struct virtio_block_config blk;
	} u;
}

What do you think?
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#4 lore raw

Re: [PATCH linux-next 1/9] vdpa_sim: Consider read only supported features instead of current

Quoted 36 lines · Parav Pandit

Hi Michael, Jason,

Quoted 11 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, February 24, 2021 12:40 PM

Quoted 7 lines · Parav Pandit

To honor VIRTIO_F_VERSION_1 feature bit, during endianness detection, consider the read only supported features bit instead of current features bit which can be modified by the driver.

This enables vdpa_sim_net driver to invoke cpu_to_vdpasim16() early enough just after vdpasim device creation in subsequent patch.

Quoted 8 lines
Quoted 2 lines

Well that works for legacy and modern devices but not for transitional ones. Without transitional device support vendors are reluctant to add modern features since that will break old guests ... I suspect we need to either add a new ioctl enabling modern mode, or abuse SET_FEATURES and call it from qemu on first config space access.

From mgmt tool kernel point of view,
(a) config space decoding depends on current feature version bit
(b) feature get/set and config read are not atomic callbacks

Mgmt. tool kernel code need to read them in single call from the vendor driver.
I need to add mgmt_dev->ops->get_features_config(struct virtio_features_config*) calllback that returns value of both atomically in structure like below.

struct virtio_features_config {
	u64 features;
	union {
		struct virtio_net_config net;
		struct virtio_block_config blk;
	} u;
}
Quoted 1 line

What do you think?

I'm wait for Michael to clairfy how the dependency will look like. E.g without multiqueue, should we consider the config as:

struct virtio_net_config {
        u8 mac[6];
        le16 status;
        le16 reserved;
        le16 mtu;
};

or

struct virtio_net_config {
        u8 mac[6];
        le16 status;
        le16 mtu;
};

And I wonder whether or not to reuse config is the best choice which needs to deal with feature.

Thanks

Quoted 1 line

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#5 lore raw

PATCH 2/9 vdpa: Introduce query of device config layout

In reply to Parav Pandit

Introduce a command to query a device config layout.

An example query of network vdpa device:

$ vdpa dev add name bar mgmtdev vdpasim_net
$ vdpa dev config show
bar: mac 00:35:09:19:48:05 link up link_announce false mtu 1500 speed 0 duplex 0
$ vdpa dev config show -jp
{
    "config": {
        "bar": {
            "mac": "00:35:09:19:48:05",
            "link ": "up",
            "link_announce ": false,
            "mtu": 1500,
            "speed": 0,
            "duplex": 0
        }
    }
}

---
changelog:
v1->v2:
- read whole net config layout instead of individual fields
- added error extack for unmanaged vdpa device

---
 drivers/vdpa/vdpa.c       | 181 ++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/vdpa.h |  11 +++
 2 files changed, 192 insertions(+)
drivers/vdpa/vdpa.c +181 -0
index 3d997b389345..cebbba500638 100644
@@ -14,6 +14,8 @@
 #include <uapi/linux/vdpa.h>
 #include <net/genetlink.h>
 #include <linux/mod_devicetable.h>
+#include <linux/virtio_net.h>
+#include <linux/virtio_ids.h>
 
 static LIST_HEAD(mdev_head);
 /* A global mutex that protects vdpa management device and device level operations. */
@@ -603,6 +605,179 @@ static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba
 	return msg->len;
 }
 
+static int vdpa_dev_net_mq_config_fill(struct vdpa_device *vdev,
+				       struct sk_buff *msg,
+				       const struct virtio_net_config *config)
+{
+	u32 hash_types;
+	u16 rss_field;
+	u64 features;
+
+	features = vdev->config->get_features(vdev);
+	if ((features & (1ULL << VIRTIO_NET_F_MQ)) == 0)
+		return 0;
+
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MAX_VQP,
+			config->max_virtqueue_pairs))
+		return -EMSGSIZE;
+	if (nla_put_u8(msg, VDPA_ATTR_DEV_NET_CFG_RSS_MAX_KEY_LEN,
+		       config->rss_max_key_size))
+		return -EMSGSIZE;
+
+	rss_field = le16_to_cpu(config->rss_max_key_size);
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_RSS_MAX_IT_LEN, rss_field))
+		return -EMSGSIZE;
+
+	hash_types = le32_to_cpu(config->supported_hash_types);
+	if (nla_put_u32(msg, VDPA_ATTR_DEV_NET_CFG_RSS_HASH_TYPES,
+			config->supported_hash_types))
+		return -EMSGSIZE;
+	return 0;
+}
+
+static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *msg)
+{
+	struct virtio_net_config config = {};
+
+	vdev->config->get_config(vdev, 0, &config, sizeof(config));
+	if (nla_put(msg, VDPA_ATTR_DEV_NET_CFG_MACADDR, sizeof(config.mac), config.mac))
+		return -EMSGSIZE;
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_STATUS, config.status))
+		return -EMSGSIZE;
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, config.mtu))
+		return -EMSGSIZE;
+	if (nla_put_u32(msg, VDPA_ATTR_DEV_NET_CFG_SPEED, config.speed))
+		return -EMSGSIZE;
+	if (nla_put_u8(msg, VDPA_ATTR_DEV_NET_CFG_DUPLEX, config.duplex))
+		return -EMSGSIZE;
+
+	return vdpa_dev_net_mq_config_fill(vdev, msg, &config);
+}
+
+static int
+vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq,
+		     int flags, struct netlink_ext_ack *extack)
+{
+	u32 device_id;
+	void *hdr;
+	int err;
+
+	hdr = genlmsg_put(msg, portid, seq, &vdpa_nl_family, flags,
+			  VDPA_CMD_DEV_CONFIG_GET);
+	if (!hdr)
+		return -EMSGSIZE;
+
+	if (nla_put_string(msg, VDPA_ATTR_DEV_NAME, dev_name(&vdev->dev))) {
+		err = -EMSGSIZE;
+		goto msg_err;
+	}
+
+	device_id = vdev->config->get_device_id(vdev);
+	if (nla_put_u32(msg, VDPA_ATTR_DEV_ID, device_id)) {
+		err = -EMSGSIZE;
+		goto msg_err;
+	}
+
+	switch (device_id) {
+	case VIRTIO_ID_NET:
+		err = vdpa_dev_net_config_fill(vdev, msg);
+		break;
+	default:
+		err = -EOPNOTSUPP;
+		break;
+	}
+	if (err)
+		goto msg_err;
+
+	genlmsg_end(msg, hdr);
+	return 0;
+
+msg_err:
+	genlmsg_cancel(msg, hdr);
+	return err;
+}
+
+static int vdpa_nl_cmd_dev_config_get_doit(struct sk_buff *skb, struct genl_info *info)
+{
+	struct vdpa_device *vdev;
+	struct sk_buff *msg;
+	const char *devname;
+	struct device *dev;
+	int err;
+
+	if (!info->attrs[VDPA_ATTR_DEV_NAME])
+		return -EINVAL;
+	devname = nla_data(info->attrs[VDPA_ATTR_DEV_NAME]);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
+	if (!msg)
+		return -ENOMEM;
+
+	mutex_lock(&vdpa_dev_mutex);
+	dev = bus_find_device(&vdpa_bus, NULL, devname, vdpa_name_match);
+	if (!dev) {
+		NL_SET_ERR_MSG_MOD(info->extack, "device not found");
+		err = -ENODEV;
+		goto dev_err;
+	}
+	vdev = container_of(dev, struct vdpa_device, dev);
+	if (!vdev->mdev) {
+		NL_SET_ERR_MSG_MOD(info->extack, "unmanaged vdpa device");
+		err = -EINVAL;
+		goto mdev_err;
+	}
+	err = vdpa_dev_config_fill(vdev, msg, info->snd_portid, info->snd_seq,
+				   0, info->extack);
+	if (!err)
+		err = genlmsg_reply(msg, info);
+
+mdev_err:
+	put_device(dev);
+dev_err:
+	mutex_unlock(&vdpa_dev_mutex);
+	if (err)
+		nlmsg_free(msg);
+	return err;
+}
+
+static int vdpa_dev_config_dump(struct device *dev, void *data)
+{
+	struct vdpa_device *vdev = container_of(dev, struct vdpa_device, dev);
+	struct vdpa_dev_dump_info *info = data;
+	int err;
+
+	if (!vdev->mdev)
+		return 0;
+	if (info->idx < info->start_idx) {
+		info->idx++;
+		return 0;
+	}
+	err = vdpa_dev_config_fill(vdev, info->msg, NETLINK_CB(info->cb->skb).portid,
+				   info->cb->nlh->nlmsg_seq, NLM_F_MULTI,
+				   info->cb->extack);
+	if (err)
+		return err;
+
+	info->idx++;
+	return 0;
+}
+
+static int
+vdpa_nl_cmd_dev_config_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb)
+{
+	struct vdpa_dev_dump_info info;
+
+	info.msg = msg;
+	info.cb = cb;
+	info.start_idx = cb->args[0];
+	info.idx = 0;
+
+	mutex_lock(&vdpa_dev_mutex);
+	bus_for_each_dev(&vdpa_bus, NULL, &info, vdpa_dev_config_dump);
+	mutex_unlock(&vdpa_dev_mutex);
+	cb->args[0] = info.idx;
+	return msg->len;
+}
+
 static const struct nla_policy vdpa_nl_policy[VDPA_ATTR_MAX + 1] = {
 	[VDPA_ATTR_MGMTDEV_BUS_NAME] = { .type = NLA_NUL_STRING },
 	[VDPA_ATTR_MGMTDEV_DEV_NAME] = { .type = NLA_STRING },
@@ -634,6 +809,12 @@ static const struct genl_ops vdpa_nl_ops[] = {
 		.doit = vdpa_nl_cmd_dev_get_doit,
 		.dumpit = vdpa_nl_cmd_dev_get_dumpit,
 	},
+	{
+		.cmd = VDPA_CMD_DEV_CONFIG_GET,
+		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+		.doit = vdpa_nl_cmd_dev_config_get_doit,
+		.dumpit = vdpa_nl_cmd_dev_config_get_dumpit,
+	},
 };
 
 static struct genl_family vdpa_nl_family __ro_after_init = {
include/uapi/linux/vdpa.h +11 -0
index 66a41e4ec163..5c31ecc3b956 100644
@@ -17,6 +17,7 @@ enum vdpa_command {
 	VDPA_CMD_DEV_NEW,
 	VDPA_CMD_DEV_DEL,
 	VDPA_CMD_DEV_GET,		/* can dump */
+	VDPA_CMD_DEV_CONFIG_GET,	/* can dump */
 };
 
 enum vdpa_attr {
@@ -33,6 +34,16 @@ enum vdpa_attr {
 	VDPA_ATTR_DEV_MAX_VQS,			/* u32 */
 	VDPA_ATTR_DEV_MAX_VQ_SIZE,		/* u16 */
 
+	VDPA_ATTR_DEV_NET_CFG_MACADDR,		/* binary */
+	VDPA_ATTR_DEV_NET_STATUS,		/* u8 */
+	VDPA_ATTR_DEV_NET_CFG_MAX_VQP,		/* u16 */
+	VDPA_ATTR_DEV_NET_CFG_MTU,		/* u16 */
+	VDPA_ATTR_DEV_NET_CFG_SPEED,		/* u16 */
+	VDPA_ATTR_DEV_NET_CFG_DUPLEX,		/* u16 */
+	VDPA_ATTR_DEV_NET_CFG_RSS_MAX_KEY_LEN,	/* u8 */
+	VDPA_ATTR_DEV_NET_CFG_RSS_MAX_IT_LEN,	/* u16 */
+	VDPA_ATTR_DEV_NET_CFG_RSS_HASH_TYPES,	/* u32 */
+
 	/* new attributes must be added above here */
 	VDPA_ATTR_MAX,
 };
Signature · 6 lines
2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#6 lore raw

Re: [PATCH linux-next 2/9] vdpa: Introduce query of device config layout

Quoted 59 lines · Parav Pandit

Introduce a command to query a device config layout.

An example query of network vdpa device:

$ vdpa dev add name bar mgmtdev vdpasim_net
$ vdpa dev config show
bar: mac 00:35:09:19:48:05 link up link_announce false mtu 1500 speed 0 duplex 0
$ vdpa dev config show -jp
{
    "config": {
        "bar": {
            "mac": "00:35:09:19:48:05",
            "link ": "up",
            "link_announce ": false,
            "mtu": 1500,
            "speed": 0,
            "duplex": 0
        }
    }
}

---
changelog:
v1->v2:
- read whole net config layout instead of individual fields
- added error extack for unmanaged vdpa device

---
 drivers/vdpa/vdpa.c       | 181 ++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/vdpa.h |  11 +++
 2 files changed, 192 insertions(+)
drivers/vdpa/vdpa.c +9 -0
index 3d997b389345..cebbba500638 100644
@@ -14,6 +14,8 @@
 #include <uapi/linux/vdpa.h>
 #include <net/genetlink.h>
 #include <linux/mod_devicetable.h>
+#include <linux/virtio_net.h>
+#include <linux/virtio_ids.h>
 
 static LIST_HEAD(mdev_head);
 /* A global mutex that protects vdpa management device and device level operations. */
@@ -603,6 +605,179 @@ static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba
 	return msg->len;
 }
 
+static int vdpa_dev_net_mq_config_fill(struct vdpa_device *vdev,
+				       struct sk_buff *msg,
+				       const struct virtio_net_config *config)
+{
+	u32 hash_types;
+	u16 rss_field;
+	u64 features;

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 624

Quoted 10 lines
drivers/vdpa/vdpa.c +10 -0
+
+	features = vdev->config->get_features(vdev);
+	if ((features & (1ULL << VIRTIO_NET_F_MQ)) == 0)
+		return 0;
+
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MAX_VQP,
+			config->max_virtqueue_pairs))
+		return -EMSGSIZE;
+	if (nla_put_u8(msg, VDPA_ATTR_DEV_NET_CFG_RSS_MAX_KEY_LEN,
+		       config->rss_max_key_size))

Why is it ok to poke at RSS fields without checking the relevant feature bits?

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 625

Quoted 1 line
drivers/vdpa/vdpa.c +1 -0
+		return -EMSGSIZE;

Did you check this with sparse?
max_virtqueue_pairs is __virtio16.

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 631

Quoted 6 lines
drivers/vdpa/vdpa.c +6 -0
+
+	rss_field = le16_to_cpu(config->rss_max_key_size);
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_RSS_MAX_IT_LEN, rss_field))
+		return -EMSGSIZE;
+
+	hash_types = le32_to_cpu(config->supported_hash_types);

unused variable

Quoted 9 lines
drivers/vdpa/vdpa.c +9 -0
+	if (nla_put_u32(msg, VDPA_ATTR_DEV_NET_CFG_RSS_HASH_TYPES,
+			config->supported_hash_types))
+		return -EMSGSIZE;
+	return 0;
+}
+
+static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *msg)
+{
+	struct virtio_net_config config = {};

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 650

Quoted 10 lines
drivers/vdpa/vdpa.c +10 -0
+
+	vdev->config->get_config(vdev, 0, &config, sizeof(config));
+	if (nla_put(msg, VDPA_ATTR_DEV_NET_CFG_MACADDR, sizeof(config.mac), config.mac))
+		return -EMSGSIZE;
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_STATUS, config.status))
+		return -EMSGSIZE;
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, config.mtu))
+		return -EMSGSIZE;
+	if (nla_put_u32(msg, VDPA_ATTR_DEV_NET_CFG_SPEED, config.speed))
+		return -EMSGSIZE;

looks like a bunch of endian-ness/sparse errors to me, and a bunch of fields checked without checking the feature bits.

Quoted 177 lines
drivers/vdpa/vdpa.c +136 -0
+	if (nla_put_u8(msg, VDPA_ATTR_DEV_NET_CFG_DUPLEX, config.duplex))
+		return -EMSGSIZE;
+
+	return vdpa_dev_net_mq_config_fill(vdev, msg, &config);
+}
+
+static int
+vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq,
+		     int flags, struct netlink_ext_ack *extack)
+{
+	u32 device_id;
+	void *hdr;
+	int err;
+
+	hdr = genlmsg_put(msg, portid, seq, &vdpa_nl_family, flags,
+			  VDPA_CMD_DEV_CONFIG_GET);
+	if (!hdr)
+		return -EMSGSIZE;
+
+	if (nla_put_string(msg, VDPA_ATTR_DEV_NAME, dev_name(&vdev->dev))) {
+		err = -EMSGSIZE;
+		goto msg_err;
+	}
+
+	device_id = vdev->config->get_device_id(vdev);
+	if (nla_put_u32(msg, VDPA_ATTR_DEV_ID, device_id)) {
+		err = -EMSGSIZE;
+		goto msg_err;
+	}
+
+	switch (device_id) {
+	case VIRTIO_ID_NET:
+		err = vdpa_dev_net_config_fill(vdev, msg);
+		break;
+	default:
+		err = -EOPNOTSUPP;
+		break;
+	}
+	if (err)
+		goto msg_err;
+
+	genlmsg_end(msg, hdr);
+	return 0;
+
+msg_err:
+	genlmsg_cancel(msg, hdr);
+	return err;
+}
+
+static int vdpa_nl_cmd_dev_config_get_doit(struct sk_buff *skb, struct genl_info *info)
+{
+	struct vdpa_device *vdev;
+	struct sk_buff *msg;
+	const char *devname;
+	struct device *dev;
+	int err;
+
+	if (!info->attrs[VDPA_ATTR_DEV_NAME])
+		return -EINVAL;
+	devname = nla_data(info->attrs[VDPA_ATTR_DEV_NAME]);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
+	if (!msg)
+		return -ENOMEM;
+
+	mutex_lock(&vdpa_dev_mutex);
+	dev = bus_find_device(&vdpa_bus, NULL, devname, vdpa_name_match);
+	if (!dev) {
+		NL_SET_ERR_MSG_MOD(info->extack, "device not found");
+		err = -ENODEV;
+		goto dev_err;
+	}
+	vdev = container_of(dev, struct vdpa_device, dev);
+	if (!vdev->mdev) {
+		NL_SET_ERR_MSG_MOD(info->extack, "unmanaged vdpa device");
+		err = -EINVAL;
+		goto mdev_err;
+	}
+	err = vdpa_dev_config_fill(vdev, msg, info->snd_portid, info->snd_seq,
+				   0, info->extack);
+	if (!err)
+		err = genlmsg_reply(msg, info);
+
+mdev_err:
+	put_device(dev);
+dev_err:
+	mutex_unlock(&vdpa_dev_mutex);
+	if (err)
+		nlmsg_free(msg);
+	return err;
+}
+
+static int vdpa_dev_config_dump(struct device *dev, void *data)
+{
+	struct vdpa_device *vdev = container_of(dev, struct vdpa_device, dev);
+	struct vdpa_dev_dump_info *info = data;
+	int err;
+
+	if (!vdev->mdev)
+		return 0;
+	if (info->idx < info->start_idx) {
+		info->idx++;
+		return 0;
+	}
+	err = vdpa_dev_config_fill(vdev, info->msg, NETLINK_CB(info->cb->skb).portid,
+				   info->cb->nlh->nlmsg_seq, NLM_F_MULTI,
+				   info->cb->extack);
+	if (err)
+		return err;
+
+	info->idx++;
+	return 0;
+}
+
+static int
+vdpa_nl_cmd_dev_config_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb)
+{
+	struct vdpa_dev_dump_info info;
+
+	info.msg = msg;
+	info.cb = cb;
+	info.start_idx = cb->args[0];
+	info.idx = 0;
+
+	mutex_lock(&vdpa_dev_mutex);
+	bus_for_each_dev(&vdpa_bus, NULL, &info, vdpa_dev_config_dump);
+	mutex_unlock(&vdpa_dev_mutex);
+	cb->args[0] = info.idx;
+	return msg->len;
+}
+
 static const struct nla_policy vdpa_nl_policy[VDPA_ATTR_MAX + 1] = {
 	[VDPA_ATTR_MGMTDEV_BUS_NAME] = { .type = NLA_NUL_STRING },
 	[VDPA_ATTR_MGMTDEV_DEV_NAME] = { .type = NLA_STRING },
@@ -634,6 +809,12 @@ static const struct genl_ops vdpa_nl_ops[] = {
 		.doit = vdpa_nl_cmd_dev_get_doit,
 		.dumpit = vdpa_nl_cmd_dev_get_dumpit,
 	},
+	{
+		.cmd = VDPA_CMD_DEV_CONFIG_GET,
+		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+		.doit = vdpa_nl_cmd_dev_config_get_doit,
+		.dumpit = vdpa_nl_cmd_dev_config_get_dumpit,
+	},
 };
 
 static struct genl_family vdpa_nl_family __ro_after_init = {
include/uapi/linux/vdpa.h +11 -0
index 66a41e4ec163..5c31ecc3b956 100644
@@ -17,6 +17,7 @@ enum vdpa_command {
 	VDPA_CMD_DEV_NEW,
 	VDPA_CMD_DEV_DEL,
 	VDPA_CMD_DEV_GET,		/* can dump */
+	VDPA_CMD_DEV_CONFIG_GET,	/* can dump */
 };
 
 enum vdpa_attr {
@@ -33,6 +34,16 @@ enum vdpa_attr {
 	VDPA_ATTR_DEV_MAX_VQS,			/* u32 */
 	VDPA_ATTR_DEV_MAX_VQ_SIZE,		/* u16 */
 
+	VDPA_ATTR_DEV_NET_CFG_MACADDR,		/* binary */
+	VDPA_ATTR_DEV_NET_STATUS,		/* u8 */
+	VDPA_ATTR_DEV_NET_CFG_MAX_VQP,		/* u16 */
+	VDPA_ATTR_DEV_NET_CFG_MTU,		/* u16 */
+	VDPA_ATTR_DEV_NET_CFG_SPEED,		/* u16 */
+	VDPA_ATTR_DEV_NET_CFG_DUPLEX,		/* u16 */
+	VDPA_ATTR_DEV_NET_CFG_RSS_MAX_KEY_LEN,	/* u8 */
+	VDPA_ATTR_DEV_NET_CFG_RSS_MAX_IT_LEN,	/* u16 */
+	VDPA_ATTR_DEV_NET_CFG_RSS_HASH_TYPES,	/* u32 */
+
 	/* new attributes must be added above here */
 	VDPA_ATTR_MAX,
 };
Signature · 1 line
2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#7 lore raw

RE: [PATCH linux-next 2/9] vdpa: Introduce query of device config layout

Quoted 15 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, February 24, 2021 12:33 PM

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba

Quoted 9 lines
drivers/vdpa/vdpa.c +9 -0
+
+	features = vdev->config->get_features(vdev);
+	if ((features & (1ULL << VIRTIO_NET_F_MQ)) == 0)
+		return 0;
+
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MAX_VQP,
+			config->max_virtqueue_pairs))
+		return -EMSGSIZE;
+	if (nla_put_u8(msg,

VDPA_ATTR_DEV_NET_CFG_RSS_MAX_KEY_LEN,

Quoted 4 lines

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 624

Quoted 1 line
drivers/vdpa/vdpa.c +1 -0
+		       config->rss_max_key_size))

Why is it ok to poke at RSS fields without checking the relevant feature bits?

It should be checked.
I relied on _MQ feature bit but yes, even with MQ, RSS can be off. Will fix to read RSS feature bit.

Quoted 4 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		return -EMSGSIZE;

Did you check this with sparse?
max_virtqueue_pairs is __virtio16.

I will check and go through the types.

Quoted 10 lines

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba

Quoted 4 lines
drivers/vdpa/vdpa.c +3 -0
+
+	rss_field = le16_to_cpu(config->rss_max_key_size);
+	if (nla_put_u16(msg,

VDPA_ATTR_DEV_NET_CFG_RSS_MAX_IT_LEN, rss_field))

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 631

Quoted 3 lines
drivers/vdpa/vdpa.c +3 -0
+		return -EMSGSIZE;
+
+	hash_types = le32_to_cpu(config->supported_hash_types);

unused variable

Will remove.

Quoted 19 lines

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba

Quoted 13 lines
drivers/vdpa/vdpa.c +12 -0
+	if (nla_put_u32(msg, VDPA_ATTR_DEV_NET_CFG_RSS_HASH_TYPES,
+			config->supported_hash_types))
+		return -EMSGSIZE;
+	return 0;
+}
+
+static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct
+sk_buff *msg) {
+	struct virtio_net_config config = {};
+
+	vdev->config->get_config(vdev, 0, &config, sizeof(config));
+	if (nla_put(msg, VDPA_ATTR_DEV_NET_CFG_MACADDR,

sizeof(config.mac), config.mac))

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba

Quoted 4 lines
drivers/vdpa/vdpa.c +4 -0
+		return -EMSGSIZE;
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_STATUS, config.status))
+		return -EMSGSIZE;
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU,

config.mtu))

Quoted 7 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+		return -EMSGSIZE;
+	if (nla_put_u32(msg, VDPA_ATTR_DEV_NET_CFG_SPEED,

config.speed))

Review

Quoted 1 line
(quoted diff) +1 -0
+		return -EMSGSIZE;

looks like a bunch of endian-ness/sparse errors to me, and a bunch of fields checked without checking the feature bits.

Yes, few are missed out.
Fixing them in v2.
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#8 lore raw

Re: [PATCH linux-next 2/9] vdpa: Introduce query of device config layout

In reply to Parav Pandit
Quoted 57 lines · Parav Pandit

Introduce a command to query a device config layout.

An example query of network vdpa device:

$ vdpa dev add name bar mgmtdev vdpasim_net
$ vdpa dev config show
bar: mac 00:35:09:19:48:05 link up link_announce false mtu 1500 speed 0 duplex 0
$ vdpa dev config show -jp
{
     "config": {
         "bar": {
             "mac": "00:35:09:19:48:05",
             "link ": "up",
             "link_announce ": false,
             "mtu": 1500,
             "speed": 0,
             "duplex": 0
         }
     }
}

---
changelog:
v1->v2:
- read whole net config layout instead of individual fields
- added error extack for unmanaged vdpa device

---
  drivers/vdpa/vdpa.c       | 181 ++++++++++++++++++++++++++++++++++++++
  include/uapi/linux/vdpa.h |  11 +++
  2 files changed, 192 insertions(+)
drivers/vdpa/vdpa.c +7 -0
index 3d997b389345..cebbba500638 100644
@@ -14,6 +14,8 @@
  #include <uapi/linux/vdpa.h>
  #include <net/genetlink.h>
  #include <linux/mod_devicetable.h>
+#include <linux/virtio_net.h>
+#include <linux/virtio_ids.h>
 
  static LIST_HEAD(mdev_head);
  /* A global mutex that protects vdpa management device and device level operations. */
@@ -603,6 +605,179 @@ static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba
  	return msg->len;
  }
 
+static int vdpa_dev_net_mq_config_fill(struct vdpa_device *vdev,
+				       struct sk_buff *msg,
+				       const struct virtio_net_config *config)
+{
+	u32 hash_types;

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 622

Quoted 10 lines
drivers/vdpa/vdpa.c +10 -0
+	u16 rss_field;
+	u64 features;
+
+	features = vdev->config->get_features(vdev);
+	if ((features & (1ULL << VIRTIO_NET_F_MQ)) == 0)
+		return 0;
+
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MAX_VQP,
+			config->max_virtqueue_pairs))
+		return -EMSGSIZE;

We probably need to check VIRTIO_NET_F_RSS here.

Quoted 10 lines
drivers/vdpa/vdpa.c +10 -0
+	if (nla_put_u8(msg, VDPA_ATTR_DEV_NET_CFG_RSS_MAX_KEY_LEN,
+		       config->rss_max_key_size))
+		return -EMSGSIZE;
+
+	rss_field = le16_to_cpu(config->rss_max_key_size);
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_RSS_MAX_IT_LEN, rss_field))
+		return -EMSGSIZE;
+
+	hash_types = le32_to_cpu(config->supported_hash_types);
+	if (nla_put_u32(msg, VDPA_ATTR_DEV_NET_CFG_RSS_HASH_TYPES,

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 642

Quoted 10 lines
drivers/vdpa/vdpa.c +10 -0
+			config->supported_hash_types))
+		return -EMSGSIZE;
+	return 0;
+}
+
+static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *msg)
+{
+	struct virtio_net_config config = {};
+
+	vdev->config->get_config(vdev, 0, &config, sizeof(config));

Do we need to sync with other possible get_config calls here?

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 648

Quoted 6 lines
drivers/vdpa/vdpa.c +6 -0
+	if (nla_put(msg, VDPA_ATTR_DEV_NET_CFG_MACADDR, sizeof(config.mac), config.mac))
+		return -EMSGSIZE;
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_STATUS, config.status))
+		return -EMSGSIZE;
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, config.mtu))
+		return -EMSGSIZE;

And check VIRTIO_NET_F_SPEED_DUPLEX.

Quoted 69 lines
drivers/vdpa/vdpa.c +69 -0
+	if (nla_put_u32(msg, VDPA_ATTR_DEV_NET_CFG_SPEED, config.speed))
+		return -EMSGSIZE;
+	if (nla_put_u8(msg, VDPA_ATTR_DEV_NET_CFG_DUPLEX, config.duplex))
+		return -EMSGSIZE;
+
+	return vdpa_dev_net_mq_config_fill(vdev, msg, &config);
+}
+
+static int
+vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq,
+		     int flags, struct netlink_ext_ack *extack)
+{
+	u32 device_id;
+	void *hdr;
+	int err;
+
+	hdr = genlmsg_put(msg, portid, seq, &vdpa_nl_family, flags,
+			  VDPA_CMD_DEV_CONFIG_GET);
+	if (!hdr)
+		return -EMSGSIZE;
+
+	if (nla_put_string(msg, VDPA_ATTR_DEV_NAME, dev_name(&vdev->dev))) {
+		err = -EMSGSIZE;
+		goto msg_err;
+	}
+
+	device_id = vdev->config->get_device_id(vdev);
+	if (nla_put_u32(msg, VDPA_ATTR_DEV_ID, device_id)) {
+		err = -EMSGSIZE;
+		goto msg_err;
+	}
+
+	switch (device_id) {
+	case VIRTIO_ID_NET:
+		err = vdpa_dev_net_config_fill(vdev, msg);
+		break;
+	default:
+		err = -EOPNOTSUPP;
+		break;
+	}
+	if (err)
+		goto msg_err;
+
+	genlmsg_end(msg, hdr);
+	return 0;
+
+msg_err:
+	genlmsg_cancel(msg, hdr);
+	return err;
+}
+
+static int vdpa_nl_cmd_dev_config_get_doit(struct sk_buff *skb, struct genl_info *info)
+{
+	struct vdpa_device *vdev;
+	struct sk_buff *msg;
+	const char *devname;
+	struct device *dev;
+	int err;
+
+	if (!info->attrs[VDPA_ATTR_DEV_NAME])
+		return -EINVAL;
+	devname = nla_data(info->attrs[VDPA_ATTR_DEV_NAME]);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
+	if (!msg)
+		return -ENOMEM;
+
+	mutex_lock(&vdpa_dev_mutex);
+	dev = bus_find_device(&vdpa_bus, NULL, devname, vdpa_name_match);
+	if (!dev) {

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 727

Quoted 10 lines
drivers/vdpa/vdpa.c +10 -0
+		NL_SET_ERR_MSG_MOD(info->extack, "device not found");
+		err = -ENODEV;
+		goto dev_err;
+	}
+	vdev = container_of(dev, struct vdpa_device, dev);
+	if (!vdev->mdev) {
+		NL_SET_ERR_MSG_MOD(info->extack, "unmanaged vdpa device");
+		err = -EINVAL;
+		goto mdev_err;
+	}

Though it's fine but it looks to me mdev is not required to work here.

Quoted 88 lines
drivers/vdpa/vdpa.c +59 -0
+	err = vdpa_dev_config_fill(vdev, msg, info->snd_portid, info->snd_seq,
+				   0, info->extack);
+	if (!err)
+		err = genlmsg_reply(msg, info);
+
+mdev_err:
+	put_device(dev);
+dev_err:
+	mutex_unlock(&vdpa_dev_mutex);
+	if (err)
+		nlmsg_free(msg);
+	return err;
+}
+
+static int vdpa_dev_config_dump(struct device *dev, void *data)
+{
+	struct vdpa_device *vdev = container_of(dev, struct vdpa_device, dev);
+	struct vdpa_dev_dump_info *info = data;
+	int err;
+
+	if (!vdev->mdev)
+		return 0;
+	if (info->idx < info->start_idx) {
+		info->idx++;
+		return 0;
+	}
+	err = vdpa_dev_config_fill(vdev, info->msg, NETLINK_CB(info->cb->skb).portid,
+				   info->cb->nlh->nlmsg_seq, NLM_F_MULTI,
+				   info->cb->extack);
+	if (err)
+		return err;
+
+	info->idx++;
+	return 0;
+}
+
+static int
+vdpa_nl_cmd_dev_config_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb)
+{
+	struct vdpa_dev_dump_info info;
+
+	info.msg = msg;
+	info.cb = cb;
+	info.start_idx = cb->args[0];
+	info.idx = 0;
+
+	mutex_lock(&vdpa_dev_mutex);
+	bus_for_each_dev(&vdpa_bus, NULL, &info, vdpa_dev_config_dump);
+	mutex_unlock(&vdpa_dev_mutex);
+	cb->args[0] = info.idx;
+	return msg->len;
+}
+
  static const struct nla_policy vdpa_nl_policy[VDPA_ATTR_MAX + 1] = {
  	[VDPA_ATTR_MGMTDEV_BUS_NAME] = { .type = NLA_NUL_STRING },
  	[VDPA_ATTR_MGMTDEV_DEV_NAME] = { .type = NLA_STRING },
@@ -634,6 +809,12 @@ static const struct genl_ops vdpa_nl_ops[] = {
  		.doit = vdpa_nl_cmd_dev_get_doit,
  		.dumpit = vdpa_nl_cmd_dev_get_dumpit,
  	},
+	{
+		.cmd = VDPA_CMD_DEV_CONFIG_GET,
+		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+		.doit = vdpa_nl_cmd_dev_config_get_doit,
+		.dumpit = vdpa_nl_cmd_dev_config_get_dumpit,
+	},
  };
 
  static struct genl_family vdpa_nl_family __ro_after_init = {
include/uapi/linux/vdpa.h +4 -0
index 66a41e4ec163..5c31ecc3b956 100644
@@ -17,6 +17,7 @@ enum vdpa_command {
  	VDPA_CMD_DEV_NEW,
  	VDPA_CMD_DEV_DEL,
  	VDPA_CMD_DEV_GET,		/* can dump */
+	VDPA_CMD_DEV_CONFIG_GET,	/* can dump */
  };
 
  enum vdpa_attr {
@@ -33,6 +34,16 @@ enum vdpa_attr {
  	VDPA_ATTR_DEV_MAX_VQS,			/* u32 */
  	VDPA_ATTR_DEV_MAX_VQ_SIZE,		/* u16 */
 
+	VDPA_ATTR_DEV_NET_CFG_MACADDR,		/* binary */
+	VDPA_ATTR_DEV_NET_STATUS,		/* u8 */
+	VDPA_ATTR_DEV_NET_CFG_MAX_VQP,		/* u16 */

include/uapi/linux/vdpa.h enum vdpa_attr { · line 49

Quoted 10 lines
include/uapi/linux/vdpa.h +7 -0
+	VDPA_ATTR_DEV_NET_CFG_MTU,		/* u16 */
+	VDPA_ATTR_DEV_NET_CFG_SPEED,		/* u16 */
+	VDPA_ATTR_DEV_NET_CFG_DUPLEX,		/* u16 */
+	VDPA_ATTR_DEV_NET_CFG_RSS_MAX_KEY_LEN,	/* u8 */
+	VDPA_ATTR_DEV_NET_CFG_RSS_MAX_IT_LEN,	/* u16 */
+	VDPA_ATTR_DEV_NET_CFG_RSS_HASH_TYPES,	/* u32 */
+
  	/* new attributes must be added above here */
  	VDPA_ATTR_MAX,
  };

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#9 lore raw

RE: [PATCH linux-next 2/9] vdpa: Introduce query of device config layout

Quoted 5 lines

From: Jason Wang <[email protected]>
Sent: Wednesday, February 24, 2021 2:18 PM

Quoted 8 lines

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 622

Quoted 4 lines · Parav Pandit
drivers/vdpa/vdpa.c +4 -0
+
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MAX_VQP,
+			config->max_virtqueue_pairs))
+		return -EMSGSIZE;

We probably need to check VIRTIO_NET_F_RSS here.

Yes. Will use it in v2.

Quoted 18 lines

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba

Quoted 8 lines
drivers/vdpa/vdpa.c +6 -0
+	if (nla_put_u8(msg, VDPA_ATTR_DEV_NET_CFG_RSS_MAX_KEY_LEN,
+		       config->rss_max_key_size))
+		return -EMSGSIZE;
+
+	rss_field = le16_to_cpu(config->rss_max_key_size);
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_RSS_MAX_IT_LEN,

rss_field))

Quoted 9 lines
drivers/vdpa/vdpa.c +9 -0
+		return -EMSGSIZE;
+
+	hash_types = le32_to_cpu(config->supported_hash_types);
+	if (nla_put_u32(msg, VDPA_ATTR_DEV_NET_CFG_RSS_HASH_TYPES,
+			config->supported_hash_types))
+		return -EMSGSIZE;
+	return 0;
+}
+
Quoted 8 lines

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 642

Quoted 5 lines
drivers/vdpa/vdpa.c +5 -0
+static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct
+sk_buff *msg) {
+	struct virtio_net_config config = {};
+
+	vdev->config->get_config(vdev, 0, &config, sizeof(config));

Do we need to sync with other possible get_config calls here?

To readers of get_config() is ok. No need to sync.
However, I think set_config() and get_config() should sync otherwise get_config can get partial value. Will probably have to add vdpa_device->config_access_lock().

Quoted 4 lines

Review

Quoted 3 lines
(quoted diff) +1 -0
+	if (nla_put(msg, VDPA_ATTR_DEV_NET_CFG_MACADDR,

sizeof(config.mac), config.mac))

Quoted 8 lines

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 648

Quoted 5 lines
drivers/vdpa/vdpa.c +5 -0
+		return -EMSGSIZE;
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_STATUS, config.status))
+		return -EMSGSIZE;
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, config.mtu))
+		return -EMSGSIZE;

And check VIRTIO_NET_F_SPEED_DUPLEX.

Yes, will do.

Quoted 82 lines

Review

Quoted 3 lines
(quoted diff) +1 -0
+	if (nla_put_u32(msg, VDPA_ATTR_DEV_NET_CFG_SPEED,

config.speed))

Review

Quoted 2 lines
(quoted diff) +2 -0
+		return -EMSGSIZE;
+	if (nla_put_u8(msg, VDPA_ATTR_DEV_NET_CFG_DUPLEX,

config.duplex))

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba

Quoted 6 lines
drivers/vdpa/vdpa.c +6 -0
+		return -EMSGSIZE;
+
+	return vdpa_dev_net_mq_config_fill(vdev, msg, &config); }
+
+static int
+vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32

portid, u32 seq,

Quoted 48 lines
drivers/vdpa/vdpa.c +11 -0
+		     int flags, struct netlink_ext_ack *extack) {
+	u32 device_id;
+	void *hdr;
+	int err;
+
+	hdr = genlmsg_put(msg, portid, seq, &vdpa_nl_family, flags,
+			  VDPA_CMD_DEV_CONFIG_GET);
+	if (!hdr)
+		return -EMSGSIZE;
+
+	if (nla_put_string(msg, VDPA_ATTR_DEV_NAME, dev_name(&vdev-

dev))) {

drivers/vdpa/vdpa.c +36 -0
+		err = -EMSGSIZE;
+		goto msg_err;
+	}
+
+	device_id = vdev->config->get_device_id(vdev);
+	if (nla_put_u32(msg, VDPA_ATTR_DEV_ID, device_id)) {
+		err = -EMSGSIZE;
+		goto msg_err;
+	}
+
+	switch (device_id) {
+	case VIRTIO_ID_NET:
+		err = vdpa_dev_net_config_fill(vdev, msg);
+		break;
+	default:
+		err = -EOPNOTSUPP;
+		break;
+	}
+	if (err)
+		goto msg_err;
+
+	genlmsg_end(msg, hdr);
+	return 0;
+
+msg_err:
+	genlmsg_cancel(msg, hdr);
+	return err;
+}
+
+static int vdpa_nl_cmd_dev_config_get_doit(struct sk_buff *skb,
+struct genl_info *info) {
+	struct vdpa_device *vdev;
+	struct sk_buff *msg;
+	const char *devname;
+	struct device *dev;
+	int err;

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba

Quoted 10 lines
drivers/vdpa/vdpa.c +10 -0
+
+	if (!info->attrs[VDPA_ATTR_DEV_NAME])
+		return -EINVAL;
+	devname = nla_data(info->attrs[VDPA_ATTR_DEV_NAME]);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
+	if (!msg)
+		return -ENOMEM;
+
+	mutex_lock(&vdpa_dev_mutex);
+	dev = bus_find_device(&vdpa_bus, NULL, devname,

vdpa_name_match);

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba

Quoted 8 lines
drivers/vdpa/vdpa.c +8 -0
+	if (!dev) {
+		NL_SET_ERR_MSG_MOD(info->extack, "device not found");
+		err = -ENODEV;
+		goto dev_err;
+	}
+	vdev = container_of(dev, struct vdpa_device, dev);
+	if (!vdev->mdev) {
+		NL_SET_ERR_MSG_MOD(info->extack, "unmanaged vdpa

device");

Quoted 7 lines

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 727

Quoted 3 lines
drivers/vdpa/vdpa.c +3 -0
+		err = -EINVAL;
+		goto mdev_err;
+	}

Though it's fine but it looks to me mdev is not required to work here.

Yes, mdev is not required here. However it was little weird to allow $ vdpa dev config show, but not allow $ vdpa dev show. It transition phase right now. Subsequently will able to allow this as well.
After this series only ifc driver will be left to convert to user created devices.
At that point, this checks will have chance to simplify.
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#10 lore raw

Re: [PATCH linux-next 2/9] vdpa: Introduce query of device config layout

Quoted 37 lines · Parav Pandit
Quoted 11 lines

From: Jason Wang <[email protected]>
Sent: Wednesday, February 24, 2021 2:18 PM

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 622

Quoted 4 lines · Parav Pandit
drivers/vdpa/vdpa.c +4 -0
+
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MAX_VQP,
+			config->max_virtqueue_pairs))
+		return -EMSGSIZE;

We probably need to check VIRTIO_NET_F_RSS here.

Yes. Will use it in v2.

Quoted 8 lines

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba

Quoted 7 lines
drivers/vdpa/vdpa.c +6 -0
+	if (nla_put_u8(msg, VDPA_ATTR_DEV_NET_CFG_RSS_MAX_KEY_LEN,
+		       config->rss_max_key_size))
+		return -EMSGSIZE;
+
+	rss_field = le16_to_cpu(config->rss_max_key_size);
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_RSS_MAX_IT_LEN,

rss_field))

Quoted 16 lines
Quoted 4 lines
drivers/vdpa/vdpa.c +4 -0
+		return -EMSGSIZE;
+
+	hash_types = le32_to_cpu(config->supported_hash_types);
+	if (nla_put_u32(msg, VDPA_ATTR_DEV_NET_CFG_RSS_HASH_TYPES,

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 642

Quoted 10 lines
drivers/vdpa/vdpa.c +10 -0
+			config->supported_hash_types))
+		return -EMSGSIZE;
+	return 0;
+}
+
+static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct
+sk_buff *msg) {
+	struct virtio_net_config config = {};
+
+	vdev->config->get_config(vdev, 0, &config, sizeof(config));

Do we need to sync with other possible get_config calls here?

Quoted 3 lines

To readers of get_config() is ok. No need to sync.
However, I think set_config() and get_config() should sync otherwise get_config can get partial value. Will probably have to add vdpa_device->config_access_lock().

Probably. And the set_config() should be synchronized with the requrest that comes from vDPA bus. This makes me think whether we should go back to two phases method, create and enable.

The vDPA device is only registred after enabling, then there's no need to sync with vDPA bus, and mgmt is not allowed to change config after enalbing?

Quoted 100 lines
Quoted 11 lines

Review

Quoted 3 lines
(quoted diff) +1 -0
+	if (nla_put(msg, VDPA_ATTR_DEV_NET_CFG_MACADDR,

sizeof(config.mac), config.mac))

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 648

Quoted 5 lines
drivers/vdpa/vdpa.c +5 -0
+		return -EMSGSIZE;
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_STATUS, config.status))
+		return -EMSGSIZE;
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, config.mtu))
+		return -EMSGSIZE;

And check VIRTIO_NET_F_SPEED_DUPLEX.

Yes, will do.

Quoted 81 lines

Review

Quoted 2 lines
(quoted diff) +1 -0
+	if (nla_put_u32(msg, VDPA_ATTR_DEV_NET_CFG_SPEED,

config.speed))

Review

Quoted 2 lines
(quoted diff) +2 -0
+		return -EMSGSIZE;
+	if (nla_put_u8(msg, VDPA_ATTR_DEV_NET_CFG_DUPLEX,

config.duplex))

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba

Quoted 6 lines
drivers/vdpa/vdpa.c +6 -0
+		return -EMSGSIZE;
+
+	return vdpa_dev_net_mq_config_fill(vdev, msg, &config); }
+
+static int
+vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32

portid, u32 seq,

Quoted 48 lines
drivers/vdpa/vdpa.c +11 -0
+		     int flags, struct netlink_ext_ack *extack) {
+	u32 device_id;
+	void *hdr;
+	int err;
+
+	hdr = genlmsg_put(msg, portid, seq, &vdpa_nl_family, flags,
+			  VDPA_CMD_DEV_CONFIG_GET);
+	if (!hdr)
+		return -EMSGSIZE;
+
+	if (nla_put_string(msg, VDPA_ATTR_DEV_NAME, dev_name(&vdev-

dev))) {

drivers/vdpa/vdpa.c +36 -0
+		err = -EMSGSIZE;
+		goto msg_err;
+	}
+
+	device_id = vdev->config->get_device_id(vdev);
+	if (nla_put_u32(msg, VDPA_ATTR_DEV_ID, device_id)) {
+		err = -EMSGSIZE;
+		goto msg_err;
+	}
+
+	switch (device_id) {
+	case VIRTIO_ID_NET:
+		err = vdpa_dev_net_config_fill(vdev, msg);
+		break;
+	default:
+		err = -EOPNOTSUPP;
+		break;
+	}
+	if (err)
+		goto msg_err;
+
+	genlmsg_end(msg, hdr);
+	return 0;
+
+msg_err:
+	genlmsg_cancel(msg, hdr);
+	return err;
+}
+
+static int vdpa_nl_cmd_dev_config_get_doit(struct sk_buff *skb,
+struct genl_info *info) {
+	struct vdpa_device *vdev;
+	struct sk_buff *msg;
+	const char *devname;
+	struct device *dev;
+	int err;

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba

Quoted 10 lines
drivers/vdpa/vdpa.c +10 -0
+
+	if (!info->attrs[VDPA_ATTR_DEV_NAME])
+		return -EINVAL;
+	devname = nla_data(info->attrs[VDPA_ATTR_DEV_NAME]);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
+	if (!msg)
+		return -ENOMEM;
+
+	mutex_lock(&vdpa_dev_mutex);
+	dev = bus_find_device(&vdpa_bus, NULL, devname,

vdpa_name_match);

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba

Quoted 8 lines
drivers/vdpa/vdpa.c +8 -0
+	if (!dev) {
+		NL_SET_ERR_MSG_MOD(info->extack, "device not found");
+		err = -ENODEV;
+		goto dev_err;
+	}
+	vdev = container_of(dev, struct vdpa_device, dev);
+	if (!vdev->mdev) {
+		NL_SET_ERR_MSG_MOD(info->extack, "unmanaged vdpa

device");

Quoted 6 lines

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 727

Quoted 3 lines
drivers/vdpa/vdpa.c +3 -0
+		err = -EINVAL;
+		goto mdev_err;
+	}

Though it's fine but it looks to me mdev is not required to work here.

Quoted 4 lines

Yes, mdev is not required here. However it was little weird to allow $ vdpa dev config show, but not allow $ vdpa dev show. It transition phase right now. Subsequently will able to allow this as well.
After this series only ifc driver will be left to convert to user created devices.
At that point, this checks will have chance to simplify.

I agree.

Thanks

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#11 lore raw

RE: [PATCH linux-next 2/9] vdpa: Introduce query of device config layout

Quoted 44 lines

From: Jason Wang <[email protected]>
Sent: Friday, February 26, 2021 1:56 PM

Quoted 37 lines · Parav Pandit
Quoted 11 lines

From: Jason Wang <[email protected]>
Sent: Wednesday, February 24, 2021 2:18 PM

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 622

Quoted 4 lines · Parav Pandit
drivers/vdpa/vdpa.c +4 -0
+
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MAX_VQP,
+			config->max_virtqueue_pairs))
+		return -EMSGSIZE;

We probably need to check VIRTIO_NET_F_RSS here.

Yes. Will use it in v2.

Quoted 24 lines

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba

Quoted 7 lines
drivers/vdpa/vdpa.c +6 -0
+	if (nla_put_u8(msg, VDPA_ATTR_DEV_NET_CFG_RSS_MAX_KEY_LEN,
+		       config->rss_max_key_size))
+		return -EMSGSIZE;
+
+	rss_field = le16_to_cpu(config->rss_max_key_size);
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_RSS_MAX_IT_LEN,

rss_field))

Quoted 4 lines
drivers/vdpa/vdpa.c +4 -0
+		return -EMSGSIZE;
+
+	hash_types = le32_to_cpu(config->supported_hash_types);
+	if (nla_put_u32(msg, VDPA_ATTR_DEV_NET_CFG_RSS_HASH_TYPES,

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 642

Quoted 10 lines
drivers/vdpa/vdpa.c +10 -0
+			config->supported_hash_types))
+		return -EMSGSIZE;
+	return 0;
+}
+
+static int vdpa_dev_net_config_fill(struct vdpa_device *vdev,
+struct sk_buff *msg) {
+	struct virtio_net_config config = {};
+
+	vdev->config->get_config(vdev, 0, &config, sizeof(config));

Do we need to sync with other possible get_config calls here?

Quoted 8 lines
Quoted 2 lines

To readers of get_config() is ok. No need to sync. However, I think set_config() and get_config() should sync otherwise

get_config can get partial value.

Quoted 1 line

Will probably have to add vdpa_device->config_access_lock().

Probably. And the set_config() should be synchronized with the requrest that comes from vDPA bus.

Yes, a rw semaphore is good enough.
Device config fields can be change from the device side anyway, such as link status anyway. Sync using lock shouldn’t be problem.

Quoted 6 lines

This makes me think whether we should go back to
two phases method, create and enable.

The vDPA device is only registred after enabling, then there's no need to sync with vDPA bus, and mgmt is not allowed to change config after enalbing?

In that case we should be able to disable it as well. Disable should take the device of the bus.
I find it weird to have this model to linger around the device without anchoring on the bus.
For example device is not yet enabled, so it is not anchored on the bus, but its name is still have to remain unique.

Do we have to anchor vdpa device on the bus? Can vdpa be a class?
_______________________________________________
Virtualization mailing list [email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#12 lore raw

Re: [PATCH linux-next 2/9] vdpa: Introduce query of device config layout

Quoted 53 lines · Parav Pandit
Quoted 39 lines

From: Jason Wang <[email protected]>
Sent: Friday, February 26, 2021 1:56 PM

Quoted 33 lines · Parav Pandit
Quoted 9 lines

From: Jason Wang <[email protected]>
Sent: Wednesday, February 24, 2021 2:18 PM

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 622

Quoted 4 lines · Parav Pandit
drivers/vdpa/vdpa.c +4 -0
+
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MAX_VQP,
+			config->max_virtqueue_pairs))
+		return -EMSGSIZE;

We probably need to check VIRTIO_NET_F_RSS here.

Yes. Will use it in v2.

Quoted 22 lines

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba

Quoted 6 lines
drivers/vdpa/vdpa.c +6 -0
+	if (nla_put_u8(msg, VDPA_ATTR_DEV_NET_CFG_RSS_MAX_KEY_LEN,
+		       config->rss_max_key_size))
+		return -EMSGSIZE;
+
+	rss_field = le16_to_cpu(config->rss_max_key_size);
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_RSS_MAX_IT_LEN,

rss_field))

Quoted 4 lines
drivers/vdpa/vdpa.c +4 -0
+		return -EMSGSIZE;
+
+	hash_types = le32_to_cpu(config->supported_hash_types);
+	if (nla_put_u32(msg, VDPA_ATTR_DEV_NET_CFG_RSS_HASH_TYPES,

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 642

Quoted 10 lines
drivers/vdpa/vdpa.c +10 -0
+			config->supported_hash_types))
+		return -EMSGSIZE;
+	return 0;
+}
+
+static int vdpa_dev_net_config_fill(struct vdpa_device *vdev,
+struct sk_buff *msg) {
+	struct virtio_net_config config = {};
+
+	vdev->config->get_config(vdev, 0, &config, sizeof(config));

Do we need to sync with other possible get_config calls here?

Quoted 7 lines
Quoted 2 lines

To readers of get_config() is ok. No need to sync. However, I think set_config() and get_config() should sync otherwise

get_config can get partial value.

Quoted 1 line

Will probably have to add vdpa_device->config_access_lock().

Probably. And the set_config() should be synchronized with the requrest that comes from vDPA bus.

Yes, a rw semaphore is good enough.
Device config fields can be change from the device side anyway, such as link status anyway. Sync using lock shouldn’t be problem.

Quoted 3 lines

This makes me think whether we should go back to
two phases method, create and enable.

Quoted 6 lines
Quoted 3 lines

The vDPA device is only registred after enabling, then there's no need to sync with vDPA bus, and mgmt is not allowed to change config after enalbing?

In that case we should be able to disable it as well. Disable should take the device of the bus.
I find it weird to have this model to linger around the device without anchoring on the bus.
For example device is not yet enabled, so it is not anchored on the bus, but its name is still have to remain unique.

Can we do some synchornization between vdpa device allocation and vdpa device registier to solve the naming issue?

Quoted 2 lines

Do we have to anchor vdpa device on the bus? Can vdpa be a class?

I think not, it's a bus that is expected to be bound to different driver instead of a subsystem.

Thanks

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#13 lore raw

RE: [PATCH linux-next 2/9] vdpa: Introduce query of device config layout

Quoted 70 lines

From: Jason Wang <[email protected]>
Sent: Monday, March 1, 2021 9:29 AM

Quoted 5 lines · Parav Pandit
Quoted 5 lines

From: Jason Wang <[email protected]>
Sent: Friday, February 26, 2021 1:56 PM

Quoted 7 lines
Quoted 7 lines · Parav Pandit
Quoted 6 lines
Quoted 6 lines

From: Jason Wang <[email protected]>
Sent: Wednesday, February 24, 2021 2:18 PM

Review

Quoted 2 lines · Parav Pandit
(quoted diff) +2 -0
+
+	if (nla_put_u16(msg,

VDPA_ATTR_DEV_NET_CFG_MAX_VQP,

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+			config->max_virtqueue_pairs))
+		return -EMSGSIZE;

We probably need to check VIRTIO_NET_F_RSS here.

Yes. Will use it in v2.

Quoted 1 line

Review

Quoted 1 line
(quoted diff) +1 -0
+	if (nla_put_u8(msg,

VDPA_ATTR_DEV_NET_CFG_RSS_MAX_KEY_LEN,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba

Quoted 5 lines
drivers/vdpa/vdpa.c +5 -0
+		       config->rss_max_key_size))
+		return -EMSGSIZE;
+
+	rss_field = le16_to_cpu(config->rss_max_key_size);
+	if (nla_put_u16(msg,

VDPA_ATTR_DEV_NET_CFG_RSS_MAX_IT_LEN,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

rss_field))

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba

Quoted 4 lines
drivers/vdpa/vdpa.c +4 -0
+		return -EMSGSIZE;
+
+	hash_types = le32_to_cpu(config->supported_hash_types);
+	if (nla_put_u32(msg,

VDPA_ATTR_DEV_NET_CFG_RSS_HASH_TYPES,

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 11 lines

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba · line 642

Quoted 10 lines
drivers/vdpa/vdpa.c +10 -0
+			config->supported_hash_types))
+		return -EMSGSIZE;
+	return 0;
+}
+
+static int vdpa_dev_net_config_fill(struct vdpa_device *vdev,
+struct sk_buff *msg) {
+	struct virtio_net_config config = {};
+
+	vdev->config->get_config(vdev, 0, &config, sizeof(config));

Do we need to sync with other possible get_config calls here?

To readers of get_config() is ok. No need to sync. However, I think set_config() and get_config() should sync otherwise

Quoted 7 lines
Quoted 5 lines

get_config can get partial value.

Quoted 1 line

Will probably have to add vdpa_device->config_access_lock().

Probably. And the set_config() should be synchronized with the requrest that comes from vDPA bus.

Yes, a rw semaphore is good enough.
Device config fields can be change from the device side anyway, such as

link status anyway.

Quoted 7 lines

Sync using lock shouldn’t be problem.

Quoted 5 lines

This makes me think whether we should go back to two phases method, create and enable.

The vDPA device is only registred after enabling, then there's no need to sync with vDPA bus, and mgmt is not allowed to change config

after enalbing?

Quoted 2 lines
Quoted 1 line

In that case we should be able to disable it as well. Disable should take the

device of the bus.

Quoted 8 lines
Quoted 1 line

I find it weird to have this model to linger around the device without

anchoring on the bus.

Quoted 1 line

For example device is not yet enabled, so it is not anchored on the bus, but

its name is still have to remain unique.

Can we do some synchornization between vdpa device allocation and vdpa device registier to solve the naming issue?

mgmt tool querying the device config space after vdpa device is in use is real. So I don't see solving it any differently.

Now upper layers of vdpa to not access the device on the placed on the vdpa bus, can be taken care by existing driver code using echo 0 > /sys/bus/vdpa/drivers_autoprobe

By default vdpa device placed on the bus wont bind to any driver (net/vhost etc).
1. Decision to bind to which driver is done after config of the vdpa device is done.
2. orchestration sw does create and config before it binds to the right driver
3. which driver to bind to decided based on the use case of that individual vdpa device For example,
(a) vdpa0 binds to net driver to have Netdev for container
(b) vdpa1 binds to vhost driver to map vdpa device to VM

Quoted 6 lines
Quoted 2 lines

Do we have to anchor vdpa device on the bus? Can vdpa be a class?

I think not, it's a bus that is expected to be bound to different driver instead of a subsystem.

Yeah, I realized it lately after writing the previous email.
Lets see if above scheme works or not to use existing drivers_autoprobe file.
_______________________________________________
Virtualization mailing list [email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#14 lore raw

Re: [PATCH linux-next 2/9] vdpa: Introduce query of device config layout

Quoted 80 lines · Parav Pandit
Quoted 66 lines

From: Jason Wang <[email protected]>
Sent: Monday, March 1, 2021 9:29 AM

Quoted 11 lines · Parav Pandit
Quoted 11 lines

From: Jason Wang <[email protected]>
Sent: Friday, February 26, 2021 1:56 PM

Quoted 6 lines · Parav Pandit
Quoted 6 lines

From: Jason Wang <[email protected]>
Sent: Wednesday, February 24, 2021 2:18 PM

Review

Quoted 2 lines · Parav Pandit
(quoted diff) +2 -0
+
+	if (nla_put_u16(msg,

VDPA_ATTR_DEV_NET_CFG_MAX_VQP,

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+			config->max_virtqueue_pairs))
+		return -EMSGSIZE;

We probably need to check VIRTIO_NET_F_RSS here.

Yes. Will use it in v2.

Quoted 1 line

Review

Quoted 1 line
(quoted diff) +1 -0
+	if (nla_put_u8(msg,

VDPA_ATTR_DEV_NET_CFG_RSS_MAX_KEY_LEN,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+		       config->rss_max_key_size))
+		return -EMSGSIZE;
+
+	rss_field = le16_to_cpu(config->rss_max_key_size);
+	if (nla_put_u16(msg,

VDPA_ATTR_DEV_NET_CFG_RSS_MAX_IT_LEN,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

rss_field))

Review

Quoted 4 lines
(quoted diff) +4 -0
+		return -EMSGSIZE;
+
+	hash_types = le32_to_cpu(config->supported_hash_types);
+	if (nla_put_u32(msg,

VDPA_ATTR_DEV_NET_CFG_RSS_HASH_TYPES,

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Review

Quoted 10 lines
(quoted diff) +10 -0
+			config->supported_hash_types))
+		return -EMSGSIZE;
+	return 0;
+}
+
+static int vdpa_dev_net_config_fill(struct vdpa_device *vdev,
+struct sk_buff *msg) {
+	struct virtio_net_config config = {};
+
+	vdev->config->get_config(vdev, 0, &config, sizeof(config));

Do we need to sync with other possible get_config calls here?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

To readers of get_config() is ok. No need to sync. However, I think set_config() and get_config() should sync otherwise

get_config can get partial value.

Quoted 1 line

Will probably have to add vdpa_device->config_access_lock().

Probably. And the set_config() should be synchronized with the requrest that comes from vDPA bus.

Yes, a rw semaphore is good enough.
Device config fields can be change from the device side anyway, such as

link status anyway.

Quoted 7 lines

Sync using lock shouldn’t be problem.

Quoted 5 lines

This makes me think whether we should go back to two phases method, create and enable.

The vDPA device is only registred after enabling, then there's no need to sync with vDPA bus, and mgmt is not allowed to change config

after enalbing?

Quoted 1 line

In that case we should be able to disable it as well. Disable should take the

device of the bus.

Quoted 8 lines
Quoted 1 line

I find it weird to have this model to linger around the device without

anchoring on the bus.

Quoted 1 line

For example device is not yet enabled, so it is not anchored on the bus, but

its name is still have to remain unique.

Can we do some synchornization between vdpa device allocation and vdpa device registier to solve the naming issue?

mgmt tool querying the device config space after vdpa device is in use is real. So I don't see solving it any differently.

Now upper layers of vdpa to not access the device on the placed on the vdpa bus, can be taken care by existing driver code using echo 0 > /sys/bus/vdpa/drivers_autoprobe

Quoted 7 lines

By default vdpa device placed on the bus wont bind to any driver (net/vhost etc).
1. Decision to bind to which driver is done after config of the vdpa device is done.
2. orchestration sw does create and config before it binds to the right driver
3. which driver to bind to decided based on the use case of that individual vdpa device For example,
(a) vdpa0 binds to net driver to have Netdev for container
(b) vdpa1 binds to vhost driver to map vdpa device to VM

I think it should work.

Adding Adrian, Maxime and Sean for more comments.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Do we have to anchor vdpa device on the bus? Can vdpa be a class?

I think not, it's a bus that is expected to be bound to different driver instead of a subsystem.

Yeah, I realized it lately after writing the previous email.
Lets see if above scheme works or not to use existing drivers_autoprobe file.

Yes.

Thanks

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#15 lore raw

Re: [PATCH linux-next 2/9] vdpa: Introduce query of device config layout

Quoted 94 lines · Jason Wang
Quoted 81 lines · Parav Pandit
Quoted 66 lines

From: Jason Wang <[email protected]>
Sent: Monday, March 1, 2021 9:29 AM

Quoted 11 lines · Parav Pandit
Quoted 11 lines

From: Jason Wang <[email protected]>
Sent: Friday, February 26, 2021 1:56 PM

Quoted 6 lines · Parav Pandit
Quoted 6 lines

From: Jason Wang <[email protected]>
Sent: Wednesday, February 24, 2021 2:18 PM

Quoted 2 lines · Parav Pandit

+
+    if (nla_put_u16(msg,

VDPA_ATTR_DEV_NET_CFG_MAX_VQP,

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

+            config->max_virtqueue_pairs))
+        return -EMSGSIZE;

We probably need to check VIRTIO_NET_F_RSS here.

Yes. Will use it in v2.

Quoted 1 line
Quoted 1 line

+    if (nla_put_u8(msg,

VDPA_ATTR_DEV_NET_CFG_RSS_MAX_KEY_LEN,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

+               config->rss_max_key_size))
+        return -EMSGSIZE;
+
+    rss_field = le16_to_cpu(config->rss_max_key_size); +    if (nla_put_u16(msg,

VDPA_ATTR_DEV_NET_CFG_RSS_MAX_IT_LEN,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

rss_field))

Quoted 4 lines

+        return -EMSGSIZE;
+
+    hash_types = le32_to_cpu(config->supported_hash_types); +    if (nla_put_u32(msg,

VDPA_ATTR_DEV_NET_CFG_RSS_HASH_TYPES,

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Review

Quoted 10 lines

+            config->supported_hash_types))
+        return -EMSGSIZE;
+    return 0;

(quoted diff) +7 -0
+}
+
+static int vdpa_dev_net_config_fill(struct vdpa_device *vdev,
+struct sk_buff *msg) {
+    struct virtio_net_config config = {};
+
+    vdev->config->get_config(vdev, 0, &config, sizeof(config));

Do we need to sync with other possible get_config calls here?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

To readers of get_config() is ok. No need to sync. However, I think set_config() and get_config() should sync otherwise

get_config can get partial value.

Quoted 1 line

Will probably have to add vdpa_device->config_access_lock().

Probably. And the set_config() should be synchronized with the requrest that comes from vDPA bus.

Yes, a rw semaphore is good enough.
Device config fields can be change from the device side anyway, such as

link status anyway.

Quoted 7 lines

Sync using lock shouldn’t be problem.

Quoted 5 lines

This makes me think whether we should go back to two phases method, create and enable.

The vDPA device is only registred after enabling, then there's no need to sync with vDPA bus, and mgmt is not allowed to change config

after enalbing?

Quoted 1 line

In that case we should be able to disable it as well. Disable should take the

device of the bus.

Quoted 8 lines
Quoted 1 line

I find it weird to have this model to linger around the device without

anchoring on the bus.

Quoted 1 line

For example device is not yet enabled, so it is not anchored on the bus, but

its name is still have to remain unique.

Can we do some synchornization between vdpa device allocation and vdpa device registier to solve the naming issue?

mgmt tool querying the device config space after vdpa device is in use is real. So I don't see solving it any differently.

Now upper layers of vdpa to not access the device on the placed on the vdpa bus, can be taken care by existing driver code using
echo 0 > /sys/bus/vdpa/drivers_autoprobe

Quoted 9 lines

By default vdpa device placed on the bus wont bind to any driver (net/vhost etc).
1. Decision to bind to which driver is done after config of the vdpa device is done.
2. orchestration sw does create and config before it binds to the right driver
3. which driver to bind to decided based on the use case of that individual vdpa device
For example,
(a) vdpa0 binds to net driver to have Netdev for container
(b) vdpa1 binds to vhost driver to map vdpa device to VM

Quoted 2 lines

I think it should work.

Quoted 1 line

Adding Adrian, Maxime and Sean for more comments.

Is this a strong requirement or just a optional operation?
This might break some existing logic that expects netdev or vhost-vdpa device to exist before the some config (e.g:mac address) is set.

Thanks

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

A message that is not in the archive (sent off-list or not yet received): [email protected]

#17 lore raw

Re: [PATCH linux-next 2/9] vdpa: Introduce query of device config layout

Quoted 93 lines · Sean Mooney
Quoted 92 lines · Adrian Moreno
Quoted 91 lines · Jason Wang
Quoted 89 lines · Parav Pandit
Quoted 65 lines

From: Jason Wang <[email protected]>
Sent: Monday, March 1, 2021 9:29 AM

Quoted 11 lines · Parav Pandit
Quoted 11 lines

From: Jason Wang <[email protected]>
Sent: Friday, February 26, 2021 1:56 PM

Quoted 6 lines · Parav Pandit
Quoted 6 lines

From: Jason Wang <[email protected]>
Sent: Wednesday, February 24, 2021 2:18 PM

Quoted 2 lines · Parav Pandit

+
+    if (nla_put_u16(msg,

VDPA_ATTR_DEV_NET_CFG_MAX_VQP,

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

+            config->max_virtqueue_pairs))
+        return -EMSGSIZE;

We probably need to check VIRTIO_NET_F_RSS here.

Yes. Will use it in v2.

Quoted 1 line
Quoted 1 line

+    if (nla_put_u8(msg,

VDPA_ATTR_DEV_NET_CFG_RSS_MAX_KEY_LEN,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

+               config->rss_max_key_size))
+        return -EMSGSIZE;
+
+    rss_field = le16_to_cpu(config->rss_max_key_size); +    if (nla_put_u16(msg,

VDPA_ATTR_DEV_NET_CFG_RSS_MAX_IT_LEN,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

rss_field))

Quoted 4 lines

+        return -EMSGSIZE;
+
+    hash_types = le32_to_cpu(config->supported_hash_types); +    if (nla_put_u32(msg,

VDPA_ATTR_DEV_NET_CFG_RSS_HASH_TYPES,

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Review

Quoted 10 lines

+            config->supported_hash_types))
+        return -EMSGSIZE;
+    return 0;

(quoted diff) +7 -0
+}
+
+static int vdpa_dev_net_config_fill(struct vdpa_device *vdev,
+struct sk_buff *msg) {
+    struct virtio_net_config config = {};
+
+    vdev->config->get_config(vdev, 0, &config, sizeof(config));

Do we need to sync with other possible get_config calls here?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

To readers of get_config() is ok. No need to sync. However, I think set_config() and get_config() should sync otherwise

get_config can get partial value.

Quoted 1 line

Will probably have to add vdpa_device->config_access_lock().

Probably. And the set_config() should be synchronized with the requrest that comes from vDPA bus.

Yes, a rw semaphore is good enough.
Device config fields can be change from the device side anyway, such as

link status anyway.

Quoted 7 lines

Sync using lock shouldn’t be problem.

Quoted 5 lines

This makes me think whether we should go back to two phases method, create and enable.

The vDPA device is only registred after enabling, then there's no need to sync with vDPA bus, and mgmt is not allowed to change config

after enalbing?

Quoted 1 line

In that case we should be able to disable it as well. Disable should take the

device of the bus.

Quoted 8 lines
Quoted 1 line

I find it weird to have this model to linger around the device without

anchoring on the bus.

Quoted 1 line

For example device is not yet enabled, so it is not anchored on the bus, but

its name is still have to remain unique.

Can we do some synchornization between vdpa device allocation and vdpa device registier to solve the naming issue?

mgmt tool querying the device config space after vdpa device is in use is real. So I don't see solving it any differently.

Now upper layers of vdpa to not access the device on the placed on the vdpa bus, can be taken care by existing driver code using
echo 0 > /sys/bus/vdpa/drivers_autoprobe

By default vdpa device placed on the bus wont bind to any driver (net/vhost etc).
1. Decision to bind to which driver is done after config of the vdpa device is done.
2. orchestration sw does create and config before it binds to the right driver
3. which driver to bind to decided based on the use case of that individual vdpa device
For example,
(a) vdpa0 binds to net driver to have Netdev for container
(b) vdpa1 binds to vhost driver to map vdpa device to VM

Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

I think it should work.

Quoted 1 line

Adding Adrian, Maxime and Sean for more comments.

Is this a strong requirement or just a optional operation?

So my understanding is that something needs to be done to make sure:

1) the vpda device is not bound to virtio-vdpa
2) config is not changed if it has been set by management

Quoted 11 lines
Quoted 2 lines

This might break some existing logic that expects netdev or vhost-vdpa device to exist before the some config (e.g:mac address) is set.

the orcestration software should not require permission to do dirver binding and in the case of openstack will not have the capablity to bind the vdpa device to a dirvier in the current proposed design. the ordering we are expecting to support in openstack at least initally is that the adminsitrator will use either systemd service files or udev rules to allocate the VF and vdpa device staictly at boot.

in the case of openstack we will expect all vdpa devies that will be used by openstack(nova) for assignment to vms will be prebound by the adminstrators to vhost-vdpa. openstack will simply track the /dev/vhost* paths corallated to the vdpa devices whose parent VF are allowed by the pci passthough whitelist.

Quoted 8 lines

if the adminstrator binds the vdpa device to virtio-vdpa so that virtio-net-pci is used on the host nova and libvirt will not correct that and the vm boot will fail. but provided you do not list that parent VF in the whitelist nova will also ignore it. so if you want to mix and match the vdpa device driver that should not break anything provided you do not list its parent in the pci whitelist.

but one thing to keep in mind is whlie we are not planning to create VF/VDPA devices dynamiclaly at lesat not for the initall implentation we do expact to be able to configure attibute of the vdpa device after tehy are create like any other nic. for example the mac, mtu, link-state should all be configureable at runtime via normal ip route2 commands.

So in the case of vDPA, this task is expected to be done by vdpa tool. (There's no guarantee that vDPA is a VF).

Quoted 4 lines

at the morment we are encounterng issue with the mac adress specificly which qemu is hopefully going to work around since libvirt and nova cannot currently configure the mac address of a vhost-vdpa device so we are relying on qemu to take the mac adress form the qemu command line so that it does not end up as all 0 macs in the guest.

Note that a kernel patch is posted by Eli[1] which assign a randomized mac. This should solve the issue in another way.

Quoted 4 lines

as some one that works on orcestration level i would have expect that setting the mac/mtu on either the vf or the netdev representor to match the deireed mac/mtu in the guest would have been sufficent to alter the vdpa device confirutation. likely the netdev representor would make the most sence to alter to match the desired mac so that the mac adress see on the ovs bridge matches the mac of the vm.

Speaking for genreal vDPA, it's not guaranteed that the vendor will implmenet the device with a representor. So vDPA tool is expected to be the only way to configure the device.

Thanks

[1] https://www.spinics.net/lists/linux-virtualization/msg48451.html

Quoted 11 lines

the current case where the vdpa representor netdev seams to have no bareing on the vdpa device
config makes debugging much more difficalt and is likely to confuse monitoring software. fortunetly openstack is not matching on the mac address in this spefic case to identify the netdev represntor port but we have other backend that do look at the mac. in the case of ovs we store the uuid of the neutron port in the ovsdb when adding a port to ovs so we rely on that not the mac but for legacy mode sriov which we hope to support with vdpa eventulally after we comple the hardware offloaed ovs support, currenlty relys on the mac in some cases.

i hope that answered your questions?
we are aware that we likely will have to support vdpa device creation at some point if we intend to add support for vdpa devices created form subfunctions or intels siov howver that was not ready when we started this work so it was declared out of scope and the curernt static approch was taken as the only path we could enable before code free in 10 days.

Quoted 7 lines

regards sean.

Quoted 3 lines

Thanks

https://www.spinics.net/lists/linux-virtualization/msg48451.html

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#18 lore raw

Re: [PATCH linux-next 2/9] vdpa: Introduce query of device config layout

Quoted 99 lines · Jason Wang
Quoted 97 lines · Sean Mooney
Quoted 96 lines · Adrian Moreno
Quoted 95 lines · Jason Wang
Quoted 82 lines · Parav Pandit
Quoted 66 lines

From: Jason Wang <[email protected]>
Sent: Monday, March 1, 2021 9:29 AM

Quoted 11 lines · Parav Pandit
Quoted 11 lines

From: Jason Wang <[email protected]>
Sent: Friday, February 26, 2021 1:56 PM

Quoted 6 lines · Parav Pandit
Quoted 6 lines

From: Jason Wang <[email protected]>
Sent: Wednesday, February 24, 2021 2:18 PM

Quoted 2 lines · Parav Pandit

+
+    if (nla_put_u16(msg,

VDPA_ATTR_DEV_NET_CFG_MAX_VQP,

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

+            config->max_virtqueue_pairs))
+        return -EMSGSIZE;

We probably need to check VIRTIO_NET_F_RSS here.

Yes. Will use it in v2.

Quoted 1 line
Quoted 1 line

+    if (nla_put_u8(msg,

VDPA_ATTR_DEV_NET_CFG_RSS_MAX_KEY_LEN,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

+               config->rss_max_key_size))
+        return -EMSGSIZE;
+
+    rss_field = le16_to_cpu(config->rss_max_key_size); +    if (nla_put_u16(msg,

VDPA_ATTR_DEV_NET_CFG_RSS_MAX_IT_LEN,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

rss_field))

Quoted 4 lines

+        return -EMSGSIZE;
+
+    hash_types = le32_to_cpu(config->supported_hash_types); +    if (nla_put_u32(msg,

VDPA_ATTR_DEV_NET_CFG_RSS_HASH_TYPES,

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Review

Quoted 10 lines

+            config->supported_hash_types))
+        return -EMSGSIZE;
+    return 0;

(quoted diff) +7 -0
+}
+
+static int vdpa_dev_net_config_fill(struct vdpa_device *vdev,
+struct sk_buff *msg) {
+    struct virtio_net_config config = {};
+
+    vdev->config->get_config(vdev, 0, &config, sizeof(config));

Do we need to sync with other possible get_config calls here?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

To readers of get_config() is ok. No need to sync. However, I think set_config() and get_config() should sync otherwise

get_config can get partial value.

Quoted 1 line

Will probably have to add vdpa_device->config_access_lock().

Probably. And the set_config() should be synchronized with the requrest that comes from vDPA bus.

Yes, a rw semaphore is good enough.
Device config fields can be change from the device side anyway, such as

link status anyway.

Quoted 7 lines

Sync using lock shouldn’t be problem.

Quoted 5 lines

This makes me think whether we should go back to two phases method, create and enable.

The vDPA device is only registred after enabling, then there's no need to sync with vDPA bus, and mgmt is not allowed to change config

after enalbing?

Quoted 2 lines

In that case we should be able to disable it as well. Disable should take the

device of the bus.

Quoted 8 lines
Quoted 1 line

I find it weird to have this model to linger around the device without

anchoring on the bus.

Quoted 1 line

For example device is not yet enabled, so it is not anchored on the bus, but

its name is still have to remain unique.

Can we do some synchornization between vdpa device allocation and vdpa device registier to solve the naming issue?

mgmt tool querying the device config space after vdpa device is in use is real.
So I don't see solving it any differently.

Now upper layers of vdpa to not access the device on the placed on the vdpa bus, can be taken care by existing driver code using
echo 0 > /sys/bus/vdpa/drivers_autoprobe

Quoted 10 lines

By default vdpa device placed on the bus wont bind to any driver (net/vhost etc).
1. Decision to bind to which driver is done after config of the vdpa device is done.
2. orchestration sw does create and config before it binds to the right driver
3. which driver to bind to decided based on the use case of that individual vdpa device
For example,
(a) vdpa0 binds to net driver to have Netdev for container
(b) vdpa1 binds to vhost driver to map vdpa device to VM

I think it should work.

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line

Adding Adrian, Maxime and Sean for more comments.

Is this a strong requirement or just a optional operation?

So my understanding is that something needs to be done to make sure:

1) the vpda device is not bound to virtio-vdpaThis is a problem of api not being unified, right? If vdpa device is bound to

virtio-vdpa I would expect some net-specific options (like mac or tso) would be modifiable through net_device_ops if the needed capabilities are held.

Quoted 2 lines

2) config is not changed if it has been set by management
For virtio-vdpa (virtio-net) devices, that would be controlled via CAP_NET_ADMIN.

For vhost-vdpa case, are you thinking of a way of stopping a user from sending VHOST_VDPA_SET_CONFIG messages? or making it fail if management has made some config at the vdpa level?

Quoted 97 lines
Quoted 27 lines
Quoted 3 lines

This might break some existing logic that expects netdev or vhost-vdpa device to exist before the some config (e.g:mac address) is set.

the orcestration software should not require permission to do dirver binding and in the case of openstack will
not have the capablity to bind the vdpa device to a dirvier in the current proposed design.
the ordering we are expecting to support in openstack at least initally is that the adminsitrator
will use either systemd service files or udev rules to allocate the VF and vdpa device staictly at boot.

in the case of openstack we will expect all vdpa devies that will be used by openstack(nova) for assignment
to vms will be prebound by the adminstrators to vhost-vdpa. openstack will simply track the /dev/vhost* paths
corallated to the vdpa devices whose parent VF are allowed by the pci passthough whitelist.

if the adminstrator binds the vdpa device to virtio-vdpa so that virtio-net-pci is used on the host nova and libvirt
will not correct that and the vm boot will fail. but provided you do not list that parent VF in the whitelist nova
will also ignore it. so if you want to mix and match the vdpa device driver that should not break anything provided
you do not list its parent in the pci whitelist.

Quoted 6 lines

but one thing to keep in mind is whlie we are not planning to create VF/VDPA devices dynamiclaly at lesat not for the initall
implentation we do expact to be able to configure attibute of the vdpa device after tehy are create like any other nic.
for example the mac, mtu, link-state should all be configureable at runtime via normal ip route2 commands.

So in the case of vDPA, this task is expected to be done by vdpa tool. (There's no guarantee that vDPA is a VF).

Quoted 7 lines

at the morment we are encounterng issue with the mac adress specificly which qemu is hopefully going to work around since
libvirt and nova cannot currently configure the mac address of a vhost-vdpa device so we are relying on qemu
to take the mac adress form the qemu command line so that it does not end up as all 0 macs in the guest.

Note that a kernel patch is posted by Eli[1] which assign a randomized mac. This should solve the issue in another way.

Quoted 7 lines

as some one that works on orcestration level i would have expect that setting the mac/mtu on either the vf or the netdev
representor to match the deireed mac/mtu in the guest would have been sufficent to alter the vdpa device confirutation.
likely  the netdev representor would make the most sence to alter to match the desired mac so that the mac adress see on the ovs
bridge matches the mac of the vm.

Speaking for genreal vDPA, it's not guaranteed that the vendor will implmenet the device with a representor. So vDPA tool is expected to be the only way to configure the device.

Thanks

[1] https://www.spinics.net/lists/linux-virtualization/msg48451.html

Quoted 26 lines

the current case where the vdpa representor netdev seams to have no bareing on the vdpa device
config makes debugging much more difficalt and is likely to confuse monitoring software. fortunetly openstack is not matching on the mac
address in this spefic case to identify the netdev represntor port but we have other backend that do look at the mac. in the case of ovs
we store the uuid of the neutron port in the ovsdb when adding a port to ovs so we rely on that not the mac but  for legacy mode
sriov which we hope to support with vdpa eventulally after we comple the hardware offloaed ovs support, currenlty relys on the mac in some cases.

i hope that answered your questions?
we are aware that we likely will have to support vdpa device creation at some point if we intend to add support for vdpa devices
created form subfunctions or intels siov howver that was not ready when we started this work so it was declared out of scope and
the curernt static approch was taken as the only path we could enable before code free in 10 days.

regards sean.

Quoted 3 lines

Thanks

https://www.spinics.net/lists/linux-virtualization/msg48451.html

Signature · 6 lines
Adrián Moreno

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#19 lore raw

PATCH 3/9 vdpa: Enable user to set mac and mtu of vdpa device

In reply to Parav Pandit
$ vdpa dev add name bar mgmtdev vdpasim_net
$ vdpa dev config set bar 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 speed 0 duplex 0
$ vdpa dev config show -jp
{
    "config": {
        "bar": {
            "mac": "00:11:22:33:44:55",
            "link ": "up",
            "link_announce ": false,
            "mtu": 9000,
            "speed": 0,
            "duplex": 0
        }
    }
}
---
 drivers/vdpa/vdpa.c       | 89 +++++++++++++++++++++++++++++++++++++++
 include/linux/vdpa.h      | 16 +++++++
 include/uapi/linux/vdpa.h |  1 +
 3 files changed, 106 insertions(+)
drivers/vdpa/vdpa.c +89 -0
index cebbba500638..ae4656dcea16 100644
@@ -778,10 +778,93 @@ vdpa_nl_cmd_dev_config_get_dumpit(struct sk_buff *msg, struct netlink_callback *
 	return msg->len;
 }
 
+static void build_dev_net_config_attrs(struct genl_info *info,
+				       struct vdpa_dev_config_set_attr *attrs)
+{
+	struct nlattr **nl_attrs = info->attrs;
+	const u8 *macaddr;
+
+	if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MACADDR]) {
+		macaddr = nla_data(nl_attrs[VDPA_ATTR_DEV_NET_CFG_MACADDR]);
+		memcpy(attrs->cfg.mac, macaddr, sizeof(attrs->cfg.mac));
+		attrs->mask.mac_valid = true;
+	}
+	if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MTU]) {
+		attrs->cfg.mtu =
+			nla_get_u16(nl_attrs[VDPA_ATTR_DEV_NET_CFG_MTU]);
+		attrs->mask.mtu_valid = true;
+	}
+}
+
+static int
+vdpa_dev_net_config_set(struct vdpa_device *vdev,
+			const struct vdpa_dev_config_set_attr *attrs)
+{
+	struct vdpa_mgmt_dev *mdev = vdev->mdev;
+
+	if (!mdev->ops->dev_config_set)
+		return -EOPNOTSUPP;
+	return mdev->ops->dev_config_set(mdev, vdev, attrs);
+}
+
+static int vdpa_dev_config_set(struct vdpa_device *vdev, struct genl_info *info)
+{
+	struct vdpa_dev_config_set_attr attrs = {};
+	int err = -EOPNOTSUPP;
+	u32 device_id;
+
+	if (!vdev->mdev)
+		return -EOPNOTSUPP;
+
+	device_id = vdev->config->get_device_id(vdev);
+	switch (device_id) {
+	case VIRTIO_ID_NET:
+		build_dev_net_config_attrs(info, &attrs);
+		err = vdpa_dev_net_config_set(vdev, &attrs);
+		break;
+	default:
+		break;
+	}
+	return err;
+}
+
+static int vdpa_nl_cmd_dev_config_set_doit(struct sk_buff *skb, struct genl_info *info)
+{
+	struct vdpa_device *vdev;
+	const char *devname;
+	struct device *dev;
+	int err;
+
+	if (!info->attrs[VDPA_ATTR_DEV_NAME])
+		return -EINVAL;
+	devname = nla_data(info->attrs[VDPA_ATTR_DEV_NAME]);
+
+	mutex_lock(&vdpa_dev_mutex);
+	dev = bus_find_device(&vdpa_bus, NULL, devname, vdpa_name_match);
+	if (!dev) {
+		mutex_unlock(&vdpa_dev_mutex);
+		NL_SET_ERR_MSG_MOD(info->extack, "device not found");
+		return -ENODEV;
+	}
+	vdev = container_of(dev, struct vdpa_device, dev);
+	if (!vdev->mdev) {
+		mutex_unlock(&vdpa_dev_mutex);
+		put_device(dev);
+		return -EINVAL;
+	}
+	err = vdpa_dev_config_set(vdev, info);
+	put_device(dev);
+	mutex_unlock(&vdpa_dev_mutex);
+	return err;
+}
+
 static const struct nla_policy vdpa_nl_policy[VDPA_ATTR_MAX + 1] = {
 	[VDPA_ATTR_MGMTDEV_BUS_NAME] = { .type = NLA_NUL_STRING },
 	[VDPA_ATTR_MGMTDEV_DEV_NAME] = { .type = NLA_STRING },
 	[VDPA_ATTR_DEV_NAME] = { .type = NLA_STRING },
+	[VDPA_ATTR_DEV_NET_CFG_MACADDR] = NLA_POLICY_EXACT_LEN(ETH_ALEN),
+	/* virtio spec 1.1 section 5.1.4.1 for valid MTU range */
+	[VDPA_ATTR_DEV_NET_CFG_MTU] = NLA_POLICY_RANGE(NLA_U16, 68, 65535),
 };
 
 static const struct genl_ops vdpa_nl_ops[] = {
@@ -815,6 +898,12 @@ static const struct genl_ops vdpa_nl_ops[] = {
 		.doit = vdpa_nl_cmd_dev_config_get_doit,
 		.dumpit = vdpa_nl_cmd_dev_config_get_dumpit,
 	},
+	{
+		.cmd = VDPA_CMD_DEV_CONFIG_SET,
+		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+		.doit = vdpa_nl_cmd_dev_config_set_doit,
+		.flags = GENL_ADMIN_PERM,
+	},
 };
 
 static struct genl_family vdpa_nl_family __ro_after_init = {
include/linux/vdpa.h +16 -0
index 4ab5494503a8..c43a9e86c0ee 100644
@@ -6,6 +6,7 @@
 #include <linux/device.h>
 #include <linux/interrupt.h>
 #include <linux/vhost_iotlb.h>
+#include <linux/virtio_net.h>
 
 /**
  * vDPA callback definition.
@@ -343,6 +344,14 @@ static inline void vdpa_get_config(struct vdpa_device *vdev, unsigned offset,
 	ops->get_config(vdev, offset, buf, len);
 }
 
+struct vdpa_dev_config_set_attr {
+	struct virtio_net_config cfg;
+	struct {
+		u8 mac_valid : 1;
+		u8 mtu_valid : 1;
+	} mask;
+};
+
 /**
  * vdpa_mgmtdev_ops - vdpa device ops
  * @dev_add:	Add a vdpa device using alloc and register
@@ -356,10 +365,17 @@ static inline void vdpa_get_config(struct vdpa_device *vdev, unsigned offset,
  *		@dev: vdpa device to remove
  *		Driver need to remove the specified device by calling
  *		_vdpa_unregister_device().
+ * @dev_config_set: Setup one or more fields of the device configuration layout
+ *		    @mdev: management device of the vdpa device
+ *		    @dev: vdpa device whose config fields to setup/modify
+ *		    @attrs: attributes to updated
  */
 struct vdpa_mgmtdev_ops {
 	int (*dev_add)(struct vdpa_mgmt_dev *mdev, const char *name);
 	void (*dev_del)(struct vdpa_mgmt_dev *mdev, struct vdpa_device *dev);
+	int (*dev_config_set)(struct vdpa_mgmt_dev *mdev,
+			      struct vdpa_device *dev,
+			      const struct vdpa_dev_config_set_attr *attrs);
 };
 
 struct vdpa_mgmt_dev {
include/uapi/linux/vdpa.h +1 -0
index 5c31ecc3b956..ec349789b8d1 100644
@@ -18,6 +18,7 @@ enum vdpa_command {
 	VDPA_CMD_DEV_DEL,
 	VDPA_CMD_DEV_GET,		/* can dump */
 	VDPA_CMD_DEV_CONFIG_GET,	/* can dump */
+	VDPA_CMD_DEV_CONFIG_SET,
 };
 
 enum vdpa_attr {
Signature · 6 lines
2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#20 lore raw

PATCH 4/9 vdpa_sim_net: Enable user to set mac address and mtu

In reply to Parav Pandit

Enable user to set the mac address and mtu so that each vdpa device can have its own user specified mac address and mtu. This is done by implementing the management device's configuration layout fields setting callback routine.

Now that user is enabled to set the mac address, remove the module parameter for same.

And example of setting mac addr and mtu:

$ vdpa mgmtdev show
$ vdpa dev add name bar mgmtdev vdpasim_net
$ vdpa dev config set bar mac 00:11:22:33:44:55 mtu 9000

View the config after setting:

$ vdpa dev config show
bar: mac 00:11:22:33:44:55 link up link_announce false mtu 9000 speed 0 duplex 0
---
 drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 39 ++++++++++++++++------------
 1 file changed, 22 insertions(+), 17 deletions(-)
drivers/vdpa/vdpa_sim/vdpa_sim_net.c +22 -17
index 240a5f1306b5..6e941b0e7935 100644
@@ -29,12 +29,6 @@
 
 #define VDPASIM_NET_VQ_NUM	2
 
-static char *macaddr;
-module_param(macaddr, charp, 0);
-MODULE_PARM_DESC(macaddr, "Ethernet MAC address");
-
-static u8 macaddr_buf[ETH_ALEN];
-
 static void vdpasim_net_work(struct work_struct *work)
 {
 	struct vdpasim *vdpasim = container_of(work, struct vdpasim, work);
@@ -113,9 +107,7 @@ static void vdpasim_net_get_config(struct vdpasim *vdpasim, void *config)
 	struct virtio_net_config *net_config =
 		(struct virtio_net_config *)config;
 
-	net_config->mtu = cpu_to_vdpasim16(vdpasim, 1500);
 	net_config->status = cpu_to_vdpasim16(vdpasim, VIRTIO_NET_S_LINK_UP);
-	memcpy(net_config->mac, macaddr_buf, ETH_ALEN);
 }
 
 static void vdpasim_net_mgmtdev_release(struct device *dev)
@@ -134,6 +126,7 @@ static struct device vdpasim_net_mgmtdev_dummy = {
 
 static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name)
 {
+	struct virtio_net_config *cfg;
 	struct vdpasim_dev_attr dev_attr = {};
 	struct vdpasim *simdev;
 	int ret;
@@ -152,6 +145,10 @@ static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name)
 	if (IS_ERR(simdev))
 		return PTR_ERR(simdev);
 
+	cfg = simdev->config;
+	eth_random_addr(cfg->mac);
+	cfg->mtu = cpu_to_vdpasim16(simdev, 1500);
+
 	ret = _vdpa_register_device(&simdev->vdpa);
 	if (ret)
 		goto reg_err;
@@ -171,9 +168,25 @@ static void vdpasim_net_dev_del(struct vdpa_mgmt_dev *mdev,
 	_vdpa_unregister_device(&simdev->vdpa);
 }
 
+static int
+vdpasim_net_dev_config_set(struct vdpa_mgmt_dev *mdev,
+			   struct vdpa_device *dev,
+			   const struct vdpa_dev_config_set_attr *attrs)
+{
+	struct vdpasim *simdev = container_of(dev, struct vdpasim, vdpa);
+	struct virtio_net_config *dev_cfg = simdev->config;
+
+	if (attrs->mask.mac_valid)
+		memcpy(dev_cfg->mac, attrs->cfg.mac, sizeof(dev_cfg->mac));
+	if (attrs->mask.mtu_valid)
+		dev_cfg->mtu = cpu_to_vdpasim16(simdev, attrs->cfg.mtu);
+	return 0;
+}
+
 static const struct vdpa_mgmtdev_ops vdpasim_net_mgmtdev_ops = {
 	.dev_add = vdpasim_net_dev_add,
-	.dev_del = vdpasim_net_dev_del
+	.dev_del = vdpasim_net_dev_del,
+	.dev_config_set = vdpasim_net_dev_config_set,
 };
 
 static struct virtio_device_id id_table[] = {
@@ -198,14 +211,6 @@ static int __init vdpasim_net_init(void)
 {
 	int ret;
 
-	if (macaddr) {
-		mac_pton(macaddr, macaddr_buf);
-		if (!is_valid_ether_addr(macaddr_buf))
-			return -EADDRNOTAVAIL;
-	} else {
-		eth_random_addr(macaddr_buf);
-	}
-
 	ret = device_register(&vdpasim_net_mgmtdev);
 	if (ret)
 		return ret;
Signature · 6 lines
2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#21 lore raw

Re: [PATCH linux-next 4/9] vdpa_sim_net: Enable user to set mac address and mtu

Quoted 7 lines · Parav Pandit

Enable user to set the mac address and mtu so that each vdpa device can have its own user specified mac address and mtu. This is done by implementing the management device's configuration layout fields setting callback routine.

Now that user is enabled to set the mac address, remove the module parameter for same.

Will likely break some testing setups ...
Not too hard to keep it around, is it?

Quoted 53 lines

And example of setting mac addr and mtu:

$ vdpa mgmtdev show
$ vdpa dev add name bar mgmtdev vdpasim_net
$ vdpa dev config set bar mac 00:11:22:33:44:55 mtu 9000

View the config after setting:

$ vdpa dev config show
bar: mac 00:11:22:33:44:55 link up link_announce false mtu 9000 speed 0 duplex 0
---
 drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 39 ++++++++++++++++------------
 1 file changed, 22 insertions(+), 17 deletions(-)
drivers/vdpa/vdpa_sim/vdpa_sim_net.c +1 -8
index 240a5f1306b5..6e941b0e7935 100644
@@ -29,12 +29,6 @@
 
 #define VDPASIM_NET_VQ_NUM	2
 
-static char *macaddr;
-module_param(macaddr, charp, 0);
-MODULE_PARM_DESC(macaddr, "Ethernet MAC address");
-
-static u8 macaddr_buf[ETH_ALEN];
-
 static void vdpasim_net_work(struct work_struct *work)
 {
 	struct vdpasim *vdpasim = container_of(work, struct vdpasim, work);
@@ -113,9 +107,7 @@ static void vdpasim_net_get_config(struct vdpasim *vdpasim, void *config)
 	struct virtio_net_config *net_config =
 		(struct virtio_net_config *)config;
 
-	net_config->mtu = cpu_to_vdpasim16(vdpasim, 1500);
 	net_config->status = cpu_to_vdpasim16(vdpasim, VIRTIO_NET_S_LINK_UP);
-	memcpy(net_config->mac, macaddr_buf, ETH_ALEN);
 }
 
 static void vdpasim_net_mgmtdev_release(struct device *dev)
@@ -134,6 +126,7 @@ static struct device vdpasim_net_mgmtdev_dummy = {
 
 static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name)
 {
+	struct virtio_net_config *cfg;
 	struct vdpasim_dev_attr dev_attr = {};
 	struct vdpasim *simdev;
 	int ret;

drivers/vdpa/vdpa_sim/vdpa_sim_net.c static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name) · line 154

Quoted 10 lines
drivers/vdpa/vdpa_sim/vdpa_sim_net.c +4 -0
@@ -152,6 +145,10 @@ static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name)
 	if (IS_ERR(simdev))
 		return PTR_ERR(simdev);
 
+	cfg = simdev->config;
+	eth_random_addr(cfg->mac);
+	cfg->mtu = cpu_to_vdpasim16(simdev, 1500);
+
 	ret = _vdpa_register_device(&simdev->vdpa);
 	if (ret)
 		goto reg_err;

Hmm moving it here is problematic:
this part happens before set_features so I suspect endian-ness will be wrong for BE hosts ...

Quoted 44 lines
drivers/vdpa/vdpa_sim/vdpa_sim_net.c +17 -9
@@ -171,9 +168,25 @@ static void vdpasim_net_dev_del(struct vdpa_mgmt_dev *mdev,
 	_vdpa_unregister_device(&simdev->vdpa);
 }
 
+static int
+vdpasim_net_dev_config_set(struct vdpa_mgmt_dev *mdev,
+			   struct vdpa_device *dev,
+			   const struct vdpa_dev_config_set_attr *attrs)
+{
+	struct vdpasim *simdev = container_of(dev, struct vdpasim, vdpa);
+	struct virtio_net_config *dev_cfg = simdev->config;
+
+	if (attrs->mask.mac_valid)
+		memcpy(dev_cfg->mac, attrs->cfg.mac, sizeof(dev_cfg->mac));
+	if (attrs->mask.mtu_valid)
+		dev_cfg->mtu = cpu_to_vdpasim16(simdev, attrs->cfg.mtu);
+	return 0;
+}
+
 static const struct vdpa_mgmtdev_ops vdpasim_net_mgmtdev_ops = {
 	.dev_add = vdpasim_net_dev_add,
-	.dev_del = vdpasim_net_dev_del
+	.dev_del = vdpasim_net_dev_del,
+	.dev_config_set = vdpasim_net_dev_config_set,
 };
 
 static struct virtio_device_id id_table[] = {
@@ -198,14 +211,6 @@ static int __init vdpasim_net_init(void)
 {
 	int ret;
 
-	if (macaddr) {
-		mac_pton(macaddr, macaddr_buf);
-		if (!is_valid_ether_addr(macaddr_buf))
-			return -EADDRNOTAVAIL;
-	} else {
-		eth_random_addr(macaddr_buf);
-	}
-
 	ret = device_register(&vdpasim_net_mgmtdev);
 	if (ret)
 		return ret;
Signature · 1 line
2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#22 lore raw

RE: [PATCH linux-next 4/9] vdpa_sim_net: Enable user to set mac address and mtu

Quoted 11 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, February 24, 2021 12:27 PM

Quoted 5 lines · Parav Pandit

Enable user to set the mac address and mtu so that each vdpa device can have its own user specified mac address and mtu. This is done by implementing the management device's configuration layout fields setting callback routine.

Quoted 6 lines
Quoted 2 lines

Now that user is enabled to set the mac address, remove the module parameter for same.

Will likely break some testing setups ...
Not too hard to keep it around, is it?

Mostly not. In previous series, we moved away from default device to user created device without an additional module param. So this shouldn't break it.
It gets confusing which one to use and module param applies same mac to all the vdpa devices.
So lets shift to user provided mac.

Quoted 61 lines

drivers/vdpa/vdpa_sim/vdpa_sim_net.c static void vdpasim_net_get_config(struct vdpasim

Quoted 37 lines

And example of setting mac addr and mtu:

$ vdpa mgmtdev show
$ vdpa dev add name bar mgmtdev vdpasim_net $ vdpa dev config set bar
mac 00:11:22:33:44:55 mtu 9000

View the config after setting:

$ vdpa dev config show
bar: mac 00:11:22:33:44:55 link up link_announce false mtu 9000 speed
0 duplex 0
---
 drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 39
++++++++++++++++------------
 1 file changed, 22 insertions(+), 17 deletions(-)
drivers/vdpa/vdpa_sim/vdpa_sim_net.c +0 -6
index 240a5f1306b5..6e941b0e7935 100644
@@ -29,12 +29,6 @@
 
 #define VDPASIM_NET_VQ_NUM	2
 
-static char *macaddr;
-module_param(macaddr, charp, 0);
-MODULE_PARM_DESC(macaddr, "Ethernet MAC address");
-
-static u8 macaddr_buf[ETH_ALEN];
-
 static void vdpasim_net_work(struct work_struct *work)  {
 	struct vdpasim *vdpasim = container_of(work, struct vdpasim, work);
@@ -113,9 +107,7 @@ static void vdpasim_net_get_config(struct vdpasim

*vdpasim, void *config)

drivers/vdpa/vdpa_sim/vdpa_sim_net.c static void vdpasim_net_get_config(struct vdpasim *vdpasim, void *config)

Quoted 5 lines
drivers/vdpa/vdpa_sim/vdpa_sim_net.c +0 -1
 	struct virtio_net_config *net_config =
 		(struct virtio_net_config *)config;
 
-	net_config->mtu = cpu_to_vdpasim16(vdpasim, 1500);
 	net_config->status = cpu_to_vdpasim16(vdpasim,

VIRTIO_NET_S_LINK_UP);

drivers/vdpa/vdpa_sim/vdpa_sim_net.c static int vdpasim_net_dev_add(struct

Quoted 13 lines
drivers/vdpa/vdpa_sim/vdpa_sim_net.c +1 -1
-	memcpy(net_config->mac, macaddr_buf, ETH_ALEN);
 }
 
 static void vdpasim_net_mgmtdev_release(struct device *dev) @@ -134,6
+126,7 @@ static struct device vdpasim_net_mgmtdev_dummy = {
 
 static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char

*name) {

drivers/vdpa/vdpa_sim/vdpa_sim_net.c +1 -0
+	struct virtio_net_config *cfg;
 	struct vdpasim_dev_attr dev_attr = {};
 	struct vdpasim *simdev;
 	int ret;
@@ -152,6 +145,10 @@ static int vdpasim_net_dev_add(struct

vdpa_mgmt_dev *mdev, const char *name)

Quoted 3 lines
drivers/vdpa/vdpa_sim/vdpa_sim_net.c +0 -0
 	if (IS_ERR(simdev))
 		return PTR_ERR(simdev);
 
Quoted 12 lines

drivers/vdpa/vdpa_sim/vdpa_sim_net.c static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name) · line 154

Quoted 7 lines
drivers/vdpa/vdpa_sim/vdpa_sim_net.c +4 -0
+	cfg = simdev->config;
+	eth_random_addr(cfg->mac);
+	cfg->mtu = cpu_to_vdpasim16(simdev, 1500);
+
 	ret = _vdpa_register_device(&simdev->vdpa);
 	if (ret)
 		goto reg_err;

Hmm moving it here is problematic:
this part happens before set_features so I suspect endian-ness will be wrong for BE hosts ...

Hmm. I see it. Looking for solution to it now.
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#23 lore raw

PATCH 5/9 vdpa_sim_net: Remove redundant get_config callback

In reply to Parav Pandit

Now that mac address and mtu are set in the vdpa_sim allocated config space and read from the vdpa_sim maintained memory area, remove get_config callback implementation.

Link status is setup only once, set up once after config space is allocated by the vdpa_sim.

---
 drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/vdpa/vdpa_sim/vdpa_sim_net.c +1 -9
index 6e941b0e7935..61f1d37d8d60 100644
@@ -102,14 +102,6 @@ static void vdpasim_net_work(struct work_struct *work)
 	spin_unlock(&vdpasim->lock);
 }
 
-static void vdpasim_net_get_config(struct vdpasim *vdpasim, void *config)
-{
-	struct virtio_net_config *net_config =
-		(struct virtio_net_config *)config;
-
-	net_config->status = cpu_to_vdpasim16(vdpasim, VIRTIO_NET_S_LINK_UP);
-}
-
 static void vdpasim_net_mgmtdev_release(struct device *dev)
 {
 }
@@ -137,7 +129,6 @@ static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name)
 	dev_attr.supported_features = VDPASIM_NET_FEATURES;
 	dev_attr.nvqs = VDPASIM_NET_VQ_NUM;
 	dev_attr.config_size = sizeof(struct virtio_net_config);
-	dev_attr.get_config = vdpasim_net_get_config;
 	dev_attr.work_fn = vdpasim_net_work;
 	dev_attr.buffer_size = PAGE_SIZE;
 
@@ -148,6 +139,7 @@ static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name)
 	cfg = simdev->config;
 	eth_random_addr(cfg->mac);
 	cfg->mtu = cpu_to_vdpasim16(simdev, 1500);
+	cfg->status = cpu_to_vdpasim16(simdev, VIRTIO_NET_S_LINK_UP);
 
 	ret = _vdpa_register_device(&simdev->vdpa);
 	if (ret)
Signature · 6 lines
2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#24 lore raw

PATCH 6/9 vdpa/mlx5: Enable user to add/delete vdpa device

In reply to Parav Pandit

From: Eli Cohen <[email protected]>

Allow to control vdpa device creation and destruction using the vdpa management tool.

Examples:
1. List the management devices

$ vdpa mgmtdev show
pci/0000:3b:00.1:
  supported_classes net

2. Create vdpa instance

$ vdpa dev add mgmtdev pci/0000:3b:00.1 name vdpa0

3. Show vdpa devices

$ vdpa dev show
vdpa0: type network mgmtdev pci/0000:3b:00.1 vendor_id 5555 max_vqs 16 \
max_vq_size 256
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 79 +++++++++++++++++++++++++++----
 1 file changed, 70 insertions(+), 9 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +70 -9
index 10e9b09932eb..b67bba581dfd 100644
@@ -1966,23 +1966,32 @@ static void init_mvqs(struct mlx5_vdpa_net *ndev)
 	}
 }
 
-static int mlx5v_probe(struct auxiliary_device *adev,
-		       const struct auxiliary_device_id *id)
+struct mlx5_vdpa_mgmtdev {
+	struct vdpa_mgmt_dev mgtdev;
+	struct mlx5_adev *madev;
+	struct mlx5_vdpa_net *ndev;
+};
+
+static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name)
 {
-	struct mlx5_adev *madev = container_of(adev, struct mlx5_adev, adev);
-	struct mlx5_core_dev *mdev = madev->mdev;
+	struct mlx5_vdpa_mgmtdev *mgtdev = container_of(v_mdev, struct mlx5_vdpa_mgmtdev, mgtdev);
 	struct virtio_net_config *config;
 	struct mlx5_vdpa_dev *mvdev;
 	struct mlx5_vdpa_net *ndev;
+	struct mlx5_core_dev *mdev;
 	u32 max_vqs;
 	int err;
 
+	if (mgtdev->ndev)
+		return -ENOSPC;
+
+	mdev = mgtdev->madev->mdev;
 	/* we save one virtqueue for control virtqueue should we require it */
 	max_vqs = MLX5_CAP_DEV_VDPA_EMULATION(mdev, max_num_virtio_queues);
 	max_vqs = min_t(u32, max_vqs, MLX5_MAX_SUPPORTED_VQS);
 
 	ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, mdev->device, &mlx5_vdpa_ops,
-				 2 * mlx5_vdpa_max_qps(max_vqs), NULL);
+				 2 * mlx5_vdpa_max_qps(max_vqs), name);
 	if (IS_ERR(ndev))
 		return PTR_ERR(ndev);
 
@@ -2009,11 +2018,12 @@ static int mlx5v_probe(struct auxiliary_device *adev,
 	if (err)
 		goto err_res;
 
-	err = vdpa_register_device(&mvdev->vdev);
+	mvdev->vdev.mdev = &mgtdev->mgtdev;
+	err = _vdpa_register_device(&mvdev->vdev);
 	if (err)
 		goto err_reg;
 
-	dev_set_drvdata(&adev->dev, ndev);
+	mgtdev->ndev = ndev;
 	return 0;
 
 err_reg:
@@ -2026,11 +2036,62 @@ static int mlx5v_probe(struct auxiliary_device *adev,
 	return err;
 }
 
+static void mlx5_vdpa_dev_del(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *dev)
+{
+	struct mlx5_vdpa_mgmtdev *mgtdev = container_of(v_mdev, struct mlx5_vdpa_mgmtdev, mgtdev);
+
+	_vdpa_unregister_device(dev);
+	mgtdev->ndev = NULL;
+}
+
+static const struct vdpa_mgmtdev_ops mdev_ops = {
+	.dev_add = mlx5_vdpa_dev_add,
+	.dev_del = mlx5_vdpa_dev_del,
+};
+
+static struct virtio_device_id id_table[] = {
+	{ VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID },
+	{ 0 },
+};
+
+static int mlx5v_probe(struct auxiliary_device *adev,
+		       const struct auxiliary_device_id *id)
+
+{
+	struct mlx5_adev *madev = container_of(adev, struct mlx5_adev, adev);
+	struct mlx5_core_dev *mdev = madev->mdev;
+	struct mlx5_vdpa_mgmtdev *mgtdev;
+	int err;
+
+	mgtdev = kzalloc(sizeof(*mgtdev), GFP_KERNEL);
+	if (!mgtdev)
+		return -ENOMEM;
+
+	mgtdev->mgtdev.ops = &mdev_ops;
+	mgtdev->mgtdev.device = mdev->device;
+	mgtdev->mgtdev.id_table = id_table;
+	mgtdev->madev = madev;
+
+	err = vdpa_mgmtdev_register(&mgtdev->mgtdev);
+	if (err)
+		goto reg_err;
+
+	dev_set_drvdata(&adev->dev, mgtdev);
+
+	return 0;
+
+reg_err:
+	kfree(mdev);
+	return err;
+}
+
 static void mlx5v_remove(struct auxiliary_device *adev)
 {
-	struct mlx5_vdpa_dev *mvdev = dev_get_drvdata(&adev->dev);
+	struct mlx5_vdpa_mgmtdev *mgtdev;
 
-	vdpa_unregister_device(&mvdev->vdev);
+	mgtdev = dev_get_drvdata(&adev->dev);
+	vdpa_mgmtdev_unregister(&mgtdev->mgtdev);
+	kfree(mgtdev);
 }
 
 static const struct auxiliary_device_id mlx5v_id_table[] = {
Signature · 6 lines
2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#25 lore raw

PATCH 7/9 vdpa/mlx5: Provide device generated random MAC address

In reply to Parav Pandit

From: Eli Cohen <[email protected]>

Use a randomly generated MAC address to be applied in case it is not configured by management tool.

The value queried through mlx5_query_nic_vport_mac_address() is not relelavnt to vdpa since it is the mac that should be used by the regular NIC driver.

---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -4
index b67bba581dfd..ece2183e7b20 100644
@@ -2005,10 +2005,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name)
 	if (err)
 		goto err_mtu;
 
-	err = mlx5_query_nic_vport_mac_address(mdev, 0, 0, config->mac);
-	if (err)
-		goto err_mtu;
-
+	eth_random_addr(config->mac);
 	mvdev->vdev.dma_dev = mdev->device;
 	err = mlx5_vdpa_alloc_resources(&ndev->mvdev);
 	if (err)
Signature · 6 lines
2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Acked-by on v1 7/9
#26 lore raw

Re: [PATCH linux-next 7/9] vdpa/mlx5: Provide device generated random MAC address

Quoted 11 lines · Parav Pandit

From: Eli Cohen <[email protected]>

Use a randomly generated MAC address to be applied in case it is not configured by management tool.

The value queried through mlx5_query_nic_vport_mac_address() is not relelavnt to vdpa since it is the mac that should be used by the regular NIC driver.

Quoted 10 lines
---
  drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
index b67bba581dfd..ece2183e7b20 100644
@@ -2005,10 +2005,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name)
  	if (err)

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name) · line 2011

Quoted 10 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -4
  		goto err_mtu;
 
-	err = mlx5_query_nic_vport_mac_address(mdev, 0, 0, config->mac);
-	if (err)
-		goto err_mtu;
-
+	eth_random_addr(config->mac);
  	mvdev->vdev.dma_dev = mdev->device;
  	err = mlx5_vdpa_alloc_resources(&ndev->mvdev);
  	if (err)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

A message that is not in the archive (sent off-list or not yet received): [email protected]

#28 lore raw

Re: [PATCH linux-next 7/9] vdpa/mlx5: Provide device generated random MAC address

Quoted 23 lines · Eli Cohen
Quoted 22 lines · Jason Wang
Quoted 11 lines · Parav Pandit

From: Eli Cohen <[email protected]>

Use a randomly generated MAC address to be applied in case it is not configured by management tool.

The value queried through mlx5_query_nic_vport_mac_address() is not relelavnt to vdpa since it is the mac that should be used by the regular NIC driver.

Quoted 4 lines
---
  drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
index b67bba581dfd..ece2183e7b20 100644
Quoted 8 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name) · line 2007

Quoted 8 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -4
@@ -2005,10 +2005,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name)
  	if (err)
  		goto err_mtu;
-	err = mlx5_query_nic_vport_mac_address(mdev, 0, 0, config->mac);
-	if (err)
-		goto err_mtu;
-
+	eth_random_addr(config->mac);

I think this patch is missing setting VIRTIO_NET_F_MTU. I will post v2 with the other fixes in this series.

I don't really understand why this is a good idea.

If userspace wants a random mac it can set it, with this patch it is impossible to know whether the mac is
a hardware one (which will be persistent e.g. across reboots) or a random one.

E.g. there is a patch configuring a userspace supplied mac if the hardware mac is zero.

This patch will break it.

Quoted 4 lines
Quoted 4 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name) · line 2011

Quoted 3 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
  	mvdev->vdev.dma_dev = mdev->device;
  	err = mlx5_vdpa_alloc_resources(&ndev->mvdev);
  	if (err)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

A message that is not in the archive (sent off-list or not yet received): [email protected]

#30 lore raw

Re: [PATCH linux-next 7/9] vdpa/mlx5: Provide device generated random MAC address

Quoted 49 lines · Eli Cohen
Quoted 40 lines · Michael S. Tsirkin
Quoted 23 lines · Eli Cohen
Quoted 22 lines · Jason Wang
Quoted 11 lines · Parav Pandit

From: Eli Cohen <[email protected]>

Use a randomly generated MAC address to be applied in case it is not configured by management tool.

The value queried through mlx5_query_nic_vport_mac_address() is not relelavnt to vdpa since it is the mac that should be used by the regular NIC driver.

Quoted 4 lines
---
  drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
index b67bba581dfd..ece2183e7b20 100644
Quoted 8 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name) · line 2007

Quoted 8 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -4
@@ -2005,10 +2005,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name)
  	if (err)
  		goto err_mtu;
-	err = mlx5_query_nic_vport_mac_address(mdev, 0, 0, config->mac);
-	if (err)
-		goto err_mtu;
-
+	eth_random_addr(config->mac);

I think this patch is missing setting VIRTIO_NET_F_MTU. I will post v2 with the other fixes in this series.

Quoted 7 lines

I don't really understand why this is a good idea.

If userspace wants a random mac it can set it, with this patch it is impossible to know whether the mac is
a hardware one (which will be persistent e.g. across reboots) or a random one.

Quoted 6 lines

You can still get a persistent MAC set by the vdpa tool. e.g

vdpa dev config set vdpa0 mac 00:11:22:33:44:55

If you don't use vdpa tool, the device assigns a random MAC. This MAC is used to filter imcoming unicast traffic (done in a subsequent patch).

Well previously device learned the MAC from outgoing traffic and used that for the filter.
Is changing that to a random value really all that useful as a default? Why not do the randomization in userspace?

Quoted 10 lines
Quoted 10 lines

E.g. there is a patch configuring a userspace supplied mac if the hardware mac is zero.

This patch will break it.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
  	mvdev->vdev.dma_dev = mdev->device;
  	err = mlx5_vdpa_alloc_resources(&ndev->mvdev);
  	if (err)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#31 lore raw

Re: [PATCH linux-next 7/9] vdpa/mlx5: Provide device generated random MAC address

Quoted 47 lines · Michael S. Tsirkin
Quoted 46 lines · Eli Cohen
Quoted 36 lines · Michael S. Tsirkin
Quoted 21 lines · Eli Cohen
Quoted 20 lines · Jason Wang
Quoted 11 lines · Parav Pandit

From: Eli Cohen <[email protected]>

Use a randomly generated MAC address to be applied in case it is not configured by management tool.

The value queried through mlx5_query_nic_vport_mac_address() is not relelavnt to vdpa since it is the mac that should be used by the regular NIC driver.

Quoted 4 lines
---
   drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +----
   1 file changed, 1 insertion(+), 4 deletions(-)
Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
index b67bba581dfd..ece2183e7b20 100644
Quoted 8 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name) · line 2007

Quoted 8 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -4
@@ -2005,10 +2005,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name)
   	if (err)
   		goto err_mtu;
-	err = mlx5_query_nic_vport_mac_address(mdev, 0, 0, config->mac);
-	if (err)
-		goto err_mtu;
-
+	eth_random_addr(config->mac);

I think this patch is missing setting VIRTIO_NET_F_MTU. I will post v2 with the other fixes in this series.

Quoted 7 lines

I don't really understand why this is a good idea.

If userspace wants a random mac it can set it, with this patch it is impossible to know whether the mac is
a hardware one (which will be persistent e.g. across reboots) or a random one.

You can still get a persistent MAC set by the vdpa tool. e.g

Quoted 8 lines
Quoted 4 lines

vdpa dev config set vdpa0 mac 00:11:22:33:44:55

If you don't use vdpa tool, the device assigns a random MAC. This MAC is used to filter imcoming unicast traffic (done in a subsequent patch).

Well previously device learned the MAC from outgoing traffic and used that for the filter.
Is changing that to a random value really all that useful as a default? Why not do the randomization in userspace?

I think the point is that, if userspace doens't specify a mac, it can still work.

Thanks

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

E.g. there is a patch configuring a userspace supplied mac if the hardware mac is zero.

This patch will break it.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
   	mvdev->vdev.dma_dev = mdev->device;
   	err = mlx5_vdpa_alloc_resources(&ndev->mvdev);
   	if (err)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

A message that is not in the archive (sent off-list or not yet received): [email protected]

#33 lore raw

RE: [PATCH linux-next 7/9] vdpa/mlx5: Provide device generated random MAC address

Hi Eli,

Quoted 75 lines

From: Eli Cohen <[email protected]>
Sent: Tuesday, March 2, 2021 11:09 AM

Quoted 26 lines · Michael S. Tsirkin
Quoted 25 lines · Eli Cohen
Quoted 24 lines · Michael S. Tsirkin
Quoted 23 lines · Eli Cohen
Quoted 22 lines · Jason Wang
Quoted 11 lines · Parav Pandit

From: Eli Cohen <[email protected]>

Use a randomly generated MAC address to be applied in case it is not configured by management tool.

The value queried through mlx5_query_nic_vport_mac_address() is not relelavnt to vdpa since it is the mac that should be used by the regular NIC driver.

Quoted 4 lines
---
  drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_dev_add(struct

Quoted 6 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
index b67bba581dfd..ece2183e7b20 100644
@@ -2005,10 +2005,7 @@ static int mlx5_vdpa_dev_add(struct

vdpa_mgmt_dev *v_mdev, const char *name)

Quoted 25 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_dev_add(struct · line 2007

Quoted 3 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -1
  	if (err)
  		goto err_mtu;
-	err = mlx5_query_nic_vport_mac_address(mdev, 0, 0, config-

mac);

Quoted 21 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_dev_add(struct · line 2007

Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -3
-	if (err)
-		goto err_mtu;
-
+	eth_random_addr(config->mac);

I think this patch is missing setting VIRTIO_NET_F_MTU. I will post v2 with the other fixes in this series.

Quoted 6 lines

I don't really understand why this is a good idea.

If userspace wants a random mac it can set it, with this patch it is impossible to know whether the mac is a hardware one (which will be persistent e.g. across reboots) or a random one.

You can still get a persistent MAC set by the vdpa tool. e.g

vdpa dev config set vdpa0 mac 00:11:22:33:44:55

If you don't use vdpa tool, the device assigns a random MAC. This MAC is used to filter imcoming unicast traffic (done in a subsequent

patch).

Quoted 3 lines

Well previously device learned the MAC from outgoing traffic and used that for the filter.

No, was is added only in the last series that Parav send. Before that the device did not filter and forwarded any packet that was forwarded to it buy the eswitch.

Quoted 3 lines

Is changing that to a random value really all that useful as a default? Why not do the randomization in userspace?

Quoted 6 lines

I think we want management entity to set the MAC, that's the VDPA tool. So as things are right now (with the last series applied), the vdpa tool is the tool to assign MAC addresses and if it doesn't, a device randomly generated MAC applies. Currently MAC addresses set by qemu command line are ignored (set_config is not implementd). We can allow this but this will override vdpa tool configuration.

I believe its incorrect to always do random generated mac as of this patch.
This is because, doing so ignores any admin config done by the sysadmin on the switch (ovs side) using [1].

So if user choose to configure using eswitch config, mlx5_vnet to honor that.
And if user prefers to override is using vdpa tool or set_config from QEMU side, so be it.
Hence, instead of reporting all zeros, mlx5 should query own vport context and publish that mac in the config layout and rx steering side.

If user choose to override it, config layout and rx rules will have to updated on such config.

[1] devlink port function set pci/0000:03:00.0/<port_id_of_sf/vf>/ hw_addr 00:11:22:33:44:55
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

A message that is not in the archive (sent off-list or not yet received): [email protected]

#35 lore raw

Re: [PATCH linux-next 7/9] vdpa/mlx5: Provide device generated random MAC address

Quoted 85 lines · Eli Cohen
Quoted 84 lines · Parav Pandit

Hi Eli,

Quoted 81 lines

From: Eli Cohen <[email protected]>
Sent: Tuesday, March 2, 2021 11:09 AM

Quoted 26 lines · Michael S. Tsirkin
Quoted 25 lines · Eli Cohen
Quoted 24 lines · Michael S. Tsirkin
Quoted 23 lines · Eli Cohen
Quoted 22 lines · Jason Wang
Quoted 11 lines · Parav Pandit

From: Eli Cohen <[email protected]>

Use a randomly generated MAC address to be applied in case it is not configured by management tool.

The value queried through mlx5_query_nic_vport_mac_address() is not relelavnt to vdpa since it is the mac that should be used by the regular NIC driver.

Quoted 4 lines
---
  drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_dev_add(struct

Quoted 6 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
index b67bba581dfd..ece2183e7b20 100644
@@ -2005,10 +2005,7 @@ static int mlx5_vdpa_dev_add(struct

vdpa_mgmt_dev *v_mdev, const char *name)

Quoted 25 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_dev_add(struct · line 2007

Quoted 3 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -1
  	if (err)
  		goto err_mtu;
-	err = mlx5_query_nic_vport_mac_address(mdev, 0, 0, config-

mac);

Quoted 21 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_dev_add(struct · line 2007

Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -3
-	if (err)
-		goto err_mtu;
-
+	eth_random_addr(config->mac);

I think this patch is missing setting VIRTIO_NET_F_MTU. I will post v2 with the other fixes in this series.

Quoted 6 lines

I don't really understand why this is a good idea.

If userspace wants a random mac it can set it, with this patch it is impossible to know whether the mac is a hardware one (which will be persistent e.g. across reboots) or a random one.

You can still get a persistent MAC set by the vdpa tool. e.g

vdpa dev config set vdpa0 mac 00:11:22:33:44:55

If you don't use vdpa tool, the device assigns a random MAC. This MAC is used to filter imcoming unicast traffic (done in a subsequent

patch).

Quoted 3 lines

Well previously device learned the MAC from outgoing traffic and used that for the filter.

No, was is added only in the last series that Parav send. Before that the device did not filter and forwarded any packet that was forwarded to it buy the eswitch.

Quoted 3 lines

Is changing that to a random value really all that useful as a default? Why not do the randomization in userspace?

I think we want management entity to set the MAC, that's the VDPA tool. So as things are right now (with the last series applied), the vdpa tool is the tool to assign MAC addresses and if it doesn't, a device randomly generated MAC applies. Currently MAC addresses set by qemu command line are ignored (set_config is not implementd). We can allow this but this will override vdpa tool configuration.

Quoted 8 lines
Quoted 3 lines

I believe its incorrect to always do random generated mac as of this patch.
This is because, doing so ignores any admin config done by the sysadmin on the switch (ovs side) using [1].

Well, when this patch was sent, we still had thoughts to let mlx5e NIC and the VDPA to co-exist on the same function (VF or SF). Now that we're off this idea you can become tempted to use the MAC address configured for the NIC but I don't think it's a good idea. We already have a dedicated tool to configure MAC for VDPA so let's use it.

Right. And users can decide to reuse the hardware MAC if they want to.

Quoted 6 lines
Quoted 2 lines

So if user choose to configure using eswitch config, mlx5_vnet to honor that. And if user prefers to override is using vdpa tool or set_config from QEMU side, so be it.

I agree that we should let the user to configure the MAC through qemu argument when booting the VM. So I'll add this for the next spin of this series.

OK so
- if MAC is configured it is used
- if not configured 0 is reported to userspace

fair summary?

Quoted 5 lines
Quoted 5 lines

Hence, instead of reporting all zeros, mlx5 should query own vport context and publish that mac in the config layout and rx steering side.

If user choose to override it, config layout and rx rules will have to updated on such config.

[1] devlink port function set pci/0000:03:00.0/<port_id_of_sf/vf>/ hw_addr 00:11:22:33:44:55

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#36 lore raw

RE: [PATCH linux-next 7/9] vdpa/mlx5: Provide device generated random MAC address

Quoted 102 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, March 3, 2021 2:59 PM

Quoted 42 lines · Eli Cohen
Quoted 41 lines · Parav Pandit

Hi Eli,

Quoted 39 lines

From: Eli Cohen <[email protected]>
Sent: Tuesday, March 2, 2021 11:09 AM

Quoted 27 lines · Michael S. Tsirkin
Quoted 26 lines · Eli Cohen
Quoted 25 lines · Michael S. Tsirkin
Quoted 24 lines · Eli Cohen
Quoted 23 lines · Jason Wang
Quoted 5 lines · Parav Pandit

From: Eli Cohen <[email protected]>

Use a randomly generated MAC address to be applied in case it is not configured by management tool.

Quoted 7 lines

The value queried through mlx5_query_nic_vport_mac_address()
is not relelavnt to vdpa since it is the mac that should be used by the regular NIC driver.

Quoted 4 lines
---
  drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
index b67bba581dfd..ece2183e7b20 100644
@@ -2005,10 +2005,7 @@ static int

mlx5_vdpa_dev_add(struct

vdpa_mgmt_dev *v_mdev, const char *name)

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c

Quoted 3 lines

if (err)
goto err_mtu;

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -1
-	err = mlx5_query_nic_vport_mac_address(mdev, 0,

0, config-

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

mac);

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c

Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -3
-	if (err)
-		goto err_mtu;
-
+	eth_random_addr(config->mac);

I think this patch is missing setting VIRTIO_NET_F_MTU. I will post v2 with the other fixes in this series.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

I don't really understand why this is a good idea.

If userspace wants a random mac it can set it, with this patch it is impossible to know whether the mac is a hardware one (which will be persistent e.g. across reboots) or a random

one.

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
Quoted 1 line

You can still get a persistent MAC set by the vdpa tool. e.g

vdpa dev config set vdpa0 mac 00:11:22:33:44:55

If you don't use vdpa tool, the device assigns a random MAC. This MAC is used to filter imcoming unicast traffic (done in a subsequent

patch).

Quoted 3 lines

Well previously device learned the MAC from outgoing traffic and used that for the filter.

No, was is added only in the last series that Parav send. Before that the device did not filter and forwarded any packet that was forwarded to it buy the eswitch.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

Is changing that to a random value really all that useful as a default? Why not do the randomization in userspace?

I think we want management entity to set the MAC, that's the VDPA

tool.

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

So as things are right now (with the last series applied), the vdpa tool is the tool to assign MAC addresses and if it doesn't, a device randomly generated MAC applies. Currently MAC addresses set by qemu command line are ignored (set_config is not implementd). We can allow this but this will override vdpa tool configuration.

I believe its incorrect to always do random generated mac as of this

patch.

Quoted 1 line
Quoted 1 line

This is because, doing so ignores any admin config done by the sysadmin

on the switch (ovs side) using [1].

Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 5 lines

Well, when this patch was sent, we still had thoughts to let mlx5e NIC and the VDPA to co-exist on the same function (VF or SF). Now that we're off this idea you can become tempted to use the MAC address configured for the NIC but I don't think it's a good idea. We already have a dedicated tool to configure MAC for VDPA so let's use it.

Right. And users can decide to reuse the hardware MAC if they want to.

Right.
If user chose to reuse the hw mac set by the eswitch, so let them use it.
When smartnic is used, some users do not trust compute side for network attributes configuration. So those users to configure the MAC from eswitch along with ovs policy.
I think Sean gave one example of it.

And user can choose to override it via vdpa tool/qemu.

I am not sure doing only one_way fits all.
Switch/ovs side configuring the mac along with policy seems fine to me.
But this may not fit the case for those who doesn't have eswitch.
Jason offline or in previous thread mentioned a use case to create multiple vdpa device from single PF/VF. At Mellanox at least we don't see that use case at moment given its attached to eswitch.

Quoted 10 lines
Quoted 2 lines
Quoted 2 lines

So if user choose to configure using eswitch config, mlx5_vnet to honor

that.

Quoted 1 line
Quoted 1 line

And if user prefers to override is using vdpa tool or set_config from

QEMU side, so be it.

Quoted 4 lines

I agree that we should let the user to configure the MAC through qemu argument when booting the VM. So I'll add this for the next spin of this series.

Quoted 6 lines

OK so
- if MAC is configured it is used
- if not configured 0 is reported to userspace

fair summary?

LGTM.
Eli?

Quoted 8 lines
Quoted 1 line
Quoted 1 line

Hence, instead of reporting all zeros, mlx5 should query own vport

context and publish that mac in the config layout and rx steering side.

Quoted 2 lines
Quoted 2 lines

If user choose to override it, config layout and rx rules will have to

updated on such config.

Quoted 3 lines
Quoted 3 lines

[1] devlink port function set pci/0000:03:00.0/<port_id_of_sf/vf>/ hw_addr 00:11:22:33:44:55

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#37 lore raw

Re: [PATCH linux-next 7/9] vdpa/mlx5: Provide device generated random MAC address

In reply to Parav Pandit
Quoted 87 lines · Parav Pandit

Hi Eli,

Quoted 75 lines

From: Eli Cohen <[email protected]>
Sent: Tuesday, March 2, 2021 11:09 AM

Quoted 26 lines · Michael S. Tsirkin
Quoted 25 lines · Eli Cohen
Quoted 24 lines · Michael S. Tsirkin
Quoted 23 lines · Eli Cohen
Quoted 22 lines · Jason Wang
Quoted 11 lines · Parav Pandit

From: Eli Cohen <[email protected]>

Use a randomly generated MAC address to be applied in case it is not configured by management tool.

The value queried through mlx5_query_nic_vport_mac_address() is not relelavnt to vdpa since it is the mac that should be used by the regular NIC driver.

Quoted 4 lines
---
  drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_dev_add(struct

Quoted 6 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
index b67bba581dfd..ece2183e7b20 100644
@@ -2005,10 +2005,7 @@ static int mlx5_vdpa_dev_add(struct

vdpa_mgmt_dev *v_mdev, const char *name)

Quoted 25 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_dev_add(struct · line 2007

Quoted 3 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -1
  	if (err)
  		goto err_mtu;
-	err = mlx5_query_nic_vport_mac_address(mdev, 0, 0, config-

mac);

Quoted 21 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_dev_add(struct · line 2007

Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -3
-	if (err)
-		goto err_mtu;
-
+	eth_random_addr(config->mac);

I think this patch is missing setting VIRTIO_NET_F_MTU. I will post v2 with the other fixes in this series.

Quoted 6 lines

I don't really understand why this is a good idea.

If userspace wants a random mac it can set it, with this patch it is impossible to know whether the mac is a hardware one (which will be persistent e.g. across reboots) or a random one.

You can still get a persistent MAC set by the vdpa tool. e.g

vdpa dev config set vdpa0 mac 00:11:22:33:44:55

If you don't use vdpa tool, the device assigns a random MAC. This MAC is used to filter imcoming unicast traffic (done in a subsequent

patch).

Quoted 3 lines

Well previously device learned the MAC from outgoing traffic and used that for the filter.

No, was is added only in the last series that Parav send. Before that the device did not filter and forwarded any packet that was forwarded to it buy the eswitch.

Quoted 3 lines

Is changing that to a random value really all that useful as a default? Why not do the randomization in userspace?

Quoted 6 lines

I think we want management entity to set the MAC, that's the VDPA tool. So as things are right now (with the last series applied), the vdpa tool is the tool to assign MAC addresses and if it doesn't, a device randomly generated MAC applies. Currently MAC addresses set by qemu command line are ignored (set_config is not implementd). We can allow this but this will override vdpa tool configuration.

I believe its incorrect to always do random generated mac as of this patch.
This is because, doing so ignores any admin config done by the sysadmin on the switch (ovs side) using [1].

Quoted 7 lines

So if user choose to configure using eswitch config, mlx5_vnet to honor that.
And if user prefers to override is using vdpa tool or set_config from QEMU side, so be it.
Hence, instead of reporting all zeros, mlx5 should query own vport context and publish that mac in the config layout and rx steering side.

If user choose to override it, config layout and rx rules will have to updated on such config.

[1] devlink port function set pci/0000:03:00.0/<port_id_of_sf/vf>/ hw_addr 00:11:22:33:44:55

well it has reported all zeros to mean "learning bridge" for a so while I suspect changing that is an ABI change, though a minor one ...

If you do change it please add some other way to find out whether it still learns from outgoing traffic (ie whether mac spoofing is enabled).

Signature · 6 lines
MST

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#38 lore raw

PATCH 8/9 vdpa/mlx5: Support configuration of MAC

In reply to Parav Pandit

From: Eli Cohen <[email protected]>

Add code to accept MAC configuration through vdpa tool. The MAC is written into the config struct and later can be retrieved through get_config().

Examples:
1. Configure MAC:

$ vdpa dev config set vdpa0 mac 00:11:22:33:44:55

2. Show configured params:

$ vdpa dev config show
vdpa0: mac 00:11:22:33:44:55 link down link_announce false mtu 0 speed 0 duplex 0
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/vdpa/mlx5/net/mlx5_vnet.c +17 -0
index ece2183e7b20..51a3fc4cde4d 100644
@@ -1972,6 +1972,22 @@ struct mlx5_vdpa_mgmtdev {
 	struct mlx5_vdpa_net *ndev;
 };
 
+static int mlx5_vdpa_net_dev_config_set(struct vdpa_mgmt_dev *v_mdev,
+					struct vdpa_device *vdev,
+					const struct vdpa_dev_config_set_attr *attrs)
+{
+	struct mlx5_vdpa_mgmtdev *mgtdev = container_of(v_mdev, struct mlx5_vdpa_mgmtdev, mgtdev);
+	struct mlx5_vdpa_net *ndev = mgtdev->ndev;
+
+	if (attrs->mask.mtu_valid)
+		return -EOPNOTSUPP;
+
+	if (attrs->mask.mac_valid)
+		memcpy(ndev->config.mac, attrs->cfg.mac, ETH_ALEN);
+
+	return 0;
+}
+
 static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name)
 {
 	struct mlx5_vdpa_mgmtdev *mgtdev = container_of(v_mdev, struct mlx5_vdpa_mgmtdev, mgtdev);
@@ -2044,6 +2060,7 @@ static void mlx5_vdpa_dev_del(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
 static const struct vdpa_mgmtdev_ops mdev_ops = {
 	.dev_add = mlx5_vdpa_dev_add,
 	.dev_del = mlx5_vdpa_dev_del,
+	.dev_config_set = mlx5_vdpa_net_dev_config_set,
 };
 
 static struct virtio_device_id id_table[] = {
Signature · 6 lines
2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Acked-by on v1 8/9
#39 lore raw

Re: [PATCH linux-next 8/9] vdpa/mlx5: Support configuration of MAC

Quoted 10 lines · Parav Pandit

From: Eli Cohen <[email protected]>

Add code to accept MAC configuration through vdpa tool. The MAC is written into the config struct and later can be retrieved through get_config().

Examples:
1. Configure MAC:

$ vdpa dev config set vdpa0 mac 00:11:22:33:44:55
Quoted 7 lines

2. Show configured params:

$ vdpa dev config show
vdpa0: mac 00:11:22:33:44:55 link down link_announce false mtu 0 speed 0 duplex 0

---

Quoted 31 lines
  drivers/vdpa/mlx5/net/mlx5_vnet.c | 17 +++++++++++++++++
  1 file changed, 17 insertions(+)
drivers/vdpa/mlx5/net/mlx5_vnet.c +16 -0
index ece2183e7b20..51a3fc4cde4d 100644
@@ -1972,6 +1972,22 @@ struct mlx5_vdpa_mgmtdev {
  	struct mlx5_vdpa_net *ndev;
  };
 
+static int mlx5_vdpa_net_dev_config_set(struct vdpa_mgmt_dev *v_mdev,
+					struct vdpa_device *vdev,
+					const struct vdpa_dev_config_set_attr *attrs)
+{
+	struct mlx5_vdpa_mgmtdev *mgtdev = container_of(v_mdev, struct mlx5_vdpa_mgmtdev, mgtdev);
+	struct mlx5_vdpa_net *ndev = mgtdev->ndev;
+
+	if (attrs->mask.mtu_valid)
+		return -EOPNOTSUPP;
+
+	if (attrs->mask.mac_valid)
+		memcpy(ndev->config.mac, attrs->cfg.mac, ETH_ALEN);
+
+	return 0;
+}
+
  static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name)
  {
  	struct mlx5_vdpa_mgmtdev *mgtdev = container_of(v_mdev, struct mlx5_vdpa_mgmtdev, mgtdev);

drivers/vdpa/mlx5/net/mlx5_vnet.c static void mlx5_vdpa_dev_del(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device * · line 2066

Quoted 7 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -0
@@ -2044,6 +2060,7 @@ static void mlx5_vdpa_dev_del(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
  static const struct vdpa_mgmtdev_ops mdev_ops = {
  	.dev_add = mlx5_vdpa_dev_add,
  	.dev_del = mlx5_vdpa_dev_del,
+	.dev_config_set = mlx5_vdpa_net_dev_config_set,
  };
 
  static struct virtio_device_id id_table[] = {

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#40 lore raw

PATCH 9/9 vdpa/mlx5: Forward only packets with allowed MAC address

In reply to Parav Pandit

From: Eli Cohen <[email protected]>

Add rules to forward packets to the net device's TIR only if the destination MAC is equal to the configured MAC. This is required to prevent the netdevice from receiving traffic not destined to its configured MAC.

---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 84 +++++++++++++++++++++++--------
 1 file changed, 64 insertions(+), 20 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +64 -20
index 51a3fc4cde4d..9b580c67acda 100644
@@ -147,7 +147,8 @@ struct mlx5_vdpa_net {
 	struct mutex reslock;
 	struct mlx5_flow_table *rxft;
 	struct mlx5_fc *rx_counter;
-	struct mlx5_flow_handle *rx_rule;
+	struct mlx5_flow_handle *rx_rule_ucast;
+	struct mlx5_flow_handle *rx_rule_mcast;
 	bool setup;
 	u16 mtu;
 };
@@ -1294,21 +1295,34 @@ static int add_fwd_to_tir(struct mlx5_vdpa_net *ndev)
 	struct mlx5_flow_table_attr ft_attr = {};
 	struct mlx5_flow_act flow_act = {};
 	struct mlx5_flow_namespace *ns;
+	struct mlx5_flow_spec *spec;
+	void *headers_c;
+	void *headers_v;
+	u8 *dmac_c;
+	u8 *dmac_v;
 	int err;
 
-	/* for now, one entry, match all, forward to tir */
-	ft_attr.max_fte = 1;
-	ft_attr.autogroup.max_num_groups = 1;
+	spec = kvzalloc(sizeof(*spec), GFP_KERNEL);
+	if (!spec)
+		return -ENOMEM;
+
+	spec->match_criteria_enable = MLX5_MATCH_OUTER_HEADERS;
+	ft_attr.max_fte = 2;
+	ft_attr.autogroup.max_num_groups = 2;
 
-	ns = mlx5_get_flow_namespace(ndev->mvdev.mdev, MLX5_FLOW_NAMESPACE_BYPASS);
+	ns = mlx5_get_flow_namespace(ndev->mvdev.mdev,
+				     MLX5_FLOW_NAMESPACE_BYPASS);
 	if (!ns) {
-		mlx5_vdpa_warn(&ndev->mvdev, "get flow namespace\n");
-		return -EOPNOTSUPP;
+		mlx5_vdpa_warn(&ndev->mvdev, "failed to get flow namespace\n");
+		err = -EOPNOTSUPP;
+		goto err_ns;
 	}
 
 	ndev->rxft = mlx5_create_auto_grouped_flow_table(ns, &ft_attr);
-	if (IS_ERR(ndev->rxft))
-		return PTR_ERR(ndev->rxft);
+	if (IS_ERR(ndev->rxft)) {
+		err = PTR_ERR(ndev->rxft);
+		goto err_ns;
+	}
 
 	ndev->rx_counter = mlx5_fc_create(ndev->mvdev.mdev, false);
 	if (IS_ERR(ndev->rx_counter)) {
@@ -1316,37 +1330,67 @@ static int add_fwd_to_tir(struct mlx5_vdpa_net *ndev)
 		goto err_fc;
 	}
 
-	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST | MLX5_FLOW_CONTEXT_ACTION_COUNT;
+	headers_c = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, outer_headers);
+	dmac_c = MLX5_ADDR_OF(fte_match_param, headers_c, outer_headers.dmac_47_16);
+	memset(dmac_c, 0xff, ETH_ALEN);
+	headers_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, outer_headers);
+	dmac_v = MLX5_ADDR_OF(fte_match_param, headers_v, outer_headers.dmac_47_16);
+	ether_addr_copy(dmac_v, ndev->config.mac);
+
+	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
+			  MLX5_FLOW_CONTEXT_ACTION_COUNT;
 	dest[0].type = MLX5_FLOW_DESTINATION_TYPE_TIR;
 	dest[0].tir_num = ndev->res.tirn;
 	dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
 	dest[1].counter_id = mlx5_fc_id(ndev->rx_counter);
-	ndev->rx_rule = mlx5_add_flow_rules(ndev->rxft, NULL, &flow_act, dest, 2);
-	if (IS_ERR(ndev->rx_rule)) {
-		err = PTR_ERR(ndev->rx_rule);
-		ndev->rx_rule = NULL;
-		goto err_rule;
+	ndev->rx_rule_ucast = mlx5_add_flow_rules(ndev->rxft, spec, &flow_act,
+						  dest, 2);
+
+	if (IS_ERR(ndev->rx_rule_ucast)) {
+		err = PTR_ERR(ndev->rx_rule_ucast);
+		ndev->rx_rule_ucast = NULL;
+		goto err_rule_ucast;
+	}
+
+	memset(dmac_c, 0, ETH_ALEN);
+	memset(dmac_v, 0, ETH_ALEN);
+	dmac_c[0] = 1;
+	dmac_v[0] = 1;
+	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
+	ndev->rx_rule_mcast = mlx5_add_flow_rules(ndev->rxft, spec, &flow_act,
+						  dest, 1);
+	if (IS_ERR(ndev->rx_rule_mcast)) {
+		err = PTR_ERR(ndev->rx_rule_mcast);
+		ndev->rx_rule_mcast = NULL;
+		goto err_rule_mcast;
 	}
 
+	kvfree(spec);
 	return 0;
 
-err_rule:
+err_rule_mcast:
+	mlx5_del_flow_rules(ndev->rx_rule_ucast);
+	ndev->rx_rule_ucast = NULL;
+err_rule_ucast:
 	mlx5_fc_destroy(ndev->mvdev.mdev, ndev->rx_counter);
 err_fc:
 	mlx5_destroy_flow_table(ndev->rxft);
+err_ns:
+	kvfree(spec);
 	return err;
 }
 
 static void remove_fwd_to_tir(struct mlx5_vdpa_net *ndev)
 {
-	if (!ndev->rx_rule)
+	if (!ndev->rx_rule_ucast)
 		return;
 
-	mlx5_del_flow_rules(ndev->rx_rule);
+	mlx5_del_flow_rules(ndev->rx_rule_mcast);
+	ndev->rx_rule_mcast = NULL;
+	mlx5_del_flow_rules(ndev->rx_rule_ucast);
+	ndev->rx_rule_ucast = NULL;
 	mlx5_fc_destroy(ndev->mvdev.mdev, ndev->rx_counter);
 	mlx5_destroy_flow_table(ndev->rxft);
-
-	ndev->rx_rule = NULL;
 }
 
 static void mlx5_vdpa_kick_vq(struct vdpa_device *vdev, u16 idx)
Signature · 6 lines
2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#41 lore raw

Re: [PATCH linux-next 9/9] vdpa/mlx5: Forward only packets with allowed MAC address

Quoted 6 lines · Parav Pandit

From: Eli Cohen <[email protected]>

Add rules to forward packets to the net device's TIR only if the destination MAC is equal to the configured MAC. This is required to prevent the netdevice from receiving traffic not destined to its configured MAC.

Just to confirm, this will only apply to unicast packet and we will still let multicast/broadcast to go?

Thanks

Quoted 133 lines
---
  drivers/vdpa/mlx5/net/mlx5_vnet.c | 84 +++++++++++++++++++++++--------
  1 file changed, 64 insertions(+), 20 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +61 -18
index 51a3fc4cde4d..9b580c67acda 100644
@@ -147,7 +147,8 @@ struct mlx5_vdpa_net {
  	struct mutex reslock;
  	struct mlx5_flow_table *rxft;
  	struct mlx5_fc *rx_counter;
-	struct mlx5_flow_handle *rx_rule;
+	struct mlx5_flow_handle *rx_rule_ucast;
+	struct mlx5_flow_handle *rx_rule_mcast;
  	bool setup;
  	u16 mtu;
  };
@@ -1294,21 +1295,34 @@ static int add_fwd_to_tir(struct mlx5_vdpa_net *ndev)
  	struct mlx5_flow_table_attr ft_attr = {};
  	struct mlx5_flow_act flow_act = {};
  	struct mlx5_flow_namespace *ns;
+	struct mlx5_flow_spec *spec;
+	void *headers_c;
+	void *headers_v;
+	u8 *dmac_c;
+	u8 *dmac_v;
  	int err;
 
-	/* for now, one entry, match all, forward to tir */
-	ft_attr.max_fte = 1;
-	ft_attr.autogroup.max_num_groups = 1;
+	spec = kvzalloc(sizeof(*spec), GFP_KERNEL);
+	if (!spec)
+		return -ENOMEM;
+
+	spec->match_criteria_enable = MLX5_MATCH_OUTER_HEADERS;
+	ft_attr.max_fte = 2;
+	ft_attr.autogroup.max_num_groups = 2;
 
-	ns = mlx5_get_flow_namespace(ndev->mvdev.mdev, MLX5_FLOW_NAMESPACE_BYPASS);
+	ns = mlx5_get_flow_namespace(ndev->mvdev.mdev,
+				     MLX5_FLOW_NAMESPACE_BYPASS);
  	if (!ns) {
-		mlx5_vdpa_warn(&ndev->mvdev, "get flow namespace\n");
-		return -EOPNOTSUPP;
+		mlx5_vdpa_warn(&ndev->mvdev, "failed to get flow namespace\n");
+		err = -EOPNOTSUPP;
+		goto err_ns;
  	}
 
  	ndev->rxft = mlx5_create_auto_grouped_flow_table(ns, &ft_attr);
-	if (IS_ERR(ndev->rxft))
-		return PTR_ERR(ndev->rxft);
+	if (IS_ERR(ndev->rxft)) {
+		err = PTR_ERR(ndev->rxft);
+		goto err_ns;
+	}
 
  	ndev->rx_counter = mlx5_fc_create(ndev->mvdev.mdev, false);
  	if (IS_ERR(ndev->rx_counter)) {
@@ -1316,37 +1330,67 @@ static int add_fwd_to_tir(struct mlx5_vdpa_net *ndev)
  		goto err_fc;
  	}
 
-	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST | MLX5_FLOW_CONTEXT_ACTION_COUNT;
+	headers_c = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, outer_headers);
+	dmac_c = MLX5_ADDR_OF(fte_match_param, headers_c, outer_headers.dmac_47_16);
+	memset(dmac_c, 0xff, ETH_ALEN);
+	headers_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, outer_headers);
+	dmac_v = MLX5_ADDR_OF(fte_match_param, headers_v, outer_headers.dmac_47_16);
+	ether_addr_copy(dmac_v, ndev->config.mac);
+
+	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
+			  MLX5_FLOW_CONTEXT_ACTION_COUNT;
  	dest[0].type = MLX5_FLOW_DESTINATION_TYPE_TIR;
  	dest[0].tir_num = ndev->res.tirn;
  	dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
  	dest[1].counter_id = mlx5_fc_id(ndev->rx_counter);
-	ndev->rx_rule = mlx5_add_flow_rules(ndev->rxft, NULL, &flow_act, dest, 2);
-	if (IS_ERR(ndev->rx_rule)) {
-		err = PTR_ERR(ndev->rx_rule);
-		ndev->rx_rule = NULL;
-		goto err_rule;
+	ndev->rx_rule_ucast = mlx5_add_flow_rules(ndev->rxft, spec, &flow_act,
+						  dest, 2);
+
+	if (IS_ERR(ndev->rx_rule_ucast)) {
+		err = PTR_ERR(ndev->rx_rule_ucast);
+		ndev->rx_rule_ucast = NULL;
+		goto err_rule_ucast;
+	}
+
+	memset(dmac_c, 0, ETH_ALEN);
+	memset(dmac_v, 0, ETH_ALEN);
+	dmac_c[0] = 1;
+	dmac_v[0] = 1;
+	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
+	ndev->rx_rule_mcast = mlx5_add_flow_rules(ndev->rxft, spec, &flow_act,
+						  dest, 1);
+	if (IS_ERR(ndev->rx_rule_mcast)) {
+		err = PTR_ERR(ndev->rx_rule_mcast);
+		ndev->rx_rule_mcast = NULL;
+		goto err_rule_mcast;
  	}
 
+	kvfree(spec);
  	return 0;
 
-err_rule:
+err_rule_mcast:
+	mlx5_del_flow_rules(ndev->rx_rule_ucast);
+	ndev->rx_rule_ucast = NULL;
+err_rule_ucast:
  	mlx5_fc_destroy(ndev->mvdev.mdev, ndev->rx_counter);
  err_fc:
  	mlx5_destroy_flow_table(ndev->rxft);
+err_ns:
+	kvfree(spec);
  	return err;
  }
 
  static void remove_fwd_to_tir(struct mlx5_vdpa_net *ndev)
  {
-	if (!ndev->rx_rule)
+	if (!ndev->rx_rule_ucast)
  		return;
 
-	mlx5_del_flow_rules(ndev->rx_rule);
+	mlx5_del_flow_rules(ndev->rx_rule_mcast);

drivers/vdpa/mlx5/net/mlx5_vnet.c static int add_fwd_to_tir(struct mlx5_vdpa_net *ndev) · line 1396

Quoted 10 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +3 -2
+	ndev->rx_rule_mcast = NULL;
+	mlx5_del_flow_rules(ndev->rx_rule_ucast);
+	ndev->rx_rule_ucast = NULL;
  	mlx5_fc_destroy(ndev->mvdev.mdev, ndev->rx_counter);
  	mlx5_destroy_flow_table(ndev->rxft);
-
-	ndev->rx_rule = NULL;
  }
 
  static void mlx5_vdpa_kick_vq(struct vdpa_device *vdev, u16 idx)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#42 lore raw
In reply to Parav Pandit
Quoted 35 lines · Parav Pandit

Currently user cannot set the mac address and mtu of the vdpa device. This patchset enables users to set the mac address and mtu of the vdpa device once the device is created.
If a vendor driver supports such configuration user can set it otherwise user gets unsupported error.

vdpa mac address and mtu are device configuration layout fields. To keep interface generic enough for multiple types of vdpa devices, mac address and mtu setting is implemented as configuration layout config knobs.
This enables to use similar config layout for other virtio devices.

An example of query & set of config layout fields for vdpa_sim_net driver:

Configuration layout fields are set after device is created.
This enables user to change such fields at later point without destroying and recreating the device for new config.

$ vdpa mgmtdev show
vdpasim_net:
  supported_classes net

Add the device:

$ vdpa dev add name bar mgmtdev vdpasim_net

Configure mac address and mtu:

$ vdpa dev config set bar mac 00:11:22:33:44:55 mtu 9000

In above command only mac address or only mtu can also be set.

View the config after setting:

$ vdpa dev config show
bar: mac 00:11:22:33:44:55 link up link_announce false mtu 9000 speed 0 duplex 0
Quoted 10 lines

Patch summary:
Patch-1 uses read only features bit to detect endianness Patch-2 implements new config layout query command
Patch-3 implements callback for setting vdpa net config fields Patch-4 extends vdpa_sim_net driver to implement mac, mtu setting Patch-5 removed redundant get_config callback
Patch-6 mlx5 vdpa driver migrates to user created vdpa device Patch-7 mlx5 vdpa driver uses random mac address when not configured Patch-8 mlx5 vdpa driver supports user provided mac config Patch-9 mlx5 vdpa driver uses user provided mac during rx flow steering

which tree is this for? does not seem to apply to linux-next branch of vhost ...

Quoted 13 lines

Eli Cohen (4):
vdpa/mlx5: Enable user to add/delete vdpa device vdpa/mlx5: Provide device generated random MAC address vdpa/mlx5: Support configuration of MAC vdpa/mlx5: Forward only packets with allowed MAC address

Parav Pandit (5):
vdpa_sim: Consider read only supported features instead of current
vdpa: Introduce query of device config layout
vdpa: Enable user to set mac and mtu of vdpa device
vdpa_sim_net: Enable user to set mac address and mtu
vdpa_sim_net: Remove redundant get_config callback

Quoted 10 lines
 drivers/vdpa/mlx5/net/mlx5_vnet.c    | 185 ++++++++++++++----
 drivers/vdpa/vdpa.c                  | 270 +++++++++++++++++++++++++++
 drivers/vdpa/vdpa_sim/vdpa_sim.h     |   4 +-
 drivers/vdpa/vdpa_sim/vdpa_sim_net.c |  49 +++--
 include/linux/vdpa.h                 |  16 ++
 include/uapi/linux/vdpa.h            |  12 ++
 6 files changed, 476 insertions(+), 60 deletions(-)
Signature · 1 line
2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#43 lore raw
Quoted 8 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, February 24, 2021 12:21 PM

Quoted 2 lines · Parav Pandit

Currently user cannot set the mac address and mtu of the vdpa device. This patchset enables users to set the mac address and mtu of the vdpa

[..]

Quoted 13 lines
Quoted 12 lines

Patch summary:
Patch-1 uses read only features bit to detect endianness Patch-2 implements new config layout query command Patch-3 implements callback for setting vdpa net config fields Patch-4 extends vdpa_sim_net driver to implement mac, mtu setting Patch-5 removed redundant get_config callback
Patch-6 mlx5 vdpa driver migrates to user created vdpa device Patch-7 mlx5 vdpa driver uses random mac address when not configured Patch-8 mlx5 vdpa driver supports user provided mac config Patch-9 mlx5 vdpa driver uses user provided mac during rx flow steering

Quoted 1 line

which tree is this for? does not seem to apply to linux-next branch of vhost ...

It is for linux-next branch of vhost. However I missed to rebase before sending. My bad.
Preparing to send v2 after addressing other comments and after rebase.
_______________________________________________
Virtualization mailing list [email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization