Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13896008pxu; Mon, 4 Jan 2021 07:22:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJyrBTC9XKFIKgSnlBt4bXlRqySmT5E3va9m19elcZHaKLQXrXzlafb19JAWLOUEPIKHhlxs X-Received: by 2002:a17:906:2257:: with SMTP id 23mr41027140ejr.497.1609773770484; Mon, 04 Jan 2021 07:22:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609773770; cv=none; d=google.com; s=arc-20160816; b=qM05CNfB7Ad7iQEgz25J6QC4COjqN/Wn+IGv7DrJZvBcR0dtJhJqMuIgZtAb21S3S2 0uAgjihDuubungVufbsi4/1OxF00BPSeMhknCWHT0XI8guK42kepyoCoBSN7BCIbnsPC tLu83G2pxeHIJyRuXThX8pC14l7S0xvRtwvQxw4SebwM2qmceTnd3Gw3uqZCYpExYK1B 37hx1xh2yEpYS2XjtCnZHUL2R+mhDDRDQxM3ejoE1oqlDakgZIXAr2ZjllWRbLprcwkz folPcpXwn7wd5wiGf74d/FI8rfkkMPgngbEainXHJ/+e9AjxSkR/YR+UiyQS0Wya65ox YRSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=10UdGMJMomYlzzdQHEY62GVmhlNkXI6zfPu4lGgkeZ0=; b=LTPI3n5q1e6vsGaMQG0oEQtlQ/pXBV2fCntzOwI8tE/ah4PNSe33IEocYHSRIuMt9m RU4a0uViSOHyRQ1G2nBbCTNQlbJv74VL2tmPCZRoPI7u1z3V/TV2SbhrfK32JRRrH4eO nbUB1CEpvcnW3qRehhrEMsfq6ZC2YjwaA5g1sfyXb3IGZhSWkYYEIOPJh+RhQuheAcPT SEmPzdr0IqJaKrpUP9XPhNjWaCIaE4aXUx9//YzqH//RHNnxUizcBeKfRVAh4Wq1kOo/ 6ajgM8Zvik9A8tZY6ISlOeOjxcvwNnXC9Vc92vL5vfDc/RXP0TZpGQCjpyr3ilquaweG 1lFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=g+k9HGCe; 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 kt11si29212082ejb.445.2021.01.04.07.22.27; Mon, 04 Jan 2021 07:22:50 -0800 (PST) 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=k20201202 header.b=g+k9HGCe; 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 S1727225AbhADPVu (ORCPT + 99 others); Mon, 4 Jan 2021 10:21:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:54894 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726579AbhADPVt (ORCPT ); Mon, 4 Jan 2021 10:21:49 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id E366A221E5; Mon, 4 Jan 2021 15:21:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609773668; bh=HFmeWgP/ZwiP+hsm1k1sd6flGOowieQ4iCyWAlhoJv8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g+k9HGCekSuBIIVVZ/ISjvZonqSkNugJc5J5p4J/mSDFKTkdxuIdUMGN1QalOHEdk f7aRNnS1mdr8BczwxjxfrDMXpcUc8fYcPcQ9mj6jEcsdokhd8vOuR2qRHeI8vgS+YE DBDubISmg6gxHR6JrKrwimOmjBkWpGF5/KbhrVMlutD0AU0vW6wmBmZB1feFH/zvr7 j81hw8oarxzf6ewpFfIXn/ncGwaaUFtaQQmcqJNuR2+OGvyvoTkjRuOOxYAHnor5Tw iLQZS4ZULUhxhgUXgA8F4X2S3mSlUuMAmlVyPdvrRLow64PpXZ9/0n23trV8z4xeGj bB+6i6q/TFWew== From: Frederic Weisbecker To: Peter Zijlstra Cc: LKML , Frederic Weisbecker , "Rafael J . Wysocki" , Ingo Molnar , Fabio Estevam , stable@vger.kernel.org, Thomas Gleixner , "Paul E . McKenney" , Len Brown , Pengutronix Kernel Team , NXP Linux Team , Daniel Lezcano , Shawn Guo , Sascha Hauer Subject: [PATCH 1/4] sched/idle: Fix missing need_resched() check after rcu_idle_enter() Date: Mon, 4 Jan 2021 16:20:55 +0100 Message-Id: <20210104152058.36642-2-frederic@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210104152058.36642-1-frederic@kernel.org> References: <20210104152058.36642-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Entering RCU idle mode may cause a deferred wake up of an RCU NOCB_GP kthread (rcuog) to be serviced. Usually a wake up happening while running the idle task is spotted in one of the need_resched() checks carefully placed within the idle loop that can break to the scheduler. Unfortunately in default_idle_call(), the call to rcu_idle_enter() is already beyond the last need_resched() check and we may halt the CPU with a resched request unhandled, leaving the task hanging. Fix this with performing a last minute need_resched() check after calling rcu_idle_enter(). Reported-and-tested-by: Paul E. McKenney Reviewed-by: Rafael J. Wysocki Fixes: 96d3fd0d315a (rcu: Break call_rcu() deadlock involving scheduler and perf) Cc: stable@vger.kernel.org Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Ingo Molnar Signed-off-by: Frederic Weisbecker --- kernel/sched/idle.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index 305727ea0677..1af60dc50beb 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -109,15 +109,21 @@ void __cpuidle default_idle_call(void) rcu_idle_enter(); lockdep_hardirqs_on(_THIS_IP_); - arch_cpu_idle(); + /* + * Last need_resched() check must come after rcu_idle_enter() + * which may wake up RCU internal tasks. + */ + if (!need_resched()) { + arch_cpu_idle(); + raw_local_irq_disable(); + } /* - * OK, so IRQs are enabled here, but RCU needs them disabled to - * turn itself back on.. funny thing is that disabling IRQs - * will cause tracing, which needs RCU. Jump through hoops to - * make it 'work'. + * OK, so IRQs are enabled after arch_cpu_idle(), but RCU needs + * them disabled to turn itself back on.. funny thing is that + * disabling IRQs will cause tracing, which needs RCU. Jump through + * hoops to make it 'work'. */ - raw_local_irq_disable(); lockdep_hardirqs_off(_THIS_IP_); rcu_idle_exit(); lockdep_hardirqs_on(_THIS_IP_); -- 2.25.1