All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] block: io_context refcount fixes
@ 2009-12-04 13:52 Louis Rilling
  2009-12-04 13:52 ` [PATCH 1/2] block: Fix io_context leak after clone with CLONE_IO Louis Rilling
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Louis Rilling @ 2009-12-04 13:52 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel


Hi,

When reading copy_io() I found probable refcounting issues with shared
io_context. IIUC, the following two patches could fix those issues.
If I am correct, then those fixes should go to stable too.

Based on v2.6.32 and compile-tested only.

Thanks,

Louis

Louis Rilling (2):
      block: Fix io_context leak after clone with CLONE_IO
      block: Fix io_context leak after failure of clone with CLONE_IO

 block/blk-ioc.c           |   12 ++++++------
 include/linux/iocontext.h |    5 +++--
 kernel/exit.c             |    2 +-
 kernel/fork.c             |    3 ++-
 4 files changed, 12 insertions(+), 10 deletions(-)
-- 
Dr Louis Rilling			Kerlabs
Skype: louis.rilling			Batiment Germanium
Phone: (+33|0) 6 80 89 08 23		80 avenue des Buttes de Coesmes
http://www.kerlabs.com/			35700 Rennes

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

* [PATCH 1/2] block: Fix io_context leak after clone with CLONE_IO
  2009-12-04 13:52 [RFC] block: io_context refcount fixes Louis Rilling
@ 2009-12-04 13:52 ` Louis Rilling
  2009-12-04 13:52 ` [PATCH 2/2] block: Fix io_context leak after failure of " Louis Rilling
  2009-12-04 15:34 ` [RFC] block: io_context refcount fixes Jens Axboe
  2 siblings, 0 replies; 5+ messages in thread
From: Louis Rilling @ 2009-12-04 13:52 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel, Louis Rilling

With CLONE_IO, copy_io() increments both ioc->refcount and ioc->nr_tasks.
However exit_io_context() only decrements ioc->refcount if ioc->nr_tasks
reaches 0.

Always call put_io_context() in exit_io_context().

Signed-off-by: Louis Rilling <louis.rilling@kerlabs.com>
---
 block/blk-ioc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/block/blk-ioc.c b/block/blk-ioc.c
index d4ed600..dcd0412 100644
--- a/block/blk-ioc.c
+++ b/block/blk-ioc.c
@@ -80,8 +80,8 @@ void exit_io_context(void)
 			ioc->aic->exit(ioc->aic);
 		cfq_exit(ioc);
 
-		put_io_context(ioc);
 	}
+	put_io_context(ioc);
 }
 
 struct io_context *alloc_io_context(gfp_t gfp_flags, int node)
-- 
1.5.6.5


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

* [PATCH 2/2] block: Fix io_context leak after failure of clone with CLONE_IO
  2009-12-04 13:52 [RFC] block: io_context refcount fixes Louis Rilling
  2009-12-04 13:52 ` [PATCH 1/2] block: Fix io_context leak after clone with CLONE_IO Louis Rilling
@ 2009-12-04 13:52 ` Louis Rilling
  2009-12-04 15:34 ` [RFC] block: io_context refcount fixes Jens Axboe
  2 siblings, 0 replies; 5+ messages in thread
From: Louis Rilling @ 2009-12-04 13:52 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel, Louis Rilling

With CLONE_IO, parent's io_context->nr_tasks is incremented, but never
decremented whenever copy_process() fails afterwards, which prevents
exit_io_context() from calling IO schedulers exit functions.

Give a task_struct to exit_io_context(), and call exit_io_context() instead of
put_io_context() in copy_process() cleanup path.

Signed-off-by: Louis Rilling <louis.rilling@kerlabs.com>
---
 block/blk-ioc.c           |   10 +++++-----
 include/linux/iocontext.h |    5 +++--
 kernel/exit.c             |    2 +-
 kernel/fork.c             |    3 ++-
 4 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/block/blk-ioc.c b/block/blk-ioc.c
index dcd0412..cbdabb0 100644
--- a/block/blk-ioc.c
+++ b/block/blk-ioc.c
@@ -66,14 +66,14 @@ static void cfq_exit(struct io_context *ioc)
 }
 
 /* Called by the exitting task */
-void exit_io_context(void)
+void exit_io_context(struct task_struct *task)
 {
 	struct io_context *ioc;
 
-	task_lock(current);
-	ioc = current->io_context;
-	current->io_context = NULL;
-	task_unlock(current);
+	task_lock(task);
+	ioc = task->io_context;
+	task->io_context = NULL;
+	task_unlock(task);
 
 	if (atomic_dec_and_test(&ioc->nr_tasks)) {
 		if (ioc->aic && ioc->aic->exit)
diff --git a/include/linux/iocontext.h b/include/linux/iocontext.h
index 4da4a75..80a4b53 100644
--- a/include/linux/iocontext.h
+++ b/include/linux/iocontext.h
@@ -99,14 +99,15 @@ static inline struct io_context *ioc_task_link(struct io_context *ioc)
 	return NULL;
 }
 
+struct task_struct;
 #ifdef CONFIG_BLOCK
 int put_io_context(struct io_context *ioc);
-void exit_io_context(void);
+void exit_io_context(struct task_struct *task);
 struct io_context *get_io_context(gfp_t gfp_flags, int node);
 struct io_context *alloc_io_context(gfp_t gfp_flags, int node);
 void copy_io_context(struct io_context **pdst, struct io_context **psrc);
 #else
-static inline void exit_io_context(void)
+static inline void exit_io_context(struct task_struct *task)
 {
 }
 
diff --git a/kernel/exit.c b/kernel/exit.c
index f7864ac..2544000 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -1004,7 +1004,7 @@ NORET_TYPE void do_exit(long code)
 	tsk->flags |= PF_EXITPIDONE;
 
 	if (tsk->io_context)
-		exit_io_context();
+		exit_io_context(tsk);
 
 	if (tsk->splice_pipe)
 		__free_pipe_info(tsk->splice_pipe);
diff --git a/kernel/fork.c b/kernel/fork.c
index 166b8c4..6073534 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1310,7 +1310,8 @@ bad_fork_free_pid:
 	if (pid != &init_struct_pid)
 		free_pid(pid);
 bad_fork_cleanup_io:
-	put_io_context(p->io_context);
+	if (p->io_context)
+		exit_io_context(p);
 bad_fork_cleanup_namespaces:
 	exit_task_namespaces(p);
 bad_fork_cleanup_mm:
-- 
1.5.6.5


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

* Re: [RFC] block: io_context refcount fixes
  2009-12-04 13:52 [RFC] block: io_context refcount fixes Louis Rilling
  2009-12-04 13:52 ` [PATCH 1/2] block: Fix io_context leak after clone with CLONE_IO Louis Rilling
  2009-12-04 13:52 ` [PATCH 2/2] block: Fix io_context leak after failure of " Louis Rilling
@ 2009-12-04 15:34 ` Jens Axboe
  2009-12-04 16:03   ` Louis Rilling
  2 siblings, 1 reply; 5+ messages in thread
From: Jens Axboe @ 2009-12-04 15:34 UTC (permalink / raw)
  To: Louis Rilling; +Cc: linux-kernel

On Fri, Dec 04 2009, Louis Rilling wrote:
> 
> Hi,
> 
> When reading copy_io() I found probable refcounting issues with shared
> io_context. IIUC, the following two patches could fix those issues.
> If I am correct, then those fixes should go to stable too.
> 
> Based on v2.6.32 and compile-tested only.

Thanks, those both look correct. I will apply them, but please also do
whatever testing that caused you to find this in the first place (or was
it code inspection)?

-- 
Jens Axboe


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

* Re: [RFC] block: io_context refcount fixes
  2009-12-04 15:34 ` [RFC] block: io_context refcount fixes Jens Axboe
@ 2009-12-04 16:03   ` Louis Rilling
  0 siblings, 0 replies; 5+ messages in thread
From: Louis Rilling @ 2009-12-04 16:03 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 821 bytes --]

On 04/12/09 16:34 +0100, Jens Axboe wrote:
> On Fri, Dec 04 2009, Louis Rilling wrote:
> > 
> > Hi,
> > 
> > When reading copy_io() I found probable refcounting issues with shared
> > io_context. IIUC, the following two patches could fix those issues.
> > If I am correct, then those fixes should go to stable too.
> > 
> > Based on v2.6.32 and compile-tested only.
> 
> Thanks, those both look correct. I will apply them, but please also do
> whatever testing that caused you to find this in the first place (or was
> it code inspection)?

Yes this was code inspection. I have no testcase for CLONE_IO.

Thanks,

Louis

-- 
Dr Louis Rilling			Kerlabs
Skype: louis.rilling			Batiment Germanium
Phone: (+33|0) 6 80 89 08 23		80 avenue des Buttes de Coesmes
http://www.kerlabs.com/			35700 Rennes

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

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

end of thread, other threads:[~2009-12-04 16:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-04 13:52 [RFC] block: io_context refcount fixes Louis Rilling
2009-12-04 13:52 ` [PATCH 1/2] block: Fix io_context leak after clone with CLONE_IO Louis Rilling
2009-12-04 13:52 ` [PATCH 2/2] block: Fix io_context leak after failure of " Louis Rilling
2009-12-04 15:34 ` [RFC] block: io_context refcount fixes Jens Axboe
2009-12-04 16:03   ` Louis Rilling

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.