dio: remove bogus refcounting BUG_ON
authorZach Brown <zach.brown@oracle.com>
Tue, 3 Jul 2007 22:28:55 +0000 (15:28 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Wed, 4 Jul 2007 01:23:23 +0000 (18:23 -0700)
Badari Pulavarty reported a case of this BUG_ON is triggering during
testing.  It's completely bogus and should be removed.

It's trying to notice if we left references to the dio hanging around in
the sync case.  They should have been dropped as IO completed while this
path was in dio_await_completion().  This condition will also be
checked, via some twisty logic, by the BUG_ON(ret != -EIOCBQUEUED) a few
lines lower.  So to start this BUG_ON() is redundant.

More fatally, it's dereferencing dio-> after having dropped its
reference.  It's only safe to dereference the dio after releasing the
lock if the final reference was just dropped.  Another CPU might free
the dio in bio completion and reuse the memory after this path drops the
dio lock but before the BUG_ON() is evaluated.

This patch passed aio+dio regression unit tests and aio-stress on ext3.

Signed-off-by: Zach Brown <zach.brown@oracle.com>
Cc: Badari Pulavarty <pbadari@us.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/direct-io.c

index 8593f3dfd2990a013b6fd580e22e1e82b83d4fbf..52bb2638f7ab703e9a3d5205b097ddbf90a071e2 100644 (file)
@@ -1106,7 +1106,7 @@ direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
        spin_lock_irqsave(&dio->bio_lock, flags);
        ret2 = --dio->refcount;
        spin_unlock_irqrestore(&dio->bio_lock, flags);
        spin_lock_irqsave(&dio->bio_lock, flags);
        ret2 = --dio->refcount;
        spin_unlock_irqrestore(&dio->bio_lock, flags);
-       BUG_ON(!dio->is_async && ret2 != 0);
+
        if (ret2 == 0) {
                ret = dio_complete(dio, offset, ret);
                kfree(dio);
        if (ret2 == 0) {
                ret = dio_complete(dio, offset, ret);
                kfree(dio);