mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@tv-sign.ru>
To: Chris Wright <chrisw@sous-sol.org>
Cc: Manfred Spraul <manfred@colorfullife.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, Roland McGrath <roland@redhat.com>,
	"Agarwal, Lomesh" <lomesh.agarwal@intel.com>
Subject: Re: [PATCH] Use ERESTART_RESTARTBLOCK if poll() is interrupted by a signal (was: Re: [PATCH] Use ERESTARTNOHAND if poll() is interrupted by a signal)
Date: Sat, 4 Aug 2007 15:07:21 +0400	[thread overview]
Message-ID: <20070804110721.GA83@tv-sign.ru> (raw)
In-Reply-To: <20070804063947.GQ3672@sequoia.sous-sol.org>

On 08/03, Chris Wright wrote:
>
> +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;
> +
> +	restart_block->fn = do_no_restart_syscall;

(just in case, this is not strictly necessary)

> +	ret = do_sys_poll(ufds, nfds, &timeout);
> +	if (ret == -EINTR) {
> +		restart_block->fn = do_restart_poll;
> +		restart_block->arg2 = timeout & 0xFFFFFFFF;
> +		restart_block->arg3 = timeout >> 32;
> +		ret = -ERESTART_RESTARTBLOCK;
> +	}
> +	return ret;
> +}
> +
>  asmlinkage long sys_poll(struct pollfd __user *ufds, unsigned int nfds,
>  			long timeout_msecs)
>  {
>  	s64 timeout_jiffies;
> +	int ret;
>  
>  	if (timeout_msecs > 0) {
>  #if HZ > 1000
> @@ -754,7 +773,20 @@ asmlinkage long sys_poll(struct pollfd __user *ufds, unsigned int nfds,
>  		timeout_jiffies = timeout_msecs;
>  	}
>  
> -	return do_sys_poll(ufds, nfds, &timeout_jiffies);
> +	ret = do_sys_poll(ufds, nfds, &timeout_jiffies);
> +	if (ret == -EINTR) {
> +		if (timeout_msecs > 0) {

This should be "if (timeout_msecs)", a negative timeout means
"wait indefinitely", so we should restart as well.

> +			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 = timeout_jiffies >> 32;

and, in that case, we should use "(u64)timeout_jiffies >> 32".


Small nit: sys_poll() and do_restart_poll() are not "symmetrical", the latter
doesn't check *timeout at all. Either way is correct, restart with zero timeout
means "try again once but doesn't wait".

There is a subtle (but harmless) difference though. Suppose that *timeout == 0
(either because timeout_msecs == 0 or because timeout expiried) and we have a
"false" signal_pending(). In that case sys_poll() returns EINTR, but do_restart_poll()
returns 0.

I was a bit surprized that sys_poll() return EINTR even if timeout expired, but
preserved this behaviour in do_poll-return-eintr-when-signalled.patch.

Perhaps it is better to just remove "if (timeout_msecs > 0)" check from sys_poll().
Then we can modify do_poll() to return EINTR only when !*timeout, to eliminate
unneeded (but correct) restart.

What do you think?

Oleg.


  reply	other threads:[~2007-08-04 11:07 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-29 17:05 [PATCH] Use ERESTARTNOHAND if poll() is interrupted by a signal Manfred Spraul
2007-07-30 23:35 ` Andrew Morton
2007-07-30 23:59   ` Chris Wright
2007-07-31  0:11   ` Oleg Nesterov
2007-07-31  0:18     ` Oleg Nesterov
2007-07-31 17:36       ` Chris Wright
2007-07-31 20:31   ` Manfred Spraul
2007-07-31 21:08     ` Oleg Nesterov
2007-08-04  6:39       ` [PATCH] Use ERESTART_RESTARTBLOCK if poll() is interrupted by a signal (was: Re: [PATCH] Use ERESTARTNOHAND if poll() is interrupted by a signal) Chris Wright
2007-08-04 11:07         ` Oleg Nesterov [this message]
2007-08-15 22:27           ` [PATCH take2] Use ERESTART_RESTARTBLOCK if poll() is interrupted by a signal Chris Wright
2007-08-16 15:51             ` Oleg Nesterov
2007-08-28  9:11   ` [PATCH] Use ERESTARTNOHAND " Roland McGrath
2007-07-30 23:56 ` Chris Wright

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=20070804110721.GA83@tv-sign.ru \
    --to=oleg@tv-sign.ru \
    --cc=akpm@linux-foundation.org \
    --cc=chrisw@sous-sol.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lomesh.agarwal@intel.com \
    --cc=manfred@colorfullife.com \
    --cc=roland@redhat.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

Powered by JetHome