DPDK patches and discussions
 help / color / mirror / Atom feed
From: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
To: "Min Hu (Connor)" <humin29@huawei.com>, dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Ferruh Yigit <ferruh.yigit@xilinx.com>
Subject: Re: [PATCH v5] kni: fix device address set
Date: Fri, 3 Jun 2022 14:50:26 +0300	[thread overview]
Message-ID: <a8ef0b6a-9f95-0de7-961a-b0ed73629fe1@oktetlabs.ru> (raw)
In-Reply-To: <20220602065421.3964-1-humin29@huawei.com>

On 6/2/22 09:54, Min Hu (Connor) wrote:
> Currently, run KNI APP When Kernel version is 5.17. When quit the APP,
> dmesg buffer get calltrace, info like:
> [ 5965.847401] rte_kni: Creating kni...
> [ 6225.627205] vEth0 (unregistered): Current addr:  70 fd 45 d0 72 a7 00..
> [ 6225.640113] vEth0 (unregistered): Expected addr: 00 00 00 00 00 00 00..
> [ 6225.653010] ------------[ cut here ]------------
> [ 6225.657609] netdevice: vEth0 (unregistered): Incorrect netdev->dev_addr
> [ 6225.832647] Call trace:
> [ 6225.835083]  dev_addr_check+0xa0/0x144
> [ 6225.838816]  dev_addr_flush+0x30/0x9c
> [ 6225.842462]  free_netdev+0x8c/0x1e0
> [ 6225.845939]  kni_release+0xc0/0x1d0 [rte_kni]
> [ 6225.850281]  __fput+0x78/0x220
> [ 6225.853327]  ____fput+0x1c/0x30
> [ 6225.856455]  task_work_run+0x88/0xc0
> [ 6225.860017]  do_exit+0x2fc/0x940
> [ 6225.863232]  do_group_exit+0x40/0xac
> [ 6225.866791]  get_signal+0x190/0x960
> [ 6225.870265]  do_notify_resume+0x26c/0x1360
> [ 6225.874346]  el0_interrupt+0x60/0xe0
> [ 6225.877910]  __el0_irq_handler_common+0x18/0x24
> [ 6225.882420]  el0t_64_irq_handler+0x14/0x20
> [ 6225.886499]  el0t_64_irq+0x1a0/0x1a4
> [ 6225.890059] ---[ end trace 0000000000000000 ]---
> [ 6245.598157] rte_kni: Creating kni...
> 
> The reason is that 5.17 kernel introduce 'dev_addr_shadow' in function
> 'dev_addr_set' to ensure that netdev->dev_addr should only be modified
> via helpers('dev_addr_set'). 'dev_addr_check' will check if
> netdev->dev_addr is modified by other ways, like 'memcpy'.
> 
> More info could get by referring to kernel patch:
> https://patchwork.kernel.org/project/netdevbpf/patch/
> 20211118041501.3102861-8-kuba@kernel.org/
> https://www.spinics.net/lists/netdev/msg764992.html
> 
> Fixes: ea6b39b5b847 ("kni: remove ethtool support")
> 
> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
> ---
> v5:
> * define 'HAVE_DEV_ADDR_SHADOW'.
> 
> v3,v4:
> * fix compiling errors.
> 
> v2:
> * change 'memcpy' to 'ether_addr_copy' to copy device addr.
> ---
>   kernel/linux/kni/compat.h   |  4 ++++
>   kernel/linux/kni/kni_misc.c | 10 ++++++++--
>   2 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/linux/kni/compat.h b/kernel/linux/kni/compat.h
> index 664785674f..7ffca63bd4 100644
> --- a/kernel/linux/kni/compat.h
> +++ b/kernel/linux/kni/compat.h
> @@ -141,3 +141,7 @@
>   #if KERNEL_VERSION(5, 9, 0) > LINUX_VERSION_CODE
>   #define HAVE_TSK_IN_GUP
>   #endif
> +
> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 17, 0)
> +#define HAVE_DEV_ADDR_SHADOW
> +#endif
> diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
> index 780187d8bf..0470d349c5 100644
> --- a/kernel/linux/kni/kni_misc.c
> +++ b/kernel/linux/kni/kni_misc.c
> @@ -299,6 +299,7 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,
>   	struct kni_net *knet = net_generic(net, kni_net_id);
>   	int ret;
>   	struct rte_kni_device_info dev_info;
> +	unsigned char mac_addr[ETH_ALEN];
>   	struct net_device *net_dev = NULL;
>   	struct kni_dev *kni, *dev, *n;
>   
> @@ -403,10 +404,15 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,
>   
>   	/* if user has provided a valid mac address */
>   	if (is_valid_ether_addr(dev_info.mac_addr))
> -		memcpy(net_dev->dev_addr, dev_info.mac_addr, ETH_ALEN);
> +		ether_addr_copy(mac_addr, dev_info.mac_addr);
>   	else
>   		/* Generate random MAC address. */
> -		eth_random_addr(net_dev->dev_addr);
> +		eth_random_addr(mac_addr);

The following point from Stephen is still not processed:

<quote>
This is still not the best way to handle this.
If you use eth_hw_addr_random() it will set the address assign type. 
Right now KNI is not doing this correctly.
</quote>

> +#ifdef HAVE_DEV_ADDR_SHADOW
> +	dev_addr_set(net_dev, mac_addr);
> +#else
> +	ether_addr_copy(net_dev->dev_addr, mac_addr);
> +#endif
>   
>   	if (dev_info.mtu)
>   		net_dev->mtu = dev_info.mtu;


  reply	other threads:[~2022-06-03 11:50 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-06  8:22 [PATCH] " Min Hu (Connor)
2022-04-06 15:17 ` Stephen Hemminger
2022-04-07  0:44   ` Min Hu (Connor)
2022-04-07  3:18     ` Stephen Hemminger
2022-04-07  6:21       ` Min Hu (Connor)
2022-04-07  7:42     ` Thomas Monjalon
2022-04-07  8:08       ` Min Hu (Connor)
2022-04-07  8:25 ` [PATCH v2] " Min Hu (Connor)
2022-04-25  3:58   ` Min Hu (Connor)
2022-05-23  9:24 ` [PATCH v3] " Min Hu (Connor)
2022-05-31 15:32   ` Andrew Rybchenko
2022-06-01  2:01     ` Min Hu (Connor)
2022-06-01  1:59 ` [PATCH v4] " Min Hu (Connor)
2022-06-01  9:02   ` Andrew Rybchenko
2022-06-02  6:58     ` Min Hu (Connor)
2022-06-02  6:54 ` [PATCH v5] " Min Hu (Connor)
2022-06-03 11:50   ` Andrew Rybchenko [this message]
2022-06-02 15:31 ` [PATCH] " Stephen Hemminger

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=a8ef0b6a-9f95-0de7-961a-b0ed73629fe1@oktetlabs.ru \
    --to=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@xilinx.com \
    --cc=humin29@huawei.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).