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 BF8B745A48; Sat, 28 Sep 2024 00:13:59 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 128D14067C; Sat, 28 Sep 2024 00:13:38 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) by mails.dpdk.org (Postfix) with ESMTP id 2D58E402EA for ; Thu, 26 Sep 2024 16:03:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1727359424; x=1758895424; h=from:to:cc:subject:date:message-id:references: in-reply-to:mime-version:content-transfer-encoding; bh=YeClqPcvy0XcvNtef5md05axOLpnLmwQdHJ0E1Nqy34=; b=TadY4YDcNV7G6fx6H+WvlXz6h0qrCt4BF6ua730MkS/M4XzTPrfW6NtC OaQ8NGy7ZeMox3BihGoaBpi7ypwMO5KP+m7puc0diIC+vx1dMyqtWq1b6 g5NUCLFdWtUgz9tlaha8Uutdjc8xt6zIGRIQJGAJnHh4jXkX8c4P8SxCI 3NQ2ElJnQRNVJbHguTk90AbzvPMB4qOgA2KOV6DLcBUumzmYbeL6Ocl3x feUzHzn10uvDgOr3REMx331DJrpqwpbmdG7cbarOh4wnosF9wlNJxFDvc a32Untl4QkAgSRYWE0M5JFUCnzEf0zL/5RJ2WbVi8ItcPIKIE4f76oFmJ w==; X-CSE-ConnectionGUID: 5Tg10uDjSKWJnVm/lA8HOg== X-CSE-MsgGUID: lI/BYu7fTJu9QzqvYlqGPw== X-IronPort-AV: E=McAfee;i="6700,10204,11207"; a="29342200" X-IronPort-AV: E=Sophos;i="6.11,155,1725346800"; d="scan'208";a="29342200" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2024 07:03:42 -0700 X-CSE-ConnectionGUID: KP1Ro1n9T6CCN+wE9lm3dA== X-CSE-MsgGUID: dncQXH70SAactyo4q3yLjQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,155,1725346800"; d="scan'208";a="95501233" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by fmviesa002.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 26 Sep 2024 07:03:42 -0700 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 26 Sep 2024 07:03:41 -0700 Received: from fmsmsx601.amr.corp.intel.com (10.18.126.81) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 26 Sep 2024 07:03:38 -0700 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Thu, 26 Sep 2024 07:03:38 -0700 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (104.47.74.47) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 26 Sep 2024 07:03:27 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=aYPZ1I6l54nryEo5+jaP+/J4bD3HnK58waGtVBKa8JX0lCW9cn2khCvFRXQYnW+1MOHRtxFg7s5hgqxFJE7uTBQv24Bzl9v/7UzuiewSQoUU6pUSyxZXwzgUX9RkUutCqRR8QfIUgdM8fTrg254HGW1vBagQDRXDNu5B6zgKPmvQgjRUF7mQVmFpeYUOanBQV4I/uBjtZk1Ht6LBB9c2+RkjjFsCNldKaMBvkLUIS9mNZHaA190oa3wT3pDW1jTxvz6/2/wWwpTFBEgplXSCdGIM7Wvs0NxofkJWe1lCP9zhSkfgg+vKhWEuCwly6Zyn5IfRzillX2l+n1+FpI8Duw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+541ErHp2oMAzRxnL8Jc4JAR1wnVW5le56A3PBJ1aOk=; b=xZODyJ1Cr4XBn+C9T1IKL01N+AKJQVZU0F89ZsQanLkxlnMMhX+dy6gocuSLT3qV0kRDGOW/kWlzY+JDc/Ic/YqRbUHgu/rLBzfaNPwD+zdu0vT/6ajaqOdMwkAEm18ysaLFl8Mo9PQl9TqStt7sIqLx25+FBuSWygFEDErTQMIHTKwnH9vYtWnYRb3TxD2BoPvQjzRs7J6S4a8QfdWi7Zshwd5x3s3TLW/wIB3fJfMtU7ib9S3zLsF0fwyhm8SzDh8hL0K6Z+vu0Y8B2eqaDIbc6dJo2QVNn5yRpnXp5OZ/+Fq1qPSMNLbRU8PDcr5YNNGPeIJk47jbOTaPBvL2Cw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from SN7PR11MB6725.namprd11.prod.outlook.com (2603:10b6:806:267::18) by PH7PR11MB6747.namprd11.prod.outlook.com (2603:10b6:510:1b5::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.26; Thu, 26 Sep 2024 14:03:23 +0000 Received: from SN7PR11MB6725.namprd11.prod.outlook.com ([fe80::da01:fd51:d6ef:551]) by SN7PR11MB6725.namprd11.prod.outlook.com ([fe80::da01:fd51:d6ef:551%4]) with mapi id 15.20.7982.022; Thu, 26 Sep 2024 14:03:23 +0000 From: "Meade, Niall" To: Ferruh Yigit , "andrew.rybchenko@oktetlabs.ru" CC: "dev@dpdk.org" , "thomas@monjalon.net" , "roman.zhukov@arknetworks.am" Subject: Re: [PATCH v1] ethdev: fix int overflow in descriptor count logic Thread-Topic: [PATCH v1] ethdev: fix int overflow in descriptor count logic Thread-Index: AQHbDZq2rujmtJ2IbUKzhWOB2XSJz7JpJsaAgADeTu0= Date: Thu, 26 Sep 2024 14:03:23 +0000 Message-ID: References: <20240923092601.728817-1-niall.meade@intel.com> <461501aa-9483-49b1-b244-60c2719878f9@amd.com> In-Reply-To: <461501aa-9483-49b1-b244-60c2719878f9@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: SN7PR11MB6725:EE_|PH7PR11MB6747:EE_ x-ms-office365-filtering-correlation-id: c1dffaf3-9780-4df4-8cac-08dcde33fc10 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230040|376014|1800799024|366016|38070700018; x-microsoft-antispam-message-info: =?iso-8859-1?Q?TtUoHAanOYbRRpBM8yM7lC4/0ZXsxg8hB2gx9CdXsvwomISTKucNyawsTc?= =?iso-8859-1?Q?qPKaIskT7hf2raKx0ymG5PfyXWFG2WTKULUfgAFPViS2cK24dVxQObId9e?= =?iso-8859-1?Q?Lpnk87ppzuTrECKk6n1T2nDuPdzVSFH921dEmQ91w1qmCJjl1byzlqhehi?= =?iso-8859-1?Q?2NZRrrYhA5j/eCPy6Xbqn8PsjzxXLx0Cpd3KU1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VvxxUkQ3s+OcZ0h9v5mWYlqotdeLKZEYLXuqUX52lIDjKe062YRDg?= =?iso-8859-1?Q?FL0+AuM4PVKCxrkv0A0US91EU7EiywoDyeVybSV14vUhs1/5YOJGcyRSwR?= =?iso-8859-1?Q?vAQGD1oDZ/E3vif6NpkgaCMuZrKwvWrScYQP7QB/Yi3g3Klu/JDYYtlva7?= =?iso-8859-1?Q?RkgHOydkJj03LIsYlUxfQayfzURhUW1Lqdyr6efiSJoVYZ9QNJY1RsLgui?= =?iso-8859-1?Q?xdMIl1cWPte3qMJUmcrLsE2oH/usCAH9SWbCLTG6Txr+TvIski6tjSZymp?= =?iso-8859-1?Q?ifL/myqGDARJRnXEOda42tWm1cZx+SGttZawh4szGUxFq5dT0ws/N1Sr00?= =?iso-8859-1?Q?4TuGCO6b/npSCCzUQYkB4/51pilf/uvoWwqnCQ=3D=3D?= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN7PR11MB6725.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016)(38070700018); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?Q?krQ8Og6d6YbcyClaRO8mojw/Et9yeOpP9ehOr+GMgcO3i/azNqk6ZH2BCA?= =?iso-8859-1?Q?OUa+XCBvh/5FnqgY1SZBgZeAJMzGFnfFQxOGtMwunyfUMqb/wYuTNCwMdt?= =?iso-8859-1?Q?lbTyOoG9dqcnBDx+mnjcYDhrn72cvmhjzBclReYLec24Py90Jl5C1rsrft?= =?iso-8859-1?Q?ONxCqKeXmwPioPV6kpmgrGnHfWhqZzzGgmlP6lLLM0hFVYma1OnnHgTtNw?= =?iso-8859-1?Q?vL2yJYu5t/DQweoQZL6DfXf2JEa4l8qQYdpZ56TMfM6erEW33XUqkleMoA?= =?iso-8859-1?Q?DAO7XM/h7OtMB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1?Q?859v3VwJpOwdC7ZZ/7s4JHEBSep5c8D92abQe7HgE6WccHPcv4sWev+CFN?= =?iso-8859-1?Q?PCNJ6+vzDxziPNSzUdla/wRR7iP6u3iN8qp8M+Q3p3pYzSdmUeZgY5QsUw?= =?iso-8859-1?Q?WFEAK5kj1CufIUy9KvOrTtADvHBtAiYxeLNu5P42rAgemX8GRCuospu3MB?= =?iso-8859-1?Q?DAl8IepEDeZnfyak0PIqwhGDLwXybkZixg6xvURyP5KUa7MA6tWnfDqPUm?= =?iso-8859-1?Q?mGnL/61tltCfMOiiS1Me1w1FqPeMLRa7JjNQSEOYMMDaldMd1vrVEp/aAk?= =?iso-8859-1?Q?MMnjZhYdsM8tLFn5x/Dg0LmtAIoU01MfJ6mhsJz0LI7vMRSfICO31XifSV?= =?iso-8859-1?Q?rF00yCcyNrE3cDGixmpQuKBl+ur6KM8n58tKMHUChdnth4UMUsM27axVO0?= =?iso-8859-1?Q?cbMzqzIdS0deTbRm/URcxGcoJVqSvXp68x?= Content-Type: text/plain; charset="iso-8859-1" MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SN7PR11MB6725.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c1dffaf3-9780-4df4-8cac-08dcde33fc10 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Sep 2024 14:03:23.3209 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: u+IwQw/9WGros38eOUeskAm4Mq7Wq86bSUgUP8S5BtKQMZvITH5b0Bf1g2QsKAd7Ueu8F2G0zUihYzeGy1MUfQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR11MB6747 X-OriginatorOrg: intel.com Content-Transfer-Encoding: quoted-printable X-Mailman-Approved-At: Sat, 28 Sep 2024 00:13:29 +0200 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 > From: Ferruh Yigit > Sent: Thursday, September 26, 2024 12:16 AM > To: Meade, Niall ; Thomas Monjalon ; Andrew Rybchenko ; Roman Zhukov > Cc: dev@dpdk.org > Subject: Re: [PATCH v1] ethdev: fix int overflow in descriptor count logic > > The resolution involves upcasting nb_desc to a uint32_t before the > > RTE_ALIGN_CEIL macro is applied. This change ensures that the subsequent > > call to RTE_ALIGN_FLOOR(nb_desc + (nb_align - 1), nb_align) does not > > result in an overflow, as it would when nb_desc is a uint16_t. By using > > a uint32_t for these operations, the correct behavior is maintained > > without the risk of overflow. > > > > Hi Niall, Hi Ferruh, > Thanks for the patch. > > For the 'RTE_ALIGN_CEIL(val, align)' macro, 'align' should be power of > two, as 'desc_lim->nb_align' is uint16_t, max value it can get is 2^15. > 'val' should be smaller than or equal to 'align', so '*nb_desc' can be > maximum 2^15. > > So RTE_ALIGN_CEIL(2^15-1, 2^15) =3D 2^15, I think this should work fine > (although I didn't test). > > And even with your uint32_t cast, I think following will fail: > RTE_ALIGN_CEIL(2^16-1, 2^15) > (again, not tested). > I tested my code with these values and the behaviour is as expected from what I can see. At a high level I ran into this issue when passing uint16_tMAX into rte_eth_dev_adjust_nb_rx_tx_desc() with the intent of selecting the maximum ring descriptor size but the minimum was selected. > Or maybe I am missing a case, can you please give some actual numbers to > show the problem and the fix? Yes sure! If we take an example of val=3D (2^16)-1 and align=3D 32. RTE_ALIGN_CEIL(val, align)=A0calls RTE_ALIGN_FLOOR(val + align - 1, align).= With val as a uint16_t this subsequent macro call results in a wrap around for v= al (originally was the max uint16_t and now we are attempting to add align to it). The returned value of RTE_ALIGN_CEIL() in this case is 0. This results= in nb_desc being set to 0, and later set to the minimum ring descriptor size f= or that NIC with *nb_desc =3D RTE_MAX(*nb_desc, desc_lim->nb_min). While this example is an unreasonably large request for a descriptor ring s= ize, the expected behaviour would be that the descriptor ring=A0size defaults ba= ck to the maximum possible for that particular NIC, not to the minimum which it currently does. By introducing a uint32_t, the wrap around in RTE_ALIGN_FLOOR() is avoided, keeping the large value of nb_desc_32 which is later set to an appropriate = size in RTE_MIN(*nb_desc_32, desc_lim->nb_max) > > =A0{ > > + =A0 =A0 /* Upcast to uint32 to avoid potential overflow with RTE_ALIG= N_CEIL(). */ > > + =A0 =A0 uint32_t nb_desc_32 =3D *nb_desc; > > + > > =A0 =A0 =A0 =A0if (desc_lim->nb_align !=3D 0) > > - =A0 =A0 =A0 =A0 =A0 =A0 *nb_desc =3D RTE_ALIGN_CEIL(*nb_desc, desc_li= m->nb_align); > > + =A0 =A0 =A0 =A0 =A0 =A0 nb_desc_32 =3D RTE_ALIGN_CEIL(nb_desc_32, des= c_lim->nb_align); -------------------------------------------------------------- Intel Research and Development Ireland Limited Registered in Ireland Registered Office: Collinstown Industrial Park, Leixlip, County Kildare Registered Number: 308263 This e-mail and any attachments may contain confidential material for the s= ole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact = the sender and delete all copies.