Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

uml: deal with inaccessible address space start

This patch makes os_get_task_size locate the bottom of the address space,
as well as the top. This is for systems which put a lower limit on mmap
addresses. It works by manually scanning pages from zero onwards until a
valid page is found.

Because the bottom of the address space may not be zero, it's not
sufficient to assume the top of the address space is the size of the
address space. The size is the difference between the top address and
bottom address.

[jdike@addtoit.com: changed the name to reflect that this function is
supposed to return the top of the process address space, not its size and
changed the return value to reflect that. Also some minor formatting
changes]
Signed-off-by: Tom Spink <tspink@gmail.com>
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Tom Spink and committed by
Linus Torvalds
40fb16a3 9f31287b

+26 -11
+1 -1
arch/um/include/os.h
··· 299 299 extern int get_pty(void); 300 300 301 301 /* sys-$ARCH/task_size.c */ 302 - extern unsigned long os_get_task_size(void); 302 + extern unsigned long os_get_top_address(void); 303 303 304 304 #endif
+1 -1
arch/um/kernel/um_arch.c
··· 274 274 if (have_root == 0) 275 275 add_arg(DEFAULT_COMMAND_LINE); 276 276 277 - host_task_size = os_get_task_size(); 277 + host_task_size = os_get_top_address(); 278 278 /* 279 279 * TASK_SIZE needs to be PGDIR_SIZE aligned or else exit_mmap craps 280 280 * out
+23 -8
arch/um/os-Linux/sys-i386/task_size.c
··· 63 63 return ok; 64 64 } 65 65 66 - unsigned long os_get_task_size(void) 66 + unsigned long os_get_top_address(void) 67 67 { 68 68 struct sigaction sa, old; 69 69 unsigned long bottom = 0; ··· 76 76 * hosts, but shouldn't hurt otherwise. 77 77 */ 78 78 unsigned long top = 0xffffd000 >> UM_KERN_PAGE_SHIFT; 79 - unsigned long test; 79 + unsigned long test, original; 80 80 81 - printf("Locating the top of the address space ... "); 81 + printf("Locating the bottom of the address space ... "); 82 82 fflush(stdout); 83 83 84 84 /* ··· 89 89 sigemptyset(&sa.sa_mask); 90 90 sa.sa_flags = SA_NODEFER; 91 91 if (sigaction(SIGSEGV, &sa, &old)) { 92 - perror("os_get_task_size"); 92 + perror("os_get_top_address"); 93 93 exit(1); 94 94 } 95 95 96 - if (!page_ok(bottom)) { 97 - fprintf(stderr, "Address 0x%x no good?\n", 98 - bottom << UM_KERN_PAGE_SHIFT); 96 + /* Manually scan the address space, bottom-up, until we find 97 + * the first valid page (or run out of them). 98 + */ 99 + for (bottom = 0; bottom < top; bottom++) { 100 + if (page_ok(bottom)) 101 + break; 102 + } 103 + 104 + /* If we've got this far, we ran out of pages. */ 105 + if (bottom == top) { 106 + fprintf(stderr, "Unable to determine bottom of address " 107 + "space.\n"); 99 108 exit(1); 100 109 } 110 + 111 + printf("0x%x\n", bottom << UM_KERN_PAGE_SHIFT); 112 + printf("Locating the top of the address space ... "); 113 + fflush(stdout); 114 + 115 + original = bottom; 101 116 102 117 /* This could happen with a 4G/4G split */ 103 118 if (page_ok(top)) ··· 129 114 out: 130 115 /* Restore the old SIGSEGV handling */ 131 116 if (sigaction(SIGSEGV, &old, NULL)) { 132 - perror("os_get_task_size"); 117 + perror("os_get_top_address"); 133 118 exit(1); 134 119 } 135 120 top <<= UM_KERN_PAGE_SHIFT;
+1 -1
arch/um/os-Linux/sys-x86_64/task_size.c
··· 1 - unsigned long os_get_task_size(unsigned long shift) 1 + unsigned long os_get_top_address(unsigned long shift) 2 2 { 3 3 /* The old value of CONFIG_TOP_ADDR */ 4 4 return 0x7fc0000000;