Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1182460lql; Tue, 12 Mar 2024 09:26:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUIM1rPymp840Gp3kon0voAExmQu2x3Tk3rufbTECytj7eL0bbIm2kL4DpAfbVM9mpnDkFTF6ooiQ6MM9TqNAVkjNCtTXmhm2b5aberKA== X-Google-Smtp-Source: AGHT+IGTpbqwWxcFYULNF+BibZDX7lgjI012chz+6Anfn5zM/52aeD4Grk1bsJqVSBtyPtazuWce X-Received: by 2002:ad4:4e4d:0:b0:690:c7ec:adf0 with SMTP id eb13-20020ad44e4d000000b00690c7ecadf0mr8517693qvb.35.1710260773436; Tue, 12 Mar 2024 09:26:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710260773; cv=pass; d=google.com; s=arc-20160816; b=Jrt/akPCqX2P73jxUTq/+KK7whR3CdhwRNvYRQBdnIsArdgrVc0WFzrex9Dc0OC4NO gqyY3SaarfJ9kFio8pwrJUAMC32gwQOBmkJj4hX79I+98WIy02t3In4Nzkt8bTEtRH7S M6mf5971+QhdcVg1QF2r/kDaqh3uXi/e4nSbjDjSgLshhqgkc6OxCGTl8k4+6qfNj4N3 LaIDc5MiNF8hpQZrDb1Z35Qa7Q2SZa1rjrwEaLSGWR0l2TVb2tPRyncySjAz8ne1TytM 7bjwl/NjbMUv+7WTIMaW9gw91v2aRSFxqKzqxvamFgCcVxGr7htZroBp62hDkwdB1YzO yLvA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Pmgtt4mh52E0ERFpZQ40Zoz9sGIFhtqH6Ihl0RxJeMs=; fh=cGTiXEW680tjRkJBO0R8Z7uT0RUWfkbNFWDDGM1ZY2g=; b=HidCToPQqNm1n79AgcAgYlFcBpu45sfLR8FcIuj4Ql7uyy1wfsdvbvDTSF9EGz6Sk7 RzHkorjQDCxaD/ZXUN4J57XvxuDn0xHo/nnQwn4FE1iELyVkG3xbnUSeBpwatXfKPE9k 8aWXn4JzVy7oOYMfKGDYX5eIaJbxVDGczbCSHm7MS+eSm0XOQVDF16u4nINBPo289TOb CRYueEqs3tzl5M6vJm9G6XF2tJ6Tgm+I9SsKSTFbB0MxaNJMbI6OyVAcXoPNVDMeCeQ4 sBK5ZO2Im0meWLyyVvsI57k7t085SVT+5VEQ6lySqvWTnddd5xQnl46zgp4Zk8tmIyvm GhfA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=BOeLFV7H; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-100312-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100312-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id pf16-20020a056214499000b0068f8eee6161si7946835qvb.404.2024.03.12.09.26.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 09:26:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100312-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=BOeLFV7H; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-100312-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100312-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1103B1C22103 for ; Tue, 12 Mar 2024 14:00:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 359327B3D5; Tue, 12 Mar 2024 14:00:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="BOeLFV7H" Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 2FC777A700; Tue, 12 Mar 2024 14:00:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710252012; cv=none; b=gsaWdj/sO3p8o5Qk6xbPUOasbzOMYxo0RxmJBAWlH8263dc/V1QM4h9LrcVvhxaiQRtRbdS4bYVABSR2hCqAU6UDQhi7taD//Cd0e/4nQZ6iNNlc3YV/ECM0ARtjHkzKcfq0GOEnwPklZ03RwZ7eY0nM+KHMQhFidlX7BA1YU0k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710252012; c=relaxed/simple; bh=HMH0aJ/yhL4TtEL6UtwH+nkbeX43Qv6MTp6+ytOSTDE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mnonVG8RwsQnOske36AoAzE/rI/SxAgBNQDjzBzpdtkX31V1PWTU0El2EvUcmCuja8xeOVlTYnYqWeSSync2c4rQ9eOxgUazuObhyJsjkHW193nJ/kBJxJAStuIMDDH0uwPrdcV4DPjA7oKLPlKtPLo07Zx4oDaoxqADV65fVpE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=desiato.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=BOeLFV7H; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=desiato.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=Pmgtt4mh52E0ERFpZQ40Zoz9sGIFhtqH6Ihl0RxJeMs=; b=BOeLFV7H7h+EF4VfHWTOf+BQRx ynSXjJYPgpTj/CXyGDQQqQ5Qsv/8KHJ0vqSaOhjfWgKd0/M/BKk/k16aciKflY9M3RLdUUwcyQtXc PFOaLY8d1Dn+et+lAzKpNciAb1D+uB9DinhWwwI9LspSwWWiL2O1h1uUSbzqiRnbe1b1tYFyKijDV PmhtSMTk/j7jaNu3tpU7LS269lAaHrcS15y5JeBuslsfiNvcszqCJveYThFZiL4JglBp0KvZzB6tF l1Mgy7GlMCtGloklTRIB/lPjCPLvFh4EQ2izHayipJZ4JO3iiBqAqau7uQfI6YP7Jt8BjFta6a8it GlsV5iZw==; Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by desiato.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rk2fh-00000009V5O-3rT4; Tue, 12 Mar 2024 14:00:02 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rk2fg-000000033N9-3I8x; Tue, 12 Mar 2024 14:00:00 +0000 From: David Woodhouse To: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Jonathan Corbet , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Lorenzo Pieralisi , "Rafael J. Wysocki" , Len Brown , Pavel Machek , David Woodhouse , Mostafa Saleh , Jean-Philippe Brucker , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-pm@vger.kernel.org Subject: [RFC PATCH 2/2] arm64: Use SYSTEM_OFF2 PSCI call to power off for hibernate Date: Tue, 12 Mar 2024 13:51:29 +0000 Message-ID: <20240312135958.727765-3-dwmw2@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240312135958.727765-1-dwmw2@infradead.org> References: <20240312135958.727765-1-dwmw2@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by desiato.infradead.org. See http://www.infradead.org/rpr.html From: David Woodhouse 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 --- 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 4b0b7cf2e019..ac87b3cb670c 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -676,8 +676,11 @@ static void power_down(void) } 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(); -- 2.44.0