From patchwork Fri Mar 11 17:39:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 1604488 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=Wj9PLFF8; 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=YcqrJdbS; 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 4KFYBZ1yz1z9sGD for ; Sat, 12 Mar 2022 04:41:10 +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=BjmpLczAu5I/7tdRzw72SD9DhaTRvT5OxzX59KsIung=; b=Wj9PLFF8PPvY8wkZXCVjbtfA4Q s5NWcBweirD+wtLolUwuKDlWTPHQDMRh+SVaVgGATbW1Zptq2o0qfLToaKOvjQP/7e1yHw4ogz14Q nOmn3nvNX76scbDeaAMuc12LYcrKK0WgpyU75L6LqSqCH59C7bHoWwDqVy7jMs2r8x2Ft+P2iD1v8 8r/2ZIW+thXC/4yjbbbszMaGfOldna7oSsH547EH45lNqzd/58TKT9CBJKHU5MB9qAZZmhJ432M4F Biws0b1CiPsjFL5DGVQhRtxA5RPwuUA+ArKrYdPFC67KCsLnGuUKk/loUFztgmxkaLAPKAq23dGhY 6RZYkeSw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGG-00HWLa-1G; Fri, 11 Mar 2022 17:41:08 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGC-00HWJL-6T for kvm-riscv@lists.infradead.org; Fri, 11 Mar 2022 17:41:05 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2dcfa6bab2aso73817037b3.22 for ; Fri, 11 Mar 2022 09:41:02 -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=j0xad0wsUd0JZg0GeKxejSss4gL9J8KLC9CepguR0Is=; b=YcqrJdbSsWWCZ9HE1h7BQY6mSi1J6diw5nGgmloSw7X6l7oE8NvPnzc2OaKBwBOV2+ zAMMemqEu0ghtWECIO0qUAdItddQbD13SclvXZf+YIVhojgX9aI+DnkcmigL4DUo7cMO hrQBGA6Byfu542kaahVe1WaPDqlD62PauplnFxYb7vG9fmcRKUK2ag2eC1vs00/nhdt5 JDxLPgBmm76D1G0RQSs1bxcy+01CU5yMx9RXB76gAVSj1CMcm+3Lr1ubK4ahARjyHsTO ey8uT6wULZ+vnvC5/fM0M9NUSUxpB/VAPn1Nk/WYPTf0aaC0e0hZc5+bHW0FgE9W6xOh tWRg== 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=j0xad0wsUd0JZg0GeKxejSss4gL9J8KLC9CepguR0Is=; b=gsHv1CsDbn9aZpPlYAzqDZ1Nksrz9OHhazUZmEAT5xuZxB8WdaA6iuF4IC5OSJ7ePl u1iqXpS1hzr62Yrdg27XVhOCs+rzU0kgU6V1FZdWfinKTokMcCRTHFh5RvBr+ZPTE4nt t8HclLReREk3PAh1r4989WRgCVjAxjo/JEvoRWRoMBFYtmBPyyiBa8gr0RyLSsoBioyf bbbGsPNbGxwDAwtHUg4KmFCLvuajgKyayam5roCmMKrJAQCke3xicI3GJ0jvyMa6Ay5Q lbmqUhJHAgoGz4BximMUaQLUIsYxD8sYXajMU194rKTRohDplqgClgFkuZrkM4qo82NQ 7N/g== X-Gm-Message-State: AOAM533yh1GkHgjeHqq/lrpwbQfmGG9F2bCVXgRFKMBfoxdeKIEFslwb 1m8M3rCpLIM4k2v9EKPGmPZX4NVLZPA= X-Google-Smtp-Source: ABdhPJyYtiCOxt/joBrBg+VAXK+PjFmD0BozCAPN55Ws8+mEBUulPGJB8S41rOZzbW8h7P950PMGDXF3jF4= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a25:be8a:0:b0:608:67d7:22fe with SMTP id i10-20020a25be8a000000b0060867d722femr8644022ybk.336.1647020461786; Fri, 11 Mar 2022 09:41:01 -0800 (PST) Date: Fri, 11 Mar 2022 17:39:47 +0000 In-Reply-To: <20220311174001.605719-1-oupton@google.com> Message-Id: <20220311174001.605719-2-oupton@google.com> Mime-Version: 1.0 References: <20220311174001.605719-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH v4 01/15] KVM: arm64: Generalise VM features into a set of flags From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: alexandru.elisei@arm.com, anup@brainfault.org, atishp@atishpatra.org, james.morse@arm.com, jingzhangos@google.com, jmattson@google.com, joro@8bytes.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, maz@kernel.org, pbonzini@redhat.com, pshier@google.com, rananta@google.com, reijiw@google.com, ricarkol@google.com, seanjc@google.com, suzuki.poulose@arm.com, vkuznets@redhat.com, wanpengli@tencent.com, Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220311_094104_267168_D6CD7D8D X-CRM114-Status: GOOD ( 15.18 ) 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: From: Marc Zyngier We currently deal with a set of booleans for VM features, while they could be better represented as set of flags contained in an unsigned long, similarily to what we are doing on the CPU side. 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:1149 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 From: Marc Zyngier We currently deal with a set of booleans for VM features, while they could be better represented as set of flags contained in an unsigned long, similarily to what we are doing on the CPU side. Signed-off-by: Marc Zyngier [Oliver: Flag-ify the 'ran_once' boolean] Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_host.h | 15 +++++++++------ arch/arm64/kvm/arm.c | 7 ++++--- arch/arm64/kvm/mmio.c | 3 ++- arch/arm64/kvm/pmu-emul.c | 4 ++-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 76f795b628f1..0e96087885fe 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -122,7 +122,12 @@ struct kvm_arch { * should) opt in to this feature if KVM_CAP_ARM_NISV_TO_USER is * supported. */ - bool return_nisv_io_abort_to_user; +#define KVM_ARCH_FLAG_RETURN_NISV_IO_ABORT_TO_USER 0 + /* Memory Tagging Extension enabled for the guest */ +#define KVM_ARCH_FLAG_MTE_ENABLED 1 + /* At least one vCPU has ran in the VM */ +#define KVM_ARCH_FLAG_HAS_RAN_ONCE 2 + unsigned long flags; /* * VM-wide PMU filter, implemented as a bitmap and big enough for @@ -135,10 +140,6 @@ struct kvm_arch { u8 pfr0_csv2; u8 pfr0_csv3; - - /* Memory Tagging Extension enabled for the guest */ - bool mte_enabled; - bool ran_once; }; struct kvm_vcpu_fault_info { @@ -810,7 +811,9 @@ bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu); #define kvm_arm_vcpu_sve_finalized(vcpu) \ ((vcpu)->arch.flags & KVM_ARM64_VCPU_SVE_FINALIZED) -#define kvm_has_mte(kvm) (system_supports_mte() && (kvm)->arch.mte_enabled) +#define kvm_has_mte(kvm) \ + (system_supports_mte() && \ + test_bit(KVM_ARCH_FLAG_MTE_ENABLED, &(kvm)->arch.flags)) #define kvm_vcpu_has_pmu(vcpu) \ (test_bit(KVM_ARM_VCPU_PMU_V3, (vcpu)->arch.features)) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index f49ebdd9c990..17021bc8ee2c 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -84,7 +84,8 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, switch (cap->cap) { case KVM_CAP_ARM_NISV_TO_USER: r = 0; - kvm->arch.return_nisv_io_abort_to_user = true; + set_bit(KVM_ARCH_FLAG_RETURN_NISV_IO_ABORT_TO_USER, + &kvm->arch.flags); break; case KVM_CAP_ARM_MTE: mutex_lock(&kvm->lock); @@ -92,7 +93,7 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, r = -EINVAL; } else { r = 0; - kvm->arch.mte_enabled = true; + set_bit(KVM_ARCH_FLAG_MTE_ENABLED, &kvm->arch.flags); } mutex_unlock(&kvm->lock); break; @@ -559,7 +560,7 @@ int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu) kvm_call_hyp_nvhe(__pkvm_vcpu_init_traps, vcpu); mutex_lock(&kvm->lock); - kvm->arch.ran_once = true; + set_bit(KVM_ARCH_FLAG_HAS_RAN_ONCE, &kvm->arch.flags); mutex_unlock(&kvm->lock); return ret; diff --git a/arch/arm64/kvm/mmio.c b/arch/arm64/kvm/mmio.c index 3e2d8ba11a02..3dd38a151d2a 100644 --- a/arch/arm64/kvm/mmio.c +++ b/arch/arm64/kvm/mmio.c @@ -135,7 +135,8 @@ int io_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa) * volunteered to do so, and bail out otherwise. */ if (!kvm_vcpu_dabt_isvalid(vcpu)) { - if (vcpu->kvm->arch.return_nisv_io_abort_to_user) { + if (test_bit(KVM_ARCH_FLAG_RETURN_NISV_IO_ABORT_TO_USER, + &vcpu->kvm->arch.flags)) { run->exit_reason = KVM_EXIT_ARM_NISV; run->arm_nisv.esr_iss = kvm_vcpu_dabt_iss_nisv_sanitized(vcpu); run->arm_nisv.fault_ipa = fault_ipa; diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c index 4526a5824dac..78fdc443adc7 100644 --- a/arch/arm64/kvm/pmu-emul.c +++ b/arch/arm64/kvm/pmu-emul.c @@ -961,7 +961,7 @@ static int kvm_arm_pmu_v3_set_pmu(struct kvm_vcpu *vcpu, int pmu_id) list_for_each_entry(entry, &arm_pmus, entry) { arm_pmu = entry->arm_pmu; if (arm_pmu->pmu.type == pmu_id) { - if (kvm->arch.ran_once || + if (test_bit(KVM_ARCH_FLAG_HAS_RAN_ONCE, &kvm->arch.flags) || (kvm->arch.pmu_filter && kvm->arch.arm_pmu != arm_pmu)) { ret = -EBUSY; break; @@ -1044,7 +1044,7 @@ int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr) mutex_lock(&kvm->lock); - if (kvm->arch.ran_once) { + if (test_bit(KVM_ARCH_FLAG_HAS_RAN_ONCE, &kvm->arch.flags)) { mutex_unlock(&kvm->lock); return -EBUSY; } From patchwork Fri Mar 11 17:39:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 1604489 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=3q36ajzt; 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=h/4vsGpJ; 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 4KFYBZ2dJwz9sGJ for ; Sat, 12 Mar 2022 04:41:10 +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=PsqOVD1YSld5pEyh7O99rBjos9dnfh+Zu7GE7qXf2Mo=; b=3q36ajztwqXsy1Gxhv6JEjJyAx sGIsf75ZbiE3f4vOHs7UN6ItQSzVtA+zVNuXkIQaDMFqH3uupKiGCXd8PwFY39ozzAgeWSHk/7+1u ISIfNQl38ofgvWdMwNJSy607MaWtyFDrjaUCBPUW2JpHqg0QboUkkHCHPd392k/fUF9rRgpOpZdVe 0l2bNJkWhIYvuSvA++paE4UhShbqlLeMcZU9bxsC9l7kfyJE8zwsrK1ADexT8/m7iW7R7R1uBhCxi ZPx5OukxLa4gacHRrYtnCAFOlOO2io0zpdjwcszj2TkjYqGuoICiY97xiCpoOXP3ijouVgep8TwXf Wvip7cmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGG-00HWLk-6Z; Fri, 11 Mar 2022 17:41:08 +0000 Received: from mail-il1-x149.google.com ([2607:f8b0:4864:20::149]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGC-00HWJc-IL for kvm-riscv@lists.infradead.org; Fri, 11 Mar 2022 17:41:05 +0000 Received: by mail-il1-x149.google.com with SMTP id x6-20020a923006000000b002bea39c3974so5972416ile.12 for ; Fri, 11 Mar 2022 09:41:03 -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=bb6B842pEmhb30IvOzOiYqYYt77sVbIbggImUmDeV5M=; b=h/4vsGpJyL/y/LTn5xTMyoq+QkJyJ59Xi9313T5WhXTIsMtDBSJmbACMzL4slDnoKp kIA6/1hycnhNho9//xNJfeaYXzKCjk3Ec5Ix81+73rzg3+OAT+oC3kzOVvW6mo1n6zUF GSn+9mH69PuLAsh5LipoiG4W4ivojlNhQRAcxJPaz+xDAH7FW2wBcHAhvZsMyM7Mx3G3 iPJpoPZgK/JDOZzsZWSvrPPX9QQe3KRS+Y4EEnuAABhwrI/Ia2bfYPkgqssjz0/4AVYN mX1ejFS0BmN9ZyhJ1+iy+SQHkAYMdyjJq0+3J58xuAW19dJo3pDpYHv7davgyHzTvXHU anTw== 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=bb6B842pEmhb30IvOzOiYqYYt77sVbIbggImUmDeV5M=; b=Iq/2smv0sSMnys5y8uHexqufHoW11okRy3DCTeqgEiMDvIoDFsA6MCjTF/Zed6RVbG mezM4WEPrgZjdmiVLAstL2ituNfg99zH7RCveqDQoY3Rf0yM0QoIjRNv7O3SDeCCVY/f yReNCIFrbqcYEx9g0Tqs3H0AV3y3UHlJY/95qx7Hy08g8ojPaZBJrrAhD/k8XyXTNBaG mE2Auckg5Clw6PjI/4GQFthgEcab1t8x3Ai1/Fk9ydxdnj5hU7nYOdM60CnGLDdtfxzv 4pmKUaNUnNGN/k6a4rx/ZLYr9d8UfBoFmO+mR2AU3gLpJRLJDzPV0Iy6jCzCF5Z+1w1d nbDA== X-Gm-Message-State: AOAM531HV8uZroFTQnuBTppqUaFHvlUJ05Xr1ELS0Zn9nzjGO48u5o2h L/9bfHN0NyQvZBPmnpd0jtmR7WbpsRE= X-Google-Smtp-Source: ABdhPJy26RVyRtQLKLLzR4hA+MhLcGGs86k+aA8I8jFVqssnsm7zreR/BVCQ4wVXWIAy9nqH55+p8NmX3Xs= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6638:12c3:b0:319:9b70:5ad8 with SMTP id v3-20020a05663812c300b003199b705ad8mr9045950jas.132.1647020463061; Fri, 11 Mar 2022 09:41:03 -0800 (PST) Date: Fri, 11 Mar 2022 17:39:48 +0000 In-Reply-To: <20220311174001.605719-1-oupton@google.com> Message-Id: <20220311174001.605719-3-oupton@google.com> Mime-Version: 1.0 References: <20220311174001.605719-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH v4 02/15] KVM: arm64: Generally disallow SMC64 for AArch32 guests From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: alexandru.elisei@arm.com, anup@brainfault.org, atishp@atishpatra.org, james.morse@arm.com, jingzhangos@google.com, jmattson@google.com, joro@8bytes.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, maz@kernel.org, pbonzini@redhat.com, pshier@google.com, rananta@google.com, reijiw@google.com, ricarkol@google.com, seanjc@google.com, suzuki.poulose@arm.com, vkuznets@redhat.com, wanpengli@tencent.com, Oliver Upton , Andrew Jones X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220311_094104_630212_F1F57D34 X-CRM114-Status: UNSURE ( 9.34 ) X-CRM114-Notice: Please train this message. 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: The only valid calling SMC calling convention from an AArch32 state is SMC32. Disallow any PSCI function that sets the SMC64 function ID bit when called from AArch32 rather than comparing against know [...] 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:149 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 The only valid calling SMC calling convention from an AArch32 state is SMC32. Disallow any PSCI function that sets the SMC64 function ID bit when called from AArch32 rather than comparing against known SMC64 PSCI functions. It is important to note that the SMC64 flavor of SYSTEM_RESET2 is unintentionally allowed for AArch32 guests without this change. Signed-off-by: Oliver Upton Reviewed-by: Reiji Watanabe Reviewed-by: Andrew Jones --- arch/arm64/kvm/psci.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kvm/psci.c b/arch/arm64/kvm/psci.c index a433c3eac9b7..cd3ee947485f 100644 --- a/arch/arm64/kvm/psci.c +++ b/arch/arm64/kvm/psci.c @@ -216,15 +216,11 @@ static void kvm_psci_narrow_to_32bit(struct kvm_vcpu *vcpu) static unsigned long kvm_psci_check_allowed_function(struct kvm_vcpu *vcpu, u32 fn) { - switch(fn) { - case PSCI_0_2_FN64_CPU_SUSPEND: - case PSCI_0_2_FN64_CPU_ON: - case PSCI_0_2_FN64_AFFINITY_INFO: - /* Disallow these functions for 32bit guests */ - if (vcpu_mode_is_32bit(vcpu)) - return PSCI_RET_NOT_SUPPORTED; - break; - } + /* + * Prevent 32 bit guests from calling 64 bit PSCI functions. + */ + if ((fn & PSCI_0_2_64BIT) && vcpu_mode_is_32bit(vcpu)) + return PSCI_RET_NOT_SUPPORTED; return 0; } From patchwork Fri Mar 11 17:39:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 1604490 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=R9FYRml3; 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=KhxDlCEP; 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 4KFYBb4dVrz9sGD for ; Sat, 12 Mar 2022 04:41:11 +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=O/fy99ufxXWPcXa+aDSAxM5xpUJv0ydHITHYIEbiq8o=; b=R9FYRml3+lYyZ7AiFRVJhsvDKY CF5mPVPaOB9piq0M859iKWqzh4z6TNtD7VeXiQJe6l8KbvJPDEa4p+7gJEQK7cmaePLQsUZU6yVnN lvj83CVuKG7jUqiBLsn14BDYAubVw3TT5f2fP+VSPTfcZYxK1dkhWq7vKw4hiykEKx64GGpX1Mc/5 r7WF9vc6O4hCIDWxRvMFceGbw+zKp5QT0G7XEpiqUWx08aoLSAsNBkW/XgfKdZ3kWyUZd137ZN/KN 5Oe/T+f5yJIIUS5FCw77Rk6HSJ4FfGN4apJlNiIqeowXYmmSDrXXwnq18oOHle1mnwk03eQxwNnFr g1zJvmHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGH-00HWMo-Bm; Fri, 11 Mar 2022 17:41:09 +0000 Received: from mail-il1-x14a.google.com ([2607:f8b0:4864:20::14a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGE-00HWJz-2m for kvm-riscv@lists.infradead.org; Fri, 11 Mar 2022 17:41:07 +0000 Received: by mail-il1-x14a.google.com with SMTP id y11-20020a056e021beb00b002c3f8984f9eso5968669ilv.10 for ; Fri, 11 Mar 2022 09:41:04 -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=/OTsX1zNy9viFOplBNYstPkRDHNcJFJG5fv5Uk1YQKg=; b=KhxDlCEP7i5pg+TPes7A4wiJybDXQnCja8W3xvkSNQF7H3DtgDmlWLCoPooaX4bWcG jNjBUpUgA/81YMzi2tT8kBAhg20V3w9qA9irPbwHGRIXeiq9EJ+WSw5f9HuvIqUXXN9i Q+H4xiqVVwfMuHybjREevMIZdBqDFKe2FTk7Pp5DEGVxYYxe14uDne8K+0kcHNNhWp8V 7qNrsuG+AJ3rzAuEf2KGaUWJQa0yZiIkpi1Ho3pU7bMqDx2LXIRKFsK5fYO7KJROHDME SH3KK9Zmp7xrdleqoXvSOFBiVC9i9SvtKoEtKPIhJMGe6wzm3Tx2epfNkQolsZ+pWKyY 0Diw== 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=/OTsX1zNy9viFOplBNYstPkRDHNcJFJG5fv5Uk1YQKg=; b=xv/45Kc98etLm8mtkcBmcKFhrvcQXZJW522LE1vOQQukyCf32pyJ7QCPYkebo0E0Eb vsbHumfISSLpn6QOSlNI+PWyHvHt0noOh7enRxnJw+Tnbv5nE9bukdFQ60WA+/uDt1yR rUaKLJSeEOFj0yjtlNd5bqpWLWduah5BPWEKXY+AaGI8AnVcsn5vDK1MULb7iJnDKdyb myHJlDUlvyKfPXDMtObXNNpNdHJVA7OH967ApbvmTZQ38jrxFachVdBSdxj+28JTWTpT Iai/1wQFQhsBNZKL0hEH/CI8cCQuCGWPFauVgYJQssonOpOJxxRZFBLZPbkE4uTZ/MJO ItRw== X-Gm-Message-State: AOAM530e13ehOcBB5qqeuzct+jBm5TRUrTtGnZ9NrP8hGQpF2mz/u1dw tsXVOe/Z2/jd5ZY+yr+fUz5wOSfc2t8= X-Google-Smtp-Source: ABdhPJwKry5EljdgitptBSCjxFA/9c5/1sGuFjMs3bGcqzT+eXHRrSrwo4UcxHiZrrN7ePcMplZ7dnDcXOQ= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a6b:750c:0:b0:641:3b39:7b24 with SMTP id l12-20020a6b750c000000b006413b397b24mr8761326ioh.139.1647020464165; Fri, 11 Mar 2022 09:41:04 -0800 (PST) Date: Fri, 11 Mar 2022 17:39:49 +0000 In-Reply-To: <20220311174001.605719-1-oupton@google.com> Message-Id: <20220311174001.605719-4-oupton@google.com> Mime-Version: 1.0 References: <20220311174001.605719-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH v4 03/15] KVM: arm64: Don't depend on fallthrough to hide SYSTEM_RESET2 From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: alexandru.elisei@arm.com, anup@brainfault.org, atishp@atishpatra.org, james.morse@arm.com, jingzhangos@google.com, jmattson@google.com, joro@8bytes.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, maz@kernel.org, pbonzini@redhat.com, pshier@google.com, rananta@google.com, reijiw@google.com, ricarkol@google.com, seanjc@google.com, suzuki.poulose@arm.com, vkuznets@redhat.com, wanpengli@tencent.com, Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220311_094106_153953_EFE2E9F9 X-CRM114-Status: GOOD ( 11.82 ) 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: Depending on a fallthrough to the default case for hiding SYSTEM_RESET2 requires that any new case statements clean up the failure path for this PSCI call. Unhitch SYSTEM_RESET2 from the default case by setting val to PSCI_RET_NOT_SUPPORTED outside of the switch statement. Apply the cleanup to both the PSCI_1_1_FN_SYSTEM_RESET2 and PSCI_1_0_FN_PSCI_FEATU [...] 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:14a 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 Depending on a fallthrough to the default case for hiding SYSTEM_RESET2 requires that any new case statements clean up the failure path for this PSCI call. Unhitch SYSTEM_RESET2 from the default case by setting val to PSCI_RET_NOT_SUPPORTED outside of the switch statement. Apply the cleanup to both the PSCI_1_1_FN_SYSTEM_RESET2 and PSCI_1_0_FN_PSCI_FEATURES handlers. No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/kvm/psci.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kvm/psci.c b/arch/arm64/kvm/psci.c index cd3ee947485f..2a228744d0c4 100644 --- a/arch/arm64/kvm/psci.c +++ b/arch/arm64/kvm/psci.c @@ -310,9 +310,9 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu) static int kvm_psci_1_x_call(struct kvm_vcpu *vcpu, u32 minor) { + unsigned long val = PSCI_RET_NOT_SUPPORTED; u32 psci_fn = smccc_get_function(vcpu); u32 arg; - unsigned long val; int ret = 1; if (minor > 1) @@ -328,6 +328,8 @@ static int kvm_psci_1_x_call(struct kvm_vcpu *vcpu, u32 minor) if (val) break; + val = PSCI_RET_NOT_SUPPORTED; + switch(arg) { case PSCI_0_2_FN_PSCI_VERSION: case PSCI_0_2_FN_CPU_SUSPEND: @@ -346,13 +348,8 @@ static int kvm_psci_1_x_call(struct kvm_vcpu *vcpu, u32 minor) break; case PSCI_1_1_FN_SYSTEM_RESET2: case PSCI_1_1_FN64_SYSTEM_RESET2: - if (minor >= 1) { + if (minor >= 1) val = 0; - break; - } - fallthrough; - default: - val = PSCI_RET_NOT_SUPPORTED; break; } break; @@ -373,7 +370,7 @@ static int kvm_psci_1_x_call(struct kvm_vcpu *vcpu, u32 minor) val = PSCI_RET_INVALID_PARAMS; break; } - fallthrough; + break; default: return kvm_psci_0_2_call(vcpu); } From patchwork Fri Mar 11 17:39:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 1604491 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=s+naHIUc; 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=ifcI2icc; 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 4KFYBb5X8cz9sGJ for ; Sat, 12 Mar 2022 04:41:11 +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=5eUg5kMnf8oresiZNcpRmfhX5I4u5fsS/SEj+YfmW0A=; b=s+naHIUcr2N94QsX+Ys6Xy0ftk SRCJk90OQE3Ud1kW11ZGrxL8YYR87IjruXHSp0VBCq2lwaBCM3mdSQZf/lW7Asg5VuNqogxvoTU+g R7CdF1I9J2bt8OoadpBs5RejJ5YT4eEbSn/hvBkXkVN37W/uP4hYiar95ZznNlgJ40CIsF+mD3acU uvGPIUOfNnh/scDH49qWFSl5V0iWLUIX11IUrkswaNS4nYmm/fX7Op82y8ELSoF1R9U307WZk2l7j NZG2UF9YzIco2L7MW0HlUSYnpelxDH5v9ZfAy4/3aAjUQ39ts9H8D4+icl+/NDuKoeKaKma45eurv JHyQsPbQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGH-00HWMy-JH; Fri, 11 Mar 2022 17:41:09 +0000 Received: from mail-il1-x14a.google.com ([2607:f8b0:4864:20::14a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGE-00HWKO-KI for kvm-riscv@lists.infradead.org; Fri, 11 Mar 2022 17:41:07 +0000 Received: by mail-il1-x14a.google.com with SMTP id m17-20020a923f11000000b002c10e8f4c44so5990043ila.1 for ; Fri, 11 Mar 2022 09:41:05 -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=WkuuwGfi14coE8ixYDYlznYyITLCUK6RL9rnjxo/EMQ=; b=ifcI2iccrckyoj5u9oTr/pf9a3mM4OBwnO9VJ+IR6Ko80mV6SEi6/JDQnehd2z+mll qVL/vQGjAC0wcAVLHyDNpWYCybE0dUBSXAbsnGRGIHoUBj4DODFXFSaSDAYSDB9L6E/2 zA8ZP7giNob46Z4mmaHsxqQ+atFSX/Y8hlmuDcjWdV8kOgx2ty5ne0imY2jlvXkDNLEw DFJo+k59FcI5DjvVwhJkZLNlevW1ElkHLZFHzK0N9htgU94rDohu0aMvE562OBmi+OKU uUDC9JLaw0a+FMZ9zOWVTyOT8erKXKdSNOSdpf3jRxYrineA6GdrUL/6Wbj5Ir+WwoVe HOaw== 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=WkuuwGfi14coE8ixYDYlznYyITLCUK6RL9rnjxo/EMQ=; b=F85TldNbs5JrHLfdPMZRkDKjWZW1LjiDF8C0EltOFMXm38hgwbYOJjm7KqJrSkQHs+ oy5P/Tq4yoF0WbqnSoISKlzn6s/2z7uowsUQhCLuL8HYvwQOTed7D6TIZ7IbPG7uonms xNPNiVhZ6yjLAyeqG6O46YcjNJChKLtSsjdq53ZQJIT3XYhhC+11VARNs+HH8vBxqrqn HoVsMHMKlcadmLF42VKHIryiWGS0sut6TgzHzTGWXxAfD6cdJ7mN3lTEv+pt93XAAupQ gBV5+m7uvt1gkwGz2825BwwH1PDKCEu0JowFSOEkiQ1G7PMGbNrdLRe70o1mh2MduL+7 qSkw== X-Gm-Message-State: AOAM533fMRN/jmGdMgOW+PvNtTmiixhLL6vv0gDGpzHiiIpkdQPYXf+L fse3J5RdaDcibu3KgFtqGsKeydRWMrg= X-Google-Smtp-Source: ABdhPJxGWatXCqCoiKhIiZky04qigEDGVCFcOMZBHSLW1DHnTi8cxj4H94EdjPxP2GR9SIoaEqsx1XYL/70= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6602:45b:b0:645:bdc2:fe13 with SMTP id e27-20020a056602045b00b00645bdc2fe13mr8682643iov.114.1647020465380; Fri, 11 Mar 2022 09:41:05 -0800 (PST) Date: Fri, 11 Mar 2022 17:39:50 +0000 In-Reply-To: <20220311174001.605719-1-oupton@google.com> Message-Id: <20220311174001.605719-5-oupton@google.com> Mime-Version: 1.0 References: <20220311174001.605719-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH v4 04/15] KVM: arm64: Dedupe vCPU power off helpers From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: alexandru.elisei@arm.com, anup@brainfault.org, atishp@atishpatra.org, james.morse@arm.com, jingzhangos@google.com, jmattson@google.com, joro@8bytes.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, maz@kernel.org, pbonzini@redhat.com, pshier@google.com, rananta@google.com, reijiw@google.com, ricarkol@google.com, seanjc@google.com, suzuki.poulose@arm.com, vkuznets@redhat.com, wanpengli@tencent.com, Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220311_094106_689016_952EBD57 X-CRM114-Status: UNSURE ( 9.72 ) X-CRM114-Notice: Please train this message. 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: vcpu_power_off() and kvm_psci_vcpu_off() are equivalent; rename the former and replace all callsites to the latter. No functional change intended. Signed-off-by: Oliver Upton Reviewed-by: Reiji Watanabe --- arch/arm64/include/asm/kvm_host.h | 2 ++ arch/arm64/kvm/arm.c | 6 +++--- arch/arm64/kvm/psci.c | 11 [...] 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:14a 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 vcpu_power_off() and kvm_psci_vcpu_off() are equivalent; rename the former and replace all callsites to the latter. No functional change intended. Signed-off-by: Oliver Upton Reviewed-by: Reiji Watanabe --- arch/arm64/include/asm/kvm_host.h | 2 ++ arch/arm64/kvm/arm.c | 6 +++--- arch/arm64/kvm/psci.c | 11 ++--------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 0e96087885fe..a2e00129cf4b 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -826,4 +826,6 @@ void __init kvm_hyp_reserve(void); static inline void kvm_hyp_reserve(void) { } #endif +void kvm_arm_vcpu_power_off(struct kvm_vcpu *vcpu); + #endif /* __ARM64_KVM_HOST_H__ */ diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 17021bc8ee2c..0b71c0a27a20 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -432,7 +432,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) vcpu->cpu = -1; } -static void vcpu_power_off(struct kvm_vcpu *vcpu) +void kvm_arm_vcpu_power_off(struct kvm_vcpu *vcpu) { vcpu->arch.power_off = true; kvm_make_request(KVM_REQ_SLEEP, vcpu); @@ -460,7 +460,7 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, vcpu->arch.power_off = false; break; case KVM_MP_STATE_STOPPED: - vcpu_power_off(vcpu); + kvm_arm_vcpu_power_off(vcpu); break; default: ret = -EINVAL; @@ -1124,7 +1124,7 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu, * Handle the "start in power-off" case. */ if (test_bit(KVM_ARM_VCPU_POWER_OFF, vcpu->arch.features)) - vcpu_power_off(vcpu); + kvm_arm_vcpu_power_off(vcpu); else vcpu->arch.power_off = false; diff --git a/arch/arm64/kvm/psci.c b/arch/arm64/kvm/psci.c index 2a228744d0c4..f5c865485f09 100644 --- a/arch/arm64/kvm/psci.c +++ b/arch/arm64/kvm/psci.c @@ -52,13 +52,6 @@ static unsigned long kvm_psci_vcpu_suspend(struct kvm_vcpu *vcpu) return PSCI_RET_SUCCESS; } -static void kvm_psci_vcpu_off(struct kvm_vcpu *vcpu) -{ - vcpu->arch.power_off = true; - kvm_make_request(KVM_REQ_SLEEP, vcpu); - kvm_vcpu_kick(vcpu); -} - static inline bool kvm_psci_valid_affinity(struct kvm_vcpu *vcpu, unsigned long affinity) { @@ -249,7 +242,7 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu) val = kvm_psci_vcpu_suspend(vcpu); break; case PSCI_0_2_FN_CPU_OFF: - kvm_psci_vcpu_off(vcpu); + kvm_arm_vcpu_power_off(vcpu); val = PSCI_RET_SUCCESS; break; case PSCI_0_2_FN_CPU_ON: @@ -387,7 +380,7 @@ static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu) switch (psci_fn) { case KVM_PSCI_FN_CPU_OFF: - kvm_psci_vcpu_off(vcpu); + kvm_arm_vcpu_power_off(vcpu); val = PSCI_RET_SUCCESS; break; case KVM_PSCI_FN_CPU_ON: From patchwork Fri Mar 11 17:39:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 1604493 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=d0VNMMvZ; 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=fbVhFEnR; 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 4KFYBd2Ldvz9sGJ for ; Sat, 12 Mar 2022 04:41:13 +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=AoGkjBUX/6gasj77ulrJ/JKut+hjFKSBS7UtyaZFBVg=; b=d0VNMMvZMorSYsfuPvuVKv+d88 cUmhoCZdChwuCfgZQF4AA1jP7EYu0WgdvsXPhu3N7kJg3i0EV4Dr+dLG6r/do9sJ3bn0NbS6R3RSF GdsKoyXi22bG2qZGE4FR2IZ/gulcCMJeY+SLUb+diSXwKwDRIH4AN+G/62phUFn65dBvrSUhzLOpv xzV84mcenBjiNmQCYHKjX0+L/yh6PdDvgAqKc4MvmShw5TcygxDYG/UTdu2FB2UhmUbDamNeOksd5 +3KKyuRrODzepY1d3tCKZ0jnV7UtYujn48cTeC9M5nsqdoSNsM7TVin92TDdZGv1ZphMrN6nYr7KU 88TAEKqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGJ-00HWOR-5M; Fri, 11 Mar 2022 17:41:11 +0000 Received: from mail-io1-xd4a.google.com ([2607:f8b0:4864:20::d4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGG-00HWL4-5b for kvm-riscv@lists.infradead.org; Fri, 11 Mar 2022 17:41:09 +0000 Received: by mail-io1-xd4a.google.com with SMTP id g11-20020a056602072b00b00645cc0735d7so6758549iox.1 for ; Fri, 11 Mar 2022 09:41:06 -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=0m6A5PPOCVg09Pxf2RbRPcM9r3W2FFgrGrefirCG0dw=; b=fbVhFEnRC0EJPcOif4yxOG+vX5ff+3YEmZwaviTIYAHDXLbxiZ7Zo8BLsfLuOBjSdP DJ6FmCWIJ1fHqZij7wk4TnaYX2amMeAqIxi5LXKh66ycjGDLUEY9sZoXWUVd34tAegQu r9Zp4d1mv73ckFVqO0oQLkmJHIruMrHD32EO3Zj0DnyVQZvX3zb5R05EPBxZY1bk1Buv tVFCcDiWJUQ8q23UelSfmdcwp45bECQ0uTyvwfot1322EPqUCHY8D5B+G5drMDP98iOg 5RggRtDBZxVeCgnlrZw1yXVAAXuDBtvYr57fNQYX3vVHf05Bl2p32LEAViPl+HtPGtm7 NXXQ== 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=0m6A5PPOCVg09Pxf2RbRPcM9r3W2FFgrGrefirCG0dw=; b=5hnmQbnWUPhE4IBR6mhLJd3q2pnTeFxDrl2N3NCA8np53jiN4M+WLmSi0lB2NfPqAk CTD7SG3w5MZ9vuBqns0jgOJ8ZUi0l1OaNXpcDKsThXhingSVyCKlbyFwfFgRNDh1YmqH 0tRMsTaR5Vwz9Pdq0DpUtXUHgP9iaFshuB6N2LAaV0kh+hD2d23NTaxvfG6hJjED33in 7fDxdTXP0bp/smA4sm3lsyknc4FPnfKenq40TS4zUqKOr3oPl+joE04CKvKWSd1rjYQ5 KNUPJ5hG+ALUcDDMbJ7NCIdd0cEGV2C/1k/vaRHQIt4tz4NuLshfbcy8f5yG4I8KPS5b +tTg== X-Gm-Message-State: AOAM531vwyMjHYfdSFZo5Lr7JJExbsZCbJrbhC8B4brmljSJ5l6BwoNt 38PWy8ZHcZ+LvRfcIdktH1gFu1mqslk= X-Google-Smtp-Source: ABdhPJw3zPOyvK81rSTzo3SeazHpGkvLlivP1gVUMcVrJfawtucSdssR21NPEIR4SffXhQo1QgfyQitzJL8= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a5d:89d8:0:b0:645:d853:66f0 with SMTP id a24-20020a5d89d8000000b00645d85366f0mr8552754iot.30.1647020466288; Fri, 11 Mar 2022 09:41:06 -0800 (PST) Date: Fri, 11 Mar 2022 17:39:51 +0000 In-Reply-To: <20220311174001.605719-1-oupton@google.com> Message-Id: <20220311174001.605719-6-oupton@google.com> Mime-Version: 1.0 References: <20220311174001.605719-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH v4 05/15] KVM: arm64: Track vCPU power state using MP state values From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: alexandru.elisei@arm.com, anup@brainfault.org, atishp@atishpatra.org, james.morse@arm.com, jingzhangos@google.com, jmattson@google.com, joro@8bytes.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, maz@kernel.org, pbonzini@redhat.com, pshier@google.com, rananta@google.com, reijiw@google.com, ricarkol@google.com, seanjc@google.com, suzuki.poulose@arm.com, vkuznets@redhat.com, wanpengli@tencent.com, Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220311_094108_261101_B4A6C795 X-CRM114-Status: GOOD ( 17.46 ) 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: A subsequent change to KVM will add support for additional power states. Store the MP state by value rather than keeping track of it as a boolean. No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_host.h | 5 +++-- arch/arm64/kvm/arm.c | 22 ++++++++++++ arch/arm64/kvm/psci.c | 12 ++++++------ 3 files changed [...] 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:d4a 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 A subsequent change to KVM will add support for additional power states. Store the MP state by value rather than keeping track of it as a boolean. No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_host.h | 5 +++-- arch/arm64/kvm/arm.c | 22 ++++++++++++---------- arch/arm64/kvm/psci.c | 12 ++++++------ 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index a2e00129cf4b..da58eb96d2a8 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -355,8 +355,8 @@ struct kvm_vcpu_arch { u32 mdscr_el1; } guest_debug_preserved; - /* vcpu power-off state */ - bool power_off; + /* vcpu power state */ + struct kvm_mp_state mp_state; /* Don't run the guest (internal implementation need) */ bool pause; @@ -827,5 +827,6 @@ static inline void kvm_hyp_reserve(void) { } #endif void kvm_arm_vcpu_power_off(struct kvm_vcpu *vcpu); +bool kvm_arm_vcpu_stopped(struct kvm_vcpu *vcpu); #endif /* __ARM64_KVM_HOST_H__ */ diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 0b71c0a27a20..3918d078fc4d 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -434,18 +434,20 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) void kvm_arm_vcpu_power_off(struct kvm_vcpu *vcpu) { - vcpu->arch.power_off = true; + vcpu->arch.mp_state.mp_state = KVM_MP_STATE_STOPPED; kvm_make_request(KVM_REQ_SLEEP, vcpu); kvm_vcpu_kick(vcpu); } +bool kvm_arm_vcpu_stopped(struct kvm_vcpu *vcpu) +{ + return vcpu->arch.mp_state.mp_state == KVM_MP_STATE_STOPPED; +} + int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu, struct kvm_mp_state *mp_state) { - if (vcpu->arch.power_off) - mp_state->mp_state = KVM_MP_STATE_STOPPED; - else - mp_state->mp_state = KVM_MP_STATE_RUNNABLE; + *mp_state = vcpu->arch.mp_state; return 0; } @@ -457,7 +459,7 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, switch (mp_state->mp_state) { case KVM_MP_STATE_RUNNABLE: - vcpu->arch.power_off = false; + vcpu->arch.mp_state = *mp_state; break; case KVM_MP_STATE_STOPPED: kvm_arm_vcpu_power_off(vcpu); @@ -480,7 +482,7 @@ int kvm_arch_vcpu_runnable(struct kvm_vcpu *v) { bool irq_lines = *vcpu_hcr(v) & (HCR_VI | HCR_VF); return ((irq_lines || kvm_vgic_vcpu_pending_irq(v)) - && !v->arch.power_off && !v->arch.pause); + && !kvm_arm_vcpu_stopped(v) && !v->arch.pause); } bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu) @@ -597,10 +599,10 @@ static void vcpu_req_sleep(struct kvm_vcpu *vcpu) struct rcuwait *wait = kvm_arch_vcpu_get_wait(vcpu); rcuwait_wait_event(wait, - (!vcpu->arch.power_off) &&(!vcpu->arch.pause), + (!kvm_arm_vcpu_stopped(vcpu)) && (!vcpu->arch.pause), TASK_INTERRUPTIBLE); - if (vcpu->arch.power_off || vcpu->arch.pause) { + if (kvm_arm_vcpu_stopped(vcpu) || vcpu->arch.pause) { /* Awaken to handle a signal, request we sleep again later. */ kvm_make_request(KVM_REQ_SLEEP, vcpu); } @@ -1126,7 +1128,7 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu, if (test_bit(KVM_ARM_VCPU_POWER_OFF, vcpu->arch.features)) kvm_arm_vcpu_power_off(vcpu); else - vcpu->arch.power_off = false; + vcpu->arch.mp_state.mp_state = KVM_MP_STATE_RUNNABLE; return 0; } diff --git a/arch/arm64/kvm/psci.c b/arch/arm64/kvm/psci.c index f5c865485f09..efd4428fda1c 100644 --- a/arch/arm64/kvm/psci.c +++ b/arch/arm64/kvm/psci.c @@ -77,7 +77,7 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu) */ if (!vcpu) return PSCI_RET_INVALID_PARAMS; - if (!vcpu->arch.power_off) { + if (!kvm_arm_vcpu_stopped(vcpu)) { if (kvm_psci_version(source_vcpu) != KVM_ARM_PSCI_0_1) return PSCI_RET_ALREADY_ON; else @@ -101,12 +101,12 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu) kvm_make_request(KVM_REQ_VCPU_RESET, vcpu); /* - * Make sure the reset request is observed if the change to - * power_off is observed. + * Make sure the reset request is observed if the RUNNABLE mp_state is + * observed. */ smp_wmb(); - vcpu->arch.power_off = false; + vcpu->arch.mp_state.mp_state = KVM_MP_STATE_RUNNABLE; kvm_vcpu_wake_up(vcpu); return PSCI_RET_SUCCESS; @@ -144,7 +144,7 @@ static unsigned long kvm_psci_vcpu_affinity_info(struct kvm_vcpu *vcpu) mpidr = kvm_vcpu_get_mpidr_aff(tmp); if ((mpidr & target_affinity_mask) == target_affinity) { matching_cpus++; - if (!tmp->arch.power_off) + if (!kvm_arm_vcpu_stopped(tmp)) return PSCI_0_2_AFFINITY_LEVEL_ON; } } @@ -170,7 +170,7 @@ static void kvm_prepare_system_event(struct kvm_vcpu *vcpu, u32 type, u64 flags) * re-initialized. */ kvm_for_each_vcpu(i, tmp, vcpu->kvm) - tmp->arch.power_off = true; + tmp->arch.mp_state.mp_state = KVM_MP_STATE_STOPPED; kvm_make_all_cpus_request(vcpu->kvm, KVM_REQ_SLEEP); memset(&vcpu->run->system_event, 0, sizeof(vcpu->run->system_event)); From patchwork Fri Mar 11 17:39:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 1604492 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=oAE5BZqx; 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=agb3tdzK; 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 4KFYBd1gqRz9sGD for ; Sat, 12 Mar 2022 04:41:13 +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=XrylJxoard6D+B6/9QpSHQmcXsSgjltVBkaeA9Ry3+M=; b=oAE5BZqx7aifWEgiccP20l9Iy0 e8oTcdnSWSS62WcdMSKTY2qWm6xNe3Qs7OMnYPLvPrir9ssW1wIcHPRmepTHSZU+6g1dkoYS25B+Q rPs5CbgrFHtIbDKPak+e62N6OjZ9tQvdO5efRmdlAtUBLX23BYwH2lbEmo7V1mae19ri2aLZclS8e NnH/Vkj+pDD+8lOJcC1YXsZYuhOCXz16fibkZ9Gx2C/EW+zPJ7ZcADte/7kMzWxVXw3FVuqzOuLwz 0TVFV3jlr9vZ3vF0KJjKKxogn7DCMV0GNjj8EiFFyg8uR5Mkrce7bRoNgsr397ID47S3t2Hj2SiUW KNvgYilQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGJ-00HWOE-0E; Fri, 11 Mar 2022 17:41:11 +0000 Received: from mail-il1-x14a.google.com ([2607:f8b0:4864:20::14a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGG-00HWLP-C5 for kvm-riscv@lists.infradead.org; Fri, 11 Mar 2022 17:41:09 +0000 Received: by mail-il1-x14a.google.com with SMTP id j7-20020a92ca07000000b002c2b8f24cffso5984916ils.9 for ; Fri, 11 Mar 2022 09:41:07 -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=7ZRBkS4U0RFhMHj2rsuxMbzaij5n0dyzv68dBdi/1V4=; b=agb3tdzKqOaqoSpS5U/p593tiHNWqqZJpCJfTx6gflLYyYPaiUx9HO1yB+3F8H6FmE cVmT3Q3SIyKv2ALdwrHb71MbMAovi69YILYjVnI8iH2bT94dX9eYTXj922gCmpI9Bz4G 0ICO77FbsL3yb1LVQra6lGmL0ybIgUa5vLxMGVJUJGMWGQplz1gVTXf7+h9teAs/s7ly 6VS2GxT/OsB7vGqrMOHEmHMZq2e9MRHJ64j7+VwGzT9A3Ct64Kb6KQFimn57Jg1ISLuX 3I07mWDcVavQz4BZFLNYaY4e67ThPDC2U7U3teJaD5KtlB/2Wu3f/3S8JFbaA0GrCvh3 sLQQ== 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=7ZRBkS4U0RFhMHj2rsuxMbzaij5n0dyzv68dBdi/1V4=; b=JBu/+jzfIVkUj+GMSrS8Bx4n5daZqARQxmsVAxk1RasVz6xiV82pC66xFR1+blHIwd qlAdA3Cz9JkqK+aUVBnBzVOUXaaTyPKQrgEeSQvAkmpV4I/xMv+veaMyWGtrop7rrLTK ywvhl0ALJZdO6xxEete8dfoqGEVa/amU12ErbWK9imjRTGa4QIseUhNn/m9NbNtdiiC9 Xg+kI6V4JWce+tyXFYws9+1q1yKmiRVkvCaxqI+Hu6OlwcqgMz1KT/WOtsPPmovLtvTW gtBWJYyU1SuA+HMDhzfjj94RqlrzN4f9zg+JhFEDsxsYcdDYAVlAcM2fcOl7XVlWiIha Id/w== X-Gm-Message-State: AOAM5321NI8p+CDNHyyWfXTQ41E7zcACX5Jv2Mj2adb5KIN7EIx0xvKC T1iS2hKlGLM8jnACjkfq95KATzEXhQs= X-Google-Smtp-Source: ABdhPJw9BiYukm5oFkfLFDSfcoF0YG+SBFyjRPDOEtEfu56g5hciDXgPevhVFTjypFLBz3WPqlZZ86y7cJg= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a5e:a80a:0:b0:645:b477:bc23 with SMTP id c10-20020a5ea80a000000b00645b477bc23mr8739969ioa.191.1647020467117; Fri, 11 Mar 2022 09:41:07 -0800 (PST) Date: Fri, 11 Mar 2022 17:39:52 +0000 In-Reply-To: <20220311174001.605719-1-oupton@google.com> Message-Id: <20220311174001.605719-7-oupton@google.com> Mime-Version: 1.0 References: <20220311174001.605719-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH v4 06/15] KVM: arm64: Rename the KVM_REQ_SLEEP handler From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: alexandru.elisei@arm.com, anup@brainfault.org, atishp@atishpatra.org, james.morse@arm.com, jingzhangos@google.com, jmattson@google.com, joro@8bytes.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, maz@kernel.org, pbonzini@redhat.com, pshier@google.com, rananta@google.com, reijiw@google.com, ricarkol@google.com, seanjc@google.com, suzuki.poulose@arm.com, vkuznets@redhat.com, wanpengli@tencent.com, Oliver Upton , Andrew Jones X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220311_094108_436775_09F479B4 X-CRM114-Status: GOOD ( 10.06 ) 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: The naming of the kvm_req_sleep function is confusing: the function itself sleeps the vCPU, it does not request such an event. Rename the function to make its purpose more clear. No functional change intended. 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:14a 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 The naming of the kvm_req_sleep function is confusing: the function itself sleeps the vCPU, it does not request such an event. Rename the function to make its purpose more clear. No functional change intended. Signed-off-by: Oliver Upton Reviewed-by: Andrew Jones --- arch/arm64/kvm/arm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 3918d078fc4d..7c297ddc8177 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -594,7 +594,7 @@ void kvm_arm_resume_guest(struct kvm *kvm) } } -static void vcpu_req_sleep(struct kvm_vcpu *vcpu) +static void kvm_vcpu_sleep(struct kvm_vcpu *vcpu) { struct rcuwait *wait = kvm_arch_vcpu_get_wait(vcpu); @@ -652,7 +652,7 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu) { if (kvm_request_pending(vcpu)) { if (kvm_check_request(KVM_REQ_SLEEP, vcpu)) - vcpu_req_sleep(vcpu); + kvm_vcpu_sleep(vcpu); if (kvm_check_request(KVM_REQ_VCPU_RESET, vcpu)) kvm_reset_vcpu(vcpu); From patchwork Fri Mar 11 17:39:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 1604494 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=YnEJXhXx; 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=iBYHZZIu; 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 4KFYBf4J1wz9sGD for ; Sat, 12 Mar 2022 04:41:14 +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=DpXfr4CSYi5jguJ1jYnacrZbg/qE3OljYxaIW9yXOSk=; b=YnEJXhXxSP+Xk6o3nPbmRzeOp4 lAJXgIxrg7h0wXVt/E3JkuRNEuYd0GT5D3WeylgM+U4IMBXaGCAElA9SFdKqtgaKpBRu5HheMG/nu agNu9R3JojzPlT35LqpsyU49mZF+BiDEr4ftZSXmwlpad93QEizbb14xa/IQr7939J+qxya6FvEB8 gHA+ore5VrpVyNHAILnDQ5kEBSv8No+Wyb3lkS7SxFeMIjrmpD68YHE2hcKGvTvEDdFCqxK/zrOGz d/JS/KXby4Rqrq9k1Tf7f4KGL6rgOS5Z1dBkXAI7Txe6YB5NtKafixqpLElLgax7mF+0TT9tgHxuR fkq+JtBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGK-00HWPh-A3; Fri, 11 Mar 2022 17:41:12 +0000 Received: from mail-io1-xd4a.google.com ([2607:f8b0:4864:20::d4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGH-00HWMG-Ds for kvm-riscv@lists.infradead.org; Fri, 11 Mar 2022 17:41:11 +0000 Received: by mail-io1-xd4a.google.com with SMTP id z16-20020a05660217d000b006461c7cbee3so6699953iox.21 for ; Fri, 11 Mar 2022 09:41:08 -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=9XdJKUFytcHkfxO8A0zHHdaSq5C6RUOo0dHsNroWzi4=; b=iBYHZZIu4+glns+DBM+1sLjFX7LQFA3zP0tDyNnFwpnRI/lNEol8HGFtx6Y2+Mi7ZK bQtPSTWOAKYg0fLgu1VqZ6kbC9RU/AJW6FF/ihA6uwiYBOHi1mk8SMwigIy/2ixjySNR tPuIxyMPycs0AUgDQulOYiG6DlF4YTQTc3sq37NMQn+Ohtd7drMQyK77PNolcn2BeeOV qzyTOTnZmWjZ6VaMTWv36WU9dPNOA1B5S+XBQqnCsDEK/FRqSBALFbxs5m91dBcFGMae y4S1v/2F5Sil92fkkuNmvMeX1cSkC8BFJL67AirOBoNyu1OH5kEKaDoVbtFCenBSFAzW w4uA== 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=9XdJKUFytcHkfxO8A0zHHdaSq5C6RUOo0dHsNroWzi4=; b=rRQLAabbFwr8UpACJ371sIVgBBE8Imm5TPInEIXN7hkzutGtaaWAXp4b/HKFjg7WDF 6+sjwVpMvQWJhNlRv+KRcewFv35LmXWeQH36+bfqV+ib7Q3SGif+bLzeQiRsuz0dgI96 hG67NpzWgTFfse7ynNnDlXJ0HxWBeZJ6YS6+AExw2KyVKpB42AWHyAhPlZNawOI8Oz6J o6dp9SEZVTNo8zEX4pzFKm3c5hiH7FzsOEgyZxw9v6Amg4X5fa++WPhGSeBmdbEBQ0Dz jV4P8Qg6hOwdWrauH+eEX9j6FFC5ze1q/q9fC6+GhINFzBgI1tuX4jogk6WR2xUSaIMk W6iA== X-Gm-Message-State: AOAM533U6epQLJulFIFsCyZhDjtEwZptaoX8aslLHT2vD38c6+KzNoHv PBOmVMLaXfgtwDNxDv/y5aCFm/0eBO0= X-Google-Smtp-Source: ABdhPJy0gVFdG3BgjTaM6i8MVhqzhgFYYyl2pWvpkR0CNXcn7tlc65SXQKYNv9FC9ebaoIoCLgIk9P8Y8yM= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6e02:1569:b0:2be:ffc9:8bb4 with SMTP id k9-20020a056e02156900b002beffc98bb4mr9168928ilu.229.1647020468144; Fri, 11 Mar 2022 09:41:08 -0800 (PST) Date: Fri, 11 Mar 2022 17:39:53 +0000 In-Reply-To: <20220311174001.605719-1-oupton@google.com> Message-Id: <20220311174001.605719-8-oupton@google.com> Mime-Version: 1.0 References: <20220311174001.605719-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH v4 07/15] KVM: Create helper for setting a system event exit From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: alexandru.elisei@arm.com, anup@brainfault.org, atishp@atishpatra.org, james.morse@arm.com, jingzhangos@google.com, jmattson@google.com, joro@8bytes.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, maz@kernel.org, pbonzini@redhat.com, pshier@google.com, rananta@google.com, reijiw@google.com, ricarkol@google.com, seanjc@google.com, suzuki.poulose@arm.com, vkuznets@redhat.com, wanpengli@tencent.com, Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220311_094109_513530_A7260823 X-CRM114-Status: GOOD ( 10.95 ) 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: Create a helper that appropriately configures kvm_run for a system event exit. No functional change intended. Suggested-by: Marc Zyngier Signed-off-by: Oliver Upton Acked-by: Anup Patel --- arch/arm64/kvm/psci.c | 5 +---- arch/riscv/kvm/vcpu_sbi_v01.c [...] 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:d4a 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 Create a helper that appropriately configures kvm_run for a system event exit. No functional change intended. Suggested-by: Marc Zyngier Signed-off-by: Oliver Upton Acked-by: Anup Patel --- arch/arm64/kvm/psci.c | 5 +---- arch/riscv/kvm/vcpu_sbi_v01.c | 4 +--- arch/x86/kvm/x86.c | 6 ++---- include/linux/kvm_host.h | 2 ++ virt/kvm/kvm_main.c | 8 ++++++++ 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/arch/arm64/kvm/psci.c b/arch/arm64/kvm/psci.c index efd4428fda1c..78266716165e 100644 --- a/arch/arm64/kvm/psci.c +++ b/arch/arm64/kvm/psci.c @@ -173,10 +173,7 @@ static void kvm_prepare_system_event(struct kvm_vcpu *vcpu, u32 type, u64 flags) tmp->arch.mp_state.mp_state = KVM_MP_STATE_STOPPED; kvm_make_all_cpus_request(vcpu->kvm, KVM_REQ_SLEEP); - memset(&vcpu->run->system_event, 0, sizeof(vcpu->run->system_event)); - vcpu->run->system_event.type = type; - vcpu->run->system_event.flags = flags; - vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT; + kvm_vcpu_set_system_event_exit(vcpu, type, flags); } static void kvm_psci_system_off(struct kvm_vcpu *vcpu) diff --git a/arch/riscv/kvm/vcpu_sbi_v01.c b/arch/riscv/kvm/vcpu_sbi_v01.c index 07e2de14433a..c5581008dd88 100644 --- a/arch/riscv/kvm/vcpu_sbi_v01.c +++ b/arch/riscv/kvm/vcpu_sbi_v01.c @@ -24,9 +24,7 @@ static void kvm_sbi_system_shutdown(struct kvm_vcpu *vcpu, tmp->arch.power_off = true; kvm_make_all_cpus_request(vcpu->kvm, KVM_REQ_SLEEP); - memset(&run->system_event, 0, sizeof(run->system_event)); - run->system_event.type = type; - run->exit_reason = KVM_EXIT_SYSTEM_EVENT; + kvm_vcpu_set_system_event_exit(vcpu, type, 0); } static int kvm_sbi_ext_v01_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 7131d735b1ef..b3b94408cc61 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9903,14 +9903,12 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) if (kvm_check_request(KVM_REQ_APIC_PAGE_RELOAD, vcpu)) kvm_vcpu_reload_apic_access_page(vcpu); if (kvm_check_request(KVM_REQ_HV_CRASH, vcpu)) { - vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT; - vcpu->run->system_event.type = KVM_SYSTEM_EVENT_CRASH; + kvm_vcpu_set_system_event_exit(vcpu, KVM_SYSTEM_EVENT_CRASH, 0); r = 0; goto out; } if (kvm_check_request(KVM_REQ_HV_RESET, vcpu)) { - vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT; - vcpu->run->system_event.type = KVM_SYSTEM_EVENT_RESET; + kvm_vcpu_set_system_event_exit(vcpu, KVM_SYSTEM_EVENT_RESET, 0); r = 0; goto out; } diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index f11039944c08..c2a4fd2382e2 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -2202,6 +2202,8 @@ static inline void kvm_handle_signal_exit(struct kvm_vcpu *vcpu) } #endif /* CONFIG_KVM_XFER_TO_GUEST_WORK */ +void kvm_vcpu_set_system_event_exit(struct kvm_vcpu *vcpu, u32 type, u64 flags); + /* * This defines how many reserved entries we want to keep before we * kick the vcpu to the userspace to avoid dirty ring full. This diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 58d31da8a2f7..197bae04ca34 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3194,6 +3194,14 @@ void kvm_vcpu_mark_page_dirty(struct kvm_vcpu *vcpu, gfn_t gfn) } EXPORT_SYMBOL_GPL(kvm_vcpu_mark_page_dirty); +void kvm_vcpu_set_system_event_exit(struct kvm_vcpu *vcpu, u32 type, u64 flags) +{ + memset(&vcpu->run->system_event, 0, sizeof(vcpu->run->system_event)); + vcpu->run->system_event.type = type; + vcpu->run->system_event.flags = flags; + vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT; +} + void kvm_sigset_activate(struct kvm_vcpu *vcpu) { if (!vcpu->sigset_active) From patchwork Fri Mar 11 17:39:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 1604495 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=kVk0hi0d; 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=TfK01IHy; 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 4KFYBh5qfXz9sGD for ; Sat, 12 Mar 2022 04:41:16 +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=RDWCkkAMC4YTfj95spTyeoyt9g08QT2v5vPvDZNFPQU=; b=kVk0hi0dCgPY7oeGCiRB0G5yvM qca1VSFLX/qyNL2HaTG+qS44wNjm1RakgK8JW+0gJbOwcEJJErRYWC8vB+/cs8pFXpbvbaidpd8Mi F93bMlEu5iUDRReTdGCcWejsm8CkcUsn/3XQq4dSNgD+T1sy+e3Dl7ntPG0CJPC1tdxiq9NUJWELd x/owxhNfQDdKZAQkMlDHKYcKrYX5dcMYkHyLC67HTOr2Ene73N/lAilfvSe+FDVmNvND3fqy//BqF qMhkoPraG7ZEY9xmsU8xX7Tv6/fExXZs9k7MeNaRv7Vffs3592W5f2polByCZHfJU25rNJUekInGB ScwJjwPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGM-00HWSG-GP; Fri, 11 Mar 2022 17:41:14 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGJ-00HWNE-Ni for kvm-riscv@lists.infradead.org; Fri, 11 Mar 2022 17:41:13 +0000 Received: by mail-yb1-xb49.google.com with SMTP id q76-20020a25d94f000000b00628bdf8d1a9so7835183ybg.17 for ; Fri, 11 Mar 2022 09:41:10 -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=w/UueSoSfkkV5ZaqeN0ZkehJnNoFhHswChR0IcyQwpo=; b=TfK01IHyAJv8UjNfgpMHJTRDOcY+rjaLXLwHX8CTPaggNTNSs0HThWZMwPyEW+RH6b Df/jtoIuvebeXdJL5qwLz6xDhezAQfiw2Q2Kqlk7SMBqvPfhBdPpqinjwyM6JndYT29J T5JEBqfXLSys4nSDeEviHGA23CQ5D40dPJYzfP8su0JbVaUV4U0ohlDz4pUmaPuJM7Xo f05u8DHN2kp/671bnZG7AMZ7a+0bvS+xvkBRgOuzxHHtfqq1CcbXJwn8ZtcOsTWUL7MZ FPM9x9cuBiYHoNf60PAc9taPpdHg3t5D2RCSUBVSWG+trlTI+MZ93yJFGyuuX9cQfLN8 sLdA== 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=w/UueSoSfkkV5ZaqeN0ZkehJnNoFhHswChR0IcyQwpo=; b=Cu4vgfUm1Oz+U328TlbrkulhKEN1y4+fVSQScxk/CelrQIV9EXFxNXP+5poaUDylP4 VWWFzxV4v3iojYGyEM95a6LT89v8/BYXTVNua+u7DSd6XJ3Zb48WzEkq/Ko7sfL53PeY 5i4Yj5/rPGrEbRuvH4xtiia+YXEv9xNTARpRQngXQ1eniLlPPJnaI1nAmt12wF97Aw9R YmXq1M2fa8N7v+DW+YkcuMj4xOFmZf7DUPCW2L1Si0OaLh+1miSaz0CCHqvm7TTCS02M LZRN8Ok7nuRNE3hCo4S2JSkh63rD/5Q6Ur/kjZc7Pj9JRa5w/i8+mes2IgUJa5Crge4j v9OA== X-Gm-Message-State: AOAM532nCcg2XcEjPQgd9HxKHXPP2VqkAm11gXKcphMlJ+iaijHULtYr 8MtYBfwUJ87tQZbbDJVY8KZxUiKOF/8= X-Google-Smtp-Source: ABdhPJxoEVMNtFjxHU99BsNcOYHXwhP+US3YZzXI2U5bhTrho6KkLYFgzIovIc/T+wSFvNoNO7bsaIvB9iM= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a5b:dcc:0:b0:628:d6d9:d4bc with SMTP id t12-20020a5b0dcc000000b00628d6d9d4bcmr8743678ybr.178.1647020469266; Fri, 11 Mar 2022 09:41:09 -0800 (PST) Date: Fri, 11 Mar 2022 17:39:54 +0000 In-Reply-To: <20220311174001.605719-1-oupton@google.com> Message-Id: <20220311174001.605719-9-oupton@google.com> Mime-Version: 1.0 References: <20220311174001.605719-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH v4 08/15] KVM: arm64: Return a value from check_vcpu_requests() From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: alexandru.elisei@arm.com, anup@brainfault.org, atishp@atishpatra.org, james.morse@arm.com, jingzhangos@google.com, jmattson@google.com, joro@8bytes.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, maz@kernel.org, pbonzini@redhat.com, pshier@google.com, rananta@google.com, reijiw@google.com, ricarkol@google.com, seanjc@google.com, suzuki.poulose@arm.com, vkuznets@redhat.com, wanpengli@tencent.com, Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220311_094111_810389_CEFD574B X-CRM114-Status: GOOD ( 12.58 ) 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: A subsequent change to KVM will introduce a vCPU request that could result in an exit to userspace. Change check_vcpu_requests() to return a value and document the function. Unconditionally return 1 f [...] 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:b49 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 A subsequent change to KVM will introduce a vCPU request that could result in an exit to userspace. Change check_vcpu_requests() to return a value and document the function. Unconditionally return 1 for now. Signed-off-by: Oliver Upton --- arch/arm64/kvm/arm.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 7c297ddc8177..8eed0556ccaa 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -648,7 +648,16 @@ void kvm_vcpu_wfi(struct kvm_vcpu *vcpu) preempt_enable(); } -static void check_vcpu_requests(struct kvm_vcpu *vcpu) +/** + * check_vcpu_requests - check and handle pending vCPU requests + * @vcpu: the VCPU pointer + * + * Return: 1 if we should enter the guest + * 0 if we should exit to userspace + * <= 0 if we should exit to userspace, where the return value indicates + * an error + */ +static int check_vcpu_requests(struct kvm_vcpu *vcpu) { if (kvm_request_pending(vcpu)) { if (kvm_check_request(KVM_REQ_SLEEP, vcpu)) @@ -678,6 +687,8 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu) kvm_pmu_handle_pmcr(vcpu, __vcpu_sys_reg(vcpu, PMCR_EL0)); } + + return 1; } static bool vcpu_mode_is_bad_32bit(struct kvm_vcpu *vcpu) @@ -793,7 +804,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) if (!ret) ret = 1; - check_vcpu_requests(vcpu); + if (ret > 0) + ret = check_vcpu_requests(vcpu); /* * Preparing the interrupts to be injected also From patchwork Fri Mar 11 17:39:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 1604496 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=XeHjNAiE; 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=s2H+Z/OD; 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 4KFYBm1Mwwz9sGD for ; Sat, 12 Mar 2022 04:41:20 +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=IzI6bxXpThCO4CzkF9WIKsic1fqn68rhi80HaKNaKHU=; b=XeHjNAiEt7vC8ulaIj4FpSdDX4 pW/GgIFh8yS0BTZBqNJ0grKFLPYvMpX3kTjIumO4IaN71bzBiraBuZGFQea7kX8cf2kiUq29ouDGX DgaAFkkbIsCWu6Et46WoWDsnqWKy1Q+h/8y3SxaWJdIvP5hdajXZUFlVxsZzHki7Htq9x58L0LB8v 9177MSzpCxyzaBiqGH4yTvdPmFQbV3rr4KrY2sOkPNRbiknlrh+ZDV2IoYkXJ7lzf0fNb8FJJb/XG WWxGFNrKaXowmcrHEAg/q1Pwjdsur9MVAzjII+8wsLbCXNNSoWs/zJLCQhrQ2fMzZdqKcaPtWtPgp c/zczSiA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGP-00HWWu-SJ; Fri, 11 Mar 2022 17:41:17 +0000 Received: from mail-io1-xd49.google.com ([2607:f8b0:4864:20::d49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGK-00HWO4-DD for kvm-riscv@lists.infradead.org; Fri, 11 Mar 2022 17:41:14 +0000 Received: by mail-io1-xd49.google.com with SMTP id z10-20020a056602080a00b00645b9fdc630so6753650iow.5 for ; Fri, 11 Mar 2022 09:41:10 -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=N08wvp33WkcjIpobnqWK/suWPKt+tAxx4i2VnS0cwgQ=; b=s2H+Z/ODb8asiSTyd1Y7/XpBFYNpChZn/EXdpezoLfZOJh3I2KOjRFQ0/12EhgS0Ou +3tjHSRLye2xwojCbc2BrvQda8Z/8nrqcDle3jbChXPDde1+NyJbrM4i7kRyc2P9HPqp vz9ZvTZkZkd+vUNMBi3uiwkaqmzJ+q9V1pDYeGtHQoTA4wztJsCLEiPotuYv7BvEcX/8 m5KxNh6A+bhueDVEhb/OhQR4qOb2TQC+uARkW4qHcI3ZCDDjlQ9vkgbfDxXsSAiFJLkp L3sobRPAcsYjfI1Kl+TUDdLl6phNnl/6uEnujdpEcA8mEfcBOdCJczcfMn5/0u0bnhN2 aIeA== 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=N08wvp33WkcjIpobnqWK/suWPKt+tAxx4i2VnS0cwgQ=; b=zW0/IZx8gI5/G3uFEsHVtzUGaG8Dh0wUElh72k679lXMctDEbHvawCAaqIMESCFBPv ilxEz7q+lWUlpDyy2SjQPJs7C2YGJIQAsUhAI6BOl70QbJuqof3ZD3rANiaAmRsvlZdY Z/QHper/SNXOXtk+dfDSzz/EEjFwDDncASDtnC+KcLIpHDcUgdfb5ystpgOFzG26k839 iw0GIx9mlYSu243KzsJs7417zrzTYbyprc/yn9W7ztWyLppKvlxM4t0ar1jZg1RDHS2m bG/mBjNf8Qn/4Jae/ElZaONQHBgqX1jOl72YDcJXkeOlZcZqg0+++XOWCLvgTCpN6u5E dBbQ== X-Gm-Message-State: AOAM531S6kbFy7oAH+1UT/xL6k790VBwvJEl6ZbpiGgAjtNgKdU3yrIg StpGyLG9lkdZc7nqYzow3bkNZ9+c5NA= X-Google-Smtp-Source: ABdhPJxJnhqOztOXute1W6oxfMwLBZR4LpePt0v06BaWe3xlqWgLApO6bsYqsLwco3kSxcDDWgE/ZI7lj2E= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6e02:5d0:b0:2c6:23cb:2fa9 with SMTP id l16-20020a056e0205d000b002c623cb2fa9mr8091751ils.68.1647020470492; Fri, 11 Mar 2022 09:41:10 -0800 (PST) Date: Fri, 11 Mar 2022 17:39:55 +0000 In-Reply-To: <20220311174001.605719-1-oupton@google.com> Message-Id: <20220311174001.605719-10-oupton@google.com> Mime-Version: 1.0 References: <20220311174001.605719-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH v4 09/15] KVM: arm64: Add support for userspace to suspend a vCPU From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: alexandru.elisei@arm.com, anup@brainfault.org, atishp@atishpatra.org, james.morse@arm.com, jingzhangos@google.com, jmattson@google.com, joro@8bytes.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, maz@kernel.org, pbonzini@redhat.com, pshier@google.com, rananta@google.com, reijiw@google.com, ricarkol@google.com, seanjc@google.com, suzuki.poulose@arm.com, vkuznets@redhat.com, wanpengli@tencent.com, Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220311_094112_479176_D08EA779 X-CRM114-Status: GOOD ( 23.10 ) 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: Introduce a new MP state, KVM_MP_STATE_SUSPENDED, which indicates a vCPU is in a suspended state. In the suspended state the vCPU will block until a wakeup event (pending interrupt) is recognized. Add a new system event type, KVM_SYSTEM_EVENT_WAKEUP, to indicate to userspace that KVM has recognized one such wakeup event. It is the responsibility of userspace to then make the vCPU runnable, or l [...] 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:d49 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 Introduce a new MP state, KVM_MP_STATE_SUSPENDED, which indicates a vCPU is in a suspended state. In the suspended state the vCPU will block until a wakeup event (pending interrupt) is recognized. Add a new system event type, KVM_SYSTEM_EVENT_WAKEUP, to indicate to userspace that KVM has recognized one such wakeup event. It is the responsibility of userspace to then make the vCPU runnable, or leave it suspended until the next wakeup event. Signed-off-by: Oliver Upton --- Documentation/virt/kvm/api.rst | 37 +++++++++++++++++++++++++++++-- arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/arm.c | 35 +++++++++++++++++++++++++++++ include/uapi/linux/kvm.h | 2 ++ 4 files changed, 73 insertions(+), 2 deletions(-) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 5625c08b4a0e..426bcdc1216d 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -1482,14 +1482,43 @@ Possible values are: [s390] KVM_MP_STATE_LOAD the vcpu is in a special load/startup state [s390] + KVM_MP_STATE_SUSPENDED the vcpu is in a suspend state and is waiting + for a wakeup event [arm64] ========================== =============================================== On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel irqchip, the multiprocessing state must be maintained by userspace on these architectures. -For arm64/riscv: -^^^^^^^^^^^^^^^^ +For arm64: +^^^^^^^^^^ + +If a vCPU is in the KVM_MP_STATE_SUSPENDED state, KVM will emulate the +architectural execution of a WFI instruction. + +If a wakeup event is recognized, KVM will exit to userspace with a +KVM_SYSTEM_EVENT exit, where the event type is KVM_SYSTEM_EVENT_WAKEUP. If +userspace wants to honor the wakeup, it must set the vCPU's MP state to +KVM_MP_STATE_RUNNABLE. If it does not, KVM will continue to await a wakeup +event in subsequent calls to KVM_RUN. + +.. warning:: + + If userspace intends to keep the vCPU in a SUSPENDED state, it is + strongly recommended that userspace take action to suppress the + wakeup event (such as masking an interrupt). Otherwise, subsequent + calls to KVM_RUN will immediately exit with a KVM_SYSTEM_EVENT_WAKEUP + event and inadvertently waste CPU cycles. + + Additionally, if userspace takes action to suppress a wakeup event, + it is strongly recommended that it also restore the vCPU to its + original state when the vCPU is made RUNNABLE again. For example, + if userspace masked a pending interrupt to suppress the wakeup, + the interrupt should be unmasked before returning control to the + guest. + +For riscv: +^^^^^^^^^^ The only states that are valid are KVM_MP_STATE_STOPPED and KVM_MP_STATE_RUNNABLE which reflect if the vcpu is paused or not. @@ -5914,6 +5943,7 @@ should put the acknowledged interrupt vector into the 'epr' field. #define KVM_SYSTEM_EVENT_SHUTDOWN 1 #define KVM_SYSTEM_EVENT_RESET 2 #define KVM_SYSTEM_EVENT_CRASH 3 + #define KVM_SYSTEM_EVENT_WAKEUP 4 __u32 type; __u64 flags; } system_event; @@ -5938,6 +5968,9 @@ Valid values for 'type' are: has requested a crash condition maintenance. Userspace can choose to ignore the request, or to gather VM memory core dump and/or reset/shutdown of the VM. + - 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. Valid flags are: diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index da58eb96d2a8..899f2c0b4c7b 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -46,6 +46,7 @@ #define KVM_REQ_RECORD_STEAL KVM_ARCH_REQ(3) #define KVM_REQ_RELOAD_GICv4 KVM_ARCH_REQ(4) #define KVM_REQ_RELOAD_PMU KVM_ARCH_REQ(5) +#define KVM_REQ_SUSPEND KVM_ARCH_REQ(6) #define KVM_DIRTY_LOG_MANUAL_CAPS (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \ KVM_DIRTY_LOG_INITIALLY_SET) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 8eed0556ccaa..b94efa05d869 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -444,6 +444,18 @@ bool kvm_arm_vcpu_stopped(struct kvm_vcpu *vcpu) return vcpu->arch.mp_state.mp_state == KVM_MP_STATE_STOPPED; } +static void kvm_arm_vcpu_suspend(struct kvm_vcpu *vcpu) +{ + vcpu->arch.mp_state.mp_state = KVM_MP_STATE_SUSPENDED; + kvm_make_request(KVM_REQ_SUSPEND, vcpu); + kvm_vcpu_kick(vcpu); +} + +static bool kvm_arm_vcpu_suspended(struct kvm_vcpu *vcpu) +{ + return vcpu->arch.mp_state.mp_state == KVM_MP_STATE_SUSPENDED; +} + int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu, struct kvm_mp_state *mp_state) { @@ -464,6 +476,9 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, case KVM_MP_STATE_STOPPED: kvm_arm_vcpu_power_off(vcpu); break; + case KVM_MP_STATE_SUSPENDED: + kvm_arm_vcpu_suspend(vcpu); + break; default: ret = -EINVAL; } @@ -648,6 +663,23 @@ void kvm_vcpu_wfi(struct kvm_vcpu *vcpu) preempt_enable(); } +static int kvm_vcpu_suspend(struct kvm_vcpu *vcpu) +{ + if (!kvm_arm_vcpu_suspended(vcpu)) + return 1; + + kvm_vcpu_wfi(vcpu); + + /* + * The suspend state is sticky; we do not leave it until userspace + * explicitly marks the vCPU as runnable. Request that we suspend again + * later. + */ + kvm_make_request(KVM_REQ_SUSPEND, vcpu); + kvm_vcpu_set_system_event_exit(vcpu, KVM_SYSTEM_EVENT_WAKEUP, 0); + return 0; +} + /** * check_vcpu_requests - check and handle pending vCPU requests * @vcpu: the VCPU pointer @@ -686,6 +718,9 @@ static int check_vcpu_requests(struct kvm_vcpu *vcpu) if (kvm_check_request(KVM_REQ_RELOAD_PMU, vcpu)) kvm_pmu_handle_pmcr(vcpu, __vcpu_sys_reg(vcpu, PMCR_EL0)); + + if (kvm_check_request(KVM_REQ_SUSPEND, vcpu)) + return kvm_vcpu_suspend(vcpu); } return 1; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 5191b57e1562..babb16c2abe5 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -444,6 +444,7 @@ struct kvm_run { #define KVM_SYSTEM_EVENT_SHUTDOWN 1 #define KVM_SYSTEM_EVENT_RESET 2 #define KVM_SYSTEM_EVENT_CRASH 3 +#define KVM_SYSTEM_EVENT_WAKEUP 4 __u32 type; __u64 flags; } system_event; @@ -634,6 +635,7 @@ struct kvm_vapic_addr { #define KVM_MP_STATE_OPERATING 7 #define KVM_MP_STATE_LOAD 8 #define KVM_MP_STATE_AP_RESET_HOLD 9 +#define KVM_MP_STATE_SUSPENDED 10 struct kvm_mp_state { __u32 mp_state; From patchwork Fri Mar 11 17:39:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 1604498 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=DktnDq5t; 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=DricpLg5; 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 4KFYBm3SGCz9sGM for ; Sat, 12 Mar 2022 04:41:20 +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=7OGkOiA7yUyAhNEqqcFRU9SopkUpIIbmkv5YLSCa/VY=; b=DktnDq5tHQDCjHctnEEu46QYIO 8h9R/oSdZUT+1WUpIYLRCfVJfTClI5utrxpSNxaC9CZ1dVYpw2spkP1CsaDmlNem3jajnjPKafRC4 IQ1eWgNg/cA6vx/Jhhi4MHsbi2AM9LR5PTSGBJQ3Z5l+Wdy9j7jW7nfAvwMMSXsCmYKSbxMZXd/s+ LPuuq8V6DNOSl+zbf7dk+X//IKpNUSJLDXXV7Hq/lEuMf+wGmX/9BnM3YDJiTkCdpCRl3nEbptC2E 6RJq0hXJbhUXgY1LWmO5VnAy9r0bCDvjLYrxtDW+ycKtpoL+f2tn/qlc0a3xZME56BYrm+0ScnSkJ xyVaD49Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGQ-00HWXS-9O; Fri, 11 Mar 2022 17:41:18 +0000 Received: from mail-io1-xd4a.google.com ([2607:f8b0:4864:20::d4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGK-00HWP3-MT for kvm-riscv@lists.infradead.org; Fri, 11 Mar 2022 17:41:15 +0000 Received: by mail-io1-xd4a.google.com with SMTP id b15-20020a05660214cf00b00648a910b964so4031471iow.19 for ; Fri, 11 Mar 2022 09:41:11 -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=wLgTYRPMnh01Zlz1eglLJFiUoRqP8W9xVYGstLsgmmc=; b=DricpLg5tjBoDBtiHkYfMTnrkKupw3UlNwbYQ6+iWXD0DkRK5rAZBuE5KZ3+FcVZb4 w993xNoyPUWCX+5Vvf5cnF6NmGFDj4mwR4ITF/ZCx9hJMMa+1LZl58G7bPE7dEi0NGfI iuBaVpe9ieMVaWnRrctYY7cJtaJrHtGr4FQFkB+/aRwNpGMTOvAlrZeF/0wNaaLtea7w 7WP0z0I2+xq1kuumh0TCvP1GqnA2tKItTbLSLcDdhAMJ8Umu1jwY5D7pkSrB8SghrOQb 0BhEdtNAfrfS/+ugtld5T+qg5v59VKuiqVDXfL676OjZEA7rAUjgK/5YWafOpYqhjlFW umJg== 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=wLgTYRPMnh01Zlz1eglLJFiUoRqP8W9xVYGstLsgmmc=; b=orJ4D6TWTKiuL9yA/OA4GhdUHPNdmaojiUAiOZNPXvqB4pp5PBcivvljSK1SGkvj+h tK1i6gPgPjhbTOBMubpibxw4x0QVj9/YTjpUz436txAnFlz/tbj9nK001vlC71aVisSR QlexpT1Gh7B7lUw+g+/hfZ2NBDJImmpNGshIL2s3NmGhgpa3GkzyJcuY3t0EupyvW13N +Wm/UC9BdY/IgpdN8W4cNdjDgeavK6zF7FjBbOpc5B9pk/Q63TssSYzUx/xH9tbzaMo9 eGfYMF5dr0Vv7N3z+Qunm+tCRkmKq9CXyMFHdwCIxpgsFpTA6RCftjRvphpDoo5MHBve Yr5w== X-Gm-Message-State: AOAM530/cZ+Y5g0ns49OdQNOLbEbSCb+ZkW3nsTrTnbjN/WqFacVEY9W KjPHSR7UF5i5vE/UBWijfX85HTkpNCc= X-Google-Smtp-Source: ABdhPJzCQ+YYMNukL81rCk6AcaObcxLHHbQxUxPvY6bi54irylbyTsa5mWYIEmRO3OzoPMfZWTHeiZ7qRQU= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6e02:20e8:b0:2c7:6e73:2279 with SMTP id q8-20020a056e0220e800b002c76e732279mr5662214ilv.60.1647020471395; Fri, 11 Mar 2022 09:41:11 -0800 (PST) Date: Fri, 11 Mar 2022 17:39:56 +0000 In-Reply-To: <20220311174001.605719-1-oupton@google.com> Message-Id: <20220311174001.605719-11-oupton@google.com> Mime-Version: 1.0 References: <20220311174001.605719-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH v4 10/15] KVM: arm64: Implement PSCI SYSTEM_SUSPEND From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: alexandru.elisei@arm.com, anup@brainfault.org, atishp@atishpatra.org, james.morse@arm.com, jingzhangos@google.com, jmattson@google.com, joro@8bytes.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, maz@kernel.org, pbonzini@redhat.com, pshier@google.com, rananta@google.com, reijiw@google.com, ricarkol@google.com, seanjc@google.com, suzuki.poulose@arm.com, vkuznets@redhat.com, wanpengli@tencent.com, Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220311_094112_775074_5BD1FF86 X-CRM114-Status: GOOD ( 26.02 ) 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: ARM DEN0022D.b 5.19 "SYSTEM_SUSPEND" describes a PSCI call that allows software to request that a system be placed in the deepest possible low-power state. Effectively, software can use this to suspen [...] 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:d4a 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 ARM DEN0022D.b 5.19 "SYSTEM_SUSPEND" describes a PSCI call that allows software to request that a system be placed in the deepest possible low-power state. Effectively, software can use this to suspend itself to RAM. Unfortunately, there really is no good way to implement a system-wide PSCI call in KVM. Any precondition checks done in the kernel will need to be repeated by userspace since there is no good way to protect a critical section that spans an exit to userspace. SYSTEM_RESET and SYSTEM_OFF are equally plagued by this issue, although no users have seemingly cared for the relatively long time these calls have been supported. The solution is to just make the whole implementation userspace's problem. Introduce a new system event, KVM_SYSTEM_EVENT_SUSPEND, that indicates to userspace a calling vCPU has invoked PSCI SYSTEM_SUSPEND. Additionally, add a CAP to get buy-in from userspace for this new exit type. Only advertise the SYSTEM_SUSPEND PSCI call if userspace has opted in. If a vCPU calls SYSTEM_SUSPEND, punt straight to userspace. Provide explicit documentation of userspace's responsibilites for the exit and point to the PSCI specification to describe the actual PSCI call. Signed-off-by: Oliver Upton --- Documentation/virt/kvm/api.rst | 39 +++++++++++++++++++++++++++++++ arch/arm64/include/asm/kvm_host.h | 2 ++ arch/arm64/kvm/arm.c | 12 +++++++++- arch/arm64/kvm/psci.c | 25 ++++++++++++++++++++ include/uapi/linux/kvm.h | 2 ++ 5 files changed, 79 insertions(+), 1 deletion(-) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 426bcdc1216d..396589e3b178 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -5944,6 +5944,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; @@ -5971,6 +5972,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 invokes the PSCI + SYSTEM_SUSPEND function, KVM will exit to userspace with this event + type. + + It is the sole responsibility of userspace to implement the PSCI + SYSTEM_SUSPEND call according to ARM DEN0022D.b 5.19 "SYSTEM_SUSPEND". + KVM does not change the vCPU's state before exiting to userspace, so + the call parameters are left in-place in the vCPU registers. + + Userspace is _required_ to take action for such an exit. It must + either: + + - Honor the guest request to suspend the VM. Userspace can request + in-kernel emulation of suspension by setting the calling vCPU's + state to KVM_MP_STATE_SUSPENDED. Userspace must configure the vCPU's + state according to the parameters passed to the PSCI function when + the calling vCPU is resumed. See ARM DEN0022D.b 5.19.1 "Intended use" + for details on the function parameters. + + - Deny the guest request to suspend the VM. See ARM DEN0022D.b 5.19.2 + "Caller responsibilities" for possible return values. Valid flags are: @@ -7598,3 +7627,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 899f2c0b4c7b..ca3ac32e40c8 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -128,6 +128,8 @@ struct kvm_arch { #define KVM_ARCH_FLAG_MTE_ENABLED 1 /* At least one vCPU has ran in the VM */ #define KVM_ARCH_FLAG_HAS_RAN_ONCE 2 + /* PSCI SYSTEM_SUSPEND enabled for the guest */ +#define KVM_ARCH_FLAG_SYSTEM_SUSPEND_ENABLED 3 unsigned long flags; /* diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index b94efa05d869..c9b616ddb512 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -97,6 +97,10 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, } mutex_unlock(&kvm->lock); break; + case KVM_CAP_ARM_SYSTEM_SUSPEND: + r = 0; + set_bit(KVM_ARCH_FLAG_SYSTEM_SUSPEND_ENABLED, &kvm->arch.flags); + break; default: r = -EINVAL; break; @@ -210,6 +214,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: @@ -447,8 +452,13 @@ bool kvm_arm_vcpu_stopped(struct kvm_vcpu *vcpu) static void kvm_arm_vcpu_suspend(struct kvm_vcpu *vcpu) { vcpu->arch.mp_state.mp_state = KVM_MP_STATE_SUSPENDED; + + /* + * Since this is only called from the intended vCPU, the target vCPU is + * guaranteed to not be running. As such there is no need to kick the + * target to handle the request. + */ kvm_make_request(KVM_REQ_SUSPEND, vcpu); - kvm_vcpu_kick(vcpu); } static bool kvm_arm_vcpu_suspended(struct kvm_vcpu *vcpu) diff --git a/arch/arm64/kvm/psci.c b/arch/arm64/kvm/psci.c index 78266716165e..2239143a9d6c 100644 --- a/arch/arm64/kvm/psci.c +++ b/arch/arm64/kvm/psci.c @@ -192,6 +192,11 @@ static void kvm_psci_system_reset2(struct kvm_vcpu *vcpu) KVM_SYSTEM_EVENT_RESET_FLAG_PSCI_RESET2); } +static void kvm_psci_system_suspend(struct kvm_vcpu *vcpu) +{ + kvm_vcpu_set_system_event_exit(vcpu, KVM_SYSTEM_EVENT_SUSPEND, 0); +} + static void kvm_psci_narrow_to_32bit(struct kvm_vcpu *vcpu) { int i; @@ -302,6 +307,7 @@ static int kvm_psci_1_x_call(struct kvm_vcpu *vcpu, u32 minor) { unsigned long val = PSCI_RET_NOT_SUPPORTED; u32 psci_fn = smccc_get_function(vcpu); + struct kvm *kvm = vcpu->kvm; u32 arg; int ret = 1; @@ -336,6 +342,11 @@ static int kvm_psci_1_x_call(struct kvm_vcpu *vcpu, u32 minor) case ARM_SMCCC_VERSION_FUNC_ID: val = 0; break; + case PSCI_1_0_FN_SYSTEM_SUSPEND: + case PSCI_1_0_FN64_SYSTEM_SUSPEND: + if (test_bit(KVM_ARCH_FLAG_SYSTEM_SUSPEND_ENABLED, &kvm->arch.flags)) + val = 0; + break; case PSCI_1_1_FN_SYSTEM_RESET2: case PSCI_1_1_FN64_SYSTEM_RESET2: if (minor >= 1) @@ -343,6 +354,20 @@ static int kvm_psci_1_x_call(struct kvm_vcpu *vcpu, u32 minor) break; } break; + case PSCI_1_0_FN_SYSTEM_SUSPEND: + kvm_psci_narrow_to_32bit(vcpu); + fallthrough; + case PSCI_1_0_FN64_SYSTEM_SUSPEND: + /* + * Return directly to userspace without changing the vCPU's + * registers. Userspace depends on reading the SMCCC parameters + * to implement SYSTEM_SUSPEND. + */ + if (test_bit(KVM_ARCH_FLAG_SYSTEM_SUSPEND_ENABLED, &kvm->arch.flags)) { + kvm_psci_system_suspend(vcpu); + return 0; + } + break; case PSCI_1_1_FN_SYSTEM_RESET2: kvm_psci_narrow_to_32bit(vcpu); fallthrough; 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 From patchwork Fri Mar 11 17:39:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 1604497 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=smykh3S4; 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=emHdHGZ7; 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 4KFYBm315Dz9sGJ for ; Sat, 12 Mar 2022 04:41:20 +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=ZyNYTSQEdNXshqHoeRR7L4WTb+LPBvIMnf4z4HVz6M4=; b=smykh3S498k7gEb168nUf7Q8oh A+53ILq9FwN76S5EX4huTv8KhhVdTrygOT0ef/hpa3nJW96aWQgjdI5qmhH86T4xJXR4E5FdVzbr4 yJnXhrZNyMJKUcYiAhnYhy2ueQl4FC+6CG4ynVXQ1hMqmBSclZol/5GjNaUJqx43h6MXMRcSFG2rA uvMygJKgMYWVh2e4betKQnhdSHbRFsq3PqHsxZTZz/1NjSy71rAzlaZyP4XTAlw6GzdAml04bYwz7 twRPbC8kOZSvBmajPTBg1XMkuluJjujf5t49/6SBBWpRBRrBFanNQ3rl36mXW2vVxwAIoohcc472B ThZze1hQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGQ-00HWX1-24; Fri, 11 Mar 2022 17:41:18 +0000 Received: from mail-io1-xd49.google.com ([2607:f8b0:4864:20::d49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGL-00HWQ7-Pn for kvm-riscv@lists.infradead.org; Fri, 11 Mar 2022 17:41:15 +0000 Received: by mail-io1-xd49.google.com with SMTP id f7-20020a056602088700b00645ebbe277cso6711743ioz.22 for ; Fri, 11 Mar 2022 09:41:12 -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=Ueuw6G3CB3aC6lh20NpaqUZj77A7koOiFEWMjHH47o0=; b=emHdHGZ7VoMCVW+tBvbqRBR3shon8hDPVzTreGlVv0x5af9H5PaJYsRQ6qP1Y1qg93 w5su+HLqeZpGjfPiHTWt8cz7N9M1xzHGIRqxVGK53Dbo3fXYn09/n3m7dwpP4PStKOFV vKmJOfUA3PNgAzQ6nRKcN+/xUMG9aELEDVogerM/pfhhqw0bXSlpdCLTWWSiFroD+1M+ SCOvQdmhyzJsmCRuid+gZ/AH5d0e2IpfPzImkHJmNA4JqXhT8ezksrnvKA4iDLHWaiOj ouxq8jazGhLAgermQ4RF+EoaZcL3nrP4OM06PQwBMBoGqqyfSDChLR0RkOGXRj8e3Nxm 8+oQ== 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=Ueuw6G3CB3aC6lh20NpaqUZj77A7koOiFEWMjHH47o0=; b=VXqP3jye6/2NFVglIvIGF5FvWlfci8SooQOCn6UOYXIHOazYlikevEqPLrUJtZakVr SOGff8kQTpobCbgQkuFAjK+O7ERcWbRGuIFAelXTWunpHS7G4Uc553RAFlYFWdqyymyB wQkxBhviyqf4XrmjJRwn61/n6Rrn+Z1BZRUFApTOhGR7HJUfx93zv7JyJRNs3UIeXKsl AqJld5+q2HwS6kh7WLT1HhAa2tmf+AUiFCbPmCUM2+ObmqWlYmEjigse71RkKLVuvkee hAR0Q3FQisswC1HbKilrM2Ur9452jkBwGn9bEqfHVsmLxzX/7pd5sQMso0+E9yjgvGN1 e5SA== X-Gm-Message-State: AOAM530/Py0B7oU3stpe9TGcESRECmkvVBfpSgnTj5FSeJsMx23ewWJ4 E/z82bRQLiPSu8tgxo0Bq62EQ6OfeHM= X-Google-Smtp-Source: ABdhPJyOYB8mAhfnrE18fEDSYqH98DncrKtJHVGBq0WqibguhNJlqPsHtU7nCGpfqDEzzx7hzv9FxNaDErw= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6602:154b:b0:648:cab0:aa72 with SMTP id h11-20020a056602154b00b00648cab0aa72mr1961053iow.33.1647020472189; Fri, 11 Mar 2022 09:41:12 -0800 (PST) Date: Fri, 11 Mar 2022 17:39:57 +0000 In-Reply-To: <20220311174001.605719-1-oupton@google.com> Message-Id: <20220311174001.605719-12-oupton@google.com> Mime-Version: 1.0 References: <20220311174001.605719-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH v4 11/15] selftests: KVM: Rename psci_cpu_on_test to psci_test From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: alexandru.elisei@arm.com, anup@brainfault.org, atishp@atishpatra.org, james.morse@arm.com, jingzhangos@google.com, jmattson@google.com, joro@8bytes.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, maz@kernel.org, pbonzini@redhat.com, pshier@google.com, rananta@google.com, reijiw@google.com, ricarkol@google.com, seanjc@google.com, suzuki.poulose@arm.com, vkuznets@redhat.com, wanpengli@tencent.com, Oliver Upton , Andrew Jones X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220311_094113_869343_3D88D301 X-CRM114-Status: UNSURE ( 7.45 ) X-CRM114-Notice: Please train this message. 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: There are other interactions with PSCI worth testing; rename the PSCI test to make it more generic. No functional change intended. Signed-off-by: Oliver Upton Reviewed-by: Andrew Jones --- tools/testing/selftests/kvm/.gitignore | 2 +- tools/testing/selftests/kvm/Makefile | 2 +- .../selftes [...] 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:d49 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 There are other interactions with PSCI worth testing; rename the PSCI test to make it more generic. No functional change intended. Signed-off-by: Oliver Upton Reviewed-by: Andrew Jones --- tools/testing/selftests/kvm/.gitignore | 2 +- tools/testing/selftests/kvm/Makefile | 2 +- .../selftests/kvm/aarch64/{psci_cpu_on_test.c => psci_test.c} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename tools/testing/selftests/kvm/aarch64/{psci_cpu_on_test.c => psci_test.c} (100%) diff --git a/tools/testing/selftests/kvm/.gitignore b/tools/testing/selftests/kvm/.gitignore index dce7de7755e6..ac69108d9ffd 100644 --- a/tools/testing/selftests/kvm/.gitignore +++ b/tools/testing/selftests/kvm/.gitignore @@ -2,7 +2,7 @@ /aarch64/arch_timer /aarch64/debug-exceptions /aarch64/get-reg-list -/aarch64/psci_cpu_on_test +/aarch64/psci_test /aarch64/vgic_init /aarch64/vgic_irq /s390x/memop diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index 0e4926bc9a58..61e11e372366 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -103,7 +103,7 @@ TEST_GEN_PROGS_x86_64 += system_counter_offset_test TEST_GEN_PROGS_aarch64 += aarch64/arch_timer TEST_GEN_PROGS_aarch64 += aarch64/debug-exceptions TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list -TEST_GEN_PROGS_aarch64 += aarch64/psci_cpu_on_test +TEST_GEN_PROGS_aarch64 += aarch64/psci_test TEST_GEN_PROGS_aarch64 += aarch64/vgic_init TEST_GEN_PROGS_aarch64 += aarch64/vgic_irq TEST_GEN_PROGS_aarch64 += demand_paging_test diff --git a/tools/testing/selftests/kvm/aarch64/psci_cpu_on_test.c b/tools/testing/selftests/kvm/aarch64/psci_test.c similarity index 100% rename from tools/testing/selftests/kvm/aarch64/psci_cpu_on_test.c rename to tools/testing/selftests/kvm/aarch64/psci_test.c From patchwork Fri Mar 11 17:39:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 1604499 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=eRolhcw/; 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=lwoYMy7N; 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 4KFYBm4nGyz9sGS for ; Sat, 12 Mar 2022 04:41:20 +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=Eh97YbOZ6E6gEyWNNDLzLnXi1E1IyUP0Dv0Ur3N2P+Y=; b=eRolhcw/FaloOTzAmimrbcCV8E Xc/g1KwvxqnnAeGVfnDC7FPjr5zPjfm83Er9N/kt2TJxWV/2Go19KyNiJSgduMlZlFIvUA7UDBWZg jJmY25VBJAn91yCD7/evjp5GBmQ/CQHWP/HtUSrOzdvk7fgdnz6v/YQJE3eC7e0RGuGMOc68xt8x4 sk1nZfLwRRxxw6cDUcte7P9GhaGX7DqKn2UmZgHZHyvv2/goj9lgE19iackngSTalLWxsq+GCqb1q I9zVOcO3/kqlZrnhhvwltm30+wK/A9cwi8KcfS6nJUUWhzqA5/lU2wxkrZDa9pob1H5rgAA2sN5O4 X5iJfNUg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGQ-00HWXs-EQ; Fri, 11 Mar 2022 17:41:18 +0000 Received: from mail-io1-xd4a.google.com ([2607:f8b0:4864:20::d4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGM-00HWRZ-Ie for kvm-riscv@lists.infradead.org; Fri, 11 Mar 2022 17:41:16 +0000 Received: by mail-io1-xd4a.google.com with SMTP id w25-20020a6bd619000000b00640ddd0ad11so6774437ioa.2 for ; Fri, 11 Mar 2022 09:41:13 -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=15ALodezktg5rSBXdOu3gPy5I4IPaYXdBd1Dvt3rcGg=; b=lwoYMy7NpxI1EiS0XM6ypEpQgLVOw071V+L89QlSMkRaf87mBw3mzZlySHfIduSlRs UGiRiAafOdifDlW+2+O5uiVMZ1UEwUP9mbvJfk2081+Jsn9NHTRtxRpj9I3MYbZzOcjZ lv00KWYeGc+ZqpcHp0qX5pZ/4hLpMOj4zY6xguyd8akJ34km9/ptGYplndcfTkGcgum+ de+1DIjXj70ysGjwH8IpcMa8o1Jek/0gTc6CYkTFMEh4UH4teKP6nbORVgS6f2ihxtbb KL4MEWTKIMcwMvJp0ogTZVV3OMZbKpOwt7gJ3cHc2mWepASwsTL76R3+l4hkGZfGbFHr 33+w== 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=15ALodezktg5rSBXdOu3gPy5I4IPaYXdBd1Dvt3rcGg=; b=cl6LiflxxEzmj2zYKZNLWt5uYQm4sCj3IWjlkP2m5H/f9LFNhmKAlaT3w7YPKUvetH VdKY7LvzFbgZJH2aN44I5J3KqFBGylbymFD59hRKhsVOFd9vRpYKZJfhJURRNYMSN5IU ywDhMFXCrT6HKpBEa3HaqTZLbaPbiBVX4bCJyWdewbVkYcc59Ip95xgG/1NpIiGYIXND SFuo8fRnuivZyRXsdzpUHwPIWVACXmXztt7ygXhMvXymG7lZNot0yf+bNkJ08yAVf2/6 om8DdtmUTzgjtBlI7Gid9x7VjKL1uUaP9VE+UuPd/5KS9HzCM9kiCgyOyCCK8VRZiPTl aLCg== X-Gm-Message-State: AOAM533pKfgZiTMitIrLIUQXqTD+etH4Q9NoFPAL55VL0LV2RDc1PPGq eeN6NyJv657TXu3MgqbAFFM4irpakF4= X-Google-Smtp-Source: ABdhPJzTKNFdb6MhKjGYU0UAr2AraFi1txIlqJ0CpXPiOl8IoC78/RPrJs9+Fap/wy9Bw2ot6ILX0F6U5X4= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a5d:84c5:0:b0:60b:bd34:bb6f with SMTP id z5-20020a5d84c5000000b0060bbd34bb6fmr8933660ior.32.1647020473264; Fri, 11 Mar 2022 09:41:13 -0800 (PST) Date: Fri, 11 Mar 2022 17:39:58 +0000 In-Reply-To: <20220311174001.605719-1-oupton@google.com> Message-Id: <20220311174001.605719-13-oupton@google.com> Mime-Version: 1.0 References: <20220311174001.605719-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH v4 12/15] selftests: KVM: Create helper for making SMCCC calls From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: alexandru.elisei@arm.com, anup@brainfault.org, atishp@atishpatra.org, james.morse@arm.com, jingzhangos@google.com, jmattson@google.com, joro@8bytes.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, maz@kernel.org, pbonzini@redhat.com, pshier@google.com, rananta@google.com, reijiw@google.com, ricarkol@google.com, seanjc@google.com, suzuki.poulose@arm.com, vkuznets@redhat.com, wanpengli@tencent.com, Oliver Upton , Andrew Jones X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220311_094114_675685_998928BB X-CRM114-Status: GOOD ( 12.88 ) 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: The PSCI and PV stolen time tests both need to make SMCCC calls within the guest. Create a helper for making SMCCC calls and rework the existing tests to use the library function. Signed-off-by: Oliver Upton Reviewed-by: Andrew Jones --- .../testing/selftests/kvm/aarch64/psci_test.c | 25 ++++++ .../selftests/kvm/include/aarc [...] 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:d4a 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 The PSCI and PV stolen time tests both need to make SMCCC calls within the guest. Create a helper for making SMCCC calls and rework the existing tests to use the library function. Signed-off-by: Oliver Upton Reviewed-by: Andrew Jones --- .../testing/selftests/kvm/aarch64/psci_test.c | 25 ++++++------------- .../selftests/kvm/include/aarch64/processor.h | 22 ++++++++++++++++ .../selftests/kvm/lib/aarch64/processor.c | 25 +++++++++++++++++++ tools/testing/selftests/kvm/steal_time.c | 13 +++------- 4 files changed, 58 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/psci_test.c b/tools/testing/selftests/kvm/aarch64/psci_test.c index 4c5f6814030f..8c998f0b802c 100644 --- a/tools/testing/selftests/kvm/aarch64/psci_test.c +++ b/tools/testing/selftests/kvm/aarch64/psci_test.c @@ -26,32 +26,23 @@ static uint64_t psci_cpu_on(uint64_t target_cpu, uint64_t entry_addr, uint64_t context_id) { - register uint64_t x0 asm("x0") = PSCI_0_2_FN64_CPU_ON; - register uint64_t x1 asm("x1") = target_cpu; - register uint64_t x2 asm("x2") = entry_addr; - register uint64_t x3 asm("x3") = context_id; + struct arm_smccc_res res; - asm("hvc #0" - : "=r"(x0) - : "r"(x0), "r"(x1), "r"(x2), "r"(x3) - : "memory"); + smccc_hvc(PSCI_0_2_FN64_CPU_ON, target_cpu, entry_addr, context_id, + 0, 0, 0, 0, &res); - return x0; + return res.a0; } static uint64_t psci_affinity_info(uint64_t target_affinity, uint64_t lowest_affinity_level) { - register uint64_t x0 asm("x0") = PSCI_0_2_FN64_AFFINITY_INFO; - register uint64_t x1 asm("x1") = target_affinity; - register uint64_t x2 asm("x2") = lowest_affinity_level; + struct arm_smccc_res res; - asm("hvc #0" - : "=r"(x0) - : "r"(x0), "r"(x1), "r"(x2) - : "memory"); + smccc_hvc(PSCI_0_2_FN64_AFFINITY_INFO, target_affinity, lowest_affinity_level, + 0, 0, 0, 0, 0, &res); - return x0; + return res.a0; } static void guest_main(uint64_t target_cpu) diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h index 8f9f46979a00..59ece9d4e0d1 100644 --- a/tools/testing/selftests/kvm/include/aarch64/processor.h +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h @@ -185,4 +185,26 @@ static inline void local_irq_disable(void) asm volatile("msr daifset, #3" : : : "memory"); } +/** + * struct arm_smccc_res - Result from SMC/HVC call + * @a0-a3 result values from registers 0 to 3 + */ +struct arm_smccc_res { + unsigned long a0; + unsigned long a1; + unsigned long a2; + unsigned long a3; +}; + +/** + * smccc_hvc - Invoke a SMCCC function using the hvc conduit + * @function_id: the SMCCC function to be called + * @arg0-arg6: SMCCC function arguments, corresponding to registers x1-x7 + * @res: pointer to write the return values from registers x0-x3 + * + */ +void smccc_hvc(uint32_t function_id, uint64_t arg0, uint64_t arg1, + uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5, + uint64_t arg6, struct arm_smccc_res *res); + #endif /* SELFTEST_KVM_PROCESSOR_H */ diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c index 9343d82519b4..6a041289fa80 100644 --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c @@ -500,3 +500,28 @@ void __attribute__((constructor)) init_guest_modes(void) { guest_modes_append_default(); } + +void smccc_hvc(uint32_t function_id, uint64_t arg0, uint64_t arg1, + uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5, + uint64_t arg6, struct arm_smccc_res *res) +{ + asm volatile("mov w0, %w[function_id]\n" + "mov x1, %[arg0]\n" + "mov x2, %[arg1]\n" + "mov x3, %[arg2]\n" + "mov x4, %[arg3]\n" + "mov x5, %[arg4]\n" + "mov x6, %[arg5]\n" + "mov x7, %[arg6]\n" + "hvc #0\n" + "mov %[res0], x0\n" + "mov %[res1], x1\n" + "mov %[res2], x2\n" + "mov %[res3], x3\n" + : [res0] "=r"(res->a0), [res1] "=r"(res->a1), + [res2] "=r"(res->a2), [res3] "=r"(res->a3) + : [function_id] "r"(function_id), [arg0] "r"(arg0), + [arg1] "r"(arg1), [arg2] "r"(arg2), [arg3] "r"(arg3), + [arg4] "r"(arg4), [arg5] "r"(arg5), [arg6] "r"(arg6) + : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7"); +} diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c index 62f2eb9ee3d5..8c4e811bd586 100644 --- a/tools/testing/selftests/kvm/steal_time.c +++ b/tools/testing/selftests/kvm/steal_time.c @@ -118,17 +118,10 @@ struct st_time { static int64_t smccc(uint32_t func, uint64_t arg) { - unsigned long ret; + struct arm_smccc_res res; - asm volatile( - "mov w0, %w1\n" - "mov x1, %2\n" - "hvc #0\n" - "mov %0, x0\n" - : "=r" (ret) : "r" (func), "r" (arg) : - "x0", "x1", "x2", "x3"); - - return ret; + smccc_hvc(func, arg, 0, 0, 0, 0, 0, 0, &res); + return res.a0; } static void check_status(struct st_time *st) From patchwork Fri Mar 11 17:39:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 1604500 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=GQJBPx9d; 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=Z1f4KpYa; 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 4KFYBm5wSZz9sGT for ; Sat, 12 Mar 2022 04:41:20 +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=+VkhZMfzgMEViZ5vcW3N9zvlKDxO1MCp/1Xs/5pgX68=; b=GQJBPx9dsP6bKTw3zDK8dWMzaz BznKK2giEkVAxTVsmH+lwNIJ04J/WLc8Q0dpqy2hHmo7zAs5aIE6F+xj7O/ob65QP0wFbUVpvVtK5 JJ54Hql39PFqAqcUXrbdfUkTe6VGuVNO6pvPGKXt29+sDOmWvFwaw1YdYvTUGNDtbGOt7P0MOcNpc sA30XzTfgliipl6Gk31TC1FhYg3hhUOzXCBqXlt1W/P69HZ9hGSCxAd/IJdfOnwMMoxvN9A8aFSnn AcyWZCmHw31VpULLm4W4eQqGZkoVCmFbH4CevnRQ88vJF8/z2orBA3dkxBj8gaf/bTbKu0p+8Mt8r 3FQxuDNQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGQ-00HWY5-J1; Fri, 11 Mar 2022 17:41:18 +0000 Received: from mail-io1-xd49.google.com ([2607:f8b0:4864:20::d49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGN-00HWS9-EP for kvm-riscv@lists.infradead.org; Fri, 11 Mar 2022 17:41:16 +0000 Received: by mail-io1-xd49.google.com with SMTP id k10-20020a5d91ca000000b006414a00b160so6719389ior.18 for ; Fri, 11 Mar 2022 09:41:14 -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=OfvwPno/vdVeaI3Bj5TBXZDiFhwzoDjkPKpMT+kPSsg=; b=Z1f4KpYaERqF+Z8wu4YaA3FqS4uUe0o489BvF9qQu+m5jAdV0e2lMnn0bKzZiIFKyu X9L0LQInEbA43NtmcasH163uIOWEZHF3m9b1oFQ+1LaU4nvjnfGfZTIHgK5xa8joRgCu U5boVyiFvKsnlsC95lZ8jC9d8iyyZSrkS6SVwlS2nJh7p3Ido7dU9sc6ZRyMyHxJmau0 i8N6iXnmHtU2hFZEQmx8s9+B31O6AD4yFPqMS1Nhpn2SBevF+B/EsO+kow7ntN2w8Ct7 CBaCCGL/lP8tkCaikzq/yHBUzh5uGWOOQ7sObzGy/4p6HA3MQwYcM7CsC78SX91YbDz5 DpHQ== 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=OfvwPno/vdVeaI3Bj5TBXZDiFhwzoDjkPKpMT+kPSsg=; b=XvOi5OfW3N0xn04Zw+Bk4hJqUxgmHBBoMBvnBFspHB9mrIDQ1cX72DhSFRhZpWZydO vsH4YWPj2l1up9Z0L9bzim4kP2Ai5gKP70NcECrmjTr5wAO04ctwezWHBt4ZUtSgQXs/ 3INR3ZHJE/v6MoclsInbRvD3tyEn9Z3Nf/iAy5e0cnevSzuiw1MzLVro9jZh6H4unF1W J/Dw5KNRpE5UZBbndV7oQuvXm4PyOd79zMtRi1aBsosriWLh0LpEgXdzLQx+1dbXnIKj DOX/1t/wJCNV3vvIj6g8WzIwyZuYGgUk1TkG1QVUP9lUY2LDQTIJ5Wh9p3M5MaWz1QS/ CQNg== X-Gm-Message-State: AOAM532NnS8KcyE5UE9BrYBzBv/HpFXvBg/GyMrXEgGaG82kbw2SyUre dlFGTznIhD4Fqt+ZksB62Xt/iQ/lzZY= X-Google-Smtp-Source: ABdhPJxU4o6d12HlS+cwJHR6AnNPMTg+5NGTOavt5pmb+N5rymKdGyajtqzZmyUeSPjQs3h26Wf1GyDGFoA= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6638:dcf:b0:319:e022:ad6c with SMTP id m15-20020a0566380dcf00b00319e022ad6cmr1001835jaj.143.1647020474006; Fri, 11 Mar 2022 09:41:14 -0800 (PST) Date: Fri, 11 Mar 2022 17:39:59 +0000 In-Reply-To: <20220311174001.605719-1-oupton@google.com> Message-Id: <20220311174001.605719-14-oupton@google.com> Mime-Version: 1.0 References: <20220311174001.605719-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH v4 13/15] selftests: KVM: Use KVM_SET_MP_STATE to power off vCPU in psci_test From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: alexandru.elisei@arm.com, anup@brainfault.org, atishp@atishpatra.org, james.morse@arm.com, jingzhangos@google.com, jmattson@google.com, joro@8bytes.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, maz@kernel.org, pbonzini@redhat.com, pshier@google.com, rananta@google.com, reijiw@google.com, ricarkol@google.com, seanjc@google.com, suzuki.poulose@arm.com, vkuznets@redhat.com, wanpengli@tencent.com, Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220311_094115_548242_3A25BFDA X-CRM114-Status: GOOD ( 10.61 ) 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: Setting a vCPU's MP state to KVM_MP_STATE_STOPPED has the effect of powering off the vCPU. Rather than using the vCPU init feature flag, use the KVM_SET_MP_STATE ioctl to power off the target vCPU. Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm/aarch64/psci_test.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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:d49 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 Setting a vCPU's MP state to KVM_MP_STATE_STOPPED has the effect of powering off the vCPU. Rather than using the vCPU init feature flag, use the KVM_SET_MP_STATE ioctl to power off the target vCPU. Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm/aarch64/psci_test.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/psci_test.c b/tools/testing/selftests/kvm/aarch64/psci_test.c index 8c998f0b802c..fe1d5d343a2f 100644 --- a/tools/testing/selftests/kvm/aarch64/psci_test.c +++ b/tools/testing/selftests/kvm/aarch64/psci_test.c @@ -60,6 +60,15 @@ static void guest_main(uint64_t target_cpu) GUEST_DONE(); } +static void vcpu_power_off(struct kvm_vm *vm, uint32_t vcpuid) +{ + struct kvm_mp_state mp_state = { + .mp_state = KVM_MP_STATE_STOPPED, + }; + + vcpu_set_mp_state(vm, vcpuid, &mp_state); +} + int main(void) { uint64_t target_mpidr, obs_pc, obs_x0; @@ -75,12 +84,12 @@ int main(void) init.features[0] |= (1 << KVM_ARM_VCPU_PSCI_0_2); aarch64_vcpu_add_default(vm, VCPU_ID_SOURCE, &init, guest_main); + aarch64_vcpu_add_default(vm, VCPU_ID_TARGET, &init, guest_main); /* * make sure the target is already off when executing the test. */ - init.features[0] |= (1 << KVM_ARM_VCPU_POWER_OFF); - aarch64_vcpu_add_default(vm, VCPU_ID_TARGET, &init, guest_main); + vcpu_power_off(vm, VCPU_ID_TARGET); get_reg(vm, VCPU_ID_TARGET, KVM_ARM64_SYS_REG(SYS_MPIDR_EL1), &target_mpidr); vcpu_args_set(vm, VCPU_ID_SOURCE, 1, target_mpidr & MPIDR_HWID_BITMASK); From patchwork Fri Mar 11 17:40:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 1604502 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=O/qJTAg6; 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=bNZnYHvc; 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 4KFYBq0z1Jz9sGJ for ; Sat, 12 Mar 2022 04:41:23 +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=r0x3iuSK1z547byCOOYAOZQ0eQ9pqwe65FAI3/a6Eok=; b=O/qJTAg6K4EMpaGNp71ZqjzfeL AvBuIi0AHQZTHjOQulXIf37PsSyPaW266rFIj9ulVcJ4LHc7eY4cwNfceMJfAs272v1ekxxXq5WxI H3q5QrmQFraQ+MTkAoYmrcIiO/XDD43EpPbw+m26HYxWjFshfPT/I59pvgcsx5nNOmGnvE01e679K cE5KQmxP7Lfc39P0J3fJUj2SAeNrT1gjl/T7KK8RLBY4Br1iyYuR0tA0jmHYD3hquRGpMr6BH1T8i wRolzor53GHUr9IoVS4b2v5AcIxyANYIzc4ByUkHdilcY7tV/IP2rnWCX50KuRti8xaadDJAtwZKP 2l6VBKAg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGS-00HWaK-So; Fri, 11 Mar 2022 17:41:20 +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 1nSjGP-00HWU1-CY for kvm-riscv@lists.infradead.org; Fri, 11 Mar 2022 17:41:19 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id x11-20020a5b0f0b000000b0062277953037so7823689ybr.21 for ; Fri, 11 Mar 2022 09:41:15 -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=9RhoYygE0YhbGgss02L1IrZ/eHu2ZW7VKbFiJR/6NsY=; b=bNZnYHvc0yZVoXSbr4tfbuMjCK2pakFObgjh4jNf/3piaNOO0HK44ST3c/47DILmGu C6FptlsVWrpn0xSxRuj/CBb9dvoNa55o5/+0HHpwz5KKhn4CJqckY0cOvpgL+mq/AsoV UBSCpPeD8IEAY24qzqoHCy4p+M3wE8U/cqnTxaL3HuTIH0g9Og8g8mGlGGAk1uTPXlRB 8AAUXcM88iM/B5dkYC1Z76oYetFVl0eAc8s3hZjWFTXQRvzgDWDlWJIKCC4ZstaJrsKy +8EdtudDjMqc8ZE0Psnd9IEG4elr2A67DUFT/bciiofousvMNjMvsqkPwdl16QVX2f+M VqqQ== 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=9RhoYygE0YhbGgss02L1IrZ/eHu2ZW7VKbFiJR/6NsY=; b=wem6bGR0OgW/Q9HrqvgAySsGP9GGgNKjxzNJV9Y/VruKhMqzwJo5v37zLgiTT1SXua EI0h9pU4FM5iwZ9/ni3HBPMxbiitFkGDqO4s7AQhVIqQvE3NedotPPWRcYQbu/LQyZW8 cmUjMUPEMfRSx5FIgJ2Xs45MX+ytseBUxUcwnejBK0I0FAUl0QzYOcpICft1eNRrzu1H 7SHZFG7JENa3w0Y2oY8vgSAkfY79mZaL7VckSGJGbhQOvw9d06hKStG29wtSBhmelbWo FGWZiuKTvNVNSZFuVl4z7AUxYcsaJkkVEgaTb2Bi9ipOG0tsm0r3MCjvUVNFDXDeTWr3 Kzwg== X-Gm-Message-State: AOAM533hgqmQSgF2SWgWCrpjMU5/gx3aBUiGaUL9hhWM84sVDRE6Vkma 3SlLxA/cLdiLj/eMZ8Hpd9YRc7scXc0= X-Google-Smtp-Source: ABdhPJxdgvSQlAtJSB+leGExvzKh3AfOFvObrD5Ft3CPDFWvPEtEQzDUUOU/i5dt+qgJADukvuYpFX3UlVM= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6902:1388:b0:624:6892:5495 with SMTP id x8-20020a056902138800b0062468925495mr8910786ybu.379.1647020475097; Fri, 11 Mar 2022 09:41:15 -0800 (PST) Date: Fri, 11 Mar 2022 17:40:00 +0000 In-Reply-To: <20220311174001.605719-1-oupton@google.com> Message-Id: <20220311174001.605719-15-oupton@google.com> Mime-Version: 1.0 References: <20220311174001.605719-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH v4 14/15] selftests: KVM: Refactor psci_test to make it amenable to new tests From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: alexandru.elisei@arm.com, anup@brainfault.org, atishp@atishpatra.org, james.morse@arm.com, jingzhangos@google.com, jmattson@google.com, joro@8bytes.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, maz@kernel.org, pbonzini@redhat.com, pshier@google.com, rananta@google.com, reijiw@google.com, ricarkol@google.com, seanjc@google.com, suzuki.poulose@arm.com, vkuznets@redhat.com, wanpengli@tencent.com, Oliver Upton , Andrew Jones X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220311_094117_465556_79EF88F2 X-CRM114-Status: GOOD ( 12.88 ) 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: Split up the current test into several helpers that will be useful to subsequent test cases added to the PSCI test suite. Signed-off-by: Oliver Upton Reviewed-by: Andrew Jones --- .../testing/selftests/kvm/aarch64/psci_test.c | 97 ++++++++++++------- 1 file changed, 60 insertions( [...] 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 Split up the current test into several helpers that will be useful to subsequent test cases added to the PSCI test suite. Signed-off-by: Oliver Upton Reviewed-by: Andrew Jones --- .../testing/selftests/kvm/aarch64/psci_test.c | 97 ++++++++++++------- 1 file changed, 60 insertions(+), 37 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/psci_test.c b/tools/testing/selftests/kvm/aarch64/psci_test.c index fe1d5d343a2f..535130d5e97f 100644 --- a/tools/testing/selftests/kvm/aarch64/psci_test.c +++ b/tools/testing/selftests/kvm/aarch64/psci_test.c @@ -45,21 +45,6 @@ static uint64_t psci_affinity_info(uint64_t target_affinity, return res.a0; } -static void guest_main(uint64_t target_cpu) -{ - GUEST_ASSERT(!psci_cpu_on(target_cpu, CPU_ON_ENTRY_ADDR, CPU_ON_CONTEXT_ID)); - uint64_t target_state; - - do { - target_state = psci_affinity_info(target_cpu, 0); - - GUEST_ASSERT((target_state == PSCI_0_2_AFFINITY_LEVEL_ON) || - (target_state == PSCI_0_2_AFFINITY_LEVEL_OFF)); - } while (target_state != PSCI_0_2_AFFINITY_LEVEL_ON); - - GUEST_DONE(); -} - static void vcpu_power_off(struct kvm_vm *vm, uint32_t vcpuid) { struct kvm_mp_state mp_state = { @@ -69,12 +54,10 @@ static void vcpu_power_off(struct kvm_vm *vm, uint32_t vcpuid) vcpu_set_mp_state(vm, vcpuid, &mp_state); } -int main(void) +static struct kvm_vm *setup_vm(void *guest_code) { - uint64_t target_mpidr, obs_pc, obs_x0; struct kvm_vcpu_init init; struct kvm_vm *vm; - struct ucall uc; vm = vm_create(VM_MODE_DEFAULT, DEFAULT_GUEST_PHY_PAGES, O_RDWR); kvm_vm_elf_load(vm, program_invocation_name); @@ -83,31 +66,28 @@ int main(void) vm_ioctl(vm, KVM_ARM_PREFERRED_TARGET, &init); init.features[0] |= (1 << KVM_ARM_VCPU_PSCI_0_2); - aarch64_vcpu_add_default(vm, VCPU_ID_SOURCE, &init, guest_main); - aarch64_vcpu_add_default(vm, VCPU_ID_TARGET, &init, guest_main); + aarch64_vcpu_add_default(vm, VCPU_ID_SOURCE, &init, guest_code); + aarch64_vcpu_add_default(vm, VCPU_ID_TARGET, &init, guest_code); - /* - * make sure the target is already off when executing the test. - */ - vcpu_power_off(vm, VCPU_ID_TARGET); + return vm; +} - get_reg(vm, VCPU_ID_TARGET, KVM_ARM64_SYS_REG(SYS_MPIDR_EL1), &target_mpidr); - vcpu_args_set(vm, VCPU_ID_SOURCE, 1, target_mpidr & MPIDR_HWID_BITMASK); - vcpu_run(vm, VCPU_ID_SOURCE); +static void enter_guest(struct kvm_vm *vm, uint32_t vcpuid) +{ + struct ucall uc; - switch (get_ucall(vm, VCPU_ID_SOURCE, &uc)) { - case UCALL_DONE: - break; - case UCALL_ABORT: + vcpu_run(vm, vcpuid); + if (get_ucall(vm, vcpuid, &uc) == UCALL_ABORT) TEST_FAIL("%s at %s:%ld", (const char *)uc.args[0], __FILE__, uc.args[1]); - break; - default: - TEST_FAIL("Unhandled ucall: %lu", uc.cmd); - } +} + +static void assert_vcpu_reset(struct kvm_vm *vm, uint32_t vcpuid) +{ + uint64_t obs_pc, obs_x0; - get_reg(vm, VCPU_ID_TARGET, ARM64_CORE_REG(regs.pc), &obs_pc); - get_reg(vm, VCPU_ID_TARGET, ARM64_CORE_REG(regs.regs[0]), &obs_x0); + get_reg(vm, vcpuid, ARM64_CORE_REG(regs.pc), &obs_pc); + get_reg(vm, vcpuid, ARM64_CORE_REG(regs.regs[0]), &obs_x0); TEST_ASSERT(obs_pc == CPU_ON_ENTRY_ADDR, "unexpected target cpu pc: %lx (expected: %lx)", @@ -115,7 +95,50 @@ int main(void) TEST_ASSERT(obs_x0 == CPU_ON_CONTEXT_ID, "unexpected target context id: %lx (expected: %lx)", obs_x0, CPU_ON_CONTEXT_ID); +} + +static void guest_test_cpu_on(uint64_t target_cpu) +{ + uint64_t target_state; + + GUEST_ASSERT(!psci_cpu_on(target_cpu, CPU_ON_ENTRY_ADDR, CPU_ON_CONTEXT_ID)); + + do { + target_state = psci_affinity_info(target_cpu, 0); + + GUEST_ASSERT((target_state == PSCI_0_2_AFFINITY_LEVEL_ON) || + (target_state == PSCI_0_2_AFFINITY_LEVEL_OFF)); + } while (target_state != PSCI_0_2_AFFINITY_LEVEL_ON); + + GUEST_DONE(); +} + +static void host_test_cpu_on(void) +{ + uint64_t target_mpidr; + struct kvm_vm *vm; + struct ucall uc; + + vm = setup_vm(guest_test_cpu_on); + + /* + * make sure the target is already off when executing the test. + */ + vcpu_power_off(vm, VCPU_ID_TARGET); + + get_reg(vm, VCPU_ID_TARGET, KVM_ARM64_SYS_REG(SYS_MPIDR_EL1), &target_mpidr); + vcpu_args_set(vm, VCPU_ID_SOURCE, 1, target_mpidr & MPIDR_HWID_BITMASK); + enter_guest(vm, VCPU_ID_SOURCE); + + if (get_ucall(vm, VCPU_ID_SOURCE, &uc) != UCALL_DONE) + TEST_FAIL("Unhandled ucall: %lu", uc.cmd); + assert_vcpu_reset(vm, VCPU_ID_TARGET); kvm_vm_free(vm); +} + +int main(void) +{ + host_test_cpu_on(); return 0; } From patchwork Fri Mar 11 17:40:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 1604501 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=O2RNgPWs; 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=VlHiPeyT; 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 4KFYBp6Gnmz9sGD for ; Sat, 12 Mar 2022 04:41:22 +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=Wq5B+jLLrHWD8hMkSjkYRto0ZWhEqUukuiPS3yQrTTc=; b=O2RNgPWsr3hBrEZGBAt3yHqmO1 naiCEyGJ5jxtQwrVQbINDieImITU+iBq9CyKUZ8kZXhzmRDhac7pxHh14JwUwoALdIsIWxS/i34R+ lBD1XUSTRb/aglc1xkjOYNazz5tEHlVN+pPu29D1EKAd2zqRseYSDso7KQVwmcORvMys2oeUW02He gbdymFbHLI7aGhjHIcbJUmbkMnm8YrdAd3GfumyfjDGNrFnwSlZTZiwmkQkjgvWWdvIRKvgYKN0e+ 5Ed7F7EVyzypG8H3/XpHPqmEbVO1J0B9GHyU0GTSbu0CJq7KPgmNMryK+pQSYd2mpBkMCGTeWlvbi kCknLw3A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGS-00HWa8-OT; Fri, 11 Mar 2022 17:41:20 +0000 Received: from mail-io1-xd49.google.com ([2607:f8b0:4864:20::d49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjGP-00HWV8-Ce for kvm-riscv@lists.infradead.org; Fri, 11 Mar 2022 17:41:18 +0000 Received: by mail-io1-xd49.google.com with SMTP id d19-20020a0566022bf300b00645eba5c992so6778630ioy.4 for ; Fri, 11 Mar 2022 09:41:16 -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=2LSJANjSYpAWOJFNIXz+8dt0F/NtwX4/yDcBJViXKEo=; b=VlHiPeyTld/1NEk/E5VMaNHpezW5J48Ln8kdGwQgrmfpaHqxesSVY7tRWUosoJXplI F9W3pkhSk76+quWnsaAbZW2S3ltT21dCRJ+kP1wGmDThq7tm+k+tZiwmNXcRevC6Y5+y Gp2tz9/2N16lbXBwYoSoWap+jD7C5H28Vvdv/R3bInAqoxEIwxuTyyF6X/GyalQ7Jgup JiTlA4qtNID5BN0RG4tP5GSnFvSLV0kiNsUTm072zN9GzW0CNiE/i05m5vx8GrLK7tNJ qhP4mXDkxPI9VLdwja9wo9ByBlpVK0w29OTvnLhK78lglNFRbSuc6DGQg+w3lLAVMctE gkIA== 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=2LSJANjSYpAWOJFNIXz+8dt0F/NtwX4/yDcBJViXKEo=; b=CvVWOlNmeMmwb3hywpYQU8ayHnrKOkdWxqGkThUADtKznfBT05qF7JaAODjDzNbVZ/ n4dCGjacSJB5oWBeff3ZF0fHOIO7uI4nnbPntCTT/nR6UhCa/vY/TCWe31N0ABGHlbL6 juJuN8TEYnjokRwNPQ8iJBqyUZRlWWOt9G8dN69k9wlXGaxaRNoBEIUT0uVuo42HprjY OxipQ85kIORw3Tv/IKxF/XrjH0dXu7TU0I4W+Tzne4vR03eFWbsQU7owj3RV1W6Za2MF dOG7EBTrnWZ3OYqdufpTBOxLypt3p+7a7LqKqx6LmZFkZ30eYvbwsu6SQZ1FGPLwqNJU Zlsw== X-Gm-Message-State: AOAM5330qP7109d9bBQLl6k6mn+ZupgO/pZFnkE6SJUH1bQVRLACrG19 5FAW/5mMQ611YiyYaMQz1lvyc8T2oDA= X-Google-Smtp-Source: ABdhPJwFStQunXcwugd9xidupQuW9bZm+6k3cfSglfyyz0xljBqYTInRveQuXk40mwAmA8qhksT+CAzWSXk= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a6b:d003:0:b0:646:4652:bd57 with SMTP id x3-20020a6bd003000000b006464652bd57mr8748957ioa.51.1647020476191; Fri, 11 Mar 2022 09:41:16 -0800 (PST) Date: Fri, 11 Mar 2022 17:40:01 +0000 In-Reply-To: <20220311174001.605719-1-oupton@google.com> Message-Id: <20220311174001.605719-16-oupton@google.com> Mime-Version: 1.0 References: <20220311174001.605719-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH v4 15/15] selftests: KVM: Test SYSTEM_SUSPEND PSCI call From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: alexandru.elisei@arm.com, anup@brainfault.org, atishp@atishpatra.org, james.morse@arm.com, jingzhangos@google.com, jmattson@google.com, joro@8bytes.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, maz@kernel.org, pbonzini@redhat.com, pshier@google.com, rananta@google.com, reijiw@google.com, ricarkol@google.com, seanjc@google.com, suzuki.poulose@arm.com, vkuznets@redhat.com, wanpengli@tencent.com, Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220311_094117_475932_0F2C61D5 X-CRM114-Status: UNSURE ( 9.95 ) X-CRM114-Notice: Please train this message. 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: Assert that the vCPU exits to userspace with KVM_SYSTEM_EVENT_SUSPEND if the guest calls PSCI SYSTEM_SUSPEND. Additionally, guarantee that the SMC32 and SMC64 flavors of this call are discoverable wit [...] 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:d49 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 Assert that the vCPU exits to userspace with KVM_SYSTEM_EVENT_SUSPEND if the guest calls PSCI SYSTEM_SUSPEND. Additionally, guarantee that the SMC32 and SMC64 flavors of this call are discoverable with the PSCI_FEATURES call. Signed-off-by: Oliver Upton --- .../testing/selftests/kvm/aarch64/psci_test.c | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tools/testing/selftests/kvm/aarch64/psci_test.c b/tools/testing/selftests/kvm/aarch64/psci_test.c index 535130d5e97f..88541de21c41 100644 --- a/tools/testing/selftests/kvm/aarch64/psci_test.c +++ b/tools/testing/selftests/kvm/aarch64/psci_test.c @@ -45,6 +45,25 @@ static uint64_t psci_affinity_info(uint64_t target_affinity, return res.a0; } +static uint64_t psci_system_suspend(uint64_t entry_addr, uint64_t context_id) +{ + struct arm_smccc_res res; + + smccc_hvc(PSCI_1_0_FN64_SYSTEM_SUSPEND, entry_addr, context_id, + 0, 0, 0, 0, 0, &res); + + return res.a0; +} + +static uint64_t psci_features(uint32_t func_id) +{ + struct arm_smccc_res res; + + smccc_hvc(PSCI_1_0_FN_PSCI_FEATURES, func_id, 0, 0, 0, 0, 0, 0, &res); + + return res.a0; +} + static void vcpu_power_off(struct kvm_vm *vm, uint32_t vcpuid) { struct kvm_mp_state mp_state = { @@ -137,8 +156,58 @@ static void host_test_cpu_on(void) kvm_vm_free(vm); } +static void enable_system_suspend(struct kvm_vm *vm) +{ + struct kvm_enable_cap cap = { + .cap = KVM_CAP_ARM_SYSTEM_SUSPEND, + }; + + vm_enable_cap(vm, &cap); +} + +static void guest_test_system_suspend(void) +{ + uint64_t ret; + + /* assert that SYSTEM_SUSPEND is discoverable */ + GUEST_ASSERT(!psci_features(PSCI_1_0_FN_SYSTEM_SUSPEND)); + GUEST_ASSERT(!psci_features(PSCI_1_0_FN64_SYSTEM_SUSPEND)); + + ret = psci_system_suspend(CPU_ON_ENTRY_ADDR, CPU_ON_CONTEXT_ID); + GUEST_SYNC(ret); +} + +static void host_test_system_suspend(void) +{ + struct kvm_run *run; + struct kvm_vm *vm; + + vm = setup_vm(guest_test_system_suspend); + enable_system_suspend(vm); + + vcpu_power_off(vm, VCPU_ID_TARGET); + run = vcpu_state(vm, VCPU_ID_SOURCE); + + enter_guest(vm, VCPU_ID_SOURCE); + + TEST_ASSERT(run->exit_reason == KVM_EXIT_SYSTEM_EVENT, + "Unhandled exit reason: %u (%s)", + run->exit_reason, exit_reason_str(run->exit_reason)); + TEST_ASSERT(run->system_event.type == KVM_SYSTEM_EVENT_SUSPEND, + "Unhandled system event: %u (expected: %u)", + run->system_event.type, KVM_SYSTEM_EVENT_SUSPEND); + + kvm_vm_free(vm); +} + int main(void) { + if (!kvm_check_cap(KVM_CAP_ARM_SYSTEM_SUSPEND)) { + print_skip("KVM_CAP_ARM_SYSTEM_SUSPEND not supported"); + exit(KSFT_SKIP); + } + host_test_cpu_on(); + host_test_system_suspend(); return 0; }