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 D0E45A0487 for ; Tue, 30 Jul 2019 11:21:05 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 74DD01C01B; Tue, 30 Jul 2019 11:21:05 +0200 (CEST) Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-eopbgr130075.outbound.protection.outlook.com [40.107.13.75]) by dpdk.org (Postfix) with ESMTP id 6DA9D1BEB6 for ; Tue, 30 Jul 2019 11:21:03 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GLKC1ts81caMQ5Er4btbT/8wIMkUJEml2aE9iJlChiv9BbE/2G58kTf/2a8xaaNAIJlwP31oYmNF+MGcACOWd6KINkE8swlj1O8Dy3+Wt5i6ULznTnzOWLDT5nE5Vws300DWr310StJESq81isXwREavbCFtOEZ+Z6d0fN9+pvlpkzKehxDdAeBAvfAfCzRePzaRBY2KsxDIpfLXcMEjUtYHVYdaxtwtt2tPjR/Z9xqRrcDG0UWlJzQP+/AjF/NsZcDhKMgipSW2AhdoANZJ4CLLtvvabQrkTPUHiYV8Nrs6dV46FYO4BUzDMBocEPrWeKL/CjmmqFdyur2u6GJmeA== 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=J+Z7NmXUQZwa2xS8dkQbf/8TVlhubV3QFn01lNhQT2Y=; b=mEo1U/gpxYh8Dr5ceNKOHCLNzvkzzsN6FK5yKGbOqJQ7L6e6oR32Fcjh3XkC/wiRzwmHTcs2r2GmhKOSsQUbCtiioTqYioiB4+bvDJQfXbK+zycasXKQGQG4xI1d6GkowlHkggE4z+btV3pJbAuMdGGPnKIqrDWpLJzxO7j4YiDU+0iCTJBrqE2QAZAjU/j8Z/hwqjo+s1ch+xe5D0pncy0ZA9Bu2FNZxojkm/nzZNu88Bonoz3BalaDuOOirZR51LOveaugaHozZg+LyTs3R8NtdOaq6GANo7AcTbbHfbRV0T7PZUQNQnicOoSZ4kLzHPXOL/V+Tb9IcmCRQs00rQ== 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=J+Z7NmXUQZwa2xS8dkQbf/8TVlhubV3QFn01lNhQT2Y=; b=dL2/7KrUOt0WBABidZT3tsD5iUWtKGMfE5f6DifN40SORKeZoVZe1VluZqW6W25Mlnci3iv8aTBcJf2LMSPKQ34wc+geJrNl2aTPyB+ylHeJX0qjWLO0YnDdL5Epf7moCnk98wmBgZu9C7BDScLcn3YuFKYvhFOwwCnhmuUdan8= Received: from AM0PR0502MB4019.eurprd05.prod.outlook.com (52.133.39.139) by AM0PR0502MB3955.eurprd05.prod.outlook.com (52.133.39.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2115.10; Tue, 30 Jul 2019 09:21:02 +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.2115.005; Tue, 30 Jul 2019 09:21:02 +0000 From: Matan Azrad To: Stephen Hemminger , "dev@dpdk.org" CC: Stephen Hemminger Thread-Topic: [dpdk-dev] [PATCH v4 1/4] examples/multi_process/client_server_mp: check port validity Thread-Index: AQHVQ9JZ6Z4XSeF3EEi0qQjX3dyE2Kbi5tOA Date: Tue, 30 Jul 2019 09:21:02 +0000 Message-ID: References: <20190709150939.31338-1-stephen@networkplumber.org> <20190726165054.24078-1-stephen@networkplumber.org> <20190726165054.24078-2-stephen@networkplumber.org> In-Reply-To: <20190726165054.24078-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: [193.47.165.251] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 3bbffaa3-0ef0-4aa4-f5af-08d714cf3dd2 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(5600148)(711020)(4605104)(1401327)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020); SRVR:AM0PR0502MB3955; x-ms-traffictypediagnostic: AM0PR0502MB3955: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7691; x-forefront-prvs: 0114FF88F6 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(346002)(376002)(39860400002)(366004)(136003)(199004)(189003)(99286004)(6116002)(55016002)(26005)(14454004)(68736007)(81156014)(81166006)(256004)(2501003)(110136005)(316002)(86362001)(33656002)(14444005)(71190400001)(8936002)(5660300002)(478600001)(71200400001)(7696005)(66476007)(486006)(53936002)(66066001)(7736002)(476003)(66946007)(52536014)(64756008)(74316002)(305945005)(6506007)(229853002)(76116006)(6436002)(2906002)(102836004)(66446008)(9686003)(186003)(76176011)(6246003)(11346002)(3846002)(25786009)(446003)(66556008)(4326008); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR0502MB3955; 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: iyAJNc0YVC+ZHgAk0iskageOtlgwsyGp61geVr/ov0vP3McnmaBrt3aYjI3nI5R4dgp+oZBNgFrqqUV4czbuL43kF1C72Vc5CdRUbYiHiQWCBBerObadfeHAQb8x51kjLyn+qxLDfjWLf8RBp9a21ElU6EsH5QXmEdcQbjYRWbNQp3ovb2+4hITre4/28V6cjaviJd+3KoaxCwZWFgYnKI9vqr8OQ/ZiSBu/ZcW4Az87FLdr/zPZBC8ZwzUoBOdGsGiYTGtuHiMo6bxR70FAvKUNleDEHzxpIrFuXsj5Z3rUyehMepxIXglfO0eXWgurOWSOML4Bp5OjaloZhWl1UaeumXSOu2x3LrDl3jtMHVTIsjtPSHgurQpHxQdXw3ZlmH/VVyb5nfIYOr8S0dXn1YbnUTBOcI+Sbvd/jKnwTTg= 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: 3bbffaa3-0ef0-4aa4-f5af-08d714cf3dd2 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Jul 2019 09:21:02.3296 (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: AM0PR0502MB3955 Subject: Re: [dpdk-dev] [PATCH v4 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 From: Stephen Hemminger > 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 | 46 +++++++++++++------ > .../client_server_mp/mp_server/args.h | 2 +- > .../client_server_mp/mp_server/init.c | 7 +-- > 3 files changed, 35 insertions(+), 20 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..c1ab12ad00d1 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" > @@ -34,6 +35,22 @@ usage(void) > , progname); > } >=20 > +/** > + * Check if port is present in the system > + * It maybe owned by a device and should not be used. > + */ > +static int > +port_is_present(uint16_t portid) > +{ > + uint16_t id; > + > + RTE_ETH_FOREACH_DEV(id) { > + if (id =3D=3D portid) > + return 1; > + } > + return 0; > +} > + > /** > * The ports to be used by the application are passed in > * the form of a bitmask. This function parses the bitmask @@ -41,31 +58= ,32 > @@ 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 count; >=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= ) > 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; > + for (count =3D 0; pm !=3D 0; pm >>=3D 1, ++count) { > + if ((pm & 0x1) =3D=3D 0) > + continue; > + > + if (!port_is_present(count)) { > + printf("WARNING: requested port %u not present - > ignoring\n", > + count); > + continue; > } > - pm =3D (pm >> 1); > - count++; > + > + ports->id[ports->num_ports++] =3D count; > } Why not just to do something like: RTE_ETH_FOREACH_DEV(id) { If (pm & (1 << id)) { pm &=3D ~(1 << id)=20 put in list } } If (pm)=20 Warning > return 0; > @@ -99,7 +117,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 +130,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