From patchwork Tue Jun 16 15:35:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 224481 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17D3EC433DF for ; Tue, 16 Jun 2020 15:48:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E9CA820776 for ; Tue, 16 Jun 2020 15:48:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592322485; bh=DV1eG+bY7x696UP/Pb0uc8f2sQAeD4yGUDNfsEzAbek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=izt//mSblQFGAP3flSomUqdMEKI0C3lS1aVWHQwdFNw25Y4Q9wLJ1Z88JkFv5zLuZ fSYNLHwVtxPoNFKbR8iOvOZqJJeJM8VJd5gNbFAsZhdnkGMSguI82SAiIMuBDL73CP hNI/Oet9qiZ3+mBAnh8u567aAts4KFl9vodWxVAk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732378AbgFPPsD (ORCPT ); Tue, 16 Jun 2020 11:48:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:41950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732360AbgFPPsC (ORCPT ); Tue, 16 Jun 2020 11:48:02 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CC26220776; Tue, 16 Jun 2020 15:48:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592322481; bh=DV1eG+bY7x696UP/Pb0uc8f2sQAeD4yGUDNfsEzAbek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=frP36BZgk0eJ3WhkBn8pZgbsG2VPsGGslTncqDk3ZMCe+WTFVgk2P288Pj+fqlLpf U5WjTscI4xLlmVnrMlUrlgMlVcQKo3qR43Q0Ag7T0rrGmW0sGwRM3wopic8jqHF5Ch bchVlhObxceU4CQVFUDVJbG954EFDcTnpD6BU/x4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+bb4935a5c09b5ff79940@syzkaller.appspotmail.com, Barret Rhoden , "Peter Zijlstra (Intel)" Subject: [PATCH 5.7 148/163] perf: Add cond_resched() to task_function_call() Date: Tue, 16 Jun 2020 17:35:22 +0200 Message-Id: <20200616153113.894021545@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200616153106.849127260@linuxfoundation.org> References: <20200616153106.849127260@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Barret Rhoden commit 2ed6edd33a214bca02bd2b45e3fc3038a059436b upstream. 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. Reported-by: syzbot+bb4935a5c09b5ff79940@syzkaller.appspotmail.com Signed-off-by: Barret Rhoden Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20200414222920.121401-1-brho@google.com Signed-off-by: Greg Kroah-Hartman --- kernel/events/core.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -95,11 +95,11 @@ static void remote_function(void *data) * @info: the function call argument * * Calls the function @func when the task is currently running. This might - * be on the current CPU, which just calls the function directly + * be on the current CPU, which just calls the function directly. This will + * retry due to any failures in smp_call_function_single(), such as if the + * task_cpu() goes offline concurrently. * - * returns: @func return value, or - * -ESRCH - when the process isn't running - * -EAGAIN - when the process moved away + * returns @func return value or -ESRCH when the process isn't running */ static int task_function_call(struct task_struct *p, remote_function_f func, void *info) @@ -112,11 +112,16 @@ task_function_call(struct task_struct *p }; int ret; - do { - ret = smp_call_function_single(task_cpu(p), remote_function, &data, 1); - if (!ret) - ret = data.ret; - } while (ret == -EAGAIN); + for (;;) { + ret = smp_call_function_single(task_cpu(p), remote_function, + &data, 1); + ret = !ret ? data.ret : -EAGAIN; + + if (ret != -EAGAIN) + break; + + cond_resched(); + } return ret; }