From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: Re: [PATCH v2 2/3] KVM: send IPI to vcpu only when it's in guest mode Date: Fri, 7 Jan 2011 09:55:27 -0200 Message-ID: <20110107115527.GA13196@amt.cnet> References: <4D26C4D4.30303@cn.fujitsu.com> <4D26C527.9090403@cn.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Avi Kivity , LKML , KVM To: Xiao Guangrong Return-path: Content-Disposition: inline In-Reply-To: <4D26C527.9090403@cn.fujitsu.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On Fri, Jan 07, 2011 at 03:47:51PM +0800, Xiao Guangrong wrote: > We can interrupt the vcpu only when it's running in guest mode > to reduce IPI > > It looks like only ia64 and x86 need to send IPI to other vcpus, so > i only add the implementation of 'vcpu->guest_mode' in ia64, but i > don't know ia64 well, please point out the right way for me if the > implementation is incorrect > > Also reorganize struct kvm_vcpu to make ->guest_mode and ->requests > in the same cache line explicitly. > > Signed-off-by: Xiao Guangrong > --- > arch/ia64/kvm/kvm-ia64.c | 2 ++ > arch/x86/kvm/x86.c | 6 +++++- > include/linux/kvm_host.h | 9 +++++---- > virt/kvm/kvm_main.c | 7 ++++++- > 4 files changed, 18 insertions(+), 6 deletions(-) > > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index b1b6cbb..a475264 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -153,7 +153,12 @@ static bool make_all_cpus_request(struct kvm *kvm, unsigned int req) > if (kvm_make_check_request(req, vcpu)) > continue; > cpu = vcpu->cpu; > - if (cpus != NULL && cpu != -1 && cpu != me) > + > + /* Set ->requests bit before we read ->guest_mode */ > + smp_mb(); > + > + if (cpus != NULL && cpu != -1 && cpu != me && > + atomic_read(&vcpu->guest_mode)) > cpumask_set_cpu(cpu, cpus); Don't think this is safe, since guest_mode does not imply that a vcpu has received the IPI, only that IPI has been sent (see kvm_vcpu_kick). And make_all_cpus_request must guarantee all target vcpus are out of guest mode before it returns.