Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1237004lqp; Fri, 22 Mar 2024 09:06:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVkZ1XuQc5mHd/t4GQvhliaW35YRLeBxY/664eKSUvrBsBRzdA13zaJCgd0exrpE6cRNhfuQJTOgseX+Y6fla1ns5tVUMotfTzYBWc2Cg== X-Google-Smtp-Source: AGHT+IEPKWO1dcWqm6d/7dk6TggPLipi7whRUsEt/KIEI20WjX4TyYgCOiCmM7KISuttgBHV519Z X-Received: by 2002:a05:6a00:3c96:b0:6ea:90b4:417f with SMTP id lm22-20020a056a003c9600b006ea90b4417fmr250244pfb.0.1711123605075; Fri, 22 Mar 2024 09:06:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711123605; cv=pass; d=google.com; s=arc-20160816; b=Itxf+ntkXe1QZxyW7YZhnGp5hC/hU2gEIhK65ejsVhtlTxxDGHoyYtme8ZFvOxEZck L5/JxWhez2EPMj4yAdlXAfT808d/RLhZcxc+BpoHltVzsX+xpBuJOkaL/LgAIZzrhcl4 my52QO5NkH+Cy58uBOn+EqLw4KyygQ+aGoExCdyMeO2FnZPZHvFi6LaM+rW1QP7hUS1N MuDQ6Ew7dTAGiiueI7qkUKvc7+0kTiwf6JvjN4UlunJyXkhhs7WrbfXaIuz5Im4+bnn5 KpZ3ZEjVvsqAdw2wGXPJhm5fVderUoIfSi7RPvsUHDidh66atZu+t358WNV33Oi2cFWz naSg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature; bh=Hxe7Itt9d+dllYiRt9zlc3BYn4VfadAcPdllxeC1QSc=; fh=/m/KvBm29e8C82BxLyQmZAabVpMOhKD/wkT2O8iGeDs=; b=z44hUA2KteZwy07qWQkLKpNQy2zM9hZ3u3Gg1/550EQumTJZHuNr/SVGk+WCCVHgz5 Wz9MJgXptQB+30qEjzYp/GdzuMMHcV4FiSuhA0wXedbleRWfwuzfHzQRAaFxGoLV1hDz PAnqDiFcSZ2UaY8R2bI+Oz3dp6MH/0qNb6YcvWHyOgIwkij7jBcCpaJaLrnHTxfcABOv FcVE379ltaEMNkCcJJo/8AEwBZCp7+IGptHbCEk+i9MY0sFCW/4Yll4sAxKKmaS81t4w NHFVJMWqSQ6N1PdVlIriDeYzuzvi0oV+CTk7osrQqGW9sOUuaL6yICQGM3HKpONavyPQ TXEQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VznjFNpv; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-111745-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111745-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d14-20020a631d0e000000b005e83b676209si2164453pgd.512.2024.03.22.09.06.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 09:06:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-111745-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VznjFNpv; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-111745-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111745-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 652A5281CB5 for ; Fri, 22 Mar 2024 16:06:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 16A505820C; Fri, 22 Mar 2024 16:06:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VznjFNpv" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 054CB56B61; Fri, 22 Mar 2024 16:06:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711123593; cv=none; b=sEH4j/TKZ591F7miUzZFeJkEmPRhXeSuUc7DzmnD9YykXMdFbsuMtZW+NPVa3F7PpMIY75ubFRG7USkGLkEGEyN9hgQoRCVHPVHtPVKSEabelsk3sOqe2FOADx1cO/czHr7Kd5QAQguBRRRAYvgjzOVTdhY79d4POHj41OtKh5k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711123593; c=relaxed/simple; bh=/RfrFwsyqQv/p9dVCAnOPaOHTu/fU2xZlRNgkN+5be8=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=hqq3n1C6+1cHCGIUE8dXs8R0tBDmIxUc6gVlUOnZxU64+A7YqEjzJ81AV6mdwkAmKgmPd0d0JAVXou2rrAmQkpqeixb91FeQQW2DxMnQvKQBbRcgaIsg4u/91baN0wnXiSoNDFytgkTw5uEE4YLEJT/hq6UoKl19Zn01hS/uHmI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VznjFNpv; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3D29C433F1; Fri, 22 Mar 2024 16:06:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711123592; bh=/RfrFwsyqQv/p9dVCAnOPaOHTu/fU2xZlRNgkN+5be8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=VznjFNpvyLvrqYSpzjKvmCvvjY2PlHc+O5z/VW+a4ngBaz6gatupcz0uWv5XXTkCT gC73akO5cgQwmLW7nw7WDjTDWYzLCPxiVgDGxq4n7/jb0EI4n29TBTSgwE6a90F9Jh 6zuzuSw/kVfKTPIA3YfHKPaERenIGAmaX70WlB3aSzJbAQ3d/d50krO7AiJCcFU9Kj f4HK+xTC18n4tURFGHrN4uC9PHzLeupX/TIXzps6zyDFYBA2pmIEaJY/TB/oXGl7e1 xlpb/SGz0+sIsxMNREJe/tcuMdbfFiBRYTNwGLLQo1NkuKE0SIwKGX93jmb2fM/Hr0 4yrYTlwhXUBHQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rnhPa-00EYHz-Gy; Fri, 22 Mar 2024 16:06:30 +0000 Date: Fri, 22 Mar 2024 16:06:29 +0000 Message-ID: <86h6gyz1x6.wl-maz@kernel.org> From: Marc Zyngier To: David Woodhouse Cc: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, Paolo Bonzini , Jonathan Corbet , 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: Re: [RFC PATCH v3 3/5] KVM: arm64: Add PSCI v1.3 SYSTEM_OFF2 function for hibernation In-Reply-To: <20240319130957.1050637-4-dwmw2@infradead.org> References: <20240319130957.1050637-1-dwmw2@infradead.org> <20240319130957.1050637-4-dwmw2@infradead.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: dwmw2@infradead.org, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, pbonzini@redhat.com, corbet@lwn.net, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, lpieralisi@kernel.org, rafael@kernel.org, len.brown@intel.com, pavel@ucw.cz, dwmw@amazon.co.uk, smostafa@google.com, jean-philippe@linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-pm@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Tue, 19 Mar 2024 12:59:04 +0000, David Woodhouse wrote: > > 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 > 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). > > The beta version will be changed to say that PSCI_FEATURES returns a bit > mask of the supported hibernate types, which is implemented here. > > Although this new feature is inflicted unconditionally on unexpecting > userspace, it ought to be mostly OK because it still results in the same > KVM_SYSTEM_EVENT_SHUTDOWN event, just with a new flag which hopefully > won't cause userspace to get unhappy. > > Signed-off-by: David Woodhouse > --- > Documentation/virt/kvm/api.rst | 11 +++++++++ > arch/arm64/include/uapi/asm/kvm.h | 6 +++++ > arch/arm64/kvm/psci.c | 37 +++++++++++++++++++++++++++++++ > 3 files changed, 54 insertions(+) > > diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst > index 0b5a33ee71ee..ba4ddb13e253 100644 > --- a/Documentation/virt/kvm/api.rst > +++ b/Documentation/virt/kvm/api.rst > @@ -6761,6 +6761,10 @@ the first `ndata` items (possibly zero) of the data array are valid. > the guest issued a SYSTEM_RESET2 call according to v1.1 of the PSCI > specification. > > + - for arm64, data[0] is set to KVM_SYSTEM_EVENT_SHUTDOWN_FLAG_PSCI_OFF2 > + if the guest issued a SYSTEM_OFF2 call according to v1.3 of the PSCI > + specification. > + > - for RISC-V, data[0] is set to the value of the second argument of the > ``sbi_system_reset`` call. > > @@ -6794,6 +6798,13 @@ either: > - Deny the guest request to suspend the VM. See ARM DEN0022D.b 5.19.2 > "Caller responsibilities" for possible return values. > > +Hibernation using the PSCI SYSTEM_OFF2 call is enabled when PSCI v1.3 > +is enabled. If a guest invokes the PSCI SYSTEM_OFF2 function, KVM will > +exit to userspace with the KVM_SYSTEM_EVENT_SHUTDOWN event type and with > +data[0] set to KVM_SYSTEM_EVENT_SHUTDOWN_FLAG_PSCI_OFF2. The only > +supported hibernate type for the SYSTEM_OFF2 function is HIBERNATE_OFF > +0x0). > + > :: > > /* KVM_EXIT_IOAPIC_EOI */ > diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h > index 964df31da975..66736ff04011 100644 > --- a/arch/arm64/include/uapi/asm/kvm.h > +++ b/arch/arm64/include/uapi/asm/kvm.h > @@ -484,6 +484,12 @@ enum { > */ > #define KVM_SYSTEM_EVENT_RESET_FLAG_PSCI_RESET2 (1ULL << 0) > > +/* > + * Shutdown caused by a PSCI v1.3 SYSTEM_OFF2 call. > + * Valid only when the system event has a type of KVM_SYSTEM_EVENT_SHUTDOWN. > + */ > +#define KVM_SYSTEM_EVENT_SHUTDOWN_FLAG_PSCI_OFF2 (1ULL << 0) > + > /* run->fail_entry.hardware_entry_failure_reason codes. */ > #define KVM_EXIT_FAIL_ENTRY_CPU_UNSUPPORTED (1ULL << 0) > > diff --git a/arch/arm64/kvm/psci.c b/arch/arm64/kvm/psci.c > index f689ef3f2f10..7acf07900c08 100644 > --- a/arch/arm64/kvm/psci.c > +++ b/arch/arm64/kvm/psci.c > @@ -194,6 +194,12 @@ static void kvm_psci_system_off(struct kvm_vcpu *vcpu) > kvm_prepare_system_event(vcpu, KVM_SYSTEM_EVENT_SHUTDOWN, 0); > } > > +static void kvm_psci_system_off2(struct kvm_vcpu *vcpu) > +{ > + kvm_prepare_system_event(vcpu, KVM_SYSTEM_EVENT_SHUTDOWN, > + KVM_SYSTEM_EVENT_SHUTDOWN_FLAG_PSCI_OFF2); > +} > + > static void kvm_psci_system_reset(struct kvm_vcpu *vcpu) > { > kvm_prepare_system_event(vcpu, KVM_SYSTEM_EVENT_RESET, 0); > @@ -353,6 +359,11 @@ static int kvm_psci_1_x_call(struct kvm_vcpu *vcpu, u32 minor) > if (test_bit(KVM_ARCH_FLAG_SYSTEM_SUSPEND_ENABLED, &kvm->arch.flags)) > val = 0; > break; > + case PSCI_1_3_FN_SYSTEM_OFF2: > + case PSCI_1_3_FN64_SYSTEM_OFF2: > + if (minor >= 3) > + val = 1UL << PSCI_1_3_HIBERNATE_TYPE_OFF; > + break; > case PSCI_1_1_FN_SYSTEM_RESET2: > case PSCI_1_1_FN64_SYSTEM_RESET2: nit: please keep the switch ordered by version number. > if (minor >= 1) > @@ -374,6 +385,32 @@ static int kvm_psci_1_x_call(struct kvm_vcpu *vcpu, u32 minor) > return 0; > } > break; > + case PSCI_1_3_FN_SYSTEM_OFF2: > + kvm_psci_narrow_to_32bit(vcpu); > + fallthrough; > + case PSCI_1_3_FN64_SYSTEM_OFF2: > + if (minor < 3) > + break; > + > + arg = smccc_get_arg1(vcpu); > + if (arg != PSCI_1_3_HIBERNATE_TYPE_OFF) { > + val = PSCI_RET_INVALID_PARAMS; > + break; > + } > + kvm_psci_system_off2(vcpu); > + /* > + * We shouldn't be going back to guest VCPU after > + * receiving SYSTEM_OFF2 request. > + * > + * If user space accidentally/deliberately resumes > + * guest VCPU after SYSTEM_OFF2 request then guest > + * VCPU should see internal failure from PSCI return > + * value. To achieve this, we preload r0 (or x0) with > + * PSCI return value INTERNAL_FAILURE. > + */ > + val = PSCI_RET_INTERNAL_FAILURE; > + ret = 0; > + break; > case PSCI_1_1_FN_SYSTEM_RESET2: > kvm_psci_narrow_to_32bit(vcpu); > fallthrough; Same thing here. Thanks, M. -- Without deviation from the norm, progress is not possible.