Skip to contentSkip to conversation

net: enetc: use generic interfaces to get phc_index for ENETC v1

PATCH In review Wei Fang 4 participants 7 messages Sep 18, 2025 – Sep 22, 2025

Subsystems (5)
lore
Share & tools
lore

Wei Fang

author maintainer
#0 lore raw

PATCH 1/1 net: enetc: use generic interfaces to get phc_index for ENETC v1

The commit 61f132ca8c46 ("ptp: add helpers to get the phc_index by of_node or dev") has added two generic interfaces to get the phc_index of the PTP clock. This eliminates the need for PTP device drivers to provide custom APIs for consumers to retrieve the phc_index. This has already been implemented for ENETC v4 and is also applicable to ENETC v1. Therefore, the global variable enetc_phc_index is removed from the driver. ENETC v1 now uses the same interface as v4 to get phc_index.

---
 drivers/net/ethernet/freescale/enetc/enetc.h  |  3 ---
 .../ethernet/freescale/enetc/enetc_ethtool.c  | 25 ++++++++-----------
 .../net/ethernet/freescale/enetc/enetc_ptp.c  |  5 ----
 3 files changed, 10 insertions(+), 23 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc.h +0 -3
index 815afdc2ec23..0ec010a7d640 100644
@@ -493,9 +493,6 @@ struct enetc_msg_cmd_set_primary_mac {
 
 #define ENETC_CBDR_TIMEOUT	1000 /* usecs */
 
-/* PTP driver exports */
-extern int enetc_phc_index;
-
 /* SI common */
 u32 enetc_port_mac_rd(struct enetc_si *si, u32 reg);
 void enetc_port_mac_wr(struct enetc_si *si, u32 reg, u32 val);
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +10 -15
index 6215e9c68fc5..5f17ff150fd5 100644
@@ -880,7 +880,7 @@ static int enetc_set_coalesce(struct net_device *ndev,
 	return 0;
 }
 
-static int enetc4_get_phc_index_by_pdev(struct enetc_si *si)
+static int enetc_get_phc_index_by_pdev(struct enetc_si *si)
 {
 	struct pci_bus *bus = si->pdev->bus;
 	struct pci_dev *timer_pdev;
@@ -888,6 +888,9 @@ static int enetc4_get_phc_index_by_pdev(struct enetc_si *si)
 	int phc_index;
 
 	switch (si->revision) {
+	case ENETC_REV_1_0:
+		devfn = PCI_DEVFN(0, 4);
+		break;
 	case ENETC_REV_4_1:
 		devfn = PCI_DEVFN(24, 0);
 		break;
@@ -905,18 +908,18 @@ static int enetc4_get_phc_index_by_pdev(struct enetc_si *si)
 	return phc_index;
 }
 
-static int enetc4_get_phc_index(struct enetc_si *si)
+static int enetc_get_phc_index(struct enetc_si *si)
 {
 	struct device_node *np = si->pdev->dev.of_node;
 	struct device_node *timer_np;
 	int phc_index;
 
 	if (!np)
-		return enetc4_get_phc_index_by_pdev(si);
+		return enetc_get_phc_index_by_pdev(si);
 
 	timer_np = of_parse_phandle(np, "ptp-timer", 0);
 	if (!timer_np)
-		return enetc4_get_phc_index_by_pdev(si);
+		return enetc_get_phc_index_by_pdev(si);
 
 	phc_index = ptp_clock_index_by_of_node(timer_np);
 	of_node_put(timer_np);
@@ -954,17 +957,9 @@ static int enetc_get_ts_info(struct net_device *ndev,
 	if (!enetc_ptp_clock_is_enabled(si))
 		goto timestamp_tx_sw;
 
-	if (is_enetc_rev1(si)) {
-		phc_idx = symbol_get(enetc_phc_index);
-		if (phc_idx) {
-			info->phc_index = *phc_idx;
-			symbol_put(enetc_phc_index);
-		}
-	} else {
-		info->phc_index = enetc4_get_phc_index(si);
-		if (info->phc_index < 0)
-			goto timestamp_tx_sw;
-	}
+	info->phc_index = enetc_get_phc_index(si);
+	if (info->phc_index < 0)
+		goto timestamp_tx_sw;
 
 	enetc_get_ts_generic_info(ndev, info);
 
drivers/net/ethernet/freescale/enetc/enetc_ptp.c +0 -5
index 5243fc031058..b8413d3b4f16 100644
@@ -7,9 +7,6 @@
 
 #include "enetc.h"
 
-int enetc_phc_index = -1;
-EXPORT_SYMBOL_GPL(enetc_phc_index);
-
 static struct ptp_clock_info enetc_ptp_caps = {
 	.owner		= THIS_MODULE,
 	.name		= "ENETC PTP clock",
@@ -92,7 +89,6 @@ static int enetc_ptp_probe(struct pci_dev *pdev,
 	if (err)
 		goto err_no_clock;
 
-	enetc_phc_index = ptp_qoriq->phc_index;
 	pci_set_drvdata(pdev, ptp_qoriq);
 
 	return 0;
@@ -118,7 +114,6 @@ static void enetc_ptp_remove(struct pci_dev *pdev)
 {
 	struct ptp_qoriq *ptp_qoriq = pci_get_drvdata(pdev);
 
-	enetc_phc_index = -1;
 	ptp_qoriq_free(ptp_qoriq);
 	pci_free_irq_vectors(pdev);
 	kfree(ptp_qoriq);
Signature · 1 line
2.34.1
maintainer
#1 lore raw

drivers/net/ethernet/freescale/enetc/enetc_ethtool.c static int enetc_get_ts_info(struct net_device *ndev, · line 960

Quoted 8 lines · Wei Fang
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +0 -4
@@ -954,17 +957,9 @@ static int enetc_get_ts_info(struct net_device *ndev,
 	if (!enetc_ptp_clock_is_enabled(si))
 		goto timestamp_tx_sw;
 
-	if (is_enetc_rev1(si)) {
-		phc_idx = symbol_get(enetc_phc_index);
-		if (phc_idx) {
-			info->phc_index = *phc_idx;

phc_idx remains unused in enetc_get_ts_info() after this change, and it produces a build warning.

drivers/net/ethernet/freescale/enetc/enetc_ethtool.c static int enetc_get_ts_info(struct net_device *ndev, · line 965

Quoted 13 lines
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +3 -7
-			symbol_put(enetc_phc_index);
-		}
-	} else {
-		info->phc_index = enetc4_get_phc_index(si);
-		if (info->phc_index < 0)
-			goto timestamp_tx_sw;
-	}
+	info->phc_index = enetc_get_phc_index(si);
+	if (info->phc_index < 0)
+		goto timestamp_tx_sw;
 
 	enetc_get_ts_generic_info(ndev, info);
 

Also, testing reveals:

root@fii:~# ethtool -T eno2
[   43.374227] BUG: sleeping function called from invalid context at kernel/locking/rwsem.c:1536
[   43.383268] in_atomic(): 0, irqs_disabled(): 0, non_block: 0, pid: 460, name: ethtool
[   43.392076] preempt_count: 0, expected: 0
[   43.396454] RCU nest depth: 1, expected: 0
[   43.400908] 3 locks held by ethtool/460:
[   43.405206]  #0: ffffcb976c5fb608 (cb_lock){++++}-{4:4}, at: genl_rcv+0x30/0x60
[   43.412886]  #1: ffffcb976c5e9f88 (rtnl_mutex){+.+.}-{4:4}, at: rtnl_lock+0x28/0x40
[   43.420931]  #2: ffffcb976c0b32d0 (rcu_read_lock){....}-{1:3}, at: rcu_lock_acquire+0x4/0x48
[   43.429785] CPU: 1 UID: 0 PID: 460 Comm: ethtool Not tainted 6.17.0-rc5+ #2920 PREEMPT
[   43.429796] Call trace:
[   43.429799]  show_stack+0x24/0x38 (C)
[   43.429814]  dump_stack_lvl+0x40/0xa0
[   43.429822]  dump_stack+0x18/0x24
[   43.429828]  __might_resched+0x200/0x218
[   43.429837]  __might_sleep+0x54/0x90
[   43.429844]  down_read+0x3c/0x1f0
[   43.429852]  pci_get_slot+0x30/0x88
[   43.429860]  enetc_get_ts_info+0x108/0x1a0
[   43.429867]  __ethtool_get_ts_info+0x140/0x218
[   43.429875]  tsinfo_prepare_data+0x9c/0xc8
[   43.429881]  ethnl_default_doit+0x1cc/0x410
[   43.429888]  genl_rcv_msg+0x2d8/0x358
[   43.429896]  netlink_rcv_skb+0x124/0x148
[   43.429903]  genl_rcv+0x40/0x60
[   43.429910]  netlink_unicast+0x198/0x358
[   43.429916]  netlink_sendmsg+0x22c/0x348
[   43.429923]  __sys_sendto+0x138/0x1d8
[   43.429928]  __arm64_sys_sendto+0x34/0x50
[   43.429933]  invoke_syscall+0x4c/0x110
[   43.429940]  el0_svc_common+0xb8/0xf0
[   43.429946]  do_el0_svc+0x28/0x40
[   43.429953]  el0_svc+0x4c/0xe0
[   43.429960]  el0t_64_sync_handler+0x78/0x130
[   43.429967]  el0t_64_sync+0x198/0x1a0
[   43.429974]
[   43.537263] =============================
[   43.541282] [ BUG: Invalid wait context ]
[   43.545301] 6.17.0-rc5+ #2920 Tainted: G        W
[   43.550891] -----------------------------
[   43.554909] ethtool/460 is trying to lock:
[   43.559016] ffffcb976c26ab80 (pci_bus_sem){++++}-{4:4}, at: pci_get_slot+0x30/0x88
[   43.566628] other info that might help us debug this:
[   43.571694] context-{5:5}
[   43.574317] 3 locks held by ethtool/460:
[   43.578251]  #0: ffffcb976c5fb608 (cb_lock){++++}-{4:4}, at: genl_rcv+0x30/0x60
[   43.585603]  #1: ffffcb976c5e9f88 (rtnl_mutex){+.+.}-{4:4}, at: rtnl_lock+0x28/0x40
[   43.593301]  #2: ffffcb976c0b32d0 (rcu_read_lock){....}-{1:3}, at: rcu_lock_acquire+0x4/0x48
[   43.601786] stack backtrace:
[   43.604672] CPU: 1 UID: 0 PID: 460 Comm: ethtool Tainted: G        W           6.17.0-rc5+ #2920 PREEMPT
[   43.604679] Tainted: [W]=WARN
[   43.604683] Call trace:
[   43.604685]  show_stack+0x24/0x38 (C)
[   43.604692]  dump_stack_lvl+0x40/0xa0
[   43.604699]  dump_stack+0x18/0x24
[   43.604706]  __lock_acquire+0xab4/0x31f8
[   43.604713]  lock_acquire+0x11c/0x278
[   43.604720]  down_read+0x6c/0x1f0
[   43.604726]  pci_get_slot+0x30/0x88
[   43.604732]  enetc_get_ts_info+0x108/0x1a0
[   43.604738]  __ethtool_get_ts_info+0x140/0x218
[   43.604745]  tsinfo_prepare_data+0x9c/0xc8
[   43.604750]  ethnl_default_doit+0x1cc/0x410
[   43.604757]  genl_rcv_msg+0x2d8/0x358
[   43.604765]  netlink_rcv_skb+0x124/0x148
[   43.604771]  genl_rcv+0x40/0x60
[   43.604778]  netlink_unicast+0x198/0x358
[   43.604784]  netlink_sendmsg+0x22c/0x348
[   43.604790]  __sys_sendto+0x138/0x1d8
[   43.604795]  __arm64_sys_sendto+0x34/0x50
[   43.604799]  invoke_syscall+0x4c/0x110
[   43.604806]  el0_svc_common+0xb8/0xf0
[   43.604812]  do_el0_svc+0x28/0x40
[   43.604818]  el0_svc+0x4c/0xe0
[   43.604825]  el0t_64_sync_handler+0x78/0x130
[   43.604832]  el0t_64_sync+0x198/0x1a0
Time stamping parameters for eno2:
Capabilities:
        hardware-transmit
        software-transmit
        hardware-receive
        software-receive
        software-system-clock
        hardware-raw-clock
PTP Hardware Clock: 0
Hardware Transmit Timestamp Modes:
        off
        on
        onestep-sync
Hardware Receive Filter Modes:
        none
        all

It looks like we have a problem and can't call pci_get_slot(), which sleeps on down_read(&pci_bus_sem), from ethtool_ops :: get_ts_info(), which can't sleep, as of commit 4c61d809cf60 ("net: ethtool: Fix suspicious rcu_dereference usage").

Köry, do you have any comments or suggestions? Patch is here:
https://lore.kernel.org/netdev/[email protected]/

pw-bot: cr

author maintainer
#2 lore raw
Quoted 6 lines · Wei Fang

Review static int enetc_get_ts_info(struct net_device

Quoted 1 line
(quoted diff) +0 -0
@@ -954,17 +957,9 @@ static int enetc_get_ts_info(struct net_device

*ndev,

Quoted 3 lines
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +0 -0
 	if (!enetc_ptp_clock_is_enabled(si))
 		goto timestamp_tx_sw;
 
Quoted 7 lines

drivers/net/ethernet/freescale/enetc/enetc_ethtool.c static int enetc_get_ts_info(struct net_device *ndev, · line 960

Quoted 4 lines
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +0 -4
-	if (is_enetc_rev1(si)) {
-		phc_idx = symbol_get(enetc_phc_index);
-		if (phc_idx) {
-			info->phc_index = *phc_idx;

phc_idx remains unused in enetc_get_ts_info() after this change, and it produces a build warning.

Oh, I missed the build warning, sorry.

Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +3 -7
-			symbol_put(enetc_phc_index);
-		}
-	} else {
-		info->phc_index = enetc4_get_phc_index(si);
-		if (info->phc_index < 0)
-			goto timestamp_tx_sw;
-	}
+	info->phc_index = enetc_get_phc_index(si);
+	if (info->phc_index < 0)
+		goto timestamp_tx_sw;
 
Quoted 8 lines

drivers/net/ethernet/freescale/enetc/enetc_ethtool.c static int enetc_get_ts_info(struct net_device *ndev, · line 965

Quoted 2 lines
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +0 -0
 	enetc_get_ts_generic_info(ndev, info);
 

It looks like we have a problem and can't call pci_get_slot(), which sleeps on down_read(&pci_bus_sem), from ethtool_ops :: get_ts_info(), which can't sleep, as of commit 4c61d809cf60 ("net: ethtool: Fix suspicious rcu_dereference usage").

Thanks for catching this issue. CONFIG_DEBUG_ATOMIC_SLEEP was not enabled in my config file, so I did not see this issue on both i.MX95 and LS1028A. :(

The introduction of rcu_read_lock() in __ethtool_get_ts_info() makes the device drivers cannot use any functions which might sleep, I do not have an idea to fix this issue in the upper layer. Currently, I can use pci_get_domain_bus_and_slot() to instead of pci_get_slot() to fix this issue in the enetc driver.

Quoted 1 line

pw-bot: cr

#3 lore raw
In reply to Vladimir Oltean
Quoted 122 lines · On Thu, 18 Sep 2025 15:48:23 +0300 Vladimir Oltean <[email protected]>…

drivers/net/ethernet/freescale/enetc/enetc_ethtool.c static int enetc_get_ts_info(struct net_device *ndev, · line 960

Quoted 8 lines · Wei Fang
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +0 -4
@@ -954,17 +957,9 @@ static int enetc_get_ts_info(struct net_device *ndev,
 	if (!enetc_ptp_clock_is_enabled(si))
 		goto timestamp_tx_sw;
 
-	if (is_enetc_rev1(si)) {
-		phc_idx = symbol_get(enetc_phc_index);
-		if (phc_idx) {
-			info->phc_index = *phc_idx;  

phc_idx remains unused in enetc_get_ts_info() after this change, and it produces a build warning.

drivers/net/ethernet/freescale/enetc/enetc_ethtool.c static int enetc_get_ts_info(struct net_device *ndev, · line 965

Quoted 13 lines
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +3 -7
-			symbol_put(enetc_phc_index);
-		}
-	} else {
-		info->phc_index = enetc4_get_phc_index(si);
-		if (info->phc_index < 0)
-			goto timestamp_tx_sw;
-	}
+	info->phc_index = enetc_get_phc_index(si);
+	if (info->phc_index < 0)
+		goto timestamp_tx_sw;
 
 	enetc_get_ts_generic_info(ndev, info);
 

Also, testing reveals:

root@fii:~# ethtool -T eno2
[   43.374227] BUG: sleeping function called from invalid context at
kernel/locking/rwsem.c:1536 [   43.383268] in_atomic(): 0, irqs_disabled():
0, non_block: 0, pid: 460, name: ethtool [   43.392076] preempt_count: 0,
expected: 0 [   43.396454] RCU nest depth: 1, expected: 0
[   43.400908] 3 locks held by ethtool/460:
[   43.405206]  #0: ffffcb976c5fb608 (cb_lock){++++}-{4:4}, at:
genl_rcv+0x30/0x60 [   43.412886]  #1: ffffcb976c5e9f88
(rtnl_mutex){+.+.}-{4:4}, at: rtnl_lock+0x28/0x40 [   43.420931]  #2:
ffffcb976c0b32d0 (rcu_read_lock){....}-{1:3}, at: rcu_lock_acquire+0x4/0x48 [
  43.429785] CPU: 1 UID: 0 PID: 460 Comm: ethtool Not tainted 6.17.0-rc5+
#2920 PREEMPT [   43.429796] Call trace: [   43.429799]  show_stack+0x24/0x38
(C) [   43.429814]  dump_stack_lvl+0x40/0xa0
[   43.429822]  dump_stack+0x18/0x24
[   43.429828]  __might_resched+0x200/0x218
[   43.429837]  __might_sleep+0x54/0x90
[   43.429844]  down_read+0x3c/0x1f0
[   43.429852]  pci_get_slot+0x30/0x88
[   43.429860]  enetc_get_ts_info+0x108/0x1a0
[   43.429867]  __ethtool_get_ts_info+0x140/0x218
[   43.429875]  tsinfo_prepare_data+0x9c/0xc8
[   43.429881]  ethnl_default_doit+0x1cc/0x410
[   43.429888]  genl_rcv_msg+0x2d8/0x358
[   43.429896]  netlink_rcv_skb+0x124/0x148
[   43.429903]  genl_rcv+0x40/0x60
[   43.429910]  netlink_unicast+0x198/0x358
[   43.429916]  netlink_sendmsg+0x22c/0x348
[   43.429923]  __sys_sendto+0x138/0x1d8
[   43.429928]  __arm64_sys_sendto+0x34/0x50
[   43.429933]  invoke_syscall+0x4c/0x110
[   43.429940]  el0_svc_common+0xb8/0xf0
[   43.429946]  do_el0_svc+0x28/0x40
[   43.429953]  el0_svc+0x4c/0xe0
[   43.429960]  el0t_64_sync_handler+0x78/0x130
[   43.429967]  el0t_64_sync+0x198/0x1a0
[   43.429974]
[   43.537263] =============================
[   43.541282] [ BUG: Invalid wait context ]
[   43.545301] 6.17.0-rc5+ #2920 Tainted: G        W
[   43.550891] -----------------------------
[   43.554909] ethtool/460 is trying to lock:
[   43.559016] ffffcb976c26ab80 (pci_bus_sem){++++}-{4:4}, at:
pci_get_slot+0x30/0x88 [   43.566628] other info that might help us debug
this: [   43.571694] context-{5:5}
[   43.574317] 3 locks held by ethtool/460:
[   43.578251]  #0: ffffcb976c5fb608 (cb_lock){++++}-{4:4}, at:
genl_rcv+0x30/0x60 [   43.585603]  #1: ffffcb976c5e9f88
(rtnl_mutex){+.+.}-{4:4}, at: rtnl_lock+0x28/0x40 [   43.593301]  #2:
ffffcb976c0b32d0 (rcu_read_lock){....}-{1:3}, at: rcu_lock_acquire+0x4/0x48 [
  43.601786] stack backtrace: [   43.604672] CPU: 1 UID: 0 PID: 460 Comm:
ethtool Tainted: G        W           6.17.0-rc5+ #2920 PREEMPT [
43.604679] Tainted: [W]=WARN [   43.604683] Call trace:
[   43.604685]  show_stack+0x24/0x38 (C)
[   43.604692]  dump_stack_lvl+0x40/0xa0
[   43.604699]  dump_stack+0x18/0x24
[   43.604706]  __lock_acquire+0xab4/0x31f8
[   43.604713]  lock_acquire+0x11c/0x278
[   43.604720]  down_read+0x6c/0x1f0
[   43.604726]  pci_get_slot+0x30/0x88
[   43.604732]  enetc_get_ts_info+0x108/0x1a0
[   43.604738]  __ethtool_get_ts_info+0x140/0x218
[   43.604745]  tsinfo_prepare_data+0x9c/0xc8
[   43.604750]  ethnl_default_doit+0x1cc/0x410
[   43.604757]  genl_rcv_msg+0x2d8/0x358
[   43.604765]  netlink_rcv_skb+0x124/0x148
[   43.604771]  genl_rcv+0x40/0x60
[   43.604778]  netlink_unicast+0x198/0x358
[   43.604784]  netlink_sendmsg+0x22c/0x348
[   43.604790]  __sys_sendto+0x138/0x1d8
[   43.604795]  __arm64_sys_sendto+0x34/0x50
[   43.604799]  invoke_syscall+0x4c/0x110
[   43.604806]  el0_svc_common+0xb8/0xf0
[   43.604812]  do_el0_svc+0x28/0x40
[   43.604818]  el0_svc+0x4c/0xe0
[   43.604825]  el0t_64_sync_handler+0x78/0x130
[   43.604832]  el0t_64_sync+0x198/0x1a0
Time stamping parameters for eno2:
Capabilities:
        hardware-transmit
        software-transmit
        hardware-receive
        software-receive
        software-system-clock
        hardware-raw-clock
PTP Hardware Clock: 0
Hardware Transmit Timestamp Modes:
        off
        on
        onestep-sync
Hardware Receive Filter Modes:
        none
        all
Quoted 7 lines

It looks like we have a problem and can't call pci_get_slot(), which sleeps on down_read(&pci_bus_sem), from ethtool_ops :: get_ts_info(), which can't sleep, as of commit 4c61d809cf60 ("net: ethtool: Fix suspicious rcu_dereference usage").

Köry, do you have any comments or suggestions? Patch is here:
https://lore.kernel.org/netdev/[email protected]/

This is annoying indeed. I don't know how this enetc drivers works but why ts_info needs this pci_get_slot() call? It seems this call seems to not be used in ndo_hwtstamp_get/set while ts_info which does not need any hardware communication report only a list of capabilities.

Regards,

Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
author maintainer
#4 lore raw
Quoted 16 lines
Quoted 7 lines

It looks like we have a problem and can't call pci_get_slot(), which sleeps on down_read(&pci_bus_sem), from ethtool_ops :: get_ts_info(), which can't sleep, as of commit 4c61d809cf60 ("net: ethtool: Fix suspicious rcu_dereference usage").

Köry, do you have any comments or suggestions? Patch is here:

https://lore.kern/
el.org%2Fnetdev%2F20250918074454.1742328-1-wei.fang%40nxp.com%2F&d ata=05%7C02%7Cwei.fang%40nxp.com%7Cca70608eb6c9487d98e108ddf7571 de6%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C63893867571474 2481%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjA uMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7 C%7C&sdata=h6rMPPxArsYdoPOz95UZRU88Oz9IJ3sD6lRjqC5SHMU%3D&reser ved=0

Quoted 5 lines

This is annoying indeed. I don't know how this enetc drivers works but why ts_info needs this pci_get_slot() call? It seems this call seems to not be used in ndo_hwtstamp_get/set while ts_info which does not need any hardware communication report only a list of capabilities.

The ENETC (MAC controller) and the PTP timer are separate devices, they are both PCIe devices, the PTP timer provides the PHC for ENETC to use, so enetc_get_ts_info() needs to get the phc_index of the PTP timer, so pci_get_slot() is called to get the pci_dev pointer of the PTP timer. I can use pci_get_domain_bus_and_slot() to instead to fix this issue.

I do not know whether it is a good idea to place the get_ts_info() callback within an atomic lock context. I also noticed that idpf driver also has the same potential issue (idpf_get_ts_info()).

#5 lore raw
Quoted 28 lines · On Fri, 19 Sep 2025 08:48:57 +0000 Wei Fang <[email protected]> wrote:
Quoted 16 lines
Quoted 7 lines

It looks like we have a problem and can't call pci_get_slot(), which sleeps on down_read(&pci_bus_sem), from ethtool_ops :: get_ts_info(), which can't sleep, as of commit 4c61d809cf60 ("net: ethtool: Fix suspicious rcu_dereference usage").

Köry, do you have any comments or suggestions? Patch is here:

https://lore.kern/
el.org%2Fnetdev%2F20250918074454.1742328-1-wei.fang%40nxp.com%2F&d ata=05%7C02%7Cwei.fang%40nxp.com%7Cca70608eb6c9487d98e108ddf7571 de6%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C63893867571474 2481%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjA uMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7 C%7C&sdata=h6rMPPxArsYdoPOz95UZRU88Oz9IJ3sD6lRjqC5SHMU%3D&reser ved=0

Quoted 5 lines

This is annoying indeed. I don't know how this enetc drivers works but why ts_info needs this pci_get_slot() call? It seems this call seems to not be used in ndo_hwtstamp_get/set while ts_info which does not need any hardware communication report only a list of capabilities.

The ENETC (MAC controller) and the PTP timer are separate devices, they are both PCIe devices, the PTP timer provides the PHC for ENETC to use, so enetc_get_ts_info() needs to get the phc_index of the PTP timer, so pci_get_slot() is called to get the pci_dev pointer of the PTP timer. I can use pci_get_domain_bus_and_slot() to instead to fix this issue.

Quoted 3 lines

I do not know whether it is a good idea to place the get_ts_info() callback within an atomic lock context. I also noticed that idpf driver also has the same potential issue (idpf_get_ts_info()).

We can change the device providing the PTP (currently between MAC or PHY), that's why we need to acquire the rcu lock to avoid any pointer change during the get_ts_info callback which could cause an use after free issue.

Regards,

Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
#6 lore raw
In reply to Wei Fang
kernel test robot noticed the following build warnings:

Hi Wei,

kernel test robot noticed the following build warnings:

[auto build test WARNING on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Wei-Fang/net-enetc-use-generic-interfaces-to-get-phc_index-for-ENETC-v1/20250918-160739
base:   net-next/main
patch link:    https://lore.kernel.org/r/20250918074454.1742328-1-wei.fang%40nxp.com
patch subject: [PATCH net-next] net: enetc: use generic interfaces to get phc_index for ENETC v1
config: parisc-randconfig-001-20250919 (https://download.01.org/0day-ci/archive/20250919/[email protected]/config)
compiler: hppa-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250919/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/net/ethernet/freescale/enetc/enetc_ethtool.c: In function 'enetc_get_ts_info':

>> drivers/net/ethernet/freescale/enetc/enetc_ethtool.c:955:14: warning: unused variable 'phc_idx' [-Wunused-variable]
     955 |         int *phc_idx;
         |              ^~~~~~~

vim +/phc_idx +955 drivers/net/ethernet/freescale/enetc/enetc_ethtool.c

f5b9a1cde0a26c Wei Fang     2025-08-29  949  
f5b9a1cde0a26c Wei Fang     2025-08-29  950  static int enetc_get_ts_info(struct net_device *ndev,
f5b9a1cde0a26c Wei Fang     2025-08-29  951  			     struct kernel_ethtool_ts_info *info)
f5b9a1cde0a26c Wei Fang     2025-08-29  952  {
f5b9a1cde0a26c Wei Fang     2025-08-29  953  	struct enetc_ndev_priv *priv = netdev_priv(ndev);
f5b9a1cde0a26c Wei Fang     2025-08-29  954  	struct enetc_si *si = priv->si;
f5b9a1cde0a26c Wei Fang     2025-08-29 @955  	int *phc_idx;
f5b9a1cde0a26c Wei Fang     2025-08-29  956  
f5b9a1cde0a26c Wei Fang     2025-08-29  957  	if (!enetc_ptp_clock_is_enabled(si))
f5b9a1cde0a26c Wei Fang     2025-08-29  958  		goto timestamp_tx_sw;
f5b9a1cde0a26c Wei Fang     2025-08-29  959  
5f3b8f93ed1b53 Wei Fang     2025-09-18  960  	info->phc_index = enetc_get_phc_index(si);
f5b9a1cde0a26c Wei Fang     2025-08-29  961  	if (info->phc_index < 0)
f5b9a1cde0a26c Wei Fang     2025-08-29  962  		goto timestamp_tx_sw;
f5b9a1cde0a26c Wei Fang     2025-08-29  963  
f5b9a1cde0a26c Wei Fang     2025-08-29  964  	enetc_get_ts_generic_info(ndev, info);
f5b9a1cde0a26c Wei Fang     2025-08-29  965  
f5b9a1cde0a26c Wei Fang     2025-08-29  966  	return 0;
f5b9a1cde0a26c Wei Fang     2025-08-29  967  
f5b9a1cde0a26c Wei Fang     2025-08-29  968  timestamp_tx_sw:
f5b9a1cde0a26c Wei Fang     2025-08-29  969  	info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE;
9c699a8f3b273c Martyn Welch 2024-09-12  970  
41514737ecaa60 Y.b. Lu      2019-05-23  971  	return 0;
41514737ecaa60 Y.b. Lu      2019-05-23  972  }
41514737ecaa60 Y.b. Lu      2019-05-23  973  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki