logid_index = cluster + __ffs(bitmap);
- if (!apic_x2apic_mode(source)) {
+ if (apic_x2apic_mode(source)) {
+ /*
+ * For x2APIC, the logical APIC ID is a read-only value
+ * that is derived from the x2APIC ID, thus the x2APIC
+ * ID can be found by reversing the calculation (done
+ * above). Note, bits 31:20 of the x2APIC ID are not
+ * propagated to the logical ID, but KVM limits the
+ * x2APIC ID limited to KVM_MAX_VCPU_IDS.
+ */
+ l1_physical_id = logid_index;
+ } else {
u32 *avic_logical_id_table =
page_address(kvm_svm->avic_logical_id_table_page);
l1_physical_id = logid_entry &
AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK;
- } else {
- /*
- * For x2APIC logical mode, cannot leverage the index.
- * Instead, calculate physical ID from logical ID in ICRH.
- */
- int cluster = (icrh & 0xffff0000) >> 16;
- int apic = ffs(icrh & 0xffff) - 1;
-
- /*
- * If the x2APIC logical ID sub-field (i.e. icrh[15:0])
- * contains anything but a single bit, we cannot use the
- * fast path, because it is limited to a single vCPU.
- */
- if (apic < 0 || icrh != (1 << apic))
- return -EINVAL;
-
- l1_physical_id = (cluster << 4) + apic;
}
}