public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Quentin Monnet <qmo@kernel.org>
To: Simone Magnani <simone.magnani@isovalent.com>, bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org,
	yonghong.song@linux.dev, john.fastabend@gmail.com,
	kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com,
	jolsa@kernel.org, nathan@kernel.org, ndesaulniers@google.com,
	morbo@google.com, justinstitt@google.com,
	linux-kernel@vger.kernel.org, llvm@lists.linux.dev
Subject: Re: [PATCH bpf-next v2] bpftool: Probe for ISA v4 instruction set extension
Date: Mon, 9 Dec 2024 15:20:15 +0000	[thread overview]
Message-ID: <11d588c2-febe-46c4-ab49-8fb0ed80faac@kernel.org> (raw)
In-Reply-To: <20241209145439.336362-1-simone.magnani@isovalent.com>

On 09/12/2024 14:54, Simone Magnani wrote:
> This patch introduces a new probe to check whether the kernel supports
> instruction set extensions v4. The v4 extension comprises several new
> instructions: BPF_{SDIV,SMOD} (signed div and mod), BPF_{LD,LDX,ST,STX,MOV}
> (sign-extended load/store/move), 32-bit BPF_JA (unconditional jump),
> target-independent BPF_ALU64 BSWAP (byte-swapping 16/32/64). These have
> been introduced in the following commits respectively:
> 
> * ec0e2da ("bpf: Support new signed div/mod instructions.")
> * 1f9a1ea ("bpf: Support new sign-extension load insns")
> * 8100928 ("bpf: Support new sign-extension mov insns")
> * 4cd58e9 ("bpf: Support new 32bit offset jmp instruction")
> * 0845c3d ("bpf: Support new unconditional bswap instruction")
> 
> Support in bpftool for previous ISA extensions were added in commit
> 0fd800b2 ("bpftool: Probe for instruction set extensions"). These probes
> are useful for userspace BPF projects that want to use newer
> instruction set extensions on newer kernels, to reduce the programs'
> sizes or their complexity. LLVM provides the mcpu=v4 option since commit
> "[BPF] support for BPF_ST instruction in codegen"
> (https://github.com/llvm/llvm-project/commit/8f28e8069c4ba1110daee8bddc4d5049b6d4646e).
> 
> Changelog:
> 
> - v2:
>   - moved BPF_JMP32_A macro after BPF_JMP_A in filter.h for consistency
>     with include/linux/filter.h, noted by Quentin Monnet <qmo@kernel.org>
> 
> Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
> ---
>  tools/bpf/bpftool/feature.c  | 23 +++++++++++++++++++++++
>  tools/include/linux/filter.h | 10 ++++++++++
>  2 files changed, 33 insertions(+)
> 
> diff --git a/tools/bpf/bpftool/feature.c b/tools/bpf/bpftool/feature.c
> index 4dbc4fcdf473..24fecdf8e430 100644
> --- a/tools/bpf/bpftool/feature.c
> +++ b/tools/bpf/bpftool/feature.c
> @@ -885,6 +885,28 @@ probe_v3_isa_extension(const char *define_prefix, __u32 ifindex)
>  			   "V3_ISA_EXTENSION");
>  }
> 
> +/*
> + * Probe for the v4 instruction set extension introduced in commit 1f9a1ea821ff
> + * ("bpf: Support new sign-extension load insns").
> + */
> +static void
> +probe_v4_isa_extension(const char *define_prefix, __u32 ifindex)
> +{
> +	struct bpf_insn insns[5] = {
> +		BPF_MOV64_IMM(BPF_REG_0, 0),
> +		BPF_JMP32_IMM(BPF_JEQ, BPF_REG_0, 1, 1),


Looking again at the probe itself, does the second instruction serve any
practical purpose here? Don't you just need to test the BPF_JMP32_A?

Looks good otherwise, thank you!

Reviewed-by: Quentin Monnet <qmo@kernel.org>


> +		BPF_JMP32_A(1),
> +		BPF_MOV64_IMM(BPF_REG_0, 1),
> +		BPF_EXIT_INSN()
> +	};

  reply	other threads:[~2024-12-09 15:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20241209102644.29880-1-simone.magnani@isovalent.com>
2024-12-09 14:54 ` [PATCH bpf-next v2] bpftool: Probe for ISA v4 instruction set extension Simone Magnani
2024-12-09 15:20   ` Quentin Monnet [this message]
2024-12-09 17:01     ` Simone Magnani
2024-12-09 17:05       ` Quentin Monnet
2024-12-12 16:40   ` patchwork-bot+netdevbpf

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=11d588c2-febe-46c4-ab49-8fb0ed80faac@kernel.org \
    --to=qmo@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=justinstitt@google.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=martin.lau@linux.dev \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=sdf@fomichev.me \
    --cc=simone.magnani@isovalent.com \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox