From patchwork Wed Feb 23 04:18:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 1596485 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=efffHbKR; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=MojSaeqq; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4K3N9W2bhdz9sG2 for ; Wed, 23 Feb 2022 15:19:59 +1100 (AEDT) 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:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=1ZERpDNPo0NekHhBvlBZU+x+Yu9e3Fjme/ESXd/eOwE=; b=efffHbKRugnt/rQ8CJMsjYwd9Q V+fpfj7Maztt07/k4W7RrgjbPzEgxuC1gwYUWWC6jVq3mUiAD1fnJDuTj7NMpRrcq0jY+WSs56sga 6/cX/ChtHRP2AdQJ+D/iwviOD/qynuJxfCOv1Bwt4fbqFXle9LPciPy3VOd3gfV6/kdheaAuO8Npg +XOqFDUVynn8LYDJEiP6FFRDVSGFjR8TpIvGs5XICwh7ujjnY/VCHeb8JqGC5VyiQCgXeuQmlBXxt R4cpRnT+EZicqe5GBP6ZoOSe8ntOm1b0nvoWJBoEVCIWXhfy0OPs1i5oa1kMwTHqiqnLhkqbC6gvC EM4u/nHA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMj89-00CmXp-2p; Wed, 23 Feb 2022 04:19:57 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMj84-00CmVD-5P for kvm-riscv@lists.infradead.org; Wed, 23 Feb 2022 04:19:54 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id b64-20020a256743000000b0061e169a5f19so26430443ybc.11 for ; Tue, 22 Feb 2022 20:19:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=oBFB/xilh37p90MAtedZ2XW8fyKmtZw3IlbClh+i4lM=; b=MojSaeqqFqDqfFiYP3GR7fpzY0v5x4pnqhX3VBYwF5yFq0D4eA8efuBrFc/dN5InRf mU629W/8VBRhfYCTuIUgoBniLHrNo6LXoPd9LXa+r/0CWi5SI+IPG0AD/9xtQUbKA9DM qnXOQDrMl7O87Zece/28SpHmBowt05GTXrp4VO7BDYeGr3lUAFUEU3DYxA5TejaZCyfR Pre2TDI4+Sw+qtMSJRhROfX+7i9oDVeoxmQrGlR/cc/eFQyAKufXTAKy9h5Y+JamOOeo Wx9Df6bQi7FbV9YCBq5ObX6ISYS+95ifzqS+vZPF8Xi+Er1W+/4Dnup0fF2lCat8M1ym A2JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=oBFB/xilh37p90MAtedZ2XW8fyKmtZw3IlbClh+i4lM=; b=664Sm86KZCSXdUIZ4czwXzpwOJ+4e9Gr1Zhb4rdI3ONCUdPqh30lPBa51u4uxweUfa ry0jrgunxoHVaGeau8tplfIrJRaEvehFd6eL7YWJ4jVu8decG3XyCvYLhBn4iUnv8RMa bqsSJsULqDDW8D/Si8iJqNNCBurSbMIu9T/DxkGxXCp71VR/mHsNkFoUgrdb+6WXj9yr nf0ZR8b755UPDT+VZU4Ie288ioxhxK1f9I3g4vXh5GXpvgRDMw3aXZ0ZosReSabuJhfh KYrOaHE8zI8Xv3NEEnZ+dHvfl6KKlcIPNeL+tj8wX/61sQMaFlppL70JksTJEWssuMiP cU6w== X-Gm-Message-State: AOAM532B7bVuXCnJVfWz84xXSbr2pgeZGM+egvjiTqouY7BsU4RyiWrb OWZLus1o9z3+jJYdCL1l8nu93GxAJMQ= X-Google-Smtp-Source: ABdhPJz9b+hfmnwYAU6AfGGVvol/lvhuJaB4WCMZd/mum6HGubo/Jo2QgD+znembhbgJPqgYTeAp2lLJ9BI= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a5b:347:0:b0:610:7b35:2806 with SMTP id q7-20020a5b0347000000b006107b352806mr26626791ybp.486.1645589990807; Tue, 22 Feb 2022 20:19:50 -0800 (PST) Date: Wed, 23 Feb 2022 04:18:38 +0000 In-Reply-To: <20220223041844.3984439-1-oupton@google.com> Message-Id: <20220223041844.3984439-14-oupton@google.com> Mime-Version: 1.0 References: <20220223041844.3984439-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.473.g83b2b277ed-goog Subject: [PATCH v3 13/19] KVM: arm64: Add support KVM_SYSTEM_EVENT_SUSPEND to PSCI SYSTEM_SUSPEND From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: Paolo Bonzini , Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Anup Patel , Atish Patra , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Peter Shier , Reiji Watanabe , Ricardo Koller , Raghavendra Rao Ananta , Jing Zhang , Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220222_201952_254851_B750170F X-CRM114-Status: GOOD ( 18.00 ) X-Spam-Score: -7.7 (-------) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add a new system event type, KVM_SYSTEM_EVENT_SUSPEND, which indicates to userspace that the guest has requested the VM be suspended. Userspace can decide whether or not it wants to honor the guest's [...] Content analysis details: (-7.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:b4a listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -7.5 USER_IN_DEF_DKIM_WL From: address is in the default DKIM white-list -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 DKIMWL_WL_MED DKIMwl.org - Medium trust sender X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add a new system event type, KVM_SYSTEM_EVENT_SUSPEND, which indicates to userspace that the guest has requested the VM be suspended. Userspace can decide whether or not it wants to honor the guest's request by changing the MP state of the vCPU. If it does not, userspace is responsible for configuring the vCPU to return an error to the guest. Document these expectations in the KVM API documentation. To preserve ABI, this new exit requires explicit opt-in from userspace. Add KVM_CAP_ARM_SYSTEM_SUSPEND which grants userspace the ability to opt-in to these exits on a per-VM basis. Signed-off-by: Oliver Upton --- Documentation/virt/kvm/api.rst | 39 +++++++++++++++++++++++++++++++ arch/arm64/include/asm/kvm_host.h | 3 +++ arch/arm64/kvm/arm.c | 5 ++++ arch/arm64/kvm/psci.c | 5 ++++ include/uapi/linux/kvm.h | 2 ++ 5 files changed, 54 insertions(+) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 2b4bdbc2dcc0..1e207bbc01f5 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -5930,6 +5930,7 @@ should put the acknowledged interrupt vector into the 'epr' field. #define KVM_SYSTEM_EVENT_RESET 2 #define KVM_SYSTEM_EVENT_CRASH 3 #define KVM_SYSTEM_EVENT_WAKEUP 4 + #define KVM_SYSTEM_EVENT_SUSPENDED 5 __u32 type; __u64 flags; } system_event; @@ -5957,6 +5958,34 @@ Valid values for 'type' are: - KVM_SYSTEM_EVENT_WAKEUP -- the guest is in a suspended state and KVM has recognized a wakeup event. Userspace may honor this event by marking the exiting vCPU as runnable, or deny it and call KVM_RUN again. + - KVM_SYSTEM_EVENT_SUSPENDED -- the guest has requested a suspension of + the VM. + +For arm/arm64: +^^^^^^^^^^^^^^ + + KVM_SYSTEM_EVENT_SUSPENDED exits are enabled with the + KVM_CAP_ARM_SYSTEM_SUSPEND VM capability. If a guest successfully + invokes the PSCI SYSTEM_SUSPEND function, KVM will exit to userspace + with this event type. + + The guest's x2 register contains the 'entry_address' where execution + should resume when the VM is brought out of suspend. The guest's x3 + register contains the 'context_id' corresponding to the request. When + the guest resumes execution at 'entry_address', x0 should contain the + 'context_id'. For more details on the SYSTEM_SUSPEND PSCI call, see + ARM DEN0022D.b 5.19 "SYSTEM_SUSPEND". + + Userspace is _required_ to take action for such an exit. It must + either: + + - Honor the guest request to suspend the VM. Userspace must reset + the calling vCPU, then set PC to 'entry_address' and x0 to + 'context_id'. Userspace may request in-kernel emulation of the + suspension by setting the vCPU's state to KVM_MP_STATE_SUSPENDED. + + - Deny the guest request to suspend the VM. Userspace must set + registers x1-x3 to 0 and set x0 to PSCI_RET_INTERNAL_ERROR (-6). :: @@ -7580,3 +7609,13 @@ The argument to KVM_ENABLE_CAP is also a bitmask, and must be a subset of the result of KVM_CHECK_EXTENSION. KVM will forward to userspace the hypercalls whose corresponding bit is in the argument, and return ENOSYS for the others. + +8.35 KVM_CAP_ARM_SYSTEM_SUSPEND +------------------------------- + +:Capability: KVM_CAP_ARM_SYSTEM_SUSPEND +:Architectures: arm64 +:Type: vm + +When enabled, KVM will exit to userspace with KVM_EXIT_SYSTEM_EVENT of +type KVM_SYSTEM_EVENT_SUSPEND to process the guest suspend request. diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index d32cab0c9752..e1c2ec18d1aa 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -146,6 +146,9 @@ struct kvm_arch { /* Memory Tagging Extension enabled for the guest */ bool mte_enabled; + + /* System Suspend Event exits enabled for the VM */ + bool system_suspend_exits; }; struct kvm_vcpu_fault_info { diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index d2b190f32651..ce3f14a77a49 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -101,6 +101,10 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, } mutex_unlock(&kvm->lock); break; + case KVM_CAP_ARM_SYSTEM_SUSPEND: + r = 0; + kvm->arch.system_suspend_exits = true; + break; default: r = -EINVAL; break; @@ -209,6 +213,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) case KVM_CAP_SET_GUEST_DEBUG: case KVM_CAP_VCPU_ATTRIBUTES: case KVM_CAP_PTP_KVM: + case KVM_CAP_ARM_SYSTEM_SUSPEND: r = 1; break; case KVM_CAP_SET_GUEST_DEBUG2: diff --git a/arch/arm64/kvm/psci.c b/arch/arm64/kvm/psci.c index 2bb8d047cde4..a7de84cec2e4 100644 --- a/arch/arm64/kvm/psci.c +++ b/arch/arm64/kvm/psci.c @@ -245,6 +245,11 @@ static int kvm_psci_system_suspend(struct kvm_vcpu *vcpu) return 1; } + if (kvm->arch.system_suspend_exits) { + kvm_vcpu_set_system_event_exit(vcpu, KVM_SYSTEM_EVENT_SUSPEND); + return 0; + } + __kvm_reset_vcpu(vcpu, &reset_state); kvm_vcpu_wfi(vcpu); return 1; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index babb16c2abe5..e5bb5f15c0eb 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -445,6 +445,7 @@ struct kvm_run { #define KVM_SYSTEM_EVENT_RESET 2 #define KVM_SYSTEM_EVENT_CRASH 3 #define KVM_SYSTEM_EVENT_WAKEUP 4 +#define KVM_SYSTEM_EVENT_SUSPEND 5 __u32 type; __u64 flags; } system_event; @@ -1136,6 +1137,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_VM_GPA_BITS 207 #define KVM_CAP_XSAVE2 208 #define KVM_CAP_SYS_ATTRIBUTES 209 +#define KVM_CAP_ARM_SYSTEM_SUSPEND 210 #ifdef KVM_CAP_IRQ_ROUTING