AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/09/10 19:11 flow patch-triage
1m Args:
null

Results:
{
  "EnableConfigs": [
    "ETHTOOL_NETLINK",
    "PHYLIB",
    "PHYLINK"
  ],
  "FocusSymbols": [
    "ethnl_port_dumpit",
    "ethnl_port_dump_start",
    "ethnl_port_dump_done",
    "port_prepare_data",
    "port_fill_reply",
    "phy_link_topo_add_port",
    "phy_link_topo_del_port",
    "phy_caps_linkmode_filter_ifaces",
    "phy_set_upstream_port"
  ],
  "KMSANReasoning": "The patch series implements the ETHTOOL_MSG_PORT_GET netlink interface (do and dump operations) and associated PHY port topology handling in phylib and phylink.\n\nAnalysis of memory handling:\n1. Heap \u0026 Stack allocations:\n   - Port structures (`struct phy_port`) are allocated using `phy_port_alloc()` which zeros memory via `kzalloc_obj(*port)` and explicit `linkmode_zero()`.\n   - In ethtool netlink request/reply handling (`net/ethtool/port.c`), request structures are zero-allocated with `kzalloc_obj()` / `kzalloc()`, and reply buffers are explicitly cleared using `memset()` or `ethnl_init_reply_data()` before population.\n   - Stack variables in helper functions (e.g. `phy_caps_linkmode_filter_ifaces`) are zero-initialized (`= {}` and `= 0`).\n2. Userspace communication:\n   - Communication with user space is done exclusively using Netlink TLVs via standard Netlink attribute serialization functions (`nla_put_u32()`, `ethnl_put_bitset()`, `ethnl_fill_reply_header()`). No raw kernel structs with potential uninitialized padding or uninitialized fields are copied to userspace.\n3. Potential bugs:\n   - Any bugs introduced by this patch series (e.g., locking concurrency with RTNL/netdev locks, list/xarray management, reference counting of SFP bus/ports, or NULL dereferences) fall within the scope of KASAN, LOCKDEP, and standard kernel debugging facilities.\n   - There are no uninitialized memory reads or information leak risks that would require dedicated KMSAN fuzzing.\n\nTherefore, NeedsKMSAN is false.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch introduces the ETHTOOL_MSG_PORT_GET netlink command (both DO and DUMP operations) along with supporting PHY link topology port management and phylib SFP cage/module port handling. This new netlink interface can be reached directly from userspace via generic netlink sockets, making it a high-value target for fuzzing.",
  "WorthFuzzing": true
}

1/1 2026/09/10 19:11 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 02572d1cc948837eac36bce03b1f2254f2e77f39\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Thu Sep 10 19:11:12 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netlink/specs/ethtool.yaml\nindex 5dd4d1b5d94bb..35e028c0be296 100644\n--- a/Documentation/netlink/specs/ethtool.yaml\n+++ b/Documentation/netlink/specs/ethtool.yaml\n@@ -210,6 +210,11 @@ definitions:\n       -\n         name: discard\n         value: 31\n+  -\n+    name: port-type\n+    doc: type of physical connector\n+    type: enum\n+    entries: [mdi, sfp]\n \n attribute-sets:\n   -\n@@ -1905,6 +1910,32 @@ attribute-sets:\n         name: link\n         type: nest\n         nested-attributes: mse-snapshot\n+  -\n+    name: port\n+    attr-cnt-name: --ethtool-a-port-cnt\n+    attributes:\n+      -\n+        name: header\n+        type: nest\n+        nested-attributes: header\n+      -\n+        name: id\n+        type: u32\n+      -\n+        name: supported-modes\n+        type: nest\n+        nested-attributes: bitset\n+      -\n+        name: supported-interfaces\n+        type: nest\n+        nested-attributes: bitset\n+      -\n+        name: type\n+        type: u32\n+        enum: port-type\n+      -\n+        name: upstream-port\n+        type: u32\n \n operations:\n   enum-model: directional\n@@ -2859,6 +2890,30 @@ operations:\n             - worst-channel\n             - link\n       dump: *mse-get-op\n+    -\n+      name: port-get\n+      doc: Get ports attached to an interface\n+\n+      attribute-set: port\n+\n+      do:\n+        request:\n+          attributes:\n+            - header\n+            - id\n+        reply: \u0026port-get-op-reply\n+          attributes:\n+            - header\n+            - id\n+            - supported-modes\n+            - supported-interfaces\n+            - type\n+            - upstream-port\n+      dump:\n+        request:\n+          attributes:\n+            - header\n+        reply: *port-get-op-reply\n \n mcast-groups:\n   list:\ndiff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst\nindex e92abf45faf50..b4326c89b0751 100644\n--- a/Documentation/networking/ethtool-netlink.rst\n+++ b/Documentation/networking/ethtool-netlink.rst\n@@ -2537,6 +2537,39 @@ Within each channel nest, only the metrics supported by the PHY will be present.\n See ``struct phy_mse_snapshot`` kernel documentation in\n ``include/linux/phy.h``.\n \n+PORT_GET\n+========\n+\n+Retrieve information about the physical connection points of a network device,\n+referred to as \"ports\". User needs to specify a PORT_ID for the DO operation,\n+in which case the DO request returns information about that specific port.\n+\n+As there can be more than one port, the DUMP operation can be used to list the\n+ports present on a given interface, by passing an interface index or name in\n+the dump request.\n+\n+Request contents:\n+\n+  ===================================== ======  ===============================\n+  ``ETHTOOL_A_PORT_HEADER``             nested  request header\n+  ``ETHTOOL_A_PORT_ID``                 u32     port id\n+  ===================================== ======  ===============================\n+\n+Kernel response contents:\n+\n+  ======================================= ======  =============================\n+  ``ETHTOOL_A_PORT_HEADER``               nested  request header\n+  ``ETHTOOL_A_PORT_ID``                   u32     the port's unique identifier,\n+                                                  per netdevice.\n+  ``ETHTOOL_A_PORT_SUPPORTED_MODES``      bitset  bitset of supported linkmodes\n+  ``ETHTOOL_A_PORT_SUPPORTED_INTERFACES`` bitset  bitset of supported MII\n+                                                  interfaces\n+  ``ETHTOOL_A_PORT_TYPE``                 u32     the port type\n+  ``ETHTOOL_A_PORT_UPSTREAM_PORT``        u32     If any, the index of the MII\n+                                                  port that feeds into this\n+                                                  port.\n+  ======================================= ======  =============================\n+\n Request translation\n ===================\n \n@@ -2647,4 +2680,5 @@ are netlink only.\n   n/a                                 ``ETHTOOL_MSG_PHY_GET``\n   ``SIOCGHWTSTAMP``                   ``ETHTOOL_MSG_TSCONFIG_GET``\n   ``SIOCSHWTSTAMP``                   ``ETHTOOL_MSG_TSCONFIG_SET``\n+  n/a                                 ``ETHTOOL_MSG_PORT_GET``\n   =================================== =====================================\ndiff --git a/Documentation/networking/phy-port.rst b/Documentation/networking/phy-port.rst\nindex 6e28d9094bce3..2a9b1ec93b70f 100644\n--- a/Documentation/networking/phy-port.rst\n+++ b/Documentation/networking/phy-port.rst\n@@ -99,13 +99,29 @@ will eventually be able to report its own ksettings::\n             (_____)-----| Port |\n                         +------+\n \n+SFP ports\n+=========\n+\n+SFP interfaces involve 2 distinct components, each represented by\n+a :c:type:`struct phy_port \u003cphy_port\u003e` instance :\n+\n+ - The SFP cage itself is a :c:type:`struct phy_port \u003cphy_port\u003e`. It's special\n+   in that it's not an MDI interface, but rather a hot-pluggable MII.\n+   The :c:type:`struct phy_port \u003cphy_port\u003e` associated to it lists the different\n+   MII interfaces we can use on the cage.\n+\n+ - The SFP module, when inserted, will also be associated to a\n+   :c:type:`struct phy_port \u003cphy_port\u003e`, that represents the various linkmodes\n+   that it gives access to. The module's :c:type:`struct phy_port \u003cphy_port\u003e`\n+   doesn't supersede the cage's port, it references it through\n+   the :c:type:`struct phy_port \u003cphy_port\u003e` :c:member:`upstream_port` field.\n+\n Next steps\n ==========\n \n-As of writing this documentation, only ports controlled by PHY devices are\n-supported. The next steps will be to add the Netlink API to expose these\n-to userspace and add support for raw ports (controlled by some firmware, and directly\n-managed by the NIC driver).\n+As of writing this documentation, the port's presence and information can only\n+be queried, and it's not possible to change any of the port's settings or select\n+which one should be used.\n \n Another parallel task is the introduction of a MII muxing framework to allow the\n-control of non-PHY driver multi-port setups.\n+control of non-PHY driven multi-port setups.\ndiff --git a/MAINTAINERS b/MAINTAINERS\nindex 878ecf1fdf27c..973bbb7d2419b 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -18994,6 +18994,7 @@ F:\tDocumentation/devicetree/bindings/net/ethernet-connector.yaml\n F:\tDocumentation/networking/phy-port.rst\n F:\tdrivers/net/phy/phy_port.c\n F:\tinclude/linux/phy_port.h\n+F:\tnet/ethtool/port.c\n K:\tstruct\\s+phy_port|phy_port_\n \n NETWORKING [GENERAL]\ndiff --git a/drivers/net/phy/phy-caps.h b/drivers/net/phy/phy-caps.h\nindex 421088e6f6e8f..ec3d39a0ae06b 100644\n--- a/drivers/net/phy/phy-caps.h\n+++ b/drivers/net/phy/phy-caps.h\n@@ -66,5 +66,7 @@ void phy_caps_medium_get_supported(unsigned long *supported,\n \t\t\t\t   enum ethtool_link_medium medium,\n \t\t\t\t   int lanes);\n u32 phy_caps_mediums_from_linkmodes(unsigned long *linkmodes);\n+void phy_caps_linkmode_filter_ifaces(unsigned long *to, const unsigned long *from,\n+\t\t\t\t     const unsigned long *interfaces);\n \n #endif /* __PHY_CAPS_H */\ndiff --git a/drivers/net/phy/phy_caps.c b/drivers/net/phy/phy_caps.c\nindex 942d43191561e..558e4df4d63c0 100644\n--- a/drivers/net/phy/phy_caps.c\n+++ b/drivers/net/phy/phy_caps.c\n@@ -445,3 +445,29 @@ u32 phy_caps_mediums_from_linkmodes(unsigned long *linkmodes)\n \treturn mediums;\n }\n EXPORT_SYMBOL_GPL(phy_caps_mediums_from_linkmodes);\n+\n+/**\n+ * phy_caps_linkmode_filter_ifaces() - Filter linkmodes with an interface list\n+ * @to: Stores the filtered linkmodes\n+ * @from: Linkmodes to filter\n+ * @interfaces: Bitfield of phy_interface_t that we use for filtering\n+ *\n+ * Filter the provided linkmodes, only to keep the ones we can possibly achieve\n+ * when using any of the provided MII interfaces.\n+ */\n+void phy_caps_linkmode_filter_ifaces(unsigned long *to,\n+\t\t\t\t     const unsigned long *from,\n+\t\t\t\t     const unsigned long *interfaces)\n+{\n+\t__ETHTOOL_DECLARE_LINK_MODE_MASK(ifaces_supported) = {};\n+\tunsigned int ifaces_caps = 0;\n+\tphy_interface_t interface;\n+\n+\tfor_each_set_bit(interface, interfaces, PHY_INTERFACE_MODE_MAX)\n+\t\tifaces_caps |= phy_caps_from_interface(interface);\n+\n+\tphy_caps_linkmodes(ifaces_caps, ifaces_supported);\n+\n+\tlinkmode_and(to, from, ifaces_supported);\n+}\n+EXPORT_SYMBOL_GPL(phy_caps_linkmode_filter_ifaces);\ndiff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c\nindex 41d1b20cde2c0..561d19edf331c 100644\n--- a/drivers/net/phy/phy_device.c\n+++ b/drivers/net/phy/phy_device.c\n@@ -1490,11 +1490,22 @@ static int phy_sfp_connect_phy(void *upstream, struct phy_device *phy)\n {\n \tstruct phy_device *phydev = upstream;\n \tstruct net_device *dev = phydev-\u003eattached_dev;\n+\tint ret;\n \n-\tif (dev)\n-\t\treturn phy_link_topo_add_phy(dev, phy, PHY_UPSTREAM_PHY, phydev);\n+\tphydev-\u003ehas_sfp_mod_phy = true;\n+\tphy_set_upstream_port(phy, phydev-\u003esfp_cage_port);\n \n-\treturn 0;\n+\t/* If we aren't attached to a netdev, we can't add the SFP PHY to its\n+\t * topology.\n+\t */\n+\tif (!dev)\n+\t\treturn 0;\n+\n+\tret = phy_link_topo_add_phy(dev, phy, PHY_UPSTREAM_PHY, phydev);\n+\tif (ret)\n+\t\tphydev-\u003ehas_sfp_mod_phy = false;\n+\n+\treturn ret;\n }\n \n /**\n@@ -1512,8 +1523,12 @@ static void phy_sfp_disconnect_phy(void *upstream, struct phy_device *phy)\n \tstruct phy_device *phydev = upstream;\n \tstruct net_device *dev = phydev-\u003eattached_dev;\n \n+\tphydev-\u003ehas_sfp_mod_phy = false;\n+\n \tif (dev)\n \t\tphy_link_topo_del_phy(dev, phy);\n+\n+\tphy_set_upstream_port(phy, NULL);\n }\n \n /**\n@@ -1617,6 +1632,77 @@ static void phy_sfp_link_down(void *upstream)\n \t\tport-\u003eops-\u003elink_down(port);\n }\n \n+static int phy_add_sfp_mod_port(struct phy_device *phydev)\n+{\n+\tconst struct sfp_module_caps *caps;\n+\tstruct phy_port *port;\n+\tint ret = 0;\n+\n+\t/* Create mod port */\n+\tport = phy_port_alloc();\n+\tif (!port)\n+\t\treturn -ENOMEM;\n+\n+\tport-\u003eactive = true;\n+\n+\tcaps = sfp_get_module_caps(phydev-\u003esfp_bus);\n+\n+\tphy_caps_linkmode_filter_ifaces(port-\u003esupported, caps-\u003elink_modes,\n+\t\t\t\t\tphydev-\u003esfp_cage_port-\u003einterfaces);\n+\n+\tif (phydev-\u003eattached_dev) {\n+\t\tret = phy_link_topo_add_port(phydev-\u003eattached_dev, port);\n+\t\tif (ret) {\n+\t\t\tphy_port_destroy(port);\n+\t\t\treturn ret;\n+\t\t}\n+\t}\n+\n+\t/* we don't use phy_add_port() here as the module port isn't a direct\n+\t * interface from the PHY, but rather an extension to the sfp-bus, that\n+\t * is already represented by its own phy_port\n+\t */\n+\tphydev-\u003emod_port = port;\n+\n+\tport-\u003eupstream_port = phydev-\u003esfp_cage_port;\n+\n+\treturn 0;\n+}\n+\n+static void phy_del_sfp_mod_port(struct phy_device *phydev)\n+{\n+\tif (!phydev-\u003emod_port)\n+\t\treturn;\n+\n+\tif (phydev-\u003eattached_dev)\n+\t\tphy_link_topo_del_port(phydev-\u003eattached_dev, phydev-\u003emod_port);\n+\n+\tphy_port_destroy(phydev-\u003emod_port);\n+\tphydev-\u003emod_port = NULL;\n+}\n+\n+static int phy_sfp_module_start(void *upstream)\n+{\n+\tstruct phy_device *phydev = upstream;\n+\n+\t/* If there's a downstream SFP module, and it doesn't contain a PHY\n+\t * device, let's create a phy_port to represent that module.\n+\t */\n+\tif (!phydev-\u003ehas_sfp_mod_phy)\n+\t\treturn phy_add_sfp_mod_port(phydev);\n+\n+\treturn 0;\n+}\n+\n+static void phy_sfp_module_stop(void *upstream)\n+{\n+\tstruct phy_device *phydev = upstream;\n+\n+\t/* Called upon module removal or upstream removal */\n+\tif (!phydev-\u003ehas_sfp_mod_phy)\n+\t\tphy_del_sfp_mod_port(phydev);\n+}\n+\n static const struct sfp_upstream_ops sfp_phydev_ops = {\n \t.attach = phy_sfp_attach,\n \t.detach = phy_sfp_detach,\n@@ -1626,6 +1712,8 @@ static const struct sfp_upstream_ops sfp_phydev_ops = {\n \t.link_down = phy_sfp_link_down,\n \t.connect_phy = phy_sfp_connect_phy,\n \t.disconnect_phy = phy_sfp_disconnect_phy,\n+\t.module_start = phy_sfp_module_start,\n+\t.module_stop = phy_sfp_module_stop,\n };\n \n static int phy_add_port(struct phy_device *phydev, struct phy_port *port)\n@@ -1670,16 +1758,19 @@ static void phy_del_port(struct phy_device *phydev, struct phy_port *port)\n \n \tlist_del(\u0026port-\u003ehead);\n \n+\tif (phydev-\u003eattached_dev)\n+\t\tphy_link_topo_del_port(phydev-\u003eattached_dev, port);\n+\n \tphydev-\u003en_ports--;\n }\n \n-static int phy_setup_sfp_port(struct phy_device *phydev)\n+static struct phy_port *phy_setup_sfp_port(struct phy_device *phydev)\n {\n \tstruct phy_port *port = phy_port_alloc();\n \tint ret;\n \n \tif (!port)\n-\t\treturn -ENOMEM;\n+\t\treturn ERR_PTR(-ENOMEM);\n \n \tport-\u003eparent_type = PHY_PORT_PHY;\n \tport-\u003ephy = phydev;\n@@ -1694,10 +1785,12 @@ static int phy_setup_sfp_port(struct phy_device *phydev)\n \t * when attaching the port to the phydev.\n \t */\n \tret = phy_add_port(phydev, port);\n-\tif (ret)\n+\tif (ret) {\n \t\tphy_port_destroy(port);\n+\t\treturn ERR_PTR(ret);\n+\t}\n \n-\treturn ret;\n+\treturn port;\n }\n \n /**\n@@ -1706,30 +1799,50 @@ static int phy_setup_sfp_port(struct phy_device *phydev)\n  */\n static int phy_sfp_probe(struct phy_device *phydev)\n {\n+\tstruct phy_port *port = NULL;\n \tstruct sfp_bus *bus;\n-\tint ret = 0;\n+\tint ret;\n \n-\tif (phydev-\u003emdio.dev.fwnode) {\n-\t\tbus = sfp_bus_find_fwnode(phydev-\u003emdio.dev.fwnode);\n-\t\tif (IS_ERR(bus))\n-\t\t\treturn PTR_ERR(bus);\n+\tif (!phydev-\u003emdio.dev.fwnode)\n+\t\treturn 0;\n \n-\t\tphydev-\u003esfp_bus = bus;\n+\tbus = sfp_bus_find_fwnode(phydev-\u003emdio.dev.fwnode);\n+\tif (IS_ERR(bus))\n+\t\treturn PTR_ERR(bus);\n \n-\t\tret = sfp_bus_add_upstream(bus, phydev, \u0026sfp_phydev_ops);\n-\t\tsfp_bus_put(bus);\n+\tphydev-\u003esfp_bus = bus;\n \n-\t\tif (ret)\n-\t\t\tphydev-\u003esfp_bus = NULL;\n+\tif (bus) {\n+\t\tport = phy_setup_sfp_port(phydev);\n+\t\tif (IS_ERR(port)) {\n+\t\t\tret = PTR_ERR(port);\n+\t\t\tport = NULL;\n+\t\t\tgoto out_sfp;\n+\t\t}\n \t}\n \n-\tif (!ret \u0026\u0026 phydev-\u003esfp_bus) {\n-\t\tret = phy_setup_sfp_port(phydev);\n-\t\tif (ret) {\n-\t\t\tsfp_bus_del_upstream(phydev-\u003esfp_bus);\n-\t\t\tphydev-\u003esfp_bus = NULL;\n-\t\t}\n+\tphydev-\u003esfp_cage_port = port;\n+\n+\tret = sfp_bus_add_upstream(bus, phydev, \u0026sfp_phydev_ops);\n+\tif (ret)\n+\t\tgoto out_port;\n+\n+\t/* sfp_bus_add_upstream() grabs a ref to the sfp bus on success, it's\n+\t * safe to release it now.\n+\t */\n+\tsfp_bus_put(bus);\n+\n+\treturn ret;\n+\n+out_port:\n+\tif (port) {\n+\t\tphy_del_port(phydev, port);\n+\t\tphy_port_destroy(port);\n+\t\tphydev-\u003esfp_cage_port = NULL;\n \t}\n+out_sfp:\n+\tsfp_bus_put(bus);\n+\tphydev-\u003esfp_bus = NULL;\n \n \treturn ret;\n }\n@@ -1813,6 +1926,8 @@ static void phy_detach_internal(struct phy_device *phydev, bool notify_bus)\n \t\tphydev-\u003eattached_dev-\u003ephydev = NULL;\n \t\tphydev-\u003eattached_dev = NULL;\n \t\tphy_link_topo_del_phy(dev, phydev);\n+\t\tif (phydev-\u003emod_port)\n+\t\t\tphy_link_topo_del_port(dev, phydev-\u003emod_port);\n \t}\n \n \tphydev-\u003ephy_link_change = NULL;\n@@ -1942,6 +2057,12 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,\n \t\terr = phy_link_topo_add_phy(dev, phydev, PHY_UPSTREAM_MAC, dev);\n \t\tif (err)\n \t\t\tgoto error;\n+\n+\t\tif (phydev-\u003emod_port) {\n+\t\t\terr = phy_link_topo_add_port(dev, phydev-\u003emod_port);\n+\t\t\tif (err)\n+\t\t\t\tgoto error;\n+\t\t}\n \t}\n \n \t/* Some Ethernet drivers try to connect to a PHY device before\n@@ -3662,6 +3783,25 @@ struct phy_port *phy_get_sfp_port(struct phy_device *phydev)\n }\n EXPORT_SYMBOL_GPL(phy_get_sfp_port);\n \n+/**\n+ * phy_set_upstream_port() - Sets the phy_port controlling the MII this PHY is\n+ *\t\t\t     attached to.\n+ * @phydev: pointer to the PHY device we set the upstream of.\n+ * @port: The phy_port upstream of this PHY, can be NULL.\n+ */\n+void phy_set_upstream_port(struct phy_device *phydev, struct phy_port *port)\n+{\n+\tstruct phy_port *local_port;\n+\n+\tASSERT_RTNL();\n+\n+\tphydev-\u003eupstream_port = port;\n+\n+\tphy_for_each_port(phydev, local_port)\n+\t\tlocal_port-\u003eupstream_port = port;\n+}\n+EXPORT_SYMBOL_GPL(phy_set_upstream_port);\n+\n /**\n  * fwnode_mdio_find_device - Given a fwnode, find the mdio_device\n  * @fwnode: pointer to the mdio_device's fwnode\ndiff --git a/drivers/net/phy/phy_link_topology.c b/drivers/net/phy/phy_link_topology.c\nindex 4134de7ae313d..22885bf2e0455 100644\n--- a/drivers/net/phy/phy_link_topology.c\n+++ b/drivers/net/phy/phy_link_topology.c\n@@ -7,6 +7,7 @@\n  */\n \n #include \u003clinux/phy_link_topology.h\u003e\n+#include \u003clinux/phy_port.h\u003e\n #include \u003clinux/phy.h\u003e\n #include \u003clinux/rtnetlink.h\u003e\n #include \u003clinux/xarray.h\u003e\n@@ -23,17 +24,89 @@ static int netdev_alloc_phy_link_topology(struct net_device *dev)\n \txa_init_flags(\u0026topo-\u003ephys, XA_FLAGS_ALLOC1);\n \ttopo-\u003enext_phy_index = 1;\n \n+\txa_init_flags(\u0026topo-\u003eports, XA_FLAGS_ALLOC1);\n+\ttopo-\u003enext_port_index = 1;\n+\n \tdev-\u003elink_topo = topo;\n \n \treturn 0;\n }\n \n+static struct phy_link_topology *phy_link_topo_get_or_alloc(struct net_device *dev)\n+{\n+\tint ret;\n+\n+\tif (dev-\u003elink_topo)\n+\t\treturn dev-\u003elink_topo;\n+\n+\t/* The topology is allocated the first time we add an object to it.\n+\t * It is freed alongside the netdev. It can be called on multiple\n+\t * contexts:\n+\t *  - It can be called from .probe() : No rtnl, no netdev_lock\n+\t *  - .ndo_open() : rtnl and possibly netdev_lock\n+\t *  - SFP state machine : rtnl held or not\n+\t *\n+\t *  However, we can't really have races :\n+\t *  - If we have a PHY, phy_link_topo_add_phy() will always run first\n+\t *    and trigger the alloc. Only then the ports can be added through\n+\t *    phylib or sfp.\n+\t *  - If we don't, the SFP port for the cage is registered first, and\n+\t *    only then other ports/PHYs can be registered.\n+\t */\n+\tret = netdev_alloc_phy_link_topology(dev);\n+\tif (ret)\n+\t\treturn ERR_PTR(ret);\n+\n+\treturn dev-\u003elink_topo;\n+}\n+\n+int phy_link_topo_add_port(struct net_device *dev, struct phy_port *port)\n+{\n+\tstruct phy_link_topology *topo;\n+\tint ret;\n+\n+\t/* Ports can now be queried without rtnl for ops-locked devices, which\n+\t * we don't support now as port retrieval is done under rtnl.\n+\t * We don't have phy_port enabled devices yet, let's make sure\n+\t * we are loudly warned about that when it happens.\n+\t */\n+\tif (WARN_ON_ONCE(netdev_need_ops_lock(dev)))\n+\t\treturn -EOPNOTSUPP;\n+\n+\ttopo = phy_link_topo_get_or_alloc(dev);\n+\tif (IS_ERR(topo))\n+\t\treturn PTR_ERR(topo);\n+\n+\t/* Attempt to re-use a previously allocated port_id */\n+\tif (port-\u003eid)\n+\t\tret = xa_insert(\u0026topo-\u003eports, port-\u003eid, port, GFP_KERNEL);\n+\telse\n+\t\tret = xa_alloc_cyclic(\u0026topo-\u003eports, \u0026port-\u003eid, port,\n+\t\t\t\t      xa_limit_32b, \u0026topo-\u003enext_port_index,\n+\t\t\t\t      GFP_KERNEL);\n+\n+\treturn ret \u003c 0 ? ret : 0;\n+}\n+EXPORT_SYMBOL_GPL(phy_link_topo_add_port);\n+\n+void phy_link_topo_del_port(struct net_device *dev, struct phy_port *port)\n+{\n+\tstruct phy_link_topology *topo = dev-\u003elink_topo;\n+\n+\tif (!topo)\n+\t\treturn;\n+\n+\txa_erase(\u0026topo-\u003eports, port-\u003eid);\n+}\n+EXPORT_SYMBOL_GPL(phy_link_topo_del_port);\n+\n int phy_link_topo_add_phy(struct net_device *dev,\n \t\t\t  struct phy_device *phy,\n \t\t\t  enum phy_upstream upt, void *upstream)\n {\n-\tstruct phy_link_topology *topo = dev-\u003elink_topo;\n+\tstruct phy_link_topology *topo;\n \tstruct phy_device_node *pdn;\n+\tstruct phy_port *port;\n \tint ret;\n \n \t/* ethtool ops may run without rtnl_lock, and rtnl_lock is what\n@@ -45,13 +118,9 @@ int phy_link_topo_add_phy(struct net_device *dev,\n \tif (WARN_ON_ONCE(netdev_need_ops_lock(dev)))\n \t\treturn -EOPNOTSUPP;\n \n-\tif (!topo) {\n-\t\tret = netdev_alloc_phy_link_topology(dev);\n-\t\tif (ret)\n-\t\t\treturn ret;\n-\n-\t\ttopo = dev-\u003elink_topo;\n-\t}\n+\ttopo = phy_link_topo_get_or_alloc(dev);\n+\tif (IS_ERR(topo))\n+\t\treturn PTR_ERR(topo);\n \n \tpdn = kzalloc_obj(*pdn);\n \tif (!pdn)\n@@ -86,8 +155,20 @@ int phy_link_topo_add_phy(struct net_device *dev,\n \tif (ret \u003c 0)\n \t\tgoto err;\n \n+\t/* Add all the PHY's ports to the topology */\n+\tlist_for_each_entry(port, \u0026phy-\u003eports, head) {\n+\t\tret = phy_link_topo_add_port(dev, port);\n+\t\tif (ret)\n+\t\t\tgoto del_ports;\n+\t}\n+\n \treturn 0;\n \n+del_ports:\n+\tlist_for_each_entry_continue_reverse(port, \u0026phy-\u003eports, head)\n+\t\tphy_link_topo_del_port(dev, port);\n+\n+\txa_erase(\u0026topo-\u003ephys, phy-\u003ephyindex);\n err:\n \tkfree(pdn);\n \treturn ret;\n@@ -99,10 +180,14 @@ void phy_link_topo_del_phy(struct net_device *dev,\n {\n \tstruct phy_link_topology *topo = dev-\u003elink_topo;\n \tstruct phy_device_node *pdn;\n+\tstruct phy_port *port;\n \n \tif (!topo)\n \t\treturn;\n \n+\tlist_for_each_entry(port, \u0026phy-\u003eports, head)\n+\t\tphy_link_topo_del_port(dev, port);\n+\n \tpdn = xa_erase(\u0026topo-\u003ephys, phy-\u003ephyindex);\n \n \t/* We delete the PHY from the topology, however we don't re-set the\ndiff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c\nindex b9fc8599df749..d05cde44f401d 100644\n--- a/drivers/net/phy/phylink.c\n+++ b/drivers/net/phy/phylink.c\n@@ -14,6 +14,8 @@\n #include \u003clinux/of_mdio.h\u003e\n #include \u003clinux/phy.h\u003e\n #include \u003clinux/phy_fixed.h\u003e\n+#include \u003clinux/phy_link_topology.h\u003e\n+#include \u003clinux/phy_port.h\u003e\n #include \u003clinux/phylink.h\u003e\n #include \u003clinux/rtnetlink.h\u003e\n #include \u003clinux/spinlock.h\u003e\n@@ -93,6 +95,8 @@ struct phylink {\n \tDECLARE_PHY_INTERFACE_MASK(sfp_interfaces);\n \t__ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support);\n \tu8 sfp_port;\n+\tstruct phy_port *sfp_cage_port;\n+\tstruct phy_port *mod_port;\n \n \tstruct eee_config eee_cfg;\n \n@@ -1765,6 +1769,51 @@ static void phylink_fixed_poll(struct timer_list *t)\n \n static const struct sfp_upstream_ops sfp_phylink_ops;\n \n+static int phylink_create_sfp_cage_port(struct phylink *pl)\n+{\n+\tstruct phy_port *port;\n+\tint ret = 0;\n+\n+\tif (!pl-\u003enetdev || !pl-\u003esfp_bus)\n+\t\treturn 0;\n+\n+\tport = phy_port_alloc();\n+\tif (!port)\n+\t\treturn -ENOMEM;\n+\n+\tport-\u003eis_sfp = true;\n+\tport-\u003eis_mii = true;\n+\tport-\u003eactive = true;\n+\n+\tphy_interface_and(port-\u003einterfaces, pl-\u003econfig-\u003esupported_interfaces,\n+\t\t\t  phylink_sfp_interfaces);\n+\tphy_port_update_supported(port);\n+\n+\tret = phy_link_topo_add_port(pl-\u003enetdev, port);\n+\tif (ret)\n+\t\tgoto out_destroy_port;\n+\n+\tpl-\u003esfp_cage_port = port;\n+\n+\treturn 0;\n+\n+out_destroy_port:\n+\tphy_port_destroy(port);\n+\tpl-\u003esfp_cage_port = NULL;\n+\treturn ret;\n+}\n+\n+static void phylink_destroy_sfp_cage_port(struct phylink *pl)\n+{\n+\tif (pl-\u003enetdev \u0026\u0026 pl-\u003esfp_cage_port)\n+\t\tphy_link_topo_del_port(pl-\u003enetdev, pl-\u003esfp_cage_port);\n+\n+\tif (pl-\u003esfp_cage_port)\n+\t\tphy_port_destroy(pl-\u003esfp_cage_port);\n+\n+\tpl-\u003esfp_cage_port = NULL;\n+}\n+\n static int phylink_register_sfp(struct phylink *pl,\n \t\t\t\tconst struct fwnode_handle *fwnode)\n {\n@@ -1782,9 +1831,18 @@ static int phylink_register_sfp(struct phylink *pl,\n \n \tpl-\u003esfp_bus = bus;\n \n+\tret = phylink_create_sfp_cage_port(pl);\n+\tif (ret) {\n+\t\tsfp_bus_put(bus);\n+\t\treturn ret;\n+\t}\n+\n \tret = sfp_bus_add_upstream(bus, pl, \u0026sfp_phylink_ops);\n \tsfp_bus_put(bus);\n \n+\tif (ret)\n+\t\tphylink_destroy_sfp_cage_port(pl);\n+\n \treturn ret;\n }\n \n@@ -2067,6 +2125,7 @@ EXPORT_SYMBOL_GPL(phylink_create);\n void phylink_destroy(struct phylink *pl)\n {\n \tsfp_bus_del_upstream(pl-\u003esfp_bus);\n+\tphylink_destroy_sfp_cage_port(pl);\n \tif (pl-\u003elink_gpio)\n \t\tgpiod_put(pl-\u003elink_gpio);\n \n@@ -3939,14 +3998,67 @@ static void phylink_sfp_module_remove(void *upstream)\n \tphy_interface_zero(pl-\u003esfp_interfaces);\n }\n \n+static int phylink_add_sfp_mod_port(struct phylink *pl)\n+{\n+\tconst struct sfp_module_caps *caps;\n+\tstruct phy_port *port;\n+\tint ret = 0;\n+\n+\tif (!pl-\u003esfp_cage_port)\n+\t\treturn 0;\n+\n+\t/* Create mod port */\n+\tport = phy_port_alloc();\n+\tif (!port)\n+\t\treturn -ENOMEM;\n+\n+\tport-\u003eactive = true;\n+\n+\tcaps = sfp_get_module_caps(pl-\u003esfp_bus);\n+\n+\tphy_caps_linkmode_filter_ifaces(port-\u003esupported, caps-\u003elink_modes,\n+\t\t\t\t\tpl-\u003esfp_cage_port-\u003einterfaces);\n+\n+\tif (pl-\u003enetdev) {\n+\t\tret = phy_link_topo_add_port(pl-\u003enetdev, port);\n+\t\tif (ret) {\n+\t\t\tphy_port_destroy(port);\n+\t\t\treturn ret;\n+\t\t}\n+\t}\n+\n+\tport-\u003eupstream_port = pl-\u003esfp_cage_port;\n+\n+\tpl-\u003emod_port = port;\n+\n+\treturn 0;\n+}\n+\n+static void phylink_del_sfp_mod_port(struct phylink *pl)\n+{\n+\tif (!pl-\u003emod_port)\n+\t\treturn;\n+\n+\tif (pl-\u003enetdev)\n+\t\tphy_link_topo_del_port(pl-\u003enetdev, pl-\u003emod_port);\n+\n+\tphy_port_destroy(pl-\u003emod_port);\n+\tpl-\u003emod_port = NULL;\n+}\n+\n static int phylink_sfp_module_start(void *upstream)\n {\n \tstruct phylink *pl = upstream;\n+\tint ret;\n \n \t/* If this SFP module has a PHY, start the PHY now. */\n \tif (pl-\u003ephydev) {\n \t\tphy_start(pl-\u003ephydev);\n \t\treturn 0;\n+\t} else {\n+\t\tret = phylink_add_sfp_mod_port(pl);\n+\t\tif (ret)\n+\t\t\treturn ret;\n \t}\n \n \t/* If the module may have a PHY but we didn't detect one we\n@@ -3955,7 +4067,16 @@ static int phylink_sfp_module_start(void *upstream)\n \tif (!pl-\u003esfp_may_have_phy)\n \t\treturn 0;\n \n-\treturn phylink_sfp_config_optical(pl);\n+\tret = phylink_sfp_config_optical(pl);\n+\tif (ret)\n+\t\tgoto del_mod_port;\n+\n+\treturn 0;\n+\n+del_mod_port:\n+\tphylink_del_sfp_mod_port(pl);\n+\n+\treturn ret;\n }\n \n static void phylink_sfp_module_stop(void *upstream)\n@@ -3965,6 +4086,8 @@ static void phylink_sfp_module_stop(void *upstream)\n \t/* If this SFP module has a PHY, stop it. */\n \tif (pl-\u003ephydev)\n \t\tphy_stop(pl-\u003ephydev);\n+\telse\n+\t\tphylink_del_sfp_mod_port(pl);\n }\n \n static void phylink_sfp_link_down(void *upstream)\n@@ -4009,6 +4132,8 @@ static int phylink_sfp_connect_phy(void *upstream, struct phy_device *phy)\n \tphy_interface_and(phy-\u003ehost_interfaces, phylink_sfp_interfaces,\n \t\t\t  pl-\u003econfig-\u003esupported_interfaces);\n \n+\tphy_set_upstream_port(phy, pl-\u003esfp_cage_port);\n+\n \t/* Do the initial configuration */\n \treturn phylink_sfp_config_phy(pl, phy);\n }\n@@ -4017,6 +4142,7 @@ static void phylink_sfp_disconnect_phy(void *upstream,\n \t\t\t\t       struct phy_device *phydev)\n {\n \tphylink_disconnect_phy(upstream);\n+\tphy_set_upstream_port(phydev, NULL);\n }\n \n static const struct sfp_upstream_ops sfp_phylink_ops = {\ndiff --git a/include/linux/phy.h b/include/linux/phy.h\nindex 3d8afe6b7f1c5..335821eb22171 100644\n--- a/include/linux/phy.h\n+++ b/include/linux/phy.h\n@@ -600,6 +600,7 @@ struct phy_oatc14_sqi_capability {\n  * @wol_enabled: Set to true if the PHY or the attached MAC have Wake-on-LAN\n  * \t\t enabled.\n  * @is_genphy_driven: PHY is driven by one of the generic PHY drivers\n+ * @has_sfp_mod_phy: Set true if downstream SFP bus's module contains a PHY\n  * @state: State of the PHY for management purposes\n  * @dev_flags: Device-specific flags used by the PHY driver.\n  *\n@@ -612,6 +613,9 @@ struct phy_oatc14_sqi_capability {\n  * @phylink: Pointer to phylink instance for this PHY\n  * @sfp_bus_attached: Flag indicating whether the SFP bus has been attached\n  * @sfp_bus: SFP bus attached to this PHY's fiber port\n+ * @sfp_cage_port: The phy_port connected to the downstream SFP cage\n+ * @mod_port: phy_port representing the SFP module, if it is phy-less\n+ * @upstream_port: phy_port this PHY's MII attaches to, if any\n  * @attached_dev: The attached enet driver's device instance ptr\n  * @adjust_link: Callback for the enet controller to respond to changes: in the\n  *               link state.\n@@ -724,6 +728,7 @@ struct phy_device {\n \tunsigned irq_rerun:1;\n \n \tunsigned default_timestamp:1;\n+\tunsigned has_sfp_mod_phy:1;\n \n \tint rate_matching;\n \n@@ -803,6 +808,9 @@ struct phy_device {\n \t/* This may be modified under the rtnl lock */\n \tbool sfp_bus_attached;\n \tstruct sfp_bus *sfp_bus;\n+\tstruct phy_port *sfp_cage_port;\n+\tstruct phy_port *mod_port;\n+\tstruct phy_port *upstream_port;\n \tstruct phylink *phylink;\n \tstruct net_device *attached_dev;\n \tstruct mii_timestamper *mii_ts;\n@@ -2487,6 +2495,8 @@ int __phy_hwtstamp_set(struct phy_device *phydev,\n \n struct phy_port *phy_get_sfp_port(struct phy_device *phydev);\n \n+void phy_set_upstream_port(struct phy_device *phydev, struct phy_port *port);\n+\n /**\n  * phy_module_driver() - Helper macro for registering PHY drivers\n  * @__phy_drivers: array of PHY drivers to register\ndiff --git a/include/linux/phy_link_topology.h b/include/linux/phy_link_topology.h\nindex 95575f68d5bc7..9585282cae3fc 100644\n--- a/include/linux/phy_link_topology.h\n+++ b/include/linux/phy_link_topology.h\n@@ -13,14 +13,19 @@\n \n #include \u003clinux/ethtool.h\u003e\n #include \u003clinux/netdevice.h\u003e\n+#include \u003clinux/rtnetlink.h\u003e\n \n struct xarray;\n struct phy_device;\n+struct phy_port;\n struct sfp_bus;\n \n struct phy_link_topology {\n \tstruct xarray phys;\n \tu32 next_phy_index;\n+\n+\tstruct xarray ports;\n+\tu32 next_port_index;\n };\n \n struct phy_device_node {\n@@ -48,6 +53,9 @@ int phy_link_topo_add_phy(struct net_device *dev,\n \n void phy_link_topo_del_phy(struct net_device *dev, struct phy_device *phy);\n \n+int phy_link_topo_add_port(struct net_device *dev, struct phy_port *port);\n+void phy_link_topo_del_port(struct net_device *dev, struct phy_port *port);\n+\n static inline struct phy_device *\n phy_link_topo_get_phy(struct net_device *dev, u32 phyindex)\n {\n@@ -64,6 +72,25 @@ phy_link_topo_get_phy(struct net_device *dev, u32 phyindex)\n \treturn NULL;\n }\n \n+static inline struct phy_port *\n+phy_link_topo_get_port(struct net_device *dev, u32 port_id)\n+{\n+\tstruct phy_link_topology *topo = dev-\u003elink_topo;\n+\n+\tif (!topo)\n+\t\treturn NULL;\n+\n+\t/* ports in the topo are RTNL protected, but may be accessed under\n+\t * netdev_lock for ops-locked devices. For now keep them under rtnl\n+\t * protection, as no ops-locked devices have phy_port capabilities\n+\t * yet.\n+\t */\n+\tASSERT_RTNL();\n+\n+\t/* Caller must hold RTNL while handling the phy_port */\n+\treturn xa_load(\u0026topo-\u003eports, port_id);\n+}\n+\n #else\n static inline int phy_link_topo_add_phy(struct net_device *dev,\n \t\t\t\t\tstruct phy_device *phy,\n@@ -77,11 +104,28 @@ static inline void phy_link_topo_del_phy(struct net_device *dev,\n {\n }\n \n+static inline int phy_link_topo_add_port(struct net_device *dev,\n+\t\t\t\t\t struct phy_port *port)\n+{\n+\treturn 0;\n+}\n+\n+static inline void phy_link_topo_del_port(struct net_device *dev,\n+\t\t\t\t\t  struct phy_port *port)\n+{\n+}\n+\n static inline struct phy_device *\n phy_link_topo_get_phy(struct net_device *dev, u32 phyindex)\n {\n \treturn NULL;\n }\n+\n+static inline struct phy_port *\n+phy_link_topo_get_port(struct net_device *dev, u32 port_id)\n+{\n+\treturn NULL;\n+}\n #endif\n \n #endif /* __PHY_LINK_TOPOLOGY_H */\ndiff --git a/include/linux/phy_port.h b/include/linux/phy_port.h\nindex 0ef0f5ce47092..8f45c031cbc10 100644\n--- a/include/linux/phy_port.h\n+++ b/include/linux/phy_port.h\n@@ -36,9 +36,12 @@ struct phy_port_ops {\n /**\n  * struct phy_port - A representation of a network device physical interface\n  *\n+ * @id: Unique identifier for the port within the topology\n  * @head: Used by the port's parent to list ports\n  * @parent_type: The type of device this port is directly connected to\n  * @phy: If the parent is PHY_PORT_PHYDEV, the PHY controlling that port\n+ * @upstream_port: Indicates the MII port that feeds this port, if any,\n+ *\t\t   e.g. the SFP cage port for a SFP module port.\n  * @ops: Callback ops implemented by the port controller\n  * @pairs: The number of  pairs this port has, 0 if not applicable\n  * @mediums: Bitmask of the physical mediums this port provides access to\n@@ -52,11 +55,13 @@ struct phy_port_ops {\n  * @is_sfp: Indicates if this port drives an SFP cage.\n  */\n struct phy_port {\n+\tu32 id;\n \tstruct list_head head;\n \tenum phy_port_parent parent_type;\n \tunion {\n \t\tstruct phy_device *phy;\n \t};\n+\tstruct phy_port *upstream_port;\n \n \tconst struct phy_port_ops *ops;\n \ndiff --git a/include/uapi/linux/ethtool_netlink_generated.h b/include/uapi/linux/ethtool_netlink_generated.h\nindex 8134baf7860f3..660e0c08a766a 100644\n--- a/include/uapi/linux/ethtool_netlink_generated.h\n+++ b/include/uapi/linux/ethtool_netlink_generated.h\n@@ -78,6 +78,14 @@ enum ethtool_pse_event {\n \tETHTOOL_PSE_EVENT_SW_PW_CONTROL_ERROR = 64,\n };\n \n+/*\n+ * type of physical connector\n+ */\n+enum ethtool_port_type {\n+\tETHTOOL_PORT_TYPE_MDI,\n+\tETHTOOL_PORT_TYPE_SFP,\n+};\n+\n enum {\n \tETHTOOL_A_HEADER_UNSPEC,\n \tETHTOOL_A_HEADER_DEV_INDEX,\n@@ -840,6 +848,18 @@ enum {\n \tETHTOOL_A_MSE_MAX = (__ETHTOOL_A_MSE_CNT - 1)\n };\n \n+enum {\n+\tETHTOOL_A_PORT_HEADER = 1,\n+\tETHTOOL_A_PORT_ID,\n+\tETHTOOL_A_PORT_SUPPORTED_MODES,\n+\tETHTOOL_A_PORT_SUPPORTED_INTERFACES,\n+\tETHTOOL_A_PORT_TYPE,\n+\tETHTOOL_A_PORT_UPSTREAM_PORT,\n+\n+\t__ETHTOOL_A_PORT_CNT,\n+\tETHTOOL_A_PORT_MAX = (__ETHTOOL_A_PORT_CNT - 1)\n+};\n+\n enum {\n \tETHTOOL_MSG_USER_NONE = 0,\n \tETHTOOL_MSG_STRSET_GET = 1,\n@@ -893,6 +913,7 @@ enum {\n \tETHTOOL_MSG_RSS_CREATE_ACT,\n \tETHTOOL_MSG_RSS_DELETE_ACT,\n \tETHTOOL_MSG_MSE_GET,\n+\tETHTOOL_MSG_PORT_GET,\n \n \t__ETHTOOL_MSG_USER_CNT,\n \tETHTOOL_MSG_USER_MAX = (__ETHTOOL_MSG_USER_CNT - 1)\n@@ -954,6 +975,7 @@ enum {\n \tETHTOOL_MSG_RSS_CREATE_NTF,\n \tETHTOOL_MSG_RSS_DELETE_NTF,\n \tETHTOOL_MSG_MSE_GET_REPLY,\n+\tETHTOOL_MSG_PORT_GET_REPLY,\n \n \t__ETHTOOL_MSG_KERNEL_CNT,\n \tETHTOOL_MSG_KERNEL_MAX = (__ETHTOOL_MSG_KERNEL_CNT - 1)\ndiff --git a/net/core/dev.c b/net/core/dev.c\nindex 290e0f099e6bf..8c061df5b6a8f 100644\n--- a/net/core/dev.c\n+++ b/net/core/dev.c\n@@ -11367,6 +11367,7 @@ static void netdev_free_phy_link_topology(struct net_device *dev)\n \n \tif (IS_ENABLED(CONFIG_PHYLIB) \u0026\u0026 topo) {\n \t\txa_destroy(\u0026topo-\u003ephys);\n+\t\txa_destroy(\u0026topo-\u003eports);\n \t\tkfree(topo);\n \t\tdev-\u003elink_topo = NULL;\n \t}\ndiff --git a/net/ethtool/Makefile b/net/ethtool/Makefile\nindex 629c10916670e..9b5b096700081 100644\n--- a/net/ethtool/Makefile\n+++ b/net/ethtool/Makefile\n@@ -9,4 +9,4 @@ ethtool_nl-y\t:= netlink.o bitset.o strset.o linkinfo.o linkmodes.o rss.o \\\n \t\t   channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o \\\n \t\t   tunnels.o fec.o eeprom.o stats.o phc_vclocks.o mm.o \\\n \t\t   module.o cmis_fw_update.o cmis_cdb.o pse-pd.o plca.o \\\n-\t\t   phy.o tsconfig.o mse.o\n+\t\t   phy.o tsconfig.o mse.o port.o\ndiff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c\nindex 1af395b54330e..c076c07d0a080 100644\n--- a/net/ethtool/netlink.c\n+++ b/net/ethtool/netlink.c\n@@ -26,6 +26,8 @@ static u32 ethnl_bcast_seq;\n \t\t\t     ETHTOOL_FLAG_OMIT_REPLY)\n #define ETHTOOL_FLAGS_STATS (ETHTOOL_FLAGS_BASIC | ETHTOOL_FLAG_STATS)\n \n+char phy_interface_names[PHY_INTERFACE_MODE_MAX][ETH_GSTRING_LEN] __ro_after_init;\n+\n const struct nla_policy ethnl_header_policy[] = {\n \t[ETHTOOL_A_HEADER_DEV_INDEX]\t= { .type = NLA_U32 },\n \t[ETHTOOL_A_HEADER_DEV_NAME]\t= { .type = NLA_NUL_STRING,\n@@ -431,6 +433,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = {\n \t[ETHTOOL_MSG_TSCONFIG_SET]\t= \u0026ethnl_tsconfig_request_ops,\n \t[ETHTOOL_MSG_PHY_GET]\t\t= \u0026ethnl_phy_request_ops,\n \t[ETHTOOL_MSG_MSE_GET]\t\t= \u0026ethnl_mse_request_ops,\n+\t[ETHTOOL_MSG_PORT_GET]\t\t= \u0026ethnl_port_request_ops,\n };\n \n static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb)\n@@ -1572,6 +1575,15 @@ static const struct genl_ops ethtool_genl_ops[] = {\n \t\t.policy = ethnl_mse_get_policy,\n \t\t.maxattr = ARRAY_SIZE(ethnl_mse_get_policy) - 1,\n \t},\n+\t{\n+\t\t.cmd\t= ETHTOOL_MSG_PORT_GET,\n+\t\t.doit\t= ethnl_default_doit,\n+\t\t.start\t= ethnl_port_dump_start,\n+\t\t.dumpit\t= ethnl_port_dumpit,\n+\t\t.done\t= ethnl_port_dump_done,\n+\t\t.policy = ethnl_port_get_policy,\n+\t\t.maxattr = ARRAY_SIZE(ethnl_port_get_policy) - 1,\n+\t},\n };\n \n static const struct genl_multicast_group ethtool_nl_mcgrps[] = {\n@@ -1594,10 +1606,23 @@ static struct genl_family ethtool_genl_family __ro_after_init = {\n \n /* module setup */\n \n+static void __init ethnl_phy_names_populate(void)\n+{\n+\tconst char *name;\n+\tint i;\n+\n+\tfor (i = 0; i \u003c PHY_INTERFACE_MODE_MAX; i++) {\n+\t\tname = phy_modes(i);\n+\t\tstrscpy(phy_interface_names[i], name, ETH_GSTRING_LEN);\n+\t}\n+}\n+\n static int __init ethnl_init(void)\n {\n \tint ret;\n \n+\tethnl_phy_names_populate();\n+\n \tret = genl_register_family(\u0026ethtool_genl_family);\n \tif (WARN(ret \u003c 0, \"ethtool: genetlink family registration failed\"))\n \t\treturn ret;\ndiff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h\nindex 3e969a070f9fe..dc7211f67c4d5 100644\n--- a/net/ethtool/netlink.h\n+++ b/net/ethtool/netlink.h\n@@ -5,11 +5,14 @@\n \n #include \u003clinux/ethtool_netlink.h\u003e\n #include \u003clinux/netdevice.h\u003e\n+#include \u003clinux/phy.h\u003e\n #include \u003cnet/genetlink.h\u003e\n #include \u003cnet/sock.h\u003e\n \n struct ethnl_req_info;\n \n+extern char phy_interface_names[PHY_INTERFACE_MODE_MAX][ETH_GSTRING_LEN];\n+\n int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info,\n \t\t\t       const struct nlattr *nest, struct net *net,\n \t\t\t       struct netlink_ext_ack *extack,\n@@ -474,6 +477,7 @@ extern const struct ethnl_request_ops ethnl_mm_request_ops;\n extern const struct ethnl_request_ops ethnl_phy_request_ops;\n extern const struct ethnl_request_ops ethnl_tsconfig_request_ops;\n extern const struct ethnl_request_ops ethnl_mse_request_ops;\n+extern const struct ethnl_request_ops ethnl_port_request_ops;\n \n extern const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_FLAGS + 1];\n extern const struct nla_policy ethnl_header_policy_stats[ETHTOOL_A_HEADER_FLAGS + 1];\n@@ -530,6 +534,7 @@ extern const struct nla_policy ethnl_phy_get_policy[ETHTOOL_A_PHY_HEADER + 1];\n extern const struct nla_policy ethnl_tsconfig_get_policy[ETHTOOL_A_TSCONFIG_HEADER + 1];\n extern const struct nla_policy ethnl_tsconfig_set_policy[ETHTOOL_A_TSCONFIG_MAX + 1];\n extern const struct nla_policy ethnl_mse_get_policy[ETHTOOL_A_MSE_HEADER + 1];\n+extern const struct nla_policy ethnl_port_get_policy[ETHTOOL_A_PORT_ID + 1];\n \n int ethnl_set_features(struct sk_buff *skb, struct genl_info *info);\n int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info);\n@@ -545,6 +550,9 @@ int ethnl_tsinfo_dumpit(struct sk_buff *skb, struct netlink_callback *cb);\n int ethnl_tsinfo_done(struct netlink_callback *cb);\n int ethnl_rss_create_doit(struct sk_buff *skb, struct genl_info *info);\n int ethnl_rss_delete_doit(struct sk_buff *skb, struct genl_info *info);\n+int ethnl_port_dump_start(struct netlink_callback *cb);\n+int ethnl_port_dumpit(struct sk_buff *skb, struct netlink_callback *cb);\n+int ethnl_port_dump_done(struct netlink_callback *cb);\n \n extern const char stats_std_names[__ETHTOOL_STATS_CNT][ETH_GSTRING_LEN];\n extern const char stats_eth_phy_names[__ETHTOOL_A_STATS_ETH_PHY_CNT][ETH_GSTRING_LEN];\ndiff --git a/net/ethtool/port.c b/net/ethtool/port.c\nnew file mode 100644\nindex 0000000000000..0d6150e5f66a2\n--- /dev/null\n+++ b/net/ethtool/port.c\n@@ -0,0 +1,382 @@\n+// SPDX-License-Identifier: GPL-2.0-only\n+/*\n+ * Copyright 2026 Bootlin\n+ */\n+#include \u003clinux/phy.h\u003e\n+#include \u003clinux/phy_link_topology.h\u003e\n+#include \u003clinux/phy_port.h\u003e\n+#include \u003cnet/netdev_lock.h\u003e\n+\n+#include \"bitset.h\"\n+#include \"common.h\"\n+#include \"netlink.h\"\n+\n+struct port_req_info {\n+\tstruct ethnl_req_info base;\n+\tu32 port_id;\n+};\n+\n+struct port_reply_data {\n+\tstruct ethnl_reply_data\tbase;\n+\t__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);\n+\tDECLARE_PHY_INTERFACE_MASK(interfaces);\n+\tu32 port_id;\n+\tbool mii;\n+\tbool sfp;\n+\tu32 upstream_port;\n+};\n+\n+#define PORT_REQINFO(__req_base) \\\n+\tcontainer_of(__req_base, struct port_req_info, base)\n+\n+#define PORT_REPDATA(__reply_base) \\\n+\tcontainer_of(__reply_base, struct port_reply_data, base)\n+\n+const struct nla_policy ethnl_port_get_policy[ETHTOOL_A_PORT_ID + 1] = {\n+\t[ETHTOOL_A_PORT_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy),\n+\t[ETHTOOL_A_PORT_ID] = NLA_POLICY_MIN(NLA_U32, 1),\n+};\n+\n+static int port_parse_request(struct ethnl_req_info *req_info,\n+\t\t\t      const struct genl_info *info,\n+\t\t\t      struct nlattr **tb,\n+\t\t\t      struct netlink_ext_ack *extack)\n+{\n+\tstruct port_req_info *request = PORT_REQINFO(req_info);\n+\n+\tif (GENL_REQ_ATTR_CHECK(info, ETHTOOL_A_PORT_ID))\n+\t\treturn -EINVAL;\n+\n+\trequest-\u003eport_id = nla_get_u32(tb[ETHTOOL_A_PORT_ID]);\n+\n+\treturn 0;\n+}\n+\n+static int port_prepare_data(const struct ethnl_req_info *req_info,\n+\t\t\t     struct ethnl_reply_data *reply_data,\n+\t\t\t     const struct genl_info *info)\n+{\n+\tstruct port_reply_data *reply = PORT_REPDATA(reply_data);\n+\tstruct port_req_info *request = PORT_REQINFO(req_info);\n+\tstruct phy_port *port;\n+\n+\t/* RTNL must be held while holding a ref to the phy_port. Here, caller\n+\t * holds RTNL.\n+\t */\n+\tport = phy_link_topo_get_port(req_info-\u003edev, request-\u003eport_id);\n+\tif (!port)\n+\t\treturn -ENODEV;\n+\n+\tlinkmode_copy(reply-\u003esupported, port-\u003esupported);\n+\tphy_interface_copy(reply-\u003einterfaces, port-\u003einterfaces);\n+\treply-\u003eport_id = port-\u003eid;\n+\treply-\u003emii = port-\u003eis_mii;\n+\treply-\u003esfp = port-\u003eis_sfp;\n+\treply-\u003eupstream_port = port-\u003eupstream_port ? port-\u003eupstream_port-\u003eid : 0;\n+\n+\treturn 0;\n+}\n+\n+static int port_reply_size(const struct ethnl_req_info *req_info,\n+\t\t\t   const struct ethnl_reply_data *reply_data)\n+{\n+\tbool compact = req_info-\u003eflags \u0026 ETHTOOL_FLAG_COMPACT_BITSETS;\n+\tstruct port_reply_data *reply = PORT_REPDATA(reply_data);\n+\tsize_t size = 0;\n+\tint ret;\n+\n+\t/* ETHTOOL_A_PORT_ID */\n+\tsize += nla_total_size(sizeof(u32));\n+\n+\tif (!reply-\u003emii) {\n+\t\t/* ETHTOOL_A_PORT_SUPPORTED_MODES */\n+\t\tret = ethnl_bitset_size(reply-\u003esupported, NULL,\n+\t\t\t\t\t__ETHTOOL_LINK_MODE_MASK_NBITS,\n+\t\t\t\t\tlink_mode_names, compact);\n+\t\tif (ret \u003c 0)\n+\t\t\treturn ret;\n+\n+\t\tsize += ret;\n+\t} else {\n+\t\t/* ETHTOOL_A_PORT_SUPPORTED_INTERFACES */\n+\t\tret = ethnl_bitset_size(reply-\u003einterfaces, NULL,\n+\t\t\t\t\tPHY_INTERFACE_MODE_MAX,\n+\t\t\t\t\tphy_interface_names, compact);\n+\t\tif (ret \u003c 0)\n+\t\t\treturn ret;\n+\n+\t\tsize += ret;\n+\t}\n+\n+\t/* ETHTOOL_A_PORT_TYPE */\n+\tsize += nla_total_size(sizeof(u32));\n+\n+\t/* ETHTOOL_A_PORT_UPSTREAM_PORT */\n+\tif (reply-\u003eupstream_port)\n+\t\tsize += nla_total_size(sizeof(u32));\n+\n+\treturn size;\n+}\n+\n+static int port_fill_reply(struct sk_buff *skb,\n+\t\t\t   const struct ethnl_req_info *req_info,\n+\t\t\t   const struct ethnl_reply_data *reply_data)\n+{\n+\tbool compact = req_info-\u003eflags \u0026 ETHTOOL_FLAG_COMPACT_BITSETS;\n+\tstruct port_reply_data *reply = PORT_REPDATA(reply_data);\n+\tint ret, port_type = ETHTOOL_PORT_TYPE_MDI;\n+\n+\tif (nla_put_u32(skb, ETHTOOL_A_PORT_ID, reply-\u003eport_id))\n+\t\treturn -EMSGSIZE;\n+\n+\tif (!reply-\u003emii) {\n+\t\tret = ethnl_put_bitset(skb, ETHTOOL_A_PORT_SUPPORTED_MODES,\n+\t\t\t\t       reply-\u003esupported, NULL,\n+\t\t\t\t       __ETHTOOL_LINK_MODE_MASK_NBITS,\n+\t\t\t\t       link_mode_names, compact);\n+\t\tif (ret \u003c 0)\n+\t\t\treturn ret;\n+\t} else {\n+\t\tret = ethnl_put_bitset(skb, ETHTOOL_A_PORT_SUPPORTED_INTERFACES,\n+\t\t\t\t       reply-\u003einterfaces, NULL,\n+\t\t\t\t       PHY_INTERFACE_MODE_MAX,\n+\t\t\t\t       phy_interface_names, compact);\n+\t\tif (ret \u003c 0)\n+\t\t\treturn ret;\n+\t}\n+\n+\tif (reply-\u003emii || reply-\u003esfp)\n+\t\tport_type = ETHTOOL_PORT_TYPE_SFP;\n+\n+\tif (nla_put_u32(skb, ETHTOOL_A_PORT_TYPE, port_type))\n+\t\treturn -EMSGSIZE;\n+\n+\tif (reply-\u003eupstream_port \u0026\u0026\n+\t    nla_put_u32(skb, ETHTOOL_A_PORT_UPSTREAM_PORT,\n+\t\t\treply-\u003eupstream_port))\n+\t\treturn -EMSGSIZE;\n+\n+\treturn 0;\n+}\n+\n+struct port_dump_ctx {\n+\tstruct port_req_info\t*req_info;\n+\tstruct port_reply_data\t*reply_data;\n+\tunsigned long\t\tifindex;\n+\tunsigned long\t\tpos_ifindex;\n+\tunsigned long\t\tpos_portid;\n+};\n+\n+static struct port_dump_ctx *\n+port_dump_ctx_get(struct netlink_callback *cb)\n+{\n+\treturn (struct port_dump_ctx *)cb-\u003ectx;\n+}\n+\n+int ethnl_port_dump_start(struct netlink_callback *cb)\n+{\n+\tconst struct genl_dumpit_info *info = genl_dumpit_info(cb);\n+\tstruct port_dump_ctx *ctx = port_dump_ctx_get(cb);\n+\tstruct nlattr **tb = info-\u003einfo.attrs;\n+\tstruct port_reply_data *reply_data;\n+\tstruct port_req_info *req_info;\n+\tint ret;\n+\n+\tBUILD_BUG_ON(sizeof(*ctx) \u003e sizeof(cb-\u003ectx));\n+\n+\treq_info = kzalloc_obj(*req_info);\n+\tif (!req_info)\n+\t\treturn -ENOMEM;\n+\n+\treply_data = kmalloc_obj(*reply_data);\n+\tif (!reply_data) {\n+\t\tret = -ENOMEM;\n+\t\tgoto free_req_info;\n+\t}\n+\n+\tret = ethnl_parse_header_dev_get(\u0026req_info-\u003ebase, tb[ETHTOOL_A_PORT_HEADER],\n+\t\t\t\t\t genl_info_net(\u0026info-\u003einfo),\n+\t\t\t\t\t info-\u003einfo.extack, false);\n+\tif (ret \u003c 0)\n+\t\tgoto free_rep_data;\n+\n+\tctx-\u003eifindex = 0;\n+\tctx-\u003epos_ifindex = 0;\n+\n+\t/* For filtered DUMP requests, let's just store the ifindex. We'll check\n+\t * again if the netdev is still there when looping over the netdev list\n+\t * in the DUMP loop.\n+\t */\n+\tif (req_info-\u003ebase.dev) {\n+\t\tctx-\u003eifindex = req_info-\u003ebase.dev-\u003eifindex;\n+\t\tnetdev_put(req_info-\u003ebase.dev, \u0026req_info-\u003ebase.dev_tracker);\n+\t\treq_info-\u003ebase.dev = NULL;\n+\t}\n+\n+\tctx-\u003ereq_info = req_info;\n+\tctx-\u003ereply_data = reply_data;\n+\n+\treturn 0;\n+\n+free_rep_data:\n+\tkfree(reply_data);\n+free_req_info:\n+\tkfree(req_info);\n+\n+\treturn ret;\n+}\n+\n+static int port_dump_one(struct sk_buff *skb, struct net_device *dev,\n+\t\t\t struct netlink_callback *cb)\n+{\n+\tstruct port_dump_ctx *ctx = port_dump_ctx_get(cb);\n+\tvoid *ehdr;\n+\tint ret;\n+\n+\tehdr = ethnl_dump_put(skb, cb, ETHTOOL_MSG_PORT_GET_REPLY);\n+\tif (!ehdr)\n+\t\treturn -EMSGSIZE;\n+\n+\tmemset(ctx-\u003ereply_data, 0, sizeof(struct port_reply_data));\n+\tctx-\u003ereply_data-\u003ebase.dev = dev;\n+\n+\trtnl_lock();\n+\tnetdev_lock_ops(dev);\n+\n+\tret = port_prepare_data(\u0026ctx-\u003ereq_info-\u003ebase, \u0026ctx-\u003ereply_data-\u003ebase,\n+\t\t\t\tgenl_info_dump(cb));\n+\n+\tnetdev_unlock_ops(dev);\n+\trtnl_unlock();\n+\n+\tif (ret \u003c 0)\n+\t\tgoto out;\n+\n+\tret = ethnl_fill_reply_header(skb, dev, ETHTOOL_A_PORT_HEADER);\n+\tif (ret \u003c 0)\n+\t\tgoto out;\n+\n+\tret = port_fill_reply(skb, \u0026ctx-\u003ereq_info-\u003ebase, \u0026ctx-\u003ereply_data-\u003ebase);\n+\n+out:\n+\tctx-\u003ereply_data-\u003ebase.dev = NULL;\n+\tif (ret \u003c 0)\n+\t\tgenlmsg_cancel(skb, ehdr);\n+\telse\n+\t\tgenlmsg_end(skb, ehdr);\n+\n+\treturn ret;\n+}\n+\n+static int port_dump_one_dev(struct sk_buff *skb, struct netlink_callback *cb)\n+{\n+\tstruct port_dump_ctx *ctx = port_dump_ctx_get(cb);\n+\tstruct net_device *dev;\n+\tstruct phy_port *port;\n+\tint ret;\n+\n+\tdev = ctx-\u003ereq_info-\u003ebase.dev;\n+\n+\tif (!dev-\u003elink_topo)\n+\t\treturn 0;\n+\n+\txa_for_each_start(\u0026dev-\u003elink_topo-\u003eports, ctx-\u003epos_portid, port,\n+\t\t\t  ctx-\u003epos_portid) {\n+\t\tctx-\u003ereq_info-\u003eport_id = ctx-\u003epos_portid;\n+\n+\t\tret = port_dump_one(skb, dev, cb);\n+\t\tif (ret == -ENODEV)\n+\t\t\tcontinue;\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t}\n+\n+\tctx-\u003epos_portid = 0;\n+\n+\treturn 0;\n+}\n+\n+static int port_dump_all_dev(struct sk_buff *skb, struct netlink_callback *cb)\n+{\n+\tstruct port_dump_ctx *ctx = port_dump_ctx_get(cb);\n+\tstruct net *net = sock_net(skb-\u003esk);\n+\tnetdevice_tracker dev_tracker;\n+\tstruct net_device *dev;\n+\tint ret = 0;\n+\n+\trcu_read_lock();\n+\tfor_each_netdev_dump(net, dev, ctx-\u003epos_ifindex) {\n+\t\tnetdev_hold(dev, \u0026dev_tracker, GFP_ATOMIC);\n+\t\trcu_read_unlock();\n+\n+\t\tctx-\u003ereq_info-\u003ebase.dev = dev;\n+\t\tret = port_dump_one_dev(skb, cb);\n+\n+\t\trcu_read_lock();\n+\t\tnetdev_put(dev, \u0026dev_tracker);\n+\t\tctx-\u003ereq_info-\u003ebase.dev = NULL;\n+\n+\t\tif (ret \u003c 0 \u0026\u0026 ret != -EOPNOTSUPP) {\n+\t\t\tif (likely(skb-\u003elen))\n+\t\t\t\tret = skb-\u003elen;\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tret = 0;\n+\t}\n+\trcu_read_unlock();\n+\n+\treturn ret;\n+}\n+\n+int ethnl_port_dumpit(struct sk_buff *skb, struct netlink_callback *cb)\n+{\n+\tconst struct genl_dumpit_info *info = genl_dumpit_info(cb);\n+\tstruct port_dump_ctx *ctx = port_dump_ctx_get(cb);\n+\tint ret = 0;\n+\n+\tif (ctx-\u003eifindex) {\n+\t\tnetdevice_tracker dev_tracker;\n+\t\tstruct net_device *dev;\n+\n+\t\tdev = netdev_get_by_index(genl_info_net(\u0026info-\u003einfo),\n+\t\t\t\t\t  ctx-\u003eifindex, \u0026dev_tracker,\n+\t\t\t\t\t  GFP_KERNEL);\n+\t\tif (!dev)\n+\t\t\treturn -ENODEV;\n+\n+\t\tctx-\u003ereq_info-\u003ebase.dev = dev;\n+\t\tret = port_dump_one_dev(skb, cb);\n+\t\tif (ret \u003c 0 \u0026\u0026 ret != -EOPNOTSUPP \u0026\u0026 likely(skb-\u003elen))\n+\t\t\tret = skb-\u003elen;\n+\n+\t\tnetdev_put(dev, \u0026dev_tracker);\n+\t} else {\n+\t\tret = port_dump_all_dev(skb, cb);\n+\t}\n+\n+\treturn ret;\n+}\n+\n+int ethnl_port_dump_done(struct netlink_callback *cb)\n+{\n+\tstruct port_dump_ctx *ctx = port_dump_ctx_get(cb);\n+\n+\tkfree(ctx-\u003ereq_info);\n+\tkfree(ctx-\u003ereply_data);\n+\n+\treturn 0;\n+}\n+\n+const struct ethnl_request_ops ethnl_port_request_ops = {\n+\t.request_cmd\t\t= ETHTOOL_MSG_PORT_GET,\n+\t.reply_cmd\t\t= ETHTOOL_MSG_PORT_GET_REPLY,\n+\t.hdr_attr\t\t= ETHTOOL_A_PORT_HEADER,\n+\t.req_info_size\t\t= sizeof(struct port_req_info),\n+\t.reply_data_size\t= sizeof(struct port_reply_data),\n+\n+\t.parse_request\t\t= port_parse_request,\n+\t.prepare_data\t\t= port_prepare_data,\n+\t.reply_size\t\t= port_reply_size,\n+\t.fill_reply\t\t= port_fill_reply,\n+};\n"
}

