Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp956758lqt; Tue, 19 Mar 2024 08:40:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUxTY2d+zGfgfPpL7kmCvOgQOqCHmZ0DZTDsCKWw7k3UdQz3YNqULSaendHV7/QZboQ668ONt0KIpwv6NODXoDo49c3zzBQXTNbIqjnDQ== X-Google-Smtp-Source: AGHT+IEiageW4um3sIXZ69Wat+Ph+smpOui7dP8YY16Tq9CcrSeGhZVrB+spMteONMkuDiKhC3ax X-Received: by 2002:a17:902:e843:b0:1e0:2f59:524c with SMTP id t3-20020a170902e84300b001e02f59524cmr6208026plg.37.1710862813816; Tue, 19 Mar 2024 08:40:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710862813; cv=pass; d=google.com; s=arc-20160816; b=HZggvDyKnA6RK8ec2j5BkJ2OFBJlUhsTRvSQ4CmkYedLkuhiCtWnFMK48Km0t6yMTi NL2HosbzbpGivctvwSd3ZmO4+VNf3+RoPOtHT6mP9/mdwaFu5sZsO4WGohcjU2a3jBav qKGt5k8uHLle6S+tQvPwz0DUYTlhBRRownXB1cLVunK7u3NIaPETUq585+Gi/Oe4LprZ fMEbv4/r3/Iu0AcxrJ2b1VrMOvOf8C2hIvt47GdwSI2RGxTlKE7TiooRLvYfjRajP3g4 9Coeq6ppm4eEGT+BGDkNneQo7nPO1kaR8nE9d3ioTvsoxJ4mfxtFUd7IU/QKwNX4RLdu TUFA== 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=B9A+Pb5hiKQ29EKst8ISOkp52cEc90IIUKWNzSvmQifmk8FsDqXPzuYd2T4yCs8qbv VrQMgICUrIJg0owAziDA/Tzo81o/MjAqJJIyDuO8eP7WwTNpoJl04riJ/WV3eAdjwH/a cZLwxh+UJQd3O7EuGxOg4AvrbUlPDuUAhXF/Zr+Zye9LWZVXBDOVIDsp2TwLKlK0MKdm dXZx2KvlddKJnT/+bKRH7qL9Zvy/fBu1i4nfGkQHYchgpJ4KaCayfUcs2kA1Whtf3rm6 nzYQYdPsM7cx+dCWcc+x3pm75EioIX19PwDT4UTVsHhPh4dp2NFmGik/chHMfX7So0Lo 24qQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=BzVstWiW; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-107573-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107573-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id p8-20020a170902780800b001dd96c16feasi10587931pll.621.2024.03.19.08.40.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 08:40:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107573-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=BzVstWiW; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-107573-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107573-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 6FE5CB226BE for ; Tue, 19 Mar 2024 13:13:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0227D823D8; Tue, 19 Mar 2024 13:10:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="BzVstWiW" 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 AAF1781724; Tue, 19 Mar 2024 13:10:12 +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=1710853814; cv=none; b=lcK0oiHZ/SFoLG2uy49JFHzPnpyePdpCwXRBB9ILloJBy5aoApLyU/VRlq+FgtSDUOvMzeXI1/f1swRTRpGIm/Hx0/ilfU7OYn2icbgdV9p0hBD05J7cNJZFHd1hlIZM91V5QhiUJmEWYEdqjMJLQ+Bhs1y9bR/trfpD1FWN2mE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710853814; c=relaxed/simple; bh=HMH0aJ/yhL4TtEL6UtwH+nkbeX43Qv6MTp6+ytOSTDE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YlbOlof590IQW8Y6g0VsZmr/6OFzOjQoymgtogW4UmM7Muom6OzS7+B3tKtqyzQY5abKzRk55hE3tMsnOVbEEdlsOsZgSZNHBlFvE3sdRxEb9DySQ855Z5YM1hpYpGtaegEgmth7YZmfHgeiSEin3HYKTh26aVn9l1Yr7X2S8iI= 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=BzVstWiW; 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=BzVstWiW0OSzgfgyp5EL36bCHd 86Xs7gLeF5roLtNMG54Dn1YYIvNc7gFSioT8eLie20NZCKfUJ6KFGEiyFND8oEuIZ+7+7AezXl03n VULB8oA3SmrzJohhfyMB/jh4zIsGuA4NsqZXoacin9gfq2IfsgoPNeBzKwb6ETlsP3TBvRP2knK0I 14S05r5narRksQo6uCu9f5Ck1Eza3Er1wUjTRC2D5JID3D2X6KgDEvDVynePdJ3uWgJlvNRv2ONKu DNdKKV8cej+zKVKSi6KYsz2pAyA7fa/tzmJbKlfx2NpbvBzSA1dDefq3bjUgZhWdByX2Z4P0cUMAm RgiQvtkw==; 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 1rmZEA-0000000DDly-1ioY; Tue, 19 Mar 2024 13:10:02 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rmZE9-00000004PN6-0ttC; Tue, 19 Mar 2024 13:10:01 +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 v3 5/5] arm64: Use SYSTEM_OFF2 PSCI call to power off for hibernate Date: Tue, 19 Mar 2024 12:59:06 +0000 Message-ID: <20240319130957.1050637-6-dwmw2@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240319130957.1050637-1-dwmw2@infradead.org> References: <20240319130957.1050637-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