From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH v2 2/3] KVM: send IPI to vcpu only when it's in guest mode Date: Sun, 09 Jan 2011 12:00:10 +0200 Message-ID: <4D29872A.608@redhat.com> References: <4D26C4D4.30303@cn.fujitsu.com> <4D26C527.9090403@cn.fujitsu.com> <20110107115527.GA13196@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Xiao Guangrong , LKML , KVM To: Marcelo Tosatti Return-path: Received: from mx1.redhat.com ([209.132.183.28]:32885 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750869Ab1AIKAX (ORCPT ); Sun, 9 Jan 2011 05:00:23 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p09A0ErB015745 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 9 Jan 2011 05:00:16 -0500 In-Reply-To: <20110107115527.GA13196@amt.cnet> Sender: kvm-owner@vger.kernel.org List-ID: On 01/07/2011 01:55 PM, Marcelo Tosatti wrote: > 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. > Good catch. We could remove the atomic_xchg() in kvm_vcpu_kick(), but need to think of any drawbacks to that. Maybe we could replace guest_mode with a three value variable: in guest, outside guest, and transitioning out of guest. So kvm_vcpu_kick() avoids the IPI on the last two, while make_all_cpus_request() only avoids an IPI if outside guest mode. -- error compiling committee.c: too many arguments to function