patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
To: wangyunjian <wangyunjian@huawei.com>,
	Thomas Monjalon <thomas@monjalon.net>
Cc: "dev@dpdk.org" <dev@dpdk.org>,
	"ferruh.yigit@intel.com" <ferruh.yigit@intel.com>,
	"Lilijun (Jerry)" <jerry.lilijun@huawei.com>,
	xudingke <xudingke@huawei.com>,
	"stable@dpdk.org" <stable@dpdk.org>
Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH v2] ethdev: fix data type for port id
Date: Thu, 29 Oct 2020 15:40:09 +0300
Message-ID: <f9646d27-d0e4-85fc-809e-af8ef3ac193b@oktetlabs.ru> (raw)
In-Reply-To: <34EFBCA9F01B0748BEB6B629CE643AE60DADDBEB@DGGEMM533-MBX.china.huawei.com>

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 <wangyunjian@huawei.com>
>> Cc: dev@dpdk.org; ferruh.yigit@intel.com; andrew.rybchenko@oktetlabs.ru;
>> Lilijun (Jerry) <jerry.lilijun@huawei.com>; xudingke <xudingke@huawei.com>;
>> wangyunjian <wangyunjian@huawei.com>; 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 <wangyunjian@huawei.com>
>>>
>>> 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 <wangyunjian@huawei.com>
>>> ---
>>> 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.

  reply	other threads:[~2020-10-29 12:40 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-26 12:24 [dpdk-stable] [dpdk-dev] [PATCH] " wangyunjian
2020-10-26 12:29 ` Andrew Rybchenko
2020-10-27 13:41 ` [dpdk-stable] [dpdk-dev] [PATCH v2] " wangyunjian
2020-10-27 14:29   ` Thomas Monjalon
2020-10-29 12:18     ` wangyunjian
2020-10-29 12:40       ` Andrew Rybchenko [this message]
2020-10-29 12:43       ` Thomas Monjalon
2020-11-02  9:18   ` [dpdk-stable] [dpdk-dev] [PATCH v3] " wangyunjian
2020-11-03 18:44     ` Thomas Monjalon
2020-11-03 23:42       ` Stephen Hemminger
2020-11-04  1:57       ` wangyunjian
2020-11-04  2:57     ` [dpdk-stable] [dpdk-dev] [PATCH v4] " wangyunjian
2020-11-04  3:26       ` Ajit Khaparde
2020-11-04 11:46         ` Ferruh Yigit
2020-11-04 13:49           ` Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f9646d27-d0e4-85fc-809e-af8ef3ac193b@oktetlabs.ru \
    --to=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=jerry.lilijun@huawei.com \
    --cc=stable@dpdk.org \
    --cc=thomas@monjalon.net \
    --cc=wangyunjian@huawei.com \
    --cc=xudingke@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

patches for DPDK stable branches

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/stable/0 stable/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 stable stable/ https://inbox.dpdk.org/stable \
		stable@dpdk.org
	public-inbox-index stable

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.stable


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git