BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Hou Tao <houtao@huaweicloud.com>, bpf@vger.kernel.org
Cc: Martin KaFai Lau <martin.lau@linux.dev>,
	Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>, Song Liu <song@kernel.org>,
	Hao Luo <haoluo@google.com>,
	Yonghong Song <yonghong.song@linux.dev>,
	Daniel Borkmann <daniel@iogearbox.net>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@google.com>, Jiri Olsa <jolsa@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	 houtao1@huawei.com
Subject: Re: [PATCH bpf-next 1/3] bpf: Support inlining bpf_kptr_xchg() helper
Date: Wed, 20 Dec 2023 19:07:22 +0200	[thread overview]
Message-ID: <3ced2738d99310fdd448ecbcbf1370b6f60bc05f.camel@gmail.com> (raw)
In-Reply-To: <20231219135615.2656572-2-houtao@huaweicloud.com>

On Tue, 2023-12-19 at 21:56 +0800, Hou Tao wrote:
> From: Hou Tao <houtao1@huawei.com>
[...]
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 9456ee0ad129..7814c4f7576e 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -19668,6 +19668,23 @@ static int do_misc_fixups(struct bpf_verifier_env *env)
>  			continue;
>  		}
>  
> +		/* Implement bpf_kptr_xchg inline */
> +		if (prog->jit_requested && BITS_PER_LONG == 64 &&
> +		    insn->imm == BPF_FUNC_kptr_xchg &&
> +		    bpf_jit_supports_ptr_xchg()) {
> +			insn_buf[0] = BPF_MOV64_REG(BPF_REG_0, BPF_REG_2);
> +			insn_buf[1] = BPF_ATOMIC_OP(BPF_DW, BPF_XCHG, BPF_REG_1, BPF_REG_0, 0);
> +			cnt = 2;
> +
> +			new_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);
> +			if (!new_prog)
> +				return -ENOMEM;
> +
> +			delta    += cnt - 1;
> +			env->prog = prog = new_prog;
> +			insn      = new_prog->insnsi + i + delta;
> +			continue;
> +		}
>  patch_call_imm:
>  		fn = env->ops->get_func_proto(insn->imm, env->prog);
>  		/* all functions that have prototype and verifier allowed

Hi Hou,

I have a suggestion about testing this rewrite.
It is possible to use function get_xlated_program() from
tools/testing/selftests/bpf/prog_tests/ctx_rewrite.c,
to obtain a BPF disassembly for the program after
do_misc_fixups() are applied.

So, it shouldn't be difficult to:
- prepare a dummy program in progs/ that uses bpf_kptr_xchg();
- prepare a new test_* function in prog_tests/ that:
  - loads that dummy program;
  - queries it's disassembly using get_xlated_program();
  - compares it with expected template.

I know that do_misc_fixups() are usually not tested this way,
but that does not mean they shouldn't, wdyt?

Thanks,
Eduard

  parent reply	other threads:[~2023-12-20 17:07 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-19 13:56 [PATCH bpf-next 0/3] bpf: inline bpf_kptr_xchg() Hou Tao
2023-12-19 13:56 ` [PATCH bpf-next 1/3] bpf: Support inlining bpf_kptr_xchg() helper Hou Tao
2023-12-20 15:02   ` Daniel Borkmann
2023-12-20 17:07   ` Eduard Zingerman [this message]
2023-12-21 11:40     ` Hou Tao
2023-12-19 13:56 ` [PATCH bpf-next 2/3] bpf, x86: Don't generate lock prefix for BPF_XCHG Hou Tao
2023-12-20 14:58   ` Daniel Borkmann
2023-12-20 18:25     ` Alexei Starovoitov
2023-12-20 18:46       ` Daniel Borkmann
2023-12-21 11:37         ` Hou Tao
2023-12-23  4:01           ` Hou Tao
2023-12-19 13:56 ` [PATCH bpf-next 3/3] bpf, x86: Inline bpf_kptr_xchg() on x86-64 Hou Tao
2023-12-20 14:54 ` [PATCH bpf-next 0/3] bpf: inline bpf_kptr_xchg() Daniel Borkmann
2023-12-21 11:32   ` Hou Tao

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=3ced2738d99310fdd448ecbcbf1370b6f60bc05f.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=houtao1@huawei.com \
    --cc=houtao@huaweicloud.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@google.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