Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3341228yba; Mon, 6 May 2019 22:50:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqzlxVcQ6E1xOl5FdAQir9RMBD/PZSP9GA4x7k03FoiqpU4akDRG4DpUQSVDsx381Doy/KVO X-Received: by 2002:a17:902:d708:: with SMTP id w8mr37841059ply.231.1557208241466; Mon, 06 May 2019 22:50:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557208241; cv=none; d=google.com; s=arc-20160816; b=Fa9jQn9CJ3vlqFssdJ4nYCGULwpmGFSHyV2Bdv+/z6fASCpMXQr/2Y3sXM4gzTbVbZ cVLSnaf77X/ogjrBdv9D4sTlJi6pWzDdQsQsFSZkQFWAVD02V1KY3Qe5wxE58lodyd0U Zhfn4ohlOjF4+aZtqxOiFS2CjJSEteq7861gRhwIagYNulIN5oeS34GvG8BG759sO1PD xdnQkYRPJ1VtaED/iE2WpVTCbCd1WDjX4uqrqgQ30g0rDTYQVR8e4dBp5vy8xaCOZIck wkMg0BJ/Us5d26aIwRQzug3F1aFar1GmRxO2LsyVA+IrWQbWz/sWeBM6U/9Y98JBz8Lj P8mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/hXYr+9+V+nZ1SFik2pVj/xq/o4+bbGjU/v+ERCDNpc=; b=L7+xkT50F/H9jVMakpXXj+0BMuRCgmR6OP2weLZRCLreWHb5MZ0kH//CEzW8B02ajA J+ViWODBrUPp8kRr3E2P+C+2c+l6VOBbsSy3dNPn2W4fo4+b9OLIQ+rvr+bhuC65n7mi /HGFRmeKHY2junM2+yJwgX5Qs0C/mtM+Gn1iqVATw+e8TPtmJyBd3X65ue/ep0z/9Rt7 Z2/QHkca1jljHajAzjxRQm74CBTUf+cAtVwpic95UYv5xj+jCsSq/4g8ozeNsYODl3Re UEMUUQswAg237pSoktlZZbfCGCgFw7Rlg5ngcV6ja5MYLe2zcp2x28uzIi5GYG3vxEqJ oUGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DlUNJYJq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b36si18431224pla.353.2019.05.06.22.50.25; Mon, 06 May 2019 22:50:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DlUNJYJq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729279AbfEGFti (ORCPT + 99 others); Tue, 7 May 2019 01:49:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:59918 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728293AbfEGFk0 (ORCPT ); Tue, 7 May 2019 01:40:26 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 60077216C8; Tue, 7 May 2019 05:40:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557207625; bh=5P2H5+gsVcPZ1ggy4BitQnui3B9j4EZ5RodrYR8oJJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DlUNJYJqRVdPkIcTWhyswyECS6OeSd22y3+1vtJaq3i/H10sAMWUnqCZkPSne9VHF iLKjxS8MkTpKgiHXk7dfJUM5Lo5GPbetzNpMpkpKISdCagpWhQ8TdD3f43+GFsjyKt wC58OTzKfkDd5fK3SMmWPkH70M3ubTNMREWBw/60= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Marc Zyngier , Christoffer Dall , James Morse , Will Deacon , Sasha Levin , kvmarm@lists.cs.columbia.edu Subject: [PATCH AUTOSEL 4.14 63/95] arm64: KVM: Make VHE Stage-2 TLB invalidation operations non-interruptible Date: Tue, 7 May 2019 01:37:52 -0400 Message-Id: <20190507053826.31622-63-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190507053826.31622-1-sashal@kernel.org> References: <20190507053826.31622-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Zyngier [ Upstream commit c987876a80e7bcb98a839f10dca9ce7fda4feced ] Contrary to the non-VHE version of the TLB invalidation helpers, the VHE code has interrupts enabled, meaning that we can take an interrupt in the middle of such a sequence, and start running something else with HCR_EL2.TGE cleared. That's really not a good idea. Take the heavy-handed option and disable interrupts in __tlb_switch_to_guest_vhe, restoring them in __tlb_switch_to_host_vhe. The latter also gain an ISB in order to make sure that TGE really has taken effect. Cc: stable@vger.kernel.org Acked-by: Christoffer Dall Reviewed-by: James Morse Signed-off-by: Marc Zyngier Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- arch/arm64/kvm/hyp/tlb.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/arch/arm64/kvm/hyp/tlb.c b/arch/arm64/kvm/hyp/tlb.c index 73464a96c365..db23c6e5c885 100644 --- a/arch/arm64/kvm/hyp/tlb.c +++ b/arch/arm64/kvm/hyp/tlb.c @@ -15,13 +15,18 @@ * along with this program. If not, see . */ +#include + #include #include -static void __hyp_text __tlb_switch_to_guest_vhe(struct kvm *kvm) +static void __hyp_text __tlb_switch_to_guest_vhe(struct kvm *kvm, + unsigned long *flags) { u64 val; + local_irq_save(*flags); + /* * With VHE enabled, we have HCR_EL2.{E2H,TGE} = {1,1}, and * most TLB operations target EL2/EL0. In order to affect the @@ -36,7 +41,8 @@ static void __hyp_text __tlb_switch_to_guest_vhe(struct kvm *kvm) isb(); } -static void __hyp_text __tlb_switch_to_guest_nvhe(struct kvm *kvm) +static void __hyp_text __tlb_switch_to_guest_nvhe(struct kvm *kvm, + unsigned long *flags) { write_sysreg(kvm->arch.vttbr, vttbr_el2); isb(); @@ -47,7 +53,8 @@ static hyp_alternate_select(__tlb_switch_to_guest, __tlb_switch_to_guest_vhe, ARM64_HAS_VIRT_HOST_EXTN); -static void __hyp_text __tlb_switch_to_host_vhe(struct kvm *kvm) +static void __hyp_text __tlb_switch_to_host_vhe(struct kvm *kvm, + unsigned long flags) { /* * We're done with the TLB operation, let's restore the host's @@ -55,9 +62,12 @@ static void __hyp_text __tlb_switch_to_host_vhe(struct kvm *kvm) */ write_sysreg(0, vttbr_el2); write_sysreg(HCR_HOST_VHE_FLAGS, hcr_el2); + isb(); + local_irq_restore(flags); } -static void __hyp_text __tlb_switch_to_host_nvhe(struct kvm *kvm) +static void __hyp_text __tlb_switch_to_host_nvhe(struct kvm *kvm, + unsigned long flags) { write_sysreg(0, vttbr_el2); } @@ -69,11 +79,13 @@ static hyp_alternate_select(__tlb_switch_to_host, void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa) { + unsigned long flags; + dsb(ishst); /* Switch to requested VMID */ kvm = kern_hyp_va(kvm); - __tlb_switch_to_guest()(kvm); + __tlb_switch_to_guest()(kvm, &flags); /* * We could do so much better if we had the VA as well. @@ -116,36 +128,39 @@ void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa) if (!has_vhe() && icache_is_vpipt()) __flush_icache_all(); - __tlb_switch_to_host()(kvm); + __tlb_switch_to_host()(kvm, flags); } void __hyp_text __kvm_tlb_flush_vmid(struct kvm *kvm) { + unsigned long flags; + dsb(ishst); /* Switch to requested VMID */ kvm = kern_hyp_va(kvm); - __tlb_switch_to_guest()(kvm); + __tlb_switch_to_guest()(kvm, &flags); __tlbi(vmalls12e1is); dsb(ish); isb(); - __tlb_switch_to_host()(kvm); + __tlb_switch_to_host()(kvm, flags); } void __hyp_text __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu) { struct kvm *kvm = kern_hyp_va(kern_hyp_va(vcpu)->kvm); + unsigned long flags; /* Switch to requested VMID */ - __tlb_switch_to_guest()(kvm); + __tlb_switch_to_guest()(kvm, &flags); __tlbi(vmalle1); dsb(nsh); isb(); - __tlb_switch_to_host()(kvm); + __tlb_switch_to_host()(kvm, flags); } void __hyp_text __kvm_flush_vm_context(void) -- 2.20.1