All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2] x86/gart: Check for GART support before accessing GART registers
@ 2015-04-07 21:46 Aravind Gopalakrishnan
  2015-04-08 15:25 ` Borislav Petkov
  2015-05-06 10:13 ` [tip:x86/cpu] " tip-bot for Aravind Gopalakrishnan
  0 siblings, 2 replies; 3+ messages in thread
From: Aravind Gopalakrishnan @ 2015-04-07 21:46 UTC (permalink / raw)
  To: mingo, bp, linux-kernel
  Cc: Suravee.Suthikulpanit, Joerg Rodel, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, Bjorn Helgaas, x86-ml

GART registers are not present in newer processors (Fam15h, Model 10h
and later). So, avoid accesses to GART registers in PCI config
space by returning early in early_gart_iommu_check() and
gart_iommu_hole_init() if GART is not available.

Current code doesn't break on existing processors but there are some
side effects:

We get bogus AGP aperture messages which are simply noise on
GART-less processors:

  AGP: Node 0: aperture [bus addr 0x00000000-0x01ffffff] (32MB)
  AGP: Your BIOS doesn't leave aperture memory hole
  AGP: Please enable the IOMMU option in the BIOS setup
  AGP: This costs you 64MB of RAM
  AGP: Mapping aperture over RAM [mem 0xd4000000-0xd7ffffff]

We can avoid calling allocate_aperture() and would not have to
wastefully reserve 64MB of RAM with memblock_reserve(). Also, we can
avoid having to loop through all PCI buses and devices twice, searching
for a non-existent AGP bridge if we bail out early.

Refactoring the family check used in amd_nb.c into an inline function
so we can use it here as well as in amd_nb.c

Fix some typos while at it.
Tested the patch on Fam10h and Fam15h Model 00h-fh and this code
runs fine. On Fam15h Model 60h-6fh and on Fam16h, we bail early
as they don't have GART.

Signed-off-by: Aravind Gopalakrishnan <Aravind.Gopalakrishnan@amd.com>
Reviewed-by: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>
Cc: Joerg Rodel <joro@8bytes.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: x86-ml <x86@kernel.org>
---
Changes in V2:
 - move amd_gart_present() before any other checks as it's least intrusive (per Boris)
 - fix typos in code and commit message (per Ingo)
 - minor change to subject line (per Boris' change)
 - Link to V1:http://marc.info/?l=linux-kernel&m=142792069809730&w=2

 arch/x86/include/asm/amd_nb.h | 11 +++++++++++
 arch/x86/kernel/amd_nb.c      |  4 +---
 arch/x86/kernel/aperture_64.c |  8 +++++++-
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/amd_nb.h b/arch/x86/include/asm/amd_nb.h
index aaac3b2..1a5da2e 100644
--- a/arch/x86/include/asm/amd_nb.h
+++ b/arch/x86/include/asm/amd_nb.h
@@ -98,11 +98,22 @@ static inline u16 amd_get_node_id(struct pci_dev *pdev)
 	return 0;
 }
 
+static inline bool amd_gart_present(void)
+{
+	/* GART present only on Fam15h, upto model 0fh */
+	if (boot_cpu_data.x86 == 0xf || boot_cpu_data.x86 == 0x10 ||
+	    (boot_cpu_data.x86 == 0x15 && boot_cpu_data.x86_model < 0x10))
+		return true;
+
+	return false;
+}
+
 #else
 
 #define amd_nb_num(x)		0
 #define amd_nb_has_feature(x)	false
 #define node_to_amd_nb(x)	NULL
+#define amd_gart_present(x)	false
 
 #endif
 
diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c
index 5caed1d..29fa475 100644
--- a/arch/x86/kernel/amd_nb.c
+++ b/arch/x86/kernel/amd_nb.c
@@ -89,9 +89,7 @@ int amd_cache_northbridges(void)
 			next_northbridge(link, amd_nb_link_ids);
 	}
 
