public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] eventfd/kaio integration fix
@ 2008-04-09 18:45 Davide Libenzi
  2008-04-09 19:08 ` Andrew Morton
  2008-04-13 12:29 ` Oliver Pinter
  0 siblings, 2 replies; 8+ messages in thread
From: Davide Libenzi @ 2008-04-09 18:45 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Linux Kernel Mailing List, Zach Brown, Jeff Roberson

Jeff Roberson discovered a race when using kaio eventfd based 
notifications. This patch fixes the race by moving the notification inside 
the spinlocked section of kaio. The operation is safe since eventfd 
spinlock and kaio one are unrelated.



Signed-off-by: Davide Libenzi <davidel@xmailserver.org>


- Davide


---
 fs/aio.c |   17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

Index: linux-2.6.mod/fs/aio.c
===================================================================
--- linux-2.6.mod.orig/fs/aio.c	2008-04-08 16:25:27.000000000 -0700
+++ linux-2.6.mod/fs/aio.c	2008-04-09 11:37:10.000000000 -0700
@@ -936,14 +936,6 @@
 		return 1;
 	}
 
-	/*
-	 * Check if the user asked us to deliver the result through an
-	 * eventfd. The eventfd_signal() function is safe to be called
-	 * from IRQ context.
-	 */
-	if (!IS_ERR(iocb->ki_eventfd))
-		eventfd_signal(iocb->ki_eventfd, 1);
-
 	info = &ctx->ring_info;
 
 	/* add a completion event to the ring buffer.
@@ -992,6 +984,15 @@
 	kunmap_atomic(ring, KM_IRQ1);
 
 	pr_debug("added to ring %p at [%lu]\n", iocb, tail);
+
+	/*
+	 * Check if the user asked us to deliver the result through an
+	 * eventfd. The eventfd_signal() function is safe to be called
+	 * from IRQ context.
+	 */
+	if (!IS_ERR(iocb->ki_eventfd))
+		eventfd_signal(iocb->ki_eventfd, 1);
+
 put_rq:
 	/* everything turned out well, dispose of the aiocb. */
 	ret = __aio_put_req(ctx, iocb);

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch] eventfd/kaio integration fix
  2008-04-09 18:45 [patch] eventfd/kaio integration fix Davide Libenzi
@ 2008-04-09 19:08 ` Andrew Morton
  2008-04-09 19:19   ` Davide Libenzi
  2008-04-13 12:29 ` Oliver Pinter
  1 sibling, 1 reply; 8+ messages in thread
From: Andrew Morton @ 2008-04-09 19:08 UTC (permalink / raw)
  To: Davide Libenzi; +Cc: linux-kernel, zach.brown, jroberson

On Wed, 9 Apr 2008 11:45:47 -0700 (PDT)
Davide Libenzi <davidel@xmailserver.org> wrote:

> Jeff Roberson discovered a race when using kaio eventfd based 
> notifications. This patch fixes the race by moving the notification inside 
> the spinlocked section of kaio.

Missing information.

What are the consequences of this race, when it occurs?

> The operation is safe since eventfd 
> spinlock and kaio one are unrelated.

Yes, it's safe from that perspective.

However with this patch applied, we will no longer run eventfd_signal() if
kiocbIsCancelled(iocb).  Convincing is needed, please?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch] eventfd/kaio integration fix
  2008-04-09 19:08 ` Andrew Morton
@ 2008-04-09 19:19   ` Davide Libenzi
  2008-04-09 19:33     ` Jeff Roberson
  0 siblings, 1 reply; 8+ messages in thread
From: Davide Libenzi @ 2008-04-09 19:19 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Linux Kernel Mailing List, zach.brown, jroberson

On Wed, 9 Apr 2008, Andrew Morton wrote:

> On Wed, 9 Apr 2008 11:45:47 -0700 (PDT)
> Davide Libenzi <davidel@xmailserver.org> wrote:
> 
> > Jeff Roberson discovered a race when using kaio eventfd based 
> > notifications. This patch fixes the race by moving the notification inside 
> > the spinlocked section of kaio.
> 
> Missing information.
> 
> What are the consequences of this race, when it occurs?

