All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Morten Brørup" <mb@smartsharesystems.com>
To: "Marat Khalili" <marat.khalili@huawei.com>,
	"Christophe Fontaine" <cfontain@redhat.com>, <dev@dpdk.org>
Cc: "Konstantin Ananyev" <konstantin.ananyev@huawei.com>,
	"Wathsala Vithanage" <wathsala.vithanage@arm.com>
Subject: RE: [PATCH] bpf/arm64: support packet data load instructions
Date: Wed, 18 Mar 2026 13:54:47 +0100	[thread overview]
Message-ID: <98CBD80474FA8B44BF855DF32C47DC35F6579F@smartserver.smartshare.dk> (raw)
In-Reply-To: <b10d0edcdaac4fd9a4f5a0261205670c@huawei.com>

> > +static void
> > +emit_ld_mbuf(struct a64_jit_ctx *ctx, uint32_t op, uint8_t tmp1,
> uint8_t tmp2,
> > +	uint8_t src, uint32_t imm)
> 
> Handling immediate as unsigned is questionable, especially in the
> BPF_IND case
> it may produce incorrect results.

In Classic BPF (cBPF), when the immediate "k" is negative (when cast to signed integer), it is used for getting packet metadata (e.g. SKF_AD_VLAN_TAG gets the VLAN ID); otherwise it is considered unsigned.

> 
> To make things worse, `__rte_pktmbuf_read` is also buggy when passed
> very large
> lengths (again, technically not ARM eBPF fault).

Are you referring to the potential integer wraparound in the off+len > rte_pktmbuf_pkt_len(m) comparison?
[BZ1724]
Or some other bug in __rte_pktmbuf_read()?

[BZ1724]: https://bugs.dpdk.org/show_bug.cgi?id=1724

> 
> > +{
> > +	uint8_t r0 = ebpf_to_a64_reg(ctx, EBPF_REG_0);
> > +	uint8_t r6 = ebpf_to_a64_reg(ctx, EBPF_REG_6);
> > +	uint32_t mode = BPF_MODE(op);
> > +	uint32_t opsz = BPF_SIZE(op);
> > +	uint32_t sz = bpf_size(opsz);
> > +	int16_t jump_to_epilogue;
> > +
> > +	/* r0 = mbuf (R6) */
> > +	emit_mov_64(ctx, A64_R(0), r6);
> > +
> > +	/* r1 = off: for ABS use imm, for IND use src + imm */
> > +	if (mode == BPF_ABS) {
> > +		emit_mov_imm(ctx, 1, A64_R(1), imm);
> > +	} else {
> > +		emit_mov_imm(ctx, 1, tmp2, imm);
> > +		emit_add(ctx, 1, tmp2, src);
> > +		emit_mov_64(ctx, A64_R(1), tmp2);
> > +	}
> > +
> > +	/* r2 = len */
> > +	emit_mov_imm(ctx, 1, A64_R(2), sz);
> > +
> > +	/* r3 = buf (SP) */
> > +	emit_mov_64(ctx, A64_R(3), A64_SP);
> > +
> > +	/* call __rte_pktmbuf_read */
> > +	emit_call(ctx, tmp1, __rte_pktmbuf_read);
> > +	/* check return value of __rte_pktmbuf_read */
> > +	emit_cbnz(ctx, 1, A64_R(0), 3);
> > +	emit_mov_imm(ctx, 1, r0, 0);
> > +	jump_to_epilogue = (ctx->program_start + ctx->program_sz) - ctx-
> >idx;
> > +	emit_b(ctx, jump_to_epilogue);
> 
> Could we call emit_return_zero_if_src_zero here instead?
> 
> > +
> > +	/* r0 points to the data, load 1/2/4 bytes */
> > +	emit_ldr(ctx, opsz, A64_R(0), A64_R(0), A64_ZR);
> > +	if (sz != sizeof(uint8_t))
> > +		emit_be(ctx, A64_R(0), sz * CHAR_BIT);
> > +	emit_mov_64(ctx, r0, A64_R(0));
> > +}
> > +
> 
> I would also pass final verdict on ARM code to ARM folks. To my
> untrained eye
> it looks correct apart from the signed immediate issue. Optimizations
> are
> possible, but since we're only implementing slow path for now maybe not
> worth
> the effort.

  reply	other threads:[~2026-03-18 12:54 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-10 12:20 [PATCH] bpf/arm64: support packet data load instructions Christophe Fontaine
2026-03-17  9:07 ` David Marchand
2026-03-18 11:59 ` Marat Khalili
2026-03-18 12:54   ` Morten Brørup [this message]
2026-03-18 13:07     ` Marat Khalili
2026-03-18 13:39       ` Morten Brørup
2026-03-18 15:34         ` Christophe Fontaine
2026-03-18 16:16           ` Marat Khalili
2026-03-18 16:37             ` Morten Brørup
2026-03-18 16:43               ` Marat Khalili
2026-03-18 18:10                 ` Konstantin Ananyev
2026-03-19  9:20                   ` Morten Brørup
2026-03-18 23:13     ` Stephen Hemminger
2026-03-19 11:44 ` [PATCH v2 0/2] " Christophe Fontaine
2026-03-19 11:44   ` [PATCH v2 1/2] bpf/arm64: fix offset type to allow a negative jump Christophe Fontaine
2026-03-19 11:44   ` [PATCH v2 2/2] bpf/arm64: support packet data load instructions Christophe Fontaine
2026-03-23  8:15     ` Christophe Fontaine
2026-03-23  9:26       ` Marat Khalili
2026-04-09 22:11       ` Wathsala Vithanage
2026-05-13 20:56         ` Christophe Fontaine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=98CBD80474FA8B44BF855DF32C47DC35F6579F@smartserver.smartshare.dk \
    --to=mb@smartsharesystems.com \
    --cc=cfontain@redhat.com \
    --cc=dev@dpdk.org \
    --cc=konstantin.ananyev@huawei.com \
    --cc=marat.khalili@huawei.com \
    --cc=wathsala.vithanage@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.