From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Tejun Heo <tj@kernel.org>,
Jan Kara <jack@suse.cz>, Derek Basehore <dbasehore@chromium.org>,
Jens Axboe <axboe@kernel.dk>,
Andrew Morton <akpm@linux-foundation.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH 3.13 17/32] bdi: avoid oops on device removal
Date: Sun, 20 Apr 2014 19:13:34 -0700 [thread overview]
Message-ID: <20140421021136.227907243@linuxfoundation.org> (raw)
In-Reply-To: <20140421021133.865086647@linuxfoundation.org>
3.13-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <jack@suse.cz>
commit 5acda9d12dcf1ad0d9a5a2a7c646de3472fa7555 upstream.
After commit 839a8e8660b6 ("writeback: replace custom worker pool
implementation with unbound workqueue") when device is removed while we
are writing to it we crash in bdi_writeback_workfn() ->
set_worker_desc() because bdi->dev is NULL.
This can happen because even though bdi_unregister() cancels all pending
flushing work, nothing really prevents new ones from being queued from
balance_dirty_pages() or other places.
Fix the problem by clearing BDI_registered bit in bdi_unregister() and
checking it before scheduling of any flushing work.
Fixes: 839a8e8660b6777e7fe4e80af1a048aebe2b5977
Reviewed-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jan Kara <jack@suse.cz>
Cc: Derek Basehore <dbasehore@chromium.org>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
fs/fs-writeback.c | 23 ++++++++++++++++++-----
include/linux/backing-dev.h | 2 +-
mm/backing-dev.c | 13 +++++++++----
3 files changed, 28 insertions(+), 10 deletions(-)
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -89,16 +89,29 @@ static inline struct inode *wb_inode(str
#define CREATE_TRACE_POINTS
#include <trace/events/writeback.h>
+static void bdi_wakeup_thread(struct backing_dev_info *bdi)
+{
+ spin_lock_bh(&bdi->wb_lock);
+ if (test_bit(BDI_registered, &bdi->state))
+ mod_delayed_work(bdi_wq, &bdi->wb.dwork, 0);
+ spin_unlock_bh(&bdi->wb_lock);
+}
+
static void bdi_queue_work(struct backing_dev_info *bdi,
struct wb_writeback_work *work)
{
trace_writeback_queue(bdi, work);
spin_lock_bh(&bdi->wb_lock);
+ if (!test_bit(BDI_registered, &bdi->state)) {
+ if (work->done)
+ complete(work->done);
+ goto out_unlock;
+ }
list_add_tail(&work->list, &bdi->work_list);
- spin_unlock_bh(&bdi->wb_lock);
-
mod_delayed_work(bdi_wq, &bdi->wb.dwork, 0);
+out_unlock:
+ spin_unlock_bh(&bdi->wb_lock);
}
static void
@@ -114,7 +127,7 @@ __bdi_start_writeback(struct backing_dev
work = kzalloc(sizeof(*work), GFP_ATOMIC);
if (!work) {
trace_writeback_nowork(bdi);
- mod_delayed_work(bdi_wq, &bdi->wb.dwork, 0);
+ bdi_wakeup_thread(bdi);
return;
}
@@ -161,7 +174,7 @@ void bdi_start_background_writeback(stru
* writeback as soon as there is no other work to do.
*/
trace_writeback_wake_background(bdi);
- mod_delayed_work(bdi_wq, &bdi->wb.dwork, 0);
+ bdi_wakeup_thread(bdi);
}
/*
@@ -1017,7 +1030,7 @@ void bdi_writeback_workfn(struct work_st
current->flags |= PF_SWAPWRITE;
if (likely(!current_is_workqueue_rescuer() ||
- list_empty(&bdi->bdi_list))) {
+ !test_bit(BDI_registered, &bdi->state))) {
/*
* The normal path. Keep writing back @bdi until its
* work_list is empty. Note that this path is also taken
--- a/include/linux/backing-dev.h
+++ b/include/linux/backing-dev.h
@@ -95,7 +95,7 @@ struct backing_dev_info {
unsigned int max_ratio, max_prop_frac;
struct bdi_writeback wb; /* default writeback info for this bdi */
- spinlock_t wb_lock; /* protects work_list */
+ spinlock_t wb_lock; /* protects work_list & wb.dwork scheduling */
struct list_head work_list;
--- a/mm/backing-dev.c
+++ b/mm/backing-dev.c
@@ -297,7 +297,10 @@ void bdi_wakeup_thread_delayed(struct ba
unsigned long timeout;
timeout = msecs_to_jiffies(dirty_writeback_interval * 10);
- queue_delayed_work(bdi_wq, &bdi->wb.dwork, timeout);
+ spin_lock_bh(&bdi->wb_lock);
+ if (test_bit(BDI_registered, &bdi->state))
+ queue_delayed_work(bdi_wq, &bdi->wb.dwork, timeout);
+ spin_unlock_bh(&bdi->wb_lock);
}
/*
@@ -310,9 +313,6 @@ static void bdi_remove_from_list(struct
spin_unlock_bh(&bdi_lock);
synchronize_rcu_expedited();
-
- /* bdi_list is now unused, clear it to mark @bdi dying */
- INIT_LIST_HEAD(&bdi->bdi_list);
}
int bdi_register(struct backing_dev_info *bdi, struct device *parent,
@@ -363,6 +363,11 @@ static void bdi_wb_shutdown(struct backi
*/
bdi_remove_from_list(bdi);
+ /* Make sure nobody queues further work */
+ spin_lock_bh(&bdi->wb_lock);
+ clear_bit(BDI_registered, &bdi->state);
+ spin_unlock_bh(&bdi->wb_lock);
+
/*
* Drain work list and shutdown the delayed_work. At this point,
* @bdi->bdi_list is empty telling bdi_Writeback_workfn() that @bdi
next prev parent reply other threads:[~2014-04-21 4:36 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-21 2:13 [PATCH 3.13 00/32] 3.13.11-stable review Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 01/32] user namespace: fix incorrect memory barriers Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 02/32] Char: ipmi_bt_sm, fix infinite loop Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 03/32] x86, hyperv: Bypass the timer_irq_works() check Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 04/32] x86: Adjust irq remapping quirk for older revisions of 5500/5520 chipsets Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 05/32] PCI: designware: Fix RC BAR to be single 64-bit non-prefetchable memory BAR Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 06/32] PCI: designware: Fix iATU programming for cfg1, io and mem viewport Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 07/32] ACPI / button: Add ACPI Button event via netlink routine Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 08/32] PCI: Enable INTx in pci_reenable_device() only when MSI/MSI-X not enabled Greg Kroah-Hartman
2014-04-21 14:24 ` Ben Hutchings
2014-04-22 16:32 ` Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 09/32] staging: comedi: 8255_pci: initialize MITE data window Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 10/32] tty: Set correct tty name in active sysfs attribute Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 11/32] tty: Fix low_latency BUG Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 12/32] SCSI: sd: dont fail if the device doesnt recognize SYNCHRONIZE CACHE Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 14/32] Bluetooth: Fix removing Long Term Key Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 15/32] ima: restore the original behavior for sending data with ima template Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 16/32] backing_dev: fix hung task on sync Greg Kroah-Hartman
2014-04-21 2:13 ` Greg Kroah-Hartman [this message]
2014-04-21 2:13 ` [PATCH 3.13 18/32] xfs: fix directory hash ordering bug Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 19/32] Btrfs: skip submitting barrier for missing device Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 20/32] Btrfs: fix deadlock with nested trans handles Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 21/32] ext4: fix error return from ext4_ext_handle_uninitialized_extents() Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 22/32] ext4: fix partial cluster handling for bigalloc file systems Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 23/32] ext4: fix premature freeing of partial clusters split across leaf blocks Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 24/32] jffs2: Fix segmentation fault found in stress test Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 25/32] jffs2: Fix crash due to truncation of csize Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 26/32] jffs2: avoid soft-lockup in jffs2_reserve_space_gc() Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 27/32] jffs2: remove from wait queue after schedule() Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 28/32] sparc32: fix build failure for arch_jump_label_transform Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 29/32] sparc64: dont treat 64-bit syscall return codes as 32-bit Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 30/32] sparc64: Make sure %pil interrupts are enabled during hypervisor yield Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 31/32] wait: fix reparent_leader() vs EXIT_DEAD->EXIT_ZOMBIE race Greg Kroah-Hartman
2014-04-21 2:13 ` [PATCH 3.13 32/32] exit: call disassociate_ctty() before exit_task_namespaces() Greg Kroah-Hartman
2014-04-21 13:25 ` [PATCH 3.13 00/32] 3.13.11-stable review Guenter Roeck
2014-04-21 19:03 ` Greg Kroah-Hartman
2014-04-22 1:06 ` Guenter Roeck
2014-04-22 1:14 ` Greg Kroah-Hartman
2014-04-22 15:48 ` Shuah Khan
2014-04-22 19:36 ` Greg Kroah-Hartman
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=20140421021136.227907243@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=dbasehore@chromium.org \
--cc=jack@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.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