This was described in the original email. I posted a patch back then 
(waiting for Jeff test feedback - that never came), but then I forgot 
about it till now:

http://groups.google.com/group/linux.kernel/browse_thread/thread/e814b54c14198616



> > The operation is safe since eventfd 
> > spinlock and kaio one are unrelated.
> 
> Yes, it's safe from that perspective.
> 
> However with this patch applied, we will no longer run eventfd_signal() if
> kiocbIsCancelled(iocb).  Convincing is needed, please?

This was the intended behaviour. No event was actually *ready*, so no need 
to signal completion of an event.



- Davide



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch] eventfd/kaio integration fix
  2008-04-09 19:19   ` Davide Libenzi
@ 2008-04-09 19:33     ` Jeff Roberson
  0 siblings, 0 replies; 8+ messages in thread
From: Jeff Roberson @ 2008-04-09 19:33 UTC (permalink / raw)
  To: Davide Libenzi
  Cc: Andrew Morton, Linux Kernel Mailing List, zach.brown, jroberson


On Wed, 9 Apr 2008, Davide Libenzi wrote:

> On Wed, 9 Apr 2008, Andrew Morton wrote:
>
>> On Wed, 9 Apr 2008 11:45:47 -0700 (PDT)
>> Davide Libenzi <davidel@xmailserver.org> wrote:
>>
>>> Jeff Roberson discovered a race when using kaio eventfd based
>>> notifications. This patch fixes the race by moving the notification inside
>>> the spinlocked section of kaio.
>>
>> Missing information.
>>
>> What are the consequences of this race, when it occurs?
>
> This was described in the original email. I posted a patch back then
> (waiting for Jeff test feedback - that never came), but then I forgot
> about it till now:
>
> http://groups.google.com/group/linux.kernel/browse_thread/thread/e814b54c14198616
>

I was thinking about stirring this up again myself.  Testing was 
complicated by several factors.  None of them related to this patch. 
However, I feel confident that this has solved our issue.

Jeff

>
>
>>> The operation is safe since eventfd
>>> spinlock and kaio one are unrelated.
>>
>> Yes, it's safe from that perspective.
>>
>> However with this patch applied, we will no longer run eventfd_signal() if
>> kiocbIsCancelled(iocb).  Convincing is needed, please?
>
> This was the intended behaviour. No event was actually *ready*, so no need
> to signal completion of an event.
>
>
>
> - Davide
>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch] eventfd/kaio integration fix
  2008-04-09 18:45 [patch] eventfd/kaio integration fix Davide Libenzi
  2008-04-09 19:08 ` Andrew Morton
@ 2008-04-13 12:29 ` Oliver Pinter
  2008-04-13 22:57   ` Davide Libenzi
  1 sibling, 1 reply; 8+ messages in thread
From: Oliver Pinter @ 2008-04-13 12:29 UTC (permalink / raw)
  To: Davide Libenzi
  Cc: Andrew Morton, Linux Kernel Mailing List, Zach Brown,
	Jeff Roberson

for 2.6.22.y ?

On 4/9/08, Davide Libenzi <davidel@xmailserver.org> wrote:
> Jeff Roberson discovered a race when using kaio eventfd based
> notifications. This patch fixes the race by moving the notification inside
> the spinlocked section of kaio. The operation is safe since eventfd
> spinlock and kaio one are unrelated.
>
>
>
> Signed-off-by: Davide Libenzi <davidel@xmailserver.org>
>
>
> - Davide
>
>
> ---
>  fs/aio.c |   17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
>
> Index: linux-2.6.mod/fs/aio.c
> ===================================================================
> --- linux-2.6.mod.orig/fs/aio.c	2008-04-08 16:25:27.000000000 -0700
> +++ linux-2.6.mod/fs/aio.c	2008-04-09 11:37:10.000000000 -0700
> @@ -936,14 +936,6 @@
>  		return 1;
>  	}
>
> -	/*
> -	 * Check if the user asked us to deliver the result through an
> -	 * eventfd. The eventfd_signal() function is safe to be called
> -	 * from IRQ context.
> -	 */
> -	if (!IS_ERR(iocb->ki_eventfd))
> -		eventfd_signal(iocb->ki_eventfd, 1);
> -
>  	info = &ctx->ring_info;
>
>  	/* add a completion event to the ring buffer.
> @@ -992,6 +984,15 @@
>  	kunmap_atomic(ring, KM_IRQ1);
>
>  	pr_debug("added to ring %p at [%lu]\n", iocb, tail);
> +
> +	/*
> +	 * Check if the user asked us to deliver the result through an
> +	 * eventfd. The eventfd_signal() function is safe to be called
> +	 * from IRQ context.
> +	 */
> +	if (!IS_ERR(iocb->ki_eventfd))
> +		eventfd_signal(iocb->ki_eventfd, 1);
> +
>  put_rq:
>  	/* everything turned out well, dispose of the aiocb. */
>  	ret = __aio_put_req(ctx, iocb);
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>


-- 
Thanks,
Oliver

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch] eventfd/kaio integration fix
  2008-04-13 12:29 ` Oliver Pinter
@ 2008-04-13 22:57   ` Davide Libenzi
  2008-04-14 17:56     ` Oliver Pinter
  0 siblings, 1 reply; 8+ messages in thread
From: Davide Libenzi @ 2008-04-13 22:57 UTC (permalink / raw)
  To: Oliver Pinter
  Cc: Andrew Morton, Linux Kernel Mailing List, Zach Brown,
	Jeff Roberson

On Sun, 13 Apr 2008, Oliver Pinter wrote:

> for 2.6.22.y ?

You may want to talk to either Greg KH or Chris Wright for that.



- Davide



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch] eventfd/kaio integration fix
  2008-04-13 22:57   ` Davide Libenzi
@ 2008-04-14 17:56     ` Oliver Pinter
  2008-04-14 18:02       ` Davide Libenzi
  0 siblings, 1 reply; 8+ messages in thread
From: Oliver Pinter @ 2008-04-14 17:56 UTC (permalink / raw)
  To: Davide Libenzi
  Cc: Andrew Morton, Linux Kernel Mailing List, Zach Brown,
	Jeff Roberson

this race presented in forigen kernels or only in 2.6.25-rcX?

I added this patch for "queue-2.6.22.y"
http://repo.or.cz/w/linux-2.6.22.y-op-patches.git

On 4/14/08, Davide Libenzi <davidel@xmailserver.org> wrote:
> On Sun, 13 Apr 2008, Oliver Pinter wrote:
>
> > for 2.6.22.y ?
>
> You may want to talk to either Greg KH or Chris Wright for that.
>
>
>
> - Davide
>
>
>


-- 
Thanks,
Oliver

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch] eventfd/kaio integration fix
  2008-04-14 17:56     ` Oliver Pinter
@ 2008-04-14 18:02       ` Davide Libenzi
  0 siblings, 0 replies; 8+ messages in thread
From: Davide Libenzi @ 2008-04-14 18:02 UTC (permalink / raw)
  To: Oliver Pinter
  Cc: Andrew Morton, Linux Kernel Mailing List, Zach Brown,
	Jeff Roberson

On Mon, 14 Apr 2008, Oliver Pinter wrote:

> this race presented in forigen kernels or only in 2.6.25-rcX?

"Forigen"?
The race is there since day one of kaio+eventfd integration. So basically, 
if your kernel has eventfd, it has also the race.
Needless to say, simple kaio usage w/out eventfd, is fine.



- Davide



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-04-14 18:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-09 18:45 [patch] eventfd/kaio integration fix Davide Libenzi
2008-04-09 19:08 ` Andrew Morton
2008-04-09 19:19   ` Davide Libenzi
2008-04-09 19:33     ` Jeff Roberson
2008-04-13 12:29 ` Oliver Pinter
2008-04-13 22:57   ` Davide Libenzi
2008-04-14 17:56     ` Oliver Pinter
2008-04-14 18:02       ` Davide Libenzi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox