๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #13009

Re: [PATCH net v2] ptp: Report clock removal to poll waiters

#13009
From: netdev-bot+sashiko
Date: Mon, 09 Nov 2026 06:50
110 lines
11780 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 ยท High: 0 ยท Medium: 1 ยท Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The patch is incomplete for epoll waiters registered with
  EPOLLEXCLUSIVE.

--

ptp: Report clock removal to poll waiters

This patch makes ptp_poll() return EPOLLERR once the clock is marked
defunct. Before, a poll waiter could take the removal wakeup, see an
empty queue and stay blocked until timeout. It also changes the defunct
accesses in ptp_read() to READ_ONCE() and the store in
ptp_clock_unregister() to WRITE_ONCE().

> diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
> index f63b45f5ee6ae..dc5865e95f775 100644
> --- a/drivers/ptp/ptp_chardev.c
> +++ b/drivers/ptp/ptp_chardev.c
> @@ -593,6 +593,9 @@ __poll_t ptp_poll(struct posix_clock_context *pccontext, struct file *fp,
>  
>  	poll_wait(fp, &ptp->tsev_wq, wait);
>  
> +	if (READ_ONCE(ptp->defunct))
> +		return EPOLLERR;
> +
>  	return queue_cnt(queue) ? EPOLLIN : 0;
>  }
>  

[ ... ]

> diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
> index 47ffc773065a3..67f53ab4df61d 100644
> --- a/drivers/ptp/ptp_clock.c
> +++ b/drivers/ptp/ptp_clock.c
> @@ -523,7 +523,7 @@ int ptp_clock_unregister(struct ptp_clock *ptp)
>  	get_device(&ptp->dev);
>  
>  	/* Wake up any userspace waiting for an event. */
> -	ptp->defunct = 1;
> +	WRITE_ONCE(ptp->defunct, 1);
>  	wake_up_interruptible(&ptp->tsev_wq);

[Severity: Medium]
Is this fix complete for epoll waiters that registered with EPOLLEXCLUSIVE?

wake_up_interruptible() expands to __wake_up(x, TASK_INTERRUPTIBLE, 1,
NULL), so it wakes at most one exclusive entry and passes a NULL key. An
EPOLLEXCLUSIVE epitem is added to tsev_wq with add_wait_queue_exclusive()
in ep_ptable_queue_proc().

With a NULL key, pollflags is 0, and ep_poll_callback() takes this branch
whenever its epoll instance has a thread blocked in epoll_wait():

fs/eventpoll.c:ep_poll_callback() {
    ...
	if (waitqueue_active(&ep->wq)) {
		if ((epi->event.events & EPOLLEXCLUSIVE) &&
					!(pollflags & POLLFREE)) {
			switch (pollflags & EPOLLINOUT_BITS) {
			...
			case 0:
				ewake = 1;
				break;
    ...
}

__wake_up_common() then stops walking the queue:

	if (ret && (flags & WQ_FLAG_EXCLUSIVE) && !--nr_exclusive)
		break;

The remaining exclusive epitems on tsev_wq are never called, so their
epoll instances never re-poll the file. They never reach the new defunct
check in ptp_poll() or the zombie check in posix_clock_poll().

After this wakeup, ptp_clock_unregister() calls ptp_disable_all_events()
and tears down the kworker. posix_clock_unregister() does no wakeup of
its own. Nothing wakes tsev_wq again, so the other EPOLLEXCLUSIVE waiters
stay blocked until their timeout, or forever with a timeout of -1 unless
a signal arrives. That is the same symptom the commit message describes
as fixed:

  "remain blocked until timeout after device removal."

Plain poll/select, non-exclusive epoll, and the wait_event_interruptible()
in ptp_read() all use non-exclusive entries, so they are always woken.
That would explain why all 12 test waits passed.

Would wake_up_interruptible_all(&ptp->tsev_wq) be better for this final
removal wakeup, as sock_def_wakeup() does? A keyed wake-one such as
wake_up_interruptible_poll(..., EPOLLERR) would not help. EPOLLERR has no
EPOLLIN or EPOLLOUT bits, so it still lands in case 0 and sets ewake.

>  
>  	/* Tear down the POSIX clock, which removes the user interface. */

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261108064928.1931917-2-thnkslprpt%40gmail.com
Technical Details
Message-ID: <179420701368.994134.16970520289562773534@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359050-linux-kernel-netdev=dewy.ru
References: <20261108064928.1931917-2-thnkslprpt@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359050-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2] ptp: Report clock removal to poll waiters
Date: Mon, 09 Nov 2026 06:50:13 +0000
Organization: Usenet Network
Message-ID: <179420701368.994134.16970520289562773534@kernel.org>
References: <20261108064928.1931917-2-thnkslprpt@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="292793"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:FbiULua94Xt8EiJhTvQeSCjdgJM= sha256:JtllmaVEuwCluSBqoXcQjuFv67FYdp5cg6iLUlpQuD0=
	sha1:GdMWjNWs1/szR9LqkNSvWkxtrGg= sha256:qtQjAEkozScrf/NSCmaMgu0BccjkcVCBI1KlqpfoyWs=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 4B1911136EF; Mon,  9 Nov 2026 09:51:17 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id gygpKdsIc7kt;
	Mon,  9 Nov 2026 09:51:11 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-359050-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id F3BB3113691; Mon,  9 Nov 2026 09:51:01 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 31E46C5C20; Mon,  9 Nov 2026 06:50:32 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794207031;
	b=LhY2Vgg7oGfCrmTdj/LV3+rAVFpVNBwlodG5U4m5qjirs3hjeMnKhj0Alemr+Ngp+RI7
	 MLyIMBMWkt1fGfUfLz1md6xCKspn6XVZyW1Uj23gLIxDo5bicdeKuXa8VYoBmggS/BD3E
	 RKCP+Ed5EooIg15sdv1FTlg4uFpZfGnuX/AdmvbIhmppTVVnYiwQyIvBFVUvcqSXHJcBA
	 3/1X6M8jbvyb/jPCd2dprm0ZshGopDTepMEzRJZEV3M2Yh+17JvBy5Nz0d5EG6Ti2ZWE9
	 l+G3OEKrvs156Ka8USBBYcphXvhN2mWqRR7cW0y9fBHXXh/kfWCzNeLnCL37wTx67aw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794207031;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=nLRn9E9rDIIqHMb+z0GXGKtvDcL0o8fvdbUF/jWiy4U=;
	b=PztLg6H6mGyad/D5/1WrHR5rIGE+0Uh8VRY7cgk1N/AEfolngjL/q+frCSTnZOGSvcDi
	 oS2QA68JndOBEogxi7OSoKjRdIlfnFPyfjhQijw0v8r4s97RQu4Aeo8/FMs5+MP9tYPZH
	 bUBcHg9nQzXyKI60APTjMerV3rbwK15ZkoykqpLAMv1v1xt6JCGMgvir0YPF+tXZkIFGW
	 Y/7ooXaBrvab1IaEqPPKBANfuXSIVacxz/HdlKLsu9Waesq/3xtJ0pG6enl4mGG4QF582
	 SZNyzLshBwI9fUg9GR2uiNpnVdCNA2IcZ44xXpnZ0/kCOyicSqBdT8scBZO+pLNMvPw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IA2G3smf;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 4A3C6606A326;
	Mon,  9 Nov 2026 06:50:31 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IA2G3smf
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794207015;
	b=NiBm1ZpKHMe9ylhOxgTifKvbuF4+iE1GutkHS4ejjURGCoI49+FnZ9R8DxugAFb8exqK
	 siHbX/YQoHDBJma6epyxlmLU1KgUjOBL2ROw4iwG1mYxQPoRta9xyQruwvw2g56SmMy8U
	 2XbpK12noRtp8wfafeYI1H7GKr9l1JKi817vqWvl+mNyCDhJz3OpGBEXrnWxcaOz6PBaB
	 6pSkPpxWJQq6kgsm55XZ5ZbAx1ZPgE/aFuHvD4AZO41htOZwuUghNWwZj4qPuRBp8WMWH
	 QT2WQwMV1icLsEZnHWH6oHrrv7T41VtgoT9OvFE3OuF0qCcgjTQY8cB3wR1cyOHnbig==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794207015;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=nLRn9E9rDIIqHMb+z0GXGKtvDcL0o8fvdbUF/jWiy4U=;
	b=clefNAwAQmEjzs3D3/B/GXqOfrglHxKeQyc5qUXcRhdT3xKrgRfWOvHqHXNOvVfIhJhX
	 wp4h2JDNr4fMHKeicGSaEwVj+VEoJzm7/z+g6o2HXGAMorv9GjY8FI4RtIeHDwusUaV9I
	 MooGljMl2+uWs+jeV/pkrJBDgzBkH5vpgqAIoIA0EBK6Htrb3dNSnNPXxpXHbOsHsoEtT
	 Ax8tnMBfAN/g8GLg+fjA7b5SmqDobibD9OXNtcKGQRuZ/f9qAxW7MNSbo8vheSkCqMZ3D
	 pRAZwsaQ88QAY7+FPqBMziBZVLZha1VnNQeZZgiA+Qg26bRocrwDY+Rzrl1k9bY02zw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IA2G3smf;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23F7A606A31C;
	Mon,  9 Nov 2026 06:50:14 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 287CD1F0089F;
	Mon,  9 Nov 2026 06:50:14 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794207014;
	bh=nLRn9E9rDIIqHMb+z0GXGKtvDcL0o8fvdbUF/jWiy4U=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=IA2G3smfFVuLKysbcWlAyLcyFL1drRq9FoD1+450npPyiPn3XnkckqTAyYLpBGLmJ
	 C1Qw5jkTDR6jDtQRWxP669xmAGulhB872vL0RD7qEJng1KJ3XQ9FiufrPtPVEOYnKu
	 uF0soySFszlao09vbeZU2XMAyzGt3LAQ9uzpf6m+VxXEsoocDIM+jX+DbJA47Ab/Ao
	 vWzI7cbS6QISmwmXkfbzLJUnBy2WhcjFaOa86dpG3azpF7tVEqt6r8XjBH3ZNFEliX
	 kR42xBL1bsqhO/ZXQ/f9m2NQjRCGM73bNM6GFS7il2MMG1uv6ecjhDVRz/NueD8YvE
	 +ZxH/RmVGO81g==
X-Cc: richardcochran@gmail.com, netdev@vger.kernel.org, horms@kernel.org,
 andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, arnd@arndb.de, john.stultz@linaro.org,
 linux-kernel@vger.kernel.org
X-In-Reply-To: <20261108064928.1931917-2-thnkslprpt@gmail.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list