From patchwork Fri Feb 22 15:06:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 10826411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9CE4B1805 for ; Fri, 22 Feb 2019 15:08:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 845363123F for ; Fri, 22 Feb 2019 15:08:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7301D313CD; Fri, 22 Feb 2019 15:08:40 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 209403123F for ; Fri, 22 Feb 2019 15:08:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=bOM40XYr+TQtdBQlp0rGuO+cKSBB7Zrv4QrTQXY6xRs=; b=Lg2XS69Iw7lUNh4jrD5BPFTNZX KHDkrRsTzhaMsGM3vWGh3y7yvRw4VIoZsk6MCGsyAxiZlEsqobc4Yo1ciP+hi9SNN9AICOZPQj1tH q7kQd8yaXaC8gCeOQtf9KehjscEKWQGNXc4VngMqNvpk0x58A2l+Aab6Uki1EA9jiH+H16ZFVr4dk 9W5aSTb1003FZsFeILqqCLIBMyNHPWCgz1FfvQLovw4QD2Tlz0S1QwsliI2IS2G4n5M4/pRgMkRqQ SyiMsgEOk7fgh+E7tlOPcDyPV+67AlJbxfN7+ksTb/8cpP3FWPdBiEMux/FCRJGV3apNYJieUCfxB gntW6Xqg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gxCRJ-0001K3-IB; Fri, 22 Feb 2019 15:08:37 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gxCQY-0000OO-QP for linux-arm-kernel@lists.infradead.org; Fri, 22 Feb 2019 15:08:00 +0000 Received: by mail-pg1-x544.google.com with SMTP id q206so1262059pgq.4 for ; Fri, 22 Feb 2019 07:07:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7Go7voUR7PP9IbtPtHYJZJ9KLXpiKBFH7bP0tDDsjB4=; b=OMYxgFb/TH+McvC6/yX42s2bOKqIFuH7liGSdQk8dA6R6rivWAFzdcTvJKKIW7G4nu lXYzdbjHlZnvOqn1M4ZA9z730vCqf2E1ybCCqsj65itbbqBKwDX6hpuZHXoy0miurviB kxP6/HeP2wKEXEVp3a+Ug85E1C5++G9MDrdRQLX225uRpiuqsgIHz8qEUnfGUhbFyBst nrdGgq8aT26OjCzFjuLr/3y3vhcfqcb4viY/i5FAVoqBRY4uuiJ5fu4uyigEKBWrsW/O YyIgfPonVe/xzXniC19S3KWG4/oNp0oM5MXd41ZVqSHpzwaZL+UjWa7IuouoIhAcXe+t 2ySg== 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=7Go7voUR7PP9IbtPtHYJZJ9KLXpiKBFH7bP0tDDsjB4=; b=sJCGEAv36em3sT0GaNkquzp5DM4CU3biWsd7J2ahnfj2irqX+hqJaLEHQsvAMUMZwM CrFjsyp+HbibcCrdwjZssUBYJ91J7UTNtFEd5qvtaH8nvvKs4K9GhAtcYEHRUT9tIim4 nY3U17iMuydK8/E666QManIP+ti8kpTJJQOFPWeM4gkc6RXYfp1p+60VehHMPrP5YKTg FFTW+XczfuZkX6B/HzoqaSnpc3ElGfVylCRFzGBoDnH2rMOaPQlMjlyMOJla+mPB2fU0 NnX8/IFWCZBxZuWR8QdsTcZ3TJdCv8q7T84ICieF6zJMuQMWsU8KigJxcl22cYYaAK4g HQXw== X-Gm-Message-State: AHQUAuYkxq+QodBQp+TW24pK3wegUnEB43uegwyh0tOnjY5xAazP+fdq xqebpqxX1KCcqjAtBNGvfII= X-Google-Smtp-Source: AHgI3IZHlSqh4FBsJPrlCgkevIFZismIyLuu2+1WWH0cRzRKJdFO+uEViGuOXjTF2NY5mtMA0QRKFQ== X-Received: by 2002:a63:1260:: with SMTP id 32mr4435319pgs.278.1550848070153; Fri, 22 Feb 2019 07:07:50 -0800 (PST) Received: from localhost.corp.microsoft.com ([167.220.255.67]) by smtp.googlemail.com with ESMTPSA id a4sm6151780pga.52.2019.02.22.07.07.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Feb 2019 07:07:49 -0800 (PST) From: lantianyu1986@gmail.com X-Google-Original-From: Tianyu.Lan@microsoft.com To: Subject: [PATCH V3 7/10] KVM: Use tlb range flush in the kvm_vm_ioctl_get/clear_dirty_log() Date: Fri, 22 Feb 2019 23:06:34 +0800 Message-Id: <20190222150637.2337-8-Tianyu.Lan@microsoft.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20190222150637.2337-1-Tianyu.Lan@microsoft.com> References: <20190222150637.2337-1-Tianyu.Lan@microsoft.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190222_070753_715388_E4470B96 X-CRM114-Status: GOOD ( 12.75 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, rkrcmar@redhat.com, catalin.marinas@arm.com, will.deacon@arm.com, christoffer.dall@arm.com, paulus@ozlabs.org, hpa@zytor.com, kys@microsoft.com, kvmarm@lists.cs.columbia.edu, mpe@ellerman.id.au, x86@kernel.org, linux@armlinux.org.uk, michael.h.kelley@microsoft.com, mingo@redhat.com, benh@kernel.crashing.org, jhogan@kernel.org, linux-mips@vger.kernel.org, Lan Tianyu , marc.zyngier@arm.com, kvm-ppc@vger.kernel.org, bp@alien8.de, tglx@linutronix.de, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, ralf@linux-mips.org, paul.burton@mips.com, pbonzini@redhat.com, vkuznets@redhat.com, linuxppc-dev@lists.ozlabs.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Lan Tianyu This patch is to use tlb range flush to flush memslot's in the kvm_vm_ioctl_get/clear_dirty_log() instead of flushing tlbs of entire ept page table when range flush is available. Signed-off-by: Lan Tianyu --- arch/x86/kvm/mmu.c | 8 +------- arch/x86/kvm/mmu.h | 7 +++++++ arch/x86/kvm/x86.c | 16 ++++++++++++---- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 60b1771e400e..e9a727aad603 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -266,12 +266,6 @@ static void mmu_spte_set(u64 *sptep, u64 spte); static union kvm_mmu_page_role kvm_mmu_calc_root_page_role(struct kvm_vcpu *vcpu); - -static inline bool kvm_available_flush_tlb_with_range(void) -{ - return kvm_x86_ops->tlb_remote_flush_with_range; -} - static void kvm_flush_remote_tlbs_with_range(struct kvm *kvm, struct kvm_tlb_range *range) { @@ -284,7 +278,7 @@ static void kvm_flush_remote_tlbs_with_range(struct kvm *kvm, kvm_flush_remote_tlbs(kvm); } -static void kvm_flush_remote_tlbs_with_address(struct kvm *kvm, +void kvm_flush_remote_tlbs_with_address(struct kvm *kvm, u64 start_gfn, u64 pages) { struct kvm_tlb_range range; diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h index bbdc60f2fae8..5e0d9418b912 100644 --- a/arch/x86/kvm/mmu.h +++ b/arch/x86/kvm/mmu.h @@ -63,6 +63,13 @@ void kvm_init_shadow_ept_mmu(struct kvm_vcpu *vcpu, bool execonly, bool kvm_can_do_async_pf(struct kvm_vcpu *vcpu); int kvm_handle_page_fault(struct kvm_vcpu *vcpu, u64 error_code, u64 fault_address, char *insn, int insn_len); +void kvm_flush_remote_tlbs_with_address(struct kvm *kvm, + u64 start_gfn, u64 pages); + +static inline bool kvm_available_flush_tlb_with_range(void) +{ + return kvm_x86_ops->tlb_remote_flush_with_range; +} static inline unsigned int kvm_mmu_available_pages(struct kvm *kvm) { diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 40d8272bee96..35738a7256f4 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4448,9 +4448,13 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) * kvm_mmu_slot_remove_write_access(). */ lockdep_assert_held(&kvm->slots_lock); - if (flush) - kvm_flush_remote_tlbs(kvm); + if (flush) { + struct kvm_memory_slot *memslot = kvm_get_memslot(kvm, + log->slot); + kvm_flush_remote_tlbs_with_address(kvm, memslot->base_gfn, + memslot->npages); + } mutex_unlock(&kvm->slots_lock); return r; } @@ -4475,9 +4479,13 @@ int kvm_vm_ioctl_clear_dirty_log(struct kvm *kvm, struct kvm_clear_dirty_log *lo * kvm_mmu_slot_remove_write_access(). */ lockdep_assert_held(&kvm->slots_lock); - if (flush) - kvm_flush_remote_tlbs(kvm); + if (flush) { + struct kvm_memory_slot *memslot = kvm_get_memslot(kvm, + log->slot); + kvm_flush_remote_tlbs_with_address(kvm, memslot->base_gfn, + memslot->npages); + } mutex_unlock(&kvm->slots_lock); return r; }