diff mbox series

[bpf,1/2] net: introduce __sk_rmem_schedule() helper

Message ID 20230726142029.2867663-2-liujian56@huawei.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series fix rmem incorrect accounting in bpf_tcp_ingress() | expand

Checks

Context Check Description
bpf/vmtest-bpf-PR success PR summary
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for bpf, async
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 3844 this patch: 3844
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 1899 this patch: 1899
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 4018 this patch: 4018
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 24 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-VM_Test-8 success Logs for veristat
bpf/vmtest-bpf-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-VM_Test-6 success Logs for set-matrix
bpf/vmtest-bpf-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-VM_Test-4 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-VM_Test-5 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-3 success Logs for build for s390x with gcc
bpf/vmtest-bpf-VM_Test-7 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-19 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-22 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-25 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-9 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-11 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-13 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-15 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-17 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-20 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-21 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-24 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-27 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-28 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-29 success Logs for veristat
bpf/vmtest-bpf-VM_Test-10 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-14 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-18 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-23 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-26 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-VM_Test-16 fail Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-VM_Test-12 success Logs for test_progs on s390x with gcc

Commit Message

liujian (CE) July 26, 2023, 2:20 p.m. UTC
Compared with sk_wmem_schedule(), sk_rmem_schedule() not only performs
rmem accounting, but also checks skb_pfmemalloc. The __sk_rmem_schedule()
helper function is introduced here to perform only rmem accounting related
activities.

Signed-off-by: Liu Jian <liujian56@huawei.com>
---
 include/net/sock.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

Eric Dumazet July 26, 2023, 2:25 p.m. UTC | #1
On Wed, Jul 26, 2023 at 4:15 PM Liu Jian <liujian56@huawei.com> wrote:
>
> Compared with sk_wmem_schedule(), sk_rmem_schedule() not only performs
> rmem accounting, but also checks skb_pfmemalloc. The __sk_rmem_schedule()
> helper function is introduced here to perform only rmem accounting related
> activities.
>

Why not care about pfmemalloc ? Why is it safe ?

You need to give more details, or simply reuse the existing helper.

> Signed-off-by: Liu Jian <liujian56@huawei.com>
> ---
>  include/net/sock.h | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/include/net/sock.h b/include/net/sock.h
> index 2eb916d1ff64..58bf26c5c041 100644
> --- a/include/net/sock.h
> +++ b/include/net/sock.h
> @@ -1617,16 +1617,20 @@ static inline bool sk_wmem_schedule(struct sock *sk, int size)
>         return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_SEND);
>  }
>
> -static inline bool
> -sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size)
> +static inline bool __sk_rmem_schedule(struct sock *sk, int size)
>  {
>         int delta;
>
>         if (!sk_has_account(sk))
>                 return true;
>         delta = size - sk->sk_forward_alloc;
> -       return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_RECV) ||
> -               skb_pfmemalloc(skb);
> +       return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_RECV);
> +}
> +
> +static inline bool
> +sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size)
> +{
> +       return __sk_rmem_schedule(sk, size) || skb_pfmemalloc(skb);
>  }
>
>  static inline int sk_unused_reserved_mem(const struct sock *sk)
> --
> 2.34.1
>
John Fastabend July 27, 2023, 7:16 p.m. UTC | #2
Eric Dumazet wrote:
> On Wed, Jul 26, 2023 at 4:15 PM Liu Jian <liujian56@huawei.com> wrote:
> >
> > Compared with sk_wmem_schedule(), sk_rmem_schedule() not only performs
> > rmem accounting, but also checks skb_pfmemalloc. The __sk_rmem_schedule()
> > helper function is introduced here to perform only rmem accounting related
> > activities.
> >
> 
> Why not care about pfmemalloc ? Why is it safe ?
> 
> You need to give more details, or simply reuse the existing helper.

I would just use the existing helper. Seems it should be fine.

