kvm: x86: lapic: remove one redundant judging condition
PATCH 1/1 kvm: x86: lapic: remove one redundant judging condition
Finally we always return highest_irr so its unnecessary to return -1 after check if highest_irr == -1.
--- arch/x86/kvm/lapic.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kvm/lapic.c +1 -2
@@ -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; }
Signature · 1 line
1.9.1
Paolo Bonzini
maintainerQuoted 13 lines · Tiejun Chen
Finally we always return
highest_irrso its unnecessary to return -1 after check ifhighest_irr== -1.Signed-off-by Tiejun Chen <[email protected]>--- arch/x86/kvm/lapic.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)arch/x86/kvm/lapic.c +0
-0
arch/x86/kvm/lapic.c int kvm_apic_has_interrupt(struct kvm_vcpu *vcpu) · line 1644
Quoted 9 lines
arch/x86/kvm/lapic.c +1
-2@@ -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.
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
Quoted 28 lines · Paolo Bonzini
Quoted 13 lines · Tiejun Chen
Finally we always return
highest_irrso its unnecessary to return -1 after check ifhighest_irr== -1.Signed-off-by Tiejun Chen <[email protected]>--- arch/x86/kvm/lapic.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)arch/x86/kvm/lapic.c +0
-0arch/x86/kvm/lapic.c int kvm_apic_has_interrupt(struct kvm_vcpu *vcpu) · line 1644
Quoted 9 lines
arch/x86/kvm/lapic.c +1
-2@@ -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:
Quoted 8 lines
- return -1: no interrupt to inject
- return
highest_irr: inject this interruptWith 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 computinghighest_irr&0xF0would make no sense ifhighest_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
Quoted 21 lines
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;
returnhighest_irr;Then removing the check on
highest_irr== -1 would trigger a warning.Paolo