linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] tools/x86/kcpuid: Check last token too
@ 2021-03-15 12:59 Borislav Petkov
  2021-03-15 12:59 ` [PATCH 2/2] tools/x86/kcpuid: Add AMD leaf 0x8000001E Borislav Petkov
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Borislav Petkov @ 2021-03-15 12:59 UTC (permalink / raw)
  To: Feng Tang; +Cc: X86 ML, LKML

From: Borislav Petkov <bp@suse.de>

Input lines like

  0x8000001E,     0, EAX,   31:0, Extended APIC ID

where the short name is missing lead to a segfault because the loop
takes the long name for the short name and tokens[5] becomes NULL which
explodes later in strcpy().

Check its value too before further processing.

Signed-off-by: Borislav Petkov <bp@suse.de>
---
 tools/arch/x86/kcpuid/kcpuid.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/arch/x86/kcpuid/kcpuid.c b/tools/arch/x86/kcpuid/kcpuid.c
index 6048da34fcc6..dae75511fef7 100644
--- a/tools/arch/x86/kcpuid/kcpuid.c
+++ b/tools/arch/x86/kcpuid/kcpuid.c
@@ -324,6 +324,8 @@ static int parse_line(char *line)
 		str = NULL;
 	}
 	tokens[5] = strtok(str, "\n");
+	if (!tokens[5])
+		goto err_exit;
 
 	/* index/main-leaf */
 	index = strtoull(tokens[0], NULL, 0);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] tools/x86/kcpuid: Add AMD leaf 0x8000001E
  2021-03-15 12:59 [PATCH 1/2] tools/x86/kcpuid: Check last token too Borislav Petkov
@ 2021-03-15 12:59 ` Borislav Petkov
  2021-03-16  7:42   ` Feng Tang
  2021-03-18 10:38   ` [tip: x86/misc] " tip-bot2 for Borislav Petkov
  2021-03-16  7:34 ` [PATCH 1/2] tools/x86/kcpuid: Check last token too Feng Tang
  2021-03-18 10:38 ` [tip: x86/misc] " tip-bot2 for Borislav Petkov
  2 siblings, 2 replies; 9+ messages in thread
From: Borislav Petkov @ 2021-03-15 12:59 UTC (permalink / raw)
  To: Feng Tang; +Cc: X86 ML, LKML

From: Borislav Petkov <bp@suse.de>

Contains core IDs, node IDs and other topology info.

Signed-off-by: Borislav Petkov <bp@suse.de>
---
 tools/arch/x86/kcpuid/cpuid.csv | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/tools/arch/x86/kcpuid/cpuid.csv b/tools/arch/x86/kcpuid/cpuid.csv
index dd94c07421a8..4f1c4b0c29e9 100644
--- a/tools/arch/x86/kcpuid/cpuid.csv
+++ b/tools/arch/x86/kcpuid/cpuid.csv
@@ -379,12 +379,22 @@
 0x80000008,    0,  EAX,   15:8, lnr_adr_bits, Linear Address Bits
 0x80000007,    0,  EBX,      9, wbnoinvd, WBNOINVD
 
+# 0x8000001E
+# EAX: Extended APIC ID
+0x8000001E,	0, EAX,   31:0, extended_apic_id, Extended APIC ID
+# EBX: Core Identifiers
+0x8000001E,	0, EBX,    7:0, core_id, Identifies the logical core ID
+0x8000001E,	0, EBX,   15:8, threads_per_core, The number of threads per core is threads_per_core + 1
+# ECX: Node Identifiers
+0x8000001E,	0, ECX,    7:0, node_id, Node ID
+0x8000001E,	0, ECX,   10:8, nodes_per_processor, Nodes per processor { 0: 1 node, else reserved }
+
 # 8000001F: AMD Secure Encryption
