From patchwork Fri Sep 24 12:53:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 12515377 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0851CC433F5 for ; Fri, 24 Sep 2021 13:18:37 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C30AD60F41 for ; Fri, 24 Sep 2021 13:18:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C30AD60F41 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=V+5oBraqVcqBCH6vazPZe2IWbWUbrjoMfFi47QfW80A=; b=pQIO8oRuK649cEtc5K6MJPF9pi OhI/CDPF5MNxS3yqRygFDQX63YHaFG+ZPJ89rfuCfFH622wVMhLyeMfcSMjxMV6h9r8ET84ZN6ntT st+JvcSPwHbyjUh+pz3rLm8aCIjLmG9wn707+TBEmLk1pmYNXzkut0joSovV/RAXjnrSw/sZ7nyDi cbh0ovrwtL7v2tG2RGzzsw0jSFki6kJw6xREZIf+5+C9njEIV99f3Dy1ds7U8NIMs8YCapIX/LIUp KvryaFkqVpvCStBlC/gVK8C4NNlAA2ocBbEpW60i178k2y/q5W5e4sl3Qi6rTqjBTMA7ytZOTlWhc YsZ40Opg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mTl46-00EVLk-Hk; Fri, 24 Sep 2021 13:16:35 +0000 Received: from mail-qt1-x849.google.com ([2607:f8b0:4864:20::849]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mTkjF-00EMMH-NN for linux-arm-kernel@lists.infradead.org; Fri, 24 Sep 2021 12:55:03 +0000 Received: by mail-qt1-x849.google.com with SMTP id a22-20020ac86116000000b002a1463f30ddso28344252qtm.17 for ; Fri, 24 Sep 2021 05:55:01 -0700 (PDT) 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=y44fzIX1ftLMcQsIMexqk7MlH9WcFM4Uf4DFLHOV8zw=; b=kbcSGdX6W1DTAU32KsoIRyu5RXf3fqm9Ft5iyr3m/VyqUU0YPxHG/sYle+VkB16whN 9piwWyrAzf3Hxu30Th595VibMFLO2rpVfcxRv8/4Vr3TxfZOOinM57oyVhs3Lyv3EEw9 3CD8zN0/CXFY+HOMRwnQZFvaTz/vPVp1e2YFjT8nonSduXGwPCwDIb6KxRjLfSKyrEtU rm8/pwdZ5NhnzCLYTqiDn9sxDW66NgWRbLMVtkQ6y1APguvqZIitvKc9pajmjDzx7G2S D3fDEfhzx/5Av6NBQz11mDPmB0KHsuaTGp3D1kawfgMWZ5D6+PDgqcBdRjHtYliJMgMP flYw== 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=y44fzIX1ftLMcQsIMexqk7MlH9WcFM4Uf4DFLHOV8zw=; b=Zal1H0gLs/QUnBMUmu/S7cQ0uEYzoMsLEMv6KNacvsVhCs8EbgcmWD8zS6oVcREdx7 xHEdn9pz2DuwL0hGB1ZnQ9NvbqPeVpsayl3pKKW8eRIEX6mWdDOr9KjwYCQp8HkBddOl NpOj8VB2jTrC4xj8Q9+B86fBVfVYlrDAaeS0FIQNfpLdoIcQC1efJQfuepbpCP6KepdD 9B882BOfeNFwRY7SSByQFLYwfFnvAX/wQl5u/5WuRFwgI5CJ4SdeY4Qu9Kxqw3G6vnqx 6miO9vLiihmtgwvUKcK0mS13W3sA2mT/rJLhJA3mWgfY4Dopfn/0hcC8GNdA5wYR1eqX yXmw== X-Gm-Message-State: AOAM531B8bqrw2/jqqtwxthpgG3BKE07TKR2Xe7dy2fQrPhOEVzV319q DQ3OCPPtNe5OPJSGrayL0fSPhgOXrg== X-Google-Smtp-Source: ABdhPJwzDg459e5SoIW1gM5OBltgwgX9FKJl95y+IxUYvre8ucu6ik03AQSvZPZnEMDcAv3LYlxmQdXBGA== X-Received: from tabba.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:482]) (user=tabba job=sendgmr) by 2002:a05:6214:2e4:: with SMTP id h4mr9596859qvu.3.1632488100413; Fri, 24 Sep 2021 05:55:00 -0700 (PDT) Date: Fri, 24 Sep 2021 13:53:57 +0100 In-Reply-To: <20210924125359.2587041-1-tabba@google.com> Message-Id: <20210924125359.2587041-29-tabba@google.com> Mime-Version: 1.0 References: <20210924125359.2587041-1-tabba@google.com> X-Mailer: git-send-email 2.33.0.685.g46640cef36-goog Subject: [RFC PATCH v1 28/30] KVM: arm64: reduce scope of pVM fixup_guest_exit to hyp_state and kvm_cpu_ctxt From: Fuad Tabba To: kvmarm@lists.cs.columbia.edu Cc: maz@kernel.org, will@kernel.org, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, mark.rutland@arm.com, christoffer.dall@arm.com, drjones@redhat.com, qperret@google.com, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel-team@android.com, tabba@google.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210924_055501_856601_3D5D5925 X-CRM114-Status: GOOD ( 13.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Reduce the scope of fixup_guest_exit for protected VMs to only need hyp_state and kvm_cpu_ctxt Signed-off-by: Fuad Tabba --- arch/arm64/kvm/hyp/include/hyp/switch.h | 23 +++++++++++++++++++---- arch/arm64/kvm/hyp/nvhe/switch.c | 7 ++----- arch/arm64/kvm/hyp/vhe/switch.c | 3 +-- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h index 3ef429cfd9af..ea9571f712c6 100644 --- a/arch/arm64/kvm/hyp/include/hyp/switch.h +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h @@ -423,11 +423,8 @@ static inline bool __hyp_handle_ptrauth(struct kvm_vcpu *vcpu) * the guest, false when we should restore the host state and return to the * main run loop. */ -static inline bool fixup_guest_exit(struct kvm_vcpu *vcpu, struct vgic_dist *vgic, u64 *exit_code) +static inline bool _fixup_guest_exit(struct kvm_vcpu *vcpu, struct vgic_dist *vgic, struct kvm_cpu_context *vcpu_ctxt, struct vcpu_hyp_state *vcpu_hyps, u64 *exit_code) { - struct vcpu_hyp_state *vcpu_hyps = &hyp_state(vcpu); - struct kvm_cpu_context *vcpu_ctxt = &vcpu_ctxt(vcpu); - if (ARM_EXCEPTION_CODE(*exit_code) != ARM_EXCEPTION_IRQ) hyp_state_fault(vcpu_hyps).esr_el2 = read_sysreg_el2(SYS_ESR); @@ -518,6 +515,24 @@ static inline bool fixup_guest_exit(struct kvm_vcpu *vcpu, struct vgic_dist *vgi return true; } +static inline bool fixup_guest_exit(struct kvm_vcpu *vcpu, u64 *exit_code) +{ + struct kvm_cpu_context *ctxt = &vcpu->arch.ctxt; + struct vcpu_hyp_state *hyps = &vcpu->arch.hyp_state; + // TODO: create helper for getting VA + struct kvm *kvm = vcpu->kvm; + + if (is_nvhe_hyp_code()) + kvm = kern_hyp_va(kvm); + + return _fixup_guest_exit(vcpu, &kvm->arch.vgic, ctxt, hyps, exit_code); +} + +static inline bool fixup_pvm_guest_exit(struct kvm_vcpu *vcpu, struct vgic_dist *vgic, struct kvm_cpu_context *ctxt, struct vcpu_hyp_state *hyps, u64 *exit_code) +{ + return _fixup_guest_exit(vcpu, vgic, ctxt, hyps, exit_code); +} + static inline void __kvm_unexpected_el2_exception(void) { extern char __guest_exit_panic[]; diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c index aa0dc4f0433b..1920aebbe49a 100644 --- a/arch/arm64/kvm/hyp/nvhe/switch.c +++ b/arch/arm64/kvm/hyp/nvhe/switch.c @@ -182,8 +182,6 @@ static int __kvm_vcpu_run_nvhe(struct kvm_vcpu *vcpu) { struct vcpu_hyp_state *vcpu_hyps = &vcpu->arch.hyp_state; struct kvm_cpu_context *vcpu_ctxt = &vcpu->arch.ctxt; - struct kvm *kvm = kern_hyp_va(vcpu->kvm); - struct vgic_dist *vgic = &kvm->arch.vgic; struct kvm_cpu_context *host_ctxt; struct kvm_cpu_context *guest_ctxt; bool pmu_switch_needed; @@ -245,7 +243,7 @@ static int __kvm_vcpu_run_nvhe(struct kvm_vcpu *vcpu) exit_code = __guest_enter(guest_ctxt); /* And we're baaack! */ - } while (fixup_guest_exit(vcpu, vgic, &exit_code)); + } while (fixup_guest_exit(vcpu, &exit_code)); __sysreg_save_state_nvhe(guest_ctxt); __sysreg32_save_state(vcpu); @@ -285,7 +283,6 @@ static int __kvm_vcpu_run_pvm(struct kvm_vcpu *vcpu) struct vcpu_hyp_state *vcpu_hyps = &hyp_state(vcpu); struct kvm_cpu_context *vcpu_ctxt = &vcpu_ctxt(vcpu); struct kvm *kvm = kern_hyp_va(vcpu->kvm); - struct vgic_dist *vgic = &kvm->arch.vgic; struct kvm_cpu_context *host_ctxt; struct kvm_cpu_context *guest_ctxt; u64 exit_code; @@ -325,7 +322,7 @@ static int __kvm_vcpu_run_pvm(struct kvm_vcpu *vcpu) exit_code = __guest_enter(guest_ctxt); /* And we're baaack! */ - } while (fixup_guest_exit(vcpu, vgic, &exit_code)); + } while (fixup_pvm_guest_exit(vcpu, &kvm->arch.vgic, vcpu_ctxt, vcpu_hyps, &exit_code)); __sysreg_save_state_nvhe(guest_ctxt); __timer_disable_traps(); diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c index 7f926016cebe..4a05aff37325 100644 --- a/arch/arm64/kvm/hyp/vhe/switch.c +++ b/arch/arm64/kvm/hyp/vhe/switch.c @@ -110,7 +110,6 @@ static int __kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu) { struct vcpu_hyp_state *vcpu_hyps = &hyp_state(vcpu); struct kvm_cpu_context *vcpu_ctxt = &vcpu_ctxt(vcpu); - struct vgic_dist *vgic = &vcpu->kvm->arch.vgic; struct kvm_cpu_context *host_ctxt; struct kvm_cpu_context *guest_ctxt; u64 exit_code; @@ -148,7 +147,7 @@ static int __kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu) exit_code = __guest_enter(guest_ctxt); /* And we're baaack! */ - } while (fixup_guest_exit(vcpu, vgic, &exit_code)); + } while (fixup_guest_exit(vcpu, &exit_code)); sysreg_save_guest_state_vhe(guest_ctxt);