mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Jiri Olsa <jolsa@redhat.com>
Cc: Vince Weaver <vincent.weaver@maine.edu>,
	Ravi Bangoria <ravi.bangoria@linux.ibm.com>,
	lkml <linux-kernel@vger.kernel.org>,
	linux-perf-users@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Andi Kleen <ak@linux.intel.com>,
	eranian@google.com,
	"Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>,
	Ingo Molnar <mingo@kernel.org>
Subject: Re: [PATCH] perf: Add check_period pmu callback
Date: Mon, 11 Feb 2019 11:11:39 +0100	[thread overview]
Message-ID: <20190211101139.GV32511@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20190204123532.GA4794@krava>

On Mon, Feb 04, 2019 at 01:35:32PM +0100, Jiri Olsa wrote:
> Vince (and later on Ravi) reported crash in BTS code during
> fuzzing with following backtrace:
> 
>   general protection fault: 0000 [#1] SMP PTI
>   ...
>   RIP: 0010:perf_prepare_sample+0x8f/0x510
>   ...
>   Call Trace:
>    <IRQ>
>    ? intel_pmu_drain_bts_buffer+0x194/0x230
>    intel_pmu_drain_bts_buffer+0x160/0x230
>    ? tick_nohz_irq_exit+0x31/0x40
>    ? smp_call_function_single_interrupt+0x48/0xe0
>    ? call_function_single_interrupt+0xf/0x20
>    ? call_function_single_interrupt+0xa/0x20
>    ? x86_schedule_events+0x1a0/0x2f0
>    ? x86_pmu_commit_txn+0xb4/0x100
>    ? find_busiest_group+0x47/0x5d0
>    ? perf_event_set_state.part.42+0x12/0x50
>    ? perf_mux_hrtimer_restart+0x40/0xb0
>    intel_pmu_disable_event+0xae/0x100
>    ? intel_pmu_disable_event+0xae/0x100
>    x86_pmu_stop+0x7a/0xb0
>    x86_pmu_del+0x57/0x120
>    event_sched_out.isra.101+0x83/0x180
>    group_sched_out.part.103+0x57/0xe0
>    ctx_sched_out+0x188/0x240
>    ctx_resched+0xa8/0xd0
>    __perf_event_enable+0x193/0x1e0
>    event_function+0x8e/0xc0
>    remote_function+0x41/0x50
>    flush_smp_call_function_queue+0x68/0x100
>    generic_smp_call_function_single_interrupt+0x13/0x30
>    smp_call_function_single_interrupt+0x3e/0xe0
>    call_function_single_interrupt+0xf/0x20
>    </IRQ>
> 
> The reason is that while event init code does several checks
> for BTS events and prevents several unwanted config bits for
> BTS event (like precise_ip), the PERF_EVENT_IOC_PERIOD allows
> to create BTS event without those checks being done.
> 
> Following sequence will cause the crash:
>   - create 'almost' BTS event with precise_ip and callchains,
>     (perf command line -e option equiv.):
> 
>     -e cpu/branch-instructions/up -c 2 -g
> 
>   - change the period of that event to '1', which will turn
>     it to BTS event, with precise_ip and callchains
> 
> That will immediately cause crash in perf_prepare_sample
> function because precise_ip events are expected to come
> in with callchain data initialized, but that's not the
> case for intel_pmu_drain_bts_buffer caller.
> 
> Adding a check_period callback to be called before the period
> is changed via PERF_EVENT_IOC_PERIOD. It will deny the change
> if the event would become BTS. Plus adding also the limit_period
> check as well.
> 
> Cc: Vince Weaver <vincent.weaver@maine.edu>
> Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
> Reported-by: Vince Weaver <vincent.weaver@maine.edu>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>

Thanks Jiri!

  reply	other threads:[~2019-02-11 10:11 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-25  6:46 System crash with perf_fuzzer (kernel: 5.0.0-rc3) Ravi Bangoria
2019-01-25 15:11 ` Vince Weaver
2019-01-25 16:00 ` Andi Kleen
2019-01-31  7:58   ` Ravi Bangoria
2019-01-31 13:00     ` Andi Kleen
2019-01-31 20:27   ` Cong Wang
2019-01-31 20:39     ` Andi Kleen
2019-03-06 23:09   ` Pavel Machek
2019-01-30 18:36 ` Jiri Olsa
2019-01-30 20:39   ` Andi Kleen
2019-01-30 22:33     ` Jiri Olsa
2019-01-31  7:36   ` Jiri Olsa
2019-01-31  8:27   ` Jiri Olsa
2019-02-01  7:43     ` Jiri Olsa
2019-02-01  7:54       ` Ravi Bangoria
2019-02-02  3:24         ` Ravi Bangoria
2019-02-02 10:34           ` Jiri Olsa
2019-02-01 16:27       ` Vince Weaver
2019-02-01 17:38         ` Jiri Olsa
2019-02-02 17:58           ` Vince Weaver
2019-02-04 12:35             ` [PATCH] perf: Add check_period pmu callback Jiri Olsa
2019-02-11 10:11               ` Peter Zijlstra [this message]
2019-02-11 13:22               ` [tip:perf/urgent] perf/x86: Add check_period PMU callback tip-bot for Jiri Olsa

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=20190211101139.GV32511@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=eranian@google.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=naveen.n.rao@linux.vnet.ibm.com \
    --cc=ravi.bangoria@linux.ibm.com \
    --cc=vincent.weaver@maine.edu \
    /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

all inboxes | Powered by JetHome®