Fix BUG-on-swapout
This fixes BUG-on-swapout for srmmu-based systems. The problem is caused by kmap_atomic_to_page being fed an aliased (pagetable) address and returning bogons. This also adjusts the pkmap and fixmap base addresses so they cannot overlap.
Dave, unless it's braindead, please apply.
arch/sparc/Kconfig +7 -0
@@ -313,6 +313,13 @@ This results in a large slowdown, but helps to find certain types of memory corruptions. +config DEBUG_HIGHMEM + bool "Highmem debugging" + depends on DEBUG_KERNEL && HIGHMEM + help + This options enables addition error checking for high memory systems. + Disable for production systems. + config DEBUG_SPINLOCK_SLEEP bool "Sleep-inside-spinlock checking" depends on DEBUG_KERNEL
arch/sparc/mm/fault.c +2 -2
@@ -36,7 +36,7 @@#define ELEMENTS (arr) (sizeof (arr)/sizeof (arr[0])) -extern struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS ]; +extern struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS +1 ];extern int prom_node_root;/* At boot time we determine these two values necessary for setting
@@ -72,7 +72,7 @@ mlist = mlist->theres_more; bytes = mlist->num_bytes; tally += bytes; -if (i >=SPARC_PHYS_BANKS -1 ) { +if (i >SPARC_PHYS_BANKS -1 ) {printk ("The machine has more banks than " "this kernel can support\n" "Increase the SPARC_PHYS_BANKS "
arch/sparc/mm/highmem.c +29 -11
@@ -27,6 +27,7 @@#include <asm/pgalloc.h> #include <asm/cacheflush.h> #include <asm/tlbflush.h> +#include <asm/fixmap.h> void *kmap_atomic (struct page *page,enum km_type type) {
@@ -39,7 +40,7 @@return page_address (page); idx = type +KM_TYPE_NR *smp_processor_id (); - vaddr = fix_kmap_begin + idx *PAGE_SIZE ; + vaddr =__fix_to_virt (FIX_KMAP_BEGIN + idx);/* XXX Fix - Anton */ #if 0
@@ -48,11 +49,10 @@flush_cache_all ();#endif -#if HIGHMEM_DEBUG -if (!pte_none (*(kmap_pte+idx))) -BUG (); +#ifdef CONFIG_DEBUG_HIGHMEM +BUG_ON (!pte_none (*(kmap_pte-idx)));#endif -set_pte (kmap_pte+idx,mk_pte (page, kmap_prot)); +set_pte (kmap_pte-idx,mk_pte (page, kmap_prot));/* XXX Fix - Anton */ #if 0 __flush_tlb_one (vaddr);
@@ -65,17 +65,17 @@void kunmap_atomic (void *kvaddr,enum km_type type) { -unsigned long vaddr = (unsigned long ) kvaddr; +#ifdef CONFIG_DEBUG_HIGHMEM +unsigned long vaddr = (unsigned long ) kvaddr &PAGE_MASK ;unsigned long idx = type +KM_TYPE_NR *smp_processor_id (); -if (vaddr < fix_kmap_begin) {// FIXME +if (vaddr <FIXADDR_START ) {// FIXME dec_preempt_count ();preempt_check_resched ();return ; } -if (vaddr != fix_kmap_begin + idx *PAGE_SIZE ) -BUG (); +BUG_ON (vaddr !=__fix_to_virt (FIX_KMAP_BEGIN +idx));/* XXX Fix - Anton */ #if 0
@@ -84,12 +84,11 @@flush_cache_all ();#endif -#ifdef HIGHMEM_DEBUG /* * force other mappings to Oops if they'll try to access * this pte without first remap it */ -pte_clear (kmap_pte+idx); +pte_clear (kmap_pte-idx);/* XXX Fix - Anton */ #if 0 __flush_tlb_one (vaddr);
@@ -97,6 +96,25 @@flush_tlb_all ();#endif #endif +dec_preempt_count ();preempt_check_resched (); +} + +/* We may be fed a pagetable here by ptep_to_xxx and others. */ +struct page *kmap_atomic_to_page (void *ptr) +{ +unsigned long idx, vaddr = (unsigned long )ptr; +pte_t *pte; + +if (vaddr <SRMMU_NOCACHE_VADDR ) +return virt_to_page (ptr); +if (vaddr <PKMAP_BASE ) +return pfn_to_page (__nocache_pa (vaddr) >>PAGE_SHIFT ); +BUG_ON (vaddr <FIXADDR_START ); +BUG_ON (vaddr >FIXADDR_TOP ); + + idx =virt_to_fix (vaddr); + pte = kmap_pte - (idx -FIX_KMAP_BEGIN ); +return pte_page (*pte); }
arch/sparc/mm/init.c +17 -10
@@ -41,7 +41,7 @@unsigned long page_kernel; -struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS ]; +struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS +1 ];unsigned long sparc_unmapped_base;struct pgtable_cache_struct pgt_quicklists;
@@ -61,17 +61,13 @@EXPORT_SYMBOL (kmap_prot);EXPORT_SYMBOL (kmap_pte); -/* These are set in {srmmu,sun4c}_paging_init() */ -unsigned long fix_kmap_begin; -unsigned long fix_kmap_end; - -#define kmap_get_fixed_pte (vaddr) \ +#define kmap_get_fixmap_pte (vaddr) \ pte_offset_kernel(pmd_offset(pgd_offset_k(vaddr), (vaddr)), (vaddr))void __init kmap_init (void ) {/* cache the first kmap pte */ - kmap_pte =kmap_get_fixed_pte (fix_kmap_begin); + kmap_pte =kmap_get_fixmap_pte (__fix_to_virt (FIX_KMAP_BEGIN )); kmap_prot =__pgprot (SRMMU_ET_PTE |SRMMU_PRIV |SRMMU_CACHE ); }
@@ -385,12 +381,12 @@ {unsigned long tmp; -#ifdef DEBUG_HIGHMEM +#ifdef CONFIG_DEBUG_HIGHMEM printk ("mapping high region %08lx - %08lx\n" , start_pfn, end_pfn);#endif for (tmp = start_pfn; tmp < end_pfn; tmp++) { -struct page *page = mem_map + tmp; +struct page *page =pfn_to_page (tmp);ClearPageReserved (page);set_bit (PG_highmem, &page->flags);
@@ -407,7 +403,18 @@int initpages =0 ;int i; - highmem_start_page = mem_map + highstart_pfn; + highmem_start_page =pfn_to_page (highstart_pfn); + +if (PKMAP_BASE +LAST_PKMAP *PAGE_SIZE >=FIXADDR_START ) { +prom_printf ("BUG: fixmap and pkmap areas overlap\n" ); +prom_printf ("pkbase: 0x%lx pkend: 0x%lx fixstart 0x%lx\n" , +PKMAP_BASE , + (unsigned long )PKMAP_BASE +LAST_PKMAP *PAGE_SIZE , +FIXADDR_START ); +prom_printf ("Please mail [email protected].\n" ); +prom_halt (); + } +/* Saves us work later. */ memset ((void *)&empty_zero_page,0 ,PAGE_SIZE );
arch/sparc/mm/io-unit.c +3 -3
@@ -65,7 +65,7 @@for (xptend = iounit->page_table + (16 *PAGE_SIZE ) /sizeof (iopte_t); xpt < xptend;) - *xpt++ =0 ; +iopte_val (*xpt++) =0 ; }/* One has to hold iounit->lock to call this */
@@ -199,7 +199,7 @@ pmdp =pmd_offset (pgdp, addr); ptep =pte_offset_map (pmdp, addr); -set_pte (ptep,pte_val (mk_pte (virt_to_page (page), dvma_prot))); +set_pte (ptep,mk_pte (virt_to_page (page), dvma_prot)); i = ((addr -IOUNIT_DMA_BASE ) >>PAGE_SHIFT );
@@ -207,7 +207,7 @@struct iounit_struct *iounit = (struct iounit_struct *)sbus->iommu; iopte = (iopte_t *)(iounit->page_table + i); - *iopte =__iopte (MKIOPTE (__pa (page))); + *iopte =MKIOPTE (__pa (page)); } } addr +=PAGE_SIZE ;
arch/sparc/mm/iommu.c +1 -1
@@ -405,7 +405,7 @@iopte_t *iopte = iommu->page_table; iopte += ((busa - iommu->start) >>PAGE_SHIFT ); - return pfn_to_page((pte_val(*iopte) & IOPTE_PAGE) >> (PAGE_SHIFT-4)); + return pfn_to_page((iopte_val(*iopte) & IOPTE_PAGE) >> (PAGE_SHIFT-4)); }#endif
arch/sparc/mm/srmmu.c +18 -27
104 lines not on this page · raw message
arch/sparc/mm/sun4c.c +0 -6
@@ -2028,18 +2028,12 @@extern unsigned long bootmem_init (unsigned long *pages_avail);extern unsigned long last_valid_pfn; -extern unsigned long fix_kmap_begin; -extern unsigned long fix_kmap_end; -void __init sun4c_paging_init (void ) {int i, cnt;unsigned long kernel_end, vaddr;extern struct resource sparc_iomap;unsigned long end_pfn, pages_avail; - - fix_kmap_begin =KERNBASE +SRMMU_MAXMEM ;/* Why bother with SRMMU_MAXMEM? */ - fix_kmap_end = fix_kmap_begin + ((KM_TYPE_NR *NR_CPUS )-1 )*PAGE_SIZE ; kernel_end = (unsigned long ) &end; kernel_end += (SUN4C_REAL_PGDIR_SIZE *4 );
include/asm-sparc/fixmap.h +111 -0
111 lines not on this page · raw message
include/asm-sparc/highmem.h +11 -28
@@ -21,10 +21,10 @@#ifdef __KERNEL__#include <linux/interrupt.h> +#include <asm/fixmap.h> +#include <asm/vaddrs.h> #include <asm/kmap_types.h> - -/* undef for production */ -#define HIGHMEM_DEBUG 1 +#include <asm/pgtsrmmu.h> /* declarations for highmem.c */ extern unsigned long highstart_pfn, highend_pfn;
@@ -33,12 +33,6 @@extern pgprot_t kmap_prot;extern pte_t *pkmap_page_table; -/* This gets set in {srmmu,sun4c}_paging_init() */ -extern unsigned long fix_kmap_begin; - -/* Only used and set with srmmu? */ -extern unsigned long pkmap_base; -extern void kmap_init (void )__init ;/*
@@ -46,19 +40,21 @@* easily, subsequent pte tables have to be allocated in one physical * chunk of RAM. */ +#define PKMAP_BASE (SRMMU_NOCACHE_VADDR + (SRMMU_MAX_NOCACHE_PAGES << PAGE_SHIFT))#define LAST_PKMAP 1024#define LAST_PKMAP_MASK (LAST_PKMAP - 1) -#define PKMAP_NR (virt) ((virt - pkmap_base) >> PAGE_SHIFT) -#define PKMAP_ADDR (nr) (pkmap_base + ((nr) << PAGE_SHIFT)) +#define PKMAP_NR (virt) ((virt - PKMAP_BASE) >> PAGE_SHIFT) +#define PKMAP_ADDR (nr) (PKMAP_BASE + ((nr) << PAGE_SHIFT)) + +#define PKMAP_END (PKMAP_ADDR(LAST_PKMAP))extern void *kmap_high (struct page *page);extern void kunmap_high (struct page *page);static inline void *kmap (struct page *page) { -if (in_interrupt ()) -BUG (); +BUG_ON (in_interrupt ());if (page < highmem_start_page)return page_address (page);return kmap_high (page);
@@ -66,8 +62,7 @@static inline void kunmap (struct page *page) { -if (in_interrupt ()) -BUG (); +BUG_ON (in_interrupt ());if (page < highmem_start_page)return ;kunmap_high (page);
@@ -75,19 +70,7 @@extern void *kmap_atomic (struct page *page,enum km_type type);extern void kunmap_atomic (void *kvaddr,enum km_type type); - -static inline struct page *kmap_atomic_to_page (void *ptr) -{ -unsigned long idx, vaddr = (unsigned long )ptr; -pte_t *pte; - -if (vaddr < fix_kmap_begin) -return virt_to_page (ptr); - - idx = ((vaddr - fix_kmap_begin) >>PAGE_SHIFT ); - pte = kmap_pte + idx; -return pte_page (*pte); -} +extern struct page *kmap_atomic_to_page (void *vaddr);#define flush_cache_kmaps () flush_cache_all()
include/asm-sparc/kmap_types.h +1 -0
@@ -11,6 +11,7 @@KM_BIO_DST_IRQ ,KM_PTE0 ,KM_PTE1 , +KM_PTE2 ,KM_IRQ0 ,KM_IRQ1 , KM_SOFTIRQ0,
include/asm-sparc/page.h +1 -1
@@ -54,7 +54,7 @@#define SPARC_PHYS_BANKS 32 -extern struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS ]; +extern struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS +1 ];/* Cache alias structure. Entry is valid if context != -1. */ struct cache_palias {
include/asm-sparc/pgtsrmmu.h +7 -0
@@ -109,6 +109,13 @@#ifndef __ASSEMBLY__ +/* This makes sense. Honest it does - Anton */ +/* XXX Yes but it's ugly as sin. FIXME. -KMW */ +extern void *srmmu_nocache_pool; +#define __nocache_pa (VADDR ) (((unsigned long)VADDR) - SRMMU_NOCACHE_VADDR + __pa((unsigned long)srmmu_nocache_pool)) +#define __nocache_va (PADDR ) (__va((unsigned long)PADDR) - (unsigned long)srmmu_nocache_pool + SRMMU_NOCACHE_VADDR) +#define __nocache_fix (VADDR ) __va(__nocache_pa(VADDR)) +/* Accessing the MMU control register. */ extern __inline__unsigned int srmmu_get_mmureg (void ) {
include/asm-sparc/vaddrs.h +3 -0
@@ -16,6 +16,9 @@#define SRMMU_NOCACHE_VADDR (KERNBASE + SRMMU_MAXMEM)/* = 0x0fc000000 */ +/* XXX Empiricals - this needs to go away - KMW */ +#define SRMMU_MIN_NOCACHE_PAGES (550) +#define SRMMU_MAX_NOCACHE_PAGES (1280)/* The following constant is used in mm/srmmu.c::srmmu_nocache_calcsize() * to determine the amount of memory that will be reserved as nocache:
Signature · 4 lines
Keith M Wesolowski <[email protected]> http://foobazco.org/~wesolows ------(( Project Foobazco Coordinator and Network Administrator ))------ "May Buddha bless all stubborn people!" -- Uliassutai Karakorum Blake
Quoted 6 lines · On Mon, 5 Jan 2004 20:08:05 -0800 Keith M Wesolowski <[email protected]>…
This fixes BUG-on-swapout for srmmu-based systems. The problem is caused by
kmap_atomic_to_pagebeing fed an aliased (pagetable) address and returning bogons. This also adjusts the pkmap and fixmap base addresses so they cannot overlap.Dave, unless it's braindead, please apply.
Looks good, I'll apply.
Thanks Keith.
Quoted 5 lines · Keith M Wesolowski
This fixes BUG-on-swapout for srmmu-based systems. The problem is caused by
kmap_atomic_to_pagebeing fed an aliased (pagetable) address and returning bogons. This also adjusts the pkmap and fixmap base addresses so they cannot overlap.
Go, Keith!
Quoted 15 lines
arch/sparc/mm/fault.c +1
-1@@ -36,7 +36,7 @@#define ELEMENTS (arr) (sizeof (arr)/sizeof (arr[0])) -extern struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS ]; +extern struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS +1 ];extern int prom_node_root;/* At boot time we determine these two values necessary for setting
include/asm-sparc/page.h line 60
Quoted 8 lines
include/asm-sparc/page.h +1
-1@@ -54,7 +54,7 @@#define SPARC_PHYS_BANKS 32 -extern struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS ]; +extern struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS +1 ];/* Cache alias structure. Entry is valid if context != -1. */ struct cache_palias {
Seems that the first one can be just removed altogether, since you're on it.
include/asm-sparc/kmap_types.h line 17
Quoted 10 lines
include/asm-sparc/kmap_types.h +1
-0@@ -11,6 +11,7 @@KM_BIO_DST_IRQ ,KM_PTE0 ,KM_PTE1 , +KM_PTE2 ,KM_IRQ0 ,KM_IRQ1 , KM_SOFTIRQ0,
Is this needed for anything?
-- Pete
Quoted 5 lines · Pete Zaitcev
Review
Quoted 2 lines
(quoted diff) +1
-1-extern struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS]; +extern struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS+1];Seems that the first one can be just removed altogether, since you're on it.
Yes, you're right. I'll nuke it in my next go-round with mm. Thanks.
Quoted 3 lines
include/asm-sparc/kmap_types.h line 14
Quoted 1 line
include/asm-sparc/kmap_types.h +1
-0+ KM_PTE2,Is this needed for anything?
Not at the moment. It is used on other arches for HIGHPTE however. Thus far I've not dreamed up a sane way to implement that, but a fresh batch of srmmu mushrooms just came in so I'm optimistic. :-)
The options I've considered:
Uncache-in-place. We can't do large mappings, which wastes memory and blows TLB locality to hell.
Uncache-in-place for user pagetables, allocate the kernel pagetables from an uncached block as we do now. This effectively requires user pagetables in highmem, which not all boxes have.
Abuse the zone allocator to force pagetable allocations to come from preassigned regions which are either small-mapped (kernel pte) or unmapped (HIGHPTE for user pagetables). Uncache these in place. Incredibly evil, needlessly complex, and you can still run out.
The 2.2 way.
Leave it the way it is and put in a less fragmentation-happy allocator. Sorry, no HIGHPTE.
Please drop your ideas in the suggestion box. Thanks.
Signature · 4 lines
Keith M Wesolowski <[email protected]> http://foobazco.org/~wesolows ------(( Project Foobazco Coordinator and Network Administrator ))------ "May Buddha bless all stubborn people!" -- Uliassutai Karakorum Blake