[PATCH 02/16] x86/amd_nb: Restrict init function to AMD-based systems

Yazen Ghannam posted 16 patches 1 month ago
[PATCH 02/16] x86/amd_nb: Restrict init function to AMD-based systems
Posted by Yazen Ghannam 1 month ago
The code implicitly operates on AMD-based systems by matching on PCI
IDs. However, the use of these IDs is going away.

Add an explicit CPU vendor check instead of relying on PCI IDs.

Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
---
 arch/x86/kernel/amd_nb.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c
index 9fe9972d2071..37b8244899d8 100644
--- a/arch/x86/kernel/amd_nb.c
+++ b/arch/x86/kernel/amd_nb.c
@@ -582,6 +582,10 @@ static __init void fix_erratum_688(void)
 
 static __init int init_amd_nbs(void)
 {
+	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD &&
+	    boot_cpu_data.x86_vendor != X86_VENDOR_HYGON)
+		return 0;
+
 	amd_cache_northbridges();
 	amd_cache_gart();
 
-- 
2.43.0
RE: [PATCH 02/16] x86/amd_nb: Restrict init function to AMD-based systems
Posted by Zhuo, Qiuxu 3 weeks, 4 days ago
> From: Yazen Ghannam <yazen.ghannam@amd.com>
> [..]
> --- a/arch/x86/kernel/amd_nb.c
> +++ b/arch/x86/kernel/amd_nb.c
> @@ -582,6 +582,10 @@ static __init void fix_erratum_688(void)
> 
>  static __init int init_amd_nbs(void)
>  {
> +	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD &&
> +	    boot_cpu_data.x86_vendor != X86_VENDOR_HYGON)
> +		return 0;
> +
>  	amd_cache_northbridges();

This function could fail and return an error.
Is an early return with an error code needed if this function fails?

[ I know this is out of this patch scope. ]

>  	amd_cache_gart();

-Qiuxu
Re: [PATCH 02/16] x86/amd_nb: Restrict init function to AMD-based systems
Posted by Borislav Petkov 3 weeks, 4 days ago
On Thu, Oct 31, 2024 at 08:09:14AM +0000, Zhuo, Qiuxu wrote:
> This function could fail and return an error.
> Is an early return with an error code needed if this function fails?

No, grep for amd_northbridges.num checks in the code.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
RE: [PATCH 02/16] x86/amd_nb: Restrict init function to AMD-based systems
Posted by Zhuo, Qiuxu 3 weeks, 4 days ago
> From: Borislav Petkov <bp@alien8.de>
> [...]
> 
> On Thu, Oct 31, 2024 at 08:09:14AM +0000, Zhuo, Qiuxu wrote:
> > This function could fail and return an error.
> > Is an early return with an error code needed if this function fails?
> 
> No, grep for amd_northbridges.num checks in the code.

If the return value of amd_cache_northbridges() isn't used in any place, 
make it return void?

-Qiuxu
RE: [PATCH 02/16] x86/amd_nb: Restrict init function to AMD-based systems
Posted by Borislav Petkov 3 weeks, 4 days ago
On October 31, 2024 12:50:10 PM GMT+01:00, "Zhuo, Qiuxu" <qiuxu.zhuo@intel.com> wrote:
>> From: Borislav Petkov <bp@alien8.de>
>> [...]
>> 
>> On Thu, Oct 31, 2024 at 08:09:14AM +0000, Zhuo, Qiuxu wrote:
>> > This function could fail and return an error.
>> > Is an early return with an error code needed if this function fails?
>> 
>> No, grep for amd_northbridges.num checks in the code.
>
>If the return value of amd_cache_northbridges() isn't used in any place, 
>make it return void?
>
>-Qiuxu

Feel free to propose patches *after* the dust around that area settles.
-- 
Sent from a small device: formatting sucks and brevity is inevitable.