2/1 2026/09/10 19:11 agent patch-evaluator
0m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "ETHTOOL_NETLINK",
    "PHYLIB",
    "PHYLINK"
  ],
  "FocusSymbols": [
    "ethnl_port_dumpit",
    "ethnl_port_dump_start",
    "ethnl_port_dump_done",
    "port_prepare_data",
    "port_fill_reply",
    "phy_link_topo_add_port",
    "phy_link_topo_del_port",
    "phy_caps_linkmode_filter_ifaces",
    "phy_set_upstream_port"
  ],
  "Reasoning": "The patch introduces the ETHTOOL_MSG_PORT_GET netlink command (both DO and DUMP operations) along with supporting PHY link topology port management and phylib SFP cage/module port handling. This new netlink interface can be reached directly from userspace via generic netlink sockets, making it a high-value target for fuzzing.",
  "WorthFuzzing": true
}

Instruction:
You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.

================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.

- REACHABILITY IS THE PRIMARY GATE:
  Fuzzing can only discover bugs in code that can actually execute in standard virtualized
  environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
  If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
  regardless of whether it adds assertions or complex logic.

- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
  Patch authors routinely label changes as "cleanups", "refactorings", or state
  "No functional change intended". Do NOT take these claims at face value.
  Code refactorings that rearrange logic, introduce helper functions, or alter state management
  in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
  If reachable executable code is modified or refactored, it MUST be fuzzed.

- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
  When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
  BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
  Even if the author believes the invariant always holds, fuzzing is essential to verify whether
  an unusual sequence of operations can violate it.

================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:

- Non-kernel and non-executable changes:
  * Modifications to Documentation/, comments, or spelling fixes.
  * User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
    that do not affect the compiled kernel image (vmlinux) or kernel modules.
  * Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
    that do not alter control flow or data structures.
  * Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
  * Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
    ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
  * Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
    physical PCI hot-unplug or manual sysfs driver unbinding.
  * Code paths exclusive to architectures other than the target architecture.

================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
  * Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
    BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
  * Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
  * Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
  * Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).

================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:

- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
  Do NOT list generic, ubiquitous functions called by almost every program in the corpus
  (including, but not limited to: general memory allocators and deallocators, page fault
  and trap handlers, or core synchronization primitives; this is not an exhaustive list).
  Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
  which severely dilutes fuzzing effort away from the actual changes.

- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
  List functions that specifically implement the logic being added or altered, or direct API entrypoints
  for the subsystem feature under review.

- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
  Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
  distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
  If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
  functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).

================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 02572d1cc948837eac36bce03b1f2254f2e77f39
Author: syz-cluster <triage@syzkaller.com>
Date:   Thu Sep 10 19:11:12 2026 +0000

    syz-cluster: applied patch under review

diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netlink/specs/ethtool.yaml
index 5dd4d1b5d94bb..35e028c0be296 100644
--- a/Documentation/netlink/specs/ethtool.yaml
+++ b/Documentation/netlink/specs/ethtool.yaml
@@ -210,6 +210,11 @@ definitions:
       -
         name: discard
         value: 31
+  -
+    name: port-type
+    doc: type of physical connector
+    type: enum
+    entries: [mdi, sfp]
 
 attribute-sets:
   -
@@ -1905,6 +1910,32 @@ attribute-sets:
         name: link
         type: nest
         nested-attributes: mse-snapshot
+  -
+    name: port
+    attr-cnt-name: --ethtool-a-port-cnt
+    attributes:
+      -
+        name: header
+        type: nest
+        nested-attributes: header
+      -
+        name: id
+        type: u32
+      -
+        name: supported-modes
+        type: nest
+        nested-attributes: bitset
+      -
+        name: supported-interfaces
+        type: nest
+        nested-attributes: bitset
+      -
+        name: type
+        type: u32
+        enum: port-type
+      -
+        name: upstream-port
+        type: u32
 
 operations:
   enum-model: directional
@@ -2859,6 +2890,30 @@ operations:
             - worst-channel
             - link
       dump: *mse-get-op
+    -
+      name: port-get
+      doc: Get ports attached to an interface
+
+      attribute-set: port
+
+      do:
+        request:
+          attributes:
+            - header
+            - id
+        reply: &port-get-op-reply
+          attributes:
+            - header
+            - id
+            - supported-modes
+            - supported-interfaces
+            - type
+            - upstream-port
+      dump:
+        request:
+          attributes:
+            - header
+        reply: *port-get-op-reply
 
 mcast-groups:
   list:
diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst
index e92abf45faf50..b4326c89b0751 100644
--- a/Documentation/networking/ethtool-netlink.rst
+++ b/Documentation/networking/ethtool-netlink.rst
@@ -2537,6 +2537,39 @@ Within each channel nest, only the metrics supported by the PHY will be present.
 See ``struct phy_mse_snapshot`` kernel documentation in
 ``include/linux/phy.h``.
 
+PORT_GET
+========
+
+Retrieve information about the physical connection points of a network device,
+referred to as "ports". User needs to specify a PORT_ID for the DO operation,
+in which case the DO request returns information about that specific port.
+
+As there can be more than one port, the DUMP operation can be used to list the
+ports present on a given interface, by passing an interface index or name in
+the dump request.
+
+Request contents:
+
+  ===================================== ======  ===============================
+  ``ETHTOOL_A_PORT_HEADER``             nested  request header
+  ``ETHTOOL_A_PORT_ID``                 u32     port id
+  ===================================== ======  ===============================
+
+Kernel response contents:
+
+  ======================================= ======  =============================
+  ``ETHTOOL_A_PORT_HEADER``               nested  request header
+  ``ETHTOOL_A_PORT_ID``                   u32     the port's unique identifier,
+                                                  per netdevice.
+  ``ETHTOOL_A_PORT_SUPPORTED_MODES``      bitset  bitset of supported linkmodes
+  ``ETHTOOL_A_PORT_SUPPORTED_INTERFACES`` bitset  bitset of supported MII
+                                                  interfaces
+  ``ETHTOOL_A_PORT_TYPE``                 u32     the port type
+  ``ETHTOOL_A_PORT_UPSTREAM_PORT``        u32     If any, the index of the MII
+                                                  port that feeds into this
+                                                  port.
+  ======================================= ======  =============================
+
 Request translation
 ===================
 
@@ -2647,4 +2680,5 @@ are netlink only.
   n/a                                 ``ETHTOOL_MSG_PHY_GET``
   ``SIOCGHWTSTAMP``                   ``ETHTOOL_MSG_TSCONFIG_GET``
   ``SIOCSHWTSTAMP``                   ``ETHTOOL_MSG_TSCONFIG_SET``
+  n/a                                 ``ETHTOOL_MSG_PORT_GET``
   =================================== =====================================
diff --git a/Documentation/networking/phy-port.rst b/Documentation/networking/phy-port.rst
index 6e28d9094bce3..2a9b1ec93b70f 100644
--- a/Documentation/networking/phy-port.rst
+++ b/Documentation/networking/phy-port.rst
@@ -99,13 +99,29 @@ will eventually be able to report its own ksettings::
             (_____)-----| Port |
                         +------+
 
+SFP ports
+=========
+
+SFP interfaces involve 2 distinct components, each represented by
+a :c:type:`struct phy_port <phy_port>` instance :
+
+ - The SFP cage itself is a :c:type:`struct phy_port <phy_port>`. It's special
+   in that it's not an MDI interface, but rather a hot-pluggable MII.
+   The :c:type:`struct phy_port <phy_port>` associated to it lists the different
+   MII interfaces we can use on the cage.
+
+ - The SFP module, when inserted, will also be associated to a
+   :c:type:`struct phy_port <phy_port>`, that represents the various linkmodes
+   that it gives access to. The module's :c:type:`struct phy_port <phy_port>`
+   doesn't supersede the cage's port, it references it through
+   the :c:type:`struct phy_port <phy_port>` :c:member:`upstream_port` field.
+
 Next steps
 ==========
 
-As of writing this documentation, only ports controlled by PHY devices are
-supported. The next steps will be to add the Netlink API to expose these
-to userspace and add support for raw ports (controlled by some firmware, and directly
-managed by the NIC driver).
+As of writing this documentation, the port's presence and information can only
+be queried, and it's not possible to change any of the port's settings or select
+which one should be used.
 
 Another parallel task is the introduction of a MII muxing framework to allow the
-control of non-PHY driver multi-port setups.
+control of non-PHY driven multi-port setups.
diff --git a/MAINTAINERS b/MAINTAINERS
index 878ecf1fdf27c..973bbb7d2419b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -18994,6 +18994,7 @@ F:	Documentation/devicetree/bindings/net/ethernet-connector.yaml
 F:	Documentation/networking/phy-port.rst
 F:	drivers/net/phy/phy_port.c
 F:	include/linux/phy_port.h
+F:	net/ethtool/port.c
 K:	struct\s+phy_port|phy_port_
 
 NETWORKING [GENERAL]
diff --git a/drivers/net/phy/phy-caps.h b/drivers/net/phy/phy-caps.h
index 421088e6f6e8f..ec3d39a0ae06b 100644
--- a/drivers/net/phy/phy-caps.h
+++ b/drivers/net/phy/phy-caps.h
@@ -66,5 +66,7 @@ void phy_caps_medium_get_supported(unsigned long *supported,
 				   enum ethtool_link_medium medium,
 				   int lanes);
 u32 phy_caps_mediums_from_linkmodes(unsigned long *linkmodes);
+void phy_caps_linkmode_filter_ifaces(unsigned long *to, const unsigned long *from,
+				     const unsigned long *interfaces);
 
 #endif /* __PHY_CAPS_H */
diff --git a/drivers/net/phy/phy_caps.c b/drivers/net/phy/phy_caps.c
index 942d43191561e..558e4df4d63c0 100644
--- a/drivers/net/phy/phy_caps.c
+++ b/drivers/net/phy/phy_caps.c
@@ -445,3 +445,29 @@ u32 phy_caps_mediums_from_linkmodes(unsigned long *linkmodes)
 	return mediums;
 }
 EXPORT_SYMBOL_GPL(phy_caps_mediums_from_linkmodes);
+
+/**
+ * phy_caps_linkmode_filter_ifaces() - Filter linkmodes with an interface list
+ * @to: Stores the filtered linkmodes
+ * @from: Linkmodes to filter
+ * @interfaces: Bitfield of phy_interface_t that we use for filtering
+ *
+ * Filter the provided linkmodes, only to keep the ones we can possibly achieve
+ * when using any of the provided MII interfaces.
+ */
+void phy_caps_linkmode_filter_ifaces(unsigned long *to,
+				     const unsigned long *from,
+				     const unsigned long *interfaces)
+{
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(ifaces_supported) = {};
+	unsigned int ifaces_caps = 0;
+	phy_interface_t interface;
+
+	for_each_set_bit(interface, interfaces, PHY_INTERFACE_MODE_MAX)
+		ifaces_caps |= phy_caps_from_interface(interface);
+
+	phy_caps_linkmodes(ifaces_caps, ifaces_supported);
+
+	linkmode_and(to, from, ifaces_supported);
+}
+EXPORT_SYMBOL_GPL(phy_caps_linkmode_filter_ifaces);
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 41d1b20cde2c0..561d19edf331c 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1490,11 +1490,22 @@ static int phy_sfp_connect_phy(void *upstream, struct phy_device *phy)
 {
 	struct phy_device *phydev = upstream;
 	struct net_device *dev = phydev->attached_dev;
+	int ret;
 
-	if (dev)
-		return phy_link_topo_add_phy(dev, phy, PHY_UPSTREAM_PHY, phydev);
+	phydev->has_sfp_mod_phy = true;
+	phy_set_upstream_port(phy, phydev->sfp_cage_port);
 
-	return 0;
+	/* If we aren't attached to a netdev, we can't add the SFP PHY to its
+	 * topology.
+	 */
+	if (!dev)
+		return 0;
+
+	ret = phy_link_topo_add_phy(dev, phy, PHY_UPSTREAM_PHY, phydev);
+	if (ret)
+		phydev->has_sfp_mod_phy = false;
+
+	return ret;
 }
 
 /**
@@ -1512,8 +1523,12 @@ static void phy_sfp_disconnect_phy(void *upstream, struct phy_device *phy)
 	struct phy_device *phydev = upstream;
 	struct net_device *dev = phydev->attached_dev;
 
+	phydev->has_sfp_mod_phy = false;
+
 	if (dev)
 		phy_link_topo_del_phy(dev, phy);
+
+	phy_set_upstream_port(phy, NULL);
 }
 
 /**
@@ -1617,6 +1632,77 @@ static void phy_sfp_link_down(void *upstream)
 		port->ops->link_down(port);
 }
 
+static int phy_add_sfp_mod_port(struct phy_device *phydev)
+{
+	const struct sfp_module_caps *caps;
+	struct phy_port *port;
+	int ret = 0;
+
+	/* Create mod port */
+	port = phy_port_alloc();
+	if (!port)
+		return -ENOMEM;
+
+	port->active = true;
+
+	caps = sfp_get_module_caps(phydev->sfp_bus);
+
+	phy_caps_linkmode_filter_ifaces(port->supported, caps->link_modes,
+					phydev->sfp_cage_port->interfaces);
+
+	if (phydev->attached_dev) {
+		ret = phy_link_topo_add_port(phydev->attached_dev, port);
+		if (ret) {
+			phy_port_destroy(port);
+			return ret;
+		}
+	}
+
+	/* we don't use phy_add_port() here as the module port isn't a direct
+	 * interface from the PHY, but rather an extension to the sfp-bus, that
+	 * is already represented by its own phy_port
+	 */
+	phydev->mod_port = port;
+
+	port->upstream_port = phydev->sfp_cage_port;
+
+	return 0;
+}
+
+static void phy_del_sfp_mod_port(struct phy_device *phydev)
+{
+	if (!phydev->mod_port)
+		return;
+
+	if (phydev->attached_dev)
+		phy_link_topo_del_port(phydev->attached_dev, phydev->mod_port);
+
+	phy_port_destroy(phydev->mod_port);
+	phydev->mod_port = NULL;
+}
+
+static int phy_sfp_module_start(void *upstream)
+{
+	struct phy_device *phydev = upstream;
+
+	/* If there's a downstream SFP module, and it doesn't contain a PHY
+	 * device, let's create a phy_port to represent that module.
+	 */
+	if (!phydev->has_sfp_mod_phy)
+		return phy_add_sfp_mod_port(phydev);
+
+	return 0;
+}
+
+static void phy_sfp_module_stop(void *upstream)
+{
+	struct phy_device *phydev = upstream;
+
+	/* Called upon module removal or upstream removal */
+	if (!phydev->has_sfp_mod_phy)
+		phy_del_sfp_mod_port(phydev);
+}
+
 static const struct sfp_upstream_ops sfp_phydev_ops = {
 	.attach = phy_sfp_attach,
 	.detach = phy_sfp_detach,
@@ -1626,6 +1712,8 @@ static const struct sfp_upstream_ops sfp_phydev_ops = {
 	.link_down = phy_sfp_link_down,
 	.connect_phy = phy_sfp_connect_phy,
 	.disconnect_phy = phy_sfp_disconnect_phy,
+	.module_start = phy_sfp_module_start,
+	.module_stop = phy_sfp_module_stop,
 };
 
 static int phy_add_port(struct phy_device *phydev, struct phy_port *port)
@@ -1670,16 +1758,19 @@ static void phy_del_port(struct phy_device *phydev, struct phy_port *port)
 
 	list_del(&port->head);
 
+	if (phydev->attached_dev)
+		phy_link_topo_del_port(phydev->attached_dev, port);
+
 	phydev->n_ports--;
 }
 
-static int phy_setup_sfp_port(struct phy_device *phydev)
+static struct phy_port *phy_setup_sfp_port(struct phy_device *phydev)
 {
 	struct phy_port *port = phy_port_alloc();
 	int ret;
 
 	if (!port)
-		return -ENOMEM;
+		return ERR_PTR(-ENOMEM);
 
 	port->parent_type = PHY_PORT_PHY;
 	port->phy = phydev;
@@ -1694,10 +1785,12 @@ static int phy_setup_sfp_port(struct phy_device *phydev)
 	 * when attaching the port to the phydev.
 	 */
 	ret = phy_add_port(phydev, port);
-	if (ret)
+	if (ret) {
 		phy_port_destroy(port);
+		return ERR_PTR(ret);
+	}
 
-	return ret;
+	return port;
 }
 
 /**
@@ -1706,30 +1799,50 @@ static int phy_setup_sfp_port(struct phy_device *phydev)
  */
 static int phy_sfp_probe(struct phy_device *phydev)
 {
+	struct phy_port *port = NULL;
 	struct sfp_bus *bus;
-	int ret = 0;
+	int ret;
 
-	if (phydev->mdio.dev.fwnode) {
-		bus = sfp_bus_find_fwnode(phydev->mdio.dev.fwnode);
-		if (IS_ERR(bus))
-			return PTR_ERR(bus);
+	if (!phydev->mdio.dev.fwnode)
+		return 0;
 
-		phydev->sfp_bus = bus;
+	bus = sfp_bus_find_fwnode(phydev->mdio.dev.fwnode);
+	if (IS_ERR(bus))
+		return PTR_ERR(bus);
 
-		ret = sfp_bus_add_upstream(bus, phydev, &sfp_phydev_ops);
-		sfp_bus_put(bus);
+	phydev->sfp_bus = bus;
 
-		if (ret)
-			phydev->sfp_bus = NULL;
+	if (bus) {
+		port = phy_setup_sfp_port(phydev);
+		if (IS_ERR(port)) {
+			ret = PTR_ERR(port);
+			port = NULL;
+			goto out_sfp;
+		}
 	}
 
-	if (!ret && phydev->sfp_bus) {
-		ret = phy_setup_sfp_port(phydev);
-		if (ret) {
-			sfp_bus_del_upstream(phydev->sfp_bus);
-			phydev->sfp_bus = NULL;
-		}
+	phydev->sfp_cage_port = port;
+
+	ret = sfp_bus_add_upstream(bus, phydev, &sfp_phydev_ops);
+	if (ret)
+		goto out_port;
+
+	/* sfp_bus_add_upstream() grabs a ref to the sfp bus on success, it's
+	 * safe to release it now.
+	 */
+	sfp_bus_put(bus);
+
+	return ret;
+
+out_port:
+	if (port) {
+		phy_del_port(phydev, port);
+		phy_port_destroy(port);
+		phydev->sfp_cage_port = NULL;
 	}
+out_sfp:
+	sfp_bus_put(bus);
+	phydev->sfp_bus = NULL;
 
 	return ret;
 }
@@ -1813,6 +1926,8 @@ static void phy_detach_internal(struct phy_device *phydev, bool notify_bus)
 		phydev->attached_dev->phydev = NULL;
 		phydev->attached_dev = NULL;
 		phy_link_topo_del_phy(dev, phydev);
+		if (phydev->mod_port)
+			phy_link_topo_del_port(dev, phydev->mod_port);
 	}
 
 	phydev->phy_link_change = NULL;
@@ -1942,6 +2057,12 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
 		err = phy_link_topo_add_phy(dev, phydev, PHY_UPSTREAM_MAC, dev);
 		if (err)
 			goto error;
+
+		if (phydev->mod_port) {
+			err = phy_link_topo_add_port(dev, phydev->mod_port);
+			if (err)
+				goto error;
+		}
 	}
 
 	/* Some Ethernet drivers try to connect to a PHY device before
@@ -3662,6 +3783,25 @@ struct phy_port *phy_get_sfp_port(struct phy_device *phydev)
 }
 EXPORT_SYMBOL_GPL(phy_get_sfp_port);
 
+/**
+ * phy_set_upstream_port() - Sets the phy_port controlling the MII this PHY is
+ *			     attached to.
+ * @phydev: pointer to the PHY device we set the upstream of.
+ * @port: The phy_port upstream of this PHY, can be NULL.
+ */
+void phy_set_upstream_port(struct phy_device *phydev, struct phy_port *port)
+{
+	struct phy_port *local_port;
+
+	ASSERT_RTNL();
+
+	phydev->upstream_port = port;
+
+	phy_for_each_port(phydev, local_port)
+		local_port->upstream_port = port;
+}
+EXPORT_SYMBOL_GPL(phy_set_upstream_port);
+
 /**
  * fwnode_mdio_find_device - Given a fwnode, find the mdio_device
  * @fwnode: pointer to the mdio_device's fwnode
diff --git a/drivers/net/phy/phy_link_topology.c b/drivers/net/phy/phy_link_topology.c
index 4134de7ae313d..22885bf2e0455 100644
--- a/drivers/net/phy/phy_link_topology.c
+++ b/drivers/net/phy/phy_link_topology.c
@@ -7,6 +7,7 @@
  */
 
 #include <linux/phy_link_topology.h>
+#include <linux/phy_port.h>
 #include <linux/phy.h>
 #include <linux/rtnetlink.h>
 #include <linux/xarray.h>
@@ -23,17 +24,89 @@ static int netdev_alloc_phy_link_topology(struct net_device *dev)
 	xa_init_flags(&topo->phys, XA_FLAGS_ALLOC1);
 	topo->next_phy_index = 1;
 
+	xa_init_flags(&topo->ports, XA_FLAGS_ALLOC1);
+	topo->next_port_index = 1;
+
 	dev->link_topo = topo;
 
 	return 0;
 }
 
