Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3720459pxv; Mon, 26 Jul 2021 10:12:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5uQSUs7mWg1U8Ap6tAzuVKpvNQzWZPXmZnP4cHn02a1RbsDJ3BDjhhXClL4T6wYXPTVpc X-Received: by 2002:a05:600c:2306:: with SMTP id 6mr34520wmo.144.1627319404376; Mon, 26 Jul 2021 10:10:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627319404; cv=none; d=google.com; s=arc-20160816; b=P8vUcaG0fp4uf29JrOLvm4wRTrBMb6xdiHbyrpGTPTQ1HwpxrDOp0Sp5KyEzDuJd8p pK2LkhKiZiaNXZj5yDJiorb+zSEed6PWaj4H9sUu50wp71Y75sB466jtsrKOioo7HVYx clBec00imgQqOxXI4N0kbEjJ7qqbxSW3bsGhrCLvODcMl0pVF0eVVtQUwrMMwB8toadc 0u20cV9itxQ4XEj3sQTfFfxCtEVpCb3BuUACHQ6ffIKMYwem5120voX0r5fsSVeSyxfz zm1Zlyi+8gyDgQ73ospZuFb3elsGrW55gdsPIetTlG825sm4URflV3zc0txu1VBZPgYY Suew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=y7xB1rXLg81WbppTIWKFla+sXE2W+EdadUY0fHxSUsk=; b=nuhY0LwABohPgXyoG/PgUq9VupeOLd2uC3sqkmHa6oD3XRXnULpN9C3EJpcuzcBDN6 9CwxG8spFu0SfpQT6sQ0cYKIqoqzF275inu/2U4+vQgrMficRH177++bp5+IaZgAU9dJ itmwWcSzs7qUVlr1m0dnyaoghwvNrPSu+sfXjm/zcMo8Lc0Hlf5y87aerzhmgRdWUmOC ddWMaIDvQLGBkB/vTv6V2VngHQExXlyy+MHOMnkRzE6f/DlQO6X5gk08kTPyNb9no3cn t2ALXTOxubfQ/n5l/uBlTZezMagQYdim1MCo8C0PqfX4U/TC/EayDbcrbSx8i7XWYepZ GPBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Bw8mOPXG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 19si46070wmg.202.2021.07.26.10.09.36; Mon, 26 Jul 2021 10:10:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Bw8mOPXG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239449AbhGZPwd (ORCPT + 99 others); Mon, 26 Jul 2021 11:52:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:48244 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233441AbhGZPcU (ORCPT ); Mon, 26 Jul 2021 11:32:20 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 92A7260C40; Mon, 26 Jul 2021 16:12:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315965; bh=9gIvzkB3UGqRN0BG9Zxjq53srvaJIaXklkW2JvwjXtg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bw8mOPXG61DFbYD4Aw5HdWMYUtLsE0QJ0C/TDGvQhONau4FluoJ3M8seP590tgOoY 3rQnGXzwzcBAfRcUVT9UiznwZ/z1ZWkLaHSCk8mhoHmIb8gPjJnTVR7DMNQebKmnUk ugNraJs+pei8fLK077s3+lDBXk3uMeNZSKu7LfnA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Radu Pirea (NXP OSS)" , Vladimir Oltean , "David S. Miller" , Sasha Levin Subject: [PATCH 5.13 135/223] net: dsa: sja1105: make VID 4095 a bridge VLAN too Date: Mon, 26 Jul 2021 17:38:47 +0200 Message-Id: <20210726153850.663680353@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153846.245305071@linuxfoundation.org> References: <20210726153846.245305071@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vladimir Oltean [ Upstream commit e40cba9490bab1414d45c2d62defc0ad4f6e4136 ] This simple series of commands: ip link add br0 type bridge vlan_filtering 1 ip link set swp0 master br0 fails on sja1105 with the following error: [ 33.439103] sja1105 spi0.1: vlan-lookup-table needs to have at least the default untagged VLAN [ 33.447710] sja1105 spi0.1: Invalid config, cannot upload Warning: sja1105: Failed to change VLAN Ethertype. For context, sja1105 has 3 operating modes: - SJA1105_VLAN_UNAWARE: the dsa_8021q_vlans are committed to hardware - SJA1105_VLAN_FILTERING_FULL: the bridge_vlans are committed to hardware - SJA1105_VLAN_FILTERING_BEST_EFFORT: both the dsa_8021q_vlans and the bridge_vlans are committed to hardware Swapping out a VLAN list and another in happens in sja1105_build_vlan_table(), which performs a delta update procedure. That function is called from a few places, notably from sja1105_vlan_filtering() which is called from the SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING handler. The above set of 2 commands fails when run on a kernel pre-commit 8841f6e63f2c ("net: dsa: sja1105: make devlink property best_effort_vlan_filtering true by default"). So the priv->vlan_state transition that takes place is between VLAN-unaware and full VLAN filtering. So the dsa_8021q_vlans are swapped out and the bridge_vlans are swapped in. So why does it fail? Well, the bridge driver, through nbp_vlan_init(), first sets up the SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING attribute, and only then proceeds to call nbp_vlan_add for the default_pvid. So when we swap out the dsa_8021q_vlans and swap in the bridge_vlans in the SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING handler, there are no bridge VLANs (yet). So we have wiped the VLAN table clean, and the low-level static config checker complains of an invalid configuration. We _will_ add the bridge VLANs using the dynamic config interface, albeit later, when nbp_vlan_add() calls us. So it is natural that it fails. So why did it ever work? Surprisingly, it looks like I only tested this configuration with 2 things set up in a particular way: - a network manager that brings all ports up - a kernel with CONFIG_VLAN_8021Q=y It is widely known that commit ad1afb003939 ("vlan_dev: VLAN 0 should be treated as "no vlan tag" (802.1p packet)") installs VID 0 to every net device that comes up. DSA treats these VLANs as bridge VLANs, and therefore, in my testing, the list of bridge_vlans was never empty. However, if CONFIG_VLAN_8021Q is not enabled, or the port is not up when it joins a VLAN-aware bridge, the bridge_vlans list will be temporarily empty, and the sja1105_static_config_reload() call from sja1105_vlan_filtering() will fail. To fix this, the simplest thing is to keep VID 4095, the one used for CPU-injected control packets since commit ed040abca4c1 ("net: dsa: sja1105: use 4095 as the private VLAN for untagged traffic"), in the list of bridge VLANs too, not just the list of tag_8021q VLANs. This ensures that the list of bridge VLANs will never be empty. Fixes: ec5ae61076d0 ("net: dsa: sja1105: save/restore VLANs using a delta commit method") Reported-by: Radu Pirea (NXP OSS) Signed-off-by: Vladimir Oltean Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/dsa/sja1105/sja1105_main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index ebe4d33cda27..6e5dbe9f3892 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -378,6 +378,12 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv) if (dsa_is_cpu_port(ds, port)) v->pvid = true; list_add(&v->list, &priv->dsa_8021q_vlans); + + v = kmemdup(v, sizeof(*v), GFP_KERNEL); + if (!v) + return -ENOMEM; + + list_add(&v->list, &priv->bridge_vlans); } ((struct sja1105_vlan_lookup_entry *)table->entries)[0] = pvid; -- 2.30.2