Since we split the scsi_request out of struct request bsg fails to
provide a reply-buffer for the drivers. This was done via the pointer
for sense-data, that is not preallocated anymore.
Failing to allocate/assign it results in illegal dereferences because
LLDs use this pointer unquestioned.
An example panic on s390x, using the zFCP driver, looks like this (I had
debugging on, otherwise NULL-pointer dereferences wouldn't even panic on
s390x):
Unable to handle kernel pointer dereference in virtual kernel address space
Failing address: 6b6b6b6b6b6b6000 TEID: 6b6b6b6b6b6b6403
Fault in home space mode while using kernel ASCE.
AS:01590007 R3:0024
Oops: 0038 ilc:2 [#1] PREEMPT SMP DEBUG_PAGEALLOC
Modules linked in:
CPU: 2 PID: 0 Comm: swapper/2 Not tainted 4.12.0-bsg-regression+ #3
Hardware name: IBM 2964 N96 702 (z/VM 6.4.0)
task: 65cb0100 task.stack: 65cb4000
Krnl PSW : 0704e0018000 03ff801e4156
(zfcp_fc_ct_els_job_handler+0x16/0x58 [zfcp])
R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:2 PM:0 RI:0 EA:3
Krnl GPRS: 0001 5fa9d0d0 5fa9d078 00e16866
03ff0290 6b6b6b6b6b6b6b6b 59f78f00 000f
593a0958 593a0958 60d88800 5ddd4c38
58b50100 0700659cba08 03ff801e8556 659cb9a8
Krnl Code: 03ff801e4146: e3102054lg %r1,80(%r2)
03ff801e414c: 58402040 l %r4,64(%r2)
#03ff801e4150: e3502024 lg %r5,32(%r2)
>03ff801e4156: 50405004 st %r4,4(%r5)
03ff801e415a: e54c5008 mvhi8(%r5),0
03ff801e4160: e33010280012 lt %r3,40(%r1)
03ff801e4166: a718fffb lhi %r1,-5
03ff801e416a: 1803 lr %r0,%r3
Call Trace:
([<03ff801e8556>] zfcp_fsf_req_complete+0x726/0x768 [zfcp])
[<03ff801ea82a>] zfcp_fsf_reqid_check+0x102/0x180 [zfcp]
[<03ff801eb980>] zfcp_qdio_int_resp+0x230/0x278 [zfcp]
[<009b91b6>] qdio_kick_handler+0x2ae/0x2c8
[<009b9e3e>] __tiqdio_inbound_processing+0x406/0xc10
[<001684c2>] tasklet_action+0x15a/0x1d8
[<00bd28ec>] __do_softirq+0x3ec/0x848
[<001675a4>] irq_exit+0x74/0xf8
[<0010dd6a>] do_IRQ+0xba/0xf0
[<00bd19e8>] io_int_handler+0x104/0x2d4
[<001033b6>] enabled_wait+0xb6/0x188
([<0010339e>] enabled_wait+0x9e/0x188)
[<0010396a>] arch_cpu_idle+0x32/0x50
[<00bd0112>] default_idle_call+0x52/0x68
[<001cd0fa>] do_idle+0x102/0x188
[<001cd41e>] cpu_startup_entry+0x3e/0x48
[<00118c64>] smp_start_secondary+0x11c/0x130
[<00bd2016>] restart_int_handler+0x62/0x78
[<>] (null)
INFO: lockdep is turned off.
Last Breaking-Event-Address:
[<03ff801e41d6>] zfcp_fc_ct_job_handler+0x3e/0x48 [zfcp]
Kernel panic - not syncing: Fatal exception in interrupt
This patch moves bsg-lib to allocate and setup struct bsg_job ahead of
time, including the allocation of a buffer for the reply-data.
This means, struct bsg_job is not allocated separately anymore, but as part
of struct request allocation - similar to struct scsi_cmd. Reflect this in
the function names that used to handle creation/destruction of struct
bsg_job.
Reported-by: Steffen Maier
Suggested-by: Christoph Hellwig
Signed-off-by: Benjamin Block
Fixes: 82ed4db499b8 ("block: split scsi_request out of struct request")
Cc: #4.11+
---
block/bsg-lib.c | 74 +
include/linux/blkdev.h | 1 -
include/linux/bsg-lib.h | 2 ++
3 files changed, 46 insertions(+), 31 deletions(-)
diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index c4513b23f57a..dd56d7460cb9 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -29,26 +29,25 @@
#include
/**
- * bsg_destroy_job - routine to teardown/delete a bsg job
+ * bsg_teardown_job - routine to teardown a bsg job
* @job: bsg_job that is to be torn down
*/
-static void bsg_destroy_job(struct kref *kref)
+static void bsg_teardown_job(struct kref *kref)
{
struct bsg_job *job = container_of(kref, struct bsg_job, kref);
struct request *rq = job->req;
- blk_end_request_all(rq, BLK_STS_OK);
-
put_device(job->dev); /* release reference for the request */
kfree(job->request_payload.sg_list);
kfree(job->reply_payload.sg_list);
- kfree(job);
+
+ blk_end_request_all(rq, BLK_STS_OK);
}
void bsg_job_put(struct bsg_job *job)
{
- kref_put(>kref, bsg_destroy_job);
+ kref_put(>kref, bsg_teardown_job);
}
EXPORT_SYMBOL_GPL(bsg_job_put);
@@ -100,7 +99,7 @@ EXPORT_SYMBOL_GPL(bsg_job_done);
*/
static void bsg_softirq_done(struct request *rq)
{
-