Re: [PATCH v2 1/2] KVM: VMX: FIXED+PHYSICAL mode single target IPI fastpath

From: Vitaly Kuznetsov
Date: Tue Nov 19 2019 - 07:27:00 EST


Wanpeng Li <kernellwp@xxxxxxxxx> writes:

> On Tue, 19 Nov 2019 at 19:54, Vitaly Kuznetsov <vkuznets@xxxxxxxxxx> wrote:
>>
>> Wanpeng Li <kernellwp@xxxxxxxxx> writes:
>>
>> > From: Wanpeng Li <wanpengli@xxxxxxxxxxx>
>> >
>> > + if (lapic_in_kernel(vcpu) && apic_x2apic_mode(vcpu->arch.apic)) {
>> > + /*
>> > + * fastpath to IPI target, FIXED+PHYSICAL which is popular
>> > + */
>> > + index = kvm_rcx_read(vcpu);
>> > + data = kvm_read_edx_eax(vcpu);
>> > +
>> > + if (((index - APIC_BASE_MSR) << 4 == APIC_ICR) &&
>>
>> What if index (RCX) is < APIC_BASE_MSR?
>
> How about if (index == (APIC_BASE_MSR + 0x300) &&
>

What about ' << 4', don't we still need it? :-) And better APIC_ICR
instead of 0x300...

Personally, I'd write something like

if (index > APIC_BASE_MSR && (index - APIC_BASE_MSR) == APIC_ICR >> 4)

and let compiler optimize this, I bet it's going to be equally good.

--
Vitaly