On 4/23/2025 7:46 PM, Zhao Liu wrote:
Per SDM, 0x80000005 leaf is reserved for Intel CPU, and its current
"assert" check blocks adding new cache model for non-AMD CPUs.

Therefore, check the vendor and encode this leaf as all-0 for Intel
CPU. And since Zhaoxin mostly follows Intel behavior, apply the vendor
check for Zhaoxin as well.

Note, for !vendor_cpuid_only case, non-AMD CPU would get the wrong
information, i.e., get AMD's cache model for Intel or Zhaoxin CPUs.
For this case, there is no need to tweak for non-AMD CPUs, because
vendor_cpuid_only has been turned on by default since PC machine v6.1.

Signed-off-by: Zhao Liu <zhao1....@intel.com>
---
  target/i386/cpu.c | 16 ++++++++++++++--
  1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 1b64ceaaba46..8fdafa8aedaf 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -7248,11 +7248,23 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
          *edx = env->cpuid_model[(index - 0x80000002) * 4 + 3];
          break;
      case 0x80000005:
-        /* cache info (L1 cache) */
-        if (cpu->cache_info_passthrough) {
+        /*
+         * cache info (L1 cache)
+         *
+         * For !vendor_cpuid_only case, non-AMD CPU would get the wrong
+         * information, i.e., get AMD's cache model. It doesn't matter,
+         * vendor_cpuid_only has been turned on by default since
+         * PC machine v6.1.
+         */

We need to define a new compat property for it other than vendor_cpuid_only, for 10.1.

I proposed some change to leaf FEAT_8000_0001_EDX[1], and I was told by Paolo (privately) that vendor_cpuid_only doesn't suffice.

 On Fri, Oct 11, 2024 at 6:22 PM Xiaoyao Li <xiaoyao...@intel.com> wrote:
 >
 > On 10/11/2024 11:30 PM, Paolo Bonzini wrote:
> > On Fri, Oct 11, 2024 at 4:55 PM Xiaoyao Li <xiaoyao...@intel.com> wrote:
 > >>
 > >> I think patch 8 is also a general issue> Without it, the
 > >> CPUID_EXT2_AMD_ALIASES bits are exposed to Intel VMs which are
 > >> reserved bits for Intel.
 > >
 > > Yes but you'd have to add compat properties for these. If you can do
 > > it for TDX only, that's easier.
 >
 > Does vendor_cpuid_only suffice?

 Unfortunately not, because it is turned off only for <=6.0 machine
 types. Here you'd have to turn it off for <=9.1 machine types.


[1] https://lore.kernel.org/qemu-devel/20240814075431.339209-9-xiaoyao...@intel.com/


+        if (cpu->vendor_cpuid_only &&
+            (IS_INTEL_CPU(env) || IS_ZHAOXIN_CPU(env))) {
+            *eax = *ebx = *ecx = *edx = 0;
+            break;
+        } else if (cpu->cache_info_passthrough) {
              x86_cpu_get_cache_cpuid(index, 0, eax, ebx, ecx, edx);
              break;
          }
+
          *eax = (L1_DTLB_2M_ASSOC << 24) | (L1_DTLB_2M_ENTRIES << 16) |
                 (L1_ITLB_2M_ASSOC <<  8) | (L1_ITLB_2M_ENTRIES);
          *ebx = (L1_DTLB_4K_ASSOC << 24) | (L1_DTLB_4K_ENTRIES << 16) |


Reply via email to