Skip to contentSkip to conversation

Add vdpa device management tool

PATCH Superseded Parav Pandit 4 participants 31 messages Jan 22, 2021 – Feb 10, 2021

Subsystems (5)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

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

Patch summary:
Patch-1 adds kernel headers for vdpa subsystem
Patch-2 adds vdpa tool and its man pages

Kernel headers are from the vhost kernel tree [1] from branch linux-next.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git

Parav Pandit (2):
Add kernel headers
vdpa: Add vdpa tool

 Makefile                        |   2 +-
 include/uapi/linux/vdpa.h       |  40 ++
 include/uapi/linux/virtio_ids.h |  58 +++
 man/man8/vdpa-dev.8             |  96 ++++
 man/man8/vdpa-mgmtdev.8         |  53 ++
 man/man8/vdpa.8                 |  76 +++
 vdpa/Makefile                   |  24 +
 vdpa/vdpa.c                     | 828 ++++++++++++++++++++++++++++++++
 8 files changed, 1176 insertions(+), 1 deletion(-)
 create mode 100644 include/uapi/linux/vdpa.h
 create mode 100644 include/uapi/linux/virtio_ids.h
 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
Signature · 6 lines
2.26.2

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

PATCH 1/2 Add kernel headers

Add kernel headers to commit from kernel tree [1].
79991caf5202c7 ("vdpa_sim_net: Add support for user supported devices")

[1] https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git branch: linux-next

---
 include/uapi/linux/vdpa.h       | 40 +++++++++++++++++++++++
 include/uapi/linux/virtio_ids.h | 58 +++++++++++++++++++++++++++++++++
 2 files changed, 98 insertions(+)
 create mode 100644 include/uapi/linux/vdpa.h
 create mode 100644 include/uapi/linux/virtio_ids.h
include/uapi/linux/vdpa.h new file +40 -0
new file mode 100644
index 00000000..66a41e4e
@@ -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 _UAPI_LINUX_VDPA_H_
+#define _UAPI_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
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
#2 lore raw

PATCH 2/2 vdpa: Add vdpa tool

In reply to Parav Pandit

vdpa 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
---
 Makefile                |   2 +-
 man/man8/vdpa-dev.8     |  96 +++++
 man/man8/vdpa-mgmtdev.8 |  53 +++
 man/man8/vdpa.8         |  76 ++++
 vdpa/Makefile           |  24 ++
 vdpa/vdpa.c             | 828 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 1078 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
index e64c6599..19bd163e 100644
@@ -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 +24 -0
new file mode 100644
index 00000000..275f9ded
@@ -0,0 +1,24 @@
+# SPDX-License-Identifier: GPL-2.0
+include ../config.mk
+
+TARGETS :=
+
+ifeq ($(HAVE_MNL),y)
+
+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 +828 -0

828 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
#3 lore raw

Re: [PATCH iproute2-next 2/2] vdpa: Add vdpa tool

Looks fine. A few comments below around code re-use.

Quoted 17 lines · Parav Pandit
vdpa/vdpa.c new file +11 -0
new file mode 100644
index 00000000..942524b7
@@ -0,0 +1,828 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include <stdio.h>
+#include <getopt.h>
+#include <errno.h>
+#include <linux/genetlink.h>
+#include <linux/vdpa.h>
+#include <linux/virtio_ids.h>
+#include <linux/netlink.h>
+#include <libmnl/libmnl.h>
+#include "mnl_utils.h"

vdpa/vdpa.c line 21

Quoted 10 lines
vdpa/vdpa.c new file +10 -0
+
+#include "version.h"
+#include "json_print.h"
+#include "utils.h"
+
+static int g_indent_level;
+
+#define INDENT_STR_STEP 2
+#define INDENT_STR_MAXLEN 32
+static char g_indent_str[INDENT_STR_MAXLEN + 1] = "";

The indent code has a lot of parallels with devlink -- including helpers below around indent_inc and _dec. Please take a look at how to refactor and re-use.