+static struct phy_link_topology *phy_link_topo_get_or_alloc(struct net_device *dev)
+{
+	int ret;
+
+	if (dev->link_topo)
+		return dev->link_topo;
+
+	/* The topology is allocated the first time we add an object to it.
+	 * It is freed alongside the netdev. It can be called on multiple
+	 * contexts:
+	 *  - It can be called from .probe() : No rtnl, no netdev_lock
+	 *  - .ndo_open() : rtnl and possibly netdev_lock
+	 *  - SFP state machine : rtnl held or not
+	 *
+	 *  However, we can't really have races :
+	 *  - If we have a PHY, phy_link_topo_add_phy() will always run first
+	 *    and trigger the alloc. Only then the ports can be added through
+	 *    phylib or sfp.
+	 *  - If we don't, the SFP port for the cage is registered first, and
+	 *    only then other ports/PHYs can be registered.
+	 */
+	ret = netdev_alloc_phy_link_topology(dev);
+	if (ret)
+		return ERR_PTR(ret);
+
+	return dev->link_topo;
+}
+
+int phy_link_topo_add_port(struct net_device *dev, struct phy_port *port)
+{
+	struct phy_link_topology *topo;
+	int ret;
+
+	/* Ports can now be queried without rtnl for ops-locked devices, which
+	 * we don't support now as port retrieval is done under rtnl.
+	 * We don't have phy_port enabled devices yet, let's make sure
+	 * we are loudly warned about that when it happens.
+	 */
+	if (WARN_ON_ONCE(netdev_need_ops_lock(dev)))
+		return -EOPNOTSUPP;
+
+	topo = phy_link_topo_get_or_alloc(dev);
+	if (IS_ERR(topo))
+		return PTR_ERR(topo);
+
+	/* Attempt to re-use a previously allocated port_id */
+	if (port->id)
+		ret = xa_insert(&topo->ports, port->id, port, GFP_KERNEL);
+	else
+		ret = xa_alloc_cyclic(&topo->ports, &port->id, port,
+				      xa_limit_32b, &topo->next_port_index,
+				      GFP_KERNEL);
+
+	return ret < 0 ? ret : 0;
+}
+EXPORT_SYMBOL_GPL(phy_link_topo_add_port);
+
+void phy_link_topo_del_port(struct net_device *dev, struct phy_port *port)
+{
+	struct phy_link_topology *topo = dev->link_topo;
+
+	if (!topo)
+		return;
+
+	xa_erase(&topo->ports, port->id);
+}
+EXPORT_SYMBOL_GPL(phy_link_topo_del_port);
+
 int phy_link_topo_add_phy(struct net_device *dev,
 			  struct phy_device *phy,
 			  enum phy_upstream upt, void *upstream)
 {
-	struct phy_link_topology *topo = dev->link_topo;
+	struct phy_link_topology *topo;
 	struct phy_device_node *pdn;
+	struct phy_port *port;
 	int ret;
 
 	/* ethtool ops may run without rtnl_lock, and rtnl_lock is what
@@ -45,13 +118,9 @@ int phy_link_topo_add_phy(struct net_device *dev,
 	if (WARN_ON_ONCE(netdev_need_ops_lock(dev)))
 		return -EOPNOTSUPP;
 
-	if (!topo) {
-		ret = netdev_alloc_phy_link_topology(dev);
-		if (ret)
-			return ret;
-
-		topo = dev->link_topo;
-	}
+	topo = phy_link_topo_get_or_alloc(dev);
+	if (IS_ERR(topo))
+		return PTR_ERR(topo);
 
 	pdn = kzalloc_obj(*pdn);
 	if (!pdn)
@@ -86,8 +155,20 @@ int phy_link_topo_add_phy(struct net_device *dev,
 	if (ret < 0)
 		goto err;
 
+	/* Add all the PHY's ports to the topology */
+	list_for_each_entry(port, &phy->ports, head) {
+		ret = phy_link_topo_add_port(dev, port);
+		if (ret)
+			goto del_ports;
+	}
+
 	return 0;
 
+del_ports:
+	list_for_each_entry_continue_reverse(port, &phy->ports, head)
+		phy_link_topo_del_port(dev, port);
+
+	xa_erase(&topo->phys, phy->phyindex);
 err:
 	kfree(pdn);
 	return ret;
@@ -99,10 +180,14 @@ void phy_link_topo_del_phy(struct net_device *dev,
 {
 	struct phy_link_topology *topo = dev->link_topo;
 	struct phy_device_node *pdn;
+	struct phy_port *port;
 
 	if (!topo)
 		return;
 
+	list_for_each_entry(port, &phy->ports, head)
+		phy_link_topo_del_port(dev, port);
+
 	pdn = xa_erase(&topo->phys, phy->phyindex);
 
 	/* We delete the PHY from the topology, however we don't re-set the
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index b9fc8599df749..d05cde44f401d 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -14,6 +14,8 @@
 #include <linux/of_mdio.h>
 #include <linux/phy.h>
 #include <linux/phy_fixed.h>
+#include <linux/phy_link_topology.h>
+#include <linux/phy_port.h>
 #include <linux/phylink.h>
 #include <linux/rtnetlink.h>
 #include <linux/spinlock.h>
@@ -93,6 +95,8 @@ struct phylink {
 	DECLARE_PHY_INTERFACE_MASK(sfp_interfaces);
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support);
 	u8 sfp_port;
+	struct phy_port *sfp_cage_port;
+	struct phy_port *mod_port;
 
 	struct eee_config eee_cfg;
 
@@ -1765,6 +1769,51 @@ static void phylink_fixed_poll(struct timer_list *t)
 
 static const struct sfp_upstream_ops sfp_phylink_ops;
 
+static int phylink_create_sfp_cage_port(struct phylink *pl)
+{
+	struct phy_port *port;
+	int ret = 0;
+
+	if (!pl->netdev || !pl->sfp_bus)
+		return 0;
+
+	port = phy_port_alloc();
+	if (!port)
+		return -ENOMEM;
+
+	port->is_sfp = true;
+	port->is_mii = true;
+	port->active = true;
+
+	phy_interface_and(port->interfaces, pl->config->supported_interfaces,
+			  phylink_sfp_interfaces);
+	phy_port_update_supported(port);
+
+	ret = phy_link_topo_add_port(pl->netdev, port);
+	if (ret)
+		goto out_destroy_port;
+
+	pl->sfp_cage_port = port;
+
+	return 0;
+
+out_destroy_port:
+	phy_port_destroy(port);
+	pl->sfp_cage_port = NULL;
+	return ret;
+}
+
+static void phylink_destroy_sfp_cage_port(struct phylink *pl)
+{
+	if (pl->netdev && pl->sfp_cage_port)
+		phy_link_topo_del_port(pl->netdev, pl->sfp_cage_port);
+
+	if (pl->sfp_cage_port)
+		phy_port_destroy(pl->sfp_cage_port);
+
+	pl->sfp_cage_port = NULL;
+}
+
 static int phylink_register_sfp(struct phylink *pl,
 				const struct fwnode_handle *fwnode)
 {
@@ -1782,9 +1831,18 @@ static int phylink_register_sfp(struct phylink *pl,
 
 	pl->sfp_bus = bus;
 
+	ret = phylink_create_sfp_cage_port(pl);
+	if (ret) {
+		sfp_bus_put(bus);
+		return ret;
+	}
+
 	ret = sfp_bus_add_upstream(bus, pl, &sfp_phylink_ops);
 	sfp_bus_put(bus);
 
+	if (ret)
+		phylink_destroy_sfp_cage_port(pl);
+
 	return ret;
 }
 
@@ -2067,6 +2125,7 @@ EXPORT_SYMBOL_GPL(phylink_create);
 void phylink_destroy(struct phylink *pl)
 {
 	sfp_bus_del_upstream(pl->sfp_bus);
+	phylink_destroy_sfp_cage_port(pl);
 	if (pl->link_gpio)
 		gpiod_put(pl->link_gpio);
 
@@ -3939,14 +3998,67 @@ static void phylink_sfp_module_remove(void *upstream)
 	phy_interface_zero(pl->sfp_interfaces);
 }
 
+static int phylink_add_sfp_mod_port(struct phylink *pl)
+{
+	const struct sfp_module_caps *caps;
+	struct phy_port *port;
+	int ret = 0;
+
+	if (!pl->sfp_cage_port)
+		return 0;
+
+	/* Create mod port */
+	port = phy_port_alloc();
+	if (!port)
+		return -ENOMEM;
+
+	port->active = true;
+
+	caps = sfp_get_module_caps(pl->sfp_bus);
+
+	phy_caps_linkmode_filter_ifaces(port->supported, caps->link_modes,
+					pl->sfp_cage_port->interfaces);
+
+	if (pl->netdev) {
+		ret = phy_link_topo_add_port(pl->netdev, port);
+		if (ret) {
+			phy_port_destroy(port);
+			return ret;
+		}
+	}
+
+	port->upstream_port = pl->sfp_cage_port;
+
+	pl->mod_port = port;
+
+	return 0;
+}
+
+static void phylink_del_sfp_mod_port(struct phylink *pl)
+{
+	if (!pl->mod_port)
+		return;
+
+	if (pl->netdev)
+		phy_link_topo_del_port(pl->netdev, pl->mod_port);
+
+	phy_port_destroy(pl->mod_port);
+	pl->mod_port = NULL;
+}
+
 static int phylink_sfp_module_start(void *upstream)
 {
 	struct phylink *pl = upstream;
+	int ret;
 
 	/* If this SFP module has a PHY, start the PHY now. */
 	if (pl->phydev) {
 		phy_start(pl->phydev);
 		return 0;
+	} else {
+		ret = phylink_add_sfp_mod_port(pl);
+		if (ret)
+			return ret;
 	}
 
 	/* If the module may have a PHY but we didn't detect one we
@@ -3955,7 +4067,16 @@ static int phylink_sfp_module_start(void *upstream)
 	if (!pl->sfp_may_have_phy)
 		return 0;
 
-	return phylink_sfp_config_optical(pl);
+	ret = phylink_sfp_config_optical(pl);
+	if (ret)
+		goto del_mod_port;
+
+	return 0;
+
+del_mod_port:
+	phylink_del_sfp_mod_port(pl);
+
+	return ret;
 }
 
 static void phylink_sfp_module_stop(void *upstream)
@@ -3965,6 +4086,8 @@ static void phylink_sfp_module_stop(void *upstream)
 	/* If this SFP module has a PHY, stop it. */
 	if (pl->phydev)
 		phy_stop(pl->phydev);
+	else
+		phylink_del_sfp_mod_port(pl);
 }
 
 static void phylink_sfp_link_down(void *upstream)
@@ -4009,6 +4132,8 @@ static int phylink_sfp_connect_phy(void *upstream, struct phy_device *phy)
 	phy_interface_and(phy->host_interfaces, phylink_sfp_interfaces,
 			  pl->config->supported_interfaces);
 
+	phy_set_upstream_port(phy, pl->sfp_cage_port);
+
 	/* Do the initial configuration */
 	return phylink_sfp_config_phy(pl, phy);
 }
@@ -4017,6 +4142,7 @@ static void phylink_sfp_disconnect_phy(void *upstream,
 				       struct phy_device *phydev)
 {
 	phylink_disconnect_phy(upstream);
+	phy_set_upstream_port(phydev, NULL);
 }
 
 static const struct sfp_upstream_ops sfp_phylink_ops = {
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 3d8afe6b7f1c5..335821eb22171 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -600,6 +600,7 @@ struct phy_oatc14_sqi_capability {
  * @wol_enabled: Set to true if the PHY or the attached MAC have Wake-on-LAN
  * 		 enabled.
  * @is_genphy_driven: PHY is driven by one of the generic PHY drivers
+ * @has_sfp_mod_phy: Set true if downstream SFP bus's module contains a PHY
  * @state: State of the PHY for management purposes
  * @dev_flags: Device-specific flags used by the PHY driver.
  *
@@ -612,6 +613,9 @@ struct phy_oatc14_sqi_capability {
  * @phylink: Pointer to phylink instance for this PHY
  * @sfp_bus_attached: Flag indicating whether the SFP bus has been attached
  * @sfp_bus: SFP bus attached to this PHY's fiber port
+ * @sfp_cage_port: The phy_port connected to the downstream SFP cage
+ * @mod_port: phy_port representing the SFP module, if it is phy-less
+ * @upstream_port: phy_port this PHY's MII attaches to, if any
  * @attached_dev: The attached enet driver's device instance ptr
  * @adjust_link: Callback for the enet controller to respond to changes: in the
  *               link state.
@@ -724,6 +728,7 @@ struct phy_device {
 	unsigned irq_rerun:1;
 
 	unsigned default_timestamp:1;
+	unsigned has_sfp_mod_phy:1;
 
 	int rate_matching;
 
@@ -803,6 +808,9 @@ struct phy_device {
 	/* This may be modified under the rtnl lock */
 	bool sfp_bus_attached;
 	struct sfp_bus *sfp_bus;
+	struct phy_port *sfp_cage_port;
+	struct phy_port *mod_port;
+	struct phy_port *upstream_port;
 	struct phylink *phylink;
 	struct net_device *attached_dev;
 	struct mii_timestamper *mii_ts;
@@ -2487,6 +2495,8 @@ int __phy_hwtstamp_set(struct phy_device *phydev,
 
 struct phy_port *phy_get_sfp_port(struct phy_device *phydev);
 
+void phy_set_upstream_port(struct phy_device *phydev, struct phy_port *port);
+
 /**
  * phy_module_driver() - Helper macro for registering PHY drivers
  * @__phy_drivers: array of PHY drivers to register
diff --git a/include/linux/phy_link_topology.h b/include/linux/phy_link_topology.h
index 95575f68d5bc7..9585282cae3fc 100644
--- a/include/linux/phy_link_topology.h
+++ b/include/linux/phy_link_topology.h
@@ -13,14 +13,19 @@
 
 #include <linux/ethtool.h>
 #include <linux/netdevice.h>
+#include <linux/rtnetlink.h>
 
 struct xarray;
 struct phy_device;
+struct phy_port;
 struct sfp_bus;
 
 struct phy_link_topology {
 	struct xarray phys;
 	u32 next_phy_index;
+
+	struct xarray ports;
+	u32 next_port_index;
 };
 
 struct phy_device_node {
@@ -48,6 +53,9 @@ int phy_link_topo_add_phy(struct net_device *dev,
 
 void phy_link_topo_del_phy(struct net_device *dev, struct phy_device *phy);
 
+int phy_link_topo_add_port(struct net_device *dev, struct phy_port *port);
+void phy_link_topo_del_port(struct net_device *dev, struct phy_port *port);
+
 static inline struct phy_device *
 phy_link_topo_get_phy(struct net_device *dev, u32 phyindex)
 {
@@ -64,6 +72,25 @@ phy_link_topo_get_phy(struct net_device *dev, u32 phyindex)
 	return NULL;
 }
 
+static inline struct phy_port *
+phy_link_topo_get_port(struct net_device *dev, u32 port_id)
+{
+	struct phy_link_topology *topo = dev->link_topo;
+
+	if (!topo)
+		return NULL;
+
+	/* ports in the topo are RTNL protected, but may be accessed under
+	 * netdev_lock for ops-locked devices. For now keep them under rtnl
+	 * protection, as no ops-locked devices have phy_port capabilities
+	 * yet.
+	 */
+	ASSERT_RTNL();
+
+	/* Caller must hold RTNL while handling the phy_port */
+	return xa_load(&topo->ports, port_id);
+}
+
 #else
 static inline int phy_link_topo_add_phy(struct net_device *dev,
 					struct phy_device *phy,
@@ -77,11 +104,28 @@ static inline void phy_link_topo_del_phy(struct net_device *dev,
 {
 }
 
+static inline int phy_link_topo_add_port(struct net_device *dev,
+					 struct phy_port *port)
+{
+	return 0;
+}
+
+static inline void phy_link_topo_del_port(struct net_device *dev,
+					  struct phy_port *port)
+{
+}
+
 static inline struct phy_device *
 phy_link_topo_get_phy(struct net_device *dev, u32 phyindex)
 {
 	return NULL;
 }
+
+static inline struct phy_port *
+phy_link_topo_get_port(struct net_device *dev, u32 port_id)
+{
+	return NULL;
+}
 #endif
 
 #endif /* __PHY_LINK_TOPOLOGY_H */
diff --git a/include/linux/phy_port.h b/include/linux/phy_port.h
index 0ef0f5ce47092..8f45c031cbc10 100644
--- a/include/linux/phy_port.h
+++ b/include/linux/phy_port.h
@@ -36,9 +36,12 @@ struct phy_port_ops {
 /**
  * struct phy_port - A representation of a network device physical interface
  *
+ * @id: Unique identifier for the port within the topology
  * @head: Used by the port's parent to list ports
  * @parent_type: The type of device this port is directly connected to
  * @phy: If the parent is PHY_PORT_PHYDEV, the PHY controlling that port
+ * @upstream_port: Indicates the MII port that feeds this port, if any,
+ *		   e.g. the SFP cage port for a SFP module port.
  * @ops: Callback ops implemented by the port controller
  * @pairs: The number of  pairs this port has, 0 if not applicable
  * @mediums: Bitmask of the physical mediums this port provides access to
@@ -52,11 +55,13 @@ struct phy_port_ops {
  * @is_sfp: Indicates if this port drives an SFP cage.
  */
 struct phy_port {
+	u32 id;
 	struct list_head head;
 	enum phy_port_parent parent_type;
 	union {
 		struct phy_device *phy;
 	};
+	struct phy_port *upstream_port;
 
 	const struct phy_port_ops *ops;
 
diff --git a/include/uapi/linux/ethtool_netlink_generated.h b/include/uapi/linux/ethtool_netlink_generated.h
index 8134baf7860f3..660e0c08a766a 100644
--- a/include/uapi/linux/ethtool_netlink_generated.h
+++ b/include/uapi/linux/ethtool_netlink_generated.h
@@ -78,6 +78,14 @@ enum ethtool_pse_event {
 	ETHTOOL_PSE_EVENT_SW_PW_CONTROL_ERROR = 64,
 };
 
+/*
+ * type of physical connector
+ */
+enum ethtool_port_type {
+	ETHTOOL_PORT_TYPE_MDI,
+	ETHTOOL_PORT_TYPE_SFP,
+};
+
 enum {
 	ETHTOOL_A_HEADER_UNSPEC,
 	ETHTOOL_A_HEADER_DEV_INDEX,
@@ -840,6 +848,18 @@ enum {
 	ETHTOOL_A_MSE_MAX = (__ETHTOOL_A_MSE_CNT - 1)
 };
 
+enum {
+	ETHTOOL_A_PORT_HEADER = 1,
+	ETHTOOL_A_PORT_ID,
+	ETHTOOL_A_PORT_SUPPORTED_MODES,
+	ETHTOOL_A_PORT_SUPPORTED_INTERFACES,
+	ETHTOOL_A_PORT_TYPE,
+	ETHTOOL_A_PORT_UPSTREAM_PORT,
+
+	__ETHTOOL_A_PORT_CNT,
+	ETHTOOL_A_PORT_MAX = (__ETHTOOL_A_PORT_CNT - 1)
+};
+
 enum {
 	ETHTOOL_MSG_USER_NONE = 0,
 	ETHTOOL_MSG_STRSET_GET = 1,
@@ -893,6 +913,7 @@ enum {
 	ETHTOOL_MSG_RSS_CREATE_ACT,
 	ETHTOOL_MSG_RSS_DELETE_ACT,
 	ETHTOOL_MSG_MSE_GET,
+	ETHTOOL_MSG_PORT_GET,
 
 	__ETHTOOL_MSG_USER_CNT,
 	ETHTOOL_MSG_USER_MAX = (__ETHTOOL_MSG_USER_CNT - 1)
@@ -954,6 +975,7 @@ enum {
 	ETHTOOL_MSG_RSS_CREATE_NTF,
 	ETHTOOL_MSG_RSS_DELETE_NTF,
 	ETHTOOL_MSG_MSE_GET_REPLY,
+	ETHTOOL_MSG_PORT_GET_REPLY,
 
 	__ETHTOOL_MSG_KERNEL_CNT,
 	ETHTOOL_MSG_KERNEL_MAX = (__ETHTOOL_MSG_KERNEL_CNT - 1)
diff --git a/net/core/dev.c b/net/core/dev.c
index 290e0f099e6bf..8c061df5b6a8f 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -11367,6 +11367,7 @@ static void netdev_free_phy_link_topology(struct net_device *dev)
 
 	if (IS_ENABLED(CONFIG_PHYLIB) && topo) {
 		xa_destroy(&topo->phys);
+		xa_destroy(&topo->ports);
 		kfree(topo);
 		dev->link_topo = NULL;
 	}
diff --git a/net/ethtool/Makefile b/net/ethtool/Makefile
index 629c10916670e..9b5b096700081 100644
--- a/net/ethtool/Makefile
+++ b/net/ethtool/Makefile
@@ -9,4 +9,4 @@ ethtool_nl-y	:= netlink.o bitset.o strset.o linkinfo.o linkmodes.o rss.o \
 		   channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o \
 		   tunnels.o fec.o eeprom.o stats.o phc_vclocks.o mm.o \
 		   module.o cmis_fw_update.o cmis_cdb.o pse-pd.o plca.o \
-		   phy.o tsconfig.o mse.o
+		   phy.o tsconfig.o mse.o port.o
diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c
index 1af395b54330e..c076c07d0a080 100644
--- a/net/ethtool/netlink.c
+++ b/net/ethtool/netlink.c
@@ -26,6 +26,8 @@ static u32 ethnl_bcast_seq;
 			     ETHTOOL_FLAG_OMIT_REPLY)
 #define ETHTOOL_FLAGS_STATS (ETHTOOL_FLAGS_BASIC | ETHTOOL_FLAG_STATS)
 
+char phy_interface_names[PHY_INTERFACE_MODE_MAX][ETH_GSTRING_LEN] __ro_after_init;
+
 const struct nla_policy ethnl_header_policy[] = {
 	[ETHTOOL_A_HEADER_DEV_INDEX]	= { .type = NLA_U32 },
 	[ETHTOOL_A_HEADER_DEV_NAME]	= { .type = NLA_NUL_STRING,
@@ -431,6 +433,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = {
 	[ETHTOOL_MSG_TSCONFIG_SET]	= &ethnl_tsconfig_request_ops,
 	[ETHTOOL_MSG_PHY_GET]		= &ethnl_phy_request_ops,
 	[ETHTOOL_MSG_MSE_GET]		= &ethnl_mse_request_ops,
+	[ETHTOOL_MSG_PORT_GET]		= &ethnl_port_request_ops,
 };
 
 static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb)
@@ -1572,6 +1575,15 @@ static const struct genl_ops ethtool_genl_ops[] = {
 		.policy = ethnl_mse_get_policy,
 		.maxattr = ARRAY_SIZE(ethnl_mse_get_policy) - 1,
 	},
+	{
+		.cmd	= ETHTOOL_MSG_PORT_GET,
+		.doit	= ethnl_default_doit,
+		.start	= ethnl_port_dump_start,
+		.dumpit	= ethnl_port_dumpit,
+		.done	= ethnl_port_dump_done,
+		.policy = ethnl_port_get_policy,
+		.maxattr = ARRAY_SIZE(ethnl_port_get_policy) - 1,
+	},
 };
 
 static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
@@ -1594,10 +1606,23 @@ static struct genl_family ethtool_genl_family __ro_after_init = {
 
 /* module setup */
 
+static void __init ethnl_phy_names_populate(void)
+{
+	const char *name;
+	int i;
+
+	for (i = 0; i < PHY_INTERFACE_MODE_MAX; i++) {
+		name = phy_modes(i);
+		strscpy(phy_interface_names[i], name, ETH_GSTRING_LEN);
+	}
+}
+
 static int __init ethnl_init(void)
 {
 	int ret;
 
+	ethnl_phy_names_populate();
+
 	ret = genl_register_family(&ethtool_genl_family);
 	if (WARN(ret < 0, "ethtool: genetlink family registration failed"))
 		return ret;
diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h
index 3e969a070f9fe..dc7211f67c4d5 100644
--- a/net/ethtool/netlink.h
+++ b/net/ethtool/netlink.h
@@ -5,11 +5,14 @@
 
 #include <linux/ethtool_netlink.h>
 #include <linux/netdevice.h>
+#include <linux/phy.h>
 #include <net/genetlink.h>
 #include <net/sock.h>
 
 struct ethnl_req_info;
 
+extern char phy_interface_names[PHY_INTERFACE_MODE_MAX][ETH_GSTRING_LEN];
+
 int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info,
 			       const struct nlattr *nest, struct net *net,
 			       struct netlink_ext_ack *extack,
@@ -474,6 +477,7 @@ extern const struct ethnl_request_ops ethnl_mm_request_ops;
 extern const struct ethnl_request_ops ethnl_phy_request_ops;
 extern const struct ethnl_request_ops ethnl_tsconfig_request_ops;
 extern const struct ethnl_request_ops ethnl_mse_request_ops;
+extern const struct ethnl_request_ops ethnl_port_request_ops;
 
 extern const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_FLAGS + 1];
 extern const struct nla_policy ethnl_header_policy_stats[ETHTOOL_A_HEADER_FLAGS + 1];
@@ -530,6 +534,7 @@ extern const struct nla_policy ethnl_phy_get_policy[ETHTOOL_A_PHY_HEADER + 1];
 extern const struct nla_policy ethnl_tsconfig_get_policy[ETHTOOL_A_TSCONFIG_HEADER + 1];
 extern const struct nla_policy ethnl_tsconfig_set_policy[ETHTOOL_A_TSCONFIG_MAX + 1];
 extern const struct nla_policy ethnl_mse_get_policy[ETHTOOL_A_MSE_HEADER + 1];
+extern const struct nla_policy ethnl_port_get_policy[ETHTOOL_A_PORT_ID + 1];
 
 int ethnl_set_features(struct sk_buff *skb, struct genl_info *info);
 int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info);
@@ -545,6 +550,9 @@ int ethnl_tsinfo_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
 int ethnl_tsinfo_done(struct netlink_callback *cb);
 int ethnl_rss_create_doit(struct sk_buff *skb, struct genl_info *info);
 int ethnl_rss_delete_doit(struct sk_buff *skb, struct genl_info *info);
+int ethnl_port_dump_start(struct netlink_callback *cb);
+int ethnl_port_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
+int ethnl_port_dump_done(struct netlink_callback *cb);
 
 extern const char stats_std_names[__ETHTOOL_STATS_CNT][ETH_GSTRING_LEN];
 extern const char stats_eth_phy_names[__ETHTOOL_A_STATS_ETH_PHY_CNT][ETH_GSTRING_LEN];
diff --git a/net/ethtool/port.c b/net/ethtool/port.c
new file mode 100644
index 0000000000000..0d6150e5f66a2
--- /dev/null
+++ b/net/ethtool/port.c
@@ -0,0 +1,382 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright 2026 Bootlin
+ */
+#include <linux/phy.h>
+#include <linux/phy_link_topology.h>
+#include <linux/phy_port.h>
+#include <net/netdev_lock.h>
+
+#include "bitset.h"
+#include "common.h"
+#include "netlink.h"
+
+struct port_req_info {
+	struct ethnl_req_info base;
+	u32 port_id;
+};
+
+struct port_reply_data {
+	struct ethnl_reply_data	base;
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
+	DECLARE_PHY_INTERFACE_MASK(interfaces);
+	u32 port_id;
+	bool mii;
+	bool sfp;
+	u32 upstream_port;
+};
+
+#define PORT_REQINFO(__req_base) \
+	container_of(__req_base, struct port_req_info, base)
+
+#define PORT_REPDATA(__reply_base) \
+	container_of(__reply_base, struct port_reply_data, base)
+
+const struct nla_policy ethnl_port_get_policy[ETHTOOL_A_PORT_ID + 1] = {
+	[ETHTOOL_A_PORT_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy),
+	[ETHTOOL_A_PORT_ID] = NLA_POLICY_MIN(NLA_U32, 1),
+};
+
+static int port_parse_request(struct ethnl_req_info *req_info,
+			      const struct genl_info *info,
+			      struct nlattr **tb,
+			      struct netlink_ext_ack *extack)
+{
+	struct port_req_info *request = PORT_REQINFO(req_info);
+
+	if (GENL_REQ_ATTR_CHECK(info, ETHTOOL_A_PORT_ID))
+		return -EINVAL;
+
+	request->port_id = nla_get_u32(tb[ETHTOOL_A_PORT_ID]);
+
+	return 0;
+}
+
+static int port_prepare_data(const struct ethnl_req_info *req_info,
+			     struct ethnl_reply_data *reply_data,
+			     const struct genl_info *info)
+{
+	struct port_reply_data *reply = PORT_REPDATA(reply_data);
+	struct port_req_info *request = PORT_REQINFO(req_info);
+	struct phy_port *port;
+
+	/* RTNL must be held while holding a ref to the phy_port. Here, caller
+	 * holds RTNL.
+	 */
+	port = phy_link_topo_get_port(req_info->dev, request->port_id);
+	if (!port)
+		return -ENODEV;
+
+	linkmode_copy(reply->supported, port->supported);
+	phy_interface_copy(reply->interfaces, port->interfaces);
+	reply->port_id = port->id;
+	reply->mii = port->is_mii;
+	reply->sfp = port->is_sfp;
+	reply->upstream_port = port->upstream_port ? port->upstream_port->id : 0;
+
+	return 0;
+}
+
+static int port_reply_size(const struct ethnl_req_info *req_info,
+			   const struct ethnl_reply_data *reply_data)
+{
+	bool compact = req_info->flags & ETHTOOL_FLAG_COMPACT_BITSETS;
+	struct port_reply_data *reply = PORT_REPDATA(reply_data);
+	size_t size = 0;
+	int ret;
+
+	/* ETHTOOL_A_PORT_ID */
+	size += nla_total_size(sizeof(u32));
+
+	if (!reply->mii) {
+		/* ETHTOOL_A_PORT_SUPPORTED_MODES */
+		ret = ethnl_bitset_size(reply->supported, NULL,
+					__ETHTOOL_LINK_MODE_MASK_NBITS,
+					link_mode_names, compact);
+		if (ret < 0)
+			return ret;
+
+		size += ret;
+	} else {
+		/* ETHTOOL_A_PORT_SUPPORTED_INTERFACES */
+		ret = ethnl_bitset_size(reply->interfaces, NULL,
+					PHY_INTERFACE_MODE_MAX,
+					phy_interface_names, compact);
+		if (ret < 0)
+			return ret;
+
+		size += ret;
+	}
+
+	/* ETHTOOL_A_PORT_TYPE */
+	size += nla_total_size(sizeof(u32));
+
+	/* ETHTOOL_A_PORT_UPSTREAM_PORT */
+	if (reply->upstream_port)
+		size += nla_total_size(sizeof(u32));
+
+	return size;
+}
+
+static int port_fill_reply(struct sk_buff *skb,
+			   const struct ethnl_req_info *req_info,
+			   const struct ethnl_reply_data *reply_data)
+{
+	bool compact = req_info->flags & ETHTOOL_FLAG_COMPACT_BITSETS;
+	struct port_reply_data *reply = PORT_REPDATA(reply_data);
+	int ret, port_type = ETHTOOL_PORT_TYPE_MDI;
+
+	if (nla_put_u32(skb, ETHTOOL_A_PORT_ID, reply->port_id))
+		return -EMSGSIZE;
+
+	if (!reply->mii) {
+		ret = ethnl_put_bitset(skb, ETHTOOL_A_PORT_SUPPORTED_MODES,
+				       reply->supported, NULL,
+				       __ETHTOOL_LINK_MODE_MASK_NBITS,
+				       link_mode_names, compact);
+		if (ret < 0)
+			return ret;
+	} else {
+		ret = ethnl_put_bitset(skb, ETHTOOL_A_PORT_SUPPORTED_INTERFACES,
+				       reply->interfaces, NULL,
+				       PHY_INTERFACE_MODE_MAX,
+				       phy_interface_names, compact);
+		if (ret < 0)
+			return ret;
+	}
+
+	if (reply->mii || reply->sfp)
+		port_type = ETHTOOL_PORT_TYPE_SFP;
+
+	if (nla_put_u32(skb, ETHTOOL_A_PORT_TYPE, port_type))
+		return -EMSGSIZE;
+
+	if (reply->upstream_port &&
+	    nla_put_u32(skb, ETHTOOL_A_PORT_UPSTREAM_PORT,
+			reply->upstream_port))
+		return -EMSGSIZE;
+
+	return 0;
+}
+
+struct port_dump_ctx {
+	struct port_req_info	*req_info;
+	struct port_reply_data	*reply_data;
+	unsigned long		ifindex;
+	unsigned long		pos_ifindex;
+	unsigned long		pos_portid;
+};
+
+static struct port_dump_ctx *
+port_dump_ctx_get(struct netlink_callback *cb)
+{
+	return (struct port_dump_ctx *)cb->ctx;
+}
+
+int ethnl_port_dump_start(struct netlink_callback *cb)
+{
+	const struct genl_dumpit_info *info = genl_dumpit_info(cb);
+	struct port_dump_ctx *ctx = port_dump_ctx_get(cb);
+	struct nlattr **tb = info->info.attrs;
+	struct port_reply_data *reply_data;
+	struct port_req_info *req_info;
+	int ret;
+
+	BUILD_BUG_ON(sizeof(*ctx) > sizeof(cb->ctx));
+
+	req_info = kzalloc_obj(*req_info);
+	if (!req_info)
+		return -ENOMEM;
+
+	reply_data = kmalloc_obj(*reply_data);
+	if (!reply_data) {
+		ret = -ENOMEM;
+		goto free_req_info;
+	}
+
+	ret = ethnl_parse_header_dev_get(&req_info->base, tb[ETHTOOL_A_PORT_HEADER],
+					 genl_info_net(&info->info),
+					 info->info.extack, false);
+	if (ret < 0)
+		goto free_rep_data;
+
+	ctx->ifindex = 0;
+	ctx->pos_ifindex = 0;
+
+	/* For filtered DUMP requests, let's just store the ifindex. We'll check
+	 * again if the netdev is still there when looping over the netdev list
+	 * in the DUMP loop.
+	 */
+	if (req_info->base.dev) {
+		ctx->ifindex = req_info->base.dev->ifindex;
+		netdev_put(req_info->base.dev, &req_info->base.dev_tracker);
+		req_info->base.dev = NULL;
+	}
+
+	ctx->req_info = req_info;
+	ctx->reply_data = reply_data;
+
+	return 0;
+
+free_rep_data:
+	kfree(reply_data);
+free_req_info:
+	kfree(req_info);
+
+	return ret;
+}
+
+static int port_dump_one(struct sk_buff *skb, struct net_device *dev,
+			 struct netlink_callback *cb)
+{
+	struct port_dump_ctx *ctx = port_dump_ctx_get(cb);
+	void *ehdr;
+	int ret;
+
+	ehdr = ethnl_dump_put(skb, cb, ETHTOOL_MSG_PORT_GET_REPLY);
+	if (!ehdr)
+		return -EMSGSIZE;
+
+	memset(ctx->reply_data, 0, sizeof(struct port_reply_data));
+	ctx->reply_data->base.dev = dev;
+
+	rtnl_lock();
+	netdev_lock_ops(dev);
+
+	ret = port_prepare_data(&ctx->req_info->base, &ctx->reply_data->base,
+				genl_info_dump(cb));
+
+	netdev_unlock_ops(dev);
+	rtnl_unlock();
+
+	if (ret < 0)
+		goto out;
+
+	ret = ethnl_fill_reply_header(skb, dev, ETHTOOL_A_PORT_HEADER);
+	if (ret < 0)
+		goto out;
+
+	ret = port_fill_reply(skb, &ctx->req_info->base, &ctx->reply_data->base);
+
+out:
+	ctx->reply_data->base.dev = NULL;
+	if (ret < 0)
+		genlmsg_cancel(skb, ehdr);
+	else
+		genlmsg_end(skb, ehdr);
+
+	return ret;
+}
+
+static int port_dump_one_dev(struct sk_buff *skb, struct netlink_callback *cb)
+{
+	struct port_dump_ctx *ctx = port_dump_ctx_get(cb);
+	struct net_device *dev;
+	struct phy_port *port;
+	int ret;
+
+	dev = ctx->req_info->base.dev;
+
+	if (!dev->link_topo)
+		return 0;
+
+	xa_for_each_start(&dev->link_topo->ports, ctx->pos_portid, port,
+			  ctx->pos_portid) {
+		ctx->req_info->port_id = ctx->pos_portid;
+
+		ret = port_dump_one(skb, dev, cb);
+		if (ret == -ENODEV)
+			continue;
+		if (ret)
+			return ret;
+	}
+
+	ctx->pos_portid = 0;
+
+	return 0;
+}
+
+static int port_dump_all_dev(struct sk_buff *skb, struct netlink_callback *cb)
+{
+	struct port_dump_ctx *ctx = port_dump_ctx_get(cb);
+	struct net *net = sock_net(skb->sk);
+	netdevice_tracker dev_tracker;
+	struct net_device *dev;
+	int ret = 0;
+
+	rcu_read_lock();
+	for_each_netdev_dump(net, dev, ctx->pos_ifindex) {
+		netdev_hold(dev, &dev_tracker, GFP_ATOMIC);
+		rcu_read_unlock();
+
+		ctx->req_info->base.dev = dev;
+		ret = port_dump_one_dev(skb, cb);
+
+		rcu_read_lock();
+		netdev_put(dev, &dev_tracker);
+		ctx->req_info->base.dev = NULL;
+
+		if (ret < 0 && ret != -EOPNOTSUPP) {
+			if (likely(skb->len))
+				ret = skb->len;
+			break;
+		}
+
+		ret = 0;
+	}
+	rcu_read_unlock();
+
+	return ret;
+}
+
+int ethnl_port_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
+{
+	const struct genl_dumpit_info *info = genl_dumpit_info(cb);
+	struct port_dump_ctx *ctx = port_dump_ctx_get(cb);
+	int ret = 0;
+
+	if (ctx->ifindex) {
+		netdevice_tracker dev_tracker;
+		struct net_device *dev;
+
+		dev = netdev_get_by_index(genl_info_net(&info->info),
+					  ctx->ifindex, &dev_tracker,
+					  GFP_KERNEL);
+		if (!dev)
+			return -ENODEV;
+
+		ctx->req_info->base.dev = dev;
+		ret = port_dump_one_dev(skb, cb);
+		if (ret < 0 && ret != -EOPNOTSUPP && likely(skb->len))
+			ret = skb->len;
+
+		netdev_put(dev, &dev_tracker);
+	} else {
+		ret = port_dump_all_dev(skb, cb);
+	}
+
+	return ret;
+}
+
+int ethnl_port_dump_done(struct netlink_callback *cb)
+{
+	struct port_dump_ctx *ctx = port_dump_ctx_get(cb);
+
+	kfree(ctx->req_info);
+	kfree(ctx->reply_data);
+
+	return 0;
+}
+
+const struct ethnl_request_ops ethnl_port_request_ops = {
+	.request_cmd		= ETHTOOL_MSG_PORT_GET,
+	.reply_cmd		= ETHTOOL_MSG_PORT_GET_REPLY,
+	.hdr_attr		= ETHTOOL_A_PORT_HEADER,
+	.req_info_size		= sizeof(struct port_req_info),
+	.reply_data_size	= sizeof(struct port_reply_data),
+
+	.parse_request		= port_parse_request,
+	.prepare_data		= port_prepare_data,
+	.reply_size		= port_reply_size,
+	.fill_reply		= port_fill_reply,
+};

3/2 2026/09/10 19:11 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 21686
							output: 38
							thoughts: 721
						

Thoughts:
**Analyzing the ethtool Port Query Patch for Fuzzing**

Alright, let's break down this patch and see if it's worth our time to fuzz. First, I need to understand what this thing actually *does*. It looks like it's adding a `PORT_GET` netlink command to ethtool, allowing userspace to query the physical ports attached to network interfaces using generic netlink (`ETHTOOL_MSG_PORT_GET`). Okay, that's interesting. Sounds like a good target.

The changes are all over the place, but mainly centered around documentation, and the `drivers/net/phy` directory. It's touching `phy_caps.c`, `phy_device.c`, `phy_link_topology.c`, and `phylink.c` – a good sign that there's new topology and port handling code. It also includes new header files and updates `dev.c` to free topology ports. And of course there are all the ethtool netlink changes in `net/ethtool/`. This is quite a bit of code, spanning PHY drivers and netlink interfaces.

Now, the crucial question: Is this reachable code? Absolutely. Anyone with access to the kernel can create netlink sockets, send those `ETHTOOL_MSG_PORT_GET` requests, and trigger those handlers, both privileged and unprivileged. We're looking at a user-space controllable interface, perfect for fuzzing. We have new netlink command handlers like `port_prepare_data`, `port_fill_reply`, and `ethnl_port_dumpit` along with other PHY specific functions. This should be a goldmine. We could even get a nice fuzzer harness going.

Next step: Kconfig and symbols. I'll need to figure out the dependencies to be able to build a test kernel. Let's fire up `grepper` and see what it turns up, or just check the Kconfig files. Time to get my hands dirty.



4/2 2026/09/10 19:11 tool grepper
0m Args:
{
  "Expression": "CONFIG_ETHTOOL_NETLINK|CONFIG_PHYLIB",
  "PathPrefix": "net/ethtool"
}

Results:
{
  "Output": "net/ethtool/Makefile=3=obj-y\t\t\t\t+= ioctl.o common.o\nnet/ethtool/Makefile-4-\nnet/ethtool/Makefile:5:obj-$(CONFIG_ETHTOOL_NETLINK)\t+= ethtool_nl.o\nnet/ethtool/Makefile-6-\n--\nnet/ethtool/common.h=138=ethtool_ioctl_needs_rtnl(const struct net_device *dev, u32 ethcmd)\n--\nnet/ethtool/common.h-169-\nnet/ethtool/common.h:170:#if IS_ENABLED(CONFIG_ETHTOOL_NETLINK)\nnet/ethtool/common.h-171-void ethtool_rss_notify(struct net_device *dev, u32 type, u32 rss_context);\n"
}

5/2 2026/09/10 19:11 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 23092
							output: 21
							thoughts: 44
						

Thoughts:
Here's my thought process, as requested:

**Investigating Network Configuration Dependencies**

Okay, so I need to track down where `CONFIG_ETHTOOL_NETLINK` and `CONFIG_PHYLIB` are defined in the kernel configuration. I'm pretty sure they're related to networking features, so my first instinct is to look within the `net/` directory. Given the scope, it's likely they are defined in either the core `net/Kconfig` or possibly a more specific `net/ethtool/Kconfig` file, as the latter seems a logical place to house ethtool-related settings. It's a structured approach, start with the most likely and work outwards if needed, to pinpoint the definitive locations of these configurations.



6/2 2026/09/10 19:11 tool grepper
0m Args:
{
  "Expression": "config ETHTOOL_NETLINK"
}

Results:
{
  "Output": "net/Kconfig=507=config FAILOVER\n--\nnet/Kconfig-519-\nnet/Kconfig:520:config ETHTOOL_NETLINK\nnet/Kconfig-521-\tbool \"Netlink interface for ethtool\"\n"
}

7/2 2026/09/10 19:11 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 23394
							output: 32
							thoughts: 17
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Diving into the Kernel Configuration Landscape**

Okay, so I'm thinking, where's the most likely place to find information about that particular configuration option? Let's zoom in on `net/Kconfig`, specifically around line 520. That's usually where the core network-related configurations tend to cluster. I'm expecting to find the definition, potentially some dependencies, maybe even some help text that'll refresh my memory. This should be a quick way to understand the relationships between options in that area of the network subsystem, or at least quickly rule out that specific option.



8/2 2026/09/10 19:11 tool read-file
0m Args:
{
  "File": "net/Kconfig",
  "FirstLine": 515,
  "LineCount": 25
}

Results:
{
  "Contents": " 515:\t\t  failover netdev. This enables paravirtual drivers to use a\n 516:\t\t  VF as an accelerated low latency datapath. It also allows live\n 517:\t\t  migration of VMs with direct attached VFs by failing over to the\n 518:\t\t  paravirtual datapath when the VF is unplugged.\n 519:\t\n 520:\tconfig ETHTOOL_NETLINK\n 521:\t\tbool \"Netlink interface for ethtool\"\n 522:\t\tselect DIMLIB\n 523:\t\tdefault y\n 524:\t\thelp\n 525:\t\t  An alternative userspace interface for ethtool based on generic\n 526:\t\t  netlink. It provides better extensibility and some new features,\n 527:\t\t  e.g. notification messages.\n 528:\t\n 529:\tconfig NETDEV_ADDR_LIST_TEST\n 530:\t\ttristate \"Unit tests for device address list\"\n 531:\t\tdefault KUNIT_ALL_TESTS\n 532:\t\tdepends on KUNIT\n 533:\t\n 534:\tconfig NET_TEST\n 535:\t\ttristate \"KUnit tests for networking\" if !KUNIT_ALL_TESTS\n 536:\t\tdepends on KUNIT\n 537:\t\tdefault KUNIT_ALL_TESTS\n 538:\t\thelp\n 539:\t\t  KUnit tests covering core networking infra, such as sk_buff.\n"
}

9/2 2026/09/10 19:11 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 23971
							output: 37
							thoughts: 24
						

Thoughts:
Here's my take on the thought process, as if it were my own:

**Kconfig Configuration Deep Dive**

Okay, time to get my hands dirty. I need to make sure the network setup is configured correctly. First, I'm going to jump into the `Kconfig` files – specifically, I'm thinking about the low-level PHY (Physical Layer) stuff. Let's see... I need to verify that the `PHYLIB` and `PHYLINK` options are set appropriately. I need to ensure they're enabled, and that they match the hardware I'm using, as well as considering any potential dependencies with the specific networking stack being implemented. Then, it's also worth checking the `SFP` (Small Form-factor Pluggable) configuration. This is crucial if I'm using any SFP modules – I need to ensure the driver is enabled, and that any relevant settings for speed or transceiver type are set according to what is specified by the system. I have to think about every detail to avoid running into problems during bring-up. It's all about ensuring the hardware is correctly recognized, configured, and managed by the kernel.



10/2 2026/09/10 19:11 tool grepper
0m Args:
{
  "Expression": "config (PHYLIB|PHYLINK|SFP)",
  "PathPrefix": "drivers/net/phy"
}

Results:
{
  "Output": "drivers/net/phy/Kconfig-5-\ndrivers/net/phy/Kconfig:6:config PHYLINK\ndrivers/net/phy/Kconfig-7-\ttristate\n--\ndrivers/net/phy/Kconfig-14-\ndrivers/net/phy/Kconfig:15:menuconfig PHYLIB\ndrivers/net/phy/Kconfig-16-\ttristate \"PHY Device support and infrastructure\"\n--\ndrivers/net/phy/Kconfig=46=config OPEN_ALLIANCE_HELPERS\n--\ndrivers/net/phy/Kconfig-48-\ndrivers/net/phy/Kconfig:49:config PHYLIB_LEDS\ndrivers/net/phy/Kconfig-50-\tdef_bool OF\n--\ndrivers/net/phy/Kconfig=65=config RUST_PHYLIB_ABSTRACTIONS\n--\ndrivers/net/phy/Kconfig-72-\ndrivers/net/phy/Kconfig:73:config SFP\ndrivers/net/phy/Kconfig-74-\ttristate \"SFP cage support\"\n"
}

11/2 2026/09/10 19:11 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 24546
							output: 38
							thoughts: 44
						

Thoughts:
Here's my take on those thoughts:

**Investigating the PHY Build Process**

Okay, so I need to understand how the PHY-related code is compiled, specifically how `phy_link_topology.c`, `phy_port.c`, and `phy_caps.c` are integrated into the build process. My instinct tells me the best starting point is likely the `drivers/net/phy/Makefile`. That file should contain the necessary rules and dependencies that dictate how these specific PHY modules are built within the larger networking subsystem. It's the Makefile that tells the kernel build system where to find source files, what dependencies they have, and how to compile and link them. This is the logical place to start digging into the build configuration. Let's see what that file reveals... I'm hoping it's straightforward!



12/2 2026/09/10 19:11 tool grepper
0m Args:
{
  "Expression": "phy_link_topology|phy_port|phy_caps",
  "PathPrefix": "drivers/net/phy"
}

Results:
{
  "Output": "\nFull output is too long, showing 500 out of 755 lines.\nUse more precise expression if possible.\n\ndrivers/net/phy/Makefile=4=libphy-y\t\t\t:= phy.o phy-c45.o phy-core.o phy_device.o \\\ndrivers/net/phy/Makefile:5:\t\t\t\t   linkmode.o phy_link_topology.o \\\ndrivers/net/phy/Makefile:6:\t\t\t\t   phy_caps.o mdio_bus_provider.o phy_port.o \\\ndrivers/net/phy/Makefile-7-\t\t\t\t   mdio_device.o\n--\ndrivers/net/phy/dp83822.c-14-#include \u003clinux/phy.h\u003e\ndrivers/net/phy/dp83822.c:15:#include \u003clinux/phy_port.h\u003e\ndrivers/net/phy/dp83822.c-16-#include \u003clinux/netdevice.h\u003e\n--\ndrivers/net/phy/dp83822.c=944=static int dp83822_attach_mdi_port(struct phy_device *phydev,\ndrivers/net/phy/dp83822.c:945:\t\t\t\t   struct phy_port *port)\ndrivers/net/phy/dp83822.c-946-{\n--\ndrivers/net/phy/dp83822.c-950-\tif (port-\u003emediums) {\ndrivers/net/phy/dp83822.c:951:\t\tif (phy_port_is_fiber(port))\ndrivers/net/phy/dp83822.c-952-\t\t\tdp83822-\u003efx_enabled = true;\n--\ndrivers/net/phy/marvell-88x2222.c-15-#include \u003clinux/of.h\u003e\ndrivers/net/phy/marvell-88x2222.c:16:#include \u003clinux/phy_port.h\u003e\ndrivers/net/phy/marvell-88x2222.c-17-#include \u003clinux/netdevice.h\u003e\n--\ndrivers/net/phy/marvell-88x2222.c=468=static int mv2222_config_init(struct phy_device *phydev)\n--\ndrivers/net/phy/marvell-88x2222.c-475-\ndrivers/net/phy/marvell-88x2222.c:476:static int mv2222_configure_serdes(struct phy_port *port, bool enable,\ndrivers/net/phy/marvell-88x2222.c-477-\t\t\t\t   phy_interface_t interface)\n--\ndrivers/net/phy/marvell-88x2222.c-504-\ndrivers/net/phy/marvell-88x2222.c:505:static void mv2222_port_link_up(struct phy_port *port)\ndrivers/net/phy/marvell-88x2222.c-506-{\n--\ndrivers/net/phy/marvell-88x2222.c-513-\ndrivers/net/phy/marvell-88x2222.c:514:static void mv2222_port_link_down(struct phy_port *port)\ndrivers/net/phy/marvell-88x2222.c-515-{\n--\ndrivers/net/phy/marvell-88x2222.c-522-\ndrivers/net/phy/marvell-88x2222.c:523:static const struct phy_port_ops mv2222_port_ops = {\ndrivers/net/phy/marvell-88x2222.c-524-\t.link_up = mv2222_port_link_up,\n--\ndrivers/net/phy/marvell-88x2222.c-528-\ndrivers/net/phy/marvell-88x2222.c:529:static int mv2222_attach_mii_port(struct phy_device *phydev, struct phy_port *port)\ndrivers/net/phy/marvell-88x2222.c-530-{\n--\ndrivers/net/phy/marvell.c-31-#include \u003clinux/phy.h\u003e\ndrivers/net/phy/marvell.c:32:#include \u003clinux/phy_port.h\u003e\ndrivers/net/phy/marvell.c-33-#include \u003clinux/marvell_phy.h\u003e\n--\ndrivers/net/phy/marvell.c=3588=static int marvell_probe(struct phy_device *phydev)\n--\ndrivers/net/phy/marvell.c-3600-\ndrivers/net/phy/marvell.c:3601:static int m88e1510_port_configure_serdes(struct phy_port *port, bool enable,\ndrivers/net/phy/marvell.c-3602-\t\t\t\t\t  phy_interface_t interface)\n--\ndrivers/net/phy/marvell.c-3650-\ndrivers/net/phy/marvell.c:3651:static const struct phy_port_ops m88e1510_serdes_port_ops = {\ndrivers/net/phy/marvell.c-3652-\t.configure_mii = m88e1510_port_configure_serdes,\n--\ndrivers/net/phy/marvell.c=3655=static int m88e1510_attach_mii_port(struct phy_device *phy_device,\ndrivers/net/phy/marvell.c:3656:\t\t\t\t    struct phy_port *port)\ndrivers/net/phy/marvell.c-3657-{\n--\ndrivers/net/phy/marvell10g.c-30-#include \u003clinux/phy.h\u003e\ndrivers/net/phy/marvell10g.c:31:#include \u003clinux/phy_port.h\u003e\ndrivers/net/phy/marvell10g.c-32-#include \u003clinux/netdevice.h\u003e\n--\ndrivers/net/phy/marvell10g.c=466=static int mv3310_attach_mii_port(struct phy_device *phydev,\ndrivers/net/phy/marvell10g.c:467:\t\t\t\t  struct phy_port *port)\ndrivers/net/phy/marvell10g.c-468-{\n--\ndrivers/net/phy/marvell10g.c=473=static int mv3310_attach_mdi_port(struct phy_device *phydev,\ndrivers/net/phy/marvell10g.c:474:\t\t\t\t  struct phy_port *port)\ndrivers/net/phy/marvell10g.c-475-{\n--\ndrivers/net/phy/marvell10g.c-482-\tif (port-\u003enot_described)\ndrivers/net/phy/marvell10g.c:483:\t\treturn phy_port_restrict_mediums(port,\ndrivers/net/phy/marvell10g.c-484-\t\t\t\t\t\t BIT(ETHTOOL_LINK_MEDIUM_BASET));\n--\ndrivers/net/phy/phy-caps.h=40=struct link_capabilities {\n--\ndrivers/net/phy/phy-caps.h-45-\ndrivers/net/phy/phy-caps.h:46:int __init phy_caps_init(void);\ndrivers/net/phy/phy-caps.h-47-\ndrivers/net/phy/phy-caps.h:48:size_t phy_caps_speeds(unsigned int *speeds, size_t size,\ndrivers/net/phy/phy-caps.h-49-\t\t       unsigned long *linkmodes);\ndrivers/net/phy/phy-caps.h:50:void phy_caps_linkmode_max_speed(u32 max_speed, unsigned long *linkmodes);\ndrivers/net/phy/phy-caps.h:51:bool phy_caps_valid(int speed, int duplex, const unsigned long *linkmodes);\ndrivers/net/phy/phy-caps.h:52:void phy_caps_linkmodes(unsigned long caps, unsigned long *linkmodes);\ndrivers/net/phy/phy-caps.h:53:unsigned long phy_caps_from_interface(phy_interface_t interface);\ndrivers/net/phy/phy-caps.h-54-\ndrivers/net/phy/phy-caps.h=55=const struct link_capabilities *\ndrivers/net/phy/phy-caps.h:56:phy_caps_lookup_by_linkmode(const unsigned long *linkmodes);\ndrivers/net/phy/phy-caps.h-57-\ndrivers/net/phy/phy-caps.h=58=const struct link_capabilities *\ndrivers/net/phy/phy-caps.h:59:phy_caps_lookup_by_linkmode_rev(const unsigned long *linkmodes, bool fdx_only);\ndrivers/net/phy/phy-caps.h-60-\ndrivers/net/phy/phy-caps.h=61=const struct link_capabilities *\ndrivers/net/phy/phy-caps.h:62:phy_caps_lookup(int speed, unsigned int duplex, const unsigned long *supported,\ndrivers/net/phy/phy-caps.h-63-\t\tbool exact);\ndrivers/net/phy/phy-caps.h-64-\ndrivers/net/phy/phy-caps.h:65:void phy_caps_medium_get_supported(unsigned long *supported,\ndrivers/net/phy/phy-caps.h-66-\t\t\t\t   enum ethtool_link_medium medium,\ndrivers/net/phy/phy-caps.h-67-\t\t\t\t   int lanes);\ndrivers/net/phy/phy-caps.h:68:u32 phy_caps_mediums_from_linkmodes(unsigned long *linkmodes);\ndrivers/net/phy/phy-caps.h:69:void phy_caps_linkmode_filter_ifaces(unsigned long *to, const unsigned long *from,\ndrivers/net/phy/phy-caps.h-70-\t\t\t\t     const unsigned long *interfaces);\n--\ndrivers/net/phy/phy-core.c-6-#include \u003clinux/phy.h\u003e\ndrivers/net/phy/phy-core.c:7:#include \u003clinux/phy_port.h\u003e\ndrivers/net/phy/phy-core.c-8-#include \u003clinux/of.h\u003e\n--\ndrivers/net/phy/phy-core.c=212=static void __set_phy_supported(struct phy_device *phydev, u32 max_speed)\ndrivers/net/phy/phy-core.c-213-{\ndrivers/net/phy/phy-core.c:214:\tstruct phy_port *port;\ndrivers/net/phy/phy-core.c-215-\ndrivers/net/phy/phy-core.c:216:\tphy_caps_linkmode_max_speed(max_speed, phydev-\u003esupported);\ndrivers/net/phy/phy-core.c-217-\ndrivers/net/phy/phy-core.c-218-\tphy_for_each_port(phydev, port)\ndrivers/net/phy/phy-core.c:219:\t\tphy_caps_linkmode_max_speed(max_speed, port-\u003esupported);\ndrivers/net/phy/phy-core.c-220-}\n--\ndrivers/net/phy/phy-core.c=342=void phy_resolve_aneg_linkmode(struct phy_device *phydev)\n--\ndrivers/net/phy/phy-core.c-348-\ndrivers/net/phy/phy-core.c:349:\tc = phy_caps_lookup_by_linkmode(common);\ndrivers/net/phy/phy-core.c-350-\tif (c) {\n--\ndrivers/net/phy/phy-core.c=368=void phy_check_downshift(struct phy_device *phydev)\n--\ndrivers/net/phy/phy-core.c-381-\ndrivers/net/phy/phy-core.c:382:\tc = phy_caps_lookup_by_linkmode(common);\ndrivers/net/phy/phy-core.c-383-\tif (c)\n--\ndrivers/net/phy/phy-core.c=395=static int phy_resolve_min_speed(struct phy_device *phydev, bool fdx_only)\n--\ndrivers/net/phy/phy-core.c-401-\ndrivers/net/phy/phy-core.c:402:\tc = phy_caps_lookup_by_linkmode_rev(common, fdx_only);\ndrivers/net/phy/phy-core.c-403-\tif (c)\n--\ndrivers/net/phy/phy-core.c=409=int phy_speed_down_core(struct phy_device *phydev)\n--\ndrivers/net/phy/phy-core.c-415-\ndrivers/net/phy/phy-core.c:416:\tphy_caps_linkmode_max_speed(min_common_speed, phydev-\u003eadvertising);\ndrivers/net/phy/phy-core.c-417-\n--\ndrivers/net/phy/phy.c=226=unsigned int phy_supported_speeds(struct phy_device *phy,\n--\ndrivers/net/phy/phy.c-229-{\ndrivers/net/phy/phy.c:230:\treturn phy_caps_speeds(speeds, size, phy-\u003esupported);\ndrivers/net/phy/phy.c-231-}\n--\ndrivers/net/phy/phy.c=242=bool phy_check_valid(int speed, int duplex, unsigned long *features)\ndrivers/net/phy/phy.c-243-{\ndrivers/net/phy/phy.c:244:\treturn phy_caps_valid(speed, duplex, features);\ndrivers/net/phy/phy.c-245-}\n--\ndrivers/net/phy/phy.c=256=static void phy_sanitize_settings(struct phy_device *phydev)\n--\ndrivers/net/phy/phy.c-259-\ndrivers/net/phy/phy.c:260:\tc = phy_caps_lookup(phydev-\u003espeed, phydev-\u003eduplex, phydev-\u003esupported,\ndrivers/net/phy/phy.c-261-\t\t\t    false);\n--\ndrivers/net/phy/phy_caps.c=32=static int speed_duplex_to_capa(int speed, unsigned int duplex)\n--\ndrivers/net/phy/phy_caps.c-70-/**\ndrivers/net/phy/phy_caps.c:71: * phy_caps_init() - Initializes the link_caps array from the link_mode_params.\ndrivers/net/phy/phy_caps.c-72- *\n--\ndrivers/net/phy/phy_caps.c-76- */\ndrivers/net/phy/phy_caps.c:77:int __init phy_caps_init(void)\ndrivers/net/phy/phy_caps.c-78-{\n--\ndrivers/net/phy/phy_caps.c-110-/**\ndrivers/net/phy/phy_caps.c:111: * phy_caps_speeds() - Fill an array of supported SPEED_* values for given modes\ndrivers/net/phy/phy_caps.c-112- * @speeds: Output array to store the speeds list into\n--\ndrivers/net/phy/phy_caps.c-121- */\ndrivers/net/phy/phy_caps.c:122:size_t phy_caps_speeds(unsigned int *speeds, size_t size,\ndrivers/net/phy/phy_caps.c-123-\t\t       unsigned long *linkmodes)\n--\ndrivers/net/phy/phy_caps.c-140-/**\ndrivers/net/phy/phy_caps.c:141: * phy_caps_lookup_by_linkmode() - Lookup the fastest matching link_capabilities\ndrivers/net/phy/phy_caps.c-142- * @linkmodes: Linkmodes to match against\n--\ndrivers/net/phy/phy_caps.c=148=const struct link_capabilities *\ndrivers/net/phy/phy_caps.c:149:phy_caps_lookup_by_linkmode(const unsigned long *linkmodes)\ndrivers/net/phy/phy_caps.c-150-{\n--\ndrivers/net/phy/phy_caps.c-160-/**\ndrivers/net/phy/phy_caps.c:161: * phy_caps_lookup_by_linkmode_rev() - Lookup the slowest matching link_capabilities\ndrivers/net/phy/phy_caps.c-162- * @linkmodes: Linkmodes to match against\n--\ndrivers/net/phy/phy_caps.c=169=const struct link_capabilities *\ndrivers/net/phy/phy_caps.c:170:phy_caps_lookup_by_linkmode_rev(const unsigned long *linkmodes, bool fdx_only)\ndrivers/net/phy/phy_caps.c-171-{\n--\ndrivers/net/phy/phy_caps.c-185-/**\ndrivers/net/phy/phy_caps.c:186: * phy_caps_lookup() - Lookup capabilities by speed/duplex that matches a mask\ndrivers/net/phy/phy_caps.c-187- * @speed: Speed to match\n--\ndrivers/net/phy/phy_caps.c=209=const struct link_capabilities *\ndrivers/net/phy/phy_caps.c:210:phy_caps_lookup(int speed, unsigned int duplex, const unsigned long *supported,\ndrivers/net/phy/phy_caps.c-211-\t\tbool exact)\n--\ndrivers/net/phy/phy_caps.c-235-}\ndrivers/net/phy/phy_caps.c:236:EXPORT_SYMBOL_GPL(phy_caps_lookup);\ndrivers/net/phy/phy_caps.c-237-\ndrivers/net/phy/phy_caps.c-238-/**\ndrivers/net/phy/phy_caps.c:239: * phy_caps_linkmode_max_speed() - Clamp a linkmodes set to a max speed\ndrivers/net/phy/phy_caps.c-240- * @max_speed: Speed limit for the linkmode set\n--\ndrivers/net/phy/phy_caps.c-242- */\ndrivers/net/phy/phy_caps.c:243:void phy_caps_linkmode_max_speed(u32 max_speed, unsigned long *linkmodes)\ndrivers/net/phy/phy_caps.c-244-{\n--\ndrivers/net/phy/phy_caps.c-254-/**\ndrivers/net/phy/phy_caps.c:255: * phy_caps_valid() - Validate a linkmodes set agains given speed and duplex\ndrivers/net/phy/phy_caps.c-256- * @speed: input speed to validate\n--\ndrivers/net/phy/phy_caps.c-262- */\ndrivers/net/phy/phy_caps.c:263:bool phy_caps_valid(int speed, int duplex, const unsigned long *linkmodes)\ndrivers/net/phy/phy_caps.c-264-{\n--\ndrivers/net/phy/phy_caps.c-273-/**\ndrivers/net/phy/phy_caps.c:274: * phy_caps_linkmodes() - Convert a bitfield of capabilities into linkmodes\ndrivers/net/phy/phy_caps.c-275- * @caps: The list of caps, each bit corresponding to a LINK_CAPA value\n--\ndrivers/net/phy/phy_caps.c-277- */\ndrivers/net/phy/phy_caps.c:278:void phy_caps_linkmodes(unsigned long caps, unsigned long *linkmodes)\ndrivers/net/phy/phy_caps.c-279-{\n--\ndrivers/net/phy/phy_caps.c-284-}\ndrivers/net/phy/phy_caps.c:285:EXPORT_SYMBOL_GPL(phy_caps_linkmodes);\ndrivers/net/phy/phy_caps.c-286-\ndrivers/net/phy/phy_caps.c-287-/**\ndrivers/net/phy/phy_caps.c:288: * phy_caps_from_interface() - Get the link capa from a given PHY interface\ndrivers/net/phy/phy_caps.c-289- * @interface: The PHY interface we want to get the possible Speed/Duplex from\n--\ndrivers/net/phy/phy_caps.c-293- */\ndrivers/net/phy/phy_caps.c:294:unsigned long phy_caps_from_interface(phy_interface_t interface)\ndrivers/net/phy/phy_caps.c-295-{\n--\ndrivers/net/phy/phy_caps.c-389-}\ndrivers/net/phy/phy_caps.c:390:EXPORT_SYMBOL_GPL(phy_caps_from_interface);\ndrivers/net/phy/phy_caps.c-391-\ndrivers/net/phy/phy_caps.c-392-/**\ndrivers/net/phy/phy_caps.c:393: * phy_caps_medium_get_supported() - Returns linkmodes supported on a given medium\ndrivers/net/phy/phy_caps.c-394- * @supported: After this call, contains all possible linkmodes on a given medium,\n--\ndrivers/net/phy/phy_caps.c-401- */\ndrivers/net/phy/phy_caps.c:402:void phy_caps_medium_get_supported(unsigned long *supported,\ndrivers/net/phy/phy_caps.c-403-\t\t\t\t   enum ethtool_link_medium medium,\n--\ndrivers/net/phy/phy_caps.c-424-}\ndrivers/net/phy/phy_caps.c:425:EXPORT_SYMBOL_GPL(phy_caps_medium_get_supported);\ndrivers/net/phy/phy_caps.c-426-\ndrivers/net/phy/phy_caps.c-427-/**\ndrivers/net/phy/phy_caps.c:428: * phy_caps_mediums_from_linkmodes() - Get all mediums from a linkmodes list\ndrivers/net/phy/phy_caps.c-429- * @linkmodes: A bitset of linkmodes to get the mediums from\n--\ndrivers/net/phy/phy_caps.c-433- */\ndrivers/net/phy/phy_caps.c:434:u32 phy_caps_mediums_from_linkmodes(unsigned long *linkmodes)\ndrivers/net/phy/phy_caps.c-435-{\n--\ndrivers/net/phy/phy_caps.c-446-}\ndrivers/net/phy/phy_caps.c:447:EXPORT_SYMBOL_GPL(phy_caps_mediums_from_linkmodes);\ndrivers/net/phy/phy_caps.c-448-\ndrivers/net/phy/phy_caps.c-449-/**\ndrivers/net/phy/phy_caps.c:450: * phy_caps_linkmode_filter_ifaces() - Filter linkmodes with an interface list\ndrivers/net/phy/phy_caps.c-451- * @to: Stores the filtered linkmodes\n--\ndrivers/net/phy/phy_caps.c-457- */\ndrivers/net/phy/phy_caps.c:458:void phy_caps_linkmode_filter_ifaces(unsigned long *to,\ndrivers/net/phy/phy_caps.c-459-\t\t\t\t     const unsigned long *from,\n--\ndrivers/net/phy/phy_caps.c-466-\tfor_each_set_bit(interface, interfaces, PHY_INTERFACE_MODE_MAX)\ndrivers/net/phy/phy_caps.c:467:\t\tifaces_caps |= phy_caps_from_interface(interface);\ndrivers/net/phy/phy_caps.c-468-\ndrivers/net/phy/phy_caps.c:469:\tphy_caps_linkmodes(ifaces_caps, ifaces_supported);\ndrivers/net/phy/phy_caps.c-470-\n--\ndrivers/net/phy/phy_caps.c-472-}\ndrivers/net/phy/phy_caps.c:473:EXPORT_SYMBOL_GPL(phy_caps_linkmode_filter_ifaces);\n--\ndrivers/net/phy/phy_device.c-31-#include \u003clinux/phy_led_triggers.h\u003e\ndrivers/net/phy/phy_device.c:32:#include \u003clinux/phy_link_topology.h\u003e\ndrivers/net/phy/phy_device.c:33:#include \u003clinux/phy_port.h\u003e\ndrivers/net/phy/phy_device.c-34-#include \u003clinux/pse-pd/pse.h\u003e\n--\ndrivers/net/phy/phy_device.c=1566=static int phy_sfp_module_insert(void *upstream, const struct sfp_eeprom_id *id)\n--\ndrivers/net/phy/phy_device.c-1570-\tconst struct sfp_module_caps *caps;\ndrivers/net/phy/phy_device.c:1571:\tstruct phy_port *port;\ndrivers/net/phy/phy_device.c-1572-\n--\ndrivers/net/phy/phy_device.c=1605=static void phy_sfp_module_remove(void *upstream)\n--\ndrivers/net/phy/phy_device.c-1607-\tstruct phy_device *phydev = upstream;\ndrivers/net/phy/phy_device.c:1608:\tstruct phy_port *port = phy_get_sfp_port(phydev);\ndrivers/net/phy/phy_device.c-1609-\n--\ndrivers/net/phy/phy_device.c=1617=static void phy_sfp_link_up(void *upstream)\n--\ndrivers/net/phy/phy_device.c-1619-\tstruct phy_device *phydev = upstream;\ndrivers/net/phy/phy_device.c:1620:\tstruct phy_port *port = phy_get_sfp_port(phydev);\ndrivers/net/phy/phy_device.c-1621-\n--\ndrivers/net/phy/phy_device.c=1626=static void phy_sfp_link_down(void *upstream)\n--\ndrivers/net/phy/phy_device.c-1628-\tstruct phy_device *phydev = upstream;\ndrivers/net/phy/phy_device.c:1629:\tstruct phy_port *port = phy_get_sfp_port(phydev);\ndrivers/net/phy/phy_device.c-1630-\n--\ndrivers/net/phy/phy_device.c=1635=static int phy_add_sfp_mod_port(struct phy_device *phydev)\n--\ndrivers/net/phy/phy_device.c-1637-\tconst struct sfp_module_caps *caps;\ndrivers/net/phy/phy_device.c:1638:\tstruct phy_port *port;\ndrivers/net/phy/phy_device.c-1639-\tint ret = 0;\n--\ndrivers/net/phy/phy_device.c-1641-\t/* Create mod port */\ndrivers/net/phy/phy_device.c:1642:\tport = phy_port_alloc();\ndrivers/net/phy/phy_device.c-1643-\tif (!port)\n--\ndrivers/net/phy/phy_device.c-1649-\ndrivers/net/phy/phy_device.c:1650:\tphy_caps_linkmode_filter_ifaces(port-\u003esupported, caps-\u003elink_modes,\ndrivers/net/phy/phy_device.c-1651-\t\t\t\t\tphydev-\u003esfp_cage_port-\u003einterfaces);\n--\ndrivers/net/phy/phy_device.c-1655-\t\tif (ret) {\ndrivers/net/phy/phy_device.c:1656:\t\t\tphy_port_destroy(port);\ndrivers/net/phy/phy_device.c-1657-\t\t\treturn ret;\n--\ndrivers/net/phy/phy_device.c-1662-\t * interface from the PHY, but rather an extension to the sfp-bus, that\ndrivers/net/phy/phy_device.c:1663:\t * is already represented by its own phy_port\ndrivers/net/phy/phy_device.c-1664-\t */\n--\ndrivers/net/phy/phy_device.c=1672=static void phy_del_sfp_mod_port(struct phy_device *phydev)\n--\ndrivers/net/phy/phy_device.c-1679-\ndrivers/net/phy/phy_device.c:1680:\tphy_port_destroy(phydev-\u003emod_port);\ndrivers/net/phy/phy_device.c-1681-\tphydev-\u003emod_port = NULL;\n--\ndrivers/net/phy/phy_device.c=1684=static int phy_sfp_module_start(void *upstream)\n--\ndrivers/net/phy/phy_device.c-1688-\t/* If there's a downstream SFP module, and it doesn't contain a PHY\ndrivers/net/phy/phy_device.c:1689:\t * device, let's create a phy_port to represent that module.\ndrivers/net/phy/phy_device.c-1690-\t */\n--\ndrivers/net/phy/phy_device.c=1706=static const struct sfp_upstream_ops sfp_phydev_ops = {\n--\ndrivers/net/phy/phy_device.c-1718-\ndrivers/net/phy/phy_device.c:1719:static int phy_add_port(struct phy_device *phydev, struct phy_port *port)\ndrivers/net/phy/phy_device.c-1720-{\n--\ndrivers/net/phy/phy_device.c-1744-\t */\ndrivers/net/phy/phy_device.c:1745:\tphy_port_update_supported(port);\ndrivers/net/phy/phy_device.c-1746-\n--\ndrivers/net/phy/phy_device.c-1753-\ndrivers/net/phy/phy_device.c:1754:static void phy_del_port(struct phy_device *phydev, struct phy_port *port)\ndrivers/net/phy/phy_device.c-1755-{\n--\ndrivers/net/phy/phy_device.c-1766-\ndrivers/net/phy/phy_device.c:1767:static struct phy_port *phy_setup_sfp_port(struct phy_device *phydev)\ndrivers/net/phy/phy_device.c-1768-{\ndrivers/net/phy/phy_device.c:1769:\tstruct phy_port *port = phy_port_alloc();\ndrivers/net/phy/phy_device.c-1770-\tint ret;\n--\ndrivers/net/phy/phy_device.c-1788-\tif (ret) {\ndrivers/net/phy/phy_device.c:1789:\t\tphy_port_destroy(port);\ndrivers/net/phy/phy_device.c-1790-\t\treturn ERR_PTR(ret);\n--\ndrivers/net/phy/phy_device.c=1800=static int phy_sfp_probe(struct phy_device *phydev)\ndrivers/net/phy/phy_device.c-1801-{\ndrivers/net/phy/phy_device.c:1802:\tstruct phy_port *port = NULL;\ndrivers/net/phy/phy_device.c-1803-\tstruct sfp_bus *bus;\n--\ndrivers/net/phy/phy_device.c-1839-\t\tphy_del_port(phydev, port);\ndrivers/net/phy/phy_device.c:1840:\t\tphy_port_destroy(port);\ndrivers/net/phy/phy_device.c-1841-\t\tphydev-\u003esfp_cage_port = NULL;\n--\ndrivers/net/phy/phy_device.c-1854- * Release the SFP resources set up by a successful phy_sfp_probe(). Unregister\ndrivers/net/phy/phy_device.c:1855: * the upstream before destroying its phy_port, so SFP upstream callbacks cannot\ndrivers/net/phy/phy_device.c-1856- * race with port destruction.\n--\ndrivers/net/phy/phy_device.c=1858=static void phy_sfp_release(struct phy_device *phydev)\ndrivers/net/phy/phy_device.c-1859-{\ndrivers/net/phy/phy_device.c:1860:\tstruct phy_port *port, *tmp;\ndrivers/net/phy/phy_device.c-1861-\n--\ndrivers/net/phy/phy_device.c-1869-\t\tphy_del_port(phydev, port);\ndrivers/net/phy/phy_device.c:1870:\t\tphy_port_destroy(port);\ndrivers/net/phy/phy_device.c-1871-\t}\n--\ndrivers/net/phy/phy_device.c=2483=int __genphy_config_aneg(struct phy_device *phydev, bool changed)\n--\ndrivers/net/phy/phy_device.c-2511-\ndrivers/net/phy/phy_device.c:2512:\t\tc = phy_caps_lookup(phydev-\u003espeed, phydev-\u003eduplex,\ndrivers/net/phy/phy_device.c-2513-\t\t\t\t    phydev-\u003esupported, true);\n--\ndrivers/net/phy/phy_device.c=3617=static void phy_cleanup_ports(struct phy_device *phydev)\ndrivers/net/phy/phy_device.c-3618-{\ndrivers/net/phy/phy_device.c:3619:\tstruct phy_port *tmp, *port;\ndrivers/net/phy/phy_device.c-3620-\n--\ndrivers/net/phy/phy_device.c-3622-\t\tphy_del_port(phydev, port);\ndrivers/net/phy/phy_device.c:3623:\t\tphy_port_destroy(port);\ndrivers/net/phy/phy_device.c-3624-\t}\n--\ndrivers/net/phy/phy_device.c=3627=static int phy_default_setup_single_port(struct phy_device *phydev)\ndrivers/net/phy/phy_device.c-3628-{\ndrivers/net/phy/phy_device.c:3629:\tstruct phy_port *port = phy_port_alloc();\ndrivers/net/phy/phy_device.c-3630-\tunsigned long mode;\n--\ndrivers/net/phy/phy_device.c-3651-\tlinkmode_copy(port-\u003esupported, phydev-\u003esupported);\ndrivers/net/phy/phy_device.c:3652:\tport-\u003emediums = phy_caps_mediums_from_linkmodes(port-\u003esupported);\ndrivers/net/phy/phy_device.c-3653-\n--\ndrivers/net/phy/phy_device.c-3659-\tif (ret)\ndrivers/net/phy/phy_device.c:3660:\t\tphy_port_destroy(port);\ndrivers/net/phy/phy_device.c-3661-\n--\ndrivers/net/phy/phy_device.c-3664-\ndrivers/net/phy/phy_device.c:3665:static int of_phy_ports(struct phy_device *phydev)\ndrivers/net/phy/phy_device.c-3666-{\n--\ndrivers/net/phy/phy_device.c-3668-\tstruct device_node *mdi;\ndrivers/net/phy/phy_device.c:3669:\tstruct phy_port *port;\ndrivers/net/phy/phy_device.c-3670-\tint err;\n--\ndrivers/net/phy/phy_device.c-3695-\t\tif (err) {\ndrivers/net/phy/phy_device.c:3696:\t\t\tphy_port_destroy(port);\ndrivers/net/phy/phy_device.c-3697-\t\t\tgoto out_err;\n--\ndrivers/net/phy/phy_device.c=3710=static int phy_setup_ports(struct phy_device *phydev)\n--\ndrivers/net/phy/phy_device.c-3712-\t__ETHTOOL_DECLARE_LINK_MODE_MASK(ports_supported);\ndrivers/net/phy/phy_device.c:3713:\tstruct phy_port *port;\ndrivers/net/phy/phy_device.c-3714-\tint ret;\ndrivers/net/phy/phy_device.c-3715-\ndrivers/net/phy/phy_device.c:3716:\tret = of_phy_ports(phydev);\ndrivers/net/phy/phy_device.c-3717-\tif (ret)\n--\ndrivers/net/phy/phy_device.c-3753-\t\tif (port-\u003eactive) {\ndrivers/net/phy/phy_device.c:3754:\t\t\tphydev-\u003eport = phy_port_get_type(port);\ndrivers/net/phy/phy_device.c-3755-\t\t\tbreak;\n--\ndrivers/net/phy/phy_device.c-3773- */\ndrivers/net/phy/phy_device.c:3774:struct phy_port *phy_get_sfp_port(struct phy_device *phydev)\ndrivers/net/phy/phy_device.c-3775-{\ndrivers/net/phy/phy_device.c:3776:\tstruct phy_port *port;\ndrivers/net/phy/phy_device.c-3777-\n--\ndrivers/net/phy/phy_device.c=3784=EXPORT_SYMBOL_GPL(phy_get_sfp_port);\n--\ndrivers/net/phy/phy_device.c-3786-/**\ndrivers/net/phy/phy_device.c:3787: * phy_set_upstream_port() - Sets the phy_port controlling the MII this PHY is\ndrivers/net/phy/phy_device.c-3788- *\t\t\t     attached to.\ndrivers/net/phy/phy_device.c-3789- * @phydev: pointer to the PHY device we set the upstream of.\ndrivers/net/phy/phy_device.c:3790: * @port: The phy_port upstream of this PHY, can be NULL.\ndrivers/net/phy/phy_device.c-3791- */\ndrivers/net/phy/phy_device.c:3792:void phy_set_upstream_port(struct phy_device *phydev, struct phy_port *port)\ndrivers/net/phy/phy_device.c-3793-{\ndrivers/net/phy/phy_device.c:3794:\tstruct phy_port *local_port;\ndrivers/net/phy/phy_device.c-3795-\n--\ndrivers/net/phy/phy_device.c=4178=static int __init phy_init(void)\n--\ndrivers/net/phy/phy_device.c-4194-\ndrivers/net/phy/phy_device.c:4195:\trc = phy_caps_init();\ndrivers/net/phy/phy_device.c-4196-\tif (rc)\n--\ndrivers/net/phy/phy_link_topology.c-8-\ndrivers/net/phy/phy_link_topology.c:9:#include \u003clinux/phy_link_topology.h\u003e\ndrivers/net/phy/phy_link_topology.c:10:#include \u003clinux/phy_port.h\u003e\ndrivers/net/phy/phy_link_topology.c-11-#include \u003clinux/phy.h\u003e\n--\ndrivers/net/phy/phy_link_topology.c-15-\ndrivers/net/phy/phy_link_topology.c:16:static int netdev_alloc_phy_link_topology(struct net_device *dev)\ndrivers/net/phy/phy_link_topology.c-17-{\ndrivers/net/phy/phy_link_topology.c:18:\tstruct phy_link_topology *topo;\ndrivers/net/phy/phy_link_topology.c-19-\n--\ndrivers/net/phy/phy_link_topology.c-34-\ndrivers/net/phy/phy_link_topology.c:35:static struct phy_link_topology *phy_link_topo_get_or_alloc(struct net_device *dev)\ndrivers/net/phy/phy_link_topology.c-36-{\n--\ndrivers/net/phy/phy_link_topology.c-55-\t */\ndrivers/net/phy/phy_link_topology.c:56:\tret = netdev_alloc_phy_link_topology(dev);\ndrivers/net/phy/phy_link_topology.c-57-\tif (ret)\n--\ndrivers/net/phy/phy_link_topology.c-62-\ndrivers/net/phy/phy_link_topology.c:63:int phy_link_topo_add_port(struct net_device *dev, struct phy_port *port)\ndrivers/net/phy/phy_link_topology.c-64-{\ndrivers/net/phy/phy_link_topology.c:65:\tstruct phy_link_topology *topo;\ndrivers/net/phy/phy_link_topology.c-66-\tint ret;\n--\ndrivers/net/phy/phy_link_topology.c-69-\t * we don't support now as port retrieval is done under rtnl.\ndrivers/net/phy/phy_link_topology.c:70:\t * We don't have phy_port enabled devices yet, let's make sure\ndrivers/net/phy/phy_link_topology.c-71-\t * we are loudly warned about that when it happens.\n--\ndrivers/net/phy/phy_link_topology.c=90=EXPORT_SYMBOL_GPL(phy_link_topo_add_port);\n\n"
}

13/2 2026/09/10 19:11 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 35493
							output: 217
							thoughts: 1209
						

Thoughts:
**Patch Analysis Summary**

Okay, let's break down this patch. My immediate thought is that this is definitely fuzzable.

First, the `WorthFuzzing` aspect is clear. We're looking at a new `ETHTOOL_MSG_PORT_GET` netlink command, with both DO and DUMP operations. The implementation involves new handlers in `net/ethtool/port.c`, namely `port_parse_request`, `port_prepare_data`, `port_reply_size`, `port_fill_reply`, `ethnl_port_dump_start`, `ethnl_port_dumpit`, `ethnl_port_dump_done`, `port_dump_one`, `port_dump_one_dev`, and `port_dump_all_dev`. We're also seeing changes to phylib topology, adding functions like `phy_link_topo_add_port`, `phy_link_topo_del_port`, `phy_caps_linkmode_filter_ifaces`, `phy_set_upstream_port`, `phylink_create_sfp_cage_port`, `phylink_add_sfp_mod_port`, and `phy_add_sfp_mod_port`. This is core networking code, ethtool generic netlink, and phylib code, all reachable through netlink messages, thus readily exploitable by tools like syzkaller. Easy call on that one.

Next, for `FocusSymbols`, I've zeroed in on the key, less-common entrypoints and core logic added or modified. The critical ones are `ethnl_port_dumpit`, `ethnl_port_dump_start`, `ethnl_port_dump_done`, `port_prepare_data`, `port_fill_reply`, `port_dump_one_dev`, `port_dump_all_dev`, `phy_link_topo_add_port`, `phy_link_topo_del_port`, `phy_caps_linkmode_filter_ifaces`, and `phy_set_upstream_port`. I checked which symbols are non-static or exported, to further refine the list. Specifically, I know that: `ethnl_port_dump_start`, `ethnl_port_dumpit`, `ethnl_port_dump_done`, `phy_link_topo_add_port`, `phy_link_topo_del_port`, `phy_caps_linkmode_filter_ifaces`, and `phy_set_upstream_port` are non-static. So, those are the ones I'm interested in. The static functions can still be interesting though.

Finally, for `EnableConfigs`, it looks like `ETHTOOL_NETLINK`, `PHYLIB`, and `PHYLINK` are required. I've double-checked the relevant Makefiles and Kconfig files to confirm, and `ETHTOOL_NETLINK` depends on `NET`, as expected. So those are the configurations we'll need to enable.

Reachability is confirmed: generic netlink interface for ethtool is directly reachable by user programs. The `FocusSymbols` are non-ubiquitous, directly added/modified handlers and functions. The required `EnableConfigs` are `ETHTOOL_NETLINK`, `PHYLIB`, and `PHYLINK`. The reasoning is concise: new code, directly reachable, with targeted entrypoints. Looks like a solid fuzzing target.



14/2 2026/09/10 19:11 tool set-results
0m Args:
{
  "EnableConfigs": [
    "ETHTOOL_NETLINK",
    "PHYLIB",
    "PHYLINK"
  ],
  "FocusSymbols": [
    "ethnl_port_dumpit",
    "ethnl_port_dump_start",
    "ethnl_port_dump_done",
    "port_prepare_data",
    "port_fill_reply",
    "phy_link_topo_add_port",
    "phy_link_topo_del_port",
    "phy_caps_linkmode_filter_ifaces",
    "phy_set_upstream_port"
  ],
  "Reasoning": "The patch introduces the ETHTOOL_MSG_PORT_GET netlink command (both DO and DUMP operations) along with supporting PHY link topology port management and phylib SFP cage/module port handling. This new netlink interface can be reached directly from userspace via generic netlink sockets, making it a high-value target for fuzzing.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "ETHTOOL_NETLINK",
    "PHYLIB",
    "PHYLINK"
  ],
  "FocusSymbols": [
    "ethnl_port_dumpit",
    "ethnl_port_dump_start",
    "ethnl_port_dump_done",
    "port_prepare_data",
    "port_fill_reply",
    "phy_link_topo_add_port",
    "phy_link_topo_del_port",
    "phy_caps_linkmode_filter_ifaces",
    "phy_set_upstream_port"
  ],
  "Reasoning": "The patch introduces the ETHTOOL_MSG_PORT_GET netlink command (both DO and DUMP operations) along with supporting PHY link topology port management and phylib SFP cage/module port handling. This new netlink interface can be reached directly from userspace via generic netlink sockets, making it a high-value target for fuzzing.",
  "WorthFuzzing": true
}

15/1 2026/09/10 19:11 action If
1m Args:
{
  "WorthFuzzing": true
}

Results:
null

16/2 2026/09/10 19:11 agent kmsan-evaluator
1m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch series implements the ETHTOOL_MSG_PORT_GET netlink interface (do and dump operations) and associated PHY port topology handling in phylib and phylink.\n\nAnalysis of memory handling:\n1. Heap \u0026 Stack allocations:\n   - Port structures (`struct phy_port`) are allocated using `phy_port_alloc()` which zeros memory via `kzalloc_obj(*port)` and explicit `linkmode_zero()`.\n   - In ethtool netlink request/reply handling (`net/ethtool/port.c`), request structures are zero-allocated with `kzalloc_obj()` / `kzalloc()`, and reply buffers are explicitly cleared using `memset()` or `ethnl_init_reply_data()` before population.\n   - Stack variables in helper functions (e.g. `phy_caps_linkmode_filter_ifaces`) are zero-initialized (`= {}` and `= 0`).\n2. Userspace communication:\n   - Communication with user space is done exclusively using Netlink TLVs via standard Netlink attribute serialization functions (`nla_put_u32()`, `ethnl_put_bitset()`, `ethnl_fill_reply_header()`). No raw kernel structs with potential uninitialized padding or uninitialized fields are copied to userspace.\n3. Potential bugs:\n   - Any bugs introduced by this patch series (e.g., locking concurrency with RTNL/netdev locks, list/xarray management, reference counting of SFP bus/ports, or NULL dereferences) fall within the scope of KASAN, LOCKDEP, and standard kernel debugging facilities.\n   - There are no uninitialized memory reads or information leak risks that would require dedicated KMSAN fuzzing.\n\nTherefore, NeedsKMSAN is false.",
  "NeedsKMSAN": false
}

Instruction:
You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.

CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
  a comprehensive suite of debugging tools and sanitizers, including KASAN
  (out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
  (locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
  or page allocations) and kernel-to-user memory info-leaks.

Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.

Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.

Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
   attributes, ioctl output arguments, socket options, or BPF buffers) where fields
   or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
   or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
   could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
   uninitialized bytes of existing buffers.

Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
  dereferences, locking deadlocks, or use-after-free bugs (these are already caught
  by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
  or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.

Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 02572d1cc948837eac36bce03b1f2254f2e77f39
Author: syz-cluster <triage@syzkaller.com>
Date:   Thu Sep 10 19:11:12 2026 +0000

    syz-cluster: applied patch under review

diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netlink/specs/ethtool.yaml
index 5dd4d1b5d94bb..35e028c0be296 100644
--- a/Documentation/netlink/specs/ethtool.yaml
+++ b/Documentation/netlink/specs/ethtool.yaml
@@ -210,6 +210,11 @@ definitions:
       -
         name: discard
         value: 31
+  -
+    name: port-type
+    doc: type of physical connector
+    type: enum
+    entries: [mdi, sfp]
 
 attribute-sets:
   -
@@ -1905,6 +1910,32 @@ attribute-sets:
         name: link
         type: nest
         nested-attributes: mse-snapshot
+  -
+    name: port
+    attr-cnt-name: --ethtool-a-port-cnt
+    attributes:
+      -
+        name: header
+        type: nest
+        nested-attributes: header
+      -
+        name: id
+        type: u32
+      -
+        name: supported-modes
+        type: nest
+        nested-attributes: bitset
+      -
+        name: supported-interfaces
+        type: nest
+        nested-attributes: bitset
+      -
+        name: type
+        type: u32
+        enum: port-type
+      -
+        name: upstream-port
+        type: u32
 
 operations:
   enum-model: directional
@@ -2859,6 +2890,30 @@ operations:
             - worst-channel
             - link
       dump: *mse-get-op
+    -
+      name: port-get
+      doc: Get ports attached to an interface
+
+      attribute-set: port
+
+      do:
+        request:
+          attributes:
+            - header
+            - id
+        reply: &port-get-op-reply
+          attributes:
+            - header
+            - id
+            - supported-modes
+            - supported-interfaces
+            - type
+            - upstream-port
+      dump:
+        request:
+          attributes:
+            - header
+        reply: *port-get-op-reply
 
 mcast-groups:
   list:
diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst
index e92abf45faf50..b4326c89b0751 100644
--- a/Documentation/networking/ethtool-netlink.rst
+++ b/Documentation/networking/ethtool-netlink.rst
@@ -2537,6 +2537,39 @@ Within each channel nest, only the metrics supported by the PHY will be present.
 See ``struct phy_mse_snapshot`` kernel documentation in
 ``include/linux/phy.h``.
 
+PORT_GET
+========
+
+Retrieve information about the physical connection points of a network device,
+referred to as "ports". User needs to specify a PORT_ID for the DO operation,
+in which case the DO request returns information about that specific port.
+
+As there can be more than one port, the DUMP operation can be used to list the
+ports present on a given interface, by passing an interface index or name in
+the dump request.
+
+Request contents:
+
+  ===================================== ======  ===============================
+  ``ETHTOOL_A_PORT_HEADER``             nested  request header
+  ``ETHTOOL_A_PORT_ID``                 u32     port id
+  ===================================== ======  ===============================
+
+Kernel response contents:
+
+  ======================================= ======  =============================
+  ``ETHTOOL_A_PORT_HEADER``               nested  request header
+  ``ETHTOOL_A_PORT_ID``                   u32     the port's unique identifier,
+                                                  per netdevice.
+  ``ETHTOOL_A_PORT_SUPPORTED_MODES``      bitset  bitset of supported linkmodes
+  ``ETHTOOL_A_PORT_SUPPORTED_INTERFACES`` bitset  bitset of supported MII
+                                                  interfaces
+  ``ETHTOOL_A_PORT_TYPE``                 u32     the port type
+  ``ETHTOOL_A_PORT_UPSTREAM_PORT``        u32     If any, the index of the MII
+                                                  port that feeds into this
+                                                  port.
+  ======================================= ======  =============================
+
 Request translation
 ===================
 
@@ -2647,4 +2680,5 @@ are netlink only.
   n/a                                 ``ETHTOOL_MSG_PHY_GET``
   ``SIOCGHWTSTAMP``                   ``ETHTOOL_MSG_TSCONFIG_GET``
   ``SIOCSHWTSTAMP``                   ``ETHTOOL_MSG_TSCONFIG_SET``
+  n/a                                 ``ETHTOOL_MSG_PORT_GET``
   =================================== =====================================
diff --git a/Documentation/networking/phy-port.rst b/Documentation/networking/phy-port.rst
index 6e28d9094bce3..2a9b1ec93b70f 100644
--- a/Documentation/networking/phy-port.rst
+++ b/Documentation/networking/phy-port.rst
@@ -99,13 +99,29 @@ will eventually be able to report its own ksettings::
             (_____)-----| Port |
                         +------+
 
+SFP ports
+=========
+
+SFP interfaces involve 2 distinct components, each represented by
+a :c:type:`struct phy_port <phy_port>` instance :
+
+ - The SFP cage itself is a :c:type:`struct phy_port <phy_port>`. It's special
+   in that it's not an MDI interface, but rather a hot-pluggable MII.
+   The :c:type:`struct phy_port <phy_port>` associated to it lists the different
+   MII interfaces we can use on the cage.
+
+ - The SFP module, when inserted, will also be associated to a
+   :c:type:`struct phy_port <phy_port>`, that represents the various linkmodes
+   that it gives access to. The module's :c:type:`struct phy_port <phy_port>`
+   doesn't supersede the cage's port, it references it through
+   the :c:type:`struct phy_port <phy_port>` :c:member:`upstream_port` field.
+
 Next steps
 ==========
 
-As of writing this documentation, only ports controlled by PHY devices are
-supported. The next steps will be to add the Netlink API to expose these
-to userspace and add support for raw ports (controlled by some firmware, and directly
-managed by the NIC driver).
+As of writing this documentation, the port's presence and information can only
+be queried, and it's not possible to change any of the port's settings or select
+which one should be used.
 
 Another parallel task is the introduction of a MII muxing framework to allow the
-control of non-PHY driver multi-port setups.
+control of non-PHY driven multi-port setups.
diff --git a/MAINTAINERS b/MAINTAINERS
index 878ecf1fdf27c..973bbb7d2419b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -18994,6 +18994,7 @@ F:	Documentation/devicetree/bindings/net/ethernet-connector.yaml
 F:	Documentation/networking/phy-port.rst
 F:	drivers/net/phy/phy_port.c
 F:	include/linux/phy_port.h
+F:	net/ethtool/port.c
 K:	struct\s+phy_port|phy_port_
 
 NETWORKING [GENERAL]
diff --git a/drivers/net/phy/phy-caps.h b/drivers/net/phy/phy-caps.h
index 421088e6f6e8f..ec3d39a0ae06b 100644
--- a/drivers/net/phy/phy-caps.h
+++ b/drivers/net/phy/phy-caps.h
@@ -66,5 +66,7 @@ void phy_caps_medium_get_supported(unsigned long *supported,
 				   enum ethtool_link_medium medium,
 				   int lanes);
 u32 phy_caps_mediums_from_linkmodes(unsigned long *linkmodes);
+void phy_caps_linkmode_filter_ifaces(unsigned long *to, const unsigned long *from,
+				     const unsigned long *interfaces);
 
 #endif /* __PHY_CAPS_H */
diff --git a/drivers/net/phy/phy_caps.c b/drivers/net/phy/phy_caps.c
index 942d43191561e..558e4df4d63c0 100644
--- a/drivers/net/phy/phy_caps.c
+++ b/drivers/net/phy/phy_caps.c
@@ -445,3 +445,29 @@ u32 phy_caps_mediums_from_linkmodes(unsigned long *linkmodes)
 	return mediums;
 }
 EXPORT_SYMBOL_GPL(phy_caps_mediums_from_linkmodes);
+
+/**
+ * phy_caps_linkmode_filter_ifaces() - Filter linkmodes with an interface list
+ * @to: Stores the filtered linkmodes
+ * @from: Linkmodes to filter
+ * @interfaces: Bitfield of phy_interface_t that we use for filtering
+ *
+ * Filter the provided linkmodes, only to keep the ones we can possibly achieve
+ * when using any of the provided MII interfaces.
+ */
+void phy_caps_linkmode_filter_ifaces(unsigned long *to,
+				     const unsigned long *from,
+				     const unsigned long *interfaces)
+{
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(ifaces_supported) = {};
+	unsigned int ifaces_caps = 0;
+	phy_interface_t interface;
+
+	for_each_set_bit(interface, interfaces, PHY_INTERFACE_MODE_MAX)
+		ifaces_caps |= phy_caps_from_interface(interface);
+
+	phy_caps_linkmodes(ifaces_caps, ifaces_supported);
+
+	linkmode_and(to, from, ifaces_supported);
+}
+EXPORT_SYMBOL_GPL(phy_caps_linkmode_filter_ifaces);
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 41d1b20cde2c0..561d19edf331c 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1490,11 +1490,22 @@ static int phy_sfp_connect_phy(void *upstream, struct phy_device *phy)
 {
 	struct phy_device *phydev = upstream;
 	struct net_device *dev = phydev->attached_dev;
+	int ret;
 
-	if (dev)
-		return phy_link_topo_add_phy(dev, phy, PHY_UPSTREAM_PHY, phydev);
+	phydev->has_sfp_mod_phy = true;
+	phy_set_upstream_port(phy, phydev->sfp_cage_port);
 
-	return 0;
+	/* If we aren't attached to a netdev, we can't add the SFP PHY to its
+	 * topology.
+	 */
+	if (!dev)
+		return 0;
+
+	ret = phy_link_topo_add_phy(dev, phy, PHY_UPSTREAM_PHY, phydev);
+	if (ret)
+		phydev->has_sfp_mod_phy = false;
+
+	return ret;
 }
 
 /**
@@ -1512,8 +1523,12 @@ static void phy_sfp_disconnect_phy(void *upstream, struct phy_device *phy)
 	struct phy_device *phydev = upstream;
 	struct net_device *dev = phydev->attached_dev;
 
+	phydev->has_sfp_mod_phy = false;
+
 	if (dev)
 		phy_link_topo_del_phy(dev, phy);
+
+	phy_set_upstream_port(phy, NULL);
 }
 
 /**
@@ -1617,6 +1632,77 @@ static void phy_sfp_link_down(void *upstream)
 		port->ops->link_down(port);
 }
 
+static int phy_add_sfp_mod_port(struct phy_device *phydev)
+{
+	const struct sfp_module_caps *caps;
+	struct phy_port *port;
+	int ret = 0;
+
+	/* Create mod port */
+	port = phy_port_alloc();
+	if (!port)
+		return -ENOMEM;
+
+	port->active = true;
+
+	caps = sfp_get_module_caps(phydev->sfp_bus);
+
+	phy_caps_linkmode_filter_ifaces(port->supported, caps->link_modes,
+					phydev->sfp_cage_port->interfaces);
+
+	if (phydev->attached_dev) {
+		ret = phy_link_topo_add_port(phydev->attached_dev, port);
+		if (ret) {
+			phy_port_destroy(port);
+			return ret;
+		}
+	}
+
+	/* we don't use phy_add_port() here as the module port isn't a direct
+	 * interface from the PHY, but rather an extension to the sfp-bus, that
+	 * is already represented by its own phy_port
+	 */
+	phydev->mod_port = port;
+
+	port->upstream_port = phydev->sfp_cage_port;
+
+	return 0;
+}
+
+static void phy_del_sfp_mod_port(struct phy_device *phydev)
+{
+	if (!phydev->mod_port)
+		return;
+
+	if (phydev->attached_dev)
+		phy_link_topo_del_port(phydev->attached_dev, phydev->mod_port);
+
+	phy_port_destroy(phydev->mod_port);
+	phydev->mod_port = NULL;
+}
+
+static int phy_sfp_module_start(void *upstream)
+{
+	struct phy_device *phydev = upstream;
+
+	/* If there's a downstream SFP module, and it doesn't contain a PHY
+	 * device, let's create a phy_port to represent that module.
+	 */
+	if (!phydev->has_sfp_mod_phy)
+		return phy_add_sfp_mod_port(phydev);
+
+	return 0;
+}
+
+static void phy_sfp_module_stop(void *upstream)
+{
+	struct phy_device *phydev = upstream;
+
+	/* Called upon module removal or upstream removal */
+	if (!phydev->has_sfp_mod_phy)
+		phy_del_sfp_mod_port(phydev);
+}
+
 static const struct sfp_upstream_ops sfp_phydev_ops = {
 	.attach = phy_sfp_attach,
 	.detach = phy_sfp_detach,
@@ -1626,6 +1712,8 @@ static const struct sfp_upstream_ops sfp_phydev_ops = {
 	.link_down = phy_sfp_link_down,
 	.connect_phy = phy_sfp_connect_phy,
 	.disconnect_phy = phy_sfp_disconnect_phy,
+	.module_start = phy_sfp_module_start,
+	.module_stop = phy_sfp_module_stop,
 };
 
 static int phy_add_port(struct phy_device *phydev, struct phy_port *port)
@@ -1670,16 +1758,19 @@ static void phy_del_port(struct phy_device *phydev, struct phy_port *port)
 
 	list_del(&port->head);
 
+	if (phydev->attached_dev)
+		phy_link_topo_del_port(phydev->attached_dev, port);
+
 	phydev->n_ports--;
 }
 
-static int phy_setup_sfp_port(struct phy_device *phydev)
+static struct phy_port *phy_setup_sfp_port(struct phy_device *phydev)
 {
 	struct phy_port *port = phy_port_alloc();
 	int ret;
 
 	if (!port)
-		return -ENOMEM;
+		return ERR_PTR(-ENOMEM);
 
 	port->parent_type = PHY_PORT_PHY;
 	port->phy = phydev;
@@ -1694,10 +1785,12 @@ static int phy_setup_sfp_port(struct phy_device *phydev)
 	 * when attaching the port to the phydev.
 	 */
 	ret = phy_add_port(phydev, port);
-	if (ret)
+	if (ret) {
 		phy_port_destroy(port);
+		return ERR_PTR(ret);
+	}
 
-	return ret;
+	return port;
 }
 
 /**
@@ -1706,30 +1799,50 @@ static int phy_setup_sfp_port(struct phy_device *phydev)
  */
 static int phy_sfp_probe(struct phy_device *phydev)
 {
+	struct phy_port *port = NULL;
 	struct sfp_bus *bus;
-	int ret = 0;
+	int ret;
 
-	if (phydev->mdio.dev.fwnode) {
-		bus = sfp_bus_find_fwnode(phydev->mdio.dev.fwnode);
-		if (IS_ERR(bus))
-			return PTR_ERR(bus);
+	if (!phydev->mdio.dev.fwnode)
+		return 0;
 
-		phydev->sfp_bus = bus;
+	bus = sfp_bus_find_fwnode(phydev->mdio.dev.fwnode);
+	if (IS_ERR(bus))
+		return PTR_ERR(bus);
 
-		ret = sfp_bus_add_upstream(bus, phydev, &sfp_phydev_ops);
-		sfp_bus_put(bus);
+	phydev->sfp_bus = bus;
 
-		if (ret)
-			phydev->sfp_bus = NULL;
+	if (bus) {
+		port = phy_setup_sfp_port(phydev);
+		if (IS_ERR(port)) {
+			ret = PTR_ERR(port);
+			port = NULL;
+			goto out_sfp;
+		}
 	}
 
-	if (!ret && phydev->sfp_bus) {
-		ret = phy_setup_sfp_port(phydev);
-		if (ret) {
-			sfp_bus_del_upstream(phydev->sfp_bus);
-			phydev->sfp_bus = NULL;
-		}
+	phydev->sfp_cage_port = port;
+
+	ret = sfp_bus_add_upstream(bus, phydev, &sfp_phydev_ops);
+	if (ret)
+		goto out_port;
+
+	/* sfp_bus_add_upstream() grabs a ref to the sfp bus on success, it's
+	 * safe to release it now.
+	 */
+	sfp_bus_put(bus);
+
+	return ret;
+
+out_port:
+	if (port) {
+		phy_del_port(phydev, port);
+		phy_port_destroy(port);
+		phydev->sfp_cage_port = NULL;
 	}
+out_sfp:
+	sfp_bus_put(bus);
+	phydev->sfp_bus = NULL;
 
 	return ret;
 }
@@ -1813,6 +1926,8 @@ static void phy_detach_internal(struct phy_device *phydev, bool notify_bus)
 		phydev->attached_dev->phydev = NULL;
 		phydev->attached_dev = NULL;
 		phy_link_topo_del_phy(dev, phydev);
+		if (phydev->mod_port)
+			phy_link_topo_del_port(dev, phydev->mod_port);
 	}
 
 	phydev->phy_link_change = NULL;
@@ -1942,6 +2057,12 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
 		err = phy_link_topo_add_phy(dev, phydev, PHY_UPSTREAM_MAC, dev);
 		if (err)
 			goto error;
+
+		if (phydev->mod_port) {
+			err = phy_link_topo_add_port(dev, phydev->mod_port);
+			if (err)
+				goto error;
+		}
 	}
 
 	/* Some Ethernet drivers try to connect to a PHY device before
@@ -3662,6 +3783,25 @@ struct phy_port *phy_get_sfp_port(struct phy_device *phydev)
 }
 EXPORT_SYMBOL_GPL(phy_get_sfp_port);
 
+/**
+ * phy_set_upstream_port() - Sets the phy_port controlling the MII this PHY is
+ *			     attached to.
+ * @phydev: pointer to the PHY device we set the upstream of.
+ * @port: The phy_port upstream of this PHY, can be NULL.
+ */
+void phy_set_upstream_port(struct phy_device *phydev, struct phy_port *port)
+{
+	struct phy_port *local_port;
+
+	ASSERT_RTNL();
+
+	phydev->upstream_port = port;
+
+	phy_for_each_port(phydev, local_port)
+		local_port->upstream_port = port;
+}
+EXPORT_SYMBOL_GPL(phy_set_upstream_port);
+
 /**
  * fwnode_mdio_find_device - Given a fwnode, find the mdio_device
  * @fwnode: pointer to the mdio_device's fwnode
diff --git a/drivers/net/phy/phy_link_topology.c b/drivers/net/phy/phy_link_topology.c
index 4134de7ae313d..22885bf2e0455 100644
--- a/drivers/net/phy/phy_link_topology.c
+++ b/drivers/net/phy/phy_link_topology.c
@@ -7,6 +7,7 @@
  */
 
 #include <linux/phy_link_topology.h>
+#include <linux/phy_port.h>
 #include <linux/phy.h>
 #include <linux/rtnetlink.h>
 #include <linux/xarray.h>
@@ -23,17 +24,89 @@ static int netdev_alloc_phy_link_topology(struct net_device *dev)
 	xa_init_flags(&topo->phys, XA_FLAGS_ALLOC1);
 	topo->next_phy_index = 1;
 
+	xa_init_flags(&topo->ports, XA_FLAGS_ALLOC1);
+	topo->next_port_index = 1;
+
 	dev->link_topo = topo;
 
 	return 0;
 }
 
+static struct phy_link_topology *phy_link_topo_get_or_alloc(struct net_device *dev)
+{
+	int ret;
+
+	if (dev->link_topo)
+		return dev->link_topo;
+
+	/* The topology is allocated the first time we add an object to it.
+	 * It is freed alongside the netdev. It can be called on multiple
+	 * contexts:
+	 *  - It can be called from .probe() : No rtnl, no netdev_lock
+	 *  - .ndo_open() : rtnl and possibly netdev_lock
+	 *  - SFP state machine : rtnl held or not
+	 *
+	 *  However, we can't really have races :
+	 *  - If we have a PHY, phy_link_topo_add_phy() will always run first
+	 *    and trigger the alloc. Only then the ports can be added through
+	 *    phylib or sfp.
+	 *  - If we don't, the SFP port for the cage is registered first, and
+	 *    only then other ports/PHYs can be registered.
+	 */
+	ret = netdev_alloc_phy_link_topology(dev);
+	if (ret)
+		return ERR_PTR(ret);
+
+	return dev->link_topo;
+}
+
+int phy_link_topo_add_port(struct net_device *dev, struct phy_port *port)
+{
+	struct phy_link_topology *topo;
+	int ret;
+
+	/* Ports can now be queried without rtnl for ops-locked devices, which
+	 * we don't support now as port retrieval is done under rtnl.
+	 * We don't have phy_port enabled devices yet, let's make sure
+	 * we are loudly warned about that when it happens.
+	 */
+	if (WARN_ON_ONCE(netdev_need_ops_lock(dev)))
+		return -EOPNOTSUPP;
+
+	topo = phy_link_topo_get_or_alloc(dev);
+	if (IS_ERR(topo))
+		return PTR_ERR(topo);
+
+	/* Attempt to re-use a previously allocated port_id */
+	if (port->id)
+		ret = xa_insert(&topo->ports, port->id, port, GFP_KERNEL);
+	else
+		ret = xa_alloc_cyclic(&topo->ports, &port->id, port,
+				      xa_limit_32b, &topo->next_port_index,
+				      GFP_KERNEL);
+
+	return ret < 0 ? ret : 0;
+}
+EXPORT_SYMBOL_GPL(phy_link_topo_add_port);
+
+void phy_link_topo_del_port(struct net_device *dev, struct phy_port *port)
+{
+	struct phy_link_topology *topo = dev->link_topo;
+
+	if (!topo)
+		return;
+
+	xa_erase(&topo->ports, port->id);
+}
+EXPORT_SYMBOL_GPL(phy_link_topo_del_port);
+
 int phy_link_topo_add_phy(struct net_device *dev,
 			  struct phy_device *phy,
 			  enum phy_upstream upt, void *upstream)
 {
-	struct phy_link_topology *topo = dev->link_topo;
+	struct phy_link_topology *topo;
 	struct phy_device_node *pdn;
+	struct phy_port *port;
 	int ret;
 
 	/* ethtool ops may run without rtnl_lock, and rtnl_lock is what
@@ -45,13 +118,9 @@ int phy_link_topo_add_phy(struct net_device *dev,
 	if (WARN_ON_ONCE(netdev_need_ops_lock(dev)))
 		return -EOPNOTSUPP;
 
-	if (!topo) {
-		ret = netdev_alloc_phy_link_topology(dev);
-		if (ret)
-			return ret;
-
-		topo = dev->link_topo;
-	}
+	topo = phy_link_topo_get_or_alloc(dev);
+	if (IS_ERR(topo))
+		return PTR_ERR(topo);
 
 	pdn = kzalloc_obj(*pdn);
 	if (!pdn)
@@ -86,8 +155,20 @@ int phy_link_topo_add_phy(struct net_device *dev,
 	if (ret < 0)
 		goto err;
 
+	/* Add all the PHY's ports to the topology */
+	list_for_each_entry(port, &phy->ports, head) {
+		ret = phy_link_topo_add_port(dev, port);
+		if (ret)
+			goto del_ports;
+	}
+
 	return 0;
 
+del_ports:
+	list_for_each_entry_continue_reverse(port, &phy->ports, head)
+		phy_link_topo_del_port(dev, port);
+
+	xa_erase(&topo->phys, phy->phyindex);
 err:
 	kfree(pdn);
 	return ret;
@@ -99,10 +180,14 @@ void phy_link_topo_del_phy(struct net_device *dev,
 {
 	struct phy_link_topology *topo = dev->link_topo;
 	struct phy_device_node *pdn;
+	struct phy_port *port;
 
 	if (!topo)
 		return;
 
+	list_for_each_entry(port, &phy->ports, head)
+		phy_link_topo_del_port(dev, port);
+
 	pdn = xa_erase(&topo->phys, phy->phyindex);
 
 	/* We delete the PHY from the topology, however we don't re-set the
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index b9fc8599df749..d05cde44f401d 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -14,6 +14,8 @@
 #include <linux/of_mdio.h>
 #include <linux/phy.h>
 #include <linux/phy_fixed.h>
+#include <linux/phy_link_topology.h>
+#include <linux/phy_port.h>
 #include <linux/phylink.h>
 #include <linux/rtnetlink.h>
 #include <linux/spinlock.h>
@@ -93,6 +95,8 @@ struct phylink {
 	DECLARE_PHY_INTERFACE_MASK(sfp_interfaces);
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support);
 	u8 sfp_port;
+	struct phy_port *sfp_cage_port;
+	struct phy_port *mod_port;
 
 	struct eee_config eee_cfg;
 
@@ -1765,6 +1769,51 @@ static void phylink_fixed_poll(struct timer_list *t)
 
 static const struct sfp_upstream_ops sfp_phylink_ops;
 
+static int phylink_create_sfp_cage_port(struct phylink *pl)
+{
+	struct phy_port *port;
+	int ret = 0;
+
+	if (!pl->netdev || !pl->sfp_bus)
+		return 0;
+
+	port = phy_port_alloc();
+	if (!port)
+		return -ENOMEM;
+
+	port->is_sfp = true;
+	port->is_mii = true;
+	port->active = true;
+
+	phy_interface_and(port->interfaces, pl->config->supported_interfaces,
+			  phylink_sfp_interfaces);
+	phy_port_update_supported(port);
+
+	ret = phy_link_topo_add_port(pl->netdev, port);
+	if (ret)
+		goto out_destroy_port;
+
+	pl->sfp_cage_port = port;
+
+	return 0;
+
+out_destroy_port:
+	phy_port_destroy(port);
+	pl->sfp_cage_port = NULL;
+	return ret;
+}
+
+static void phylink_destroy_sfp_cage_port(struct phylink *pl)
+{
+	if (pl->netdev && pl->sfp_cage_port)
+		phy_link_topo_del_port(pl->netdev, pl->sfp_cage_port);
+
+	if (pl->sfp_cage_port)
+		phy_port_destroy(pl->sfp_cage_port);
+
+	pl->sfp_cage_port = NULL;
+}
+
 static int phylink_register_sfp(struct phylink *pl,
 				const struct fwnode_handle *fwnode)
 {
@@ -1782,9 +1831,18 @@ static int phylink_register_sfp(struct phylink *pl,
 
 	pl->sfp_bus = bus;
 
+	ret = phylink_create_sfp_cage_port(pl);
+	if (ret) {
+		sfp_bus_put(bus);
+		return ret;
+	}
+
 	ret = sfp_bus_add_upstream(bus, pl, &sfp_phylink_ops);
 	sfp_bus_put(bus);
 
+	if (ret)
+		phylink_destroy_sfp_cage_port(pl);
+
 	return ret;
 }
 
@@ -2067,6 +2125,7 @@ EXPORT_SYMBOL_GPL(phylink_create);
 void phylink_destroy(struct phylink *pl)
 {
 	sfp_bus_del_upstream(pl->sfp_bus);
+	phylink_destroy_sfp_cage_port(pl);
 	if (pl->link_gpio)
 		gpiod_put(pl->link_gpio);
 
@@ -3939,14 +3998,67 @@ static void phylink_sfp_module_remove(void *upstream)
 	phy_interface_zero(pl->sfp_interfaces);
 }
 
+static int phylink_add_sfp_mod_port(struct phylink *pl)
+{
+	const struct sfp_module_caps *caps;
+	struct phy_port *port;
+	int ret = 0;
+
+	if (!pl->sfp_cage_port)
+		return 0;
+
+	/* Create mod port */
+	port = phy_port_alloc();
+	if (!port)
+		return -ENOMEM;
+
+	port->active = true;
+
+	caps = sfp_get_module_caps(pl->sfp_bus);
+
+	phy_caps_linkmode_filter_ifaces(port->supported, caps->link_modes,
+					pl->sfp_cage_port->interfaces);
+
+	if (pl->netdev) {
+		ret = phy_link_topo_add_port(pl->netdev, port);
+		if (ret) {
+			phy_port_destroy(port);
+			return ret;
+		}
+	}
+
+	port->upstream_port = pl->sfp_cage_port;
+
+	pl->mod_port = port;
+
+	return 0;
+}
+
+static void phylink_del_sfp_mod_port(struct phylink *pl)
+{
+	if (!pl->mod_port)
+		return;
+
+	if (pl->netdev)
+		phy_link_topo_del_port(pl->netdev, pl->mod_port);
+
+	phy_port_destroy(pl->mod_port);
+	pl->mod_port = NULL;
+}
+
 static int phylink_sfp_module_start(void *upstream)
 {
 	struct phylink *pl = upstream;
+	int ret;
 
 	/* If this SFP module has a PHY, start the PHY now. */
 	if (pl->phydev) {
 		phy_start(pl->phydev);
 		return 0;
+	} else {
+		ret = phylink_add_sfp_mod_port(pl);
+		if (ret)
+			return ret;
 	}
 
 	/* If the module may have a PHY but we didn't detect one we
@@ -3955,7 +4067,16 @@ static int phylink_sfp_module_start(void *upstream)
 	if (!pl->sfp_may_have_phy)
 		return 0;
 
-	return phylink_sfp_config_optical(pl);
+	ret = phylink_sfp_config_optical(pl);
+	if (ret)
+		goto del_mod_port;
+
+	return 0;
+
+del_mod_port:
+	phylink_del_sfp_mod_port(pl);
+
+	return ret;
 }
 
 static void phylink_sfp_module_stop(void *upstream)
@@ -3965,6 +4086,8 @@ static void phylink_sfp_module_stop(void *upstream)
 	/* If this SFP module has a PHY, stop it. */
 	if (pl->phydev)
 		phy_stop(pl->phydev);
+	else
+		phylink_del_sfp_mod_port(pl);
 }
 
 static void phylink_sfp_link_down(void *upstream)
@@ -4009,6 +4132,8 @@ static int phylink_sfp_connect_phy(void *upstream, struct phy_device *phy)
 	phy_interface_and(phy->host_interfaces, phylink_sfp_interfaces,
 			  pl->config->supported_interfaces);
 
+	phy_set_upstream_port(phy, pl->sfp_cage_port);
+
 	/* Do the initial configuration */
 	return phylink_sfp_config_phy(pl, phy);
 }
@@ -4017,6 +4142,7 @@ static void phylink_sfp_disconnect_phy(void *upstream,
 				       struct phy_device *phydev)
 {
 	phylink_disconnect_phy(upstream);
+	phy_set_upstream_port(phydev, NULL);
 }
 
 static const struct sfp_upstream_ops sfp_phylink_ops = {
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 3d8afe6b7f1c5..335821eb22171 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -600,6 +600,7 @@ struct phy_oatc14_sqi_capability {
  * @wol_enabled: Set to true if the PHY or the attached MAC have Wake-on-LAN
  * 		 enabled.
  * @is_genphy_driven: PHY is driven by one of the generic PHY drivers
+ * @has_sfp_mod_phy: Set true if downstream SFP bus's module contains a PHY
  * @state: State of the PHY for management purposes
  * @dev_flags: Device-specific flags used by the PHY driver.
  *
@@ -612,6 +613,9 @@ struct phy_oatc14_sqi_capability {
  * @phylink: Pointer to phylink instance for this PHY
  * @sfp_bus_attached: Flag indicating whether the SFP bus has been attached
  * @sfp_bus: SFP bus attached to this PHY's fiber port
+ * @sfp_cage_port: The phy_port connected to the downstream SFP cage
+ * @mod_port: phy_port representing the SFP module, if it is phy-less
+ * @upstream_port: phy_port this PHY's MII attaches to, if any
  * @attached_dev: The attached enet driver's device instance ptr
  * @adjust_link: Callback for the enet controller to respond to changes: in the
  *               link state.
@@ -724,6 +728,7 @@ struct phy_device {
 	unsigned irq_rerun:1;
 
 	unsigned default_timestamp:1;
+	unsigned has_sfp_mod_phy:1;
 
 	int rate_matching;
 
@@ -803,6 +808,9 @@ struct phy_device {
 	/* This may be modified under the rtnl lock */
 	bool sfp_bus_attached;
 	struct sfp_bus *sfp_bus;
+	struct phy_port *sfp_cage_port;
+	struct phy_port *mod_port;
+	struct phy_port *upstream_port;
 	struct phylink *phylink;
 	struct net_device *attached_dev;
 	struct mii_timestamper *mii_ts;
@@ -2487,6 +2495,8 @@ int __phy_hwtstamp_set(struct phy_device *phydev,
 
 struct phy_port *phy_get_sfp_port(struct phy_device *phydev);
 
+void phy_set_upstream_port(struct phy_device *phydev, struct phy_port *port);
+
 /**
  * phy_module_driver() - Helper macro for registering PHY drivers
  * @__phy_drivers: array of PHY drivers to register
diff --git a/include/linux/phy_link_topology.h b/include/linux/phy_link_topology.h
index 95575f68d5bc7..9585282cae3fc 100644
--- a/include/linux/phy_link_topology.h
+++ b/include/linux/phy_link_topology.h
@@ -13,14 +13,19 @@
 
 #include <linux/ethtool.h>
 #include <linux/netdevice.h>
+#include <linux/rtnetlink.h>
 
 struct xarray;
 struct phy_device;
+struct phy_port;
 struct sfp_bus;
 
 struct phy_link_topology {
 	struct xarray phys;
 	u32 next_phy_index;
+
+	struct xarray ports;
+	u32 next_port_index;
 };
 
 struct phy_device_node {
@@ -48,6 +53,9 @@ int phy_link_topo_add_phy(struct net_device *dev,
 
 void phy_link_topo_del_phy(struct net_device *dev, struct phy_device *phy);
 
+int phy_link_topo_add_port(struct net_device *dev, struct phy_port *port);
+void phy_link_topo_del_port(struct net_device *dev, struct phy_port *port);
+
 static inline struct phy_device *
 phy_link_topo_get_phy(struct net_device *dev, u32 phyindex)
 {
@@ -64,6 +72,25 @@ phy_link_topo_get_phy(struct net_device *dev, u32 phyindex)
 	return NULL;
 }
 
+static inline struct phy_port *
+phy_link_topo_get_port(struct net_device *dev, u32 port_id)
+{
+	struct phy_link_topology *topo = dev->link_topo;
+
+	if (!topo)
+		return NULL;
+
+	/* ports in the topo are RTNL protected, but may be accessed under
+	 * netdev_lock for ops-locked devices. For now keep them under rtnl
+	 * protection, as no ops-locked devices have phy_port capabilities
+	 * yet.
+	 */
+	ASSERT_RTNL();
+
+	/* Caller must hold RTNL while handling the phy_port */
+	return xa_load(&topo->ports, port_id);
+}
+
 #else
 static inline int phy_link_topo_add_phy(struct net_device *dev,
 					struct phy_device *phy,
@@ -77,11 +104,28 @@ static inline void phy_link_topo_del_phy(struct net_device *dev,
 {
 }
 
+static inline int phy_link_topo_add_port(struct net_device *dev,
+					 struct phy_port *port)
+{
+	return 0;
+}
+
+static inline void phy_link_topo_del_port(struct net_device *dev,
+					  struct phy_port *port)
+{
+}
+
 static inline struct phy_device *
 phy_link_topo_get_phy(struct net_device *dev, u32 phyindex)
 {
 	return NULL;
 }
+
+static inline struct phy_port *
+phy_link_topo_get_port(struct net_device *dev, u32 port_id)
+{
+	return NULL;
+}
 #endif
 
 #endif /* __PHY_LINK_TOPOLOGY_H */
diff --git a/include/linux/phy_port.h b/include/linux/phy_port.h
index 0ef0f5ce47092..8f45c031cbc10 100644
--- a/include/linux/phy_port.h
+++ b/include/linux/phy_port.h
@@ -36,9 +36,12 @@ struct phy_port_ops {
 /**
  * struct phy_port - A representation of a network device physical interface
  *
+ * @id: Unique identifier for the port within the topology
  * @head: Used by the port's parent to list ports
  * @parent_type: The type of device this port is directly connected to
  * @phy: If the parent is PHY_PORT_PHYDEV, the PHY controlling that port
+ * @upstream_port: Indicates the MII port that feeds this port, if any,
+ *		   e.g. the SFP cage port for a SFP module port.
  * @ops: Callback ops implemented by the port controller
  * @pairs: The number of  pairs this port has, 0 if not applicable
  * @mediums: Bitmask of the physical mediums this port provides access to
@@ -52,11 +55,13 @@ struct phy_port_ops {
  * @is_sfp: Indicates if this port drives an SFP cage.
  */
 struct phy_port {
+	u32 id;
 	struct list_head head;
 	enum phy_port_parent parent_type;
 	union {
 		struct phy_device *phy;
 	};
+	struct phy_port *upstream_port;
 
 	const struct phy_port_ops *ops;
 
diff --git a/include/uapi/linux/ethtool_netlink_generated.h b/include/uapi/linux/ethtool_netlink_generated.h
index 8134baf7860f3..660e0c08a766a 100644
--- a/include/uapi/linux/ethtool_netlink_generated.h
+++ b/include/uapi/linux/ethtool_netlink_generated.h
@@ -78,6 +78,14 @@ enum ethtool_pse_event {
 	ETHTOOL_PSE_EVENT_SW_PW_CONTROL_ERROR = 64,
 };
 
+/*
+ * type of physical connector
+ */
+enum ethtool_port_type {
+	ETHTOOL_PORT_TYPE_MDI,
+	ETHTOOL_PORT_TYPE_SFP,
+};
+
 enum {
 	ETHTOOL_A_HEADER_UNSPEC,
 	ETHTOOL_A_HEADER_DEV_INDEX,
@@ -840,6 +848,18 @@ enum {
 	ETHTOOL_A_MSE_MAX = (__ETHTOOL_A_MSE_CNT - 1)
 };
 
+enum {
+	ETHTOOL_A_PORT_HEADER = 1,
+	ETHTOOL_A_PORT_ID,
+	ETHTOOL_A_PORT_SUPPORTED_MODES,
+	ETHTOOL_A_PORT_SUPPORTED_INTERFACES,
+	ETHTOOL_A_PORT_TYPE,
+	ETHTOOL_A_PORT_UPSTREAM_PORT,
+
+	__ETHTOOL_A_PORT_CNT,
+	ETHTOOL_A_PORT_MAX = (__ETHTOOL_A_PORT_CNT - 1)
+};
+
 enum {
 	ETHTOOL_MSG_USER_NONE = 0,
 	ETHTOOL_MSG_STRSET_GET = 1,
@@ -893,6 +913,7 @@ enum {
 	ETHTOOL_MSG_RSS_CREATE_ACT,
 	ETHTOOL_MSG_RSS_DELETE_ACT,
 	ETHTOOL_MSG_MSE_GET,
+	ETHTOOL_MSG_PORT_GET,
 
 	__ETHTOOL_MSG_USER_CNT,
 	ETHTOOL_MSG_USER_MAX = (__ETHTOOL_MSG_USER_CNT - 1)
@@ -954,6 +975,7 @@ enum {
 	ETHTOOL_MSG_RSS_CREATE_NTF,
 	ETHTOOL_MSG_RSS_DELETE_NTF,
 	ETHTOOL_MSG_MSE_GET_REPLY,
+	ETHTOOL_MSG_PORT_GET_REPLY,
 
 	__ETHTOOL_MSG_KERNEL_CNT,
 	ETHTOOL_MSG_KERNEL_MAX = (__ETHTOOL_MSG_KERNEL_CNT - 1)
diff --git a/net/core/dev.c b/net/core/dev.c
index 290e0f099e6bf..8c061df5b6a8f 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -11367,6 +11367,7 @@ static void netdev_free_phy_link_topology(struct net_device *dev)
 
 	if (IS_ENABLED(CONFIG_PHYLIB) && topo) {
 		xa_destroy(&topo->phys);
+		xa_destroy(&topo->ports);
 		kfree(topo);
 		dev->link_topo = NULL;
 	}
diff --git a/net/ethtool/Makefile b/net/ethtool/Makefile
index 629c10916670e..9b5b096700081 100644
--- a/net/ethtool/Makefile
+++ b/net/ethtool/Makefile
@@ -9,4 +9,4 @@ ethtool_nl-y	:= netlink.o bitset.o strset.o linkinfo.o linkmodes.o rss.o \
 		   channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o \
 		   tunnels.o fec.o eeprom.o stats.o phc_vclocks.o mm.o \
 		   module.o cmis_fw_update.o cmis_cdb.o pse-pd.o plca.o \
-		   phy.o tsconfig.o mse.o
+		   phy.o tsconfig.o mse.o port.o
diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c
index 1af395b54330e..c076c07d0a080 100644
--- a/net/ethtool/netlink.c
+++ b/net/ethtool/netlink.c
@@ -26,6 +26,8 @@ static u32 ethnl_bcast_seq;
 			     ETHTOOL_FLAG_OMIT_REPLY)
 #define ETHTOOL_FLAGS_STATS (ETHTOOL_FLAGS_BASIC | ETHTOOL_FLAG_STATS)
 
+char phy_interface_names[PHY_INTERFACE_MODE_MAX][ETH_GSTRING_LEN] __ro_after_init;
+
 const struct nla_policy ethnl_header_policy[] = {
 	[ETHTOOL_A_HEADER_DEV_INDEX]	= { .type = NLA_U32 },
 	[ETHTOOL_A_HEADER_DEV_NAME]	= { .type = NLA_NUL_STRING,
@@ -431,6 +433,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = {
 	[ETHTOOL_MSG_TSCONFIG_SET]	= &ethnl_tsconfig_request_ops,
 	[ETHTOOL_MSG_PHY_GET]		= &ethnl_phy_request_ops,
 	[ETHTOOL_MSG_MSE_GET]		= &ethnl_mse_request_ops,
+	[ETHTOOL_MSG_PORT_GET]		= &ethnl_port_request_ops,
 };
 
 static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb)
@@ -1572,6 +1575,15 @@ static const struct genl_ops ethtool_genl_ops[] = {
 		.policy = ethnl_mse_get_policy,
 		.maxattr = ARRAY_SIZE(ethnl_mse_get_policy) - 1,
 	},
+	{
+		.cmd	= ETHTOOL_MSG_PORT_GET,
+		.doit	= ethnl_default_doit,
+		.start	= ethnl_port_dump_start,
+		.dumpit	= ethnl_port_dumpit,
+		.done	= ethnl_port_dump_done,
+		.policy = ethnl_port_get_policy,
+		.maxattr = ARRAY_SIZE(ethnl_port_get_policy) - 1,
+	},
 };
 
 static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
@@ -1594,10 +1606,23 @@ static struct genl_family ethtool_genl_family __ro_after_init = {
 
 /* module setup */
 
+static void __init ethnl_phy_names_populate(void)
+{
+	const char *name;
+	int i;
+
+	for (i = 0; i < PHY_INTERFACE_MODE_MAX; i++) {
+		name = phy_modes(i);
+		strscpy(phy_interface_names[i], name, ETH_GSTRING_LEN);
+	}
+}
+
 static int __init ethnl_init(void)
 {
 	int ret;
 
+	ethnl_phy_names_populate();
+
 	ret = genl_register_family(&ethtool_genl_family);
 	if (WARN(ret < 0, "ethtool: genetlink family registration failed"))
 		return ret;
diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h
index 3e969a070f9fe..dc7211f67c4d5 100644
--- a/net/ethtool/netlink.h
+++ b/net/ethtool/netlink.h
@@ -5,11 +5,14 @@
 
 #include <linux/ethtool_netlink.h>
 #include <linux/netdevice.h>
+#include <linux/phy.h>
 #include <net/genetlink.h>
 #include <net/sock.h>
 
 struct ethnl_req_info;
 
+extern char phy_interface_names[PHY_INTERFACE_MODE_MAX][ETH_GSTRING_LEN];
+
 int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info,
 			       const struct nlattr *nest, struct net *net,
 			       struct netlink_ext_ack *extack,
@@ -474,6 +477,7 @@ extern const struct ethnl_request_ops ethnl_mm_request_ops;
 extern const struct ethnl_request_ops ethnl_phy_request_ops;
 extern const struct ethnl_request_ops ethnl_tsconfig_request_ops;
 extern const struct ethnl_request_ops ethnl_mse_request_ops;
+extern const struct ethnl_request_ops ethnl_port_request_ops;
 
 extern const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_FLAGS + 1];
 extern const struct nla_policy ethnl_header_policy_stats[ETHTOOL_A_HEADER_FLAGS + 1];
@@ -530,6 +534,7 @@ extern const struct nla_policy ethnl_phy_get_policy[ETHTOOL_A_PHY_HEADER + 1];
 extern const struct nla_policy ethnl_tsconfig_get_policy[ETHTOOL_A_TSCONFIG_HEADER + 1];
 extern const struct nla_policy ethnl_tsconfig_set_policy[ETHTOOL_A_TSCONFIG_MAX + 1];
 extern const struct nla_policy ethnl_mse_get_policy[ETHTOOL_A_MSE_HEADER + 1];
+extern const struct nla_policy ethnl_port_get_policy[ETHTOOL_A_PORT_ID + 1];
 
 int ethnl_set_features(struct sk_buff *skb, struct genl_info *info);
 int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info);
@@ -545,6 +550,9 @@ int ethnl_tsinfo_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
 int ethnl_tsinfo_done(struct netlink_callback *cb);
 int ethnl_rss_create_doit(struct sk_buff *skb, struct genl_info *info);
 int ethnl_rss_delete_doit(struct sk_buff *skb, struct genl_info *info);
+int ethnl_port_dump_start(struct netlink_callback *cb);
+int ethnl_port_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
+int ethnl_port_dump_done(struct netlink_callback *cb);
 
 extern const char stats_std_names[__ETHTOOL_STATS_CNT][ETH_GSTRING_LEN];
 extern const char stats_eth_phy_names[__ETHTOOL_A_STATS_ETH_PHY_CNT][ETH_GSTRING_LEN];
diff --git a/net/ethtool/port.c b/net/ethtool/port.c
new file mode 100644
index 0000000000000..0d6150e5f66a2
--- /dev/null
+++ b/net/ethtool/port.c
@@ -0,0 +1,382 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright 2026 Bootlin
+ */
+#include <linux/phy.h>
+#include <linux/phy_link_topology.h>
+#include <linux/phy_port.h>
+#include <net/netdev_lock.h>
+
+#include "bitset.h"
+#include "common.h"
+#include "netlink.h"
+
+struct port_req_info {
+	struct ethnl_req_info base;
+	u32 port_id;
+};
+
+struct port_reply_data {
+	struct ethnl_reply_data	base;
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
+	DECLARE_PHY_INTERFACE_MASK(interfaces);
+	u32 port_id;
+	bool mii;
+	bool sfp;
+	u32 upstream_port;
+};
+
+#define PORT_REQINFO(__req_base) \
+	container_of(__req_base, struct port_req_info, base)
+
+#define PORT_REPDATA(__reply_base) \
+	container_of(__reply_base, struct port_reply_data, base)
+
+const struct nla_policy ethnl_port_get_policy[ETHTOOL_A_PORT_ID + 1] = {
+	[ETHTOOL_A_PORT_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy),
+	[ETHTOOL_A_PORT_ID] = NLA_POLICY_MIN(NLA_U32, 1),
+};
+
+static int port_parse_request(struct ethnl_req_info *req_info,
+			      const struct genl_info *info,
+			      struct nlattr **tb,
+			      struct netlink_ext_ack *extack)
+{
+	struct port_req_info *request = PORT_REQINFO(req_info);
+
+	if (GENL_REQ_ATTR_CHECK(info, ETHTOOL_A_PORT_ID))
+		return -EINVAL;
+
+	request->port_id = nla_get_u32(tb[ETHTOOL_A_PORT_ID]);
+
+	return 0;
+}
+
+static int port_prepare_data(const struct ethnl_req_info *req_info,
+			     struct ethnl_reply_data *reply_data,
+			     const struct genl_info *info)
+{
+	struct port_reply_data *reply = PORT_REPDATA(reply_data);
+	struct port_req_info *request = PORT_REQINFO(req_info);
+	struct phy_port *port;
+
+	/* RTNL must be held while holding a ref to the phy_port. Here, caller
+	 * holds RTNL.
+	 */
+	port = phy_link_topo_get_port(req_info->dev, request->port_id);
+	if (!port)
+		return -ENODEV;
+
+	linkmode_copy(reply->supported, port->supported);
+	phy_interface_copy(reply->interfaces, port->interfaces);
+	reply->port_id = port->id;
+	reply->mii = port->is_mii;
+	reply->sfp = port->is_sfp;
+	reply->upstream_port = port->upstream_port ? port->upstream_port->id : 0;
+
+	return 0;
+}
+
+static int port_reply_size(const struct ethnl_req_info *req_info,
+			   const struct ethnl_reply_data *reply_data)
+{
+	bool compact = req_info->flags & ETHTOOL_FLAG_COMPACT_BITSETS;
+	struct port_reply_data *reply = PORT_REPDATA(reply_data);
+	size_t size = 0;
+	int ret;
+
+	/* ETHTOOL_A_PORT_ID */
+	size += nla_total_size(sizeof(u32));
+
+	if (!reply->mii) {
+		/* ETHTOOL_A_PORT_SUPPORTED_MODES */
+		ret = ethnl_bitset_size(reply->supported, NULL,
+					__ETHTOOL_LINK_MODE_MASK_NBITS,
+					link_mode_names, compact);
+		if (ret < 0)
+			return ret;
+
+		size += ret;
+	} else {
+		/* ETHTOOL_A_PORT_SUPPORTED_INTERFACES */
+		ret = ethnl_bitset_size(reply->interfaces, NULL,
+					PHY_INTERFACE_MODE_MAX,
+					phy_interface_names, compact);
+		if (ret < 0)
+			return ret;
+
+		size += ret;
+	}
+
+	/* ETHTOOL_A_PORT_TYPE */
+	size += nla_total_size(sizeof(u32));
+
+	/* ETHTOOL_A_PORT_UPSTREAM_PORT */
+	if (reply->upstream_port)
+		size += nla_total_size(sizeof(u32));
+
+	return size;
+}
+
+static int port_fill_reply(struct sk_buff *skb,
+			   const struct ethnl_req_info *req_info,
+			   const struct ethnl_reply_data *reply_data)
+{
+	bool compact = req_info->flags & ETHTOOL_FLAG_COMPACT_BITSETS;
+	struct port_reply_data *reply = PORT_REPDATA(reply_data);
+	int ret, port_type = ETHTOOL_PORT_TYPE_MDI;
+
+	if (nla_put_u32(skb, ETHTOOL_A_PORT_ID, reply->port_id))
+		return -EMSGSIZE;
+
+	if (!reply->mii) {
+		ret = ethnl_put_bitset(skb, ETHTOOL_A_PORT_SUPPORTED_MODES,
+				       reply->supported, NULL,
+				       __ETHTOOL_LINK_MODE_MASK_NBITS,
+				       link_mode_names, compact);
+		if (ret < 0)
+			return ret;
+	} else {
+		ret = ethnl_put_bitset(skb, ETHTOOL_A_PORT_SUPPORTED_INTERFACES,
+				       reply->interfaces, NULL,
+				       PHY_INTERFACE_MODE_MAX,
+				       phy_interface_names, compact);
+		if (ret < 0)
+			return ret;
+	}
+
+	if (reply->mii || reply->sfp)
+		port_type = ETHTOOL_PORT_TYPE_SFP;
+
+	if (nla_put_u32(skb, ETHTOOL_A_PORT_TYPE, port_type))
+		return -EMSGSIZE;
+
+	if (reply->upstream_port &&
+	    nla_put_u32(skb, ETHTOOL_A_PORT_UPSTREAM_PORT,
+			reply->upstream_port))
+		return -EMSGSIZE;
+
+	return 0;
+}
+
+struct port_dump_ctx {
+	struct port_req_info	*req_info;
+	struct port_reply_data	*reply_data;
+	unsigned long		ifindex;
+	unsigned long		pos_ifindex;
+	unsigned long		pos_portid;
+};
+
+static struct port_dump_ctx *
+port_dump_ctx_get(struct netlink_callback *cb)
+{
+	return (struct port_dump_ctx *)cb->ctx;
+}
+
+int ethnl_port_dump_start(struct netlink_callback *cb)
+{
+	const struct genl_dumpit_info *info = genl_dumpit_info(cb);
+	struct port_dump_ctx *ctx = port_dump_ctx_get(cb);
+	struct nlattr **tb = info->info.attrs;
+	struct port_reply_data *reply_data;
+	struct port_req_info *req_info;
+	int ret;
+
+	BUILD_BUG_ON(sizeof(*ctx) > sizeof(cb->ctx));
+
+	req_info = kzalloc_obj(*req_info);
+	if (!req_info)
+		return -ENOMEM;
+
+	reply_data = kmalloc_obj(*reply_data);
+	if (!reply_data) {
+		ret = -ENOMEM;
+		goto free_req_info;
+	}
+
+	ret = ethnl_parse_header_dev_get(&req_info->base, tb[ETHTOOL_A_PORT_HEADER],
+					 genl_info_net(&info->info),
+					 info->info.extack, false);
+	if (ret < 0)
+		goto free_rep_data;
+
+	ctx->ifindex = 0;
+	ctx->pos_ifindex = 0;
+
+	/* For filtered DUMP requests, let's just store the ifindex. We'll check
+	 * again if the netdev is still there when looping over the netdev list
+	 * in the DUMP loop.
+	 */
+	if (req_info->base.dev) {
+		ctx->ifindex = req_info->base.dev->ifindex;
+		netdev_put(req_info->base.dev, &req_info->base.dev_tracker);
+		req_info->base.dev = NULL;
+	}
+
+	ctx->req_info = req_info;
+	ctx->reply_data = reply_data;
+
+	return 0;
+
+free_rep_data:
+	kfree(reply_data);
+free_req_info:
+	kfree(req_info);
+
+	return ret;
+}
+
+static int port_dump_one(struct sk_buff *skb, struct net_device *dev,
+			 struct netlink_callback *cb)
+{
+	struct port_dump_ctx *ctx = port_dump_ctx_get(cb);
+	void *ehdr;
+	int ret;
+
+	ehdr = ethnl_dump_put(skb, cb, ETHTOOL_MSG_PORT_GET_REPLY);
+	if (!ehdr)
+		return -EMSGSIZE;
+
+	memset(ctx->reply_data, 0, sizeof(struct port_reply_data));
+	ctx->reply_data->base.dev = dev;
+
+	rtnl_lock();
+	netdev_lock_ops(dev);
+
+	ret = port_prepare_data(&ctx->req_info->base, &ctx->reply_data->base,
+				genl_info_dump(cb));
+
+	netdev_unlock_ops(dev);
+	rtnl_unlock();
+
+	if (ret < 0)
+		goto out;
+
+	ret = ethnl_fill_reply_header(skb, dev, ETHTOOL_A_PORT_HEADER);
+	if (ret < 0)
+		goto out;
+
+	ret = port_fill_reply(skb, &ctx->req_info->base, &ctx->reply_data->base);
+
+out:
+	ctx->reply_data->base.dev = NULL;
+	if (ret < 0)
+		genlmsg_cancel(skb, ehdr);
+	else
+		genlmsg_end(skb, ehdr);
+
+	return ret;
+}
+
+static int port_dump_one_dev(struct sk_buff *skb, struct netlink_callback *cb)
+{
+	struct port_dump_ctx *ctx = port_dump_ctx_get(cb);
+	struct net_device *dev;
+	struct phy_port *port;
+	int ret;
+
+	dev = ctx->req_info->base.dev;
+
+	if (!dev->link_topo)
+		return 0;
+
+	xa_for_each_start(&dev->link_topo->ports, ctx->pos_portid, port,
+			  ctx->pos_portid) {
+		ctx->req_info->port_id = ctx->pos_portid;
+
+		ret = port_dump_one(skb, dev, cb);
+		if (ret == -ENODEV)
+			continue;
+		if (ret)
+			return ret;
+	}
+
+	ctx->pos_portid = 0;
+
+	return 0;
+}
+
+static int port_dump_all_dev(struct sk_buff *skb, struct netlink_callback *cb)
+{
+	struct port_dump_ctx *ctx = port_dump_ctx_get(cb);
+	struct net *net = sock_net(skb->sk);
+	netdevice_tracker dev_tracker;
+	struct net_device *dev;
+	int ret = 0;
+
+	rcu_read_lock();
+	for_each_netdev_dump(net, dev, ctx->pos_ifindex) {
+		netdev_hold(dev, &dev_tracker, GFP_ATOMIC);
+		rcu_read_unlock();
+
+		ctx->req_info->base.dev = dev;
+		ret = port_dump_one_dev(skb, cb);
+
+		rcu_read_lock();
+		netdev_put(dev, &dev_tracker);
+		ctx->req_info->base.dev = NULL;
+
+		if (ret < 0 && ret != -EOPNOTSUPP) {
+			if (likely(skb->len))
+				ret = skb->len;
+			break;
+		}
+
+		ret = 0;
+	}
+	rcu_read_unlock();
+
+	return ret;
+}
+
+int ethnl_port_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
+{
+	const struct genl_dumpit_info *info = genl_dumpit_info(cb);
+	struct port_dump_ctx *ctx = port_dump_ctx_get(cb);
+	int ret = 0;
+
+	if (ctx->ifindex) {
+		netdevice_tracker dev_tracker;
+		struct net_device *dev;
+
+		dev = netdev_get_by_index(genl_info_net(&info->info),
+					  ctx->ifindex, &dev_tracker,
+					  GFP_KERNEL);
+		if (!dev)
+			return -ENODEV;
+
+		ctx->req_info->base.dev = dev;
+		ret = port_dump_one_dev(skb, cb);
+		if (ret < 0 && ret != -EOPNOTSUPP && likely(skb->len))
+			ret = skb->len;
+
+		netdev_put(dev, &dev_tracker);
+	} else {
+		ret = port_dump_all_dev(skb, cb);
+	}
+
+	return ret;
+}
+
+int ethnl_port_dump_done(struct netlink_callback *cb)
+{
+	struct port_dump_ctx *ctx = port_dump_ctx_get(cb);
+
+	kfree(ctx->req_info);
+	kfree(ctx->reply_data);
+
+	return 0;
+}
+
+const struct ethnl_request_ops ethnl_port_request_ops = {
+	.request_cmd		= ETHTOOL_MSG_PORT_GET,
+	.reply_cmd		= ETHTOOL_MSG_PORT_GET_REPLY,
+	.hdr_attr		= ETHTOOL_A_PORT_HEADER,
+	.req_info_size		= sizeof(struct port_req_info),
+	.reply_data_size	= sizeof(struct port_reply_data),
+
+	.parse_request		= port_parse_request,
+	.prepare_data		= port_prepare_data,
+	.reply_size		= port_reply_size,
+	.fill_reply		= port_fill_reply,
+};

17/3 2026/09/10 19:11 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 20898
							output: 19
							thoughts: 795
						

Thoughts:
**Analyzing the Patch for KMSAN Implications**

Okay, let's dive into this patch with KMSAN in mind. The primary question is whether these code changes warrant a dedicated KMSAN fuzzing session. Remember, the key distinction is that KMSAN specifically targets reads of *uninitialized* memory, unlike KASAN which handles more general memory errors. We need to be on the lookout for code that introduces or exposes the risk of reading uninitialized stack, heap, or page allocations, or potential kernel-to-user memory leaks. The guidelines are clear:  NeedsKMSAN should only be set if the code changes directly introduce *uninitialized memory reads* that KMSAN would catch.

The specific scenarios to watch out for are: kernel structures being sent to user space where fields might be uninitialized, conditional logic depending on uninitialized variables, allocation and initialization of complex data structures where uninitialized fields could be read later, or logic or bounds checks that expose uninitialized bytes.

Now, let's examine the actual code changes. First, we have documentation updates, which are unlikely to be relevant. Then, we see changes in `drivers/net/phy/phy_caps.c`.  The key function is `phy_caps_linkmode_filter_ifaces()`.  It initializes `ifaces_supported` to `{}` and `ifaces_caps` to `0`.  That's good; looks like those variables are being initialized, so no obvious KMSAN risk there.

Next, we move to `drivers/net/phy/phy_device.c`.  There are a number of functions being modified: `phy_sfp_connect_phy()`, `phy_sfp_disconnect_phy()`, `phy_add_sfp_mod_port()`, `phy_del_sfp_mod_port()`, `phy_sfp_module_start()`, `phy_sfp_module_stop()`, `phy_setup_sfp_port()`, `phy_sfp_probe()`, `phy_detach_internal()`, `phy_attach_direct()`, and `phy_set_upstream_port()`.  In particular, `phy_add_sfp_mod_port()` allocates a `phy_port` using `phy_port_alloc()`. *That's* the one that catches my eye. We need to confirm how `phy_port_alloc()` initializes the `phy_port` structure and what its members are. Any uninitialized fields in that structure could be a KMSAN risk if they are later read. So, time to grep the kernel for `phy_port_alloc()` and related initializations. Let's see what we can find.



18/3 2026/09/10 19:11 tool grepper
0m Args:
{
  "Expression": "phy_port_alloc"
}

Results:
{
  "Output": "drivers/net/phy/phy_device.c=1635=static int phy_add_sfp_mod_port(struct phy_device *phydev)\n--\ndrivers/net/phy/phy_device.c-1641-\t/* Create mod port */\ndrivers/net/phy/phy_device.c:1642:\tport = phy_port_alloc();\ndrivers/net/phy/phy_device.c-1643-\tif (!port)\n--\ndrivers/net/phy/phy_device.c=1767=static struct phy_port *phy_setup_sfp_port(struct phy_device *phydev)\ndrivers/net/phy/phy_device.c-1768-{\ndrivers/net/phy/phy_device.c:1769:\tstruct phy_port *port = phy_port_alloc();\ndrivers/net/phy/phy_device.c-1770-\tint ret;\n--\ndrivers/net/phy/phy_device.c=3627=static int phy_default_setup_single_port(struct phy_device *phydev)\ndrivers/net/phy/phy_device.c-3628-{\ndrivers/net/phy/phy_device.c:3629:\tstruct phy_port *port = phy_port_alloc();\ndrivers/net/phy/phy_device.c-3630-\tunsigned long mode;\n--\ndrivers/net/phy/phy_port.c-13-/**\ndrivers/net/phy/phy_port.c:14: * phy_port_alloc() - Allocate a new phy_port\ndrivers/net/phy/phy_port.c-15- *\n--\ndrivers/net/phy/phy_port.c-17- */\ndrivers/net/phy/phy_port.c:18:struct phy_port *phy_port_alloc(void)\ndrivers/net/phy/phy_port.c-19-{\n--\ndrivers/net/phy/phy_port.c-30-}\ndrivers/net/phy/phy_port.c:31:EXPORT_SYMBOL_GPL(phy_port_alloc);\ndrivers/net/phy/phy_port.c-32-\n--\ndrivers/net/phy/phy_port.c=50=struct phy_port *phy_of_parse_port(struct device_node *dn)\n--\ndrivers/net/phy/phy_port.c-87-\ndrivers/net/phy/phy_port.c:88:\tport = phy_port_alloc();\ndrivers/net/phy/phy_port.c-89-\tif (!port)\n--\ndrivers/net/phy/phylink.c=1772=static int phylink_create_sfp_cage_port(struct phylink *pl)\n--\ndrivers/net/phy/phylink.c-1779-\ndrivers/net/phy/phylink.c:1780:\tport = phy_port_alloc();\ndrivers/net/phy/phylink.c-1781-\tif (!port)\n--\ndrivers/net/phy/phylink.c=4001=static int phylink_add_sfp_mod_port(struct phylink *pl)\n--\ndrivers/net/phy/phylink.c-4010-\t/* Create mod port */\ndrivers/net/phy/phylink.c:4011:\tport = phy_port_alloc();\ndrivers/net/phy/phylink.c-4012-\tif (!port)\n--\ninclude/linux/phy_port.h=57=struct phy_port {\n--\ninclude/linux/phy_port.h-78-\ninclude/linux/phy_port.h:79:struct phy_port *phy_port_alloc(void);\ninclude/linux/phy_port.h-80-void phy_port_destroy(struct phy_port *port);\n"
}

19/3 2026/09/10 19:11 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 23246
							output: 37
							thoughts: 23
						

Thoughts:
Here's a summary of my thought process, as requested:

**Diving into `phy_port.c`**

Alright, let's get down to brass tacks. I'm going to start by taking a look at `drivers/net/phy/phy_port.c`. Specifically, I'm focusing my attention around line 18. This is likely where the core data structure or function calls related to the PHY port management are defined, or perhaps it's an important include. Given my experience, I'm expecting something foundational – maybe a structure definition for a PHY port, initialization routines, or even the top-level dispatch table for PHY driver interactions. This location usually provides a good entry point to understand how the PHY subsystem interacts with the rest of the networking stack, so this is a great place to begin.



20/3 2026/09/10 19:11 tool read-file
0m Args:
{
  "File": "drivers/net/phy/phy_port.c",
  "FirstLine": 1,
  "LineCount": 40
}

Results:
{
  "Contents": "   1:\t// SPDX-License-Identifier: GPL-2.0+\n   2:\t/* Framework to drive Ethernet ports\n   3:\t *\n   4:\t * Copyright (c) 2024 Maxime Chevallier \u003cmaxime.chevallier@bootlin.com\u003e\n   5:\t */\n   6:\t\n   7:\t#include \u003clinux/linkmode.h\u003e\n   8:\t#include \u003clinux/of.h\u003e\n   9:\t#include \u003clinux/phy_port.h\u003e\n  10:\t\n  11:\t#include \"phy-caps.h\"\n  12:\t\n  13:\t/**\n  14:\t * phy_port_alloc() - Allocate a new phy_port\n  15:\t *\n  16:\t * Returns: a newly allocated struct phy_port, or NULL.\n  17:\t */\n  18:\tstruct phy_port *phy_port_alloc(void)\n  19:\t{\n  20:\t\tstruct phy_port *port;\n  21:\t\n  22:\t\tport = kzalloc_obj(*port);\n  23:\t\tif (!port)\n  24:\t\t\treturn NULL;\n  25:\t\n  26:\t\tlinkmode_zero(port-\u003esupported);\n  27:\t\tINIT_LIST_HEAD(\u0026port-\u003ehead);\n  28:\t\n  29:\t\treturn port;\n  30:\t}\n  31:\tEXPORT_SYMBOL_GPL(phy_port_alloc);\n  32:\t\n  33:\t/**\n  34:\t * phy_port_destroy() - Free a struct phy_port\n  35:\t * @port: The port to destroy\n  36:\t */\n  37:\tvoid phy_port_destroy(struct phy_port *port)\n  38:\t{\n  39:\t\tkfree(port);\n  40:\t}\n"
}

21/3 2026/09/10 19:11 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 23961
							output: 33
							thoughts: 313
						

Thoughts:
**Analyzing Port Allocation and Netlink Request Handling**

Okay, so `phy_port_alloc()` is using `kzalloc_obj(*port)` – that means the entire `struct` is being zeroed out. Good to know. Now, I want to see how `net/ethtool/port.c` handles these Netlink requests and replies, specifically to understand how the port information is being managed. Let's dig in line-by-line.

First, the `port_parse_request()` function:
```c
static int port_parse_request(struct ethnl_req_info *req_info,
			      const struct genl_info *info,
			      struct nlattr **tb,
			      struct netlink_ext_ack *extack)
{
	struct port_req_info *request = PORT_REQINFO(req_info);

	if (GENL_REQ_ATTR_CHECK(info, ETHTOOL_A_PORT_ID))
		return -EINVAL;

	request->port_id = nla_get_u32(tb[ETHTOOL_A_PORT_ID]);

	return 0;
}
```
Alright, looks like `port_parse_request` is responsible for parsing the incoming Netlink request. I see it's extracting the `port_id` from the `ETHTOOL_A_PORT_ID` attribute. The `PORT_REQINFO` macro suggests there's some common request information being handled. Also, I need to remember that for the `doit` function, `ethnl_default_doit()` allocates `req_info` and `reply_data` using `kzalloc`. That confirms the zero-initialization strategy. I need to understand how `ethnl_default_doit()` works because this is the fundamental process. Let's look at `net/ethtool/netlink.c`.



22/3 2026/09/10 19:11 tool grepper
0m Args:
{
  "Expression": "ethnl_default_doit",
  "PathPrefix": "net/ethtool/"
}

Results:
{
  "Output": "net/ethtool/netlink.c=501=static void ethnl_init_reply_data(struct ethnl_reply_data *reply_data,\n--\nnet/ethtool/netlink.c-509-/* default -\u003edoit() handler for GET type requests */\nnet/ethtool/netlink.c:510:static int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info)\nnet/ethtool/netlink.c-511-{\n--\nnet/ethtool/netlink.c=1164=static const struct genl_ops ethtool_genl_ops[] = {\n--\nnet/ethtool/netlink.c-1166-\t\t.cmd\t= ETHTOOL_MSG_STRSET_GET,\nnet/ethtool/netlink.c:1167:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1168-\t\t.start\t= ethnl_default_start,\n--\nnet/ethtool/netlink.c-1175-\t\t.cmd\t= ETHTOOL_MSG_LINKINFO_GET,\nnet/ethtool/netlink.c:1176:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1177-\t\t.start\t= ethnl_default_start,\n--\nnet/ethtool/netlink.c-1191-\t\t.cmd\t= ETHTOOL_MSG_LINKMODES_GET,\nnet/ethtool/netlink.c:1192:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1193-\t\t.start\t= ethnl_default_start,\n--\nnet/ethtool/netlink.c-1207-\t\t.cmd\t= ETHTOOL_MSG_LINKSTATE_GET,\nnet/ethtool/netlink.c:1208:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1209-\t\t.start\t= ethnl_default_start,\n--\nnet/ethtool/netlink.c-1216-\t\t.cmd\t= ETHTOOL_MSG_DEBUG_GET,\nnet/ethtool/netlink.c:1217:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1218-\t\t.start\t= ethnl_default_start,\n--\nnet/ethtool/netlink.c-1233-\t\t.flags\t= GENL_UNS_ADMIN_PERM,\nnet/ethtool/netlink.c:1234:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1235-\t\t.start\t= ethnl_default_start,\n--\nnet/ethtool/netlink.c-1249-\t\t.cmd\t= ETHTOOL_MSG_FEATURES_GET,\nnet/ethtool/netlink.c:1250:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1251-\t\t.start\t= ethnl_default_start,\n--\nnet/ethtool/netlink.c-1265-\t\t.cmd\t= ETHTOOL_MSG_PRIVFLAGS_GET,\nnet/ethtool/netlink.c:1266:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1267-\t\t.start\t= ethnl_default_start,\n--\nnet/ethtool/netlink.c-1281-\t\t.cmd\t= ETHTOOL_MSG_RINGS_GET,\nnet/ethtool/netlink.c:1282:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1283-\t\t.start\t= ethnl_default_start,\n--\nnet/ethtool/netlink.c-1297-\t\t.cmd\t= ETHTOOL_MSG_CHANNELS_GET,\nnet/ethtool/netlink.c:1298:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1299-\t\t.start\t= ethnl_default_start,\n--\nnet/ethtool/netlink.c-1313-\t\t.cmd\t= ETHTOOL_MSG_COALESCE_GET,\nnet/ethtool/netlink.c:1314:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1315-\t\t.start\t= ethnl_default_start,\n--\nnet/ethtool/netlink.c-1329-\t\t.cmd\t= ETHTOOL_MSG_PAUSE_GET,\nnet/ethtool/netlink.c:1330:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1331-\t\t.start\t= ethnl_default_start,\n--\nnet/ethtool/netlink.c-1345-\t\t.cmd\t= ETHTOOL_MSG_EEE_GET,\nnet/ethtool/netlink.c:1346:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1347-\t\t.start\t= ethnl_default_start,\n--\nnet/ethtool/netlink.c-1361-\t\t.cmd\t= ETHTOOL_MSG_TSINFO_GET,\nnet/ethtool/netlink.c:1362:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1363-\t\t.start\t= ethnl_tsinfo_start,\n--\nnet/ethtool/netlink.c-1392-\t\t.cmd\t= ETHTOOL_MSG_FEC_GET,\nnet/ethtool/netlink.c:1393:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1394-\t\t.start\t= ethnl_default_start,\n--\nnet/ethtool/netlink.c-1409-\t\t.flags  = GENL_UNS_ADMIN_PERM,\nnet/ethtool/netlink.c:1410:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1411-\t\t.start\t= ethnl_default_start,\n--\nnet/ethtool/netlink.c-1418-\t\t.cmd\t= ETHTOOL_MSG_STATS_GET,\nnet/ethtool/netlink.c:1419:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1420-\t\t.start\t= ethnl_default_start,\n--\nnet/ethtool/netlink.c-1427-\t\t.cmd\t= ETHTOOL_MSG_PHC_VCLOCKS_GET,\nnet/ethtool/netlink.c:1428:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1429-\t\t.start\t= ethnl_default_start,\n--\nnet/ethtool/netlink.c-1436-\t\t.cmd\t= ETHTOOL_MSG_MODULE_GET,\nnet/ethtool/netlink.c:1437:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1438-\t\t.start\t= ethnl_default_start,\n--\nnet/ethtool/netlink.c-1452-\t\t.cmd\t= ETHTOOL_MSG_PSE_GET,\nnet/ethtool/netlink.c:1453:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1454-\t\t.start\t= ethnl_perphy_start,\n--\nnet/ethtool/netlink.c-1468-\t\t.cmd\t= ETHTOOL_MSG_RSS_GET,\nnet/ethtool/netlink.c:1469:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1470-\t\t.start\t= ethnl_rss_dump_start,\n--\nnet/ethtool/netlink.c-1476-\t\t.cmd\t= ETHTOOL_MSG_PLCA_GET_CFG,\nnet/ethtool/netlink.c:1477:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1478-\t\t.start\t= ethnl_perphy_start,\n--\nnet/ethtool/netlink.c-1492-\t\t.cmd\t= ETHTOOL_MSG_PLCA_GET_STATUS,\nnet/ethtool/netlink.c:1493:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1494-\t\t.start\t= ethnl_perphy_start,\n--\nnet/ethtool/netlink.c-1501-\t\t.cmd\t= ETHTOOL_MSG_MM_GET,\nnet/ethtool/netlink.c:1502:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1503-\t\t.start\t= ethnl_default_start,\n--\nnet/ethtool/netlink.c-1524-\t\t.cmd\t= ETHTOOL_MSG_PHY_GET,\nnet/ethtool/netlink.c:1525:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1526-\t\t.start\t= ethnl_perphy_start,\n--\nnet/ethtool/netlink.c-1533-\t\t.cmd\t= ETHTOOL_MSG_TSCONFIG_GET,\nnet/ethtool/netlink.c:1534:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1535-\t\t.start\t= ethnl_default_start,\n--\nnet/ethtool/netlink.c-1570-\t\t.cmd\t= ETHTOOL_MSG_MSE_GET,\nnet/ethtool/netlink.c:1571:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1572-\t\t.start\t= ethnl_perphy_start,\n--\nnet/ethtool/netlink.c-1579-\t\t.cmd\t= ETHTOOL_MSG_PORT_GET,\nnet/ethtool/netlink.c:1580:\t\t.doit\t= ethnl_default_doit,\nnet/ethtool/netlink.c-1581-\t\t.start\t= ethnl_port_dump_start,\n--\nnet/ethtool/netlink.h=357=int ethnl_sock_priv_set(struct sk_buff *skb, struct net *net, u32 portid,\n--\nnet/ethtool/netlink.h-416- * structure is to be added to \u0026ethnl_default_requests array and generic\nnet/ethtool/netlink.h:417: * handlers ethnl_default_doit(), ethnl_default_dumpit(),\nnet/ethtool/netlink.h-418- * ethnl_default_start() and ethnl_default_done() used in @ethtool_genl_ops;\n--\nnet/ethtool/plca.c=54=static int plca_get_cfg_prepare_data(const struct ethnl_req_info *req_base,\n--\nnet/ethtool/plca.c-72-\nnet/ethtool/plca.c:73:\t// note: rtnl_lock is held already by ethnl_default_doit\nnet/ethtool/plca.c-74-\tops = ethtool_phy_ops;\n--\nnet/ethtool/plca.c=203=static int plca_get_status_prepare_data(const struct ethnl_req_info *req_base,\n--\nnet/ethtool/plca.c-221-\nnet/ethtool/plca.c:222:\t// note: rtnl_lock is held already by ethnl_default_doit\nnet/ethtool/plca.c-223-\tops = ethtool_phy_ops;\n"
}

23/3 2026/09/10 19:11 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 27977
							output: 38
							thoughts: 26
						

Thoughts:
Here's my summary, as if I were thinking these thoughts:

**Analyzing `ethnl_default_doit` in `net/ethtool/netlink.c`**

Alright, let's dive into `ethnl_default_doit` within `net/ethtool/netlink.c`. I'm going to quickly get a handle on the default Netlink handler for ethtool. I need to understand how it processes generic Netlink requests, especially those that aren't explicitly handled elsewhere. My goal is to see the default behaviour and error checking this function does. It should handle unknown commands, perhaps route them to some default action. I expect this will be the fallback for all ethtool related commands sent through Netlink if more specific handling isn't in place. I'll pay close attention to the return codes and how errors are reported back to userspace. This will provide a baseline understanding that can then be compared with the more specific handlers. Knowing this function's behaviour is essential for understanding ethtool's overall netlink-based interface and how it handles unexpected or unimplemented commands. I need to see how it might, for instance, validate message attributes or perform basic checks before potentially forwarding the request. I also want to see if there are any obvious security considerations or potential denial-of-service vectors that might need further scrutiny. I'll need to remember this function, and its general purpose, as a key point of the overall design.



24/3 2026/09/10 19:12 tool read-file
0m Args:
{
  "File": "net/ethtool/netlink.c",
  "FirstLine": 510,
  "LineCount": 70
}

Results:
{
  "Contents": " 510:\tstatic int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info)\n 511:\t{\n 512:\t\tstruct ethnl_reply_data *reply_data = NULL;\n 513:\t\tstruct ethnl_req_info *req_info = NULL;\n 514:\t\tconst u8 cmd = info-\u003egenlhdr-\u003ecmd;\n 515:\t\tconst struct ethnl_request_ops *ops;\n 516:\t\tbool need_rtnl = false;\n 517:\t\tint hdr_len, reply_len;\n 518:\t\tstruct sk_buff *rskb;\n 519:\t\tvoid *reply_payload;\n 520:\t\tint ret;\n 521:\t\n 522:\t\tops = ethnl_default_requests[cmd];\n 523:\t\tif (WARN_ONCE(!ops, \"cmd %u has no ethnl_request_ops\\n\", cmd))\n 524:\t\t\treturn -EOPNOTSUPP;\n 525:\t\tif (GENL_REQ_ATTR_CHECK(info, ops-\u003ehdr_attr))\n 526:\t\t\treturn -EINVAL;\n 527:\t\n 528:\t\treq_info = kzalloc(ops-\u003ereq_info_size, GFP_KERNEL);\n 529:\t\tif (!req_info)\n 530:\t\t\treturn -ENOMEM;\n 531:\t\treply_data = kmalloc(ops-\u003ereply_data_size, GFP_KERNEL);\n 532:\t\tif (!reply_data) {\n 533:\t\t\tkfree(req_info);\n 534:\t\t\treturn -ENOMEM;\n 535:\t\t}\n 536:\t\n 537:\t\tret = ethnl_default_parse(req_info, info, ops, !ops-\u003eallow_nodev_do);\n 538:\t\tif (ret \u003c 0)\n 539:\t\t\tgoto err_free;\n 540:\t\tethnl_init_reply_data(reply_data, ops, req_info-\u003edev);\n 541:\t\n 542:\t\tif (req_info-\u003edev) {\n 543:\t\t\tneed_rtnl = !netdev_need_ops_lock(req_info-\u003edev) ||\n 544:\t\t\t\t    ethtool_nl_msg_needs_rtnl(req_info-\u003edev, cmd);\n 545:\t\t\tif (need_rtnl)\n 546:\t\t\t\trtnl_lock();\n 547:\t\t\tnetdev_lock_ops(req_info-\u003edev);\n 548:\t\t}\n 549:\t\tret = ops-\u003eprepare_data(req_info, reply_data, info);\n 550:\t\tif (req_info-\u003edev) {\n 551:\t\t\tnetdev_unlock_ops(req_info-\u003edev);\n 552:\t\t\tif (need_rtnl)\n 553:\t\t\t\trtnl_unlock();\n 554:\t\t}\n 555:\t\tif (ret \u003c 0)\n 556:\t\t\tgoto err_dev;\n 557:\t\tret = ops-\u003ereply_size(req_info, reply_data);\n 558:\t\tif (ret \u003c 0)\n 559:\t\t\tgoto err_cleanup;\n 560:\t\treply_len = ret;\n 561:\t\tret = -ENOMEM;\n 562:\t\trskb = ethnl_reply_init(reply_len + ethnl_reply_header_size(),\n 563:\t\t\t\t\treq_info-\u003edev, ops-\u003ereply_cmd,\n 564:\t\t\t\t\tops-\u003ehdr_attr, info, \u0026reply_payload);\n 565:\t\tif (!rskb)\n 566:\t\t\tgoto err_cleanup;\n 567:\t\thdr_len = rskb-\u003elen;\n 568:\t\tret = ops-\u003efill_reply(rskb, req_info, reply_data);\n 569:\t\tif (ret \u003c 0)\n 570:\t\t\tgoto err_msg;\n 571:\t\tWARN_ONCE(rskb-\u003elen - hdr_len \u003e reply_len,\n 572:\t\t\t  \"ethnl cmd %d: calculated reply length %d, but consumed %d\\n\",\n 573:\t\t\t  cmd, reply_len, rskb-\u003elen - hdr_len);\n 574:\t\tif (ops-\u003ecleanup_data)\n 575:\t\t\tops-\u003ecleanup_data(reply_data);\n 576:\t\n 577:\t\tgenlmsg_end(rskb, reply_payload);\n 578:\t\tnetdev_put(req_info-\u003edev, \u0026req_info-\u003edev_tracker);\n 579:\t\tkfree(reply_data);\n"
}

25/3 2026/09/10 19:12 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 29571
							output: 38
							thoughts: 24
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience and written in the first person:

**Analyzing `ethnl_init_reply_data()`**

Okay, time to dive into `ethnl_init_reply_data()`. Let me refresh my memory on what this function is specifically responsible for. Given the naming convention, I'm expecting it's going to initialize the data structure that holds the reply for an Ethernet Netlink interaction, probably setting up the header and preparing the payload buffer. I'll need to check the function definition, paying close attention to how it handles memory allocation, error checking (particularly for NULL pointers or allocation failures), and how it sets the various Netlink message attributes (like message type, sequence number, and port ID). I also want to see what assumptions it makes about the underlying Netlink socket and the caller's context. Is it thread-safe? Does it handle potential race conditions? Specifically, I'll be looking for potential buffer overflows or integer underflow/overflow vulnerabilities, especially if the function deals with sizes and lengths. Finally, I'll assess its overall efficiency - is it optimized for performance, or are there any obvious areas for improvement? Let's get cracking.



26/3 2026/09/10 19:12 tool read-file
0m Args:
{
  "File": "net/ethtool/netlink.c",
  "FirstLine": 498,
  "LineCount": 15
}

Results:
{
  "Contents": " 498:\t * before calling the -\u003efill_reply() callback (for each iteration when handling\n 499:\t * dump requests).\n 500:\t */\n 501:\tstatic void ethnl_init_reply_data(struct ethnl_reply_data *reply_data,\n 502:\t\t\t\t\t  const struct ethnl_request_ops *ops,\n 503:\t\t\t\t\t  struct net_device *dev)\n 504:\t{\n 505:\t\tmemset(reply_data, 0, ops-\u003ereply_data_size);\n 506:\t\treply_data-\u003edev = dev;\n 507:\t}\n 508:\t\n 509:\t/* default -\u003edoit() handler for GET type requests */\n 510:\tstatic int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info)\n 511:\t{\n 512:\t\tstruct ethnl_reply_data *reply_data = NULL;\n"
}

27/3 2026/09/10 19:12 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 30153
							output: 25
							thoughts: 318
						

Thoughts:
**My Initial Thoughts on Data Initialization and Handling**

Okay, so I'm looking at how this `reply_data` structure is initialized and used across these functions. I see a few places where zeroing is happening. In `doit`, `ethnl_init_reply_data()` zeroes it out. Then, in the `dumpit` function (`port_dump_one`), there's a `memset` on `ctx->reply_data`.  `ethnl_port_dump_start` is allocating memory with `kzalloc_obj` for `req_info` and `kmalloc_obj` for `reply_data` - that could be an issue if there is a problem with the kmalloc call, but the kzalloc should take care of that. And just to reiterate, we have another `memset` in `port_dump_one`. It appears that we are consistently initializing this struct to zero, which is good practice to ensure we start with a known state and avoid any garbage values.

Now, let's switch gears and investigate `ethnl_phy_names_populate()`. I need to understand how these PHY interface names are being populated. I see a loop that iterates through `PHY_INTERFACE_MODE_MAX` and calls `phy_modes(i)`. Then it copies the returned name into `phy_interface_names[i]` using `strscpy`.

I should probably verify the declaration of `phy_interface_names` - Yep, it's a `char` array, and `__ro_after_init` indicates it's read-only after initialization. Good, this is probably something we want to maintain!

My next step is to examine what `phy_modes()` returns. Specifically, I need to know what happens if `i` is a valid index versus an invalid index. I'm especially interested in the boundary conditions and whether `phy_modes()` handles out-of-bounds indices gracefully or if it could potentially lead to unexpected behavior. This has the potential to become a subtle bug if not handled carefully.



28/3 2026/09/10 19:12 tool grepper
0m Args:
{
  "Expression": "phy_modes",
  "PathPrefix": "include/"
}

Results:
{
  "Output": "include/linux/fsl_devices.h=55=enum fsl_usb2_operating_modes {\n--\ninclude/linux/fsl_devices.h-61-\ninclude/linux/fsl_devices.h:62:enum fsl_usb2_phy_modes {\ninclude/linux/fsl_devices.h-63-\tFSL_USB2_PHY_NONE,\n--\ninclude/linux/fsl_devices.h=74=struct fsl_usb2_platform_data {\n--\ninclude/linux/fsl_devices.h-77-\tenum fsl_usb2_operating_modes\toperating_mode;\ninclude/linux/fsl_devices.h:78:\tenum fsl_usb2_phy_modes\t\tphy_mode;\ninclude/linux/fsl_devices.h-79-\tunsigned int\t\t\tport_enables;\n--\ninclude/linux/phy.h=194=static inline void phy_interface_set_rgmii(unsigned long *intf)\n--\ninclude/linux/phy.h-202-/**\ninclude/linux/phy.h:203: * phy_modes - map phy_interface_t enum to device tree binding of phy-mode\ninclude/linux/phy.h-204- * @interface: enum phy_interface_t value\n--\ninclude/linux/phy.h-209- */\ninclude/linux/phy.h:210:static inline const char *phy_modes(phy_interface_t interface)\ninclude/linux/phy.h-211-{\n"
}

29/3 2026/09/10 19:12 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 31319
							output: 35
							thoughts: 19
						

Thoughts:
Here's my take on those thoughts:

**Investigating PHY Mode Definitions**

Okay, so I need to refresh my memory on how PHY modes are defined within the kernel. Let's start with `include/linux/phy.h`. That's where I would expect to find the core data structures and enums that govern the configuration and operation of Physical Layer Transceivers. I need to understand what specific attributes are defined, what options are available, and how these modes are represented internally. I'm probably looking for things like enumerations of supported speeds, duplex settings, and any specific PHY-specific flags that might be relevant to the driver I'm currently working with. I want to confirm my understanding of the fundamental building blocks of the PHY interface before I move on to more driver-specific code. Time to dig in and remind myself of those details!



30/3 2026/09/10 19:12 tool read-file
0m Args:
{
  "File": "include/linux/phy.h",
  "FirstLine": 210,
  "LineCount": 45
}

Results:
{
  "Contents": " 210:\tstatic inline const char *phy_modes(phy_interface_t interface)\n 211:\t{\n 212:\t\tswitch (interface) {\n 213:\t\tcase PHY_INTERFACE_MODE_NA:\n 214:\t\t\treturn \"\";\n 215:\t\tcase PHY_INTERFACE_MODE_INTERNAL:\n 216:\t\t\treturn \"internal\";\n 217:\t\tcase PHY_INTERFACE_MODE_MII:\n 218:\t\t\treturn \"mii\";\n 219:\t\tcase PHY_INTERFACE_MODE_GMII:\n 220:\t\t\treturn \"gmii\";\n 221:\t\tcase PHY_INTERFACE_MODE_SGMII:\n 222:\t\t\treturn \"sgmii\";\n 223:\t\tcase PHY_INTERFACE_MODE_TBI:\n 224:\t\t\treturn \"tbi\";\n 225:\t\tcase PHY_INTERFACE_MODE_REVMII:\n 226:\t\t\treturn \"rev-mii\";\n 227:\t\tcase PHY_INTERFACE_MODE_RMII:\n 228:\t\t\treturn \"rmii\";\n 229:\t\tcase PHY_INTERFACE_MODE_REVRMII:\n 230:\t\t\treturn \"rev-rmii\";\n 231:\t\tcase PHY_INTERFACE_MODE_RGMII:\n 232:\t\t\treturn \"rgmii\";\n 233:\t\tcase PHY_INTERFACE_MODE_RGMII_ID:\n 234:\t\t\treturn \"rgmii-id\";\n 235:\t\tcase PHY_INTERFACE_MODE_RGMII_RXID:\n 236:\t\t\treturn \"rgmii-rxid\";\n 237:\t\tcase PHY_INTERFACE_MODE_RGMII_TXID:\n 238:\t\t\treturn \"rgmii-txid\";\n 239:\t\tcase PHY_INTERFACE_MODE_RTBI:\n 240:\t\t\treturn \"rtbi\";\n 241:\t\tcase PHY_INTERFACE_MODE_SMII:\n 242:\t\t\treturn \"smii\";\n 243:\t\tcase PHY_INTERFACE_MODE_XGMII:\n 244:\t\t\treturn \"xgmii\";\n 245:\t\tcase PHY_INTERFACE_MODE_XLGMII:\n 246:\t\t\treturn \"xlgmii\";\n 247:\t\tcase PHY_INTERFACE_MODE_MOCA:\n 248:\t\t\treturn \"moca\";\n 249:\t\tcase PHY_INTERFACE_MODE_PSGMII:\n 250:\t\t\treturn \"psgmii\";\n 251:\t\tcase PHY_INTERFACE_MODE_QSGMII:\n 252:\t\t\treturn \"qsgmii\";\n 253:\t\tcase PHY_INTERFACE_MODE_TRGMII:\n 254:\t\t\treturn \"trgmii\";\n"
}

31/3 2026/09/10 19:12 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 32246
							output: 35
							thoughts: 21
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Analyzing `phy_modes()` for Default Behavior**

Okay, so I'm looking at this `phy_modes()` function, and my first instinct is to double-check something crucial for robust code: Does it handle all potential input scenarios? Specifically, I need to confirm that it has a clear default case. I don't want to get caught off guard by unexpected values or edge conditions. A well-defined default ensures consistent behavior, even if the input data isn't perfectly structured. This is especially important in low-level systems code where unpredictable hardware behavior is always a possibility. Let's dig deeper into the code to ensure this is addressed and understand how it functions in those circumstances.



32/3 2026/09/10 19:12 tool read-file
0m Args:
{
  "File": "include/linux/phy.h",
  "FirstLine": 255,
  "LineCount": 40
}

Results:
{
  "Contents": " 255:\t\tcase PHY_INTERFACE_MODE_1000BASEX:\n 256:\t\t\treturn \"1000base-x\";\n 257:\t\tcase PHY_INTERFACE_MODE_1000BASEKX:\n 258:\t\t\treturn \"1000base-kx\";\n 259:\t\tcase PHY_INTERFACE_MODE_2500BASEX:\n 260:\t\t\treturn \"2500base-x\";\n 261:\t\tcase PHY_INTERFACE_MODE_5GBASER:\n 262:\t\t\treturn \"5gbase-r\";\n 263:\t\tcase PHY_INTERFACE_MODE_RXAUI:\n 264:\t\t\treturn \"rxaui\";\n 265:\t\tcase PHY_INTERFACE_MODE_XAUI:\n 266:\t\t\treturn \"xaui\";\n 267:\t\tcase PHY_INTERFACE_MODE_10GBASER:\n 268:\t\t\treturn \"10gbase-r\";\n 269:\t\tcase PHY_INTERFACE_MODE_25GBASER:\n 270:\t\t\treturn \"25gbase-r\";\n 271:\t\tcase PHY_INTERFACE_MODE_USXGMII:\n 272:\t\t\treturn \"usxgmii\";\n 273:\t\tcase PHY_INTERFACE_MODE_10GKR:\n 274:\t\t\treturn \"10gbase-kr\";\n 275:\t\tcase PHY_INTERFACE_MODE_100BASEX:\n 276:\t\t\treturn \"100base-x\";\n 277:\t\tcase PHY_INTERFACE_MODE_QUSGMII:\n 278:\t\t\treturn \"qusgmii\";\n 279:\t\tcase PHY_INTERFACE_MODE_10G_QXGMII:\n 280:\t\t\treturn \"10g-qxgmii\";\n 281:\t\tcase PHY_INTERFACE_MODE_50GBASER:\n 282:\t\t\treturn \"50gbase-r\";\n 283:\t\tcase PHY_INTERFACE_MODE_LAUI:\n 284:\t\t\treturn \"laui\";\n 285:\t\tcase PHY_INTERFACE_MODE_100GBASEP:\n 286:\t\t\treturn \"100gbase-p\";\n 287:\t\tcase PHY_INTERFACE_MODE_MIILITE:\n 288:\t\t\treturn \"mii-lite\";\n 289:\t\tdefault:\n 290:\t\t\treturn \"unknown\";\n 291:\t\t}\n 292:\t}\n 293:\t\n 294:\t/**\n"
}

33/3 2026/09/10 19:12 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 33113
							output: 33
							thoughts: 568
						

Thoughts:
**Analyzing Bitset Serialization in Netlink for Ethernet Ports**

Okay, so I'm thinking about how we handle Ethernet port information, specifically the bitsets used to represent supported modes and interfaces in the Netlink messages. It's crucial for correct communication, so let's delve into the details.

First, I'm confident that `phy_modes()` always returns a valid, NUL-terminated string, and `strscpy()` is used to NUL-pad and terminate the data correctly when copying into `phy_interface_names[]`. That part seems sound.

Now, I need to understand how the bitsets themselves are formatted and serialized over Netlink. Let's look at `net/ethtool/port.c`. In `port_fill_reply()`, it seems we construct the Netlink message. The interesting part here is how we handle supported modes and interfaces within the `if (!reply->mii)` and `else` blocks respectively. We call `ethnl_put_bitset()` to handle the serialization of the bitsets. Notably, we use `link_mode_names` or `phy_interface_names` as the human-readable names, depending on whether we're dealing with a MII interface or something else. I also see that there's a flag `ETHTOOL_FLAG_COMPACT_BITSETS` for potentially compressing the bitset representation, interesting. The rest of the `port_fill_reply` function handles other port attributes, like the port ID, type, and upstream port information, which is fine, I'm more focused on the bitset representation right now.

Now, I'm going to shift focus to `ethnl_put_bitset()` itself, to truly understand how it operates on these bitset arrays. This is the critical piece that I need to analyze to ensure data integrity during serialization.



34/3 2026/09/10 19:12 tool grepper
0m Args:
{
  "Expression": "ethnl_put_bitset",
  "PathPrefix": "net/ethtool/"
}

Results:
{
  "Output": "net/ethtool/bitset.c=154=static bool ethnl_bitmap32_test_bit(const u32 *map, unsigned int index)\n--\nnet/ethtool/bitset.c-167- * Estimate length of netlink attribute composed by a later call to\nnet/ethtool/bitset.c:168: * ethnl_put_bitset32() call with the same arguments.\nnet/ethtool/bitset.c-169- *\n--\nnet/ethtool/bitset.c=172=int ethnl_bitset32_size(const u32 *val, const u32 *mask, unsigned int nbits,\n--\nnet/ethtool/bitset.c-217-/**\nnet/ethtool/bitset.c:218: * ethnl_put_bitset32() - Put a bitset nest into a message\nnet/ethtool/bitset.c-219- * @skb:      skb with the message\n--\nnet/ethtool/bitset.c-232- */\nnet/ethtool/bitset.c:233:int ethnl_put_bitset32(struct sk_buff *skb, int attrtype, const u32 *val,\nnet/ethtool/bitset.c-234-\t\t       const u32 *mask, unsigned int nbits,\n--\nnet/ethtool/bitset.c=740=int ethnl_bitset_size(const unsigned long *val, const unsigned long *mask,\n--\nnet/ethtool/bitset.c-774-\nnet/ethtool/bitset.c:775:int ethnl_put_bitset(struct sk_buff *skb, int attrtype,\nnet/ethtool/bitset.c-776-\t\t     const unsigned long *val, const unsigned long *mask,\n--\nnet/ethtool/bitset.c-802-\t\tmask32 = NULL;\nnet/ethtool/bitset.c:803:\tret = ethnl_put_bitset32(skb, attrtype, val32, mask32, nbits, names,\nnet/ethtool/bitset.c-804-\t\t\t\t compact);\n--\nnet/ethtool/bitset.c=849=int ethnl_bitset_size(const unsigned long *val, const unsigned long *mask,\n--\nnet/ethtool/bitset.c-856-\nnet/ethtool/bitset.c:857:int ethnl_put_bitset(struct sk_buff *skb, int attrtype,\nnet/ethtool/bitset.c-858-\t\t     const unsigned long *val, const unsigned long *mask,\n--\nnet/ethtool/bitset.c-861-{\nnet/ethtool/bitset.c:862:\treturn ethnl_put_bitset32(skb, attrtype, (const u32 *)val,\nnet/ethtool/bitset.c-863-\t\t\t\t  (const u32 *)mask, nbits, names, compact);\n--\nnet/ethtool/bitset.h=17=int ethnl_bitset32_size(const u32 *val, const u32 *mask, unsigned int nbits,\nnet/ethtool/bitset.h-18-\t\t\tethnl_string_array_t names, bool compact);\nnet/ethtool/bitset.h:19:int ethnl_put_bitset(struct sk_buff *skb, int attrtype,\nnet/ethtool/bitset.h-20-\t\t     const unsigned long *val, const unsigned long *mask,\n--\nnet/ethtool/bitset.h-22-\t\t     bool compact);\nnet/ethtool/bitset.h:23:int ethnl_put_bitset32(struct sk_buff *skb, int attrtype, const u32 *val,\nnet/ethtool/bitset.h-24-\t\t       const u32 *mask, unsigned int nbits,\n--\nnet/ethtool/debug.c=54=static int debug_fill_reply(struct sk_buff *skb,\n--\nnet/ethtool/debug.c-60-\nnet/ethtool/debug.c:61:\treturn ethnl_put_bitset32(skb, ETHTOOL_A_DEBUG_MSGMASK, \u0026data-\u003emsg_mask,\nnet/ethtool/debug.c-62-\t\t\t\t  NULL, NETIF_MSG_CLASS_COUNT,\n--\nnet/ethtool/eee.c=76=static int eee_fill_reply(struct sk_buff *skb,\n--\nnet/ethtool/eee.c-84-\nnet/ethtool/eee.c:85:\tret = ethnl_put_bitset(skb, ETHTOOL_A_EEE_MODES_OURS,\nnet/ethtool/eee.c-86-\t\t\t       eee-\u003eadvertised, eee-\u003esupported,\n--\nnet/ethtool/eee.c-90-\t\treturn ret;\nnet/ethtool/eee.c:91:\tret = ethnl_put_bitset(skb, ETHTOOL_A_EEE_MODES_PEER,\nnet/ethtool/eee.c-92-\t\t\t       eee-\u003elp_advertised, NULL,\n--\nnet/ethtool/features.c=88=static int features_fill_reply(struct sk_buff *skb,\n--\nnet/ethtool/features.c-95-\nnet/ethtool/features.c:96:\tret = ethnl_put_bitset32(skb, ETHTOOL_A_FEATURES_HW, data-\u003ehw,\nnet/ethtool/features.c-97-\t\t\t\t data-\u003eall, NETDEV_FEATURE_COUNT,\n--\nnet/ethtool/features.c-100-\t\treturn ret;\nnet/ethtool/features.c:101:\tret = ethnl_put_bitset32(skb, ETHTOOL_A_FEATURES_WANTED, data-\u003ewanted,\nnet/ethtool/features.c-102-\t\t\t\t NULL, NETDEV_FEATURE_COUNT,\n--\nnet/ethtool/features.c-105-\t\treturn ret;\nnet/ethtool/features.c:106:\tret = ethnl_put_bitset32(skb, ETHTOOL_A_FEATURES_ACTIVE, data-\u003eactive,\nnet/ethtool/features.c-107-\t\t\t\t NULL, NETDEV_FEATURE_COUNT,\n--\nnet/ethtool/features.c-110-\t\treturn ret;\nnet/ethtool/features.c:111:\treturn ethnl_put_bitset32(skb, ETHTOOL_A_FEATURES_NOCHANGE,\nnet/ethtool/features.c-112-\t\t\t\t  data-\u003enochange, NULL, NETDEV_FEATURE_COUNT,\n--\nnet/ethtool/features.c=158=static int features_send_reply(struct net_device *dev, struct genl_info *info,\n--\nnet/ethtool/features.c-187-\nnet/ethtool/features.c:188:\tret = ethnl_put_bitset(rskb, ETHTOOL_A_FEATURES_WANTED, wanted,\nnet/ethtool/features.c-189-\t\t\t       wanted_mask, NETDEV_FEATURE_COUNT,\n--\nnet/ethtool/features.c-192-\t\tgoto nla_put_failure;\nnet/ethtool/features.c:193:\tret = ethnl_put_bitset(rskb, ETHTOOL_A_FEATURES_ACTIVE, active,\nnet/ethtool/features.c-194-\t\t\t       active_mask, NETDEV_FEATURE_COUNT,\n--\nnet/ethtool/fec.c=265=static int fec_fill_reply(struct sk_buff *skb,\n--\nnet/ethtool/fec.c-272-\nnet/ethtool/fec.c:273:\tret = ethnl_put_bitset(skb, ETHTOOL_A_FEC_MODES,\nnet/ethtool/fec.c-274-\t\t\t       data-\u003efec_link_modes, NULL,\n--\nnet/ethtool/linkmodes.c=100=static int linkmodes_fill_reply(struct sk_buff *skb,\n--\nnet/ethtool/linkmodes.c-112-\nnet/ethtool/linkmodes.c:113:\tret = ethnl_put_bitset(skb, ETHTOOL_A_LINKMODES_OURS,\nnet/ethtool/linkmodes.c-114-\t\t\t       ksettings-\u003elink_modes.advertising,\n--\nnet/ethtool/linkmodes.c-120-\tif (!data-\u003epeer_empty) {\nnet/ethtool/linkmodes.c:121:\t\tret = ethnl_put_bitset(skb, ETHTOOL_A_LINKMODES_PEER,\nnet/ethtool/linkmodes.c-122-\t\t\t\t       ksettings-\u003elink_modes.lp_advertising,\n--\nnet/ethtool/port.c=121=static int port_fill_reply(struct sk_buff *skb,\n--\nnet/ethtool/port.c-132-\tif (!reply-\u003emii) {\nnet/ethtool/port.c:133:\t\tret = ethnl_put_bitset(skb, ETHTOOL_A_PORT_SUPPORTED_MODES,\nnet/ethtool/port.c-134-\t\t\t\t       reply-\u003esupported, NULL,\n--\nnet/ethtool/port.c-139-\t} else {\nnet/ethtool/port.c:140:\t\tret = ethnl_put_bitset(skb, ETHTOOL_A_PORT_SUPPORTED_INTERFACES,\nnet/ethtool/port.c-141-\t\t\t\t       reply-\u003einterfaces, NULL,\n--\nnet/ethtool/privflags.c=100=static int privflags_fill_reply(struct sk_buff *skb,\n--\nnet/ethtool/privflags.c-107-\nnet/ethtool/privflags.c:108:\treturn ethnl_put_bitset32(skb, ETHTOOL_A_PRIVFLAGS_FLAGS,\nnet/ethtool/privflags.c-109-\t\t\t\t  \u0026data-\u003epriv_flags, \u0026all_flags,\n--\nnet/ethtool/tsconfig.c=133=static int tsconfig_fill_reply(struct sk_buff *skb,\n--\nnet/ethtool/tsconfig.c-141-\tif (data-\u003ehwtst_config.flags) {\nnet/ethtool/tsconfig.c:142:\t\tret = ethnl_put_bitset32(skb, ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS,\nnet/ethtool/tsconfig.c-143-\t\t\t\t\t \u0026data-\u003ehwtst_config.flags, NULL,\n--\nnet/ethtool/tsconfig.c-150-\tif (data-\u003ehwtst_config.tx_type) {\nnet/ethtool/tsconfig.c:151:\t\tret = ethnl_put_bitset32(skb, ETHTOOL_A_TSCONFIG_TX_TYPES,\nnet/ethtool/tsconfig.c-152-\t\t\t\t\t \u0026data-\u003ehwtst_config.tx_type, NULL,\n--\nnet/ethtool/tsconfig.c-159-\tif (data-\u003ehwtst_config.rx_filter) {\nnet/ethtool/tsconfig.c:160:\t\tret = ethnl_put_bitset32(skb, ETHTOOL_A_TSCONFIG_RX_FILTERS,\nnet/ethtool/tsconfig.c-161-\t\t\t\t\t \u0026data-\u003ehwtst_config.rx_filter,\n--\nnet/ethtool/tsinfo.c=220=static int tsinfo_fill_reply(struct sk_buff *skb,\n--\nnet/ethtool/tsinfo.c-229-\tif (ts_info-\u003eso_timestamping) {\nnet/ethtool/tsinfo.c:230:\t\tret = ethnl_put_bitset32(skb, ETHTOOL_A_TSINFO_TIMESTAMPING,\nnet/ethtool/tsinfo.c-231-\t\t\t\t\t \u0026ts_info-\u003eso_timestamping, NULL,\n--\nnet/ethtool/tsinfo.c-237-\tif (ts_info-\u003etx_types) {\nnet/ethtool/tsinfo.c:238:\t\tret = ethnl_put_bitset32(skb, ETHTOOL_A_TSINFO_TX_TYPES,\nnet/ethtool/tsinfo.c-239-\t\t\t\t\t \u0026ts_info-\u003etx_types, NULL,\n--\nnet/ethtool/tsinfo.c-245-\tif (ts_info-\u003erx_filters) {\nnet/ethtool/tsinfo.c:246:\t\tret = ethnl_put_bitset32(skb, ETHTOOL_A_TSINFO_RX_FILTERS,\nnet/ethtool/tsinfo.c-247-\t\t\t\t\t \u0026ts_info-\u003erx_filters, NULL,\n--\nnet/ethtool/tunnels.c=82=ethnl_tunnel_info_fill_reply(const struct ethnl_req_info *req_base,\n--\nnet/ethtool/tunnels.c-109-\nnet/ethtool/tunnels.c:110:\t\tif (ethnl_put_bitset32(skb, ETHTOOL_A_TUNNEL_UDP_TABLE_TYPES,\nnet/ethtool/tunnels.c-111-\t\t\t\t       \u0026info-\u003etables[i].tunnel_types, NULL,\n--\nnet/ethtool/tunnels.c-131-\nnet/ethtool/tunnels.c:132:\t\tif (ethnl_put_bitset32(skb, ETHTOOL_A_TUNNEL_UDP_TABLE_TYPES,\nnet/ethtool/tunnels.c-133-\t\t\t\t       \u0026zero, NULL,\n--\nnet/ethtool/wol.c=65=static int wol_fill_reply(struct sk_buff *skb,\n--\nnet/ethtool/wol.c-72-\nnet/ethtool/wol.c:73:\tret = ethnl_put_bitset32(skb, ETHTOOL_A_WOL_MODES, \u0026data-\u003ewol.wolopts,\nnet/ethtool/wol.c-74-\t\t\t\t \u0026data-\u003ewol.supported, WOL_MODE_COUNT,\n"
}

35/3 2026/09/10 19:12 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 37814
							output: 29
							thoughts: 20
						

Thoughts:
Here's my take on those thoughts:

**Peering into the Macro Depths**

Okay, first things first, let's dive into this `DECLARE_PHY_INTERFACE_MASK` thing. I need to refresh my memory on exactly how it's defined. It's probably a macro, so I need to understand its expansion to see what kind of operations it's enabling. I'm guessing it likely involves some bitmasking or enumeration, given the "mask" in its name and its purpose of declaring a PHY interface. I want to quickly ascertain what it is doing.



36/3 2026/09/10 19:12 tool grepper
0m Args:
{
  "Expression": "DECLARE_PHY_INTERFACE_MASK",
  "PathPrefix": "include/"
}

Results:
{
  "Output": "include/linux/phy.h=114=typedef enum {\n--\ninclude/linux/phy.h-158-/* PHY interface mode bitmap handling */\ninclude/linux/phy.h:159:#define DECLARE_PHY_INTERFACE_MASK(name) \\\ninclude/linux/phy.h-160-\tDECLARE_BITMAP(name, PHY_INTERFACE_MODE_MAX)\n--\ninclude/linux/phy.h=690=struct phy_device {\n--\ninclude/linux/phy.h-739-\tphy_interface_t interface;\ninclude/linux/phy.h:740:\tDECLARE_PHY_INTERFACE_MASK(possible_interfaces);\ninclude/linux/phy.h-741-\n--\ninclude/linux/phy.h-770-\t/* Host supported PHY interface types. Should be ignored if empty. */\ninclude/linux/phy.h:771:\tDECLARE_PHY_INTERFACE_MASK(host_interfaces);\ninclude/linux/phy.h-772-\n--\ninclude/linux/phy_port.h=57=struct phy_port {\n--\ninclude/linux/phy_port.h-70-\t__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);\ninclude/linux/phy_port.h:71:\tDECLARE_PHY_INTERFACE_MASK(interfaces);\ninclude/linux/phy_port.h-72-\n--\ninclude/linux/phylink.h=164=struct phylink_config {\n--\ninclude/linux/phylink.h-173-\t\t\t\tstruct phylink_link_state *state);\ninclude/linux/phylink.h:174:\tDECLARE_PHY_INTERFACE_MASK(supported_interfaces);\ninclude/linux/phylink.h:175:\tDECLARE_PHY_INTERFACE_MASK(lpi_interfaces);\ninclude/linux/phylink.h-176-\tunsigned long mac_capabilities;\n--\ninclude/linux/phylink.h=494=struct phylink_pcs {\ninclude/linux/phylink.h:495:\tDECLARE_PHY_INTERFACE_MASK(supported_interfaces);\ninclude/linux/phylink.h-496-\tconst struct phylink_pcs_ops *ops;\n--\ninclude/linux/sfp.h=529=struct sfp_module_caps {\ninclude/linux/sfp.h:530:\tDECLARE_PHY_INTERFACE_MASK(interfaces);\ninclude/linux/sfp.h-531-\t__ETHTOOL_DECLARE_LINK_MODE_MASK(link_modes);\n"
}

37/3 2026/09/10 19:12 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 38615
							output: 19
							thoughts: 302
						

Thoughts:
**Analyzing the `port_prepare_data` Function**

Okay, let's dive into this `port_prepare_data` function. I see it's part of the Ethernet netlink interface, specifically handling some data preparation for port information requests. First, I need to remind myself, the caller *should* be holding RTNL (the Read-Transaction Netlink lock) because we're going to grab a reference to `phy_port` structure. This is critical for preventing race conditions.

I immediately spot the critical safety check: `phy_link_topo_get_port`. It attempts to retrieve a `phy_port` structure, using the device information and the requested `port_id`. If that fails and returns NULL, we immediately return `-ENODEV`, indicating the requested port doesn't exist – that's good practice.

Assuming the `phy_port` retrieval succeeds, the code moves on to copying data from the `phy_port` structure into our `reply` structure. I recognize calls to functions like `linkmode_copy` and `phy_interface_copy`, which are, of course, used to transfer the supported link modes and interface information. It's a standard pattern I see all the time, for ensuring the replies conform to our data structures. 

Specifically, I'm noting the `port_id` (makes sense), `mii`, `sfp`, and `upstream_port` data transfers. Grabbing the `upstream_port`'s ID, if it exists, is crucial for topology information. This looks like a solid and standard function. Now let's just make sure `phy_interface_copy` works as expected.



38/3 2026/09/10 19:12 tool grepper
0m Args:
{
  "Expression": "phy_interface_copy"
}

Results:
{
  "Output": "drivers/net/phy/phylink.c=3973=static int phylink_sfp_module_insert(void *upstream,\n--\ndrivers/net/phy/phylink.c-3981-\tcaps = sfp_get_module_caps(pl-\u003esfp_bus);\ndrivers/net/phy/phylink.c:3982:\tphy_interface_copy(pl-\u003esfp_interfaces, caps-\u003einterfaces);\ndrivers/net/phy/phylink.c-3983-\tlinkmode_copy(pl-\u003esfp_support, caps-\u003elink_modes);\n--\ninclude/linux/phy.h=167=static inline bool phy_interface_empty(const unsigned long *intf)\n--\ninclude/linux/phy.h-171-\ninclude/linux/phy.h:172:static inline void phy_interface_copy(unsigned long *d, const unsigned long *s)\ninclude/linux/phy.h-173-{\n--\nnet/ethtool/port.c=55=static int port_prepare_data(const struct ethnl_req_info *req_info,\n--\nnet/ethtool/port.c-70-\tlinkmode_copy(reply-\u003esupported, port-\u003esupported);\nnet/ethtool/port.c:71:\tphy_interface_copy(reply-\u003einterfaces, port-\u003einterfaces);\nnet/ethtool/port.c-72-\treply-\u003eport_id = port-\u003eid;\n"
}

39/3 2026/09/10 19:12 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 39657
							output: 406
							thoughts: 2104
						

Thoughts:
**KMSAN Assessment: No Uninitialized Memory Risks Detected**

Alright, let's break this down. My primary concern is ensuring this patch doesn't introduce any new vulnerabilities related to uninitialized memory reads or information leaks. We're dealing with the network subsystem, so that's particularly crucial.

First, I examined the core functions: `phy_link_topo_add_port`, which looks to be correctly handling port ID allocation using either reusing an existing ID or allocating a new one from an XArray, and `netdev_alloc_phy_link_topology`, which properly initializes the `phy_link_topology` structure with zeroed XArrays. Good start.

I then did a deep dive into the code, meticulously checking for any potential issues related to uninitialized variables or struct padding that could be copied to userspace. In the ethtool netlink interactions, I observed the standard `nla_put_*` calls and `ethnl_put_bitset` usage, which means we're dealing with well-defined netlink attributes, no raw struct dumps or uninitialized data being passed. Allocation of the request and reply data is done using `kzalloc_obj`, `kzalloc`, or `kmalloc`, explicitly zeroing them before data population using `memset` or `ethnl_init_reply_data()`. `ctx` data is correctly initialized by the netlink dump infrastructure. Furthermore, `phy_port` allocations are also handled correctly, zeroing out the structure at allocation. The `phy_caps_linkmode_filter_ifaces` function initializes its relevant structures, and `ethnl_phy_names_populate()` copies into `phy_interface_names` via `strscpy`, so no problems there. In essence, nothing is being sent to user space that is uninitialized.

Next, I looked for potential issues that KASAN or KMSAN would normally catch, such as memory allocation issues, netlink formatting issues, list or xarray issues. My examination reveals the patch leverages `kzalloc_obj`, `kzalloc`, `kmalloc_obj` with explicit `memset` calls. The Netlink message construction uses standard functions with known behavior. List and XArray operations are performed correctly. If there were concurrency or life-cycle issues, these would likely manifest as UAF, NULL pointer dereferences, locking deadlocks, or out-of-bounds errors, all of which are already detected by KASAN and general kernel checks.

I then carefully reviewed the KMSAN vs. KASAN criteria. The rule is very clear: KMSAN is only needed if this change introduces risks that are *only* detected by KMSAN.  Standard KASAN is already enabled, as are LOCKDEP, and memory corruption checks. We're trying to identify *uninitialized memory reads* or *kernel-to-user memory leaks*, and that's the focus.

I went through every modified and added file line by line: documentation, the `MAINTAINERS` file, and the new and modified code.  I checked all allocations, variable initializations, and data copying operations. `phy_caps.c`, `phy_device.c`, `phy_link_topology.c`, `phylink.c`, the new headers, `net/core/dev.c` and ethtool code. Nothing is leaking uninitialized memory.

**Conclusion: After this meticulous review, I am confident that this patch does not introduce any risks of uninitialized memory usage or information leaks.**  Therefore, NeedsKMSAN = false. The patch's primary risks lie in areas covered by KASAN and standard kernel checks.



40/3 2026/09/10 19:12 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch series implements the ETHTOOL_MSG_PORT_GET netlink interface (do and dump operations) and associated PHY port topology handling in phylib and phylink.\n\nAnalysis of memory handling:\n1. Heap \u0026 Stack allocations:\n   - Port structures (`struct phy_port`) are allocated using `phy_port_alloc()` which zeros memory via `kzalloc_obj(*port)` and explicit `linkmode_zero()`.\n   - In ethtool netlink request/reply handling (`net/ethtool/port.c`), request structures are zero-allocated with `kzalloc_obj()` / `kzalloc()`, and reply buffers are explicitly cleared using `memset()` or `ethnl_init_reply_data()` before population.\n   - Stack variables in helper functions (e.g. `phy_caps_linkmode_filter_ifaces`) are zero-initialized (`= {}` and `= 0`).\n2. Userspace communication:\n   - Communication with user space is done exclusively using Netlink TLVs via standard Netlink attribute serialization functions (`nla_put_u32()`, `ethnl_put_bitset()`, `ethnl_fill_reply_header()`). No raw kernel structs with potential uninitialized padding or uninitialized fields are copied to userspace.\n3. Potential bugs:\n   - Any bugs introduced by this patch series (e.g., locking concurrency with RTNL/netdev locks, list/xarray management, reference counting of SFP bus/ports, or NULL dereferences) fall within the scope of KASAN, LOCKDEP, and standard kernel debugging facilities.\n   - There are no uninitialized memory reads or information leak risks that would require dedicated KMSAN fuzzing.\n\nTherefore, NeedsKMSAN is false.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch series implements the ETHTOOL_MSG_PORT_GET netlink interface (do and dump operations) and associated PHY port topology handling in phylib and phylink.\n\nAnalysis of memory handling:\n1. Heap \u0026 Stack allocations:\n   - Port structures (`struct phy_port`) are allocated using `phy_port_alloc()` which zeros memory via `kzalloc_obj(*port)` and explicit `linkmode_zero()`.\n   - In ethtool netlink request/reply handling (`net/ethtool/port.c`), request structures are zero-allocated with `kzalloc_obj()` / `kzalloc()`, and reply buffers are explicitly cleared using `memset()` or `ethnl_init_reply_data()` before population.\n   - Stack variables in helper functions (e.g. `phy_caps_linkmode_filter_ifaces`) are zero-initialized (`= {}` and `= 0`).\n2. Userspace communication:\n   - Communication with user space is done exclusively using Netlink TLVs via standard Netlink attribute serialization functions (`nla_put_u32()`, `ethnl_put_bitset()`, `ethnl_fill_reply_header()`). No raw kernel structs with potential uninitialized padding or uninitialized fields are copied to userspace.\n3. Potential bugs:\n   - Any bugs introduced by this patch series (e.g., locking concurrency with RTNL/netdev locks, list/xarray management, reference counting of SFP bus/ports, or NULL dereferences) fall within the scope of KASAN, LOCKDEP, and standard kernel debugging facilities.\n   - There are no uninitialized memory reads or information leak risks that would require dedicated KMSAN fuzzing.\n\nTherefore, NeedsKMSAN is false.",
  "NeedsKMSAN": false
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)