BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xu Kuohai" <xukuohai@huaweicloud.com>, bpf@vger.kernel.org
Subject: Re: [RFC PATCH 3/3] selftests/bpf: Add benchmark for seccomp filter install
Date: Fri, 20 Nov 2026 07:24:42 +0000	[thread overview]
Message-ID: <sashiko-outbox-224622@kernel.org> (raw)
In-Reply-To: <23962b56d36f05c2176053d772cc9739e2e48ba5.1795139109.git.xukuohai@huaweicloud.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] selftests/bpf: seccomp insn budget undercount and overflow in
  setup()
- [Low] selftests/bpf: barrier hang on malloc() failure in producer()
--

commit e23b8e529406f7cf306411e18be355c8be76105c
Author: Xu Kuohai <xukuohai@huawei.com>

selftests/bpf: Add benchmark for seccomp filter install

This commit adds a benchmark to measure the throughput of installing
seccomp filters in batches from worker threads.

> diff --git a/tools/testing/selftests/bpf/benchs/bench_seccomp_install.c b/tools/testing/selftests/bpf/benchs/bench_seccomp_install.c
> new file mode 100644
> index 0000000000000..5044d786bdf4b
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/benchs/bench_seccomp_install.c
> @@ -0,0 +1,249 @@

[ ... ]

> +static void *producer(void *input)
> +{
> +	struct sock_filter *insns;
> +	pthread_t thread;
> +	void *ret;
> +
> +	insns = malloc(ctx.filter_len * sizeof(*insns));
> +	if (!insns) {
> +		atomic_inc(&ctx.drops.value);
> +		return NULL;
> +	}

[Severity: Low]
Can a malloc() failure in one producer thread hang the remaining workers
on ctx.barrier?

When ctx.sync is enabled, setup() initializes ctx.barrier with
env.producer_cnt threads.  If malloc() fails here, this producer exits
without spawning worker threads, so the workers created by the remaining
producers block in install_batch() at pthread_barrier_wait(&ctx.barrier)
for the rest of the benchmark run.

[ ... ]

> +static void setup(void)
> +{
> +	if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) {
> +		fprintf(stderr, "PR_SET_NO_NEW_PRIVS failed: %d\n", -errno);
> +		exit(1);
> +	}
> +
> +	if ((args.filter_len + 4) * args.batch > SECCOMP_MAX_INSNS_PER_PATH) {
> +		fprintf(stderr, "the batch exceeds the seccomp insns budget of one task\n");
> +		exit(1);
> +	}

[Severity: Low]
Does this budget check undercount the kernel's per-task seccomp
instruction calculation and risk 32-bit overflow?

bpf_convert_filter() expands the cBPF filter built by fill_filter() from
args.filter_len to args.filter_len + 4 eBPF instructions (3-insn prologue
and 2 insns for BPF_RET | BPF_K).  seccomp_attach_filter() then charges
prog->len for the new filter plus walker->prog->len + 4 for each existing
filter on the task, reaching (args.filter_len + 8) * args.batch - 4 on
the final install of a batch.  Because setup() checks
(args.filter_len + 4) * args.batch (and does so in 32-bit unsigned
arithmetic, which can wrap on large --batch values), combinations such as
--filter-len 4090 with default --batch 8 pass setup() and fail every
seccomp() call in install_batch() with ENOMEM.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795139109.git.xukuohai@huaweicloud.com?part=3

      reply	other threads:[~2026-11-20  7:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  6:48 [RFC PATCH 0/3] Introduce a classic BPF filter cache for seccomp Xu Kuohai
2026-11-20  6:48 ` [RFC PATCH 1/3] bpf: Introduce classic BPF filter cache Xu Kuohai
2026-11-20  7:31   ` sashiko-bot
2026-11-20  6:48 ` [RFC PATCH 2/3] seccomp: Use the " Xu Kuohai
2026-11-20  6:48 ` [RFC PATCH 3/3] selftests/bpf: Add benchmark for seccomp filter install Xu Kuohai
2026-11-20  7:24   ` sashiko-bot [this message]

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=sashiko-outbox-224622@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xukuohai@huaweicloud.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox