]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[cpuid] Allow reading hypervisor CPUID leaves
authorMichael Brown <mcb30@ipxe.org>
Wed, 31 Jul 2024 15:35:31 +0000 (16:35 +0100)
committerMichael Brown <mcb30@ipxe.org>
Thu, 1 Aug 2024 11:49:48 +0000 (12:49 +0100)
Hypervisors typically intercept CPUID leaves in the range 0x40000000
to 0x400000ff, with leaf 0x40000000 returning the maximum supported
function within this range in register %eax.

iPXE currently masks off bit 30 from the requested CPUID leaf when
checking to see if a function is supported, which causes this check to
read from leaf 0x00000000 instead of 0x40000000.

Fix by including bit 30 within the mask.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/x86/core/cpuid.c
src/arch/x86/include/ipxe/cpuid.h

index 1a7c93e837b597878053b5b801a1d55b376d48c2..b7d9fb6c66c1ad218b2f9715b490fb11308bc694 100644 (file)
@@ -84,8 +84,8 @@ int cpuid_supported ( uint32_t function ) {
                return rc;
 
        /* Find highest supported function number within this family */
-       cpuid ( ( function & CPUID_EXTENDED ), 0, &max_function, &discard_b,
-               &discard_c, &discard_d );
+       cpuid ( ( function & ( CPUID_EXTENDED | CPUID_HYPERVISOR ) ), 0,
+                 &max_function, &discard_b, &discard_c, &discard_d );
 
        /* Fail if maximum function number is meaningless (e.g. if we
         * are attempting to call an extended function on a CPU which
index 90d1bf01dec95162d3a8e7e92f4afd9833a5460f..99b91c5c8e8bde49d0ec6dfde96fba6a874954da 100644 (file)
@@ -33,6 +33,9 @@ struct x86_features {
 /** CPUID extended function */
 #define CPUID_EXTENDED 0x80000000UL
 
+/** CPUID hypervisor function */
+#define CPUID_HYPERVISOR 0x40000000UL
+
 /** Get vendor ID and largest standard function */
 #define CPUID_VENDOR_ID 0x00000000UL