From mboxrd@z Thu Jan 1 00:00:00 1970 From: Radim =?utf-8?B?S3LEjW3DocWZ?= Subject: Re: [PATCH v1 02/11] KVM: x86: add kvm_apic_map_get_dest_lapic Date: Fri, 1 Jul 2016 14:39:42 +0200 Message-ID: <20160701123941.GA27840@potion> References: <20160630205429.16480-1-rkrcmar@redhat.com> <20160630205429.16480-3-rkrcmar@redhat.com> <7f5a8277-f905-e6a2-fba8-7f859d300b66@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, "Lan, Tianyu" , Igor Mammedov , Jan Kiszka , Peter Xu To: Paolo Bonzini Return-path: Content-Disposition: inline In-Reply-To: <7f5a8277-f905-e6a2-fba8-7f859d300b66@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org 2016-07-01 09:57+0200, Paolo Bonzini: > On 30/06/2016 22:54, Radim Kr=C4=8Dm=C3=A1=C5=99 wrote: >> kvm_irq_delivery_to_apic_fast and kvm_intr_is_single_vcpu_fast both >> compute the interrupt destination. Factor the code. >>=20 >> 'struct kvm_lapic **dst =3D NULL' had to be added to silence GCC. >> GCC might complain about potential NULL access in the future, becaus= e it >> missed conditions that avoided uninitialized uses of dst. >>=20 >> Signed-off-by: Radim Kr=C4=8Dm=C3=A1=C5=99 >> --- >> v1: improved comment for kvm_apic_map_get_dest_lapic() [Peter] >>=20 >> arch/x86/kvm/lapic.c | 241 ++++++++++++++++++++++------------------= ----------- >> 1 file changed, 103 insertions(+), 138 deletions(-) >>=20 >> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c >> index 22a6474af220..238b87b068db 100644 >> --- a/arch/x86/kvm/lapic.c >> +++ b/arch/x86/kvm/lapic.c >> @@ -671,14 +671,98 @@ static void kvm_apic_disabled_lapic_found(stru= ct kvm *kvm) >> } >> } >> =20 >> +/* Return true if the interrupt can be handled by using *bitmap as = index mask >> + * for valid destinations in *dst array. >> + * Return false if kvm_apic_map_get_dest_lapic did nothing useful. >> + * Note: we may have zero kvm_lapic destinations when we return tru= e, which >> + * means that the interrupt should be dropped. In this case, *bitm= ap would be >> + * zero and *dst undefined. >> + */ >> +static inline bool kvm_apic_map_get_dest_lapic(struct kvm *kvm, str= uct kvm_lapic *src, >> + struct kvm_lapic_irq *irq, struct kvm_apic_map *map, >> + struct kvm_lapic ***dst, unsigned long *bitmap) >> +{ >> + int i, lowest; >> + bool x2apic_ipi; >> + u16 cid; >> + >> + if (irq->shorthand =3D=3D APIC_DEST_SELF) { >> + *dst =3D &src; >=20 > This is not valid, &src dies as soon as you leave the function. You > need to pass &src into kvm_apic_map_get_dest_lapic and here do someth= ing > like Indeed, that would have been bad. > if (irq->shorthand) { > if (irq->shorthand =3D=3D APIC_DEST_SELF && p_src) { > *dst =3D p_src; > *bitmap =3D 1; > return true; > } > return false; > } >=20 > If it's not too hard, I'd like to have patch 4 before this one. Sure, thanks.