Skip to contentSkip to conversation

bpf: devmap: hoist loop-invariant xdp buff pointer setup

PATCH In review Anand Kumar Shaw 2 participants 2 messages Feb 16 – Feb 20

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: devmap: hoist loop-invariant xdp buff pointer setup

In dev_map_bpf_prog_run(), xdp.txq and xdp.rxq are assigned the same stack-local pointers on every iteration. xdp_convert_frame_to_buff() does not modify these fields, so the assignments are loop-invariant.

Hoist them before the loop, matching the pattern already used by cpu_map_bpf_prog_run_xdp() in cpumap.c.

No functional change.

---
 kernel/bpf/devmap.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/bpf/devmap.c +3 -2
index 2625601de..568477ce7 100644
@@ -341,14 +341,15 @@ static int dev_map_bpf_prog_run(struct bpf_prog *xdp_prog,
 	struct xdp_buff xdp;
 	int i, nframes = 0;
 
+	xdp.txq = &txq;
+	xdp.rxq = &rxq;
+
 	for (i = 0; i < n; i++) {
 		struct xdp_frame *xdpf = frames[i];
 		u32 act;
 		int err;
 
 		xdp_convert_frame_to_buff(xdpf, &xdp);
-		xdp.txq = &txq;
-		xdp.rxq = &rxq;
 
 		act = bpf_prog_run_xdp(xdp_prog, &xdp);
 		switch (act) {
Signature · 1 line
2.39.5 (Apple Git-154)
#1 lore raw
Quoted 24 lines · Anand Kumar Shaw

In dev_map_bpf_prog_run(), xdp.txq and xdp.rxq are assigned the same stack-local pointers on every iteration. xdp_convert_frame_to_buff() does not modify these fields, so the assignments are loop-invariant.

Hoist them before the loop, matching the pattern already used by cpu_map_bpf_prog_run_xdp() in cpumap.c.

No functional change.

---
 kernel/bpf/devmap.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/bpf/devmap.c +1 -0
index 2625601de..568477ce7 100644
@@ -341,14 +341,15 @@ static int dev_map_bpf_prog_run(struct bpf_prog *xdp_prog,
        struct xdp_buff xdp;
        int i, nframes = 0;
 
+       xdp.txq = &txq;

kernel/bpf/devmap.c static int dev_map_bpf_prog_run(struct bpf_prog *xdp_prog, · line 351

Quoted 10 lines
kernel/bpf/devmap.c +2 -2
+       xdp.rxq = &rxq;
+
        for (i = 0; i < n; i++) {
                struct xdp_frame *xdpf = frames[i];
                u32 act;
                int err;
 
                xdp_convert_frame_to_buff(xdpf, &xdp);
-               xdp.txq = &txq;
-               xdp.rxq = &rxq;

Compilers are smart enough to hoist on their own,
but with this change the humans would have to think harder whether xdp_convert_frame_to_buff() doesn't touch these two fields.

pw-bot: cr