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 D3AF1A00E6 for ; Tue, 6 Aug 2019 14:07:28 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8122F1B956; Tue, 6 Aug 2019 14:07:28 +0200 (CEST) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80081.outbound.protection.outlook.com [40.107.8.81]) by dpdk.org (Postfix) with ESMTP id 78CAB1B955 for ; Tue, 6 Aug 2019 14:07:26 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nWTRFA32arKim1203P3+04/eFmym6eGK2CaqNNR8ia086wR4Az9p99GsKbiYcrrxJcTFy6McnnQGZX5IcaGNpb/9753rTtCKVTCDf5zWirp2wnNjWmljFXio3JQZ3ppyS+ZujxPzp26Dw0UXwwHCZ0nUXUI/S8AgdUpujLm5ASTeWx2BZb6QaYyrpbf5uqOfdC46A1Xdhpoho+pQ+lIrwSEsp040Unfi4Iw0VFZwClEN+NlhPFNfn68WN267Cne6Hh/ulIY1PFV2IAuJLA9RoH+RnRXzPfyKf6zj4zjWP7g0rLuEcRyQ2w7LKTLE75i9ttbEQBL170BmtLVHJO9sgQ== 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=cocBwPF/zDDArWaxf4O9RoG3rBgKN+ueRc8AuM/M1nE=; b=RY4PdPy8MhervCeqeA4aMYe5L3AoUXSfCxfzTvZay+EP7CmD1F/+ZXWs4Ud88FbQhXXAAhTOockuvOKjAytEcOxdXJnKTCetmb+2n2QyKXHU4Naw64hMkvLIsK2SCtpygj8xG5vKiTMFTIuYa1F49e2onv9eF6xFJNucYEweE7giywXcYA83/9VyCZR7+VonpmLfIjX0zatiLWoDDbYVdnMDHhLbiXqwPYzaQVWqMDb6k9gv58X3qIwaIfKPDslDXwibBXRDhYwBvsrQ4ua+PCA7vz8OWV3SHIAZgcix0xA0DcB7SrvbJv1fgpmhjFiGuLcX0X/HHAryj/BqBa4TzQ== 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=cocBwPF/zDDArWaxf4O9RoG3rBgKN+ueRc8AuM/M1nE=; b=eXUZ4x4AjLqq5ehfNwkasw2WGem8AFXaLZ+5rqklXVjdaNWREVlZTNjPeok/CT/oPruYmJXf7KcZ0CLCiNjgBPoWTNPo3IpHU2lFd9eZXCuKXp1Rb/p2RBwujLr/y0JJwa+NhEWK80UZNUdPdZ8K/jPyEcMhzb5cr/SYbGmS7Kk= Received: from AM0PR0502MB4019.eurprd05.prod.outlook.com (52.133.39.139) by AM0PR0502MB3924.eurprd05.prod.outlook.com (52.133.48.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2157.14; Tue, 6 Aug 2019 12:07:25 +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; Tue, 6 Aug 2019 12:07:25 +0000 From: Matan Azrad To: Stephen Hemminger , "dev@dpdk.org" CC: Stephen Hemminger Thread-Topic: [dpdk-dev] [PATCH v7 1/2] examples/multi_process/client_server_mp: check port validity Thread-Index: AQHVS6w71uEJA1UT70OLvuVrp+0t2KbuBx4g Date: Tue, 6 Aug 2019 12:07:25 +0000 Message-ID: References: <20190726165054.24078-1-stephen@networkplumber.org> <20190805163817.3713-1-stephen@networkplumber.org> <20190805163817.3713-2-stephen@networkplumber.org> In-Reply-To: <20190805163817.3713-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: 1c83a2e1-8090-4c12-9158-08d71a66a52e 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:AM0PR0502MB3924; x-ms-traffictypediagnostic: AM0PR0502MB3924: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6430; x-forefront-prvs: 0121F24F22 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(366004)(136003)(346002)(376002)(39860400002)(396003)(189003)(199004)(13464003)(71190400001)(102836004)(33656002)(71200400001)(316002)(52536014)(486006)(26005)(86362001)(66556008)(64756008)(7736002)(66446008)(66476007)(66946007)(14444005)(256004)(76116006)(25786009)(186003)(6116002)(3846002)(305945005)(74316002)(478600001)(229853002)(2906002)(99286004)(8936002)(6246003)(9686003)(6436002)(55016002)(66066001)(53936002)(2501003)(68736007)(14454004)(5660300002)(53546011)(76176011)(6506007)(7696005)(476003)(11346002)(81156014)(81166006)(446003)(110136005)(4326008); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR0502MB3924; H:AM0PR0502MB4019.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-message-info: m+5pTIAMBj9H5opIGNOm58oKeU5xHY6WYKBdpAQVpwVLOXPnupy38xYHISHbfM6xtuzlOcmHTTsnNOktN+sbzvX/VtoRpdDAi4bFKpAzId98HG+At8w945VTvyHSBgkqmrW4ssye2kKZe8/cxywyzEwoxmD9cby+XKRl0ebRywpM9PVcz9XN0QOVpetZ2UIbtsLy0ztXWpsH0u7SJFtgYom1wBWvOTvIn/ZDBYJvLWHUxOcUWykbk3X8V6Kx/avMsk05Wz9qQyKLAl4277rsZAD1iTou1/Jfv+A3NkmbovFVoYn2lHGc6M7HGTZ9RnFYpyXzKwZDruLfHJAQs3iLi8RL+VqGg6xCofSK9rA3OZ5h/N8RiNc0EzNfHj+1Qi3LPAhS1R7CDIb8aTXHHW57/fKMiBZNK069pkG4SgZL8ww= x-ms-exchange-transport-forked: True 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: 1c83a2e1-8090-4c12-9158-08d71a66a52e X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Aug 2019 12:07:25.4874 (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: AM0PR0502MB3924 Subject: Re: [dpdk-dev] [PATCH v7 1/2] 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 > -----Original Message----- > From: dev On Behalf Of Stephen Hemminger > Sent: Monday, August 5, 2019 7:38 PM > To: dev@dpdk.org > Cc: Stephen Hemminger > Subject: [dpdk-dev] [PATCH v7 1/2] > 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 | 40 ++++++++++--------- > .../client_server_mp/mp_server/args.h | 2 +- > .../client_server_mp/mp_server/init.c | 7 +--- > 3 files changed, 25 insertions(+), 24 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..3c2ca266b096 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,34 @@ 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; > + unsigned long long pm; > + 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) > + errno =3D 0; > + pm =3D strtoull(portmask, &end, 16); > + if (errno !=3D 0 || end =3D=3D NULL || *end !=3D '\0') > return -1; >=20 Please Continue discussion on this on V5 thread. > - /* 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 %#llx - ignoring\n", > + pm); > } >=20 > return 0; > @@ -99,7 +103,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 +116,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