From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4DE3DA051A; Fri, 17 Jan 2020 10:01:57 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 06FBD1D17E; Fri, 17 Jan 2020 10:01:56 +0100 (CET) Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00088.outbound.protection.outlook.com [40.107.0.88]) by dpdk.org (Postfix) with ESMTP id 2C7D31D17B for ; Fri, 17 Jan 2020 10:01:55 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nRx95SWEGqW9QEG0RC5+WSkH2KaSsFe9y0dGfbkODnOEl8JCZL5FLUlNXfAbju2vXchhbwCYw59GDrPkqt/ZyRSKPK1E1Y0qAvkdTWY5q2AX3HHvK8xJY8FNAHRm61nBoMgMLuGURDnjYz9c0LOARJk4ewpFmdfjkEAK0M5pDNr1l9NqrQGE3WZh8ylcdaDf16FpmUAa34kol5dO88iVdiiXkrKZ1S9HWd4nBAPOQcz1w/yhD4V6PnVYRJJM8UvOQJAwaAbaPrbFJED87ACtThLOqb6OHsPoLQ/ZNS0kS7QTR511jtCPWP9m4yA79p63B39/NWo8mSzWKS2GgSGjgA== 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=7VNajAi/byK7LCf8USXd8P4jM7gT9J9MRa7rxagZbAQ=; b=hs/rBUgG4qcK6g0D+3q374BORfcYuRNyCo2wWEB+edlud7qZHfWYgMCkPwGqtEYixS13UNSCkO2axXTQ5QDuuHX2np27iH24K9CY+KYIEkuMOdCCICEGbkUpMAVjJ1p69wrshOEzTFbdCDSNvOF7etsjMOvyP8TI9g2i3tiP4O+IylepBzYNR+kNEGv/qQshoEbxgOwmSvQyti8RFuOR61w9Yl89gMDOrOK/y+DMm/LrSuDPx6j+aZ81jf58/uduNeBRIEJwD5q1ocXU1Sp4QvnZ+ikEKr0Z1gh5qpx3nTjR+WED6QSh4oEB6kl76fRr34ymhORcZLRy0LmqCyY9AA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=mellanox.com; dmarc=pass action=none header.from=mellanox.com; dkim=pass header.d=mellanox.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7VNajAi/byK7LCf8USXd8P4jM7gT9J9MRa7rxagZbAQ=; b=a/V/2y/QUzEpyDjpC9G16FAZk3KAmzAmxXecT6CWNkQm6Dn5pgcO7Q3XhRphN2UxD3nI51Xm/pc76soZdoo6tu5t1cu3CxAS9pq/O0YOiKDbI3P58YYCVU0hBl6o1S3VnIxIPnZS0xF4ZB9LbjnI6To/ZTOyLM6/AbxBs24WXpI= Received: from AM6PR05MB6567.eurprd05.prod.outlook.com (20.179.6.215) by AM6PR05MB5426.eurprd05.prod.outlook.com (20.177.188.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20; Fri, 17 Jan 2020 09:01:53 +0000 Received: from AM6PR05MB6567.eurprd05.prod.outlook.com ([fe80::19a2:76a9:2b23:5c91]) by AM6PR05MB6567.eurprd05.prod.outlook.com ([fe80::19a2:76a9:2b23:5c91%4]) with mapi id 15.20.2644.021; Fri, 17 Jan 2020 09:01:53 +0000 Received: from mellanox.com (2408:8025:349:cd40:9191:1a10:dc63:2083) by HK2PR06CA0004.apcprd06.prod.outlook.com (2603:1096:202:2e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.18 via Frontend Transport; Fri, 17 Jan 2020 09:01:47 +0000 From: Jack Min To: Slava Ovsiienko CC: "jerinjacobk@gmail.com" , Ori Kam , Matan Azrad , Raslan Darawsheh , Shahaf Shuler , Anatoly Burakov , "dev@dpdk.org" , "Xueming(Steven) Li" Thread-Topic: [PATCH 4/5] net/mlx5: add socket server for external tools Thread-Index: AQHVzRLREHMHW/jK/U+JXfuT6Rmx1Kfuj0sA Date: Fri, 17 Jan 2020 09:01:53 +0000 Message-ID: <20200117090136.3aunznm2qp6zwsgy@mellanox.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HK2PR06CA0004.apcprd06.prod.outlook.com (2603:1096:202:2e::16) To AM6PR05MB6567.eurprd05.prod.outlook.com (2603:10a6:20b:bc::23) authentication-results: spf=none (sender IP is ) smtp.mailfrom=jackmin@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [2408:8025:349:cd40:9191:1a10:dc63:2083] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 2dbc9bed-88cd-42a7-06f1-08d79b2be55d x-ms-traffictypediagnostic: AM6PR05MB5426:|AM6PR05MB5426: x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtFwd x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3173; x-forefront-prvs: 0285201563 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(39860400002)(396003)(376002)(346002)(136003)(366004)(189003)(199004)(508600001)(7696005)(4326008)(5660300002)(2906002)(52116002)(186003)(2616005)(53546011)(8886007)(16526019)(66446008)(66556008)(66946007)(86362001)(37006003)(55016002)(6862004)(1076003)(107886003)(66476007)(8936002)(64756008)(36756003)(81156014)(6666004)(81166006)(8676002)(316002)(54906003)(6636002)(71200400001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR05MB5426; H:AM6PR05MB6567.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: B2sT5i3C06P3HjHXsXG6oeQBLy3qG3/W8WjPtyJiGTPc7eTAYT96o6Qokx8r9yszmP9+NKFFhQGQG7t1CtMM5NCvA4RDM/pZb9JGQ7myGjbltxeg2TtOeazC25+RInP0Jd63X7PrEhoFqlqCHd2NoDrjd9RCCqirWldblchyxCwBBJ4xl1QYQwiys2Wz+kNO8Qqndd7u5TU3ISTaji9iOR1pOW0IhuiSK5JvgU4Ol7E3mWz9lxjEfQLVyfu/ehjxWfUNTjoBdzKzk+KPFS+SDIIUKPu3B27+tO3afySZOWLyVFJA95ay9FfbnsWbCjXdN/smQDMkKOWrWHxyoPwLR6kn4OZfFHpb88LsqT2jrENpMJTxk8A+Ng9GO9D/y21+cRWGnl1X9Q0hfu1kCpjbHuVgkIOs5TVxCTeb2FgHzx7K6is1+lwuZMYeO43zk0G/ Content-Type: text/plain; charset="us-ascii" Content-ID: <2F03A5A766AFEC448929347D4C673BBB@eurprd05.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2dbc9bed-88cd-42a7-06f1-08d79b2be55d X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jan 2020 09:01:53.5439 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: +w8SdwSGuzsbL5TyVocQxpVTv+sOP7aV5toTh3GvE5XAqjaB1Nd9vyy1/6y0vMs1hngECFt7QqssxRjJpiEB3w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR05MB5426 Subject: Re: [dpdk-dev] [PATCH 4/5] net/mlx5: add socket server for external tools X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Fri, 20-01-17, 16:47, Slava Ovsiienko wrote: > Hi, Jack >=20 > > -----Original Message----- > > From: Xiaoyu Min > > Sent: Thursday, January 16, 2020 12:14 > > To: jerinjacobk@gmail.com; Ori Kam ; Slava Ovsiienk= o > > ; Matan Azrad ; Raslan > > Darawsheh ; Shahaf Shuler > > ; Anatoly Burakov > > Cc: dev@dpdk.org; Xueming(Steven) Li > > Subject: [PATCH 4/5] net/mlx5: add socket server for external tools > >=20 > > From: Xueming Li > >=20 > > Add pmd unix socket server to enable external tool applications to trig= ger > > flow dump. > >=20 > > Socket path: > > /var/tmp/dpdk_mlx5_ > > Socket format: > > io_raw: port_id of uint16 > > file: file descriptor of int > >=20 > > Signed-off-by: Xueming Li > > Signed-off-by: Xiaoyu Min > > --- > > drivers/net/mlx5/Makefile | 1 + > > drivers/net/mlx5/meson.build | 1 + > > drivers/net/mlx5/mlx5.c | 2 + > > drivers/net/mlx5/mlx5.h | 5 + > > drivers/net/mlx5/mlx5_socket.c | 227 +++++++++++++++++++++++++++++++++ > > 5 files changed, 236 insertions(+) > > create mode 100644 drivers/net/mlx5/mlx5_socket.c > >=20 > > diff --git a/drivers/net/mlx5/Makefile b/drivers/net/mlx5/Makefile inde= x > > 6e5921b292..397e29dcbb 100644 > > --- a/drivers/net/mlx5/Makefile > > +++ b/drivers/net/mlx5/Makefile > > @@ -39,6 +39,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) +=3D mlx5_mp.c > > SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) +=3D mlx5_nl.c > > SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) +=3D mlx5_devx_cmds.c > > SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) +=3D mlx5_utils.c > > +SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) +=3D mlx5_socket.c > >=20 > > ifeq ($(CONFIG_RTE_IBVERBS_LINK_DLOPEN),y) > > INSTALL-$(CONFIG_RTE_LIBRTE_MLX5_PMD)-lib +=3D $(LIB_GLUE) diff --git > > a/drivers/net/mlx5/meson.build b/drivers/net/mlx5/meson.build index > > d7ef032afb..cb2fb90495 100644 > > --- a/drivers/net/mlx5/meson.build > > +++ b/drivers/net/mlx5/meson.build > > @@ -61,6 +61,7 @@ if build > > 'mlx5_vlan.c', > > 'mlx5_devx_cmds.c', > > 'mlx5_utils.c', > > + 'mlx5_socket.c', > > ) > > if (dpdk_conf.has('RTE_ARCH_X86_64') > > or dpdk_conf.has('RTE_ARCH_ARM64') > > diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index > > 50960c91ce..ffee39c1a0 100644 > > --- a/drivers/net/mlx5/mlx5.c > > +++ b/drivers/net/mlx5/mlx5.c > > @@ -2954,6 +2954,8 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv > > __rte_unused, > > struct mlx5_dev_config dev_config; > > int ret; > >=20 > > + if (rte_eal_process_type() =3D=3D RTE_PROC_PRIMARY) > > + mlx5_pmd_socket_init(); > > ret =3D mlx5_init_once(); > > if (ret) { > > DRV_LOG(ERR, "unable to init PMD global data: %s", diff --git > > a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index > > 047181b32e..ceb6de821e 100644 > > --- a/drivers/net/mlx5/mlx5.h > > +++ b/drivers/net/mlx5/mlx5.h > > @@ -990,6 +990,11 @@ void mlx5_mp_uninit_primary(void); int > > mlx5_mp_init_secondary(void); void mlx5_mp_uninit_secondary(void); > >=20 > > +/* mlx5_socket.c */ > > + > > +int mlx5_pmd_socket_init(void); > > +void mlx5_pmd_socket_uninit(void); > > + > > /* mlx5_nl.c */ > >=20 > > int mlx5_nl_init(int protocol); > > diff --git a/drivers/net/mlx5/mlx5_socket.c b/drivers/net/mlx5/mlx5_soc= ket.c > > new file mode 100644 index 0000000000..e4c93c4312 > > --- /dev/null > > +++ b/drivers/net/mlx5/mlx5_socket.c > > @@ -0,0 +1,227 @@ > > +/* SPDX-License-Identifier: BSD-3-Clause > > + * Copyright 2019 Mellanox Technologies, Ltd */ > > + > > +#ifndef _GNU_SOURCE > > +#define _GNU_SOURCE > > +#endif > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#include "rte_eal.h" > > +#include "mlx5_utils.h" > > +#include "mlx5.h" > > + > > +/* PMD socket service for tools. */ > > + > > +int server_socket; /* Unix socket for primary process. */ struct > > +rte_intr_handle server_intr_handle; /* Interrupt handler. */ > > + > > +static void > > +mlx5_pmd_make_path(struct sockaddr_un *addr, int pid) { > > + snprintf(addr->sun_path, sizeof(addr->sun_path), > > "/var/tmp/dpdk_%s_%d", > > + MLX5_DRIVER_NAME, pid); > > +} > > + > > +/** > > + * Handle server pmd socket interrupts. > > + */ > > +static void > > +mlx5_pmd_socket_handle(void *cb __rte_unused) { > > + int conn_sock; > > + int ret =3D -1; > > + struct cmsghdr *cmsg =3D NULL; > > + int data; > > + char buf[CMSG_SPACE(sizeof(int))] =3D { 0 }; > > + struct iovec io =3D { > > + .iov_base =3D &data, > > + .iov_len =3D sizeof(data), > > + }; > > + struct msghdr msg =3D { > > + .msg_iov =3D &io, > > + .msg_iovlen =3D 1, > > + .msg_control =3D buf, > > + .msg_controllen =3D sizeof(buf), > > + }; > > + uint16_t port_id; > > + int fd; > > + FILE *file =3D NULL; > > + struct rte_eth_dev *dev; > > + > > + /* Accept the connection from the client. */ > > + conn_sock =3D accept(server_socket, NULL, NULL); > > + if (conn_sock < 0) { > > + DRV_LOG(WARNING, "connection failed: %s", strerror(errno)); > > + return; > > + } > > + ret =3D recvmsg(conn_sock, &msg, MSG_WAITALL); > > + if (ret < 0) { > > + DRV_LOG(WARNING, "wrong message received: %s", > > + strerror(errno)); > > + goto error; > > + } > > + /* Receive file descriptor. */ > > + cmsg =3D CMSG_FIRSTHDR(&msg); > > + if (cmsg =3D=3D NULL || cmsg->cmsg_type !=3D SCM_RIGHTS || > > + cmsg->cmsg_len < sizeof(int)) { > > + DRV_LOG(WARNING, "invalid file descriptor message"); > > + goto error; > > + } > > + memcpy(&fd, CMSG_DATA(cmsg), sizeof(fd)); > > + file =3D fdopen(fd, "w"); > > + if (!file) { > > + DRV_LOG(WARNING, "Failed to open file"); > > + goto error; > > + } > > + /* Receive port number. */ > > + if (msg.msg_iovlen !=3D 1 || msg.msg_iov->iov_len < sizeof(uint16_t))= { > > + DRV_LOG(WARNING, "wrong port number message"); > > + goto error; > > + } > > + memcpy(&port_id, msg.msg_iov->iov_base, sizeof(port_id)); > I would add the port_id check here. > The message with wrong port_id may crash the server. Yes, you are right. I'll update it in v2. >=20 >=20 > > + /* Dump flow. */ > > + dev =3D &rte_eth_devices[port_id]; > > + ret =3D mlx5_flow_dev_dump(dev, file, NULL); > > + /* Set-up the ancillary data and reply. */ > > + msg.msg_controllen =3D 0; > > + msg.msg_control =3D NULL; > > + msg.msg_iovlen =3D 1; > > + msg.msg_iov =3D &io; > > + data =3D -ret; > > + io.iov_len =3D sizeof(data); > > + io.iov_base =3D &data; > > + do { > > + ret =3D sendmsg(conn_sock, &msg, 0); > > + } while (ret < 0 && errno =3D=3D EINTR); > > + if (ret < 0) > > + DRV_LOG(WARNING, "failed to send response %s", > > + strerror(errno)); > > +error: > > + if (conn_sock > 0) > > + close(conn_sock); > > + if (file) > > + fclose(file); > > +} > > + > > +/** > > + * Install interrupt handler. > > + * > > + * @param dev > > + * Pointer to Ethernet device. > > + * @return > > + * 0 on success, a negative errno value otherwise. > > + */ > > +static int > > +mlx5_pmd_interrupt_handler_install(void) > > +{ > > + assert(server_socket); > > + server_intr_handle.fd =3D server_socket; > > + server_intr_handle.type =3D RTE_INTR_HANDLE_EXT; > > + return rte_intr_callback_register(&server_intr_handle, > > + mlx5_pmd_socket_handle, NULL); > > +} > > + > > +/** > > + * Uninstall interrupt handler. > > + */ > > +static void > > +mlx5_pmd_interrupt_handler_uninstall(void) > > +{ > > + if (server_socket) { > > + mlx5_intr_callback_unregister(&server_intr_handle, > > + mlx5_pmd_socket_handle, > > + NULL); > > + } > > + server_intr_handle.fd =3D 0; > > + server_intr_handle.type =3D RTE_INTR_HANDLE_UNKNOWN; } > > + > > +/** > > + * Initialise the socket to communicate with the secondary process > > + * > > + * @param[in] dev > > + * Pointer to Ethernet device. > > + * > > + * @return > > + * 0 on success, a negative value otherwise. > > + */ > > +int > > +mlx5_pmd_socket_init(void) > > +{ > > + struct sockaddr_un sun =3D { > > + .sun_family =3D AF_UNIX, > > + }; > > + int ret =3D -1; > > + int flags; > > + > > + assert(rte_eal_process_type() =3D=3D RTE_PROC_PRIMARY); > > + if (server_socket) > > + return 0; > > + /* > > + * Initialize the socket to communicate with the secondary > > + * process. > > + */ > > + ret =3D socket(AF_UNIX, SOCK_STREAM, 0); > > + if (ret < 0) { > > + DRV_LOG(WARNING, "Failed to open mlx5 socket: %s", > > + strerror(errno)); > > + goto error; > > + } > > + server_socket =3D ret; > > + flags =3D fcntl(server_socket, F_GETFL, 0); > > + if (flags =3D=3D -1) > > + goto error; > > + ret =3D fcntl(server_socket, F_SETFL, flags | O_NONBLOCK); > > + if (ret < 0) > > + goto error; > > + mlx5_pmd_make_path(&sun, getpid()); > > + remove(sun.sun_path); > > + ret =3D bind(server_socket, (const struct sockaddr *)&sun, sizeof(sun= )); > > + if (ret < 0) { > > + DRV_LOG(WARNING, > > + "cannot bind mlx5 socket: %s", strerror(errno)); > > + goto close; > > + } > > + ret =3D listen(server_socket, 0); > > + if (ret < 0) { > > + DRV_LOG(WARNING, "cannot listen on mlx5 socket: %s", > > + strerror(errno)); > > + goto close; > > + } > > + if (mlx5_pmd_interrupt_handler_install()) { > > + DRV_LOG(WARNING, "cannot register interrupt handler for > > mlx5 socket: %s", > > + strerror(errno)); > > + goto close; > > + } > > + return 0; > > +close: > > + remove(sun.sun_path); > > +error: > > + claim_zero(close(server_socket)); > > + server_socket =3D 0; > > + DRV_LOG(ERR, "Cannot initialize socket: %s", strerror(errno)); > > + return -errno; > > +} > > + > > +/** > > + * Un-Initialize the pmd socket > > + */ > > +void __attribute__((destructor)) > > +mlx5_pmd_socket_uninit(void) > > +{ > > + if (!server_socket) > > + return; > > + mlx5_pmd_interrupt_handler_uninstall(); > > + MKSTR(path, "/var/tmp/dpdk_%s_%d", MLX5_DRIVER_NAME, > > getpid()); > I would move the MKSTR a couple lines below, after the close() call. OK, this seems make code more readable. I'll update it in v2. >=20 > > + claim_zero(close(server_socket)); > > + server_socket =3D 0; > > + claim_zero(remove(path)); > > +} > > -- > > 2.24.1 > With best regards, Slava Thank you~ -Jack