Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp110863ybg; Mon, 8 Jun 2020 17:54:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJye/ER9QB0B38hw29in5goWiagzzcwGVx0X2CPEJySSC10hjjqCaKDA3wn4PlpGN0G3mqCC X-Received: by 2002:a17:906:805a:: with SMTP id x26mr16596647ejw.458.1591664085448; Mon, 08 Jun 2020 17:54:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591664085; cv=none; d=google.com; s=arc-20160816; b=F0X9rnHbBabvu/B2gSvZ/ZRYJYuKAPQ+RVfJVTkgjZheVUE5g60FWdEQ7SSDPUoeIF RjtwEaHj4NUTRZUUqj6IzXtTi4yRwFmchyj8shxV8U0jRBcg5OHkDfrGZgZVD3Ke4tHM lRPztt8v/yecKYWwqC/2iSX0roM80j6wTeEZmwDCjGNLZMqG7saX0jyqE6zX2ku8Y0Pm ro1bghLaU2BcwtPVLlVQCj0P4giBtJ7ZsItTOlDT7cQJUVlrCkmpyNIaLOnXRzATnxSO JEQqCcw0SeXLJv2+59xmcRty0PdX750qE/Myq0Xy/Zn9GHjLMJrvSLgiTXb2/OPd/90N MgZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Mt+3cznXgKE67rWcnAP/41svmHsQYUYzIAIGknQQTDg=; b=v6igqQK+gXfa0uTF4DCdXkQOQSrSTg7pLYh7Izf6NRBRjmWaG4d16j0UTEDG2ULO56 p04ZDOjO94MVvHbb+qoy1qhnWdi3xhSQ3EQ3IxH6AuhpShmuzmLxvu6Y414JuhsJhNbS gNLeU8b8wfis+LpnerSOLhLyZKwTyK3cJyDasxfccaq9iLoJ7zNFfvfFaFMWR18oC+qY 5z9IV6jmWssUM5lBLBaP+qbYX+MJRiH7TiNKr5IoNu5+Bk1aMPF3jzRbRuFH6tMew0N+ TwFVwA+L30mtiqMI32pryNcYvy1K4U7kDcSGe6jGWuCmOkaemen3hswgHX411npb/JTv iXVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="snT6sf2/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cf23si9561344ejb.540.2020.06.08.17.54.23; Mon, 08 Jun 2020 17:54:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="snT6sf2/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728657AbgFHXK1 (ORCPT + 99 others); Mon, 8 Jun 2020 19:10:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:55008 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726939AbgFHXJS (ORCPT ); Mon, 8 Jun 2020 19:09:18 -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 02FCD208A9; Mon, 8 Jun 2020 23:09:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657757; bh=bPijKvbdkE4m5opaHN4/KMkGmc5AfHZ03wHvgv5RCjs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=snT6sf2/woAJFpDwv6GJn72OEZpW9uXahpFrj65V7Kj5/a+25/B1OyivBe/ugwGZE 8fpnk+8H8XRGtecuKqWaMW1qGsnzG7wRq8L59LycqMEkmcgsOz7my+oLSN47j1DuGT 9Brq0ePrFRBZPmnIj/t6NVZ79bL8eJGWvx6uu21g= 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 5.7 143/274] perf: Add cond_resched() to task_function_call() Date: Mon, 8 Jun 2020 19:03:56 -0400 Message-Id: <20200608230607.3361041-143-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-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 633b4ae72ed5..1dd91f960839 100644 --- 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, 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