-	/* GART present only on Fam15h upto model 0fh */
-	if (boot_cpu_data.x86 == 0xf || boot_cpu_data.x86 == 0x10 ||
-	    (boot_cpu_data.x86 == 0x15 && boot_cpu_data.x86_model < 0x10))
+	if (amd_gart_present())
 		amd_northbridges.flags |= AMD_NB_GART;
 
 	/*
diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
index 76164e1..5c3e9b56 100644
--- a/arch/x86/kernel/aperture_64.c
+++ b/arch/x86/kernel/aperture_64.c
@@ -262,6 +262,9 @@ void __init early_gart_iommu_check(void)
 	u64 aper_base = 0, last_aper_base = 0;
 	int aper_enabled = 0, last_aper_enabled = 0, last_valid = 0;
 
+	if (!amd_gart_present())
+		return;
+
 	if (!early_pci_allowed())
 		return;
 
@@ -355,6 +358,9 @@ int __init gart_iommu_hole_init(void)
 	int fix, slot, valid_agp = 0;
 	int i, node;
 
+	if (!amd_gart_present())
+		return -ENODEV;
+
 	if (gart_iommu_aperture_disabled || !fix_aperture ||
 	    !early_pci_allowed())
 		return -ENODEV;
@@ -452,7 +458,7 @@ out:
 		   force_iommu ||
 		   valid_agp ||
 		   fallback_aper_force) {
-		pr_info("Your BIOS doesn't leave a aperture memory hole\n");
+		pr_info("Your BIOS doesn't leave aperture memory hole\n");
 		pr_info("Please enable the IOMMU option in the BIOS setup\n");
 		pr_info("This costs you %dMB of RAM\n",
 			32 << fallback_aper_order);
-- 
1.9.1


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

* Re: [PATCH V2] x86/gart: Check for GART support before accessing GART registers
  2015-04-07 21:46 [PATCH V2] x86/gart: Check for GART support before accessing GART registers Aravind Gopalakrishnan
@ 2015-04-08 15:25 ` Borislav Petkov
  2015-05-06 10:13 ` [tip:x86/cpu] " tip-bot for Aravind Gopalakrishnan
  1 sibling, 0 replies; 3+ messages in thread
From: Borislav Petkov @ 2015-04-08 15:25 UTC (permalink / raw)
  To: Aravind Gopalakrishnan
  Cc: mingo, bp, linux-kernel, Suravee.Suthikulpanit, Joerg Rodel,
	Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Bjorn Helgaas,
	x86-ml

On Tue, Apr 07, 2015 at 04:46:37PM -0500, Aravind Gopalakrishnan wrote:
> GART registers are not present in newer processors (Fam15h, Model 10h
> and later). So, avoid accesses to GART registers in PCI config
> space by returning early in early_gart_iommu_check() and
> gart_iommu_hole_init() if GART is not available.
> 
> Current code doesn't break on existing processors but there are some
> side effects:
> 
> We get bogus AGP aperture messages which are simply noise on
> GART-less processors:
> 
>   AGP: Node 0: aperture [bus addr 0x00000000-0x01ffffff] (32MB)
>   AGP: Your BIOS doesn't leave aperture memory hole
>   AGP: Please enable the IOMMU option in the BIOS setup
>   AGP: This costs you 64MB of RAM
>   AGP: Mapping aperture over RAM [mem 0xd4000000-0xd7ffffff]
> 
> We can avoid calling allocate_aperture() and would not have to
> wastefully reserve 64MB of RAM with memblock_reserve(). Also, we can
> avoid having to loop through all PCI buses and devices twice, searching
> for a non-existent AGP bridge if we bail out early.
> 
> Refactoring the family check used in amd_nb.c into an inline function
> so we can use it here as well as in amd_nb.c
> 
> Fix some typos while at it.
> Tested the patch on Fam10h and Fam15h Model 00h-fh and this code
> runs fine. On Fam15h Model 60h-6fh and on Fam16h, we bail early
> as they don't have GART.
> 
> Signed-off-by: Aravind Gopalakrishnan <Aravind.Gopalakrishnan@amd.com>
> Reviewed-by: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>
> Cc: Joerg Rodel <joro@8bytes.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: H. Peter Anvin <hpa@zytor.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: x86-ml <x86@kernel.org>
> ---
> Changes in V2:
>  - move amd_gart_present() before any other checks as it's least intrusive (per Boris)
>  - fix typos in code and commit message (per Ingo)
>  - minor change to subject line (per Boris' change)
>  - Link to V1:http://marc.info/?l=linux-kernel&m=142792069809730&w=2
> 
>  arch/x86/include/asm/amd_nb.h | 11 +++++++++++
>  arch/x86/kernel/amd_nb.c      |  4 +---
>  arch/x86/kernel/aperture_64.c |  8 +++++++-
>  3 files changed, 19 insertions(+), 4 deletions(-)

Applied, thanks.

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

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

* [tip:x86/cpu] x86/gart: Check for GART support before accessing GART registers
  2015-04-07 21:46 [PATCH V2] x86/gart: Check for GART support before accessing GART registers Aravind Gopalakrishnan
  2015-04-08 15:25 ` Borislav Petkov
@ 2015-05-06 10:13 ` tip-bot for Aravind Gopalakrishnan
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Aravind Gopalakrishnan @ 2015-05-06 10:13 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: bp, tglx, Suravee.Suthikulpanit, joro, Aravind.Gopalakrishnan,
	mingo, bp, hpa, bhelgaas, linux-kernel

Commit-ID:  1b4574292e9d2d37b3bb437c9e778fd2bba8e170
Gitweb:     http://git.kernel.org/tip/1b4574292e9d2d37b3bb437c9e778fd2bba8e170
Author:     Aravind Gopalakrishnan <Aravind.Gopalakrishnan@amd.com>
AuthorDate: Tue, 7 Apr 2015 16:46:37 -0500
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 6 May 2015 11:15:53 +0200

x86/gart: Check for GART support before accessing GART registers

GART registers are not present in newer AMD processors (Fam15h, Model
10h and later). So, avoid accessing those in PCI config space by
returning early in early_gart_iommu_check() and gart_iommu_hole_init()
if GART is not available.

Current code doesn't break on existing processors but there are some
side effects:

We get bogus AGP aperture messages which are simply noise on
GART-less processors:

  AGP: Node 0: aperture [bus addr 0x00000000-0x01ffffff] (32MB)
  AGP: Your BIOS doesn't leave aperture memory hole
  AGP: Please enable the IOMMU option in the BIOS setup
  AGP: This costs you 64MB of RAM
  AGP: Mapping aperture over RAM [mem 0xd4000000-0xd7ffffff]

We can avoid calling allocate_aperture() and would not have to
wastefully reserve 64MB of RAM with memblock_reserve(). Also, we can
avoid having to loop through all PCI buses and devices twice, searching
for a non-existent AGP bridge if we bail out early.

Refactor the family check used in amd_nb.c into an inline function so we
can use it here as well as in amd_nb.c

Fix some typos while at it.

Tested the patch on Fam10h and Fam15h Model 00h-fh and this code runs
fine. On Fam15h Model 60h-6fh and on Fam16h, we bail early as they don't
have GART.

Signed-off-by: Aravind Gopalakrishnan <Aravind.Gopalakrishnan@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Joerg Rodel <joro@8bytes.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1428443197-3834-1-git-send-email-Aravind.Gopalakrishnan@amd.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/amd_nb.h | 11 +++++++++++
 arch/x86/kernel/amd_nb.c      |  4 +---
 arch/x86/kernel/aperture_64.c |  8 +++++++-
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/amd_nb.h b/arch/x86/include/asm/amd_nb.h
index aaac3b2..1a5da2e 100644
--- a/arch/x86/include/asm/amd_nb.h
+++ b/arch/x86/include/asm/amd_nb.h
@@ -98,11 +98,22 @@ static inline u16 amd_get_node_id(struct pci_dev *pdev)
 	return 0;
 }
 
+static inline bool amd_gart_present(void)
+{
+	/* GART present only on Fam15h, upto model 0fh */
+	if (boot_cpu_data.x86 == 0xf || boot_cpu_data.x86 == 0x10 ||
+	    (boot_cpu_data.x86 == 0x15 && boot_cpu_data.x86_model < 0x10))
+		return true;
+
+	return false;
+}
+
 #else
 
 #define amd_nb_num(x)		0
 #define amd_nb_has_feature(x)	false
 #define node_to_amd_nb(x)	NULL
+#define amd_gart_present(x)	false
 
 #endif
 
diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c
index 5caed1d..29fa475 100644
--- a/arch/x86/kernel/amd_nb.c
+++ b/arch/x86/kernel/amd_nb.c
@@ -89,9 +89,7 @@ int amd_cache_northbridges(void)
 			next_northbridge(link, amd_nb_link_ids);
 	}
 
-	/* GART present only on Fam15h upto model 0fh */
-	if (boot_cpu_data.x86 == 0xf || boot_cpu_data.x86 == 0x10 ||
-	    (boot_cpu_data.x86 == 0x15 && boot_cpu_data.x86_model < 0x10))
+	if (amd_gart_present())
 		amd_northbridges.flags |= AMD_NB_GART;
 
 	/*
diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
index 76164e1..6e85f71 100644
--- a/arch/x86/kernel/aperture_64.c
+++ b/arch/x86/kernel/aperture_64.c
@@ -262,6 +262,9 @@ void __init early_gart_iommu_check(void)
 	u64 aper_base = 0, last_aper_base = 0;
 	int aper_enabled = 0, last_aper_enabled = 0, last_valid = 0;
 
+	if (!amd_gart_present())
+		return;
+
 	if (!early_pci_allowed())
 		return;
 
@@ -355,6 +358,9 @@ int __init gart_iommu_hole_init(void)
 	int fix, slot, valid_agp = 0;
 	int i, node;
 
+	if (!amd_gart_present())
+		return -ENODEV;
+
 	if (gart_iommu_aperture_disabled || !fix_aperture ||
 	    !early_pci_allowed())
 		return -ENODEV;
@@ -452,7 +458,7 @@ out:
 		   force_iommu ||
 		   valid_agp ||
 		   fallback_aper_force) {
-		pr_info("Your BIOS doesn't leave a aperture memory hole\n");
+		pr_info("Your BIOS doesn't leave an aperture memory hole\n");
 		pr_info("Please enable the IOMMU option in the BIOS setup\n");
 		pr_info("This costs you %dMB of RAM\n",
 			32 << fallback_aper_order);

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

end of thread, other threads:[~2015-05-06 10:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-07 21:46 [PATCH V2] x86/gart: Check for GART support before accessing GART registers Aravind Gopalakrishnan
2015-04-08 15:25 ` Borislav Petkov
2015-05-06 10:13 ` [tip:x86/cpu] " tip-bot for Aravind Gopalakrishnan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.