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 B5653A051A; Fri, 17 Jan 2020 09:48:00 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B51181D3F0; Fri, 17 Jan 2020 09:47:59 +0100 (CET) Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-eopbgr130079.outbound.protection.outlook.com [40.107.13.79]) by dpdk.org (Postfix) with ESMTP id 4FCCD1D37F for ; Fri, 17 Jan 2020 09:47:58 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bPovXxHaPgpm6Jr8gWERohEQtv9J4GoA1K9TbGRNl6RmQB4tN0pdYUZ1eGmMpp/y2KEA2Q7Ekfrv8rRANdobL2AKG6U1P2o7Gv+h/nGwoV4Lnt2XeL/Aw5FvypRJpe0KKY1u6cR/mnCbDkirwFKgjYL0MxS4GfRs4MnFHvA2EmEHzcCezbrTencDuoUfXbJGBKhlV3YuikO5OV6x+DFxu3LOE+cgA/CpUMJHECSnCQ+Yk4oPeBEDXyIDRPHNoZR6um84QIoS8AZoOrRzuck/wX+Xh4P4sxDumBjIrgzYO/zWjjzf+mJ4f1gdTtKzaYtJFfzaGzSdmRbB1pou2Rzamw== 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=wHPXNEeclxxQk9RIQ6EynEvhBEdE2/umOOLq5uqBq8k=; b=eobm/hZe15s9Euf0cw5vsSjndW3WUlagyLiJwCCAksR1eIZDWHn37iVIyr4e+v8WgdnDiHsqwZSHza6hwnb/NMuv8aShhHIqC7SF3qVKN+QQuDWPbKCMVm34O7iW2Xs/H1uFm+gzBknsbHrC9M2lgMNRGmn4OOZX/eYzXajk9y9NHZro2urOWg9faibHJz8UR3OjjGx8zuJykPMTG5xblW2uaqLMszn+xyb2Z+tMA+JjLhdAEqukyZu+/WzOE9ac68rUiEfVbqolp2GpiCbxcxHi1ADVCzmROrFHcvu+eZna2WeVtCdZxV7QzGWrknpLpaH/w0QdB/91h7+z0VG+TQ== 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=wHPXNEeclxxQk9RIQ6EynEvhBEdE2/umOOLq5uqBq8k=; b=YV4biGmPbIvyxcl828PQbEoMoCgk2c9FI826+QLMztUK9MAgh/HE2cLx+YC30WZj2vUTjISiqChVYJgK/H/YqciPq4AcjHhptEGKKzny/iCnaAac9xzNrDWldyblFocpH2Gu9vf234HT5yVbuGjR5UbAuQ0j0VigqHvKi5206lE= Received: from AM4PR05MB3265.eurprd05.prod.outlook.com (10.171.188.154) by AM4PR05MB3315.eurprd05.prod.outlook.com (10.171.190.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Fri, 17 Jan 2020 08:47:56 +0000 Received: from AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::68eb:ad79:71f4:110f]) by AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::68eb:ad79:71f4:110f%3]) with mapi id 15.20.2623.018; Fri, 17 Jan 2020 08:47:56 +0000 From: Slava Ovsiienko To: Jack Min , "jerinjacobk@gmail.com" , Ori Kam , Matan Azrad , Raslan Darawsheh , Shahaf Shuler , Anatoly Burakov CC: "dev@dpdk.org" , "Xueming(Steven) Li" Thread-Topic: [PATCH 4/5] net/mlx5: add socket server for external tools Thread-Index: AQHVzFXt9wwLCxNFmkCChbQD7PQrWqfui+vw Date: Fri, 17 Jan 2020 08:47:56 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=viacheslavo@mellanox.com; x-originating-ip: [77.75.144.194] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: b3351071-49f2-4192-9e4f-08d79b29f2ac x-ms-traffictypediagnostic: AM4PR05MB3315:|AM4PR05MB3315: 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:849; x-forefront-prvs: 0285201563 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(376002)(39850400004)(396003)(366004)(346002)(136003)(199004)(189003)(76116006)(7696005)(110136005)(55016002)(54906003)(316002)(66446008)(71200400001)(107886003)(66946007)(6506007)(33656002)(53546011)(26005)(186003)(4326008)(478600001)(64756008)(9686003)(66476007)(66556008)(86362001)(2906002)(5660300002)(8676002)(52536014)(81166006)(81156014)(8936002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR05MB3315; H:AM4PR05MB3265.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX: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: /w1Dv+h1On2409nmRjQ8lDebLUh05rZO2WBiwAVwGkflHpnqIeIsA5QGWW4ic1MCi1LgHbeAA//x1aQ8LkffTbbqShzS+wUeaeAqy1/tO2na16n93DNOGnFzazMIpAXHbQxI3psofOf3Mn/kl/DVLi8IbiYEeCWqXAiEViyOjfpGct7NEJ00lszmmumI4U3ug9F+c+wWHc+kFFEc214JOZvXYbIMwve/Z/xJdBWtoy6Us8qitgLr55Xr/Crt5ArCLCLpa8G6lh/HFDkeSk83n9U34Z6RFXNS40ryTuKpaYNhl05LNoDeNoS2A/H9vsFyb7NCYLMPv1UM6elsDTdb48fIlsEf0Ww0AUqB+FIQ5DJd2GI6llGprlrj6NBSiyrsXdv0D3NqbXe2kDjmoANson4Zz/k7M0SDjHZ7LhmBKiEnIwrkTk2p+HjsqrNLMncn Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: b3351071-49f2-4192-9e4f-08d79b29f2ac X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jan 2020 08:47:56.0959 (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: 7wzOhEC3wvM3/8H4MNDijEW3eN1EchTwihjma/HZNlArNkXB9J0dnkhxsyeF3Kkp36/XsFlJyu5u4yC5cTKYLMsGj/2nGWLN0QiX4Gv+KvQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR05MB3315 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" Hi, Jack > -----Original Message----- > From: Xiaoyu Min > Sent: Thursday, January 16, 2020 12:14 > To: jerinjacobk@gmail.com; Ori Kam ; Slava Ovsiienko > ; 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 trigge= r > 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 index > 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_socke= t.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. > + /* 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. > + claim_zero(close(server_socket)); > + server_socket =3D 0; > + claim_zero(remove(path)); > +} > -- > 2.24.1 With best regards, Slava