public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bpf: devmap: hoist loop-invariant xdp buff pointer setup
@ 2026-02-16 14:53 Anand Kumar Shaw
  2026-02-20  2:53 ` Alexei Starovoitov
  0 siblings, 1 reply; 2+ messages in thread
From: Anand Kumar Shaw @ 2026-02-16 14:53 UTC (permalink / raw)
  To: bpf
  Cc: netdev, ast, daniel, hawk, john.fastabend, kuba, davem, sdf,
	andrii, martin.lau, 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.

Signed-off-by: Anand Kumar Shaw <anandkrshawheritage@gmail.com>
---
 kernel/bpf/devmap.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
index 2625601de..568477ce7 100644
--- a/kernel/bpf/devmap.c
+++ b/kernel/bpf/devmap.c
@@ -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) {
-- 
2.39.5 (Apple Git-154)


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] bpf: devmap: hoist loop-invariant xdp buff pointer setup
  2026-02-16 14:53 [PATCH] bpf: devmap: hoist loop-invariant xdp buff pointer setup Anand Kumar Shaw
@ 2026-02-20  2:53 ` Alexei Starovoitov
  0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2026-02-20  2:53 UTC (permalink / raw)
  To: Anand Kumar Shaw
  Cc: bpf, Network Development, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Jakub Kicinski,
	David S. Miller, Stanislav Fomichev, Andrii Nakryiko,
	Martin KaFai Lau

On Mon, Feb 16, 2026 at 6:53 AM Anand Kumar Shaw
<anandkrshawheritage@gmail.com> wrote:
>
> 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.
>
> Signed-off-by: Anand Kumar Shaw <anandkrshawheritage@gmail.com>
> ---
>  kernel/bpf/devmap.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
> index 2625601de..568477ce7 100644
> --- a/kernel/bpf/devmap.c
> +++ b/kernel/bpf/devmap.c
> @@ -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;

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-02-20  2:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-16 14:53 [PATCH] bpf: devmap: hoist loop-invariant xdp buff pointer setup Anand Kumar Shaw
2026-02-20  2:53 ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox