linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Barret Rhoden <brho@google.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	linux-kernel@vger.kernel.org,
	syzbot+bb4935a5c09b5ff79940@syzkaller.appspotmail.com
Subject: Re: perf: add cond_resched() to task_function_call()
Date: Tue, 14 Apr 2020 17:16:05 -0400	[thread overview]
Message-ID: <bbec4199-37ef-fda2-b18f-3d485c1d5b70@google.com> (raw)
In-Reply-To: <20200414204208.GI2483@worktop.programming.kicks-ass.net>

On 4/14/20 4:42 PM, Peter Zijlstra wrote:
> On Tue, Apr 14, 2020 at 03:03:51PM -0400, Barret Rhoden wrote:
>> Under rare circumstances, task_function_call() can repeatedly fail and
>> cause a soft lockup.
>>
>> There is a slight race where the process is no longer running on the cpu
>> we targeted by the time remote_function() runs.  The code will simply
>> try again.  If we are very unlucky, this will continue to fail, until a
>> watchdog fires.  This can happen in a heavily loaded, multi-core virtual
>> machine.
> 
> Sigh,.. virt again :/
> 
>> Reported-by: syzbot+bb4935a5c09b5ff79940@syzkaller.appspotmail.com
>> Signed-off-by: Barret Rhoden <brho@google.com>
>> ---
>>   kernel/events/core.c | 12 ++++++++----
>>   1 file changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/kernel/events/core.c b/kernel/events/core.c
>> index 55e44417f66d..65c2c05e24c2 100644
>> --- a/kernel/events/core.c
>> +++ b/kernel/events/core.c
>> @@ -99,7 +99,7 @@ static void remote_function(void *data)
>>    *
>>    * returns: @func return value, or
>>    *	    -ESRCH  - when the process isn't running
>> - *	    -EAGAIN - when the process moved away
>> + *	    -ENXIO  - when the cpu the process was on has gone offline
>>    */
> 
> Hurm.. I don't think that was actually intended behaviour.

Yeah, I noticed we never return EAGAIN, so I figured I'd look for any 
other potential return values.

> As long as
> the task lives we ought to retry. Luckily I don't think the current code
> cares much, it'll loop again on the caller side.
> 
> With the exception of perf_cgroup_attach() that is, that might actually
> be broken because of this.
> 
>>   static int
>>   task_function_call(struct task_struct *p, remote_function_f func, void *info)
>> @@ -112,11 +112,15 @@ task_function_call(struct task_struct *p, remote_function_f func, void *info)
>>   	};
>>   	int ret;
>>   
>> -	do {
>> -		ret = smp_call_function_single(task_cpu(p), remote_function, &data, 1);
>> +	while (1) {
>> +		ret = smp_call_function_single(task_cpu(p), remote_function,
>> +					       &data, 1);
>>   		if (!ret)
>>   			ret = data.ret;
>> -	} while (ret == -EAGAIN);
>> +		if (ret != -EAGAIN)
>> +			break;
>> +		cond_resched();
>> +	}
> 
> So how about we make that:
> 
> 	for (;;) {
> 		ret = smp_call_function_single(task_cpu(p), remote_function, &data, 1);
> 		ret = !ret ? data.ret : -EAGAIN;
> 
> 		if (ret != -EAGAIN)
> 			break;
> 
> 		cond_resched();
> 	}
> 
> Or something like that, hmmm?

Can do.  I can put a comment in too.  /* Retry due to any failure in 
smp_call_function */ or something.

Thanks,

Barret




  reply	other threads:[~2020-04-14 21:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-14 19:03 perf: add cond_resched() to task_function_call() Barret Rhoden
2020-04-14 20:42 ` Peter Zijlstra
2020-04-14 21:16   ` Barret Rhoden [this message]
2020-04-14 22:29 ` Barret Rhoden
2020-05-01 18:22   ` [tip: perf/core] perf: Add " tip-bot2 for Barret Rhoden
2020-05-23  9:20     ` Jiri Olsa
2020-05-23  9:27       ` 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=bbec4199-37ef-fda2-b18f-3d485c1d5b70@google.com \
    --to=brho@google.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=syzbot+bb4935a5c09b5ff79940@syzkaller.appspotmail.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;
as well as URLs for NNTP newsgroup(s).