mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: zhangmingyi <zhangmingyi5@huawei.com>
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	song@kernel.org, yhs@fb.com, john.fastabend@gmail.com,
	kpsingh@kernel.org, sdf@google.com, haoluo@google.com,
	jolsa@kernel.org, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org, yanan@huawei.com,
	wuchangye@huawei.com, xiesongyang@huawei.com,
	liuxin350@huawei.com, liwei883@huawei.com, tianmuyang@huawei.com
Subject: Re: [PATCH 2/2] add selftest for TCP_ULP in bpf_setsockopt
Date: Wed, 29 Jan 2025 15:31:37 -0800	[thread overview]
Message-ID: <11d72466-f2b2-4133-beb8-056ebc589bc9@linux.dev> (raw)
In-Reply-To: <20250127090724.3168791-3-zhangmingyi5@huawei.com>

On 1/27/25 1:07 AM, zhangmingyi wrote:
> This case invokes bpf_setsockopt and bpf_getsockopt to set ulp.
> The existing smc_ulp_ops of the kernel is used as a test case to test
> whether the setting and get operations can be performed normally.
> 
> Signed-off-by: zhangmingyi <zhangmingyi5@huawei.com>
> ---
>   .../selftests/bpf/progs/setget_sockopt.c      | 21 ++++++++++++++++---
>   1 file changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/progs/setget_sockopt.c b/tools/testing/selftests/bpf/progs/setget_sockopt.c
> index 6dd4318debbf..dcdf26ef41c4 100644
> --- a/tools/testing/selftests/bpf/progs/setget_sockopt.c
> +++ b/tools/testing/selftests/bpf/progs/setget_sockopt.c
> @@ -327,6 +327,18 @@ static int test_tcp_maxseg(void *ctx, struct sock *sk)
>   	return 0;
>   }
>   
> +static int test_tcp_ulp(void *ctx, struct sock *sk)
> +{
> +	__u8 saved_syn[20];
> +
> +	if (sk->sk_state == TCP_SYN_SENT)
> +		return bpf_setsockopt(ctx, IPPROTO_TCP, TCP_ULP,
> +						"smc", sizeof("smc"));

The test_progs/setget_sockopt.c is using "tls" in a setsockopt(TCP_ULP) call. I 
would rather not to introduce another ulp in this selftest. Let stay with "tls".

btw, the indentation is off...

> +
> +	return bpf_getsockopt(ctx, IPPROTO_TCP, TCP_ULP,
> +			    saved_syn, sizeof(saved_syn));

same here on indentation.

Also, the getsockopt test should ensure it gets the same ulp name back (i.e. 
"tls"). Take a look at bpf_strncmp.

> +}
> +
>   static int test_tcp_saved_syn(void *ctx, struct sock *sk)
>   {
>   	__u8 saved_syn[20];
> @@ -395,16 +407,19 @@ int skops_sockopt(struct bpf_sock_ops *skops)
>   		break;
>   	case BPF_SOCK_OPS_TCP_CONNECT_CB:
>   		nr_connect += !(bpf_test_sockopt(skops, sk) ||
> -				test_tcp_maxseg(skops, sk));
> +				test_tcp_maxseg(skops, sk) ||
> +				test_tcp_ulp(skops, sk));

For other optnames, it makes sense to reuse the existing "skops_sockopt" BPF 
program. For ulp, it could change the sendmsg, recvmsg, and a few other 
behaviors. I would prefer to separate it out into its own BPF program to avoid 
future surprises on the existing tests in prog_tests/setget_sockopt.c. Keep the 
new BPF program simple, e.g. implement a new BPF program for 
"lsm_cgroup/socket_post_create" and only check for bpf_set/getsockopt(TCP_ULP).

Please tag the set for bpf-next. The "ipv4" in the patch 1's subject is not 
accurate also. afaik, ulp is not specific to ipv4.

Also, the bpf CI complains that the test cannot compile.

pw-bot: cr

>   		break;
>   	case BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB:
>   		nr_active += !(bpf_test_sockopt(skops, sk) ||
> -			       test_tcp_maxseg(skops, sk));
> +			       test_tcp_maxseg(skops, sk) ||
> +				   test_tcp_ulp(skops, sk));
>   		break;
>   	case BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB:
>   		nr_passive += !(bpf_test_sockopt(skops, sk) ||
>   				test_tcp_maxseg(skops, sk) ||
> -				test_tcp_saved_syn(skops, sk));
> +				test_tcp_saved_syn(skops, sk) ||
> +				test_tcp_ulp(skops, sk));
>   		flags = skops->bpf_sock_ops_cb_flags | BPF_SOCK_OPS_STATE_CB_FLAG;
>   		bpf_setsockopt(skops, SOL_TCP, TCP_BPF_SOCK_OPS_CB_FLAGS, &flags, sizeof(flags));
>   		break;


  reply	other threads:[~2025-01-29 23:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-27  9:07 [PATCH 0/2] ipv4, bpf: Introduced to support the ULP to get or set sockets zhangmingyi
2025-01-27  9:07 ` [PATCH 1/2] " zhangmingyi
2025-01-29 21:20   ` Martin KaFai Lau
2025-01-27  9:07 ` [PATCH 2/2] add selftest for TCP_ULP in bpf_setsockopt zhangmingyi
2025-01-29 23:31   ` Martin KaFai Lau [this message]
2025-01-29 20:58 ` [PATCH 0/2] ipv4, bpf: Introduced to support the ULP to get or set sockets Martin KaFai Lau

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=11d72466-f2b2-4133-beb8-056ebc589bc9@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liuxin350@huawei.com \
    --cc=liwei883@huawei.com \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=tianmuyang@huawei.com \
    --cc=wuchangye@huawei.com \
    --cc=xiesongyang@huawei.com \
    --cc=yanan@huawei.com \
    --cc=yhs@fb.com \
    --cc=zhangmingyi5@huawei.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

all inboxes | Powered by JetHome®