vdpa tool enhancements
Subsystems (2)
PATCH 1/4 vdpa: Remove unsupported command line option
In reply to Eli Cohen"-v[erbose]" option is not supported.
Remove it.
--- vdpa/vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
vdpa/vdpa.c +1 -1
@@ -711,7 +711,7 @@ static void help(void)fprintf (stderr,"Usage: vdpa [ OPTIONS ] OBJECT { COMMAND | help }\n" "where OBJECT := { mgmtdev | dev }\n" -" OPTIONS := { -V[ersion] | -n[o-nice-names] | -j[son] | -p[retty] | -v[erbose] }\n" ); +" OPTIONS := { -V[ersion] | -n[o-nice-names] | -j[son] | -p[retty] }\n" ); }static int vdpa_cmd (struct vdpa *vdpa,int argc,char **argv)
Signature · 1 line
2.34.1
cover vdpa tool enhancements
The following four patch series enhances vdpa to show negotiated features for a vdpa device, max features for a management device and allows to configure max number of virtqueue pairs.
v0 -> v1:
1. Split patches to present added functionality in separate patches.
2. Remove patch 0002 and add required definitions from uapi linux headers.
3. Print bit numbers for non net devices.
Eli Cohen (4):
vdpa: Remove unsupported command line option
vdpa: Allow for printing negotiated features of a device
vdpa: Support for configuring max VQ pairs for a device
vdpa: Support reading device features
vdpa/include/uapi/linux/vdpa.h | 4 + vdpa/vdpa.c | 164 +++++++++++++++++++++++++++++++-- 2 files changed, 162 insertions(+), 6 deletions(-)
Signature · 1 line
2.34.1
PATCH 2/4 vdpa: Allow for printing negotiated features of a device
When reading the configuration of a vdpa device, check if the VDPA_ATTR_DEV_NEGOTIATED_FEATURES is available. If it is, parse the feature bits and print a string representation of each of the feature bits.
We keep the strings in two different arrays. One for net device related devices and one for generic feature bits.
In this patch we parse only net device specific features. Support for other devices can be added later. If the device queried is not a net device, we print its bit number only.
Examples:
1.
$ vdpa dev config show vdpa-a
vdpa-a: mac 00:00:00:00:88:88 link up link_announce false max_vq_pairs 3 \
mtu 1500
negotiated_features CSUM GUEST_CSUM MTU MAC HOST_TSO4 HOST_TSO6 STATUS \
CTRL_VQ MQ CTRL_MAC_ADDR VERSION_1 ACCESS_PLATFORM2. json output
$ vdpa -j dev config show vdpa-a
{"config":{"vdpa-a":{"mac":"00:00:00:00:88:88","link":"up","link_announce":false, \
"max_vq_pairs":3,"mtu":1500,"negotiated_features":["CSUM","GUEST_CSUM","MTU", \
"MAC","HOST_TSO4","HOST_TSO6","STATUS","CTRL_VQ","MQ","CTRL_MAC_ADDR", \
"VERSION_1","ACCESS_PLATFORM"]}}}3. pretty json
$ vdpa -jp dev config show vdpa-a
{
"config": {
"vdpa-a": {
"mac": "00:00:00:00:88:88",
"link ": "up",
"link_announce ": false,
"max_vq_pairs": 3,
"mtu": 1500,
"negotiated_features": [
"CSUM","GUEST_CSUM","MTU","MAC","HOST_TSO4","HOST_TSO6","STATUS","CTRL_VQ", \
"MQ","CTRL_MAC_ADDR","VERSION_1","ACCESS_PLATFORM" ]
}
}
}--- vdpa/include/uapi/linux/vdpa.h | 2 + vdpa/vdpa.c | 126 +++++++++++++++++++++++++++++++-- 2 files changed, 124 insertions(+), 4 deletions(-)
vdpa/include/uapi/linux/vdpa.h +2 -0
@@ -40,6 +40,8 @@ enum vdpa_attr {VDPA_ATTR_DEV_NET_CFG_MAX_VQP ,/* u16 */ VDPA_ATTR_DEV_NET_CFG_MTU ,/* u16 */ +VDPA_ATTR_DEV_NEGOTIATED_FEATURES ,/* u64 */ +/* new attributes must be added above here */ VDPA_ATTR_MAX, };
vdpa/vdpa.c +122 -4
173 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 4/4 vdpa: Support reading device features
In reply to Eli CohenWhen showing the available management devices, check if VDPA_ATTR_DEV_SUPPORTED_FEATURES feature is available and print the supported features for a management device.
Example:
$ vdpa mgmtdev show
auxiliary/mlx5_core.sf.1:
supported_classes net
max_supported_vqs 257
dev_features CSUM GUEST_CSUM MTU HOST_TSO4 HOST_TSO6 STATUS CTRL_VQ MQ \
CTRL_MAC_ADDR VERSION_1 ACCESS_PLATFORM--- vdpa/include/uapi/linux/vdpa.h | 1 + vdpa/vdpa.c | 11 +++++++++++ 2 files changed, 12 insertions(+)
vdpa/include/uapi/linux/vdpa.h +1 -0
@@ -42,6 +42,7 @@ enum vdpa_attr {VDPA_ATTR_DEV_NEGOTIATED_FEATURES ,/* u64 */ VDPA_ATTR_DEV_MGMTDEV_MAX_VQS ,/* u32 */ +VDPA_ATTR_DEV_SUPPORTED_FEATURES ,/* u64 */ /* new attributes must be added above here */ VDPA_ATTR_MAX,
vdpa/vdpa.c +11 -0
@@ -83,6 +83,7 @@ static const enum mnl_attr_data_type vdpa_policy[VDPA_ATTR_MAX + 1] = { [VDPA_ATTR_DEV_MAX_VQ_SIZE] = MNL_TYPE_U16, [VDPA_ATTR_DEV_NEGOTIATED_FEATURES] = MNL_TYPE_U64, [VDPA_ATTR_DEV_MGMTDEV_MAX_VQS] = MNL_TYPE_U32, + [VDPA_ATTR_DEV_SUPPORTED_FEATURES] = MNL_TYPE_U64, };static int attr_cb (const struct nlattr *attr,void *data)
@@ -535,6 +536,16 @@ static void pr_out_mgmtdev_show(struct vdpa *vdpa, const struct nlmsghdr *nlh,print_uint (PRINT_ANY ,"max_supported_vqs" ," max_supported_vqs %d" , num_vqs); } +if (tb[VDPA_ATTR_DEV_SUPPORTED_FEATURES ]) { +uint64_t features; + + features =mnl_attr_get_u64 (tb[VDPA_ATTR_DEV_SUPPORTED_FEATURES ]); +if (classes &BIT (VIRTIO_ID_NET )) +print_net_features (vdpa, features, true); +else +print_generic_features (vdpa, features, true); + } +pr_out_handle_end (vdpa); }
Signature · 1 line
2.34.1
PATCH 3/4 vdpa: Support for configuring max VQ pairs for a device
In reply to Eli CohenUse VDPA_ATTR_DEV_MGMTDEV_MAX_VQS to specify max number of virtqueue pairs to configure for a vdpa device when adding a device.
Examples:
1. Create a device with 3 virtqueue pairs:
$ vdpa dev add name vdpa-a mgmtdev auxiliary/mlx5_core.sf.1 max_vqp 3
2. Read the configuration of a vdpa device
$ vdpa dev config show vdpa-a
vdpa-a: mac 00:00:00:00:88:88 link up link_announce false max_vq_pairs 3 \
mtu 1500
negotiated_features CSUM GUEST_CSUM MTU MAC HOST_TSO4 HOST_TSO6 STATUS \
CTRL_VQ MQ CTRL_MAC_ADDR VERSION_1 ACCESS_PLATFORM--- vdpa/include/uapi/linux/vdpa.h | 1 + vdpa/vdpa.c | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-)
vdpa/include/uapi/linux/vdpa.h +1 -0
@@ -41,6 +41,7 @@ enum vdpa_attr {VDPA_ATTR_DEV_NET_CFG_MTU ,/* u16 */ VDPA_ATTR_DEV_NEGOTIATED_FEATURES ,/* u64 */ +VDPA_ATTR_DEV_MGMTDEV_MAX_VQS ,/* u32 */ /* new attributes must be added above here */ VDPA_ATTR_MAX,
vdpa/vdpa.c +24 -1
@@ -24,6 +24,7 @@#define VDPA_OPT_VDEV_HANDLE BIT(3)#define VDPA_OPT_VDEV_MAC BIT(4)#define VDPA_OPT_VDEV_MTU BIT(5) +#define VDPA_OPT_MAX_VQP BIT(6)struct vdpa_opts {uint64_t present;/* flags of present items */
@@ -33,6 +34,7 @@ struct vdpa_opts {unsigned int device_id;char mac[ETH_ALEN ];uint16_t mtu; +uint16_t max_vqp; };struct vdpa {
@@ -80,6 +82,7 @@ static const enum mnl_attr_data_type vdpa_policy[VDPA_ATTR_MAX + 1] = { [VDPA_ATTR_DEV_MAX_VQS] = MNL_TYPE_U32, [VDPA_ATTR_DEV_MAX_VQ_SIZE] = MNL_TYPE_U16, [VDPA_ATTR_DEV_NEGOTIATED_FEATURES] = MNL_TYPE_U64, + [VDPA_ATTR_DEV_MGMTDEV_MAX_VQS] = MNL_TYPE_U32, };static int attr_cb (const struct nlattr *attr,void *data)
@@ -221,6 +224,8 @@ static void vdpa_opts_put(struct nlmsghdr *nlh, struct vdpa *vdpa) sizeof(opts->mac), opts->mac);if (opts->present &VDPA_OPT_VDEV_MTU )mnl_attr_put_u16 (nlh,VDPA_ATTR_DEV_NET_CFG_MTU , opts->mtu); +if (opts->present &VDPA_OPT_MAX_VQP ) +mnl_attr_put_u16 (nlh,VDPA_ATTR_DEV_NET_CFG_MAX_VQP , opts->max_vqp); } static int vdpa_argv_parse(struct vdpa *vdpa, int argc, char **argv,
@@ -289,6 +294,14 @@ static int vdpa_argv_parse(struct vdpa *vdpa, int argc, char **argv,NEXT_ARG_FWD (); o_found |=VDPA_OPT_VDEV_MTU ; + }else if ((matches (*argv,"max_vqp" ) ==0 ) && (o_optional &VDPA_OPT_MAX_VQP )) { +NEXT_ARG_FWD (); + err =vdpa_argv_u16 (vdpa, argc, argv, &opts->max_vqp); +if (err) +return err; + +NEXT_ARG_FWD (); + o_found |=VDPA_OPT_MAX_VQP ; }else {fprintf (stderr,"Unknown option \"%s\"\n" , *argv);return -EINVAL ;
@@ -513,6 +526,15 @@ static void pr_out_mgmtdev_show(struct vdpa *vdpa, const struct nlmsghdr *nlh,pr_out_array_end (vdpa); } +if (tb[VDPA_ATTR_DEV_MGMTDEV_MAX_VQS ]) { +uint16_t num_vqs; + +if (!vdpa->json_output) +printf ("\n" ); + num_vqs =mnl_attr_get_u16 (tb[VDPA_ATTR_DEV_MGMTDEV_MAX_VQS ]); +print_uint (PRINT_ANY ,"max_supported_vqs" ," max_supported_vqs %d" , num_vqs); + } +pr_out_handle_end (vdpa); }
@@ -662,7 +684,8 @@ static int cmd_dev_add(struct vdpa *vdpa, int argc, char **argv) NLM_F_REQUEST | NLM_F_ACK); err =vdpa_argv_parse_put (nlh, vdpa, argc, argv,VDPA_OPT_VDEV_MGMTDEV_HANDLE |VDPA_OPT_VDEV_NAME , -VDPA_OPT_VDEV_MAC |VDPA_OPT_VDEV_MTU ); +VDPA_OPT_VDEV_MAC |VDPA_OPT_VDEV_MTU | +VDPA_OPT_MAX_VQP );if (err)return err;
Signature · 1 line
2.34.1
Re: [PATCH v1 3/4] vdpa: Support for configuring max VQ pairs for a device
Quoted 71 lines · Eli Cohen
Use
VDPA_ATTR_DEV_MGMTDEV_MAX_VQSto specify max number of virtqueue pairs to configure for a vdpa device when adding a device.Examples:
1. Create a device with 3 virtqueue pairs:$ vdpa dev add name vdpa-a mgmtdev auxiliary/mlx5_core.sf.1 max_vqp 32. Read the configuration of a vdpa device
$ vdpa dev config show vdpa-a vdpa-a: mac 00:00:00:00:88:88 link up link_announce false max_vq_pairs 3 \ mtu 1500 negotiated_features CSUM GUEST_CSUM MTU MAC HOST_TSO4 HOST_TSO6 STATUS \ CTRL_VQ MQ CTRL_MAC_ADDR VERSION_1 ACCESS_PLATFORMSigned-off-by Eli Cohen <[email protected]>--- vdpa/include/uapi/linux/vdpa.h | 1 + vdpa/vdpa.c | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-)vdpa/include/uapi/linux/vdpa.h +1
-0@@ -41,6 +41,7 @@ enum vdpa_attr {VDPA_ATTR_DEV_NET_CFG_MTU ,/* u16 */ VDPA_ATTR_DEV_NEGOTIATED_FEATURES ,/* u64 */ +VDPA_ATTR_DEV_MGMTDEV_MAX_VQS ,/* u32 */ /* new attributes must be added above here */ VDPA_ATTR_MAX,vdpa/vdpa.c +5
-0@@ -24,6 +24,7 @@#define VDPA_OPT_VDEV_HANDLE BIT(3)#define VDPA_OPT_VDEV_MAC BIT(4)#define VDPA_OPT_VDEV_MTU BIT(5) +#define VDPA_OPT_MAX_VQP BIT(6)struct vdpa_opts {uint64_t present;/* flags of present items */ @@ -33,6 +34,7 @@ struct vdpa_opts {unsigned int device_id;char mac[ETH_ALEN ];uint16_t mtu; +uint16_t max_vqp; };struct vdpa {@@ -80,6 +82,7 @@ static const enum mnl_attr_data_type vdpa_policy[VDPA_ATTR_MAX + 1] = { [VDPA_ATTR_DEV_MAX_VQS] = MNL_TYPE_U32, [VDPA_ATTR_DEV_MAX_VQ_SIZE] = MNL_TYPE_U16, [VDPA_ATTR_DEV_NEGOTIATED_FEATURES] = MNL_TYPE_U64, + [VDPA_ATTR_DEV_MGMTDEV_MAX_VQS] = MNL_TYPE_U32, };static int attr_cb (const struct nlattr *attr,void *data)@@ -221,6 +224,8 @@ static void vdpa_opts_put(struct nlmsghdr *nlh, struct vdpa *vdpa) sizeof(opts->mac), opts->mac);if (opts->present &VDPA_OPT_VDEV_MTU )mnl_attr_put_u16 (nlh,VDPA_ATTR_DEV_NET_CFG_MTU , opts->mtu); +if (opts->present &VDPA_OPT_MAX_VQP ) +mnl_attr_put_u16 (nlh,VDPA_ATTR_DEV_NET_CFG_MAX_VQP , opts->max_vqp); } static int vdpa_argv_parse(struct vdpa *vdpa, int argc, char **argv,@@ -289,6 +294,14 @@ static int vdpa_argv_parse(struct vdpa *vdpa, int argc, char **argv,
vdpa/vdpa.c static int vdpa_argv_parse(struct vdpa *vdpa, int argc, char **argv, · line 304
Quoted 10 lines
vdpa/vdpa.c +8
-0NEXT_ARG_FWD (); o_found |=VDPA_OPT_VDEV_MTU ; + }else if ((matches (*argv,"max_vqp" ) ==0 ) && (o_optional &VDPA_OPT_MAX_VQP )) { +NEXT_ARG_FWD (); + err =vdpa_argv_u16 (vdpa, argc, argv, &opts->max_vqp); +if (err) +return err; + +NEXT_ARG_FWD (); + o_found |=VDPA_OPT_MAX_VQP ;
It'd be nice to update cmd_dev_help() to include the max_vqp option as well.
Quoted 29 lines
vdpa/vdpa.c +11
-1}else {fprintf (stderr,"Unknown option \"%s\"\n" , *argv);return -EINVAL ;@@ -513,6 +526,15 @@ static void pr_out_mgmtdev_show(struct vdpa *vdpa, const struct nlmsghdr *nlh,pr_out_array_end (vdpa); } +if (tb[VDPA_ATTR_DEV_MGMTDEV_MAX_VQS ]) { +uint16_t num_vqs; + +if (!vdpa->json_output) +printf ("\n" ); + num_vqs =mnl_attr_get_u16 (tb[VDPA_ATTR_DEV_MGMTDEV_MAX_VQS ]); +print_uint (PRINT_ANY ,"max_supported_vqs" ," max_supported_vqs %d" , num_vqs); + } +pr_out_handle_end (vdpa); }@@ -662,7 +684,8 @@ static int cmd_dev_add(struct vdpa *vdpa, int argc, char **argv) NLM_F_REQUEST | NLM_F_ACK); err =vdpa_argv_parse_put (nlh, vdpa, argc, argv,VDPA_OPT_VDEV_MGMTDEV_HANDLE |VDPA_OPT_VDEV_NAME , -VDPA_OPT_VDEV_MAC |VDPA_OPT_VDEV_MTU ); +VDPA_OPT_VDEV_MAC |VDPA_OPT_VDEV_MTU | +VDPA_OPT_MAX_VQP );if (err)return err;
Re: [PATCH v1 4/4] vdpa: Support reading device features
In reply to Eli CohenQuoted 11 lines · Eli Cohen
When showing the available management devices, check if
VDPA_ATTR_DEV_SUPPORTED_FEATURESfeature is available and print the supported features for a management device.Example:
$ vdpa mgmtdev show auxiliary/mlx5_core.sf.1: supported_classes net max_supported_vqs 257 dev_features CSUM GUEST_CSUM MTU HOST_TSO4 HOST_TSO6 STATUS CTRL_VQ MQ \ CTRL_MAC_ADDR VERSION_1 ACCESS_PLATFORM
It'd be nice to add an example output for json pretty format.
Quoted 48 lines
Signed-off-by Eli Cohen <[email protected]>--- vdpa/include/uapi/linux/vdpa.h | 1 + vdpa/vdpa.c | 11 +++++++++++ 2 files changed, 12 insertions(+)vdpa/include/uapi/linux/vdpa.h +1
-0@@ -42,6 +42,7 @@ enum vdpa_attr {VDPA_ATTR_DEV_NEGOTIATED_FEATURES ,/* u64 */ VDPA_ATTR_DEV_MGMTDEV_MAX_VQS ,/* u32 */ +VDPA_ATTR_DEV_SUPPORTED_FEATURES ,/* u64 */ /* new attributes must be added above here */ VDPA_ATTR_MAX,vdpa/vdpa.c +11
-0@@ -83,6 +83,7 @@ static const enum mnl_attr_data_type vdpa_policy[VDPA_ATTR_MAX + 1] = { [VDPA_ATTR_DEV_MAX_VQ_SIZE] = MNL_TYPE_U16, [VDPA_ATTR_DEV_NEGOTIATED_FEATURES] = MNL_TYPE_U64, [VDPA_ATTR_DEV_MGMTDEV_MAX_VQS] = MNL_TYPE_U32, + [VDPA_ATTR_DEV_SUPPORTED_FEATURES] = MNL_TYPE_U64, };static int attr_cb (const struct nlattr *attr,void *data)@@ -535,6 +536,16 @@ static void pr_out_mgmtdev_show(struct vdpa *vdpa, const struct nlmsghdr *nlh,print_uint (PRINT_ANY ,"max_supported_vqs" ," max_supported_vqs %d" , num_vqs); } +if (tb[VDPA_ATTR_DEV_SUPPORTED_FEATURES ]) { +uint64_t features; + + features =mnl_attr_get_u64 (tb[VDPA_ATTR_DEV_SUPPORTED_FEATURES ]); +if (classes &BIT (VIRTIO_ID_NET )) +print_net_features (vdpa, features, true); +else +print_generic_features (vdpa, features, true); + } +pr_out_handle_end (vdpa); }
Re: [PATCH v1 1/4] vdpa: Remove unsupported command line option
In reply to Eli CohenQuoted 15 lines · Eli Cohen
"-v[erbose]" option is not supported.
Remove it.Acked-by Jason Wang <[email protected]>Reviewed-by Jianbo Liu <[email protected]>Signed-off-by Eli Cohen <[email protected]>--- vdpa/vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)vdpa/vdpa.c +0
-0
vdpa/vdpa.c static void help(void) · line 714
Quoted 5 lines
vdpa/vdpa.c +1
-1@@ -711,7 +711,7 @@ static void help(void)fprintf (stderr,"Usage: vdpa [ OPTIONS ] OBJECT { COMMAND | help }\n" "where OBJECT := { mgmtdev | dev }\n" -" OPTIONS := { -V[ersion] | -n[o-nice-names] | -j[son] | -p[retty] | -v[erbose] }\n" ); +" OPTIONS := { -V[ersion] | -n[o-nice-names] | -j[son] | -p[retty] }\n" );
Maybe remove -n option that is also unsupported yet?
Quoted 3 lines
vdpa/vdpa.c +0
-0}static int vdpa_cmd (struct vdpa *vdpa,int argc,char **argv)
Re: [PATCH v1 2/4] vdpa: Allow for printing negotiated features of a device
In reply to Eli CohenQuoted 132 lines · Eli Cohen
When reading the configuration of a vdpa device, check if the
VDPA_ATTR_DEV_NEGOTIATED_FEATURESis available. If it is, parse the feature bits and print a string representation of each of the feature bits.We keep the strings in two different arrays. One for net device related devices and one for generic feature bits.
In this patch we parse only net device specific features. Support for other devices can be added later. If the device queried is not a net device, we print its bit number only.
Examples:
1.$ vdpa dev config show vdpa-a vdpa-a: mac 00:00:00:00:88:88 link up link_announce false max_vq_pairs 3 \ mtu 1500 negotiated_features CSUM GUEST_CSUM MTU MAC HOST_TSO4 HOST_TSO6 STATUS \ CTRL_VQ MQ CTRL_MAC_ADDR VERSION_1 ACCESS_PLATFORM2. json output
$ vdpa -j dev config show vdpa-a {"config":{"vdpa-a":{"mac":"00:00:00:00:88:88","link":"up","link_announce":false, \ "max_vq_pairs":3,"mtu":1500,"negotiated_features":["CSUM","GUEST_CSUM","MTU", \ "MAC","HOST_TSO4","HOST_TSO6","STATUS","CTRL_VQ","MQ","CTRL_MAC_ADDR", \ "VERSION_1","ACCESS_PLATFORM"]}}}3. pretty json
$ vdpa -jp dev config show vdpa-a { "config": { "vdpa-a": { "mac": "00:00:00:00:88:88", "link ": "up", "link_announce ": false, "max_vq_pairs": 3, "mtu": 1500, "negotiated_features": [ "CSUM","GUEST_CSUM","MTU","MAC","HOST_TSO4","HOST_TSO6","STATUS","CTRL_VQ", \ "MQ","CTRL_MAC_ADDR","VERSION_1","ACCESS_PLATFORM" ] } } }Signed-off-by Eli Cohen <[email protected]>--- vdpa/include/uapi/linux/vdpa.h | 2 + vdpa/vdpa.c | 126 +++++++++++++++++++++++++++++++-- 2 files changed, 124 insertions(+), 4 deletions(-)vdpa/include/uapi/linux/vdpa.h +2
-0@@ -40,6 +40,8 @@ enum vdpa_attr {VDPA_ATTR_DEV_NET_CFG_MAX_VQP ,/* u16 */ VDPA_ATTR_DEV_NET_CFG_MTU ,/* u16 */ +VDPA_ATTR_DEV_NEGOTIATED_FEATURES ,/* u64 */ +/* new attributes must be added above here */ VDPA_ATTR_MAX, };vdpa/vdpa.c +47
-0@@ -10,6 +10,7 @@#include <linux/virtio_net.h> #include <linux/netlink.h> #include <libmnl/libmnl.h> +#include <linux/virtio_ring.h> #include "mnl_utils.h" #include <rt_names.h> @@ -78,6 +79,7 @@ static const enum mnl_attr_data_type vdpa_policy[VDPA_ATTR_MAX + 1] = { [VDPA_ATTR_DEV_VENDOR_ID] = MNL_TYPE_U32, [VDPA_ATTR_DEV_MAX_VQS] = MNL_TYPE_U32, [VDPA_ATTR_DEV_MAX_VQ_SIZE] = MNL_TYPE_U16, + [VDPA_ATTR_DEV_NEGOTIATED_FEATURES] = MNL_TYPE_U64, };static int attr_cb (const struct nlattr *attr,void *data)@@ -385,17 +387,120 @@ static const char *parse_class(int num)return class ? class :"< unknown class >" ; } +static const char *const net_feature_strs[64 ] = { + [VIRTIO_NET_F_CSUM ] ="CSUM" , + [VIRTIO_NET_F_GUEST_CSUM ] ="GUEST_CSUM" , + [VIRTIO_NET_F_CTRL_GUEST_OFFLOADS ] ="CTRL_GUEST_OFFLOADS" , + [VIRTIO_NET_F_MTU ] ="MTU" , + [VIRTIO_NET_F_MAC ] ="MAC" , + [VIRTIO_NET_F_GUEST_TSO4 ] ="GUEST_TSO4" , + [VIRTIO_NET_F_GUEST_TSO6 ] ="GUEST_TSO6" , + [VIRTIO_NET_F_GUEST_ECN ] ="GUEST_ECN" , + [VIRTIO_NET_F_GUEST_UFO ] ="GUEST_UFO" , + [VIRTIO_NET_F_HOST_TSO4 ] ="HOST_TSO4" , + [VIRTIO_NET_F_HOST_TSO6 ] ="HOST_TSO6" , + [VIRTIO_NET_F_HOST_ECN ] ="HOST_ECN" , + [VIRTIO_NET_F_HOST_UFO ] ="HOST_UFO" , + [VIRTIO_NET_F_MRG_RXBUF ] ="MRG_RXBUF" , + [VIRTIO_NET_F_STATUS ] ="STATUS" , + [VIRTIO_NET_F_CTRL_VQ ] ="CTRL_VQ" , + [VIRTIO_NET_F_CTRL_RX ] ="CTRL_RX" , + [VIRTIO_NET_F_CTRL_VLAN ] ="CTRL_VLAN" , + [VIRTIO_NET_F_CTRL_RX_EXTRA ] ="CTRL_RX_EXTRA" , + [VIRTIO_NET_F_GUEST_ANNOUNCE ] ="GUEST_ANNOUNCE" , + [VIRTIO_NET_F_MQ ] ="MQ" , + [VIRTIO_F_NOTIFY_ON_EMPTY ] ="NOTIFY_ON_EMPTY" , + [VIRTIO_NET_F_CTRL_MAC_ADDR ] ="CTRL_MAC_ADDR" , + [VIRTIO_F_ANY_LAYOUT ] ="ANY_LAYOUT" , + [VIRTIO_NET_F_RSC_EXT ] ="RSC_EXT" , + [VIRTIO_NET_F_HASH_REPORT ] ="HASH_REPORT" , + [VIRTIO_NET_F_RSS ] ="RSS" , + [VIRTIO_NET_F_STANDBY ] ="STANDBY" , + [VIRTIO_NET_F_SPEED_DUPLEX ] ="SPEED_DUPLEX" , +}; + +#define VIRTIO_F_IN_ORDER 35 +#define VIRTIO_F_NOTIFICATION_DATA 38 +#define VDPA_EXT_FEATURES_SZ (VIRTIO_TRANSPORT_F_END - \ + VIRTIO_TRANSPORT_F_START + 1) + +static const char *const ext_feature_strs[VDPA_EXT_FEATURES_SZ ] = { + [VIRTIO_RING_F_INDIRECT_DESC -VIRTIO_TRANSPORT_F_START ] ="RING_INDIRECT_DESC" , + [VIRTIO_RING_F_EVENT_IDX -VIRTIO_TRANSPORT_F_START ] ="RING_EVENT_IDX" , + [VIRTIO_F_VERSION_1 -VIRTIO_TRANSPORT_F_START ] ="VERSION_1" , + [VIRTIO_F_ACCESS_PLATFORM -VIRTIO_TRANSPORT_F_START ] ="ACCESS_PLATFORM" , + [VIRTIO_F_RING_PACKED -VIRTIO_TRANSPORT_F_START ] ="RING_PACKED" , + [VIRTIO_F_IN_ORDER -VIRTIO_TRANSPORT_F_START ] ="IN_ORDER" , + [VIRTIO_F_ORDER_PLATFORM -VIRTIO_TRANSPORT_F_START ] ="ORDER_PLATFORM" ,
vdpa/vdpa.c static const char *parse_class(int num) · line 444
Quoted 10 lines
vdpa/vdpa.c +10
-0+ [VIRTIO_F_SR_IOV - VIRTIO_TRANSPORT_F_START] = "SR_IOV", + [VIRTIO_F_NOTIFICATION_DATA - VIRTIO_TRANSPORT_F_START] = "NOTIFICATION_DATA", +}; + +static void print_net_features (struct vdpa *vdpa,uint64_t features,bool maxf) +{ +const char *s; +int i; + +if (maxf)
This could use a better name. mgmtdevf maybe?
Quoted 38 lines
vdpa/vdpa.c +38
-0+pr_out_array_start (vdpa,"dev_features" ); + else + pr_out_array_start(vdpa, "negotiated_features"); + +for (i =0 ; i <64 ; i++) { +if (!(features & (1ULL << i))) +continue ; + +if (i >=VIRTIO_TRANSPORT_F_START && i <=VIRTIO_TRANSPORT_F_END ) + s = ext_feature_strs[i -VIRTIO_TRANSPORT_F_START ]; +else + s = net_feature_strs[i]; + +if (!s) +print_uint (PRINT_ANY ,NULL ," unrecognized_bit_%d" , i); +else +print_string (PRINT_ANY ,NULL ," %s" , s); + } +pr_out_array_end (vdpa); +} + +static void print_generic_features (struct vdpa *vdpa,uint64_t features,bool maxf) +{ +const char *s; +int i; + +if (maxf) +pr_out_array_start (vdpa,"dev_features" ); +else +pr_out_array_start (vdpa,"negotiated_features" ); + +for (i =0 ; i <64 ; i++) { +if (!(features & (1ULL << i))) +continue ; + +if (i >=VIRTIO_TRANSPORT_F_START && i <=VIRTIO_TRANSPORT_F_END ) + s = ext_feature_strs[i -VIRTIO_TRANSPORT_F_START ]; +else
vdpa/vdpa.c static const char *parse_class(int num) · line 492
Quoted 10 lines
vdpa/vdpa.c +10
-0+ s =NULL ; + +if (!s) +print_uint (PRINT_ANY ,NULL ," bit_%d" , i); +else +print_string (PRINT_ANY ,NULL ," %s" , s); + } +pr_out_array_end (vdpa); +} +
It looks like most of the implantation in the above two functions are the same and the rest are similar. I wonder if can consolidate into one by adding a virtio type (dev_id) argument? You may create another global static array that helps mapping VIRTIO_ID_NET to net_feature_strs?
Quoted 4 lines
vdpa/vdpa.c +1
-0static void pr_out_mgmtdev_show (struct vdpa *vdpa,const struct nlmsghdr *nlh,struct nlattr **tb) { +uint64_t classes =0 ;
vdpa/vdpa.c static const char *parse_class(int num) · line 504
Quoted 10 lines
vdpa/vdpa.c +1
-2const char *class;unsigned int i;pr_out_handle_start (vdpa, tb);if (tb[VDPA_ATTR_MGMTDEV_SUPPORTED_CLASSES ]) { -uint64_t classes =mnl_attr_get_u64 (tb[VDPA_ATTR_MGMTDEV_SUPPORTED_CLASSES ]); - + classes =mnl_attr_get_u64 (tb[VDPA_ATTR_MGMTDEV_SUPPORTED_CLASSES ]);pr_out_array_start (vdpa,"supported_classes" );
This looks like a minor adjustment to the existing code? Not sure if worth another patch though.
Quoted 19 lines
vdpa/vdpa.c +3
-1for (i =1 ; i <64 ; i++) {@@ -579,9 +684,10 @@ static int cmd_dev_del(struct vdpa *vdpa, int argc, char **argv)return mnlu_gen_socket_sndrcv (&vdpa->nlg, nlh,NULL ,NULL ); } -static void pr_out_dev_net_config (struct nlattr **tb) +static void pr_out_dev_net_config (struct vdpa *vdpa,struct nlattr **tb) {SPRINT_BUF (macaddr); +uint64_t val_u64;uint16_t val_u16;if (tb[VDPA_ATTR_DEV_NET_CFG_MACADDR ]) {@@ -610,6 +716,18 @@ static void pr_out_dev_net_config(struct nlattr **tb) val_u16 =mnl_attr_get_u16 (tb[VDPA_ATTR_DEV_NET_CFG_MTU ]);print_uint (PRINT_ANY ,"mtu" ,"mtu %d " , val_u16); } +if (tb[VDPA_ATTR_DEV_NEGOTIATED_FEATURES ]) {
vdpa/vdpa.c static void pr_out_dev_net_config(struct nlattr **tb) · line 729
Quoted 10 lines
vdpa/vdpa.c +10
-0+uint16_t dev_id =0 ; + +if (tb[VDPA_ATTR_DEV_ID ]) + dev_id =mnl_attr_get_u32 (tb[VDPA_ATTR_DEV_ID ]); + + val_u64 =mnl_attr_get_u64 (tb[VDPA_ATTR_DEV_NEGOTIATED_FEATURES ]); +if (tb[VDPA_ATTR_DEV_NEGOTIATED_FEATURES ] && dev_id ==VIRTIO_ID_NET ) +print_net_features (vdpa, val_u64, false); +else +print_generic_features (vdpa, val_u64, true);
Why the last arg is true? That would output the dev_features line instead.
-Siwei
Quoted 13 lines
vdpa/vdpa.c +2
-1+ } }static void pr_out_dev_config (struct vdpa *vdpa,struct nlattr **tb)@@ -619,7 +737,7 @@ static void pr_out_dev_config(struct vdpa *vdpa, struct nlattr **tb)pr_out_vdev_handle_start (vdpa, tb);switch (device_id) {case VIRTIO_ID_NET : -pr_out_dev_net_config (tb); +pr_out_dev_net_config (vdpa, tb);break ;default :break ;
Re: [PATCH v1 3/4] vdpa: Support for configuring max VQ pairs for a device
In reply to Si-Wei LiuQuoted 70 lines · Si-Wei Liu
Quoted 67 lines · Eli Cohen
Use
VDPA_ATTR_DEV_MGMTDEV_MAX_VQSto specify max number of virtqueue pairs to configure for a vdpa device when adding a device.Examples:
1. Create a device with 3 virtqueue pairs:$ vdpa dev add name vdpa-a mgmtdev auxiliary/mlx5_core.sf.1 max_vqp 32. Read the configuration of a vdpa device
$ vdpa dev config show vdpa-a vdpa-a: mac 00:00:00:00:88:88 link up link_announce false max_vq_pairs 3 \ mtu 1500 negotiated_features CSUM GUEST_CSUM MTU MAC HOST_TSO4 HOST_TSO6 STATUS \ CTRL_VQ MQ CTRL_MAC_ADDR VERSION_1 ACCESS_PLATFORMSigned-off-by Eli Cohen <[email protected]>--- vdpa/include/uapi/linux/vdpa.h | 1 + vdpa/vdpa.c | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-)vdpa/include/uapi/linux/vdpa.h +1
-0@@ -41,6 +41,7 @@ enum vdpa_attr {VDPA_ATTR_DEV_NET_CFG_MTU ,/* u16 */ VDPA_ATTR_DEV_NEGOTIATED_FEATURES ,/* u64 */ +VDPA_ATTR_DEV_MGMTDEV_MAX_VQS ,/* u32 */ /* new attributes must be added above here */ VDPA_ATTR_MAX,vdpa/vdpa.c +6
-0@@ -24,6 +24,7 @@#define VDPA_OPT_VDEV_HANDLE BIT(3)#define VDPA_OPT_VDEV_MAC BIT(4)#define VDPA_OPT_VDEV_MTU BIT(5) +#define VDPA_OPT_MAX_VQP BIT(6)struct vdpa_opts {uint64_t present;/* flags of present items */ @@ -33,6 +34,7 @@ struct vdpa_opts {unsigned int device_id;char mac[ETH_ALEN ];uint16_t mtu; +uint16_t max_vqp; };struct vdpa {@@ -80,6 +82,7 @@ static const enum mnl_attr_data_type vdpa_policy[VDPA_ATTR_MAX + 1] = { [VDPA_ATTR_DEV_MAX_VQS] = MNL_TYPE_U32, [VDPA_ATTR_DEV_MAX_VQ_SIZE] = MNL_TYPE_U16, [VDPA_ATTR_DEV_NEGOTIATED_FEATURES] = MNL_TYPE_U64, + [VDPA_ATTR_DEV_MGMTDEV_MAX_VQS] = MNL_TYPE_U32, };static int attr_cb (const struct nlattr *attr,void *data)@@ -221,6 +224,8 @@ static void vdpa_opts_put(struct nlmsghdr *nlh, struct vdpa *vdpa) sizeof(opts->mac), opts->mac);if (opts->present &VDPA_OPT_VDEV_MTU )mnl_attr_put_u16 (nlh,VDPA_ATTR_DEV_NET_CFG_MTU , opts->mtu); +if (opts->present &VDPA_OPT_MAX_VQP ) +mnl_attr_put_u16 (nlh,VDPA_ATTR_DEV_NET_CFG_MAX_VQP , opts->max_vqp); } static int vdpa_argv_parse(struct vdpa *vdpa, int argc, char **argv,@@ -289,6 +294,14 @@ static int vdpa_argv_parse(struct vdpa *vdpa, int argc, char **argv,NEXT_ARG_FWD (); o_found |=VDPA_OPT_VDEV_MTU ; + }else if ((matches (*argv,"max_vqp" ) ==0 ) && (o_optional &VDPA_OPT_MAX_VQP )) {
Quoted 9 lines
vdpa/vdpa.c static int vdpa_argv_parse(struct vdpa *vdpa, int argc, char **argv, · line 304
Quoted 7 lines
vdpa/vdpa.c +7
-0+NEXT_ARG_FWD (); + err =vdpa_argv_u16 (vdpa, argc, argv, &opts->max_vqp); +if (err) +return err; + +NEXT_ARG_FWD (); + o_found |=VDPA_OPT_MAX_VQP ;It'd be nice to update
cmd_dev_help()to include themax_vqpoption as well.
Will do.
Quoted 29 lines
Reviewed-by Si-Wei Liu <[email protected]>Quoted 26 lines
vdpa/vdpa.c +11
-1}else {fprintf (stderr,"Unknown option \"%s\"\n" , *argv);return -EINVAL ;@@ -513,6 +526,15 @@ static void pr_out_mgmtdev_show(struct vdpa *vdpa, const struct nlmsghdr *nlh,pr_out_array_end (vdpa); } +if (tb[VDPA_ATTR_DEV_MGMTDEV_MAX_VQS ]) { +uint16_t num_vqs; + +if (!vdpa->json_output) +printf ("\n" ); + num_vqs =mnl_attr_get_u16 (tb[VDPA_ATTR_DEV_MGMTDEV_MAX_VQS ]); +print_uint (PRINT_ANY ,"max_supported_vqs" ," max_supported_vqs %d" , num_vqs); + } +pr_out_handle_end (vdpa); }@@ -662,7 +684,8 @@ static int cmd_dev_add(struct vdpa *vdpa, int argc, char **argv) NLM_F_REQUEST | NLM_F_ACK); err =vdpa_argv_parse_put (nlh, vdpa, argc, argv,VDPA_OPT_VDEV_MGMTDEV_HANDLE |VDPA_OPT_VDEV_NAME , -VDPA_OPT_VDEV_MAC |VDPA_OPT_VDEV_MTU ); +VDPA_OPT_VDEV_MAC |VDPA_OPT_VDEV_MTU | +VDPA_OPT_MAX_VQP );if (err)return err;
Re: [PATCH v1 4/4] vdpa: Support reading device features
In reply to Si-Wei LiuQuoted 7 lines · Si-Wei Liu
Quoted 4 lines · Eli Cohen
When showing the available management devices, check if
VDPA_ATTR_DEV_SUPPORTED_FEATURESfeature is available and print the supported features for a management device.
Quoted 9 lines
Quoted 7 lines
Example:
$ vdpa mgmtdev show auxiliary/mlx5_core.sf.1: supported_classes net max_supported_vqs 257 dev_features CSUM GUEST_CSUM MTU HOST_TSO4 HOST_TSO6 STATUS CTRL_VQ MQ \ CTRL_MAC_ADDR VERSION_1 ACCESS_PLATFORMIt'd be nice to add an example output for json pretty format.
Will add
Quoted 46 lines
Reviewed-by Si-Wei Liu <[email protected]>Quoted 43 lines
Signed-off-by Eli Cohen <[email protected]>--- vdpa/include/uapi/linux/vdpa.h | 1 + vdpa/vdpa.c | 11 +++++++++++ 2 files changed, 12 insertions(+)vdpa/include/uapi/linux/vdpa.h +1
-0@@ -42,6 +42,7 @@ enum vdpa_attr {VDPA_ATTR_DEV_NEGOTIATED_FEATURES ,/* u64 */ VDPA_ATTR_DEV_MGMTDEV_MAX_VQS ,/* u32 */ +VDPA_ATTR_DEV_SUPPORTED_FEATURES ,/* u64 */ /* new attributes must be added above here */ VDPA_ATTR_MAX,vdpa/vdpa.c +11
-0@@ -83,6 +83,7 @@ static const enum mnl_attr_data_type vdpa_policy[VDPA_ATTR_MAX + 1] = { [VDPA_ATTR_DEV_MAX_VQ_SIZE] = MNL_TYPE_U16, [VDPA_ATTR_DEV_NEGOTIATED_FEATURES] = MNL_TYPE_U64, [VDPA_ATTR_DEV_MGMTDEV_MAX_VQS] = MNL_TYPE_U32, + [VDPA_ATTR_DEV_SUPPORTED_FEATURES] = MNL_TYPE_U64, };static int attr_cb (const struct nlattr *attr,void *data)@@ -535,6 +536,16 @@ static void pr_out_mgmtdev_show(struct vdpa *vdpa, const struct nlmsghdr *nlh,print_uint (PRINT_ANY ,"max_supported_vqs" ," max_supported_vqs %d" , num_vqs); } +if (tb[VDPA_ATTR_DEV_SUPPORTED_FEATURES ]) { +uint64_t features; + + features =mnl_attr_get_u64 (tb[VDPA_ATTR_DEV_SUPPORTED_FEATURES ]); +if (classes &BIT (VIRTIO_ID_NET )) +print_net_features (vdpa, features, true); +else +print_generic_features (vdpa, features, true); + } +pr_out_handle_end (vdpa); }
Re: [PATCH v1 1/4] vdpa: Remove unsupported command line option
In reply to Si-Wei LiuQuoted 13 lines · Si-Wei Liu
Quoted 10 lines · Eli Cohen
"-v[erbose]" option is not supported.
Remove it.Acked-by Jason Wang <[email protected]>Reviewed-by Jianbo Liu <[email protected]>Signed-off-by Eli Cohen <[email protected]>--- vdpa/vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 11 lines
vdpa/vdpa.c static void help(void) · line 714
Quoted 10 lines
vdpa/vdpa.c +1
-1@@ -711,7 +711,7 @@ static void help(void)fprintf (stderr,"Usage: vdpa [ OPTIONS ] OBJECT { COMMAND | help }\n" "where OBJECT := { mgmtdev | dev }\n" -" OPTIONS := { -V[ersion] | -n[o-nice-names] | -j[son] | -p[retty] | -v[erbose] }\n" ); +" OPTIONS := { -V[ersion] | -n[o-nice-names] | -j[son] | -p[retty] }\n" );Maybe remove -n option that is also unsupported yet?
I didn't notice this. Will review all help messages and fix in a follow up patch.
Quoted 5 lines
Reviewed-by Si-Wei Liu <[email protected]>Quoted 2 lines
vdpa/vdpa.c +0
-0}static int vdpa_cmd (struct vdpa *vdpa,int argc,char **argv)
Re: [PATCH v1 2/4] vdpa: Allow for printing negotiated features of a device
In reply to Si-Wei LiuQuoted 134 lines · Si-Wei Liu
Quoted 131 lines · Eli Cohen
When reading the configuration of a vdpa device, check if the
VDPA_ATTR_DEV_NEGOTIATED_FEATURESis available. If it is, parse the feature bits and print a string representation of each of the feature bits.We keep the strings in two different arrays. One for net device related devices and one for generic feature bits.
In this patch we parse only net device specific features. Support for other devices can be added later. If the device queried is not a net device, we print its bit number only.
Examples:
1.$ vdpa dev config show vdpa-a vdpa-a: mac 00:00:00:00:88:88 link up link_announce false max_vq_pairs 3 \ mtu 1500 negotiated_features CSUM GUEST_CSUM MTU MAC HOST_TSO4 HOST_TSO6 STATUS \ CTRL_VQ MQ CTRL_MAC_ADDR VERSION_1 ACCESS_PLATFORM2. json output
$ vdpa -j dev config show vdpa-a {"config":{"vdpa-a":{"mac":"00:00:00:00:88:88","link":"up","link_announce":false, \ "max_vq_pairs":3,"mtu":1500,"negotiated_features":["CSUM","GUEST_CSUM","MTU", \ "MAC","HOST_TSO4","HOST_TSO6","STATUS","CTRL_VQ","MQ","CTRL_MAC_ADDR", \ "VERSION_1","ACCESS_PLATFORM"]}}}3. pretty json
$ vdpa -jp dev config show vdpa-a { "config": { "vdpa-a": { "mac": "00:00:00:00:88:88", "link ": "up", "link_announce ": false, "max_vq_pairs": 3, "mtu": 1500, "negotiated_features": [ "CSUM","GUEST_CSUM","MTU","MAC","HOST_TSO4","HOST_TSO6","STATUS","CTRL_VQ", \ "MQ","CTRL_MAC_ADDR","VERSION_1","ACCESS_PLATFORM" ] } } }Signed-off-by Eli Cohen <[email protected]>--- vdpa/include/uapi/linux/vdpa.h | 2 + vdpa/vdpa.c | 126 +++++++++++++++++++++++++++++++-- 2 files changed, 124 insertions(+), 4 deletions(-)vdpa/include/uapi/linux/vdpa.h +2
-0@@ -40,6 +40,8 @@ enum vdpa_attr {VDPA_ATTR_DEV_NET_CFG_MAX_VQP ,/* u16 */ VDPA_ATTR_DEV_NET_CFG_MTU ,/* u16 */ +VDPA_ATTR_DEV_NEGOTIATED_FEATURES ,/* u64 */ +/* new attributes must be added above here */ VDPA_ATTR_MAX, };vdpa/vdpa.c +50
-0@@ -10,6 +10,7 @@#include <linux/virtio_net.h> #include <linux/netlink.h> #include <libmnl/libmnl.h> +#include <linux/virtio_ring.h> #include "mnl_utils.h" #include <rt_names.h> @@ -78,6 +79,7 @@ static const enum mnl_attr_data_type vdpa_policy[VDPA_ATTR_MAX + 1] = { [VDPA_ATTR_DEV_VENDOR_ID] = MNL_TYPE_U32, [VDPA_ATTR_DEV_MAX_VQS] = MNL_TYPE_U32, [VDPA_ATTR_DEV_MAX_VQ_SIZE] = MNL_TYPE_U16, + [VDPA_ATTR_DEV_NEGOTIATED_FEATURES] = MNL_TYPE_U64, };static int attr_cb (const struct nlattr *attr,void *data)@@ -385,17 +387,120 @@ static const char *parse_class(int num)return class ? class :"< unknown class >" ; } +static const char *const net_feature_strs[64 ] = { + [VIRTIO_NET_F_CSUM ] ="CSUM" , + [VIRTIO_NET_F_GUEST_CSUM ] ="GUEST_CSUM" , + [VIRTIO_NET_F_CTRL_GUEST_OFFLOADS ] ="CTRL_GUEST_OFFLOADS" , + [VIRTIO_NET_F_MTU ] ="MTU" , + [VIRTIO_NET_F_MAC ] ="MAC" , + [VIRTIO_NET_F_GUEST_TSO4 ] ="GUEST_TSO4" , + [VIRTIO_NET_F_GUEST_TSO6 ] ="GUEST_TSO6" , + [VIRTIO_NET_F_GUEST_ECN ] ="GUEST_ECN" , + [VIRTIO_NET_F_GUEST_UFO ] ="GUEST_UFO" , + [VIRTIO_NET_F_HOST_TSO4 ] ="HOST_TSO4" , + [VIRTIO_NET_F_HOST_TSO6 ] ="HOST_TSO6" , + [VIRTIO_NET_F_HOST_ECN ] ="HOST_ECN" , + [VIRTIO_NET_F_HOST_UFO ] ="HOST_UFO" , + [VIRTIO_NET_F_MRG_RXBUF ] ="MRG_RXBUF" , + [VIRTIO_NET_F_STATUS ] ="STATUS" , + [VIRTIO_NET_F_CTRL_VQ ] ="CTRL_VQ" , + [VIRTIO_NET_F_CTRL_RX ] ="CTRL_RX" , + [VIRTIO_NET_F_CTRL_VLAN ] ="CTRL_VLAN" , + [VIRTIO_NET_F_CTRL_RX_EXTRA ] ="CTRL_RX_EXTRA" , + [VIRTIO_NET_F_GUEST_ANNOUNCE ] ="GUEST_ANNOUNCE" , + [VIRTIO_NET_F_MQ ] ="MQ" , + [VIRTIO_F_NOTIFY_ON_EMPTY ] ="NOTIFY_ON_EMPTY" , + [VIRTIO_NET_F_CTRL_MAC_ADDR ] ="CTRL_MAC_ADDR" , + [VIRTIO_F_ANY_LAYOUT ] ="ANY_LAYOUT" , + [VIRTIO_NET_F_RSC_EXT ] ="RSC_EXT" , + [VIRTIO_NET_F_HASH_REPORT ] ="HASH_REPORT" , + [VIRTIO_NET_F_RSS ] ="RSS" , + [VIRTIO_NET_F_STANDBY ] ="STANDBY" , + [VIRTIO_NET_F_SPEED_DUPLEX ] ="SPEED_DUPLEX" , +}; + +#define VIRTIO_F_IN_ORDER 35 +#define VIRTIO_F_NOTIFICATION_DATA 38 +#define VDPA_EXT_FEATURES_SZ (VIRTIO_TRANSPORT_F_END - \ + VIRTIO_TRANSPORT_F_START + 1) + +static const char *const ext_feature_strs[VDPA_EXT_FEATURES_SZ ] = { + [VIRTIO_RING_F_INDIRECT_DESC -VIRTIO_TRANSPORT_F_START ] ="RING_INDIRECT_DESC" , + [VIRTIO_RING_F_EVENT_IDX -VIRTIO_TRANSPORT_F_START ] ="RING_EVENT_IDX" , + [VIRTIO_F_VERSION_1 -VIRTIO_TRANSPORT_F_START ] ="VERSION_1" , + [VIRTIO_F_ACCESS_PLATFORM -VIRTIO_TRANSPORT_F_START ] ="ACCESS_PLATFORM" , + [VIRTIO_F_RING_PACKED -VIRTIO_TRANSPORT_F_START ] ="RING_PACKED" , + [VIRTIO_F_IN_ORDER -VIRTIO_TRANSPORT_F_START ] ="IN_ORDER" , + [VIRTIO_F_ORDER_PLATFORM -VIRTIO_TRANSPORT_F_START ] ="ORDER_PLATFORM" , + [VIRTIO_F_SR_IOV -VIRTIO_TRANSPORT_F_START ] ="SR_IOV" , + [VIRTIO_F_NOTIFICATION_DATA -VIRTIO_TRANSPORT_F_START ] ="NOTIFICATION_DATA" , +};
Quoted 8 lines
vdpa/vdpa.c static const char *parse_class(int num) · line 444
Quoted 7 lines
vdpa/vdpa.c +7
-0+ +static void print_net_features (struct vdpa *vdpa,uint64_t features,bool maxf) +{ +const char *s; +int i; + +if (maxf)This could use a better name. mgmtdevf maybe?
Will change.
Quoted 44 lines
Quoted 44 lines
vdpa/vdpa.c +44
-0+pr_out_array_start (vdpa,"dev_features" ); + else + pr_out_array_start(vdpa, "negotiated_features"); + +for (i =0 ; i <64 ; i++) { +if (!(features & (1ULL << i))) +continue ; + +if (i >=VIRTIO_TRANSPORT_F_START && i <=VIRTIO_TRANSPORT_F_END ) + s = ext_feature_strs[i -VIRTIO_TRANSPORT_F_START ]; +else + s = net_feature_strs[i]; + +if (!s) +print_uint (PRINT_ANY ,NULL ," unrecognized_bit_%d" , i); +else +print_string (PRINT_ANY ,NULL ," %s" , s); + } +pr_out_array_end (vdpa); +} + +static void print_generic_features (struct vdpa *vdpa,uint64_t features,bool maxf) +{ +const char *s; +int i; + +if (maxf) +pr_out_array_start (vdpa,"dev_features" ); +else +pr_out_array_start (vdpa,"negotiated_features" ); + +for (i =0 ; i <64 ; i++) { +if (!(features & (1ULL << i))) +continue ; + +if (i >=VIRTIO_TRANSPORT_F_START && i <=VIRTIO_TRANSPORT_F_END ) + s = ext_feature_strs[i -VIRTIO_TRANSPORT_F_START ]; +else + s =NULL ; + +if (!s) +print_uint (PRINT_ANY ,NULL ," bit_%d" , i); +else +print_string (PRINT_ANY ,NULL ," %s" , s);
Quoted 9 lines
vdpa/vdpa.c static const char *parse_class(int num) · line 465
Quoted 4 lines
vdpa/vdpa.c +4
-0+ } +pr_out_array_end (vdpa); +} +It looks like most of the implantation in the above two functions are the same and the rest are similar. I wonder if can consolidate into one by adding a virtio type (
dev_id) argument? You may create another global static array that helps mappingVIRTIO_ID_NETtonet_feature_strs?
So maybe just create multidimensional array of to find the string for a device_id/bit number combination and simplify the code above. And for now just populate it for net devices. For undefined just print "bit_n".
Quoted 6 lines
Quoted 6 lines
vdpa/vdpa.c +1
-0static void pr_out_mgmtdev_show (struct vdpa *vdpa,const struct nlmsghdr *nlh,struct nlattr **tb) { +uint64_t classes =0 ;const char *class;unsigned int i;
Quoted 8 lines
vdpa/vdpa.c static const char *parse_class(int num) · line 504
Quoted 6 lines
vdpa/vdpa.c +1
-2pr_out_handle_start (vdpa, tb);if (tb[VDPA_ATTR_MGMTDEV_SUPPORTED_CLASSES ]) { -uint64_t classes =mnl_attr_get_u64 (tb[VDPA_ATTR_MGMTDEV_SUPPORTED_CLASSES ]); - + classes =mnl_attr_get_u64 (tb[VDPA_ATTR_MGMTDEV_SUPPORTED_CLASSES ]);pr_out_array_start (vdpa,"supported_classes" );This looks like a minor adjustment to the existing code? Not sure if worth another patch though.
I will remove it from this patch.
Quoted 20 lines
Quoted 20 lines
vdpa/vdpa.c +6
-1for (i =1 ; i <64 ; i++) {@@ -579,9 +684,10 @@ static int cmd_dev_del(struct vdpa *vdpa, int argc, char **argv)return mnlu_gen_socket_sndrcv (&vdpa->nlg, nlh,NULL ,NULL ); } -static void pr_out_dev_net_config (struct nlattr **tb) +static void pr_out_dev_net_config (struct vdpa *vdpa,struct nlattr **tb) {SPRINT_BUF (macaddr); +uint64_t val_u64;uint16_t val_u16;if (tb[VDPA_ATTR_DEV_NET_CFG_MACADDR ]) {@@ -610,6 +716,18 @@ static void pr_out_dev_net_config(struct nlattr **tb) val_u16 =mnl_attr_get_u16 (tb[VDPA_ATTR_DEV_NET_CFG_MTU ]);print_uint (PRINT_ANY ,"mtu" ,"mtu %d " , val_u16); } +if (tb[VDPA_ATTR_DEV_NEGOTIATED_FEATURES ]) { +uint16_t dev_id =0 ; + +if (tb[VDPA_ATTR_DEV_ID ])
Quoted 9 lines
vdpa/vdpa.c static void pr_out_dev_net_config(struct nlattr **tb) · line 729
Quoted 7 lines
vdpa/vdpa.c +7
-0+ dev_id =mnl_attr_get_u32 (tb[VDPA_ATTR_DEV_ID ]); + + val_u64 =mnl_attr_get_u64 (tb[VDPA_ATTR_DEV_NEGOTIATED_FEATURES ]); +if (tb[VDPA_ATTR_DEV_NEGOTIATED_FEATURES ] && dev_id ==VIRTIO_ID_NET ) +print_net_features (vdpa, val_u64, false); +else +print_generic_features (vdpa, val_u64, true);Why the last arg is true? That would output the
dev_featuresline instead.
Will fix.
Quoted 15 lines
-Siwei
Quoted 12 lines
vdpa/vdpa.c +2
-1+ } }static void pr_out_dev_config (struct vdpa *vdpa,struct nlattr **tb)@@ -619,7 +737,7 @@ static void pr_out_dev_config(struct vdpa *vdpa, struct nlattr **tb)pr_out_vdev_handle_start (vdpa, tb);switch (device_id) {case VIRTIO_ID_NET : -pr_out_dev_net_config (tb); +pr_out_dev_net_config (vdpa, tb);break ;default :break ;
Re: [PATCH v1 2/4] vdpa: Allow for printing negotiated features of a device
Quoted 197 lines · Eli Cohen
Quoted 133 lines · Si-Wei Liu
Quoted 131 lines · Eli Cohen
When reading the configuration of a vdpa device, check if the
VDPA_ATTR_DEV_NEGOTIATED_FEATURESis available. If it is, parse the feature bits and print a string representation of each of the feature bits.We keep the strings in two different arrays. One for net device related devices and one for generic feature bits.
In this patch we parse only net device specific features. Support for other devices can be added later. If the device queried is not a net device, we print its bit number only.
Examples:
1.$ vdpa dev config show vdpa-a vdpa-a: mac 00:00:00:00:88:88 link up link_announce false max_vq_pairs 3 \ mtu 1500 negotiated_features CSUM GUEST_CSUM MTU MAC HOST_TSO4 HOST_TSO6 STATUS \ CTRL_VQ MQ CTRL_MAC_ADDR VERSION_1 ACCESS_PLATFORM2. json output
$ vdpa -j dev config show vdpa-a {"config":{"vdpa-a":{"mac":"00:00:00:00:88:88","link":"up","link_announce":false, \ "max_vq_pairs":3,"mtu":1500,"negotiated_features":["CSUM","GUEST_CSUM","MTU", \ "MAC","HOST_TSO4","HOST_TSO6","STATUS","CTRL_VQ","MQ","CTRL_MAC_ADDR", \ "VERSION_1","ACCESS_PLATFORM"]}}}3. pretty json
$ vdpa -jp dev config show vdpa-a { "config": { "vdpa-a": { "mac": "00:00:00:00:88:88", "link ": "up", "link_announce ": false, "max_vq_pairs": 3, "mtu": 1500, "negotiated_features": [ "CSUM","GUEST_CSUM","MTU","MAC","HOST_TSO4","HOST_TSO6","STATUS","CTRL_VQ", \ "MQ","CTRL_MAC_ADDR","VERSION_1","ACCESS_PLATFORM" ] } } }Signed-off-by Eli Cohen <[email protected]>--- vdpa/include/uapi/linux/vdpa.h | 2 + vdpa/vdpa.c | 126 +++++++++++++++++++++++++++++++-- 2 files changed, 124 insertions(+), 4 deletions(-)vdpa/include/uapi/linux/vdpa.h +2
-0@@ -40,6 +40,8 @@ enum vdpa_attr {VDPA_ATTR_DEV_NET_CFG_MAX_VQP ,/* u16 */ VDPA_ATTR_DEV_NET_CFG_MTU ,/* u16 */ +VDPA_ATTR_DEV_NEGOTIATED_FEATURES ,/* u64 */ +/* new attributes must be added above here */ VDPA_ATTR_MAX, };vdpa/vdpa.c +50
-0@@ -10,6 +10,7 @@#include <linux/virtio_net.h> #include <linux/netlink.h> #include <libmnl/libmnl.h> +#include <linux/virtio_ring.h> #include "mnl_utils.h" #include <rt_names.h> @@ -78,6 +79,7 @@ static const enum mnl_attr_data_type vdpa_policy[VDPA_ATTR_MAX + 1] = { [VDPA_ATTR_DEV_VENDOR_ID] = MNL_TYPE_U32, [VDPA_ATTR_DEV_MAX_VQS] = MNL_TYPE_U32, [VDPA_ATTR_DEV_MAX_VQ_SIZE] = MNL_TYPE_U16, + [VDPA_ATTR_DEV_NEGOTIATED_FEATURES] = MNL_TYPE_U64, };static int attr_cb (const struct nlattr *attr,void *data)@@ -385,17 +387,120 @@ static const char *parse_class(int num)return class ? class :"< unknown class >" ; } +static const char *const net_feature_strs[64 ] = { + [VIRTIO_NET_F_CSUM ] ="CSUM" , + [VIRTIO_NET_F_GUEST_CSUM ] ="GUEST_CSUM" , + [VIRTIO_NET_F_CTRL_GUEST_OFFLOADS ] ="CTRL_GUEST_OFFLOADS" , + [VIRTIO_NET_F_MTU ] ="MTU" , + [VIRTIO_NET_F_MAC ] ="MAC" , + [VIRTIO_NET_F_GUEST_TSO4 ] ="GUEST_TSO4" , + [VIRTIO_NET_F_GUEST_TSO6 ] ="GUEST_TSO6" , + [VIRTIO_NET_F_GUEST_ECN ] ="GUEST_ECN" , + [VIRTIO_NET_F_GUEST_UFO ] ="GUEST_UFO" , + [VIRTIO_NET_F_HOST_TSO4 ] ="HOST_TSO4" , + [VIRTIO_NET_F_HOST_TSO6 ] ="HOST_TSO6" , + [VIRTIO_NET_F_HOST_ECN ] ="HOST_ECN" , + [VIRTIO_NET_F_HOST_UFO ] ="HOST_UFO" , + [VIRTIO_NET_F_MRG_RXBUF ] ="MRG_RXBUF" , + [VIRTIO_NET_F_STATUS ] ="STATUS" , + [VIRTIO_NET_F_CTRL_VQ ] ="CTRL_VQ" , + [VIRTIO_NET_F_CTRL_RX ] ="CTRL_RX" , + [VIRTIO_NET_F_CTRL_VLAN ] ="CTRL_VLAN" , + [VIRTIO_NET_F_CTRL_RX_EXTRA ] ="CTRL_RX_EXTRA" , + [VIRTIO_NET_F_GUEST_ANNOUNCE ] ="GUEST_ANNOUNCE" , + [VIRTIO_NET_F_MQ ] ="MQ" , + [VIRTIO_F_NOTIFY_ON_EMPTY ] ="NOTIFY_ON_EMPTY" , + [VIRTIO_NET_F_CTRL_MAC_ADDR ] ="CTRL_MAC_ADDR" , + [VIRTIO_F_ANY_LAYOUT ] ="ANY_LAYOUT" , + [VIRTIO_NET_F_RSC_EXT ] ="RSC_EXT" , + [VIRTIO_NET_F_HASH_REPORT ] ="HASH_REPORT" , + [VIRTIO_NET_F_RSS ] ="RSS" , + [VIRTIO_NET_F_STANDBY ] ="STANDBY" , + [VIRTIO_NET_F_SPEED_DUPLEX ] ="SPEED_DUPLEX" , +}; + +#define VIRTIO_F_IN_ORDER 35 +#define VIRTIO_F_NOTIFICATION_DATA 38 +#define VDPA_EXT_FEATURES_SZ (VIRTIO_TRANSPORT_F_END - \ + VIRTIO_TRANSPORT_F_START + 1) + +static const char *const ext_feature_strs[VDPA_EXT_FEATURES_SZ ] = { + [VIRTIO_RING_F_INDIRECT_DESC -VIRTIO_TRANSPORT_F_START ] ="RING_INDIRECT_DESC" , + [VIRTIO_RING_F_EVENT_IDX -VIRTIO_TRANSPORT_F_START ] ="RING_EVENT_IDX" , + [VIRTIO_F_VERSION_1 -VIRTIO_TRANSPORT_F_START ] ="VERSION_1" , + [VIRTIO_F_ACCESS_PLATFORM -VIRTIO_TRANSPORT_F_START ] ="ACCESS_PLATFORM" , + [VIRTIO_F_RING_PACKED -VIRTIO_TRANSPORT_F_START ] ="RING_PACKED" , + [VIRTIO_F_IN_ORDER -VIRTIO_TRANSPORT_F_START ] ="IN_ORDER" , + [VIRTIO_F_ORDER_PLATFORM -VIRTIO_TRANSPORT_F_START ] ="ORDER_PLATFORM" , + [VIRTIO_F_SR_IOV -VIRTIO_TRANSPORT_F_START ] ="SR_IOV" , + [VIRTIO_F_NOTIFICATION_DATA -VIRTIO_TRANSPORT_F_START ] ="NOTIFICATION_DATA" , +};Quoted 8 lines
vdpa/vdpa.c static const char *parse_class(int num) · line 444
Quoted 7 lines
vdpa/vdpa.c +7
-0+ +static void print_net_features (struct vdpa *vdpa,uint64_t features,bool maxf) +{ +const char *s; +int i; + +if (maxf)This could use a better name. mgmtdevf maybe?
Will change.
Quoted 44 lines
Quoted 44 lines
vdpa/vdpa.c +44
-0+pr_out_array_start (vdpa,"dev_features" ); + else + pr_out_array_start(vdpa, "negotiated_features"); + +for (i =0 ; i <64 ; i++) { +if (!(features & (1ULL << i))) +continue ; + +if (i >=VIRTIO_TRANSPORT_F_START && i <=VIRTIO_TRANSPORT_F_END ) + s = ext_feature_strs[i -VIRTIO_TRANSPORT_F_START ]; +else + s = net_feature_strs[i]; + +if (!s) +print_uint (PRINT_ANY ,NULL ," unrecognized_bit_%d" , i); +else +print_string (PRINT_ANY ,NULL ," %s" , s); + } +pr_out_array_end (vdpa); +} + +static void print_generic_features (struct vdpa *vdpa,uint64_t features,bool maxf) +{ +const char *s; +int i; + +if (maxf) +pr_out_array_start (vdpa,"dev_features" ); +else +pr_out_array_start (vdpa,"negotiated_features" ); + +for (i =0 ; i <64 ; i++) { +if (!(features & (1ULL << i))) +continue ; + +if (i >=VIRTIO_TRANSPORT_F_START && i <=VIRTIO_TRANSPORT_F_END ) + s = ext_feature_strs[i -VIRTIO_TRANSPORT_F_START ]; +else + s =NULL ; + +if (!s) +print_uint (PRINT_ANY ,NULL ," bit_%d" , i); +else +print_string (PRINT_ANY ,NULL ," %s" , s);Quoted 9 lines
vdpa/vdpa.c static const char *parse_class(int num) · line 465
Quoted 4 lines
vdpa/vdpa.c +4
-0+ } +pr_out_array_end (vdpa); +} +It looks like most of the implantation in the above two functions are the same and the rest are similar. I wonder if can consolidate into one by adding a virtio type (
dev_id) argument? You may create another global static array that helps mappingVIRTIO_ID_NETtonet_feature_strs?
Quoted 3 lines
So maybe just create multidimensional array of to find the string for a device_id/bit number combination and simplify the code above. And for now just populate it for net devices. For undefined just print "
bit_n".
Yeah, that sounds fine, too.
Thanks,
-Siwei
Quoted 60 lines
Quoted 15 lines
vdpa/vdpa.c static const char *parse_class(int num) · line 504
Quoted 13 lines
vdpa/vdpa.c +2
-2static void pr_out_mgmtdev_show (struct vdpa *vdpa,const struct nlmsghdr *nlh,struct nlattr **tb) { +uint64_t classes =0 ;const char *class;unsigned int i;pr_out_handle_start (vdpa, tb);if (tb[VDPA_ATTR_MGMTDEV_SUPPORTED_CLASSES ]) { -uint64_t classes =mnl_attr_get_u64 (tb[VDPA_ATTR_MGMTDEV_SUPPORTED_CLASSES ]); - + classes =mnl_attr_get_u64 (tb[VDPA_ATTR_MGMTDEV_SUPPORTED_CLASSES ]);pr_out_array_start (vdpa,"supported_classes" );This looks like a minor adjustment to the existing code? Not sure if worth another patch though.
I will remove it from this patch.
Quoted 19 lines
Quoted 19 lines
vdpa/vdpa.c +6
-1for (i =1 ; i <64 ; i++) {@@ -579,9 +684,10 @@ static int cmd_dev_del(struct vdpa *vdpa, int argc, char **argv)return mnlu_gen_socket_sndrcv (&vdpa->nlg, nlh,NULL ,NULL ); } -static void pr_out_dev_net_config (struct nlattr **tb) +static void pr_out_dev_net_config (struct vdpa *vdpa,struct nlattr **tb) {SPRINT_BUF (macaddr); +uint64_t val_u64;uint16_t val_u16;if (tb[VDPA_ATTR_DEV_NET_CFG_MACADDR ]) {@@ -610,6 +716,18 @@ static void pr_out_dev_net_config(struct nlattr **tb) val_u16 =mnl_attr_get_u16 (tb[VDPA_ATTR_DEV_NET_CFG_MTU ]);print_uint (PRINT_ANY ,"mtu" ,"mtu %d " , val_u16); } +if (tb[VDPA_ATTR_DEV_NEGOTIATED_FEATURES ]) { +uint16_t dev_id =0 ; + +if (tb[VDPA_ATTR_DEV_ID ])Quoted 9 lines
vdpa/vdpa.c static void pr_out_dev_net_config(struct nlattr **tb) · line 729
Quoted 7 lines
vdpa/vdpa.c +7
-0+ dev_id =mnl_attr_get_u32 (tb[VDPA_ATTR_DEV_ID ]); + + val_u64 =mnl_attr_get_u64 (tb[VDPA_ATTR_DEV_NEGOTIATED_FEATURES ]); +if (tb[VDPA_ATTR_DEV_NEGOTIATED_FEATURES ] && dev_id ==VIRTIO_ID_NET ) +print_net_features (vdpa, val_u64, false); +else +print_generic_features (vdpa, val_u64, true);Why the last arg is true? That would output the
dev_featuresline instead.Will fix.
Quoted 14 lines
-Siwei
Quoted 12 lines
vdpa/vdpa.c +2
-1+ } }static void pr_out_dev_config (struct vdpa *vdpa,struct nlattr **tb)@@ -619,7 +737,7 @@ static void pr_out_dev_config(struct vdpa *vdpa, struct nlattr **tb)pr_out_vdev_handle_start (vdpa, tb);switch (device_id) {case VIRTIO_ID_NET : -pr_out_dev_net_config (tb); +pr_out_dev_net_config (vdpa, tb);break ;default :break ;