From patchwork Wed Nov 15 09:04:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 165213 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2412578vqg; Wed, 15 Nov 2023 01:06:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IHikzgbyZ0HdFXAT8X6I4gB+o/o4Q8NkqaU8dM5oUpVKN9QcSUA8bU5qO4TVF1xYC28LSNZ X-Received: by 2002:a17:902:e801:b0:1ca:8629:829f with SMTP id u1-20020a170902e80100b001ca8629829fmr5371688plg.26.1700039168461; Wed, 15 Nov 2023 01:06:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700039168; cv=none; d=google.com; s=arc-20160816; b=PrN372CuU8OMJy/ZK2IHNh9/3fOW68OVNACwvzGWZeafq7bMAAa3dTdZigOIhPZv1h KQoFDZjAjyKJD06egOau2nsxJD5q4o5qxU0An4pd+Ofn5403+rEYxIAKSyRvl89faY3F CvGJ8Xz8ohBjKwNxwb/Dn3d96SSxVC3HUtBEGzFGXEL8Quz1aefYrE44cIYhgC/30R9D USx/TbNGqzXMWbxhi5zObwW4NKbFLBSQwL8V8TRulHGOdx7r3yMKJ3zNzcvG3k2vD0zJ W4fmunt720/8CqLlWFtxRm0P5bivmHiruVDxr/DjtuTP1vDZEordhQpUp9or7wgDWZXk DTeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=CiagETb+EIhLnlRlKgxN+Qn60M9WIRvjphEzuDjgzB8=; fh=KFSO1avKpsj2PbLT7939+iqdBuUcdlAP4LSCNdUZQ/k=; b=d6AVNRvKAvuLigIz/ONcMBEr06Evs9fVclNHE7ZGboKOIVgEvGsKLZWmD3zkzm645V EtwcJoB8EzG4CTPZbz1KK2UhSXdgjtUNQ+1q0A8Jv/kUZqyqha5Qoo7YNkE+0Y6WNr9/ S21ziDfN5wu2rFDOZwa7FrVtkXSNhgmwdg0a2TFSYHXBARTDatJINQxYc4CUwnLyCHwx Co1dFdi9y4Kw9LqSvFVQnk+ATW59HdG41h37VNxGnRc+QSIqo7nAUPocZDckGUDbvtFT +Us/uYP17sOMO5JIr4M99FfugYScSHCJYO7hWeD/RPTRstXNp9j/DrPwGd+5MsmU+35J kVMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2hJwdjws; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=L0A82ts+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id h5-20020a170902f7c500b001c74d844254si9219302plw.101.2023.11.15.01.06.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 01:06:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2hJwdjws; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=L0A82ts+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id D66E78020A2C; Wed, 15 Nov 2023 01:05:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234695AbjKOJE4 (ORCPT + 28 others); Wed, 15 Nov 2023 04:04:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234675AbjKOJEy (ORCPT ); Wed, 15 Nov 2023 04:04:54 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38384116; Wed, 15 Nov 2023 01:04:51 -0800 (PST) Date: Wed, 15 Nov 2023 09:04:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1700039089; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CiagETb+EIhLnlRlKgxN+Qn60M9WIRvjphEzuDjgzB8=; b=2hJwdjws3Kr+gjDuD09s+jOlHs9Rp9CgB78iRIo0YqAXdNQ6ONvV9BjY7BT6dL2eGcVIQI NtBM6WYo34VXG9v5MerOuHd5qY13M4R/hD0Ui7/Mv40g+85S0pAMXef8Rd5qb3C334e8L4 CVuvqQbRnxD6Hdc3pSwTkaXiGEalXx7mndov7ojGGh78hOEIwUZhfOd1MEbxrC8qhmRGWq Abd986crt8YtZ+mtMfbvxnpZa5VDI8vS0T4AqhXHmc1Uw8pjytbqR2Kk+Yq7KbDotsih3j EC7wo4a2FK8R2iboMydLfv37nELV4CXs/ZhbMJ9kcNP3SzmP1t/Z+mjZoK7m0g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1700039089; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CiagETb+EIhLnlRlKgxN+Qn60M9WIRvjphEzuDjgzB8=; b=L0A82ts+pJSxc8152bNLSc3s6kkwShfbTfhTmkwTDYRiHwmabTrMfFmMBfRGANbhj6dc5+ nWZKeOEJv4gtfHDw== From: "tip-bot2 for Frederic Weisbecker" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/cpuidle: Comment about timers requirements VS idle handler Cc: Frederic Weisbecker , "Peter Zijlstra (Intel)" , "Rafael J. Wysocki" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231114193840.4041-2-frederic@kernel.org> References: <20231114193840.4041-2-frederic@kernel.org> MIME-Version: 1.0 Message-ID: <170003908886.391.2109617605485917006.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 15 Nov 2023 01:05:20 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782569500237745867 X-GMAIL-MSGID: 1782620270847218741 The following commit has been merged into the sched/core branch of tip: Commit-ID: dd5403869a40595eb953f12e8cd2bb57bb88bb67 Gitweb: https://git.kernel.org/tip/dd5403869a40595eb953f12e8cd2bb57bb88bb67 Author: Frederic Weisbecker AuthorDate: Tue, 14 Nov 2023 14:38:39 -05:00 Committer: Peter Zijlstra CommitterDate: Wed, 15 Nov 2023 09:57:51 +01:00 sched/cpuidle: Comment about timers requirements VS idle handler Add missing explanation concerning IRQs re-enablement constraints in the cpuidle path against timers. Signed-off-by: Frederic Weisbecker Signed-off-by: Peter Zijlstra (Intel) Acked-by: Rafael J. Wysocki Link: https://lkml.kernel.org/r/20231114193840.4041-2-frederic@kernel.org --- kernel/sched/idle.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index 565f837..3123192 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -258,6 +258,36 @@ static void do_idle(void) while (!need_resched()) { rmb(); + /* + * Interrupts shouldn't be re-enabled from that point on until + * the CPU sleeping instruction is reached. Otherwise an interrupt + * may fire and queue a timer that would be ignored until the CPU + * wakes from the sleeping instruction. And testing need_resched() + * doesn't tell about pending needed timer reprogram. + * + * Several cases to consider: + * + * - SLEEP-UNTIL-PENDING-INTERRUPT based instructions such as + * "wfi" or "mwait" are fine because they can be entered with + * interrupt disabled. + * + * - sti;mwait() couple is fine because the interrupts are + * re-enabled only upon the execution of mwait, leaving no gap + * in-between. + * + * - ROLLBACK based idle handlers with the sleeping instruction + * called with interrupts enabled are NOT fine. In this scheme + * when the interrupt detects it has interrupted an idle handler, + * it rolls back to its beginning which performs the + * need_resched() check before re-executing the sleeping + * instruction. This can leak a pending needed timer reprogram. + * If such a scheme is really mandatory due to the lack of an + * appropriate CPU sleeping instruction, then a FAST-FORWARD + * must instead be applied: when the interrupt detects it has + * interrupted an idle handler, it must resume to the end of + * this idle handler so that the generic idle loop is iterated + * again to reprogram the tick. + */ local_irq_disable(); if (cpu_is_offline(cpu)) {