From: Like Xu <like.xu@linux.intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
Richard Henderson <richard.henderson@linaro.org>,
Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: [PATCH v2 2/2] target/i386: add kvm_exact_match_flags to FeatureWordInfo
Date: Mon, 1 Feb 2021 12:54:53 +0800 [thread overview]
Message-ID: <20210201045453.240258-2-like.xu@linux.intel.com> (raw)
In-Reply-To: <20210201045453.240258-1-like.xu@linux.intel.com>
Eduardo has a suggestion: instead of hardcoding the
PERF_CAPABILITIES rules in this loop, this could become a
FeatureWordInfo field. It would be very useful for other
features like intel-pt, where we need some bits to match the
host too.
Suggested-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Like Xu <like.xu@linux.intel.com>
---
target/i386/cpu.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 80a5d3f0c2..8eaa5879ea 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -708,6 +708,8 @@ typedef struct FeatureWordInfo {
uint64_t migratable_flags; /* Feature flags known to be migratable */
/* Features that shouldn't be auto-enabled by "-cpu host" */
uint64_t no_autoenable_flags;
+ /* Bits that must match host exactly when using KVM */
+ uint64_t kvm_exact_match_flags;
} FeatureWordInfo;
static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
@@ -1147,6 +1149,11 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
.msr = {
.index = MSR_IA32_PERF_CAPABILITIES,
},
+ /*
+ * KVM is not able to emulate a VCPU with LBR_FMT different
+ * from the host, so LBR_FMT must match the host exactly.
+ */
+ .kvm_exact_match_flags = PERF_CAP_LBR_FMT,
},
[FEAT_VMX_PROCBASED_CTLS] = {
@@ -6500,16 +6507,18 @@ static void x86_cpu_filter_features(X86CPU *cpu, bool verbose)
}
for (w = 0; w < FEATURE_WORDS; w++) {
+ FeatureWordInfo *fi = &feature_word_info[w];
+ uint64_t match_flags = fi->kvm_exact_match_flags;
uint64_t host_feat =
x86_cpu_get_supported_feature_word(w, false);
uint64_t requested_features = env->features[w];
uint64_t unavailable_features = requested_features & ~host_feat;
- if (kvm_enabled() && w == FEAT_PERF_CAPABILITIES &&
- (requested_features & PERF_CAP_LBR_FMT)) {
- if ((host_feat & PERF_CAP_LBR_FMT) !=
- (requested_features & PERF_CAP_LBR_FMT)) {
- unavailable_features |= PERF_CAP_LBR_FMT;
- }
+ if (kvm_enabled() && match_flags) {
+ uint64_t mismatches = (requested_features & match_flags) &&
+ (requested_features ^ host_feat) & match_flags;
+ mark_unavailable_features(cpu, w,
+ mismatches, "feature doesn't match host");
+ unavailable_features &= ~match_flags;
}
mark_unavailable_features(cpu, w, unavailable_features, prefix);
}
--
2.29.2
next prev parent reply other threads:[~2021-02-01 5:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-01 4:54 [PATCH v2 1/2] target/i386: add "-cpu, lbr-fmt=*" support to enable guest LBR Like Xu
2021-02-01 4:54 ` Like Xu [this message]
2021-03-01 2:57 ` Like Xu
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=20210201045453.240258-2-like.xu@linux.intel.com \
--to=like.xu@linux.intel.com \
--cc=ehabkost@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/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).