Commit 3075d9da authored by Chris Wright's avatar Chris Wright Committed by Linus Torvalds

Use ERESTART_RESTARTBLOCK if poll() is interrupted by a signal

Lomesh reported poll returning EINTR during suspend/resume cycle.  This is
caused by the STOP/CONT cycle that the freezer uses, generating a pending
signal for what in effect is an ignored signal.  In general poll is a
little eager in returning EINTR, when it could try not bother userspace and
simply restart the syscall.  Both select and ppoll do use ERESTARTNOHAND to
restart the syscall.  Oleg points out that simply using ERESTARTNOHAND will
cause poll to restart with original timeout value.  which could ultimately
lead to process never returning to userspace.  Instead use
ERESTART_RESTARTBLOCK, and restart poll with updated timeout value.
Inspired by Manfred's use ERESTARTNOHAND in poll patch.

[bunk@kernel.org: do_restart_poll() can become static]
Cc: Manfred Spraul <manfred@colorfullife.com>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Roland McGrath <roland@redhat.com>
Cc: "Agarwal, Lomesh" <lomesh.agarwal@intel.com>
Signed-off-by: default avatarChris Wright <chrisw@sous-sol.org>
Signed-off-by: default avatarAdrian Bunk <bunk@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7e341fa1
...@@ -714,10 +714,28 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds, s64 *timeout) ...@@ -714,10 +714,28 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds, s64 *timeout)
return err; return err;
} }
static long do_restart_poll(struct restart_block *restart_block)
{
struct pollfd __user *ufds = (struct pollfd __user*)restart_block->arg0;
int nfds = restart_block->arg1;
s64 timeout = ((s64)restart_block->arg3<<32) | (s64)restart_block->arg2;
int ret;
ret = do_sys_poll(ufds, nfds, &timeout);
if (ret == -EINTR) {
restart_block->fn = do_restart_poll;
restart_block->arg2 = timeout & 0xFFFFFFFF;
restart_block->arg3 = (u64)timeout >> 32;
ret = -ERESTART_RESTARTBLOCK;
}
return ret;
}
asmlinkage long sys_poll(struct pollfd __user *ufds, unsigned int nfds, asmlinkage long sys_poll(struct pollfd __user *ufds, unsigned int nfds,
long timeout_msecs) long timeout_msecs)
{ {
s64 timeout_jiffies; s64 timeout_jiffies;
int ret;
if (timeout_msecs > 0) { if (timeout_msecs > 0) {
#if HZ > 1000 #if HZ > 1000
...@@ -732,7 +750,18 @@ asmlinkage long sys_poll(struct pollfd __user *ufds, unsigned int nfds, ...@@ -732,7 +750,18 @@ asmlinkage long sys_poll(struct pollfd __user *ufds, unsigned int nfds,
timeout_jiffies = timeout_msecs; timeout_jiffies = timeout_msecs;
} }
return do_sys_poll(ufds, nfds, &timeout_jiffies); ret = do_sys_poll(ufds, nfds, &timeout_jiffies);
if (ret == -EINTR) {
struct restart_block *restart_block;
restart_block = &current_thread_info()->restart_block;
restart_block->fn = do_restart_poll;
restart_block->arg0 = (unsigned long)ufds;
restart_block->arg1 = nfds;
restart_block->arg2 = timeout_jiffies & 0xFFFFFFFF;
restart_block->arg3 = (u64)timeout_jiffies >> 32;
ret = -ERESTART_RESTARTBLOCK;
}
return ret;
} }
#ifdef TIF_RESTORE_SIGMASK #ifdef TIF_RESTORE_SIGMASK
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment