From patchwork Tue Mar 19 12:59:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 13596665 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8E0DDC54E60 for ; Tue, 19 Mar 2024 13:10:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=bp9/swDMIjDfVEP2xA6CejSYzQ/h1e12eulfgWbhKXw=; b=1OBZ8bXejWOIzt nb2PROdIgO3Wihp0iirk/8/uz8VP2cbrup0/VQtQOhfSEWpDdNkSRWRp7acSA2GWlJp/HXig0xZSD qAvJsQ2W/5vRQO8/DTKaCU3hx/vFuwmtnR/zMKvTeUS5zdtBj19B2nzYBvaZ0ojg58NMSW9WAVZd9 FAGRpNLUdOvhm3RUTJpCLGxO2ds4FjAT7OOrx+PZp0bzOhQeltaNbw4wMUFV5g+AVuAxXoRK3IbkY 5NAnUBF+W8gCFzPBdc33npCi+aq3lyswH1Oj6mpr+mGH0IyQPS9KSsbwM2X1v1VZWGZZ3GySYE2dJ 5eHCjutdb1WSPg1xe/0g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rmZEP-0000000Cjrs-1CLA; Tue, 19 Mar 2024 13:10:17 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rmZEM-0000000CjnT-34Oq for linux-arm-kernel@bombadil.infradead.org; Tue, 19 Mar 2024 13:10:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:In-Reply-To:References; bh=NRFhPNgO2KTc9pPyC3K2O36/9jEWFqud2QKSFyqGdjk=; b=Fk31kwtY0xiAnzFHmq5RbsfnPl sZjE/0LXazWJZFkqELo5wcmgHGdb4PJmx9n+LLppmtb/ES00rt4HI/4IxKNJkQd+s2TwtwFnV0Z6J wv86rcQLi2x6XkqLa32lg0qL5ipFtT/vYobvqVL631TNU1wSAExw6wFY/fuhbiRdlZYLjjDnSg9j1 HF2E2D+Q9rJvZIOUB8ShvIZObfyqGm9fqZg3UrxqXpE7XvV5PfABKe8zarvbnedYrEE7cIZsbGKEu tbMTaxomdjYUxr4nzPQ955Ih2NBewXNFGnSD3u5YOYiDFHj1npk5PilLKgUxb+8mfl8QqFQA6OoDu Gup9ef0Q==; Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by casper.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rmZE9-00000001zLS-11MH; Tue, 19 Mar 2024 13:10:01 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rmZE8-00000004PMn-3PUg; Tue, 19 Mar 2024 13:10: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 v3 0/5] Add PSCI v1.3 SYSTEM_OFF2 support for hibernation Date: Tue, 19 Mar 2024 12:59:01 +0000 Message-ID: <20240319130957.1050637-1-dwmw2@infradead.org> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The PSCI v1.3 spec (https://developer.arm.com/documentation/den0022, currently in Alpha state, hence 'RFC') adds support for a SYSTEM_OFF2 function enabling a HIBERNATE_OFF state which is analogous to ACPI S4. This will allow hosting environments to determine that a guest is hibernated rather than just powered off, and ensure that they preserve the virtual environment appropriately to allow the guest to resume safely (or bump the hardware_signature in the FACS to trigger a clean reboot instead). This updates KVM to support advertising PSCI v1.3, and unconditionally enables the SYSTEM_OFF2 support when PSCI v1.3 is enabled. For now, KVM defaults to PSCI v1.2 unless explicitly requested. For the guest side, add a new SYS_OFF_MODE_POWER_OFF handler with higher priority than the EFI one, but which *only* triggers when there's a hibernation in progress. There are other ways to do this (see the commit message for more details) but this seemed like the simplest. Version 2 of the patch series splits out the psci.h definitions into a separate commit (a dependency for both the guest and KVM side), and adds definitions for the other new functions added in v1.3. It also moves the pKVM psci-relay support to a separate commit; although in arch/arm64/kvm that's actually about the *guest* side of SYSTEM_OFF2 (i.e. using it from the host kernel, relayed through nVHE). Version 3 dropped the KVM_CAP which allowed userspace to explicitly opt in to the new feature like with SYSTEM_SUSPEND, and makes it depend only on PSCI v1.3 being exposed to the guest. David Woodhouse (5): firmware/psci: Add definitions for PSCI v1.3 specification (ALPHA) KVM: arm64: Add support for PSCI v1.2 and v1.3 KVM: arm64: Add PSCI v1.3 SYSTEM_OFF2 function for hibernation KVM: arm64: nvhe: Pass through PSCI v1.3 SYSTEM_OFF2 call arm64: Use SYSTEM_OFF2 PSCI call to power off for hibernate Documentation/virt/kvm/api.rst | 11 +++++++++ arch/arm64/include/uapi/asm/kvm.h | 6 +++++ arch/arm64/kvm/hyp/nvhe/psci-relay.c | 2 ++ arch/arm64/kvm/hypercalls.c | 2 ++ arch/arm64/kvm/psci.c | 43 +++++++++++++++++++++++++++++++++++- drivers/firmware/psci/psci.c | 35 +++++++++++++++++++++++++++++ include/kvm/arm_psci.h | 4 +++- include/uapi/linux/psci.h | 20 +++++++++++++++++ kernel/power/hibernate.c | 5 ++++- 9 files changed, 125 insertions(+), 3 deletions(-) Signed-off-by: David Woodhouse