From: Slava Ovsiienko <viacheslavo@mellanox.com>
To: Stephen Hemminger <stephen@networkplumber.org>,
Matan Azrad <matan@mellanox.com>,
Shahaf Shuler <shahafs@mellanox.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>, Alexander Kozyrev <akozyrev@mellanox.com>
Subject: Re: [dpdk-dev] [PATCH] common/mlx5: fix bogus assert
Date: Tue, 31 Mar 2020 07:31:48 +0000 [thread overview]
Message-ID: <AM4PR05MB3265DC2FC996A1CCBDDF3471D2C80@AM4PR05MB3265.eurprd05.prod.outlook.com> (raw)
In-Reply-To: <20200331060247.10954-1-stephen@networkplumber.org>
Hi, Stephen
Thank you for the fix.
The exposed API to set MAC addresses:
- mlx5_mac_addr_set (invoked by rte_mac_addr_set ())
- mlx5_set_mc_addr_list (invoked by rte_eth_dev_set_mc_addr_list())
Both routines call mlx5_internal_mac_addr_add(), it in its turn calls
mlx5_nl_mac_addr_add() (that is subject of the patch).
mlx5_nl_mac_addr_add is internal function, not exposed external API,
the wrong parameter means the critical internal bug, so assert looks to be relevant here.
I would not remove MLX5_ASSERT at all but fix just it.
Adding the parameter check and return an error is nice.
What do you think?
With best regards, Slava
> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Tuesday, March 31, 2020 9:03
> To: Matan Azrad <matan@mellanox.com>; Shahaf Shuler
> <shahafs@mellanox.com>; Slava Ovsiienko <viacheslavo@mellanox.com>
> Cc: dev@dpdk.org; Stephen Hemminger <stephen@networkplumber.org>;
> Alexander Kozyrev <akozyrev@mellanox.com>
> Subject: [PATCH] common/mlx5: fix bogus assert
>
> The MLX5 device supports up to 256 MAC addresses.
> The code flushes all MAC devices.
>
> If DPDK is compiled with MLX5_DEBUG this would an assert.
> PANIC in mlx5_nl_mac_addr_flush():
> line 775 assert "(size_t)(i) < sizeof(mac_own) * 8" failed
>
> The root cause is that mac_own is a pointer and is being used as a bitmap
> array. The sizeof(mac_own) would therfore be 64 but the number of entries
> to be flushed would be 256.
>
> There is a whole set of asserts in MLX5 netlink code with the same bug; that
> should just be changed into proper error checks.
>
> Fixes: 8e46d4e18f09 ("common/mlx5: improve assert control")
> Cc: akozyrev@mellanox.com
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> drivers/common/mlx5/mlx5_nl.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/common/mlx5/mlx5_nl.c
> b/drivers/common/mlx5/mlx5_nl.c index 549e787b04bf..69f5efa50aa8 100644
> --- a/drivers/common/mlx5/mlx5_nl.c
> +++ b/drivers/common/mlx5/mlx5_nl.c
> @@ -671,7 +671,9 @@ mlx5_nl_mac_addr_add(int nlsk_fd, unsigned int
> iface_idx,
>
> ret = mlx5_nl_mac_addr_modify(nlsk_fd, iface_idx, mac, 1);
> if (!ret) {
> - MLX5_ASSERT((size_t)(index) < sizeof(mac_own) * CHAR_BIT);
> + if (index >= MLX5_MAX_MAC_ADDRESSES)
> + return -EINVAL;
> +
> BITFIELD_SET(mac_own, index);
> }
> if (ret == -EEXIST)
> @@ -700,7 +702,9 @@ int
> mlx5_nl_mac_addr_remove(int nlsk_fd, unsigned int iface_idx, uint64_t
> *mac_own,
> struct rte_ether_addr *mac, uint32_t index) {
> - MLX5_ASSERT((size_t)(index) < sizeof(mac_own) * CHAR_BIT);
> + if (index >= MLX5_MAX_MAC_ADDRESSES)
> + return -EINVAL;
> +
> BITFIELD_RESET(mac_own, index);
> return mlx5_nl_mac_addr_modify(nlsk_fd, iface_idx, mac, 0); } @@ -
> 769,10 +773,12 @@ mlx5_nl_mac_addr_flush(int nlsk_fd, unsigned int
> iface_idx, {
> int i;
>
> + if (n <= 0 || n >= MLX5_MAX_MAC_ADDRESSES)
> + return;
> +
> for (i = n - 1; i >= 0; --i) {
> struct rte_ether_addr *m = &mac_addrs[i];
>
> - MLX5_ASSERT((size_t)(i) < sizeof(mac_own) * CHAR_BIT);
> if (BITFIELD_ISSET(mac_own, i))
> mlx5_nl_mac_addr_remove(nlsk_fd, iface_idx,
> mac_own, m,
> i);
> --
> 2.20.1
next prev parent reply other threads:[~2020-03-31 7:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-31 6:02 Stephen Hemminger
2020-03-31 7:31 ` Slava Ovsiienko [this message]
2020-03-31 14:55 ` Stephen Hemminger
2020-03-31 15:09 ` Slava Ovsiienko
2020-04-10 17:14 ` Stephen Hemminger
2020-04-13 9:51 ` Slava Ovsiienko
2020-05-14 7:09 ` [dpdk-dev] [PATCH v2] " Viacheslav Ovsiienko
2020-05-14 15:11 ` Alexander Kozyrev
2020-05-14 20:38 ` Slava Ovsiienko
2020-05-17 12:02 ` Matan Azrad
2020-05-17 12:39 ` Raslan Darawsheh
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=AM4PR05MB3265DC2FC996A1CCBDDF3471D2C80@AM4PR05MB3265.eurprd05.prod.outlook.com \
--to=viacheslavo@mellanox.com \
--cc=akozyrev@mellanox.com \
--cc=dev@dpdk.org \
--cc=matan@mellanox.com \
--cc=shahafs@mellanox.com \
--cc=stephen@networkplumber.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).