From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752083AbdKMIEJ (ORCPT ); Mon, 13 Nov 2017 03:04:09 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:60413 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751705AbdKMIEH (ORCPT ); Mon, 13 Nov 2017 03:04:07 -0500 Date: Mon, 13 Nov 2017 09:04:03 +0100 From: Peter Zijlstra To: Wanpeng Li Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Radim Kr??m???? , Wanpeng Li Subject: Re: [PATCH v4 2/4] KVM: X86: Add paravirt remote TLB flush Message-ID: <20171113080403.ici7nt5r4b5fpxa6@hirez.programming.kicks-ass.net> References: <1510533206-9821-1-git-send-email-wanpeng.li@hotmail.com> <1510533206-9821-3-git-send-email-wanpeng.li@hotmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1510533206-9821-3-git-send-email-wanpeng.li@hotmail.com> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Nov 12, 2017 at 04:33:24PM -0800, Wanpeng Li wrote: > +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; > + struct cpumask *flushmask = this_cpu_cpumask_var_ptr(__pv_tlb_mask); > + > + if (unlikely(!flushmask)) > + return; > + > + cpumask_copy(flushmask, cpumask); > + /* > + * We have to call flush only on online vCPUs. And > + * queue flush_on_enter for pre-empted vCPUs > + */ > + for_each_cpu(cpu, cpumask) { > + src = &per_cpu(steal_time, cpu); > + state = READ_ONCE(src->preempted); > + if ((state & KVM_VCPU_PREEMPTED)) { > + if (try_cmpxchg(&src->preempted, &state, > + state | KVM_VCPU_SHOULD_FLUSH)) > + __cpumask_clear_cpu(cpu, flushmask); > + } > + } So if at this point a vCPU gets preempted we'll still spin-wait for it, which is sub-optimal. I think we can come up with something to get around that 'problem' if indeed it is a problem. But we can easily do that as follow up patches. Just let me know if you think its worth spending more time on. > + native_flush_tlb_others(flushmask, info); > +}