From patchwork Mon Nov 25 13:20:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patryk Wlazlyn X-Patchwork-Id: 13884894 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67C6C1ABEBF; Mon, 25 Nov 2024 13:20:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732540849; cv=none; b=NUilGviX+Ctkxayi0uz7Xfx1G2nDna51toxZ/2C3cWi2gfXmLE3vouqyguis3yxiUjVtUAzaK2OsfiUhY8kFdS2XY/zFMfzt0bNKjNIdoZRb41FxPQl3PhRrtcKHR/qERuPt5zMK9jT6+UytWHarkSmqb+MTBEONKt3uF3tbtsI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732540849; c=relaxed/simple; bh=teDKZrKy/w1Opc/KP13wrYLNIVP1b7k45GEBotf70e0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TFP57cNCPIATcrOInCxa3PeOEGiTWSz1Cx7pXDyikqyRyuoic91jiPBlsKAAwyYRvyD75G5njomi2kVPeMoIJF1vgF5K3uMv630CpzCP2dn1rbcEL01AWebKcqKwERfimMcrTQ6bFBgnnsqRLWikBpJKP580mbpD5NH/PxeuZ/Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=cuuJ1Emg; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="cuuJ1Emg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1732540848; x=1764076848; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=teDKZrKy/w1Opc/KP13wrYLNIVP1b7k45GEBotf70e0=; b=cuuJ1EmgwWqW+2AwLWMg+T/hf5UvFLfDN370IycYqmxEN8sSFSbFcfx+ OptcUC1x7E+vsyh5d0uH1U7xILceoq5+0fVU/MW0zPwOgpw8VzomKwGCg DeN8MfFe7PnHkhiEUTO5QIzWboYJj7rjrg5KpyRiBI+xm5V93l1QHqpIK ZoKul0bryTjSGzSk6MCvFxCjH/LYAcxbWNgy5FKJAbMcM2UJJlQADyShz vV7hWmqGHfTQ96QMWenPpaQdwTR41U7R6y0ms/9+TkBT5PxRUMB6ZJPY/ hlbNG3ISwBO1vsCl7QpnUl3Q2387mPN/tsF+dGZjGcNWgYPOuB8+Vl9Zd w==; X-CSE-ConnectionGUID: GhvcXuxAREymYUO320xAnw== X-CSE-MsgGUID: GbuMMR30TxKeJ+4RUkn0ew== X-IronPort-AV: E=McAfee;i="6700,10204,11267"; a="43145430" X-IronPort-AV: E=Sophos;i="6.12,182,1728975600"; d="scan'208";a="43145430" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2024 05:20:47 -0800 X-CSE-ConnectionGUID: ULMhK4RAQjK4mHBa7pke3g== X-CSE-MsgGUID: ElAhKrukTC2vKpKFPMKCzQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,182,1728975600"; d="scan'208";a="91161674" Received: from bergbenj-mobl1.ger.corp.intel.com (HELO pwlazlyn-mobl1.intel.com) ([10.245.245.34]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2024 05:20:43 -0800 From: Patryk Wlazlyn To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael.j.wysocki@intel.com, len.brown@intel.com, artem.bityutskiy@linux.intel.com, dave.hansen@linux.intel.com, patryk.wlazlyn@linux.intel.com, peterz@infradead.org, tglx@linutronix.de, gautham.shenoy@amd.com Subject: [RFC PATCH v4 1/8] cpuidle: Do not return from cpuidle_play_dead() on callback failures Date: Mon, 25 Nov 2024 14:20:21 +0100 Message-ID: <20241125132029.7241-2-patryk.wlazlyn@linux.intel.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241125132029.7241-1-patryk.wlazlyn@linux.intel.com> References: <20241125132029.7241-1-patryk.wlazlyn@linux.intel.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: "Rafael J. Wysocki" If the :enter_dead() idle state callback fails for a certain state, there may be still a shallower state for which it will work. Because the only caller of cpuidle_play_dead(), native_play_dead(), falls back to hlt_play_dead() if it returns an error, it should better try all of the idle states for which :enter_dead() is present before failing, so change it accordingly. Also notice that the :enter_dead() state callback is not expected to return on success (the CPU should be "dead" then), so make cpuidle_play_dead() ignore its return value. Signed-off-by: Rafael J. Wysocki Reviewed-by: Mario Limonciello Tested-by: Mario Limonciello # 6.12-rc7 Reviewed-by: Gautham R. Shenoy --- drivers/cpuidle/cpuidle.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 06ace16f9e71..0835da449db8 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -69,11 +69,15 @@ int cpuidle_play_dead(void) if (!drv) return -ENODEV; - /* Find lowest-power state that supports long-term idle */ - for (i = drv->state_count - 1; i >= 0; i--) + for (i = drv->state_count - 1; i >= 0; i--) { if (drv->states[i].enter_dead) - return drv->states[i].enter_dead(dev, i); + drv->states[i].enter_dead(dev, i); + } + /* + * If :enter_dead() is successful, it will never return, so reaching + * here means that all of them failed above or were not present. + */ return -ENODEV; } From patchwork Mon Nov 25 13:20:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patryk Wlazlyn X-Patchwork-Id: 13884895 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06DF61ACDE8; Mon, 25 Nov 2024 13:20:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732540853; cv=none; b=A2wT0cNsiHn8mg2V5TfSrh4l6GCKmqe2Wg8T/fLV0+Ue3zCkDaXkhzBpBQILW7XMW5UymJ4ZgQOL11R7kpWgRRGrKpc4PEIYzp3+UfGQpZeokB3Bord0JPG3kdqoWHfiomPS4gbpWoJY8UHlmGkBHwPOk8qABAUB1V8/I8xX7Ew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732540853; c=relaxed/simple; bh=oWtQwGipsMqqo+z9NwC+tp18oJA88l1mfYAtb0kGkeU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uC7dDryW58+XfJ2M+6EC5OWHRVaFEUW2fxXP09QXVD1WBRUExC/dnTU3CHcjgM2dNBxCcfSXDl8Ulw61lu4wbLEtu0u90fwAJ+NIpoBQEmJ7qX0j5FOuteoF74z9KM+mGp8LiaGkKzghkkBVFLHnNbzOT1pVj7aKI4a7Aff+dGs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=jLW50sqh; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jLW50sqh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1732540852; x=1764076852; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oWtQwGipsMqqo+z9NwC+tp18oJA88l1mfYAtb0kGkeU=; b=jLW50sqh6kUq9f+jnMxT6YVV1Z82ppuT+roB5Ewcj+JWqdbYY7pjiVuT I6XCX11gLluIrrQYGK3ehIkyDLagFc+FmC+t3Dr6dXOZf4C1CmPkKGnIk cuIAj3PvHTx9QM/p0OaygazWWnVX76nG+VQcI0RWLDEYAeFpwTikczGMi EWNX9MCUHxrw3mjEhKUOp9axvHqh3z7V/U563NrkAjC5HBTw4KXt6mVZn RstPcY5kETsgOZ2h59Z6tu9iyy/PhmFsPUC323qmrvuHtDPe8gXuqGlOk 8GIPW4IQxSJp+op/HxPQ8pVaxw7yZEYwLFCBGq9ziiWirINhKXsDrDqke Q==; X-CSE-ConnectionGUID: 1slZmeGVRaOpJFCAR7uZEw== X-CSE-MsgGUID: mXOcVVR0RGeCsLxCDct7lw== X-IronPort-AV: E=McAfee;i="6700,10204,11267"; a="43145444" X-IronPort-AV: E=Sophos;i="6.12,182,1728975600"; d="scan'208";a="43145444" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2024 05:20:52 -0800 X-CSE-ConnectionGUID: RrzuxBCFQsGge6htfLMmsQ== X-CSE-MsgGUID: qRPbCf7vSD2MlJzrA6UvQA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,182,1728975600"; d="scan'208";a="91161688" Received: from bergbenj-mobl1.ger.corp.intel.com (HELO pwlazlyn-mobl1.intel.com) ([10.245.245.34]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2024 05:20:47 -0800 From: Patryk Wlazlyn To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael.j.wysocki@intel.com, len.brown@intel.com, artem.bityutskiy@linux.intel.com, dave.hansen@linux.intel.com, patryk.wlazlyn@linux.intel.com, peterz@infradead.org, tglx@linutronix.de, gautham.shenoy@amd.com Subject: [RFC PATCH v4 2/8] cpuidle: Change :enter_dead() driver callback return type to void Date: Mon, 25 Nov 2024 14:20:22 +0100 Message-ID: <20241125132029.7241-3-patryk.wlazlyn@linux.intel.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241125132029.7241-1-patryk.wlazlyn@linux.intel.com> References: <20241125132029.7241-1-patryk.wlazlyn@linux.intel.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: "Rafael J. Wysocki" After a previous change, cpuidle_play_dead(), which is the only caller of idle state :enter_dead() callbacks, ignores their return values, so they may as well be void. Suggested-by: Peter Zijlstra Signed-off-by: Rafael J. Wysocki Reviewed-by: Gautham R. Shenoy Reviewed-by: Mario Limonciello --- drivers/acpi/processor_idle.c | 7 ++----- include/linux/cpuidle.h | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index 831fa4a12159..ce728cf7e301 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -578,7 +578,7 @@ static void __cpuidle acpi_idle_do_entry(struct acpi_processor_cx *cx) * @dev: the target CPU * @index: the index of suggested state */ -static int acpi_idle_play_dead(struct cpuidle_device *dev, int index) +static void acpi_idle_play_dead(struct cpuidle_device *dev, int index) { struct acpi_processor_cx *cx = per_cpu(acpi_cstate[index], dev->cpu); @@ -591,11 +591,8 @@ static int acpi_idle_play_dead(struct cpuidle_device *dev, int index) else if (cx->entry_method == ACPI_CSTATE_SYSTEMIO) { io_idle(cx->address); } else - return -ENODEV; + return; } - - /* Never reached */ - return 0; } static __always_inline bool acpi_idle_fallback_to_c1(struct acpi_processor *pr) diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index 3183aeb7f5b4..a9ee4fe55dcf 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -61,7 +61,7 @@ struct cpuidle_state { struct cpuidle_driver *drv, int index); - int (*enter_dead) (struct cpuidle_device *dev, int index); + void (*enter_dead) (struct cpuidle_device *dev, int index); /* * CPUs execute ->enter_s2idle with the local tick or entire timekeeping From patchwork Mon Nov 25 13:20:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patryk Wlazlyn X-Patchwork-Id: 13884896 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 977421AE005; Mon, 25 Nov 2024 13:20:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732540858; cv=none; b=osWsuaDxwWYBmUAfn55OxElzQ2MMlUKmtLZCIOngJgaEClfNtD+QaMZlY0RMZ4JpCd/hDO3JOjYW6gReTPLwHjeyETTty19T3xxAAnEylQaUbXDXeNXDVZSFeyu7v/3BYD1JU1feIAgbe9sW2ghIoIEhb5v1mBIgLd1Qg/lp4R8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732540858; c=relaxed/simple; bh=ySAUFoVjetQHqEoSldpuSYe7PRSTVKbbx/RG/H/AMIw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EfhzA5M24qXsbE0UYVTHE0kMKIT2mO1tvZbtUontqJo6WbQ0fQDXJQDers4nMnaTidP2VkIxgf7PEPOuCQC23wyYsDF3Kbvk36HuntXjjLwU/bUWkh0ptP7ZZvXG2aPlJstjGs6a4tUTXSZsS37CIcAqnyckn17SOSUkN0Upu2U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=TE2u2/z0; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="TE2u2/z0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1732540857; x=1764076857; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ySAUFoVjetQHqEoSldpuSYe7PRSTVKbbx/RG/H/AMIw=; b=TE2u2/z0Tbs7FyFbAgITe1Kfgn8/Xwlu+DUJu1/tXrQWeF9QIJPV4wVs GOhVyIt3R4ghrWwBaYpi/syhbALTslTf/TZ3s2Po4BJL0UDIEqu3IGR9N 3wVG8hdmIcXxk8TXdWpJsQvjF4jg9rpiBG9HT9xZ058dDtZelt/UAwLLx l5kNhNB7Kf76EylsbiZmVztNG+aHSCvYfKI9nhQionrNbcvmi2Nj83cwr le6tN2MBEFXM6FUynhc3BTC1gMagcKqgmOenXxeF7W6LTwC8G48XBwrUt BfEkTarc5IhObMBDisimgF7r3XiEXndeNbsAojpgMrNnPuGdU+89i0e42 A==; X-CSE-ConnectionGUID: DrOZguQBTSqCeLTK0UBZDA== X-CSE-MsgGUID: Zw+uMc7oSe2U2CdggNLAEg== X-IronPort-AV: E=McAfee;i="6700,10204,11267"; a="43145454" X-IronPort-AV: E=Sophos;i="6.12,182,1728975600"; d="scan'208";a="43145454" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2024 05:20:57 -0800 X-CSE-ConnectionGUID: p/czT652RnGVEN9V36iX4w== X-CSE-MsgGUID: Kl1SW9T8RA+j61kxDK+9Vg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,182,1728975600"; d="scan'208";a="91161693" Received: from bergbenj-mobl1.ger.corp.intel.com (HELO pwlazlyn-mobl1.intel.com) ([10.245.245.34]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2024 05:20:52 -0800 From: Patryk Wlazlyn To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael.j.wysocki@intel.com, len.brown@intel.com, artem.bityutskiy@linux.intel.com, dave.hansen@linux.intel.com, patryk.wlazlyn@linux.intel.com, peterz@infradead.org, tglx@linutronix.de, gautham.shenoy@amd.com Subject: [RFC PATCH v4 3/8] ACPI: processor_idle: Use acpi_idle_play_dead() for all C-states Date: Mon, 25 Nov 2024 14:20:23 +0100 Message-ID: <20241125132029.7241-4-patryk.wlazlyn@linux.intel.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241125132029.7241-1-patryk.wlazlyn@linux.intel.com> References: <20241125132029.7241-1-patryk.wlazlyn@linux.intel.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: "Rafael J. Wysocki" Notice that acpi_processor_setup_cstates() can set state->enter_dead to acpi_idle_play_dead() for all C-states unconditionally and remove the confusing C-state type check done before setting it. No intentional functional impact. Suggested-by: Peter Zijlstra Signed-off-by: Rafael J. Wysocki Reviewed-by: Mario Limonciello Tested-by: Mario Limonciello # 6.12-rc7 Acked-by: Peter Zijlstra (Intel) Reviewed-by: Gautham R. Shenoy --- drivers/acpi/processor_idle.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index ce728cf7e301..698897b29de2 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -800,12 +800,12 @@ static int acpi_processor_setup_cstates(struct acpi_processor *pr) state->enter = acpi_idle_enter; state->flags = 0; - if (cx->type == ACPI_STATE_C1 || cx->type == ACPI_STATE_C2 || - cx->type == ACPI_STATE_C3) { - state->enter_dead = acpi_idle_play_dead; - if (cx->type != ACPI_STATE_C3) - drv->safe_state_index = count; - } + + state->enter_dead = acpi_idle_play_dead; + + if (cx->type == ACPI_STATE_C1 || cx->type == ACPI_STATE_C2) + drv->safe_state_index = count; + /* * Halt-induced C1 is not good for ->enter_s2idle, because it * re-enables interrupts on exit. Moreover, C1 is generally not From patchwork Mon Nov 25 13:20:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patryk Wlazlyn X-Patchwork-Id: 13884897 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0072B1ABEA0; Mon, 25 Nov 2024 13:21:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732540864; cv=none; b=ev3ndn4OFPYrZgrFYbRBmUM8SVvsAYhWpLIEQLy4S6SRbY9Sy5vE8TdVp3/cQudKzhJFhua7mKgfel7grR2buMvYP5fbd0/DTDbGsg7iOmWUCuAX4om4oNuRZXukF0D1CL6jjrWRyH+w6g92qxxRYpVN7b5mrCnm02XRV7fb6ug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732540864; c=relaxed/simple; bh=CeeQ0dFzv1BrbotXihAUXKkfZ/dZKppVe1itQis5KWg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NX/nVDUWefucq7sQE2moOYfc15EXPO2xBiy8dR9yV5wWCe7D2CpSSmTO6rdSPwY/L7yDUj/ZMbWmYtOi1iVbfu8QDh/QRJPOrhEU+Y/JGnAJafGs8yh+4JT0O8bk9YTQqlwIDZiIJlvwSKzoKLtFWZLESxJD26Tj2So8lDRxGZE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=U30kob43; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="U30kob43" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1732540862; x=1764076862; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CeeQ0dFzv1BrbotXihAUXKkfZ/dZKppVe1itQis5KWg=; b=U30kob43mF6SLwQctFBaJL3UcQFxmCsvPQajhyGQzd344dQbpKx+97LK sMIX6yZhLKaV9QKvodYn9PAMtkUK2OT+e8rSsdeAj45VHYGFWMHkWRIHL I3uuHsR64T7b4uyDrNgEuL6cS+d0APBWlLmYtwCWGcb2tIBnuq25jdKC0 k2ri3UHAau2LRDd8lyoPWXKF4qiHBJM5dI43cJ0nKmY7Qjs9sFUqwsrY9 LvpyxZGjd0Nad64DLoBOHlxA6aF7BiDETQVVJDcq6IK26TsmzHHF+Jk5d sRGkKro2fm/K/xx/ONhC+mE/b6Omeg8tno23bsb3zA5AJs5wvmHDjRd4B w==; X-CSE-ConnectionGUID: qJUmiTXhQ1m+/ayUZIBb6g== X-CSE-MsgGUID: 415JR6/GRkGXqTsG+F1NAg== X-IronPort-AV: E=McAfee;i="6700,10204,11267"; a="43145470" X-IronPort-AV: E=Sophos;i="6.12,182,1728975600"; d="scan'208";a="43145470" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2024 05:21:02 -0800 X-CSE-ConnectionGUID: 16p4D08vSTmZUc1NQPqkgQ== X-CSE-MsgGUID: x+3URJXKR+2IQQawBLKnbA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,182,1728975600"; d="scan'208";a="91161711" Received: from bergbenj-mobl1.ger.corp.intel.com (HELO pwlazlyn-mobl1.intel.com) ([10.245.245.34]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2024 05:20:57 -0800 From: Patryk Wlazlyn To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael.j.wysocki@intel.com, len.brown@intel.com, artem.bityutskiy@linux.intel.com, dave.hansen@linux.intel.com, patryk.wlazlyn@linux.intel.com, peterz@infradead.org, tglx@linutronix.de, gautham.shenoy@amd.com Subject: [RFC PATCH v4 4/8] x86/smp: Allow calling mwait_play_dead with arbitrary hint Date: Mon, 25 Nov 2024 14:20:24 +0100 Message-ID: <20241125132029.7241-5-patryk.wlazlyn@linux.intel.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241125132029.7241-1-patryk.wlazlyn@linux.intel.com> References: <20241125132029.7241-1-patryk.wlazlyn@linux.intel.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The MWAIT instruction needs different hints on different CPUs to reach the most specific idle states. The current hint calculation* in mwait_play_dead() code works in practice on current hardware, but it fails on a recent one, Intel's Sierra Forest and possibly some future ones. Those newer CPUs' power efficiency suffers when the CPU is put offline. * The current calculation is the for loop inspecting edx in mwait_play_dead() The current implementation for looking up the mwait hint for the deepest cstate, in mwait_play_dead() code works by inspecting CPUID leaf 0x5 and calculates the mwait hint based on the number of reported substates. This approach depends on the hints associated with them to be continuous in the range [0, NUM_SUBSTATES-1]. This continuity is not documented and is not met on the recent Intel platforms. For example, Intel's Sierra Forest report two cstates with two substates each in cpuid leaf 5: Name* target cstate target subcstate (mwait hint) =========================================================== C1 0x00 0x00 C1E 0x00 0x01 -- 0x10 ---- C6S 0x20 0x22 C6P 0x20 0x23 -- 0x30 ---- /* No more (sub)states all the way down to the end. */ =========================================================== * Names of the cstates are not included in the CPUID leaf 0x5, they are taken from the product specific documentation. Notice that hints 0x20 and 0x21 are skipped entirely for the target cstate 0x20 (C6), being a cause of the problem for the current cpuid leaf 0x5 algorithm. Allow cpuidle code to provide mwait play dead loop with known, mwait hint for the deepest idle state on a given platform, skipping the cpuid based calculation. Signed-off-by: Patryk Wlazlyn --- arch/x86/include/asm/smp.h | 3 ++ arch/x86/kernel/smpboot.c | 86 ++++++++++++++++++++------------------ 2 files changed, 49 insertions(+), 40 deletions(-) diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h index ca073f40698f..d12fab4a83c5 100644 --- a/arch/x86/include/asm/smp.h +++ b/arch/x86/include/asm/smp.h @@ -114,6 +114,7 @@ void wbinvd_on_cpu(int cpu); int wbinvd_on_all_cpus(void); void smp_kick_mwait_play_dead(void); +void mwait_play_dead_with_hint(unsigned long hint); void native_smp_send_reschedule(int cpu); void native_send_call_func_ipi(const struct cpumask *mask); @@ -164,6 +165,8 @@ static inline struct cpumask *cpu_llc_shared_mask(int cpu) { return (struct cpumask *)cpumask_of(0); } + +static inline void mwait_play_dead_with_hint(unsigned long eax_hint) { } #endif /* CONFIG_SMP */ #ifdef CONFIG_DEBUG_NMI_SELFTEST diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index b5a8f0891135..d0464c7a0af5 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -1272,13 +1272,57 @@ void play_dead_common(void) local_irq_disable(); } +void __noreturn mwait_play_dead_with_hint(unsigned long eax_hint) +{ + struct mwait_cpu_dead *md = this_cpu_ptr(&mwait_cpu_dead); + + /* Set up state for the kexec() hack below */ + md->status = CPUDEAD_MWAIT_WAIT; + md->control = CPUDEAD_MWAIT_WAIT; + + wbinvd(); + + while (1) { + /* + * The CLFLUSH is a workaround for erratum AAI65 for + * the Xeon 7400 series. It's not clear it is actually + * needed, but it should be harmless in either case. + * The WBINVD is insufficient due to the spurious-wakeup + * case where we return around the loop. + */ + mb(); + clflush(md); + mb(); + __monitor(md, 0, 0); + mb(); + __mwait(eax_hint, 0); + + if (READ_ONCE(md->control) == CPUDEAD_MWAIT_KEXEC_HLT) { + /* + * Kexec is about to happen. Don't go back into mwait() as + * the kexec kernel might overwrite text and data including + * page tables and stack. So mwait() would resume when the + * monitor cache line is written to and then the CPU goes + * south due to overwritten text, page tables and stack. + * + * Note: This does _NOT_ protect against a stray MCE, NMI, + * SMI. They will resume execution at the instruction + * following the HLT instruction and run into the problem + * which this is trying to prevent. + */ + WRITE_ONCE(md->status, CPUDEAD_MWAIT_KEXEC_HLT); + while(1) + native_halt(); + } + } +} + /* * We need to flush the caches before going to sleep, lest we have * dirty data in our caches when we come back up. */ static inline void mwait_play_dead(void) { - struct mwait_cpu_dead *md = this_cpu_ptr(&mwait_cpu_dead); unsigned int eax, ebx, ecx, edx; unsigned int highest_cstate = 0; unsigned int highest_subcstate = 0; @@ -1316,45 +1360,7 @@ static inline void mwait_play_dead(void) (highest_subcstate - 1); } - /* Set up state for the kexec() hack below */ - md->status = CPUDEAD_MWAIT_WAIT; - md->control = CPUDEAD_MWAIT_WAIT; - - wbinvd(); - - while (1) { - /* - * The CLFLUSH is a workaround for erratum AAI65 for - * the Xeon 7400 series. It's not clear it is actually - * needed, but it should be harmless in either case. - * The WBINVD is insufficient due to the spurious-wakeup - * case where we return around the loop. - */ - mb(); - clflush(md); - mb(); - __monitor(md, 0, 0); - mb(); - __mwait(eax, 0); - - if (READ_ONCE(md->control) == CPUDEAD_MWAIT_KEXEC_HLT) { - /* - * Kexec is about to happen. Don't go back into mwait() as - * the kexec kernel might overwrite text and data including - * page tables and stack. So mwait() would resume when the - * monitor cache line is written to and then the CPU goes - * south due to overwritten text, page tables and stack. - * - * Note: This does _NOT_ protect against a stray MCE, NMI, - * SMI. They will resume execution at the instruction - * following the HLT instruction and run into the problem - * which this is trying to prevent. - */ - WRITE_ONCE(md->status, CPUDEAD_MWAIT_KEXEC_HLT); - while(1) - native_halt(); - } - } + mwait_play_dead_with_hint(eax); } /* From patchwork Mon Nov 25 13:20:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patryk Wlazlyn X-Patchwork-Id: 13884898 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CC6D1ABECD; Mon, 25 Nov 2024 13:21:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732540868; cv=none; b=ajiTkgIdH++nyueq45qNi5jHkDWm+07S+NfC6opWX2vBmwrUTNjaLpl0KyXIa6NRqwnLw2i0BAGezVWB7HbyrNr1cY/+4oateoI0fVWi9cDiLPpJLbm+/Kp806Gll8Q/VAAOD0S/eCPxSrJV2r0qH6Zsr695D21B94JX/uxGoyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732540868; c=relaxed/simple; bh=GLH12fT3/lYQq3EY/HgfN3IRPf9HflYri+2sOBdLQmk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mQ3wMdoawlloppB1mj0oPCYyOi1yK5HZdAt2KUPv4nuLpL+mEWNpTE+cBwu+WeMzIulwGcobQAG9E81ge4nLLj0OxDwkD7RGWAwpXnrG7nnluX3xmLF/uqGg+bUDorEg0sgvgw2TKqlYGVu70SzO88pQiaEkYS5amoCt+y4JuqA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ksp73htM; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ksp73htM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1732540867; x=1764076867; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GLH12fT3/lYQq3EY/HgfN3IRPf9HflYri+2sOBdLQmk=; b=ksp73htM8WU8Vuf8GnK19Y+/MgLsEkEIkifg7eCUx8/wh98UBnkuo2nN /lfFNqMjAeU09ivbRJv3sw7WR4jTZhwYeaN26+RoznuNgm+C2Co8UxJXx YcTVN3hcDF/T0A4xuSu+iqsVoUuSpX3Iwu9MTab5WTiqwPKSfiSKanD0n Hao0N2Aqi2c+gcileJ+Rq+B7ebNEDD/+wDslRd2n+jF6eOw/MRxHi5orY hRX0DtYfEWsYUldkGl5mEtdhynQQOXn2aqIVqXtndAdDfqZuusWCm2Lbn m94ehMRXtCI2kis21959aSaCeDZgsDRvKYKJ7CkAB1g7esao2su/+2FYR w==; X-CSE-ConnectionGUID: HNiWrji+Rkaufbl8lTRpzA== X-CSE-MsgGUID: IRvSvEZ4SzqnjI1S3kP0Cg== X-IronPort-AV: E=McAfee;i="6700,10204,11267"; a="43145483" X-IronPort-AV: E=Sophos;i="6.12,182,1728975600"; d="scan'208";a="43145483" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2024 05:21:06 -0800 X-CSE-ConnectionGUID: YbOhICPrS3WeQATz5ZdX2g== X-CSE-MsgGUID: b235ZwNMTn6wAJ3pOUVadw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,182,1728975600"; d="scan'208";a="91161742" Received: from bergbenj-mobl1.ger.corp.intel.com (HELO pwlazlyn-mobl1.intel.com) ([10.245.245.34]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2024 05:21:02 -0800 From: Patryk Wlazlyn To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael.j.wysocki@intel.com, len.brown@intel.com, artem.bityutskiy@linux.intel.com, dave.hansen@linux.intel.com, patryk.wlazlyn@linux.intel.com, peterz@infradead.org, tglx@linutronix.de, gautham.shenoy@amd.com Subject: [RFC PATCH v4 5/8] x86/smp native_play_dead: Prefer cpuidle_play_dead() over mwait_play_dead() Date: Mon, 25 Nov 2024 14:20:25 +0100 Message-ID: <20241125132029.7241-6-patryk.wlazlyn@linux.intel.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241125132029.7241-1-patryk.wlazlyn@linux.intel.com> References: <20241125132029.7241-1-patryk.wlazlyn@linux.intel.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The algorithm based on cpuid leaf 0x5 in the mwait_play_dead(), for looking up the mwait hint for the deepest cstate may calculate the wrong hint on recent Intel x86 platforms. Prefer cpuidle_play_dead() over the generic mwait_play_dead() loop and only fallback to the later in case of missing appropriate enter_dead() handler. Signed-off-by: Patryk Wlazlyn --- arch/x86/kernel/smpboot.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index d0464c7a0af5..2627b56fb9bc 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -1413,9 +1413,10 @@ void native_play_dead(void) play_dead_common(); tboot_shutdown(TB_SHUTDOWN_WFS); + /* The first successful play_dead() will not return */ + cpuidle_play_dead(); mwait_play_dead(); - if (cpuidle_play_dead()) - hlt_play_dead(); + hlt_play_dead(); } #else /* ... !CONFIG_HOTPLUG_CPU */ From patchwork Mon Nov 25 13:20:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patryk Wlazlyn X-Patchwork-Id: 13884899 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 528D91B21B8; Mon, 25 Nov 2024 13:21:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732540871; cv=none; b=afqNU7fo/iUYeUBYaAHWhoN0gZzoKwH58wPQZQlvnFg/8OkQ0ArHywvDcFW8OuW2wELmuJ3IF+9sWC+unaesqAM/FjgmQ+wL6qL2ZO4ve4cT1tG6WLOixqG6Isbqoii1X1Ko0GBVJVnyB0Fxqer57s92K0FpQFqrHCj7sAsLhl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732540871; c=relaxed/simple; bh=nK+FjxLYCzmOviioR/C/S44LMaHEzHb2qOLPW+eGqHY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YlQfmQ5PpEgbl4pqXXMSH6F+SU8uu3T8Mq2sfg5pVpSf70GqlcwrvrvhJrPLWD3USCibFkUFImFMTo3bPzE4amslfRPEbeqyGJHnpL5DbnOzTgnV5NVxgp1bEZ/O0u1J1+JPxZGmTRoL0JjRhUKkBgqrZairUuIE8IGTFlVXlG0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=MV4RL0o3; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MV4RL0o3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1732540871; x=1764076871; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nK+FjxLYCzmOviioR/C/S44LMaHEzHb2qOLPW+eGqHY=; b=MV4RL0o3HTizuI//mbA9mssnSwAxS928woD7PVc7RrElsX2iqK2G7pH4 M5J+w23gAXTI+6aZ7Oi7smg8Y1Ut+EYjn5iD0G0vYj0Rouy8jqiGrMNN9 UAz1LHrYMU4C1aq8Z1GR3+tHDtvBwFuiimK+u4XNv/TMYeeHTOHX8tWPv AtVjLkppjKAhHpJonmrPSnNd7y8QQT5t9kpWCtwT2jmCV8QqYEzYAXfm6 My6MM5/zGDuXlHQP3feQemvTGRELQ21Qi1XcT1KiDtI6y5mRjvmTvmmAx NnGa5Z5FV6uARGKT5st71WwXMb9YDH0HCyjanPTqIffecLKZLx8u3qX/E Q==; X-CSE-ConnectionGUID: M5lU2zavQEq0k61rKR9krw== X-CSE-MsgGUID: f3ts6vNKTCyFppUxo8yl/g== X-IronPort-AV: E=McAfee;i="6700,10204,11267"; a="43145491" X-IronPort-AV: E=Sophos;i="6.12,182,1728975600"; d="scan'208";a="43145491" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2024 05:21:10 -0800 X-CSE-ConnectionGUID: lN4oCRZ6RUuEvF/X2Drt4Q== X-CSE-MsgGUID: K2Ita2/6QzSaHz6fpDtnmQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,182,1728975600"; d="scan'208";a="91161766" Received: from bergbenj-mobl1.ger.corp.intel.com (HELO pwlazlyn-mobl1.intel.com) ([10.245.245.34]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2024 05:21:06 -0800 From: Patryk Wlazlyn To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael.j.wysocki@intel.com, len.brown@intel.com, artem.bityutskiy@linux.intel.com, dave.hansen@linux.intel.com, patryk.wlazlyn@linux.intel.com, peterz@infradead.org, tglx@linutronix.de, gautham.shenoy@amd.com Subject: [RFC PATCH v4 6/8] intel_idle: Provide enter_dead() handler for SRF Date: Mon, 25 Nov 2024 14:20:26 +0100 Message-ID: <20241125132029.7241-7-patryk.wlazlyn@linux.intel.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241125132029.7241-1-patryk.wlazlyn@linux.intel.com> References: <20241125132029.7241-1-patryk.wlazlyn@linux.intel.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Intel's Sierra Forest report two C6 substates in cpuid leaf 5: C6S (hint 0x22) C6SP (hint 0x23) Hints 0x20 and 0x21 are skipped entirely, causing the generic implementation in mwait_play_dead() to compute the wrong hint, when looking for the deepest cstate. As a result, package with an offlined CPU can never reach PC6. Define the enter_dead() handler for SRF. Signed-off-by: Patryk Wlazlyn --- drivers/idle/intel_idle.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c index ac4d8faa3886..c2ca01e74add 100644 --- a/drivers/idle/intel_idle.c +++ b/drivers/idle/intel_idle.c @@ -56,6 +56,7 @@ #include #include #include +#include #define INTEL_IDLE_VERSION "0.5.1" @@ -227,6 +228,16 @@ static __cpuidle int intel_idle_s2idle(struct cpuidle_device *dev, return 0; } +static __cpuidle void intel_idle_enter_dead(struct cpuidle_device *dev, + int index) +{ + struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev); + struct cpuidle_state *state = &drv->states[index]; + unsigned long eax = flg2MWAIT(state->flags); + + mwait_play_dead_with_hint(eax); +} + /* * States are indexed by the cstate number, * which is also the index into the MWAIT hint array. @@ -1391,6 +1402,7 @@ static struct cpuidle_state srf_cstates[] __initdata = { .exit_latency = 1, .target_residency = 1, .enter = &intel_idle, + .enter_dead = &intel_idle_enter_dead, .enter_s2idle = intel_idle_s2idle, }, { .name = "C1E", @@ -1399,6 +1411,7 @@ static struct cpuidle_state srf_cstates[] __initdata = { .exit_latency = 2, .target_residency = 10, .enter = &intel_idle, + .enter_dead = &intel_idle_enter_dead, .enter_s2idle = intel_idle_s2idle, }, { .name = "C6S", @@ -1408,6 +1421,7 @@ static struct cpuidle_state srf_cstates[] __initdata = { .exit_latency = 270, .target_residency = 700, .enter = &intel_idle, + .enter_dead = &intel_idle_enter_dead, .enter_s2idle = intel_idle_s2idle, }, { .name = "C6SP", @@ -1417,6 +1431,7 @@ static struct cpuidle_state srf_cstates[] __initdata = { .exit_latency = 310, .target_residency = 900, .enter = &intel_idle, + .enter_dead = &intel_idle_enter_dead, .enter_s2idle = intel_idle_s2idle, }, { .enter = NULL } From patchwork Mon Nov 25 13:20:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patryk Wlazlyn X-Patchwork-Id: 13884900 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF3221B393E; Mon, 25 Nov 2024 13:21:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732540876; cv=none; b=uf7KC2LtA21BmObzHeKbDCQJpYIZIkRpEBSzNW+xAXRMovfw2rwwxiP2qN+LHHOQDVk9zNo9mB4rIgsOKWJTA1iyyeAdcS1YLWOxyXOQ9QwvmatXNf04Ex/p0B2QEm5ruJlApMCZQ/wgMTGEuDmHwtl3e30gE6DEgTS6XfJMg6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732540876; c=relaxed/simple; bh=VF9mEYDyF8AVV2/MlyLqhDnzQPABSbqh+jPmpb/z4GA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L8h4T9Y+3rXr10wrB10iAasfm+ef6AP/+Aggmemue6kLJKyF7r7SB4hdHhPM4/FEQLaRvZJrS/MoIO3MbPFAej3i2PbreMvtHMXC8Z/L2JAVrbEsLO3avXpZqBRlRpHlkb3ny/N0YnlJGCL6RcVSG4deFdy/1jZqQw1OyiDAGZc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=cGDYSa7f; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="cGDYSa7f" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1732540875; x=1764076875; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VF9mEYDyF8AVV2/MlyLqhDnzQPABSbqh+jPmpb/z4GA=; b=cGDYSa7f2oPqofrr8/Om0efVj2cVqmABSYveCIWtJbJ+Q1c0FxxiWzcL PZP7wZ+2Hshn7CDbfCbUakYqTwe0kXez6SfB2DFHIjHWANCvpEZD5Mg3f KQKG99nxCSKPEz6Jc8W+n7QJLgPqID4OB6pT1/c5i4Q8dk8m9n6lTE52S bFxMS0+KDd9DJv92JLvb3Vp9pyTRYQkbwLG6H94lmK3JNRx+Cb2Ul0Lk9 m4rDjdrlM6R4CFNkUM3aagCsR0BAB7+L1i0Dc3UitC2ywxUdrE6fIj8uS sxuBXQtsICv3W2/FJwj7eynAfXsYoKiMJ4JiYd5/zRzReRuPPe+N3YciT w==; X-CSE-ConnectionGUID: J9rbj7tZRlOCw8EDpVnAhg== X-CSE-MsgGUID: DdMXJPivRCuwD2Skdq2tTQ== X-IronPort-AV: E=McAfee;i="6700,10204,11267"; a="43145502" X-IronPort-AV: E=Sophos;i="6.12,182,1728975600"; d="scan'208";a="43145502" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2024 05:21:15 -0800 X-CSE-ConnectionGUID: aW1aLRTmT+iMba12+wKY7g== X-CSE-MsgGUID: +RaUdqgcSEWsApBy7VKLQA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,182,1728975600"; d="scan'208";a="91161778" Received: from bergbenj-mobl1.ger.corp.intel.com (HELO pwlazlyn-mobl1.intel.com) ([10.245.245.34]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2024 05:21:10 -0800 From: Patryk Wlazlyn To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael.j.wysocki@intel.com, len.brown@intel.com, artem.bityutskiy@linux.intel.com, dave.hansen@linux.intel.com, patryk.wlazlyn@linux.intel.com, peterz@infradead.org, tglx@linutronix.de, gautham.shenoy@amd.com Subject: [RFC PATCH v4 7/8] acpi_idle: Add FFH cstate handling Date: Mon, 25 Nov 2024 14:20:27 +0100 Message-ID: <20241125132029.7241-8-patryk.wlazlyn@linux.intel.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241125132029.7241-1-patryk.wlazlyn@linux.intel.com> References: <20241125132029.7241-1-patryk.wlazlyn@linux.intel.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Patryk Wlazlyn --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/acpi/cstate.c | 9 +++++++++ drivers/acpi/processor_idle.c | 2 ++ include/acpi/processor.h | 5 +++++ 4 files changed, 17 insertions(+) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index ea33439a5d00..1da5e08de257 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -236,6 +236,7 @@ #define X86_FEATURE_PVUNLOCK ( 8*32+20) /* PV unlock function */ #define X86_FEATURE_VCPUPREEMPT ( 8*32+21) /* PV vcpu_is_preempted function */ #define X86_FEATURE_TDX_GUEST ( 8*32+22) /* "tdx_guest" Intel Trust Domain Extensions Guest */ +#define X86_FEATURE_NO_MWAIT_OFFLINE ( 8*32+23) /* Don't use MWAIT states for offlined CPUs */ /* Intel-defined CPU features, CPUID level 0x00000007:0 (EBX), word 9 */ #define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* "fsgsbase" RDFSBASE, WRFSBASE, RDGSBASE, WRGSBASE instructions*/ diff --git a/arch/x86/kernel/acpi/cstate.c b/arch/x86/kernel/acpi/cstate.c index f3ffd0a3a012..c80a3e6dba5f 100644 --- a/arch/x86/kernel/acpi/cstate.c +++ b/arch/x86/kernel/acpi/cstate.c @@ -204,6 +204,15 @@ int acpi_processor_ffh_cstate_probe(unsigned int cpu, } EXPORT_SYMBOL_GPL(acpi_processor_ffh_cstate_probe); +void acpi_processor_ffh_play_dead(struct acpi_processor_cx *cx) +{ + unsigned int cpu = smp_processor_id(); + struct cstate_entry *percpu_entry; + + percpu_entry = per_cpu_ptr(cpu_cstate_entry, cpu); + mwait_play_dead_with_hint(percpu_entry->states[cx->index].eax); +} + void __cpuidle acpi_processor_ffh_cstate_enter(struct acpi_processor_cx *cx) { unsigned int cpu = smp_processor_id(); diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index 698897b29de2..586cc7d1d8aa 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -590,6 +590,8 @@ static void acpi_idle_play_dead(struct cpuidle_device *dev, int index) raw_safe_halt(); else if (cx->entry_method == ACPI_CSTATE_SYSTEMIO) { io_idle(cx->address); + } else if (cx->entry_method == ACPI_CSTATE_FFH) { + acpi_processor_ffh_play_dead(cx); } else return; } diff --git a/include/acpi/processor.h b/include/acpi/processor.h index a17e97e634a6..63a37e72b721 100644 --- a/include/acpi/processor.h +++ b/include/acpi/processor.h @@ -280,6 +280,7 @@ int acpi_processor_ffh_cstate_probe(unsigned int cpu, struct acpi_processor_cx *cx, struct acpi_power_register *reg); void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx *cstate); +void acpi_processor_ffh_play_dead(struct acpi_processor_cx *cx); #else static inline void acpi_processor_power_init_bm_check(struct acpi_processor_flags @@ -300,6 +301,10 @@ static inline void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx { return; } +static inline void acpi_processor_ffh_play_dead(struct acpi_processor_cx *cx) +{ + return; +} #endif static inline int call_on_cpu(int cpu, long (*fn)(void *), void *arg, From patchwork Mon Nov 25 13:20:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patryk Wlazlyn X-Patchwork-Id: 13884901 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 746691B3956; Mon, 25 Nov 2024 13:21:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732540880; cv=none; b=ZkJVBzs7k3QHuHVYQk8ORW+QSVsKKf0LyKQ9tIBYUhvi/8sE+sxf5cwwkDa9FJBeGAOATw4CnBAQZqJFgwimI3MO3TsLWtbc7FpJqOywS/r+ysAArlW83FCAXZMdETwKsDp+/PofX4Sds4RyHMVOQ0V1qCOQa45sVNm4Q34zd60= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732540880; c=relaxed/simple; bh=6Lp0IV64+HavzuhO75TCUMSNsfZbWcVXamNaEiN0TXw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YXTIK7DHUDrKBdiB1/BHFoglVk67c31dxt15PswVWKJnS4xPsog6i5O3JJqYoxAa06GfpGoaFT2eqdDeCVVBZCce3J5CD/XhHveBfw5dSelahED8K4fnOncxuoUM/ANP5NHdTOyFL4wm4aERUL4vM48BLrmPOudm6ycskzwhECM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=c1YQMDvx; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="c1YQMDvx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1732540880; x=1764076880; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6Lp0IV64+HavzuhO75TCUMSNsfZbWcVXamNaEiN0TXw=; b=c1YQMDvxEzYFqyZu7TB7WfmiIzCt2quAgpEmEvP4QCBuEIgttx76kMKx hFbd6cFLyF7ZFdXBpCPjft5hVdrVJuGW1zBd2IxRIe8NjET971lsE9HrZ Lchv8JJKHd6BqOYx0KR/VVFiaqRrVVgym8Hd6KIgksY7xOmL9SrOZZkl5 c0hCzx046gAxyL/NuoxOwxXS/5ZZZhWCsvffcSulBq24Z8q78hUGO2a6C ZS+koZG8zJjUbDRxwK1MwidXWyoWwJgK4DY9cI5u9N8uLUWm2SupCnudN Ojp7f4Eqitbi6vNSM35IQPDLFceMPAEMg/0JgTBYT8zovteyzuELk22px Q==; X-CSE-ConnectionGUID: xSsbRPcGTg2OxMM1cHdDcQ== X-CSE-MsgGUID: 3exD20YLSRa3uJeXj0Nliw== X-IronPort-AV: E=McAfee;i="6700,10204,11267"; a="43145511" X-IronPort-AV: E=Sophos;i="6.12,182,1728975600"; d="scan'208";a="43145511" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2024 05:21:20 -0800 X-CSE-ConnectionGUID: swPvfLtbReKhSTMXeDGAQQ== X-CSE-MsgGUID: NqH7bS67SpmBvL7nkvax/Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,182,1728975600"; d="scan'208";a="91161793" Received: from bergbenj-mobl1.ger.corp.intel.com (HELO pwlazlyn-mobl1.intel.com) ([10.245.245.34]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2024 05:21:15 -0800 From: Patryk Wlazlyn To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael.j.wysocki@intel.com, len.brown@intel.com, artem.bityutskiy@linux.intel.com, dave.hansen@linux.intel.com, patryk.wlazlyn@linux.intel.com, peterz@infradead.org, tglx@linutronix.de, gautham.shenoy@amd.com Subject: [RFC PATCH v4 8/8] acpi_idle: Disallow play_dead with FFH cstate on AMD platforms Date: Mon, 25 Nov 2024 14:20:28 +0100 Message-ID: <20241125132029.7241-9-patryk.wlazlyn@linux.intel.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241125132029.7241-1-patryk.wlazlyn@linux.intel.com> References: <20241125132029.7241-1-patryk.wlazlyn@linux.intel.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Patryk Wlazlyn Suggested-by: Gautham R. Shenoy --- drivers/acpi/processor_idle.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index 586cc7d1d8aa..4b4ac8d55b55 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -803,7 +803,11 @@ static int acpi_processor_setup_cstates(struct acpi_processor *pr) state->flags = 0; - state->enter_dead = acpi_idle_play_dead; + /* AMD doesn't want to use mwait for play dead. */ + bool amd_or_hygon = boot_cpu_data.x86_vendor == X86_VENDOR_AMD || + boot_cpu_data.x86_vendor == X86_VENDOR_HYGON; + if (!(cx->entry_method == ACPI_CSTATE_FFH && amd_or_hygon)) + state->enter_dead = acpi_idle_play_dead; if (cx->type == ACPI_STATE_C1 || cx->type == ACPI_STATE_C2) drv->safe_state_index = count;