DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Xing, Beilei" <beilei.xing@intel.com>
To: "Xia, Chenbo" <chenbo.xia@intel.com>,
	"dev@dpdk.org" <dev@dpdk.org>,
	"thomas@monjalon.net" <thomas@monjalon.net>,
	"david.marchand@redhat.com" <david.marchand@redhat.com>
Cc: "stephen@networkplumber.org" <stephen@networkplumber.org>,
	"Liang, Cunming" <cunming.liang@intel.com>,
	"Lu, Xiuchun" <xiuchun.lu@intel.com>,
	"Li, Miao" <miao.li@intel.com>,
	"Wu, Jingjing" <jingjing.wu@intel.com>
Subject: Re: [dpdk-dev] [PATCH 3/9] vfio_user: implement device and region	related APIs
Date: Wed, 6 Jan 2021 05:51:42 +0000	[thread overview]
Message-ID: <MN2PR11MB38078A574697E0B0192F5D71F7D00@MN2PR11MB3807.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20201218073851.93609-4-chenbo.xia@intel.com>



> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Chenbo Xia
> Sent: Friday, December 18, 2020 3:39 PM
> To: dev@dpdk.org; thomas@monjalon.net; david.marchand@redhat.com
> Cc: stephen@networkplumber.org; Liang, Cunming
> <cunming.liang@intel.com>; Lu, Xiuchun <xiuchun.lu@intel.com>; Li, Miao
> <miao.li@intel.com>; Wu, Jingjing <jingjing.wu@intel.com>
> Subject: [dpdk-dev] [PATCH 3/9] vfio_user: implement device and region
> related APIs
> 
> This patch introduces device and region related APIs, which are
> rte_vfio_user_set_dev_info() and rte_vfio_user_set_reg_info().
> The corresponding vfio-user command handling is also added with the
> definition of all vfio-user command identity.
> 
> Signed-off-by: Chenbo Xia <chenbo.xia@intel.com>
> Signed-off-by: Xiuchun Lu <xiuchun.lu@intel.com>
> ---
>  lib/librte_vfio_user/rte_vfio_user.h    |  60 ++++++
>  lib/librte_vfio_user/version.map        |   2 +
>  lib/librte_vfio_user/vfio_user_base.c   |  12 ++
>  lib/librte_vfio_user/vfio_user_base.h   |  32 +++-
>  lib/librte_vfio_user/vfio_user_server.c | 232 ++++++++++++++++++++++++
>  lib/librte_vfio_user/vfio_user_server.h |   2 +
>  6 files changed, 339 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/librte_vfio_user/rte_vfio_user.h
> b/lib/librte_vfio_user/rte_vfio_user.h
> index 0d4f6c1be2..8a999c7aa0 100644
> --- a/lib/librte_vfio_user/rte_vfio_user.h
> +++ b/lib/librte_vfio_user/rte_vfio_user.h
> @@ -5,13 +5,35 @@
>  #ifndef _RTE_VFIO_USER_H
>  #define _RTE_VFIO_USER_H
> 

<snip>

> +static int vfio_user_device_get_reg_info(struct vfio_user_server *dev,
> +	VFIO_USER_MSG *msg)
> +{
> +	struct vfio_user_reg *reg = &msg->payload.reg_info;
> +	struct rte_vfio_user_reg_info *reg_info;
> +	struct vfio_region_info *vinfo;
> +
> +	if (vfio_user_check_msg_fdnum(msg, 0) != 0)
> +		return -EINVAL;
> +
> +	if (msg->size > sizeof(*reg) + VFIO_USER_MSG_HDR_SIZE ||
> +		dev->reg->reg_num <= reg->reg_info.index) {
> +		VFIO_USER_LOG(ERR, "Invalid message for get dev info\n");

Invalid message for get region info?

> +		return -EINVAL;
> +	}
> +
> +	reg_info = &dev->reg->reg_info[reg->reg_info.index];
> +	vinfo = reg_info->info;
> +	memcpy(reg, vinfo, vinfo->argsz);
> +
> +	if (reg_info->fd != -1) {
> +		msg->fd_num = 1;
> +		msg->fds[0] = reg_info->fd;
> +	}
> +
> +	VFIO_USER_LOG(DEBUG, "Region(%u) info: addr(0x%" PRIx64 "),
> fd(%d), "
> +		"sz(0x%llx), argsz(0x%x), c_off(0x%x), flags(0x%x) "
> +		"off(0x%llx)\n", vinfo->index, (uint64_t)reg_info->base,
> +		reg_info->fd, vinfo->size, vinfo->argsz, vinfo->cap_offset,
> +		vinfo->flags, vinfo->offset);
> +
> +	return 0;
> +}
> +

