From mboxrd@z Thu Jan 1 00:00:00 1970 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=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 B8116C433E0 for ; Mon, 8 Jun 2020 23:56:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 978CD20801 for ; Mon, 8 Jun 2020 23:56:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591660595; bh=avWdFj37NMip2P2W0fcIikEE6L21xMfrdQzLbyRfW8k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=FAlDXDzFf2Fo89lcXh2x2hrKeZ+JHg+OKUvgeZwKeE+lPyyCnay/95/PKJ0ZIHk+I OTa/zmx8qc9UPzOBeTfZjvF/a3zIe0e45Vj7UZ3C1+3oPgezqLhRwJh+uSjOBLMEbd L0jg7pWD+L2nX/FidiNcUsHULS+vEN2lAACPaVQo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732746AbgFHX4e (ORCPT ); Mon, 8 Jun 2020 19:56:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:49314 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731535AbgFHXXm (ORCPT ); Mon, 8 Jun 2020 19:23:42 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1ACFD2074B; Mon, 8 Jun 2020 23:23:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591658622; bh=avWdFj37NMip2P2W0fcIikEE6L21xMfrdQzLbyRfW8k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=loFX7mVBYMBWFIzskup1q1ms6B6vqKk3ysmq0FbnNzzicv4EF1KvR/fyRzK9Cm9Hc NV+qr+A5Y5j/WLOvOg8R2WFNJYNYdfa207X1bBDO668KHTIzZkUIwpFXlNGkdoERJE rp79j1T4fD6vXoe8H3gLnPlcnGcsCNfLtEv1BPr0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Barret Rhoden , syzbot+bb4935a5c09b5ff79940@syzkaller.appspotmail.com, Peter Zijlstra , Sasha Levin Subject: [PATCH AUTOSEL 4.19 047/106] perf: Add cond_resched() to task_function_call() Date: Mon, 8 Jun 2020 19:21:39 -0400 Message-Id: <20200608232238.3368589-47-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608232238.3368589-1-sashal@kernel.org> References: <20200608232238.3368589-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Barret Rhoden [ Upstream commit 2ed6edd33a214bca02bd2b45e3fc3038a059436b ] 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: Sasha Levin --- kernel/events/core.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 21e3c65abc76..a17e6302ded5 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -94,11 +94,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) @@ -111,11 +111,16 @@ 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); - 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; } -- 2.25.1