Quoted 96 lines
vdpa/vdpa.c new file +96 -0
+
+struct vdpa_socket {
+	struct mnl_socket *nl;
+	char *buf;
+	uint32_t family;
+	unsigned int seq;
+};
+
+static int vdpa_socket_sndrcv(struct vdpa_socket *nlg, const struct nlmsghdr *nlh,
+			      mnl_cb_t data_cb, void *data)
+{
+	int err;
+
+	err = mnl_socket_sendto(nlg->nl, nlh, nlh->nlmsg_len);
+	if (err < 0) {
+		perror("Failed to send data");
+		return -errno;
+	}
+
+	err = mnlu_socket_recv_run(nlg->nl, nlh->nlmsg_seq, nlg->buf, MNL_SOCKET_BUFFER_SIZE,
+				   data_cb, data);
+	if (err < 0) {
+		fprintf(stderr, "vdpa answers: %s\n", strerror(errno));
+		return -errno;
+	}
+	return 0;
+}
+
+static int get_family_id_attr_cb(const struct nlattr *attr, void *data)
+{
+	int type = mnl_attr_get_type(attr);
+	const struct nlattr **tb = data;
+
+	if (mnl_attr_type_valid(attr, CTRL_ATTR_MAX) < 0)
+		return MNL_CB_ERROR;
+
+	if (type == CTRL_ATTR_FAMILY_ID &&
+	    mnl_attr_validate(attr, MNL_TYPE_U16) < 0)
+		return MNL_CB_ERROR;
+	tb[type] = attr;
+	return MNL_CB_OK;
+}
+
+static int get_family_id_cb(const struct nlmsghdr *nlh, void *data)
+{
+	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
+	struct nlattr *tb[CTRL_ATTR_MAX + 1] = {};
+	uint32_t *p_id = data;
+
+	mnl_attr_parse(nlh, sizeof(*genl), get_family_id_attr_cb, tb);
+	if (!tb[CTRL_ATTR_FAMILY_ID])
+		return MNL_CB_ERROR;
+	*p_id = mnl_attr_get_u16(tb[CTRL_ATTR_FAMILY_ID]);
+	return MNL_CB_OK;
+}
+
+static int family_get(struct vdpa_socket *nlg)
+{
+	struct genlmsghdr hdr = {};
+	struct nlmsghdr *nlh;
+	int err;
+
+	hdr.cmd = CTRL_CMD_GETFAMILY;
+	hdr.version = 0x1;
+
+	nlh = mnlu_msg_prepare(nlg->buf, GENL_ID_CTRL,
+			       NLM_F_REQUEST | NLM_F_ACK,
+			       &hdr, sizeof(hdr));
+
+	mnl_attr_put_strz(nlh, CTRL_ATTR_FAMILY_NAME, VDPA_GENL_NAME);
+
+	err = mnl_socket_sendto(nlg->nl, nlh, nlh->nlmsg_len);
+	if (err < 0)
+		return err;
+
+	err = mnlu_socket_recv_run(nlg->nl, nlh->nlmsg_seq, nlg->buf,
+				   MNL_SOCKET_BUFFER_SIZE,
+				   get_family_id_cb, &nlg->family);
+	return err;
+}
+
+static int vdpa_socket_open(struct vdpa_socket *nlg)
+{
+	int err;
+
+	nlg->buf = malloc(MNL_SOCKET_BUFFER_SIZE);
+	if (!nlg->buf)
+		goto err_buf_alloc;
+
+	nlg->nl = mnlu_socket_open(NETLINK_GENERIC);
+	if (!nlg->nl)
+		goto err_socket_open;
+
+	err = family_get(nlg);
+	if (err)
+		goto err_socket;

vdpa/vdpa.c line 127

Quoted 10 lines
vdpa/vdpa.c new file +10 -0
+
+	return 0;
+
+err_socket:
+	mnl_socket_close(nlg->nl);
+err_socket_open:
+	free(nlg->buf);
+err_buf_alloc:
+	return -1;
+}

The above 4 functions duplicate a lot of devlink functionality. Please create a helper in lib/mnl_utils.c that can be used in both.

