From: Zhao Liu <zhao1.liu@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, Zhao Liu <zhaop1.liu@intel.com>
Subject: Re: [PATCH 19/20] target/i386/tcg: mark APX as supported
Date: Wed, 2 Sep 2026 17:15:04 +0800 [thread overview]
Message-ID: <apfpGLM4eZd2U9O1@intel.com> (raw)
In-Reply-To: <20260825122921.431739-20-pbonzini@redhat.com>
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index e5ffb10d156..e966bd8049b 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -1005,7 +1005,7 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1,
> #define TCG_7_1_EAX_FEATURES (CPUID_7_1_EAX_FZRM | CPUID_7_1_EAX_FSRS | \
> CPUID_7_1_EAX_FSRC | CPUID_7_1_EAX_CMPCCXADD)
> #define TCG_7_1_ECX_FEATURES 0
> -#define TCG_7_1_EDX_FEATURES 0
> +#define TCG_7_1_EDX_FEATURES CPUID_7_1_EDX_APXF
And NCI/NDD/NF is supported :-)
+#define TCG_29_0_EBX_FEATURES CPUID_29_0_EBX_APX_NCI_NDD_NF
> #define TCG_7_2_EDX_FEATURES 0
> #define TCG_APM_FEATURES 0
> #define TCG_6_EAX_FEATURES CPUID_6_EAX_ARAT
> @@ -1554,7 +1554,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
> },
> .tcg_features = XSTATE_FP_MASK | XSTATE_SSE_MASK |
> XSTATE_YMM_MASK | XSTATE_BNDREGS_MASK | XSTATE_BNDCSR_MASK |
> - XSTATE_PKRU_MASK,
> + XSTATE_PKRU_MASK | XSTATE_APX_MASK,
> .migratable_flags = XSTATE_FP_MASK | XSTATE_SSE_MASK |
> XSTATE_YMM_MASK | XSTATE_BNDREGS_MASK | XSTATE_BNDCSR_MASK |
> XSTATE_OPMASK_MASK | XSTATE_ZMM_Hi256_MASK | XSTATE_Hi16_ZMM_MASK |
> @@ -9722,6 +9722,17 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
> * inside x86_cpu_parse_featurestr() too.
> */
> if (xcc->max_features) {
> + /*
> + * TCG supports both MPX and APX. Since they they cannot be enabled together,
> + * disable one---prefer APX if none was chosen explicitly.
> + */
> + if ((x86_cpu_get_supported_feature_word(cpu, FEAT_7_1_EDX) & CPUID_7_1_EDX_APXF) &&
> + env->user_features[FEAT_7_0_EBX] & CPUID_7_0_EBX_MPX) {
> + feature_word_info[FEAT_7_1_EDX].no_autoenable_flags |= CPUID_7_1_EDX_APXF;
> + } else {
> + feature_word_info[FEAT_7_0_EBX].no_autoenable_flags |= CPUID_7_0_EBX_MPX;
> + }
I have some thoughts here:
1. we should check env->features[] instead of env->user_features[]
since the latter just indicates whether user touches this feature (maybe
on, or maybe off), in x86_cpu_set_bit_prop().
2. if accel doesn't supports APXF, then it goes to "else" and disable
MPX by default - I think this would hurt KVM.
3. changing feature_word_info seems not good - it is a global variable
and has longer life time than CPU object - so that changes to it will
affect multiple CPU instances (QMP's dummy instance).
For example,
(QMP) query-cpu-model-expansion type=full model={"name":"max"}
[mpx=off, apxf=on]
(QMP) query-cpu-model-expansion type=full model={"name":"max","props":{"mpx":true}}
[mpx=on, apxf=off]
(QMP) query-cpu-model-expansion type=full model={"name":"max"}
[mpx=off, apxf=off, NOTE: this gets the different result with 1st try!]
So, I think that if we're going to change a feature, we should change the
feature list that corresponds to the CPU lifetime, such as env->features[].
But I find it's still tricky to keep this check before FEATURE_WORDS
loop. So how about the following instead?
- /*
- * TCG supports both MPX and APX. Since they they cannot be enabled together,
- * disable one---prefer APX if none was chosen explicitly.
- */
- if ((x86_cpu_get_supported_feature_word(cpu, FEAT_7_1_EDX) & CPUID_7_1_EDX_APXF) &&
- env->user_features[FEAT_7_0_EBX] & CPUID_7_0_EBX_MPX) {
- feature_word_info[FEAT_7_1_EDX].no_autoenable_flags |= CPUID_7_1_EDX_APXF;
- } else {
- feature_word_info[FEAT_7_0_EBX].no_autoenable_flags |= CPUID_7_0_EBX_MPX;
- }
-
for (w = 0; w < FEATURE_WORDS; w++) {
/* Override only features that weren't set explicitly
* by the user.
*/
env->features[w] |=
x86_cpu_get_supported_feature_word(cpu, w) &
~env->user_features[w] &
~feature_word_info[w].no_autoenable_flags;
}
+ /*
+ * TCG supports both MPX and APX. Since they they cannot be enabled together,
+ * disable one---prefer APX if none was chosen explicitly. If both were
+ * requested explicitly, leave them alone and let the check below report the
+ * conflict.
+ */
+ if ((env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_MPX) &&
+ (env->features[FEAT_7_1_EDX] & CPUID_7_1_EDX_APXF)) {
+ if (!(env->user_features[FEAT_7_0_EBX] & CPUID_7_0_EBX_MPX)) {
+ env->features[FEAT_7_0_EBX] &= ~CPUID_7_0_EBX_MPX;
+ } else if (!(env->user_features[FEAT_7_1_EDX] & CPUID_7_1_EDX_APXF)) {
+ env->features[FEAT_7_1_EDX] &= ~CPUID_7_1_EDX_APXF;
+ }
+ }
Thanks,
Zhao
next prev parent reply other threads:[~2026-09-02 9:16 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 12:29 [PATCH 00/20] target/i386/tcg: implement APX Paolo Bonzini
2026-08-25 12:29 ` [PATCH 01/20] target/i386/tcg: do not reuse cc_srcT Paolo Bonzini
2026-08-25 23:09 ` Richard Henderson
2026-08-25 12:29 ` [PATCH 02/20] target/i386/tcg: inline gen_ext_tl Paolo Bonzini
2026-08-25 23:09 ` Richard Henderson
2026-08-25 12:29 ` [PATCH 03/20] target/i386/tcg: simplify return value of gen_prepare_cc Paolo Bonzini
2026-08-25 12:29 ` [PATCH 04/20] target/i386/tcg: move check bits out of validate_vex Paolo Bonzini
2026-08-25 12:29 ` [PATCH 05/20] target/i386/tcg: add APX support to XSAVE/XRSTOR Paolo Bonzini
2026-09-08 2:10 ` Chang S. Bae
2026-08-25 12:29 ` [PATCH 06/20] target/i386/tcg: treat VEX as disabling high-byte registers Paolo Bonzini
2026-08-25 12:29 ` [PATCH 07/20] target/i386/tcg: add definition for REX2 prefix Paolo Bonzini
2026-09-08 2:10 ` Chang S. Bae
2026-08-25 12:29 ` [PATCH 08/20] target/i386/tcg: mark XSAVE* as not allowing REX2 Paolo Bonzini
2026-09-08 2:10 ` Chang S. Bae
2026-08-25 12:29 ` [PATCH 09/20] target/i386/tcg: decode REX2 prefix Paolo Bonzini
2026-09-08 2:10 ` Chang S. Bae
2026-08-25 12:29 ` [PATCH 10/20] target/i386/tcg: implement JMPABS instruction Paolo Bonzini
2026-08-26 14:30 ` Zhao Liu
2026-08-27 6:33 ` Paolo Bonzini
2026-08-25 12:29 ` [PATCH 11/20] target/i386/tcg: fetch modrm early Paolo Bonzini
2026-08-25 12:29 ` [PATCH 12/20] target/i386/tcg: move VEX validation early Paolo Bonzini
2026-08-28 8:32 ` Zhao Liu
2026-08-25 12:29 ` [PATCH 13/20] target/i386/tcg: extend VEX.vvvv parsing for APX Paolo Bonzini
2026-08-25 12:29 ` [PATCH 14/20] target/i386/tcg: decode EVEX prefix Paolo Bonzini
2026-08-28 9:10 ` Zhao Liu
2026-08-25 12:29 ` [PATCH 15/20] target/i386/tcg: add ZU writeback Paolo Bonzini
2026-08-25 12:29 ` [PATCH 16/20] target/i386/tcg: add decode functionality for APX Paolo Bonzini
2026-09-01 14:56 ` Zhao Liu
2026-09-02 6:55 ` Zhao Liu
2026-08-25 12:29 ` [PATCH 17/20] target/i386/tcg: implement CCMP/CTEST Paolo Bonzini
2026-09-02 6:06 ` Zhao Liu
2026-08-25 12:29 ` [PATCH 18/20] target/i386/tcg: decode APX instructions Paolo Bonzini
2026-09-02 7:27 ` Zhao Liu
2026-08-25 12:29 ` [PATCH 19/20] target/i386/tcg: mark APX as supported Paolo Bonzini
2026-09-02 9:15 ` Zhao Liu [this message]
2026-08-25 12:29 ` [PATCH 20/20] target/i386/tcg: optimize CCMP Paolo Bonzini
2026-09-02 9:29 ` Zhao Liu
2026-09-08 2:10 ` [PATCH 00/20] target/i386/tcg: implement APX Chang S. Bae
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=apfpGLM4eZd2U9O1@intel.com \
--to=zhao1.liu@intel.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=zhaop1.liu@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.