Re: [PATCH net v2 1/4] ptp: ocp: prevent timestamp rearming during detach

From
Ahmad Byagowi <hidden>
Date
2026-11-20 21:21:46
Reply to
Vadim Fedorenko, 2026-11-20
On Fri, 20 Nov 2026 at 19:31 UTC, Vadim Fedorenko wrote:
On 19/11/2026 23:46, Ahmad Byagowi wrote:
quoted
On Thu, 19 Nov 2026 at 22:23 UTC, Vadim Fedorenko wrote:
quoted
enable() callback has to set PTP_PF_EXTTS function
Thanks. I tested the cleanup path. Recording an assignment makes the core
disable that channel, but ptp_ocp exposes six timestamp channels and only
four SMA descriptors. TS0 is the internal GNSS source and TS5 is the PHC
source. All six can be enabled without pin assignments. Four descriptors
cannot record that state without rejecting requests or changing the pin
interface. extts_enable sysfs also reaches enable() without an assignment.
Fair point. Pins are pins, time stampers are time stampers. We have to
disable things which may trigger interrupts, the time stampers.
quoted
Would you and Richard prefer disabling all n_ext_ts channels in
ptp_disable_all_events(), followed by the existing PPS disable? That keeps
cleanup after posix_clock_unregister(), without inventing pin assignments.
I have prepared and tested that alternative locally, not posted it yet.
Yes, it's better to make correct core PTP cleanup function.
Thanks. V3 follows that direction: disable all n_ext_ts channels in
ptp_disable_all_events(), followed by the existing PPS disable. Pin
descriptors and SMA routing stay unchanged. The driver's preliminary
timestamp-disable loop is removed, so final shutdown runs after sysfs
callbacks and active ioctls have finished, while the clock is still alive.

You also wrote:
quoted
I also removed ptp_ocp's preliminary disable loop. Otherwise it can clear
pps_req_map while an in-flight enable subsequently rearms the hardware.
An overlapping sysfs/ioctl request can likewise leave an empty map with
the source enabled, so the final disable now always masks and drains an
empty PPS map. The shortcut remains while another subscription is active.
quoted
why do we need it now?
The v2 teardown exception covered a disable that had cleared the map and
dropped the spinlock but had not yet completed synchronize_irq(). The
previous mutex version held its lock through the IRQ drain. This local
revision removes the stopping flag and its special-case condition: core
cleanup runs after active requests finish, and an empty map is disabled
and drained regardless of its prior value.
Could you please keep more context while quoting? It's really hard to
follow the conversation otherwise
Sorry, I trimmed the original question too far. Here is the code and the
full question from your 19 November review:
quoted
-		/* if no state change, just return */
-		if ((!!old_map ^ !!bp->pps_req_map) == 0)
-			return 0;
+		/* Teardown must drain IRQs even if another disable cleared the map. */
there was no need of this in the previous patch, why do we need it now?
quoted
+		if ((!!old_map ^ !!bp->pps_req_map) == 0 && !bp->ts_stopping)
+			goto out;
In v1, the mutex stayed held through synchronize_irq(). In v2, the
spinlock had to be released before that sleeping operation. Another
disable could therefore observe an empty subscription map while the first
disable still had an IRQ to drain. The ts_stopping exception made detach
drain it too, instead of returning solely because the map was unchanged.

V3 removes that flag and the added spinlock section. After user interfaces
are removed and their active operations have drained, core cleanup disables
each channel. In ptp_ocp_ts_enable(), the shortcut becomes:

    if (old_map && bp->pps_req_map)
            return 0;

This retains the shared source while a PPS or EXTTS subscriber remains.
An empty map always takes the mask/disable/readback/synchronize_irq path.
That also handles an earlier overlapping sysfs enable and ioctl disable
which left the map empty but the hardware enabled. This final shutdown
change is not a claim to serialize every normal-operation sysfs/ioctl race.

The refreshed source-derived removal/shared-PPS tests pass 100 runs and
reject all seven deliberate regressions. The routing fixes are unchanged
and retain your Reviewed-by tags. I have posted the signed four-patch
v3 series to net in a separate thread:

https://lore.kernel.org/r/20261120-timecard-common-v3-33316bf475-0-ahmadexp@gmail.com (local)

The cover links this discussion and explains replacement of the older
pending series. Thank you for reviewing the changes.

Ahmad
Thread (12 messages) 12 messages, 2 authors, last reply 1h ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help