Re: [RFC PATCH net-next] net: dsa: tag_qca: Check for upstream VLAN tag

From: Vladimir Oltean
Date: Sun Jun 06 2021 - 15:27:54 EST


On Sun, Jun 06, 2021 at 02:09:24PM +0100, Matthew Hagan wrote:
> On 06/06/2021 01:53, Vladimir Oltean wrote:
>
> > It is a bit unconventional for the upstream Broadcom switch, which is a
> > DSA master of its own, to insert a VLAN ID of zero out of the blue,
> > especially if it operates in standalone mode. Supposedly sw0 and sw1 are
> > not under a bridge net device, are they?
>
> sw0 and sw1 are brought up but otherwise left unconfigured. The bridge
> consists of the user ports only (wanN and swNpN). A side note here is that
> your "net: dsa: don't set skb->offload_fwd_mark when not offloading the
> bridge" patch is also in use. Would setting up a bridge for sw0/sw1 not
> have implications for receiving unknown frames on one port, that have been
> sent from another port of the same switch? Since unknown frames will go to
> the CPU, dp->bridge_dev would return the bridge name, setting
> offload_fwd_mark=1 thus preventing those frames being sent back out
> sw0/sw1 to its other ports.

What you have is called "cross-chip bridging for disjoint DSA trees" and
has some level of support since this series:
http://patchwork.ozlabs.org/project/netdev/cover/20200510163743.18032-1-olteanv@xxxxxxxxx/

What you can/should do is:

create a bridge between sw0 and sw1 (say br1)
create another bridge between wanN and swNpM (say br0)

Here's the secret:

- the br1 bridge only performs hardware acceleration for forwarding
between the 2 QCA switches. The Broadcom switch is still able to
understand enough (aka the destination MAC) of the packets coming from
the QCA switches, even if they are DSA tagged, in order to perform L2
forwarding to the other port or to the CPU port. And because br0 != br1,
what you mentioned above for skb->offload_fwd_mark does not actually
matter - there are only 2 ports in br1, and both are part of the same
hardware domain, so the software bridge doesn't need to forward any
packet. As for br0, by the time the packets from swNpM reach the
software bridge, there is no longer any indication that they were
originally processed by the Broadcom ports as DSA masters, so there is
no problem forwarding them in software to the other Broadcom ports
(not DSA masters).
- the br0 bridge, in the presence of br1, doesn't have to do software
forwarding of packets between the 2 QCA switches - br1 handles it. But
even if br1 did not exist, it still could. How?
nbp_switchdev_allowed_egress() will happily forward packets between
ports with different offload_fwd_mark values. These are derived from:

nbp_switchdev_mark_set
-> dev_get_port_parent_id
-> devlink_compat_switch_id_get
-> &devlink_port->attrs.switch_id

populated by &devlink_port->attrs.switch_id based on dst->index.

Otherwise said, the devlink switch id is equal to the DSA switch tree
index.

But you already set the dsa,member properties properly (i.e. each QCA
switch is in its own tree with a unique index):

switch@10 {
compatible = "qca,qca8337";
dsa,member = <1 0>;
};

switch@10 {
compatible = "qca,qca8337";
dsa,member = <2 0>;
};

So there is in fact no problem.

The "net: dsa: don't set skb->offload_fwd_mark when not offloading the bridge"
patch was not accepted yet, am I right?
https://patchwork.kernel.org/project/netdevbpf/patch/20210318231829.3892920-15-olteanv@xxxxxxxxx/
Why are you using RFC patches instead of asking for them to be submitted
properly? :)

Regardless of that patch being present or not (which affects a different
use case which I cannot see how it relates to this), I think there is a bug:

if the DSA master sets skb->offload_fwd_mark = true, and then the DSA
tagger gets to process that same skb, and it wants to indicate it is a
standalone / non-offloading port, currently it will simply not set
skb->offload_fwd_mark = true. But not setting it to true is different
than always setting skb->offload_fwd_mark to true or false - it just
works because we assume that skb->offload_fwd_mark is initially false,
which is obv not true if the DSA master had already set it to true.
So if there is a provable bug caused by this, we might need a patch
which sets skb->offload_fwd_mark = false in dsa_switch_rcv(), right
before the call to cpu_dp->rcv(), in order to satisfy the taggers'
expectation that we do indeed start from a blank slate.
Does that make sense?

> >
> > If I'm not mistaken, this patch should solve your problem?
> >
> > -----------------------------[ cut here ]-----------------------------
> > diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
> > index 3ca6b394dd5f..d6655b516bd8 100644
> > --- a/drivers/net/dsa/b53/b53_common.c
> > +++ b/drivers/net/dsa/b53/b53_common.c
> > @@ -1462,6 +1462,7 @@ int b53_vlan_add(struct dsa_switch *ds, int port,
> > struct b53_device *dev = ds->priv;
> > bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
> > bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
> > + bool really_untagged = false;
> > struct b53_vlan *vl;
> > int err;
> >
> > @@ -1474,10 +1475,10 @@ int b53_vlan_add(struct dsa_switch *ds, int port,
> > b53_get_vlan_entry(dev, vlan->vid, vl);
> >
> > if (vlan->vid == 0 && vlan->vid == b53_default_pvid(dev))
> > - untagged = true;
> > + really_untagged = true;
> >
> > vl->members |= BIT(port);
> > - if (untagged && !dsa_is_cpu_port(ds, port))
> > + if (really_untagged || (untagged && !dsa_is_cpu_port(ds, port)))
> > vl->untag |= BIT(port);
> > else
> > vl->untag &= ~BIT(port);
> > -----------------------------[ cut here ]-----------------------------
> >
> This does seem to sort the issue as well in this case. Thanks!

I'm sure Florian will explain some of the additional constraints around
why we might want the Broadcom switches to send untagged packets as
tagged with VID 0 towards the CPU, so the patch might suffer some
changes until submitted proper. At the very least, the same configuration
needs to work regardless of the value of CONFIG_VLAN_8021Q.
Currently, the default VLAN configuration done by b53_configure_vlan()
is overwritten by:

vlan_device_event (the "adding VLAN 0 to HW filter on device %s" message)
-> vlan_vid_add
-> ...
-> dsa_slave_vlan_rx_add_vid
-> dsa_port_vlan_add
-> ...
-> b53_vlan_add

so my point is that it is not robust to only fix the case where this
chain of events happens, because CONFIG_VLAN_8021Q is entirely optional,
and if it is not enabled, nobody will add VID 0 to the RX filter of the
net devices, so the configuration of VID 0 on the Broadcom ports will be
left as it is done by the switch initialization code, and that code
should produce the same results.