Jan Beulich
2007-Jun-19 13:36 UTC
[Xen-devel] [PATCH] 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. Generic parts of the patch are in 2.6.22-rc4, but it was not tested against 2.6.18. Signed-off-by: Jan Beulich <jbeulich@novell.com> Index: head-2007-04-27/drivers/char/agp/generic.c ==================================================================--- head-2007-04-27.orig/drivers/char/agp/generic.c 2007-04-26 05:08:32.000000000 +0200 +++ head-2007-04-27/drivers/char/agp/generic.c 2007-04-27 15:44:03.000000000 +0200 @@ -51,28 +51,6 @@ int agp_memory_reserved; */ EXPORT_SYMBOL_GPL(agp_memory_reserved); -#if defined(CONFIG_X86) -int map_page_into_agp(struct page *page) -{ - int i; - i = change_page_attr(page, 1, PAGE_KERNEL_NOCACHE); - /* Caller''s responsibility to call global_flush_tlb() for - * performance reasons */ - return i; -} -EXPORT_SYMBOL_GPL(map_page_into_agp); - -int unmap_page_from_agp(struct page *page) -{ - int i; - i = change_page_attr(page, 1, PAGE_KERNEL); - /* Caller''s responsibility to call global_flush_tlb() for - * performance reasons */ - return i; -} -EXPORT_SYMBOL_GPL(unmap_page_from_agp); -#endif - /* * Generic routines for handling agp_memory structures - * They use the basic page allocation routines to do the brunt of the work. Index: head-2007-04-27/drivers/char/agp/intel-agp.c ==================================================================--- head-2007-04-27.orig/drivers/char/agp/intel-agp.c 2007-04-26 05:08:32.000000000 +0200 +++ head-2007-04-27/drivers/char/agp/intel-agp.c 2007-04-27 15:44:03.000000000 +0200 @@ -185,9 +185,17 @@ 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) { + change_page_attr(page, 4, PAGE_KERNEL); global_flush_tlb(); - __free_page(page); + __free_pages(page, 2); return NULL; } global_flush_tlb(); @@ -207,9 +215,12 @@ 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); + __free_pages(page, 2); atomic_dec(&agp_bridge->current_memory_agp); } Index: head-2007-04-27/include/asm-i386/agp.h ==================================================================--- head-2007-04-27.orig/include/asm-i386/agp.h 2007-04-26 05:08:32.000000000 +0200 +++ head-2007-04-27/include/asm-i386/agp.h 2007-04-27 15:44:03.000000000 +0200 @@ -12,8 +12,10 @@ * 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) change_page_attr(page, 1, PAGE_KERNEL_NOCACHE) +#define unmap_page_from_agp(page) 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 Index: head-2007-04-27/include/asm-i386/mach-xen/asm/agp.h ==================================================================--- head-2007-04-27.orig/include/asm-i386/mach-xen/asm/agp.h 2007-04-27 13:26:30.000000000 +0200 +++ head-2007-04-27/include/asm-i386/mach-xen/asm/agp.h 2007-04-27 15:44:03.000000000 +0200 @@ -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 Index: head-2007-04-27/include/asm-x86_64/agp.h ==================================================================--- head-2007-04-27.orig/include/asm-x86_64/agp.h 2007-04-26 05:08:32.000000000 +0200 +++ head-2007-04-27/include/asm-x86_64/agp.h 2007-04-27 15:44:03.000000000 +0200 @@ -10,8 +10,10 @@ * with different cachability attributes for the same page. */ -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) change_page_attr(page, 1, PAGE_KERNEL_NOCACHE) +#define unmap_page_from_agp(page) 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 Index: head-2007-04-27/include/asm-x86_64/mach-xen/asm/agp.h ==================================================================--- head-2007-04-27.orig/include/asm-x86_64/mach-xen/asm/agp.h 2007-04-27 13:26:30.000000000 +0200 +++ head-2007-04-27/include/asm-x86_64/mach-xen/asm/agp.h 2007-04-27 15:44:03.000000000 +0200 @@ -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 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel