From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DE31EA0C3F; Sat, 3 Jul 2021 03:32:40 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 88F7341402; Sat, 3 Jul 2021 03:32:40 +0200 (CEST) Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2043.outbound.protection.outlook.com [40.107.100.43]) by mails.dpdk.org (Postfix) with ESMTP id 06E6840696; Sat, 3 Jul 2021 03:32:39 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KsdDGg7J+HgfvQeNBcPW8g++74fBTZex2PgNCYUWgoTicFICFmkhvhruDAJiAewud5X5E4do0MPwZd+5y6AHIb3ZGDWiLBDn69ziVO/oEYSAbsLqDq9ibWl8opWlS/TYMzJRFfX2gh4OuEEOst2nD9vQAm31rn1J/WAsLdi5kZWKVF7eynLsupjTRG2vud2bphAfJa+0Je/gd3Mhn9kmDgnQclSQ5sjJ98QS8W7+9BbWv6Sjne/ZPJDy22RsiYwENzN3czbQJjRMOX7tA3KV1jA1UIbyc8YI0/h4Z4UU7Zf+tqnfzGu/+37RtoBhXBkEx5mKgJaUgNsNQBW59sBx1w== 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=bucUY+n1Oy8xRPdduPO2e0ju7V3uUvz224FicgpyxfA=; b=LO7ug4E/StQVdH6eCrVd0PEzbs/9sxidJGQl4+hYhgO7gpgaRBAxUA2QG6kQCm1SnN5bXSEidUK7VajJdzATggf5++00FqDLxYFtQ552tWUytCJvz5eAWwis0/J+GHbiOKiVrptVCMxlC21ih4VRoTRyMcxe6WyrH8jUmMpBXx5lQsEbDIG+xepVBp/hQ0JwLobjskXyFhrFyP8gs7gLTQu6/72/shUenb4vWtmyY+rLdug+rwnLmkCm3K9VaMAQJIfMW0kGeCxm0NHcZFP6dTEnt9Io2dlNABPB+yosIsb5/xvUNoNlvFITNXGoRMUE+gWWqDHxqMDJK4M/I0yoHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bucUY+n1Oy8xRPdduPO2e0ju7V3uUvz224FicgpyxfA=; b=XhcqqsQcENNI6apawkQ9xP3lybE50FHHOKp963GSAIu+0HvXbOb0pwfNS0mFXKtTkezSMIRWS+x94bxq4AiQXkrprA0GfDJALxfAVOBCL8VgDWBR/LQOOk25yYmzh0eIFZrlvaGlTpgQUlU/B12mo1Lj82q31/oEl/VaAek2LGpzaGmuuFZbUEiZhRA8CaDivQtSz+VYtCR1LL8Mr2s0e49dRJrFE2naNG1a2MyqdTRJnAy/b6LpvllLFmEgOpl+KL8n+n/oRSowUiDjW0XqAiN21rJXvQQDGgtdGRGv63DT8VhMF4Ft5ZoxYxCCBbYEYOOB2ayccpHT/FQuio5sQw== Received: from DM4PR12MB5373.namprd12.prod.outlook.com (2603:10b6:5:39a::17) by DM4PR12MB5039.namprd12.prod.outlook.com (2603:10b6:5:38a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.23; Sat, 3 Jul 2021 01:32:37 +0000 Received: from DM4PR12MB5373.namprd12.prod.outlook.com ([fe80::ac75:9b9a:a03f:1676]) by DM4PR12MB5373.namprd12.prod.outlook.com ([fe80::ac75:9b9a:a03f:1676%3]) with mapi id 15.20.4287.030; Sat, 3 Jul 2021 01:32:37 +0000 From: "Xueming(Steven) Li" To: Andrew Rybchenko , Matan Azrad , Shahaf Shuler , Slava Ovsiienko , NBU-Contact-Thomas Monjalon , Ferruh Yigit CC: "dev@dpdk.org" , Viacheslav Galaktionov , "stable@dpdk.org" Thread-Topic: [PATCH] ethdev: keep count of allocated and used representor ranges Thread-Index: AQHXb03kJya602MP90K9lAGikfe6tqswdAtA Date: Sat, 3 Jul 2021 01:32:37 +0000 Message-ID: References: <20210702142322.821302-1-andrew.rybchenko@oktetlabs.ru> In-Reply-To: <20210702142322.821302-1-andrew.rybchenko@oktetlabs.ru> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: oktetlabs.ru; dkim=none (message not signed) header.d=none;oktetlabs.ru; dmarc=none action=none header.from=nvidia.com; x-originating-ip: [2409:891e:bc07:3058:8113:3a0:f37c:3eb3] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: bc151b74-cb76-4ba8-8ccb-08d93dc270e9 x-ms-traffictypediagnostic: DM4PR12MB5039: x-ld-processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6108; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 5tNpB3r6RkpKnZrZrOEU4q088YEn1KZ+utjBxq2tyyYAMiauaJ5G8XdGO5kqspd5Kjwx0ByYd/jZyR1hKlDScYtq1SNJmdc0AwD/FGxKFQAkFACs8WurTZ8ElDjBlkP7SniuKJPiDcC8GaoKFupiMgt/vZYXl3pOajW0eXgkDQl4mm8xwbFrRckZlSyb4LLQX5WoFoOxo2oSBXD3NkfhpXLcam2oDGbg7yfIZgUH/IxTHS4wQJVu101y6IVmdcLVxRwBob4tuSDA3+sMLBKJ1IzbjuYs4QzyD/DDg3QX/nPFBKnxAFppxy4+HUt7fkgDX8Ls5UZnMBjwQSWPGrVY5CxlFds2HOQgiFw0UfFKF5YqLalB2v6hTbUMxlh1FuaVp4Jiv9CJth05WZbJvwwXF4MSAKr+qfP+zcQScjOOhykBDzssIYSoHuiG/McaHNG6gUYCV00QTx0T7WRAIotexz2ra9+FqApk+IwaJ+muSW0Ba4qdSK1R7UU3MuM7z6qkY2Wd7o8U+/Mx41q5r3L57qLgSUFgQebahTLhMc0u+67F7dXgJywADhgU8f5O0vr8YmDYy5FoS81NQmCia8pKn5SqidZGCoVlqbP6XjhugyFUK5SxYrxCkgNPfD6J8oZ9N0s0WgLqgAACEDBDyjsJFA== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR12MB5373.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(39860400002)(366004)(136003)(396003)(376002)(71200400001)(83380400001)(110136005)(4326008)(316002)(54906003)(2906002)(66476007)(66556008)(64756008)(66446008)(122000001)(38100700002)(8936002)(33656002)(8676002)(86362001)(9686003)(52536014)(186003)(76116006)(55016002)(478600001)(66946007)(53546011)(5660300002)(7696005)(6506007); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?qWWN3bzYaELsqfEPMJnG4/nWcLzDVqkynERBpFIA/RpT4cIvtmNUjIV/jtsf?= =?us-ascii?Q?g4D4c/+F1jUimQ5jTpqdeeTeQ8quo9x2MT1D2XcdHd2k/O3/RKNe8lWGiHhX?= =?us-ascii?Q?7G5HZJyYsvs+6rJ4q+xyPaBD1xE2PxlFBeiENHicXCJ2gvYacyrn4J4Rzdrb?= =?us-ascii?Q?kMR1zInMLM0VAEVxu9hn5NRHvpUfjbi2QGsfpyRoQUsTR14jBKI0sYtWGYAh?= =?us-ascii?Q?q4hVEDpW6tSkKQBAYot2wvK0TosD+BzjF1XVlXYxihbBicVzez/rSgG7eBYg?= =?us-ascii?Q?SunGdoZnnDOcgO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/8?= =?us-ascii?Q?9GZHhZk0zKaa9vdMDkK6AGharuMJDysFx4WuzeGS3Tqz2I+W87+tkv/1Zy29?= =?us-ascii?Q?wOqX61WRnFuB1HI0Vs3NH2EcGgO2D9x934+8ikuCzR+o8DefeJ9FlUkcqLfv?= =?us-ascii?Q?MCbaUsyGayrtq7iJYSvhtxC9KvLag5zoOwZhL2TP014asT4fNqtT3hK/qmDN?= =?us-ascii?Q?5n9kL3OgXKfTyfjuawwm8ZA5kD6X?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5373.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: bc151b74-cb76-4ba8-8ccb-08d93dc270e9 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Jul 2021 01:32:37.5635 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 43ZiYnuZOZTbEBCvoRhHswITfAJco9/imCTIU+Zl+/x4g1P5ZTc2r8hcZ7jbLLgRiOqQfogQVa8BtTVHM9B2fg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5039 Subject: Re: [dpdk-dev] [PATCH] ethdev: keep count of allocated and used representor ranges X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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: Andrew Rybchenko > Sent: Friday, July 2, 2021 10:23 PM > To: Matan Azrad ; Shahaf Shuler ; S= lava Ovsiienko ; NBU- > Contact-Thomas Monjalon ; Ferruh Yigit ; Xueming(Steven) Li > > Cc: dev@dpdk.org; Viacheslav Galaktionov ; stable@dpdk.org > Subject: [PATCH] ethdev: keep count of allocated and used representor ran= ges >=20 > From: Viacheslav Galaktionov >=20 > In its current state, the API can overflow the user-passed buffer if a ne= w representor range appears between function calls. >=20 > In order to solve this problem, augment the representor info structure wi= th the numbers of allocated and initialized ranges. This way > the users of this structure can be sure they will not overrun the buffer. Thanks for making this api more robust! >=20 > Fixes: 85e1588ca72f ("ethdev: add API to get representor info") > Cc: stable@dpdk.org >=20 > Signed-off-by: Viacheslav Galaktionov > Signed-off-by: Andrew Rybchenko > --- > drivers/net/mlx5/mlx5_ethdev.c | 15 +++++++++++++++ > lib/ethdev/rte_ethdev.c | 6 ++++-- > lib/ethdev/rte_ethdev.h | 9 ++++++++- > 3 files changed, 27 insertions(+), 3 deletions(-) >=20 > diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethde= v.c index 90baee5aa4..61b1c0e75c 100644 > --- a/drivers/net/mlx5/mlx5_ethdev.c > +++ b/drivers/net/mlx5/mlx5_ethdev.c > @@ -413,9 +413,15 @@ mlx5_representor_info_get(struct rte_eth_dev *dev, > int n_type =3D 4; /* Representor types, VF, HPF@VF, SF and HPF@SF. */ > int n_pf =3D 2; /* Number of PFs. */ > int i =3D 0, pf; > + int n_entries; >=20 > if (info =3D=3D NULL) > goto out; > + > + n_entries =3D n_type * n_pf; > + if ((uint32_t)n_entries > info->nb_ranges_alloc) > + n_entries =3D info->nb_ranges_alloc; > + > info->controller =3D 0; > info->pf =3D priv->pf_bond >=3D 0 ? priv->pf_bond : 0; > for (pf =3D 0; pf < n_pf; ++pf) { > @@ -431,6 +437,8 @@ mlx5_representor_info_get(struct rte_eth_dev *dev, > snprintf(info->ranges[i].name, > sizeof(info->ranges[i].name), "pf%dvf", pf); > i++; > + if (i =3D=3D n_entries) > + break; > /* HPF range of VF type. */ > info->ranges[i].type =3D RTE_ETH_REPRESENTOR_VF; > info->ranges[i].controller =3D 0; > @@ -443,6 +451,8 @@ mlx5_representor_info_get(struct rte_eth_dev *dev, > snprintf(info->ranges[i].name, > sizeof(info->ranges[i].name), "pf%dvf", pf); > i++; > + if (i =3D=3D n_entries) > + break; > /* SF range. */ > info->ranges[i].type =3D RTE_ETH_REPRESENTOR_SF; > info->ranges[i].controller =3D 0; > @@ -455,6 +465,8 @@ mlx5_representor_info_get(struct rte_eth_dev *dev, > snprintf(info->ranges[i].name, > sizeof(info->ranges[i].name), "pf%dsf", pf); > i++; > + if (i =3D=3D n_entries) > + break; > /* HPF range of SF type. */ > info->ranges[i].type =3D RTE_ETH_REPRESENTOR_SF; > info->ranges[i].controller =3D 0; > @@ -467,8 +479,11 @@ mlx5_representor_info_get(struct rte_eth_dev *dev, > snprintf(info->ranges[i].name, > sizeof(info->ranges[i].name), "pf%dsf", pf); > i++; > + if (i =3D=3D n_entries) > + break; > } > out: > + info->nb_ranges =3D i; Here info maybe NULL. > return n_type * n_pf; > } >=20 > diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index c607= eabb5b..30abc93b18 100644 > --- a/lib/ethdev/rte_ethdev.c > +++ b/lib/ethdev/rte_ethdev.c > @@ -5987,7 +5987,8 @@ rte_eth_representor_id_get(const struct rte_eth_dev= *ethdev, > int controller, int pf, int representor_port, > uint16_t *repr_id) > { > - int ret, n, i, count; > + int ret, n, count; > + uint32_t i; > struct rte_eth_representor_info *info =3D NULL; > size_t size; >=20 > @@ -6011,6 +6012,7 @@ rte_eth_representor_id_get(const struct rte_eth_dev= *ethdev, > info =3D calloc(1, size); > if (info =3D=3D NULL) > return -ENOMEM; > + info->nb_ranges_alloc =3D n; > ret =3D rte_eth_representor_info_get(ethdev->data->port_id, info); > if (ret < 0) > goto out; > @@ -6023,7 +6025,7 @@ rte_eth_representor_id_get(const struct rte_eth_dev= *ethdev, >=20 > /* Locate representor ID. */ > ret =3D -ENOENT; > - for (i =3D 0; i < n; ++i) { > + for (i =3D 0; i < info->nb_ranges; ++i) { > if (info->ranges[i].type !=3D type) > continue; > if (info->ranges[i].controller !=3D controller) diff --git a/lib/ethde= v/rte_ethdev.h b/lib/ethdev/rte_ethdev.h index > faf3bd901d..d2b27c351f 100644 > --- a/lib/ethdev/rte_ethdev.h > +++ b/lib/ethdev/rte_ethdev.h > @@ -4856,6 +4856,8 @@ struct rte_eth_representor_range { struct rte_eth_= representor_info { > uint16_t controller; /**< Controller ID of caller device. */ > uint16_t pf; /**< Physical function ID of caller device. */ > + uint32_t nb_ranges_alloc; /**< Size of the ranges array. */ > + uint32_t nb_ranges; /**< Number of initialized ranges. */ How about rte_eth_representor_info_get(info) return max ranges size if info= is NULL,=20 return real initialized ranges if info not NULL? > struct rte_eth_representor_range ranges[];/**< Representor ID range. */= }; >=20 > @@ -4871,11 +4873,16 @@ struct rte_eth_representor_info { > * A pointer to a representor info structure. > * NULL to return number of range entries and allocate memory > * for next call to store detail. > + * The number of ranges that were written into this structure > + * will be placed into its nb_ranges field. This number cannot be > + * larger than the nb_ranges_alloc that by the user before calling > + * this function. It can be smaller than the value returned by the > + * function, however. > * @return > * - (-ENOTSUP) if operation is not supported. > * - (-ENODEV) if *port_id* invalid. > * - (-EIO) if device is removed. > - * - (>=3D0) number of representor range entries supported by device. > + * - (>=3D0) number of available representor range entries. > */ > __rte_experimental > int rte_eth_representor_info_get(uint16_t port_id, > -- > 2.30.2