Re: [PATCH] perf: Fix oops when kthread execs user process
From: Russell King - ARM Linux admin
Date: Tue May 28 2019 - 08:45:44 EST
On Tue, May 28, 2019 at 08:31:29PM +0800, Young Xiao wrote:
> 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@xxxxxxxxx>
> ---
> 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;
I'd prefer it if we didn't introduce unnecessary parens - what function
do the parens around "regs_user->regs" serve?
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up