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 A6C9EA00E6 for ; Sun, 7 Jul 2019 07:44:58 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9616437B0; Sun, 7 Jul 2019 07:44:57 +0200 (CEST) Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40043.outbound.protection.outlook.com [40.107.4.43]) by dpdk.org (Postfix) with ESMTP id 643A2325F for ; Sun, 7 Jul 2019 07:44:56 +0200 (CEST) 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=+VYjZSAyv/O90AtlmyZPIBqckcOTS3B/CIJtwq+iqjQ=; b=A2N3cvx2chbtWLTxCMk4T7tslmXpiq5Zh4ca3VO56cxyZz6ZdYdy6RlH3IseQIC129Klzu5XoSFBy3ldhkQrFtY8q8/A4FHIKwp0yC3Z5mJcxs9a8b5i+hDoJKhTdmVChaaxQbuQbQZmjeFjQ0Lt4Bt89cTJjmxdFBDyjZnAX0E= Received: from AM0PR0502MB4019.eurprd05.prod.outlook.com (52.133.39.139) by AM0PR0502MB4052.eurprd05.prod.outlook.com (52.133.36.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2052.19; Sun, 7 Jul 2019 05:44:55 +0000 Received: from AM0PR0502MB4019.eurprd05.prod.outlook.com ([fe80::a81f:9e35:487d:d788]) by AM0PR0502MB4019.eurprd05.prod.outlook.com ([fe80::a81f:9e35:487d:d788%7]) with mapi id 15.20.2052.020; Sun, 7 Jul 2019 05:44:55 +0000 From: Matan Azrad To: Stephen Hemminger , "anatoly.burakov@intel.com" CC: "dev@dpdk.org" , Stephen Hemminger Thread-Topic: [dpdk-dev] [PATCH v2] examples/client_server_mp: check port ownership Thread-Index: AQHVGlu1QfOZ+lP0YEqwbORYsagaQaa+1iBw Date: Sun, 7 Jul 2019 05:44:55 +0000 Message-ID: References: <20190529224321.20760-1-stephen@networkplumber.org> <20190603222835.27909-1-stephen@networkplumber.org> In-Reply-To: <20190603222835.27909-1-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: b41b029d-07a9-44c3-40bb-08d7029e3d45 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:AM0PR0502MB4052; x-ms-traffictypediagnostic: AM0PR0502MB4052: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7219; x-forefront-prvs: 0091C8F1EB x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(39850400004)(136003)(346002)(396003)(376002)(366004)(199004)(189003)(7696005)(55016002)(52536014)(478600001)(9686003)(102836004)(86362001)(186003)(305945005)(8936002)(76176011)(26005)(7736002)(6506007)(99286004)(25786009)(5660300002)(6436002)(14444005)(6246003)(81156014)(53936002)(2906002)(256004)(81166006)(14454004)(4326008)(33656002)(2501003)(73956011)(66946007)(66066001)(229853002)(76116006)(66476007)(316002)(446003)(476003)(3846002)(6116002)(11346002)(66556008)(74316002)(54906003)(486006)(64756008)(110136005)(71190400001)(68736007)(71200400001)(66446008); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR0502MB4052; 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: cgyxJULGHamimYOwVwyOz6Ym0XHw5xi8fczbMHQ3TXtUuKM+5UVa7Tsag291BOOL19ai3CSLtK1oqlQ3+N6fBLJkJfBGAeyUdEV7cJTK5hUczwQHg6KJTjk68fXI52o7rj4kOpFIYbVFJZIgRV1ujmKr+7AaPc8QUDaLtxS3upyyyBVLfvc9ncGGOcv779+n0wedzcYOjWFgxEYXhlFJLj1v9ieGHxpouaUAG/FA1ZjamOnks3ykct0pJ/JMtof5MPRg+gc0zMxgJi4Y79H18JwEmZxilshCVS+AI5+gjgwTjEdFG2D6u4e5XmMUAsBryGhzGhJ9vnOtZRvq70ndIhph6MGEp4WWuc7fx8bu1RK1jsypscBiRaw3trcIO/RaOd86BnJvnRj3kN+L2xySTVgMYjyjpn9vRLUquv/Tw9c= 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: b41b029d-07a9-44c3-40bb-08d7029e3d45 X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Jul 2019 05:44:55.1342 (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: AM0PR0502MB4052 Subject: Re: [dpdk-dev] [PATCH v2] examples/client_server_mp: check port ownership 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 would accept a port mask that included hidden (owned) > ports and which later caused either lost packets or failed initialization= . >=20 > This fixes explicitly checks for ownership when parsing the port mask. >=20 > Fixes: 5b7ba31148a8 ("ethdev: add port ownership") > Signed-off-by: Stephen Hemminger > --- > v2 - fix checkpatch complains about return and else >=20 > .../client_server_mp/mp_server/args.c | 35 +++++++++++++------ > 1 file changed, 24 insertions(+), 11 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..72cb85008c39 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" > @@ -45,27 +46,39 @@ parse_portmask(uint8_t max_ports, 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) { > + struct rte_eth_dev_owner owner; > + > + if ((pm & 0x1) =3D=3D 0) > + continue; > + > + if (count >=3D max_ports) { > + printf("WARNING: requested port %u not present - > ignoring\n", > + count); > + continue; > + } > + if (rte_eth_dev_owner_get(count, &owner) < 0) { > + printf("ERROR: can not find port %u owner\n", > count); What if some entity will take ownership later? If you want the app will be ownership aware: if you sure that you want this port to be owned by this application you ne= ed to take ownership on it. else: the port is hidden by RTE_ETH_FOREACH_DEV if it is owned by some entity.=20 see how it was done in testpmd function: port_id_is_invalid(). > + return -1; > } > - pm =3D (pm >> 1); > - count++; > + if (owner.id !=3D RTE_ETH_DEV_NO_OWNER) { > + printf("ERROR: requested port %u is owned by > device %s\n", > + count, owner.name); > + return -1; > + } > + > + ports->id[ports->num_ports++] =3D count; > } >=20 > return 0; > --