From: Kuniyuki Iwashima <kuniyu@google.com>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
Jason Wang <jasowang@redhat.com>,
Andrew Lunn <andrew+netdev@lunn.ch>
Cc: Simon Horman <horms@kernel.org>,
Kuniyuki Iwashima <kuniyu@google.com>,
Kuniyuki Iwashima <kuni1840@gmail.com>,
netdev@vger.kernel.org
Subject: [PATCH v1 net-next] tun: Ignore tun in netdev_lock_pos().
Date: Fri, 27 Mar 2026 21:34:40 +0000 [thread overview]
Message-ID: <20260327213441.3781433-1-kuniyu@google.com> (raw)
dev->type could be any value on tun due to TUNSETLINK.
Let's not warn about it in netdev_lock_pos().
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
drivers/net/tun.c | 2 +-
include/linux/if_tun.h | 12 ++++++++++++
net/core/dev.c | 22 +++++++++++++---------
3 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index c492fda6fc15..48194e567656 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -2338,7 +2338,7 @@ static int tun_fill_info(struct sk_buff *skb, const struct net_device *dev)
return -EMSGSIZE;
}
-static struct rtnl_link_ops tun_link_ops __read_mostly = {
+struct rtnl_link_ops tun_link_ops __read_mostly = {
.kind = DRV_NAME,
.priv_size = sizeof(struct tun_struct),
.setup = tun_setup,
diff --git a/include/linux/if_tun.h b/include/linux/if_tun.h
index 80166eb62f41..89d9b7b0a044 100644
--- a/include/linux/if_tun.h
+++ b/include/linux/if_tun.h
@@ -20,6 +20,13 @@ struct tun_msg_ctl {
};
#if defined(CONFIG_TUN) || defined(CONFIG_TUN_MODULE)
+extern struct rtnl_link_ops tun_link_ops;
+
+static inline bool netdev_is_tun(const struct net_device *dev)
+{
+ return dev->rtnl_link_ops == &tun_link_ops;
+}
+
struct socket *tun_get_socket(struct file *);
struct ptr_ring *tun_get_tx_ring(struct file *file);
@@ -45,6 +52,11 @@ void tun_ptr_free(void *ptr);
struct file;
struct socket;
+static inline bool netdev_is_tun(const struct net_device *dev)
+{
+ return false;
+}
+
static inline struct socket *tun_get_socket(struct file *f)
{
return ERR_PTR(-EINVAL);
diff --git a/net/core/dev.c b/net/core/dev.c
index 200d44883fc1..bd91e0a3dbdf 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -89,6 +89,7 @@
#include <linux/errno.h>
#include <linux/interrupt.h>
#include <linux/if_ether.h>
+#include <linux/if_tun.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/ethtool.h>
@@ -526,24 +527,27 @@ static const char *const netdev_lock_name[] = {
static struct lock_class_key netdev_xmit_lock_key[ARRAY_SIZE(netdev_lock_type)];
static struct lock_class_key netdev_addr_lock_key[ARRAY_SIZE(netdev_lock_type)];
-static inline unsigned short netdev_lock_pos(unsigned short dev_type)
+static inline unsigned short netdev_lock_pos(const struct net_device *dev)
{
+ unsigned short dev_type = dev->type;
int i;
for (i = 0; i < ARRAY_SIZE(netdev_lock_type); i++)
if (netdev_lock_type[i] == dev_type)
return i;
+
/* the last key is used by default */
- WARN_ONCE(1, "netdev_lock_pos() could not find dev_type=%u\n", dev_type);
+ WARN_ONCE(!netdev_is_tun(dev),
+ "netdev_lock_pos() could not find dev_type=%u\n", dev_type);
return ARRAY_SIZE(netdev_lock_type) - 1;
}
-static inline void netdev_set_xmit_lockdep_class(spinlock_t *lock,
- unsigned short dev_type)
+static inline void netdev_set_xmit_lockdep_class(const struct net_device *dev,
+ spinlock_t *lock)
{
int i;
- i = netdev_lock_pos(dev_type);
+ i = netdev_lock_pos(dev);
lockdep_set_class_and_name(lock, &netdev_xmit_lock_key[i],
netdev_lock_name[i]);
}
@@ -552,14 +556,14 @@ static inline void netdev_set_addr_lockdep_class(struct net_device *dev)
{
int i;
- i = netdev_lock_pos(dev->type);
+ i = netdev_lock_pos(dev);
lockdep_set_class_and_name(&dev->addr_list_lock,
&netdev_addr_lock_key[i],
netdev_lock_name[i]);
}
#else
-static inline void netdev_set_xmit_lockdep_class(spinlock_t *lock,
- unsigned short dev_type)
+static inline void netdev_set_xmit_lockdep_class(const struct net_device *dev,
+ spinlock_t *lock)
{
}
@@ -11210,7 +11214,7 @@ static void netdev_init_one_queue(struct net_device *dev,
{
/* Initialize queue lock */
spin_lock_init(&queue->_xmit_lock);
- netdev_set_xmit_lockdep_class(&queue->_xmit_lock, dev->type);
+ netdev_set_xmit_lockdep_class(dev, &queue->_xmit_lock);
queue->xmit_lock_owner = -1;
netdev_queue_numa_node_write(queue, NUMA_NO_NODE);
queue->dev = dev;
--
2.53.0.1018.g2bb0e51243-goog
next reply other threads:[~2026-03-27 21:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-27 21:34 Kuniyuki Iwashima [this message]
2026-03-27 21:48 ` [PATCH v1 net-next] tun: Ignore tun in netdev_lock_pos() Eric Dumazet
2026-03-27 22:22 ` Kuniyuki Iwashima
2026-03-27 23:16 ` Willem de Bruijn
2026-03-28 0:19 ` Eric Dumazet
2026-03-30 2:29 ` Willem de Bruijn
2026-03-29 3:36 ` kernel test robot
2026-03-29 4:06 ` kernel test robot
2026-03-29 11:10 ` kernel test robot
2026-03-29 13:36 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260327213441.3781433-1-kuniyu@google.com \
--to=kuniyu@google.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jasowang@redhat.com \
--cc=kuba@kernel.org \
--cc=kuni1840@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemdebruijn.kernel@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.