All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Amery Hung <ameryhung@gmail.com>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org,
	alexei.starovoitov@gmail.com, andrii@kernel.org,
	daniel@iogearbox.net, tj@kernel.org, memxor@gmail.com,
	martin.lau@kernel.org, kernel-team@meta.com
Subject: Re: [PATCH bpf-next v2 2/3] selftests/bpf: Add multi_st_ops that supports multiple instances
Date: Wed, 6 Aug 2025 16:16:57 -0700	[thread overview]
Message-ID: <3dba1e87-5087-4641-ac9b-db800cbbf994@linux.dev> (raw)
In-Reply-To: <20250806162540.681679-3-ameryhung@gmail.com>

On 8/6/25 9:25 AM, Amery Hung wrote:
> +int bpf_kfunc_multi_st_ops_test_1(struct st_ops_args *args, u32 id)
> +{
> +	struct bpf_testmod_multi_st_ops *st_ops;
> +	unsigned long flags;
> +	int ret = -1;
> +
> +	spin_lock_irqsave(&multi_st_ops_lock, flags);
> +	st_ops = multi_st_ops_find_nolock(id);
> +	if (st_ops)
> +		ret = st_ops->test_1(args);

test_1 cannot be NULL,

> +	spin_unlock_irqrestore(&multi_st_ops_lock, flags);
> +
> +	return ret;
> +}
> +
> +static int multi_st_ops_reg(void *kdata, struct bpf_link *link)
> +{
> +	struct bpf_testmod_multi_st_ops *st_ops =
> +		(struct bpf_testmod_multi_st_ops *)kdata;
> +	unsigned long flags;
> +	int err = 0;
> +	u32 id;
> +

so I added a "if (!st_ops->test_1)" test.

> +	id = bpf_struct_ops_id(kdata);
> +
> +	spin_lock_irqsave(&multi_st_ops_lock, flags);
> +	if (multi_st_ops_find_nolock(id)) {
> +		pr_err("multi_st_ops(id:%d) has already been registered\n", id);
> +		err = -EEXIST;
> +		goto unlock;
> +	}
> +
> +	st_ops->id = id;
> +	hlist_add_head(&st_ops->node, &multi_st_ops_list);
> +unlock:
> +	spin_unlock_irqrestore(&multi_st_ops_lock, flags);
> +
> +	return err;
> +}


[ ... ]

> diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h
> index c9fab51f16e2..b8001ba7c368 100644
> --- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h
> +++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h
> @@ -116,4 +116,12 @@ struct bpf_testmod_st_ops {
>   	struct module *owner;
>   };
>   
> +#define BPF_TESTMOD_NAME_SZ 16

Not sure why it is here. I don't see it is used, so removed.

  reply	other threads:[~2025-08-06 23:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-06 16:25 [PATCH bpf-next v2 0/3] Allow struct_ops to create map id to Amery Hung
2025-08-06 16:25 ` [PATCH bpf-next v2 1/3] bpf: Allow struct_ops to get map id by kdata Amery Hung
2025-08-06 16:25 ` [PATCH bpf-next v2 2/3] selftests/bpf: Add multi_st_ops that supports multiple instances Amery Hung
2025-08-06 23:16   ` Martin KaFai Lau [this message]
2025-08-06 16:25 ` [PATCH bpf-next v2 3/3] selftests/bpf: Test multi_st_ops and calling kfuncs from different programs Amery Hung
2025-08-06 23:20   ` Martin KaFai Lau
2025-08-06 23:20 ` [PATCH bpf-next v2 0/3] Allow struct_ops to create map id to 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=3dba1e87-5087-4641-ac9b-db800cbbf994@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=alexei.starovoitov@gmail.com \
    --cc=ameryhung@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@meta.com \
    --cc=martin.lau@kernel.org \
    --cc=memxor@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=tj@kernel.org \
    /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.