public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Kim Phillips <kim.phillips@arm.com>
To: Mark Rutland <mark.rutland@arm.com>
Cc: Will Deacon <will.deacon@arm.com>, <mingo@redhat.com>,
	<linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH] perf/core: Avoid freeing static PMU contexts when PMU is unregistered
Date: Wed, 4 Oct 2017 10:31:46 -0500	[thread overview]
Message-ID: <20171004103146.43cd7185662d842ff11a5940@arm.com> (raw)
In-Reply-To: <20171003145813.GF4931@leverpostej>

On Tue, 3 Oct 2017 15:58:13 +0100
Mark Rutland <mark.rutland@arm.com> wrote:

> On Tue, Oct 03, 2017 at 03:20:50PM +0100, Will Deacon wrote:
> > Since commit 1fd7e4169954 ("perf/core: Remove perf_cpu_context::unique_pmu"),
> > when a PMU is unregistered then its associated ->pmu_cpu_context is
> > unconditionally freed. Whilst this is fine for dynamically allocated
> > context types (i.e. those registered using perf_invalid_context), this
> > causes a problem for sharing of static contexts such as
> > perf_{sw,hw}_context, which are used by multiple built-in PMUs and
> > effectively have a global lifetime.
> > 
> > Whilst testing the ARM SPE driver, which must use perf_sw_context to
> > support per-task AUX tracing, unregistering the driver as a result of a
> > module unload resulted in:
> > 
> >  Unable to handle kernel NULL pointer dereference at virtual address 00000038
> >  Internal error: Oops: 96000004 [#1] PREEMPT SMP
> >  Modules linked in: [last unloaded: arm_spe_pmu]
> >  PC is at ctx_resched+0x38/0xe8
> >  LR is at perf_event_exec+0x20c/0x278
> >  [...]
> >  ctx_resched+0x38/0xe8
> >  perf_event_exec+0x20c/0x278
> >  setup_new_exec+0x88/0x118
> >  load_elf_binary+0x26c/0x109c
> >  search_binary_handler+0x90/0x298
> >  do_execveat_common.isra.14+0x540/0x618
> >  SyS_execve+0x38/0x48
> > 
> > since the software context has been freed and the ctx.pmu->pmu_disable_count
> > field has been set to NULL.
> > 
> > This patch fixes the problem by avoiding the freeing of static PMU contexts
> > altogether. Whilst the sharing of dynamic contexts is questionable, this
> > actually requires the caller to share their context pointer explicitly
> > and so the burden is on them to manage the object lifetime.
> > 
> > Cc: Peter Zijlstra <peterz@infradead.org>
> > Fixes: 1fd7e4169954 ("perf/core: Remove perf_cpu_context::unique_pmu")
> > Reported-by: Kim Phillips <kim.phillips@arm.com>
> > Signed-off-by: Will Deacon <will.deacon@arm.com>
> 
> Acked-by: Mark Rutland <mark.rutland@arm.com>

Tested-by: Kim Phillips <kim.phillips@arm.com>

Thanks,

Kim

  reply	other threads:[~2017-10-04 15:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-03 14:20 [PATCH] perf/core: Avoid freeing static PMU contexts when PMU is unregistered Will Deacon
2017-10-03 14:58 ` Mark Rutland
2017-10-04 15:31   ` Kim Phillips [this message]
2017-10-10 10:52 ` [tip:perf/urgent] " tip-bot for Will Deacon

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=20171004103146.43cd7185662d842ff11a5940@arm.com \
    --to=kim.phillips@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=will.deacon@arm.com \
    /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