From: Zach Brown <zach.brown@oracle.com>
To: linux-kernel@vger.kernel.org, linux-aio@kvack.org
Cc: Benjamin LaHaise <bcrl@kvack.org>,
Arjan van de Ven <arjan@infradead.org>
Subject: [RFC][PATCH] Fix lock inversion aio_kick_handler()
Date: Fri, 28 Jul 2006 17:10:32 -0700 [thread overview]
Message-ID: <20060729001032.GA7885@tetsuo.zabbo.net> (raw)
Fix lock inversion aio_kick_handler()
lockdep found a AB BC CA lock inversion in retry-based AIO:
1) The task struct's alloc_lock (A) is acquired in process context with
interrupts enabled. An interrupt might arrive and call wake_up() which grabs
the wait queue's q->lock (B).
2) When performing retry-based AIO the AIO core registers aio_wake_function()
as the wake funtion for iocb->ki_wait. It is called with the wait queue's
q->lock (B) held and then tries to add the iocb to the run list after acquiring
the ctx_lock (C).
3) aio_kick_handler() holds the ctx_lock (C) while acquiring the alloc_lock (A)
via lock_task() and unuse_mm(). Lockdep emits a warning saying that we're
trying to connect the irq-safe q->lock to the irq-unsafe alloc_lock via
ctx_lock.
This fixes the inversion by calling unuse_mm() in the AIO kick handing path
after we've released the ctx_lock.
Signed-off-by: Zach Brown <zach.brown@oracle.com>
---
Ben, can you remember why we put unuse_mm() inside the ctx_lock? Is that
intentional and still needed?
Index: 2.6.18-rc2-mm1-cmdepoll/fs/aio.c
===================================================================
--- 2.6.18-rc2-mm1-cmdepoll.orig/fs/aio.c
+++ 2.6.18-rc2-mm1-cmdepoll/fs/aio.c
@@ -598,9 +598,6 @@ static void use_mm(struct mm_struct *mm)
* by the calling kernel thread
* (Note: this routine is intended to be called only
* from a kernel thread context)
- *
- * Comments: Called with ctx->ctx_lock held. This nests
- * task_lock instead ctx_lock.
*/
static void unuse_mm(struct mm_struct *mm)
{
@@ -866,8 +863,8 @@ static void aio_kick_handler(void *data)
use_mm(ctx->mm);
spin_lock_irq(&ctx->ctx_lock);
requeue =__aio_run_iocbs(ctx);
- unuse_mm(ctx->mm);
spin_unlock_irq(&ctx->ctx_lock);
+ unuse_mm(ctx->mm);
set_fs(oldfs);
/*
* we're in a worker thread already, don't use queue_delayed_work,
next reply other threads:[~2006-07-29 0:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-29 0:10 Zach Brown [this message]
2006-07-29 1:34 ` [RFC][PATCH] Fix lock inversion aio_kick_handler() Benjamin LaHaise
2006-07-29 2:02 ` Zach Brown
2006-11-09 22:41 ` Jeff Moyer
2006-11-09 22:51 ` Zach Brown
2006-11-09 22:57 ` Jeff Moyer
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=20060729001032.GA7885@tetsuo.zabbo.net \
--to=zach.brown@oracle.com \
--cc=arjan@infradead.org \
--cc=bcrl@kvack.org \
--cc=linux-aio@kvack.org \
--cc=linux-kernel@vger.kernel.org \
/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