[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250922221553.47802-8-simon.schippers@tu-dortmund.de>
Date: Tue, 23 Sep 2025 00:15:52 +0200
From: Simon Schippers <simon.schippers@...dortmund.de>
To: willemdebruijn.kernel@...il.com, jasowang@...hat.com, mst@...hat.com,
eperezma@...hat.com, stephen@...workplumber.org, leiyang@...hat.com,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
virtualization@...ts.linux.dev, kvm@...r.kernel.org
Cc: Simon Schippers <simon.schippers@...dortmund.de>,
Tim Gebauer <tim.gebauer@...dortmund.de>
Subject: [PATCH net-next v5 7/8] TUN & TAP: Methods to determine whether file is TUN/TAP for vhost_net
Those wrappers are inspired by tun_get_tx_ring/tap_get_tx_ring and replace
those methods.
Co-developed-by: Tim Gebauer <tim.gebauer@...dortmund.de>
Signed-off-by: Tim Gebauer <tim.gebauer@...dortmund.de>
Signed-off-by: Simon Schippers <simon.schippers@...dortmund.de>
---
drivers/net/tap.c | 10 +++++-----
drivers/net/tun.c | 10 +++++-----
include/linux/if_tap.h | 5 +++++
include/linux/if_tun.h | 6 ++++++
4 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/drivers/net/tap.c b/drivers/net/tap.c
index 9720481f6d41..8d3e74330309 100644
--- a/drivers/net/tap.c
+++ b/drivers/net/tap.c
@@ -1277,18 +1277,18 @@ void tap_ring_unconsume(struct file *file, void **batch, int n,
}
EXPORT_SYMBOL_GPL(tap_ring_unconsume);
-struct ptr_ring *tap_get_ptr_ring(struct file *file)
+bool is_tap_file(struct file *file)
{
struct tap_queue *q;
if (file->f_op != &tap_fops)
- return ERR_PTR(-EINVAL);
+ return false;
q = file->private_data;
if (!q)
- return ERR_PTR(-EBADFD);
- return &q->ring;
+ return false;
+ return true;
}
-EXPORT_SYMBOL_GPL(tap_get_ptr_ring);
+EXPORT_SYMBOL_GPL(is_tap_file);
int tap_queue_resize(struct tap_dev *tap)
{
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 25b170e903e1..b0193b06fedc 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -3822,18 +3822,18 @@ void tun_ring_unconsume(struct file *file, void **batch, int n,
}
EXPORT_SYMBOL_GPL(tun_ring_unconsume);
-struct ptr_ring *tun_get_tx_ring(struct file *file)
+bool is_tun_file(struct file *file)
{
struct tun_file *tfile;
if (file->f_op != &tun_fops)
- return ERR_PTR(-EINVAL);
+ return false;
tfile = file->private_data;
if (!tfile)
- return ERR_PTR(-EBADFD);
- return &tfile->tx_ring;
+ return false;
+ return true;
}
-EXPORT_SYMBOL_GPL(tun_get_tx_ring);
+EXPORT_SYMBOL_GPL(is_tun_file);
module_init(tun_init);
module_exit(tun_cleanup);
diff --git a/include/linux/if_tap.h b/include/linux/if_tap.h
index 0cf8cf200d52..5bbcc8611bf5 100644
--- a/include/linux/if_tap.h
+++ b/include/linux/if_tap.h
@@ -14,6 +14,7 @@ struct ptr_ring *tap_get_ptr_ring(struct file *file);
int tap_ring_consume_batched(struct file *file, void **array, int n);
void tap_ring_unconsume(struct file *file, void **batch, int n,
void (*destroy)(void *));
+bool is_tap_file(struct file *file);
#else
#include <linux/err.h>
#include <linux/errno.h>
@@ -32,6 +33,10 @@ static inline int tap_ring_consume_batched(struct file *f,
}
static inline void tap_ring_unconsume(struct file *file, void **batch,
int n, void (*destroy)(void *)) {}
+static inline bool is_tap_file(struct file *f)
+{
+ return false;
+}
#endif /* CONFIG_TAP */
/*
diff --git a/include/linux/if_tun.h b/include/linux/if_tun.h
index bd954bb117e8..869d61898e60 100644
--- a/include/linux/if_tun.h
+++ b/include/linux/if_tun.h
@@ -25,6 +25,7 @@ struct ptr_ring *tun_get_tx_ring(struct file *file);
int tun_ring_consume_batched(struct file *file, void **array, int n);
void tun_ring_unconsume(struct file *file, void **batch, int n,
void (*destroy)(void *));
+bool is_tun_file(struct file *file);
static inline bool tun_is_xdp_frame(void *ptr)
{
@@ -67,6 +68,11 @@ static inline int tun_ring_consume_batched(struct file *file,
static inline void tun_ring_unconsume(struct file *file, void **batch,
int n, void (*destroy)(void *)) {}
+static inline bool is_tun_file(struct file *f)
+{
+ return false;
+}
+
static inline bool tun_is_xdp_frame(void *ptr)
{
return false;
--
2.43.0
Powered by blists - more mailing lists