From patchwork Thu Jul 7 12:53:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grzegorz Jaszczyk X-Patchwork-Id: 588904 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 4281AC433EF for ; Thu, 7 Jul 2022 12:57:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235935AbiGGM5O (ORCPT ); Thu, 7 Jul 2022 08:57:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235366AbiGGM4x (ORCPT ); Thu, 7 Jul 2022 08:56:53 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44E6331DF1 for ; Thu, 7 Jul 2022 05:56:23 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id bu42so11106596lfb.0 for ; Thu, 07 Jul 2022 05:56:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2+/ZVPt3U/lu0gkn4JYhnqM2dENcEUukg3rF+ztpMp8=; b=aiInV8wkI4Ru4vjyTWbX9ib5eRWxnEEjwhFJbYSIBg3CqX0ravkePdB9v+Onju0LVb K+eypJaNYPPgfOHCCII9hz0792sYA4Gu3Zxy6zRnPs/FQco7QEgMsBY4HjhmodJSkPW4 8h0Oq3lI6b7WbvVYEmUcXV0d5McEZvuHU5ZTWvxZNq4lTlI6iuu7teZtBlU4MrEI9SIm ij+p1IFQzpEq4J1SNAo8vpYGish6Yo4NGQFOi0m58CEuyrKCdzCwGACHr0eB382yHqxg qaIzhHmWTPrwq+0vIPgLCTFqMoRgG2H5Vuds/yvUU+ZIHXPBYgcgMUwnUZHPqhsPfXSs /Bng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2+/ZVPt3U/lu0gkn4JYhnqM2dENcEUukg3rF+ztpMp8=; b=08EMF56q1eXFi3qBs71Wbi0Ee4z0OxGBpueqtYoerWqiaSBqHF75eVLgRf+wAE8pMn Rcy+gS7d5NpgsiDtBcu+53KivxD4T9oP8TyBDmR6QP85jVXcVIj5CD3oc7p1bQQVbw6e DERmAdQYxfZMKXUpVwoEDpixKngnri4umDrjUbLnu2sBJFOy2cM1eWhFX511aR/j+ZzM izIdPe/UovOoqNeN8znbd3Tila8Be4LgVQNkouGGOEYhI9k2XrHnGzm6M5JgLGGvYHz9 o3huvBknyiT/iFwjEYg3FV/yqe6R2J1wuJgwL+swuO39EyQIgHjJDuErm/IG23QK9o2p uyWQ== X-Gm-Message-State: AJIora/yK5BlhMzTAaDzRH6VyPQ5/riHn2RMHh0HJnD+0sQHqyALxc4h D81iBhPSaISV8XzPph+hHu6ajg== X-Google-Smtp-Source: AGRyM1sQMa/AsCwWa2+anJrNkfAWw1jwy0vKBCC9ftMR04N4rDu7gPvhFPpIUWkxTvpiSPGpcyEIeQ== X-Received: by 2002:a05:6512:2a91:b0:47f:6e1d:d22c with SMTP id dt17-20020a0565122a9100b0047f6e1dd22cmr31529344lfb.550.1657198581450; Thu, 07 Jul 2022 05:56:21 -0700 (PDT) Received: from jazctssd.c.googlers.com.com (138.58.228.35.bc.googleusercontent.com. [35.228.58.138]) by smtp.gmail.com with ESMTPSA id d7-20020a05651221c700b0047255d2111csm6810361lft.75.2022.07.07.05.56.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 05:56:20 -0700 (PDT) From: Grzegorz Jaszczyk To: linux-kernel@vger.kernel.org Cc: jaz@semihalf.com, dmy@semihalf.com, mario.limonciello@amd.com, seanjc@google.com, dbehr@google.com, upstream@semihalf.com, zide.chen@intel.corp-partner.google.com, "Rafael J. Wysocki" , Len Brown , Hans de Goede , Mark Gross , Pavel Machek , Mika Westerberg , Sachi King , linux-acpi@vger.kernel.org (open list:ACPI), platform-driver-x86@vger.kernel.org (open list:X86 PLATFORM DRIVERS), linux-pm@vger.kernel.org (open list:HIBERNATION (aka Software Suspend, aka swsusp)) Subject: [RFC PATCH 1/2] suspend: extend S2Idle ops by new notify handler Date: Thu, 7 Jul 2022 12:53:23 +0000 Message-Id: <20220707125329.378277-2-jaz@semihalf.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog In-Reply-To: <20220707125329.378277-1-jaz@semihalf.com> References: <20220707125329.378277-1-jaz@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Currently the LPS0 prepare_late callback is aimed to run as the very last thing before entering the S2Idle state from LPS0 perspective, nevertheless between this call and the system actually entering the S2Idle state there are several places where the suspension process could be canceled. In order to notify VMM about guest entering suspend, extend the S2Idle ops by new notify callback, which will be really invoked as a very last thing before guest actually enters S2Idle state. Additionally extend the acpi_s2idle_dev_ops by notify() callback so any driver can hook into it and allow to implement its own notification. Taking advantage of e.g. existing acpi_s2idle_dev_ops's prepare/restore hooks is not an option since it will not allow to prevent race conditions: - VM0 enters s2idle - host notes about VM0 is in s2idle - host continues with system suspension but in the meantime VM0 exits s2idle and sends notification but it is already too late (VM could not even send notification on time). Introducing notify() as a very last step before the system enters S2Idle together with an assumption that the VMM has control over guest resumption allows preventing mentioned races. Signed-off-by: Grzegorz Jaszczyk --- drivers/acpi/x86/s2idle.c | 11 +++++++++++ include/linux/acpi.h | 1 + include/linux/suspend.h | 1 + kernel/power/suspend.c | 4 ++++ 4 files changed, 17 insertions(+) diff --git a/drivers/acpi/x86/s2idle.c b/drivers/acpi/x86/s2idle.c index 2963229062f8..d5aff194c736 100644 --- a/drivers/acpi/x86/s2idle.c +++ b/drivers/acpi/x86/s2idle.c @@ -520,10 +520,21 @@ void acpi_s2idle_restore_early(void) lps0_dsm_func_mask, lps0_dsm_guid); } +static void acpi_s2idle_notify(void) +{ + struct acpi_s2idle_dev_ops *handler; + + list_for_each_entry(handler, &lps0_s2idle_devops_head, list_node) { + if (handler->notify) + handler->notify(); + } +} + static const struct platform_s2idle_ops acpi_s2idle_ops_lps0 = { .begin = acpi_s2idle_begin, .prepare = acpi_s2idle_prepare, .prepare_late = acpi_s2idle_prepare_late, + .notify = acpi_s2idle_notify, .wake = acpi_s2idle_wake, .restore_early = acpi_s2idle_restore_early, .restore = acpi_s2idle_restore, diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 4f82a5bc6d98..b32c4baed99b 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -1068,6 +1068,7 @@ struct acpi_s2idle_dev_ops { struct list_head list_node; void (*prepare)(void); void (*restore)(void); + void (*notify)(void); }; int acpi_register_lps0_dev(struct acpi_s2idle_dev_ops *arg); void acpi_unregister_lps0_dev(struct acpi_s2idle_dev_ops *arg); diff --git a/include/linux/suspend.h b/include/linux/suspend.h index 70f2921e2e70..16ef7f9d9a03 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -191,6 +191,7 @@ struct platform_s2idle_ops { int (*begin)(void); int (*prepare)(void); int (*prepare_late)(void); + void (*notify)(void); bool (*wake)(void); void (*restore_early)(void); void (*restore)(void); diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c index 827075944d28..6ba211b94ed1 100644 --- a/kernel/power/suspend.c +++ b/kernel/power/suspend.c @@ -100,6 +100,10 @@ static void s2idle_enter(void) /* Push all the CPUs into the idle loop. */ wake_up_all_idle_cpus(); + + if (s2idle_ops && s2idle_ops->notify) + s2idle_ops->notify(); + /* Make the current CPU wait so it can enter the idle loop too. */ swait_event_exclusive(s2idle_wait_head, s2idle_state == S2IDLE_STATE_WAKE);