Skip to contentSkip to conversation

devlink: Warn on resource ID collision with PARENT_TOP

PATCH Applied David Yang 3 participants 8 messages Jun 11 – Jun 15

Subsystems (7)
lore
Share & tools
lore

David Yang

author
#0 lore raw

v2 cover devlink: Warn on resource ID collision with PARENT_TOP

Filter out the ambiguous case of

enum {
    MY_RESOURCE_ID_A,  /* == DEVLINK_RESOURCE_ID_PARENT_TOP ! */
    MY_RESOURCE_ID_B,
    ...
};

register(..., MY_RESOURCE_ID_A, DEVLINK_RESOURCE_ID_PARENT_TOP, ...); register(..., MY_RESOURCE_ID_B, MY_RESOURCE_ID_A, ...);

v1: https://lore.kernel.org/r/[email protected]
- make a patchset

David Yang (5):
net: dsa: dsa_loop: avoid devlink resource IDs collision with
PARENT_TOP
net: dsa: b53: avoid devlink resource IDs collision with PARENT_TOP
net: dsa: hellcreek: avoid devlink resource IDs collision with
PARENT_TOP
net: dsa: mv88e6xxx: Avoid devlink resource IDs collision with
PARENT_TOP
devlink: Warn on resource ID collision with PARENT_TOP

 drivers/net/dsa/b53/b53_common.c       | 1 +
 drivers/net/dsa/dsa_loop.c             | 1 +
 drivers/net/dsa/hirschmann/hellcreek.h | 1 +
 drivers/net/dsa/mv88e6xxx/devlink.c    | 9 +++++----
 net/devlink/resource.c                 | 2 ++
 5 files changed, 10 insertions(+), 4 deletions(-)
Signature · 1 line
2.53.0
author
#1 lore raw

PATCH v2 1/5 net: dsa: dsa_loop: avoid devlink resource IDs collision with PARENT_TOP

This might not cause real problems, but the dsa_loop devlink resource ID collides with the sentinel DEVLINK_RESOURCE_ID_PARENT_TOP (0). Avoid it by keeping the real resource IDs starting at 1.

---
 drivers/net/dsa/dsa_loop.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/dsa/dsa_loop.c +1 -0
index 7058faf23592..0e35e9841b9b 100644
@@ -75,6 +75,7 @@ static struct phy_device *phydevs[PHY_MAX_ADDR];
 static struct mdio_device *switch_mdiodev;
 
 enum dsa_loop_devlink_resource_id {
+	DSA_LOOP_DEVLINK_PARAM_ID_NONE,  /* DEVLINK_RESOURCE_ID_PARENT_TOP */
 	DSA_LOOP_DEVLINK_PARAM_ID_VTU,
 };
 
Signature · 1 line
2.53.0
author
#2 lore raw

PATCH v2 2/5 net: dsa: b53: avoid devlink resource IDs collision with PARENT_TOP

In reply to David Yang

This might not cause real problems, but the b53 devlink resource ID collides with the sentinel DEVLINK_RESOURCE_ID_PARENT_TOP (0). Avoid it by keeping the real resource IDs starting at 1.

---
 drivers/net/dsa/b53/b53_common.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/dsa/b53/b53_common.c +1 -0
index 06b8be8dc4db..3f5b9592794d 100644
@@ -1225,6 +1225,7 @@ int b53_get_sset_count(struct dsa_switch *ds, int port, int sset)
 EXPORT_SYMBOL(b53_get_sset_count);
 
 enum b53_devlink_resource_id {
+	B53_DEVLINK_PARAM_ID_NONE,  /* DEVLINK_RESOURCE_ID_PARENT_TOP */
 	B53_DEVLINK_PARAM_ID_VLAN_TABLE,
 };
 
Signature · 1 line
2.53.0
author
#3 lore raw

PATCH v2 3/5 net: dsa: hellcreek: avoid devlink resource IDs collision with PARENT_TOP

In reply to David Yang

