[dm-devel] [PATCH] dm: do not assign error to md->kworker_task

2016-10-28 Thread Tahsin Erdogan
cleanup_mapped_device() calls kthread_stop() if kworker_task is
non-NULL. Currently the assigned value could be a valid task struct or
an error code. Do not assign in case of error.

Example failure when kthread_run() returns -ENOMEM:

[   22.255939] BUG: unable to handle kernel NULL pointer dereference at 
000c
[   22.258847] IP: [] kthread_stop+0x34/0x260
[   22.260130] PGD 78a23067 PUD 78b56067 PMD 0
[   22.260130] Oops: 0002 [#1] SMP
[   22.260130] CPU: 1 PID: 1849 Comm: dmsetup Tainted: GW 4.8.0+ #3
[   22.260130] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
Bochs 01/01/2011
[   22.260130] task: 880078966400 task.stack: c90001898000
[   22.260130] RIP: 0010:[]  [] 
kthread_stop+0x34/0x260
[   22.260130] RSP: 0018:c9000189bc40  EFLAGS: 00010202
[   22.260130] RAX: 0001 RBX: fff4 RCX: 0003
[   22.260130] RDX: 88007fd18600 RSI: 0001 RDI: 81037080
[   22.260130] RBP: c9000189bc50 R08:  R09: 
[   22.260130] R10: 0001 R11:  R12: 
[   22.260130] R13: 0001 R14: 880077f539d8 R15: 0004
[   22.260130] FS:  7fc9ef2e2840() GS:88007fd0() 
knlGS:
[   22.260130] CS:  0010 DS:  ES:  CR0: 80050033
[   22.260130] CR2: 000c CR3: 77fa2000 CR4: 06e0
[   22.260130] Stack:
[   22.260130]  880077f53800  c9000189bc68 
808b26fa
[   22.260130]  880077f53800 c9000189bcb0 808b3c58 

[   22.260130]  808b534b c9000189bd20 880077f53800 

[   22.260130] Call Trace:
[   22.260130]  [] cleanup_mapped_device+0x2a/0xe0
[   22.260130]  [] __dm_destroy+0x1a8/0x2b0
[   22.260130]  [] dm_destroy+0xe/0x10
[   22.260130]  [] dev_remove+0xd9/0x120
[   22.260130]  [] ? dev_suspend+0x210/0x210
[   22.260130]  [] ctl_ioctl+0x206/0x500
[   22.260130]  [] dm_ctl_ioctl+0xe/0x20
[   22.260130]  [] do_vfs_ioctl+0x90/0x6b0
[   22.260130]  [] ?  entry_SYSCALL_64_fastpath+0x5/0xad
[   22.260130]  [] ?  trace_hardirqs_on_caller+0xf4/0x1c0
[   22.260130]  [] SyS_ioctl+0x74/0x80
[   22.260130]  [] entry_SYSCALL_64_fastpath+0x18/0xad
[   22.260130] Code: e5 41 54 85 c0 53 48 89 fb 0f 8f bb 01 00 00 65 8b
05 a1 2d d7 7f 89 c0 48 0f a3 05 9f 94 e8 00 0f 92 c0 84 c0 0f 85 a3 00
00 00  ff 43 18 48 89 df e8 10 f8 ff ff 48 85 c0 49 89 c4 74 29 f0
[   22.260130] RIP  [] kthread_stop+0x34/0x260
[   22.260130]  RSP 
[   22.260130] CR2: 000c
[   22.301062] ---[ end trace 22b4f4f62c04f3cf ]---

Signed-off-by: Tahsin Erdogan 
---
 drivers/md/dm-rq.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/md/dm-rq.c b/drivers/md/dm-rq.c
index 5eacce1ef88b..6e5197414a57 100644
--- a/drivers/md/dm-rq.c
+++ b/drivers/md/dm-rq.c
@@ -841,6 +841,8 @@ static void dm_old_request_fn(struct request_queue *q)
  */
 int dm_old_init_request_queue(struct mapped_device *md)
 {
+   struct task_struct *task;
+
/* Fully initialize the queue */
if (!blk_init_allocated_queue(md->queue, dm_old_request_fn, NULL))
return -EINVAL;
@@ -854,11 +856,12 @@ int dm_old_init_request_queue(struct mapped_device *md)
 
/* Initialize the request-based DM worker thread */
init_kthread_worker(&md->kworker);
-   md->kworker_task = kthread_run(kthread_worker_fn, &md->kworker,
-  "kdmwork-%s", dm_device_name(md));
-   if (IS_ERR(md->kworker_task))
-   return PTR_ERR(md->kworker_task);
+   task = kthread_run(kthread_worker_fn, &md->kworker, "kdmwork-%s",
+  dm_device_name(md));
+   if (IS_ERR(task))
+   return PTR_ERR(task);
 
+   md->kworker_task = task;
elv_register_queue(md->queue);
 
return 0;
-- 
2.8.0.rc3.226.g39d4020

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel


Re: [dm-devel] dm: free io_barrier after blk_cleanup_queue call

2016-10-10 Thread Tahsin Erdogan
On Mon, Oct 10, 2016 at 6:25 AM, Mike Snitzer  wrote:
> I have to believe this was born out of code inspection rather than
> actual need (due to crash, etc)?

This got originated from several crashes I have seen with 4.3 kernel.
The crashes
were caused by null dereferencing of io_barrier->per_cpu_ref.

The issue may no longer be relevant after commit c91852ff0815
("dm: optimize dm_request_fn()") because conditions for accessing
io_barrier may not longer exist. But fix should be considered for
forked stable trees.

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel


[dm-devel] [PATCH] dm: free io_barrier after blk_cleanup_queue call

2016-10-10 Thread Tahsin Erdogan
dm_old_request_fn() has paths that access md->io_barrier. The party
destroying io_barrier should ensure that no future execution
of dm_old_request_fn() is possible. Move destruction to below
blk_cleanup_queue() to ensure this.

Signed-off-by: Tahsin Erdogan 
---
 drivers/md/dm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index be35258324c1..ec513ee864f2 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1423,8 +1423,6 @@ static void cleanup_mapped_device(struct mapped_device 
*md)
if (md->bs)
bioset_free(md->bs);
 
-   cleanup_srcu_struct(&md->io_barrier);
-
if (md->disk) {
spin_lock(&_minor_lock);
md->disk->private_data = NULL;
@@ -1436,6 +1434,8 @@ static void cleanup_mapped_device(struct mapped_device 
*md)
if (md->queue)
blk_cleanup_queue(md->queue);
 
+   cleanup_srcu_struct(&md->io_barrier);
+
if (md->bdev) {
bdput(md->bdev);
md->bdev = NULL;
-- 
2.8.0.rc3.226.g39d4020

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel


[dm-devel] [PATCH] dm: fix parameter to blk_delay_queue()

2016-07-18 Thread Tahsin Erdogan
Second parameter to blk_delay_queue() must be in msec units not jiffies.

Signed-off-by: Tahsin Erdogan 
---
 drivers/md/dm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 1b2f96205361..17c63265a205 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -2175,7 +2175,7 @@ static void dm_request_fn(struct request_queue *q)
 md_in_flight(md) && rq->bio && rq->bio->bi_vcnt == 1 &&
 md->last_rq_pos == pos && md->last_rq_rw == 
rq_data_dir(rq)) ||
(ti->type->busy && ti->type->busy(ti))) {
-   blk_delay_queue(q, HZ / 100);
+   blk_delay_queue(q, 10);
return;
}
 
-- 
2.8.0.rc3.226.g39d4020

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel


Re: [dm-devel] dm: fix parameter to blk_delay_queue()

2016-07-18 Thread Tahsin Erdogan
> This needs to be rebased against linux-next (or linux-dm.git's
> 'for-next') because the code in question has been moved out to dm-rq.c
>
> But I'll gladly take care of it.

Thanks Mike!

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel