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 43D49A04B5; Thu, 29 Oct 2020 13:40:14 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id EE55CCB03; Thu, 29 Oct 2020 13:40:12 +0100 (CET) Received: from shelob.oktetlabs.ru (shelob.oktetlabs.ru [91.220.146.113]) by dpdk.org (Postfix) with ESMTP id 62F9ECAFC; Thu, 29 Oct 2020 13:40:11 +0100 (CET) Received: from [192.168.38.17] (aros.oktetlabs.ru [192.168.38.17]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by shelob.oktetlabs.ru (Postfix) with ESMTPSA id 152137F523; Thu, 29 Oct 2020 15:40:10 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 shelob.oktetlabs.ru 152137F523 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=oktetlabs.ru; s=default; t=1603975210; bh=Rx6hvU4ETldUh9Ajbn7CezAcVqXBWqhyyirHGDCp8qk=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=xxYhPpQJuLpyUj0cSnBTOmolN8IYioX6PpCwQr5LL9uuVQjYmPPXsiqvPaTng71XE 7AgKU6HKLb3YWR3bM/Vhpse5arrgGjV7wR/gfnP2ZR0H0PT8NbWVT/TS5WINCA5tub zNewb9Om2cZD+BWVvJwk5P+r0CBrzICn0GFbbG/Q= To: wangyunjian , Thomas Monjalon Cc: "dev@dpdk.org" , "ferruh.yigit@intel.com" , "Lilijun (Jerry)" , xudingke , "stable@dpdk.org" References: <1603806082-21484-1-git-send-email-wangyunjian@huawei.com> <3015812.jyVNu9Cn7i@thomas> <34EFBCA9F01B0748BEB6B629CE643AE60DADDBEB@DGGEMM533-MBX.china.huawei.com> From: Andrew Rybchenko Organization: OKTET Labs Message-ID: Date: Thu, 29 Oct 2020 15:40:09 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <34EFBCA9F01B0748BEB6B629CE643AE60DADDBEB@DGGEMM533-MBX.china.huawei.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v2] ethdev: fix data type for port id 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" On 10/29/20 3:18 PM, wangyunjian wrote: >> -----Original Message----- >> From: Thomas Monjalon [mailto:thomas@monjalon.net] >> Sent: Tuesday, October 27, 2020 10:29 PM >> To: wangyunjian >> Cc: dev@dpdk.org; ferruh.yigit@intel.com; andrew.rybchenko@oktetlabs.ru; >> Lilijun (Jerry) ; xudingke ; >> wangyunjian ; stable@dpdk.org >> Subject: Re: [dpdk-dev] [PATCH v2] ethdev: fix data type for port id >> >> 27/10/2020 14:41, wangyunjian: >>> From: Yunjian Wang >>> >>> The ethdev port id should be 16 bits now. This patch fixes the data >>> type of the variable for 'pid', changing from uint32_t to uint16_t. >>> >>> We also need use RTE_BUILD_BUG_ON() to ensure that >> RTE_MAX_ETHPORTS is >>> less or equal to UINT16_MAX. >> >> Actually the need is to check that we have room for an increment after >> RTE_MAX_ETHPORTS, meaning RTE_MAX_ETHPORTS < UINT16_MAX. > > OK. > >> >>> Fixes: 5b7ba31148a8 ("ethdev: add port ownership") >>> Cc: stable@dpdk.org >>> >>> Signed-off-by: Yunjian Wang >>> --- >>> v2: >>> add RTE_BUILD_BUG_ON() check for RTE_MAX_ETHPORTS validity >>> --- >>> rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id) { >>> - uint32_t pid; >>> + uint16_t pid; >>> >>> if (name == NULL) { >>> RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n"); @@ -4292,6 >>> +4292,8 @@ RTE_INIT(eth_dev_init_cb_lists) { >>> int i; >>> >>> + RTE_BUILD_BUG_ON(RTE_MAX_ETHPORTS > UINT16_MAX); >> >> As explained above, should check >= >> >> This check is global for ethdev. >> Please could you move it somewhere else? >> >> > > What about following: > > # git diff > diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c > index ccea60afe7..ff878f4d4d 100644 > --- a/lib/librte_eal/freebsd/eal.c > +++ b/lib/librte_eal/freebsd/eal.c > @@ -672,6 +672,8 @@ rte_eal_init(int argc, char **argv) > struct internal_config *internal_conf = > eal_get_internal_configuration(); > > + RTE_BUILD_BUG_ON(RTE_MAX_ETHPORTS >= UINT16_MAX); > + > /* checks if the machine is adequate */ > if (!rte_cpu_is_supported()) { > rte_eal_init_alert("unsupported cpu type."); > diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c > index 9b579b8200..bd7fb7b5f1 100644 > --- a/lib/librte_eal/linux/eal.c > +++ b/lib/librte_eal/linux/eal.c > @@ -970,6 +970,8 @@ rte_eal_init(int argc, char **argv) > struct internal_config *internal_conf = > eal_get_internal_configuration(); > > + RTE_BUILD_BUG_ON(RTE_MAX_ETHPORTS >= UINT16_MAX); > + > /* checks if the machine is adequate */ > if (!rte_cpu_is_supported()) { > rte_eal_init_alert("unsupported cpu type."); > diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c > index 141f22adb7..27c2ebd114 100644 > --- a/lib/librte_eal/windows/eal.c > +++ b/lib/librte_eal/windows/eal.c > @@ -265,6 +265,8 @@ rte_eal_init(int argc, char **argv) > struct internal_config *internal_conf = > eal_get_internal_configuration(); > > + RTE_BUILD_BUG_ON(RTE_MAX_ETHPORTS >= UINT16_MAX); > + > rte_eal_log_init(NULL, 0); > If RTE_MAX_ETHPORTS is a maximum number of ports starting from 0 and loops are port_id < RTE_MAX_ETHPORTS, RTE_MAX_ETHPORTS may be UINT16_MAX and it avoid 16-bit unsigned integer overflow, but may be it is safer to cut one more port from space do checks as above.