Skip to contentSkip to conversation

Conditionally read fields in dev cfg space

PATCH RESEND Superseded Zhu Lingshan 2 participants 14 messages Sep 27, 2022

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Conditionally read fields in dev cfg space

Resend to fix a typo reace --> race in the commit message.

This series intends to read the fields in virtio-net device configuration space conditionally on the feature bits, this means:

MTU exists if VIRTIO_NET_F_MTU is set
MAC exists if VIRTIO_NET_F_NET is set
MQ exists if VIRTIO_NET_F_MQ or VIRTIO_NET_F_RSS is set.

This series report device features to userspace and invokes vdpa_config_ops.get_config() rather than vdpa_get_config_unlocked() to read the device config spcae, so no races in vdpa_set_features_unlocked()

Thanks!

Changes from V1:
1)Better comments for VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES, only in the header file(Jason)
2)Split original 3/4 into separate patches(Jason) 3)Check FEATURES_OK for reporting driver features in vdpa_dev_config_fill (Jason)
4) Add iproute2 example for reporting device features

Zhu Lingshan (6):
vDPA: allow userspace to query features of a vDPA device
vDPA: only report driver features if FEATURES_OK is set
vDPA: check VIRTIO_NET_F_RSS for max_virtqueue_paris's presence
vDPA: check virtio device features to detect MQ
vDPA: fix spars cast warning in vdpa_dev_net_mq_config_fill
vDPA: conditionally read MTU and MAC in dev cfg space

 drivers/vdpa/vdpa.c       | 71 ++++++++++++++++++++++++++++++---------
 include/uapi/linux/vdpa.h |  4 +++
 2 files changed, 59 insertions(+), 16 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH RESEND v2 1/6 vDPA: allow userspace to query features of a vDPA device

This commit adds a new vDPA netlink attribution VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES. Userspace can query features of vDPA devices through this new attr.

This commit invokes vdpa_config_ops.get_config() rather than vdpa_get_config_unlocked() to read the device config spcae, so no races in vdpa_set_features_unlocked()

Userspace tool iproute2 example:

$ vdpa dev config show vdpa0
vdpa0: mac 00:e8:ca:11:be:05 link up link_announce false max_vq_pairs 4 mtu 1500
  negotiated_features MRG_RXBUF CTRL_VQ MQ VERSION_1 ACCESS_PLATFORM
  dev_features MTU MAC MRG_RXBUF CTRL_VQ MQ ANY_LAYOUT VERSION_1 ACCESS_PLATFORM
---
 drivers/vdpa/vdpa.c       | 17 ++++++++++++-----
 include/uapi/linux/vdpa.h |  4 ++++
 2 files changed, 16 insertions(+), 5 deletions(-)
drivers/vdpa/vdpa.c +12 -5
index c06c02704461..2035700d6fc8 100644
@@ -491,6 +491,7 @@ static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_buff *m
 		err = -EMSGSIZE;
 		goto msg_err;
 	}
+
 	if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_SUPPORTED_FEATURES,
 			      mdev->supported_features, VDPA_ATTR_PAD)) {
 		err = -EMSGSIZE;
@@ -815,10 +816,10 @@ static int vdpa_dev_net_mq_config_fill(struct vdpa_device *vdev,
 static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *msg)
 {
 	struct virtio_net_config config = {};
-	u64 features;
+	u64 features_device, features_driver;
 	u16 val_u16;
 
-	vdpa_get_config_unlocked(vdev, 0, &config, sizeof(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))
@@ -832,12 +833,18 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms
 	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, val_u16))
 		return -EMSGSIZE;
 
-	features = vdev->config->get_driver_features(vdev);
-	if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_NEGOTIATED_FEATURES, features,
+	features_driver = vdev->config->get_driver_features(vdev);
+	if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_NEGOTIATED_FEATURES, features_driver,
+			      VDPA_ATTR_PAD))
+		return -EMSGSIZE;
+
+	features_device = vdev->config->get_device_features(vdev);
+
+	if (nla_put_u64_64bit(msg, VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES, features_device,
 			      VDPA_ATTR_PAD))
 		return -EMSGSIZE;
 
-	return vdpa_dev_net_mq_config_fill(vdev, msg, features, &config);
+	return vdpa_dev_net_mq_config_fill(vdev, msg, features_driver, &config);
 }
 
 static int
include/uapi/linux/vdpa.h +4 -0
index 25c55cab3d7c..07474183fdb3 100644
@@ -46,12 +46,16 @@ enum vdpa_attr {
 
 	VDPA_ATTR_DEV_NEGOTIATED_FEATURES,	/* u64 */
 	VDPA_ATTR_DEV_MGMTDEV_MAX_VQS,		/* u32 */
+	/* virtio features that are supported by the vDPA management device */
 	VDPA_ATTR_DEV_SUPPORTED_FEATURES,	/* u64 */
 
 	VDPA_ATTR_DEV_QUEUE_INDEX,              /* u32 */
 	VDPA_ATTR_DEV_VENDOR_ATTR_NAME,		/* string */
 	VDPA_ATTR_DEV_VENDOR_ATTR_VALUE,        /* u64 */
 
+	/* virtio features that are supported by the vDPA device */
+	VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES,	/* u64 */
+
 	/* new attributes must be added above here */
 	VDPA_ATTR_MAX,
 };
Signature · 1 line
2.31.1
#2 lore raw

Re: [PATCH V2 RESEND 1/6] vDPA: allow userspace to query features of a vDPA device

Quoted 27 lines · Zhu Lingshan

This commit adds a new vDPA netlink attribution VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES. Userspace can query features of vDPA devices through this new attr.

This commit invokes vdpa_config_ops.get_config() rather than vdpa_get_config_unlocked() to read the device config spcae, so no races in vdpa_set_features_unlocked()

Userspace tool iproute2 example:

$ vdpa dev config show vdpa0
vdpa0: mac 00:e8:ca:11:be:05 link up link_announce false max_vq_pairs 4 mtu 1500
  negotiated_features MRG_RXBUF CTRL_VQ MQ VERSION_1 ACCESS_PLATFORM
  dev_features MTU MAC MRG_RXBUF CTRL_VQ MQ ANY_LAYOUT VERSION_1 ACCESS_PLATFORM
---
 drivers/vdpa/vdpa.c       | 17 ++++++++++++-----
 include/uapi/linux/vdpa.h |  4 ++++
 2 files changed, 16 insertions(+), 5 deletions(-)
drivers/vdpa/vdpa.c +0 -0
index c06c02704461..2035700d6fc8 100644

drivers/vdpa/vdpa.c static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_buff *m · line 494

Quoted 4 lines
drivers/vdpa/vdpa.c +1 -0
@@ -491,6 +491,7 @@ static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_buff *m
                err = -EMSGSIZE;
                goto msg_err;
        }
+

Nit: Unnecessary changes.

Quoted 17 lines
drivers/vdpa/vdpa.c +2 -2
        if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_SUPPORTED_FEATURES,
                              mdev->supported_features, VDPA_ATTR_PAD)) {
                err = -EMSGSIZE;
@@ -815,10 +816,10 @@ static int vdpa_dev_net_mq_config_fill(struct vdpa_device *vdev,
 static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *msg)
 {
        struct virtio_net_config config = {};
-       u64 features;
+       u64 features_device, features_driver;
        u16 val_u16;
 
-       vdpa_get_config_unlocked(vdev, 0, &config, sizeof(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_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms · line 839

Quoted 9 lines
drivers/vdpa/vdpa.c +4 -2
@@ -832,12 +833,18 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms
        if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, val_u16))
                return -EMSGSIZE;
 
-       features = vdev->config->get_driver_features(vdev);
-       if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_NEGOTIATED_FEATURES, features,
+       features_driver = vdev->config->get_driver_features(vdev);
+       if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_NEGOTIATED_FEATURES, features_driver,
+                             VDPA_ATTR_PAD))
+               return -EMSGSIZE;

It looks to me that those parts were removed in patch 2. I wonder if it's better to reorder the patch to let patch 2 come first?

Thanks

Quoted 36 lines
drivers/vdpa/vdpa.c +5 -1
+
+       features_device = vdev->config->get_device_features(vdev);
+
+       if (nla_put_u64_64bit(msg, VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES, features_device,
                              VDPA_ATTR_PAD))
                return -EMSGSIZE;
 
-       return vdpa_dev_net_mq_config_fill(vdev, msg, features, &config);
+       return vdpa_dev_net_mq_config_fill(vdev, msg, features_driver, &config);
 }
 
 static int
include/uapi/linux/vdpa.h +4 -1
index 25c55cab3d7c..07474183fdb3 100644
@@ -46,12 +46,16 @@ enum vdpa_attr {
 
        VDPA_ATTR_DEV_NEGOTIATED_FEATURES,      /* u64 */
        VDPA_ATTR_DEV_MGMTDEV_MAX_VQS,          /* u32 */
+       /* virtio features that are supported by the vDPA management device */
        VDPA_ATTR_DEV_SUPPORTED_FEATURES,       /* u64 */
 
        VDPA_ATTR_DEV_QUEUE_INDEX,              /* u32 */
        VDPA_ATTR_DEV_VENDOR_ATTR_NAME,         /* string */
        VDPA_ATTR_DEV_VENDOR_ATTR_VALUE,        /* u64 */
 
+       /* virtio features that are supported by the vDPA device */
+       VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES,  /* u64 */
+
        /* new attributes must be added above here */
        VDPA_ATTR_MAX,
 };
--

2.31.1

#3 lore raw

Re: [PATCH V2 RESEND 1/6] vDPA: allow userspace to query features of a vDPA device

Quoted 22 lines · Jason Wang
Quoted 21 lines · Zhu Lingshan

This commit adds a new vDPA netlink attribution VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES. Userspace can query features of vDPA devices through this new attr.

This commit invokes vdpa_config_ops.get_config() rather than vdpa_get_config_unlocked() to read the device config spcae, so no races in vdpa_set_features_unlocked()

Userspace tool iproute2 example:

$ vdpa dev config show vdpa0
vdpa0: mac 00:e8:ca:11:be:05 link up link_announce false max_vq_pairs 4 mtu 1500
   negotiated_features MRG_RXBUF CTRL_VQ MQ VERSION_1 ACCESS_PLATFORM
   dev_features MTU MAC MRG_RXBUF CTRL_VQ MQ ANY_LAYOUT VERSION_1 ACCESS_PLATFORM
---
  drivers/vdpa/vdpa.c       | 17 ++++++++++++-----
  include/uapi/linux/vdpa.h |  4 ++++
  2 files changed, 16 insertions(+), 5 deletions(-)
Quoted 10 lines

drivers/vdpa/vdpa.c static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_buff *m · line 494

Quoted 9 lines
drivers/vdpa/vdpa.c +1 -0
index c06c02704461..2035700d6fc8 100644
@@ -491,6 +491,7 @@ static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_buff *m
                 err = -EMSGSIZE;
                 goto msg_err;
         }
+

Nit: Unnecessary changes.

oh, yes!

Quoted 21 lines
Quoted 21 lines
drivers/vdpa/vdpa.c +2 -2
         if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_SUPPORTED_FEATURES,
                               mdev->supported_features, VDPA_ATTR_PAD)) {
                 err = -EMSGSIZE;
@@ -815,10 +816,10 @@ static int vdpa_dev_net_mq_config_fill(struct vdpa_device *vdev,
  static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *msg)
  {
         struct virtio_net_config config = {};
-       u64 features;
+       u64 features_device, features_driver;
         u16 val_u16;
 
-       vdpa_get_config_unlocked(vdev, 0, &config, sizeof(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))
@@ -832,12 +833,18 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms
         if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, val_u16))
                 return -EMSGSIZE;
 
Quoted 8 lines

drivers/vdpa/vdpa.c static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms · line 839

Quoted 6 lines
drivers/vdpa/vdpa.c +4 -2
-       features = vdev->config->get_driver_features(vdev);
-       if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_NEGOTIATED_FEATURES, features,
+       features_driver = vdev->config->get_driver_features(vdev);
+       if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_NEGOTIATED_FEATURES, features_driver,
+                             VDPA_ATTR_PAD))
+               return -EMSGSIZE;

It looks to me that those parts were removed in patch 2. I wonder if it's better to reorder the patch to let patch 2 come first?

I am not sure, if we apply patch 2(check FEATURES_OK in vdpa_dev_config_fill and report driver features there) first, we need to remove driver_features in vdpa_dev_net_config_fill(),
however, we still not introduce and initialize device features(which is in patch 1, introduce device_features) yet, so the last line "return vdpa_dev_net_mq_config_fill()" which needs features as its parameter may not work, filling NULL looks worse than keep features_driver here.

Thanks
Zhu Lingshan

Quoted 39 lines

Thanks

Quoted 36 lines
drivers/vdpa/vdpa.c +5 -1
+
+       features_device = vdev->config->get_device_features(vdev);
+
+       if (nla_put_u64_64bit(msg, VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES, features_device,
                               VDPA_ATTR_PAD))
                 return -EMSGSIZE;
 
-       return vdpa_dev_net_mq_config_fill(vdev, msg, features, &config);
+       return vdpa_dev_net_mq_config_fill(vdev, msg, features_driver, &config);
  }
 
  static int
include/uapi/linux/vdpa.h +4 -1
index 25c55cab3d7c..07474183fdb3 100644
@@ -46,12 +46,16 @@ enum vdpa_attr {
 
         VDPA_ATTR_DEV_NEGOTIATED_FEATURES,      /* u64 */
         VDPA_ATTR_DEV_MGMTDEV_MAX_VQS,          /* u32 */
+       /* virtio features that are supported by the vDPA management device */
         VDPA_ATTR_DEV_SUPPORTED_FEATURES,       /* u64 */
 
         VDPA_ATTR_DEV_QUEUE_INDEX,              /* u32 */
         VDPA_ATTR_DEV_VENDOR_ATTR_NAME,         /* string */
         VDPA_ATTR_DEV_VENDOR_ATTR_VALUE,        /* u64 */
 
+       /* virtio features that are supported by the vDPA device */
+       VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES,  /* u64 */
+
         /* new attributes must be added above here */
         VDPA_ATTR_MAX,
  };
--

2.31.1

#4 lore raw

PATCH RESEND v2 2/6 vDPA: only report driver features if FEATURES_OK is set

In reply to Zhu Lingshan

This commit reports driver features to user space only after FEATURES_OK is features negotiation is done.

---
 drivers/vdpa/vdpa.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/vdpa/vdpa.c +16 -6
index 2035700d6fc8..e7765953307f 100644
@@ -816,7 +816,7 @@ static int vdpa_dev_net_mq_config_fill(struct vdpa_device *vdev,
 static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *msg)
 {
 	struct virtio_net_config config = {};
-	u64 features_device, features_driver;
+	u64 features_device;
 	u16 val_u16;
 
 	vdev->config->get_config(vdev, 0, &config, sizeof(config));
@@ -833,11 +833,6 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms
 	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, val_u16))
 		return -EMSGSIZE;
 
-	features_driver = vdev->config->get_driver_features(vdev);
-	if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_NEGOTIATED_FEATURES, features_driver,
-			      VDPA_ATTR_PAD))
-		return -EMSGSIZE;
-
 	features_device = vdev->config->get_device_features(vdev);
 
 	if (nla_put_u64_64bit(msg, VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES, features_device,
@@ -851,6 +846,8 @@ 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)
 {
+	u64 features_driver;
+	u8 status = 0;
 	u32 device_id;
 	void *hdr;
 	int err;
@@ -874,6 +871,19 @@ vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid,
 		goto msg_err;
 	}
 
+	/* only read driver features after the feature negotiation is done */
+	if (vdev->config->get_status)
+		status = vdev->config->get_status(vdev);
+
+	if (status & VIRTIO_CONFIG_S_FEATURES_OK) {
+		features_driver = vdev->config->get_driver_features(vdev);
+		if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_NEGOTIATED_FEATURES, features_driver,
+				      VDPA_ATTR_PAD)) {
+			err = -EMSGSIZE;
+			goto msg_err;
+		}
+	}
+
 	switch (device_id) {
 	case VIRTIO_ID_NET:
 		err = vdpa_dev_net_config_fill(vdev, msg);
Signature · 1 line
2.31.1
#5 lore raw

Re: [PATCH V2 RESEND 2/6] vDPA: only report driver features if FEATURES_OK is set

Quoted 44 lines · Zhu Lingshan

This commit reports driver features to user space only after FEATURES_OK is features negotiation is done.

---
 drivers/vdpa/vdpa.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/vdpa/vdpa.c +3 -6
index 2035700d6fc8..e7765953307f 100644
@@ -816,7 +816,7 @@ static int vdpa_dev_net_mq_config_fill(struct vdpa_device *vdev,
 static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *msg)
 {
        struct virtio_net_config config = {};
-       u64 features_device, features_driver;
+       u64 features_device;
        u16 val_u16;
 
        vdev->config->get_config(vdev, 0, &config, sizeof(config));
@@ -833,11 +833,6 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms
        if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, val_u16))
                return -EMSGSIZE;
 
-       features_driver = vdev->config->get_driver_features(vdev);
-       if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_NEGOTIATED_FEATURES, features_driver,
-                             VDPA_ATTR_PAD))
-               return -EMSGSIZE;
-
        features_device = vdev->config->get_device_features(vdev);
 
        if (nla_put_u64_64bit(msg, VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES, features_device,
@@ -851,6 +846,8 @@ 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)
 {
+       u64 features_driver;
+       u8 status = 0;
        u32 device_id;
        void *hdr;
        int err;

drivers/vdpa/vdpa.c vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, · line 876

Quoted 6 lines
drivers/vdpa/vdpa.c +3 -0
@@ -874,6 +871,19 @@ vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid,
                goto msg_err;
        }
 
+       /* only read driver features after the feature negotiation is done */
+       if (vdev->config->get_status)
+               status = vdev->config->get_status(vdev);

get_status is mandatory, so I think we can remove this check.

Or if you want a strict check on the config operations, we need to do that in __vdpa_alloc_device().

Thanks

Quoted 16 lines
drivers/vdpa/vdpa.c +10 -1
+
+       if (status & VIRTIO_CONFIG_S_FEATURES_OK) {
+               features_driver = vdev->config->get_driver_features(vdev);
+               if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_NEGOTIATED_FEATURES, features_driver,
+                                     VDPA_ATTR_PAD)) {
+                       err = -EMSGSIZE;
+                       goto msg_err;
+               }
+       }
+
        switch (device_id) {
        case VIRTIO_ID_NET:
                err = vdpa_dev_net_config_fill(vdev, msg);
--

2.31.1

#6 lore raw

Re: [PATCH V2 RESEND 2/6] vDPA: only report driver features if FEATURES_OK is set

Quoted 47 lines · Jason Wang
Quoted 46 lines · Zhu Lingshan

This commit reports driver features to user space only after FEATURES_OK is features negotiation is done.

---
  drivers/vdpa/vdpa.c | 22 ++++++++++++++++------
  1 file changed, 16 insertions(+), 6 deletions(-)
drivers/vdpa/vdpa.c +3 -6
index 2035700d6fc8..e7765953307f 100644
@@ -816,7 +816,7 @@ static int vdpa_dev_net_mq_config_fill(struct vdpa_device *vdev,
  static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *msg)
  {
         struct virtio_net_config config = {};
-       u64 features_device, features_driver;
+       u64 features_device;
         u16 val_u16;
 
         vdev->config->get_config(vdev, 0, &config, sizeof(config));
@@ -833,11 +833,6 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms
         if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, val_u16))
                 return -EMSGSIZE;
 