Quoted 105 lines
vdpa/vdpa.c new file +105 -0
+
+static void vdpa_socket_close(struct vdpa_socket *nlg)
+{
+	mnl_socket_close(nlg->nl);
+	free(nlg->buf);
+}
+
+#define VDPA_OPT_MGMTDEV_HANDLE		BIT(0)
+#define VDPA_OPT_VDEV_MGMTDEV_HANDLE	BIT(1)
+#define VDPA_OPT_VDEV_NAME 		BIT(2)
+#define VDPA_OPT_VDEV_HANDLE 		BIT(3)
+
+struct vdpa_opts {
+	uint64_t present; /* flags of present items */
+	const char *mdev_bus_name;
+	const char *mdev_name;
+	const char *vdev_name;
+	unsigned int device_id;
+};
+
+struct vdpa {
+	struct vdpa_socket nlg;
+	struct vdpa_opts opts;
+	bool json_output;
+};
+
+static void indent_inc(void)
+{
+	if (g_indent_level + INDENT_STR_STEP > INDENT_STR_MAXLEN)
+		return;
+	g_indent_level += INDENT_STR_STEP;
+	memset(g_indent_str, ' ', sizeof(g_indent_str));
+	g_indent_str[g_indent_level] = '\0';
+}
+
+static void indent_dec(void)
+{
+	if (g_indent_level - INDENT_STR_STEP < 0)
+		return;
+	g_indent_level -= INDENT_STR_STEP;
+	g_indent_str[g_indent_level] = '\0';
+}
+
+static void indent_print(void)
+{
+	if (g_indent_level)
+		printf("%s", g_indent_str);
+}
+
+static void pr_out_section_start(struct vdpa *vdpa, const char *name)
+{
+	open_json_object(NULL);
+	open_json_object(name);
+}
+
+static void pr_out_section_end(struct vdpa *vdpa)
+{
+	close_json_object();
+	close_json_object();
+}
+
+static void pr_out_array_start(struct vdpa *vdpa, const char *name)
+{
+	if (!vdpa->json_output) {
+		print_nl();
+		indent_inc();
+		indent_print();
+	}
+	open_json_array(PRINT_ANY, name);
+}
+
+static void pr_out_array_end(struct vdpa *vdpa)
+{
+	close_json_array(PRINT_JSON, NULL);
+	if (!vdpa->json_output)
+		indent_dec();
+}
+
+static const enum mnl_attr_data_type vdpa_policy[VDPA_ATTR_MAX + 1] = {
+	[VDPA_ATTR_MGMTDEV_BUS_NAME] = MNL_TYPE_NUL_STRING,
+	[VDPA_ATTR_MGMTDEV_DEV_NAME] = MNL_TYPE_NUL_STRING,
+	[VDPA_ATTR_DEV_NAME] = MNL_TYPE_STRING,
+	[VDPA_ATTR_DEV_ID] = MNL_TYPE_U32,
+	[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,
+};
+
+static int attr_cb(const struct nlattr *attr, void *data)
+{
+	const struct nlattr **tb = data;
+	int type;
+
+	if (mnl_attr_type_valid(attr, VDPA_ATTR_MAX) < 0)
+		return MNL_CB_OK;
+
+	type = mnl_attr_get_type(attr);
+	if (mnl_attr_validate(attr, vdpa_policy[type]) < 0)
+		return MNL_CB_ERROR;
+
+	tb[type] = attr;
+	return MNL_CB_OK;
+}
+
+static unsigned int strslashcount(char *str)

vdpa/vdpa.c line 242

Quoted 10 lines
vdpa/vdpa.c new file +10 -0
+{
+	unsigned int count = 0;
+	char *pos = str;
+
+	while ((pos = strchr(pos, '/'))) {
+		count++;
+		pos++;
+	}
+	return count;
+}

you could make that a generic function (e.g., str_char_count) by passing '/' as an input.

vdpa/vdpa.c line 255

Quoted 13 lines
vdpa/vdpa.c new file +13 -0
+
+static int strslashrsplit(char *str, const char **before, const char **after)
+{
+	char *slash;
+
+	slash = strrchr(str, '/');
+	if (!slash)
+		return -EINVAL;
+	*slash = '\0';
+	*before = str;
+	*after = slash + 1;
+	return 0;
+}

similarly here. If you start with things like this in lib/utils you make it easier for follow on users to find.

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

#4 lore raw

RE: [PATCH iproute2-next 2/2] vdpa: Add vdpa tool

Quoted 30 lines

From: David Ahern <[email protected]>
Sent: Tuesday, January 26, 2021 9:53 AM

Looks fine. A few comments below around code re-use.

Quoted 22 lines · Parav Pandit
vdpa/vdpa.c new file mode 100644 index renamed from vdpa/vdpa.c +0 -0

00000000..942524b7

vdpa/vdpa.c new file +17 -0
@@ -0,0 +1,828 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include <stdio.h>
+#include <getopt.h>
+#include <errno.h>
+#include <linux/genetlink.h>
+#include <linux/vdpa.h>
+#include <linux/virtio_ids.h>
+#include <linux/netlink.h>
+#include <libmnl/libmnl.h>
+#include "mnl_utils.h"
+
+#include "version.h"
+#include "json_print.h"
+#include "utils.h"
+
+static int g_indent_level;
Quoted 9 lines

vdpa/vdpa.c line 21

Quoted 4 lines
vdpa/vdpa.c new file +4 -0
+
+#define INDENT_STR_STEP 2
+#define INDENT_STR_MAXLEN 32
+static char g_indent_str[INDENT_STR_MAXLEN + 1] = "";

The indent code has a lot of parallels with devlink -- including helpers below around indent_inc and _dec. Please take a look at how to refactor and re- use.

Ok. Devlink has some more convoluted code with next line etc.
But I will see if I can consolidate without changing the devlink's flow/logic.

Quoted 100 lines

vdpa/vdpa.c

Quoted 9 lines
vdpa/vdpa.c new file +9 -0
+
+struct vdpa_socket {
+	struct mnl_socket *nl;
+	char *buf;
+	uint32_t family;
+	unsigned int seq;
+};
+
+static int vdpa_socket_sndrcv(struct vdpa_socket *nlg, const struct

nlmsghdr *nlh,

vdpa/vdpa.c line 97

Quoted 10 lines
vdpa/vdpa.c new file +10 -0
+			      mnl_cb_t data_cb, void *data) {
+	int err;
+
+	err = mnl_socket_sendto(nlg->nl, nlh, nlh->nlmsg_len);
+	if (err < 0) {
+		perror("Failed to send data");
+		return -errno;
+	}
+
+	err = mnlu_socket_recv_run(nlg->nl, nlh->nlmsg_seq, nlg->buf,

MNL_SOCKET_BUFFER_SIZE,

Quoted 38 lines
vdpa/vdpa.c new file +38 -0
+				   data_cb, data);
+	if (err < 0) {
+		fprintf(stderr, "vdpa answers: %s\n", strerror(errno));
+		return -errno;
+	}
+	return 0;
+}
+
+static int get_family_id_attr_cb(const struct nlattr *attr, void
+*data) {
+	int type = mnl_attr_get_type(attr);
+	const struct nlattr **tb = data;
+
+	if (mnl_attr_type_valid(attr, CTRL_ATTR_MAX) < 0)
+		return MNL_CB_ERROR;
+
+	if (type == CTRL_ATTR_FAMILY_ID &&
+	    mnl_attr_validate(attr, MNL_TYPE_U16) < 0)
+		return MNL_CB_ERROR;
+	tb[type] = attr;
+	return MNL_CB_OK;
+}
+
+static int get_family_id_cb(const struct nlmsghdr *nlh, void *data) {
+	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
+	struct nlattr *tb[CTRL_ATTR_MAX + 1] = {};
+	uint32_t *p_id = data;
+
+	mnl_attr_parse(nlh, sizeof(*genl), get_family_id_attr_cb, tb);
+	if (!tb[CTRL_ATTR_FAMILY_ID])
+		return MNL_CB_ERROR;
+	*p_id = mnl_attr_get_u16(tb[CTRL_ATTR_FAMILY_ID]);
+	return MNL_CB_OK;
+}
+
+static int family_get(struct vdpa_socket *nlg) {
+	struct genlmsghdr hdr = {};
+	struct nlmsghdr *nlh;

vdpa/vdpa.c

Quoted 10 lines
vdpa/vdpa.c new file +10 -0
+	int err;
+
+	hdr.cmd = CTRL_CMD_GETFAMILY;
+	hdr.version = 0x1;
+
+	nlh = mnlu_msg_prepare(nlg->buf, GENL_ID_CTRL,
+			       NLM_F_REQUEST | NLM_F_ACK,
+			       &hdr, sizeof(hdr));
+
+	mnl_attr_put_strz(nlh, CTRL_ATTR_FAMILY_NAME,

VDPA_GENL_NAME);

Quoted 30 lines
vdpa/vdpa.c new file +30 -0
+
+	err = mnl_socket_sendto(nlg->nl, nlh, nlh->nlmsg_len);
+	if (err < 0)
+		return err;
+
+	err = mnlu_socket_recv_run(nlg->nl, nlh->nlmsg_seq, nlg->buf,
+				   MNL_SOCKET_BUFFER_SIZE,
+				   get_family_id_cb, &nlg->family);
+	return err;
+}
+
+static int vdpa_socket_open(struct vdpa_socket *nlg) {
+	int err;
+
+	nlg->buf = malloc(MNL_SOCKET_BUFFER_SIZE);
+	if (!nlg->buf)
+		goto err_buf_alloc;
+
+	nlg->nl = mnlu_socket_open(NETLINK_GENERIC);
+	if (!nlg->nl)
+		goto err_socket_open;
+
+	err = family_get(nlg);
+	if (err)
+		goto err_socket;
+
+	return 0;
+
+err_socket:
+	mnl_socket_close(nlg->nl);
Quoted 9 lines

vdpa/vdpa.c line 127

Quoted 5 lines
vdpa/vdpa.c new file +5 -0
+err_socket_open:
+	free(nlg->buf);
+err_buf_alloc:
+	return -1;
+}

The above 4 functions duplicate a lot of devlink functionality. Please create a helper in lib/mnl_utils.c that can be used in both.

Will do.

Quoted 6 lines
Quoted 6 lines
vdpa/vdpa.c new file +6 -0
+
+static unsigned int strslashcount(char *str) {
+	unsigned int count = 0;
+	char *pos = str;
+
+	while ((pos = strchr(pos, '/'))) {
Quoted 9 lines

vdpa/vdpa.c line 242

Quoted 5 lines
vdpa/vdpa.c new file +5 -0
+		count++;
+		pos++;
+	}
+	return count;
+}

you could make that a generic function (e.g., str_char_count) by passing '/' as an input.

Yes.

Quoted 8 lines
Quoted 8 lines
vdpa/vdpa.c new file +8 -0
+
+static int strslashrsplit(char *str, const char **before, const char
+**after) {
+	char *slash;
+
+	slash = strrchr(str, '/');
+	if (!slash)
+		return -EINVAL;
Quoted 9 lines

vdpa/vdpa.c line 255

Quoted 5 lines
vdpa/vdpa.c new file +5 -0
+	*slash = '\0';
+	*before = str;
+	*after = slash + 1;
+	return 0;
+}

similarly here. If you start with things like this in lib/utils you make it easier for follow on users to find.

Will do.
Thanks for the review.
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#5 lore raw

v2 cover Add vdpa device management tool

In reply to 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.

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

Patch summary:
Patch-1 adds kernel headers for vdpa subsystem
Patch-2 adds vdpa tool along with helper library routines and man pages

Kernel headers are from the vhost kernel tree [1] from branch linux-next.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git

---
changelog:
v1->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 (2):
Add kernel headers
vdpa: Add vdpa tool

 Makefile                        |   2 +-
 include/mnl_utils.h             |  16 +
 include/uapi/linux/vdpa.h       |  40 ++
 include/uapi/linux/virtio_ids.h |  58 +++
 include/utils.h                 |  16 +
 lib/mnl_utils.c                 | 121 ++++++
 lib/utils.c                     |  66 ++++
 man/man8/vdpa-dev.8             |  96 +++++
 man/man8/vdpa-mgmtdev.8         |  53 +++
 man/man8/vdpa.8                 |  76 ++++
 vdpa/Makefile                   |  24 ++
 vdpa/vdpa.c                     | 669 ++++++++++++++++++++++++++++++++
 12 files changed, 1236 insertions(+), 1 deletion(-)
 create mode 100644 include/uapi/linux/vdpa.h
 create mode 100644 include/uapi/linux/virtio_ids.h
 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
Signature · 6 lines
2.26.2

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

PATCH v2 1/2 Add kernel headers

Add kernel headers to commit from kernel tree [1].
79991caf5202c7 ("vdpa_sim_net: Add support for user supported devices")

[1] https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git branch: linux-next

---
 include/uapi/linux/vdpa.h       | 40 +++++++++++++++++++++++
 include/uapi/linux/virtio_ids.h | 58 +++++++++++++++++++++++++++++++++
 2 files changed, 98 insertions(+)
 create mode 100644 include/uapi/linux/vdpa.h
 create mode 100644 include/uapi/linux/virtio_ids.h
include/uapi/linux/vdpa.h new file +40 -0
new file mode 100644
index 00000000..66a41e4e
@@ -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 _UAPI_LINUX_VDPA_H_
+#define _UAPI_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
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
#7 lore raw

PATCH v2 2/2 vdpa: Add vdpa tool

In reply to Parav Pandit

vdpa 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:
v1->v2:
- 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

---
 Makefile                |   2 +-
 include/mnl_utils.h     |  16 +
 include/utils.h         |  16 +
 lib/mnl_utils.c         | 121 ++++++++
 lib/utils.c             |  66 ++++
 man/man8/vdpa-dev.8     |  96 ++++++
 man/man8/vdpa-mgmtdev.8 |  53 ++++
 man/man8/vdpa.8         |  76 +++++
 vdpa/Makefile           |  24 ++
 vdpa/vdpa.c             | 669 ++++++++++++++++++++++++++++++++++++++++
 10 files changed, 1138 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
index e64c6599..19bd163e 100644
@@ -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)
include/mnl_utils.h +16 -0
index fa826ef1..9e7d6879 100644
@@ -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);
include/utils.h +16 -0
index f1403f73..a35e5103 100644
@@ -340,4 +340,20 @@ int parse_mapping(int *argcp, char ***argvp, bool allow_all,
 		  int (*mapping_cb)(__u32 key, char *value, void *data),
 		  void *mapping_cb_data);
 
