LKML Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH -tip] kprobes/x86: Use preempt_enable() in optimized_callback()
@ 2018-10-20  9:47 Masami Hiramatsu
  2018-10-21 20:42 ` Peter Zijlstra
  2018-10-22  1:33 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
  0 siblings, 2 replies; 3+ messages in thread
From: Masami Hiramatsu @ 2018-10-20  9:47 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Andy Lutomirski, Alexei Starovoitov, Oleg Nesterov,
	Peter Zijlstra, H . Peter Anvin, Thomas Gleixner, X86 ML,
	Borislav Petkov, dwmw, Masami Hiramatsu, linux-kernel

Since commit a19b2e3d7839 ("kprobes/x86: Remove IRQ disabling from
ftrace-based/optimized kprobes”) removes local_irq_save/restore()
from optimized_callback(), the handler does not protected against
reschedule interrupt. If it is able to be preempted (rescheduled)
by such interrupt, we don't need to use _no_resched macro.
Let's use preempt_enable() instead.

Fixes: a19b2e3d7839 ("kprobes/x86: Remove IRQ disabling from ftrace-based/optimized kprobes”)
Link: https://lkml.kernel.org/r/37CB98C2-AF9B-475B-8B2D-7B414DC491F3@vmware.com
Reported-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 arch/x86/kernel/kprobes/opt.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
index eaf02f2e7300..40b16b270656 100644
--- a/arch/x86/kernel/kprobes/opt.c
+++ b/arch/x86/kernel/kprobes/opt.c
@@ -179,7 +179,7 @@ optimized_callback(struct optimized_kprobe *op, struct pt_regs *regs)
 		opt_pre_handler(&op->kp, regs);
 		__this_cpu_write(current_kprobe, NULL);
 	}
-	preempt_enable_no_resched();
+	preempt_enable();
 }
 NOKPROBE_SYMBOL(optimized_callback);
 


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

* Re: [PATCH -tip] kprobes/x86: Use preempt_enable() in optimized_callback()
  2018-10-20  9:47 [PATCH -tip] kprobes/x86: Use preempt_enable() in optimized_callback() Masami Hiramatsu
@ 2018-10-21 20:42 ` Peter Zijlstra
  2018-10-22  1:33 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2018-10-21 20:42 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Ingo Molnar, Andy Lutomirski, Alexei Starovoitov, Oleg Nesterov,
	H . Peter Anvin, Thomas Gleixner, X86 ML, Borislav Petkov, dwmw,
	linux-kernel

On Sat, Oct 20, 2018 at 06:47:53PM +0900, Masami Hiramatsu wrote:
> Since commit a19b2e3d7839 ("kprobes/x86: Remove IRQ disabling from
> ftrace-based/optimized kprobes”) removes local_irq_save/restore()
> from optimized_callback(), the handler does not protected against
> reschedule interrupt. If it is able to be preempted (rescheduled)
> by such interrupt, we don't need to use _no_resched macro.

must not.

> Let's use preempt_enable() instead.
> 
> Fixes: a19b2e3d7839 ("kprobes/x86: Remove IRQ disabling from ftrace-based/optimized kprobes”)
> Link: https://lkml.kernel.org/r/37CB98C2-AF9B-475B-8B2D-7B414DC491F3@vmware.com
> Reported-by: Nadav Amit <namit@vmware.com>
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---
>  arch/x86/kernel/kprobes/opt.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
> index eaf02f2e7300..40b16b270656 100644
> --- a/arch/x86/kernel/kprobes/opt.c
> +++ b/arch/x86/kernel/kprobes/opt.c
> @@ -179,7 +179,7 @@ optimized_callback(struct optimized_kprobe *op, struct pt_regs *regs)
>  		opt_pre_handler(&op->kp, regs);
>  		__this_cpu_write(current_kprobe, NULL);
>  	}
> -	preempt_enable_no_resched();
> +	preempt_enable();
>  }

Indeed,

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>

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

* [tip:perf/core] kprobes/x86: Use preempt_enable() in optimized_callback()
  2018-10-20  9:47 [PATCH -tip] kprobes/x86: Use preempt_enable() in optimized_callback() Masami Hiramatsu
  2018-10-21 20:42 ` Peter Zijlstra
@ 2018-10-22  1:33 ` tip-bot for Masami Hiramatsu
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2018-10-22  1:33 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, oleg, torvalds, namit, mingo, alexei.starovoitov, hpa,
	mhiramat, peterz, linux-kernel, luto, stable, bp

Commit-ID:  2e62024c265aa69315ed02835623740030435380
Gitweb:     https://git.kernel.org/tip/2e62024c265aa69315ed02835623740030435380
Author:     Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate: Sat, 20 Oct 2018 18:47:53 +0900
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Mon, 22 Oct 2018 03:31:01 +0200

kprobes/x86: Use preempt_enable() in optimized_callback()

The following commit:

  a19b2e3d7839 ("kprobes/x86: Remove IRQ disabling from ftrace-based/optimized kprobes”)

removed local_irq_save/restore() from optimized_callback(), the handler
might be interrupted by the rescheduling interrupt and might be
rescheduled - so we must not use the preempt_enable_no_resched() macro.

Use preempt_enable() instead, to not lose preemption events.

[ mingo: Improved the changelog. ]

Reported-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: <stable@vger.kernel.org>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: dwmw@amazon.co.uk
Fixes: a19b2e3d7839 ("kprobes/x86: Remove IRQ disabling from ftrace-based/optimized kprobes”)
Link: http://lkml.kernel.org/r/154002887331.7627.10194920925792947001.stgit@devbox
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/kprobes/opt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
index eaf02f2e7300..40b16b270656 100644
--- a/arch/x86/kernel/kprobes/opt.c
+++ b/arch/x86/kernel/kprobes/opt.c
@@ -179,7 +179,7 @@ optimized_callback(struct optimized_kprobe *op, struct pt_regs *regs)
 		opt_pre_handler(&op->kp, regs);
 		__this_cpu_write(current_kprobe, NULL);
 	}
-	preempt_enable_no_resched();
+	preempt_enable();
 }
 NOKPROBE_SYMBOL(optimized_callback);
 

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-20  9:47 [PATCH -tip] kprobes/x86: Use preempt_enable() in optimized_callback() Masami Hiramatsu
2018-10-21 20:42 ` Peter Zijlstra
2018-10-22  1:33 ` [tip:perf/core] " tip-bot for Masami Hiramatsu

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git
	git clone --mirror https://lore.kernel.org/lkml/9 lkml/git/9.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git