-       features_driver = vdev->config->get_driver_features(vdev);
-       if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_NEGOTIATED_FEATURES, features_driver,
-                             VDPA_ATTR_PAD))
-               return -EMSGSIZE;
-
         features_device = vdev->config->get_device_features(vdev);
 
         if (nla_put_u64_64bit(msg, VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES, features_device,
@@ -851,6 +846,8 @@ 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)
  {
+       u64 features_driver;
+       u8 status = 0;
         u32 device_id;
         void *hdr;
         int err;
@@ -874,6 +871,19 @@ vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid,
                 goto msg_err;
         }
 
Quoted 7 lines

drivers/vdpa/vdpa.c vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, · line 876

Quoted 3 lines
drivers/vdpa/vdpa.c +3 -0
+       /* only read driver features after the feature negotiation is done */
+       if (vdev->config->get_status)
+               status = vdev->config->get_status(vdev);

get_status is mandatory, so I think we can remove this check.

Or if you want a strict check on the config operations, we need to do that in __vdpa_alloc_device().

I will remove it

Thanks!

Quoted 19 lines

Thanks

Quoted 16 lines
drivers/vdpa/vdpa.c +10 -1
+
+       if (status & VIRTIO_CONFIG_S_FEATURES_OK) {
+               features_driver = vdev->config->get_driver_features(vdev);
+               if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_NEGOTIATED_FEATURES, features_driver,
+                                     VDPA_ATTR_PAD)) {
+                       err = -EMSGSIZE;
+                       goto msg_err;
+               }
+       }
+
         switch (device_id) {
         case VIRTIO_ID_NET:
                 err = vdpa_dev_net_config_fill(vdev, msg);
--

2.31.1

#7 lore raw

PATCH RESEND v2 3/6 vDPA: check VIRTIO_NET_F_RSS for max_virtqueue_paris's presence

In reply to Zhu Lingshan

virtio 1.2 spec says:
max_virtqueue_pairs only exists if VIRTIO_NET_F_MQ or VIRTIO_NET_F_RSS is set.

So when reporint MQ to userspace, it should check both VIRTIO_NET_F_MQ and VIRTIO_NET_F_RSS.

unused parameter struct vdpa_device *vdev is removed

---
 drivers/vdpa/vdpa.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/vdpa/vdpa.c +3 -3
index e7765953307f..829fd4cfc038 100644
@@ -800,13 +800,13 @@ 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, u64 features,
+static int vdpa_dev_net_mq_config_fill(struct sk_buff *msg, u64 features,
 				       const struct virtio_net_config *config)
 {
 	u16 val_u16;
 
-	if ((features & BIT_ULL(VIRTIO_NET_F_MQ)) == 0)
+	if ((features & BIT_ULL(VIRTIO_NET_F_MQ)) == 0 &&
+	    (features & BIT_ULL(VIRTIO_NET_F_RSS)) == 0)
 		return 0;
 
 	val_u16 = le16_to_cpu(config->max_virtqueue_pairs);
Signature · 1 line
2.31.1
Acked-by on v2 3/6
#8 lore raw

Re: [PATCH V2 RESEND 3/6] vDPA: check VIRTIO_NET_F_RSS for max_virtqueue_paris's presence

Quoted 11 lines · Zhu Lingshan

virtio 1.2 spec says:
max_virtqueue_pairs only exists if VIRTIO_NET_F_MQ or VIRTIO_NET_F_RSS is set.

So when reporint MQ to userspace, it should check both VIRTIO_NET_F_MQ and VIRTIO_NET_F_RSS.

unused parameter struct vdpa_device *vdev is removed

Quoted 28 lines
---
 drivers/vdpa/vdpa.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/vdpa/vdpa.c +3 -4
index e7765953307f..829fd4cfc038 100644
@@ -800,13 +800,13 @@ 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, u64 features,
+static int vdpa_dev_net_mq_config_fill(struct sk_buff *msg, u64 features,
                                       const struct virtio_net_config *config)
 {
        u16 val_u16;
 
-       if ((features & BIT_ULL(VIRTIO_NET_F_MQ)) == 0)
+       if ((features & BIT_ULL(VIRTIO_NET_F_MQ)) == 0 &&
+           (features & BIT_ULL(VIRTIO_NET_F_RSS)) == 0)
                return 0;
 
        val_u16 = le16_to_cpu(config->max_virtqueue_pairs);
--

2.31.1

#9 lore raw

PATCH RESEND v2 4/6 vDPA: check virtio device features to detect MQ

In reply to Zhu Lingshan

vdpa_dev_net_mq_config_fill() should checks device features for MQ than driver features.

---
 drivers/vdpa/vdpa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vdpa/vdpa.c +1 -1
index 829fd4cfc038..84a0c3877d7c 100644
@@ -839,7 +839,7 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms
 			      VDPA_ATTR_PAD))
 		return -EMSGSIZE;
 
-	return vdpa_dev_net_mq_config_fill(vdev, msg, features_driver, &config);
+	return vdpa_dev_net_mq_config_fill(msg, features_device, &config);
 }
 
 static int
Signature · 1 line
2.31.1
Acked-by on v2 4/6
#10 lore raw

Re: [PATCH V2 RESEND 4/6] vDPA: check virtio device features to detect MQ

Quoted 5 lines · Zhu Lingshan

vdpa_dev_net_mq_config_fill() should checks device features for MQ than driver features.

Quoted 18 lines
---
 drivers/vdpa/vdpa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vdpa/vdpa.c +1 -2
index 829fd4cfc038..84a0c3877d7c 100644
@@ -839,7 +839,7 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms
                              VDPA_ATTR_PAD))
                return -EMSGSIZE;
 
-       return vdpa_dev_net_mq_config_fill(vdev, msg, features_driver, &config);
+       return vdpa_dev_net_mq_config_fill(msg, features_device, &config);
 }
 
 static int
--
Quoted 2 lines

2.31.1

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

#11 lore raw

PATCH RESEND v2 5/6 vDPA: fix spars cast warning in vdpa_dev_net_mq_config_fill

In reply to Zhu Lingshan

This commit fixes spars warnings: cast to restricted __le16 in function vdpa_dev_net_mq_config_fill()

---
 drivers/vdpa/vdpa.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa.c +2 -1
index 84a0c3877d7c..fa7f65279f79 100644
@@ -809,7 +809,8 @@ static int vdpa_dev_net_mq_config_fill(struct sk_buff *msg, u64 features,
 	    (features & BIT_ULL(VIRTIO_NET_F_RSS)) == 0)
 		return 0;
 
-	val_u16 = le16_to_cpu(config->max_virtqueue_pairs);
+	val_u16 = __virtio16_to_cpu(true, config->max_virtqueue_pairs);
+
 	return nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MAX_VQP, val_u16);
 }
 
Signature · 1 line
2.31.1
Acked-by on v2 5/6
#12 lore raw

Re: [PATCH V2 RESEND 5/6] vDPA: fix spars cast warning in vdpa_dev_net_mq_config_fill

Quoted 5 lines · Zhu Lingshan

This commit fixes spars warnings: cast to restricted __le16 in function vdpa_dev_net_mq_config_fill()

Quoted 21 lines
---
 drivers/vdpa/vdpa.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa.c +2 -2
index 84a0c3877d7c..fa7f65279f79 100644
@@ -809,7 +809,8 @@ static int vdpa_dev_net_mq_config_fill(struct sk_buff *msg, u64 features,
            (features & BIT_ULL(VIRTIO_NET_F_RSS)) == 0)
                return 0;
 
-       val_u16 = le16_to_cpu(config->max_virtqueue_pairs);
+       val_u16 = __virtio16_to_cpu(true, config->max_virtqueue_pairs);
+
        return nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MAX_VQP, val_u16);
 }
 
--

2.31.1

#13 lore raw

PATCH RESEND v2 6/6 vDPA: conditionally read MTU and MAC in dev cfg space

In reply to Zhu Lingshan

The spec says:
mtu only exists if VIRTIO_NET_F_MTU is set The mac address field always exists (though is only valid if VIRTIO_NET_F_MAC is set)

So vdpa_dev_net_config_fill() should read MTU and MAC conditionally on the feature bits.

---
 drivers/vdpa/vdpa.c | 37 +++++++++++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 8 deletions(-)
drivers/vdpa/vdpa.c +29 -8
index fa7f65279f79..3d2cf8caff7c 100644
@@ -814,6 +814,29 @@ static int vdpa_dev_net_mq_config_fill(struct sk_buff *msg, u64 features,
 	return nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MAX_VQP, val_u16);
 }
 
+static int vdpa_dev_net_mtu_config_fill(struct sk_buff *msg, u64 features,
+					const struct virtio_net_config *config)
+{
+	u16 val_u16;
+
+	if ((features & BIT_ULL(VIRTIO_NET_F_MTU)) == 0)
+		return 0;
+
+	val_u16 = __virtio16_to_cpu(true, config->mtu);
+
+	return nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, val_u16);
+}
+
+static int vdpa_dev_net_mac_config_fill(struct sk_buff *msg, u64 features,
+					const struct virtio_net_config *config)
+{
+	if ((features & BIT_ULL(VIRTIO_NET_F_MAC)) == 0)
+		return 0;
+
+	return  nla_put(msg, VDPA_ATTR_DEV_NET_CFG_MACADDR,
+			sizeof(config->mac), config->mac);
+}
+
 static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *msg)
 {
 	struct virtio_net_config config = {};
@@ -822,24 +845,22 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms
 
 	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;
-
 	val_u16 = __virtio16_to_cpu(true, config.status);
 	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_STATUS, val_u16))
 		return -EMSGSIZE;
 
-	val_u16 = __virtio16_to_cpu(true, config.mtu);
-	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, val_u16))
-		return -EMSGSIZE;
-
 	features_device = vdev->config->get_device_features(vdev);
 
 	if (nla_put_u64_64bit(msg, VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES, features_device,
 			      VDPA_ATTR_PAD))
 		return -EMSGSIZE;
 
+	if (vdpa_dev_net_mtu_config_fill(msg, features_device, &config))
+		return -EMSGSIZE;
+
+	if (vdpa_dev_net_mac_config_fill(msg, features_device, &config))
+		return -EMSGSIZE;
+
 	return vdpa_dev_net_mq_config_fill(msg, features_device, &config);
 }
 
Signature · 1 line
2.31.1