diff mbox series

[RFC,v2,1/5] x86/cpu: Add virt tag in /proc/cpuinfo

Message ID 20241001063413.687787-2-manali.shukla@amd.com (mailing list archive)
State New
Headers show
Series Add support for the Bus Lock Threshold | expand

Commit Message

Manali Shukla Oct. 1, 2024, 6:34 a.m. UTC
Add support for generating Virtualization feature names in capflags.c
and use the resulting x86_virt_flags to print the virt flags in
/proc/cpuinfo.

Currently, it is difficult to check if a feature is supported in _KVM_.
Manually querying cpuid to know whether the feature is supported or not
can be quite tedious at times.

Print the features supported in KVM hypervisor in a dedicated "virt"
line instead of adding them to the common "flags".

To do so, define flags which are needed to be added in a dedicated virt
line in /proc/cpuinfo with prefix X86_VIRT_FEATURE_.

Signed-off-by: Manali Shukla <manali.shukla@amd.com>
---
 arch/x86/include/asm/cpufeature.h | 1 +
 arch/x86/kernel/cpu/mkcapflags.sh | 3 +++
 arch/x86/kernel/cpu/proc.c        | 5 +++++
 3 files changed, 9 insertions(+)

Comments

Sean Christopherson Oct. 1, 2024, 4:41 p.m. UTC | #1
On Tue, Oct 01, 2024, Manali Shukla wrote:
> Add support for generating Virtualization feature names in capflags.c
> and use the resulting x86_virt_flags to print the virt flags in
> /proc/cpuinfo.
> 
> Currently, it is difficult to check if a feature is supported in _KVM_.
> Manually querying cpuid to know whether the feature is supported or not
> can be quite tedious at times.
> 
> Print the features supported in KVM hypervisor in a dedicated "virt"
> line instead of adding them to the common "flags".

First off, printing flags in a separate section doesn't magically connect them
to KVM support.  E.g. if you cut this series after patch 2, BUS_LOCK_THRESHOLD
will show up in "virt" despite KVM not supporting the feature.

Second, deviating from the X86_FEATURE_* syntax will make it _harder_ for KVM to
manage its configuration.

Third, this is completely orthogonal to supporting bus lock threshold in KVM,
i.e. belongs in a separate series.
Manali Shukla Oct. 3, 2024, 11:05 a.m. UTC | #2
On 10/1/2024 10:11 PM, Sean Christopherson wrote:
> On Tue, Oct 01, 2024, Manali Shukla wrote:
>> Add support for generating Virtualization feature names in capflags.c
>> and use the resulting x86_virt_flags to print the virt flags in
>> /proc/cpuinfo.
>>
>> Currently, it is difficult to check if a feature is supported in _KVM_.
>> Manually querying cpuid to know whether the feature is supported or not
>> can be quite tedious at times.
>>
>> Print the features supported in KVM hypervisor in a dedicated "virt"
>> line instead of adding them to the common "flags".
> 
> First off, printing flags in a separate section doesn't magically connect them
> to KVM support.  E.g. if you cut this series after patch 2, BUS_LOCK_THRESHOLD
> will show up in "virt" despite KVM not supporting the feature.
> 
> Second, deviating from the X86_FEATURE_* syntax will make it _harder_ for KVM to
> manage its configuration.
> 
> Third, this is completely orthogonal to supporting bus lock threshold in KVM,
> i.e. belongs in a separate series.

Okay. I agree to your point. I will remove the patch from this series.

-Manali
diff mbox series

Patch

diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
index 0b9611da6c53..74c52bfd8cf2 100644
--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -41,6 +41,7 @@  enum cpuid_leafs
 #define x86_cap_flag_num(flag) ((flag) >> 5), ((flag) & 31)
 
 extern const char * const x86_cap_flags[NCAPINTS*32];
+extern const char * const x86_virt_flags[NCAPINTS*32];
 extern const char * const x86_power_flags[32];
 #define X86_CAP_FMT "%s"
 #define x86_cap_flag(flag) x86_cap_flags[flag]
diff --git a/arch/x86/kernel/cpu/mkcapflags.sh b/arch/x86/kernel/cpu/mkcapflags.sh
index 68f537347466..3671c7892c56 100644
--- a/arch/x86/kernel/cpu/mkcapflags.sh
+++ b/arch/x86/kernel/cpu/mkcapflags.sh
@@ -62,6 +62,9 @@  trap 'rm "$OUT"' EXIT
 	dump_array "x86_bug_flags" "NBUGINTS*32" "X86_BUG_" "NCAPINTS*32" $2
 	echo ""
 
+	dump_array "x86_virt_flags" "NCAPINTS*32" "X86_VIRT_FEATURE_" "" $2
+	echo ""
+
 	echo "#ifdef CONFIG_X86_VMX_FEATURE_NAMES"
 	echo "#ifndef _ASM_X86_VMXFEATURES_H"
 	echo "#include <asm/vmxfeatures.h>"
diff --git a/arch/x86/kernel/cpu/proc.c b/arch/x86/kernel/cpu/proc.c
index e65fae63660e..3068b0a110e4 100644
--- a/arch/x86/kernel/cpu/proc.c
+++ b/arch/x86/kernel/cpu/proc.c
@@ -103,6 +103,11 @@  static int show_cpuinfo(struct seq_file *m, void *v)
 		if (cpu_has(c, i) && x86_cap_flags[i] != NULL)
 			seq_printf(m, " %s", x86_cap_flags[i]);
 
+	seq_puts(m, "\nvirt\t\t:");
+	for (i = 0; i < 32*NCAPINTS; i++)
+		if (cpu_has(c, i) && x86_virt_flags[i] != NULL)
+			seq_printf(m, " %s", x86_virt_flags[i]);
+
 #ifdef CONFIG_X86_VMX_FEATURE_NAMES
 	if (cpu_has(c, X86_FEATURE_VMX) && c->vmx_capability[0]) {
 		seq_puts(m, "\nvmx flags\t:");