Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1990748imm; Sat, 13 Oct 2018 07:56:19 -0700 (PDT) X-Google-Smtp-Source: ACcGV632xvjuRq+ZT1mDpQcE8ogvLN5nBV6aFBcz4QfgiXQy3t7uVFM0xo4sVbhAK0IaAG+yn39q X-Received: by 2002:a62:4dc4:: with SMTP id a187-v6mr10516767pfb.92.1539442579400; Sat, 13 Oct 2018 07:56:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539442579; cv=none; d=google.com; s=arc-20160816; b=XoTFCjzT+NdD6FgVxdHva7DnJeqMgKI0eFscTmSlS0/amPLIQM20Ew9byTYal0Vkmh sYHUk5oDod+aBTFYFLbMB+gAEi7QHxVjWqQtmOOi4CrHnThRlEHw6ihD/qCfpCzXRLdV jDMAIz9FgiZJIzu8v/coWNFya1FBMlLhD3/wOgCwauPWWs21IOSO6ntyfiwcJgA6CIr0 Csjl9AxcNN+RcaVONEAg1neER0x/Gey8IHrc+HIfxQlR9Z3nGnIA5+yv2aJ8EEvCA+fe jpFfJlzSV4XU8HyUiS5vs0Ci2l1m9VuLpFl8Iu8IoB0yg8i9LtjZm2/Y5az901dFOmrA vzzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:in-reply-to:message-id:date :subject:cc:from:dkim-signature; bh=q/7F43zhWx/k3N9zoPwgZYybcBw1Pe45+WdtmLtkfPE=; b=hd1R869CFrg3DHh5W6EI/oSep2eUzTAbkPnbUvEH99S2cqtYdwReFchBRAxGeUzrOG KOzuLe0VgHVrdKUA3WMCOEEJsMwztv6qjNFfTHj4ujE+T95QanSz+Rtefsx6KgYAbzC/ Tjqj9xg22kyTqoKXLKZD0bWbUeoGGXtnzoOdA80Ev1CMmyhF6gxtSgj/yVAaQYNnx8xW GP6ne6aVmdVHSPPMhtsCjJUBK+QTsmMSw/re9z87fsTypVwIP5SxIEY5oOPClwt2kZ0b OyJvgO82dTX7lPoYCm0EMvhYoZdWZR8mKQZFqmVON1WJr/pGOcgnAb7tzCezx3jV8+fS Hayg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=iZMjwXcI; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x10-v6si3655555pfm.136.2018.10.13.07.56.04; Sat, 13 Oct 2018 07:56:19 -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=fail header.i=@gmail.com header.s=20161025 header.b=iZMjwXcI; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727000AbeJMWce (ORCPT + 99 others); Sat, 13 Oct 2018 18:32:34 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:38780 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726281AbeJMWce (ORCPT ); Sat, 13 Oct 2018 18:32:34 -0400 Received: by mail-pl1-f193.google.com with SMTP id q19-v6so4182598pll.5; Sat, 13 Oct 2018 07:55:08 -0700 (PDT) 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=q/7F43zhWx/k3N9zoPwgZYybcBw1Pe45+WdtmLtkfPE=; b=iZMjwXcIZQ64Vc7p72mkpjWEZuW++pmBRYnTO420QfKWfgp/Oz9qnwRlrR3tD6md4u m0KtdxhX9jnvyaKY182mG9HaiciZcpxsiHS01J3/J88qay558wvMaAD3ot/Fh2hiWNLZ TbdFOCKCfL/E33aQUBMZSd8zpFb5wTqw3n3K7IcOL3gz6vKWfVneu9BdniNbOhMpbNvP huWxK8AB0IPNaR+U2azLVoStK7ig28McwBp+VjPAFW7A4Ocxj11mAwrHFL6yRkOWOcQw 1yKZHBNiXqd+6u3PHKpUZZI+S7gyjpodLAW+RkcpCPcqORmHk8HslnS984bX6ZZbS1BJ bFFw== 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=q/7F43zhWx/k3N9zoPwgZYybcBw1Pe45+WdtmLtkfPE=; b=rLrE2zDj8qnELyutVYKIjvk+iwfgb9Hppz5L6RewL24ct3nAzdQ3doJ3xvTYujwQqt nxEP0ohSD70D+q8ioAgiyffMBfx3rTZGCWNRb9zL7AcIgajp+q1UjUF/NozL8cHwIDep Rc4Oso1dATJMt6+uvROZZtVlncVENj5vQ4SAbiCPNBM516cIM0a/O8mZpF+I9Jf2mY32 UbI0eFhRJ04Kz/8lqLQgK11KersrBfgvsStoOEXuWznhg7cdJOsgbeMs+wl7UKv/jZ4O xR5Wy9KdxZqJ4G2mzC6IGtYzirOGZmGQg5FCT0jKoA7DE3ESui+0kJvcZ6XRTioCMMgf e+ug== X-Gm-Message-State: ABuFfogGVURdBk+//O/t/v3CSQhrzxAv63GFTE3ww9VAaFwYnDpm3OYP kvTEFvn5vqoM4cnjUyqfHGk= X-Received: by 2002:a17:902:b58c:: with SMTP id a12-v6mr9905953pls.226.1539442507928; Sat, 13 Oct 2018 07:55:07 -0700 (PDT) Received: from localhost.corp.microsoft.com ([2404:f801:9000:18:d9bf:62c6:740b:9fc4]) by smtp.googlemail.com with ESMTPSA id v81-v6sm8688724pfj.25.2018.10.13.07.55.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 13 Oct 2018 07:55:07 -0700 (PDT) From: lantianyu1986@gmail.com X-Google-Original-From: Tianyu.Lan@microsoft.com Cc: Lan Tianyu , kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, pbonzini@redhat.com, rkrcmar@redhat.com, devel@linuxdriverproject.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, michael.h.kelley@microsoft.com, vkuznets@redhat.com Subject: [PATCH V4 7/15] KVM/MMU: Flush tlb directly in the kvm_zap_gfn_range() Date: Sat, 13 Oct 2018 22:53:58 +0800 Message-Id: <20181013145406.4911-8-Tianyu.Lan@microsoft.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20181013145406.4911-1-Tianyu.Lan@microsoft.com> References: <20181013145406.4911-1-Tianyu.Lan@microsoft.com> To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lan Tianyu Originally, flush tlb is done by slot_handle_level_range(). This patch is to flush tlb directly in the kvm_zap_gfn_range() when range flush is available. Signed-off-by: Lan Tianyu --- arch/x86/kvm/mmu.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index f3742ff4ec18..c4f7679f12c3 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -5647,6 +5647,7 @@ void kvm_zap_gfn_range(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_end) { struct kvm_memslots *slots; struct kvm_memory_slot *memslot; + bool flush = false; int i; spin_lock(&kvm->mmu_lock); @@ -5654,18 +5655,27 @@ void kvm_zap_gfn_range(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_end) slots = __kvm_memslots(kvm, i); kvm_for_each_memslot(memslot, slots) { gfn_t start, end; + bool flush_tlb = true; start = max(gfn_start, memslot->base_gfn); end = min(gfn_end, memslot->base_gfn + memslot->npages); if (start >= end) continue; - slot_handle_level_range(kvm, memslot, kvm_zap_rmapp, - PT_PAGE_TABLE_LEVEL, PT_MAX_HUGEPAGE_LEVEL, - start, end - 1, true); + if (kvm_available_flush_tlb_with_range()) + flush_tlb = false; + + flush = slot_handle_level_range(kvm, memslot, + kvm_zap_rmapp, PT_PAGE_TABLE_LEVEL, + PT_MAX_HUGEPAGE_LEVEL, start, + end - 1, flush_tlb); } } + if (flush && kvm_available_flush_tlb_with_range()) + kvm_flush_remote_tlbs_with_address(kvm, gfn_start, + gfn_end - gfn_start + 1); + spin_unlock(&kvm->mmu_lock); } -- 2.14.4