-0x8000001F,	0, EAX, 0, sme,	Secure Memory Encryption
-0x8000001F,	0, EAX, 1, sev,	Secure Encrypted Virtualization
-0x8000001F,	0, EAX, 2, vmpgflush, VM Page Flush MSR
-0x8000001F,	0, EAX, 3, seves, SEV Encrypted State
-0x8000001F,	0, EBX, 5:0, c-bit, Page table bit number used to enable memory encryption
-0x8000001F,	0, EBX, 11:6, mem_encrypt_physaddr_width, Reduction of physical address space in bits with SME enabled
-0x8000001F,	0, ECX, 31:0, num_encrypted_guests, Maximum ASID value that may be used for an SEV-enabled guest
-0x8000001F,	0, EDX, 31:0, minimum_sev_asid, Minimum ASID value that must be used for an SEV-enabled, SEV-ES-disabled guest
+0x8000001F,	0, EAX,	     0, sme,	Secure Memory Encryption
+0x8000001F,	0, EAX,      1, sev,	Secure Encrypted Virtualization
+0x8000001F,	0, EAX,      2, vmpgflush, VM Page Flush MSR
+0x8000001F,	0, EAX,      3, seves, SEV Encrypted State
+0x8000001F,	0, EBX,    5:0, c-bit, Page table bit number used to enable memory encryption
+0x8000001F,	0, EBX,   11:6, mem_encrypt_physaddr_width, Reduction of physical address space in bits with SME enabled
+0x8000001F,	0, ECX,   31:0, num_encrypted_guests, Maximum ASID value that may be used for an SEV-enabled guest
+0x8000001F,	0, EDX,   31:0, minimum_sev_asid, Minimum ASID value that must be used for an SEV-enabled, SEV-ES-disabled guest
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] tools/x86/kcpuid: Check last token too
  2021-03-15 12:59 [PATCH 1/2] tools/x86/kcpuid: Check last token too Borislav Petkov
  2021-03-15 12:59 ` [PATCH 2/2] tools/x86/kcpuid: Add AMD leaf 0x8000001E Borislav Petkov
@ 2021-03-16  7:34 ` Feng Tang
  2021-03-18 10:38 ` [tip: x86/misc] " tip-bot2 for Borislav Petkov
  2 siblings, 0 replies; 9+ messages in thread
From: Feng Tang @ 2021-03-16  7:34 UTC (permalink / raw)
  To: Borislav Petkov; +Cc: X86 ML, LKML

On Mon, Mar 15, 2021 at 01:59:00PM +0100, Borislav Petkov wrote:
> From: Borislav Petkov <bp@suse.de>
> 
> Input lines like
> 
>   0x8000001E,     0, EAX,   31:0, Extended APIC ID
> 
> where the short name is missing lead to a segfault because the loop
> takes the long name for the short name and tokens[5] becomes NULL which
> explodes later in strcpy().
> 
> Check its value too before further processing.
 
Thanks for the fix!

Acked-by: Feng Tang <feng.tang@intel.com>

> Signed-off-by: Borislav Petkov <bp@suse.de>
> ---
>  tools/arch/x86/kcpuid/kcpuid.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/tools/arch/x86/kcpuid/kcpuid.c b/tools/arch/x86/kcpuid/kcpuid.c
> index 6048da34fcc6..dae75511fef7 100644
> --- a/tools/arch/x86/kcpuid/kcpuid.c
> +++ b/tools/arch/x86/kcpuid/kcpuid.c
> @@ -324,6 +324,8 @@ static int parse_line(char *line)
>  		str = NULL;
>  	}
>  	tokens[5] = strtok(str, "\n");
> +	if (!tokens[5])
> +		goto err_exit;
>  
>  	/* index/main-leaf */
>  	index = strtoull(tokens[0], NULL, 0);
> -- 
> 2.29.2

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] tools/x86/kcpuid: Add AMD leaf 0x8000001E
  2021-03-15 12:59 ` [PATCH 2/2] tools/x86/kcpuid: Add AMD leaf 0x8000001E Borislav Petkov
@ 2021-03-16  7:42   ` Feng Tang
  2021-03-16 14:28     ` Borislav Petkov
  2021-03-18 10:38   ` [tip: x86/misc] " tip-bot2 for Borislav Petkov
  1 sibling, 1 reply; 9+ messages in thread
From: Feng Tang @ 2021-03-16  7:42 UTC (permalink / raw)
  To: Borislav Petkov; +Cc: X86 ML, LKML

On Mon, Mar 15, 2021 at 01:59:01PM +0100, Borislav Petkov wrote:
> From: Borislav Petkov <bp@suse.de>
> 
> Contains core IDs, node IDs and other topology info.
> 
> Signed-off-by: Borislav Petkov <bp@suse.de>

Acked-by: Feng Tang <feng.tang@intel.com>

Also I'm wondering for some basic leaf and extended leaf which
may has different definition for different vendors, do we need
to seprate the csv to a general one and vendor specific ones.

Thanks,
Feng

> ---
>  tools/arch/x86/kcpuid/cpuid.csv | 26 ++++++++++++++++++--------
>  1 file changed, 18 insertions(+), 8 deletions(-)
> 
> diff --git a/tools/arch/x86/kcpuid/cpuid.csv b/tools/arch/x86/kcpuid/cpuid.csv
> index dd94c07421a8..4f1c4b0c29e9 100644
> --- a/tools/arch/x86/kcpuid/cpuid.csv
> +++ b/tools/arch/x86/kcpuid/cpuid.csv
> @@ -379,12 +379,22 @@
>  0x80000008,    0,  EAX,   15:8, lnr_adr_bits, Linear Address Bits
>  0x80000007,    0,  EBX,      9, wbnoinvd, WBNOINVD
>  
> +# 0x8000001E
> +# EAX: Extended APIC ID
> +0x8000001E,	0, EAX,   31:0, extended_apic_id, Extended APIC ID
> +# EBX: Core Identifiers
> +0x8000001E,	0, EBX,    7:0, core_id, Identifies the logical core ID
> +0x8000001E,	0, EBX,   15:8, threads_per_core, The number of threads per core is threads_per_core + 1
> +# ECX: Node Identifiers
> +0x8000001E,	0, ECX,    7:0, node_id, Node ID
> +0x8000001E,	0, ECX,   10:8, nodes_per_processor, Nodes per processor { 0: 1 node, else reserved }
> +
>  # 8000001F: AMD Secure Encryption
> -0x8000001F,	0, EAX, 0, sme,	Secure Memory Encryption
> -0x8000001F,	0, EAX, 1, sev,	Secure Encrypted Virtualization
> -0x8000001F,	0, EAX, 2, vmpgflush, VM Page Flush MSR
> -0x8000001F,	0, EAX, 3, seves, SEV Encrypted State
> -0x8000001F,	0, EBX, 5:0, c-bit, Page table bit number used to enable memory encryption
> -0x8000001F,	0, EBX, 11:6, mem_encrypt_physaddr_width, Reduction of physical address space in bits with SME enabled
> -0x8000001F,	0, ECX, 31:0, num_encrypted_guests, Maximum ASID value that may be used for an SEV-enabled guest
> -0x8000001F,	0, EDX, 31:0, minimum_sev_asid, Minimum ASID value that must be used for an SEV-enabled, SEV-ES-disabled guest
> +0x8000001F,	0, EAX,	     0, sme,	Secure Memory Encryption
> +0x8000001F,	0, EAX,      1, sev,	Secure Encrypted Virtualization
> +0x8000001F,	0, EAX,      2, vmpgflush, VM Page Flush MSR
> +0x8000001F,	0, EAX,      3, seves, SEV Encrypted State
> +0x8000001F,	0, EBX,    5:0, c-bit, Page table bit number used to enable memory encryption
> +0x8000001F,	0, EBX,   11:6, mem_encrypt_physaddr_width, Reduction of physical address space in bits with SME enabled
> +0x8000001F,	0, ECX,   31:0, num_encrypted_guests, Maximum ASID value that may be used for an SEV-enabled guest
> +0x8000001F,	0, EDX,   31:0, minimum_sev_asid, Minimum ASID value that must be used for an SEV-enabled, SEV-ES-disabled guest
> -- 
> 2.29.2

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] tools/x86/kcpuid: Add AMD leaf 0x8000001E
  2021-03-16  7:42   ` Feng Tang
@ 2021-03-16 14:28     ` Borislav Petkov
  2021-03-16 17:04       ` Sean Christopherson
  0 siblings, 1 reply; 9+ messages in thread
From: Borislav Petkov @ 2021-03-16 14:28 UTC (permalink / raw)
  To: Feng Tang; +Cc: X86 ML, LKML

On Tue, Mar 16, 2021 at 03:42:23PM +0800, Feng Tang wrote:
> Also I'm wondering for some basic leaf and extended leaf which
> may has different definition for different vendors, do we need
> to seprate the csv to a general one and vendor specific ones.

Do you know of such?

Because AFAIK vendors own, more or less, each range. Like, Intel owns
the base range and AMD the extended so there should be no conflicts
actually...

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] tools/x86/kcpuid: Add AMD leaf 0x8000001E
  2021-03-16 14:28     ` Borislav Petkov
@ 2021-03-16 17:04       ` Sean Christopherson
  2021-03-17  0:30         ` Feng Tang
  0 siblings, 1 reply; 9+ messages in thread
From: Sean Christopherson @ 2021-03-16 17:04 UTC (permalink / raw)
  To: Borislav Petkov; +Cc: Feng Tang, X86 ML, LKML

On Tue, Mar 16, 2021, Borislav Petkov wrote:
> On Tue, Mar 16, 2021 at 03:42:23PM +0800, Feng Tang wrote:
> > Also I'm wondering for some basic leaf and extended leaf which
> > may has different definition for different vendors, do we need
> > to seprate the csv to a general one and vendor specific ones.
> 
> Do you know of such?
> 
> Because AFAIK vendors own, more or less, each range. Like, Intel owns
> the base range and AMD the extended so there should be no conflicts
> actually...

There are no known conflicts, and all sorts of things would break horribly if
any CPU vendor (or hypervsior) were careless enough to redefine a CPUID bit.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] tools/x86/kcpuid: Add AMD leaf 0x8000001E
  2021-03-16 17:04       ` Sean Christopherson
@ 2021-03-17  0:30         ` Feng Tang
  0 siblings, 0 replies; 9+ messages in thread
From: Feng Tang @ 2021-03-17  0:30 UTC (permalink / raw)
  To: Sean Christopherson; +Cc: Borislav Petkov, X86 ML, LKML

Hi Boris and Sean,

On Tue, Mar 16, 2021 at 10:04:44AM -0700, Sean Christopherson wrote:
> On Tue, Mar 16, 2021, Borislav Petkov wrote:
> > On Tue, Mar 16, 2021 at 03:42:23PM +0800, Feng Tang wrote:
> > > Also I'm wondering for some basic leaf and extended leaf which
> > > may has different definition for different vendors, do we need
> > > to seprate the csv to a general one and vendor specific ones.
> > 
> > Do you know of such?

No. When I read the patch, I googled some doc for the registers definition
which I found different from Intel's manual.

> > 
> > Because AFAIK vendors own, more or less, each range. Like, Intel owns
> > the base range and AMD the extended so there should be no conflicts
> > actually...
> 
> There are no known conflicts, and all sorts of things would break horribly if
> any CPU vendor (or hypervsior) were careless enough to redefine a CPUID bit.

Great to know these sharing policy between vendors, which will save many
troubles for us :)

Also I just took a look at code of cpuid, which has some functions like
	print_leafX_vendorA
	print_leafX_vendorB
	print_leafX_vendorC
but as you mentioned, I didn't find obvious overlaps of specific bits.

Thanks,
Feng

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [tip: x86/misc] tools/x86/kcpuid: Add AMD leaf 0x8000001E
  2021-03-15 12:59 ` [PATCH 2/2] tools/x86/kcpuid: Add AMD leaf 0x8000001E Borislav Petkov
  2021-03-16  7:42   ` Feng Tang
@ 2021-03-18 10:38   ` tip-bot2 for Borislav Petkov
  1 sibling, 0 replies; 9+ messages in thread
From: tip-bot2 for Borislav Petkov @ 2021-03-18 10:38 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Borislav Petkov, Feng Tang, x86, linux-kernel

The following commit has been merged into the x86/misc branch of tip:

Commit-ID:     f281854fa743f3474b2d0d69533301f48cf0e184
Gitweb:        https://git.kernel.org/tip/f281854fa743f3474b2d0d69533301f48cf0e184
Author:        Borislav Petkov <bp@suse.de>
AuthorDate:    Mon, 15 Mar 2021 13:55:14 +01:00
Committer:     Borislav Petkov <bp@suse.de>
CommitterDate: Thu, 18 Mar 2021 11:36:14 +01:00

tools/x86/kcpuid: Add AMD leaf 0x8000001E

Contains core IDs, node IDs and other topology info.

Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Feng Tang <feng.tang@intel.com>
Link: https://lkml.kernel.org/r/20210315125901.30315-2-bp@alien8.de
---
 tools/arch/x86/kcpuid/cpuid.csv | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/tools/arch/x86/kcpuid/cpuid.csv b/tools/arch/x86/kcpuid/cpuid.csv
index dd94c07..4f1c4b0 100644
--- a/tools/arch/x86/kcpuid/cpuid.csv
+++ b/tools/arch/x86/kcpuid/cpuid.csv
@@ -379,12 +379,22 @@
 0x80000008,    0,  EAX,   15:8, lnr_adr_bits, Linear Address Bits
 0x80000007,    0,  EBX,      9, wbnoinvd, WBNOINVD
 
+# 0x8000001E
+# EAX: Extended APIC ID
+0x8000001E,	0, EAX,   31:0, extended_apic_id, Extended APIC ID
+# EBX: Core Identifiers
+0x8000001E,	0, EBX,    7:0, core_id, Identifies the logical core ID
+0x8000001E,	0, EBX,   15:8, threads_per_core, The number of threads per core is threads_per_core + 1
+# ECX: Node Identifiers
+0x8000001E,	0, ECX,    7:0, node_id, Node ID
+0x8000001E,	0, ECX,   10:8, nodes_per_processor, Nodes per processor { 0: 1 node, else reserved }
+
 # 8000001F: AMD Secure Encryption
-0x8000001F,	0, EAX, 0, sme,	Secure Memory Encryption
-0x8000001F,	0, EAX, 1, sev,	Secure Encrypted Virtualization
-0x8000001F,	0, EAX, 2, vmpgflush, VM Page Flush MSR
-0x8000001F,	0, EAX, 3, seves, SEV Encrypted State
-0x8000001F,	0, EBX, 5:0, c-bit, Page table bit number used to enable memory encryption
-0x8000001F,	0, EBX, 11:6, mem_encrypt_physaddr_width, Reduction of physical address space in bits with SME enabled
-0x8000001F,	0, ECX, 31:0, num_encrypted_guests, Maximum ASID value that may be used for an SEV-enabled guest
-0x8000001F,	0, EDX, 31:0, minimum_sev_asid, Minimum ASID value that must be used for an SEV-enabled, SEV-ES-disabled guest
+0x8000001F,	0, EAX,	     0, sme,	Secure Memory Encryption
+0x8000001F,	0, EAX,      1, sev,	Secure Encrypted Virtualization
+0x8000001F,	0, EAX,      2, vmpgflush, VM Page Flush MSR
+0x8000001F,	0, EAX,      3, seves, SEV Encrypted State
+0x8000001F,	0, EBX,    5:0, c-bit, Page table bit number used to enable memory encryption
+0x8000001F,	0, EBX,   11:6, mem_encrypt_physaddr_width, Reduction of physical address space in bits with SME enabled
+0x8000001F,	0, ECX,   31:0, num_encrypted_guests, Maximum ASID value that may be used for an SEV-enabled guest
+0x8000001F,	0, EDX,   31:0, minimum_sev_asid, Minimum ASID value that must be used for an SEV-enabled, SEV-ES-disabled guest

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [tip: x86/misc] tools/x86/kcpuid: Check last token too
  2021-03-15 12:59 [PATCH 1/2] tools/x86/kcpuid: Check last token too Borislav Petkov
  2021-03-15 12:59 ` [PATCH 2/2] tools/x86/kcpuid: Add AMD leaf 0x8000001E Borislav Petkov
  2021-03-16  7:34 ` [PATCH 1/2] tools/x86/kcpuid: Check last token too Feng Tang
@ 2021-03-18 10:38 ` tip-bot2 for Borislav Petkov
  2 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Borislav Petkov @ 2021-03-18 10:38 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Borislav Petkov, Feng Tang, x86, linux-kernel

The following commit has been merged into the x86/misc branch of tip:

Commit-ID:     e20f67026b5ead2afc5627e98b45e6b65e7fb38c
Gitweb:        https://git.kernel.org/tip/e20f67026b5ead2afc5627e98b45e6b65e7fb38c
Author:        Borislav Petkov <bp@suse.de>
AuthorDate:    Mon, 15 Mar 2021 13:08:35 +01:00
Committer:     Borislav Petkov <bp@suse.de>
CommitterDate: Thu, 18 Mar 2021 11:36:01 +01:00

tools/x86/kcpuid: Check last token too

Input lines like

  0x8000001E,     0, EAX,   31:0, Extended APIC ID

where the short name is missing lead to a segfault because the loop
takes the long name for the short name and tokens[5] becomes NULL which
explodes later in strcpy().

Check its value too before further processing.

Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Feng Tang <feng.tang@intel.com>
Link: https://lkml.kernel.org/r/20210315125901.30315-1-bp@alien8.de
---
 tools/arch/x86/kcpuid/kcpuid.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/arch/x86/kcpuid/kcpuid.c b/tools/arch/x86/kcpuid/kcpuid.c
index 6048da3..dae7551 100644
--- a/tools/arch/x86/kcpuid/kcpuid.c
+++ b/tools/arch/x86/kcpuid/kcpuid.c
@@ -324,6 +324,8 @@ static int parse_line(char *line)
 		str = NULL;
 	}
 	tokens[5] = strtok(str, "\n");
+	if (!tokens[5])
+		goto err_exit;
 
 	/* index/main-leaf */
 	index = strtoull(tokens[0], NULL, 0);

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-03-18 10:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-15 12:59 [PATCH 1/2] tools/x86/kcpuid: Check last token too Borislav Petkov
2021-03-15 12:59 ` [PATCH 2/2] tools/x86/kcpuid: Add AMD leaf 0x8000001E Borislav Petkov
2021-03-16  7:42   ` Feng Tang
2021-03-16 14:28     ` Borislav Petkov
2021-03-16 17:04       ` Sean Christopherson
2021-03-17  0:30         ` Feng Tang
2021-03-18 10:38   ` [tip: x86/misc] " tip-bot2 for Borislav Petkov
2021-03-16  7:34 ` [PATCH 1/2] tools/x86/kcpuid: Check last token too Feng Tang
2021-03-18 10:38 ` [tip: x86/misc] " tip-bot2 for Borislav Petkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).