All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ari Savolainen <ari.m.savolainen@gmail.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@elte.hu>,
	Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf: Fix RCU dereference check in perf_event_comm
Date: Thu, 22 Mar 2012 13:36:06 +0200	[thread overview]
Message-ID: <CAEbykaUbkgCEcufTx4ZBSdqwrifVbV384Ru4xTyF7BXYtJ85Zg@mail.gmail.com> (raw)
In-Reply-To: <1332409996.18960.511.camel@twins>

22. maaliskuuta 2012 11.53 Peter Zijlstra <a.p.zijlstra@chello.nl> kirjoitti:
> On Thu, 2012-03-22 at 01:43 +0200, Ari Savolainen wrote:
>> The warning below is printed when executing a command like
>> sudo perf record su - user -c "echo hello"
>>
>> It's fixed by moving the call of perf_event_comm to be protected
>> by the task lock.
>
> That seems like a rather poor solution since it increases the lock hold
> time for no explained reason.
>
>> include/linux/cgroup.h:567 suspicious rcu_dereference_check() usage!
>
>>  [<ffffffff8109be55>] lockdep_rcu_suspicious+0xe5/0x100
>>  [<ffffffff811131fa>] perf_event_comm+0x37a/0x4d0
>
> So where exactly is this, perf_event_comm_event() takes rcu_read_lock()
> so I presume its before that.

I think the warning comes from this source-level call path:

perf_event_comm ->
  perf_event_enable_on_exec ->
    perf_cgroup_sched_out ->
      perf_cgroup_from_task ->
        task_subsys_state ->
          task_subsys_state_check

It seems there that path does not take rcu_read_lock(). Where should
rcu_read_lock/unlock be added? In perf_group_sched_out around the
calls of perf_cgroup_from_task? Like this:

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 1b5c081..bbb4abc 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -409,6 +409,8 @@ static inline void perf_cgroup_sched_out(struct
task_struct *task,
        struct perf_cgroup *cgrp1;
        struct perf_cgroup *cgrp2 = NULL;

+       rcu_read_lock();
+
        /*
         * we come here when we know perf_cgroup_events > 0
         */
@@ -421,6 +423,8 @@ static inline void perf_cgroup_sched_out(struct
task_struct *task,
        if (next)
                cgrp2 = perf_cgroup_from_task(next);

+       rcu_read_unlock();
+
        /*
         * only schedule out current cgroup events if we know
         * that we are switching to a different cgroup. Otherwise,
--


Ari

  reply	other threads:[~2012-03-22 11:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-21 23:43 [PATCH] perf: Fix RCU dereference check in perf_event_comm Ari Savolainen
2012-03-22  9:53 ` Peter Zijlstra
2012-03-22 11:36   ` Ari Savolainen [this message]
2012-03-26 12:41     ` Peter Zijlstra
2012-04-26 15:06       ` Stephane Eranian
2012-04-29 20:07         ` Ari Savolainen
2012-05-18 16:38       ` Stephane Eranian

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=CAEbykaUbkgCEcufTx4ZBSdqwrifVbV384Ru4xTyF7BXYtJ85Zg@mail.gmail.com \
    --to=ari.m.savolainen@gmail.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@ghostprotocols.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.