cpuid virtualization for testing

Florian Weimer fweimer@redhat.com
Thu Jul 20 07:26:15 GMT 2023


* DJ Delorie via Libc-alpha:

> The latest round of cpu-specific tweaks got me thinking - is there a
> way to emulate the cpuid instruction so we can test all these tweaks
> without having the specific hardware?
>
> It turns out, yes, you can.
>
>    ARCH_SET_CPUID (since Linux 4.12)
>               Enable (addr != 0) or disable (addr == 0) the cpuid
>               instruction for the calling thread.  The instruction is
>               enabled by default.  If disabled, any execution of a cpuid
>               instruction will instead generate a SIGSEGV signal.  This
>               feature can be used to emulate cpuid results that differ
>               from what the underlying hardware would have produced
>               (e.g., in a paravirtualization setting).
>
> The catch is that it only applies to the *current* process, and we
> need it to be emulated long before main() is called.

I don't think it's possible to install a signal handler in time for
trapping CPUID instructions in ld.so.

It's also going to be really bad for workloads that use CPUID for
serializing execution (as recommended when using RDTSC, at least
historically).

Thanks,
Florian



More information about the Libc-alpha mailing list