* [PATCH v2 net-next 0/2] net: enetc: improve the interface for obtaining phc_index
@ 2025-09-19 8:45 Wei Fang
2025-09-19 8:45 ` [PATCH v2 net-next 1/2] net: enetc: fix sleeping function called from rcu_read_lock() context Wei Fang
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Wei Fang @ 2025-09-19 8:45 UTC (permalink / raw)
To: claudiu.manoil, vladimir.oltean, xiaoning.wang, yangbo.lu,
richardcochran, andrew+netdev, davem, edumazet, kuba, pabeni,
Frank.Li
Cc: imx, netdev, linux-kernel
The first patch is to fix the issue that a sleeping function is called
in the context of rcu_read_lock(). The second patch is to use the generic
API instead of the custom API to get phc_index. In addition, the second
patch depends on the first patch to work.
Note, the first patch is a fix, but the issue does not exist in the net
tree, so the target tree is net-next.
---
v2 changes:
1. Add patch 1 to fix the issue that sleeping function called from
invalid context
2. Fix the build warning of patch 2.
v1 link: https://lore.kernel.org/netdev/20250918074454.1742328-1-wei.fang@nxp.com/
---
Wei Fang (2):
net: enetc: fix sleeping function called from rcu_read_lock() context
net: enetc: use generic interfaces to get phc_index for ENETC v1
drivers/net/ethernet/freescale/enetc/enetc.h | 3 --
.../ethernet/freescale/enetc/enetc_ethtool.c | 29 ++++++++-----------
.../net/ethernet/freescale/enetc/enetc_ptp.c | 5 ----
3 files changed, 12 insertions(+), 25 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 net-next 1/2] net: enetc: fix sleeping function called from rcu_read_lock() context
2025-09-19 8:45 [PATCH v2 net-next 0/2] net: enetc: improve the interface for obtaining phc_index Wei Fang
@ 2025-09-19 8:45 ` Wei Fang
2025-09-19 8:45 ` [PATCH v2 net-next 2/2] net: enetc: use generic interfaces to get phc_index for ENETC v1 Wei Fang
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Wei Fang @ 2025-09-19 8:45 UTC (permalink / raw)
To: claudiu.manoil, vladimir.oltean, xiaoning.wang, yangbo.lu,
richardcochran, andrew+netdev, davem, edumazet, kuba, pabeni,
Frank.Li
Cc: imx, netdev, linux-kernel
The rcu_read_lock() has been introduced in __ethtool_get_ts_info() since
the commit 4c61d809cf60 ("net: ethtool: Fix suspicious rcu_dereference
usage"). Therefore, the device drivers cannot use any sleeping functions
when implementing the callback of ethtool_ops::get_ts_info(). Currently,
pci_get_slot() is used in enetc_get_ts_info(), but it calls down_read()
which might sleep, so this is a potential issue. Therefore, to fix this
issue, pci_get_domain_bus_and_slot() is used to replace pci_get_slot()
in enetc_get_ts_info().
Reported-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Closes: https://lore.kernel.org/netdev/20250918124823.t3xlzn7w2glzkhnx@skbuf/
Fixes: f5b9a1cde0a2 ("net: enetc: add PTP synchronization support for ENETC v4")
Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
index 6215e9c68fc5..445bfd032e0f 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
@@ -895,7 +895,8 @@ static int enetc4_get_phc_index_by_pdev(struct enetc_si *si)
return -1;
}
- timer_pdev = pci_get_slot(bus, devfn);
+ timer_pdev = pci_get_domain_bus_and_slot(pci_domain_nr(bus),
+ bus->number, devfn);
if (!timer_pdev)
return -1;
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 net-next 2/2] net: enetc: use generic interfaces to get phc_index for ENETC v1
2025-09-19 8:45 [PATCH v2 net-next 0/2] net: enetc: improve the interface for obtaining phc_index Wei Fang
2025-09-19 8:45 ` [PATCH v2 net-next 1/2] net: enetc: fix sleeping function called from rcu_read_lock() context Wei Fang
@ 2025-09-19 8:45 ` Wei Fang
2025-09-22 11:41 ` [PATCH v2 net-next 0/2] net: enetc: improve the interface for obtaining phc_index Vladimir Oltean
2025-09-22 19:00 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Wei Fang @ 2025-09-19 8:45 UTC (permalink / raw)
To: claudiu.manoil, vladimir.oltean, xiaoning.wang, yangbo.lu,
richardcochran, andrew+netdev, davem, edumazet, kuba, pabeni,
Frank.Li
Cc: imx, netdev, linux-kernel
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.
Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
drivers/net/ethernet/freescale/enetc/enetc.h | 3 ---
.../ethernet/freescale/enetc/enetc_ethtool.c | 26 +++++++------------
.../net/ethernet/freescale/enetc/enetc_ptp.c | 5 ----
3 files changed, 10 insertions(+), 24 deletions(-)
diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h
index 815afdc2ec23..0ec010a7d640 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.h
+++ b/drivers/net/ethernet/freescale/enetc/enetc.h
@@ -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);
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
index 445bfd032e0f..71d052de669a 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
@@ -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;
@@ -906,18 +909,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);
@@ -950,22 +953,13 @@ static int enetc_get_ts_info(struct net_device *ndev,
{
struct enetc_ndev_priv *priv = netdev_priv(ndev);
struct enetc_si *si = priv->si;
- int *phc_idx;
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);
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_ptp.c b/drivers/net/ethernet/freescale/enetc/enetc_ptp.c
index 5243fc031058..b8413d3b4f16 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_ptp.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_ptp.c
@@ -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);
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 net-next 0/2] net: enetc: improve the interface for obtaining phc_index
2025-09-19 8:45 [PATCH v2 net-next 0/2] net: enetc: improve the interface for obtaining phc_index Wei Fang
2025-09-19 8:45 ` [PATCH v2 net-next 1/2] net: enetc: fix sleeping function called from rcu_read_lock() context Wei Fang
2025-09-19 8:45 ` [PATCH v2 net-next 2/2] net: enetc: use generic interfaces to get phc_index for ENETC v1 Wei Fang
@ 2025-09-22 11:41 ` Vladimir Oltean
2025-09-22 19:00 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Vladimir Oltean @ 2025-09-22 11:41 UTC (permalink / raw)
To: Wei Fang
Cc: claudiu.manoil, xiaoning.wang, yangbo.lu, richardcochran,
andrew+netdev, davem, edumazet, kuba, pabeni, Frank.Li, imx,
netdev, linux-kernel
On Fri, Sep 19, 2025 at 04:45:07PM +0800, Wei Fang wrote:
> The first patch is to fix the issue that a sleeping function is called
> in the context of rcu_read_lock(). The second patch is to use the generic
> API instead of the custom API to get phc_index. In addition, the second
> patch depends on the first patch to work.
>
> Note, the first patch is a fix, but the issue does not exist in the net
> tree, so the target tree is net-next.
>
> ---
> v2 changes:
> 1. Add patch 1 to fix the issue that sleeping function called from
> invalid context
> 2. Fix the build warning of patch 2.
> v1 link: https://lore.kernel.org/netdev/20250918074454.1742328-1-wei.fang@nxp.com/
> ---
>
> Wei Fang (2):
> net: enetc: fix sleeping function called from rcu_read_lock() context
> net: enetc: use generic interfaces to get phc_index for ENETC v1
>
> drivers/net/ethernet/freescale/enetc/enetc.h | 3 --
> .../ethernet/freescale/enetc/enetc_ethtool.c | 29 ++++++++-----------
> .../net/ethernet/freescale/enetc/enetc_ptp.c | 5 ----
> 3 files changed, 12 insertions(+), 25 deletions(-)
>
> --
> 2.34.1
>
For the set:
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Tested-by: Vladimir Oltean <vladimir.oltean@nxp.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 net-next 0/2] net: enetc: improve the interface for obtaining phc_index
2025-09-19 8:45 [PATCH v2 net-next 0/2] net: enetc: improve the interface for obtaining phc_index Wei Fang
` (2 preceding siblings ...)
2025-09-22 11:41 ` [PATCH v2 net-next 0/2] net: enetc: improve the interface for obtaining phc_index Vladimir Oltean
@ 2025-09-22 19:00 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-09-22 19:00 UTC (permalink / raw)
To: Wei Fang
Cc: claudiu.manoil, vladimir.oltean, xiaoning.wang, yangbo.lu,
richardcochran, andrew+netdev, davem, edumazet, kuba, pabeni,
Frank.Li, imx, netdev, linux-kernel
Hello:
This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Fri, 19 Sep 2025 16:45:07 +0800 you wrote:
> The first patch is to fix the issue that a sleeping function is called
> in the context of rcu_read_lock(). The second patch is to use the generic
> API instead of the custom API to get phc_index. In addition, the second
> patch depends on the first patch to work.
>
> Note, the first patch is a fix, but the issue does not exist in the net
> tree, so the target tree is net-next.
>
> [...]
Here is the summary with links:
- [v2,net-next,1/2] net: enetc: fix sleeping function called from rcu_read_lock() context
https://git.kernel.org/netdev/net-next/c/26644c90e8fb
- [v2,net-next,2/2] net: enetc: use generic interfaces to get phc_index for ENETC v1
https://git.kernel.org/netdev/net-next/c/ac0e650fde45
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-09-22 19:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-19 8:45 [PATCH v2 net-next 0/2] net: enetc: improve the interface for obtaining phc_index Wei Fang
2025-09-19 8:45 ` [PATCH v2 net-next 1/2] net: enetc: fix sleeping function called from rcu_read_lock() context Wei Fang
2025-09-19 8:45 ` [PATCH v2 net-next 2/2] net: enetc: use generic interfaces to get phc_index for ENETC v1 Wei Fang
2025-09-22 11:41 ` [PATCH v2 net-next 0/2] net: enetc: improve the interface for obtaining phc_index Vladimir Oltean
2025-09-22 19:00 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox