Skip to contentSkip to conversation

2.6.8-rc4-mm1 - UML fixes

PATCH In review Jeff Dike 2 participants 5 messages Aug 12, 2004 User-mode Linux (UML)

lore
Share & tools
lore

Jeff Dike

author
#0 lore raw

PATCH 3/3 2.6.8-rc4-mm1 - UML fixes

The patch below fixes a few UML-specific bugs not related to the rest of the kernel
a bogus error return and some formatting in the fork code correct calculation of task.thread.kernel_stack
remove a bogus panic
a couple of fixes to allow UML to boot in the presence of exec-shield

Jeff

arch/um/kernel/process.c +7 -3
Index: 2.6.8-rc4-mm1/arch/um/kernel/process.c
===================================================================
@@ -124,10 +124,14 @@
 
 	/* Start the process and wait for it to kill itself */
 	new_pid = clone(outer_tramp, (void *) sp, clone_flags, &arg);
-	if(new_pid < 0) return(-errno);
+	if(new_pid < 0) 
+		return(new_pid);
+
 	CATCH_EINTR(err = waitpid(new_pid, &status, 0));
-	if(err < 0) panic("Waiting for outer trampoline failed - errno = %d", 
-			  errno);
+	if(err < 0) 
+		panic("Waiting for outer trampoline failed - errno = %d", 
+		      errno);
+
 	if(!WIFSIGNALED(status) || (WTERMSIG(status) != SIGKILL))
 		panic("outer trampoline didn't exit with SIGKILL, "
 		      "status = %d", status);
arch/um/kernel/process_kern.c +1 -1
Index: 2.6.8-rc4-mm1/arch/um/kernel/process_kern.c
===================================================================
@@ -167,7 +167,7 @@
 {
 	p->thread = (struct thread_struct) INIT_THREAD;
 	p->thread.kernel_stack = 
-		(unsigned long) p->thread_info + THREAD_SIZE;
+		(unsigned long) p->thread_info + 2 * PAGE_SIZE;
 	return(CHOOSE_MODE_PROC(copy_thread_tt, copy_thread_skas, nr, 
 				clone_flags, sp, stack_top, p, regs));
 }
arch/um/kernel/trap_kern.c +0 -2
Index: 2.6.8-rc4-mm1/arch/um/kernel/trap_kern.c
===================================================================
@@ -54,8 +54,6 @@
 	if(is_write && !(vma->vm_flags & VM_WRITE)) 
 		goto out;
 	page = address & PAGE_MASK;
-	if(address < (unsigned long) current_thread + 1024 && !is_user)
-		panic("Kernel stack overflow");
 	pgd = pgd_offset(mm, page);
 	pmd = pmd_offset(pgd, page);
 	do {
arch/um/kernel/tt/mem.c +1 -1
Index: 2.6.8-rc4-mm1/arch/um/kernel/tt/mem.c
===================================================================
@@ -18,7 +18,7 @@
 	if(!jail || debug)
 		remap_data(UML_ROUND_DOWN(&_stext), UML_ROUND_UP(&_etext), 1);
 	remap_data(UML_ROUND_DOWN(&_sdata), UML_ROUND_UP(&_edata), 1);
-	remap_data(UML_ROUND_DOWN(&__bss_start), UML_ROUND_UP(brk_start), 1);
+	remap_data(UML_ROUND_DOWN(&__bss_start), UML_ROUND_UP(&_end), 1);
 }
 
 #ifdef CONFIG_HOST_2G_2G
arch/um/kernel/tt/process_kern.c +1 -1
Index: 2.6.8-rc4-mm1/arch/um/kernel/tt/process_kern.c
===================================================================
@@ -412,7 +412,7 @@
 	protect_memory(start, end - start, 1, w, 1, 1);
 
 	start = (unsigned long) UML_ROUND_DOWN(&__bss_start);
-	end = (unsigned long) UML_ROUND_UP(brk_start);
+	end = (unsigned long) UML_ROUND_UP(&_end);
 	protect_memory(start, end - start, 1, w, 1, 1);
 
 	mprotect_kernel_vm(w);
#1 lore raw
Quoted 6 lines · Jeff Dike

The patch below fixes a few UML-specific bugs not related to the rest of the kernel
a bogus error return and some formatting in the fork code correct calculation of task.thread.kernel_stack
remove a bogus panic
a couple of fixes to allow UML to boot in the presence of exec-shield

[...]

arch/um/kernel/process_kern.c line 172

Quoted 5 lines
arch/um/kernel/process_kern.c +1 -1
 	p->thread.kernel_stack = 
-		(unsigned long) p->thread_info + THREAD_SIZE;
+		(unsigned long) p->thread_info + 2 * PAGE_SIZE;
 	return(CHOOSE_MODE_PROC(copy_thread_tt, copy_thread_skas, nr, 
 				clone_flags, sp, stack_top, p, regs));

Out of curiosity, why are you allocating 4*PAGE_SIZE for the stack if you're only going to use 2*PAGE_SIZE of it? I saw no other users for the rest of ->thread_info offhand.

-- wli

author
#2 lore raw
Quoted 3 lines · [email protected] said:

Out of curiosity, why are you allocating 4*PAGE_SIZE for the stack if you're only going to use 2*PAGE_SIZE of it? I saw no other users for the rest of ->thread_info offhand.

Well, that's slightly misleading. The other two pages (minus the thread_info) are available for stack if needed. UML stacks are somewhat larger than the native kernel stacks because of the userspace signal frames, so I allocate 4 pages for now to be safe.

Jeff

#3 lore raw
Quoted 3 lines · [email protected] said:
Quoted 3 lines

Out of curiosity, why are you allocating 4*PAGE_SIZE for the stack if you're only going to use 2*PAGE_SIZE of it? I saw no other users for the rest of ->thread_info offhand.

Quoted 4 lines · Jeff Dike

Well, that's slightly misleading. The other two pages (minus the thread_info) are available for stack if needed. UML stacks are somewhat larger than the native kernel stacks because of the userspace signal frames, so I allocate 4 pages for now to be safe.

This might confuse CONFIG_DEBUG_PAGEALLOC, which uses THREAD_SIZE to detect the end of the kernel stack in store_stackinfo() in mm/slab.c and kstack_end() in include/linux/sched.h, and the sizing heuristic for max_threads in fork_init().

Also, how is this meant to interoperate with CONFIG_KERNEL_STACK_ORDER? It seems to ignore the setting from the config option.

-- wli

author
#4 lore raw
Quoted 4 lines · [email protected] said:

This might confuse CONFIG_DEBUG_PAGEALLOC, which uses THREAD_SIZE to detect the end of the kernel stack in store_stackinfo() in mm/slab.c and kstack_end() in include/linux/sched.h, and the sizing heuristic for max_threads in fork_init().

I think it's OK. UML isn't lying about its stack size, just that snippet of code is misleading.

Quoted 2 lines

Also, how is this meant to interoperate with CONFIG_KERNEL_STACK_ORDER?
It seems to ignore the setting from the config option.

I'm going to fix that. For this patch I just did the quickest thing and reverted back to what was there before.

Jeff