From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753407AbdKJQtY (ORCPT ); Fri, 10 Nov 2017 11:49:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58694 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752831AbdKJQtX (ORCPT ); Fri, 10 Nov 2017 11:49:23 -0500 Subject: Re: [PATCH v3 4/4] KVM: Add flush_on_enter before guest enter To: Peter Zijlstra Cc: Wanpeng Li , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Radim Kr??m???? , Wanpeng Li References: <1510307387-14812-1-git-send-email-wanpeng.li@hotmail.com> <1510307387-14812-5-git-send-email-wanpeng.li@hotmail.com> <20171110100838.eqfccs735x4ghw6q@hirez.programming.kicks-ass.net> <58cda8a6-3bab-c34f-785b-dfff84eee69f@redhat.com> <20171110103104.h2ygyynvljvquiv6@hirez.programming.kicks-ass.net> From: Paolo Bonzini Message-ID: Date: Fri, 10 Nov 2017 17:49:18 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171110103104.h2ygyynvljvquiv6@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 10 Nov 2017 16:49:23 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/11/2017 11:31, Peter Zijlstra wrote: > On Fri, Nov 10, 2017 at 11:15:06AM +0100, Paolo Bonzini wrote: >> On 10/11/2017 11:08, Peter Zijlstra wrote: >>> On Fri, Nov 10, 2017 at 01:49:47AM -0800, Wanpeng Li wrote: >>>> @@ -2887,7 +2899,7 @@ static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu) >>>> if (!(vcpu->arch.st.msr_val & KVM_MSR_ENABLED)) >>>> return; >>>> >>>> - vcpu->arch.st.steal.preempted = KVM_VCPU_PREEMPTED; >>>> + vcpu->arch.st.steal.preempted |= KVM_VCPU_PREEMPTED; >>> >>> I don't understand this one... If there is concurrency its wrong, if >>> there is no concurrency it still doesn't make sense as there should not >>> be any FLUSH flags to preserve.. >> >> There is no concurrency, foreign VCPUs are not going to write to the >> location unless PREEMPTED is set. So indeed the "|=" is pointless. >> >> However, I wonder if it'd be useful for a VCPU to set the bit _on >> itself_ before going to sleep. Like >> >> set KVM_VCPU_SHOULD_FLUSH >> hlt >> /* Automagic TLB flush! */ >> >> This would not work currently, but if it *is* useful, we should make it >> work and document it as legal. Peter, do you think it would make any sense? > > Almost but not quite I think.. So there is no guarantee HLT (or even > MWAIT with a state that has CPUILDE_FLAG_TLB_FLUSHED set) will actually > do the TLB flush. Well, for virt you could always guarantee it if it's useful. But from the rest of your message it looks like it would be a separate PV feature than this one. Thanks, Paolo > And if we preempt the vCPU to run a kernel thread we will not in fact > invalidate the TLBs either. > > Also, you're confusing the SHOULD_FLUSH with the HAS_FLUSHED concept. > Because if we didn't flush and we should have we should still issue it > on VMENTER. > > So if we could somehow tell if a HLT or preemption did indeed flush the > TLBs post fact (reading back the attained C state is possible but really > rather expensive IIRC), then we could set a HAS_FLUSHED flag and avoid > issuing when SHOULD_FLUSH is also set. > >