From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Nikunj A. Dadhania" Subject: [PATCH v3 6/8] KVM-HV: Add flush_on_enter before guest enter Date: Tue, 31 Jul 2012 16:19:02 +0530 Message-ID: <20120731104859.16662.8738.stgit@abhimanyu.in.ibm.com> References: <20120731104312.16662.27889.stgit@abhimanyu.in.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: raghukt@linux.vnet.ibm.com, alex.shi@intel.com, mingo@elte.hu, kvm@vger.kernel.org, hpa@zytor.com To: peterz@infradead.org, mtosatti@redhat.com, avi@redhat.com Return-path: Received: from e23smtp01.au.ibm.com ([202.81.31.143]:59438 "EHLO e23smtp01.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755743Ab2GaKtr (ORCPT ); Tue, 31 Jul 2012 06:49:47 -0400 Received: from /spool/local by e23smtp01.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 31 Jul 2012 20:49:26 +1000 Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q6VAnhj419988564 for ; Tue, 31 Jul 2012 20:49:43 +1000 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q6VAnhnn001346 for ; Tue, 31 Jul 2012 20:49:43 +1000 In-Reply-To: <20120731104312.16662.27889.stgit@abhimanyu.in.ibm.com> Sender: kvm-owner@vger.kernel.org List-ID: From: Nikunj A. Dadhania PV-Flush guest would indicate to flush on enter, flush the TLB before entering and exiting the guest. Signed-off-by: Nikunj A. Dadhania --- arch/x86/kvm/x86.c | 23 +++++++---------------- 1 files changed, 7 insertions(+), 16 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 580abcf..a67e971 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1557,20 +1557,9 @@ static void record_steal_time(struct kvm_vcpu *vcpu) &vcpu->arch.st.steal, sizeof(struct kvm_steal_time)); } -static void kvm_set_atomic(u64 *addr, u64 old, u64 new) -{ - int loop = 1000000; - while (1) { - if (cmpxchg(addr, old, new) == old) - break; - loop--; - if (!loop) { - pr_info("atomic cur: %lx old: %lx new: %lx\n", - *addr, old, new); - break; - } - } -} +#define VS_NOT_IN_GUEST (0) +#define VS_IN_GUEST (1 << KVM_VCPU_STATE_IN_GUEST_MODE) +#define VS_SHOULD_FLUSH (1 << KVM_VCPU_STATE_SHOULD_FLUSH) static void kvm_set_vcpu_state(struct kvm_vcpu *vcpu) { @@ -1584,7 +1573,8 @@ static void kvm_set_vcpu_state(struct kvm_vcpu *vcpu) kaddr = kmap_atomic(vcpu->arch.v_state.vs_page); kaddr += vcpu->arch.v_state.vs_offset; vs = kaddr; - kvm_set_atomic(&vs->state, 0, 1 << KVM_VCPU_STATE_IN_GUEST_MODE); + if (xchg(&vs->state, VS_IN_GUEST) == VS_SHOULD_FLUSH) + kvm_x86_ops->tlb_flush(vcpu); kunmap_atomic(kaddr); } @@ -1600,7 +1590,8 @@ static void kvm_clear_vcpu_state(struct kvm_vcpu *vcpu) kaddr = kmap_atomic(vcpu->arch.v_state.vs_page); kaddr += vcpu->arch.v_state.vs_offset; vs = kaddr; - kvm_set_atomic(&vs->state, 1 << KVM_VCPU_STATE_IN_GUEST_MODE, 0); + if (xchg(&vs->state, VS_NOT_IN_GUEST) == VS_SHOULD_FLUSH) + kvm_x86_ops->tlb_flush(vcpu); kunmap_atomic(kaddr); }