This might not cause real problems, but the hellcreek devlink resource ID collides with the sentinel DEVLINK_RESOURCE_ID_PARENT_TOP (0). Avoid it by keeping the real resource IDs starting at 1.

---
 drivers/net/dsa/hirschmann/hellcreek.h | 1 +
 1 file changed, 1 insertion(+)
drivers/net/dsa/hirschmann/hellcreek.h +1 -0
index bebf0d3ff330..95593b5f002c 100644
@@ -311,6 +311,7 @@ struct hellcreek {
 
 /* Devlink resources */
 enum hellcreek_devlink_resource_id {
+	HELLCREEK_DEVLINK_PARAM_ID_NONE,  /* DEVLINK_RESOURCE_ID_PARENT_TOP */
 	HELLCREEK_DEVLINK_PARAM_ID_VLAN_TABLE,
 	HELLCREEK_DEVLINK_PARAM_ID_FDB_TABLE,
 };
Signature · 1 line
2.53.0
maintainer Acked-by on v2 3/5
#4 lore raw

Re: [PATCH net-next v2 3/5] net: dsa: hellcreek: avoid devlink resource IDs collision with PARENT_TOP

Quoted 5 lines · David Yang

This might not cause real problems, but the hellcreek devlink resource ID collides with the sentinel DEVLINK_RESOURCE_ID_PARENT_TOP (0). Avoid it by keeping the real resource IDs starting at 1.

author
#5 lore raw

PATCH v2 4/5 net: dsa: mv88e6xxx: Avoid devlink resource IDs collision with PARENT_TOP

In reply to David Yang

The devlink resource ID for ATU collides with the sentinel DEVLINK_RESOURCE_ID_PARENT_TOP (0). As a result, ATU_bin_* are registered as in fact registered as top-level siblings, not as children of ATU.

Whether intentional or unintentional, clarify it by keeping the real resource IDs starting at 1. Unfortunately ATU_bin_* are already registered at top-level, so keep their parent to PARENT_TOP.

---
 drivers/net/dsa/mv88e6xxx/devlink.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/dsa/mv88e6xxx/devlink.c +5 -4
index 0f84bffc8ef1..6f034841883c 100644
@@ -91,6 +91,7 @@ void mv88e6xxx_teardown_devlink_params(struct dsa_switch *ds)
 }
 
 enum mv88e6xxx_devlink_resource_id {
+	MV88E6XXX_RESOURCE_ID_NONE,  /* DEVLINK_RESOURCE_ID_PARENT_TOP */
 	MV88E6XXX_RESOURCE_ID_ATU,
 	MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
 	MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
@@ -200,7 +201,7 @@ int mv88e6xxx_setup_devlink_resources(struct dsa_switch *ds)
 	err = dsa_devlink_resource_register(ds, "ATU_bin_0",
 					    mv88e6xxx_num_macs(chip) / 4,
 					    MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
-					    MV88E6XXX_RESOURCE_ID_ATU,
+					    DEVLINK_RESOURCE_ID_PARENT_TOP,
 					    &size_params);
 	if (err)
 		goto out;
@@ -208,7 +209,7 @@ int mv88e6xxx_setup_devlink_resources(struct dsa_switch *ds)
 	err = dsa_devlink_resource_register(ds, "ATU_bin_1",
 					    mv88e6xxx_num_macs(chip) / 4,
 					    MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
-					    MV88E6XXX_RESOURCE_ID_ATU,
+					    DEVLINK_RESOURCE_ID_PARENT_TOP,
 					    &size_params);
 	if (err)
 		goto out;
@@ -216,7 +217,7 @@ int mv88e6xxx_setup_devlink_resources(struct dsa_switch *ds)
 	err = dsa_devlink_resource_register(ds, "ATU_bin_2",
 					    mv88e6xxx_num_macs(chip) / 4,
 					    MV88E6XXX_RESOURCE_ID_ATU_BIN_2,
-					    MV88E6XXX_RESOURCE_ID_ATU,
+					    DEVLINK_RESOURCE_ID_PARENT_TOP,
 					    &size_params);
 	if (err)
 		goto out;
@@ -224,7 +225,7 @@ int mv88e6xxx_setup_devlink_resources(struct dsa_switch *ds)
 	err = dsa_devlink_resource_register(ds, "ATU_bin_3",
 					    mv88e6xxx_num_macs(chip) / 4,
 					    MV88E6XXX_RESOURCE_ID_ATU_BIN_3,
-					    MV88E6XXX_RESOURCE_ID_ATU,
+					    DEVLINK_RESOURCE_ID_PARENT_TOP,
 					    &size_params);
 	if (err)
 		goto out;
Signature · 1 line
2.53.0
author
#6 lore raw

PATCH v2 5/5 devlink: Warn on resource ID collision with PARENT_TOP

In reply to David Yang

ID 0 serves as the sentinel DEVLINK_RESOURCE_ID_PARENT_TOP to mark top-level resources. While it is technically possible to use 0 as a real resource ID, a user might be tempted to write:

enum {
    MY_RESOURCE_ID_A,  /* == DEVLINK_RESOURCE_ID_PARENT_TOP ! */
    MY_RESOURCE_ID_B,
    MY_RESOURCE_ID_C,
    MY_RESOURCE_ID_D,
    ...
};

register(..., MY_RESOURCE_ID_C, DEVLINK_RESOURCE_ID_PARENT_TOP, ...); register(..., MY_RESOURCE_ID_D, MY_RESOURCE_ID_C, ...);
/* D is a child of C */

register(..., MY_RESOURCE_ID_A, DEVLINK_RESOURCE_ID_PARENT_TOP, ...); register(..., MY_RESOURCE_ID_B, MY_RESOURCE_ID_A, ...);
/* Is B intentionally top-level, or is it actually a child of A? */

Add a WARN_ON() to catch this and prevent confusion.

---
 net/devlink/resource.c | 2 ++
 1 file changed, 2 insertions(+)
net/devlink/resource.c +2 -0
index 3d2f42bc2fb5..574108ccfe5d 100644
@@ -486,6 +486,8 @@ __devl_resource_register(struct devlink *devlink,
 	struct list_head *resource_list;
 	bool top_hierarchy;
 
+	WARN_ON(resource_id == DEVLINK_RESOURCE_ID_PARENT_TOP);
+
 	lockdep_assert_held(&devlink->lock);
 
 	top_hierarchy = parent_resource_id == DEVLINK_RESOURCE_ID_PARENT_TOP;
Signature · 1 line
2.53.0
#7 lore raw
In reply to David Yang
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Thu, 11 Jun 2026 15:08:46 +0800 you wrote:

Filter out the ambiguous case of

enum {
    MY_RESOURCE_ID_A,  /* == DEVLINK_RESOURCE_ID_PARENT_TOP ! */
    MY_RESOURCE_ID_B,
    ...
};

[...]

Here is the summary with links:
- [net-next,v2,1/5] net: dsa: dsa_loop: avoid devlink resource IDs collision with PARENT_TOP

    https://git.kernel.org/netdev/net-next/c/b2772157e5ae
  - [net-next,v2,2/5] net: dsa: b53: avoid devlink resource IDs collision with PARENT_TOP
    https://git.kernel.org/netdev/net-next/c/89ccbd3fe837
  - [net-next,v2,3/5] net: dsa: hellcreek: avoid devlink resource IDs collision with PARENT_TOP
    https://git.kernel.org/netdev/net-next/c/31d2b61ba2cc
  - [net-next,v2,4/5] net: dsa: mv88e6xxx: Avoid devlink resource IDs collision with PARENT_TOP
    https://git.kernel.org/netdev/net-next/c/bfdf01f4d161
  - [net-next,v2,5/5] devlink: Warn on resource ID collision with PARENT_TOP
    https://git.kernel.org/netdev/net-next/c/f1e13d23e0c8

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html