From patchwork Wed Feb 23 04:18:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 1596480 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=ovX0vEcv; 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=DIrZsjZS; 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 4K3N8s1NVtz9sG2 for ; Wed, 23 Feb 2022 15:19:25 +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=R/RoDQ1vsGu8+02GDDbZNoXc5e66PLxP2bsOgVDzmvE=; b=ovX0vEcvVrdyvw7qTP8xuDq5Mr p1lrKu2SnEJ4G+CCkajOnceD3IsR9dIoVSL+zVfWqwGxnlHOqWXe3+54mdWghhN02M2yuwR2Jl7Lb tm5aMSFT8VgeUdIDW949Lf7Qfdml6zy4C+ZjpBnjeNbNUI0VAb/lvgugot8JyHL0xWcV5ARi7NlXH fe8RN/sdjR4K8j0bTQSpPG0MFBa6oL+tBL9imUX6Cf7Mz3SNgFteSRv8/2Hbug00UNO5rYJqN+eVy xBuJi7uGt82lqlYby3t1aObTOQ/c21Syo5XQs8nCeoYk8eVDAEIAqXDejmbtu+gqaZAUbZpW5KbHj 1agh3qog==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMj7a-00CmOT-Sv; Wed, 23 Feb 2022 04:19:22 +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 1nMj7Y-00CmKf-3r for kvm-riscv@lists.infradead.org; Wed, 23 Feb 2022 04:19:21 +0000 Received: by mail-io1-xd4a.google.com with SMTP id z23-20020a5ec917000000b0064142c95dc1so4076150iol.20 for ; Tue, 22 Feb 2022 20:19:19 -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=q4R57xxRvoqj0jvH1kp4v0WNULcwYMhHe97HrH/NaKs=; b=DIrZsjZSKFumvER62QxuVVmXN1YyjtPRSZ3IMZ/epU6OehIQXsMHpDUDJuGM0sOdM9 Xa3GkIW9L1+RIdnmjFNA5a673Mcz3uKfIixj7KMotznbMEEH9dFB8SmOHRQD74Nh2iU5 /7EiFdHWmatqdVt7VnOxpVe7w+vjpclEKpBEm02/LK+3qb4UPkYmg4HytmTCzm/wjrnA jtes3QqhSyJ8fFm8E02Gd9jcHp35eVR4Rdd9lJpdLD80QoXM56UOdi0o4w/M1qJT+wzi MKtM80CRGELEJKjtfsa2TyXi0fnONndSfUgHn+K9t6rJMB14yHAn5o3oXEAtsEZEhBiH KKWA== 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=q4R57xxRvoqj0jvH1kp4v0WNULcwYMhHe97HrH/NaKs=; b=fKjazvqoMHc2LwefV0suw9xCcez3gDHuvmhxkxnFCoUBO6nNdrZ5qAj1WFwsHKwskZ DW2s1opSaQklBoXhjGwx1JpJNt1dTW54lvfG4jG72Olx/jByocufNkCuUbW+CzH1Pigv dch84yySUjCuv5W+JJtAsuTx3E6k1vSLkmYt1PZIf/UPiu2DX7g3nCGj1DDNThTQMt9U 2UhG2Ib/xEhQWOQnE3E81Zpg0o+uUiVaOkA0ZKPUhtVT/i7lqYb3xEWHHUnwCTU5Exfb e8jc782k/LUxTVVNg5haNdD3UXa4aCPRPm0sefqaa4EV2nQiHYMLwFnyp69Hqw+My1Th FuIA== X-Gm-Message-State: AOAM533rW3wF3I+RtHIk1xnElb3JJpV5x4y/dZLoIGN3YwxUWchKTUUg usSOHplqiRJK6QEsaZbPZxzBxcqbRZA= X-Google-Smtp-Source: ABdhPJyUvSf/lmncTWDQIYy3XL/42+UT+v7lgPaWwTGgn82xM27AgseWmCm72Pgc1Dgi/YpsD2EkZrVPldE= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6e02:1b8e:b0:2c2:2750:1178 with SMTP id h14-20020a056e021b8e00b002c227501178mr12158397ili.126.1645589958479; Tue, 22 Feb 2022 20:19:18 -0800 (PST) Date: Wed, 23 Feb 2022 04:18:33 +0000 In-Reply-To: <20220223041844.3984439-1-oupton@google.com> Message-Id: <20220223041844.3984439-9-oupton@google.com> Mime-Version: 1.0 References: <20220223041844.3984439-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.473.g83b2b277ed-goog Subject: [PATCH v3 08/19] KVM: arm64: Add reset helper that accepts caller-provided reset state From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: Paolo Bonzini , Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Anup Patel , Atish Patra , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Peter Shier , Reiji Watanabe , Ricardo Koller , Raghavendra Rao Ananta , Jing Zhang , Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220222_201920_207188_A2763BE5 X-CRM114-Status: GOOD ( 18.97 ) 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: To date, struct vcpu_reset_state has been used to implement PSCI CPU_ON, as callers of this function provide context for the targeted vCPU. A subsequent change to KVM will require that a vCPU can popu [...] 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 To date, struct vcpu_reset_state has been used to implement PSCI CPU_ON, as callers of this function provide context for the targeted vCPU. A subsequent change to KVM will require that a vCPU can populate its own reset context. Extract the vCPU reset implementation into a new function to separate the locked read of shared data (vcpu->arch.reset_state) from the use of the reset context. No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_host.h | 16 ++++++----- arch/arm64/kvm/reset.c | 44 +++++++++++++++++++------------ 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 3e8bfecaa95b..33ecec755310 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -67,6 +67,15 @@ extern unsigned int kvm_sve_max_vl; int kvm_arm_init_sve(void); u32 __attribute_const__ kvm_target_cpu(void); + +struct vcpu_reset_state { + unsigned long pc; + unsigned long r0; + bool be; + bool reset; +}; + +int __kvm_reset_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reset_state *reset_state); int kvm_reset_vcpu(struct kvm_vcpu *vcpu); void kvm_arm_vcpu_destroy(struct kvm_vcpu *vcpu); @@ -271,13 +280,6 @@ extern s64 kvm_nvhe_sym(hyp_physvirt_offset); extern u64 kvm_nvhe_sym(hyp_cpu_logical_map)[NR_CPUS]; #define hyp_cpu_logical_map CHOOSE_NVHE_SYM(hyp_cpu_logical_map) -struct vcpu_reset_state { - unsigned long pc; - unsigned long r0; - bool be; - bool reset; -}; - struct kvm_vcpu_arch { struct kvm_cpu_context ctxt; void *sve_state; diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c index ecc40c8cd6f6..f879a8f6a99c 100644 --- a/arch/arm64/kvm/reset.c +++ b/arch/arm64/kvm/reset.c @@ -205,35 +205,32 @@ static bool vcpu_allowed_register_width(struct kvm_vcpu *vcpu) } /** - * kvm_reset_vcpu - sets core registers and sys_regs to reset value + * __kvm_reset_vcpu - sets core registers and sys_regs to reset value * @vcpu: The VCPU pointer + * @reset_state: Context to use to reset the vCPU * * This function sets the registers on the virtual CPU struct to their * architecturally defined reset values, except for registers whose reset is * deferred until kvm_arm_vcpu_finalize(). * - * Note: This function can be called from two paths: The KVM_ARM_VCPU_INIT - * ioctl or as part of handling a request issued by another VCPU in the PSCI - * handling code. In the first case, the VCPU will not be loaded, and in the - * second case the VCPU will be loaded. Because this function operates purely - * on the memory-backed values of system registers, we want to do a full put if + * Note: This function can be called from two paths: + * - The KVM_ARM_VCPU_INIT ioctl + * - handling a request issued by another VCPU in the PSCI handling code + * + * In the first case, the VCPU will not be loaded, and in the second case the + * VCPU will be loaded. Because this function operates purely on the + * memory-backed values of system registers, we want to do a full put if * we were loaded (handling a request) and load the values back at the end of * the function. Otherwise we leave the state alone. In both cases, we * disable preemption around the vcpu reset as we would otherwise race with * preempt notifiers which also call put/load. */ -int kvm_reset_vcpu(struct kvm_vcpu *vcpu) +int __kvm_reset_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reset_state *reset_state) { - struct vcpu_reset_state reset_state; int ret; bool loaded; u32 pstate; - mutex_lock(&vcpu->kvm->lock); - reset_state = vcpu->arch.reset_state; - WRITE_ONCE(vcpu->arch.reset_state.reset, false); - mutex_unlock(&vcpu->kvm->lock); - /* Reset PMU outside of the non-preemptible section */ kvm_pmu_vcpu_reset(vcpu); @@ -296,8 +293,8 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu) * Additional reset state handling that PSCI may have imposed on us. * Must be done after all the sys_reg reset. */ - if (reset_state.reset) { - unsigned long target_pc = reset_state.pc; + if (reset_state->reset) { + unsigned long target_pc = reset_state->pc; /* Gracefully handle Thumb2 entry point */ if (vcpu_mode_is_32bit(vcpu) && (target_pc & 1)) { @@ -306,11 +303,11 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu) } /* Propagate caller endianness */ - if (reset_state.be) + if (reset_state->be) kvm_vcpu_set_be(vcpu); *vcpu_pc(vcpu) = target_pc; - vcpu_set_reg(vcpu, 0, reset_state.r0); + vcpu_set_reg(vcpu, 0, reset_state->r0); } /* Reset timer */ @@ -320,6 +317,19 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu) kvm_arch_vcpu_load(vcpu, smp_processor_id()); preempt_enable(); return ret; + +} + +int kvm_reset_vcpu(struct kvm_vcpu *vcpu) +{ + struct vcpu_reset_state reset_state; + + mutex_lock(&vcpu->kvm->lock); + reset_state = vcpu->arch.reset_state; + WRITE_ONCE(vcpu->arch.reset_state.reset, false); + mutex_unlock(&vcpu->kvm->lock); + + return __kvm_reset_vcpu(vcpu, &reset_state); } u32 get_kvm_ipa_limit(void)