From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=68.232.153.233 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796029182; b=PDEHxY0zpwnFzTn0rNKA+E9EJSyR/wbuQpqWJRQlCdKmGefM3jUei5D/4kyHzVcRFCeK ldFt9w0zf9dA32l6U2TBN3lsKtGs/p/IuQCH5VkT6aAuV9bPLcwQ+eaCrcrDc2+3y2O/K F99LTDi2IbXzThHraGIiAq+KxHx+fevwyDd3ChkLAOc0t8NcYuuWVhUGWQmtmxOYxnf/w lPeoUGjCf+XS4sUQOY7zGStrPiveaUebXX+UmOzh5tiarK5Da45LOoK8ukJGIyQXcW2BF xcCfMaWRxpezVJy4hYoa1GOD22Yn1fzNwdvqWbZSKnS1BGRpfcfcgn9vFDQMK6/Slew== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796029182; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-Amp-Result:Received:Received:Received:MIME-Version: Content-Transfer-Encoding:Content-Type:Date:Message-ID:To:Subject:CC: From:X-Mailer:References:In-Reply-To; bh=sN+1vxjS7fet+29pJXpu/beseb80hReYZGnaBp7r4hk=; b=fkM5nHk3eLVW3UMwro9QsyJuSlSpuyPlUuYlK0h3PgocPff0ieHRldvE01qRh63LfV1O Ew1GKM6pri0a1M+gwn8ihTpXqbATFSzKCd85hXBuct6EdnKp6l65b0aeMu0UhxDBT8N7T rsijDjsyaWbf6/CGxGz2PXCYhztcox7qOpUqfJV2nWixxUTfdXrMY/8WnfyVe84spgt1d 9Y7F/1PLMFesXRdjYh45n+ykuKfLTIk0OefcMoy8DKaN6tyV732aftQeK8Cg5hSBk09ZA zK/X7ReQXd02qKhl+s4ZsZ6upJ6I5TKKpbRyFDJ/ruzPfcrRyX/uE2/CTZzDDXaXD2A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass header.d=microchip.com header.i=@microchip.com header.a=rsa-sha256 header.s=mchp header.b=CQbatJ8A; arc=none smtp.remote-ip=68.232.153.233 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85BC4606A320; Mon, 30 Nov 2026 08:59:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 85BC4606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=microchip.com header.i=@microchip.com header.a=rsa-sha256 header.s=mchp header.b=CQbatJ8A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1796029181; x=1827565181; h=mime-version:content-transfer-encoding:date:message-id: to:subject:cc:from:references:in-reply-to; bh=yHVPzXYA9no579o5+gsDvOqL5yzMGzr7cqht2nH6MEY=; b=CQbatJ8ALU7wh7IMDL2PkIf6oPZjBi2dDI7hgYep8Y+MDGRCe07Z/3mU B9ixF8Z5qoeZmnqQfhynXYV5oyblNzH77QQ9oIk9JwO+R5JGd1Jwvz8w6 e2oqqQJK15cRx9iDgMbdUT05Pam5U75oMHm6d0gdssKLkiy/B8XEeThx3 zbAJZi2OOEbXIY1NR4y24lC42komzDiewDq/8Kus/q/u353kNODEIWwQF tknXgdIeEj2/ZveSNEAUbFWKD9qm+gDQeB3wSSQ2dHgsmCIYdWOK9qWkz wB1LS2/Fq16MBN9Y3SBSEkgiuvCUPLjwovSya9ZhxSEOw8nKc8MqLWEE2 A==; X-CSE-ConnectionGUID: tdDv//+YQyawiknvn7mdMg== X-CSE-MsgGUID: c2ibJ7djTx2MxqQ/GEqLEw== X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="67217605" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa3.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 01:59:40 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.87.71) by chn-vm-ex1.mchp-main.com (10.10.87.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.57; Mon, 30 Nov 2026 01:59:39 -0700 Received: from localhost (10.10.85.11) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.58 via Frontend Transport; Mon, 30 Nov 2026 01:59:39 -0700 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" Date: Mon, 30 Nov 2026 09:59:38 +0100 Message-ID: To: , Subject: Re: [PATCH net-next v2 4/5] net: dsa: lan9645x: add mdb management CC: , , , , , , , , , From: =?utf-8?q?Jens_Emil_Schulz_=C3=98stergaard?= X-Mailer: aerc 0.21.0 References: <20261127-dsa-lan9645x-add-vlan-and-bridge-offload-v2-4-84adcd919dac@microchip.com> <179585821603.3135.8897851570267495148@kernel.org> In-Reply-To: <179585821603.3135.8897851570267495148@kernel.org> On Sat Nov 28, 2026 at 10:30 AM CET, netdev-bot+sashiko wrote: > Thank you for your contribution! Sashiko AI review found 5 potential > issue(s) to consider. > > Critical: 0 =C2=B7 High: 0 =C2=B7 Medium: 2 =C2=B7 Low: 3 > > If you believe none of the issues are legitimate, please reply to each > issue of Medium severity or higher and explain why the AI is wrong. > If any of them are legitimate and you plan to respin, please let patchwor= k > know by including "pw-bot: cr" as a separate line at the end of your repl= y > (one such reply per series is enough). > > - [Medium] Per-port MDB membership is a single bit per (MAC, hw VID), > with no refcount for IP groups that map to the same multicast MAC. > - [Medium] When the general-purpose PGIDs (48 PGIDs, 9..56, shared by all > bridges and the standalone host MDB entries) are used up,=E2=80=A6 > - [Low] When the last member leaves, lan9645x_mdb_del() calls > lan9645x_mdb_entry_destroy(). > - [Low] L2 (non-IP) MDB groups are written to the MAC table as > ENTRYTYPE_LOCKED at key (addr, hw_vid) with DEST_IDX=3Dpgid. > - [Low] For IPv4/IPv6 MDB entries, lan9645x_mdb_write_ports() passes the > full `ports` mask, including BIT(num_phys_ports) (the CPU port module,= =E2=80=A6 > > -- > > net: dsa: lan9645x: add mdb management > > This adds the DSA port_mdb_add/port_mdb_del callbacks for lan9645x. IP > multicast groups store the port mask inline in the MAC table entry. Each > L2 multicast group allocates one general purpose PGID. IGMP/MLD frames > are redirected to the CPU, and IPv4 multicast control frames are copied > to it. > >> diff --git a/drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c b/drivers= /net/dsa/microchip/lan9645x/lan9645x_mdb.c >> new file mode 100644 >> index 0000000000000..6864b89d5a2d4 >> --- /dev/null >> +++ b/drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c > > [ ... ] > >> +static int lan9645x_mdb_write_ports(struct lan9645x *lan9645x, >> + struct lan9645x_mdb_entry *mdb_entry, >> + u16 ports) >> +{ >> + unsigned char mac[ETH_ALEN] __aligned(2); >> + bool cpu_copy; >> + >> + lockdep_assert_held(&lan9645x->mdb_lock); >> + >> + if (mdb_entry->type =3D=3D ENTRYTYPE_LOCKED) { >> + lan_rmw(ANA_PGID_PGID_SET(ports), ANA_PGID_PGID, lan9645x, >> + ANA_PGID(mdb_entry->pgid)); >> + return 0; >> + } >> + >> + lan9645x_mdb_encode_mac(mac, mdb_entry->mac, ports, mdb_entry->type); >> + cpu_copy =3D !!(ports & BIT(lan9645x->num_phys_ports)); > > [Severity: Low] > Should the CPU bit be masked out of ports before it is encoded inline > here? > > As written, lan9645x_mdb_encode_mac() writes BIT(num_phys_ports) into the > inline destination bytes, and MAC_CPU_COPY is also set from the same bit. > The commit message says IP host membership is carried in MAC_CPU_COPY. > > L2 groups reach the CPU through the PGID CPU bit, and that path is gated > per VLAN. ANA_PGID_CFG.OBEY_VLAN is set, and lan9645x_vlan_hw_wr() sets > VLAN_PGID_CPU_DIS when the CPU is not in the VLAN portmask. IP entries > use the dummy DEST_IDX 0, so they don't get that gating. > > The lan966x driver keeps the CPU out of the inline mask. It only sets > cpu_copy when the CPU is a member of the VLAN. DSA doesn't add user-port > VLANs to the CPU port, so a host MDB entry can exist in a VID the CPU > isn't a member of. One example is a static "bridge mdb add dev br0 port > br0 ... vid V" where br0 isn't in V. > > In that VID, would IP host groups still be copied to the CPU while L2 > host groups are not? This is inferred from lan966x. I couldn't confirm > from the LAN9645x documentation what inline bit 9 means, or whether > MAC_CPU_COPY follows VLAN membership. > >> + >> + /* For IP multicast, the hardware lookup uses the DMAC >> + * (01:00:5E:.. / 33:33:..) as the (mac, vid) key, not the encoded mac= . >> + * Therefore, this CMD_LEARN will atomically rewrite the existing >> + * hardware entry. We intentionally do not do a forget before learn >> + * sequence, as that would not be atomic, and leave a forwarding gap. >> + */ >> + return lan9645x_mact_learn(lan9645x, IP_ENTRY_PGID, mac, mdb_entry->vi= d, >> + mdb_entry->type, cpu_copy); >> +} >> + >> +static int lan9645x_mdb_entry_create(struct lan9645x *lan9645x, int chi= p_port, >> + const unsigned char addr[ETH_ALEN], >> + u16 vid) >> +{ > > [ ... ] > >> + if (mdb_entry->type =3D=3D ENTRYTYPE_LOCKED) { >> + mdb_entry->pgid =3D find_next_zero_bit(lan9645x->mdb_pgids, >> + PGID_GP_END, >> + PGID_GP_START); >> + if (mdb_entry->pgid >=3D PGID_GP_END) { >> + kfree(mdb_entry); >> + return -ENOSPC; >> + } >> + } > > [Severity: Medium] > Does returning -ENOSPC here make a bridge join fail, instead of just > leaving the group unoffloaded? > > The commit message says: > > When they are exhausted, adding a new group fails with -ENOSPC and the > group is not offloaded. > > lan9645x_port_mdb_add() returns this code unchanged, but > br_switchdev_mdb_replay() only tolerates -EOPNOTSUPP: > > net/bridge/br_switchdev.c:br_switchdev_mdb_replay() { > ... > if (err =3D=3D -EOPNOTSUPP) > err =3D 0; > if (err) > goto out_free_mdb; > ... > } > > The error then goes through nbp_switchdev_sync_objs() to > br_switchdev_port_offload(). That function fails the offload without > unsyncing the entries that were already replayed. > > The 48 general purpose PGIDs are shared by all bridges and by the > standalone host entries. Once they are all in use, would "ip link set > swpN master br0" fail entirely? Would the PGIDs and port bits of the > entries replayed before the failure stay programmed in the driver? > > lan9645x_port_mdb_add() already returns -EOPNOTSUPP for the reserved VID > case. Could PGID exhaustion, and the -ENOSPC that lan9645x_mact_learn() > returns on CPU_LEARN_FAILED, be handled the same way? > > This becomes reachable once "net: dsa: lan9645x: add bridge support" > adds .port_bridge_join later in the series. That commit doesn't change > this error handling. > Yes, this is intended. Running out of PGIDs or MAC table space is a resource limit, and I think -ENOSPC is fitting. -EOPNOTSUPP is used for the reserved VIDs because those entries can never be offloaded. ocelot and lan966x return -ENOSPC from .port_mdb_add on PGID exhaustion as well. It is also hard to reach. Only non-IP L2 groups take a PGID. A port that joins a bridge directly has no port groups yet, so the replay only holds the host groups of the bridge, and DSA refcounts those on the CPU port, so only the first port of a bridge installs them. >> + >> + err =3D lan9645x_mdb_write_ports(lan9645x, mdb_entry, mdb_entry->ports= ); >> + if (!err && mdb_entry->type =3D=3D ENTRYTYPE_LOCKED) >> + err =3D lan9645x_mact_learn(lan9645x, mdb_entry->pgid, addr, vid, >> + mdb_entry->type, false); > > [Severity: Low] > Can this collide with a static FDB entry for the same multicast MAC and > VID? > > lan9645x_fdb_add() also learns ENTRYTYPE_LOCKED at (addr, hw_vid), with > DEST_IDX set to a port: > > drivers/net/dsa/microchip/lan9645x/lan9645x_main.c:lan9645x_fdb_add() { > ... > return lan9645x_mact_learn(lan9645x, dest, addr, > lan9645x_fdb_vid(vid, &db), > ENTRYTYPE_LOCKED, false); > } > > br_fdb_add() only rejects all-zero MACs, so a command like "bridge fdb > add 01:xx:... dev swpN master static vid V" reaches it. > > Whichever of the FDB entry and the L2 MDB entry is learned last > overwrites the other's destination. Deleting either one sends CMD_FORGET > for the shared key, which also removes the other's hardware entry. > > For ENTRYTYPE_LOCKED, lan9645x_mdb_write_ports() only rewrites ANA_PGID > and never re-learns the MAC entry. Doesn't that leave the MDB state out > of sync with the hardware until the group is deleted and recreated? > > [ ... ] > >> +static void lan9645x_mdb_entry_destroy(struct lan9645x *lan9645x, >> + struct lan9645x_mdb_entry *mdb_entry) >> +{ > > [ ... ] > >> + err =3D lan9645x_mact_forget(lan9645x, mdb_entry->mac, mdb_entry->vid, >> + mdb_entry->type); >> + if (err) >> + dev_err(lan9645x->dev, "Forgetting %pM vid %u returned %pe\n", >> + mdb_entry->mac, mdb_entry->vid, ERR_PTR(err)); >> + else if (mdb_entry->type =3D=3D ENTRYTYPE_LOCKED) >> + clear_bit(mdb_entry->pgid, lan9645x->mdb_pgids); >> + >> + list_del(&mdb_entry->list); >> + kfree(mdb_entry); >> +} > > [Severity: Low] > What happens to the hardware entry if lan9645x_mact_forget() fails here? > > lan9645x_mdb_del() clears the port from mdb_entry->ports and calls this > function. It does not first write an empty ANA_PGID(pgid) or an empty > inline mask. > > The forget can fail with a bus error, or with -ETIMEDOUT from > lan9645x_rd_poll_timeout() in __lan9645x_mact_forget(). In that case the > MAC table entry stays valid and keeps forwarding to the departed port > through the old mask. The tracking entry is freed anyway. > > For L2 groups the PGID bit is intentionally left set, so that PGID is > lost permanently. A later re-add allocates a new PGID and CMD_LEARN > repoints the same MAC slot at it. The old PGID is then orphaned, and the > pool has only 48. > > Would clearing ANA_PGID(pgid) with a register write before CMD_FORGET > stop the stale forwarding? That would also make it safe to release the > PGID whatever the forget returns. > > The partial removal path in lan9645x_mdb_del() has a similar ordering > problem. mdb_entry->ports is updated before lan9645x_mdb_write_ports(). > For IP entries that call is a CMD_LEARN, and if it fails the old inline > port set stays in hardware. > >> + >> +int lan9645x_mdb_add(struct lan9645x *lan9645x, int chip_port, >> + const unsigned char addr[ETH_ALEN], u16 vid) >> +{ >> + struct lan9645x_mdb_entry *mdb_entry; >> + u16 new_ports; >> + int err =3D 0; >> + >> + mutex_lock(&lan9645x->mdb_lock); >> + >> + mdb_entry =3D lan9645x_mdb_entry_lookup(lan9645x, addr, vid); >> + if (!mdb_entry) { >> + err =3D lan9645x_mdb_entry_create(lan9645x, chip_port, addr, vid); >> + goto out; >> + } >> + >> + if (mdb_entry->ports & BIT(chip_port)) >> + goto out; > > [Severity: Medium] > Does this need a per-port refcount for IP groups that map to the same > multicast MAC? > > The bridge sends one SWITCHDEV_OBJ_ID_PORT_MDB object per IP group. > br_switchdev_mdb_populate() turns each group into a MAC address with > ip_eth_mc_map()/ipv6_eth_mc_map(). For example, 224.1.1.1 and 225.1.1.1 > both become 01:00:5e:01:01:01. > > DSA doesn't refcount these for user ports: > > net/dsa/switch.c:dsa_port_do_mdb_del() { > ... > /* No need to bother with refcounting for user ports */ > if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) { > err =3D ds->ops->port_mdb_del(ds, port, mdb, db); > ... > } > > Take two receivers behind one port that join 224.1.1.1 and 225.1.1.1. > The second join is a no-op here. > > When one of them leaves or times out, lan9645x_mdb_del() does: > > mdb_entry->ports &=3D ~BIT(chip_port); > > It then either rewrites the mask without the port or destroys the entry. > > Would the port then stop receiving the group it is still a member of? > Bridge refreshes of the remaining group don't re-notify switchdev, so > the loss would last until the bridge recreates that port group. > > This becomes reachable with .port_bridge_join from "net: dsa: lan9645x: > add bridge support", which doesn't change lan9645x_mdb.c. This is the same finding as in v1 [1], and the answer is the same: This aliasing problem is right, but I believe this is preexisting, and that the fix needs to be in the bridge core. A reference count in the driver cannot be balanced. The switchdev MDB object only carries the group MAC and VID, and the bridge also sends an add for a port group that already exists: on bridge mdb replace (br_mdb_replace_group_sg() and br_mdb_replace_group_star_g()), when an IGMPv3/MLDv2 report changes the source list or filter mode, and when the group timer moves a group to INCLUDE mode. The delete is sent once per port group. These two sequences bridge mdb add dev br0 port swp0 grp 239.1.1.1 permanent bridge mdb add dev br0 port swp0 grp 224.129.1.1 permanent bridge mdb del dev br0 port swp0 grp 224.129.1.1 permanent bridge mdb add dev br0 port swp0 grp 239.1.1.1 permanent bridge mdb replace dev br0 port swp0 grp 239.1.1.1 permanent bridge mdb del dev br0 port swp0 grp 239.1.1.1 permanent both reach the driver as add, add, del of 01:00:5e:01:01:01. After the first, swp0 must stay in the entry for 239.1.1.1. After the second, the bridge no longer has the group and swp0 must leave it. The driver cannot tell them apart, since the IP group is not in the object. DSA does not count user port MDB entries either, and ocelot, lan966x and mv88e6xxx behave the same way. Fixing the aliasing needs a bridge change: either notify switchdev only when a port group is created, so that adds and deletes balance and a per-port count works, or pass the group address in the object, so that drivers can track port groups themselves. [1] https://lore.kernel.org/netdev/DN4BH0TO8KZ0.1PCZKO375ZQNV@microchip.com= /