From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752691AbdK3PPA (ORCPT ); Thu, 30 Nov 2017 10:15:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43184 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751443AbdK3PO6 (ORCPT ); Thu, 30 Nov 2017 10:14:58 -0500 Date: Thu, 30 Nov 2017 16:14:53 +0100 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Wanpeng Li Cc: "linux-kernel@vger.kernel.org" , kvm , Paolo Bonzini , Wanpeng Li , Peter Zijlstra Subject: Re: [PATCH v6 2/4] KVM: X86: Add Paravirt TLB Shootdown Message-ID: <20171130151452.GA1606@flask> References: <1511841955-7375-1-git-send-email-wanpeng.li@hotmail.com> <1511841955-7375-3-git-send-email-wanpeng.li@hotmail.com> <20171129162118.GA10661@flask> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 30 Nov 2017 15:14:58 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2017-11-30 14:24+0800, Wanpeng Li: > 2017-11-30 0:21 GMT+08:00 Radim Krčmář : > > 2017-11-27 20:05-0800, Wanpeng Li: > >> From: Wanpeng Li > >> diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c > >> @@ -498,6 +498,37 @@ static void __init kvm_apf_trap_init(void) > >> update_intr_gate(X86_TRAP_PF, async_page_fault); > >> } > >> > >> +static DEFINE_PER_CPU(cpumask_t, __pv_tlb_mask); > >> + > >> +static void kvm_flush_tlb_others(const struct cpumask *cpumask, > >> + const struct flush_tlb_info *info) > >> +{ > >> + u8 state; > >> + int cpu; > >> + struct kvm_steal_time *src; > >> + cpumask_t *flushmask = &per_cpu(__pv_tlb_mask, smp_processor_id()); > >> + > >> + if (unlikely(!flushmask)) > >> + return; > > > > I don't see how this can be NULL and if it could, we'd have to call > > native_flush_tlb_others() instead of returning anyway. > > > > Also, Peter mentioned that we're wasting memory (default is 1k per CPU) > > when not running on KVM. Hyper-V hijacks x86_platform.apic_post_init() > > to achieve late allocation. smp_ops.smp_prepare_cpus seems slightly > > better for our purposes, but I don't really like either. > > > > Couldn't we use use arch_initcall(), or early_initcall() if there are > > complications with allocating after smp_init()? > > Do it in v7. In addition, move pv_mmu_ops.flush_tlb_others = > kvm_flush_tlb_others to the arch_initcall() fails to work even if I > disable rodata through grub. So I continue to keep the callback > replacement in kvm_guest_init() and late allocation in > arch_initcall(). I think it has to do with the patching -- you'd need to re-patch flush_tlb_others callsites for the change to take effect or add a hypervisor late init just before check_bugs(), where the patching is currently done. Not sure how either of those is acceptable, though.