Skip to contentSkip to conversation

x86, AMD: GART optimization

PATCH In review Borislav Petkov 2 participants 7 messages Sep 3, 2010 – Sep 5, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover x86, AMD: GART optimization

From: Borislav Petkov <[email protected]>

Hi,

this is a mini-set that disables the generation of GART TLB walk probes and should improve GART TLB walk speed when the GART is being used as an IOMMU. We've been hammering on the changes with a bunch of iotests from the autotest suite and using "iommu=force" for a while now and have seen no regressions so far.

Please apply,

Thanks.

#1 lore raw

PATCH 1/3 x86, GART: Remove superfluous AMD64_GARTEN

From: Borislav Petkov <[email protected]>

There is a GARTEN so use that and drop the duplicate.

---
 arch/x86/include/asm/gart.h   |    1 -
 arch/x86/kernel/aperture_64.c |    4 ++--
 drivers/char/agp/amd64-agp.c  |    2 +-
 3 files changed, 3 insertions(+), 4 deletions(-)
arch/x86/include/asm/gart.h +0 -1
index 4ac5b0f..fba0a72 100644
@@ -27,7 +27,6 @@ extern int fix_aperture;
 #define AMD64_GARTAPERTUREBASE	0x94
 #define AMD64_GARTTABLEBASE	0x98
 #define AMD64_GARTCACHECTL	0x9c
-#define AMD64_GARTEN		(1<<0)
 
 #ifdef CONFIG_GART_IOMMU
 extern int gart_iommu_aperture;
arch/x86/kernel/aperture_64.c +2 -2
index a2e0caf..6fabd40 100644
@@ -307,7 +307,7 @@ void __init early_gart_iommu_check(void)
 				continue;
 
 			ctl = read_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL);
-			aper_enabled = ctl & AMD64_GARTEN;
+			aper_enabled = ctl & GARTEN;
 			aper_order = (ctl >> 1) & 7;
 			aper_size = (32 * 1024 * 1024) << aper_order;
 			aper_base = read_pci_config(bus, slot, 3, AMD64_GARTAPERTUREBASE) & 0x7fff;
@@ -362,7 +362,7 @@ void __init early_gart_iommu_check(void)
 				continue;
 
 			ctl = read_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL);
-			ctl &= ~AMD64_GARTEN;
+			ctl &= ~GARTEN;
 			write_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL, ctl);
 		}
 	}
drivers/char/agp/amd64-agp.c +1 -1
index 70312da..bfe372b 100644
@@ -199,7 +199,7 @@ static void amd64_cleanup(void)
 		struct pci_dev *dev = k8_northbridges[i];
 		/* disable gart translation */
 		pci_read_config_dword(dev, AMD64_GARTAPERTURECTL, &tmp);
-		tmp &= ~AMD64_GARTEN;
+		tmp &= ~GARTEN;
 		pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, tmp);
 	}
 }
Signature · 1 line
1.7.1
#5 lore raw

PATCH 3/3 AGP: Warn when GATT memory cannot be set to UC

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

This is one of those paranoid checks which should at least tell us that something is about to go haywire after we've disabled GART table walk probes which is done by default now on AMD.

---
 drivers/char/agp/generic.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/char/agp/generic.c +3 -1
index d2abf51..64255ce 100644
@@ -984,7 +984,9 @@ int agp_generic_create_gatt_table(struct agp_bridge_data *bridge)
 
 	bridge->driver->cache_flush();
 #ifdef CONFIG_X86
-	set_memory_uc((unsigned long)table, 1 << page_order);
+	if (set_memory_uc((unsigned long)table, 1 << page_order))
+		printk(KERN_WARNING "Could not set GATT table memory to UC!");
+
 	bridge->gatt_table = (void *)table;
 #else
 	bridge->gatt_table = ioremap_nocache(virt_to_phys(table),
Signature · 1 line
1.7.1
#3 lore raw

PATCH 2/3 x86, GART: Disable GART table walk probes

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Current code tramples over bit F3x90[6] which can be used to disable GART table walk probes. However, this bit should be set for performance reasons (speed up GART table walks). We are allowed to do that since we put GART tables in UC memory later anyway. Make it so.

---
 arch/x86/include/asm/gart.h   |   14 ++++++++++++++
 arch/x86/kernel/aperture_64.c |   14 ++++++++------
 arch/x86/kernel/pci-gart_64.c |    2 +-
 drivers/char/agp/amd64-agp.c  |    2 +-
 4 files changed, 24 insertions(+), 8 deletions(-)
arch/x86/include/asm/gart.h +14 -0
index fba0a72..bf357f9 100644
@@ -17,6 +17,7 @@ extern int fix_aperture;
 #define GARTEN		(1<<0)
 #define DISGARTCPU	(1<<4)
 #define DISGARTIO	(1<<5)
+#define DISTLBWALKPRB	(1<<6)
 
 /* GART cache control register bits. */
 #define INVGART		(1<<0)
@@ -56,6 +57,19 @@ static inline void gart_iommu_hole_init(void)
 
 extern int agp_amd64_init(void);
 
+static inline void gart_set_size_and_enable(struct pci_dev *dev, u32 order)
+{
+	u32 ctl;
+
+	/*
+	 * Don't enable translation but enable GART IO and CPU accesses.
+	 * Also, set DISTLBWALKPRB since GART tables memory is UC.
+	 */
+	ctl = DISTLBWALKPRB | order << 1;
+
+	pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, ctl);
+}
+
 static inline void enable_gart_translation(struct pci_dev *dev, u64 addr)
 {
 	u32 tmp, ctl;
arch/x86/kernel/aperture_64.c +8 -6
index 6fabd40..c9cb173 100644
@@ -505,8 +505,13 @@ out:
 
 	/* Fix up the north bridges */
 	for (i = 0; i < ARRAY_SIZE(bus_dev_ranges); i++) {
-		int bus;
-		int dev_base, dev_limit;
+		int bus, dev_base, dev_limit;
+
+		/*
+		 * Don't enable translation yet but enable GART IO and CPU
+		 * accesses and set DISTLBWALKPRB since GART table memory is UC.
+		 */
+		u32 ctl = DISTLBWALKPRB | aper_order << 1;
 
 		bus = bus_dev_ranges[i].bus;
 		dev_base = bus_dev_ranges[i].dev_base;
@@ -515,10 +520,7 @@ out:
 			if (!early_is_k8_nb(read_pci_config(bus, slot, 3, 0x00)))
 				continue;
 
-			/* Don't enable translation yet. That is done later.
-			   Assume this BIOS didn't initialise the GART so
-			   just overwrite all previous bits */
-			write_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL, aper_order << 1);
+			write_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL, ctl);
 			write_pci_config(bus, slot, 3, AMD64_GARTAPERTUREBASE, aper_alloc >> 25);
 		}
 	}
arch/x86/kernel/pci-gart_64.c +1 -1
index 0f7f130..6015ee1 100644
@@ -601,7 +601,7 @@ static void gart_fixup_northbridges(struct sys_device *dev)
 		 * Don't enable translations just yet.  That is the next
 		 * step.  Restore the pre-suspend aperture settings.
 		 */
-		pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, aperture_order << 1);
+		gart_set_size_and_enable(dev, aperture_order);
 		pci_write_config_dword(dev, AMD64_GARTAPERTUREBASE, aperture_alloc >> 25);
 	}
 }
drivers/char/agp/amd64-agp.c +1 -1
index bfe372b..564808a 100644
@@ -313,7 +313,7 @@ static __devinit int fix_northbridge(struct pci_dev *nb, struct pci_dev *agp,
 	if (order < 0 || !agp_aperture_valid(aper, (32*1024*1024)<<order))
 		return -1;
 
-	pci_write_config_dword(nb, AMD64_GARTAPERTURECTL, order << 1);
+	gart_set_size_and_enable(nb, order);
 	pci_write_config_dword(nb, AMD64_GARTAPERTUREBASE, aper >> 25);
 
 	return 0;
Signature · 1 line
1.7.1
#2 lore raw

[tip:core/iommu] x86, GART: Remove superfluous AMD64_GARTEN

In reply to Borislav Petkov
Commit-ID:  57ab43e33122ffdc2eebca5d6de035699f0a8c06
Gitweb:     http://git.kernel.org/tip/57ab43e33122ffdc2eebca5d6de035699f0a8c06
Author:     Borislav Petkov <[email protected]>
AuthorDate: Fri, 3 Sep 2010 18:39:39 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sun, 5 Sep 2010 14:28:34 +0200

x86, GART: Remove superfluous AMD64_GARTEN

There is a GARTEN so use that and drop the duplicate.

Cc Dave Airlie <[email protected]>
Cc FUJITA Tomonori <[email protected]>

LKML-Reference: <[email protected]>

---
 arch/x86/include/asm/gart.h   |    1 -
 arch/x86/kernel/aperture_64.c |    4 ++--
 drivers/char/agp/amd64-agp.c  |    2 +-
 3 files changed, 3 insertions(+), 4 deletions(-)
arch/x86/include/asm/gart.h +0 -1
index 4ac5b0f..fba0a72 100644
@@ -27,7 +27,6 @@ extern int fix_aperture;
 #define AMD64_GARTAPERTUREBASE	0x94
 #define AMD64_GARTTABLEBASE	0x98
 #define AMD64_GARTCACHECTL	0x9c
-#define AMD64_GARTEN		(1<<0)
 
 #ifdef CONFIG_GART_IOMMU
 extern int gart_iommu_aperture;
arch/x86/kernel/aperture_64.c +2 -2
index a2e0caf..6fabd40 100644
@@ -307,7 +307,7 @@ void __init early_gart_iommu_check(void)
 				continue;
 
 			ctl = read_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL);
-			aper_enabled = ctl & AMD64_GARTEN;
+			aper_enabled = ctl & GARTEN;
 			aper_order = (ctl >> 1) & 7;
 			aper_size = (32 * 1024 * 1024) << aper_order;
 			aper_base = read_pci_config(bus, slot, 3, AMD64_GARTAPERTUREBASE) & 0x7fff;
@@ -362,7 +362,7 @@ void __init early_gart_iommu_check(void)
 				continue;
 
 			ctl = read_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL);
-			ctl &= ~AMD64_GARTEN;
+			ctl &= ~GARTEN;
 			write_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL, ctl);
 		}
 	}
drivers/char/agp/amd64-agp.c +1 -1
index 70312da..bfe372b 100644
@@ -199,7 +199,7 @@ static void amd64_cleanup(void)
 		struct pci_dev *dev = k8_northbridges[i];
 		/* disable gart translation */
 		pci_read_config_dword(dev, AMD64_GARTAPERTURECTL, &tmp);
-		tmp &= ~AMD64_GARTEN;
+		tmp &= ~GARTEN;
 		pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, tmp);
 	}
 }
#4 lore raw

[tip:core/iommu] x86, GART: Disable GART table walk probes

In reply to Borislav Petkov
Commit-ID:  260133ab658bd2b80e07832a878e00405e19ff43
Gitweb:     http://git.kernel.org/tip/260133ab658bd2b80e07832a878e00405e19ff43
Author:     Borislav Petkov <[email protected]>
AuthorDate: Fri, 3 Sep 2010 18:39:40 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sun, 5 Sep 2010 14:28:34 +0200

x86, GART: Disable GART table walk probes

Current code tramples over bit F3x90[6] which can be used to disable GART table walk probes. However, this bit should be set for performance reasons (speed up GART table walks). We are allowed to do that since we put GART tables in UC memory later anyway. Make it so.

Cc Dave Airlie <[email protected]>
Cc FUJITA Tomonori <[email protected]>

LKML-Reference: <[email protected]>

---
 arch/x86/include/asm/gart.h   |   14 ++++++++++++++
 arch/x86/kernel/aperture_64.c |   14 ++++++++------
 arch/x86/kernel/pci-gart_64.c |    2 +-
 drivers/char/agp/amd64-agp.c  |    2 +-
 4 files changed, 24 insertions(+), 8 deletions(-)
arch/x86/include/asm/gart.h +14 -0
index fba0a72..bf357f9 100644
@@ -17,6 +17,7 @@ extern int fix_aperture;
 #define GARTEN		(1<<0)
 #define DISGARTCPU	(1<<4)
 #define DISGARTIO	(1<<5)
+#define DISTLBWALKPRB	(1<<6)
 
 /* GART cache control register bits. */
 #define INVGART		(1<<0)
@@ -56,6 +57,19 @@ static inline void gart_iommu_hole_init(void)
 
 extern int agp_amd64_init(void);
 
+static inline void gart_set_size_and_enable(struct pci_dev *dev, u32 order)
+{
+	u32 ctl;
+
+	/*
+	 * Don't enable translation but enable GART IO and CPU accesses.
+	 * Also, set DISTLBWALKPRB since GART tables memory is UC.
+	 */
+	ctl = DISTLBWALKPRB | order << 1;
+
+	pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, ctl);
+}
+
 static inline void enable_gart_translation(struct pci_dev *dev, u64 addr)
 {
 	u32 tmp, ctl;
arch/x86/kernel/aperture_64.c +8 -6
index 6fabd40..c9cb173 100644
@@ -505,8 +505,13 @@ out:
 
 	/* Fix up the north bridges */
 	for (i = 0; i < ARRAY_SIZE(bus_dev_ranges); i++) {
-		int bus;
-		int dev_base, dev_limit;
+		int bus, dev_base, dev_limit;
+
+		/*
+		 * Don't enable translation yet but enable GART IO and CPU
+		 * accesses and set DISTLBWALKPRB since GART table memory is UC.
+		 */
+		u32 ctl = DISTLBWALKPRB | aper_order << 1;
 
 		bus = bus_dev_ranges[i].bus;
 		dev_base = bus_dev_ranges[i].dev_base;
@@ -515,10 +520,7 @@ out:
 			if (!early_is_k8_nb(read_pci_config(bus, slot, 3, 0x00)))
 				continue;
 
-			/* Don't enable translation yet. That is done later.
-			   Assume this BIOS didn't initialise the GART so
-			   just overwrite all previous bits */
-			write_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL, aper_order << 1);
+			write_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL, ctl);
 			write_pci_config(bus, slot, 3, AMD64_GARTAPERTUREBASE, aper_alloc >> 25);
 		}
 	}
arch/x86/kernel/pci-gart_64.c +1 -1
index 0f7f130..6015ee1 100644
@@ -601,7 +601,7 @@ static void gart_fixup_northbridges(struct sys_device *dev)
 		 * Don't enable translations just yet.  That is the next
 		 * step.  Restore the pre-suspend aperture settings.
 		 */
-		pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, aperture_order << 1);
+		gart_set_size_and_enable(dev, aperture_order);
 		pci_write_config_dword(dev, AMD64_GARTAPERTUREBASE, aperture_alloc >> 25);
 	}
 }
drivers/char/agp/amd64-agp.c +1 -1
index bfe372b..564808a 100644
@@ -313,7 +313,7 @@ static __devinit int fix_northbridge(struct pci_dev *nb, struct pci_dev *agp,
 	if (order < 0 || !agp_aperture_valid(aper, (32*1024*1024)<<order))
 		return -1;
 
-	pci_write_config_dword(nb, AMD64_GARTAPERTURECTL, order << 1);
+	gart_set_size_and_enable(nb, order);
 	pci_write_config_dword(nb, AMD64_GARTAPERTUREBASE, aper >> 25);
 
 	return 0;
#6 lore raw

[tip:core/iommu] AGP: Warn when GATT memory cannot be set to UC

In reply to Borislav Petkov
Commit-ID:  1b13fe6a6e9986dbc079cbb05090be75edbffa5d
Gitweb:     http://git.kernel.org/tip/1b13fe6a6e9986dbc079cbb05090be75edbffa5d
Author:     Borislav Petkov <[email protected]>
AuthorDate: Fri, 3 Sep 2010 18:39:41 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sun, 5 Sep 2010 14:28:34 +0200

AGP: Warn when GATT memory cannot be set to UC

This is one of those paranoid checks which should at least tell us that something is about to go haywire after we've disabled GART table walk probes which is done by default now on AMD.

Cc Dave Airlie <[email protected]>
Cc FUJITA Tomonori <[email protected]>

LKML-Reference: <[email protected]>

---
 drivers/char/agp/generic.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/char/agp/generic.c +3 -1
index d2abf51..64255ce 100644
@@ -984,7 +984,9 @@ int agp_generic_create_gatt_table(struct agp_bridge_data *bridge)
 
 	bridge->driver->cache_flush();
 #ifdef CONFIG_X86
-	set_memory_uc((unsigned long)table, 1 << page_order);
+	if (set_memory_uc((unsigned long)table, 1 << page_order))
+		printk(KERN_WARNING "Could not set GATT table memory to UC!");
+
 	bridge->gatt_table = (void *)table;
 #else
 	bridge->gatt_table = ioremap_nocache(virt_to_phys(table),