LoongArch: Correct the calculation logic of thread_count
PATCH 1/1 LoongArch: Correct the calculation logic of thread_count
For thread_count, the current calculation method has a maximum of 255, which may not be sufficient in the future. Therefore, we are correcting it now.
Reference: SMBIOS Specification, 7.5 Processor Information (Type 4)[1]
[1]: https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.9.0.pdf
--- arch/loongarch/kernel/setup.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
arch/loongarch/kernel/setup.c +8 -1
@@ -56,6 +56,7 @@#define SMBIOS_FREQLOW_MASK 0xFF#define SMBIOS_CORE_PACKAGE_OFFSET 0x23#define SMBIOS_THREAD_PACKAGE_OFFSET 0x25 +#define SMBIOS_THREAD_PACKAGE_2_OFFSET 0x2E#define LOONGSON_EFI_ENABLE (1 << 3)unsigned long fw_arg0, fw_arg1, fw_arg2;
@@ -120,13 +121,19 @@ static void __init parse_cpu_table(const struct dmi_header *dm) {long freq_temp =0 ;char *dmi_data = (char *)dm; +u8 thread_count; +u16 thread_count2; freq_temp = ((*(dmi_data +SMBIOS_FREQHIGH_OFFSET ) <<8 ) + ((*(dmi_data +SMBIOS_FREQLOW_OFFSET )) &SMBIOS_FREQLOW_MASK )); cpu_clock_freq = freq_temp *1000000 ; loongson_sysconf.cpuname = (void *)dmi_string_parse (dm, dmi_data[16 ]); - loongson_sysconf.cores_per_package = *(dmi_data +SMBIOS_THREAD_PACKAGE_OFFSET ); + thread_count = *(dmi_data +SMBIOS_THREAD_PACKAGE_OFFSET ); + thread_count2 = *(u16 *)(dmi_data +SMBIOS_THREAD_PACKAGE_2_OFFSET ); +if (thread_count !=0 ) + loongson_sysconf.cores_per_package = dm->length >=0x30 && thread_count ==0xFF ? + thread_count2 : thread_count;pr_info ("CpuClock = %llu\n" , cpu_clock_freq); }
Signature · 1 line
2.20.1
Huacai Chen
maintainerHi, Qiang,
Quoted 4 lines · Qiang Ma
For
thread_count, the current calculation method has a maximum of 255, which may not be sufficient in the future. Therefore, we are correcting it now.
I think you should contact the Loongson BIOS team to confirm they will do so.
And we can hardly meet the case that one socket contains more than 256 cores (this is different from the case MAX_CPUS > 256)
Huacai
Quoted 46 lines
Reference: SMBIOS Specification, 7.5 Processor Information (Type 4)[1]
[1]: https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.9.0.pdf
Signed-off-by Qiang Ma <[email protected]>--- arch/loongarch/kernel/setup.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)arch/loongarch/kernel/setup.c +8
-2@@ -56,6 +56,7 @@#define SMBIOS_FREQLOW_MASK 0xFF#define SMBIOS_CORE_PACKAGE_OFFSET 0x23#define SMBIOS_THREAD_PACKAGE_OFFSET 0x25 +#define SMBIOS_THREAD_PACKAGE_2_OFFSET 0x2E#define LOONGSON_EFI_ENABLE (1 << 3)unsigned long fw_arg0, fw_arg1, fw_arg2;@@ -120,13 +121,19 @@ static void __init parse_cpu_table(const struct dmi_header *dm) {long freq_temp =0 ;char *dmi_data = (char *)dm; +u8 thread_count; +u16 thread_count2; freq_temp = ((*(dmi_data +SMBIOS_FREQHIGH_OFFSET ) <<8 ) + ((*(dmi_data +SMBIOS_FREQLOW_OFFSET )) &SMBIOS_FREQLOW_MASK )); cpu_clock_freq = freq_temp *1000000 ; loongson_sysconf.cpuname = (void *)dmi_string_parse (dm, dmi_data[16 ]); - loongson_sysconf.cores_per_package = *(dmi_data +SMBIOS_THREAD_PACKAGE_OFFSET ); + thread_count = *(dmi_data +SMBIOS_THREAD_PACKAGE_OFFSET ); + thread_count2 = *(u16 *)(dmi_data +SMBIOS_THREAD_PACKAGE_2_OFFSET ); +if (thread_count !=0 ) + loongson_sysconf.cores_per_package = dm->length >=0x30 && thread_count ==0xFF ? + thread_count2 : thread_count;pr_info ("CpuClock = %llu\n" , cpu_clock_freq); } --2.20.1
Quoted 7 lines · Huacai Chen
Hi, Qiang,
Quoted 3 lines · Qiang Ma
For
thread_count, the current calculation method has a maximum of 255, which may not be sufficient in the future. Therefore, we are correcting it now.I think you should contact the Loongson BIOS team to confirm they will do so.
I contacted Li Chao from the Loongson BIOS team and had a brief communication.
bios will do this when it exceeds 256.
Quoted 3 lines
And we can hardly meet the case that one socket contains more than 256 cores (this is different from the case
MAX_CPUS> 256)
According to Li Chao, the 256 logic core on a single chip should arrive in the next generation.
Quoted 47 lines
Huacai
Quoted 45 lines
Reference: SMBIOS Specification, 7.5 Processor Information (Type 4)[1]
[1]: https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.9.0.pdf
Signed-off-by Qiang Ma <[email protected]>--- arch/loongarch/kernel/setup.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)arch/loongarch/kernel/setup.c +8
-2@@ -56,6 +56,7 @@#define SMBIOS_FREQLOW_MASK 0xFF#define SMBIOS_CORE_PACKAGE_OFFSET 0x23#define SMBIOS_THREAD_PACKAGE_OFFSET 0x25 +#define SMBIOS_THREAD_PACKAGE_2_OFFSET 0x2E#define LOONGSON_EFI_ENABLE (1 << 3)unsigned long fw_arg0, fw_arg1, fw_arg2;@@ -120,13 +121,19 @@ static void __init parse_cpu_table(const struct dmi_header *dm) {long freq_temp =0 ;char *dmi_data = (char *)dm; +u8 thread_count; +u16 thread_count2; freq_temp = ((*(dmi_data +SMBIOS_FREQHIGH_OFFSET ) <<8 ) + ((*(dmi_data +SMBIOS_FREQLOW_OFFSET )) &SMBIOS_FREQLOW_MASK )); cpu_clock_freq = freq_temp *1000000 ; loongson_sysconf.cpuname = (void *)dmi_string_parse (dm, dmi_data[16 ]); - loongson_sysconf.cores_per_package = *(dmi_data +SMBIOS_THREAD_PACKAGE_OFFSET ); + thread_count = *(dmi_data +SMBIOS_THREAD_PACKAGE_OFFSET ); + thread_count2 = *(u16 *)(dmi_data +SMBIOS_THREAD_PACKAGE_2_OFFSET ); +if (thread_count !=0 ) + loongson_sysconf.cores_per_package = dm->length >=0x30 && thread_count ==0xFF ? + thread_count2 : thread_count;pr_info ("CpuClock = %llu\n" , cpu_clock_freq); } --2.20.1
Quoted 31 lines · Qiang Ma
For
thread_count, the current calculation method has a maximum of 255, which may not be sufficient in the future. Therefore, we are correcting it now.Reference: SMBIOS Specification, 7.5 Processor Information (Type 4)[1]
[1]: https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.9.0.pdf
Signed-off-by Qiang Ma <[email protected]>--- arch/loongarch/kernel/setup.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)arch/loongarch/kernel/setup.c +2
-0@@ -56,6 +56,7 @@#define SMBIOS_FREQLOW_MASK 0xFF#define SMBIOS_CORE_PACKAGE_OFFSET 0x23#define SMBIOS_THREAD_PACKAGE_OFFSET 0x25 +#define SMBIOS_THREAD_PACKAGE_2_OFFSET 0x2E#define LOONGSON_EFI_ENABLE (1 << 3)unsigned long fw_arg0, fw_arg1, fw_arg2;@@ -120,13 +121,19 @@ static void __init parse_cpu_table(const struct dmi_header *dm) {long freq_temp =0 ;char *dmi_data = (char *)dm; +u8 thread_count;
arch/loongarch/kernel/setup.c static void __init parse_cpu_table(const struct dmi_header *dm) · line 133
Quoted 10 lines
arch/loongarch/kernel/setup.c +3
-1+u16 thread_count2; freq_temp = ((*(dmi_data +SMBIOS_FREQHIGH_OFFSET ) <<8 ) + ((*(dmi_data +SMBIOS_FREQLOW_OFFSET )) &SMBIOS_FREQLOW_MASK )); cpu_clock_freq = freq_temp *1000000 ; loongson_sysconf.cpuname = (void *)dmi_string_parse (dm, dmi_data[16 ]); - loongson_sysconf.cores_per_package = *(dmi_data +SMBIOS_THREAD_PACKAGE_OFFSET ); + thread_count = *(dmi_data +SMBIOS_THREAD_PACKAGE_OFFSET ); + thread_count2 = *(u16 *)(dmi_data +SMBIOS_THREAD_PACKAGE_2_OFFSET );
You have dm->length >= 0x30 below but the memory load already done here.
Quoted 10 lines
arch/loongarch/kernel/setup.c +3
-1+if (thread_count !=0 ) + loongson_sysconf.cores_per_package = dm->length >=0x30 && thread_count ==0xFF ? + thread_count2 : thread_count;pr_info ("CpuClock = %llu\n" , cpu_clock_freq); } --2.20.1
Quoted 41 lines · Qiang Ma
For
thread_count, the current calculation method has a maximum of 255, which may not be sufficient in the future. Therefore, we are correcting it now.Reference: SMBIOS Specification, 7.5 Processor Information (Type 4)[1]
[1]:https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.9.0.pdf
Signed-off-by Qiang Ma<[email protected]>---
arch/loongarch/kernel/setup.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c index 25a87378e48e..760f5ce44384 100644 --- a/arch/loongarch/kernel/setup.c +++ b/arch/loongarch/kernel/setup.c @@ -56,6 +56,7 @@ #define SMBIOS_FREQLOW_MASK 0xFF #define SMBIOS_CORE_PACKAGE_OFFSET 0x23 #define SMBIOS_THREAD_PACKAGE_OFFSET 0x25 +#define SMBIOS_THREAD_PACKAGE_2_OFFSET 0x2E #define LOONGSON_EFI_ENABLE (1 << 3)unsigned long fw_arg0, fw_arg1, fw_arg2; @@ -120,13 +121,19 @@ static void __init parse_cpu_table(const struct dmi_header *dm) { long freq_temp = 0; char *dmi_data = (char *)dm; + u8 thread_count; + u16 thread_count2;freq_temp = ((*(dmi_data + SMBIOS_FREQHIGH_OFFSET) << 8) + ((*(dmi_data + SMBIOS_FREQLOW_OFFSET)) & SMBIOS_FREQLOW_MASK)); cpu_clock_freq = freq_temp * 1000000; loongson_sysconf.cpuname = (void *)dmi_string_parse(dm, dmi_data[16]); - loongson_sysconf.cores_per_package = *(dmi_data + SMBIOS_THREAD_PACKAGE_OFFSET); + thread_count = *(dmi_data + SMBIOS_THREAD_PACKAGE_OFFSET); + thread_count2 = *(u16 *)(dmi_data + SMBIOS_THREAD_PACKAGE_2_OFFSET);
Quoted 1 line
You have
dm->length >= 0x30below but the memory load already done here.
After reading thread_count2, it cannot be guaranteed that the data is valid.
'dm->length >= 0x30' can detect that thread_count2 is an available data, right?
Quoted 8 lines
+ if (
thread_count!= 0)
+ loongson_sysconf.cores_per_package =dm->length>=0x30&&thread_count==0xFF?
+thread_count2:thread_count;pr_info("CpuClock = %llu\n", cpu_clock_freq);}
--
2.20.1
Quoted 45 lines · Qiang Ma
Quoted 41 lines · Qiang Ma
For
thread_count, the current calculation method has a maximum of 255, which may not be sufficient in the future. Therefore, we are correcting it now.Reference: SMBIOS Specification, 7.5 Processor Information (Type 4)[1]
[1]:https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.9.0.pdf
Signed-off-by Qiang Ma<[email protected]>---
arch/loongarch/kernel/setup.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c index 25a87378e48e..760f5ce44384 100644 --- a/arch/loongarch/kernel/setup.c +++ b/arch/loongarch/kernel/setup.c @@ -56,6 +56,7 @@ #define SMBIOS_FREQLOW_MASK 0xFF #define SMBIOS_CORE_PACKAGE_OFFSET 0x23 #define SMBIOS_THREAD_PACKAGE_OFFSET 0x25 +#define SMBIOS_THREAD_PACKAGE_2_OFFSET 0x2E #define LOONGSON_EFI_ENABLE (1 << 3)unsigned long fw_arg0, fw_arg1, fw_arg2; @@ -120,13 +121,19 @@ static void __init parse_cpu_table(const struct dmi_header *dm) { long freq_temp = 0; char *dmi_data = (char *)dm; + u8 thread_count; + u16 thread_count2;freq_temp = ((*(dmi_data + SMBIOS_FREQHIGH_OFFSET) << 8) + ((*(dmi_data + SMBIOS_FREQLOW_OFFSET)) & SMBIOS_FREQLOW_MASK)); cpu_clock_freq = freq_temp * 1000000; loongson_sysconf.cpuname = (void *)dmi_string_parse(dm, dmi_data[16]); - loongson_sysconf.cores_per_package = *(dmi_data + SMBIOS_THREAD_PACKAGE_OFFSET); + thread_count = *(dmi_data + SMBIOS_THREAD_PACKAGE_OFFSET); + thread_count2 = *(u16 *)(dmi_data + SMBIOS_THREAD_PACKAGE_2_OFFSET);
Quoted 6 lines
Quoted 1 line
You have
dm->length >= 0x30below but the memory load already done here.After reading
thread_count2, it cannot be guaranteed that the data is valid.'
dm->length>=0x30' can detect thatthread_count2is an available data, right?
I mean you should perform the check before doing memory load.
Quoted 9 lines
Quoted 9 lines
+ if (
thread_count!= 0)
+ loongson_sysconf.cores_per_package =dm->length>=0x30&&thread_count==0xFF?
+thread_count2:thread_count;pr_info("CpuClock = %llu\n", cpu_clock_freq);}
--
2.20.1
Quoted 45 lines · Hengqi Chen
Quoted 44 lines · Qiang Ma
Quoted 41 lines · Qiang Ma
For thread_count, the current calculation method has a maximum of 255, which may not be sufficient in the future. Therefore, we are correcting it now. Reference: SMBIOS Specification, 7.5 Processor Information (Type 4)[1] [1]:https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.9.0.pdf Signed-off-by: Qiang Ma<[email protected]> --- arch/loongarch/kernel/setup.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c index 25a87378e48e..760f5ce44384 100644 --- a/arch/loongarch/kernel/setup.c +++ b/arch/loongarch/kernel/setup.c @@ -56,6 +56,7 @@ #define SMBIOS_FREQLOW_MASK 0xFF #define SMBIOS_CORE_PACKAGE_OFFSET 0x23 #define SMBIOS_THREAD_PACKAGE_OFFSET 0x25 +#define SMBIOS_THREAD_PACKAGE_2_OFFSET 0x2E #define LOONGSON_EFI_ENABLE (1 << 3) unsigned long fw_arg0, fw_arg1, fw_arg2; @@ -120,13 +121,19 @@ static void __init parse_cpu_table(const struct dmi_header *dm) { long freq_temp = 0; char *dmi_data = (char *)dm; + u8 thread_count; + u16 thread_count2; freq_temp = ((*(dmi_data + SMBIOS_FREQHIGH_OFFSET) << 8) + ((*(dmi_data + SMBIOS_FREQLOW_OFFSET)) & SMBIOS_FREQLOW_MASK)); cpu_clock_freq = freq_temp * 1000000; loongson_sysconf.cpuname = (void *)dmi_string_parse(dm, dmi_data[16]); - loongson_sysconf.cores_per_package = *(dmi_data + SMBIOS_THREAD_PACKAGE_OFFSET); + thread_count = *(dmi_data + SMBIOS_THREAD_PACKAGE_OFFSET); + thread_count2 = *(u16 *)(dmi_data + SMBIOS_THREAD_PACKAGE_2_OFFSET);
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
You have
dm->length >= 0x30below but the memory load already done here.After reading
thread_count2, it cannot be guaranteed that the data is valid.'
dm->length>=0x30' can detect thatthread_count2is an available data, right?I mean you should perform the check before doing memory load.
It doesn't matter whether it's before or after.
Anyway, here it's just reading. Before it's actually used later, it will check this length.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+ if (thread_count != 0) + loongson_sysconf.cores_per_package = dm->length >= 0x30 && thread_count == 0xFF ? + thread_count2 : thread_count; pr_info("CpuClock = %llu\n", cpu_clock_freq); } -- 2.20.1
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 47 lines · Qiang Ma
Quoted 45 lines · Hengqi Chen
Quoted 44 lines · Qiang Ma
Quoted 41 lines · Qiang Ma
For
thread_count, the current calculation method has a maximum of 255, which may not be sufficient in the future. Therefore, we are correcting it now.Reference: SMBIOS Specification, 7.5 Processor Information (Type 4)[1]
[1]:https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.9.0.pdf
Signed-off-by Qiang Ma<[email protected]>---
arch/loongarch/kernel/setup.c| 9 ++++++++-1 file changed, 8 insertions(+), 1 deletion(-)diff --git
a/arch/loongarch/kernel/setup.cb/arch/loongarch/kernel/setup.cindex25a87378e48e..760f5ce44384100644
---a/arch/loongarch/kernel/setup.c
+++b/arch/loongarch/kernel/setup.c
@@ -56,6 +56,7 @@
#define SMBIOS_FREQLOW_MASK0xFF
#define SMBIOS_CORE_PACKAGE_OFFSET0x23
#define SMBIOS_THREAD_PACKAGE_OFFSET0x25
+#defineSMBIOS_THREAD_PACKAGE_2_OFFSET0x2E
#define LOONGSON_EFI_ENABLE (1 << 3)unsigned long
fw_arg0,fw_arg1,fw_arg2;
@@ -120,13 +121,19 @@ static void__initparse_cpu_table(const struct dmi_header *dm){
longfreq_temp= 0;
char*dmi_data= (char *)dm;
+ u8thread_count;
+ u16thread_count2;
freq_temp= ((*(dmi_data +SMBIOS_FREQHIGH_OFFSET) << 8) + ((*(dmi_data +SMBIOS_FREQLOW_OFFSET)) &SMBIOS_FREQLOW_MASK));cpu_clock_freq=freq_temp* 1000000;loongson_sysconf.cpuname = (void *)dmi_string_parse(dm, dmi_data[16]); - loongson_sysconf.cores_per_package = *(dmi_data +
SMBIOS_THREAD_PACKAGE_OFFSET); +thread_count= *(dmi_data +SMBIOS_THREAD_PACKAGE_OFFSET);
+thread_count2= *(u16 *)(dmi_data +SMBIOS_THREAD_PACKAGE_2_OFFSET);
Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
You have
dm->length >= 0x30below but the memory load already done here.After reading
thread_count2, it cannot be guaranteed that the data is valid.'
dm->length>=0x30' can detect thatthread_count2is an available data, right?I mean you should perform the check before doing memory load.
It doesn't matter whether it's before or after.
My understanding was wrong. I will fix it in v2.
Quoted 14 lines
Anyway, here it's just reading. Before it's actually used later, it will check this length.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
+ if (
thread_count!= 0)
+ loongson_sysconf.cores_per_package =dm->lengthQuoted 1 line
=
0x30&&thread_count==0xFF?+
thread_count2:thread_count;
pr_info("CpuClock = %llu\n", cpu_clock_freq); }
--
2.20.1