Re: [PATCH 5/5] Make wait_on_retry_sync_kiocb killable

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Matthew Wilcox <matthew@...>
Cc: <torvalds@...>, <akpm@...>, <linux-kernel@...>, Matthew Wilcox <willy@...>, <linux-aio@...>
Date: Thursday, October 25, 2007 - 2:31 pm

Matthew Wilcox wrote:

This won't work because "sync" kiocbs are a nasty hack that don't follow
the (also nasty) refcounting patterns of the aio core.

-EIOCBRETRY means that aio_{read,write}() has taken on the "IO" kiocb
reference and has ensured that call kick_iocb() will be called in the
future.

Usually kick_iocb() would queue the kiocb to have its ki_retry method
called by the kernel aio threads while holding that reference.  But
"sync" kiocbs are on-stack and aren't reference counted.  kick_iocb() magic:

        /* sync iocbs are easy: they can only ever be executing from a

         * single context. */
        if (is_sync_kiocb(iocb)) {
                kiocbSetKicked(iocb);
                wake_up_process(iocb->ki_obj.tsk);

                return;

        }

So, with this patch, if we catch a signal and return from
wait_on_retry_sync_kiocb() and return from do_sync_{read,write}() then
that on-stack sync kiocb is going to be long gone when kick_iocb() goes
to work with it.

So the first step would be to make sync kiocbs real refcounted
structures so that kick_iocb() could find that the sync submitter has
disappeared.

But then we have to worry about leaving retrying operations in flight
after the sync submitter has returned from their system call.  They
might be VERY SURPRISED to find that a read() implemented with
do_sync_read() is still writing into their userspace pointer after the
syscall was interrupted by a signal.

This leads us to the possibility of working with the ki_cancel method to
stop a pending operation if a signal is caught from a sync submitter.
In practice, nothing sets ki_cancel.

And finally, this code will not be run in a solely mainline kernel.  The
only thing in mainline that returns -EIOCBRETRY is the goofy usb gadget.
 It has both ->{read,write} and ->aio_{read,write} file op methods so
vfs_{read,write}() will never call do_sync_{read,write}().  Sure,
out-of-tree aio providers (SDP?) might get caught up in this.

(Ha ha!  Welcome to fs/aio.c!)

So I'm not sure where to go with this.  It's a mess, but it doesn't seem
like anything is using it.  A significant clean up of the retry and
cancelation support in fs/aio.c is in flight.  Maybe we can revisit this
once that settles down.

- z
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 1/5] Use wake_up_locked() in eventpoll, Matthew Wilcox, (Wed Oct 24, 8:24 am)
[PATCH 2/5] Use macros instead of TASK_ flags, Matthew Wilcox, (Wed Oct 24, 8:24 am)
Re: [PATCH 2/5] Use macros instead of TASK_ flags, Ingo Molnar, (Wed Dec 5, 8:56 am)
Re: [PATCH 2/5] Use macros instead of TASK_ flags, Matthew Wilcox, (Thu Dec 6, 10:42 am)
Re: [PATCH 2/5] Use macros instead of TASK_ flags, Andrew Morton, (Fri Oct 26, 2:45 pm)
Re: [PATCH 2/5] Use macros instead of TASK_ flags, Alexey Dobriyan, (Fri Oct 26, 4:39 pm)
Re: [PATCH 2/5] Use macros instead of TASK_ flags, Matthew Wilcox, (Fri Oct 26, 8:33 pm)
Re: [PATCH 2/5] Use macros instead of TASK_ flags, Andrew Morton, (Wed Oct 24, 11:31 pm)
[PATCH 4/5] Add lock_page_killable, Matthew Wilcox, (Wed Oct 24, 8:24 am)
Re: [PATCH 4/5] Add lock_page_killable, Andrew Morton, (Thu Oct 25, 12:11 am)
Re: [PATCH 4/5] Add lock_page_killable, Nick Piggin, (Thu Oct 25, 12:13 am)
[PATCH 5/5] Make wait_on_retry_sync_kiocb killable, Matthew Wilcox, (Wed Oct 24, 8:24 am)
Re: [PATCH 5/5] Make wait_on_retry_sync_kiocb killable, Zach Brown, (Thu Oct 25, 2:31 pm)
Re: [PATCH 5/5] Make wait_on_retry_sync_kiocb killable, Andrew Morton, (Wed Oct 24, 11:43 pm)
[PATCH 3/5] Add TASK_WAKEKILL, Matthew Wilcox, (Wed Oct 24, 8:24 am)