qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Xiaoyao Li <xiaoyao.li@intel.com>, John Allen <john.allen@amd.com>
Subject: [PULL 07/16] target/i386: pass X86CPU to x86_cpu_get_supported_feature_word
Date: Thu,  4 Jul 2024 11:57:57 +0200	[thread overview]
Message-ID: <20240704095806.1780273-8-pbonzini@redhat.com> (raw)
In-Reply-To: <20240704095806.1780273-1-pbonzini@redhat.com>

This allows modifying the bits in "-cpu max"/"-cpu host" depending on
the guest CPU vendor (which, at least by default, is the host vendor in
the case of KVM).

For example, machine check architecture differs between Intel and AMD,
and bits from AMD should be dropped when configuring the guest for
an Intel model.

Cc: Xiaoyao Li <xiaoyao.li@intel.com>
Cc: John Allen <john.allen@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/cpu.h         |  3 +--
 target/i386/cpu.c         | 11 +++++------
 target/i386/kvm/kvm-cpu.c |  2 +-
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 29daf370485..9bea7142bf4 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -666,8 +666,7 @@ typedef enum FeatureWord {
 } FeatureWord;
 
 typedef uint64_t FeatureWordArray[FEATURE_WORDS];
-uint64_t x86_cpu_get_supported_feature_word(FeatureWord w,
-                                            bool migratable_only);
+uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w);
 
 /* cpuid_features bits */
 #define CPUID_FP87 (1U << 0)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 4c2e6f3a71e..4364cb0f8e3 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6035,8 +6035,7 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
 
 #endif /* !CONFIG_USER_ONLY */
 
-uint64_t x86_cpu_get_supported_feature_word(FeatureWord w,
-                                            bool migratable_only)
+uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w)
 {
     FeatureWordInfo *wi = &feature_word_info[w];
     uint64_t r = 0;
@@ -6078,7 +6077,7 @@ uint64_t x86_cpu_get_supported_feature_word(FeatureWord w,
         r &= ~unavail;
     }
 #endif
-    if (migratable_only) {
+    if (cpu && cpu->migratable) {
         r &= x86_cpu_get_migratable_flags(w);
     }
     return r;
@@ -7371,7 +7370,7 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
              * by the user.
              */
             env->features[w] |=
-                x86_cpu_get_supported_feature_word(w, cpu->migratable) &
+                x86_cpu_get_supported_feature_word(cpu, w) &
                 ~env->user_features[w] &
                 ~feature_word_info[w].no_autoenable_flags;
         }
@@ -7497,7 +7496,7 @@ static void x86_cpu_filter_features(X86CPU *cpu, bool verbose)
 
     for (w = 0; w < FEATURE_WORDS; w++) {
         uint64_t host_feat =
-            x86_cpu_get_supported_feature_word(w, false);
+            x86_cpu_get_supported_feature_word(NULL, w);
         uint64_t requested_features = env->features[w];
         uint64_t unavailable_features = requested_features & ~host_feat;
         mark_unavailable_features(cpu, w, unavailable_features, prefix);
@@ -7617,7 +7616,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
         env->features[FEAT_PERF_CAPABILITIES] & PERF_CAP_LBR_FMT;
     if (requested_lbr_fmt && kvm_enabled()) {
         uint64_t host_perf_cap =
-            x86_cpu_get_supported_feature_word(FEAT_PERF_CAPABILITIES, false);
+            x86_cpu_get_supported_feature_word(NULL, FEAT_PERF_CAPABILITIES);
         unsigned host_lbr_fmt = host_perf_cap & PERF_CAP_LBR_FMT;
 
         if (!cpu->enable_pmu) {
diff --git a/target/i386/kvm/kvm-cpu.c b/target/i386/kvm/kvm-cpu.c
index d57a68a301e..6bf8dcfc607 100644
--- a/target/i386/kvm/kvm-cpu.c
+++ b/target/i386/kvm/kvm-cpu.c
@@ -143,7 +143,7 @@ static void kvm_cpu_xsave_init(void)
         if (!esa->size) {
             continue;
         }
-        if ((x86_cpu_get_supported_feature_word(esa->feature, false) & esa->bits)
+        if ((x86_cpu_get_supported_feature_word(NULL, esa->feature) & esa->bits)
             != esa->bits) {
             continue;
         }
-- 
2.45.2



  parent reply	other threads:[~2024-07-04 10:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-04  9:57 [PULL 00/16] meson, i386 changes for 2024-07-04 Paolo Bonzini
2024-07-04  9:57 ` [PULL 01/16] meson: move shared_module() calls where modules are already walked Paolo Bonzini
2024-07-04  9:57 ` [PULL 02/16] meson: move block.syms dependency out of libblock Paolo Bonzini
2024-07-04  9:57 ` [PULL 03/16] meson: merge plugin_ldflags into emulator_link_args Paolo Bonzini
2024-07-04  9:57 ` [PULL 04/16] meson: Pass objects and dependencies to declare_dependency() Paolo Bonzini
2024-07-04  9:57 ` [PULL 05/16] Revert "meson: Propagate gnutls dependency" Paolo Bonzini
2024-07-04  9:57 ` [PULL 06/16] meson: Drop the .fa library suffix Paolo Bonzini
2024-07-04  9:57 ` Paolo Bonzini [this message]
2024-07-04  9:57 ` [PULL 08/16] target/i386: drop AMD machine check bits from Intel CPUID Paolo Bonzini
2024-07-04  9:57 ` [PULL 09/16] target/i386: SEV: fix formatting of CPUID mismatch message Paolo Bonzini
2024-07-04  9:58 ` [PULL 10/16] target/i386: do not include undefined bits in the AMD topoext leaf Paolo Bonzini
2024-07-04  9:58 ` [PULL 11/16] i386/sev: Fix error message in sev_get_capabilities() Paolo Bonzini
2024-07-04  9:58 ` [PULL 12/16] i386/sev: Fallback to the default SEV device if none provided " Paolo Bonzini
2024-07-04  9:58 ` [PULL 13/16] target/i386: add avx-vnni-int16 feature Paolo Bonzini
2024-07-04  9:58 ` [PULL 14/16] char-stdio: Restore blocking mode of stdout on exit Paolo Bonzini
2024-07-04  9:58 ` [PULL 15/16] target/i386: add support for masking CPUID features in confidential guests Paolo Bonzini
2024-07-04  9:58 ` [PULL 16/16] target/i386/SEV: implement mask_cpuid_features Paolo Bonzini
2024-08-06 11:42   ` Daniel P. Berrangé
2024-07-04 18:16 ` [PULL 00/16] meson, i386 changes for 2024-07-04 Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240704095806.1780273-8-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=john.allen@amd.com \
    --cc=qemu-devel@nongnu.org \
    --cc=xiaoyao.li@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).