2014-02-04 17:09:44

by KOSAKI Motohiro

[permalink] [raw]
Subject: [PATCH] __set_page_dirty uses spin_lock_irqsave instead of spin_lock_irq

From: KOSAKI Motohiro <[email protected]>

To use spin_{un}lock_irq is dangerous if caller disabled interrupt.
During aio buffer migration, we have a possibility to see the
following call stack.

aio_migratepage [disable interrupt]
migrate_page_copy
clear_page_dirty_for_io
set_page_dirty
__set_page_dirty_buffers
__set_page_dirty
spin_lock_irq

This mean, current aio migration is a deadlockable. spin_lock_irqsave
is a safer alternative and we should use it.

Reported-by: David Rientjes [email protected]>
Signed-off-by: KOSAKI Motohiro <[email protected]>
Cc: [email protected]
---
fs/buffer.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index 651dba1..27265a8 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -654,14 +654,16 @@ EXPORT_SYMBOL(mark_buffer_dirty_inode);
static void __set_page_dirty(struct page *page,
struct address_space *mapping, int warn)
{
- spin_lock_irq(&mapping->tree_lock);
+ unsigned long flags;
+
+ spin_lock_irqsave(&mapping->tree_lock, flags);
if (page->mapping) { /* Race with truncate? */
WARN_ON_ONCE(warn && !PageUptodate(page));
account_page_dirtied(page, mapping);
radix_tree_tag_set(&mapping->page_tree,
page_index(page), PAGECACHE_TAG_DIRTY);
}
- spin_unlock_irq(&mapping->tree_lock);
+ spin_unlock_irqrestore(&mapping->tree_lock, flags);
__mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
}

--
1.7.1


2014-02-04 21:34:39

by David Rientjes

[permalink] [raw]
Subject: Re: [PATCH] __set_page_dirty uses spin_lock_irqsave instead of spin_lock_irq

On Tue, 4 Feb 2014, [email protected] wrote:

> From: KOSAKI Motohiro <[email protected]>
>
> To use spin_{un}lock_irq is dangerous if caller disabled interrupt.
> During aio buffer migration, we have a possibility to see the
> following call stack.
>
> aio_migratepage [disable interrupt]
> migrate_page_copy
> clear_page_dirty_for_io
> set_page_dirty
> __set_page_dirty_buffers
> __set_page_dirty
> spin_lock_irq
>
> This mean, current aio migration is a deadlockable. spin_lock_irqsave
> is a safer alternative and we should use it.
>
> Reported-by: David Rientjes [email protected]>
> Signed-off-by: KOSAKI Motohiro <[email protected]>
> Cc: [email protected]

Acked-by: David Rientjes <[email protected]>