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 9383BA10DA for ; Fri, 2 Aug 2019 07:33:24 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9251A1C20B; Fri, 2 Aug 2019 07:33:23 +0200 (CEST) Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-eopbgr20042.outbound.protection.outlook.com [40.107.2.42]) by dpdk.org (Postfix) with ESMTP id 070EC1C1FC for ; Fri, 2 Aug 2019 07:33:21 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TIuWJbjVXT4sTIPNxtyTZovEi9rSkuqcoEwn4j146fCFLKIHKKOB9oqs8CQA/KXYk5HSMZZOiVAUPl4QHDPvZ3KsdOahJN4BTVHwCUbvZ3HidYNOM/3nxId6gfrpqwiBJImQ2xLnIm3vca8zBXzQu9ovOJ4BSXka4rUGBAb80lzILbUA4B/pSR7iYGa9L3x1H2fJPjnRKW0r9yzoS4qhBDW7WUVe8vHZaSgiGX2KW43IdZOxJRlaZsqDp//kIr2RmvTpVlOJ1vg2fDGbu9nibieZ4600rlB5H+2dzlwTCWdxhcwQfT4t4joqYMQIDxyHn71K2Uven03T4jM/KMxYiw== 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=XHd8VMIPJjcZMO2DITWqLZ8mfz+QUoDOO7gQTTlW45M=; b=EYaXmYl6WShs2c3/Ijr78VZYOmKUNQtK34100u/IGLsoXE+D7afPc80pbUif/QEzVsCD1ggIbOSG2MWUeH2c6xYh1tMaevwZvpi1s5vrNddbHyntHFX4+634S2pkaZbN7OecKkB/RQRjpsKq7l1pihl2g43fwPvJHN4LNusm4v7IMU0s/hyWed0iwUaf1vMmp+iPTGGB5ZniedmjzJQnfbset8ghKgk2alTtF2nyv9oVmqcRThhPmR85ETEbdsXnjq2IkYDCeh6ofrLu1eBLfCGymj+J5WvUiKiIg+krJYvP9+RLJcORsCgo/IoV62ezi5pV+GYhnIDYaxuqCU+kMw== 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=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XHd8VMIPJjcZMO2DITWqLZ8mfz+QUoDOO7gQTTlW45M=; b=nmCzSIO1p8tlnUoNjZlVq6riD4Ct5CaRAyvOf3GoJlvux4WB7DLd328DtWxcG4d/x8Wi34ChhWndB3A9HfCa7vzbjoAQKRSMYlMH7Qd7Xel5T9BokJo1lvWZRfTqHHY29CxD1+VoTODyBPxQXFY4AqJIXLyyEJIOzLyE8v43mD0= Received: from AM0PR0502MB4019.eurprd05.prod.outlook.com (52.133.39.139) by AM0PR0502MB3906.eurprd05.prod.outlook.com (52.133.45.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2115.14; Fri, 2 Aug 2019 05:33:20 +0000 Received: from AM0PR0502MB4019.eurprd05.prod.outlook.com ([fe80::ccc2:2dd4:ca86:7639]) by AM0PR0502MB4019.eurprd05.prod.outlook.com ([fe80::ccc2:2dd4:ca86:7639%3]) with mapi id 15.20.2136.010; Fri, 2 Aug 2019 05:33:20 +0000 From: Matan Azrad To: Stephen Hemminger , "dev@dpdk.org" CC: Stephen Hemminger Thread-Topic: [dpdk-dev] [PATCH v5 1/4] examples/multi_process/client_server_mp: check port validity Thread-Index: AQHVSN4xLv7kSing+E2mYW264dJi7abnUo3w Date: Fri, 2 Aug 2019 05:33:20 +0000 Message-ID: References: <20190726165054.24078-1-stephen@networkplumber.org> <20190802025826.1174-1-stephen@networkplumber.org> <20190802025826.1174-2-stephen@networkplumber.org> In-Reply-To: <20190802025826.1174-2-stephen@networkplumber.org> Accept-Language: en-US, he-IL Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; x-originating-ip: [77.126.64.114] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 52de8b4f-e37a-4bef-26dd-08d7170aee07 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:AM0PR0502MB3906; x-ms-traffictypediagnostic: AM0PR0502MB3906: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5516; x-forefront-prvs: 011787B9DD x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(39860400002)(346002)(376002)(366004)(136003)(199004)(189003)(33656002)(110136005)(2501003)(229853002)(66066001)(316002)(81166006)(81156014)(86362001)(68736007)(76116006)(71200400001)(99286004)(7736002)(478600001)(14454004)(9686003)(71190400001)(4326008)(6246003)(74316002)(8936002)(53936002)(476003)(6116002)(446003)(7696005)(305945005)(76176011)(102836004)(55016002)(52536014)(3846002)(11346002)(2906002)(6436002)(5660300002)(486006)(66946007)(25786009)(14444005)(66556008)(186003)(66476007)(64756008)(66446008)(53546011)(26005)(6506007)(256004); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR0502MB3906; H:AM0PR0502MB4019.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-message-info: 3VUJuwfKAiUZbmp8u2VagZn5Xn/Z41Tfd4LBZgInpzhd82mGTo6GX2yV0CodIh5clBd+SrhY0Or5hTmKv9uhaxKTCB7+0taDHrv+Y4W5k7TbAGNE3VJhxCMdvOssNby5q2+8uYDVqR7sJNiZzYf+ziBA7VizwfdYaIpTsgymEOkV0bSv4CXj+qkwPJYzB08WxwNH4d0RBsFRdi9PD9tr7PQzTBcXPp87V3cF14r6OuLF9AKy/OWcXtRuoawm0mk0YNndL1TnlPGnIcHZ4n9AJUTgFkvZi9JlERwwzVOoYOMHHQDGk1qcgYgzgJVf9wb4gBc+s+b3qZKE9oFkPBvJZziEAXO+JYxuGFxXm6XqpK2VjVossGnlOV5Qeuzt5QOAE9Iv3RIPTeABviLZ/XKPcFvQfyFm8n8HJpZWATsH/hM= 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: 52de8b4f-e37a-4bef-26dd-08d7170aee07 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Aug 2019 05:33:20.5233 (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: matan@mellanox.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0502MB3906 Subject: Re: [dpdk-dev] [PATCH v5 1/4] examples/multi_process/client_server_mp: check port validity 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 Stephen One more small comment inline From: Stephen Hemminger > Sent: Friday, August 2, 2019 5:58 AM > To: dev@dpdk.org > Cc: Stephen Hemminger > Subject: [dpdk-dev] [PATCH v5 1/4] > examples/multi_process/client_server_mp: check port validity >=20 > From: Stephen Hemminger >=20 > The mp_server incorrectly allows a port mask that included hidden ports a= nd > which later caused either lost packets or failed initialization. >=20 > This fixes explicitly checking that each bit in portmask is a valid port = before > using it. >=20 > Fixes: 5b7ba31148a8 ("ethdev: add port ownership") > Signed-off-by: Stephen Hemminger > --- > .../client_server_mp/mp_server/args.c | 35 ++++++++++--------- > .../client_server_mp/mp_server/args.h | 2 +- > .../client_server_mp/mp_server/init.c | 7 ++-- > 3 files changed, 22 insertions(+), 22 deletions(-) >=20 > diff --git a/examples/multi_process/client_server_mp/mp_server/args.c > b/examples/multi_process/client_server_mp/mp_server/args.c > index b0d8d7665c85..fdc008b3d677 100644 > --- a/examples/multi_process/client_server_mp/mp_server/args.c > +++ b/examples/multi_process/client_server_mp/mp_server/args.c > @@ -10,6 +10,7 @@ > #include >=20 > #include > +#include > #include >=20 > #include "common.h" > @@ -41,31 +42,33 @@ usage(void) > * array variable > */ > static int > -parse_portmask(uint8_t max_ports, const char *portmask) > +parse_portmask(const char *portmask) > { > char *end =3D NULL; > unsigned long pm; > - uint16_t count =3D 0; > + uint16_t id; >=20 > if (portmask =3D=3D NULL || *portmask =3D=3D '\0') > return -1; >=20 > /* convert parameter to a number and verify */ > pm =3D strtoul(portmask, &end, 16); > - if (end =3D=3D NULL || *end !=3D '\0' || pm =3D=3D 0) > + if (end =3D=3D NULL || *end !=3D '\0' || pm > UINT16_MAX || pm =3D=3D 0= ) Why pm > UINT16_MAX ? should be something like > (1 << RTE_MAX_ETHPORTS) - = 1. And need to be sure pm type can hold RTE_MAX_ETHPORTS bits, otherwise port = 0 may unlikely be all the time visible in the loop below. > return -1; >=20 > - /* loop through bits of the mask and mark ports */ > - while (pm !=3D 0){ > - if (pm & 0x01){ /* bit is set in mask, use port */ > - if (count >=3D max_ports) > - printf("WARNING: requested port %u not > present" > - " - ignoring\n", (unsigned)count); > - else > - ports->id[ports->num_ports++] =3D count; > - } > - pm =3D (pm >> 1); > - count++; > + RTE_ETH_FOREACH_DEV(id) { > + unsigned long msk =3D 1u << id; > + > + if ((pm & msk) =3D=3D 0) > + continue; > + > + pm &=3D ~msk; > + ports->id[ports->num_ports++] =3D id; > + } > + > + if (pm !=3D 0) { > + printf("WARNING: leftover ports in mask %#lx - ignoring\n", > + pm); > } >=20 > return 0; > @@ -99,7 +102,7 @@ parse_num_clients(const char *clients) > * on error. > */ > int > -parse_app_args(uint16_t max_ports, int argc, char *argv[]) > +parse_app_args(int argc, char *argv[]) > { > int option_index, opt; > char **argvopt =3D argv; > @@ -112,7 +115,7 @@ parse_app_args(uint16_t max_ports, int argc, char > *argv[]) > &option_index)) !=3D EOF){ > switch (opt){ > case 'p': > - if (parse_portmask(max_ports, optarg) !=3D 0){ > + if (parse_portmask(optarg) !=3D 0) { > usage(); > return -1; > } > diff --git a/examples/multi_process/client_server_mp/mp_server/args.h > b/examples/multi_process/client_server_mp/mp_server/args.h > index 79c190a33a37..52c8cc86e6f0 100644 > --- a/examples/multi_process/client_server_mp/mp_server/args.h > +++ b/examples/multi_process/client_server_mp/mp_server/args.h > @@ -5,6 +5,6 @@ > #ifndef _ARGS_H_ > #define _ARGS_H_ >=20 > -int parse_app_args(uint16_t max_ports, int argc, char *argv[]); > +int parse_app_args(int argc, char *argv[]); >=20 > #endif /* ifndef _ARGS_H_ */ > diff --git a/examples/multi_process/client_server_mp/mp_server/init.c > b/examples/multi_process/client_server_mp/mp_server/init.c > index 3af5dc6994bf..1b0569937b51 100644 > --- a/examples/multi_process/client_server_mp/mp_server/init.c > +++ b/examples/multi_process/client_server_mp/mp_server/init.c > @@ -238,7 +238,7 @@ init(int argc, char *argv[]) { > int retval; > const struct rte_memzone *mz; > - uint16_t i, total_ports; > + uint16_t i; >=20 > /* init EAL, parsing EAL args */ > retval =3D rte_eal_init(argc, argv); > @@ -247,9 +247,6 @@ init(int argc, char *argv[]) > argc -=3D retval; > argv +=3D retval; >=20 > - /* get total number of ports */ > - total_ports =3D rte_eth_dev_count_total(); > - > /* set up array for port data */ > mz =3D rte_memzone_reserve(MZ_PORT_INFO, sizeof(*ports), > rte_socket_id(), NO_FLAGS); > @@ -259,7 +256,7 @@ init(int argc, char *argv[]) > ports =3D mz->addr; >=20 > /* parse additional, application arguments */ > - retval =3D parse_app_args(total_ports, argc, argv); > + retval =3D parse_app_args(argc, argv); > if (retval !=3D 0) > return -1; >=20 > -- > 2.20.1