All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bpf: Allow bpf_get_netns_cookie in BPF_PROG_TYPE_SOCK_OPS
@ 2021-08-16 10:51 Xu Liu
  2021-08-17 16:18 ` Song Liu
  0 siblings, 1 reply; 2+ messages in thread
From: Xu Liu @ 2021-08-16 10:51 UTC (permalink / raw)
  To: ast, daniel, andrii, kafai, songliubraving, yhs, john.fastabend,
	kpsingh, davem, kuba
  Cc: netdev, bpf, linux-kernel, Xu Liu

We'd like to be able to identify netns from sockops hooks
to accelerate local process communication form different netns.

Signed-off-by: Xu Liu <liuxu623@gmail.com>
---
 net/core/filter.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/net/core/filter.c b/net/core/filter.c
index d70187ce851b..34938a537931 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -4664,6 +4664,18 @@ static const struct bpf_func_proto bpf_get_netns_cookie_sock_addr_proto = {
 	.arg1_type	= ARG_PTR_TO_CTX_OR_NULL,
 };
 
+BPF_CALL_1(bpf_get_netns_cookie_sock_ops, struct bpf_sock_ops_kern *, ctx)
+{
+	return __bpf_get_netns_cookie(ctx ? ctx->sk : NULL);
+}
+
+static const struct bpf_func_proto bpf_get_netns_cookie_sock_ops_proto = {
+	.func		= bpf_get_netns_cookie_sock_ops,
+	.gpl_only	= false,
+	.ret_type	= RET_INTEGER,
+	.arg1_type	= ARG_PTR_TO_CTX_OR_NULL,
+};
+
 BPF_CALL_1(bpf_get_socket_uid, struct sk_buff *, skb)
 {
 	struct sock *sk = sk_to_full_sk(skb->sk);
@@ -7445,6 +7457,8 @@ sock_ops_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
 		return &bpf_sk_storage_get_proto;
 	case BPF_FUNC_sk_storage_delete:
 		return &bpf_sk_storage_delete_proto;
+	case BPF_FUNC_get_netns_cookie:
+		return &bpf_get_netns_cookie_sock_ops_proto;
 #ifdef CONFIG_INET
 	case BPF_FUNC_load_hdr_opt:
 		return &bpf_sock_ops_load_hdr_opt_proto;
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] bpf: Allow bpf_get_netns_cookie in BPF_PROG_TYPE_SOCK_OPS
  2021-08-16 10:51 [PATCH] bpf: Allow bpf_get_netns_cookie in BPF_PROG_TYPE_SOCK_OPS Xu Liu
@ 2021-08-17 16:18 ` Song Liu
  0 siblings, 0 replies; 2+ messages in thread
From: Song Liu @ 2021-08-17 16:18 UTC (permalink / raw)
  To: Xu Liu
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Martin Lau,
	Yonghong Song, John Fastabend, kpsingh, davem, kuba, netdev, bpf,
	linux-kernel

Hi Xu, 

> On Aug 16, 2021, at 3:51 AM, Xu Liu <liuxu623@gmail.com> wrote:
> 
> We'd like to be able to identify netns from sockops hooks
> to accelerate local process communication form different netns.
> 
> Signed-off-by: Xu Liu <liuxu623@gmail.com>

The change looks good to me. Some logistics issue:

1. Please prefix the subject based on target tree, like [PATCH bpf] or
   [PATCH bpf-next]. This change should target bpf-next. Also, please 
   include v2 (or v3, v4...) when sending the revisions of the patch. 
   So the next version of this change should be [PATCH bpf-next v2] or 
   similar. 

2. Please add a selftest (see tools/testing/selftests/bpf/) to exercise 
   this function from sock_ops

Thanks,
Song


> ---
> net/core/filter.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
> 
> diff --git a/net/core/filter.c b/net/core/filter.c
> index d70187ce851b..34938a537931 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -4664,6 +4664,18 @@ static const struct bpf_func_proto bpf_get_netns_cookie_sock_addr_proto = {
> 	.arg1_type	= ARG_PTR_TO_CTX_OR_NULL,
> };
> 
> +BPF_CALL_1(bpf_get_netns_cookie_sock_ops, struct bpf_sock_ops_kern *, ctx)
> +{
> +	return __bpf_get_netns_cookie(ctx ? ctx->sk : NULL);
> +}
> +
> +static const struct bpf_func_proto bpf_get_netns_cookie_sock_ops_proto = {
> +	.func		= bpf_get_netns_cookie_sock_ops,
> +	.gpl_only	= false,
> +	.ret_type	= RET_INTEGER,
> +	.arg1_type	= ARG_PTR_TO_CTX_OR_NULL,
> +};
> +
> BPF_CALL_1(bpf_get_socket_uid, struct sk_buff *, skb)
> {
> 	struct sock *sk = sk_to_full_sk(skb->sk);
> @@ -7445,6 +7457,8 @@ sock_ops_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
> 		return &bpf_sk_storage_get_proto;
> 	case BPF_FUNC_sk_storage_delete:
> 		return &bpf_sk_storage_delete_proto;
> +	case BPF_FUNC_get_netns_cookie:
> +		return &bpf_get_netns_cookie_sock_ops_proto;
> #ifdef CONFIG_INET
> 	case BPF_FUNC_load_hdr_opt:
> 		return &bpf_sock_ops_load_hdr_opt_proto;
> -- 
> 2.28.0
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-17 16:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-16 10:51 [PATCH] bpf: Allow bpf_get_netns_cookie in BPF_PROG_TYPE_SOCK_OPS Xu Liu
2021-08-17 16:18 ` Song Liu

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.