Add vdpa device management tool
Subsystems (5)
v5 cover Add vdpa device management tool
Linux vdpa interface allows vdpa device management functionality. This includes adding, removing, querying vdpa devices.
vdpa interface also includes showing supported management devices which support such operations.
This patchset includes kernel uapi headers and a vdpa tool.
examples:
$ vdpa mgmtdev show vdpasim: supported_classes net
$ vdpa mgmtdev show -jp
{
"show": {
"vdpasim": {
"supported_classes": [ "net" ]
}
}
}Create a vdpa device of type networking named as "foo2" from the management device vdpasim_net:
$ vdpa dev add mgmtdev vdpasim_net name foo2
Show the newly created vdpa device by its name:
$ vdpa dev show foo2 foo2: type network mgmtdev vdpasim_net vendor_id 0 max_vqs 2 max_vq_size 256
$ vdpa dev show foo2 -jp
{
"dev": {
"foo2": {
"type": "network",
"mgmtdev": "vdpasim_net",
"vendor_id": 0,
"max_vqs": 2,
"max_vq_size": 256
}
}
}Delete the vdpa device after its use:
$ vdpa dev del foo2
An example of PCI PF, VF and SF management device:
pci/0000:03.00:0
supported_classes
net
pci/0000:03.00:4
supported_classes
net
auxiliary/mlx5_core.sf.8
supported_classes
net
Patch summary:
Patch-1 adds kernel headers for vdpa subsystem Patch-2 adds library routines for indent handling Patch-3 adds library routines for generic socket communication PAtch-4 adds library routine for number to string mapping Patch-5 adds vdpa tool
Kernel headers are from the linux-next [1].
[1] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
---
changelog:v4->v5:
- avoided UAPI prefix in the vdpa.h header file
- updated commit id to commit of linux-next treev3->v4:
- relocated vdpa headers to vdpa/include/uapi/linux
- added new headers path to CFLAGS of vdpa toolv2->v3:
- addressed David's comment to split patch for utils and other parts
- rebased
- using newly added helper routine for number to string mappingv1->v2:
- addressed below comments from David
- added and used library helpers for socket communication
- added and used library functions for string processing helpers
- added and used library functions indent processing helpers
Parav Pandit (5):
Add kernel headers
utils: Add helper routines for indent handling
utils: Add generic socket helpers
utils: Add helper to map string to unsigned int
vdpa: Add vdpa tool
Makefile | 2 +- include/mnl_utils.h | 16 + include/utils.h | 20 +- lib/mnl_utils.c | 121 +++++ lib/utils.c | 83 +++- man/man8/vdpa-dev.8 | 96 ++++ man/man8/vdpa-mgmtdev.8 | 53 +++ man/man8/vdpa.8 | 76 +++ vdpa/Makefile | 25 + vdpa/include/uapi/linux/vdpa.h | 40 ++ vdpa/include/uapi/linux/virtio_ids.h | 58 +++ vdpa/vdpa.c | 675 +++++++++++++++++++++++++++ 12 files changed, 1261 insertions(+), 4 deletions(-) create mode 100644 man/man8/vdpa-dev.8 create mode 100644 man/man8/vdpa-mgmtdev.8 create mode 100644 man/man8/vdpa.8 create mode 100644 vdpa/Makefile create mode 100644 vdpa/include/uapi/linux/vdpa.h create mode 100644 vdpa/include/uapi/linux/virtio_ids.h create mode 100644 vdpa/vdpa.c
Signature · 6 lines
2.26.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v5 1/5 Add kernel headers
Add kernel headers to commit from kernel tree [1].
6acba4951632 ("vdpa_sim_net: Add support for user supported devices")
[1] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
---
changelog:v4->v5:
- avoided UAPI prefix in the vdpa.h header file
- updated commit id to commit of linux-next treev3->v4:
- relocated header files to vdpa/include/uapi/linux
--- vdpa/include/uapi/linux/vdpa.h | 40 +++++++++++++++++++ vdpa/include/uapi/linux/virtio_ids.h | 58 ++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 vdpa/include/uapi/linux/vdpa.h create mode 100644 vdpa/include/uapi/linux/virtio_ids.h
vdpa/include/uapi/linux/vdpa.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +/* +* vdpa device management interface +* Copyright (c) 2020 Mellanox Technologies Ltd. All rights reserved. +*/ + +#ifndef _LINUX_VDPA_H_ +#define _LINUX_VDPA_H_ + +#define VDPA_GENL_NAME "vdpa" +#define VDPA_GENL_VERSION 0x1 + +enum vdpa_command { +VDPA_CMD_UNSPEC , +VDPA_CMD_MGMTDEV_NEW , +VDPA_CMD_MGMTDEV_GET ,/* can dump */ +VDPA_CMD_DEV_NEW , +VDPA_CMD_DEV_DEL , +VDPA_CMD_DEV_GET ,/* can dump */ +}; + +enum vdpa_attr { +VDPA_ATTR_UNSPEC , + +/* bus name (optional) + dev name together make the parent device handle */ +VDPA_ATTR_MGMTDEV_BUS_NAME ,/* string */ +VDPA_ATTR_MGMTDEV_DEV_NAME ,/* string */ +VDPA_ATTR_MGMTDEV_SUPPORTED_CLASSES ,/* u64 */ + +VDPA_ATTR_DEV_NAME ,/* string */ +VDPA_ATTR_DEV_ID ,/* u32 */ +VDPA_ATTR_DEV_VENDOR_ID ,/* u32 */ +VDPA_ATTR_DEV_MAX_VQS ,/* u32 */ +VDPA_ATTR_DEV_MAX_VQ_SIZE ,/* u16 */ + +/* new attributes must be added above here */ +VDPA_ATTR_MAX , +}; + +#endif
vdpa/include/uapi/linux/virtio_ids.h new file +58 -0
58 lines not on this page · raw message
Signature · 6 lines
2.26.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v5 2/5 utils: Add helper routines for indent handling
In reply to Parav PanditSubsequent patch needs to use 2 char indentation for nested objects. Hence introduce a generic helpers to allocate, deallocate, increment, decrement and to print indent block.
---
changelog:v2->v3:
- patch split from vdpa tool patch
--- include/utils.h | 16 ++++++++++++ lib/utils.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+)
include/utils.h +16 -0
@@ -349,4 +349,20 @@ int str_map_lookup_str(const struct str_num_map *map, const char *needle);const char *str_map_lookup_u16 (const struct str_num_map *map,uint16_t val);const char *str_map_lookup_u8 (const struct str_num_map *map,uint8_t val); +unsigned int get_str_char_count (const char *str,int match); +int str_split_by_char (char *str,char **before,char **after,int match); + +#define INDENT_STR_MAXLEN 32 + +struct indent_mem { +int indent_level; +char indent_str[INDENT_STR_MAXLEN +1 ]; +}; + +struct indent_mem *alloc_indent_mem (void ); +void free_indent_mem (struct indent_mem *mem); +void inc_indent (struct indent_mem *mem); +void dec_indent (struct indent_mem *mem); +void print_indent (struct indent_mem *mem); +#endif /* __UTILS_H__ */
lib/utils.c +66 -0
69 lines not on this page · raw message
Signature · 6 lines
2.26.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v5 3/5 utils: Add generic socket helpers
In reply to Parav PanditSubsequent patch needs to
(a) query and use socket family
(b) send/receive messages using this family
Hence add helper routines to open, close, query family and to perform send receive operations.
---
changelog:v2->v3:
- split patch from add vdpa tool for socket helpers
--- include/mnl_utils.h | 16 ++++++ lib/mnl_utils.c | 121 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+)
include/mnl_utils.h +16 -0
@@ -2,6 +2,22 @@#ifndef __MNL_UTILS_H__#define __MNL_UTILS_H__ 1 +struct mnlu_gen_socket { +struct mnl_socket *nl; +char *buf; +uint32_t family; +unsigned int seq; +uint8_t version; +}; + +int mnlu_gen_socket_open (struct mnlu_gen_socket *nlg,const char *family_name, +uint8_t version); +void mnlu_gen_socket_close (struct mnlu_gen_socket *nlg); +struct nlmsghdr *mnlu_gen_socket_cmd_prepare (struct mnlu_gen_socket *nlg, +uint8_t cmd,uint16_t flags); +int mnlu_gen_socket_sndrcv (struct mnlu_gen_socket *nlg,const struct nlmsghdr *nlh, +mnl_cb_t data_cb,void *data); +struct mnl_socket *mnlu_socket_open (int bus);struct nlmsghdr *mnlu_msg_prepare (void *buf,uint32_t nlmsg_type,uint16_t flags,void *extra_header,size_t extra_header_size);
lib/mnl_utils.c +121 -0
130 lines not on this page · raw message
Signature · 6 lines
2.26.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v5 4/5 utils: Add helper to map string to unsigned int
In reply to Parav PanditIn subsequent patch need to map a string to a unsigned int. Hence, add an API to map a string to unsigned int.
---
changelog:v2->v3:
- new patch to reuse string to unsigned int mapping
--- include/utils.h | 4 +++- lib/utils.c | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-)
include/utils.h +3 -1
@@ -342,10 +342,12 @@ int parse_mapping(int *argcp, char ***argvp, bool allow_all,struct str_num_map {const char *str; -int num; +unsigned int num; };int str_map_lookup_str (const struct str_num_map *map,const char *needle); +const char *str_map_lookup_uint (const struct str_num_map *map, +unsigned int val);const char *str_map_lookup_u16 (const struct str_num_map *map,uint16_t val);const char *str_map_lookup_u8 (const struct str_num_map *map,uint8_t val);
lib/utils.c +15 -2
@@ -1953,9 +1953,22 @@ int str_map_lookup_str(const struct str_num_map *map, const char *needle)return -EINVAL ; } +const char *str_map_lookup_uint (const struct str_num_map *map,unsigned int val) +{ +unsigned int num = val; + +while (map && map->str) { +if (num == map->num) +return map->str; + + map++; + } +return NULL ; +} +const char *str_map_lookup_u16 (const struct str_num_map *map,uint16_t val) { -int num = val; +unsigned int num = val;while (map && map->str) {if (num == map->num)
@@ -1968,7 +1981,7 @@ const char *str_map_lookup_u16(const struct str_num_map *map, uint16_t val)const char *str_map_lookup_u8 (const struct str_num_map *map,uint8_t val) { -int num = val; +unsigned int num = val;while (map && map->str) {if (num == map->num)
Signature · 6 lines
2.26.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v5 5/5 vdpa: Add vdpa tool
In reply to Parav Panditvdpa tool is created to create, delete and query vdpa devices. examples:
Show vdpa management device that supports creating, deleting vdpa devices.
$ vdpa mgmtdev show vdpasim: supported_classes net
$ vdpa mgmtdev show -jp
{
"show": {
"vdpasim": {
"supported_classes": [ "net" ]
}
}
}Create a vdpa device of type networking named as "foo2" from the management device vdpasim_net:
$ vdpa dev add mgmtdev vdpasim_net name foo2
Show the newly created vdpa device by its name:
$ vdpa dev show foo2 foo2: type network mgmtdev vdpasim_net vendor_id 0 max_vqs 2 max_vq_size 256
$ vdpa dev show foo2 -jp
{
"dev": {
"foo2": {
"type": "network",
"mgmtdev": "vdpasim_net",
"vendor_id": 0,
"max_vqs": 2,
"max_vq_size": 256
}
}
}Delete the vdpa device after its use:
$ vdpa dev del foo2
---
changelog:v3->v4:
- added new header file path vdpa/include/uapi/linux to CFLAGS
--- Makefile | 2 +- man/man8/vdpa-dev.8 | 96 ++++++ man/man8/vdpa-mgmtdev.8 | 53 ++++ man/man8/vdpa.8 | 76 +++++ vdpa/Makefile | 25 ++ vdpa/vdpa.c | 675 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 926 insertions(+), 1 deletion(-) create mode 100644 man/man8/vdpa-dev.8 create mode 100644 man/man8/vdpa-mgmtdev.8 create mode 100644 man/man8/vdpa.8 create mode 100644 vdpa/Makefile create mode 100644 vdpa/vdpa.c
Makefile +1 -1
@@ -55,7 +55,7 @@ WFLAGS += -Wmissing-declarations -Wold-style-definition -Wformat=2 CFLAGS := $(WFLAGS) $(CCOPTS) -I../include -I../include/uapi $(DEFINES) $(CFLAGS) YACCFLAGS = -d -t -v -SUBDIRS=lib ip tc bridge misc netem genl tipc devlink rdma dcb man +SUBDIRS=lib ip tc bridge misc netem genl tipc devlink rdma dcb man vdpa LIBNETLINK=../lib/libutil.a ../lib/libnetlink.a LDLIBS += $(LIBNETLINK)
man/man8/vdpa-dev.8 new file +96 -0
96 lines not on this page · raw message
man/man8/vdpa-mgmtdev.8 new file +53 -0
53 lines not on this page · raw message
man/man8/vdpa.8 new file +76 -0
76 lines not on this page · raw message
vdpa/Makefile new file +25 -0
@@ -0,0 +1,25 @@ +# SPDX-License-Identifier: GPL-2.0 +include ../config.mk + +TARGETS := + +ifeq ($(HAVE_MNL),y) + +CFLAGS += -I./include/uapi/ +VDPAOBJ = vdpa.o +TARGETS += vdpa + +endif + +all: $(TARGETS) $(LIBS) + +vdpa: $(VDPAOBJ) + $(QUIET_LINK)$(CC) $^ $(LDFLAGS) $(LDLIBS) -o $@ + +install: all + for i in $(TARGETS); \ + do install -m 0755 $$i $(DESTDIR)$(SBINDIR); \ + done + +clean: + rm -f $(VDPAOBJ) $(TARGETS)
vdpa/vdpa.c new file +675 -0
675 lines not on this page · raw message
Signature · 6 lines
2.26.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
David Ahern
AppliedQuoted 8 lines · Parav Pandit
Linux vdpa interface allows vdpa device management functionality. This includes adding, removing, querying vdpa devices.
vdpa interface also includes showing supported management devices which support such operations.
This patchset includes kernel uapi headers and a vdpa tool.
applied to iproute2-next.
I am expecting a followup converting devlink to use the indent and mnl helpers.
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 12 lines
From: David Ahern <[email protected]>
Sent: Thursday, February 11, 2021 9:50 PMQuoted 6 lines · Parav Pandit
Linux vdpa interface allows vdpa device management functionality. This includes adding, removing, querying vdpa devices.
vdpa interface also includes showing supported management devices which support such operations.
Quoted 7 lines
Quoted 2 lines
This patchset includes kernel uapi headers and a vdpa tool.
applied to iproute2-next.
I am expecting a followup converting devlink to use the indent and mnl helpers.
Yes. Thanks David.
I will finish internal review next week and more test to bring here.
_______________________________________________
Virtualization mailing list [email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization