🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #10569

[PATCH net] net: cancel napi->timer after the grace period in netif_napi_del()

#10569
From: Mani Tofigh via B4 Relay
Date: Tue, 03 Nov 2026 18:19
130 lines
16056 bytes
From: Mani Tofigh <mt4022@columbia.edu>

A napi can be freed with its timer still queued.  napi_disable()
cancels napi->timer, but napi_complete_done(), busy_poll_stop() and
napi_suspend_irqs() start it without owning the napi and can do so
right after the cancel.  netif_napi_del() only waits for that start to
finish:

  Task A (epoll_wait)                  Task B (queue reset)
  napi_suspend_irqs()
    rcu_read_lock()
    napi = napi_by_id(id)
                                       napi_disable_locked(napi)
                                         hrtimer_cancel(&napi->timer)
                                         napi_hash_del(napi)
                                       netif_napi_del_locked(napi)
                                         synchronize_net()
                                         /* waits for Task A */
    hrtimer_start(&napi->timer)
    rcu_read_unlock()
                                       kfree(rq)
                                         /* timer still queued */

With netdevsim and debug objects:

  [    3.073483] ODEBUG: free active (active state 0) object: 000000001504358f object type: hrtimer hint: napi_watchdog+0x0/0xa0
  [    3.073515] WARNING: lib/debugobjects.c:629 at debug_print_object+0x1a4/0x3b0, CPU#0: napitimer/66
  [    3.079603] CPU: 0 UID: 0 PID: 66 Comm: napitimer Tainted: G        W            7.3.0-17087-gd865f2677c44 #1 PREEMPT
  [    3.084822] RIP: 0010:debug_print_object+0x1ae/0x3b0
  ...
  [    3.103822] Call Trace:
  [    3.104408]  <TASK>
  [    3.105933]  debug_check_no_obj_freed+0x496/0x5f0
  [    3.109988]  kfree+0x33a/0x510
  [    3.110715]  netdev_rx_queue_reconfig+0x357/0x580
  [    3.111780]  netdev_rx_queue_restart+0x8f/0xc0
  [    3.113924]  nsim_qreset_write+0x24d/0x350
  [    3.117832]  full_proxy_write+0x109/0x1d0
  [    3.118741]  vfs_write+0x1e3/0x1250
  [    3.124758]  __x64_sys_pwrite64+0x18c/0x250
  [    3.129645]  do_syscall_64+0xfb/0x590
  [    3.131385]  entry_SYSCALL_64_after_hwframe+0x77/0x7f

Without debug objects, napi_watchdog() later runs on freed memory.

After napi_disable() and a grace period none of the three can reach the
napi anymore.  Two need SCHED, which napi_disable() keeps, and
napi_suspend_irqs() needs the napi hash, which napi_disable() removed it
from.  So cancel the timer again after the grace period that
netif_napi_del() already waits for, and in free_netdev(), where
unregister has already waited for one.  With the fix, debug objects
don't report a freed active timer anymore.

This bug was identified and confirmed with the help of a deterministic
hypervisor currently under development.  The C reproducer below however
hits it within about 1s.

Fixes: 6f8b12d661d0 ("net: napi: add hard irqs deferral feature")
Fixes: 3fcbecbdeb04 ("net: Add control functions for irq suspension")
Fixes: 58e2330bd455 ("net: napi: Avoid gro timer misfiring at end of busypoll")
Signed-off-by: Mani Tofigh <mt4022@columbia.edu>
---
Drivers that call __netif_napi_del{,_locked}() and then their own
synchronize_net() (eg netdevsim on close, veth, virtio_net, bnxt and
gro_cells) need the same cancel.  I can send that separately.

Reproducer: https://github.com/manitofigh/files/blob/main/linux-repros/napitimer.c
---
 include/linux/netdevice.h | 9 +++++++++
 net/core/dev.c            | 5 ++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 435be7880d7e..ad3685caf814 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -3013,8 +3013,13 @@ static inline void __netif_napi_del(struct napi_struct *napi)
 
 static inline void netif_napi_del_locked(struct napi_struct *napi)
 {
+	bool listed = test_bit(NAPI_STATE_LISTED, &napi->state);
+
 	__netif_napi_del_locked(napi);
 	synchronize_net();
+	/* napi->timer can be started until a grace period after napi_disable() */
+	if (listed)
+		hrtimer_cancel(&napi->timer);
 }
 
 /**
@@ -3025,8 +3030,12 @@ static inline void netif_napi_del_locked(struct napi_struct *napi)
  */
 static inline void netif_napi_del(struct napi_struct *napi)
 {
+	bool listed = test_bit(NAPI_STATE_LISTED, &napi->state);
+
 	__netif_napi_del(napi);
 	synchronize_net();
+	if (listed)
+		hrtimer_cancel(&napi->timer);
 }
 
 int netif_enable_cpu_rmap(struct net_device *dev, unsigned int num_irqs);
diff --git a/net/core/dev.c b/net/core/dev.c
index f32353b0467c..6d6384522a1b 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -12450,9 +12450,12 @@ static void netdev_napi_exit(struct net_device *dev)
 	if (!list_empty(&dev->napi_list)) {
 		struct napi_struct *p, *n;
 
+		/* unregister has waited for a grace period after napi_disable() */
 		netdev_lock(dev);
-		list_for_each_entry_safe(p, n, &dev->napi_list, dev_list)
+		list_for_each_entry_safe(p, n, &dev->napi_list, dev_list) {
+			hrtimer_cancel(&p->timer);
 			__netif_napi_del_locked(p);
+		}
 		netdev_unlock(dev);
 
 		synchronize_net();

---
base-commit: 647b81ddefc6364290e67bf33c89d54971f8995e
change-id: 20261103-napi-timer-cancel-fa0a285fd581

Best regards,
--  
Mani Tofigh <mt4022@columbia.edu>
Technical Details
Message-ID: <20261103-napi-timer-cancel-v1-1-55c631ad5286@columbia.edu>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355911-linux-kernel-netdev=dewy.ru

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-355911-linux-kernel-netdev=dewy.ru
From: devnull+mt4022.columbia.edu@kernel.org (Mani Tofigh via B4 Relay)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net] net: cancel napi->timer after the grace period in
 netif_napi_del()
Date: Tue, 03 Nov 2026 13:19:16 -0500
Organization: Usenet Network
Message-ID: <20261103-napi-timer-cancel-v1-1-55c631ad5286@columbia.edu>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="3231923"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:gcR6ACjjLhkuMXu2F5SacMJuMX4= sha256:XkkH+IrT2U4odwDhEu4dm9ecDtAIhowOlM8Jh8jaQDI=
	sha1:cx5je1NrK68V2LbnZIuyL/EzoRw= sha256:7QXUsYDo6Dgn4gJJa4nKlPG/FMW3aq+O6eDAWujqvmY=
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 885DD1129A0; Tue,  3 Nov 2026 21:33:36 +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 z1c6Euzy8ZRS;
	Tue,  3 Nov 2026 21:33:29 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-355911-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 E05CA112971; Tue,  3 Nov 2026 21:33:20 +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 70482883F8; Tue,  3 Nov 2026 18:19:37 +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=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793729960;
	b=U88UiVIHpCGrI12YJG6oOHHFDr6l8dN+8RmtY0oejHpPnwr0EiT7ThaiwUrssemcU5DE
	 i+V5KFfbWGa4TnZQiE/9ILVR2ggNTa4DwL1Ir/lQk1hbGxroy0ipxwcqC5PrB9leClB/J
	 upvLGvC+d62Ywf7syGyenVfPEDMy4oN4x/jJK8WHFpvhKNHR3apFhpYjGTKjFmf3dCbR+
	 VAqmQ7k0XGOFghRqCtvcz+dXxEUh38vU2KGAwhpho9zb7N6vvQdscO3pBZHCKlY3FIT2y
	 pKPHDD08sKCPZQaD8colsGnif67m/YoMJI+lTAAVcD8LJhZ3kDXz1rTLz8nZUptWZnQ==
X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793729960;
	h=X-Original-To:Received:Received:DKIM-Signature:Received:From:Date:
	 Subject:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer:
	 X-Developer-Signature:X-Developer-Key:X-Endpoint-Received:
	 X-Original-From:Reply-To:Content-Transfer-Encoding;
	bh=b5Apdfbysx3UZszHr/cOZmvpYIko3amgTXRkBzLxPAo=;
	b=QO4eY3APMZNkrYKplc69aj+tI/vtSAe2ZIPTqyZMWzgPq41AYJJxQgrkVj3I9TdUiNTI
	 iWsNzqfDRr+jnKFZSgnz5+H5LkU4HmOOUWXoqMNc0KmXgKqIVBkeC/EiArJAXBpT5Haju
	 UMD3QhvyGucZPJLDQuBy1Ug4r4sMs/R1XU9Lwkqul9VMotIdspOgn72S1QEztWMgeI73D
	 5iXEGyNsRLXQRfCGCkd+LZwAsxEQ6j/wyFNZWcr9ihRBIIRzZPMDMgN8FjV6ZFlc4ZZak
	 LMV5kYQ3+ebZ20HIiSsh8u0KtIkOIjq4OWZfjo4gdGf6zn04CFe85PwJj/z6QFVDkSg==
X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=i4jNSPJF;
	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 23FA7606D837;
	Tue,  3 Nov 2026 18:19:20 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=i4jNSPJF
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793729959;
	b=orzpTcVanS2selAuS396wP0XgxIZXpifT/amj8e/+3znVpe6Zj07Y3Ak6IJeoV6y3fHm
	 T4fZ0ILOwaiz/GKM00PRM9QlCq2euhKNUf1Kp9+tKz5xtaZ9Bi8j3mml3NDsjHJwk/ntj
	 xeMUxsvcsqQoNJqsiN0q1nJhP/LfY0UGxLLdoYKZZLqwCiAuBuTAteVO9dv/J6OOyxHwl
	 4ifFiXZcQPTPDG/G2QulBZ0CeAwnY6MbMQHD316CHeV7RtA5VaArdodsepqK9yVdE2DWO
	 zfr+hjj2rk9KPFyiOKlsKbIaoPi3I+24vuv/tVEVe/zO0pWDiTiGeV3K1jYnvZPUyyw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793729959;
	h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version:
	 Content-Type:Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer:
	 X-Developer-Signature:X-Developer-Key:X-Endpoint-Received:
	 X-Original-From:Reply-To:Content-Transfer-Encoding;
	bh=b5Apdfbysx3UZszHr/cOZmvpYIko3amgTXRkBzLxPAo=;
	b=HSW6N1m2F0bZud8/Bl5jut4QlaTwXzcH6CPfGG7CWOplwVfdaGZ+7W714C8+gXMhn8P5
	 eCBzn4JJpYTcyJ6UWH4R3BLs5zdtHxujrkWFK3mY6AmtQ0JVZhE92XJuxNdG4KkyxW90a
	 59qF59U3GsxAgQ3YtQr1vk0c/WrQT8HWVYucDDo8LhkCNphryVUl0ZVgj2T4xDWaztryg
	 UCR8/C7M7ICkLvQjOlHUILEXpA7uvRtwOj2atujWih/yLgyb6F58AvfTx/9uNBEdgLPxe
	 SGhJ86BrRmu/fRttBD8j7Y5xqVfD5t2JD0Qx024XISTHao+r2Woj2+6T2rmQfgnsYwg==
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=i4jNSPJF;
	arc=pass header.oldest-pass=0 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 EFE53606D824;
	Tue,  3 Nov 2026 18:19:18 +0000 (UTC)
X-Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77
X-ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none;
	t=1793729958;
	b=JxvyKQamrHKQPXL49Gzyc4SE4QS8P0ft+3apo/CIjxJgx2QjfRLC2/F4CrcsRRLIdBA2
	 2gFbAdfiyeqbRCAnQ5/UALxweB+B8EOOgifU6teNNZ1PifEIEds6rnpx7+ND08eIGIgKd
	 jvrZi5WMmPEr2tdu95n58kfb6WXFdsU4AS6gSM0W2Ba7cepqLPWoGv1EEtAV/uu/8IZ9w
	 AqqucnDFrF1DtLgY4sIdguFafOlVmoOylbHpD0odouyIwR10jYU/AFG+71Npf5A2t8rgg
	 GhvpRn6I9pzYwXh9e/VWGYHZqO1tGkFrtbv5+/iwW7iOfYr6D/6mQc/rkyhZiX8VPPg==
X-ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256;
	c=relaxed/relaxed; t=1793729958;
	h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type:
	 Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer:
	 X-Developer-Signature:X-Developer-Key:X-Endpoint-Received:
	 X-Original-From:Reply-To:Content-Transfer-Encoding;
	bh=b5Apdfbysx3UZszHr/cOZmvpYIko3amgTXRkBzLxPAo=;
	b=MmpYhZC5Q77yGKD9VOg5/QJdw8SxKnqXFvffqaPdBsEn8UxcKWRsgSzZ+pjoyekmWZ/W
	 7qR/MmUz/KWA7m9Dx3fXscHsvKFD2GQ7P7Uww37V7pQuaSTYOQhwA7/b/KXELOzwSyFfJ
	 hYPeye6OHxDDDQJzq69ukXt/D96WqmVculNuX0v0PuPEvfVlGR7sBsKafls6jd9mlGqHL
	 ciNCvy1Sox8dGrkkc5Il+HfqyBxHeo5JbEEaAyUCdyezdYeNHwpDwQdHQ8A7zJWSH53VD
	 F1p4qM7VfsTkOozx/qmw1pIklackXpFH7pVT6DGYDT19xaQ5vPWmZyw7xfe03wsK5Jw==
X-ARC-Authentication-Results: i=1; smtp.kernel.org; 
	arc=none smtp.remote-ip=100.80.115.77
X-Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.kernel.org (Postfix) with ESMTPS id 6EE851F00A16;
	Tue,  3 Nov 2026 18:19:16 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793729958;
	bh=b5Apdfbysx3UZszHr/cOZmvpYIko3amgTXRkBzLxPAo=;
	h=From:Date:Subject:To:Cc:Reply-To;
	b=i4jNSPJFaLkW6Ofqp75erX029EWCwKlZBxrBUNuHAbiNQBQXga5zcveb6BkWtqs/4
	 WLM2ybrAELWc4RXN/ny12AkgKlfGxU1U8VNbk5x3rObXF51EChQWA9gU4TMSwKm8g2
	 9Mlu6SSN5S7axdejTAZCH5NUu5Qq0q8OOXXHUqON04qqeKQmq3YjNUg1/QlmeoUpp4
	 8QN74PKCcE+AcfZxXe3ieyT5+/Gd7b6dP9iP0k3+8vieS+6krmGoOSbrneGJWB2+06
	 JJvYfUpPE3050B1zC9X8/F29O5kTvfGgsdqSxI6STuNUPuJEkoljtadjr6SwIs3VMn
	 Ftf0MZvuYYMHw==
X-Received: from nexus.subspace.kernel.org (localhost [IPv6:::1])
	by lkml.kernel.org (Postfix) with ESMTP id 039ED46A69;
	Tue,  3 Nov 2026 18:19:16 +0000 (UTC)
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
X-B4-Tracking: v=1; b=H4sIAAAAAAAC/yWMwQrCMBAFf6W8swtJSqX4K+JhTTe6omtJogil/
 96oxxmYWVAkqxQcugVZ3lr0aQ38rkO8sl2EdGqM4MLee9eT8axU9SGZIluUOyV2HMYhTcPo0bo
 5S9LP73mEScXpL8vrfJNYvzes6waLWeTzegAAAA==
X-Change-ID: 20261103-napi-timer-cancel-fa0a285fd581
X-Cc: Simon Horman <horms@kernel.org>, Andrew Lunn <andrew+netdev@lunn.ch>, 
 Martin Karsten <mkarsten@uwaterloo.ca>, Joe Damato <joe@dama.to>, 
 Dragos Tatulea <dtatulea@nvidia.com>, Kuniyuki Iwashima <kuniyu@google.com>, 
 Stanislav Fomichev <sdf.kernel@gmail.com>, 
 Sridhar Samudrala <sridhar.samudrala@intel.com>, 
 Cosmin Ratiu <cratiu@nvidia.com>, Tariq Toukan <tariqt@nvidia.com>, 
 Wang Zhan <wang.zhan@smartx.com>, netdev@vger.kernel.org, 
 linux-kernel@vger.kernel.org, tz2294@columbia.edu, 
 Mani Tofigh <mt4022@columbia.edu>
X-Mailer: b4 0.16.0
X-Developer-Signature: v=1; a=ed25519-sha256; t=1793729955; l=5193;
 i=mt4022@columbia.edu; s=20261026; h=from:subject:message-id;
 bh=D3DRGuFE0EATDQVzQQV5RjgLb6ytoSbotejXuz5TFKc=;
 b=ssRhd2VE5LU/8fFDf9oHRD8iJ0XKlAM1RWeKEnlFASOxuU6corXvDu0kFe6ZGsG7EEOSLCpRM
 /EI/Db8vV0yCH1bPZEHjbW0a+Y5tEYG6c1CgdcmpBFzIh3UK5NqKwMz
X-Developer-Key: i=mt4022@columbia.edu; a=ed25519;
 pk=gljCMQDuxyKPmd5y37CRpEJGSPXDV1MyAnHBhCgXl0I=
X-Endpoint-Received: by B4 Relay for mt4022@columbia.edu/20261026 with
 auth_id=1322
X-Original-From: Mani Tofigh <mt4022@columbia.edu>
X-Reply-To: mt4022@columbia.edu