+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/mnl_utils.c +121 -0

130 lines not on this page · raw message

lib/utils.c +66 -0

69 lines not on this page · raw message

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 +24 -0
new file mode 100644
index 00000000..275f9ded
@@ -0,0 +1,24 @@
+# SPDX-License-Identifier: GPL-2.0
+include ../config.mk
+
+TARGETS :=
+
+ifeq ($(HAVE_MNL),y)
+
+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 +669 -0

669 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
#8 lore raw

RE: [PATCH iproute2-next v2 2/2] vdpa: Add vdpa tool

Hi David,

Quoted 2 lines

From: Parav Pandit <[email protected]>
Sent: Friday, January 29, 2021 12:13 AM

[..]

Quoted 6 lines

---
changelog:
v1->v2:
- 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

I have converted devlink to also using string processing and socket helpers and initial round of test. However it needs more testing.
And I patchset for devlink subfunction plumbing in direct conflict with this new socket APIs. So I will finish devlink conversion to use library routines post taking care of the subfunction.
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#9 lore raw

v3 cover Add vdpa device management tool

In reply to 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.

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

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 vhost kernel tree [1] from branch linux-next.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git

---
changelog:
v2->v3:
- addressed David's comment to split patch for utils and other parts
- rebased
- using newly added helper routine for number to string mapping
v1->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/uapi/linux/vdpa.h       |  40 ++
 include/uapi/linux/virtio_ids.h |  58 +++
 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                   |  24 ++
 vdpa/vdpa.c                     | 675 ++++++++++++++++++++++++++++++++
 12 files changed, 1260 insertions(+), 4 deletions(-)
 create mode 100644 include/uapi/linux/vdpa.h
 create mode 100644 include/uapi/linux/virtio_ids.h
 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
