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(-)
--
2.31.1
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
Signed-off-by: Zhu Lingshan <redacted>
---
drivers/vdpa/vdpa.c | 17 ++++++++++++-----
include/uapi/linux/vdpa.h | 4 ++++
2 files changed, 16 insertions(+), 5 deletions(-)
@@ -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,};
This commit reports driver features to user space
only after FEATURES_OK is features negotiation is done.
Signed-off-by: Zhu Lingshan <redacted>
---
drivers/vdpa/vdpa.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
@@ -874,6 +871,19 @@ vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid,gotomsg_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;+gotomsg_err;+}+}+switch(device_id){caseVIRTIO_ID_NET:err=vdpa_dev_net_config_fill(vdev,msg);
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
Signed-off-by: Zhu Lingshan <redacted>
---
drivers/vdpa/vdpa.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
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.
Signed-off-by: Zhu Lingshan <redacted>
Acked-by: Jason Wang <redacted>
---
drivers/vdpa/vdpa.c | 37 +++++++++++++++++++++++++++++--------
1 file changed, 29 insertions(+), 8 deletions(-)
From: Jason Wang <hidden> Date: 2022-09-27 04:36:28
On Tue, Sep 27, 2022 at 11:09 AM Zhu Lingshan [off-list ref] wrote:
quoted hunk
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
Signed-off-by: Zhu Lingshan <redacted>
---
drivers/vdpa/vdpa.c | 17 ++++++++++++-----
include/uapi/linux/vdpa.h | 4 ++++
2 files changed, 16 insertions(+), 5 deletions(-)
@@ -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,};--
From: Jason Wang <hidden> Date: 2022-09-27 04:37:51
On Tue, Sep 27, 2022 at 11:09 AM Zhu Lingshan [off-list ref] wrote:
quoted hunk
This commit reports driver features to user space
only after FEATURES_OK is features negotiation is done.
Signed-off-by: Zhu Lingshan <redacted>
---
drivers/vdpa/vdpa.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
@@ -874,6 +871,19 @@ vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid,gotomsg_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
From: Jason Wang <hidden> Date: 2022-09-27 04:38:21
On Tue, Sep 27, 2022 at 11:09 AM Zhu Lingshan [off-list ref] wrote:
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
Signed-off-by: Zhu Lingshan <redacted>
On Tue, Sep 27, 2022 at 11:09 AM Zhu Lingshan [off-list ref] wrote:
quoted
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
Signed-off-by: Zhu Lingshan <redacted>
---
drivers/vdpa/vdpa.c | 17 ++++++++++++-----
include/uapi/linux/vdpa.h | 4 ++++
2 files changed, 16 insertions(+), 5 deletions(-)
@@ -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?
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
@@ -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,};--
On Tue, Sep 27, 2022 at 11:09 AM Zhu Lingshan [off-list ref] wrote:
quoted
This commit reports driver features to user space
only after FEATURES_OK is features negotiation is done.
Signed-off-by: Zhu Lingshan <redacted>
---
drivers/vdpa/vdpa.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
@@ -874,6 +871,19 @@ vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid,gotomsg_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().