Skip to contentSkip to conversation

hvm: Fix APIC-ID cpuid intercept

PATCH In review Andre Przywara 2 participants 2 messages Feb 6, 2008 – Feb 7, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hvm: Fix APIC-ID cpuid intercept

Hi,

the HVM CPUID intercept does not mask out the local APIC ID bits in CPUID Fn0000_0001, bits 24-31 in EBX. This results in inconsistent values of subsequent calls to cpuid on the same VCPU (delivering the value of the physical CPU), depending on the current scheduling. This for instance confuses Linux' NUMA code. The attached patch fixes this by replacing the physical APIC ID with the VCPU number, both in the VMX and SVM branches.

I hope this does not trigger any side effects...

Regards,
Andre

Signature · 9 lines
Andre Przywara
AMD-Operating System Research Center (OSRC), Dresden, Germany
Tel: +49 351 277-84917
----to satisfy European Law for business letters:
AMD Saxony Limited Liability Company & Co. KG,
Wilschdorfer Landstr. 101, 01109 Dresden, Germany
Register Court Dresden: HRA 4896, General Partner authorized
to represent: AMD Saxony LLC (Wilmington, Delaware, US)
General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy
xen/arch/x86/hvm/svm/svm.c +2 -0
diff -r f8db1c6baad9 xen/arch/x86/hvm/svm/svm.c
@@ -1015,6 +1015,8 @@ static void svm_vmexit_do_cpuid(struct v
         __clear_bit(X86_FEATURE_HT & 31, &edx);
         ebx &= 0xFF00FFFF;  /* clear the logical processor count when HTT=0 */
         ebx |= 0x00010000;  /* set to 1 just for precaution */
+        ebx &= 0x00FFFFFF;  /* clear the APIC ID */
+        ebx |= (current->vcpu_id&0xFF)<<24;   /* replace with vcpu_id */
         break;
 
     case 0x80000001:
xen/arch/x86/hvm/vmx/vmx.c +2 -0
diff -r f8db1c6baad9 xen/arch/x86/hvm/vmx/vmx.c
@@ -1311,6 +1311,8 @@ void vmx_cpuid_intercept(
     case 0x00000001:
         *ecx &= ~VMX_VCPU_CPUID_L1_ECX_RESERVED;
         *ebx &= NUM_THREADS_RESET_MASK;
+        *ebx &= 0x00FFFFFF;
+        *ebx |= (current->vcpu_id&0xFF)<<24;
         *ecx &= ~(bitmaskof(X86_FEATURE_VMXE) |
                   bitmaskof(X86_FEATURE_EST)  |
                   bitmaskof(X86_FEATURE_TM2)  |

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 11 lines · Andre Przywara

the HVM CPUID intercept does not mask out the local APIC ID bits in CPUID Fn0000_0001, bits 24-31 in EBX. This results in inconsistent values of subsequent calls to cpuid on the same VCPU (delivering the value of the physical CPU), depending on the current scheduling. This for instance confuses Linux' NUMA code.
The attached patch fixes this by replacing the physical APIC ID with the VCPU number, both in the VMX and SVM branches.

I hope this does not trigger any side effects...

I'm sure it can't do worse than the current broken behaviour!

Thanks,
Keir