From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH 7/8] KVM: x86: avoid logical_map when it is invalid Date: Fri, 30 Jan 2015 16:10:27 +0100 Message-ID: <54CB9EE3.3030804@redhat.com> References: <1422568135-28402-1-git-send-email-rkrcmar@redhat.com> <1422568135-28402-8-git-send-email-rkrcmar@redhat.com> <54CB5101.4010701@redhat.com> <20150130145631.GB27414@potion.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, Nadav Amit , Gleb Natapov To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= Return-path: In-Reply-To: <20150130145631.GB27414@potion.redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On 30/01/2015 15:56, Radim Kr=C4=8Dm=C3=A1=C5=99 wrote: > 2015-01-30 10:38+0100, Paolo Bonzini: >> On 29/01/2015 22:48, Radim Kr=C4=8Dm=C3=A1=C5=99 wrote: >>> + if (hweight8(new->mode) !=3D 1) >> >> Better (more optimized): >> >> if (new->mode & (new->mode - 1)) >=20 > True, hweight needs to have X86_FEATURE_POPCNT to be efficient ... >=20 > Do you know of a difference with it? > new->mode & (new->mode - 1) | hweight8(new->mode) !=3D 1 > lea -0x1(%rax),%edi | popcnt %edi,%eax > test %eax,%edi | cmp $1,%eax x & (x - 1) is really hweight8(new->mode) > 1. So if new->mode =3D=3D = 0 it would have a different result. >> Please add a comment to kvm_irq_delivery_to_apic_fast to explain wha= t >> you are doing. >=20 > Would naming it kvm_apic_need_slow_delivery(), or something, be enoug= h? Or kvm_apic_map_valid() perhaps? Paolo >>> + if (hweight8(map->mode) !=3D 1) { >>> + /* Not deliverable with optimized map. */ >>> + ret =3D false; >>> + goto out; >>> + } >> >> Put this before the computation of cid and mda. The cid and mda are= all >> wrong with a mixed map, and the result of the "if" before is influen= ced >> by the wrong cid. Fixed by patch 8, but better get it right here. >=20 > Will do, >=20 > thanks. >=20