Signature · 6 lines
2.26.2

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

PATCH v3 1/5 Add kernel headers

Add kernel headers to commit from kernel tree [1].
79991caf5202c7 ("vdpa_sim_net: Add support for user supported devices")

[1] https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git branch: linux-next

---
 include/uapi/linux/vdpa.h       | 40 +++++++++++++++++++++++
 include/uapi/linux/virtio_ids.h | 58 +++++++++++++++++++++++++++++++++
 2 files changed, 98 insertions(+)
 create mode 100644 include/uapi/linux/vdpa.h
 create mode 100644 include/uapi/linux/virtio_ids.h
include/uapi/linux/vdpa.h new file +40 -0
new file mode 100644
index 00000000..66a41e4e
@@ -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 _UAPI_LINUX_VDPA_H_
+#define _UAPI_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
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
#11 lore raw

Re: [PATCH iproute2-next v3 1/5] Add kernel headers

Quoted 5 lines · Parav Pandit

Add kernel headers to commit from kernel tree [1].
79991caf5202c7 ("vdpa_sim_net: Add support for user supported devices")

[1] https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git branch: linux-next

Thinking about this flow a bit more: If new features to uapi/linux/vdpa.h are coming through Michael's tree which is not sent via net-next, then I think this header needs to be managed like the rdma uapi files. In that case it should be added to iproute2 as vdpa/include/uapi/linux and you / vdpa dev's will be responsible for managing updates. In general, this should not be a trend, but seems to be needed since vdpa is more than just a networking tool.

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

#12 lore raw

RE: [PATCH iproute2-next v3 1/5] Add kernel headers

Quoted 14 lines

From: David Ahern <[email protected]>
Sent: Thursday, February 4, 2021 7:07 AM

Quoted 7 lines · Parav Pandit

Add kernel headers to commit from kernel tree [1].
79991caf5202c7 ("vdpa_sim_net: Add support for user supported
devices")

[1] https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git
branch: linux-next

Quoted 6 lines

Thinking about this flow a bit more: If new features to uapi/linux/vdpa.h are coming through Michael's tree which is not sent via net-next, then I think this header needs to be managed like the rdma uapi files. In that case it should be added to iproute2 as vdpa/include/uapi/linux and you / vdpa dev's will be responsible for managing updates. In general, this should not be a trend, but seems to be needed since vdpa is more than just a networking tool.

Ok. Sending v4 to relocate it to the recommended directory. Thanks.
_______________________________________________
Virtualization mailing list [email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#13 lore raw

PATCH v3 2/5 utils: Add helper routines for indent handling

In reply to Parav Pandit

Subsequent 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
index e66090ae..9b76c92a 100644
@@ -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
#14 lore raw

PATCH v3 3/5 utils: Add generic socket helpers

In reply to Parav Pandit

Subsequent 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
index fa826ef1..9e7d6879 100644
@@ -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
#15 lore raw

PATCH v3 4/5 utils: Add helper to map string to unsigned int

In reply to Parav Pandit

In 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
index 9b76c92a..b29c3798 100644
@@ -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
index cc6d0e34..633f6359 100644
@@ -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
#16 lore raw

PATCH v3 5/5 vdpa: Add vdpa tool

In reply to Parav Pandit

vdpa 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
---
 Makefile                |   2 +-
 man/man8/vdpa-dev.8     |  96 ++++++
 man/man8/vdpa-mgmtdev.8 |  53 ++++
 man/man8/vdpa.8         |  76 +++++
 vdpa/Makefile           |  24 ++
 vdpa/vdpa.c             | 675 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 925 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
index e64c6599..19bd163e 100644
@@ -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 +24 -0
new file mode 100644
index 00000000..275f9ded
@@ -0,0 +1,24 @@
+# SPDX-License-Identifier: GPL-2.0
+include ../config.mk
+
+TARGETS :=
+
+ifeq ($(HAVE_MNL),y)
+
+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
#17 lore raw
In reply to Parav Pandit
Quoted 55 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.

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

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

Quoted 5 lines

Kernel headers are from the vhost kernel tree [1] from branch linux-next.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git

---

Adding Adrian to see if this looks good for k8s integration.

Thanks

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

#18 lore raw

Sorry I have not followed this work as close as I would have wanted. Some questions below.

Quoted 16 lines · Jason Wang
Quoted 14 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.

examples:

$ vdpa mgmtdev show
vdpasim:
   supported_classes net
Quoted 9 lines
Quoted 9 lines
$ vdpa mgmtdev show -jp
{
     "show": {
         "vdpasim": {
             "supported_classes": [ "net" ]
         }
     }
}

How can a user establish the relationship between a mgmtdev and it's parent device (pci vf, sf, etc)?

Quoted 5 lines
Quoted 5 lines

Create a vdpa device of type networking named as "foo2" from the management device vdpasim_net:

$ vdpa dev add mgmtdev vdpasim_net name foo2

I guess this command will accept a 'type' parameter once more supported_classes are added?

Also, will this tool also handle the vdpa driver binding or will the user handle that through the vdpa bus' sysfs interface?

Quoted 29 lines
Quoted 29 lines

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

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 vhost kernel tree [1] from branch linux-next.

Quoted 9 lines
Quoted 3 lines

[1] https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git

---

Adding Adrian to see if this looks good for k8s integration.

Thanks

Thanks

Signature · 6 lines
Adrián Moreno

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#19 lore raw
Quoted 28 lines · Adrian Moreno

Sorry I have not followed this work as close as I would have wanted. Some questions below.

Quoted 15 lines · Jason Wang
Quoted 14 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.

examples:

$ vdpa mgmtdev show
vdpasim:
    supported_classes net
Quoted 9 lines
Quoted 9 lines
$ vdpa mgmtdev show -jp
{
      "show": {
          "vdpasim": {
              "supported_classes": [ "net" ]
          }
      }
}
Quoted 2 lines

How can a user establish the relationship between a mgmtdev and it's parent device (pci vf, sf, etc)?

Parav should know more but I try to answer.

I think there should be BDF information in the mgmtdev show command if the parent is a PCI device, or we can simply show the parent here?

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

Create a vdpa device of type networking named as "foo2" from the management device vdpasim_net:

$ vdpa dev add mgmtdev vdpasim_net name foo2

I guess this command will accept a 'type' parameter once more supported_classes are added?

This could be extended in the future.

Quoted 3 lines

Also, will this tool also handle the vdpa driver binding or will the user handle that through the vdpa bus' sysfs interface?

I think not, it's the configuration below the vdpa bus. The sysfs should be the only interface for managing driver binding.

Thanks

Quoted 32 lines
Quoted 32 lines
Quoted 32 lines

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

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 vhost kernel tree [1] from branch linux-next.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

---

Adding Adrian to see if this looks good for k8s integration.

Thanks

Thanks

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

#20 lore raw
Quoted 35 lines

From: Jason Wang <[email protected]>
Sent: Friday, February 5, 2021 9:11 AM

Quoted 28 lines · Adrian Moreno

Sorry I have not followed this work as close as I would have wanted. Some questions below.

Quoted 24 lines · Jason Wang
Quoted 23 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.

examples:

$ vdpa mgmtdev show
vdpasim:
    supported_classes net
$ vdpa mgmtdev show -jp
{
      "show": {
          "vdpasim": {
              "supported_classes": [ "net" ]
          }
      }
}
Quoted 9 lines
Quoted 2 lines

How can a user establish the relationship between a mgmtdev and it's parent device (pci vf, sf, etc)?

Parav should know more but I try to answer.

I think there should be BDF information in the mgmtdev show command if the parent is a PCI device, or we can simply show the parent here?

Yes, it is present in the mgmtdev show command.
I should have added the example from the kernel cover letter here. Link to the kernel cover letter is at

An example for real PCI PF,VF,SF device looks like below.
I will cover below example to the v4 cover letter while addressing David's comment for header file relocation.

$ vdpa mgmtdev list
pci/0000:03.00:0
  supported_classes
    net
pci/0000:03.00:4
  supported_classes
    net
auxiliary/mlx5_core.sf.8
  supported_classes
    net

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

#21 lore raw
Quoted 62 lines · Parav Pandit
Quoted 35 lines

From: Jason Wang <[email protected]>
Sent: Friday, February 5, 2021 9:11 AM

Quoted 28 lines · Adrian Moreno

Sorry I have not followed this work as close as I would have wanted. Some questions below.

Quoted 24 lines · Jason Wang
Quoted 23 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.

examples:

$ vdpa mgmtdev show
vdpasim:
    supported_classes net
$ vdpa mgmtdev show -jp
{
      "show": {
          "vdpasim": {
              "supported_classes": [ "net" ]
          }
      }
}
Quoted 9 lines
Quoted 2 lines

How can a user establish the relationship between a mgmtdev and it's parent device (pci vf, sf, etc)?

Parav should know more but I try to answer.

I think there should be BDF information in the mgmtdev show command if the parent is a PCI device, or we can simply show the parent here?

Yes, it is present in the mgmtdev show command.
I should have added the example from the kernel cover letter here. Link to the kernel cover letter is at

An example for real PCI PF,VF,SF device looks like below.
I will cover below example to the v4 cover letter while addressing David's comment for header file relocation.

$ vdpa mgmtdev list
pci/0000:03.00:0
  supported_classes
    net
pci/0000:03.00:4
  supported_classes
    net
auxiliary/mlx5_core.sf.8
  supported_classes
    net
Quoted 2 lines

[1] https://lore.kernel.org/netdev/[email protected]/

Thanks Parav

Signature · 6 lines
Adrián Moreno

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#22 lore raw
In reply to Jason Wang
Quoted 54 lines · Jason Wang
Quoted 28 lines · Adrian Moreno

Sorry I have not followed this work as close as I would have wanted. Some questions below.

Quoted 15 lines · Jason Wang
Quoted 14 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.

examples:

$ vdpa mgmtdev show
vdpasim:
    supported_classes net
Quoted 9 lines
Quoted 9 lines
$ vdpa mgmtdev show -jp
{
      "show": {
          "vdpasim": {
              "supported_classes": [ "net" ]
          }
      }
}
Quoted 2 lines

How can a user establish the relationship between a mgmtdev and it's parent device (pci vf, sf, etc)?

Parav should know more but I try to answer.

I think there should be BDF information in the mgmtdev show command if the parent is a PCI device, or we can simply show the parent here?

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

Create a vdpa device of type networking named as "foo2" from the management device vdpasim_net:

$ vdpa dev add mgmtdev vdpasim_net name foo2

I guess this command will accept a 'type' parameter once more supported_classes are added?

This could be extended in the future.

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

Also, will this tool also handle the vdpa driver binding or will the user handle that through the vdpa bus' sysfs interface?

I think not, it's the configuration below the vdpa bus. The sysfs should be the only interface for managing driver binding.

Understood, thanks.

Signature · 6 lines
Adrián Moreno

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

v4 cover Add vdpa device management tool

In reply to 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.

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 vhost kernel tree [1] from branch linux-next.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git

---
changelog:
v3->v4:
- relocated vdpa headers to vdpa/include/uapi/linux
- added new headers path to CFLAGS of vdpa tool
v2->v3:
- addressed David's comment to split patch for utils and other parts
- rebased
- using newly added helper routine for number to string mapping
v1->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
#24 lore raw

PATCH v4 1/5 Add kernel headers

Add kernel headers to commit from kernel tree [1].
79991caf5202c7 ("vdpa_sim_net: Add support for user supported devices")

[1] https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git branch: linux-next

---
 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
new file mode 100644
index 00000000..66a41e4e
@@ -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 _UAPI_LINUX_VDPA_H_
+#define _UAPI_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
#25 lore raw

Re: [PATCH iproute2-next v4 1/5] Add kernel headers

Quoted 6 lines · Parav Pandit
vdpa/include/uapi/linux/vdpa.h new file +0 -0
new file mode 100644
index 00000000..66a41e4e

vdpa/include/uapi/linux/vdpa.h line 9

Quoted 9 lines
vdpa/include/uapi/linux/vdpa.h new file +9 -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 _UAPI_LINUX_VDPA_H_
+#define _UAPI_LINUX_VDPA_H_
+

you should grab this header after a 'make headers_install' which cleans up the _UAPI prefix.

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

#26 lore raw

RE: [PATCH iproute2-next v4 1/5] Add kernel headers

Quoted 16 lines

From: David Ahern <[email protected]>
Sent: Monday, February 8, 2021 9:18 PM

Quoted 10 lines · Parav Pandit
(quoted diff) +0 -0

b/vdpa/include/uapi/linux/vdpa.h new file mode 100644 index 00000000..66a41e4e

vdpa/include/uapi/linux/vdpa.h new file +4 -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.
Quoted 8 lines

vdpa/include/uapi/linux/vdpa.h line 9

Quoted 5 lines
vdpa/include/uapi/linux/vdpa.h new file +5 -0
+ */
+
+#ifndef _UAPI_LINUX_VDPA_H_
+#define _UAPI_LINUX_VDPA_H_
+

you should grab this header after a 'make headers_install' which cleans up the _UAPI prefix.

Ah right.
Fixing it now.
Also updating the pointer to linux-next which has this patchset instead of Michaels tree.

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

#27 lore raw

PATCH v4 2/5 utils: Add helper routines for indent handling

In reply to Parav Pandit

Subsequent 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
index e66090ae..9b76c92a 100644
@@ -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
#28 lore raw

PATCH v4 3/5 utils: Add generic socket helpers

In reply to Parav Pandit

Subsequent 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
index fa826ef1..9e7d6879 100644
@@ -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
#29 lore raw

PATCH v4 4/5 utils: Add helper to map string to unsigned int

In reply to Parav Pandit

In 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
index 9b76c92a..b29c3798 100644
@@ -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
index cc6d0e34..633f6359 100644
@@ -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
#30 lore raw

PATCH v4 5/5 vdpa: Add vdpa tool

In reply to Parav Pandit

vdpa 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
---
 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
index e64c6599..19bd163e 100644
@@ -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
new file mode 100644
index 00000000..253e20a7
@@ -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