Show statistics for a vdpa device
v7 cover Show statistics for a vdpa device
The following four patch series adds support to read vendor statistics for a vdpa device.
The first patch is just a cleanup fix.
The second patch lays the ground to allow an upstream driver to provide statistics in the form of an attribute name/attribute value pairs.
The third patch makes changes to locking scheme to use readers/writers semaphore instead if mutex.
The fourth patch implements this for mlx5_vdpa which gives received descriptors and completed descriptors information for all the virtqueues.
The fifth patch changes reslock mutex to readers/writers semaphore to achieve the same goal as done in vdpa core.
Eli Cohen (5):
vdpa: Fix error logic in vdpa_nl_cmd_dev_get_doit
vdpa: Add support for querying vendor statistics net/vdpa: Use readers/writers semaphore instead of mutex vdpa/mlx5: Add support for reading descriptor statistics vdpa/mlx5: Use readers/writers semaphore instead of mutex
v6 -> v7:
1. Add a new mlx5 patch to modify reslock from a mutex to rw_semaphore
2. Clean old comments
3. Move VDPA_ATTR_DEV_NET_CFG_MAX_VQP attribute insertion from mlx5 to vdpa core.
drivers/vdpa/mlx5/core/mlx5_vdpa.h | 2 + drivers/vdpa/mlx5/net/mlx5_vnet.c | 186 ++++++++++++++++++++--- drivers/vdpa/vdpa.c | 229 +++++++++++++++++++++++++---- include/linux/mlx5/mlx5_ifc.h | 1 + include/linux/mlx5/mlx5_ifc_vdpa.h | 39 +++++ include/linux/vdpa.h | 3 + include/uapi/linux/vdpa.h | 6 + 7 files changed, 414 insertions(+), 52 deletions(-)
Signature · 1 line
2.35.1
PATCH v7 1/5 vdpa: Fix error logic in vdpa_nl_cmd_dev_get_doit
In vdpa_nl_cmd_dev_get_doit(), if the call to genlmsg_reply() fails we must not call nlmsg_free() since this is done inside genlmsg_reply().
Fix it.
--- drivers/vdpa/vdpa.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/vdpa/vdpa.c +9 -4
@@ -756,14 +756,19 @@ static int vdpa_nl_cmd_dev_get_doit(struct sk_buff *skb, struct genl_info *info) goto mdev_err; } err =vdpa_dev_fill (vdev, msg, info->snd_portid, info->snd_seq,0 , info->extack); -if (!err) - err =genlmsg_reply (msg, info); +if (err) + goto mdev_err; + + err =genlmsg_reply (msg, info); +put_device (dev); +mutex_unlock (&vdpa_dev_mutex); +return err; + mdev_err:put_device (dev); err:mutex_unlock (&vdpa_dev_mutex); -if (err) -nlmsg_free (msg); +nlmsg_free (msg);return err; }
Signature · 1 line
2.35.1
PATCH v7 2/5 vdpa: Add support for querying vendor statistics
In reply to Eli CohenAllows to read vendor statistics of a vdpa device. The specific statistics data are received from the upstream driver in the form of an (attribute name, attribute value) pairs.
An example of statistics for mlx5_vdpa device are:
received_desc - number of descriptors received by the virtqueue completed_desc - number of descriptors completed by the virtqueue
A descriptor using indirect buffers is still counted as 1. In addition, N chained descriptors are counted correctly N times as one would expect.
A new callback was added to vdpa_config_ops which provides the means for the vdpa driver to return statistics results.
The interface allows for reading all the supported virtqueues, including the control virtqueue if it exists.
Below are some examples taken from mlx5_vdpa which are introduced in the following patch:
1. Read statistics for the virtqueue at index 1
$ vdpa dev vstats show vdpa-a qidx 1 vdpa-a: queue_type tx queue_index 1 received_desc 3844836 completed_desc 3844836
2. Read statistics for the virtqueue at index 32
$ vdpa dev vstats show vdpa-a qidx 32 vdpa-a: queue_type control_vq queue_index 32 received_desc 62 completed_desc 62
3. Read statisitics for the virtqueue at index 0 with json output
$ vdpa -j dev vstats show vdpa-a qidx 0
{"vstats":{"vdpa-a":{
"queue_type":"rx","queue_index":0,"name":"received_desc","value":417776,\
"name":"completed_desc","value":417548}}}4. Read statistics for the virtqueue at index 0 with preety json output
$ vdpa -jp dev vstats show vdpa-a qidx 0
{
"vstats": {
"vdpa-a": { "queue_type": "rx",
"queue_index": 0,
"name": "received_desc",
"value": 417776,
"name": "completed_desc",
"value": 417548
}
}
}--- drivers/vdpa/vdpa.c | 160 ++++++++++++++++++++++++++++++++++++++ include/linux/vdpa.h | 3 + include/uapi/linux/vdpa.h | 6 ++ 3 files changed, 169 insertions(+)
drivers/vdpa/vdpa.c +160 -0
@@ -914,6 +914,106 @@ vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid,return err; } +static int vdpa_fill_stats_rec (struct vdpa_device *vdev,struct sk_buff *msg, +struct genl_info *info,u32 index) +{ +struct virtio_net_config config = {}; +u64 features; +u16 max_vqp; +u8 status; +int err; + + status = vdev->config->get_status (vdev); +if (!(status &VIRTIO_CONFIG_S_FEATURES_OK )) { +NL_SET_ERR_MSG_MOD (info->extack,"feature negotiation not complete" ); +return -EAGAIN ; + } +vdpa_get_config (vdev,0 , &config,sizeof (config)); + + max_vqp =le16_to_cpu (config.max_virtqueue_pairs); +if (nla_put_u16 (msg,VDPA_ATTR_DEV_NET_CFG_MAX_VQP , max_vqp)) +return -EMSGSIZE ; + + features = vdev->config->get_driver_features (vdev); +if (nla_put_u64_64bit (msg,VDPA_ATTR_DEV_NEGOTIATED_FEATURES , + features,VDPA_ATTR_PAD )) +return -EMSGSIZE ; + +if (nla_put_u32 (msg,VDPA_ATTR_DEV_QUEUE_INDEX , index)) +return -EMSGSIZE ; + + err = vdev->config->get_vendor_vq_stats (vdev, index, msg, info->extack); +if (err) +return err; + +return 0 ; +} + +static int vendor_stats_fill (struct vdpa_device *vdev,struct sk_buff *msg, +struct genl_info *info,u32 index) +{ +int err; + +if (!vdev->config->get_vendor_vq_stats) +return -EOPNOTSUPP ; + + err =vdpa_fill_stats_rec (vdev, msg, info, index); +if (err) +return err; + +return 0 ; +} + +static int vdpa_dev_vendor_stats_fill (struct vdpa_device *vdev, +struct sk_buff *msg, +struct genl_info *info,u32 index) +{ +u32 device_id; +void *hdr; +int err; +u32 portid = info->snd_portid; +u32 seq = info->snd_seq; +u32 flags =0 ; + + hdr =genlmsg_put (msg, portid, seq, &vdpa_nl_family, flags, +VDPA_CMD_DEV_VSTATS_GET ); +if (!hdr) +return -EMSGSIZE ; + +if (nla_put_string (msg,VDPA_ATTR_DEV_NAME ,dev_name (&vdev->dev))) { + err = -EMSGSIZE ; + goto undo_msg; + } + + device_id = vdev->config->get_device_id (vdev); +if (nla_put_u32 (msg,VDPA_ATTR_DEV_ID , device_id)) { + err = -EMSGSIZE ; + goto undo_msg; + } + +switch (device_id) { +case VIRTIO_ID_NET : +if (index >VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX ) { +NL_SET_ERR_MSG_MOD (info->extack,"queue index excceeds max value" ); + err = -ERANGE ; +break ; + } + + err =vendor_stats_fill (vdev, msg, info, index); +break ; +default : + err = -EOPNOTSUPP ; +break ; + } +genlmsg_end (msg, hdr); + +return err; + +undo_msg: +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;
@@ -995,6 +1095,60 @@ vdpa_nl_cmd_dev_config_get_dumpit(struct sk_buff *msg, struct netlink_callback *return msg->len; } +static int vdpa_nl_cmd_dev_stats_get_doit (struct sk_buff *skb, +struct genl_info *info) +{ +struct vdpa_device *vdev; +struct sk_buff *msg; +const char *devname; +struct device *dev; +u32 index; +int err; + +if (!info->attrs[VDPA_ATTR_DEV_NAME ]) +return -EINVAL ; + +if (!info->attrs[VDPA_ATTR_DEV_QUEUE_INDEX ]) +return -EINVAL ; + + devname =nla_data (info->attrs[VDPA_ATTR_DEV_NAME ]); + msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL ); +if (!msg) +return -ENOMEM ; + + index =nla_get_u32 (info->attrs[VDPA_ATTR_DEV_QUEUE_INDEX ]); +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_vendor_stats_fill (vdev, msg, info, index); +if (err) + goto mdev_err; + + err =genlmsg_reply (msg, info); + +put_device (dev); +mutex_unlock (&vdpa_dev_mutex); + +return err; + +mdev_err: +put_device (dev); +dev_err: +nlmsg_free (msg); +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 },
@@ -1035,6 +1189,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_VSTATS_GET, + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit = vdpa_nl_cmd_dev_stats_get_doit, + .flags = GENL_ADMIN_PERM, + }, };static struct genl_family vdpa_nl_family__ro_after_init = {
include/linux/vdpa.h +3 -0
@@ -276,6 +276,9 @@ struct vdpa_config_ops { const struct vdpa_vq_state *state);int (*get_vq_state)(struct vdpa_device *vdev,u16 idx,struct vdpa_vq_state *state); +int (*get_vendor_vq_stats)(struct vdpa_device *vdev,u16 idx, +struct sk_buff *msg, +struct netlink_ext_ack *extack);struct vdpa_notification_area (*get_vq_notification)(struct vdpa_device *vdev,u16 idx);/* vq irq is not expected to be changed once DRIVER_OK is set */
include/uapi/linux/vdpa.h +6 -0
@@ -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_VSTATS_GET, }; enum vdpa_attr {
@@ -46,6 +47,11 @@ enum vdpa_attr {VDPA_ATTR_DEV_NEGOTIATED_FEATURES ,/* u64 */ VDPA_ATTR_DEV_MGMTDEV_MAX_VQS ,/* u32 */ 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 */ +/* new attributes must be added above here */ VDPA_ATTR_MAX, };
Signature · 1 line
2.35.1
Re: [PATCH v7 2/5] vdpa: Add support for querying vendor statistics
Quoted 68 lines · Eli Cohen
Allows to read vendor statistics of a vdpa device. The specific statistics data are received from the upstream driver in the form of an (attribute name, attribute value) pairs.
An example of statistics for
mlx5_vdpadevice are:
received_desc- number of descriptors received by the virtqueuecompleted_desc- number of descriptors completed by the virtqueueA descriptor using indirect buffers is still counted as 1. In addition, N chained descriptors are counted correctly N times as one would expect.
A new callback was added to
vdpa_config_opswhich provides the means for the vdpa driver to return statistics results.The interface allows for reading all the supported virtqueues, including the control virtqueue if it exists.
Below are some examples taken from
mlx5_vdpawhich are introduced in the following patch:1. Read statistics for the virtqueue at index 1
$ vdpa dev vstats show vdpa-a qidx 1 vdpa-a: queue_type tx queue_index 1 received_desc 3844836 completed_desc 38448362. Read statistics for the virtqueue at index 32
$ vdpa dev vstats show vdpa-a qidx 32 vdpa-a: queue_type control_vq queue_index 32 received_desc 62 completed_desc 623. Read statisitics for the virtqueue at index 0 with json output
$ vdpa -j dev vstats show vdpa-a qidx 0 {"vstats":{"vdpa-a":{ "queue_type":"rx","queue_index":0,"name":"received_desc","value":417776,\ "name":"completed_desc","value":417548}}}4. Read statistics for the virtqueue at index 0 with preety json output
$ vdpa -jp dev vstats show vdpa-a qidx 0 { "vstats": { "vdpa-a": {"queue_type": "rx", "queue_index": 0, "name": "received_desc", "value": 417776, "name": "completed_desc", "value": 417548 } } }Signed-off-by Eli Cohen <[email protected]>--- drivers/vdpa/vdpa.c | 160 ++++++++++++++++++++++++++++++++++++++ include/linux/vdpa.h | 3 + include/uapi/linux/vdpa.h | 6 ++ 3 files changed, 169 insertions(+)drivers/vdpa/vdpa.c +0
-0@@ -914,6 +914,106 @@ vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid,return err; }
drivers/vdpa/vdpa.c vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, · line 925
Quoted 10 lines
drivers/vdpa/vdpa.c +9
-0+static int vdpa_fill_stats_rec (struct vdpa_device *vdev,struct sk_buff *msg, +struct genl_info *info,u32 index) +{ +struct virtio_net_config config = {}; +u64 features; +u16 max_vqp; +u8 status; +int err; +
This entire function should perhaps need to take cf_mutex (worth converting to rwsem as well) to guard against concurrent modification via .set_status() or .set_config() from the upper stack. Similar to vdpa_dev_config_fill().
drivers/vdpa/vdpa.c vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, · line 931
Quoted 6 lines
drivers/vdpa/vdpa.c +6
-0+ status = vdev->config->get_status (vdev); +if (!(status &VIRTIO_CONFIG_S_FEATURES_OK )) { +NL_SET_ERR_MSG_MOD (info->extack,"feature negotiation not complete" ); +return -EAGAIN ; + } +vdpa_get_config (vdev,0 , &config,sizeof (config));
This should use vdpa_get_config_unlocked() without lock.
Regards,
-Siwei
Quoted 190 lines
drivers/vdpa/vdpa.c +145
-0+ + max_vqp =le16_to_cpu (config.max_virtqueue_pairs); +if (nla_put_u16 (msg,VDPA_ATTR_DEV_NET_CFG_MAX_VQP , max_vqp)) +return -EMSGSIZE ; + + features = vdev->config->get_driver_features (vdev); +if (nla_put_u64_64bit (msg,VDPA_ATTR_DEV_NEGOTIATED_FEATURES , + features,VDPA_ATTR_PAD )) +return -EMSGSIZE ; + +if (nla_put_u32 (msg,VDPA_ATTR_DEV_QUEUE_INDEX , index)) +return -EMSGSIZE ; + + err = vdev->config->get_vendor_vq_stats (vdev, index, msg, info->extack); +if (err) +return err; + +return 0 ; +} + +static int vendor_stats_fill (struct vdpa_device *vdev,struct sk_buff *msg, +struct genl_info *info,u32 index) +{ +int err; + +if (!vdev->config->get_vendor_vq_stats) +return -EOPNOTSUPP ; + + err =vdpa_fill_stats_rec (vdev, msg, info, index); +if (err) +return err; + +return 0 ; +} + +static int vdpa_dev_vendor_stats_fill (struct vdpa_device *vdev, +struct sk_buff *msg, +struct genl_info *info,u32 index) +{ +u32 device_id; +void *hdr; +int err; +u32 portid = info->snd_portid; +u32 seq = info->snd_seq; +u32 flags =0 ; + + hdr =genlmsg_put (msg, portid, seq, &vdpa_nl_family, flags, +VDPA_CMD_DEV_VSTATS_GET ); +if (!hdr) +return -EMSGSIZE ; + +if (nla_put_string (msg,VDPA_ATTR_DEV_NAME ,dev_name (&vdev->dev))) { + err = -EMSGSIZE ; + goto undo_msg; + } + + device_id = vdev->config->get_device_id (vdev); +if (nla_put_u32 (msg,VDPA_ATTR_DEV_ID , device_id)) { + err = -EMSGSIZE ; + goto undo_msg; + } + +switch (device_id) { +case VIRTIO_ID_NET : +if (index >VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX ) { +NL_SET_ERR_MSG_MOD (info->extack,"queue index excceeds max value" ); + err = -ERANGE ; +break ; + } + + err =vendor_stats_fill (vdev, msg, info, index); +break ; +default : + err = -EOPNOTSUPP ; +break ; + } +genlmsg_end (msg, hdr); + +return err; + +undo_msg: +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;@@ -995,6 +1095,60 @@ vdpa_nl_cmd_dev_config_get_dumpit(struct sk_buff *msg, struct netlink_callback *return msg->len; } +static int vdpa_nl_cmd_dev_stats_get_doit (struct sk_buff *skb, +struct genl_info *info) +{ +struct vdpa_device *vdev; +struct sk_buff *msg; +const char *devname; +struct device *dev; +u32 index; +int err; + +if (!info->attrs[VDPA_ATTR_DEV_NAME ]) +return -EINVAL ; + +if (!info->attrs[VDPA_ATTR_DEV_QUEUE_INDEX ]) +return -EINVAL ; + + devname =nla_data (info->attrs[VDPA_ATTR_DEV_NAME ]); + msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL ); +if (!msg) +return -ENOMEM ; + + index =nla_get_u32 (info->attrs[VDPA_ATTR_DEV_QUEUE_INDEX ]); +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_vendor_stats_fill (vdev, msg, info, index); +if (err) + goto mdev_err; + + err =genlmsg_reply (msg, info); + +put_device (dev); +mutex_unlock (&vdpa_dev_mutex); + +return err; + +mdev_err: +put_device (dev); +dev_err: +nlmsg_free (msg); +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 },@@ -1035,6 +1189,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_VSTATS_GET, + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit = vdpa_nl_cmd_dev_stats_get_doit, + .flags = GENL_ADMIN_PERM, + }, };static struct genl_family vdpa_nl_family__ro_after_init = {include/linux/vdpa.h +3
-0@@ -276,6 +276,9 @@ struct vdpa_config_ops { const struct vdpa_vq_state *state);int (*get_vq_state)(struct vdpa_device *vdev,u16 idx,struct vdpa_vq_state *state); +int (*get_vendor_vq_stats)(struct vdpa_device *vdev,u16 idx, +struct sk_buff *msg, +struct netlink_ext_ack *extack);struct vdpa_notification_area (*get_vq_notification)(struct vdpa_device *vdev,u16 idx);/* vq irq is not expected to be changed once DRIVER_OK is set */ include/uapi/linux/vdpa.h +1
-0@@ -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_VSTATS_GET, }; enum vdpa_attr {@@ -46,6 +47,11 @@ enum vdpa_attr { VDPA_ATTR_DEV_NEGOTIATED_FEATURES, /* u64 */
include/uapi/linux/vdpa.h enum vdpa_attr { · line 57
Quoted 10 lines
include/uapi/linux/vdpa.h +5
-0VDPA_ATTR_DEV_MGMTDEV_MAX_VQS ,/* u32 */ 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 */ +/* new attributes must be added above here */ VDPA_ATTR_MAX, };
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RE: [PATCH v7 2/5] vdpa: Add support for querying vendor statistics
Quoted 78 lines
From: Si-Wei Liu <[email protected]>
Sent: Wednesday, May 18, 2022 4:03 AM
To: Eli Cohen <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [PATCH v7 2/5] vdpa: Add support for querying vendor statisticsQuoted 69 lines · Eli Cohen
Allows to read vendor statistics of a vdpa device. The specific statistics data are received from the upstream driver in the form of an (attribute name, attribute value) pairs.
An example of statistics for
mlx5_vdpadevice are:
received_desc- number of descriptors received by the virtqueuecompleted_desc- number of descriptors completed by the virtqueueA descriptor using indirect buffers is still counted as 1. In addition, N chained descriptors are counted correctly N times as one would expect.
A new callback was added to
vdpa_config_opswhich provides the means for the vdpa driver to return statistics results.The interface allows for reading all the supported virtqueues, including the control virtqueue if it exists.
Below are some examples taken from
mlx5_vdpawhich are introduced in the following patch:1. Read statistics for the virtqueue at index 1
$ vdpa dev vstats show vdpa-a qidx 1 vdpa-a: queue_type tx queue_index 1 received_desc 3844836 completed_desc 38448362. Read statistics for the virtqueue at index 32
$ vdpa dev vstats show vdpa-a qidx 32 vdpa-a: queue_type control_vq queue_index 32 received_desc 62 completed_desc 623. Read statisitics for the virtqueue at index 0 with json output
$ vdpa -j dev vstats show vdpa-a qidx 0 {"vstats":{"vdpa-a":{ "queue_type":"rx","queue_index":0,"name":"received_desc","value":417776,\ "name":"completed_desc","value":417548}}}4. Read statistics for the virtqueue at index 0 with preety json output
$ vdpa -jp dev vstats show vdpa-a qidx 0 { "vstats": { "vdpa-a": {"queue_type": "rx", "queue_index": 0, "name": "received_desc", "value": 417776, "name": "completed_desc", "value": 417548 } } }Signed-off-by Eli Cohen <[email protected]>--- drivers/vdpa/vdpa.c | 160 ++++++++++++++++++++++++++++++++++++++ include/linux/vdpa.h | 3 + include/uapi/linux/vdpa.h | 6 ++ 3 files changed, 169 insertions(+)drivers/vdpa/vdpa.c +0
-0@@ -914,6 +914,106 @@ vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid,return err; }
Quoted 14 lines
drivers/vdpa/vdpa.c vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, · line 925
Quoted 9 lines
drivers/vdpa/vdpa.c +9
-0+static int vdpa_fill_stats_rec (struct vdpa_device *vdev,struct sk_buff *msg, +struct genl_info *info,u32 index) +{ +struct virtio_net_config config = {}; +u64 features; +u16 max_vqp; +u8 status; +int err; +This entire function should perhaps need to take
cf_mutex(worth converting to rwsem as well) to guard against concurrent modification via .set_status() or .set_config() from the upper stack. Similar tovdpa_dev_config_fill().
Right.
Quoted 211 lines
drivers/vdpa/vdpa.c vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, · line 931
Quoted 6 lines
drivers/vdpa/vdpa.c +6
-0+ status = vdev->config->get_status (vdev); +if (!(status &VIRTIO_CONFIG_S_FEATURES_OK )) { +NL_SET_ERR_MSG_MOD (info->extack,"feature negotiation not complete" ); +return -EAGAIN ; + } +vdpa_get_config (vdev,0 , &config,sizeof (config));This should use
vdpa_get_config_unlocked()without lock.Regards,
-SiweiQuoted 200 lines
drivers/vdpa/vdpa.c +145
-0+ + max_vqp =le16_to_cpu (config.max_virtqueue_pairs); +if (nla_put_u16 (msg,VDPA_ATTR_DEV_NET_CFG_MAX_VQP , max_vqp)) +return -EMSGSIZE ; + + features = vdev->config->get_driver_features (vdev); +if (nla_put_u64_64bit (msg,VDPA_ATTR_DEV_NEGOTIATED_FEATURES , + features,VDPA_ATTR_PAD )) +return -EMSGSIZE ; + +if (nla_put_u32 (msg,VDPA_ATTR_DEV_QUEUE_INDEX , index)) +return -EMSGSIZE ; + + err = vdev->config->get_vendor_vq_stats (vdev, index, msg, info->extack); +if (err) +return err; + +return 0 ; +} + +static int vendor_stats_fill (struct vdpa_device *vdev,struct sk_buff *msg, +struct genl_info *info,u32 index) +{ +int err; + +if (!vdev->config->get_vendor_vq_stats) +return -EOPNOTSUPP ; + + err =vdpa_fill_stats_rec (vdev, msg, info, index); +if (err) +return err; + +return 0 ; +} + +static int vdpa_dev_vendor_stats_fill (struct vdpa_device *vdev, +struct sk_buff *msg, +struct genl_info *info,u32 index) +{ +u32 device_id; +void *hdr; +int err; +u32 portid = info->snd_portid; +u32 seq = info->snd_seq; +u32 flags =0 ; + + hdr =genlmsg_put (msg, portid, seq, &vdpa_nl_family, flags, +VDPA_CMD_DEV_VSTATS_GET ); +if (!hdr) +return -EMSGSIZE ; + +if (nla_put_string (msg,VDPA_ATTR_DEV_NAME ,dev_name (&vdev->dev))) { + err = -EMSGSIZE ; + goto undo_msg; + } + + device_id = vdev->config->get_device_id (vdev); +if (nla_put_u32 (msg,VDPA_ATTR_DEV_ID , device_id)) { + err = -EMSGSIZE ; + goto undo_msg; + } + +switch (device_id) { +case VIRTIO_ID_NET : +if (index >VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX ) { +NL_SET_ERR_MSG_MOD (info->extack,"queue index excceeds max value" ); + err = -ERANGE ; +break ; + } + + err =vendor_stats_fill (vdev, msg, info, index); +break ; +default : + err = -EOPNOTSUPP ; +break ; + } +genlmsg_end (msg, hdr); + +return err; + +undo_msg: +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;@@ -995,6 +1095,60 @@ vdpa_nl_cmd_dev_config_get_dumpit(struct sk_buff *msg, struct netlink_callback *return msg->len; } +static int vdpa_nl_cmd_dev_stats_get_doit (struct sk_buff *skb, +struct genl_info *info) +{ +struct vdpa_device *vdev; +struct sk_buff *msg; +const char *devname; +struct device *dev; +u32 index; +int err; + +if (!info->attrs[VDPA_ATTR_DEV_NAME ]) +return -EINVAL ; + +if (!info->attrs[VDPA_ATTR_DEV_QUEUE_INDEX ]) +return -EINVAL ; + + devname =nla_data (info->attrs[VDPA_ATTR_DEV_NAME ]); + msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL ); +if (!msg) +return -ENOMEM ; + + index =nla_get_u32 (info->attrs[VDPA_ATTR_DEV_QUEUE_INDEX ]); +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_vendor_stats_fill (vdev, msg, info, index); +if (err) + goto mdev_err; + + err =genlmsg_reply (msg, info); + +put_device (dev); +mutex_unlock (&vdpa_dev_mutex); + +return err; + +mdev_err: +put_device (dev); +dev_err: +nlmsg_free (msg); +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 },@@ -1035,6 +1189,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_VSTATS_GET, + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit = vdpa_nl_cmd_dev_stats_get_doit, + .flags = GENL_ADMIN_PERM, + }, };static struct genl_family vdpa_nl_family__ro_after_init = {include/linux/vdpa.h +3
-0@@ -276,6 +276,9 @@ struct vdpa_config_ops { const struct vdpa_vq_state *state);int (*get_vq_state)(struct vdpa_device *vdev,u16 idx,struct vdpa_vq_state *state); +int (*get_vendor_vq_stats)(struct vdpa_device *vdev,u16 idx, +struct sk_buff *msg, +struct netlink_ext_ack *extack);struct vdpa_notification_area (*get_vq_notification)(struct vdpa_device *vdev,u16 idx);/* vq irq is not expected to be changed once DRIVER_OK is set */ include/uapi/linux/vdpa.h +6
-0@@ -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_VSTATS_GET, }; enum vdpa_attr {@@ -46,6 +47,11 @@ enum vdpa_attr {VDPA_ATTR_DEV_NEGOTIATED_FEATURES ,/* u64 */ VDPA_ATTR_DEV_MGMTDEV_MAX_VQS ,/* u32 */ 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 */ +/* new attributes must be added above here */ VDPA_ATTR_MAX, };
PATCH v7 3/5 net/vdpa: Use readers/writers semaphore instead of mutex
In reply to Eli CohenUse rw_semaphore instead of mutex to control access to vdpa devices. This can be especially beneficial in case processes poll on statistics information.
--- drivers/vdpa/vdpa.c | 64 ++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 32 deletions(-)
drivers/vdpa/vdpa.c +32 -32
@@ -18,7 +18,7 @@static LIST_HEAD (mdev_head);/* A global mutex that protects vdpa management device and device level operations. */ -static DEFINE_MUTEX (vdpa_dev_mutex); +static DECLARE_RWSEM (vdpa_dev_lock);static DEFINE_IDA (vdpa_index_ida);void vdpa_set_status (struct vdpa_device *vdev,u8 status)
@@ -238,7 +238,7 @@ static int __vdpa_register_device(struct vdpa_device *vdev, u32 nvqs) vdev->nvqs = nvqs; -lockdep_assert_held (&vdpa_dev_mutex); +lockdep_assert_held (&vdpa_dev_lock); dev =bus_find_device (&vdpa_bus,NULL ,dev_name (&vdev->dev), vdpa_name_match);if (dev) {put_device (dev);
@@ -278,9 +278,9 @@ int vdpa_register_device(struct vdpa_device *vdev, u32 nvqs) {int err; -mutex_lock (&vdpa_dev_mutex); +down_write (&vdpa_dev_lock); err =__vdpa_register_device (vdev, nvqs); -mutex_unlock (&vdpa_dev_mutex); +up_write (&vdpa_dev_lock);return err; }EXPORT_SYMBOL_GPL (vdpa_register_device);
@@ -293,7 +293,7 @@ EXPORT_SYMBOL_GPL(vdpa_register_device);*/ void _vdpa_unregister_device (struct vdpa_device *vdev) { -lockdep_assert_held (&vdpa_dev_mutex); +lockdep_assert_held (&vdpa_dev_lock);WARN_ON (!vdev->mdev);device_unregister (&vdev->dev); }
@@ -305,9 +305,9 @@ EXPORT_SYMBOL_GPL(_vdpa_unregister_device);*/ void vdpa_unregister_device (struct vdpa_device *vdev) { -mutex_lock (&vdpa_dev_mutex); +down_write (&vdpa_dev_lock);device_unregister (&vdev->dev); -mutex_unlock (&vdpa_dev_mutex); +up_write (&vdpa_dev_lock); }EXPORT_SYMBOL_GPL (vdpa_unregister_device);
@@ -352,9 +352,9 @@ int vdpa_mgmtdev_register(struct vdpa_mgmt_dev *mdev)return -EINVAL ;INIT_LIST_HEAD (&mdev->list); -mutex_lock (&vdpa_dev_mutex); +down_write (&vdpa_dev_lock);list_add_tail (&mdev->list, &mdev_head); -mutex_unlock (&vdpa_dev_mutex); +up_write (&vdpa_dev_lock);return 0 ; }EXPORT_SYMBOL_GPL (vdpa_mgmtdev_register);
@@ -371,14 +371,14 @@ static int vdpa_match_remove(struct device *dev, void *data)void vdpa_mgmtdev_unregister (struct vdpa_mgmt_dev *mdev) { -mutex_lock (&vdpa_dev_mutex); +down_write (&vdpa_dev_lock);list_del (&mdev->list);/* Filter out all the entries belong to this management device and delete it. */ bus_for_each_dev (&vdpa_bus,NULL , mdev, vdpa_match_remove); -mutex_unlock (&vdpa_dev_mutex); +up_write (&vdpa_dev_lock); }EXPORT_SYMBOL_GPL (vdpa_mgmtdev_unregister);
@@ -532,17 +532,17 @@ static int vdpa_nl_cmd_mgmtdev_get_doit(struct sk_buff *skb, struct genl_info *iif (!msg)return -ENOMEM ; -mutex_lock (&vdpa_dev_mutex); +down_read (&vdpa_dev_lock); mdev =vdpa_mgmtdev_get_from_attr (info->attrs);if (IS_ERR (mdev)) { -mutex_unlock (&vdpa_dev_mutex); +up_read (&vdpa_dev_lock);NL_SET_ERR_MSG_MOD (info->extack,"Fail to find the specified mgmt device" ); err =PTR_ERR (mdev); goto out; } err =vdpa_mgmtdev_fill (mdev, msg, info->snd_portid, info->snd_seq,0 ); -mutex_unlock (&vdpa_dev_mutex); +up_read (&vdpa_dev_lock);if (err) goto out; err =genlmsg_reply (msg, info);
@@ -561,7 +561,7 @@ vdpa_nl_cmd_mgmtdev_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb)int idx =0 ;int err; -mutex_lock (&vdpa_dev_mutex); +down_read (&vdpa_dev_lock);list_for_each_entry (mdev, &mdev_head, list) {if (idx < start) { idx++;
@@ -574,7 +574,7 @@ vdpa_nl_cmd_mgmtdev_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb) idx++; } out: -mutex_unlock (&vdpa_dev_mutex); +up_read (&vdpa_dev_lock); cb->args[0 ] = idx;return msg->len; }
@@ -627,7 +627,7 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i !netlink_capable(skb, CAP_NET_ADMIN))return -EPERM ; -mutex_lock (&vdpa_dev_mutex); +down_write (&vdpa_dev_lock); mdev =vdpa_mgmtdev_get_from_attr (info->attrs);if (IS_ERR (mdev)) {NL_SET_ERR_MSG_MOD (info->extack,"Fail to find the specified management device" );
@@ -643,7 +643,7 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i err = mdev->ops->dev_add (mdev, name, &config); err: -mutex_unlock (&vdpa_dev_mutex); +up_write (&vdpa_dev_lock);return err; }
@@ -659,7 +659,7 @@ static int vdpa_nl_cmd_dev_del_set_doit(struct sk_buff *skb, struct genl_info *ireturn -EINVAL ; name =nla_data (info->attrs[VDPA_ATTR_DEV_NAME ]); -mutex_lock (&vdpa_dev_mutex); +down_write (&vdpa_dev_lock); dev =bus_find_device (&vdpa_bus,NULL , name, vdpa_name_match);if (!dev) {NL_SET_ERR_MSG_MOD (info->extack,"device not found" );
@@ -677,7 +677,7 @@ static int vdpa_nl_cmd_dev_del_set_doit(struct sk_buff *skb, struct genl_info *i mdev_err:put_device (dev); dev_err: -mutex_unlock (&vdpa_dev_mutex); +up_write (&vdpa_dev_lock);return err; }
@@ -743,7 +743,7 @@ static int vdpa_nl_cmd_dev_get_doit(struct sk_buff *skb, struct genl_info *info)if (!msg)return -ENOMEM ; -mutex_lock (&vdpa_dev_mutex); +down_read (&vdpa_dev_lock); dev =bus_find_device (&vdpa_bus,NULL , devname, vdpa_name_match);if (!dev) {NL_SET_ERR_MSG_MOD (info->extack,"device not found" );
@@ -761,13 +761,13 @@ static int vdpa_nl_cmd_dev_get_doit(struct sk_buff *skb, struct genl_info *info) err =genlmsg_reply (msg, info);put_device (dev); -mutex_unlock (&vdpa_dev_mutex); +up_read (&vdpa_dev_lock);return err; mdev_err:put_device (dev); err: -mutex_unlock (&vdpa_dev_mutex); +up_read (&vdpa_dev_lock);nlmsg_free (msg);return err; }
@@ -809,9 +809,9 @@ static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba info.start_idx = cb->args[0 ]; info.idx =0 ; -mutex_lock (&vdpa_dev_mutex); +down_read (&vdpa_dev_lock);bus_for_each_dev (&vdpa_bus,NULL , &info, vdpa_dev_dump); -mutex_unlock (&vdpa_dev_mutex); +up_read (&vdpa_dev_lock); cb->args[0 ] = info.idx;return msg->len; }
@@ -1029,7 +1029,7 @@ static int vdpa_nl_cmd_dev_config_get_doit(struct sk_buff *skb, struct genl_infoif (!msg)return -ENOMEM ; -mutex_lock (&vdpa_dev_mutex); +down_read (&vdpa_dev_lock); dev =bus_find_device (&vdpa_bus,NULL , devname, vdpa_name_match);if (!dev) {NL_SET_ERR_MSG_MOD (info->extack,"device not found" );
@@ -1050,7 +1050,7 @@ static int vdpa_nl_cmd_dev_config_get_doit(struct sk_buff *skb, struct genl_info mdev_err:put_device (dev); dev_err: -mutex_unlock (&vdpa_dev_mutex); +up_read (&vdpa_dev_lock);if (err)nlmsg_free (msg);return err;
@@ -1088,9 +1088,9 @@ vdpa_nl_cmd_dev_config_get_dumpit(struct sk_buff *msg, struct netlink_callback * info.start_idx = cb->args[0 ]; info.idx =0 ; -mutex_lock (&vdpa_dev_mutex); +down_read (&vdpa_dev_lock);bus_for_each_dev (&vdpa_bus,NULL , &info, vdpa_dev_config_dump); -mutex_unlock (&vdpa_dev_mutex); +up_read (&vdpa_dev_lock); cb->args[0 ] = info.idx;return msg->len; }
@@ -1117,7 +1117,7 @@ static int vdpa_nl_cmd_dev_stats_get_doit(struct sk_buff *skb,return -ENOMEM ; index =nla_get_u32 (info->attrs[VDPA_ATTR_DEV_QUEUE_INDEX ]); -mutex_lock (&vdpa_dev_mutex); +down_read (&vdpa_dev_lock); dev =bus_find_device (&vdpa_bus,NULL , devname, vdpa_name_match);if (!dev) {NL_SET_ERR_MSG_MOD (info->extack,"device not found" );
@@ -1137,7 +1137,7 @@ static int vdpa_nl_cmd_dev_stats_get_doit(struct sk_buff *skb, err =genlmsg_reply (msg, info);put_device (dev); -mutex_unlock (&vdpa_dev_mutex); +up_read (&vdpa_dev_lock);return err;
@@ -1145,7 +1145,7 @@ static int vdpa_nl_cmd_dev_stats_get_doit(struct sk_buff *skb,put_device (dev); dev_err:nlmsg_free (msg); -mutex_unlock (&vdpa_dev_mutex); +up_read (&vdpa_dev_lock);return err; }
Signature · 1 line
2.35.1
PATCH v7 4/5 vdpa/mlx5: Add support for reading descriptor statistics
In reply to Eli CohenImplement the get_vq_stats calback of vdpa_config_ops to return the statistics for a virtqueue.
The statistics are provided as vendor specific statistics where the driver provides a pair of attribute name and attribute value.
Currently supported are received descriptors and completed descriptors.
--- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 2 + drivers/vdpa/mlx5/net/mlx5_vnet.c | 149 +++++++++++++++++++++++++++++ include/linux/mlx5/mlx5_ifc.h | 1 + include/linux/mlx5/mlx5_ifc_vdpa.h | 39 ++++++++ 4 files changed, 191 insertions(+)
drivers/vdpa/mlx5/core/mlx5_vdpa.h +2 -0
@@ -61,6 +61,8 @@ struct mlx5_control_vq {struct vringh_kiov riov;struct vringh_kiov wiov;unsigned short head; +unsigned int received_desc; +unsigned int completed_desc; };struct mlx5_vdpa_wq_ent {
drivers/vdpa/mlx5/net/mlx5_vnet.c +149 -0
221 lines not on this page · raw message
include/linux/mlx5/mlx5_ifc.h +1 -0
@@ -94,6 +94,7 @@ enum {enum {MLX5_OBJ_TYPE_GENEVE_TLV_OPT =0x000b ,MLX5_OBJ_TYPE_VIRTIO_NET_Q =0x000d , +MLX5_OBJ_TYPE_VIRTIO_Q_COUNTERS =0x001c ,MLX5_OBJ_TYPE_MATCH_DEFINER =0x0018 ,MLX5_OBJ_TYPE_MKEY =0xff01 ,MLX5_OBJ_TYPE_QP =0xff02 ,
include/linux/mlx5/mlx5_ifc_vdpa.h +39 -0
@@ -165,4 +165,43 @@ struct mlx5_ifc_modify_virtio_net_q_out_bits { struct mlx5_ifc_general_obj_out_cmd_hdr_bits general_obj_out_cmd_hdr; }; +struct mlx5_ifc_virtio_q_counters_bits { +u8 modify_field_select[0x40 ]; +u8 reserved_at_40[0x40 ]; +u8 received_desc[0x40 ]; +u8 completed_desc[0x40 ]; +u8 error_cqes[0x20 ]; +u8 bad_desc_errors[0x20 ]; +u8 exceed_max_chain[0x20 ]; +u8 invalid_buffer[0x20 ]; +u8 reserved_at_180[0x280 ]; +}; + +struct mlx5_ifc_create_virtio_q_counters_in_bits { +struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr; +struct mlx5_ifc_virtio_q_counters_bits virtio_q_counters; +}; + +struct mlx5_ifc_create_virtio_q_counters_out_bits { +struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr; +struct mlx5_ifc_virtio_q_counters_bits virtio_q_counters; +}; + +struct mlx5_ifc_destroy_virtio_q_counters_in_bits { +struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr; +}; + +struct mlx5_ifc_destroy_virtio_q_counters_out_bits { +struct mlx5_ifc_general_obj_out_cmd_hdr_bits hdr; +}; + +struct mlx5_ifc_query_virtio_q_counters_in_bits { +struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr; +}; + +struct mlx5_ifc_query_virtio_q_counters_out_bits { +struct mlx5_ifc_general_obj_in_cmd_hdr_bits hdr; +struct mlx5_ifc_virtio_q_counters_bits counters; +}; +#endif /* __MLX5_IFC_VDPA_H_ */
Signature · 1 line
2.35.1
PATCH v7 5/5 vdpa/mlx5: Use readers/writers semaphore instead of mutex
In reply to Eli CohenReading statistics could be done intensively and by several processes concurrently. Reader's lock is sufficient in this case.
Change reslock from mutex to a rwsem.
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 41 ++++++++++++++----------------- 1 file changed, 19 insertions(+), 22 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +19 -22
@@ -155,7 +155,7 @@ struct mlx5_vdpa_net {* since memory map might change and we need to destroy and create * resources while driver in operational. */ -struct mutex reslock; +struct rw_semaphore reslock;struct mlx5_flow_table *rxft;struct mlx5_fc *rx_counter;struct mlx5_flow_handle *rx_rule_ucast;
@@ -1695,7 +1695,7 @@ static void mlx5_cvq_kick_handler(struct work_struct *work) ndev =to_mlx5_vdpa_ndev (mvdev); cvq = &mvdev->cvq; -mutex_lock (&ndev->reslock); +down_write (&ndev->reslock);if (!(mvdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) goto out;
@@ -1746,7 +1746,7 @@ static void mlx5_cvq_kick_handler(struct work_struct *work) } out: -mutex_unlock (&ndev->reslock); +up_write (&ndev->reslock); }static void mlx5_vdpa_kick_vq (struct vdpa_device *vdev,u16 idx)
@@ -2244,7 +2244,7 @@ static int setup_driver(struct mlx5_vdpa_dev *mvdev)struct mlx5_vdpa_net *ndev =to_mlx5_vdpa_ndev (mvdev);int err; -WARN_ON (!mutex_is_locked (&ndev->reslock)); +WARN_ON (!rwsem_is_locked (&ndev->reslock));if (ndev->setup) {mlx5_vdpa_warn (mvdev,"setup driver called for already setup driver\n" );
@@ -2292,7 +2292,7 @@ static int setup_driver(struct mlx5_vdpa_dev *mvdev)static void teardown_driver (struct mlx5_vdpa_net *ndev) { -WARN_ON (!mutex_is_locked (&ndev->reslock)); +WARN_ON (!rwsem_is_locked (&ndev->reslock));if (!ndev->setup)return ;
@@ -2322,7 +2322,7 @@ static void mlx5_vdpa_set_status(struct vdpa_device *vdev, u8 status)print_status (mvdev, status, true); -mutex_lock (&ndev->reslock); +down_write (&ndev->reslock);if ((status ^ ndev->mvdev.status) &VIRTIO_CONFIG_S_DRIVER_OK ) {if (status &VIRTIO_CONFIG_S_DRIVER_OK ) {
@@ -2338,14 +2338,14 @@ static void mlx5_vdpa_set_status(struct vdpa_device *vdev, u8 status) } ndev->mvdev.status = status; -mutex_unlock (&ndev->reslock); +up_write (&ndev->reslock);return ; err_setup:mlx5_vdpa_destroy_mr (&ndev->mvdev); ndev->mvdev.status |=VIRTIO_CONFIG_S_FAILED ; err_clear: -mutex_unlock (&ndev->reslock); +up_write (&ndev->reslock); }static int mlx5_vdpa_reset (struct vdpa_device *vdev)
@@ -2356,7 +2356,7 @@ static int mlx5_vdpa_reset(struct vdpa_device *vdev)print_status (mvdev,0 , true);mlx5_vdpa_info (mvdev,"performing device reset\n" ); -mutex_lock (&ndev->reslock); +down_write (&ndev->reslock);teardown_driver (ndev);clear_vqs_ready (ndev);mlx5_vdpa_destroy_mr (&ndev->mvdev);
@@ -2371,7 +2371,7 @@ static int mlx5_vdpa_reset(struct vdpa_device *vdev)if (mlx5_vdpa_create_mr (mvdev,NULL ))mlx5_vdpa_warn (mvdev,"create MR failed\n" ); } -mutex_unlock (&ndev->reslock); +up_write (&ndev->reslock);return 0 ; }
@@ -2411,7 +2411,7 @@ static int mlx5_vdpa_set_map(struct vdpa_device *vdev, struct vhost_iotlb *iotlbbool change_map;int err; -mutex_lock (&ndev->reslock); +down_write (&ndev->reslock); err =mlx5_vdpa_handle_set_map (mvdev, iotlb, &change_map);if (err) {
@@ -2423,7 +2423,7 @@ static int mlx5_vdpa_set_map(struct vdpa_device *vdev, struct vhost_iotlb *iotlb err =mlx5_vdpa_change_map (mvdev, iotlb); err: -mutex_unlock (&ndev->reslock); +up_write (&ndev->reslock);return err; }
@@ -2442,7 +2442,6 @@ static void mlx5_vdpa_free(struct vdpa_device *vdev)mlx5_mpfs_del_mac (pfmdev, ndev->config.mac); }mlx5_vdpa_free_resources (&ndev->mvdev); -mutex_destroy (&ndev->reslock);kfree (ndev->event_cbs);kfree (ndev->vqs); }
@@ -2527,7 +2526,7 @@ static int mlx5_vdpa_get_vendor_vq_stats(struct vdpa_device *vdev, u16 idx,u64 completed_desc;int err =0 ; -mutex_lock (&ndev->reslock); +down_read (&ndev->reslock);if (!is_index_valid (mvdev, idx)) {NL_SET_ERR_MSG_MOD (extack,"virtqueue index is not valid" ); err = -EINVAL ;
@@ -2566,7 +2565,7 @@ static int mlx5_vdpa_get_vendor_vq_stats(struct vdpa_device *vdev, u16 idx, err =0 ; out_err: -mutex_unlock (&ndev->reslock); +up_read (&ndev->reslock);return err; }
@@ -2835,18 +2834,18 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, }init_mvqs (ndev); -mutex_init (&ndev->reslock); +init_rwsem (&ndev->reslock); config = &ndev->config;if (add_config->mask &BIT_ULL (VDPA_ATTR_DEV_NET_CFG_MTU )) { err =config_func_mtu (mdev, add_config->net.mtu);if (err) - goto err_mtu; + goto err_alloc; } err =query_mtu (mdev, &mtu);if (err) - goto err_mtu; + goto err_alloc; ndev->config.mtu =cpu_to_mlx5vdpa16 (mvdev, mtu);
@@ -2860,14 +2859,14 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, }else { err =mlx5_query_nic_vport_mac_address (mdev,0 ,0 , config->mac);if (err) - goto err_mtu; + goto err_alloc; }if (!is_zero_ether_addr (config->mac)) { pfmdev =pci_get_drvdata (pci_physfn (mdev->pdev)); err =mlx5_mpfs_add_mac (pfmdev, config->mac);if (err) - goto err_mtu; + goto err_alloc; ndev->mvdev.mlx_features |=BIT_ULL (VIRTIO_NET_F_MAC ); }
@@ -2917,8 +2916,6 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, err_mpfs:if (!is_zero_ether_addr (config->mac))mlx5_mpfs_del_mac (pfmdev, config->mac); -err_mtu: -mutex_destroy (&ndev->reslock); err_alloc:put_device (&mvdev->vdev.dev);return err;
Signature · 1 line
2.35.1
Re: [PATCH v7 5/5] vdpa/mlx5: Use readers/writers semaphore instead of mutex
Quoted 7 lines · Eli Cohen
Reading statistics could be done intensively and by several processes concurrently. Reader's lock is sufficient in this case.
Change reslock from mutex to a rwsem.
Suggested-by Si-Wei Liu <[email protected]>Signed-off-by Eli Cohen <[email protected]>
Quoted 181 lines
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 41 ++++++++++++++----------------- 1 file changed, 19 insertions(+), 22 deletions(-)drivers/vdpa/mlx5/net/mlx5_vnet.c +19
-20@@ -155,7 +155,7 @@ struct mlx5_vdpa_net {* since memory map might change and we need to destroy and create * resources while driver in operational. */ -struct mutex reslock; +struct rw_semaphore reslock;struct mlx5_flow_table *rxft;struct mlx5_fc *rx_counter;struct mlx5_flow_handle *rx_rule_ucast;@@ -1695,7 +1695,7 @@ static void mlx5_cvq_kick_handler(struct work_struct *work) ndev =to_mlx5_vdpa_ndev (mvdev); cvq = &mvdev->cvq; -mutex_lock (&ndev->reslock); +down_write (&ndev->reslock);if (!(mvdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) goto out;@@ -1746,7 +1746,7 @@ static void mlx5_cvq_kick_handler(struct work_struct *work) } out: -mutex_unlock (&ndev->reslock); +up_write (&ndev->reslock); }static void mlx5_vdpa_kick_vq (struct vdpa_device *vdev,u16 idx)@@ -2244,7 +2244,7 @@ static int setup_driver(struct mlx5_vdpa_dev *mvdev)struct mlx5_vdpa_net *ndev =to_mlx5_vdpa_ndev (mvdev);int err; -WARN_ON (!mutex_is_locked (&ndev->reslock)); +WARN_ON (!rwsem_is_locked (&ndev->reslock));if (ndev->setup) {mlx5_vdpa_warn (mvdev,"setup driver called for already setup driver\n" );@@ -2292,7 +2292,7 @@ static int setup_driver(struct mlx5_vdpa_dev *mvdev)static void teardown_driver (struct mlx5_vdpa_net *ndev) { -WARN_ON (!mutex_is_locked (&ndev->reslock)); +WARN_ON (!rwsem_is_locked (&ndev->reslock));if (!ndev->setup)return ;@@ -2322,7 +2322,7 @@ static void mlx5_vdpa_set_status(struct vdpa_device *vdev, u8 status)print_status (mvdev, status, true); -mutex_lock (&ndev->reslock); +down_write (&ndev->reslock);if ((status ^ ndev->mvdev.status) &VIRTIO_CONFIG_S_DRIVER_OK ) {if (status &VIRTIO_CONFIG_S_DRIVER_OK ) {@@ -2338,14 +2338,14 @@ static void mlx5_vdpa_set_status(struct vdpa_device *vdev, u8 status) } ndev->mvdev.status = status; -mutex_unlock (&ndev->reslock); +up_write (&ndev->reslock);return ; err_setup:mlx5_vdpa_destroy_mr (&ndev->mvdev); ndev->mvdev.status |=VIRTIO_CONFIG_S_FAILED ; err_clear: -mutex_unlock (&ndev->reslock); +up_write (&ndev->reslock); }static int mlx5_vdpa_reset (struct vdpa_device *vdev)@@ -2356,7 +2356,7 @@ static int mlx5_vdpa_reset(struct vdpa_device *vdev)print_status (mvdev,0 , true);mlx5_vdpa_info (mvdev,"performing device reset\n" ); -mutex_lock (&ndev->reslock); +down_write (&ndev->reslock);teardown_driver (ndev);clear_vqs_ready (ndev);mlx5_vdpa_destroy_mr (&ndev->mvdev);@@ -2371,7 +2371,7 @@ static int mlx5_vdpa_reset(struct vdpa_device *vdev)if (mlx5_vdpa_create_mr (mvdev,NULL ))mlx5_vdpa_warn (mvdev,"create MR failed\n" ); } -mutex_unlock (&ndev->reslock); +up_write (&ndev->reslock);return 0 ; }@@ -2411,7 +2411,7 @@ static int mlx5_vdpa_set_map(struct vdpa_device *vdev, struct vhost_iotlb *iotlbbool change_map;int err; -mutex_lock (&ndev->reslock); +down_write (&ndev->reslock); err =mlx5_vdpa_handle_set_map (mvdev, iotlb, &change_map);if (err) {@@ -2423,7 +2423,7 @@ static int mlx5_vdpa_set_map(struct vdpa_device *vdev, struct vhost_iotlb *iotlb err =mlx5_vdpa_change_map (mvdev, iotlb); err: -mutex_unlock (&ndev->reslock); +up_write (&ndev->reslock);return err; }@@ -2442,7 +2442,6 @@ static void mlx5_vdpa_free(struct vdpa_device *vdev)mlx5_mpfs_del_mac (pfmdev, ndev->config.mac); }mlx5_vdpa_free_resources (&ndev->mvdev); -mutex_destroy (&ndev->reslock);kfree (ndev->event_cbs);kfree (ndev->vqs); }@@ -2527,7 +2526,7 @@ static int mlx5_vdpa_get_vendor_vq_stats(struct vdpa_device *vdev, u16 idx,u64 completed_desc;int err =0 ; -mutex_lock (&ndev->reslock); +down_read (&ndev->reslock);if (!is_index_valid (mvdev, idx)) {NL_SET_ERR_MSG_MOD (extack,"virtqueue index is not valid" ); err = -EINVAL ;@@ -2566,7 +2565,7 @@ static int mlx5_vdpa_get_vendor_vq_stats(struct vdpa_device *vdev, u16 idx, err =0 ; out_err: -mutex_unlock (&ndev->reslock); +up_read (&ndev->reslock);return err; }@@ -2835,18 +2834,18 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, }init_mvqs (ndev); -mutex_init (&ndev->reslock); +init_rwsem (&ndev->reslock); config = &ndev->config;if (add_config->mask &BIT_ULL (VDPA_ATTR_DEV_NET_CFG_MTU )) { err =config_func_mtu (mdev, add_config->net.mtu);if (err) - goto err_mtu; + goto err_alloc; } err =query_mtu (mdev, &mtu);if (err) - goto err_mtu; + goto err_alloc; ndev->config.mtu =cpu_to_mlx5vdpa16 (mvdev, mtu);@@ -2860,14 +2859,14 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, }else { err =mlx5_query_nic_vport_mac_address (mdev,0 ,0 , config->mac);if (err) - goto err_mtu; + goto err_alloc; }if (!is_zero_ether_addr (config->mac)) { pfmdev =pci_get_drvdata (pci_physfn (mdev->pdev)); err =mlx5_mpfs_add_mac (pfmdev, config->mac);if (err) - goto err_mtu; + goto err_alloc; ndev->mvdev.mlx_features |=BIT_ULL (VIRTIO_NET_F_MAC ); }
drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, · line 2921
Quoted 8 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0
-2@@ -2917,8 +2916,6 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, err_mpfs:if (!is_zero_ether_addr (config->mac))mlx5_mpfs_del_mac (pfmdev, config->mac); -err_mtu: -mutex_destroy (&ndev->reslock); err_alloc:put_device (&mvdev->vdev.dev);return err;
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization