From patchwork Mon Mar 15 14:22:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 400480 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp3470984jai; Mon, 15 Mar 2021 07:26:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVDj1/kqx15RNigps358d+sODmH8ojx9GpsXXhj9TagVHSSGDVGrGyj7nX/bvi/lZuDpzx X-Received: by 2002:a17:906:398a:: with SMTP id h10mr24217044eje.155.1615818411170; Mon, 15 Mar 2021 07:26:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615818411; cv=none; d=google.com; s=arc-20160816; b=Hfmh/cdbsSxt1DfRnE/aRnZRd6dQMv0DHVaocntDHe8vBNgUo9xbN1X5oUffS6H1VT rLAYG5SLGeiS6o2K2jAg08sLL1hhmWUGLf8Wo6AyiVVvf6lWbwXjvw/IfDPtNzRzMyqN z61xdlC7wkXugxmHZdoGImwT0323zZw3Rog2yYTaELMC9n7lImBp3sGbAWFb6Ma4XwHv H1iA40vYZAjx4TFhiorlOSRnNLMSwKLL8GrxkEg/On9STOKN7ZXdScxKu6VwzLiONBUo xX4R83ARw/GQb/z9G/ZSMUviCz3EVJYAdD64j4Yn55jJBXkmrtz45qkzt3bORwj4C3J3 e4QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xVc3Yf9iBW5sepGoGfOmmtMld8fxK0v0Ez4cUuGgSGg=; b=lI2I/azAIXEPFB1tBJ6CviT+6+VM371F9IvPd11WolW7AUPrIMwNycI8ldqekkeEbV H0Nc8+9TL7oE3Il+8C80m3wNWJseZ93iIcuH+FiSLNkkEWnSynog2clpncFkOA/ETAJH 2YHiK4zBqCGnO2Stz4U/rKiBHhGTorgQvkOdwgA404Y9akrUFt63zuLi+V6n9Pr4agks ggTvmjEY4IxDU3InjBJVsZnMak7LsRJ3bcTvw6DKzBrZa77GxVYhNtI9wx4xAYeum/2D pMBp25H7rUUhkoIQ/o8eRMlkEr7t15BBrXAt5Ady+FcXuwrXrvbBJxbwMv9IFc1S2G27 h+dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Pf9k8v8U; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h21si993553ede.37.2021.03.15.07.26.50; Mon, 15 Mar 2021 07:26:51 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Pf9k8v8U; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232917AbhCOOYP (ORCPT + 12 others); Mon, 15 Mar 2021 10:24:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:45522 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238167AbhCOOWy (ORCPT ); Mon, 15 Mar 2021 10:22:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6AD0964F39; Mon, 15 Mar 2021 14:22:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615818172; bh=zP9kTGomFgIWODqfebw3wXea67yB5tB2f/ENVtNCn34=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pf9k8v8UXuH5iB4SZypP9Fvq/BbKkNDRJwKAvydSq7vjKXekJrUN6ys/VGfpxZznn /lcxJ7+bBoBNgFVZLoYLKANx9275CLHhJvW/qjMiRSA6SXQ3voxtW3TgTvDv7W5uQK HGoZN7zLXEG+rK1wiJDl0d0LhQX7uNV9Nr2XkEWE= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoffer Dall , Marc Zyngier , Will Deacon , Catalin Marinas , Mark Rutland , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini Subject: [PATCH 5.10 280/290] KVM: arm64: nvhe: Save the SPE context early Date: Mon, 15 Mar 2021 15:22:30 +0100 Message-Id: <20210315135551.498961478@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135551.391322899@linuxfoundation.org> References: <20210315135541.921894249@linuxfoundation.org> <20210315135551.391322899@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Greg Kroah-Hartman From: Suzuki K Poulose commit b96b0c5de685df82019e16826a282d53d86d112c upstream. The nVHE KVM hyp drains and disables the SPE buffer, before entering the guest, as the EL1&0 translation regime is going to be loaded with that of the guest. But this operation is performed way too late, because : - The owning translation regime of the SPE buffer is transferred to EL2. (MDCR_EL2_E2PB == 0) - The guest Stage1 is loaded. Thus the flush could use the host EL1 virtual address, but use the EL2 translations instead of host EL1, for writing out any cached data. Fix this by moving the SPE buffer handling early enough. The restore path is doing the right thing. Fixes: 014c4c77aad7 ("KVM: arm64: Improve debug register save/restore flow") Cc: stable@vger.kernel.org Cc: Christoffer Dall Cc: Marc Zyngier Cc: Will Deacon Cc: Catalin Marinas Cc: Mark Rutland Cc: Alexandru Elisei Reviewed-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose Signed-off-by: Marc Zyngier Link: https://lore.kernel.org/r/20210302120345.3102874-1-suzuki.poulose@arm.com Message-Id: <20210305185254.3730990-2-maz@kernel.org> Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/kvm_hyp.h | 5 +++++ arch/arm64/kvm/hyp/nvhe/debug-sr.c | 12 ++++++++++-- arch/arm64/kvm/hyp/nvhe/switch.c | 11 ++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) --- a/arch/arm64/include/asm/kvm_hyp.h +++ b/arch/arm64/include/asm/kvm_hyp.h @@ -82,6 +82,11 @@ void sysreg_restore_guest_state_vhe(stru void __debug_switch_to_guest(struct kvm_vcpu *vcpu); void __debug_switch_to_host(struct kvm_vcpu *vcpu); +#ifdef __KVM_NVHE_HYPERVISOR__ +void __debug_save_host_buffers_nvhe(struct kvm_vcpu *vcpu); +void __debug_restore_host_buffers_nvhe(struct kvm_vcpu *vcpu); +#endif + void __fpsimd_save_state(struct user_fpsimd_state *fp_regs); void __fpsimd_restore_state(struct user_fpsimd_state *fp_regs); --- a/arch/arm64/kvm/hyp/nvhe/debug-sr.c +++ b/arch/arm64/kvm/hyp/nvhe/debug-sr.c @@ -58,16 +58,24 @@ static void __debug_restore_spe(u64 pmsc write_sysreg_s(pmscr_el1, SYS_PMSCR_EL1); } -void __debug_switch_to_guest(struct kvm_vcpu *vcpu) +void __debug_save_host_buffers_nvhe(struct kvm_vcpu *vcpu) { /* Disable and flush SPE data generation */ __debug_save_spe(&vcpu->arch.host_debug_state.pmscr_el1); +} + +void __debug_switch_to_guest(struct kvm_vcpu *vcpu) +{ __debug_switch_to_guest_common(vcpu); } -void __debug_switch_to_host(struct kvm_vcpu *vcpu) +void __debug_restore_host_buffers_nvhe(struct kvm_vcpu *vcpu) { __debug_restore_spe(vcpu->arch.host_debug_state.pmscr_el1); +} + +void __debug_switch_to_host(struct kvm_vcpu *vcpu) +{ __debug_switch_to_host_common(vcpu); } --- a/arch/arm64/kvm/hyp/nvhe/switch.c +++ b/arch/arm64/kvm/hyp/nvhe/switch.c @@ -188,6 +188,14 @@ int __kvm_vcpu_run(struct kvm_vcpu *vcpu pmu_switch_needed = __pmu_switch_to_guest(host_ctxt); __sysreg_save_state_nvhe(host_ctxt); + /* + * We must flush and disable the SPE buffer for nVHE, as + * the translation regime(EL1&0) is going to be loaded with + * that of the guest. And we must do this before we change the + * translation regime to EL2 (via MDCR_EL2_E2PB == 0) and + * before we load guest Stage1. + */ + __debug_save_host_buffers_nvhe(vcpu); /* * We must restore the 32-bit state before the sysregs, thanks @@ -228,11 +236,12 @@ int __kvm_vcpu_run(struct kvm_vcpu *vcpu if (vcpu->arch.flags & KVM_ARM64_FP_ENABLED) __fpsimd_save_fpexc32(vcpu); + __debug_switch_to_host(vcpu); /* * This must come after restoring the host sysregs, since a non-VHE * system may enable SPE here and make use of the TTBRs. */ - __debug_switch_to_host(vcpu); + __debug_restore_host_buffers_nvhe(vcpu); if (pmu_switch_needed) __pmu_switch_to_host(host_ctxt);