All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mahe Tardy" <mahe.tardy@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2] bpf: allow ksock connect/send calls from wq
Date: Tue, 13 Oct 2026 18:35:59 +0000	[thread overview]
Message-ID: <sashiko-outbox-170341@kernel.org> (raw)
In-Reply-To: <20261013182726.276372-1-mahe.tardy@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] selftests/bpf: u64 map key causes workqueue double-init on big-endian
--

commit 5eb6c40a460d2cca2d0dee2b208a0164f311d369
Author: Mahe Tardy <mahe.tardy@gmail.com>

bpf: allow ksock connect/send calls from wq

This commit relaxes the constraint preventing the use of ksock kfuncs from
asynchronous workqueues. It also updates the ksock_wq selftest to verify
that connect() and send() function properly when called from workqueues.

> diff --git a/tools/testing/selftests/bpf/progs/ksock_wq.c b/tools/testing/selftests/bpf/progs/ksock_wq.c
> index 16a1873d132ed..290736e219e1d 100644
> --- a/tools/testing/selftests/bpf/progs/ksock_wq.c
> +++ b/tools/testing/selftests/bpf/progs/ksock_wq.c
[ ... ]
> @@ -43,20 +73,40 @@ static int ksock_wq_callback(void *map, int *key, void *value)
>  SEC("syscall")
>  int ksock_wq_start(void *ctx)
>  {
> +	struct bpf_ksock_create_opts opts = {
> +		.family = AF_INET,
> +		.type = SOCK_DGRAM,
> +		.protocol = IPPROTO_UDP,
> +	};
>  	struct ksock_wq_value *value;
> -	u32 key = 0;
> -	int err;
> +	struct bpf_ksock *ks;
> +	u64 key = 0;
> +	int err = 0;
>  
> -	value = bpf_map_lookup_elem(&work_map, &key);
> -	if (!value)
> -		return -ENOENT;
> -	err = bpf_wq_init(&value->work, &work_map, 0);
> -	if (err)
> +	ks = bpf_ksock_create(&opts, sizeof(opts), &err);
> +	if (!ks)
>  		return err;
> -	err = bpf_wq_set_callback(&value->work, ksock_wq_callback, 0);
> +	err = ksock_ctx_insert(ks);
>  	if (err)
>  		return err;
> -	return bpf_wq_start(&value->work, 0);
> +	for (key = 0; key < 2; key++) {
> +		value = bpf_map_lookup_elem(&work_map, &key);

[Severity: Medium]
Can this cause a workqueue double-init on big-endian architectures?

The work_map map is defined with a u32 key, but the key variable here was
changed to u64. On big-endian systems, passing &key to bpf_map_lookup_elem()
will read the most significant 32 bits, which will evaluate to 0 for both
key = 0 and key = 1.

Because of this, the loop would fetch the map element for index 0 twice.
During the second iteration, bpf_wq_init() would be called on value->work
while it may already be actively queued from the first iteration. Does
re-initializing an active work_struct without serialization run the risk
of corrupting the global workqueue list and crashing?

> +		if (!value)
> +			return -ENOENT;
> +		err = bpf_wq_init(&value->work, &work_map, 0);
> +		if (err)
> +			return err;
> +		if (key)
> +			err = bpf_wq_set_callback(&value->work, ksock_wq_create, 0);
> +		else
> +			err = bpf_wq_set_callback(&value->work, ksock_wq_connect_send, 0);
> +		if (err)
> +			return err;
> +		err = bpf_wq_start(&value->work, 0);
> +		if (err)
> +			return err;
> +	}
> +	return 0;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261013182726.276372-1-mahe.tardy@gmail.com?part=1

      reply	other threads:[~2026-10-13 18:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13 18:27 [PATCH bpf-next v2] bpf: allow ksock connect/send calls from wq Mahe Tardy
2026-10-13 18:35 ` 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-170341@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=mahe.tardy@gmail.com \
    --cc=sashiko-reviews@lists.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 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.