From: "Jan Beulich" Subject: [PATCH] linux: fix agp address handling, namely intel-agp Date: Tue, 19 Jun 2007 14:36:37 +0100 Message-ID: <4677F805.76E4.0078.0@novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org 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 Index: head-2007-04-27/drivers/char/agp/generic.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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.0000000= 00 +0200 @@ -51,28 +51,6 @@ int agp_memory_reserved; */ EXPORT_SYMBOL_GPL(agp_memory_reserved); =20 -#if defined(CONFIG_X86) -int map_page_into_agp(struct page *page) -{ - int i; - i =3D 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 =3D 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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 =3D=3D NULL) return NULL; =20 +#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 =3D 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); } =20 Index: head-2007-04-27/include/asm-i386/agp.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- head-2007-04-27.orig/include/asm-i386/agp.h 2007-04-26 05:08:32.0000000= 00 +0200 +++ head-2007-04-27/include/asm-i386/agp.h 2007-04-27 15:44:03.0000000= 00 +0200 @@ -12,8 +12,10 @@ * data corruption on some CPUs. */ =20 -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_NOCA= CHE) +#define unmap_page_from_agp(page) change_page_attr(page, 1, PAGE_KERNEL) #define flush_agp_mappings() global_flush_tlb() =20 /* 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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. */ =20 -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() =20 /* Could use CLFLUSH here if the cpu supports it. But then it would Index: head-2007-04-27/include/asm-x86_64/agp.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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.0000000= 00 +0200 @@ -10,8 +10,10 @@ * with different cachability attributes for the same page. */ =20 -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_NOCA= CHE) +#define unmap_page_from_agp(page) change_page_attr(page, 1, PAGE_KERNEL) #define flush_agp_mappings() global_flush_tlb() =20 /* 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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. */ =20 -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() =20 /* Could use CLFLUSH here if the cpu supports it. But then it would