From: Jeff Dike <jdike@addtoit.com>
To: Tom Spink <tspink@gmail.com>
Cc: "linux-os (Dick Johnson)" <linux-os@analogic.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: UML fails to locate address space
Date: Wed, 21 May 2008 13:58:29 -0400 [thread overview]
Message-ID: <20080521175829.GA10648@c2.user-mode-linux.org> (raw)
In-Reply-To: <7b9198260805210504h278f014s5aba720360ac02ab@mail.gmail.com>
On Wed, May 21, 2008 at 01:04:21PM +0100, Tom Spink wrote:
> Oh No! I forgot to get rid of those nasty includes.... Take 2....
This is actually supposed to return the address space top, not the
size, so I changed the name and return value accordingly.
Other than that, this is fine. The final result is below...
Jeff
--
Work email - jdike at linux dot intel dot com
From: Tom Spink <tspink@gmail.com>
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>
---
arch/um/include/os.h | 2 -
arch/um/kernel/um_arch.c | 2 -
arch/um/os-Linux/sys-i386/task_size.c | 35 +++++++++++++++++++++-----------
arch/um/os-Linux/sys-x86_64/task_size.c | 2 -
4 files changed, 27 insertions(+), 14 deletions(-)
Index: linux-2.6.22/arch/um/include/os.h
===================================================================
--- linux-2.6.22.orig/arch/um/include/os.h 2008-05-21 13:48:23.000000000 -0400
+++ linux-2.6.22/arch/um/include/os.h 2008-05-21 13:48:47.000000000 -0400
@@ -299,6 +299,6 @@ extern int os_arch_prctl(int pid, int co
extern int get_pty(void);
/* sys-$ARCH/task_size.c */
-extern unsigned long os_get_task_size(void);
+extern unsigned long os_get_top_address(void);
#endif
Index: linux-2.6.22/arch/um/kernel/um_arch.c
===================================================================
--- linux-2.6.22.orig/arch/um/kernel/um_arch.c 2008-04-24 13:22:09.000000000 -0400
+++ linux-2.6.22/arch/um/kernel/um_arch.c 2008-05-21 13:46:56.000000000 -0400
@@ -274,7 +274,7 @@ int __init linux_main(int argc, char **a
if (have_root == 0)
add_arg(DEFAULT_COMMAND_LINE);
- host_task_size = os_get_task_size();
+ host_task_size = os_get_top_address();
/*
* TASK_SIZE needs to be PGDIR_SIZE aligned or else exit_mmap craps
* out
Index: linux-2.6.22/arch/um/os-Linux/sys-i386/task_size.c
===================================================================
--- linux-2.6.22.orig/arch/um/os-Linux/sys-i386/task_size.c 2008-04-23 13:07:23.000000000 -0400
+++ linux-2.6.22/arch/um/os-Linux/sys-i386/task_size.c 2008-05-21 13:54:47.000000000 -0400
@@ -63,7 +63,7 @@ static int page_ok(unsigned long page)
return ok;
}
-unsigned long os_get_task_size(void)
+unsigned long os_get_top_address(void)
{
struct sigaction sa, old;
unsigned long bottom = 0;
@@ -76,9 +76,9 @@ unsigned long os_get_task_size(void)
* hosts, but shouldn't hurt otherwise.
*/
unsigned long top = 0xffffd000 >> UM_KERN_PAGE_SHIFT;
- unsigned long test;
+ unsigned long test, original;
- printf("Locating the top of the address space ... ");
+ printf("Locating the bottom of the address space ... ");
fflush(stdout);
/*
@@ -89,16 +89,30 @@ unsigned long os_get_task_size(void)
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_NODEFER;
if (sigaction(SIGSEGV, &sa, &old)) {
- perror("os_get_task_size");
+ perror("os_get_top_address");
exit(1);
}
- if (!page_ok(bottom)) {
- fprintf(stderr, "Address 0x%x no good?\n",
- bottom << UM_KERN_PAGE_SHIFT);
+ /* Manually scan the address space, bottom-up, until we find
+ * the first valid page (or run out of them).
+ */
+ for (bottom = 0; bottom < top; bottom++) {
+ if (page_ok(bottom))
+ break;
+ }
+
+ /* If we've got this far, we ran out of pages. */
+ if (bottom == top) {
+ fprintf(stderr, "Unable to determine bottom of address "
+ "space.\n");
exit(1);
}
+ printf("0x%x\n", bottom << UM_KERN_PAGE_SHIFT);
+ printf("Locating the top of the address space ... ");
+ fflush(stdout);
+
+ original = bottom;
/* This could happen with a 4G/4G split */
if (page_ok(top))
goto out;
@@ -114,11 +128,10 @@ unsigned long os_get_task_size(void)
out:
/* Restore the old SIGSEGV handling */
if (sigaction(SIGSEGV, &old, NULL)) {
- perror("os_get_task_size");
+ perror("os_get_top_address");
exit(1);
}
- top <<= UM_KERN_PAGE_SHIFT;
- printf("0x%x\n", top);
+ printf("0x%x\n", top << UM_KERN_PAGE_SHIFT);
- return top;
+ return top << UM_KERN_PAGE_SHIFT;
}
Index: linux-2.6.22/arch/um/os-Linux/sys-x86_64/task_size.c
===================================================================
--- linux-2.6.22.orig/arch/um/os-Linux/sys-x86_64/task_size.c 2008-02-18 11:53:51.000000000 -0500
+++ linux-2.6.22/arch/um/os-Linux/sys-x86_64/task_size.c 2008-05-21 13:49:59.000000000 -0400
@@ -1,4 +1,4 @@
-unsigned long os_get_task_size(unsigned long shift)
+unsigned long os_get_top_address(unsigned long shift)
{
/* The old value of CONFIG_TOP_ADDR */
return 0x7fc0000000;
next prev parent reply other threads:[~2008-05-21 18:59 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-20 11:08 UML fails to locate address space Tom Spink
2008-05-20 13:52 ` Jeff Dike
2008-05-20 13:59 ` Tom Spink
2008-05-20 16:10 ` Jeff Dike
2008-05-20 16:43 ` Tom Spink
2008-05-20 17:56 ` Jeff Dike
2008-05-20 18:01 ` Tom Spink
2008-05-20 19:24 ` Jeff Dike
2008-05-20 19:42 ` Tom Spink
2008-05-20 21:27 ` Jeff Dike
2008-05-20 22:03 ` Tom Spink
2008-05-20 23:57 ` Tom Spink
2008-05-21 1:58 ` Jeff Dike
2008-05-20 15:22 ` linux-os (Dick Johnson)
2008-05-20 17:35 ` Jeff Dike
2008-05-20 21:54 ` linux-os (Dick Johnson)
2008-05-21 2:15 ` Jeff Dike
2008-05-21 12:02 ` Tom Spink
2008-05-21 12:04 ` Tom Spink
2008-05-21 17:58 ` Jeff Dike [this message]
2008-05-21 19:01 ` Tom Spink
2008-05-20 21:58 ` linux-os (Dick Johnson)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080521175829.GA10648@c2.user-mode-linux.org \
--to=jdike@addtoit.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-os@analogic.com \
--cc=tspink@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox