From: Blaisorblade <blaisorblade@yahoo.it>
To: user-mode-linux-devel@lists.sourceforge.net
Cc: Werner Almesberger <wa@almesberger.net>,
Jeff Dike <jdike@addtoit.com>, Rob Landley <rob@landley.net>
Subject: Re: [uml-devel] Occasional hang starting up.
Date: Fri, 17 Mar 2006 20:36:58 +0100 [thread overview]
Message-ID: <200603172036.59218.blaisorblade@yahoo.it> (raw)
In-Reply-To: <20060316112251.A17140@almesberger.net>
[-- Attachment #1: Type: text/plain, Size: 1395 bytes --]
On Thursday 16 March 2006 15:22, Werner Almesberger wrote:
> Jeff Dike wrote:
> > Having said that,
> > if you can get a stack from the hang, it might turn out to be an easily
> > diagnosed and fixed bug.
>
> Seems that arch/um/kernel/sigio_user.c:write_sigio_thread begins
> its poll before there are any fds in current_poll
Ah, and you mean it hangs...
> , so update_thread
> caused by a add_sigio_fd shortly thereafter hangs while waiting for
> a response.
Clearly
> A sleep(1) at the beginning of write_sigio_thread "fixes" this :-)
Er... there's only one thing which seems unclear - poll(NULL, 0, -1) shouldn't
fail with -EFAULT instead of hanging? Yep, it should. I didn't believe what
you said, so. But then I went to check the implementation. And, indeed, it
seems that Linux isn't up to this :-).
So:
1) I'll try to fix poll(2) to return -EINVAL. Dunno whether anyone will say
"no, the app is stupid, it deserves no error", but hope not (with "try" I
refer to this). Attached patch should do this.
2) write_sigio_thread should do a "down" on a semaphore/mutex and the first
update_thread should "up" it. As usually, this semaphore would be indeed
implemented as a pipe.
--
Inform me of my mistakes, so I can keep imitating Homer Simpson's "Doh!".
Paolo Giarrusso, aka Blaisorblade (Skype ID "PaoloGiarrusso", ICQ 215621894)
http://www.user-mode-linux.org/~blaisorblade
[-- Attachment #2: poll-mustn_t-hang-0-fds.patch --]
[-- Type: text/x-diff, Size: 1062 bytes --]
poll(2): don't hang caller if nfds == 0
From: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>, Werner Almesberger <wa@almesberger.net>
As Werner Almesberger observed in a real program, poll(2) will never return if
called with nfds == 0; which is stupid but not so badly deserving.
I looked at the code and verified that indeed such a case is never detected and
do_poll keeps looping, checking any fd passed, overlooking it wasn't passed any
and calling schedule_timeout() endlessly. At least it's a TASK_INTERRUPTIBLE
sleep...
Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Index: linux-2.6.git/fs/select.c
===================================================================
--- linux-2.6.git.orig/fs/select.c
+++ linux-2.6.git/fs/select.c
@@ -629,6 +629,10 @@ int do_sys_poll(struct pollfd __user *uf
struct fdtable *fdt;
int max_fdset;
+ /* Otherwise below code would hang! */
+ if (unlikely(nfds < 1))
+ return -EINVAL;
+
/* Do a sanity check on nfds ... */
rcu_read_lock();
fdt = files_fdtable(current->files);
next prev parent reply other threads:[~2006-03-17 19:38 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-11 18:01 [uml-devel] Occasional hang starting up Rob Landley
2006-03-12 20:33 ` Blaisorblade
2006-03-14 20:22 ` Jeff Dike
2006-03-14 21:31 ` Rob Landley
2006-03-16 14:22 ` Werner Almesberger
2006-03-17 19:36 ` Blaisorblade [this message]
2006-03-17 21:27 ` Werner Almesberger
2006-03-17 22:14 ` Blaisorblade
2006-03-17 23:54 ` Werner Almesberger
2006-03-20 10:20 ` Werner Almesberger
2006-03-21 1:00 ` Jeff Dike
2006-03-21 1:21 ` Blaisorblade
2006-03-23 18:45 ` Jeff Dike
2006-03-23 19:05 ` Werner Almesberger
2006-03-23 20:13 ` Jeff Dike
2006-03-23 21:23 ` Werner Almesberger
2006-03-23 21:43 ` Jeff Dike
2006-03-24 0:37 ` Blaisorblade
2006-03-24 2:26 ` Jeff Dike
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=200603172036.59218.blaisorblade@yahoo.it \
--to=blaisorblade@yahoo.it \
--cc=jdike@addtoit.com \
--cc=rob@landley.net \
--cc=user-mode-linux-devel@lists.sourceforge.net \
--cc=wa@almesberger.net \
/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