linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Young Xiao <92siuyang@gmail.com>
To: will.deacon@arm.com, linux@armlinux.org.uk, mark.rutland@arm.com,
	mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org,
	peterz@infradead.org, kan.liang@linux.intel.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Cc: Young Xiao <92siuyang@gmail.com>
Subject: [PATCH] perf: Fix oops when kthread execs user process
Date: Tue, 28 May 2019 20:31:29 +0800	[thread overview]
Message-ID: <1559046689-24091-1-git-send-email-92siuyang@gmail.com> (raw)

When a kthread calls call_usermodehelper() the steps are:
  1. allocate current->mm
  2. load_elf_binary()
  3. populate current->thread.regs

While doing this, interrupts are not disabled. If there is a perf
interrupt in the middle of this process (i.e. step 1 has completed
but not yet reached to step 3) and if perf tries to read userspace
regs, kernel oops.

Fix it by setting abi to PERF_SAMPLE_REGS_ABI_NONE when userspace
pt_regs are not set.

See commit bf05fc25f268 ("powerpc/perf: Fix oops when kthread execs
user process") for details.

Signed-off-by: Young Xiao <92siuyang@gmail.com>
---
 arch/arm/kernel/perf_regs.c   | 3 ++-
 arch/arm64/kernel/perf_regs.c | 3 ++-
 arch/x86/kernel/perf_regs.c   | 3 ++-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/arm/kernel/perf_regs.c b/arch/arm/kernel/perf_regs.c
index 05fe92a..78ee29a 100644
--- a/arch/arm/kernel/perf_regs.c
+++ b/arch/arm/kernel/perf_regs.c
@@ -36,5 +36,6 @@ void perf_get_regs_user(struct perf_regs *regs_user,
 			struct pt_regs *regs_user_copy)
 {
 	regs_user->regs = task_pt_regs(current);
-	regs_user->abi = perf_reg_abi(current);
+	regs_user->abi = (regs_user->regs) ? perf_reg_abi(current) :
+			 PERF_SAMPLE_REGS_ABI_NONE;
 }
diff --git a/arch/arm64/kernel/perf_regs.c b/arch/arm64/kernel/perf_regs.c
index 0bbac61..ac19d19 100644
--- a/arch/arm64/kernel/perf_regs.c
+++ b/arch/arm64/kernel/perf_regs.c
@@ -58,5 +58,6 @@ void perf_get_regs_user(struct perf_regs *regs_user,
 			struct pt_regs *regs_user_copy)
 {
 	regs_user->regs = task_pt_regs(current);
-	regs_user->abi = perf_reg_abi(current);
+	regs_user->abi = (regs_user->regs) ? perf_reg_abi(current) :
+			 PERF_SAMPLE_REGS_ABI_NONE;
 }
diff --git a/arch/x86/kernel/perf_regs.c b/arch/x86/kernel/perf_regs.c
index 07c30ee..fa79d6d 100644
--- a/arch/x86/kernel/perf_regs.c
+++ b/arch/x86/kernel/perf_regs.c
@@ -102,7 +102,8 @@ void perf_get_regs_user(struct perf_regs *regs_user,
 			struct pt_regs *regs_user_copy)
 {
 	regs_user->regs = task_pt_regs(current);
-	regs_user->abi = perf_reg_abi(current);
+	regs_user->abi = (regs_user->regs) ? perf_reg_abi(current) :
+			 PERF_SAMPLE_REGS_ABI_NONE;
 }
 #else /* CONFIG_X86_64 */
 #define REG_NOSUPPORT ((1ULL << PERF_REG_X86_DS) | \
-- 
2.7.4


             reply	other threads:[~2019-05-28 12:30 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-28 12:31 Young Xiao [this message]
2019-05-28 12:41 ` [PATCH] perf: Fix oops when kthread execs user process Russell King - ARM Linux admin
2019-05-28 14:01 ` Peter Zijlstra
2019-05-28 15:32   ` Will Deacon
2019-05-28 16:12     ` Mark Rutland
2019-05-28 17:32     ` Peter Zijlstra
2019-05-29  9:17       ` Will Deacon
2019-05-29 10:10         ` Peter Zijlstra
2019-05-29 10:20           ` Will Deacon
2019-05-29 12:55             ` Peter Zijlstra
2019-05-29 13:05               ` Will Deacon
2019-05-29 13:25                 ` Peter Zijlstra
2019-05-29 14:35                   ` Will Deacon
2019-05-29 16:19                     ` Peter Zijlstra
2019-05-29 16:24                       ` Mark Rutland
2019-05-29 16:38                         ` Mark Rutland
2019-05-29 17:03                           ` Peter Zijlstra
2019-05-30 10:35                             ` Mark Rutland
2019-05-29 16:25                       ` Will Deacon
2019-05-29 16:44                         ` Peter Zijlstra
2019-05-30  7:28                           ` Will Deacon
2019-05-30  8:38               ` Ravi Bangoria
2019-05-30 10:27                 ` Ravi Bangoria
2019-05-31 15:37                   ` Will Deacon
2019-06-03 11:23                     ` Will Deacon
2019-06-03 11:48                     ` Peter Zijlstra
2019-06-03 13:30                     ` Michael Ellerman
2019-05-29 10:11       ` Mark Rutland
2019-05-29  4:21     ` Michael Ellerman
2019-05-29  1:44   ` Michael Ellerman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1559046689-24091-1-git-send-email-92siuyang@gmail.com \
    --to=92siuyang@gmail.com \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=will.deacon@arm.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).