Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 Dec 2008 20:28:32 +0000 (UTC)
From:      Kip Macy <kmacy@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r185591 - projects/releng_7_xen/sys/i386/xen
Message-ID:  <200812032028.mB3KSW8j000838@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kmacy
Date: Wed Dec  3 20:28:32 2008
New Revision: 185591
URL: http://svn.freebsd.org/changeset/base/185591

Log:
  merge 184954, 185325, 185245
  
  - convert suspend mutex from semaphore to sx lock
  - make initvalues able to handle an arbitrary number of
    page directories or page tables at startup
  - ensure that all pages used as page tables are bzeroed and then mapped read-only
  - make sure that sysmaps->{CADDR1, CADDR2} are initialized

Modified:
  projects/releng_7_xen/sys/i386/xen/pmap.c
  projects/releng_7_xen/sys/i386/xen/xen_machdep.c

Modified: projects/releng_7_xen/sys/i386/xen/pmap.c
==============================================================================
--- projects/releng_7_xen/sys/i386/xen/pmap.c	Wed Dec  3 20:02:25 2008	(r185590)
+++ projects/releng_7_xen/sys/i386/xen/pmap.c	Wed Dec  3 20:28:32 2008	(r185591)
@@ -246,7 +246,7 @@ struct sysmaps {
 static struct sysmaps sysmaps_pcpu[MAXCPU];
 pt_entry_t *CMAP1 = 0;
 static pt_entry_t *CMAP3;
-caddr_t CADDR1 = 0, ptvmmap = 0;
+caddr_t ptvmmap = 0;
 static caddr_t CADDR3;
 struct msgbuf *msgbufp = 0;
 
@@ -459,9 +459,11 @@ pmap_bootstrap(vm_paddr_t firstaddr)
 		mtx_init(&sysmaps->lock, "SYSMAPS", NULL, MTX_DEF);
 		SYSMAP(caddr_t, sysmaps->CMAP1, sysmaps->CADDR1, 1)
 		SYSMAP(caddr_t, sysmaps->CMAP2, sysmaps->CADDR2, 1)
+		PT_SET_MA(sysmaps->CADDR1, 0);
+		PT_SET_MA(sysmaps->CADDR2, 0);
 	}
-	SYSMAP(caddr_t, CMAP1, CADDR1, 1)
 	SYSMAP(caddr_t, CMAP3, CADDR3, 1)
+
 	PT_SET_MA(CADDR3, 0);
 
 	/*
@@ -488,7 +490,6 @@ pmap_bootstrap(vm_paddr_t firstaddr)
 	mtx_init(&PMAP2mutex, "PMAP2", NULL, MTX_DEF);
 
 	virtual_avail = va;
-	PT_SET_MA(CADDR1, 0);
 
 	/*
 	 * Leave in place an identity mapping (virt == phys) for the low 1 MB

Modified: projects/releng_7_xen/sys/i386/xen/xen_machdep.c
==============================================================================
--- projects/releng_7_xen/sys/i386/xen/xen_machdep.c	Wed Dec  3 20:02:25 2008	(r185590)
+++ projects/releng_7_xen/sys/i386/xen/xen_machdep.c	Wed Dec  3 20:28:32 2008	(r185591)
@@ -821,16 +821,17 @@ initvalues(start_info_t *startinfo)
 	vm_offset_t cur_space, cur_space_pt;
 	struct physdev_set_iopl set_iopl;
 	
-	vm_paddr_t KPTphys, IdlePTDma;
 	vm_paddr_t console_page_ma, xen_store_ma;
-	vm_offset_t KPTphysoff, tmpva;
+	vm_offset_t tmpva;
 	vm_paddr_t shinfo;
 #ifdef PAE
 	vm_paddr_t IdlePDPTma, IdlePDPTnewma;
 	vm_paddr_t IdlePTDnewma[4];
 	pd_entry_t *IdlePDPTnew, *IdlePTDnew;
+	vm_paddr_t IdlePTDma[4];
 #else
-	vm_paddr_t pdir_shadow_ma;
+	vm_paddr_t IdlePTDma[1];
+	
 #endif
 	unsigned long i;
 	int ncpus = MAXCPU;
@@ -850,10 +851,37 @@ initvalues(start_info_t *startinfo)
 #endif	
 	xen_start_info = startinfo;
 	xen_phys_machine = (xen_pfn_t *)startinfo->mfn_list;
+	IdlePTD = (pd_entry_t *)((uint8_t *)startinfo->pt_base + PAGE_SIZE);
+	l1_pages = 0;
+	
+#ifdef PAE
+	l3_pages = 1;
+	l2_pages = 0;
+	IdlePDPT = (pd_entry_t *)startinfo->pt_base;
+	IdlePDPTma = xpmap_ptom(VTOP(startinfo->pt_base));
+	for (i = (((KERNBASE >> 18) & PAGE_MASK) >> 30);
+	     (i < 4) && (IdlePDPT[i] != 0); i++)
+			l2_pages++;
+	/*
+	 * Note that only one page directory has been allocated at this point.
+	 * Thus, if KERNBASE
+	 */
+	for (i = 0; i < l2_pages; i++)
+		IdlePTDma[i] = xpmap_ptom(VTOP(IdlePTD + i*PAGE_SIZE));
+#else	
+	l3_pages = 0;
+	l2_pages = 1;
+#endif
+	for (i = (((KERNBASE>>18) & PAGE_MASK)>>PAGE_SHIFT);
+	     (i<l2_pages*NPDEPG) && (i<(VM_MAX_KERNEL_ADDRESS>>PDRSHIFT)); i++)
+		if (IdlePTD[i] != 0)
+			l1_pages++;
 
