From patchwork Thu Nov 8 14:46:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 10674499 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 AFC8413BF for ; Thu, 8 Nov 2018 14:48:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97A5E2DD3D for ; Thu, 8 Nov 2018 14:48:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 869A72DD89; Thu, 8 Nov 2018 14:48:21 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 180FE2DD3D for ; Thu, 8 Nov 2018 14:48:20 +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=Go961FimEQY6RmSzj/+PSK7TpX+74Pzcu3V/NcuQADw=; b=j7tQhyDZLPGxFZmisMARIqlbBS LWy3wp9PRpodEo6nPbATodvkJ91K/7/uZsPAFIktWupzAVlfrK5d2L5u5I/AsxeJa88vwOegS1qR4 vfnPe3fjXKNRJxhZSD2WtCebHc860Ra6Q6ZGRvKqMuX7Goj7K6sIxmbQ+zSm/MyXnrp3nWPYBXdV6 jfN/nBZZYnOy5H7nMf5wRUxVOsf0LBxh5hJwSLsvt+xBqxmmHYPVu+54SNSmLLd4Cl9ZIGHEi085D O/cUrg5qQ4PuvpWgZOIUMuBzPSF3vaPxCwACA6nRZwehEC27esvLSVn9jE7Qs6DpMNcU71sxe78tS yIhjNrow==; 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 1gKlbN-0006Vj-So; Thu, 08 Nov 2018 14:48:09 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gKlaf-0005le-Bz for linux-arm-kernel@lists.infradead.org; Thu, 08 Nov 2018 14:47:28 +0000 Received: by mail-pf1-x443.google.com with SMTP id j13-v6so9385946pff.11 for ; Thu, 08 Nov 2018 06:47:23 -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=j64bsuj3x4K+30VilhvqfE2jLibklRus8fQn4GALxqw=; b=kSRs6yszY4IfNoC8OPqCy4ksjyyfO8vPsN92AYgcgXtqlwYrp7W9CsBb2pFWYCOWYT hzLAcMLmlTe+72KX5oE2NnIPaiws0ZyzwJ1rivC0GnmGbAZX9qFQcKu7IRKTTa5fcNt7 AntjL+6k2KUftFi1oRrs1ffyS4sDX3FeUL6voPxTS87oBXQHQsw9+BohJqmSGOD0u38j wxTVXVp6bSM0RFLXlLNxSCfv+y2byQousc+mACuHCor4/2CnpmJGhCYH2YpOgjKjrhJ5 W3G1FjZFxRVZeNqXFC1H1e5VsjKK0ew0oJJ2igzrk6MVip4mlHEpR0D+IwRk8W/isF9o qR0A== 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=j64bsuj3x4K+30VilhvqfE2jLibklRus8fQn4GALxqw=; b=otNL35wHWCBxFjTidkDjfuXj7QpoXel/Y9rslCHXSAm1toY4AKyUG6dk0URpTozmm+ /oM+WWClXikFbBJ/U7ELuxw5cWrBPKfD9FHvbuzGNblyEJkg0110Xg2nLYD/D7BpClm0 6bsmX93zmaTOoBX2vfqF6z7QsS9NxJfW3HFHNhwGf3BwAFWeBbnjnfIKkxSj3dH1gTnr btWUi8p2gkpqby/pOwGkyN3noLoAXDfFolhrTGhY0s2Yj0R4JSlJFvKSQd1o8OH5ox7O NYmmBaJWV0Izw3D/Y+dRhfK3MWykVdNyxYvu/1eOow6zIov3VKrc/4aLfg6r4SjF+uuN NIWw== X-Gm-Message-State: AGRZ1gIzG4H8YuYIb+pTwTKTMOtRBj/kQXssz5CJsRhy+ZxAUS54PHJn vobs1jJBjKKCZ+/m1t6K8XU= X-Google-Smtp-Source: AJdET5f41UCbLn034dxs1ngicJBuoodp6p58X0q0RKH54NooSvsVOJCzcR34aj+o0PpgSKVU2xXoug== X-Received: by 2002:a63:1766:: with SMTP id 38mr2232968pgx.299.1541688442907; Thu, 08 Nov 2018 06:47:22 -0800 (PST) Received: from localhost.corp.microsoft.com ([2404:f801:9000:18:d9bf:62c6:740b:9fc4]) by smtp.googlemail.com with ESMTPSA id k75-v6sm11526731pfb.119.2018.11.08.06.47.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 08 Nov 2018 06:47:22 -0800 (PST) From: lantianyu1986@gmail.com X-Google-Original-From: Tianyu.Lan@microsoft.com To: Subject: [Resend PATCH V5 5/10] KVM/MMU: Add tlb flush with range helper function Date: Thu, 8 Nov 2018 22:46:34 +0800 Message-Id: <20181108144639.11206-5-Tianyu.Lan@microsoft.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20181108144639.11206-1-Tianyu.Lan@microsoft.com> References: <20181108144639.11206-1-Tianyu.Lan@microsoft.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181108_064725_414780_8F31A323 X-CRM114-Status: GOOD ( 13.74 ) 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: linux-mips@linux-mips.org, 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, 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 add wrapper functions for tlb_remote_flush_with_range callback and flush tlb directly in kvm_mmu_zap_collapsible_spte(). kvm_mmu_zap_collapsible_spte() returns flush request to the slot_handle_leaf() and the latter does flush on demand. When range flush is available, make kvm_mmu_zap_collapsible_spte() to flush tlb with range directly to avoid returning range back to slot_handle_leaf(). Signed-off-by: Lan Tianyu --- Change since V4: Remove flush list interface and flush tlb directly in kvm_mmu_zap_collapsible_spte(). Change since V3: Remove code of updating "tlbs_dirty" Change since V2: Fix comment in the kvm_flush_remote_tlbs_with_range() --- arch/x86/kvm/mmu.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index cf5f572f2305..c1d383532066 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -264,6 +264,35 @@ 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) +{ + int ret = -ENOTSUPP; + + if (range && kvm_x86_ops->tlb_remote_flush_with_range) + ret = kvm_x86_ops->tlb_remote_flush_with_range(kvm, range); + + if (ret) + kvm_flush_remote_tlbs(kvm); +} + +static void kvm_flush_remote_tlbs_with_address(struct kvm *kvm, + u64 start_gfn, u64 pages) +{ + struct kvm_tlb_range range; + + range.start_gfn = start_gfn; + range.pages = pages; + + kvm_flush_remote_tlbs_with_range(kvm, &range); +} + void kvm_mmu_set_mmio_spte_mask(u64 mmio_mask, u64 mmio_value) { BUG_ON((mmio_mask & mmio_value) != mmio_value); @@ -5680,7 +5709,13 @@ static bool kvm_mmu_zap_collapsible_spte(struct kvm *kvm, !kvm_is_reserved_pfn(pfn) && PageTransCompoundMap(pfn_to_page(pfn))) { pte_list_remove(rmap_head, sptep); - need_tlb_flush = 1; + + if (kvm_available_flush_tlb_with_range()) + kvm_flush_remote_tlbs_with_address(kvm, sp->gfn, + KVM_PAGES_PER_HPAGE(sp->role.level)); + else + need_tlb_flush = 1; + goto restart; } }