From: "Chen, Tiejun" <tiejun.chen@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] kvm: x86: lapic: remove one redundant judging condition
Date: Thu, 06 Nov 2014 09:29:29 +0800 [thread overview]
Message-ID: <545ACEF9.3000607@intel.com> (raw)
In-Reply-To: <5459FA5B.8060207@redhat.com>
On 2014/11/5 18:22, Paolo Bonzini wrote:
> On 05/11/2014 10:03, Tiejun Chen wrote:
>> Finally we always return highest_irr so its unnecessary to return -1
>> after check if highest_irr == -1.
>>
>> Signed-off-by: Tiejun Chen <tiejun.chen@intel.com>
>> ---
>> arch/x86/kvm/lapic.c | 3 +--
>> 1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
>> index 5f574b4..e6a7eb6 100644
>> --- a/arch/x86/kvm/lapic.c
>> +++ b/arch/x86/kvm/lapic.c
>> @@ -1638,8 +1638,7 @@ int kvm_apic_has_interrupt(struct kvm_vcpu *vcpu)
>>
>> apic_update_ppr(apic);
>> highest_irr = apic_find_highest_irr(apic);
>> - if ((highest_irr == -1) ||
>> - ((highest_irr & 0xF0) <= kvm_apic_get_reg(apic, APIC_PROCPRI)))
>> + if ((highest_irr & 0xF0) <= kvm_apic_get_reg(apic, APIC_PROCPRI))
>> return -1;
>> return highest_irr;
>> }
>
> I think the code is clearer without this change.
>
> The two returns mean:
>
> - return -1: no interrupt to inject
>
> - return highest_irr: inject this interrupt
>
> With IRR equal to all zeroes (highest_irr = -1), your patch would make
> the "if" always false ("current PPR is low, can inject the interrupt"),
> but computing highest_irr & 0xF0 would make no sense if highest_irr ==
> -1.
Yeah, you're right so here is just a little confusion to read.
Actually what this code is doing looks like,
@@ -1638,7 +1638,7 @@ int kvm_apic_has_interrupt(struct kvm_vcpu *vcpu)
apic_update_ppr(apic);
highest_irr = apic_find_highest_irr(apic);
- if ((highest_irr == -1) ||
+ if ((highest_irr != -1) &&
((highest_irr & 0xF0) <= kvm_apic_get_reg(apic, APIC_PROCPRI)))
return -1;
return highest_irr;
But it's really no big deal so we can keep the original alive.
Thanks
Tiejun
>
> To put it another way, imagine the code looked like this:
>
> static inline int int_prio(int vector)
> {
> WARN_ON(vector == -1);
> return vector & 0xF0;
> }
> ...
>
> apic_update_ppr(apic);
> highest_irr = apic_find_highest_irr(apic);
> if (highest_irr == -1 ||
> int_prio(highest_irr) <= kvm_apic_get_reg(apic, APIC_PROCPRI))
> return -1;
> return highest_irr;
>
> Then removing the check on highest_irr == -1 would trigger a warning.
>
> Paolo
>
prev parent reply other threads:[~2014-11-06 1:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-05 9:03 [PATCH] kvm: x86: lapic: remove one redundant judging condition Tiejun Chen
2014-11-05 10:22 ` Paolo Bonzini
2014-11-06 1:29 ` Chen, Tiejun [this message]
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=545ACEF9.3000607@intel.com \
--to=tiejun.chen@intel.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
/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