mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] AIO: Fix reference counting in io_cancel and aio_cancel_all
@ 2010-03-16 11:18 Sergey Temerkhanov
  2010-03-16 11:29 ` [PATCH 2/2] AIO: Change pr_debug statements to dprintk in fs/aio.c Sergey Temerkhanov
  2010-03-16 14:46 ` [PATCH 1/2] AIO: Fix reference counting in io_cancel and aio_cancel_all Jeff Moyer
  0 siblings, 2 replies; 7+ messages in thread
From: Sergey Temerkhanov @ 2010-03-16 11:18 UTC (permalink / raw)
  To: LKML

[-- Attachment #1: Type: Text/Plain, Size: 269 bytes --]

io_cancel() and aio_cancel_all() have inconsistent reference counting 
(ki_users field of struct kiocb) which leads to unkillable processes upon  
io_cancel() or io_destroy() syscalls. This patch fixes the undesired behavior.

Regards, Sergey Temerkhanov, Cifronic ZAO

[-- Attachment #2: aio-fix.patch --]
[-- Type: text/x-patch, Size: 2630 bytes --]

diff -r b290b47c0880 fs/aio.c
--- a/fs/aio.c	Tue Mar 16 13:51:13 2010 +0300
+++ b/fs/aio.c	Tue Mar 16 14:11:36 2010 +0300
@@ -63,6 +63,8 @@
 static void aio_kick_handler(struct work_struct *);
 static void aio_queue_work(struct kioctx *);
 
+static void aio_cancel_all(struct kioctx *ctx);
+
 /* aio_setup
  *	Creates the slab caches used by the aio routines, panic on
  *	failure as this is done early during the boot sequence.
@@ -315,33 +317,6 @@
 	return ctx;
 }
 
-/* aio_cancel_all
- *	Cancels all outstanding aio requests on an aio context.  Used 
- *	when the processes owning a context have all exited to encourage 
- *	the rapid destruction of the kioctx.
- */
-static void aio_cancel_all(struct kioctx *ctx)
-{
-	int (*cancel)(struct kiocb *, struct io_event *);
-	struct io_event res;
-	spin_lock_irq(&ctx->ctx_lock);
-	ctx->dead = 1;
-	while (!list_empty(&ctx->active_reqs)) {
-		struct list_head *pos = ctx->active_reqs.next;
-		struct kiocb *iocb = list_kiocb(pos);
-		list_del_init(&iocb->ki_list);
-		cancel = iocb->ki_cancel;
-		kiocbSetCancelled(iocb);
-		if (cancel) {
-			iocb->ki_users++;
-			spin_unlock_irq(&ctx->ctx_lock);
-			cancel(iocb, &res);
-			spin_lock_irq(&ctx->ctx_lock);
-		}
-	}
-	spin_unlock_irq(&ctx->ctx_lock);
-}
-
 static void wait_for_all_aios(struct kioctx *ctx)
 {
 	struct task_struct *tsk = current;
@@ -1038,6 +1013,36 @@
 	return ret;
 }
 
+/* aio_cancel_all
+ *	Cancels all outstanding aio requests on an aio context.  Used 
+ *	when the processes owning a context have all exited to encourage 
+ *	the rapid destruction of the kioctx.
+ */
+static void aio_cancel_all(struct kioctx *ctx)
+{
+	int (*cancel)(struct kiocb *, struct io_event *);
+	struct io_event res;
+	spin_lock_irq(&ctx->ctx_lock);
+	ctx->dead = 1;
+	while (!list_empty(&ctx->active_reqs)) {
+		struct list_head *pos = ctx->active_reqs.next;
+		struct kiocb *iocb = list_kiocb(pos);
+		list_del_init(&iocb->ki_list);
+		cancel = iocb->ki_cancel;
+		kiocbSetCancelled(iocb);
+		if (cancel) {
+			iocb->ki_users++;
+			spin_unlock_irq(&ctx->ctx_lock);
+			cancel(iocb, &res);
+			spin_lock_irq(&ctx->ctx_lock);
+			dprintk("aio_cancel_all: iocb->ki_users: %d\n", iocb->ki_users);
+			__aio_put_req(ctx, iocb);
+		}
+		__aio_put_req(ctx, iocb);
+	}
+	spin_unlock_irq(&ctx->ctx_lock);
+}
+
 /* aio_read_evt
  *	Pull an event off of the ioctx's event ring.  Returns the number of 
  *	events fetched (0 or 1 ;-)
@@ -1787,9 +1792,11 @@
 			if (copy_to_user(result, &tmp, sizeof(tmp)))
 				ret = -EFAULT;
 		}
+		aio_put_req(kiocb);
 	} else
 		ret = -EINVAL;
 
+	aio_put_req(kiocb);
 	put_ioctx(ctx);
 
 	return ret;

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

end of thread, other threads:[~2010-03-16 16:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-16 11:18 [PATCH 1/2] AIO: Fix reference counting in io_cancel and aio_cancel_all Sergey Temerkhanov
2010-03-16 11:29 ` [PATCH 2/2] AIO: Change pr_debug statements to dprintk in fs/aio.c Sergey Temerkhanov
2010-03-16 14:49   ` Jeff Moyer
2010-03-16 14:46 ` [PATCH 1/2] AIO: Fix reference counting in io_cancel and aio_cancel_all Jeff Moyer
2010-03-16 16:26   ` [PATCH resubmit 2/3] " Сергей Темерханов
2010-03-16 16:30   ` [PATCH resubmit 3/3] AIO: Change dprintk statements to pr_debug Сергей Темерханов
2010-03-16 16:30   ` [PATCH resubmit 1/3] AIO: Move aio_cancel_all() Сергей Темерханов

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

all inboxes | Powered by JetHome®