bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* pull-request: bpf 2022-03-29
@ 2022-03-29 23:49 Alexei Starovoitov
  2022-03-30  1:41 ` Jakub Kicinski
  2022-03-30  4:10 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 13+ messages in thread
From: Alexei Starovoitov @ 2022-03-29 23:49 UTC (permalink / raw)
  To: davem; +Cc: daniel, peterz, mhiramat, kuba, andrii, netdev, bpf, kernel-team

Hi David, hi Jakub,

The following pull-request contains BPF updates for your *net* tree.

We've added 16 non-merge commits during the last 1 day(s) which contain
a total of 24 files changed, 354 insertions(+), 187 deletions(-).

The main changes are:

1) x86 specific bits of fprobe/rethook, from Masami and Peter.

2) ice/xsk fixes, from Maciej and Magnus.

3) Various small fixes, from Andrii, Yonghong, Geliang and others.

Please consider pulling these changes from:

  git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git

Thanks a lot!

Also thanks to reporters, reviewers and testers of commits in this pull-request:

Arnaldo Carvalho de Melo, Dan Carpenter, Jiri Olsa, kernel test robot, 
KP Singh, Martin KaFai Lau, Masami Hiramatsu, Quentin Monnet, Yonghong 
Song

----------------------------------------------------------------

The following changes since commit d717e4cae0fe77e10a27e8545a967b8c379873ac:

  Merge tag 'net-5.18-rc0' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net (2022-03-28 17:02:04 -0700)

are available in the Git repository at:

  https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git 

for you to fetch changes up to ccaff3d56acc47c257a99b2807b7c78a9467cf09:

  selftests/bpf: Fix clang compilation errors (2022-03-28 20:00:11 -0700)

----------------------------------------------------------------
Alexei Starovoitov (3):
      Merge branch 'fprobe: Fixes for Sparse and Smatch warnings'
      Merge branch 'kprobes: rethook: x86: Replace kretprobe trampoline with rethook'
      Merge branch 'xsk: another round of fixes'

Andrii Nakryiko (1):
      selftests/bpf: fix selftest after random: Urandom_read tracepoint removal

Geliang Tang (1):
      bpf: Sync comments for bpf_get_stack

Jiri Olsa (1):
      bpftool: Fix generated code in codegen_asserts

Maciej Fijalkowski (2):
      ice: xsk: Stop Rx processing when ntc catches ntu
      ice: xsk: Fix indexing in ice_tx_xsk_pool()

Magnus Karlsson (2):
      xsk: Do not write NULL in SW ring at allocation failure
      ice: xsk: Eliminate unnecessary loop iteration

Masami Hiramatsu (5):
      fprobe: Fix smatch type mismatch warning
      fprobe: Fix sparse warning for acccessing __rcu ftrace_hash
      kprobes: Use rethook for kretprobe if possible
      x86,rethook,kprobes: Replace kretprobe with rethook on x86
      x86,kprobes: Fix optprobe trampoline to generate complete pt_regs

Milan Landaverde (1):
      bpf/bpftool: Add unprivileged_bpf_disabled check against value of 2

Peter Zijlstra (1):
      x86,rethook: Fix arch_rethook_trampoline() to generate a complete pt_regs

Yonghong Song (1):
      selftests/bpf: Fix clang compilation errors

Yuntao Wang (1):
      bpf: Fix maximum permitted number of arguments check

 arch/Kconfig                                       |   8 +-
 arch/x86/Kconfig                                   |   1 +
 arch/x86/include/asm/unwind.h                      |  23 ++--
 arch/x86/kernel/Makefile                           |   1 +
 arch/x86/kernel/kprobes/common.h                   |   1 +
 arch/x86/kernel/kprobes/core.c                     | 107 -----------------
 arch/x86/kernel/kprobes/opt.c                      |  25 ++--
 arch/x86/kernel/rethook.c                          | 127 +++++++++++++++++++++
 arch/x86/kernel/unwind_orc.c                       |  10 +-
 drivers/net/ethernet/intel/ice/ice.h               |   2 +-
 drivers/net/ethernet/intel/ice/ice_xsk.c           |   5 +-
 include/linux/kprobes.h                            |  51 ++++++++-
 kernel/Makefile                                    |   1 +
 kernel/bpf/btf.c                                   |   2 +-
 kernel/kprobes.c                                   | 124 ++++++++++++++++----
 kernel/trace/fprobe.c                              |   8 +-
 kernel/trace/trace_kprobe.c                        |   4 +-
 net/xdp/xsk_buff_pool.c                            |   8 +-
 tools/bpf/bpftool/feature.c                        |   5 +-
 tools/bpf/bpftool/gen.c                            |   2 +-
 tools/include/uapi/linux/bpf.h                     |   8 +-
 .../selftests/bpf/prog_tests/get_stack_raw_tp.c    |   3 -
 .../selftests/bpf/progs/test_stacktrace_build_id.c |  12 +-
 tools/testing/selftests/bpf/test_lpm_map.c         |   3 +-
 24 files changed, 354 insertions(+), 187 deletions(-)
 create mode 100644 arch/x86/kernel/rethook.c

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

* Re: pull-request: bpf 2022-03-29
  2022-03-29 23:49 pull-request: bpf 2022-03-29 Alexei Starovoitov
@ 2022-03-30  1:41 ` Jakub Kicinski
  2022-03-30  1:51   ` Alexei Starovoitov
  2022-03-30  4:10 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 13+ messages in thread
From: Jakub Kicinski @ 2022-03-30  1:41 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: davem, daniel, peterz, mhiramat, andrii, netdev, bpf, kernel-team

On Tue, 29 Mar 2022 16:49:24 -0700 Alexei Starovoitov wrote:
> Hi David, hi Jakub,
> 
> The following pull-request contains BPF updates for your *net* tree.
> 
> We've added 16 non-merge commits during the last 1 day(s) which contain
> a total of 24 files changed, 354 insertions(+), 187 deletions(-).
> 
> The main changes are:
> 
> 1) x86 specific bits of fprobe/rethook, from Masami and Peter.
> 
> 2) ice/xsk fixes, from Maciej and Magnus.
> 
> 3) Various small fixes, from Andrii, Yonghong, Geliang and others.

There are some new sparse warnings here that look semi-legit.
As in harmless but not erroneous.

kernel/trace/rethook.c:68:9: error: incompatible types in comparison expression (different address spaces):
kernel/trace/rethook.c:68:9:    void ( [noderef] __rcu * )( ... )
kernel/trace/rethook.c:68:9:    void ( * )( ... )

66 void rethook_free(struct rethook *rh)
67 {
68         rcu_assign_pointer(rh->handler, NULL);
69 
70         call_rcu(&rh->rcu, rethook_free_rcu);
71 }

Looks like this should be a WRITE_ONCE() ?

And the __user annotations in bpf_trace.c are still not right,
first arg of kprobe_multi_resolve_syms() should __user:

kernel/trace/bpf_trace.c:2370:34: warning: incorrect type in argument 2 (different address spaces)
kernel/trace/bpf_trace.c:2370:34:    expected void const [noderef] __user *from
kernel/trace/bpf_trace.c:2370:34:    got void const *usyms
kernel/trace/bpf_trace.c:2376:51: warning: incorrect type in argument 2 (different address spaces)
kernel/trace/bpf_trace.c:2376:51:    expected char const [noderef] __user *src
kernel/trace/bpf_trace.c:2376:51:    got char const *
kernel/trace/bpf_trace.c:2443:49: warning: incorrect type in argument 1 (different address spaces)
kernel/trace/bpf_trace.c:2443:49:    expected void const *usyms
kernel/trace/bpf_trace.c:2443:49:    got void [noderef] __user *[assigned] usyms

How do you wanna proceed?

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

* Re: pull-request: bpf 2022-03-29
  2022-03-30  1:41 ` Jakub Kicinski
@ 2022-03-30  1:51   ` Alexei Starovoitov
  2022-03-30  2:02     ` Jakub Kicinski
                       ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Alexei Starovoitov @ 2022-03-30  1:51 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Daniel Borkmann, Peter Zijlstra,
	Masami Hiramatsu, Andrii Nakryiko, Network Development, bpf,
	Kernel Team

On Tue, Mar 29, 2022 at 6:41 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Tue, 29 Mar 2022 16:49:24 -0700 Alexei Starovoitov wrote:
> > Hi David, hi Jakub,
> >
> > The following pull-request contains BPF updates for your *net* tree.
> >
> > We've added 16 non-merge commits during the last 1 day(s) which contain
> > a total of 24 files changed, 354 insertions(+), 187 deletions(-).
> >
> > The main changes are:
> >
> > 1) x86 specific bits of fprobe/rethook, from Masami and Peter.
> >
> > 2) ice/xsk fixes, from Maciej and Magnus.
> >
> > 3) Various small fixes, from Andrii, Yonghong, Geliang and others.
>
> There are some new sparse warnings here that look semi-legit.
> As in harmless but not erroneous.

Both are new warnings and not due to these patches, right?

> kernel/trace/rethook.c:68:9: error: incompatible types in comparison expression (different address spaces):
> kernel/trace/rethook.c:68:9:    void ( [noderef] __rcu * )( ... )
> kernel/trace/rethook.c:68:9:    void ( * )( ... )
>
> 66 void rethook_free(struct rethook *rh)
> 67 {
> 68         rcu_assign_pointer(rh->handler, NULL);
> 69
> 70         call_rcu(&rh->rcu, rethook_free_rcu);
> 71 }
>
> Looks like this should be a WRITE_ONCE() ?

Masami, please take a look.

> And the __user annotations in bpf_trace.c are still not right,
> first arg of kprobe_multi_resolve_syms() should __user:
>
> kernel/trace/bpf_trace.c:2370:34: warning: incorrect type in argument 2 (different address spaces)
> kernel/trace/bpf_trace.c:2370:34:    expected void const [noderef] __user *from
> kernel/trace/bpf_trace.c:2370:34:    got void const *usyms
> kernel/trace/bpf_trace.c:2376:51: warning: incorrect type in argument 2 (different address spaces)
> kernel/trace/bpf_trace.c:2376:51:    expected char const [noderef] __user *src
> kernel/trace/bpf_trace.c:2376:51:    got char const *
> kernel/trace/bpf_trace.c:2443:49: warning: incorrect type in argument 1 (different address spaces)
> kernel/trace/bpf_trace.c:2443:49:    expected void const *usyms
> kernel/trace/bpf_trace.c:2443:49:    got void [noderef] __user *[assigned] usyms

