Jan Beulich
2007-Apr-04 15:54 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. Signed-off-by: Jan Beulich <jbeulich@novell.com> Index: sle10sp1-2007-03-28/arch/i386/mm/hypervisor.c ==================================================================--- sle10sp1-2007-03-28.orig/arch/i386/mm/hypervisor.c 2007-03-28 09:26:03.000000000 +0200 +++ sle10sp1-2007-03-28/arch/i386/mm/hypervisor.c 2007-04-04 16:49:20.000000000 +0200 @@ -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) Index: sle10sp1-2007-03-28/drivers/char/agp/generic.c ==================================================================--- sle10sp1-2007-03-28.orig/drivers/char/agp/generic.c 2007-03-28 08:47:04.000000000 +0200 +++ sle10sp1-2007-03-28/drivers/char/agp/generic.c 2007-04-04 16:49:20.000000000 +0200 @@ -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; Index: sle10sp1-2007-03-28/drivers/char/agp/intel-agp.c ==================================================================--- sle10sp1-2007-03-28.orig/drivers/char/agp/intel-agp.c 2007-03-28 08:47:04.000000000 +0200 +++ sle10sp1-2007-03-28/drivers/char/agp/intel-agp.c 2007-04-04 16:49:20.000000000 +0200 @@ -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); Index: sle10sp1-2007-03-28/include/asm-i386/mach-xen/asm/agp.h ==================================================================--- sle10sp1-2007-03-28.orig/include/asm-i386/mach-xen/asm/agp.h 2007-03-28 08:48:23.000000000 +0200 +++ sle10sp1-2007-03-28/include/asm-i386/mach-xen/asm/agp.h 2007-04-04 16:49:20.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: sle10sp1-2007-03-28/include/asm-x86_64/mach-xen/asm/agp.h ==================================================================--- sle10sp1-2007-03-28.orig/include/asm-x86_64/mach-xen/asm/agp.h 2007-03-28 08:48:23.000000000 +0200 +++ sle10sp1-2007-03-28/include/asm-x86_64/mach-xen/asm/agp.h 2007-04-04 16:49:20.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