libx86: Elide more empty CPUID leaves when serialising a policy
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 21 May 2019 17:19:33 +0000 (18:19 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 23 May 2019 14:54:06 +0000 (15:54 +0100)
commit2eed83a9aa1a12d47512675eff31ac2abed25c4f
tree3a55d9ae1df5eb2b57459e2bcf2cb5b5aa872eee
parentad8e6232d5897eab052596389ccb8eb8f1d850a1
libx86: Elide more empty CPUID leaves when serialising a policy

x86_cpuid_copy_to_buffer() currently serialises the full content of the
various subleaf unions.  While leaves 4, 0xb and 0xd don't have a concrete
max_subleaf field, they do have well defined upper bounds.

Diffing the results of `xen-cpuid -p` shows the resulting saving:

  @@ -1,5 +1,5 @@
   Xen reports there are maximum 114 leaves and 1 MSRs
  -Raw policy: 93 leaves, 1 MSRs
  +Raw policy: 38 leaves, 1 MSRs
    CPUID:
     leaf     subleaf  -> eax      ebx      ecx      edx
     00000000:ffffffff -> 00000016:756e6547:6c65746e:49656e69
  @@ -32,7 +32,7 @@ Raw policy: 93 leaves, 1 MSRs
    MSRs:
     index    -> value
     000000ce -> 0000000080000000
  -Host policy: 93 leaves, 1 MSRs
  +Host policy: 33 leaves, 1 MSRs
    CPUID:
     leaf     subleaf  -> eax      ebx      ecx      edx
     00000000:ffffffff -> 0000000d:756e6547:6c65746e:49656e69

which is mostly due to no longer writing out 64 leaves for xstate when (on
this CoffeeLake system) 8 will do.

Extend the unit tests to cover empty and partially filled subleaf unions.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
tools/tests/cpu-policy/test-cpu-policy.c
xen/lib/x86/cpuid.c