add reporting of SVM flags to /proc/cpuinfo
cover add reporting of SVM flags to /proc/cpuinfo
This small patch series introduces the reporting of the SVM revision, the number of ASIDs and the flags in /proc/cpuinfo on SVM capable AMD processors. The patches are for i386 and for x86_64 architectures.
Signature · 3 lines
Joerg Roedel Operating System Research Center AMD Saxony LLC & Co. KG
PATCH 1/2 x86_64: add reporting of SVM flags to /proc/cpuinfo
From: Joerg Roedel <[email protected]>
This patch adds the advanced SVM reporting to /proc/cpuinfo on the x86_64 architecture.
Signature · 3 lines
Joerg Roedel Operating System Research Center AMD Saxony LLC & Co. KG
arch/x86_64/kernel/setup.c +31 -1
@@ -612,6 +612,13 @@ static void __cpuinit init_amd(struct cpuinfo_x86 *c)/* RDTSC can be speculated around */ clear_bit (X86_FEATURE_SYNC_RDTSC , &c->x86_capability); + +/* SVM specific flags and information */ +if (cpu_has (c,X86_FEATURE_SVM )) { + c->svm.svm_rev = (__u8)(cpuid_eax (0x8000000a ) &0xff ); + c->svm.svm_asids =cpuid_ebx (0x8000000a ); + c->svm.svm_flags =cpuid_edx (0x8000000a ); + } }static void __cpuinit detect_ht (struct cpuinfo_x86 *c)
@@ -992,6 +999,11 @@ static int show_cpuinfo(struct seq_file *m, void *v)/* nothing */ /* constant_tsc - moved to flags */ }; +static char *x86_svm_flags[] = { +"npt" , +"lbrv" , +"svmlock" , + };#ifdef CONFIG_SMP if (!cpu_online (c-cpu_data))
@@ -1076,9 +1088,27 @@ static int show_cpuinfo(struct seq_file *m, void *v)else seq_printf (m," [%d]" , i); } +seq_printf (m,"\n" ); + } + +if (cpu_has (c,X86_FEATURE_SVM )) { +unsigned i, first=1 ; +seq_printf (m,"SVM features\t: rev=%hd #asids=%u flags=(" , + c->svm.svm_rev, c->svm.svm_asids); +for (i=0 ;i<ARRAY_SIZE (x86_svm_flags);++i) { +if (c->svm.svm_flags & (1 << i)) { +seq_printf (m,"%s" , first ?"" :" " ); + first =0 ; +if (x86_svm_flags[i]) +seq_printf (m,"%s" , x86_svm_flags[i]); +else +seq_printf (m,"[%d]" , i); + } + } +seq_printf (m,")\n" ); } -seq_printf (m,"\n\n" ); +seq_printf (m,"\n" );return 0 ; }
include/asm-x86_64/cpufeature.h +1 -0
@@ -90,6 +90,7 @@/* More extended AMD flags: CPUID level 0x80000001, ecx, word 6 */ #define X86_FEATURE_LAHF_LM (6*32+ 0)/* LAHF/SAHF in long mode */ #define X86_FEATURE_CMP_LEGACY (6*32+ 1)/* If yes HyperThreading not valid */ +#define X86_FEATURE_SVM (6*32+ 2)/* Secure Virtual Machine */ #define cpu_has (c, bit) test_bit(bit, (c)->x86_capability)#define boot_cpu_has (bit) test_bit(bit, boot_cpu_data.x86_capability)
include/asm-x86_64/processor.h +11 -0
@@ -43,6 +43,15 @@*/ #define current_text_addr () ({ void *pc; asm volatile("leaq 1f(%%rip),%0\n1:":"=r"(pc)); pc; }) +/* +* SVM flags subtype - used in struct cpuinfo_x86 +*/ +struct cpu_svm_info { +__u8 svm_rev; +__u32 svm_asids; +__u32 svm_flags; +}; +/* * CPU type and hardware bug flags. Kept separately for each CPU. */
@@ -73,6 +82,8 @@ struct cpuinfo_x86 {__u8 booted_cores;/* number of cores as seen by OS */ __u8 phys_proc_id;/* Physical Processor id. */ __u8 cpu_core_id;/* Core id. */ + +struct cpu_svm_info svm;/* SVM specific feature flags */ #endif }____cacheline_aligned ;
Re: [PATCH 1/2] x86_64: add reporting of SVM flags to /proc/cpuinfo
arch/x86_64/kernel/setup.c static int show_cpuinfo(struct seq_file *m, void *v) · line 1006
Quoted 6 lines · Joerg Roedel
+++
b/arch/x86_64/kernel/setup.carch/x86_64/kernel/setup.c +5
-0+static char *x86_svm_flags[] = { +"npt" , +"lbrv" , +"svmlock" , + };
A nitpick:
static const char *const x86_svm_flags[] = ... ?
/mjt
Re: [PATCH 1/2] x86_64: add reporting of SVM flags to /proc/cpuinfo
Quoted 11 lines · Michael Tokarev
arch/x86_64/kernel/setup.c static int show_cpuinfo(struct seq_file *m, void *v) · line 1006
Quoted 6 lines · Joerg Roedel
+++
b/arch/x86_64/kernel/setup.carch/x86_64/kernel/setup.c +5
-0+static char *x86_svm_flags[] = { +"npt" , +"lbrv" , +"svmlock" , + };A nitpick:
static const char *const x86_svm_flags[] = ... ?
Right. Its better to mark the array as const. Will wait for more comments and send an updated patch soon.
Thanks,
Joerg
Signature · 3 lines
Joerg Roedel Operating System Research Center AMD Saxony LLC & Co. KG
Re: [PATCH 1/2] x86_64: add reporting of SVM flags to /proc/cpuinfo
In reply to Joerg RoedelQuoted 4 lines · Joerg Roedel
From: Joerg Roedel <[email protected]>
This patch adds the advanced SVM reporting to
/proc/cpuinfoon thex86_64architecture.
Adding more fields to /proc/cpuinfo is always somewhat risky because there are lots of badly written parsers for it.
I considered adding the SVM fields myself, but decided against it because it didn't seem generally useful enough.
-Andi
Re: [discuss] [PATCH 1/2] x86_64: add reporting of SVM flags to /proc/cpuinfo
Quoted 11 lines · Andi Kleen
Quoted 4 lines · Joerg Roedel
From: Joerg Roedel <[email protected]>
This patch adds the advanced SVM reporting to
/proc/cpuinfoon thex86_64architecture.Adding more fields to
/proc/cpuinfois always somewhat risky because there are lots of badly written parsers for it.I considered adding the SVM fields myself, but decided against it because it didn't seem generally useful enough.
Agreed. I'm more than happy to take patches to x86info however :)
Dave
Signature · 1 line
http://www.codemonkey.org.uk
Re: [PATCH 1/2] x86_64: add reporting of SVM flags to /proc/cpuinfo
In reply to Andi KleenQuoted 8 lines · Andi Kleen
Quoted 4 lines · Joerg Roedel
From: Joerg Roedel <[email protected]>
This patch adds the advanced SVM reporting to
/proc/cpuinfoon thex86_64architecture.Adding more fields to
/proc/cpuinfois always somewhat risky because there are lots of badly written parsers for it.
Can you point me to some really broken parsers of /proc/cpuinfo to test with?
Quoted 2 lines
I considered adding the SVM fields myself, but decided against it because it didn't seem generally useful enough.
I don't see that this is less important than the power flags in that file. Some users might be interested to see if their processor has npt for example by simply looking into cpuinfo.
As I said, would be interested to know more about these badly written parsers.
Joerg
Signature · 3 lines
Joerg Roedel Operating System Research Center AMD Saxony LLC & Co. KG
PATCH 2/2 i386: add reporting of SVM flags to /proc/cpuinfo
In reply to Joerg RoedelFrom: Joerg Roedel <[email protected]>
This patch adds the advanced SVM reporting in /proc/cpuinfo to the i386 architecture.
Signature · 3 lines
Joerg Roedel Operating System Research Center AMD Saxony LLC & Co. KG
arch/i386/kernel/cpu/amd.c +7 -0
@@ -241,6 +241,13 @@ static void __cpuinit init_amd(struct cpuinfo_x86 *c)if (cpuid_eax (0x80000000 ) >=0x80000006 ) num_cache_leaves =3 ; + +/* SVM specific flags and information */ +if (cpu_has (c,X86_FEATURE_SVM )) { + c->svm.svm_rev = (__u8)(cpuid_eax (0x8000000a ) &0xff ); + c->svm.svm_asids =cpuid_ebx (0x8000000a ); + c->svm.svm_flags =cpuid_edx (0x8000000a ); + } }static unsigned int __cpuinit amd_size_cache (struct cpuinfo_x86 * c,unsigned int size)
arch/i386/kernel/cpu/proc.c +26 -1
@@ -76,6 +76,13 @@ static int show_cpuinfo(struct seq_file *m, void *v) NULL, /* constant_tsc - moved to flags *//* nothing */ }; + +static char *x86_svm_flags[] = { +"npt" , +"lbrv" , +"svmlock" , + }; +struct cpuinfo_x86 *c = v;int i, n = c - cpu_data;int fpu_exception;
@@ -159,7 +166,25 @@ static int show_cpuinfo(struct seq_file *m, void *v)seq_printf (m,"\nbogomips\t: %lu.%02lu\n" , c->loops_per_jiffy/(500000 /HZ ), (c->loops_per_jiffy/(5000 /HZ )) %100 ); -seq_printf (m,"clflush size\t: %u\n\n" , c->x86_clflush_size); +seq_printf (m,"clflush size\t: %u\n" , c->x86_clflush_size); + +if (cpu_has (c,X86_FEATURE_SVM )) { +unsigned i, first=1 ; +seq_printf (m,"SVM features\t: rev=%hd #asids=%u flags=(" , + c->svm.svm_rev, c->svm.svm_asids); +for (i=0 ;i<ARRAY_SIZE (x86_svm_flags);++i) { +if (c->svm.svm_flags & (1 << i)) { +seq_printf (m,"%s" , first ?"" :" " ); + first =0 ; +if (x86_svm_flags[i]) +seq_printf (m,"%s" , x86_svm_flags[i]); +else +seq_printf (m,"[%d]" , i); + } + } +seq_printf (m,")\n" ); + } +seq_printf (m,"\n" );return 0 ; }
include/asm-i386/cpufeature.h +1 -0
@@ -101,6 +101,7 @@/* More extended AMD flags: CPUID level 0x80000001, ecx, word 6 */ #define X86_FEATURE_LAHF_LM (6*32+ 0)/* LAHF/SAHF in long mode */ #define X86_FEATURE_CMP_LEGACY (6*32+ 1)/* If yes HyperThreading not valid */ +#define X86_FEATURE_SVM (6*32+ 2)/* Secure Virtual Machine */ #define cpu_has (c, bit) test_bit(bit, (c)->x86_capability)#define boot_cpu_has (bit) test_bit(bit, boot_cpu_data.x86_capability)
include/asm-i386/processor.h +10 -0
@@ -41,6 +41,15 @@ struct desc_struct {#define current_text_addr () ({ void *pc; __asm__("movl $1f,%0\n1:":"=g" (pc)); pc; })/* +* SVM flags subtype - used in struct cpuinfo_x86 +*/ +struct cpu_svm_info { +__u8 svm_rev; +__u32 svm_asids; +__u32 svm_flags; +}; + +/* * CPU type and hardware bug flags. Kept separately for each CPU. * Members of this structure are referenced in head.S, so think twice * before touching them. [mj]
@@ -79,6 +88,7 @@ struct cpuinfo_x86 {__u8 phys_proc_id;/* Physical processor id. */ __u8 cpu_core_id;/* Core id */ #endif +struct cpu_svm_info svm; } __attribute__((__aligned__(SMP_CACHE_BYTES)));#define X86_VENDOR_INTEL 0