This one is known. Still waiting for the fix from Jiri.

> How do you wanna proceed?

If they both are old I would proceed.
I don't consider sparse warnings as a blocker in general.

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

* Re: pull-request: bpf 2022-03-29
  2022-03-30  1:51   ` Alexei Starovoitov
@ 2022-03-30  2:02     ` Jakub Kicinski
  2022-03-30  4:52     ` Masami Hiramatsu
  2022-03-30  8:05     ` Jiri Olsa
  2 siblings, 0 replies; 13+ messages in thread
From: Jakub Kicinski @ 2022-03-30  2:02 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: David S. Miller, Daniel Borkmann, Peter Zijlstra,
	Masami Hiramatsu, Andrii Nakryiko, Network Development, bpf,
	Kernel Team

On Tue, 29 Mar 2022 18:51:22 -0700 Alexei Starovoitov wrote:
> On Tue, Mar 29, 2022 at 6:41 PM Jakub Kicinski <kuba@kernel.org> wrote:
> > On Tue, 29 Mar 2022 16:49:24 -0700 Alexei Starovoitov wrote:  
> > > Hi David, hi Jakub,
> > >
> > > The following pull-request contains BPF updates for your *net* tree.
> > >
> > > We've added 16 non-merge commits during the last 1 day(s) which contain
> > > a total of 24 files changed, 354 insertions(+), 187 deletions(-).
> > >
> > > The main changes are:
> > >
> > > 1) x86 specific bits of fprobe/rethook, from Masami and Peter.
> > >
> > > 2) ice/xsk fixes, from Maciej and Magnus.
> > >
> > > 3) Various small fixes, from Andrii, Yonghong, Geliang and others.  
> >
> > There are some new sparse warnings here that look semi-legit.
> > As in harmless but not erroneous.  
> 
> Both are new warnings and not due to these patches, right?

Erm, you're right. No idea how the build bot can generate a warning
that's present on both source and target branch :S I'll look into 
that while the my local build runs...

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

* Re: pull-request: bpf 2022-03-29
  2022-03-29 23:49 pull-request: bpf 2022-03-29 Alexei Starovoitov
  2022-03-30  1:41 ` Jakub Kicinski
@ 2022-03-30  4:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 13+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-03-30  4:10 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: davem, daniel, peterz, mhiramat, kuba, andrii, netdev, bpf, kernel-team

Hello:

This pull request was applied to bpf/bpf.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 29 Mar 2022 16:49:24 -0700 you wrote:
> Hi David, hi Jakub,
> 
> The following pull-request contains BPF updates for your *net* tree.
> 
> We've added 16 non-merge commits during the last 1 day(s) which contain
> a total of 24 files changed, 354 insertions(+), 187 deletions(-).
> 
> [...]

Here is the summary with links:
  - pull-request: bpf 2022-03-29
    https://git.kernel.org/bpf/bpf/c/77c9387c0c5b

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

* Re: pull-request: bpf 2022-03-29
  2022-03-30  1:51   ` Alexei Starovoitov
  2022-03-30  2:02     ` Jakub Kicinski
@ 2022-03-30  4:52     ` Masami Hiramatsu
  2022-03-30  9:15       ` Masami Hiramatsu
  2022-03-30  8:05     ` Jiri Olsa
  2 siblings, 1 reply; 13+ messages in thread
From: Masami Hiramatsu @ 2022-03-30  4:52 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Jakub Kicinski, David S. Miller, Daniel Borkmann, Peter Zijlstra,
	Masami Hiramatsu, Andrii Nakryiko, Network Development, bpf,
	Kernel Team

On Tue, 29 Mar 2022 18:51:22 -0700
Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:

> On Tue, Mar 29, 2022 at 6:41 PM Jakub Kicinski <kuba@kernel.org> wrote:
> >
> > On Tue, 29 Mar 2022 16:49:24 -0700 Alexei Starovoitov wrote:
> > > Hi David, hi Jakub,
> > >
> > > The following pull-request contains BPF updates for your *net* tree.
> > >
> > > We've added 16 non-merge commits during the last 1 day(s) which contain
> > > a total of 24 files changed, 354 insertions(+), 187 deletions(-).
> > >
> > > The main changes are:
> > >
> > > 1) x86 specific bits of fprobe/rethook, from Masami and Peter.
> > >
> > > 2) ice/xsk fixes, from Maciej and Magnus.
> > >
> > > 3) Various small fixes, from Andrii, Yonghong, Geliang and others.
> >
> > There are some new sparse warnings here that look semi-legit.
> > As in harmless but not erroneous.
> 
> Both are new warnings and not due to these patches, right?
> 
> > kernel/trace/rethook.c:68:9: error: incompatible types in comparison expression (different address spaces):
> > kernel/trace/rethook.c:68:9:    void ( [noderef] __rcu * )( ... )
> > kernel/trace/rethook.c:68:9:    void ( * )( ... )
> >
> > 66 void rethook_free(struct rethook *rh)
> > 67 {
> > 68         rcu_assign_pointer(rh->handler, NULL);
> > 69
> > 70         call_rcu(&rh->rcu, rethook_free_rcu);
> > 71 }
> >
> > Looks like this should be a WRITE_ONCE() ?
> 
> Masami, please take a look.

Yeah, I think we should make this rcu pointer (and read side must use rcu_dereference())
because this rh->handler becomes the key to disable this rethook.
Let me fix that.

Thanks,

-- 
Masami Hiramatsu <mhiramat@kernel.org>

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

* Re: pull-request: bpf 2022-03-29
  2022-03-30  1:51   ` Alexei Starovoitov
  2022-03-30  2:02     ` Jakub Kicinski
  2022-03-30  4:52     ` Masami Hiramatsu
@ 2022-03-30  8:05     ` Jiri Olsa
  2022-03-30 11:01       ` Jiri Olsa
  2 siblings, 1 reply; 13+ messages in thread
From: Jiri Olsa @ 2022-03-30  8:05 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Jakub Kicinski, David S. Miller, Daniel Borkmann, Peter Zijlstra,
	Masami Hiramatsu, Andrii Nakryiko, Network Development, bpf,
	Kernel Team

On Tue, Mar 29, 2022 at 06:51:22PM -0700, Alexei Starovoitov wrote:
> On Tue, Mar 29, 2022 at 6:41 PM Jakub Kicinski <kuba@kernel.org> wrote:
> >
> > On Tue, 29 Mar 2022 16:49:24 -0700 Alexei Starovoitov wrote:
> > > Hi David, hi Jakub,
> > >
> > > The following pull-request contains BPF updates for your *net* tree.
> > >
> > > We've added 16 non-merge commits during the last 1 day(s) which contain
> > > a total of 24 files changed, 354 insertions(+), 187 deletions(-).
> > >
> > > The main changes are:
> > >
> > > 1) x86 specific bits of fprobe/rethook, from Masami and Peter.
> > >
> > > 2) ice/xsk fixes, from Maciej and Magnus.
> > >
> > > 3) Various small fixes, from Andrii, Yonghong, Geliang and others.
> >
> > There are some new sparse warnings here that look semi-legit.
> > As in harmless but not erroneous.
> 
> Both are new warnings and not due to these patches, right?
> 
> > kernel/trace/rethook.c:68:9: error: incompatible types in comparison expression (different address spaces):
> > kernel/trace/rethook.c:68:9:    void ( [noderef] __rcu * )( ... )
> > kernel/trace/rethook.c:68:9:    void ( * )( ... )
> >
> > 66 void rethook_free(struct rethook *rh)
> > 67 {
> > 68         rcu_assign_pointer(rh->handler, NULL);
> > 69
> > 70         call_rcu(&rh->rcu, rethook_free_rcu);
> > 71 }
> >
> > Looks like this should be a WRITE_ONCE() ?
> 
> Masami, please take a look.
> 
> > And the __user annotations in bpf_trace.c are still not right,
> > first arg of kprobe_multi_resolve_syms() should __user:
> >
> > kernel/trace/bpf_trace.c:2370:34: warning: incorrect type in argument 2 (different address spaces)
> > kernel/trace/bpf_trace.c:2370:34:    expected void const [noderef] __user *from
> > kernel/trace/bpf_trace.c:2370:34:    got void const *usyms
> > kernel/trace/bpf_trace.c:2376:51: warning: incorrect type in argument 2 (different address spaces)
> > kernel/trace/bpf_trace.c:2376:51:    expected char const [noderef] __user *src
> > kernel/trace/bpf_trace.c:2376:51:    got char const *
> > kernel/trace/bpf_trace.c:2443:49: warning: incorrect type in argument 1 (different address spaces)
> > kernel/trace/bpf_trace.c:2443:49:    expected void const *usyms
> > kernel/trace/bpf_trace.c:2443:49:    got void [noderef] __user *[assigned] usyms
> 
> This one is known. Still waiting for the fix from Jiri.

right, I replied that for some reason I can't see these warnings
with 'make C=2' and latest sparse.. how do you run that?

if patch below fixes it for you, I can send formal patch quickly

jirka


---
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index d8553f46caa2..7fa2ebc07f60 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2349,11 +2349,11 @@ kprobe_multi_link_handler(struct fprobe *fp, unsigned long entry_ip,
 }
 
 static int
-kprobe_multi_resolve_syms(const void __user *usyms, u32 cnt,
+kprobe_multi_resolve_syms(const void *usyms, u32 cnt,
 			  unsigned long *addrs)
 {
 	unsigned long addr, size;
-	const char __user **syms;
+	const char **syms;
 	int err = -ENOMEM;
 	unsigned int i;
 	char *func;

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

* Re: pull-request: bpf 2022-03-29
  2022-03-30  4:52     ` Masami Hiramatsu
@ 2022-03-30  9:15       ` Masami Hiramatsu
  2022-03-30 15:09         ` Alexei Starovoitov
  0 siblings, 1 reply; 13+ messages in thread
From: Masami Hiramatsu @ 2022-03-30  9:15 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Alexei Starovoitov, Jakub Kicinski, David S. Miller,
	Daniel Borkmann, Peter Zijlstra, Andrii Nakryiko,
	Network Development, bpf, Kernel Team

On Wed, 30 Mar 2022 13:52:17 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> On Tue, 29 Mar 2022 18:51:22 -0700
> Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:
> 
> > On Tue, Mar 29, 2022 at 6:41 PM Jakub Kicinski <kuba@kernel.org> wrote:
> > >
> > > On Tue, 29 Mar 2022 16:49:24 -0700 Alexei Starovoitov wrote:
> > > > Hi David, hi Jakub,
> > > >
> > > > The following pull-request contains BPF updates for your *net* tree.
> > > >
> > > > We've added 16 non-merge commits during the last 1 day(s) which contain
> > > > a total of 24 files changed, 354 insertions(+), 187 deletions(-).
> > > >
> > > > The main changes are:
> > > >
> > > > 1) x86 specific bits of fprobe/rethook, from Masami and Peter.
> > > >
> > > > 2) ice/xsk fixes, from Maciej and Magnus.
> > > >
> > > > 3) Various small fixes, from Andrii, Yonghong, Geliang and others.
> > >
> > > There are some new sparse warnings here that look semi-legit.
> > > As in harmless but not erroneous.
> > 
> > Both are new warnings and not due to these patches, right?
> > 
> > > kernel/trace/rethook.c:68:9: error: incompatible types in comparison expression (different address spaces):
> > > kernel/trace/rethook.c:68:9:    void ( [noderef] __rcu * )( ... )
> > > kernel/trace/rethook.c:68:9:    void ( * )( ... )
> > >
> > > 66 void rethook_free(struct rethook *rh)
> > > 67 {
> > > 68         rcu_assign_pointer(rh->handler, NULL);
> > > 69
> > > 70         call_rcu(&rh->rcu, rethook_free_rcu);
> > > 71 }
> > >
> > > Looks like this should be a WRITE_ONCE() ?
> > 
> > Masami, please take a look.
> 
> Yeah, I think we should make this rcu pointer (and read side must use rcu_dereference())
> because this rh->handler becomes the key to disable this rethook.
> Let me fix that.

Sorry, please ignore this. Since the handler pointed by rh->handler never
be removed (unless removed by modules, but this will not happen while
the rethook is running), YES, WRITE_ONCE() is enough.
Please add below.

From 92c9c784458f03900823360981812220ce3c7bf3 Mon Sep 17 00:00:00 2001
From: Masami Hiramatsu <mhiramat@kernel.org>
Date: Wed, 30 Mar 2022 18:13:42 +0900
Subject: [PATCH] rethook: Fix to use WRITE_ONCE() for rethook::handler

Since the function pointered by rethook::handler never be removed when
the rethook is alive, it doesn't need to use rcu_assign_pointer() to
update it. Just use WRITE_ONCE().

Reported-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/trace/rethook.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c
index ab463a4d2b23..b56833700d23 100644
--- a/kernel/trace/rethook.c
+++ b/kernel/trace/rethook.c
@@ -65,7 +65,7 @@ static void rethook_free_rcu(struct rcu_head *head)
  */
 void rethook_free(struct rethook *rh)
 {
-	rcu_assign_pointer(rh->handler, NULL);
+	WRITE_ONCE(rh->handler, NULL);
 
 	call_rcu(&rh->rcu, rethook_free_rcu);
 }
-- 
2.25.1
-- 
Masami Hiramatsu <mhiramat@kernel.org>

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

* Re: pull-request: bpf 2022-03-29
  2022-03-30  8:05     ` Jiri Olsa
@ 2022-03-30 11:01       ` Jiri Olsa
  0 siblings, 0 replies; 13+ messages in thread
From: Jiri Olsa @ 2022-03-30 11:01 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Jakub Kicinski, David S. Miller, Daniel Borkmann, Peter Zijlstra,
	Masami Hiramatsu, Andrii Nakryiko, Network Development, bpf,
	Kernel Team

On Wed, Mar 30, 2022 at 10:05:34AM +0200, Jiri Olsa wrote:
> On Tue, Mar 29, 2022 at 06:51:22PM -0700, Alexei Starovoitov wrote:
> > On Tue, Mar 29, 2022 at 6:41 PM Jakub Kicinski <kuba@kernel.org> wrote:
> > >
> > > On Tue, 29 Mar 2022 16:49:24 -0700 Alexei Starovoitov wrote:
> > > > Hi David, hi Jakub,
> > > >
> > > > The following pull-request contains BPF updates for your *net* tree.
> > > >
> > > > We've added 16 non-merge commits during the last 1 day(s) which contain
> > > > a total of 24 files changed, 354 insertions(+), 187 deletions(-).
> > > >
> > > > The main changes are:
> > > >
> > > > 1) x86 specific bits of fprobe/rethook, from Masami and Peter.
> > > >
> > > > 2) ice/xsk fixes, from Maciej and Magnus.
> > > >
> > > > 3) Various small fixes, from Andrii, Yonghong, Geliang and others.
> > >
> > > There are some new sparse warnings here that look semi-legit.
> > > As in harmless but not erroneous.
> > 
> > Both are new warnings and not due to these patches, right?
> > 
> > > kernel/trace/rethook.c:68:9: error: incompatible types in comparison expression (different address spaces):
> > > kernel/trace/rethook.c:68:9:    void ( [noderef] __rcu * )( ... )
> > > kernel/trace/rethook.c:68:9:    void ( * )( ... )
> > >
> > > 66 void rethook_free(struct rethook *rh)
> > > 67 {
> > > 68         rcu_assign_pointer(rh->handler, NULL);
> > > 69
> > > 70         call_rcu(&rh->rcu, rethook_free_rcu);
> > > 71 }
> > >
> > > Looks like this should be a WRITE_ONCE() ?
> > 
> > Masami, please take a look.
> > 
> > > And the __user annotations in bpf_trace.c are still not right,
> > > first arg of kprobe_multi_resolve_syms() should __user:
> > >
> > > kernel/trace/bpf_trace.c:2370:34: warning: incorrect type in argument 2 (different address spaces)
> > > kernel/trace/bpf_trace.c:2370:34:    expected void const [noderef] __user *from
> > > kernel/trace/bpf_trace.c:2370:34:    got void const *usyms
> > > kernel/trace/bpf_trace.c:2376:51: warning: incorrect type in argument 2 (different address spaces)
> > > kernel/trace/bpf_trace.c:2376:51:    expected char const [noderef] __user *src
> > > kernel/trace/bpf_trace.c:2376:51:    got char const *
> > > kernel/trace/bpf_trace.c:2443:49: warning: incorrect type in argument 1 (different address spaces)
> > > kernel/trace/bpf_trace.c:2443:49:    expected void const *usyms
> > > kernel/trace/bpf_trace.c:2443:49:    got void [noderef] __user *[assigned] usyms
> > 
> > This one is known. Still waiting for the fix from Jiri.
> 
> right, I replied that for some reason I can't see these warnings
> with 'make C=2' and latest sparse.. how do you run that?
> 
> if patch below fixes it for you, I can send formal patch quickly

ok, I was on top of bpf-next/master where it's still reverted,
I can hit that on bpf/master, I'll send the fix

jirka

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

* Re: pull-request: bpf 2022-03-29
  2022-03-30  9:15       ` Masami Hiramatsu
@ 2022-03-30 15:09         ` Alexei Starovoitov
  2022-03-31  1:11           ` [PATCH bpf] rethook: Fix to use WRITE_ONCE() for rethook::handler Masami Hiramatsu
  2022-03-31  1:12           ` pull-request: bpf 2022-03-29 Masami Hiramatsu
  0 siblings, 2 replies; 13+ messages in thread
From: Alexei Starovoitov @ 2022-03-30 15:09 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Jakub Kicinski, David S. Miller, Daniel Borkmann, Peter Zijlstra,
	Andrii Nakryiko, Network Development, bpf, Kernel Team

On Wed, Mar 30, 2022 at 2:15 AM Masami Hiramatsu <mhiramat@kernel.org> wrote:
>
> On Wed, 30 Mar 2022 13:52:17 +0900
> Masami Hiramatsu <mhiramat@kernel.org> wrote:
>
> > On Tue, 29 Mar 2022 18:51:22 -0700
> > Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:
> >
> > > On Tue, Mar 29, 2022 at 6:41 PM Jakub Kicinski <kuba@kernel.org> wrote:
> > > >
> > > > On Tue, 29 Mar 2022 16:49:24 -0700 Alexei Starovoitov wrote:
> > > > > Hi David, hi Jakub,
> > > > >
> > > > > The following pull-request contains BPF updates for your *net* tree.
> > > > >
> > > > > We've added 16 non-merge commits during the last 1 day(s) which contain
> > > > > a total of 24 files changed, 354 insertions(+), 187 deletions(-).
> > > > >
> > > > > The main changes are:
> > > > >
> > > > > 1) x86 specific bits of fprobe/rethook, from Masami and Peter.
> > > > >
> > > > > 2) ice/xsk fixes, from Maciej and Magnus.
> > > > >
> > > > > 3) Various small fixes, from Andrii, Yonghong, Geliang and others.
> > > >
> > > > There are some new sparse warnings here that look semi-legit.
> > > > As in harmless but not erroneous.
> > >
> > > Both are new warnings and not due to these patches, right?
> > >
> > > > kernel/trace/rethook.c:68:9: error: incompatible types in comparison expression (different address spaces):
> > > > kernel/trace/rethook.c:68:9:    void ( [noderef] __rcu * )( ... )
> > > > kernel/trace/rethook.c:68:9:    void ( * )( ... )
> > > >
> > > > 66 void rethook_free(struct rethook *rh)
> > > > 67 {
> > > > 68         rcu_assign_pointer(rh->handler, NULL);
> > > > 69
> > > > 70         call_rcu(&rh->rcu, rethook_free_rcu);
> > > > 71 }
> > > >
> > > > Looks like this should be a WRITE_ONCE() ?
> > >
> > > Masami, please take a look.
> >
> > Yeah, I think we should make this rcu pointer (and read side must use rcu_dereference())
> > because this rh->handler becomes the key to disable this rethook.
> > Let me fix that.
>
> Sorry, please ignore this. Since the handler pointed by rh->handler never
> be removed (unless removed by modules, but this will not happen while
> the rethook is running), YES, WRITE_ONCE() is enough.
> Please add below.
>
> From 92c9c784458f03900823360981812220ce3c7bf3 Mon Sep 17 00:00:00 2001
> From: Masami Hiramatsu <mhiramat@kernel.org>
> Date: Wed, 30 Mar 2022 18:13:42 +0900
> Subject: [PATCH] rethook: Fix to use WRITE_ONCE() for rethook::handler
>
> Since the function pointered by rethook::handler never be removed when
> the rethook is alive, it doesn't need to use rcu_assign_pointer() to
> update it. Just use WRITE_ONCE().
>
> Reported-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>

Could you please send it as a proper patch so it registers in patchwork?

> ---
>  kernel/trace/rethook.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c
> index ab463a4d2b23..b56833700d23 100644
> --- a/kernel/trace/rethook.c
> +++ b/kernel/trace/rethook.c
> @@ -65,7 +65,7 @@ static void rethook_free_rcu(struct rcu_head *head)
>   */
>  void rethook_free(struct rethook *rh)
>  {
> -       rcu_assign_pointer(rh->handler, NULL);
> +       WRITE_ONCE(rh->handler, NULL);
>
>         call_rcu(&rh->rcu, rethook_free_rcu);
>  }
> --
> 2.25.1
> --
> Masami Hiramatsu <mhiramat@kernel.org>

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

* [PATCH bpf] rethook: Fix to use WRITE_ONCE() for rethook::handler
  2022-03-30 15:09         ` Alexei Starovoitov
@ 2022-03-31  1:11           ` Masami Hiramatsu
  2022-03-31  2:30             ` patchwork-bot+netdevbpf
  2022-03-31  1:12           ` pull-request: bpf 2022-03-29 Masami Hiramatsu
  1 sibling, 1 reply; 13+ messages in thread
From: Masami Hiramatsu @ 2022-03-31  1:11 UTC (permalink / raw)
  To: Alexei Starovoitov, Alexei Starovoitov
  Cc: davem, daniel, peterz, mhiramat, kuba, andrii, netdev, bpf, kernel-team

Since the function pointered by rethook::handler never be removed when
the rethook is alive, it doesn't need to use rcu_assign_pointer() to
update it. Just use WRITE_ONCE().

Reported-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/trace/rethook.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c
index ab463a4d2b23..b56833700d23 100644
--- a/kernel/trace/rethook.c
+++ b/kernel/trace/rethook.c
@@ -65,7 +65,7 @@ static void rethook_free_rcu(struct rcu_head *head)
  */
 void rethook_free(struct rethook *rh)
 {
-	rcu_assign_pointer(rh->handler, NULL);
+	WRITE_ONCE(rh->handler, NULL);
 
 	call_rcu(&rh->rcu, rethook_free_rcu);
 }


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

* Re: pull-request: bpf 2022-03-29
  2022-03-30 15:09         ` Alexei Starovoitov
  2022-03-31  1:11           ` [PATCH bpf] rethook: Fix to use WRITE_ONCE() for rethook::handler Masami Hiramatsu
