Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp562570imm; Wed, 22 Aug 2018 08:48:29 -0700 (PDT) X-Google-Smtp-Source: AA+uWPz0eD/kLaVgil5zm+qveNc0osqD/X2ZqcBGWP9cyv6xaoUFbv4DIxGs82gDcoCzFuotlaMW X-Received: by 2002:a63:1506:: with SMTP id v6-v6mr9764889pgl.150.1534952909748; Wed, 22 Aug 2018 08:48:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534952909; cv=none; d=google.com; s=arc-20160816; b=yJ59c4In/4jjR5mfmYd3TbqjCj7SFzu1bqxKfkGXEeBXe5eRcBI8XMUj43GwykA0Xw aZrmBlVjBGiE4Vf36r1A/Da9ZSORM1MeMjGprQX+ou2yIBQ7i6GZv7lCGslBU6lRaDhi bfGmvidCaRzFZ4vzWTywMxFwqpQQfEBPcCHxU05qwIBnet6X8iecclTyOtdMZls2NtzR 0uq68tm5qReiP06uXFcwTf89GgMi1ALFV6VtIHjhazDqPqjvHvodnAvW/okQDR7NcQ4X gOqlRE5M8Yt2wkVeDUtrwSzaoYoTFp8SP+o/4LklQ0aMyGAw9wMOQ/kzlgbFP60lc64a vZVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:subject:cc:to :from:date:user-agent:message-id:dkim-signature :arc-authentication-results; bh=gBeaEcB0CRaE9iudyXRMqxnJyX6OHIKa2QWqyXhblwA=; b=tFArbR9t+Brp//Dst5XOb2+WwI1ooBdVdwgQlPoQ9ONwyd948OwxTRH2uCj7zfVPkw D7NQqLn5UVxqrJ4bGhEByXFDtztpdf8MOQiakyNvFv7CKhH0SZOJMRPgJ00Qw3cZwW30 4Xnh8jI3eBsQlQNgNJJfIxxfQ+MhK3UpTel35wKiNtjUL9WO+S2ANahymIB/cITPWonX GyslT/Rf+AAVqf4SZrsAmpX1fd7BOP52Gs6VebkI73QA1cHvX2GQkLV/i5QQ2zk9O+f1 xcenvWTFn38MoMht+UKnKTJkvnneY97rZL1WXaCPTqjnFGbxZronDLyQLNVSUrrh+Skx zhdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=p8G9EifM; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q66-v6si2121386pfk.268.2018.08.22.08.48.14; Wed, 22 Aug 2018 08:48:29 -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=@infradead.org header.s=merlin.20170209 header.b=p8G9EifM; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729415AbeHVTLf (ORCPT + 99 others); Wed, 22 Aug 2018 15:11:35 -0400 Received: from merlin.infradead.org ([205.233.59.134]:51392 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728568AbeHVTLe (ORCPT ); Wed, 22 Aug 2018 15:11:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=gBeaEcB0CRaE9iudyXRMqxnJyX6OHIKa2QWqyXhblwA=; b=p8G9EifMms1fnFzIqWxv4jM6D0 0B4AEcLzmWE82yYl6NkQstHOzRaDl6nz148SfhDGz2POBDPUnTAsFeykKD15z9nlHnl3UPh4STzDz /IvBYWeIjwOLR2oH53h0kGxmGAFj5Xa6jRNvfNOaqqrhI0br6H3XbCckmWOd7dxwjWxwuDcmmhWEX xSDrnlqpqemTVvJNSZGc21VZjQXWL55S+9DTWiL53eJUr/FgkOZEWzcgTw0PiO35IB+YVmYf7RbFL bv68dVEqmevxLaN2YagmWBfXpkVAK6PL+iC9Ja20Ms1U52qXQvkSpjJt7XmBbzcr4KeSi3zBf2xks zJsIiR3A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fsVKN-0000WU-K1; Wed, 22 Aug 2018 15:45:47 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id C627D2024D726; Wed, 22 Aug 2018 17:45:44 +0200 (CEST) Message-ID: <20180822154046.877071284@infradead.org> User-Agent: quilt/0.65 Date: Wed, 22 Aug 2018 17:30:16 +0200 From: Peter Zijlstra To: torvalds@linux-foundation.org Cc: peterz@infradead.org, luto@kernel.org, x86@kernel.org, bp@alien8.de, will.deacon@arm.com, riel@surriel.com, jannh@google.com, ascannell@google.com, dave.hansen@intel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 4/4] x86/mm: Only use tlb_remove_table() for paravirt References: <20180822153012.173508681@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If we don't use paravirt; don't play unnecessary and complicated games to free page-tables. Suggested-by: Linus Torvalds Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/Kconfig | 2 +- arch/x86/hyperv/mmu.c | 2 ++ arch/x86/include/asm/paravirt.h | 5 +++++ arch/x86/include/asm/paravirt_types.h | 3 +++ arch/x86/include/asm/tlbflush.h | 3 +++ arch/x86/kernel/kvm.c | 5 ++++- arch/x86/kernel/paravirt.c | 2 ++ arch/x86/mm/pgtable.c | 8 ++++---- arch/x86/xen/mmu_pv.c | 1 + 9 files changed, 25 insertions(+), 6 deletions(-) --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -179,7 +179,7 @@ config X86 select HAVE_HARDLOCKUP_DETECTOR_PERF if PERF_EVENTS && HAVE_PERF_EVENTS_NMI select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP - select HAVE_RCU_TABLE_FREE + select HAVE_RCU_TABLE_FREE if PARAVIRT select HAVE_RCU_TABLE_INVALIDATE if HAVE_RCU_TABLE_FREE select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RELIABLE_STACKTRACE if X86_64 && (UNWINDER_FRAME_POINTER || UNWINDER_ORC) && STACK_VALIDATION --- a/arch/x86/hyperv/mmu.c +++ b/arch/x86/hyperv/mmu.c @@ -9,6 +9,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include @@ -231,4 +232,5 @@ void hyperv_setup_mmu_ops(void) pr_info("Using hypercall for remote TLB flush\n"); pv_mmu_ops.flush_tlb_others = hyperv_flush_tlb_others; + pv_mmu_ops.tlb_remove_table = tlb_remove_table; } --- a/arch/x86/include/asm/paravirt.h +++ b/arch/x86/include/asm/paravirt.h @@ -309,6 +309,11 @@ static inline void flush_tlb_others(cons PVOP_VCALL2(pv_mmu_ops.flush_tlb_others, cpumask, info); } +static inline void paravirt_tlb_remove_table(struct mmu_gather *tlb, void *table) +{ + PVOP_VCALL2(pv_mmu_ops.tlb_remove_table, tlb, table); +} + static inline int paravirt_pgd_alloc(struct mm_struct *mm) { return PVOP_CALL1(int, pv_mmu_ops.pgd_alloc, mm); --- a/arch/x86/include/asm/paravirt_types.h +++ b/arch/x86/include/asm/paravirt_types.h @@ -54,6 +54,7 @@ struct desc_struct; struct task_struct; struct cpumask; struct flush_tlb_info; +struct mmu_gather; /* * Wrapper type for pointers to code which uses the non-standard @@ -222,6 +223,8 @@ struct pv_mmu_ops { void (*flush_tlb_others)(const struct cpumask *cpus, const struct flush_tlb_info *info); + void (*tlb_remove_table)(struct mmu_gather *tlb, void *table); + /* Hooks for allocating and freeing a pagetable top-level */ int (*pgd_alloc)(struct mm_struct *mm); void (*pgd_free)(struct mm_struct *mm, pgd_t *pgd); --- a/arch/x86/include/asm/tlbflush.h +++ b/arch/x86/include/asm/tlbflush.h @@ -552,6 +552,9 @@ extern void arch_tlbbatch_flush(struct a #ifndef CONFIG_PARAVIRT #define flush_tlb_others(mask, info) \ native_flush_tlb_others(mask, info) + +#define paravirt_tlb_remove_table(tlb, page) \ + tlb_remove_page(tlb, (void *)(page)) #endif #endif /* _ASM_X86_TLBFLUSH_H */ --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -45,6 +45,7 @@ #include #include #include +#include static int kvmapf = 1; @@ -636,8 +637,10 @@ static void __init kvm_guest_init(void) if (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) && !kvm_para_has_hint(KVM_HINTS_REALTIME) && - kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) + kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) { pv_mmu_ops.flush_tlb_others = kvm_flush_tlb_others; + pv_mmu_ops.tlb_remove_table = tlb_remove_table; + } if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) apic_set_eoi_write(kvm_guest_apic_eoi_write); --- a/arch/x86/kernel/paravirt.c +++ b/arch/x86/kernel/paravirt.c @@ -41,6 +41,7 @@ #include #include #include +#include /* * nop stub, which must not clobber anything *including the stack* to @@ -409,6 +410,7 @@ struct pv_mmu_ops pv_mmu_ops __ro_after_ .flush_tlb_kernel = native_flush_tlb_global, .flush_tlb_one_user = native_flush_tlb_one_user, .flush_tlb_others = native_flush_tlb_others, + .tlb_remove_table = (void (*)(struct mmu_gather *, void *))tlb_remove_page, .pgd_alloc = __paravirt_pgd_alloc, .pgd_free = paravirt_nop, --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -63,7 +63,7 @@ void ___pte_free_tlb(struct mmu_gather * { pgtable_page_dtor(pte); paravirt_release_pte(page_to_pfn(pte)); - tlb_remove_table(tlb, pte); + paravirt_tlb_remove_table(tlb, pte); } #if CONFIG_PGTABLE_LEVELS > 2 @@ -79,21 +79,21 @@ void ___pmd_free_tlb(struct mmu_gather * tlb->need_flush_all = 1; #endif pgtable_pmd_page_dtor(page); - tlb_remove_table(tlb, page); + paravirt_tlb_remove_table(tlb, page); } #if CONFIG_PGTABLE_LEVELS > 3 void ___pud_free_tlb(struct mmu_gather *tlb, pud_t *pud) { paravirt_release_pud(__pa(pud) >> PAGE_SHIFT); - tlb_remove_table(tlb, virt_to_page(pud)); + paravirt_tlb_remove_table(tlb, virt_to_page(pud)); } #if CONFIG_PGTABLE_LEVELS > 4 void ___p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4d) { paravirt_release_p4d(__pa(p4d) >> PAGE_SHIFT); - tlb_remove_table(tlb, virt_to_page(p4d)); + paravirt_tlb_remove_table(tlb, virt_to_page(p4d)); } #endif /* CONFIG_PGTABLE_LEVELS > 4 */ #endif /* CONFIG_PGTABLE_LEVELS > 3 */ --- a/arch/x86/xen/mmu_pv.c +++ b/arch/x86/xen/mmu_pv.c @@ -2397,6 +2397,7 @@ static const struct pv_mmu_ops xen_mmu_o .flush_tlb_kernel = xen_flush_tlb, .flush_tlb_one_user = xen_flush_tlb_one_user, .flush_tlb_others = xen_flush_tlb_others, + .tlb_remove_table = tlb_remove_table, .pgd_alloc = xen_pgd_alloc, .pgd_free = xen_pgd_free,