public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Davi Arnaut <davi@haxent.com.br>
To: Davide Libenzi <davidel@xmailserver.org>
Cc: Oleg Nesterov <oleg@tv-sign.ru>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: + signalfd-retrieve-multiple-signals-with-one-read-call.patch added to -mm tree
Date: Mon, 21 May 2007 17:41:01 -0300	[thread overview]
Message-ID: <465203DD.4080802@haxent.com.br> (raw)
In-Reply-To: <Pine.LNX.4.64.0705211313090.24209@alien.or.mcafeemobile.com>

Davide Libenzi wrote:
> On Mon, 21 May 2007, Oleg Nesterov wrote:
> 
>>> +		schedule();
>>> +		locked = signalfd_lock(ctx, &lk);
>>> +		if (unlikely(!locked)) {
>>> +			/*
>>> +			 * Let the caller read zero byte, ala socket
>>> +			 * recv() when the peer disconnect. This test
>>> +			 * must be done before doing a dequeue_signal(),
>>> +			 * because if the sighand has been orphaned,
>>> +			 * the dequeue_signal() call is going to crash.
>>> +			 */
>> Imho, the comment is a bit confusing. dequeue_signal() needs ->siglock
>> even if signalfd_ctx is not orphaned.
> 
> The comment looks clear to me. It states:
> 
> 1) The policy of returning 0 when the sighand has been detached
> 
> 2) That we _must_not_ call dequeue_signal() in case signalfd_lock() fails
> 
> #ACK on the code mod below.
>
> - Davide
> 

Andrew, please apply on top.

Simplify signalfd locking following suggestions by Oleg Nesterov.

Signed-off-by: Davi E. M. Arnaut <davi@haxent.com.br>

Index: linux-2.6/fs/signalfd.c
===================================================================
--- linux-2.6.orig/fs/signalfd.c
+++ linux-2.6/fs/signalfd.c
@@ -211,13 +211,11 @@ static int signalfd_copyinfo(struct sign
 static ssize_t signalfd_dequeue(struct signalfd_ctx *ctx, siginfo_t *info,
 				int nonblock)
 {
-	int locked;
 	ssize_t ret;
 	struct signalfd_lockctx lk;
 	DECLARE_WAITQUEUE(wait, current);
 
-	locked = signalfd_lock(ctx, &lk);
-	if (!locked)
+	if (!signalfd_lock(ctx, &lk))
 		return 0;
 
 	ret = dequeue_signal(lk.tsk, &ctx->sigmask, info);
@@ -235,24 +233,24 @@ static ssize_t signalfd_dequeue(struct s
 	for (;;) {
 		set_current_state(TASK_INTERRUPTIBLE);
 		ret = dequeue_signal(lk.tsk, &ctx->sigmask, info);
+		signalfd_unlock(&lk);
 		if (ret != 0)
 			break;
 		if (signal_pending(current)) {
 			ret = -ERESTARTSYS;
 			break;
 		}
-		signalfd_unlock(&lk);
 		schedule();
-		locked = signalfd_lock(ctx, &lk);
-		if (unlikely(!locked)) {
+		ret = signalfd_lock(ctx, &lk);
+		if (unlikely(!ret)) {
 			/*
 			 * Let the caller read zero byte, ala socket
 			 * recv() when the peer disconnect. This test
 			 * must be done before doing a dequeue_signal(),
 			 * because if the sighand has been orphaned,
-			 * the dequeue_signal() call is going to crash.
+			 * the dequeue_signal() call is going to crash
+			 * because ->sighand will be long gone.
 			 */
-			 ret = 0;
 			 break;
 		}
 	}
@@ -260,9 +258,6 @@ static ssize_t signalfd_dequeue(struct s
 	remove_wait_queue(&ctx->wqh, &wait);
 	__set_current_state(TASK_RUNNING);
 
-	if (likely(locked))
-		signalfd_unlock(&lk);
-
 	return ret;
 }
 
 


      reply	other threads:[~2007-05-21 20:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-21 19:25 + signalfd-retrieve-multiple-signals-with-one-read-call.patch added to -mm tree Oleg Nesterov
2007-05-21 20:16 ` Davide Libenzi
2007-05-21 20:41   ` Davi Arnaut [this message]

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=465203DD.4080802@haxent.com.br \
    --to=davi@haxent.com.br \
    --cc=akpm@linux-foundation.org \
    --cc=davidel@xmailserver.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@tv-sign.ru \
    /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