From patchwork Tue Oct 3 03:10:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9981591 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4152C602B8 for ; Tue, 3 Oct 2017 03:19:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34944286DB for ; Tue, 3 Oct 2017 03:19:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 295742879D; Tue, 3 Oct 2017 03:19:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE62A286DB for ; Tue, 3 Oct 2017 03:19:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751774AbdJCDTp (ORCPT ); Mon, 2 Oct 2017 23:19:45 -0400 Received: from mail-it0-f53.google.com ([209.85.214.53]:53430 "EHLO mail-it0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751665AbdJCDLo (ORCPT ); Mon, 2 Oct 2017 23:11:44 -0400 Received: by mail-it0-f53.google.com with SMTP id 85so9735247ith.2 for ; Mon, 02 Oct 2017 20:11:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1Ucz1J4P5XUKPSNzgO4sG8gFNOHEthQaf/MHvQEb4Vo=; b=VS9z7cHcBpErAH9DZjxcZLAvGgEKw+0TDzVFYBAMV9bg1e2GmaHy8xMJgtsNutaCdv NeZmVFJL8Y/5Q7/UvxeqQ9JYUh7LHXIhWgNAEHc3DVqeRKmkvk18lXGUeRLnr5r84KSP X2Eb7Hfs1oDhkPUEeB3tGesKYVSn19KqWf7Ng= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1Ucz1J4P5XUKPSNzgO4sG8gFNOHEthQaf/MHvQEb4Vo=; b=IANccxGQyQFsHWLiBOOzyB1ofLZAfNJCBQZrl4B+OLf8Zsrdv2VQLorDu1bXlQrLdI 26M80Z8LZy5AZ5b9BfWMIzE4VeBBKMEMr4xxPhy1015xfvkPH/7W602d6NzofTVxQT3K eHww/guwP+X6R6NGszEzY4KZJB5dEDGwaxaYF7ozgrY7AztusJy4wyswkUibiJBDl8pL Gok3K0fz5Is3T+PGazNqC4hAV3pkOOcDedeHN/00AAKDqn4ifIgFM+M6ntSb12OjpyYi e5BnacqAEwyF+3Do2iXaRfy0Z9fx+UUsdQ8z96GdyNUd+3R+z5dx2ofBUCab0X35X0Ae UU+w== X-Gm-Message-State: AMCzsaVdxXc3Y7PEkJAVLbZpX5QqLmyXT5H35XtAKvWk7kOM6yGnAfvx 0/9TtmeWCdRSDoUDi8jVo4e4uA== X-Google-Smtp-Source: AOwi7QCsZQo6NhiQgypAsAOVhrCYWZuKSJ8bCa+1lqxBpGBdKtfw2+x65A9Q3cUN0IwWcW7PT/W59g== X-Received: by 10.36.83.146 with SMTP id n140mr24509145itb.104.1507000303557; Mon, 02 Oct 2017 20:11:43 -0700 (PDT) Received: from node.jintackl-qv28633.kvmarm-pg0.wisc.cloudlab.us (c220g1-031126.wisc.cloudlab.us. [128.104.222.76]) by smtp.gmail.com with ESMTPSA id h84sm5367193iod.72.2017.10.02.20.11.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Oct 2017 20:11:42 -0700 (PDT) From: Jintack Lim To: christoffer.dall@linaro.org, marc.zyngier@arm.com, kvmarm@lists.cs.columbia.edu Cc: jintack@cs.columbia.edu, pbonzini@redhat.com, rkrcmar@redhat.com, catalin.marinas@arm.com, will.deacon@arm.com, linux@armlinux.org.uk, mark.rutland@arm.com, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Jintack Lim Subject: [RFC PATCH v2 06/31] KVM: arm64: Invalidate virtual EL2 TLB entries when needed Date: Mon, 2 Oct 2017 22:10:48 -0500 Message-Id: <1507000273-3735-4-git-send-email-jintack.lim@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1507000273-3735-1-git-send-email-jintack.lim@linaro.org> References: <1507000273-3735-1-git-send-email-jintack.lim@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Christoffer Dall Sometimes when we are invalidating the TLB for a certain S2 MMU context, this context can also have EL2 context associated with it and we have to invalidate this too. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- virt/kvm/arm/arm.c | 5 +++++ virt/kvm/arm/mmu.c | 23 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index 41e0654..63dd897 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -362,6 +362,11 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) u64 vttbr = kvm_get_vttbr(&mmu->vmid, mmu); kvm_call_hyp(__kvm_tlb_flush_local_vmid, vttbr); + + if (mmu->el2_vmid.vmid) { + vttbr = kvm_get_vttbr(&mmu->el2_vmid, mmu); + kvm_call_hyp(__kvm_tlb_flush_local_vmid, vttbr); + } *last_ran = vcpu->vcpu_id; } diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c index 0edcf23..184cdc9 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -64,7 +64,21 @@ void kvm_flush_remote_tlbs(struct kvm *kvm) struct kvm_s2_mmu *mmu = &kvm->arch.mmu; u64 vttbr = kvm_get_vttbr(&mmu->vmid, mmu); - kvm_call_hyp(__kvm_tlb_flush_vmid, vttbr); + if (!mmu->el2_vmid.vmid) { + /* + * For a normal (i.e. non-nested) guest, flush entries for the + * given VMID * + */ + kvm_call_hyp(__kvm_tlb_flush_vmid, vttbr); + } else { + /* + * When supporting nested virtualization, we can have multiple + * VMIDs in play for each VCPU in the VM, so it's really not + * worth it to try to quiesce the system and flush all the + * VMIDs that may be in use, instead just nuke the whole thing. + */ + kvm_call_hyp(__kvm_flush_vm_context); + } } static void kvm_tlb_flush_vmid_ipa(struct kvm_s2_mmu *mmu, phys_addr_t ipa) @@ -72,6 +86,13 @@ static void kvm_tlb_flush_vmid_ipa(struct kvm_s2_mmu *mmu, phys_addr_t ipa) u64 vttbr = kvm_get_vttbr(&mmu->vmid, mmu); kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, vttbr, ipa); + + if (!mmu->el2_vmid.vmid) { + /* Nothing to do more for a non-nested guest */ + return; + } + vttbr = kvm_get_vttbr(&mmu->el2_vmid, mmu); + kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, vttbr, ipa); } /*