public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: remove check before __cgroup_bpf_run_filter_skb
@ 2024-02-08 17:50 Oliver Crumrine
  2024-02-09  0:43 ` Stanislav Fomichev
  0 siblings, 1 reply; 6+ messages in thread
From: Oliver Crumrine @ 2024-02-08 17:50 UTC (permalink / raw)
  To: ast, daniel, john.fastabend, andrii, martin.lau, song,
	yonghong.song, kpsingh, sdf, haoluo, jolsa
  Cc: bpf, linux-kernel

Checking if __sk is a full socket in macro 
BPF_CGROUP_RUN_PROG_INET_EGRESS is redundant, as the same check is 
done in function __cgroup_bpf_run_filter_skb, called as part of the 
macro.

Signed-off-by: Oliver Crumrine <ozlinuxc@gmail.com>
---
 include/linux/bpf-cgroup.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h
index a789266feac3..95b4a4715d60 100644
--- a/include/linux/bpf-cgroup.h
+++ b/include/linux/bpf-cgroup.h
@@ -208,7 +208,7 @@ static inline bool cgroup_bpf_sock_enabled(struct sock *sk,
 	int __ret = 0;							       \
 	if (cgroup_bpf_enabled(CGROUP_INET_EGRESS) && sk) {		       \
 		typeof(sk) __sk = sk_to_full_sk(sk);			       \
-		if (sk_fullsock(__sk) && __sk == skb_to_full_sk(skb) &&	       \
+		if (__sk == skb_to_full_sk(skb) &&			       \
 		    cgroup_bpf_sock_enabled(__sk, CGROUP_INET_EGRESS))	       \
 			__ret = __cgroup_bpf_run_filter_skb(__sk, skb,	       \
 						      CGROUP_INET_EGRESS); \
-- 
2.43.0


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

* Re: [PATCH] net: remove check before __cgroup_bpf_run_filter_skb
  2024-02-09  0:43 ` Stanislav Fomichev
@ 2024-02-08 21:50   ` Oliver Crumrine
  2024-02-09 19:00     ` Stanislav Fomichev
  0 siblings, 1 reply; 6+ messages in thread
From: Oliver Crumrine @ 2024-02-08 21:50 UTC (permalink / raw)
  To: Stanislav Fomichev; +Cc: bpf, linux-kernel

On Thu, Feb 08, 2024 at 04:43:06PM -0800, Stanislav Fomichev wrote:
> The check is here to make sure we only run this hook on non-req sockets.
> Dropping it would mean we'd be running the hook on the listeners
> instead. I don't think we want that.

You are correct that we don't want to run the code on listeners. However
the check for that is in the function this macro calls,
__cgroup_bpf_run_filter_skb (the check is on line 1367 of
kernel/bpf/cgroup.c, for 6.8.0-rc3). The check doesn't need to be done
twice, so it can be removed in this macro. 

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

* Re: [PATCH] net: remove check before __cgroup_bpf_run_filter_skb
  2024-02-08 17:50 [PATCH] net: remove check before __cgroup_bpf_run_filter_skb Oliver Crumrine
@ 2024-02-09  0:43 ` Stanislav Fomichev
  2024-02-08 21:50   ` Oliver Crumrine
  0 siblings, 1 reply; 6+ messages in thread
From: Stanislav Fomichev @ 2024-02-09  0:43 UTC (permalink / raw)
  To: Oliver Crumrine
  Cc: ast, daniel, john.fastabend, andrii, martin.lau, song,
	yonghong.song, kpsingh, haoluo, jolsa, bpf, linux-kernel

On 02/08, Oliver Crumrine wrote:
> Checking if __sk is a full socket in macro 
> BPF_CGROUP_RUN_PROG_INET_EGRESS is redundant, as the same check is 
> done in function __cgroup_bpf_run_filter_skb, called as part of the 
> macro.

The check is here to make sure we only run this hook on non-req sockets.
Dropping it would mean we'd be running the hook on the listeners
instead. I don't think we want that.

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

