[SRU][B:linux-azure-4.15][PATCH 05/40] tun: setup xdp_rxq_info
William Breathitt Gray
william.gray at canonical.com
Mon Nov 2 12:48:21 UTC 2020
From: Jesper Dangaard Brouer <brouer at redhat.com>
BugLink: https://bugs.launchpad.net/bugs/1877654
Driver hook points for xdp_rxq_info:
* reg : tun_attach
* unreg: __tun_detach
I've done some manual testing of this tun driver, but I would
appriciate good review and someone else running their use-case tests,
as I'm not 100% sure I understand the tfile->detached semantics.
V2: Removed the skb_array_cleanup() call from V1 by request from Jason Wang.
Cc: Jason Wang <jasowang at redhat.com>
Cc: "Michael S. Tsirkin" <mst at redhat.com>
Cc: Willem de Bruijn <willemb at google.com>
Signed-off-by: Jesper Dangaard Brouer <brouer at redhat.com>
Reviewed-by: Jason Wang <jasowang at redhat.com>
Signed-off-by: Alexei Starovoitov <ast at kernel.org>
(backported from commit 8bf5c4ee1889308ccd396fdfd40ac94129ee419f)
[ vilhelmgray: context adjustments ]
Signed-off-by: William Breathitt Gray <william.gray at canonical.com>
---
drivers/net/tun.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index e9c7317618fa..2434b2bd902f 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -181,6 +181,7 @@ struct tun_file {
struct list_head next;
struct tun_struct *detached;
struct skb_array tx_array;
+ struct xdp_rxq_info xdp_rxq;
};
struct tun_flow_entry {
@@ -658,7 +659,10 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
tun->dev->reg_state == NETREG_REGISTERED)
unregister_netdevice(tun->dev);
}
- skb_array_cleanup(&tfile->tx_array);
+ if (tun) {
+ skb_array_cleanup(&tfile->tx_array);
+ xdp_rxq_info_unreg(&tfile->xdp_rxq);
+ }
sock_put(&tfile->sk);
}
}
@@ -699,11 +703,13 @@ static void tun_detach_all(struct net_device *dev)
tun_napi_del(tfile);
/* Drop read queue */
tun_queue_purge(tfile);
+ xdp_rxq_info_unreg(&tfile->xdp_rxq);
sock_put(&tfile->sk);
}
list_for_each_entry_safe(tfile, tmp, &tun->disabled, next) {
tun_enable_queue(tfile);
tun_queue_purge(tfile);
+ xdp_rxq_info_unreg(&tfile->xdp_rxq);
sock_put(&tfile->sk);
}
BUG_ON(tun->numdisabled != 0);
@@ -759,6 +765,22 @@ static int tun_attach(struct tun_struct *tun, struct file *file,
tfile->queue_index = tun->numqueues;
tfile->socket.sk->sk_shutdown &= ~RCV_SHUTDOWN;
+
+ if (tfile->detached) {
+ /* Re-attach detached tfile, updating XDP queue_index */
+ WARN_ON(!xdp_rxq_info_is_reg(&tfile->xdp_rxq));
+
+ if (tfile->xdp_rxq.queue_index != tfile->queue_index)
+ tfile->xdp_rxq.queue_index = tfile->queue_index;
+ } else {
+ /* Setup XDP RX-queue info, for new tfile getting attached */
+ err = xdp_rxq_info_reg(&tfile->xdp_rxq,
+ tun->dev, tfile->queue_index);
+ if (err < 0)
+ goto out;
+ err = 0;
+ }
+
if (tfile->detached) {
tun_enable_queue(tfile);
} else {
@@ -1498,6 +1520,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
xdp.data = buf + pad;
xdp_set_data_meta_invalid(&xdp);
xdp.data_end = xdp.data + len;
+ xdp.rxq = &tfile->xdp_rxq;
orig_data = xdp.data;
act = bpf_prog_run_xdp(xdp_prog, &xdp);
--
2.25.1
More information about the kernel-team
mailing list