From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH] kvm: x86: lapic: remove one redundant judging condition Date: Wed, 05 Nov 2014 11:22:19 +0100 Message-ID: <5459FA5B.8060207@redhat.com> References: <1415178185-11109-1-git-send-email-tiejun.chen@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Cc: kvm@vger.kernel.org To: Tiejun Chen Return-path: Received: from mx1.redhat.com ([209.132.183.28]:35367 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754439AbaKEKWZ (ORCPT ); Wed, 5 Nov 2014 05:22:25 -0500 In-Reply-To: <1415178185-11109-1-git-send-email-tiejun.chen@intel.com> Sender: kvm-owner@vger.kernel.org List-ID: 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 > --- > 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. 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