From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754110AbdKNQpq (ORCPT ); Tue, 14 Nov 2017 11:45:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36432 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753515AbdKNQpd (ORCPT ); Tue, 14 Nov 2017 11:45:33 -0500 Subject: Re: [PATCH v4 1/4] KVM: X86: Add vCPU running/preempted state To: Wanpeng Li , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Peter Zijlstra , Wanpeng Li References: <1510533206-9821-1-git-send-email-wanpeng.li@hotmail.com> <1510533206-9821-2-git-send-email-wanpeng.li@hotmail.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: Date: Tue, 14 Nov 2017 17:45:30 +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: <1510533206-9821-2-git-send-email-wanpeng.li@hotmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 14 Nov 2017 16:45:32 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13.11.2017 01:33, Wanpeng Li wrote: > From: Wanpeng Li > > This patch reuses the preempted field in kvm_steal_time, and will export > the vcpu running/pre-empted information to the guest from host. This will > enable guest to intelligently send ipi to running vcpus and set flag for > pre-empted vcpus. This will prevent waiting for vcpus that are not running. > > Cc: Paolo Bonzini > Cc: Radim Krčmář > Cc: Peter Zijlstra > Signed-off-by: Wanpeng Li > --- > arch/x86/include/uapi/asm/kvm_para.h | 3 +++ > arch/x86/kernel/kvm.c | 2 +- > arch/x86/kvm/x86.c | 4 ++-- > 3 files changed, 6 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/include/uapi/asm/kvm_para.h b/arch/x86/include/uapi/asm/kvm_para.h > index 554aa8f..bf17b30 100644 > --- a/arch/x86/include/uapi/asm/kvm_para.h > +++ b/arch/x86/include/uapi/asm/kvm_para.h > @@ -51,6 +51,9 @@ struct kvm_steal_time { > __u32 pad[11]; > }; > > +#define KVM_VCPU_NOT_PREEMPTED (0 << 0) > +#define KVM_VCPU_PREEMPTED (1 << 0) These should have a prefix that makes it obvious that they are used for kvm_steal_time/preempted. What about renaming preempted to "flags" or something like that. Then we could have KVM_STEAL_TIME_(FLAG_)PREEMPTED KVM_STEAL_TIME_(FLAG_)NOT_PREEMPTED > + > #define KVM_CLOCK_PAIRING_WALLCLOCK 0 > struct kvm_clock_pairing { > __s64 sec; > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c > index 8bb9594..1b1b641 100644 > --- a/arch/x86/kernel/kvm.c > +++ b/arch/x86/kernel/kvm.c > @@ -608,7 +608,7 @@ __visible bool __kvm_vcpu_is_preempted(long cpu) > { > struct kvm_steal_time *src = &per_cpu(steal_time, cpu); > > - return !!src->preempted; > + return !!(src->preempted & KVM_VCPU_PREEMPTED); > } > PV_CALLEE_SAVE_REGS_THUNK(__kvm_vcpu_is_preempted); > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 03869eb..5e63033 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -2113,7 +2113,7 @@ static void record_steal_time(struct kvm_vcpu *vcpu) > &vcpu->arch.st.steal, sizeof(struct kvm_steal_time)))) > return; > > - vcpu->arch.st.steal.preempted = 0; > + vcpu->arch.st.steal.preempted = KVM_VCPU_NOT_PREEMPTED; > > if (vcpu->arch.st.steal.version & 1) > vcpu->arch.st.steal.version += 1; /* first time write, random junk */ > @@ -2884,7 +2884,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 = 1; > + vcpu->arch.st.steal.preempted = KVM_VCPU_PREEMPTED; > > kvm_write_guest_offset_cached(vcpu->kvm, &vcpu->arch.st.stime, > &vcpu->arch.st.steal.preempted, > -- Thanks, David / dhildenb