Skip to contentSkip to conversation

linux: fix agp address handling, namely intel-agp

PATCH New Jan Beulich 1 participant 1 message Apr 4, 2007 Agpgart driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux: fix agp address handling, namely intel-agp

Make sure machine addresses are in fact constrained to 32 bits, and assumptions about multi-page extents being contiguous are being met.

arch/i386/mm/hypervisor.c +2 -0
Index: sle10sp1-2007-03-28/arch/i386/mm/hypervisor.c
===================================================================
@@ -353,6 +353,7 @@ int xen_create_contiguous_region(
 
 	return success ? 0 : -ENOMEM;
 }
+EXPORT_SYMBOL_GPL(xen_create_contiguous_region);
 
 void xen_destroy_contiguous_region(unsigned long vstart, unsigned int order)
 {
@@ -437,6 +438,7 @@ void xen_destroy_contiguous_region(unsig
 
 	balloon_unlock(flags);
 }
+EXPORT_SYMBOL_GPL(xen_destroy_contiguous_region);
 
 #ifdef __i386__
 int write_ldt_entry(void *ldt, int entry, __u32 entry_a, __u32 entry_b)
drivers/char/agp/generic.c +1 -1
Index: sle10sp1-2007-03-28/drivers/char/agp/generic.c
===================================================================
@@ -51,7 +51,7 @@ int agp_memory_reserved;
  */
 EXPORT_SYMBOL_GPL(agp_memory_reserved);
 
-#if defined(CONFIG_X86)
+#if defined(CONFIG_X86) && !defined(CONFIG_XEN)
 int map_page_into_agp(struct page *page)
 {
 	int i;
drivers/char/agp/intel-agp.c +10 -0
Index: sle10sp1-2007-03-28/drivers/char/agp/intel-agp.c
===================================================================
@@ -164,6 +164,13 @@ static void *i8xx_alloc_pages(void)
 	if (page == NULL)
 		return NULL;
 
+#ifdef CONFIG_XEN
+	if (xen_create_contiguous_region((unsigned long)page_address(page), 2, 32)) {
+		__free_pages(page, 2);
+		return NULL;
+	}
+#endif
+
 	if (change_page_attr(page, 4, PAGE_KERNEL_NOCACHE) < 0) {
 		global_flush_tlb();
 		__free_page(page);
@@ -186,6 +193,9 @@ static void i8xx_destroy_pages(void *add
 	page = virt_to_page(addr);
 	change_page_attr(page, 4, PAGE_KERNEL);
 	global_flush_tlb();
+#ifdef CONFIG_XEN
+	xen_destroy_contiguous_region((unsigned long)page_address(page), 2);
+#endif
 	put_page(page);
 	unlock_page(page);
 	free_pages((unsigned long)addr, 2);
include/asm-i386/mach-xen/asm/agp.h +9 -2
Index: sle10sp1-2007-03-28/include/asm-i386/mach-xen/asm/agp.h
===================================================================
@@ -13,8 +13,15 @@
  * data corruption on some CPUs.
  */
 
-int map_page_into_agp(struct page *page);
-int unmap_page_from_agp(struct page *page);
+/* Caller's responsibility to call global_flush_tlb() for
+ * performance reasons */
+#define map_page_into_agp(page) ( \
+	xen_create_contiguous_region((unsigned long)page_address(page), 0, 32) \
+	?: change_page_attr(page, 1, PAGE_KERNEL_NOCACHE))
+#define unmap_page_from_agp(page) ( \
+	xen_destroy_contiguous_region((unsigned long)page_address(page), 0), \
+	/* only a fallback: xen_destroy_contiguous_region uses PAGE_KERNEL */ \
+	change_page_attr(page, 1, PAGE_KERNEL))
 #define flush_agp_mappings() global_flush_tlb()
 
 /* Could use CLFLUSH here if the cpu supports it. But then it would
include/asm-x86_64/mach-xen/asm/agp.h +7 -2
Index: sle10sp1-2007-03-28/include/asm-x86_64/mach-xen/asm/agp.h
===================================================================
@@ -11,8 +11,13 @@
  * with different cachability attributes for the same page.
  */
 
-int map_page_into_agp(struct page *page);
-int unmap_page_from_agp(struct page *page);
+#define map_page_into_agp(page) ( \
+	xen_create_contiguous_region((unsigned long)page_address(page), 0, 32) \
+	?: change_page_attr(page, 1, PAGE_KERNEL_NOCACHE))
+#define unmap_page_from_agp(page) ( \
+	xen_destroy_contiguous_region((unsigned long)page_address(page), 0), \
+	/* only a fallback: xen_destroy_contiguous_region uses PAGE_KERNEL */ \
+	change_page_attr(page, 1, PAGE_KERNEL))
 #define flush_agp_mappings() global_flush_tlb()
 
 /* Could use CLFLUSH here if the cpu supports it. But then it would