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 DF94FA0548; Thu, 2 Jun 2022 17:31:44 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8EF2D40691; Thu, 2 Jun 2022 17:31:44 +0200 (CEST) Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by mails.dpdk.org (Postfix) with ESMTP id 041FA4021E for ; Thu, 2 Jun 2022 17:31:42 +0200 (CEST) Received: by mail-pg1-f172.google.com with SMTP id e66so5028193pgc.8 for ; Thu, 02 Jun 2022 08:31:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Upjkr/VhAWrPRd7SZPbl/YlYlBmgeDUIMOOvGCO+1T4=; b=ODeTesizDz5CiZxxp5XmpYYz8oyjPa7uwhk+rLxY2YhCNky/G61T83w1rY7FpTPNcL UU87dALVEf8UEYVp3qGG5UZymJcE48gO7m250FpG/Z2RASvgJcg7rRhWa1xkBd6MXeMn GYhSLtdR9MK4Fln9w94TCBLWLQZ48qLDj5o4A2lcDwljo3HIA9EPdl8lQkhd8i7lfmhN wY4fN7yD5xxFm0D+5jhMS+XkaLrOBs4BJVLxDd572nIQQKESFzsJgcCJHhb98X4CtrMm y8mJTqVIv+/H9WNsBbnmdwOgLON9zMJxcc+GcMIL3lkbw1fMnxG8pyCZ5MF6FYapzwWQ WWFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Upjkr/VhAWrPRd7SZPbl/YlYlBmgeDUIMOOvGCO+1T4=; b=tQYtYnW1XqJdS2VpTU4C+FA06+OZ+FiD0BU9KhWqCjQZvzq0dDNKTr+xw5WbbQEf5Z DWpGZiLjViBaHp/+5iTCPVt3PMeXr0OgjCLL90p+DpxFGg35lRzxOQmm/Tf3liwGZhVu uZuYilANP5cHXhu5vUsYqcMzcmit18uX7ViVh/kQbFNItaSZjslV440vKqkcCkdq94PK OyMrUkpvuhEJuAaqfCc66PSE7J+GiwLw6aqakkvcoP82HqtatcAcFyx1OxnoYG2a8AWr vm9vEbUx1E6r5HiZWHwq2REpolc70qIvA5wzZoP8soNgRhMXwk0f4HY4wANtPpltME9q MCmQ== X-Gm-Message-State: AOAM533Aum1CohwQq7cxgFOahBowlcHP9w02oz3NfS8Q8HIGA2ViJSeJ +IFmn+kXrmuRehwFXlPDURSWEQ== X-Google-Smtp-Source: ABdhPJzRB38dqj9+2uSY0aT+Y/VOuGjOLvyn6wuPS1KQiQU3jSglRK4pJwcV8Lig2pI0di+pPIRwew== X-Received: by 2002:aa7:814a:0:b0:51b:4937:ef3a with SMTP id d10-20020aa7814a000000b0051b4937ef3amr22190436pfn.5.1654183901804; Thu, 02 Jun 2022 08:31:41 -0700 (PDT) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id x13-20020a17090a294d00b001e0cc5b13c6sm6013734pjf.26.2022.06.02.08.31.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 08:31:41 -0700 (PDT) Date: Thu, 2 Jun 2022 08:31:38 -0700 From: Stephen Hemminger To: "Min Hu (Connor)" Cc: , , Subject: Re: [PATCH] kni: fix device address set Message-ID: <20220602083138.1d981400@hermes.local> In-Reply-To: <20220406082213.45750-1-humin29@huawei.com> References: <20220406082213.45750-1-humin29@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 On Wed, 6 Apr 2022 16:22:13 +0800 "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) > --- > kernel/linux/kni/kni_misc.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c > index 780187d8bf..046de0311f 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); > + memcpy(mac_addr, dev_info.mac_addr, ETH_ALEN); > else > /* Generate random MAC address. */ > - eth_random_addr(net_dev->dev_addr); > + eth_random_addr(mac_addr); > +#if KERNEL_VERSION(5, 17, 0) > LINUX_VERSION_CODE > + memcpy(net_dev->dev_addr, mac_addr, ETH_ALEN); > +#else > + dev_addr_set(net_dev, mac_addr); > +#endif 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. Also, the code is more readable if all the kernel compatibility stuff is handled in compat.h. There should be no kernel version checks in the functions.