From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (xvm-189-124.dc0.ghst.net [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 2C587A09FF;
	Wed,  6 Jan 2021 06:51:47 +0100 (CET)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id E68821608AA;
	Wed,  6 Jan 2021 06:51:46 +0100 (CET)
Received: from mga01.intel.com (mga01.intel.com [192.55.52.88])
 by mails.dpdk.org (Postfix) with ESMTP id EDA3A1608A4
 for <dev@dpdk.org>; Wed,  6 Jan 2021 06:51:45 +0100 (CET)
IronPort-SDR: Djs1ehwDqY/xBM9cS3D2Q2FIDZ7LgwO17Sk/KIBkkLYiYlpyiOVPZpF7ZXJyEoTAcQHo8z71po
 jPkRJ4TEo1rQ==
X-IronPort-AV: E=McAfee;i="6000,8403,9855"; a="195776917"
X-IronPort-AV: E=Sophos;i="5.78,479,1599548400"; d="scan'208";a="195776917"
Received: from fmsmga002.fm.intel.com ([10.253.24.26])
 by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 05 Jan 2021 21:51:45 -0800
IronPort-SDR: CbVvqicLUdEv0c1CZN9WUcJW8ffcsZmH+8EUg9RVVECQrcYZXlgTRbSNI2qlxgpECwyeaybEw7
 getF0+PQIPKw==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.78,479,1599548400"; d="scan'208";a="398102368"
Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15])
 by fmsmga002.fm.intel.com with ESMTP; 05 Jan 2021 21:51:44 -0800
Received: from orsmsx605.amr.corp.intel.com (10.22.229.18) by
 ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id
 15.1.1713.5; Tue, 5 Jan 2021 21:51:44 -0800
Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by
 orsmsx605.amr.corp.intel.com (10.22.229.18) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5
 via Frontend Transport; Tue, 5 Jan 2021 21:51:44 -0800
Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.176)
 by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.1.1713.5; Tue, 5 Jan 2021 21:51:44 -0800
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=nt20Jpb4/ygkHS1pRvUwzNwVfJ8N84xACmUNElc0t/bUa+Q97vtWDcyZq9eKV55gjQvW/RJBbye5jfL0HQ/n4i0p0a7lQsqgltSNkH0CHutdZJIMklRMLhGVGsmQXUNKBrRClGjZMFO9bwVARbZaeDgXcS42ACEtB6wA77Lx8WYkoR8d5cVHEpCkQnJ+NqdtzLMY5BN6PhDbMzrZsc4y1Y6WFmwRKAfHStWGYEQ4t6HtCSVs342gXmD6QVUjXJm3mz6n/aJdKtdoGd3z9c+i+UBaytVOvJ60kNwjRoI/wfHlwfl+iU5EqanuWLXcbyslu9bQDCt0mov/2L+au9Bp2A==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; 
 s=arcselector9901;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=w3xi07sHiFENRp/Bn6HcRRFm6YPuFE+tS/DF3AZqpu8=;
 b=SvQQ+SyYR/7w2dwtZWkiY0/g/0hfjuk3QyyeOREdprdZ2gfgg1PGtH7ReCYk3VGpfqfRaS52FSaxWOHUDeJg8lq3P+K7wSpDWsp5qZDAQIg2rPWm+ZjELfW53vb3vb4VAGusXtJTta+Z79z7SvuLoBU5ggS7yPoV5qtIJnjtPc/uBgHwMCNDDQE3KEUMH8pdlY2Z6Vcvc9NrXYBlYxmcU6jSeIpDBvQ8wRxRzNpUfhRbfoPOAhZ0TqKhRW3xm65xObqWhBNNYxF1SpVH8LmoJV1Z3p6ZmQZbJUj7jOlcqdQ6Mwj9wTWqnLJEbl52OIy+307irAaJzoiJ+snnN49wrA==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
 smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com;
 dkim=pass header.d=intel.com; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; 
 s=selector2-intel-onmicrosoft-com;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=w3xi07sHiFENRp/Bn6HcRRFm6YPuFE+tS/DF3AZqpu8=;
 b=IogYrwvVNWi5xJlF7m5uvYXF35miyZDhVD3YH/tMfh+ZdD9DDCIRhD24wBaiUd1tgGZZnnf18dyiw7Ipr96qV/5jnfgbbtNlMCvsIWK0PxG8/8H3kR+GpeS548uclmH/anH6PSY+4tK0HjXJLVTdXaZljBtqDR6MrI3LpgRpmko=
Received: from MN2PR11MB3807.namprd11.prod.outlook.com (2603:10b6:208:f0::24)
 by MN2PR11MB3552.namprd11.prod.outlook.com (2603:10b6:208:ed::33)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Wed, 6 Jan
 2021 05:51:43 +0000
Received: from MN2PR11MB3807.namprd11.prod.outlook.com
 ([fe80::4d7f:d51:79bc:e596]) by MN2PR11MB3807.namprd11.prod.outlook.com
 ([fe80::4d7f:d51:79bc:e596%4]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021
 05:51:43 +0000
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>
Thread-Topic: [dpdk-dev] [PATCH 3/9] vfio_user: implement device and region
 related APIs
Thread-Index: AQHW1RMzXCcKygnfu0+NtJOPfBD56qoaNEPA
Date: Wed, 6 Jan 2021 05:51:42 +0000
Message-ID: <MN2PR11MB38078A574697E0B0192F5D71F7D00@MN2PR11MB3807.namprd11.prod.outlook.com>
References: <20201218073851.93609-1-chenbo.xia@intel.com>
 <20201218073851.93609-4-chenbo.xia@intel.com>
In-Reply-To: <20201218073851.93609-4-chenbo.xia@intel.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
authentication-results: intel.com; dkim=none (message not signed)
 header.d=none;intel.com; dmarc=none action=none header.from=intel.com;
x-originating-ip: [192.102.204.36]
x-ms-publictraffictype: Email
x-ms-office365-filtering-correlation-id: dc138e5c-8a0d-4f86-e264-08d8b2072527
x-ms-traffictypediagnostic: MN2PR11MB3552:
x-ms-exchange-transport-forked: True
x-microsoft-antispam-prvs: <MN2PR11MB3552A2EA3A3CA5A24FF30211F7D00@MN2PR11MB3552.namprd11.prod.outlook.com>
x-ms-oob-tlc-oobclassifiers: OLM:390;
x-ms-exchange-senderadcheck: 1
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: IkPZ2tM8qvacK+kWObAnrn+G/Q7mSWfgKwLdgD578Y/9Du1sFsDl2RPjMAQfdOBsF3MbEqwmAk4NcytlDYvu7fRJF+ul7AvYLeTwIm9E4zxI5x3rj91VBiAXTudxC8BIqWOOJyZZfgZwiFvXjibVoXYw+PEZEVKiOqoTvg8rfFktwofa7TTmdjLe7FyukE0zTSrGzZREkwwgGeQh0vxapt1BaS5mhegG5X30joRAgGPe373TnPuEHUz3bSCLNYvJnvBf1KwT4yHq8MrymliRLLP2YX0D2n5pjAJLB46DJVg3yI5fwhq69+xnBmsbDs9DtOiLC8zsmLD8q6N8uXUSdaf8LbtxnoZNz7caxnI+QOHNAQh7EZQI/QFRtRt0yNqVCZF6iS/WBWqgKMo2PW2vMw==
x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
 IPV:NLI; SFV:NSPM; H:MN2PR11MB3807.namprd11.prod.outlook.com; PTR:; CAT:NONE;
 SFS:(4636009)(366004)(39860400002)(396003)(376002)(346002)(136003)(66946007)(64756008)(66556008)(66476007)(66446008)(55016002)(6506007)(54906003)(478600001)(86362001)(76116006)(53546011)(4326008)(71200400001)(9686003)(110136005)(8936002)(5660300002)(7696005)(186003)(26005)(83380400001)(52536014)(33656002)(2906002)(107886003)(316002);
 DIR:OUT; SFP:1102; 
x-ms-exchange-antispam-messagedata: =?us-ascii?Q?gwpv1XRgVXnfS1j8fyoDhRf7SgF9O9TL+/WcjHticbyXoQtlOvsWL5DxqTAH?=
 =?us-ascii?Q?e/zV7TsA4e2BxxesK+YsHcssXj2hCDxnZIanSSoYs9anmGhSR1yAHiqe7fc5?=
 =?us-ascii?Q?XfO54RP+iX+C60YKNYNSi+q4JZyPY+nlfO0wLzelyKbuIZ1mV6nMK7v89YRq?=
 =?us-ascii?Q?msdsxZeqpsX2dcywA1k6k9pHWlqSRK5I7SFnRsDMYrBLd5HExSuHHLBVp1Cc?=
 =?us-ascii?Q?ghR8tmjuWeiklaut3grAlrXJECyHVPeu87KGiwA+Z/7E+rBNuyrKXgQPngfb?=
 =?us-ascii?Q?JL4uvwZfOOXEi7ID6aa6N3pTnk29Ka3RjfCVI/JP6pAwi3sndgoREhUc8fov?=
 =?us-ascii?Q?HUAoRYFcm0zd8qcD5oWMOvU+3G7sg3bzkCXbJx7VayZ0IHH7YcQG4j/sQRPV?=
 =?us-ascii?Q?tp20RgU0STwjzKJlpSjudHqrpNSt3wDYdilgjYYoDyjec47xavujfHYjhZO0?=
 =?us-ascii?Q?WndZSfPcCY04k7rD8Fdytv/lemKfPRdCoZBWGg9Bx+NtDkDnWWsx9gMyuacG?=
 =?us-ascii?Q?Tb3sqUNzEpEFfY+5bMqxfiwRtR0H2CTXalI6A+PCuQqGeb0i3HgmpGuKpkBV?=
 =?us-ascii?Q?hCfXIrA0ha1g0QBhhLRA5YWk1F6yreuI8ndLR40AjynYtmgrZKAEvT5gC+9P?=
 =?us-ascii?Q?k8o5Te3LC6bsV4xzKtaHaFEajOJu43kc3gsmAVxj5HNTXapYGyKemIKmaOeY?=
 =?us-ascii?Q?9kRh44GZXLM17LnFcylJizxbfcBMmOJF3pGAS8qV4j9GYsOJyd8S+kXw2y0G?=
 =?us-ascii?Q?p61PriaL7cixz3H3+ML7J+WVD49/HQ1x3l3Zl7Xp3XsHJcytX6irAykcz2wu?=
 =?us-ascii?Q?6m+xEVoP+Lkoko6+bUGqGZQScii5aSyPipj9/axNlx85qOFDPVmTcCqBLwUn?=
 =?us-ascii?Q?2LsUw0kReAs6g5c+1jARf72sl0jWznDI5yLcddNFSvF/tVjx61uRVWeMFvTS?=
 =?us-ascii?Q?3018OpEPKMvLDH+gZKqqyrIMzwWD2gW243bw3gogxQg=3D?=
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: MN2PR11MB3807.namprd11.prod.outlook.com
X-MS-Exchange-CrossTenant-Network-Message-Id: dc138e5c-8a0d-4f86-e264-08d8b2072527
X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Jan 2021 05:51:42.8662 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: Ap8QOMKmw0/B9tZhtp7uszUwop8CH790Zd5TS4ZXSH0jTZBNi4+E4stQE6xKIMheKmkmNnxewG5IopHkMIBZHg==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3552
X-OriginatorOrg: intel.com
Subject: Re: [dpdk-dev] [PATCH 3/9] vfio_user: implement device and
	region	related APIs
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>



> -----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
>=20
> 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.
>=20
> 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(-)
>=20
> 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
>=20

<snip>

> +static int vfio_user_device_get_reg_info(struct vfio_user_server *dev,
> +	VFIO_USER_MSG *msg)
> +{
> +	struct vfio_user_reg *reg =3D &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) !=3D 0)
> +		return -EINVAL;
> +
> +	if (msg->size > sizeof(*reg) + VFIO_USER_MSG_HDR_SIZE ||
> +		dev->reg->reg_num <=3D 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 =3D &dev->reg->reg_info[reg->reg_info.index];
> +	vinfo =3D reg_info->info;
> +	memcpy(reg, vinfo, vinfo->argsz);
> +
> +	if (reg_info->fd !=3D -1) {
> +		msg->fd_num =3D 1;
> +		msg->fds[0] =3D 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 =3D 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 =3D sk->sock.dev_id;
> +	dev =3D 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 =3D 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 =3D 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 =3D sk->sock.dev_id;
> +	dev =3D 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 =3D reg;
> +
> +	return 0;
> +}

Do you think if we can define a static function to cover the duplicated che=
ck part of function rte_vfio_user_set_dev_info and rte_vfio_user_set_reg_in=
fo?

> 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;
>  };
>=20
>  typedef int (*event_handler)(int fd, void *data);
> --
> 2.17.1