Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1990511imm; Sat, 13 Oct 2018 07:56:01 -0700 (PDT) X-Google-Smtp-Source: ACcGV60SDEmG8JqhKG+jG/OPzdrChglFL9cb6jWdfxOujPMVBwdKx9kWTI8q77Qa1RjhqBpcqI4d X-Received: by 2002:a62:9015:: with SMTP id a21-v6mr10545245pfe.49.1539442561661; Sat, 13 Oct 2018 07:56:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539442561; cv=none; d=google.com; s=arc-20160816; b=SK0uhCOwTAdMbIJkWFQu5MyPw9TkzTt0BDdpifNQfnAwOEWkr+BdqY/Obh2KrHEA1L QVNHLFVPvmwjfXSBYLs6GjTcqeof0uNiS34/I7WfRkNYdlzLP2MfjRvZcPnxOVpYagGo i2Z4sN0aYuO17jJ9NbZSVpHdaqZug4nZ2SiKqGoo5cOQMQIesuvz/VTyURkO0mfUVqgY FcRaCzVvUwa9NbJD2u+VqJIB5FqN2b4RIBzaQqL4fL/ifPEFFUCKgR8g8HKujXNc2HPX xDhDnJJ7JX3W0lH2DH3VrRbDVkphQdD3K1fV4+V/DfDPsZzHFqT9kt3aYgDJadTbkJ+N sS+g== 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=0GvA2HR3eOqyHHGjxCwJx3woyzx38j35WwXnqi/n/80=; b=KFg2h5vHBsg3YiL3Xo7kfLdV/x/5Jg72rnHw92itA5sJW1q98NrOeB7xQo8yvaCyet sayCftg7t6dpkKznAtFTnbBZ9dszh31MDRcvV4YLDkPAZTE8ZS1aGC7BKnSL0SQXJl4d 50woox6J37KT0BP7cVcjM2HSVHFhtpyOWwZOa9b1YvEFVSU7sGTjnnV0/FyQ3/CLeGB8 /fmHBVFDm11DF9HIWc1zX+r1Zpdac/up67NFo7bag+c9Gc0yPk+Sc3nLhpcY1s6FfUFv MHub1M1EGDtWuST+h5UhWKVOghIom6q7MhOXE/sSum9bJfZNQ0B6Qe2d+qvl7LcIHwOE I9Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=g34Durb7; 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 s12-v6si4656042pfk.213.2018.10.13.07.55.46; Sat, 13 Oct 2018 07:56:01 -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=g34Durb7; 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 S1726926AbeJMWcZ (ORCPT + 99 others); Sat, 13 Oct 2018 18:32:25 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:36508 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726795AbeJMWcZ (ORCPT ); Sat, 13 Oct 2018 18:32:25 -0400 Received: by mail-pl1-f196.google.com with SMTP id y11-v6so7260592plt.3; Sat, 13 Oct 2018 07:54:59 -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=0GvA2HR3eOqyHHGjxCwJx3woyzx38j35WwXnqi/n/80=; b=g34Durb71MEKAdijJAPq+8eZ8GT5gpHLMksd1SXsEGfOjBaND3oWn03Ac5qvZeFhM5 YDAq8qsx/55N8q6LTLpp8t82wizssjsfjueQeQ00WLvpAShBp7LDwAO2Onn1hlzKDaJp EUpJ8WZi1RtyKTEJWtyvS+SG+sImsHNdVMVM+LdwttcLA/6cRWEqpgMRvG9ejyE7yXPO Na1ivB2A8NuYrsVcLDL1J3S8bBTz+uCTKGv+WJNuooAOhf1Bpr7IWWH6ENWHh3c0r6vw mKsYuelIHyxHTeXSC5BvEvfxecdYCCn3+pGFoI2hpdWOsQPu4R10Ibrg+2gjUHLVfHsS 2Tuw== 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=0GvA2HR3eOqyHHGjxCwJx3woyzx38j35WwXnqi/n/80=; b=jyfgWtNIWQoRivv21tq38fwUPriMcUpo9xCHz/HGYPKkFam1iexPHVl0BTAeYq6pUm ngztTD4lxvqyWxr6lhOPIyAsjs3mA5o/uyQ2b0Yz75I5wMLlGQ8HO/HRswmy7jewHE+2 ZqnHsClZj9VAiC4zdqJB2Ftt7zc2CeX8tz6/Io83psFD1RedocjUvKWVSOI/Zuiunm1b 4lgdnU7n0yhdxNiTVjR/W82gX4b73Z7w//C3CNZE/V8K/aJ9KXoSZzfo1LKzjy9z7duQ +WcRB7qfswtBLUxyuOhk4xBgFfWKk8cM9KY3pZBKvUXozy0uAvl6o4OEUqQAyGgrtYrZ RpdQ== X-Gm-Message-State: ABuFfojzbObd+3Aml/nZw07c9biWk3R4c/nLm5dB9W6O5QNSK8WTU8kj y4gkncejo4Lw+EgMGYGgCgc= X-Received: by 2002:a17:902:70c4:: with SMTP id l4-v6mr10045344plt.194.1539442498886; Sat, 13 Oct 2018 07:54:58 -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.54.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 13 Oct 2018 07:54:58 -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 5/15] KVM/MMU: Move tlb flush in kvm_set_pte_rmapp() to kvm_mmu_notifier_change_pte() Date: Sat, 13 Oct 2018 22:53:56 +0800 Message-Id: <20181013145406.4911-6-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 This patch is to move tlb flush in kvm_set_pte_rmapp() to kvm_mmu_notifier_change_pte() in order to avoid redundant tlb flush. Signed-off-by: Lan Tianyu --- arch/x86/kvm/mmu.c | 8 ++------ virt/kvm/kvm_main.c | 5 ++++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index fd24a4dc45e9..5d3a180c57e2 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -1781,10 +1781,7 @@ static int kvm_set_pte_rmapp(struct kvm *kvm, struct kvm_rmap_head *rmap_head, } } - if (need_flush) - kvm_flush_remote_tlbs(kvm); - - return 0; + return need_flush; } struct slot_rmap_walk_iterator { @@ -1920,8 +1917,7 @@ int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end) int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte) { - kvm_handle_hva(kvm, hva, (unsigned long)&pte, kvm_set_pte_rmapp); - return 0; + return kvm_handle_hva(kvm, hva, (unsigned long)&pte, kvm_set_pte_rmapp); } static int kvm_age_rmapp(struct kvm *kvm, struct kvm_rmap_head *rmap_head, diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index acc951cc2663..bd026d74541e 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -354,7 +354,10 @@ static void kvm_mmu_notifier_change_pte(struct mmu_notifier *mn, idx = srcu_read_lock(&kvm->srcu); spin_lock(&kvm->mmu_lock); kvm->mmu_notifier_seq++; - kvm_set_spte_hva(kvm, address, pte); + + if (kvm_set_spte_hva(kvm, address, pte)) + kvm_flush_remote_tlbs(kvm); + spin_unlock(&kvm->mmu_lock); srcu_read_unlock(&kvm->srcu, idx); } -- 2.14.4