public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: Avi Kivity <avi@redhat.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 3/3] Cleanup vmx_intr_assist()
Date: Sat, 11 Apr 2009 22:52:07 +0300	[thread overview]
Message-ID: <20090411195207.GA24630@redhat.com> (raw)
In-Reply-To: <49E07F56.30107@redhat.com>

On Sat, Apr 11, 2009 at 02:30:30PM +0300, Avi Kivity wrote:
> Gleb Natapov wrote:
>> Signed-off-by: Gleb Natapov <gleb@redhat.com>
>> ---
>>
>>  arch/x86/kvm/vmx.c |   55 ++++++++++++++++++++++++++++------------------------
>>  1 files changed, 30 insertions(+), 25 deletions(-)
>>
>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
>> index 06252f7..9eb518f 100644
>> --- a/arch/x86/kvm/vmx.c
>> +++ b/arch/x86/kvm/vmx.c
>> @@ -3309,6 +3309,34 @@ static void vmx_complete_interrupts(struct vcpu_vmx *vmx)
>>  	}
>>  }
>>  +static void vmx_intr_inject(struct kvm_vcpu *vcpu)
>> +{
>> +	/* try to reinject previous events if any */
>> +	if (vcpu->arch.nmi_injected) {
>> +		vmx_inject_nmi(vcpu);
>> +		return;
>> +	}
>> +
>> +	if (vcpu->arch.interrupt.pending) {
>> +		vmx_inject_irq(vcpu, vcpu->arch.interrupt.nr);
>> +		return;
>> +	}
>> +
>> +	/* try to inject new event if pending */
>> +	if (vcpu->arch.nmi_pending) {
>> +		if (vcpu->arch.nmi_window_open) {
>> +			vcpu->arch.nmi_pending = false;
>> +			vcpu->arch.nmi_injected = true;
>> +			vmx_inject_nmi(vcpu);
>> +		}
>> +	} else if (kvm_cpu_has_interrupt(vcpu)) {
>> +		if (vcpu->arch.interrupt_window_open) {
>> +			kvm_queue_interrupt(vcpu, kvm_cpu_get_interrupt(vcpu));
>> +			vmx_inject_irq(vcpu, vcpu->arch.interrupt.nr);
>> +		}
>> +	}
>> +}
>> +
>>  static void vmx_intr_assist(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
>>  {
>>  	bool req_int_win = !irqchip_in_kernel(vcpu->kvm) &&
>> @@ -3323,32 +3351,9 @@ static void vmx_intr_assist(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
>>  				GUEST_INTR_STATE_STI |
>>  				GUEST_INTR_STATE_MOV_SS);
>>  -	if (vcpu->arch.nmi_pending && !vcpu->arch.nmi_injected) {
>> -		if (vcpu->arch.interrupt.pending) {
>> -			enable_nmi_window(vcpu);
>> -		} else if (vcpu->arch.nmi_window_open) {
>> -			vcpu->arch.nmi_pending = false;
>> -			vcpu->arch.nmi_injected = true;
>> -		} else {
>> -			enable_nmi_window(vcpu);
>> -			return;
>> -		}
>> -	}
>> -
>> -	if (vcpu->arch.nmi_injected) {
>> -		vmx_inject_nmi(vcpu);
>> -		goto out;
>> -	}
>> -
>> -	if (!vcpu->arch.interrupt.pending && kvm_cpu_has_interrupt(vcpu)) {
>> -		if (vcpu->arch.interrupt_window_open)
>> -			kvm_queue_interrupt(vcpu, kvm_cpu_get_interrupt(vcpu));
>> -	}
>> -
>> -	if (vcpu->arch.interrupt.pending)
>> -		vmx_inject_irq(vcpu, vcpu->arch.interrupt.nr);
>> +	vmx_intr_inject(vcpu);
>>  -out:
>> +	/* enable NMI/IRQ window open exits if needed */
>>  	if (vcpu->arch.nmi_pending)
>>  		enable_nmi_window(vcpu);
>>  	else if (kvm_cpu_has_interrupt(vcpu) || req_int_win)
>>   
>
> Not sure I understand the motivation.  Just replace a 'goto out' with a  
> return?
>
Yes. The code is much cleaner this way. It is easy to see that no matter what happened
during injection irq/nmi windows is enabled if there are pending events. With gotos
and returns scattered over the function you'll need to check every single path that may
or may not lead to the window enable code.

--
			Gleb.

  reply	other threads:[~2009-04-11 19:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-07  9:08 [PATCH 1/3] Make kvm_cpu_(has|get)_interrupt() work for userspace irqchip too Gleb Natapov
2009-04-07  9:08 ` [PATCH 2/3] Consolidate userspace and kernel interrupt injection for VMX Gleb Natapov
2009-04-11 11:29   ` Avi Kivity
2009-04-11 19:53     ` Gleb Natapov
2009-04-07  9:08 ` [PATCH 3/3] Cleanup vmx_intr_assist() Gleb Natapov
2009-04-11 11:30   ` Avi Kivity
2009-04-11 19:52     ` Gleb Natapov [this message]
2009-04-07  9:56 ` [PATCH 1/3] Make kvm_cpu_(has|get)_interrupt() work for userspace irqchip too Sheng Yang
2009-04-07 10:07   ` Gleb Natapov
2009-04-11 11:24     ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090411195207.GA24630@redhat.com \
    --to=gleb@redhat.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox