* [PATCH 1/4] um: fix UML_LIB_PATH
@ 2011-05-08 21:59 Richard Weinberger
2011-05-08 21:59 ` [PATCH 2/4] um: fix abort Richard Weinberger
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Richard Weinberger @ 2011-05-08 21:59 UTC (permalink / raw)
To: linux-kernel; +Cc: user-mode-linux-devel, Richard Weinberger
UML_LIB_PATH is hardcoded to /usr/lib/uml/,
on 64bit systems UML_LIB_PATH needs to be /usr/lib64/uml/.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
arch/um/drivers/xterm.c | 2 +-
arch/um/include/shared/os.h | 7 +++++++
arch/um/os-Linux/main.c | 2 +-
3 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/arch/um/drivers/xterm.c b/arch/um/drivers/xterm.c
index da2caa5..8ac7146 100644
--- a/arch/um/drivers/xterm.c
+++ b/arch/um/drivers/xterm.c
@@ -90,7 +90,7 @@ static int xterm_open(int input, int output, int primary, void *d,
int pid, fd, new, err;
char title[256], file[] = "/tmp/xterm-pipeXXXXXX";
char *argv[] = { terminal_emulator, title_switch, title, exec_switch,
- "/usr/lib/uml/port-helper", "-uml-socket",
+ OS_LIB_PATH "/uml/port-helper", "-uml-socket",
file, NULL };
if (access(argv[4], X_OK) < 0)
diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h
index c4617ba..83c7c2e 100644
--- a/arch/um/include/shared/os.h
+++ b/arch/um/include/shared/os.h
@@ -29,6 +29,12 @@
#define OS_ACC_R_OK 4 /* Test for read permission. */
#define OS_ACC_RW_OK (OS_ACC_W_OK | OS_ACC_R_OK) /* Test for RW permission */
+#ifdef CONFIG_64BIT
+#define OS_LIB_PATH "/usr/lib64/"
+#else
+#define OS_LIB_PATH "/usr/lib/"
+#endif
+
/*
* types taken from stat_file() in hostfs_user.c
* (if they are wrong here, they are wrong there...).
@@ -238,6 +244,7 @@ extern int raw(int fd);
extern void setup_machinename(char *machine_out);
extern void setup_hostinfo(char *buf, int len);
extern void os_dump_core(void) __attribute__ ((noreturn));
+extern void um_early_printk(const char *s, unsigned int n);
/* time.c */
extern void idle_sleep(unsigned long long nsecs);
diff --git a/arch/um/os-Linux/main.c b/arch/um/os-Linux/main.c
index eee69b9..39613ea 100644
--- a/arch/um/os-Linux/main.c
+++ b/arch/um/os-Linux/main.c
@@ -78,7 +78,7 @@ static void install_fatal_handler(int sig)
}
}
-#define UML_LIB_PATH ":/usr/lib/uml"
+#define UML_LIB_PATH ":" OS_LIB_PATH "/uml"
static void setup_env_path(void)
{
--
1.7.4.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/4] um: fix abort
2011-05-08 21:59 [PATCH 1/4] um: fix UML_LIB_PATH Richard Weinberger
@ 2011-05-08 21:59 ` Richard Weinberger
2011-05-08 21:59 ` [PATCH 3/4] um: remove SIGHUP handler Richard Weinberger
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Richard Weinberger @ 2011-05-08 21:59 UTC (permalink / raw)
To: linux-kernel; +Cc: user-mode-linux-devel, Richard Weinberger
os_dump_core() uses abort() to terminate UML in case of an
fatal error.
glibc's abort() calls raise(SIGABRT) which makes use of tgkill().
tgkill() has no effect within UML's kernel threads because they
are not pthreads. As fallback abort() executes an invalid instruction
to terminate the process. Therefore UML gets killed by SIGSEGV and
leaves a ugly log entry in the host's kernel ring buffer.
To get rid of this use our own abort routine.
# Untracked files:
Signed-off-by: Richard Weinberger <richard@nod.at>
---
arch/um/os-Linux/util.c | 23 ++++++++++++++++++++++-
1 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/arch/um/os-Linux/util.c b/arch/um/os-Linux/util.c
index 6ea7797..42827ca 100644
--- a/arch/um/os-Linux/util.c
+++ b/arch/um/os-Linux/util.c
@@ -5,6 +5,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <string.h>
@@ -75,6 +76,26 @@ void setup_hostinfo(char *buf, int len)
host.release, host.version, host.machine);
}
+/*
+ * We cannot use glibc's abort(). It makes use of tgkill() which
+ * has no effect within UML's kernel threads.
+ * After that glibc would execute an invalid instruction to kill
+ * the calling process and UML crashes with SIGSEGV.
+ */
+static inline void __attribute__ ((noreturn)) uml_abort(void)
+{
+ sigset_t sig;
+
+ fflush(NULL);
+
+ if (!sigemptyset(&sig) && !sigaddset(&sig, SIGABRT))
+ sigprocmask(SIG_UNBLOCK, &sig, 0);
+
+ for (;;)
+ if (kill(getpid(), SIGABRT) < 0)
+ exit(127);
+}
+
void os_dump_core(void)
{
int pid;
@@ -116,5 +137,5 @@ void os_dump_core(void)
while ((pid = waitpid(-1, NULL, WNOHANG | __WALL)) > 0)
os_kill_ptraced_process(pid, 0);
- abort();
+ uml_abort();
}
--
1.7.4.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/4] um: remove SIGHUP handler
2011-05-08 21:59 [PATCH 1/4] um: fix UML_LIB_PATH Richard Weinberger
2011-05-08 21:59 ` [PATCH 2/4] um: fix abort Richard Weinberger
@ 2011-05-08 21:59 ` Richard Weinberger
2011-05-08 21:59 ` [PATCH 4/4] um: os_dump_core() cleanup Richard Weinberger
2011-05-08 22:19 ` [uml-devel] [PATCH 1/4] um: fix UML_LIB_PATH Mattia Dongili
3 siblings, 0 replies; 6+ messages in thread
From: Richard Weinberger @ 2011-05-08 21:59 UTC (permalink / raw)
To: linux-kernel; +Cc: user-mode-linux-devel, Richard Weinberger
The UML kernel ignores SIGHUP anyway.
This handler is in vain.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
arch/um/os-Linux/main.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/arch/um/os-Linux/main.c b/arch/um/os-Linux/main.c
index 39613ea..fb2a97a 100644
--- a/arch/um/os-Linux/main.c
+++ b/arch/um/os-Linux/main.c
@@ -142,7 +142,6 @@ int __init main(int argc, char **argv, char **envp)
*/
install_fatal_handler(SIGINT);
install_fatal_handler(SIGTERM);
- install_fatal_handler(SIGHUP);
scan_elf_aux(envp);
--
1.7.4.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/4] um: os_dump_core() cleanup
2011-05-08 21:59 [PATCH 1/4] um: fix UML_LIB_PATH Richard Weinberger
2011-05-08 21:59 ` [PATCH 2/4] um: fix abort Richard Weinberger
2011-05-08 21:59 ` [PATCH 3/4] um: remove SIGHUP handler Richard Weinberger
@ 2011-05-08 21:59 ` Richard Weinberger
2011-05-08 22:19 ` [uml-devel] [PATCH 1/4] um: fix UML_LIB_PATH Mattia Dongili
3 siblings, 0 replies; 6+ messages in thread
From: Richard Weinberger @ 2011-05-08 21:59 UTC (permalink / raw)
To: linux-kernel; +Cc: user-mode-linux-devel, Richard Weinberger
When os_dump_core() raises SIGTERM to bring down all
UML processes this would also trigger the quite complex
do_uml_exitcalls() routine.
This is why UML crashed often while panicking.
Let's make os_dump_core() short and painless by killing all UML
processes with SIGHUP and calling the only sane exit call in this
context (remove_umid_dir()) by hand.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
arch/um/include/shared/os.h | 1 +
arch/um/os-Linux/umid.c | 2 +-
arch/um/os-Linux/util.c | 22 +++++++---------------
3 files changed, 9 insertions(+), 16 deletions(-)
diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h
index 83c7c2e..dedb345 100644
--- a/arch/um/include/shared/os.h
+++ b/arch/um/include/shared/os.h
@@ -226,6 +226,7 @@ extern int os_get_thread_area(user_desc_t *info, int pid);
extern int umid_file_name(char *name, char *buf, int len);
extern int set_umid(char *name);
extern char *get_umid(void);
+extern void remove_umid_dir(void);
/* signal.c */
extern void timer_init(void);
diff --git a/arch/um/os-Linux/umid.c b/arch/um/os-Linux/umid.c
index a27defb..48312a4 100644
--- a/arch/um/os-Linux/umid.c
+++ b/arch/um/os-Linux/umid.c
@@ -382,7 +382,7 @@ __uml_setup("uml_dir=", set_uml_dir,
" The location to place the pid and umid files.\n\n"
);
-static void remove_umid_dir(void)
+void remove_umid_dir(void)
{
char dir[strlen(uml_dir) + UMID_LEN + 1], err;
diff --git a/arch/um/os-Linux/util.c b/arch/um/os-Linux/util.c
index 42827ca..73d32f2 100644
--- a/arch/um/os-Linux/util.c
+++ b/arch/um/os-Linux/util.c
@@ -103,30 +103,21 @@ void os_dump_core(void)
signal(SIGSEGV, SIG_DFL);
/*
- * We are about to SIGTERM this entire process group to ensure that
- * nothing is around to run after the kernel exits. The
- * kernel wants to abort, not die through SIGTERM, so we
- * ignore it here.
+ * Send SIGHUP to kill non-kernel processes, kernel processes
+ * ignore SIGHUP.
+ * We are using SIGHUP because it has the same effekt as SIGTERM
+ * but it does not trigger another signal handlers.
*/
+ kill(0, SIGHUP);
- signal(SIGTERM, SIG_IGN);
- kill(0, SIGTERM);
/*
* Most of the other processes associated with this UML are
* likely sTopped, so give them a SIGCONT so they see the
- * SIGTERM.
+ * SIGHUP.
*/
kill(0, SIGCONT);
/*
- * Now, having sent signals to everyone but us, make sure they
- * die by ptrace. Processes can survive what's been done to
- * them so far - the mechanism I understand is receiving a
- * SIGSEGV and segfaulting immediately upon return. There is
- * always a SIGSEGV pending, and (I'm guessing) signals are
- * processed in numeric order so the SIGTERM (signal 15 vs
- * SIGSEGV being signal 11) is never handled.
- *
* Run a waitpid loop until we get some kind of error.
* Hopefully, it's ECHILD, but there's not a lot we can do if
* it's something else. Tell os_kill_ptraced_process not to
@@ -137,5 +128,6 @@ void os_dump_core(void)
while ((pid = waitpid(-1, NULL, WNOHANG | __WALL)) > 0)
os_kill_ptraced_process(pid, 0);
+ remove_umid_dir();
uml_abort();
}
--
1.7.4.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [uml-devel] [PATCH 1/4] um: fix UML_LIB_PATH
2011-05-08 21:59 [PATCH 1/4] um: fix UML_LIB_PATH Richard Weinberger
` (2 preceding siblings ...)
2011-05-08 21:59 ` [PATCH 4/4] um: os_dump_core() cleanup Richard Weinberger
@ 2011-05-08 22:19 ` Mattia Dongili
2011-05-08 22:24 ` Richard Weinberger
3 siblings, 1 reply; 6+ messages in thread
From: Mattia Dongili @ 2011-05-08 22:19 UTC (permalink / raw)
To: Richard Weinberger; +Cc: linux-kernel, user-mode-linux-devel
On Sun, May 08, 2011 at 11:59:42PM +0200, Richard Weinberger wrote:
> UML_LIB_PATH is hardcoded to /usr/lib/uml/,
> on 64bit systems UML_LIB_PATH needs to be /usr/lib64/uml/.
>
> Signed-off-by: Richard Weinberger <richard@nod.at>
> ---
> arch/um/drivers/xterm.c | 2 +-
> arch/um/include/shared/os.h | 7 +++++++
> arch/um/os-Linux/main.c | 2 +-
> 3 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/arch/um/drivers/xterm.c b/arch/um/drivers/xterm.c
> index da2caa5..8ac7146 100644
> --- a/arch/um/drivers/xterm.c
> +++ b/arch/um/drivers/xterm.c
> @@ -90,7 +90,7 @@ static int xterm_open(int input, int output, int primary, void *d,
> int pid, fd, new, err;
> char title[256], file[] = "/tmp/xterm-pipeXXXXXX";
> char *argv[] = { terminal_emulator, title_switch, title, exec_switch,
> - "/usr/lib/uml/port-helper", "-uml-socket",
> + OS_LIB_PATH "/uml/port-helper", "-uml-socket",
> file, NULL };
>
> if (access(argv[4], X_OK) < 0)
> diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h
> index c4617ba..83c7c2e 100644
> --- a/arch/um/include/shared/os.h
> +++ b/arch/um/include/shared/os.h
> @@ -29,6 +29,12 @@
> #define OS_ACC_R_OK 4 /* Test for read permission. */
> #define OS_ACC_RW_OK (OS_ACC_W_OK | OS_ACC_R_OK) /* Test for RW permission */
>
> +#ifdef CONFIG_64BIT
> +#define OS_LIB_PATH "/usr/lib64/"
> +#else
> +#define OS_LIB_PATH "/usr/lib/"
> +#endif
> +
> /*
> * types taken from stat_file() in hostfs_user.c
> * (if they are wrong here, they are wrong there...).
> @@ -238,6 +244,7 @@ extern int raw(int fd);
> extern void setup_machinename(char *machine_out);
> extern void setup_hostinfo(char *buf, int len);
> extern void os_dump_core(void) __attribute__ ((noreturn));
> +extern void um_early_printk(const char *s, unsigned int n);
this hunk seems unrelated to this change.
Regards,
--
mattia
:wq!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [uml-devel] [PATCH 1/4] um: fix UML_LIB_PATH
2011-05-08 22:19 ` [uml-devel] [PATCH 1/4] um: fix UML_LIB_PATH Mattia Dongili
@ 2011-05-08 22:24 ` Richard Weinberger
0 siblings, 0 replies; 6+ messages in thread
From: Richard Weinberger @ 2011-05-08 22:24 UTC (permalink / raw)
To: Mattia Dongili; +Cc: linux-kernel, user-mode-linux-devel
Am Montag 09 Mai 2011, 00:19:53 schrieb Mattia Dongili:
> On Sun, May 08, 2011 at 11:59:42PM +0200, Richard Weinberger wrote:
> > UML_LIB_PATH is hardcoded to /usr/lib/uml/,
> > on 64bit systems UML_LIB_PATH needs to be /usr/lib64/uml/.
> >
> > Signed-off-by: Richard Weinberger <richard@nod.at>
> > ---
> >
> > arch/um/drivers/xterm.c | 2 +-
> > arch/um/include/shared/os.h | 7 +++++++
> > arch/um/os-Linux/main.c | 2 +-
> > 3 files changed, 9 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/um/drivers/xterm.c b/arch/um/drivers/xterm.c
> > index da2caa5..8ac7146 100644
> > --- a/arch/um/drivers/xterm.c
> > +++ b/arch/um/drivers/xterm.c
> > @@ -90,7 +90,7 @@ static int xterm_open(int input, int output, int
> > primary, void *d,
> >
> > int pid, fd, new, err;
> > char title[256], file[] = "/tmp/xterm-pipeXXXXXX";
> > char *argv[] = { terminal_emulator, title_switch, title, exec_switch,
> >
> > - "/usr/lib/uml/port-helper", "-uml-socket",
> > + OS_LIB_PATH "/uml/port-helper", "-uml-socket",
> >
> > file, NULL };
> >
> > if (access(argv[4], X_OK) < 0)
> >
> > diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h
> > index c4617ba..83c7c2e 100644
> > --- a/arch/um/include/shared/os.h
> > +++ b/arch/um/include/shared/os.h
> > @@ -29,6 +29,12 @@
> >
> > #define OS_ACC_R_OK 4 /* Test for read permission. */
> > #define OS_ACC_RW_OK (OS_ACC_W_OK | OS_ACC_R_OK) /* Test for RW
> > permission */
> >
> > +#ifdef CONFIG_64BIT
> > +#define OS_LIB_PATH "/usr/lib64/"
> > +#else
> > +#define OS_LIB_PATH "/usr/lib/"
> > +#endif
> > +
> >
> > /*
> >
> > * types taken from stat_file() in hostfs_user.c
> > * (if they are wrong here, they are wrong there...).
> >
> > @@ -238,6 +244,7 @@ extern int raw(int fd);
> >
> > extern void setup_machinename(char *machine_out);
> > extern void setup_hostinfo(char *buf, int len);
> > extern void os_dump_core(void) __attribute__ ((noreturn));
> >
> > +extern void um_early_printk(const char *s, unsigned int n);
>
> this hunk seems unrelated to this change.
Good catch!
Thanks,
//richard
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-05-08 22:25 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-08 21:59 [PATCH 1/4] um: fix UML_LIB_PATH Richard Weinberger
2011-05-08 21:59 ` [PATCH 2/4] um: fix abort Richard Weinberger
2011-05-08 21:59 ` [PATCH 3/4] um: remove SIGHUP handler Richard Weinberger
2011-05-08 21:59 ` [PATCH 4/4] um: os_dump_core() cleanup Richard Weinberger
2011-05-08 22:19 ` [uml-devel] [PATCH 1/4] um: fix UML_LIB_PATH Mattia Dongili
2011-05-08 22:24 ` Richard Weinberger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox