From patchwork Mon Dec 6 12:29:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 520988 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8527DC433F5 for ; Mon, 6 Dec 2021 12:30:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243117AbhLFMdf (ORCPT ); Mon, 6 Dec 2021 07:33:35 -0500 Received: from mga05.intel.com ([192.55.52.43]:60264 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232833AbhLFMdd (ORCPT ); Mon, 6 Dec 2021 07:33:33 -0500 X-IronPort-AV: E=McAfee;i="6200,9189,10189"; a="323557976" X-IronPort-AV: E=Sophos;i="5.87,291,1631602800"; d="scan'208";a="323557976" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Dec 2021 04:30:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,291,1631602800"; d="scan'208";a="514838582" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 06 Dec 2021 04:30:01 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 6725CB8; Mon, 6 Dec 2021 14:30:07 +0200 (EET) From: "Kirill A. Shutemov" To: rafael@kernel.org Cc: ak@linux.intel.com, bp@alien8.de, dan.j.williams@intel.com, dave.hansen@linux.intel.com, hpa@zytor.com, kirill.shutemov@linux.intel.com, knsathya@kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, rjw@rjwysocki.net, sathyanarayanan.kuppuswamy@linux.intel.com, tglx@linutronix.de, tony.luck@intel.com, x86@kernel.org Subject: [PATCH 1/4] ACPICA: Do not flush cache for on entering S4 and S5 Date: Mon, 6 Dec 2021 15:29:49 +0300 Message-Id: <20211206122952.74139-2-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211206122952.74139-1-kirill.shutemov@linux.intel.com> References: <20211206122952.74139-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org According to the ACPI spec v6.4, section 16.2 the cache flushing is required on entering to S1, S2, and S3. ACPICA code flushes cache regardless of the sleep state. Blind cache flush on entering S5 causes problems for TDX. Flushing happens with WBINVD that is not supported in the TDX environment. TDX only supports S5 and adjusting ACPICA code to conform to the spec fixes the issue. Signed-off-by: Kirill A. Shutemov --- drivers/acpi/acpica/hwesleep.c | 3 ++- drivers/acpi/acpica/hwsleep.c | 3 ++- drivers/acpi/acpica/hwxfsleep.c | 2 -- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/acpi/acpica/hwesleep.c b/drivers/acpi/acpica/hwesleep.c index 808fdf54aeeb..ceb5a4292efa 100644 --- a/drivers/acpi/acpica/hwesleep.c +++ b/drivers/acpi/acpica/hwesleep.c @@ -104,7 +104,8 @@ acpi_status acpi_hw_extended_sleep(u8 sleep_state) /* Flush caches, as per ACPI specification */ - ACPI_FLUSH_CPU_CACHE(); + if (sleep_state < ACPI_STATE_S4) + ACPI_FLUSH_CPU_CACHE(); status = acpi_os_enter_sleep(sleep_state, sleep_control, 0); if (status == AE_CTRL_TERMINATE) { diff --git a/drivers/acpi/acpica/hwsleep.c b/drivers/acpi/acpica/hwsleep.c index 34a3825f25d3..ee094a3aaaab 100644 --- a/drivers/acpi/acpica/hwsleep.c +++ b/drivers/acpi/acpica/hwsleep.c @@ -110,7 +110,8 @@ acpi_status acpi_hw_legacy_sleep(u8 sleep_state) /* Flush caches, as per ACPI specification */ - ACPI_FLUSH_CPU_CACHE(); + if (sleep_state < ACPI_STATE_S4) + ACPI_FLUSH_CPU_CACHE(); status = acpi_os_enter_sleep(sleep_state, pm1a_control, pm1b_control); if (status == AE_CTRL_TERMINATE) { diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c index e4cde23a2906..ba77598ee43e 100644 --- a/drivers/acpi/acpica/hwxfsleep.c +++ b/drivers/acpi/acpica/hwxfsleep.c @@ -162,8 +162,6 @@ acpi_status acpi_enter_sleep_state_s4bios(void) return_ACPI_STATUS(status); } - ACPI_FLUSH_CPU_CACHE(); - status = acpi_hw_write_port(acpi_gbl_FADT.smi_command, (u32)acpi_gbl_FADT.s4_bios_request, 8); if (ACPI_FAILURE(status)) { From patchwork Mon Dec 6 12:29:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 521652 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCC6FC433F5 for ; Mon, 6 Dec 2021 12:30:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243162AbhLFMdr (ORCPT ); Mon, 6 Dec 2021 07:33:47 -0500 Received: from mga06.intel.com ([134.134.136.31]:5275 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243180AbhLFMdr (ORCPT ); Mon, 6 Dec 2021 07:33:47 -0500 X-IronPort-AV: E=McAfee;i="6200,9189,10189"; a="298101829" X-IronPort-AV: E=Sophos;i="5.87,291,1631602800"; d="scan'208";a="298101829" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Dec 2021 04:30:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,291,1631602800"; d="scan'208";a="562759884" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga008.fm.intel.com with ESMTP; 06 Dec 2021 04:30:01 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 6F2D7199; Mon, 6 Dec 2021 14:30:07 +0200 (EET) From: "Kirill A. Shutemov" To: rafael@kernel.org Cc: ak@linux.intel.com, bp@alien8.de, dan.j.williams@intel.com, dave.hansen@linux.intel.com, hpa@zytor.com, kirill.shutemov@linux.intel.com, knsathya@kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, rjw@rjwysocki.net, sathyanarayanan.kuppuswamy@linux.intel.com, tglx@linutronix.de, tony.luck@intel.com, x86@kernel.org Subject: [PATCH 2/4] ACPI: PM: Remove redundant cache flushing Date: Mon, 6 Dec 2021 15:29:50 +0300 Message-Id: <20211206122952.74139-3-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211206122952.74139-1-kirill.shutemov@linux.intel.com> References: <20211206122952.74139-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org ACPICA code takes care about cache flushing on S1/S2/S3 in acpi_hw_extended_sleep() and acpi_hw_legacy_sleep(). acpi_suspend_enter() calls into ACPICA code via acpi_enter_sleep_state() for S1 or x86_acpi_suspend_lowlevel() for S3. It only need to flush cache for S2 (not sure if this call path is ever used for S2). acpi_sleep_prepare() call tree: __acpi_pm_prepare() acpi_pm_prepare() acpi_suspend_ops::prepare_late() acpi_hibernation_ops::pre_snapshot() acpi_hibernation_ops::prepare() acpi_suspend_begin_old() acpi_suspend_begin_old::begin() acpi_hibernation_begin_old() acpi_hibernation_ops_old::acpi_hibernation_begin_old() acpi_power_off_prepare() pm_power_off_prepare() Hibernation (S4) and Power Off (S5) don't require cache flushing. So, the only interesting callsites are acpi_suspend_ops::prepare_late() and acpi_suspend_begin_old::begin(). Both of them have cache flush on ->enter() operation in acpi_suspend_enter(). Remove redundant ACPI_FLUSH_CPU_CACHE() in acpi_sleep_prepare() and acpi_suspend_enter(). Signed-off-by: Kirill A. Shutemov --- drivers/acpi/sleep.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c index eaa47753b758..14e8df0ac762 100644 --- a/drivers/acpi/sleep.c +++ b/drivers/acpi/sleep.c @@ -73,7 +73,6 @@ static int acpi_sleep_prepare(u32 acpi_state) acpi_set_waking_vector(acpi_wakeup_address); } - ACPI_FLUSH_CPU_CACHE(); #endif pr_info("Preparing to enter system sleep state S%d\n", acpi_state); acpi_enable_wakeup_devices(acpi_state); @@ -566,15 +565,15 @@ static int acpi_suspend_enter(suspend_state_t pm_state) u32 acpi_state = acpi_target_sleep_state; int error; - ACPI_FLUSH_CPU_CACHE(); - trace_suspend_resume(TPS("acpi_suspend"), acpi_state, true); switch (acpi_state) { case ACPI_STATE_S1: barrier(); status = acpi_enter_sleep_state(acpi_state); break; - + case ACPI_STATE_S2: + ACPI_FLUSH_CPU_CACHE(); + break; case ACPI_STATE_S3: if (!acpi_suspend_lowlevel) return -ENOSYS; From patchwork Mon Dec 6 12:29:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 521653 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D233C433EF for ; Mon, 6 Dec 2021 12:30:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243115AbhLFMdf (ORCPT ); Mon, 6 Dec 2021 07:33:35 -0500 Received: from mga12.intel.com ([192.55.52.136]:62519 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243104AbhLFMde (ORCPT ); Mon, 6 Dec 2021 07:33:34 -0500 X-IronPort-AV: E=McAfee;i="6200,9189,10189"; a="217329014" X-IronPort-AV: E=Sophos;i="5.87,291,1631602800"; d="scan'208";a="217329014" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Dec 2021 04:30:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,291,1631602800"; d="scan'208";a="748024786" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 06 Dec 2021 04:30:01 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 797311A0; Mon, 6 Dec 2021 14:30:07 +0200 (EET) From: "Kirill A. Shutemov" To: rafael@kernel.org Cc: ak@linux.intel.com, bp@alien8.de, dan.j.williams@intel.com, dave.hansen@linux.intel.com, hpa@zytor.com, kirill.shutemov@linux.intel.com, knsathya@kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, rjw@rjwysocki.net, sathyanarayanan.kuppuswamy@linux.intel.com, tglx@linutronix.de, tony.luck@intel.com, x86@kernel.org Subject: [PATCH 3/4] ACPI: processor idle: Only flush cache on entering C3 Date: Mon, 6 Dec 2021 15:29:51 +0300 Message-Id: <20211206122952.74139-4-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211206122952.74139-1-kirill.shutemov@linux.intel.com> References: <20211206122952.74139-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org According to the ACPI spec v6.4, section 8.2, cache flushing required on entering C3 power state. Avoid flushing cache on entering other power states. Signed-off-by: Kirill A. Shutemov --- drivers/acpi/processor_idle.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index 76ef1bcc8848..01495aca850e 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -567,7 +567,8 @@ static int acpi_idle_play_dead(struct cpuidle_device *dev, int index) { struct acpi_processor_cx *cx = per_cpu(acpi_cstate[index], dev->cpu); - ACPI_FLUSH_CPU_CACHE(); + if (cx->type == ACPI_STATE_C3) + ACPI_FLUSH_CPU_CACHE(); while (1) { From patchwork Mon Dec 6 12:29:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 520986 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28BFBC433EF for ; Mon, 6 Dec 2021 12:30:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243173AbhLFMdr (ORCPT ); Mon, 6 Dec 2021 07:33:47 -0500 Received: from mga09.intel.com ([134.134.136.24]:25407 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243187AbhLFMdr (ORCPT ); Mon, 6 Dec 2021 07:33:47 -0500 X-IronPort-AV: E=McAfee;i="6200,9189,10189"; a="237115321" X-IronPort-AV: E=Sophos;i="5.87,291,1631602800"; d="scan'208";a="237115321" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Dec 2021 04:30:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,291,1631602800"; d="scan'208";a="750353962" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga005.fm.intel.com with ESMTP; 06 Dec 2021 04:30:01 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 87464324; Mon, 6 Dec 2021 14:30:07 +0200 (EET) From: "Kirill A. Shutemov" To: rafael@kernel.org Cc: ak@linux.intel.com, bp@alien8.de, dan.j.williams@intel.com, dave.hansen@linux.intel.com, hpa@zytor.com, kirill.shutemov@linux.intel.com, knsathya@kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, rjw@rjwysocki.net, sathyanarayanan.kuppuswamy@linux.intel.com, tglx@linutronix.de, tony.luck@intel.com, x86@kernel.org Subject: [PATCH 4/4] ACPI: PM: Avoid cache flush on entering S4 Date: Mon, 6 Dec 2021 15:29:52 +0300 Message-Id: <20211206122952.74139-5-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211206122952.74139-1-kirill.shutemov@linux.intel.com> References: <20211206122952.74139-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org According to the ACPI spec v6.4, section 16.2 the cache flushing required on entering to S1, S2, and S3. No need to flush caches on hibernation (S4). Signed-off-by: Kirill A. Shutemov --- drivers/acpi/sleep.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c index 14e8df0ac762..8166d863ed6b 100644 --- a/drivers/acpi/sleep.c +++ b/drivers/acpi/sleep.c @@ -902,8 +902,6 @@ static int acpi_hibernation_enter(void) { acpi_status status = AE_OK; - ACPI_FLUSH_CPU_CACHE(); - /* This shouldn't return. If it returns, we have a problem */ status = acpi_enter_sleep_state(ACPI_STATE_S4); /* Reprogram control registers */