i386: Adjust CPUID_EXT_PDCM based on enable_pmu at realization
cover i386: Adjust CPUID_EXT_PDCM based on enable_pmu at realization
First, it's not a good practice that values in env->features[] cannot be directly used for guest CPUID in void cpu_x86_cpuid(), but require further adjustment there. env->features[] are supposed to be finalized at cpu realization, so that after it env->features[] is reliable.
Second, there is one dependency entry relates to CPUID_EXT_PDCM in feature_dependencies[]. QEMU needs to get correct value of CPUID_EXT_PDCM in env->features[] to ensure applying the dependencies correctly.
Patch 1 resolves above two points.
Patch 2 is a enhancement to give users a warning when they request pdcm explicitly while PMU disabled.
Xiaoyao Li (2):
i386/cpu: Move adjustment of CPUID_EXT_PDCM before
feature_dependencies[] check
i386/cpu: Warn about why CPUID_EXT_PDCM is not available
target/i386/cpu.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 i386/cpu: Move adjustment of CPUID_EXT_PDCM before feature_dependencies[] check
There is one entry relates to CPUID_EXT_PDCM in feature_dependencies[]. So it needs to get correct value of CPUID_EXT_PDCM before using feature_dependencies[] to apply dependencies.
Besides, it also ensures CPUID_EXT_PDCM value is tracked in env->features[FEAT_1_ECX].
--- target/i386/cpu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
target/i386/cpu.c +4 -3
@@ -6693,9 +6693,6 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,if (threads_per_pkg >1 ) { *ebx |= threads_per_pkg <<16 ; } -if (!cpu->enable_pmu) { - *ecx &= ~CPUID_EXT_PDCM ; - }break ;case 2 :/* cache info: needed for Pentium Pro compatibility */
@@ -7684,6 +7681,10 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp) } } +if (!cpu->enable_pmu) { + env->features[FEAT_1_ECX ] &= ~CPUID_EXT_PDCM ; + } +for (i =0 ; i <ARRAY_SIZE (feature_dependencies); i++) {FeatureDep *d = &feature_dependencies[i];if (!(env->features[d->from.index] & d->from.mask)) {
Signature · 1 line
2.34.1
Re: [PATCH 1/2] i386/cpu: Move adjustment of CPUID_EXT_PDCM before feature_dependencies[] check
Quoted 10 lines · Xiaoyao Li
Date: Tue, 4 Mar 2025 00:24:49 -0500
From: Xiaoyao Li <[email protected]>
Subject: [PATCH 1/2] i386/cpu: Move adjustment ofCPUID_EXT_PDCMbefore
feature_dependencies[] check
X-Mailer: git-send-email 2.34.1There is one entry relates to
CPUID_EXT_PDCMin feature_dependencies[]. So it needs to get correct value ofCPUID_EXT_PDCMbefore using feature_dependencies[] to apply dependencies.
Quoted 7 lines
Besides, it also ensures
CPUID_EXT_PDCMvalue is tracked in env->features[FEAT_1_ECX].Signed-off-by Xiaoyao Li <[email protected]>--- target/i386/cpu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
PATCH 2/2 i386/cpu: Warn about why CPUID_EXT_PDCM is not available
In reply to Xiaoyao LiWhen user requests PDCM explicitly via "+pdcm" without PMU enabled, emit a warning to inform the user.
--- target/i386/cpu.c | 3 +++ 1 file changed, 3 insertions(+)
target/i386/cpu.c +3 -0
@@ -7682,6 +7682,9 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp) }if (!cpu->enable_pmu) { +mark_unavailable_features (cpu,FEAT_1_ECX , + env->user_features[FEAT_1_ECX ] &CPUID_EXT_PDCM , +"This feature is not available due to PMU disabled" ); env->features[FEAT_1_ECX ] &= ~CPUID_EXT_PDCM ; }
Signature · 1 line
2.34.1
Re: [PATCH 2/2] i386/cpu: Warn about why CPUID_EXT_PDCM is not available
Quoted 6 lines · Xiaoyao Li
Date: Tue, 4 Mar 2025 00:24:50 -0500
From: Xiaoyao Li <[email protected]>
Subject: [PATCH 2/2] i386/cpu: Warn about whyCPUID_EXT_PDCMis not
available
X-Mailer: git-send-email 2.34.1
Quoted 7 lines
When user requests PDCM explicitly via "+pdcm" without PMU enabled, emit a warning to inform the user.
Signed-off-by Xiaoyao Li <[email protected]>--- target/i386/cpu.c | 3 +++ 1 file changed, 3 insertions(+)
Hi Xiaoyao,
Quoted 9 lines
First, it's not a good practice that values in env->features[] cannot be directly used for guest CPUID in void
cpu_x86_cpuid(), but require further adjustment there. env->features[] are supposed to be finalized at cpu realization, so that after it env->features[] is reliable.Second, there is one dependency entry relates to
CPUID_EXT_PDCMin feature_dependencies[]. QEMU needs to get correct value ofCPUID_EXT_PDCMin env->features[] to ensure applying the dependencies correctly.
I agree that this is a very good idea, especially since PDCM has a dependency entry.
"pmu" is totally a property rather than a feature bit, which makes the dependency relationships in the code complex. Therefore, I think it's worth having a series to clarify the dependencies of pmu as much as possible.
I remember Dapeng/Zide also have fixes for pmu dependencies, and if possible, I could help you combine this series with others' cleanups.
Additionally, I think patch 1 and patch 2 can be merged together. Do you agree?
Thanks,
Zhao
Quoted 15 lines · Zhao Liu
Hi Xiaoyao,
Quoted 9 lines
First, it's not a good practice that values in env->features[] cannot be directly used for guest CPUID in void
cpu_x86_cpuid(), but require further adjustment there. env->features[] are supposed to be finalized at cpu realization, so that after it env->features[] is reliable.Second, there is one dependency entry relates to
CPUID_EXT_PDCMin feature_dependencies[]. QEMU needs to get correct value ofCPUID_EXT_PDCMin env->features[] to ensure applying the dependencies correctly.I agree that this is a very good idea, especially since PDCM has a dependency entry.
Quoted 7 lines
"pmu" is totally a property rather than a feature bit, which makes the dependency relationships in the code complex. Therefore, I think it's worth having a series to clarify the dependencies of pmu as much as possible.
I remember Dapeng/Zide also have fixes for pmu dependencies, and if possible, I could help you combine this series with others' cleanups.
The reason I sent out this small series quickly is mainly for Dongli to as a reference.
In fact, there are mess on LBR enabling that it checks enable_pmu everytime with CPUID_7_0_EDX_ARCH_LBR as well as CPUID_8000_0022_EAX_PERFMON_V2. That's on my WIP list to clean it up.
I think I need to check if they are duplicated with Dapeng/Zide's series.
Quoted 2 lines
Additionally, I think patch 1 and patch 2 can be merged together. Do you agree?
IMHO, they stand as their own. I'll leave it to Paolo to make the decision.
Quoted 3 lines
Thanks,
Zhao
Paolo Bonzini
AppliedQueued, thanks; sorry about the delay.
Paolo