KVM: Get rid of KVM_REQ_KICK
KVM_REQ_KICK poisons vcpu->requests by having a bit set during normal operation. This causes the fast path check for a clear vcpu->requests to fail all the time, triggering tons of atomic operations. Fix by replacing KVM_REQ_KICK with a vcpu->guest_mode atomic. Signed-off-by: Avi Kivity <avi@redhat.com>
This commit is contained in:
		
					parent
					
						
							
								54b8486f46
							
						
					
				
			
			
				commit
				
					
						d94e1dc9af
					
				
			
		
					 2 changed files with 11 additions and 7 deletions
				
			
		| 
						 | 
					@ -4604,13 +4604,15 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
 | 
				
			||||||
	if (vcpu->fpu_active)
 | 
						if (vcpu->fpu_active)
 | 
				
			||||||
		kvm_load_guest_fpu(vcpu);
 | 
							kvm_load_guest_fpu(vcpu);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						atomic_set(&vcpu->guest_mode, 1);
 | 
				
			||||||
 | 
						smp_wmb();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	local_irq_disable();
 | 
						local_irq_disable();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	clear_bit(KVM_REQ_KICK, &vcpu->requests);
 | 
						if (!atomic_read(&vcpu->guest_mode) || vcpu->requests
 | 
				
			||||||
	smp_mb__after_clear_bit();
 | 
						    || need_resched() || signal_pending(current)) {
 | 
				
			||||||
 | 
							atomic_set(&vcpu->guest_mode, 0);
 | 
				
			||||||
	if (vcpu->requests || need_resched() || signal_pending(current)) {
 | 
							smp_wmb();
 | 
				
			||||||
		set_bit(KVM_REQ_KICK, &vcpu->requests);
 | 
					 | 
				
			||||||
		local_irq_enable();
 | 
							local_irq_enable();
 | 
				
			||||||
		preempt_enable();
 | 
							preempt_enable();
 | 
				
			||||||
		r = 1;
 | 
							r = 1;
 | 
				
			||||||
| 
						 | 
					@ -4655,7 +4657,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
 | 
				
			||||||
	if (hw_breakpoint_active())
 | 
						if (hw_breakpoint_active())
 | 
				
			||||||
		hw_breakpoint_restore();
 | 
							hw_breakpoint_restore();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	set_bit(KVM_REQ_KICK, &vcpu->requests);
 | 
						atomic_set(&vcpu->guest_mode, 0);
 | 
				
			||||||
 | 
						smp_wmb();
 | 
				
			||||||
	local_irq_enable();
 | 
						local_irq_enable();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	++vcpu->stat.exits;
 | 
						++vcpu->stat.exits;
 | 
				
			||||||
| 
						 | 
					@ -5580,7 +5583,7 @@ void kvm_vcpu_kick(struct kvm_vcpu *vcpu)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	me = get_cpu();
 | 
						me = get_cpu();
 | 
				
			||||||
	if (cpu != me && (unsigned)cpu < nr_cpu_ids && cpu_online(cpu))
 | 
						if (cpu != me && (unsigned)cpu < nr_cpu_ids && cpu_online(cpu))
 | 
				
			||||||
		if (!test_and_set_bit(KVM_REQ_KICK, &vcpu->requests))
 | 
							if (atomic_xchg(&vcpu->guest_mode, 0))
 | 
				
			||||||
			smp_send_reschedule(cpu);
 | 
								smp_send_reschedule(cpu);
 | 
				
			||||||
	put_cpu();
 | 
						put_cpu();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -81,6 +81,7 @@ struct kvm_vcpu {
 | 
				
			||||||
	int vcpu_id;
 | 
						int vcpu_id;
 | 
				
			||||||
	struct mutex mutex;
 | 
						struct mutex mutex;
 | 
				
			||||||
	int   cpu;
 | 
						int   cpu;
 | 
				
			||||||
 | 
						atomic_t guest_mode;
 | 
				
			||||||
	struct kvm_run *run;
 | 
						struct kvm_run *run;
 | 
				
			||||||
	unsigned long requests;
 | 
						unsigned long requests;
 | 
				
			||||||
	unsigned long guest_debug;
 | 
						unsigned long guest_debug;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue