netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "dongchenchen (A)" <dongchenchen2@huawei.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: <davem@davemloft.net>, <edumazet@google.com>, <pabeni@redhat.com>,
	<horms@kernel.org>, <jiri@resnulli.us>, <oscmaes92@gmail.com>,
	<linux@treblig.org>, <pedro.netdev@dondevamos.com>,
	<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<yuehaibing@huawei.com>, <zhangchangzhong@huawei.com>
Subject: Re: [PATCH net] net: vlan: fix VLAN 0 refcount imbalance of toggling filtering during runtime
Date: Thu, 26 Jun 2025 11:41:45 +0800	[thread overview]
Message-ID: <900f28da-83db-4b17-b56b-21acde70e47f@huawei.com> (raw)
In-Reply-To: <20250624174252.7fbd3dbe@kernel.org>


> On Mon, 23 Jun 2025 19:30:08 +0800 Dong Chenchen wrote:
>> $ ip link add bond0 type bond mode 0
>> $ ip link add link bond0 name vlan0 type vlan id 0 protocol 802.1q
>> $ ethtool -K bond0 rx-vlan-filter off
>> $ ifconfig bond0 up
>> $ ethtool -K bond0 rx-vlan-filter on
>> $ ifconfig bond0 down
>> $ ifconfig bond0 up
>> $ ip link del vlan0

Hi, Jakub
Thanks for your review!

> Please try to figure out the reasonable combinations in which we can
> change the flags and bring the device up and down. Create a selftest
> in bash and add it under tools/testing/selftests/net

selftest patch will be added in v2.

>> diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
>> index 06908e37c3d9..6e01ece0a95c 100644
>> --- a/net/8021q/vlan.c
>> +++ b/net/8021q/vlan.c
>> @@ -504,12 +504,21 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
>>   		break;
>>   
>>   	case NETDEV_CVLAN_FILTER_PUSH_INFO:
>> +		flgs = dev_get_flags(dev);
> Why call dev_get_flags()? You can test dev->flags & IFF_UP directly

Yes, there is no need to use this function, I will modify it in v2

>> +		if (flgs & IFF_UP) {
>> +			pr_info("adding VLAN 0 to HW filter on device %s\n",
>> +				dev->name);
>> +			vlan_vid_add(dev, htons(ETH_P_8021Q), 0);
> Not sure if this works always, because if we have no vlan at all when
> the device comes up vlan_info will be NULL and we won't even get here.
>
> IIUC adding vlan 0 has to be handled early, where UP is handled.

Yes, that's right.

the sequence as below can still trigger the issue:

$ ip link add bond0 type bond mode 0
$ ethtool -K bond0 rx-vlan-filter off
$ ifconfig bond0 up
$ ethtool -K bond0 rx-vlan-filter on
$ ip link add link bond0 name vlan0 type vlan id 0 protocol 802.1q
$ ifconfig bond0 down
$ ifconfig bond0 up
$ ip link del vlan0

maybe we can fix it by:

diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index 6e01ece0a95c..262f8d3f06ef 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -378,14 +378,18 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
              return notifier_from_errno(err);
      }
  
-    if ((event == NETDEV_UP) &&
-        (dev->features & NETIF_F_HW_VLAN_CTAG_FILTER)) {
+    if (((event == NETDEV_UP) &&
+        (dev->features & NETIF_F_HW_VLAN_CTAG_FILTER)) ||
+        (event == NETDEV_CVLAN_FILTER_PUSH_INFO &&
+        (dev->flags & IFF_UP))) {
          pr_info("adding VLAN 0 to HW filter on device %s\n",
              dev->name);
          vlan_vid_add(dev, htons(ETH_P_8021Q), 0);
      }
-    if (event == NETDEV_DOWN &&
-        (dev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
+    if ((event == NETDEV_DOWN &&
+        (dev->features & NETIF_F_HW_VLAN_CTAG_FILTER)) ||
+        (event == NETDEV_CVLAN_FILTER_DROP_INFO &&
+        (dev->flags & IFF_UP)))
          vlan_vid_del(dev, htons(ETH_P_8021Q), 0);
  
     vlan_info = rtnl_dereference(dev->vlan_info);

------
Best regards
Dong Chenchen

>> +		}
>>   		err = vlan_filter_push_vids(vlan_info, htons(ETH_P_8021Q));
>>   		if (err)
>>   			return notifier_from_errno(err);
>>   		break;
>>   
>>   	case NETDEV_CVLAN_FILTER_DROP_INFO:
>> +		flgs = dev_get_flags(dev);
>> +		if (flgs & IFF_UP)
>> +			vlan_vid_del(dev, htons(ETH_P_8021Q), 0);
>>   		vlan_filter_drop_vids(vlan_info, htons(ETH_P_8021Q));

  reply	other threads:[~2025-06-26  3:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-23 11:30 [PATCH net] net: vlan: fix VLAN 0 refcount imbalance of toggling filtering during runtime Dong Chenchen
2025-06-25  0:42 ` Jakub Kicinski
2025-06-26  3:41   ` dongchenchen (A) [this message]
2025-06-27 14:41     ` Ido Schimmel
2025-06-30  1:25       ` dongchenchen (A)
2025-06-30  8:14         ` Ido Schimmel

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=900f28da-83db-4b17-b56b-21acde70e47f@huawei.com \
    --to=dongchenchen2@huawei.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@treblig.org \
    --cc=netdev@vger.kernel.org \
    --cc=oscmaes92@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=pedro.netdev@dondevamos.com \
    --cc=yuehaibing@huawei.com \
    --cc=zhangchangzhong@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
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).