]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: Move flush list retrieval to where it is used.
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Fri, 28 Jun 2024 10:18:56 +0000 (12:18 +0200)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 2 Jul 2024 13:26:57 +0000 (15:26 +0200)
The bpf_net_ctx_get_.*_flush_list() are used at the top of the function.
This means the variable is always assigned even if unused. By moving the
function to where it is used, it is possible to delay the initialisation
until it is unavoidable.
Not sure how much this gains in reality but by looking at bq_enqueue()
(in devmap.c) gcc pushes one register less to the stack. \o/.

 Move flush list retrieval to where it is used.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Acked-by: Jesper Dangaard Brouer <hawk@kernel.org>
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
kernel/bpf/cpumap.c
kernel/bpf/devmap.c
net/xdp/xsk.c

index 4acf90cd79eb4325f196868e4c3d48eda9012aea..fbdf5a1aabfe4fadde07d395ebf4fc5e74e40b92 100644 (file)
@@ -707,7 +707,6 @@ static void bq_flush_to_queue(struct xdp_bulk_queue *bq)
  */
 static void bq_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_frame *xdpf)
 {
-       struct list_head *flush_list = bpf_net_ctx_get_cpu_map_flush_list();
        struct xdp_bulk_queue *bq = this_cpu_ptr(rcpu->bulkq);
 
        if (unlikely(bq->count == CPU_MAP_BULK_SIZE))
@@ -724,8 +723,11 @@ static void bq_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_frame *xdpf)
         */
        bq->q[bq->count++] = xdpf;
 
-       if (!bq->flush_node.prev)
+       if (!bq->flush_node.prev) {
+               struct list_head *flush_list = bpf_net_ctx_get_cpu_map_flush_list();
+
                list_add(&bq->flush_node, flush_list);
+       }
 }
 
 int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_frame *xdpf,
index 9ca47eaacdd5e0bfcb1f5a52b56628a331fd951a..b18d4a14a0a70908f6d2231b61054c5e79ffb7e2 100644 (file)
@@ -448,7 +448,6 @@ static void *__dev_map_lookup_elem(struct bpf_map *map, u32 key)
 static void bq_enqueue(struct net_device *dev, struct xdp_frame *xdpf,
                       struct net_device *dev_rx, struct bpf_prog *xdp_prog)
 {
-       struct list_head *flush_list = bpf_net_ctx_get_dev_flush_list();
        struct xdp_dev_bulk_queue *bq = this_cpu_ptr(dev->xdp_bulkq);
 
        if (unlikely(bq->count == DEV_MAP_BULK_SIZE))
@@ -462,6 +461,8 @@ static void bq_enqueue(struct net_device *dev, struct xdp_frame *xdpf,
         * are only ever modified together.
         */
        if (!bq->dev_rx) {
+               struct list_head *flush_list = bpf_net_ctx_get_dev_flush_list();
+
                bq->dev_rx = dev_rx;
                bq->xdp_prog = xdp_prog;
                list_add(&bq->flush_node, flush_list);
index de9c0322bc294815b9f5778391d2d534b9ca9cf4..7e16336044b2d68f3562fa20d11f2ed60f33f744 100644 (file)
@@ -370,15 +370,17 @@ static int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
 
 int __xsk_map_redirect(struct xdp_sock *xs, struct xdp_buff *xdp)
 {
-       struct list_head *flush_list = bpf_net_ctx_get_xskmap_flush_list();
        int err;
 
        err = xsk_rcv(xs, xdp);
        if (err)
                return err;
 
-       if (!xs->flush_node.prev)
+       if (!xs->flush_node.prev) {
+               struct list_head *flush_list = bpf_net_ctx_get_xskmap_flush_list();
+
                list_add(&xs->flush_node, flush_list);
+       }
 
        return 0;
 }