Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp753649ybt; Fri, 19 Jun 2020 12:52:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJbGDbjXNLSfgZa+nEfMYBBd1iNPWwr2fjKpThE7JCvyO5GOl6Djaq0Goql23s6zjrXNjo X-Received: by 2002:a17:906:5203:: with SMTP id g3mr5026759ejm.58.1592596350086; Fri, 19 Jun 2020 12:52:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592596350; cv=none; d=google.com; s=arc-20160816; b=CllDGz89Q7mjs/QO/xPELYZlXJ1RTOoMu6jLSxBqT0SbRnhCQxRU3G2J3Bcq7WJJ75 zBU4+9PIB0fZkXxL2HhNT2iR+9V3LNIGVWHsEDPnS5W7OdOy7gs1qgfDqXsjJ9GuNbOk rP0pJ9+kRS/Z6cQE6Y/xUW93teksQJOFpXNxb4xTuI0s25hZ7Feh0tNOMuNF7n0LhOHs OlarQZ+0ik9wsZTIFDexm6IkhaESWs+GJhKCYPbggeg1cJYsBic2oLHH502cfuKDE/UI 5FCDD0S7VS9OilXyUcE3fYQUqox3X3YzNYKOzYx9jEpAuy6PhDREkk0cw/dOPZpEAqQz FP0Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=phe6/PJlWfIlYdNc0CTU0W+V3+cg2mRMpOZW5vuySqg=; b=EGTabCAer3AmLd3x5mHjtF7WTzyWHqwuzu0agMklKjrcSomh91cvAwfnG1Q6NE5NmI y0QRhtavogEMkvvYvJbNf8t968rBmubzwb8Px3to5bVGfIi4UbZp+2o0X/XEVqigkUR/ HuMbVKYz2byJxhfATFrgdNoNvlLypQRKtn+QD1DeXMQPZgN6tbEwTHsMf4eWwOLd1pM+ gsEOYRuTeTYcQUmJNxCghD680OARcNAnrmpFL3FqmIhXnS7kFC1BsJobLHzmyEif8z9B 0p5Zq9C7nf7+vhF7a4SDseRLjLfmp9PI7ZM+EAarIYDTkdmWmHXmEmXf99QaP8CQPq2k CI2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bsb3rqaM; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 12si4423205edv.523.2020.06.19.12.52.05; Fri, 19 Jun 2020 12:52:30 -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=bsb3rqaM; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388248AbgFSOlm (ORCPT + 99 others); Fri, 19 Jun 2020 10:41:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:60154 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388244AbgFSOle (ORCPT ); Fri, 19 Jun 2020 10:41:34 -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 0DEB921582; Fri, 19 Jun 2020 14:41:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592577693; bh=lhdD1PiLme7UhYUKgbRViewWMsE28bVNHQ/k6U2U2AA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bsb3rqaMILGuDgfGCCBhKsj0X4SQZIQbXGpX1HU89GCfzCFR2aRwUx0rIJJqzBP3q POnw+RNljsmQ6PC3yQc2Ng9ui1y7++wdB10m0DEfu5VbiwLhMtF4sJxQZR3kUggKI/ V+QAPq3ofECoDvTjVYblD/gSLyIzYKEY6cqkP588= 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 4.9 050/128] perf: Add cond_resched() to task_function_call() Date: Fri, 19 Jun 2020 16:32:24 +0200 Message-Id: <20200619141622.847720330@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141620.148019466@linuxfoundation.org> References: <20200619141620.148019466@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 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 @@ -90,11 +90,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) @@ -107,11 +107,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; }