Skip to content

Commit 4300fd6

Browse files
committed
Merge branch 'ptp_vclock-fixes'
Vladimir Oltean says: ==================== ptp_vclock fixes While I was intending to test something else related to PTP in net-next I noticed any time I would run ptp4l on an interface, the kernel would print "ptp: physical clock is free running" and ptp4l would exit with an error code. I then found Jeongjun Park's patch and subsequent explanation provided to Jakub's question, specifically related to the code which introduced the breakage I am seeing. https://lore.kernel.org/netdev/CAO9qdTEjQ5414un7Yw604paECF=6etVKSDSnYmZzZ6Pg3LurXw@mail.gmail.com/ I had to look at the original issue that prompted Jeongjun Park's patch, and provide an alternative fix for it. Patch 1/2 in this set contains a logical revert plus the alternative fix, squashed into one. Patch 2/2 fixes another issue which was confusing during debugging/ characterization, namely: "ok, the kernel clearly thinks that any physical clock is free-running after this change (despite there being no vclocks), but why would ptp4l fail to create the clock altogether? Why not just fail to adjust it?" By reverting (locally) Jeongjun Park's commit, I could reproduce the reported lockdep splat using the commands from patch 1/2's commit message, and this goes away with the reworked implementation. ==================== Link: https://patch.msgid.link/20250613174749.406826-1-vladimir.oltean@nxp.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 13c9020 + aa112cb commit 4300fd6

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

drivers/ptp/ptp_clock.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct __kernel_timex *tx)
121121
struct ptp_clock_info *ops;
122122
int err = -EOPNOTSUPP;
123123

124-
if (ptp_clock_freerun(ptp)) {
124+
if (tx->modes & (ADJ_SETOFFSET | ADJ_FREQUENCY | ADJ_OFFSET) &&
125+
ptp_clock_freerun(ptp)) {
125126
pr_err("ptp: physical clock is free running\n");
126127
return -EBUSY;
127128
}

drivers/ptp/ptp_private.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,27 @@ static inline int queue_cnt(const struct timestamp_event_queue *q)
9898
/* Check if ptp virtual clock is in use */
9999
static inline bool ptp_vclock_in_use(struct ptp_clock *ptp)
100100
{
101-
return !ptp->is_virtual_clock;
101+
bool in_use = false;
102+
103+
/* Virtual clocks can't be stacked on top of virtual clocks.
104+
* Avoid acquiring the n_vclocks_mux on virtual clocks, to allow this
105+
* function to be called from code paths where the n_vclocks_mux of the
106+
* parent physical clock is already held. Functionally that's not an
107+
* issue, but lockdep would complain, because they have the same lock
108+
* class.
109+
*/
110+
if (ptp->is_virtual_clock)
111+
return false;
112+
113+
if (mutex_lock_interruptible(&ptp->n_vclocks_mux))
114+
return true;
115+
116+
if (ptp->n_vclocks)
117+
in_use = true;
118+
119+
mutex_unlock(&ptp->n_vclocks_mux);
120+
121+
return in_use;
102122
}
103123

104124
/* Check if ptp clock shall be free running */

0 commit comments

Comments
 (0)