<snip>

> +int rte_vfio_user_set_dev_info(const char *sock_addr,
> +	struct vfio_device_info *dev_info)
> +{
> +	struct vfio_user_server *dev;
> +	struct vfio_user_server_socket *sk;
> +	int dev_id;
> +
> +	if (!dev_info)
> +		return -1;
> +
> +	pthread_mutex_lock(&vfio_ep_sock.mutex);
> +	sk = find_vfio_user_socket(sock_addr);
> +	pthread_mutex_unlock(&vfio_ep_sock.mutex);
> +
> +	if (!sk) {
> +		VFIO_USER_LOG(ERR, "Failed to set device info with
> sock_addr "
> +			"%s: addr not registered.\n", sock_addr);
> +		return -1;
> +	}
> +
> +	dev_id = sk->sock.dev_id;
> +	dev = vfio_user_get_device(dev_id);
> +	if (!dev) {
> +		VFIO_USER_LOG(ERR, "Failed to set device info:"
> +			"device %d not found.\n", dev_id);
> +		return -1;
> +	}
> +
> +	if (dev->started) {
> +		VFIO_USER_LOG(ERR, "Failed to set device info for
> device %d\n"
> +			 ", device already started\n", dev_id);
> +		return -1;
> +	}
> +
> +	dev->dev_info = dev_info;
> +
> +	return 0;
> +}
> +
> +int rte_vfio_user_set_reg_info(const char *sock_addr,
> +	struct rte_vfio_user_regions *reg)
> +{
> +	struct vfio_user_server *dev;
> +	struct vfio_user_server_socket *sk;
> +	int dev_id;
> +
> +	if (!reg)
> +		return -1;
> +
> +	pthread_mutex_lock(&vfio_ep_sock.mutex);
> +	sk = find_vfio_user_socket(sock_addr);
> +	pthread_mutex_unlock(&vfio_ep_sock.mutex);
> +
> +	if (!sk) {
> +		VFIO_USER_LOG(ERR, "Failed to set region info with
> sock_addr:"
> +			"%s: addr not registered.\n", sock_addr);
> +		return -1;
> +	}
> +
> +	dev_id = sk->sock.dev_id;
> +	dev = vfio_user_get_device(dev_id);
> +	if (!dev) {
> +		VFIO_USER_LOG(ERR, "Failed to set region info:"
> +			"device %d not found.\n", dev_id);
> +		return -1;
> +	}
> +
> +	if (dev->started) {
> +		VFIO_USER_LOG(ERR, "Failed to set region info for
> device %d\n"
> +			 ", device already started\n", dev_id);
> +		return -1;
> +	}
> +
> +	dev->reg = reg;
> +
> +	return 0;
> +}

Do you think if we can define a static function to cover the duplicated check part of function rte_vfio_user_set_dev_info and rte_vfio_user_set_reg_info?

> diff --git a/lib/librte_vfio_user/vfio_user_server.h
> b/lib/librte_vfio_user/vfio_user_server.h
> index 00e3f6353d..e8fb61cb3e 100644
> --- a/lib/librte_vfio_user/vfio_user_server.h
> +++ b/lib/librte_vfio_user/vfio_user_server.h
> @@ -16,6 +16,8 @@ struct vfio_user_server {
>  	uint32_t msg_id;
>  	char sock_addr[PATH_MAX];
>  	struct vfio_user_version ver;
> +	struct vfio_device_info *dev_info;
> +	struct rte_vfio_user_regions *reg;
>  };
> 
>  typedef int (*event_handler)(int fd, void *data);
> --
> 2.17.1


  reply	other threads:[~2021-01-06  5:51 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-18  7:38 [dpdk-dev] [PATCH 0/9] Introduce vfio-user library Chenbo Xia
2020-12-18  7:38 ` [dpdk-dev] [PATCH 1/9] lib: introduce " Chenbo Xia
2020-12-18 17:13   ` Stephen Hemminger
2020-12-19  6:12     ` Xia, Chenbo
2020-12-18 17:17   ` Stephen Hemminger
2020-12-19  6:25     ` Xia, Chenbo
2020-12-18  7:38 ` [dpdk-dev] [PATCH 2/9] vfio_user: implement lifecycle related APIs Chenbo Xia
2021-01-05  8:34   ` Xing, Beilei
2021-01-05  9:58     ` Xia, Chenbo
2020-12-18  7:38 ` [dpdk-dev] [PATCH 3/9] vfio_user: implement device and region " Chenbo Xia
2021-01-06  5:51   ` Xing, Beilei [this message]
2021-01-06  7:50     ` Xia, Chenbo
2020-12-18  7:38 ` [dpdk-dev] [PATCH 4/9] vfio_user: implement DMA table and socket address API Chenbo Xia
2020-12-18  7:38 ` [dpdk-dev] [PATCH 5/9] vfio_user: implement interrupt related APIs Chenbo Xia
2020-12-30  1:04   ` Wu, Jingjing
2020-12-30  2:31     ` Xia, Chenbo
2020-12-18  7:38 ` [dpdk-dev] [PATCH 6/9] vfio_user: add client APIs of device attach/detach Chenbo Xia
2020-12-18  7:38 ` [dpdk-dev] [PATCH 7/9] vfio_user: add client APIs of DMA/IRQ/region Chenbo Xia
2021-01-07  2:41   ` Xing, Beilei
2021-01-07  7:26     ` Xia, Chenbo
2020-12-18  7:38 ` [dpdk-dev] [PATCH 8/9] test/vfio_user: introduce functional test Chenbo Xia
2020-12-18  7:38 ` [dpdk-dev] [PATCH 9/9] doc: add vfio-user library guide Chenbo Xia
2021-01-06  5:07   ` Xing, Beilei
2021-01-06  7:43     ` Xia, Chenbo
2020-12-18  9:37 ` [dpdk-dev] [PATCH 0/9] Introduce vfio-user library David Marchand
2020-12-18 14:07   ` Thanos Makatos
2023-06-29 16:10     ` Stephen Hemminger
2023-06-30  1:36       ` Xia, Chenbo
2021-01-14  6:14 ` [dpdk-dev] [PATCH v2 " Chenbo Xia
2021-01-14  6:14   ` [dpdk-dev] [PATCH v2 1/9] lib: introduce " Chenbo Xia
2024-02-12 22:53     ` Stephen Hemminger
2021-01-14  6:14   ` [dpdk-dev] [PATCH v2 2/9] vfio_user: implement lifecycle related APIs Chenbo Xia
2021-01-14  6:14   ` [dpdk-dev] [PATCH v2 3/9] vfio_user: implement device and region " Chenbo Xia
2021-01-14 18:48     ` David Christensen
2021-01-19  3:22       ` Xia, Chenbo
2021-01-14  6:14   ` [dpdk-dev] [PATCH v2 4/9] vfio_user: implement DMA table and socket address API Chenbo Xia
2021-01-14  6:14   ` [dpdk-dev] [PATCH v2 5/9] vfio_user: implement interrupt related APIs Chenbo Xia
2021-01-14  6:14   ` [dpdk-dev] [PATCH v2 6/9] vfio_user: add client APIs of device attach/detach Chenbo Xia
2021-01-14  6:14   ` [dpdk-dev] [PATCH v2 7/9] vfio_user: add client APIs of DMA/IRQ/region Chenbo Xia
2021-01-14  6:14   ` [dpdk-dev] [PATCH v2 8/9] test/vfio_user: introduce functional test Chenbo Xia
2021-01-14 19:03     ` David Christensen
2021-01-19  3:27       ` Xia, Chenbo
2021-01-19 18:26         ` David Christensen
2021-01-14  6:14   ` [dpdk-dev] [PATCH v2 9/9] doc: add vfio-user library guide Chenbo Xia
2021-01-15  7:58   ` [dpdk-dev] [PATCH v2 0/9] Introduce vfio-user library David Marchand
2021-01-19  3:13     ` Xia, Chenbo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=MN2PR11MB38078A574697E0B0192F5D71F7D00@MN2PR11MB3807.namprd11.prod.outlook.com \
    --to=beilei.xing@intel.com \
    --cc=chenbo.xia@intel.com \
    --cc=cunming.liang@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=jingjing.wu@intel.com \
    --cc=miao.li@intel.com \
    --cc=stephen@networkplumber.org \
    --cc=thomas@monjalon.net \
    --cc=xiuchun.lu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).