From patchwork Fri Apr 19 17:33:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Cox X-Patchwork-Id: 1925650 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VLhct1Kqbz1xrS for ; Sat, 20 Apr 2024 03:35:42 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1rxs9A-00017R-Jj; Fri, 19 Apr 2024 17:35:36 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1rxs96-00010T-DW for kernel-team@lists.ubuntu.com; Fri, 19 Apr 2024 17:35:32 +0000 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id AB4DB3F16A for ; Fri, 19 Apr 2024 17:35:31 +0000 (UTC) Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6a04bb7370bso28087526d6.3 for ; Fri, 19 Apr 2024 10:35:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713548130; x=1714152930; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LucDmPTxyv6ok465XytM+bnW6GEDTLcz/auruL3gsgY=; b=BMTUroxOWdF1mTTXyW/MSo7jslJIqQdNAJ3SrzSgnAY5E7ONSvPLWxqsGHtNsmARHh R4nuIWHLfBGXRjQeZJUPLLfSyHS9SfH/wEHrSPU4AitW5Xcaguno7qUIimj4FK1cetvz cVlNKjEOp/gAaKU+7v4cE8nx7bByoxIJpF9TVGwEudp00eBFxjCXabBXnAAkiwl9wxDp sKtzGPQNMwB3oiZ1Oh55iKzUrzP2ujYLiuHVD8qO6PnbpslEuafT+5jra8/D197uiffx DkCu5utjJr/CZ3sl7+nXJ9uuy4bnvBIhMgaQq9Ua1+Fmcw1TNpja1tYrLWAqKq360voL fonQ== X-Gm-Message-State: AOJu0YxzNufdCvc4G0e4/i4B9hon06fwSCj6mMRbdGbyBxzk4q0q0rG4 gTikC+r8l6eQVO2XvTmUM6HX8c3ZSSx0lqiNnhYXdYyaXBifgleuiOhVtG92lBI6vi4FB1AL2tA ELFShMvQywuA2aUFJrQ4U8jnjgdjGow2QoIEpI6jMDK60oscC6oetxcUzQU0gzss73Uspuk2Kdk jcIidyfptjLQ== X-Received: by 2002:a05:6214:905:b0:69b:7327:fcd3 with SMTP id dj5-20020a056214090500b0069b7327fcd3mr2579514qvb.53.1713548130176; Fri, 19 Apr 2024 10:35:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFfOmHibp1HhJAeo8mQMGG05KyAiyIDO9u4L59m5VHA/GuqFrpljku2v4GWuxYtEcPYRqErcw== X-Received: by 2002:a05:6214:905:b0:69b:7327:fcd3 with SMTP id dj5-20020a056214090500b0069b7327fcd3mr2579500qvb.53.1713548129912; Fri, 19 Apr 2024 10:35:29 -0700 (PDT) Received: from cox.conference (bras-base-maplon2310w-grc-36-76-69-53-230.dsl.bell.ca. [76.69.53.230]) by smtp.gmail.com with ESMTPSA id h3-20020a0cab03000000b0069bd4f7cf64sm1755987qvb.3.2024.04.19.10.35.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 10:35:26 -0700 (PDT) From: Philip Cox To: kernel-team@lists.ubuntu.com Subject: [PATCH 2/2][m/n][aws] UBUNTU: SAUCE: arm64: Use SYSTEM_OFF2 PSCI call to power off for hibernate Date: Fri, 19 Apr 2024 13:33:07 -0400 Message-Id: <20240419173307.83813-4-philip.cox@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240419173307.83813-1-philip.cox@canonical.com> References: <20240419173307.83813-1-philip.cox@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: David Woodhouse BugLink: https://bugs.launchpad.net/bugs/2060992 The PSCI v1.3 specification (alpha) adds support for a SYSTEM_OFF2 function which is analogous to ACPI S4 state. This will allow hosting environments to determine that a guest is hibernated rather than just powered off, and handle that state appropriately on subsequent launches. Since commit 60c0d45a7f7a ("efi/arm64: use UEFI for system reset and poweroff") the EFI shutdown method is deliberately preferred over PSCI or other methods. So register a SYS_OFF_MODE_POWER_OFF handler which *only* handles the hibernation, leaving the original PSCI SYSTEM_OFF as a last resort via the legacy pm_power_off function pointer. The hibernation code already exports a system_entering_hibernation() function which is be used by the higher-priority handler to check for hibernation. That existing function just returns the value of a static boolean variable from hibernate.c, which was previously only set in the hibernation_platform_enter() code path. Set the same flag in the simpler code path around the call to kernel_power_off() too. An alternative way to hook SYSTEM_OFF2 into the hibernation code would be to register a platform_hibernation_ops structure with an ->enter() method which makes the new SYSTEM_OFF2 call. But that would have the unwanted side-effect of making hibernation take a completely different code path in hibernation_platform_enter(), invoking a lot of special dpm callbacks. Another option might be to add a new SYS_OFF_MODE_HIBERNATE mode, with fallback to SYS_OFF_MODE_POWER_OFF. Or to use the sys_off_data to indicate whether the power off is for hibernation. But this version works and is relatively simple. Signed-off-by: David Woodhouse (cherry-picked from https://lore.kernel.org/lkml/20240312135958.727765-1-dwmw2@infradead.org) Signed-off-by: Philip Cox --- drivers/firmware/psci/psci.c | 35 +++++++++++++++++++++++++++++++++++ kernel/power/hibernate.c | 5 ++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index d9629ff87861..69d2f6969438 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -78,6 +78,7 @@ struct psci_0_1_function_ids get_psci_0_1_function_ids(void) static u32 psci_cpu_suspend_feature; static bool psci_system_reset2_supported; +static bool psci_system_off2_supported; static inline bool psci_has_ext_power_state(void) { @@ -333,6 +334,28 @@ static void psci_sys_poweroff(void) invoke_psci_fn(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0); } +#ifdef CONFIG_HIBERNATION +static int psci_sys_hibernate(struct sys_off_data *data) +{ + if (system_entering_hibernation()) + invoke_psci_fn(PSCI_FN_NATIVE(1_3, SYSTEM_OFF2), + PSCI_1_3_HIBERNATE_TYPE_OFF, 0, 0); + return NOTIFY_DONE; +} + +static int __init psci_hibernate_init(void) +{ + if (psci_system_off2_supported) { + /* Higher priority than EFI shutdown, but only for hibernate */ + register_sys_off_handler(SYS_OFF_MODE_POWER_OFF, + SYS_OFF_PRIO_FIRMWARE + 2, + psci_sys_hibernate, NULL); + } + return 0; +} +subsys_initcall(psci_hibernate_init); +#endif + static int psci_features(u32 psci_func_id) { return invoke_psci_fn(PSCI_1_0_FN_PSCI_FEATURES, @@ -364,6 +387,7 @@ static const struct { PSCI_ID_NATIVE(1_1, SYSTEM_RESET2), PSCI_ID(1_1, MEM_PROTECT), PSCI_ID_NATIVE(1_1, MEM_PROTECT_CHECK_RANGE), + PSCI_ID_NATIVE(1_3, SYSTEM_OFF2), }; static int psci_debugfs_read(struct seq_file *s, void *data) @@ -523,6 +547,16 @@ static void __init psci_init_system_reset2(void) psci_system_reset2_supported = true; } +static void __init psci_init_system_off2(void) +{ + int ret; + + ret = psci_features(PSCI_FN_NATIVE(1_3, SYSTEM_OFF2)); + + if (ret != PSCI_RET_NOT_SUPPORTED) + psci_system_off2_supported = true; +} + static void __init psci_init_system_suspend(void) { int ret; @@ -653,6 +687,7 @@ static int __init psci_probe(void) psci_init_cpu_suspend(); psci_init_system_suspend(); psci_init_system_reset2(); + psci_init_system_off2(); kvm_init_hyp_services(); } diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index 8d35b9f9aaa3..d049eaac11fb 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -670,8 +670,11 @@ static void power_down(void) hibernation_platform_enter(); fallthrough; case HIBERNATION_SHUTDOWN: - if (kernel_can_power_off()) + if (kernel_can_power_off()) { + entering_platform_hibernation = true; kernel_power_off(); + entering_platform_hibernation = false; + } break; } kernel_halt();