> 
> > Signed-off-by: Liu Jian <liujian56@huawei.com>
> > ---
> >  include/net/sock.h | 12 ++++++++----
> >  1 file changed, 8 insertions(+), 4 deletions(-)
> >
> > diff --git a/include/net/sock.h b/include/net/sock.h
> > index 2eb916d1ff64..58bf26c5c041 100644
> > --- a/include/net/sock.h
> > +++ b/include/net/sock.h
> > @@ -1617,16 +1617,20 @@ static inline bool sk_wmem_schedule(struct sock *sk, int size)
> >         return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_SEND);
> >  }
> >
> > -static inline bool
> > -sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size)
> > +static inline bool __sk_rmem_schedule(struct sock *sk, int size)
> >  {
> >         int delta;
> >
> >         if (!sk_has_account(sk))
> >                 return true;
> >         delta = size - sk->sk_forward_alloc;
> > -       return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_RECV) ||
> > -               skb_pfmemalloc(skb);
> > +       return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_RECV);
> > +}
> > +
> > +static inline bool
> > +sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size)
> > +{
> > +       return __sk_rmem_schedule(sk, size) || skb_pfmemalloc(skb);
> >  }
> >
> >  static inline int sk_unused_reserved_mem(const struct sock *sk)
> > --
> > 2.34.1
> >
liujian (CE) July 28, 2023, 12:36 p.m. UTC | #3
On 2023/7/28 3:16, John Fastabend wrote:
> Eric Dumazet wrote:
>> On Wed, Jul 26, 2023 at 4:15 PM Liu Jian <liujian56@huawei.com> wrote:
>>>
>>> Compared with sk_wmem_schedule(), sk_rmem_schedule() not only performs
>>> rmem accounting, but also checks skb_pfmemalloc. The __sk_rmem_schedule()
>>> helper function is introduced here to perform only rmem accounting related
>>> activities.
>>>
>>
>> Why not care about pfmemalloc ? Why is it safe ?
>>
>> You need to give more details, or simply reuse the existing helper.
I didn't think so much. I extracted this helper just to do rmem 
accounting in bpf_tcp_ingress(), because I didn't see the pfmemalloc 
flag set when alloc sk_msg in sk_msg_alloc(). And thanks for your review.
> 
> I would just use the existing helper. Seems it should be fine.
ok, let's just leave it as it is. Thanks John.
> 
>>
>>> Signed-off-by: Liu Jian <liujian56@huawei.com>
>>> ---
>>>   include/net/sock.h | 12 ++++++++----
>>>   1 file changed, 8 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/include/net/sock.h b/include/net/sock.h
>>> index 2eb916d1ff64..58bf26c5c041 100644
>>> --- a/include/net/sock.h
>>> +++ b/include/net/sock.h
>>> @@ -1617,16 +1617,20 @@ static inline bool sk_wmem_schedule(struct sock *sk, int size)
>>>          return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_SEND);
>>>   }
>>>
>>> -static inline bool
>>> -sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size)
>>> +static inline bool __sk_rmem_schedule(struct sock *sk, int size)
>>>   {
>>>          int delta;
>>>
>>>          if (!sk_has_account(sk))
>>>                  return true;
>>>          delta = size - sk->sk_forward_alloc;
>>> -       return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_RECV) ||
>>> -               skb_pfmemalloc(skb);
>>> +       return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_RECV);
>>> +}
>>> +
>>> +static inline bool
>>> +sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size)
>>> +{
>>> +       return __sk_rmem_schedule(sk, size) || skb_pfmemalloc(skb);
>>>   }
>>>
>>>   static inline int sk_unused_reserved_mem(const struct sock *sk)
>>> --
>>> 2.34.1
>>>
> 
>
diff mbox series

Patch

diff --git a/include/net/sock.h b/include/net/sock.h
index 2eb916d1ff64..58bf26c5c041 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1617,16 +1617,20 @@  static inline bool sk_wmem_schedule(struct sock *sk, int size)
 	return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_SEND);
 }
 
-static inline bool
-sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size)
+static inline bool __sk_rmem_schedule(struct sock *sk, int size)
 {
 	int delta;
 
 	if (!sk_has_account(sk))
 		return true;
 	delta = size - sk->sk_forward_alloc;
-	return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_RECV) ||
-		skb_pfmemalloc(skb);
+	return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_RECV);
+}
+
+static inline bool
+sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size)
+{
+	return __sk_rmem_schedule(sk, size) || skb_pfmemalloc(skb);
 }
 
 static inline int sk_unused_reserved_mem(const struct sock *sk)