+	
 	/* number of pages allocated after the pts + 1*/;
 	cur_space = xen_start_info->pt_base +
-	    ((xen_start_info->nr_pt_frames) + 3 )*PAGE_SIZE;
+	    (l3_pages + l2_pages + l1_pages + 1)*PAGE_SIZE;
+	
 	printk("initvalues(): wooh - availmem=%x,%x\n", avail_space, cur_space);
 
 	printk("KERNBASE=%x,pt_base=%x, VTOPFN(base)=%x, nr_pt_frames=%x\n",
@@ -861,55 +889,13 @@ initvalues(start_info_t *startinfo)
 	    xen_start_info->nr_pt_frames);
 	xendebug_flags = 0; /* 0xffffffff; */
 
-	/* allocate 4 pages for bootmem allocator */
-	bootmem_start = bootmem_current = (char *)cur_space;
-	cur_space += (4 * PAGE_SIZE);
-	bootmem_end = (char *)cur_space;
-
-	/* allocate page for gdt */
-	gdt = (union descriptor *)cur_space;
-	cur_space += PAGE_SIZE*ncpus;
-
-        /* allocate page for ldt */
-	ldt = (union descriptor *)cur_space; cur_space += PAGE_SIZE;
-	cur_space += PAGE_SIZE;
-	
-	HYPERVISOR_shared_info = (shared_info_t *)cur_space;
-	cur_space += PAGE_SIZE;
-
-	xen_store = (struct ringbuf_head *)cur_space;
-	cur_space += PAGE_SIZE;
-
-	console_page = (char *)cur_space;
-	cur_space += PAGE_SIZE;
-
 #ifdef ADD_ISA_HOLE
 	shift_phys_machine(xen_phys_machine, xen_start_info->nr_pages);
 #endif
 	/* 
 	 * pre-zero unused mapped pages - mapped on 4MB boundary
 	 */
-#ifdef PAE
-	IdlePDPT = (pd_entry_t *)startinfo->pt_base;
-	IdlePDPTma = xpmap_ptom(VTOP(startinfo->pt_base));
-	/*
-	 * Note that only one page directory has been allocated at this point.
-	 * Thus, if KERNBASE
-	 */
-	IdlePTD = (pd_entry_t *)((uint8_t *)startinfo->pt_base + PAGE_SIZE);
-	IdlePTDma = xpmap_ptom(VTOP(IdlePTD));
-	l3_pages = 1;
-#else	
-	IdlePTD = (pd_entry_t *)startinfo->pt_base;
-	IdlePTDma = xpmap_ptom(VTOP(startinfo->pt_base));
-	l3_pages = 0;
-#endif
-	l2_pages = 1;
-	l1_pages = xen_start_info->nr_pt_frames - l2_pages - l3_pages;
-
-	KPTphysoff = (l2_pages + l3_pages)*PAGE_SIZE;
 
-	KPTphys = xpmap_ptom(VTOP(startinfo->pt_base + KPTphysoff));
 	XENPRINTF("IdlePTD %p\n", IdlePTD);
 	XENPRINTF("nr_pages: %ld shared_info: 0x%lx flags: 0x%lx pt_base: 0x%lx "
 		  "mod_start: 0x%lx mod_len: 0x%lx\n",
@@ -918,16 +904,6 @@ initvalues(start_info_t *startinfo)
 		  xen_start_info->mod_start, xen_start_info->mod_len);
 	/* Map proc0's KSTACK */
 
-	proc0kstack = cur_space; cur_space += (KSTACK_PAGES * PAGE_SIZE);
-	printk("proc0kstack=%u\n", proc0kstack);
-
-	/* vm86/bios stack */
-	cur_space += PAGE_SIZE;
-
-	/* Map space for the vm86 region */
-	vm86paddr = (vm_offset_t)cur_space;
-	cur_space += (PAGE_SIZE * 3);
-
 #ifdef PAE
 	IdlePDPTnew = (pd_entry_t *)cur_space; cur_space += PAGE_SIZE;
 	bzero(IdlePDPTnew, PAGE_SIZE);
@@ -948,7 +924,6 @@ initvalues(start_info_t *startinfo)
 	for (i = 0; i < 4; i++)
 		IdlePDPTnew[i] = IdlePTDnewma[i] | PG_V;
 
-	__asm__("nop;");
 	/*
 	 *
 	 * re-map the new PDPT read-only
@@ -959,17 +934,30 @@ initvalues(start_info_t *startinfo)
 	 * Unpin the current PDPT
 	 */
 	xen_pt_unpin(IdlePDPTma);
-	
-	for (i = 0; i < 20; i++) {
-		int startidx = ((KERNBASE >> 18) & PAGE_MASK) >> 3;
-
-		if (IdlePTD[startidx + i] == 0) {
-			l1_pages = i;
-			break;
-		}	
-	}
 
 #endif  /* PAE */
+	proc0kstack = cur_space; cur_space += (KSTACK_PAGES * PAGE_SIZE);
+	printk("proc0kstack=%u\n", proc0kstack);
+
+	/* vm86/bios stack */
+	cur_space += PAGE_SIZE;
+
+	/* Map space for the vm86 region */
+	vm86paddr = (vm_offset_t)cur_space;
+	cur_space += (PAGE_SIZE * 3);
+
+	/* allocate 4 pages for bootmem allocator */
+	bootmem_start = bootmem_current = (char *)cur_space;
+	cur_space += (4 * PAGE_SIZE);
+	bootmem_end = (char *)cur_space;
+	
+	/* allocate pages for gdt */
+	gdt = (union descriptor *)cur_space;
+	cur_space += PAGE_SIZE*ncpus;
+
+        /* allocate page for ldt */
+	ldt = (union descriptor *)cur_space; cur_space += PAGE_SIZE;
+	cur_space += PAGE_SIZE;
 	
 	/* unmap remaining pages from initial 4MB chunk
 	 *
@@ -1005,10 +993,10 @@ initvalues(start_info_t *startinfo)
 		 * make sure that all the initial page table pages
 		 * have been zeroed
 		 */
-		PT_SET_MA(cur_space_pt,
+		PT_SET_MA(cur_space,
 		    xpmap_ptom(VTOP(cur_space)) | PG_V | PG_RW);
-		bzero((char *)cur_space_pt, PAGE_SIZE);
-		PT_SET_MA(cur_space_pt, (vm_paddr_t)0);
+		bzero((char *)cur_space, PAGE_SIZE);
+		PT_SET_MA(cur_space, (vm_paddr_t)0);
 		xen_pt_pin(xpmap_ptom(VTOP(cur_space)));
 		xen_queue_pt_update((vm_paddr_t)(IdlePTDnewma[pdir] +
 			curoffset*sizeof(vm_paddr_t)), 
@@ -1030,6 +1018,15 @@ initvalues(start_info_t *startinfo)
 	IdlePTD = IdlePTDnew;
 	IdlePDPT = IdlePDPTnew;
 	IdlePDPTma = IdlePDPTnewma;
+
+	HYPERVISOR_shared_info = (shared_info_t *)cur_space;
+	cur_space += PAGE_SIZE;
+
+	xen_store = (struct ringbuf_head *)cur_space;
+	cur_space += PAGE_SIZE;
+
+	console_page = (char *)cur_space;
+	cur_space += PAGE_SIZE;
 	
 	/*
 	 * shared_info is an unsigned long so this will randomly break if
@@ -1038,7 +1035,6 @@ initvalues(start_info_t *startinfo)
 	 */
 	shinfo = xen_start_info->shared_info;
 	PT_SET_MA(HYPERVISOR_shared_info, shinfo | PG_KERNEL);
-	
 	printk("#4\n");
 
 	xen_store_ma = (((vm_paddr_t)xen_start_info->store_mfn) << PAGE_SHIFT);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200812032028.mB3KSW8j000838>