linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cong Wang <xiyou.wangcong@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@redhat.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	Andi Kleen <ak@linux.intel.com>
Subject: Re: [PATCH v2] perf/core: fix a possible deadlock scenario
Date: Wed, 25 Jul 2018 11:44:34 -0700	[thread overview]
Message-ID: <CAM_iQpVT73pofGYYys+OC5OCs8w+Q+rnfnwBaQQRuobnqcEJUg@mail.gmail.com> (raw)
In-Reply-To: <20180724091824.GM2494@hirez.programming.kicks-ass.net>

On Tue, Jul 24, 2018 at 2:18 AM Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Mon, Jul 23, 2018 at 06:44:43PM -0700, Cong Wang wrote:
> > On Mon, Jul 23, 2018 at 6:35 PM Cong Wang <xiyou.wangcong@gmail.com> wrote:
> > >
> > > Hi, Peter, Andi
> > >
> > > While reviewing the deadlock, I find out it looks like we could have the
> > > following infinite recursion too:
> > >
> > > perf_event_account_interrupt()
> > > __perf_event_account_interrupt()
> > > perf_adjust_period()
> > > event->pmu->stop
> > > x86_pmu_stop()
> > > x86_pmu.disable()
> >
> > Hmm, x86_pmu_stop() calls __test_and_clear_bit(), so
> > we should not call x86_pmu.disable() twice here.
>
> Right, but since we set HES_UPTODATE after calling
> x86_perf_event_update() that can in fact recurse.

I don't see how HES_UPTODATE flag or x86_perf_event_update()
could affect the path on this call chain.


>
> Now, I don't think that'll be fatal, but it might be good to test that.
>
> If you pick these patches:
>
>   https://lkml.kernel.org/r/20170928121823.430053219@infradead.org
>
> use force_early_printk (and actually configure a serial early_printk)
> and put a printk() in x86_pmu_stop() and then run the perf_fuzzer or
> something to try and reproduce.

Is this patchset to make printk() working in NMI context?
But printk() is already used in NMI context, see perf_event_print_debug()
which is called in intel_pmu_handle_irq().


>
> But paranoia suggets moving that HES_UPTODATE thing one line up.
>
> > > intel_pmu_disable_event()
> > > intel_pmu_pebs_disable()
> > > intel_pmu_drain_pebs_buffer()
> > > intel_pmu_drain_pebs_nhm()
> > > <repeat....>
> > >
> > > This time is pure hardware events, attr.freq must be non-zero.
> > >
> > > And, we could enter this infinite recursion in NMI handler too:
> > >
> > > intel_pmu_handle_irq()
> > > perf_event_overflow()
> > > __perf_event_overflow()
> > > __perf_event_account_interrupt()
> > > ....
> > >
> > > Or this is impossible too?
>
> I'm not sure I see this second one.. can you be a little more specific?

In fact, it is this:

intel_pmu_handle_irq()
x86_pmu.drain_pebs()
intel_pmu_drain_pebs_nhm()
perf_event_account_interrupt()
__perf_event_account_interrupt()
perf_adjust_period()
event->pmu->stop()
x86_pmu_stop()
x86_pmu.disable()
intel_pmu_disable_event()
intel_pmu_pebs_disable()
intel_pmu_drain_pebs_buffer()
<repeat....>


Thanks!

  reply	other threads:[~2018-07-25 18:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-16 21:51 [PATCH] perf/core: fix a possible deadlock scenario Cong Wang
2018-07-18  8:19 ` Jiri Olsa
2018-07-18 20:21   ` Cong Wang
2018-07-19 13:28     ` Jiri Olsa
2018-07-19 19:12       ` [PATCH v2] " Cong Wang
2018-07-20 11:52         ` Peter Zijlstra
2018-07-23 23:16           ` Cong Wang
2018-07-24  1:35             ` Cong Wang
2018-07-24  1:44               ` Cong Wang
2018-07-24  9:18                 ` Peter Zijlstra
2018-07-25 18:44                   ` Cong Wang [this message]
2018-07-24  9:12             ` Peter Zijlstra

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=CAM_iQpVT73pofGYYys+OC5OCs8w+Q+rnfnwBaQQRuobnqcEJUg@mail.gmail.com \
    --to=xiyou.wangcong@gmail.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=torvalds@linux-foundation.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).