* Re: [PATCH] net: remove check before __cgroup_bpf_run_filter_skb
  2024-02-09 19:00     ` Stanislav Fomichev
@ 2024-02-09 15:36       ` Oliver Crumrine
  2024-02-09 20:33       ` Kui-Feng Lee
  1 sibling, 0 replies; 6+ messages in thread
From: Oliver Crumrine @ 2024-02-09 15:36 UTC (permalink / raw)
  To: Stanislav Fomichev; +Cc: bpf, linux-kernel

On Fri, Feb 09, 2024 at 11:00:09AM -0800, Stanislav Fomichev wrote:
> Maybe we should instead remove "(!sk || !sk_fullsock(sk))" check from
> __cgroup_bpf_run_filter_skb? BPF_CGROUP_RUN_PROG_INET_EGRESS makes
> care of all those corner conditions. We just need to add those checks to
> BPF_CGROUP_RUN_PROG_INET_INGRESS.
> 
> Let me also CC Kui-Feng, he was touching this part recently in commit
> 223f5f79f2ce ("bpf, net: Check skb ownership against full socket.").

Completely agree with this -- it would be best from a performance
standpoint. I will send out a v2 of this patch in a few hours.

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

* Re: [PATCH] net: remove check before __cgroup_bpf_run_filter_skb
  2024-02-08 21:50   ` Oliver Crumrine
@ 2024-02-09 19:00     ` Stanislav Fomichev
  2024-02-09 15:36       ` Oliver Crumrine
  2024-02-09 20:33       ` Kui-Feng Lee
  0 siblings, 2 replies; 6+ messages in thread
From: Stanislav Fomichev @ 2024-02-09 19:00 UTC (permalink / raw)
  To: Oliver Crumrine; +Cc: bpf, linux-kernel, thinker.li

On 02/08, Oliver Crumrine wrote:
> On Thu, Feb 08, 2024 at 04:43:06PM -0800, Stanislav Fomichev wrote:
> > The check is here to make sure we only run this hook on non-req sockets.
> > Dropping it would mean we'd be running the hook on the listeners
> > instead. I don't think we want that.
> 
> You are correct that we don't want to run the code on listeners. However
> the check for that is in the function this macro calls,
> __cgroup_bpf_run_filter_skb (the check is on line 1367 of
> kernel/bpf/cgroup.c, for 6.8.0-rc3). The check doesn't need to be done
> twice, so it can be removed in this macro. 

Maybe we should instead remove "(!sk || !sk_fullsock(sk))" check from
__cgroup_bpf_run_filter_skb? BPF_CGROUP_RUN_PROG_INET_EGRESS makes
care of all those corner conditions. We just need to add those checks to
BPF_CGROUP_RUN_PROG_INET_INGRESS.

Let me also CC Kui-Feng, he was touching this part recently in commit
223f5f79f2ce ("bpf, net: Check skb ownership against full socket.").

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

* Re: [PATCH] net: remove check before __cgroup_bpf_run_filter_skb
  2024-02-09 19:00     ` Stanislav Fomichev
  2024-02-09 15:36       ` Oliver Crumrine
@ 2024-02-09 20:33       ` Kui-Feng Lee
  1 sibling, 0 replies; 6+ messages in thread
From: Kui-Feng Lee @ 2024-02-09 20:33 UTC (permalink / raw)
  To: Stanislav Fomichev, Oliver Crumrine; +Cc: bpf, linux-kernel, thinker.li



On 2/9/24 11:00, Stanislav Fomichev wrote:
> On 02/08, Oliver Crumrine wrote:
>> On Thu, Feb 08, 2024 at 04:43:06PM -0800, Stanislav Fomichev wrote:
>>> The check is here to make sure we only run this hook on non-req sockets.
>>> Dropping it would mean we'd be running the hook on the listeners
>>> instead. I don't think we want that.
>>
>> You are correct that we don't want to run the code on listeners. However
>> the check for that is in the function this macro calls,
>> __cgroup_bpf_run_filter_skb (the check is on line 1367 of
>> kernel/bpf/cgroup.c, for 6.8.0-rc3). The check doesn't need to be done
>> twice, so it can be removed in this macro.
> 
> Maybe we should instead remove "(!sk || !sk_fullsock(sk))" check from
> __cgroup_bpf_run_filter_skb? BPF_CGROUP_RUN_PROG_INET_EGRESS makes
> care of all those corner conditions. We just need to add those checks to
> BPF_CGROUP_RUN_PROG_INET_INGRESS.
> 
> Let me also CC Kui-Feng, he was touching this part recently in commit
> 223f5f79f2ce ("bpf, net: Check skb ownership against full socket.").
> 

Adding those checks in BPF_CGROUP_RUN_PROG_INET_INGRESS makes sense
to me if the point here is saving CPU cycles during runtime.

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

end of thread, other threads:[~2024-02-09 20:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-08 17:50 [PATCH] net: remove check before __cgroup_bpf_run_filter_skb Oliver Crumrine
2024-02-09  0:43 ` Stanislav Fomichev
2024-02-08 21:50   ` Oliver Crumrine
2024-02-09 19:00     ` Stanislav Fomichev
2024-02-09 15:36       ` Oliver Crumrine
2024-02-09 20:33       ` Kui-Feng Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox