x86/cpuid: expose MCDT_NO
cover x86/cpuid: expose MCDT_NO
Hello,
First patch is about exposing MCDT_NO when announced by the hardware. Second patch adds detection in Xen to expose the bit if the family/model/stepping doesn't expose MCDT behavior.
Document about the feature can be found at:
Thanks, Roger.
Roger Pau Monne (2):
x86/cpuid: expose MCDT_NO to guests
x86/cpuid: set MCDT_NO for non-affected models
tools/libs/light/libxl_cpuid.c | 1 + tools/misc/xen-cpuid.c | 1 + xen/arch/x86/cpu/intel.c | 70 +++++++++++++++++++++ xen/arch/x86/cpuid.c | 10 +++ xen/include/public/arch-x86/cpufeatureset.h | 1 + 5 files changed, 83 insertions(+)
Signature · 1 line
2.36.0
PATCH 1/2 x86/cpuid: expose MCDT_NO to guests
Expose the MCDT_NO CPUID flag to guests if available. The bit signals that the CPU does not exhibit MCDT behavior, and as such can be exposed without requiring any additional work.
--- tools/libs/light/libxl_cpuid.c | 1 + tools/misc/xen-cpuid.c | 1 + xen/include/public/arch-x86/cpufeatureset.h | 1 + 3 files changed, 3 insertions(+)
tools/libs/light/libxl_cpuid.c +1 -0
@@ -235,6 +235,7 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str) {"fsrcs", 0x00000007, 1, CPUID_REG_EAX, 12, 1}, {"intel-psfd", 0x00000007, 2, CPUID_REG_EDX, 0, 1}, + {"mcdt_no", 0x00000007, 2, CPUID_REG_EDX, 5, 1}, {"lahfsahf", 0x80000001, NA, CPUID_REG_ECX, 0, 1}, {"cmplegacy", 0x80000001, NA, CPUID_REG_ECX, 1, 1},
tools/misc/xen-cpuid.c +1 -0
@@ -203,6 +203,7 @@ static const char *const str_7b1[32] =static const char *const str_7d2[32 ] = { [0 ] ="intel-psfd" , + [5 ] ="mcdt_no" , }; static const struct {
xen/include/public/arch-x86/cpufeatureset.h +1 -0
@@ -304,6 +304,7 @@ XEN_CPUFEATURE(INTEL_PPIN, 12*32+ 0) /* Protected Processor Inventory/* Intel-defined CPU features, CPUID level 0x00000007:2.edx, word 13 */ XEN_CPUFEATURE(INTEL_PSFD, 13*32+ 0) /*A MSR_SPEC_CTRL.PSFD */ +XEN_CPUFEATURE(MCDT_NO, 13*32+ 5) /*A MCDT_NO */#endif /* XEN_CPUFEATURE */
Signature · 1 line
2.36.0
Re: [PATCH 1/2] x86/cpuid: expose MCDT_NO to guests
tools/libs/light/libxl_cpuid.c int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str) · line 238
Quoted 9 lines · Roger Pau Monne
tools/libs/light/libxl_cpuid.c +1
-0@@ -235,6 +235,7 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str) {"fsrcs", 0x00000007, 1, CPUID_REG_EAX, 12, 1}, {"intel-psfd", 0x00000007, 2, CPUID_REG_EDX, 0, 1}, + {"mcdt_no", 0x00000007, 2, CPUID_REG_EDX, 5, 1},
I think we're wanting to prefer "mcdt-no". Can be fixed on commit.
Re: [PATCH 1/2] x86/cpuid: expose MCDT_NO to guests
Quoted 8 lines · Andrew Cooper
Quoted 7 lines · Roger Pau Monne
tools/libs/light/libxl_cpuid.c +0
-0@@ -235,6 +235,7 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str) {"fsrcs", 0x00000007, 1, CPUID_REG_EAX, 12, 1},
Quoted 4 lines
tools/libs/light/libxl_cpuid.c int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str) · line 238
Quoted 2 lines
tools/libs/light/libxl_cpuid.c +1
-0{"intel-psfd", 0x00000007, 2, CPUID_REG_EDX, 0, 1}, + {"mcdt_no", 0x00000007, 2, CPUID_REG_EDX, 5, 1},I think we're wanting to prefer "mcdt-no". Can be fixed on commit.
I've asked myself whether to use - or _, went with _ because that's the exact name on the manuals (minus the lowercase).
Quoted 1 line
Reviewed-by Andrew Cooper <[email protected]>
I'm fine if you want to adjust to - on commit.
Thanks, Roger.
PATCH 2/2 x86/cpuid: set MCDT_NO for non-affected models
In reply to Roger Pau MonneSome CPU models don't exhibit MCDT behavior, but also don't expose MCDT_NO. Set the MCDT_NO bit for CPUs known to not exhibit the behavior, so guests can get this information, as using family/model/stepping detection when running virtualized is not to be relied.
--- xen/arch/x86/cpu/intel.c | 70 ++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/cpuid.c | 10 ++++++ 2 files changed, 80 insertions(+)
xen/arch/x86/cpu/intel.c +70 -0
@@ -518,6 +518,73 @@ static void intel_log_freq(const struct cpuinfo_x86 *c)printk ("%u MHz\n" , (factor * max_ratio +50 ) /100 ); } +void update_mcdt_no (struct cpuinfo_x86 *c) +{ +#define FAM6_MODEL (m, s, c) { 6, m, s, c } +/* +* List of models that do not exhibit MCDT behavior, but might not +* advertise MCDT_NO on CPUID. +*/ +static const struct { +uint8_t family; +uint8_t model; +uint8_t stepping; +bool check_stepping; + } mcdt_no[] = { +/* Haswell Server EP, EP4S. */ +FAM6_MODEL (0x3f ,2 , true), +/* Elkhart Lake. */ +FAM6_MODEL (0x3f ,4 , true), +/* Cherryview. */ +FAM6_MODEL (0x4c ,0 , false), +/* Broadwell Server E, EP, EP4S, EX. */ +FAM6_MODEL (0x4f ,0 , false), +/* Broadwell DE V2, V3. */ +FAM6_MODEL (0x56 ,3 , true), +/* Broadwell DE Y0. */ +FAM6_MODEL (0x56 ,4 , true), +/* Broadwell DE A1, Hewitt Lake. */ +FAM6_MODEL (0x56 ,5 , true), +/* Anniedale. */ +FAM6_MODEL (0x5a ,0 , false), +/* Apollo Lake. */ +FAM6_MODEL (0x5c ,9 , true), +FAM6_MODEL (0x5c ,0xa , true), +/* Denverton. */ +FAM6_MODEL (0x5f ,1 , true), +/* XMM7272. */ +FAM6_MODEL (0x65 ,0 , false), +/* Cougar Mountain. */ +FAM6_MODEL (0x6e ,0 , false), +/* Butter. */ +FAM6_MODEL (0x75 ,0 , false), +/* Gemini Lake. */ +FAM6_MODEL (0x7a ,1 , true), +FAM6_MODEL (0x7a ,8 , true), +/* Snowridge. */ +FAM6_MODEL (0x86 ,4 , true), +FAM6_MODEL (0x86 ,5 , true), +FAM6_MODEL (0x86 ,7 , true), +/* Lakefield B-step. */ +FAM6_MODEL (0x8a ,1 , true), +/* Elkhart Lake. */ +FAM6_MODEL (0x96 ,1 , true), +/* Jasper Lake. */ +FAM6_MODEL (0x9c ,0 , true), + { } + }; +#undef FAM6_MODEL +const typeof (mcdt_no[0 ]) *m; + +for (m = mcdt_no; m->family | m->model | m->stepping; m++) +if ( c->x86 == m->family && c->x86_model == m->model && + (!m->check_stepping || c->x86_mask == m->stepping) ) + { +__set_bit (X86_FEATURE_MCDT_NO , c->x86_capability); +break ; + } +} + static void cf_check init_intel(struct cpuinfo_x86 *c) {/* Detect the extended topology information if available */
@@ -556,6 +623,9 @@ static void cf_check init_intel(struct cpuinfo_x86 *c)if ((opt_cpu_info && !(c->apicid & (c->x86_num_siblings -1 ))) || c == &boot_cpu_data )intel_log_freq (c); + +if (!cpu_has (c,X86_FEATURE_MCDT_NO )) +update_mcdt_no (c); }const struct cpu_dev intel_cpu_dev = {
xen/arch/x86/cpuid.c +10 -0
@@ -360,6 +360,16 @@ static void __init calculate_host_policy(void) p->basic.max_leaf =min_t (uint32_t, p->basic.max_leaf,ARRAY_SIZE (p->basic.raw) -1 ); + +/* +* For Intel hardware MCDT_NO might be set by Xen for models that don't +* exhibit MCDT behavior but also don't have the MCDT_NO bit set in +* CPUID. Extend feat.max_subleaf beyond what hardware supports to include +* the feature leaf containing this information. +*/ +if (boot_cpu_has (X86_FEATURE_MCDT_NO ) ) + p->feat.max_subleaf =max (p->feat.max_subleaf,2u ); + p->feat.max_subleaf =min_t (uint32_t, p->feat.max_subleaf,ARRAY_SIZE (p->feat.raw) -1 );
Signature · 1 line
2.36.0
Re: [PATCH 2/2] x86/cpuid: set MCDT_NO for non-affected models
Quoted 76 lines · Roger Pau Monne
Some CPU models don't exhibit MCDT behavior, but also don't expose
MCDT_NO. Set theMCDT_NObit for CPUs known to not exhibit the behavior, so guests can get this information, as using family/model/stepping detection when running virtualized is not to be relied.Signed-off-by Roger Pau Monné <[email protected]>--- xen/arch/x86/cpu/intel.c | 70 ++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/cpuid.c | 10 ++++++ 2 files changed, 80 insertions(+)xen/arch/x86/cpu/intel.c +56
-0@@ -518,6 +518,73 @@ static void intel_log_freq(const struct cpuinfo_x86 *c)printk ("%u MHz\n" , (factor * max_ratio +50 ) /100 ); } +void update_mcdt_no (struct cpuinfo_x86 *c) +{ +#define FAM6_MODEL (m, s, c) { 6, m, s, c } +/* +* List of models that do not exhibit MCDT behavior, but might not +* advertise MCDT_NO on CPUID. +*/ +static const struct { +uint8_t family; +uint8_t model; +uint8_t stepping; +bool check_stepping; + } mcdt_no[] = { +/* Haswell Server EP, EP4S. */ +FAM6_MODEL (0x3f ,2 , true), +/* Elkhart Lake. */ +FAM6_MODEL (0x3f ,4 , true), +/* Cherryview. */ +FAM6_MODEL (0x4c ,0 , false), +/* Broadwell Server E, EP, EP4S, EX. */ +FAM6_MODEL (0x4f ,0 , false), +/* Broadwell DE V2, V3. */ +FAM6_MODEL (0x56 ,3 , true), +/* Broadwell DE Y0. */ +FAM6_MODEL (0x56 ,4 , true), +/* Broadwell DE A1, Hewitt Lake. */ +FAM6_MODEL (0x56 ,5 , true), +/* Anniedale. */ +FAM6_MODEL (0x5a ,0 , false), +/* Apollo Lake. */ +FAM6_MODEL (0x5c ,9 , true), +FAM6_MODEL (0x5c ,0xa , true), +/* Denverton. */ +FAM6_MODEL (0x5f ,1 , true), +/* XMM7272. */ +FAM6_MODEL (0x65 ,0 , false), +/* Cougar Mountain. */ +FAM6_MODEL (0x6e ,0 , false), +/* Butter. */ +FAM6_MODEL (0x75 ,0 , false), +/* Gemini Lake. */ +FAM6_MODEL (0x7a ,1 , true), +FAM6_MODEL (0x7a ,8 , true), +/* Snowridge. */ +FAM6_MODEL (0x86 ,4 , true), +FAM6_MODEL (0x86 ,5 , true), +FAM6_MODEL (0x86 ,7 , true), +/* Lakefield B-step. */ +FAM6_MODEL (0x8a ,1 , true), +/* Elkhart Lake. */ +FAM6_MODEL (0x96 ,1 , true), +/* Jasper Lake. */ +FAM6_MODEL (0x9c ,0 , true), + { } + }; +#undef FAM6_MODEL
xen/arch/x86/cpu/intel.c static void intel_log_freq(const struct cpuinfo_x86 *c) · line 586
Quoted 10 lines
xen/arch/x86/cpu/intel.c +10
-0+const typeof (mcdt_no[0 ]) *m; + +for (m = mcdt_no; m->family | m->model | m->stepping; m++) +if ( c->x86 == m->family && c->x86_model == m->model && + (!m->check_stepping || c->x86_mask == m->stepping) ) + { +__set_bit (X86_FEATURE_MCDT_NO , c->x86_capability); +break ; + } +}
Please could we see about using x86_match_cpu() rather than basically opencoding it? Linux's bug.c has some fairly comprehensive examples of how to do tables like this with it.
Also, can we use our shiny new intel-family.h names?
The stepping checks guidance seems suspect. Lemme ping some people about that. I suspect that means "we checked the production CPUs but didn't look at the pre-prod hardware" which in practice means we don't care about steppings listed.
~Andrew
Re: [PATCH 2/2] x86/cpuid: set MCDT_NO for non-affected models
Quoted 83 lines · Andrew Cooper
Quoted 82 lines · Roger Pau Monne
Some CPU models don't exhibit MCDT behavior, but also don't expose
MCDT_NO. Set theMCDT_NObit for CPUs known to not exhibit the behavior, so guests can get this information, as using family/model/stepping detection when running virtualized is not to be relied.Signed-off-by Roger Pau Monné <[email protected]>--- xen/arch/x86/cpu/intel.c | 70 ++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/cpuid.c | 10 ++++++ 2 files changed, 80 insertions(+)xen/arch/x86/cpu/intel.c +62
-0@@ -518,6 +518,73 @@ static void intel_log_freq(const struct cpuinfo_x86 *c)printk ("%u MHz\n" , (factor * max_ratio +50 ) /100 ); } +void update_mcdt_no (struct cpuinfo_x86 *c) +{ +#define FAM6_MODEL (m, s, c) { 6, m, s, c } +/* +* List of models that do not exhibit MCDT behavior, but might not +* advertise MCDT_NO on CPUID. +*/ +static const struct { +uint8_t family; +uint8_t model; +uint8_t stepping; +bool check_stepping; + } mcdt_no[] = { +/* Haswell Server EP, EP4S. */ +FAM6_MODEL (0x3f ,2 , true), +/* Elkhart Lake. */ +FAM6_MODEL (0x3f ,4 , true), +/* Cherryview. */ +FAM6_MODEL (0x4c ,0 , false), +/* Broadwell Server E, EP, EP4S, EX. */ +FAM6_MODEL (0x4f ,0 , false), +/* Broadwell DE V2, V3. */ +FAM6_MODEL (0x56 ,3 , true), +/* Broadwell DE Y0. */ +FAM6_MODEL (0x56 ,4 , true), +/* Broadwell DE A1, Hewitt Lake. */ +FAM6_MODEL (0x56 ,5 , true), +/* Anniedale. */ +FAM6_MODEL (0x5a ,0 , false), +/* Apollo Lake. */ +FAM6_MODEL (0x5c ,9 , true), +FAM6_MODEL (0x5c ,0xa , true), +/* Denverton. */ +FAM6_MODEL (0x5f ,1 , true), +/* XMM7272. */ +FAM6_MODEL (0x65 ,0 , false), +/* Cougar Mountain. */ +FAM6_MODEL (0x6e ,0 , false), +/* Butter. */ +FAM6_MODEL (0x75 ,0 , false), +/* Gemini Lake. */ +FAM6_MODEL (0x7a ,1 , true), +FAM6_MODEL (0x7a ,8 , true), +/* Snowridge. */ +FAM6_MODEL (0x86 ,4 , true), +FAM6_MODEL (0x86 ,5 , true), +FAM6_MODEL (0x86 ,7 , true), +/* Lakefield B-step. */ +FAM6_MODEL (0x8a ,1 , true), +/* Elkhart Lake. */ +FAM6_MODEL (0x96 ,1 , true), +/* Jasper Lake. */ +FAM6_MODEL (0x9c ,0 , true), + { } + }; +#undef FAM6_MODEL +const typeof (mcdt_no[0 ]) *m; + +for (m = mcdt_no; m->family | m->model | m->stepping; m++) +if ( c->x86 == m->family && c->x86_model == m->model && + (!m->check_stepping || c->x86_mask == m->stepping) ) + {
Quoted 8 lines
xen/arch/x86/cpu/intel.c static void intel_log_freq(const struct cpuinfo_x86 *c) · line 586
Quoted 4 lines
xen/arch/x86/cpu/intel.c +4
-0+__set_bit (X86_FEATURE_MCDT_NO , c->x86_capability); +break ; + } +}Please could we see about using
x86_match_cpu()rather than basically opencoding it? Linux'sbug.chas some fairly comprehensive examples of how to do tables like this with it.
Yes, I know about x86_match_cpu(). I've used this open-coded form because of the conditional extra checking of the stepping which is not handled by x86_match_cpu(). I didn't feel like extending struct x86_cpu_id and x86_match_cpu() just for this use-case, but I could do it.
Quoted 6 lines
Also, can we use our shiny new
intel-family.hnames?The stepping checks guidance seems suspect. Lemme ping some people about that. I suspect that means "we checked the production CPUs but didn't look at the pre-prod hardware" which in practice means we don't care about steppings listed.
OK, that would help quite a lot, as then I could just use plain x86_match_cpu().
Thanks, Roger.
RE: [PATCH 2/2] x86/cpuid: set MCDT_NO for non-affected models
In reply to Roger Pau MonneHi,
It seems that this patch has been stale for nearly 2 months, with the first patch in series already merged and some discussions between maintainers and author in the Patch #2 thread. So I am sending this email as a gentle reminder.
Kind regards,
Henry
Quoted 130 lines
-----Original Message-----
Subject: [PATCH 2/2] x86/cpuid: setMCDT_NOfor non-affected modelsSome CPU models don't exhibit MCDT behavior, but also don't expose
MCDT_NO. Set theMCDT_NObit for CPUs known to not exhibit the behavior, so guests can get this information, as using family/model/stepping detection when running virtualized is not to be relied.Signed-off-by Roger Pau Monné <[email protected]>--- xen/arch/x86/cpu/intel.c | 70 ++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/cpuid.c | 10 ++++++ 2 files changed, 80 insertions(+)xen/arch/x86/cpu/intel.c +67
-0@@ -518,6 +518,73 @@ static void intel_log_freq(const struct cpuinfo_x86 *c)printk ("%u MHz\n" , (factor * max_ratio +50 ) /100 ); } +void update_mcdt_no (struct cpuinfo_x86 *c) +{ +#define FAM6_MODEL (m, s, c) { 6, m, s, c } +/* +* List of models that do not exhibit MCDT behavior, but might not +* advertise MCDT_NO on CPUID. +*/ +static const struct { +uint8_t family; +uint8_t model; +uint8_t stepping; +bool check_stepping; + } mcdt_no[] = { +/* Haswell Server EP, EP4S. */ +FAM6_MODEL (0x3f ,2 , true), +/* Elkhart Lake. */ +FAM6_MODEL (0x3f ,4 , true), +/* Cherryview. */ +FAM6_MODEL (0x4c ,0 , false), +/* Broadwell Server E, EP, EP4S, EX. */ +FAM6_MODEL (0x4f ,0 , false), +/* Broadwell DE V2, V3. */ +FAM6_MODEL (0x56 ,3 , true), +/* Broadwell DE Y0. */ +FAM6_MODEL (0x56 ,4 , true), +/* Broadwell DE A1, Hewitt Lake. */ +FAM6_MODEL (0x56 ,5 , true), +/* Anniedale. */ +FAM6_MODEL (0x5a ,0 , false), +/* Apollo Lake. */ +FAM6_MODEL (0x5c ,9 , true), +FAM6_MODEL (0x5c ,0xa , true), +/* Denverton. */ +FAM6_MODEL (0x5f ,1 , true), +/* XMM7272. */ +FAM6_MODEL (0x65 ,0 , false), +/* Cougar Mountain. */ +FAM6_MODEL (0x6e ,0 , false), +/* Butter. */ +FAM6_MODEL (0x75 ,0 , false), +/* Gemini Lake. */ +FAM6_MODEL (0x7a ,1 , true), +FAM6_MODEL (0x7a ,8 , true), +/* Snowridge. */ +FAM6_MODEL (0x86 ,4 , true), +FAM6_MODEL (0x86 ,5 , true), +FAM6_MODEL (0x86 ,7 , true), +/* Lakefield B-step. */ +FAM6_MODEL (0x8a ,1 , true), +/* Elkhart Lake. */ +FAM6_MODEL (0x96 ,1 , true), +/* Jasper Lake. */ +FAM6_MODEL (0x9c ,0 , true), + { } + }; +#undef FAM6_MODEL +const typeof (mcdt_no[0 ]) *m; + +for (m = mcdt_no; m->family | m->model | m->stepping; m++) +if ( c->x86 == m->family && c->x86_model == m->model && + (!m->check_stepping || c->x86_mask == m->stepping) ) + { +__set_bit (X86_FEATURE_MCDT_NO , c->x86_capability); +break ; + } +} + static void cf_check init_intel(struct cpuinfo_x86 *c) {xen/arch/x86/cpu/intel.c +3
-0/* Detect the extended topology information if available */ @@ -556,6 +623,9 @@ static void cf_check init_intel(struct cpuinfo_x86 *c)if ((opt_cpu_info && !(c->apicid & (c->x86_num_siblings -1 ))) || c == &boot_cpu_data )intel_log_freq (c); + +if (!cpu_has (c,X86_FEATURE_MCDT_NO )) +update_mcdt_no (c); }const struct cpu_dev intel_cpu_dev = {xen/arch/x86/cpuid.c +5
-0@@ -360,6 +360,16 @@ static void __init calculate_host_policy(void) p->basic.max_leaf =min_t (uint32_t, p->basic.max_leaf,ARRAY_SIZE (p->basic.raw) -1 ); + +/* +* For Intel hardware MCDT_NO might be set by Xen for models that don't +* exhibit MCDT behavior but also don't have the MCDT_NO bit set in +* CPUID. Extend feat.max_subleaf beyond what hardware supports to include
xen/arch/x86/cpuid.c +5
-1+* the feature leaf containing this information. +*/ +if (boot_cpu_has (X86_FEATURE_MCDT_NO ) ) + p->feat.max_subleaf =max (p->feat.max_subleaf,2u ); + p->feat.max_subleaf =min_t (uint32_t, p->feat.max_subleaf,ARRAY_SIZE (p->feat.raw) -1 ); --2.36.0