* [PATCH net v2] ptp: vclock: Switch from RCU to SRCU
@ 2026-05-29 17:11 Kurt Kanzenbach
2026-05-29 17:39 ` Sebastian Andrzej Siewior
0 siblings, 1 reply; 2+ messages in thread
From: Kurt Kanzenbach @ 2026-05-29 17:11 UTC (permalink / raw)
To: Richard Cochran, Yangbo Lu, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Íñigo Huguet, Miroslav Lichvar, Blanco Alcaine Hector,
Christopher S. Hall, Sebastian Andrzej Siewior, Florian Zeitz,
netdev, linux-kernel, Kurt Kanzenbach
The usage of PTP vClocks leads immediately to the following issues with
ptp4l with LOCKDEP and DEBUG_ATOMIC_SLEEP enabled: "BUG: sleeping function
called from invalid context".
ptp_convert_timestamp() acquires a mutex_t within a RCU read section. This
is illegal, because acquiring a mutex_t can result in voluntary scheduling
request which is not allowed within a RCU read section.
Replace the RCU usage with SRCU where sleeping is allowed.
Reported-by: Florian Zeitz <florian.zeitz@schettke.com>
Closes: https://lore.kernel.org/all/00a8cce8-410e-4038-98af-49be6d93d7bd@schettke.com/
Fixes: 67d93ffc0f3c ("ptp: vclock: use mutex to fix "sleep on atomic" bug")
Signed-off-by: Kurt Kanzenbach <kurt@linutronix.de>
---
Changes in v2:
- Remove RFC. No comments.
- Link to v1: https://patch.msgid.link/20260521-vclock_rcu-v1-1-9c345c18bd72@linutronix.de
---
drivers/ptp/ptp_vclock.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/drivers/ptp/ptp_vclock.c b/drivers/ptp/ptp_vclock.c
index 915a4f6defc9..84cb527f59cc 100644
--- a/drivers/ptp/ptp_vclock.c
+++ b/drivers/ptp/ptp_vclock.c
@@ -19,6 +19,8 @@ static DEFINE_SPINLOCK(vclock_hash_lock);
static DEFINE_READ_MOSTLY_HASHTABLE(vclock_hash, 8);
+DEFINE_STATIC_SRCU(vclock_srcu);
+
static void ptp_vclock_hash_add(struct ptp_vclock *vclock)
{
spin_lock(&vclock_hash_lock);
@@ -37,7 +39,7 @@ static void ptp_vclock_hash_del(struct ptp_vclock *vclock)
spin_unlock(&vclock_hash_lock);
- synchronize_rcu();
+ synchronize_srcu(&vclock_srcu);
}
static int ptp_vclock_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
@@ -276,14 +278,16 @@ ktime_t ptp_convert_timestamp(const ktime_t *hwtstamp, int vclock_index)
{
unsigned int hash = vclock_index % HASH_SIZE(vclock_hash);
struct ptp_vclock *vclock;
- u64 ns;
u64 vclock_ns = 0;
+ int srcu_idx;
+ u64 ns;
ns = ktime_to_ns(*hwtstamp);
- rcu_read_lock();
+ srcu_idx = srcu_read_lock(&vclock_srcu);
- hlist_for_each_entry_rcu(vclock, &vclock_hash[hash], vclock_hash_node) {
+ hlist_for_each_entry_srcu(vclock, &vclock_hash[hash], vclock_hash_node,
+ srcu_read_lock_held(&vclock_srcu)) {
if (vclock->clock->index != vclock_index)
continue;
@@ -294,7 +298,7 @@ ktime_t ptp_convert_timestamp(const ktime_t *hwtstamp, int vclock_index)
break;
}
- rcu_read_unlock();
+ srcu_read_unlock(&vclock_srcu, srcu_idx);
return ns_to_ktime(vclock_ns);
}
---
base-commit: 422b5233b607476ac7176bfa2a101b9a103d7653
change-id: 20260521-vclock_rcu-e29c9c107c3b
Best regards,
--
Kurt Kanzenbach <kurt@linutronix.de>
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net v2] ptp: vclock: Switch from RCU to SRCU
2026-05-29 17:11 [PATCH net v2] ptp: vclock: Switch from RCU to SRCU Kurt Kanzenbach
@ 2026-05-29 17:39 ` Sebastian Andrzej Siewior
0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-05-29 17:39 UTC (permalink / raw)
To: Kurt Kanzenbach
Cc: Richard Cochran, Yangbo Lu, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Íñigo Huguet,
Miroslav Lichvar, Blanco Alcaine Hector, Christopher S. Hall,
Florian Zeitz, netdev, linux-kernel
On 2026-05-29 19:11:47 [+0200], Kurt Kanzenbach wrote:
> The usage of PTP vClocks leads immediately to the following issues with
> ptp4l with LOCKDEP and DEBUG_ATOMIC_SLEEP enabled: "BUG: sleeping function
> called from invalid context".
>
> ptp_convert_timestamp() acquires a mutex_t within a RCU read section. This
> is illegal, because acquiring a mutex_t can result in voluntary scheduling
> request which is not allowed within a RCU read section.
>
> Replace the RCU usage with SRCU where sleeping is allowed.
>
> Reported-by: Florian Zeitz <florian.zeitz@schettke.com>
> Closes: https://lore.kernel.org/all/00a8cce8-410e-4038-98af-49be6d93d7bd@schettke.com/
> Fixes: 67d93ffc0f3c ("ptp: vclock: use mutex to fix "sleep on atomic" bug")
> Signed-off-by: Kurt Kanzenbach <kurt@linutronix.de>
Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Sebastian
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-29 17:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-29 17:11 [PATCH net v2] ptp: vclock: Switch from RCU to SRCU Kurt Kanzenbach
2026-05-29 17:39 ` Sebastian Andrzej Siewior
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox