Skip to contentSkip to conversation

x86, aperture: Check for GART before accessing GART registers

PATCH Applied Aravind Gopalakrishnan 6 participants 21 messages Apr 1, 2015 – May 4, 2015 x86

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86, aperture: Check for GART before accessing GART registers

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.

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

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.

---
 arch/x86/include/asm/amd_nb.h | 11 +++++++++++
 arch/x86/kernel/amd_nb.c      |  4 +---
 arch/x86/kernel/aperture_64.c |  4 ++--
 3 files changed, 14 insertions(+), 5 deletions(-)
arch/x86/include/asm/amd_nb.h +11 -0
index aaac3b2..864c8bd 100644
@@ -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
 
arch/x86/kernel/amd_nb.c +1 -3
index 5caed1d..29fa475 100644
@@ -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;
 
 	/*
arch/x86/kernel/aperture_64.c +2 -2
index 76164e1..1cb170b 100644
@@ -262,7 +262,7 @@ 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 (!early_pci_allowed())
+	if (!early_pci_allowed() || !amd_gart_present())
 		return;
 
 	/* This is mostly duplicate of iommu_hole_init */
@@ -356,7 +356,7 @@ int __init gart_iommu_hole_init(void)
 	int i, node;
 
 	if (gart_iommu_aperture_disabled || !fix_aperture ||
-	    !early_pci_allowed())
+	    !early_pci_allowed() || !amd_gart_present())
 		return -ENODEV;
 
 	pr_info("Checking aperture...\n");
Signature · 1 line
1.9.1
#1 lore raw
Quoted 12 lines · Aravind Gopalakrishnan

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.

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

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.

Quoted 7 lines
---
 arch/x86/include/asm/amd_nb.h | 11 +++++++++++
 arch/x86/kernel/amd_nb.c      |  4 +---
 arch/x86/kernel/aperture_64.c |  4 ++--
 3 files changed, 14 insertions(+), 5 deletions(-)

Applied, thanks.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#2 lore raw
In reply to Aravind Gopalakrishnan
Quoted 4 lines · Aravind Gopalakrishnan

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.

In what fashion did this problem manifest itself on real systems?

Thanks,

Ingo

#3 lore raw
Quoted 9 lines · Ingo Molnar
Quoted 4 lines · Aravind Gopalakrishnan

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.

In what fashion did this problem manifest itself on real systems?

This code doesn't break on existing processors.
There are some other side effects though..

We get "AGP:" messages on kernel logs like this-

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

These are just noise on processors which have no GART.
We can avoid calling allocate_aperture() and would not have to memblock_reserve() 64MB of RAM.
Also, we can avoid having to loop through all PCI buses, devices (twice) searching for AGP bridge if we bail out early.

For future processors though, we can't say how these registers will be implemented.
If we have to provide PCI IDs for them in amd_nb_misc_ids[] and this code ends up reading/writing something else then that'd be another problem.

Thanks,
-Aravind.

#4 lore raw
Quoted 15 lines · Aravind Gopalakrishnan
Quoted 9 lines · Ingo Molnar
Quoted 4 lines · Aravind Gopalakrishnan

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.

In what fashion did this problem manifest itself on real systems?

This code doesn't break on existing processors.
There are some other side effects though..

We get "AGP:" messages on kernel logs like this-

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

(65536KB)

These are just noise on processors which have no GART.

agreed.

Quoted 4 lines

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

Makes sense. Mind adding this info to the changelog and resend?

Thanks,

Ingo

#5 lore raw
Quoted 10 lines · Ingo Molnar

We get "AGP:" messages on kernel logs like this-

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

(65536KB)

Quoted 10 lines

These are just noise on processors which have no GART. agreed.

Quoted 4 lines

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

Makes sense. Mind adding this info to the changelog and resend?

Sure, will do that and resend.

Thanks,
-Aravind.

#6 lore raw
Quoted 1 line · Aravind Gopalakrishnan

Sure, will do that and resend.

No need - I can amend the local copy I have here.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#7 lore raw
Quoted 4 lines · Borislav Petkov
Quoted 1 line · Aravind Gopalakrishnan

Sure, will do that and resend.

No need - I can amend the local copy I have here.

Okay.

Thanks!
-Aravind.

Reviewed-by Suravee Suthikulpanit
#8 lore raw
Quoted 1 line · Aravind Gopalakrishnan
Quoted 1 line

No need - I can amend the local copy I have here.

Here's what I did:

---
From: Aravind Gopalakrishnan <[email protected]>
Date: Wed, 1 Apr 2015 09:32:08 -0500
Subject: [PATCH] x86/gart: Check for GART support before accessing GART
registers
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

GART registers are not present in newer AMD 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 a 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 into an inline function so we can use it here as well as in amd_nb.c.

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

Signed-off-by:

---
 arch/x86/include/asm/amd_nb.h | 11 +++++++++++
 arch/x86/kernel/amd_nb.c      |  4 +---
 arch/x86/kernel/aperture_64.c |  4 ++--
 3 files changed, 14 insertions(+), 5 deletions(-)
arch/x86/include/asm/amd_nb.h +11 -0
index aaac3b2fb746..864c8bd8cbe4 100644
@@ -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
 
arch/x86/kernel/amd_nb.c +1 -3
index 5caed1dd7ccf..29fa475ec518 100644
@@ -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;
 
 	/*
arch/x86/kernel/aperture_64.c +2 -2
index 76164e173a24..1cb170b06853 100644
@@ -262,7 +262,7 @@ 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 (!early_pci_allowed())
+	if (!early_pci_allowed() || !amd_gart_present())
 		return;
 
 	/* This is mostly duplicate of iommu_hole_init */
@@ -356,7 +356,7 @@ int __init gart_iommu_hole_init(void)
 	int i, node;
 
 	if (gart_iommu_aperture_disabled || !fix_aperture ||
-	    !early_pci_allowed())
+	    !early_pci_allowed() || !amd_gart_present())
 		return -ENODEV;
 
 	pr_info("Checking aperture...\n");
Signature · 8 lines
2.3.3

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#9 lore raw
Quoted 19 lines · Borislav Petkov
Quoted 1 line · Aravind Gopalakrishnan
Quoted 1 line

No need - I can amend the local copy I have here.

Here's what I did:

---
From: Aravind Gopalakrishnan <[email protected]>
Date: Wed, 1 Apr 2015 09:32:08 -0500
Subject: [PATCH] x86/gart: Check for GART support before accessing GART
registers
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

GART registers are not present in newer AMD 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.

Quoted 8 lines

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 a aperture memory hole

hah, someone should fix the typo in that message:

	s/a a/a
Quoted 10 lines

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 into an inline function so we

s/amd_nb/amd_nb.c

arch/x86/include/asm/amd_nb.h static inline u16 amd_get_node_id(struct pci_dev *pdev) · line 103

Quoted 4 lines
arch/x86/include/asm/amd_nb.h +3 -0
+static inline bool amd_gart_present(void)
+{
+	/* GART present only on Fam15h upto model 0fh */

s/h u/h, u

Quoted 18 lines
arch/x86/kernel/amd_nb.c +1 -0
+	if (amd_gart_present())
 		amd_northbridges.flags |= AMD_NB_GART;
 
 	/*
arch/x86/kernel/aperture_64.c +1 -1
index 76164e173a24..1cb170b06853 100644
@@ -262,7 +262,7 @@ 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 (!early_pci_allowed())
+	if (!early_pci_allowed() || !amd_gart_present())
 		return;
 
 	/* This is mostly duplicate of iommu_hole_init */

arch/x86/kernel/aperture_64.c int __init gart_iommu_hole_init(void) · line 360

Quoted 6 lines
arch/x86/kernel/aperture_64.c +1 -1
@@ -356,7 +356,7 @@ int __init gart_iommu_hole_init(void)
 	int i, node;
 
 	if (gart_iommu_aperture_disabled || !fix_aperture ||
-	    !early_pci_allowed())
+	    !early_pci_allowed() || !amd_gart_present())
 		return -ENODEV;

So what happens if !early_pci_allowed() but the GART is present? We'll set amd_northbridges.flags |= AMD_NB_GART, but won't run any of the setup code in aperture_64.c, right? Is that a valid setup?

Thanks,

Ingo

#10 lore raw
Quoted 21 lines · Ingo Molnar
Quoted 21 lines
arch/x86/kernel/amd_nb.c +1 -0
+	if (amd_gart_present())
  		amd_northbridges.flags |= AMD_NB_GART;
 
  	/*
arch/x86/kernel/aperture_64.c +1 -1
index 76164e173a24..1cb170b06853 100644
@@ -262,7 +262,7 @@ 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 (!early_pci_allowed())
+	if (!early_pci_allowed() || !amd_gart_present())
  		return;
 
  	/* This is mostly duplicate of iommu_hole_init */
@@ -356,7 +356,7 @@ int __init gart_iommu_hole_init(void)
  	int i, node;
 
Quoted 8 lines

arch/x86/kernel/aperture_64.c int __init gart_iommu_hole_init(void) · line 360

Quoted 4 lines
arch/x86/kernel/aperture_64.c +1 -1
  	if (gart_iommu_aperture_disabled || !fix_aperture ||
-	    !early_pci_allowed())
+	    !early_pci_allowed() || !amd_gart_present())
  		return -ENODEV;

So what happens if !early_pci_allowed() but the GART is present? We'll set amd_northbridges.flags |= AMD_NB_GART, but won't run any of the setup code in aperture_64.c, right? Is that a valid setup?

It might be a valid setup. But it would work correctly only if BIOS did the right thing with setting up aperture space.

If !early_pci_allowed() and BIOS did not setup aperture correctly, that would have caused problems already. But it has not been an issue so far right?

Thanks,
-Aravind.

#11 lore raw
Quoted 10 lines · Aravind Gopalakrishnan
Quoted 3 lines

So what happens if !early_pci_allowed() but the GART is present? We'll set amd_northbridges.flags |= AMD_NB_GART, but won't run any of the setup code in aperture_64.c, right? Is that a valid setup?

It might be a valid setup. But it would work correctly only if BIOS did the right thing with setting up aperture space.

If !early_pci_allowed() and BIOS did not setup aperture correctly, that would have caused problems already.
But it has not been an issue so far right?

I think the right question to ask is:

What are we doing when there's no GART?

So what you probably want to do is:

	if (!amd_gart_present())
		return -ENODEV;

*before* the compound check.

Now, if we have detected a GART, i.e., amd_gart_present() is TRUE, the code will behave as it used to behave before.

This should be the least intrusive change going forward IMHO.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#12 lore raw
Quoted 19 lines · Borislav Petkov
Quoted 9 lines · Aravind Gopalakrishnan
Quoted 3 lines

So what happens if !early_pci_allowed() but the GART is present? We'll set amd_northbridges.flags |= AMD_NB_GART, but won't run any of the setup code in aperture_64.c, right? Is that a valid setup?

It might be a valid setup. But it would work correctly only if BIOS did the right thing with setting up aperture space.

If !early_pci_allowed() and BIOS did not setup aperture correctly, that would have caused problems already.
But it has not been an issue so far right?

I think the right question to ask is:

What are we doing when there's no GART?

So what you probably want to do is:

	if (!amd_gart_present())
		return -ENODEV;
Quoted 7 lines

*before* the compound check.

Now, if we have detected a GART, i.e., amd_gart_present() is TRUE, the code will behave as it used to behave before.

This should be the least intrusive change going forward IMHO.

Okay. I'll do that and correct the typos Ingo pointed out earlier and resend.

Thanks,
-Aravind.

#13 lore raw
Quoted 2 lines · Aravind Gopalakrishnan

Okay. I'll do that and correct the typos Ingo pointed out earlier and resend.

Btw, I think you should do the same in early_gart_iommu_check() too.

Doing the testing this way would mean that we first are testing for GART hw presence and then do the rest of checks. If no GART hw, the rest of the checks are meaningless.

Also, when testing do a "pci=noearly" boot which should make

!early_pci_allowed()

true and thus test that path too.

Thanks.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#14 lore raw
Quoted 9 lines · Borislav Petkov
Quoted 2 lines · Aravind Gopalakrishnan

Okay. I'll do that and correct the typos Ingo pointed out earlier and resend.

Btw, I think you should do the same in early_gart_iommu_check() too.

Doing the testing this way would mean that we first are testing for GART hw presence and then do the rest of checks. If no GART hw, the rest of the checks are meaningless.

Quoted 6 lines

Also, when testing do a "pci=noearly" boot which should make

!early_pci_allowed()

true and thus test that path too.

Here are results from further testing:
1. on platforms with both iommu and gart
- with pci=noearly, we break out of init routines in aperture_64.c
early. amd_iommu_init() will run through it's init routine.
- if amd_iommu_init() fails somewhere, we fall back to
gart_iommu_init()
- gart_iommu_init() fails since gart_iommu_aperture is not set.
- fall back to swiotlb.
- with amd_iommu=off
- init routines in aperture_64.c run fine as both
amd_gart_present() and early_pci_allowed() are true
- amd_iommu_detect() fails due to command line arg.
- fall back to gart iommu
- with pci=noearly and amd_iommu=off
- break out of aperture_64.c init routines, and
amd_iommu_detect() fails.
- fall back to swiotlb

2. on platform with no gart but iommu present,
- pci=noearly option is not relevant as we break before that due to
!amd_gart_present()
- if amd_iommu_init() fails somewhere, we fall back to swiotlb,
else use iommu

3. on platforms with no gart and no iommu
- use swiotlb regardless of any command line options passed

Thanks,
-Aravind.

#15 lore raw
Quoted 35 lines · Aravind Gopalakrishnan
Quoted 9 lines · Borislav Petkov
Quoted 2 lines · Aravind Gopalakrishnan

Okay. I'll do that and correct the typos Ingo pointed out earlier and resend.

Btw, I think you should do the same in early_gart_iommu_check() too.

Doing the testing this way would mean that we first are testing for GART hw presence and then do the rest of checks. If no GART hw, the rest of the checks are meaningless.

Quoted 6 lines

Also, when testing do a "pci=noearly" boot which should make

!early_pci_allowed()

true and thus test that path too.

Here are results from further testing:
1. on platforms with both iommu and gart
- with pci=noearly, we break out of init routines in aperture_64.c
early. amd_iommu_init() will run through it's init routine.
- if amd_iommu_init() fails somewhere, we fall back to
gart_iommu_init()
- gart_iommu_init() fails since gart_iommu_aperture is not set.
- fall back to swiotlb.
- with amd_iommu=off
- init routines in aperture_64.c run fine as both amd_gart_present()
and early_pci_allowed() are true
- amd_iommu_detect() fails due to command line arg.
- fall back to gart iommu
- with pci=noearly and amd_iommu=off
- break out of aperture_64.c init routines, and amd_iommu_detect()
fails.
- fall back to swiotlb

Quoted 8 lines

2. on platform with no gart but iommu present,
- pci=noearly option is not relevant as we break before that due to
!amd_gart_present()
- if amd_iommu_init() fails somewhere, we fall back to swiotlb, else use
iommu

3. on platforms with no gart and no iommu
- use swiotlb regardless of any command line options passed

I don't see anything out of the ordinary but then again I don't know this code so...

@joro, can you please double-check?

Thanks.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#16 lore raw
In reply to Borislav Petkov

Hi,

tried this patch on my HP Pavilion notebook wiht AMD Phenom II processor. The BIOS has no IOMMU option.
With this patch I'm still seeing the AGP messages mention in the patch description. Is this processor affected at all? /proc/cpuinfo says "cpu family" 16. That is 10h?

Regards,
jvp.

Borislav Petkov wrote on 04/02/2015 19:17:

Quoted 31 lines · Aravind Gopalakrishnan
Quoted 1 line
Quoted 1 line

No need - I can amend the local copy I have here.

Here's what I did:

---
From: Aravind Gopalakrishnan <[email protected]>
Date: Wed, 1 Apr 2015 09:32:08 -0500
Subject: [PATCH] x86/gart: Check for GART support before accessing GART
registers
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

GART registers are not present in newer AMD 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 a 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]

<snip>

maintainer
#17 lore raw
Quoted 1 line · Jörg-Volker Peetz

Hi,

Hi,

please do not top-post.

Quoted 4 lines

tried this patch on my HP Pavilion notebook wiht AMD Phenom II processor. The BIOS has no IOMMU option.
With this patch I'm still seeing the AGP messages mention in the patch description. Is this processor affected at all?

Your CPU has an AGP bridge but the BIOS doesn't leave an aperture so the kernel has to do it. Read the message.

Quoted 1 line

/proc/cpuinfo says "cpu family" 16. That is 10h?

Yes.

Signature · 5 lines
Regards/Gruss,
    Boris.

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

Hi,

Borislav Petkov wrote on 04/14/2015 13:33:

Quoted 12 lines · Jörg-Volker Peetz
Quoted 1 line

Hi,

Hi,

please do not top-post.

Quoted 4 lines

tried this patch on my HP Pavilion notebook wiht AMD Phenom II processor. The BIOS has no IOMMU option.
With this patch I'm still seeing the AGP messages mention in the patch description. Is this processor affected at all?

Quoted 7 lines

Your CPU has an AGP bridge but the BIOS doesn't leave an aperture so the kernel has to do it. Read the message.

Quoted 1 line

/proc/cpuinfo says "cpu family" 16. That is 10h?

Yes.

thank you for the explanation. Somehow I thought I had a newer CPU w/o GART registers, but I misread the patch. Maybe wishful thinking, in the hope to save 64 MB :-(
Sorry for the noise.

Signature · 2 lines
Regards,
jvp.
maintainer
#19 lore raw
Quoted 3 lines · Jörg-Volker Peetz

thank you for the explanation. Somehow I thought I had a newer CPU w/o GART registers, but I misread the patch. Maybe wishful thinking, in the hope to save 64 MB :-(

64MB out of how much? Does it even matter?

You could turn off CONFIG_GART_IOMMU and not build aperture_64.c at all.

I think then you'll fall back to swiotlb or whatever and that will most likely slow down DMA ... the story was something like that, at least, memory's hazy. Joerg's on CC, he'll correct me if I'm talking bull.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#20 lore raw
Quoted 7 lines · Borislav Petkov

64MB out of how much? Does it even matter?

You could turn off CONFIG_GART_IOMMU and not build aperture_64.c at all.

I think then you'll fall back to swiotlb or whatever and that will most likely slow down DMA ... the story was something like that, at least, memory's hazy. Joerg's on CC, he'll correct me if I'm talking bull.

Using SWIOTLB will also eat 64MB of RAM, so it doesn't matter if you use it instead of the GART driver. So whether your machine has GART or not, it will cost you 64MB of RAM for DMA remapping (unless you have a real IOMMU).

Joerg