Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1654644pxj; Wed, 19 May 2021 10:43:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxU02VVQR118jYTKMOptUZoIkZaehvcrNLRER7Xxx8vaLEZdxSPo3IJFdulBKmUk+KzPEK X-Received: by 2002:a05:6402:416:: with SMTP id q22mr239500edv.204.1621446218280; Wed, 19 May 2021 10:43:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621446218; cv=none; d=google.com; s=arc-20160816; b=npEMVEhKdYmRDyVH5g1Phlhd2nuirCSb6m7KdJcEYZ1w2SVnSdeJ7Y9X2jCnRSwQHX r3NNK3UxHc4T2Jkt6FZF6ZkSBe7MXrmaUR8CZf+6NVO1F08eqIYL6mWKUuR1AXiweB+M YXLlMS/2Yf+ma7n4hr6hSDrboMwRl7dY/Oou6WrRlgAlyScVJT46zvgV2XA7ZdHvBsI5 kBnKRZUfFaY+FeVZw+ypy4QdOYSLFNdmxwCmXV1wCu6DmoRRjaMhWE/u1HFppIBKr9/6 Pc5SZVPY63CzsyYqHHhChZ9NTLjIIxZgEDzH7TatEjYFxZ2neN9KJpXKbN2Wo6ZNtptN QxPQ== 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=O4M1tuPpeMcv+HwLI+koJa4o1Si/SzgLQivtStAuziI=; b=XUjVlVwq08zc8r/BT0sKgRJhk4J4KT59wAoWfC1n6dYROPbA0FW/kujFhEMaCc6KdR +YDV9X7+Ly6B6LKnuKt5FXhKUv89Daco7rrZCsnMtsvMfpWgLEWIjRPG8lndqpHkHaVV 9ONUQmIe8VUEtzZkT0m/gJ3qooFjnbRHggwnoeXv54sHa8YHg6XDT3n2mP1cGzXcxWLW RoPwIwL+KsN9ea/9Hfwst8cAGfLHxr31lacOvKFgS8tYqr03CbFvpdwNeP/jWYKjOSGo d3xMTWLY3gZNtyMum7DsIsTRIxmGTVCo8enzvUO2JNWisC8X0LHTiyv/VeL1iabwkJgf FjeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MMayGdvq; 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 a4si290600ejc.644.2021.05.19.10.43.14; Wed, 19 May 2021 10:43:38 -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=k20201202 header.b=MMayGdvq; 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 S1348225AbhERJuq (ORCPT + 99 others); Tue, 18 May 2021 05:50:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:50440 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242312AbhERJt4 (ORCPT ); Tue, 18 May 2021 05:49:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 23B95613F1; Tue, 18 May 2021 09:48:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621331311; bh=44h3JsYZ/KIsAP+Upj/qBCyu3PQIrAfBaeDZkj8kEHs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MMayGdvqj7sLozMbYFnwY2WFufoESelFZSH8VuLRTDX3yLwAATjm9J81bgPDOuugT hCTg2WgfvbgkYufvVeb6qBR1RxTWc5mKSSyDGC2a+ksgEFM/o4wU3UPORukgbOdirx XS1frfOXkyKZnlH/Ii+ARG8h7cFNv7BP21kof+VBHR5KYXRVQ6IRHC3tLCeC1xp1Wg 0s3eWa2ZL08a+qhYd73PdJwGSwbR9dYH3QW3noMKqynRPt+Jqgh18gDZMgfE+s9fIc ydGY2gtkHFAEJ3Rl/mLyW7P4N5vPGXKWmjuSWk3RRTWvkiytoyFyj12egmW3tIMlSu Gd2JZAmEk6fsg== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, Will Deacon , Catalin Marinas , Marc Zyngier , Greg Kroah-Hartman , Peter Zijlstra , Morten Rasmussen , Qais Yousef , Suren Baghdasaryan , Quentin Perret , Tejun Heo , Li Zefan , Johannes Weiner , Ingo Molnar , Juri Lelli , Vincent Guittot , "Rafael J. Wysocki" , kernel-team@android.com Subject: [PATCH v6 15/21] sched: Defer wakeup in ttwu() for unschedulable frozen tasks Date: Tue, 18 May 2021 10:47:19 +0100 Message-Id: <20210518094725.7701-16-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210518094725.7701-1-will@kernel.org> References: <20210518094725.7701-1-will@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Asymmetric systems may not offer the same level of userspace ISA support across all CPUs, meaning that some applications cannot be executed by some CPUs. As a concrete example, upcoming arm64 big.LITTLE designs do not feature support for 32-bit applications on both clusters. Although we take care to prevent explicit hot-unplug of all 32-bit capable CPUs on such a system, this is required when suspending on some SoCs where the firmware mandates that the suspend/resume operation is handled by CPU 0, which may not be capable of running 32-bit tasks. Consequently, there is a window on the resume path where no 32-bit capable CPUs are available for scheduling and waking up a 32-bit task will result in a scheduler BUG() due to failure of select_fallback_rq(): | kernel BUG at kernel/sched/core.c:2858! | Internal error: Oops - BUG: 0 [#1] PREEMPT SMP | ... | Call trace: | select_fallback_rq+0x4b0/0x4e4 | try_to_wake_up.llvm.4388853297126348405+0x460/0x5b0 | default_wake_function+0x1c/0x30 | autoremove_wake_function+0x1c/0x60 | __wake_up_common.llvm.11763074518265335900+0x100/0x1b8 | __wake_up+0x78/0xc4 | ep_poll_callback+0x20c/0x3fc Prevent wakeups of unschedulable frozen tasks in ttwu() and instead defer the wakeup to __thaw_tasks(), which runs only once all the secondary CPUs are back online. Signed-off-by: Will Deacon --- kernel/freezer.c | 10 +++++++++- kernel/sched/core.c | 13 +++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/kernel/freezer.c b/kernel/freezer.c index dc520f01f99d..8f3d950c2a87 100644 --- a/kernel/freezer.c +++ b/kernel/freezer.c @@ -11,6 +11,7 @@ #include #include #include +#include /* total number of freezing conditions in effect */ atomic_t system_freezing_cnt = ATOMIC_INIT(0); @@ -146,9 +147,16 @@ bool freeze_task(struct task_struct *p) void __thaw_task(struct task_struct *p) { unsigned long flags; + const struct cpumask *mask = task_cpu_possible_mask(p); spin_lock_irqsave(&freezer_lock, flags); - if (frozen(p)) + /* + * Wake up frozen tasks. On asymmetric systems where tasks cannot + * run on all CPUs, ttwu() may have deferred a wakeup generated + * before thaw_secondary_cpus() had completed so we generate + * additional wakeups here for tasks in the PF_FREEZER_SKIP state. + */ + if (frozen(p) || (frozen_or_skipped(p) && mask != cpu_possible_mask)) wake_up_process(p); spin_unlock_irqrestore(&freezer_lock, flags); } diff --git a/kernel/sched/core.c b/kernel/sched/core.c index d7d058fc012e..f5ff55786344 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3525,6 +3525,19 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) if (!(p->state & state)) goto unlock; +#ifdef CONFIG_FREEZER + /* + * If we're going to wake up a thread which may be frozen, then + * we can only do so if we have an active CPU which is capable of + * running it. This may not be the case when resuming from suspend, + * as the secondary CPUs may not yet be back online. See __thaw_task() + * for the actual wakeup. + */ + if (unlikely(frozen_or_skipped(p)) && + !cpumask_intersects(cpu_active_mask, task_cpu_possible_mask(p))) + goto unlock; +#endif + trace_sched_waking(p); /* We're going to change ->state: */ -- 2.31.1.751.gd2f1c929bd-goog