@ 2022-03-31  1:12           ` Masami Hiramatsu
  1 sibling, 0 replies; 13+ messages in thread
From: Masami Hiramatsu @ 2022-03-31  1:12 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Jakub Kicinski, David S. Miller, Daniel Borkmann, Peter Zijlstra,
	Andrii Nakryiko, Network Development, bpf, Kernel Team

On Wed, 30 Mar 2022 08:09:59 -0700
Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:

> On Wed, Mar 30, 2022 at 2:15 AM Masami Hiramatsu <mhiramat@kernel.org> wrote:
> >
> > On Wed, 30 Mar 2022 13:52:17 +0900
> > Masami Hiramatsu <mhiramat@kernel.org> wrote:
> >
> > > On Tue, 29 Mar 2022 18:51:22 -0700
> > > Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:
> > >
> > > > On Tue, Mar 29, 2022 at 6:41 PM Jakub Kicinski <kuba@kernel.org> wrote:
> > > > >
> > > > > On Tue, 29 Mar 2022 16:49:24 -0700 Alexei Starovoitov wrote:
> > > > > > Hi David, hi Jakub,
> > > > > >
> > > > > > The following pull-request contains BPF updates for your *net* tree.
> > > > > >
> > > > > > We've added 16 non-merge commits during the last 1 day(s) which contain
> > > > > > a total of 24 files changed, 354 insertions(+), 187 deletions(-).
> > > > > >
> > > > > > The main changes are:
> > > > > >
> > > > > > 1) x86 specific bits of fprobe/rethook, from Masami and Peter.
> > > > > >
> > > > > > 2) ice/xsk fixes, from Maciej and Magnus.
> > > > > >
> > > > > > 3) Various small fixes, from Andrii, Yonghong, Geliang and others.
> > > > >
> > > > > There are some new sparse warnings here that look semi-legit.
> > > > > As in harmless but not erroneous.
> > > >
> > > > Both are new warnings and not due to these patches, right?
> > > >
> > > > > kernel/trace/rethook.c:68:9: error: incompatible types in comparison expression (different address spaces):
> > > > > kernel/trace/rethook.c:68:9:    void ( [noderef] __rcu * )( ... )
> > > > > kernel/trace/rethook.c:68:9:    void ( * )( ... )
> > > > >
> > > > > 66 void rethook_free(struct rethook *rh)
> > > > > 67 {
> > > > > 68         rcu_assign_pointer(rh->handler, NULL);
> > > > > 69
> > > > > 70         call_rcu(&rh->rcu, rethook_free_rcu);
> > > > > 71 }
> > > > >
> > > > > Looks like this should be a WRITE_ONCE() ?
> > > >
> > > > Masami, please take a look.
> > >
> > > Yeah, I think we should make this rcu pointer (and read side must use rcu_dereference())
> > > because this rh->handler becomes the key to disable this rethook.
> > > Let me fix that.
> >
> > Sorry, please ignore this. Since the handler pointed by rh->handler never
> > be removed (unless removed by modules, but this will not happen while
> > the rethook is running), YES, WRITE_ONCE() is enough.
> > Please add below.
> >
> > From 92c9c784458f03900823360981812220ce3c7bf3 Mon Sep 17 00:00:00 2001
> > From: Masami Hiramatsu <mhiramat@kernel.org>
> > Date: Wed, 30 Mar 2022 18:13:42 +0900
> > Subject: [PATCH] rethook: Fix to use WRITE_ONCE() for rethook::handler
> >
> > Since the function pointered by rethook::handler never be removed when
> > the rethook is alive, it doesn't need to use rcu_assign_pointer() to
> > update it. Just use WRITE_ONCE().
> >
> > Reported-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
> > Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> 
> Could you please send it as a proper patch so it registers in patchwork?

Sure, I sent the patch. BTW, I marked it as "bpf" instead of "bpf-next",
was that OK? (It seems bpf-next was not updated yet)

Thank you,

> 
> > ---
> >  kernel/trace/rethook.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c
> > index ab463a4d2b23..b56833700d23 100644
> > --- a/kernel/trace/rethook.c
> > +++ b/kernel/trace/rethook.c
> > @@ -65,7 +65,7 @@ static void rethook_free_rcu(struct rcu_head *head)
> >   */
> >  void rethook_free(struct rethook *rh)
> >  {
> > -       rcu_assign_pointer(rh->handler, NULL);
> > +       WRITE_ONCE(rh->handler, NULL);
> >
> >         call_rcu(&rh->rcu, rethook_free_rcu);
> >  }
> > --
> > 2.25.1
> > --
> > Masami Hiramatsu <mhiramat@kernel.org>


-- 
Masami Hiramatsu <mhiramat@kernel.org>

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

* Re: [PATCH bpf] rethook: Fix to use WRITE_ONCE() for rethook::handler
  2022-03-31  1:11           ` [PATCH bpf] rethook: Fix to use WRITE_ONCE() for rethook::handler Masami Hiramatsu
@ 2022-03-31  2:30             ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 13+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-03-31  2:30 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: ast, alexei.starovoitov, davem, daniel, peterz, kuba, andrii,
	netdev, bpf, kernel-team

Hello:

This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Thu, 31 Mar 2022 10:11:17 +0900 you wrote:
> Since the function pointered by rethook::handler never be removed when
> the rethook is alive, it doesn't need to use rcu_assign_pointer() to
> update it. Just use WRITE_ONCE().
> 
> Reported-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> 
> [...]

Here is the summary with links:
  - [bpf] rethook: Fix to use WRITE_ONCE() for rethook::handler
    https://git.kernel.org/bpf/bpf/c/a2fb49833cad

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2022-03-31  2:30 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-29 23:49 pull-request: bpf 2022-03-29 Alexei Starovoitov
2022-03-30  1:41 ` Jakub Kicinski
2022-03-30  1:51   ` Alexei Starovoitov
2022-03-30  2:02     ` Jakub Kicinski
2022-03-30  4:52     ` Masami Hiramatsu
2022-03-30  9:15       ` Masami Hiramatsu
2022-03-30 15:09         ` Alexei Starovoitov
2022-03-31  1:11           ` [PATCH bpf] rethook: Fix to use WRITE_ONCE() for rethook::handler Masami Hiramatsu
2022-03-31  2:30             ` patchwork-bot+netdevbpf
2022-03-31  1:12           ` pull-request: bpf 2022-03-29 Masami Hiramatsu
2022-03-30  8:05     ` Jiri Olsa
2022-03-30 11:01       ` Jiri Olsa
2022-03-30  4:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).