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 EB831A0C43; Fri, 8 Oct 2021 18:51:56 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C28944014F; Fri, 8 Oct 2021 18:51:56 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id 7C22E40143 for ; Fri, 8 Oct 2021 18:51:55 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10131"; a="290044444" X-IronPort-AV: E=Sophos;i="5.85,358,1624345200"; d="scan'208";a="290044444" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2021 09:51:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,358,1624345200"; d="scan'208";a="715587914" Received: from orsmsx606.amr.corp.intel.com ([10.22.229.19]) by fmsmga005.fm.intel.com with ESMTP; 08 Oct 2021 09:51:53 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX606.amr.corp.intel.com (10.22.229.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.12; Fri, 8 Oct 2021 09:51:46 -0700 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.12 via Frontend Transport; Fri, 8 Oct 2021 09:51:46 -0700 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.103) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2242.12; Fri, 8 Oct 2021 09:51:46 -0700 Received: from DM6PR11MB4491.namprd11.prod.outlook.com (2603:10b6:5:204::19) by DM6PR11MB4531.namprd11.prod.outlook.com (2603:10b6:5:2a5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.20; Fri, 8 Oct 2021 16:51:44 +0000 Received: from DM6PR11MB4491.namprd11.prod.outlook.com ([fe80::740e:126e:c785:c8fd]) by DM6PR11MB4491.namprd11.prod.outlook.com ([fe80::740e:126e:c785:c8fd%4]) with mapi id 15.20.4587.019; Fri, 8 Oct 2021 16:51:44 +0000 From: "Ananyev, Konstantin" To: "Yigit, Ferruh" , Thomas Monjalon , Andrew Rybchenko CC: "Yigit, Ferruh" , "dev@dpdk.org" , Huisong Li Thread-Topic: [dpdk-dev] [PATCH v5 5/6] ethdev: unify MTU checks Thread-Index: AQHXu5y18drg4qOMO0WRt2bFAy9ryqvJShuA Date: Fri, 8 Oct 2021 16:51:43 +0000 Message-ID: References: <20211001143624.3744505-1-ferruh.yigit@intel.com> <20211007165626.2941995-1-ferruh.yigit@intel.com> <20211007165626.2941995-5-ferruh.yigit@intel.com> In-Reply-To: <20211007165626.2941995-5-ferruh.yigit@intel.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.6.200.16 authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e54ae808-f74c-4625-9a6e-08d98a7be8c9 x-ms-traffictypediagnostic: DM6PR11MB4531: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7219; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 4c4WsLNe8S/lDbg6io/MViMkHUMhbNSmhxwVy76XNKQJKSPCiA4CZz2o7nrliuFTb9Js4A0ivkfSb5x0VvAnFHoCRhxgM707D39AfW1/JpfgBOQ7EaKdPN+0wEoNK84Ay3bNnIQcIIsbIMtSgeX26pDKxMMagXWCj2N9fh28/s3OaCpLDTlH2v9oqoFEl9kDasON4cN3OAJX+vpmP8cbweYKL7tw1Weua+FzLb3tSo9v+V0jjc0I/nR63jbI8U71EwloSOfySc8SlkmsBV0DkIzTaleHYY/ZiDh5LjwwTmjg6R7cbvYKm7SN9Tg0BcXyR3/BZgorgC/aKwPNu8JP1e9wxhbBSNvP3OqhFGaJuoeUmMz+JxykXM4oEi21K4l+Ku2Fn9zMWXU/N1w9YTw1ahAKBhZAHbhejOTEVvmMGi0/dNShEf4zlP0CsHknzGP/vifJbK0rWY7h4EGzDdgMc3fV6ACiqUy/hLy7FHPWEG7GMvdgJO5WRuQQzoBMFiAQUtkkZ6nz5mNRmOxQX5RhJvr1a3PTFU185WtnbLCTTK6C8MV18jLtIYxLlYF3Db9ENZKnrv0YP75QnOzA+5QiDuffURpVq41qDJ/vN5Ypga4qt4xoQdJ4YPlVnH7Ky2PRAZwCkZfz95pCzm63mPTEQZ3C47cXMYZflosceQUj3Z+jElr5cBVeh9iXiovJ+REsKIaYTnOEcg01Xlcps4wLgw== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR11MB4491.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(8676002)(86362001)(122000001)(83380400001)(5660300002)(498600001)(38070700005)(33656002)(38100700002)(52536014)(26005)(7696005)(110136005)(66476007)(54906003)(186003)(66946007)(6506007)(55016002)(9686003)(55236004)(76116006)(66446008)(66556008)(64756008)(2906002)(71200400001)(8936002)(4326008); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam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gI1SBEoY5X6z9A1NX5T2Y/5UTx9T2?= =?us-ascii?Q?eFCof0NY/R4MtcWp2hpXlxXMKoNKFIz+wyGzsOkqMkU7byoFrCcng0jEN3kR?= =?us-ascii?Q?SJwNx2MOMHB5UKWMTwIJsmnCUDUOGllo802gGg+787Qd9cQuXN5xlQvM6waP?= =?us-ascii?Q?YpDeBjd573ZT/6FapbTekmz4YEiDB8LH1Gz+ThojB8v/7vWm4cLXr40q1jdv?= =?us-ascii?Q?7sUOoEMiTywxpYMvO7Oxco4y2tc7E/XGBZlXtTKcdD0DZ8IV2AuIrM8XqFLd?= =?us-ascii?Q?Ga4R3Brua7zNQ2CLJgNKtMSWPr8GFJUcA0oAt7APIC/mRAqsgHwiU5Z8eVRQ?= =?us-ascii?Q?TwNYSogvfMuVd+scKekaKg8HmmqXfFjp0Q7ANdAoPfXY2pe3MdZfTfEPM0PS?= =?us-ascii?Q?XBi8qa7HRCAkkW/2dq9w9OZE5qFfv9U9i7pz4w1KdCPcSs4i1ZMb4NEXeG5h?= =?us-ascii?Q?8KU+m3MdI9hovLn063K2DQM3?= arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bG4mbtUkst8LFOnKyUaWaZGcUqq3AW4KvZO037vBgWp1aMJ4N++lSjTD0q2CHjlUzM57FqVHepAkNsyspXvoMeYs/QJL8lcadcrr06cMvcKhZFjtdW3iHhHTwxnfqnst7DSqEXm9zfyvorCEbL4DcP5yGHYg+/I1pFkFu7s9DDj98w9yj+UBlOg6ktp6Ya9xFjUT7w0rC2NGnJH6fhyxe2yJHeJjnbUFw7aTw6xA1k3Eacao3ioT59P1JEWKaUXf9MoFggY0xiogD2EddrR6+ICqyZQXSjXHQZqLaS+IW/2CbO5T8I5Mixx3tSdY808snShtjf3tjQdFDkOuUcUfcQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=t6l6wECT/M8T7OFiFdITIPH4Fg/a+olDqU2WxJ4ZtbI=; b=OGhUDE0dDx4e2Fij29bRaLuR16CkX2Dubop7BgUot+FwDLZOF9BHvzeoLy3arTU8bDexo0haG35xq3OjpHjQRTCyXfBYIcT/TRnRC9t+cGj85MgPe74PUfyg1973qVc9/jmV+6FjBMPLx3A40J87ITq5h9vXCKXguMuLXo6XBZH80+OATJbhf/ZtRDx007Vewwo8u+qea/OXPTd0NI5j7fEPwY2acI/kEYlCsBy92lwyNCfBxF4VEF7pQdkD2WlVRpguuOSzReisBoJRNj4jnm3zpjOPR5oGR/SbozO4Oh5rEm3kx0gfbeyBNOmbpGDDzbq3kLNzw+9h4xXXh7dDIQ== 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 dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=t6l6wECT/M8T7OFiFdITIPH4Fg/a+olDqU2WxJ4ZtbI=; b=rPoJ9OTykfT7d2rhd3kgSBQfEn6uBiFUREgGSQ8h38WVYl07E1ORMHO3JtxFpkUmUkBhRiHgkJ7AqnOCDIIRRw2itfJeGbIp6pneJtXPsfxtUtrFq79LfG+AVPUfaNkT8ueg/SSUZ1oHAC4PAWw49D9S75kixVfOcawb8TQKHfw= x-ms-exchange-crosstenant-authas: Internal x-ms-exchange-crosstenant-authsource: DM6PR11MB4491.namprd11.prod.outlook.com x-ms-exchange-crosstenant-network-message-id: e54ae808-f74c-4625-9a6e-08d98a7be8c9 x-ms-exchange-crosstenant-originalarrivaltime: 08 Oct 2021 16:51:43.9903 (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: gvkpUJehUPrB+cX4+emeiPbCjG2SXRCBEZXWk5n40toIE+TnTyCH6ERQ3uckCKrGx5dn7ftwyeJKRvREVNzdQPNEJz7XML6SdC5p9cm/7xw= x-ms-exchange-transport-crosstenantheadersstamped: DM6PR11MB4531 x-originatororg: intel.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v5 5/6] ethdev: unify MTU checks 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" > Both 'rte_eth_dev_configure()' & 'rte_eth_dev_set_mtu()' sets MTU but > have slightly different checks. Like one checks min MTU against > RTE_ETHER_MIN_MTU and other RTE_ETHER_MIN_LEN. > > Checks moved into common function to unify the checks. Also this has > benefit to have common error logs. > > Suggested-by: Huisong Li > Signed-off-by: Ferruh Yigit > --- > lib/ethdev/rte_ethdev.c | 82 ++++++++++++++++++++++++++--------------- > lib/ethdev/rte_ethdev.h | 2 +- > 2 files changed, 54 insertions(+), 30 deletions(-) > > diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c > index c2b624aba1a0..0a6e952722ae 100644 > --- a/lib/ethdev/rte_ethdev.c > +++ b/lib/ethdev/rte_ethdev.c > @@ -1336,6 +1336,47 @@ eth_dev_get_overhead_len(uint32_t max_rx_pktlen, u= int16_t max_mtu) > return overhead_len; > } > > +/* rte_eth_dev_info_get() should be called prior to this function */ > +static int > +eth_dev_validate_mtu(uint16_t port_id, struct rte_eth_dev_info *dev_info= , > + uint16_t mtu) > +{ > + uint16_t overhead_len; Again, I would just always use 32-bit arithmetic - safe and easy. Apart from that: Acked-by: Konstantin Ananyev > + uint32_t frame_size; > + > + if (mtu < dev_info->min_mtu) { > + RTE_ETHDEV_LOG(ERR, > + "MTU (%u) < device min MTU (%u) for port_id %u\n", > + mtu, dev_info->min_mtu, port_id); > + return -EINVAL; > + } > + if (mtu > dev_info->max_mtu) { > + RTE_ETHDEV_LOG(ERR, > + "MTU (%u) > device max MTU (%u) for port_id %u\n", > + mtu, dev_info->max_mtu, port_id); > + return -EINVAL; > + } > + > + overhead_len =3D eth_dev_get_overhead_len(dev_info->max_rx_pktlen, > + dev_info->max_mtu); > + frame_size =3D mtu + overhead_len; > + if (frame_size < RTE_ETHER_MIN_LEN) { > + RTE_ETHDEV_LOG(ERR, > + "Frame size (%u) < min frame size (%u) for port_id = %u\n", > + frame_size, RTE_ETHER_MIN_LEN, port_id); > + return -EINVAL; > + } > + > + if (frame_size > dev_info->max_rx_pktlen) { > + RTE_ETHDEV_LOG(ERR, > + "Frame size (%u) > device max frame size (%u) for p= ort_id %u\n", > + frame_size, dev_info->max_rx_pktlen, port_id); > + return -EINVAL; > + } > + > + return 0; > +} > + > int > rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx= _q, > const struct rte_eth_conf *dev_conf) > @@ -1463,26 +1504,13 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t = nb_rx_q, uint16_t nb_tx_q, > goto rollback; > } > > - /* > - * Check that the maximum RX packet length is supported by the > - * configured device. > - */ > if (dev_conf->rxmode.mtu =3D=3D 0) > dev->data->dev_conf.rxmode.mtu =3D RTE_ETHER_MTU; > - max_rx_pktlen =3D dev->data->dev_conf.rxmode.mtu + overhead_len; > - if (max_rx_pktlen > dev_info.max_rx_pktlen) { > - RTE_ETHDEV_LOG(ERR, > - "Ethdev port_id=3D%u max_rx_pktlen %u > max valid v= alue %u\n", > - port_id, max_rx_pktlen, dev_info.max_rx_pktlen); > - ret =3D -EINVAL; > - goto rollback; > - } else if (max_rx_pktlen < RTE_ETHER_MIN_LEN) { > - RTE_ETHDEV_LOG(ERR, > - "Ethdev port_id=3D%u max_rx_pktlen %u < min valid v= alue %u\n", > - port_id, max_rx_pktlen, RTE_ETHER_MIN_LEN); > - ret =3D -EINVAL; > + > + ret =3D eth_dev_validate_mtu(port_id, &dev_info, > + dev->data->dev_conf.rxmode.mtu); > + if (ret !=3D 0) > goto rollback; > - } > > dev->data->mtu =3D dev->data->dev_conf.rxmode.mtu; > > @@ -1491,6 +1519,9 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb= _rx_q, uint16_t nb_tx_q, > * size is supported by the configured device. > */ > if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_TCP_LRO) { > + overhead_len =3D eth_dev_get_overhead_len(dev_info.max_rx_p= ktlen, > + dev_info.max_mtu); > + max_rx_pktlen =3D dev->data->dev_conf.rxmode.mtu + overhead= _len; > if (dev_conf->rxmode.max_lro_pkt_size =3D=3D 0) > dev->data->dev_conf.rxmode.max_lro_pkt_size =3D max= _rx_pktlen; > ret =3D eth_dev_check_lro_pkt_size(port_id, > @@ -3437,7 +3468,8 @@ rte_eth_dev_info_get(uint16_t port_id, struct rte_e= th_dev_info *dev_info) > dev_info->rx_desc_lim =3D lim; > dev_info->tx_desc_lim =3D lim; > dev_info->device =3D dev->device; > - dev_info->min_mtu =3D RTE_ETHER_MIN_MTU; > + dev_info->min_mtu =3D RTE_ETHER_MIN_LEN - RTE_ETHER_HDR_LEN - > + RTE_ETHER_CRC_LEN; > dev_info->max_mtu =3D UINT16_MAX; > > RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP); > @@ -3643,21 +3675,13 @@ rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mt= u) > * which relies on dev->dev_ops->dev_infos_get. > */ > if (*dev->dev_ops->dev_infos_get !=3D NULL) { > - uint16_t overhead_len; > - uint32_t frame_size; > - > ret =3D rte_eth_dev_info_get(port_id, &dev_info); > if (ret !=3D 0) > return ret; > > - if (mtu < dev_info.min_mtu || mtu > dev_info.max_mtu) > - return -EINVAL; > - > - overhead_len =3D eth_dev_get_overhead_len(dev_info.max_rx_p= ktlen, > - dev_info.max_mtu); > - frame_size =3D mtu + overhead_len; > - if (mtu < RTE_ETHER_MIN_MTU || frame_size > dev_info.max_rx= _pktlen) > - return -EINVAL; > + ret =3D eth_dev_validate_mtu(port_id, &dev_info, mtu); > + if (ret !=3D 0) > + return ret; > } > > ret =3D (*dev->dev_ops->mtu_set)(dev, mtu); > diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h > index 4d0f956a4b28..50e124ff631f 100644 > --- a/lib/ethdev/rte_ethdev.h > +++ b/lib/ethdev/rte_ethdev.h > @@ -3056,7 +3056,7 @@ int rte_eth_macaddr_get(uint16_t port_id, struct rt= e_ether_addr *mac_addr); > * }; > * > * device =3D dev->device > - * min_mtu =3D RTE_ETHER_MIN_MTU > + * min_mtu =3D RTE_ETHER_MIN_LEN - RTE_ETHER_HDR_LEN - RTE_ETHER_CRC_LEN > * max_mtu =3D UINT16_MAX > * > * The following fields will be populated if support for dev_infos_get() > -- > 2.31.1