Commit

ec6b083915e8146e147314a5f4f1285d07b57bfc

scsi: bsg: Pass reply_len to bsg_setup_queue() to fit UFS ARPMB replies

bsg-lib allocates a 96-byte (SCSI_SENSE_BUFFERSIZE) reply buffer per
job, but struct ufs_rpmb_reply is 104 bytes: a 40-byte struct
ufs_bsg_reply followed by a 64-byte EHS. When an Advanced RPMB command
returns an EHS, ufshcd_advanced_rpmb_req_handler() copies it right after
the 40-byte header and writes 8 bytes past the end of the buffer.

Let each BSG transport pass its reply buffer size to bsg_setup_queue()
and have ufs_bsg request sizeof(struct ufs_rpmb_reply), so the full
reply reaches user space. Other transports keep SCSI_SENSE_BUFFERSIZE.

Fixes: 6ff265fc5ef6 ("scsi: ufs: core: bsg: Add advanced RPMB support in ufs_bsg")
Cc: stable@vger.kernel.org
Signed-off-by: Stanley Jhu <stanleyjhu@google.com>
Link: https://patch.msgid.link/20261013132708.1669415-1-stanleyjhu@google.com
Signed-off-by: Martin K. Petersen (Oracle) <mkp@kernel.org>

Stanley Jhu <stanleyjhu@google.com> · 2026-10-13 13:27 UTC · committed by Martin K. Petersen (Oracle)

Browse files
7 files changed, +23 −11
modified block/bsg-lib.c
@@ -23,11 +23,14 @@ struct bsg_set {
23 23 struct bsg_device *bd;
24 24 bsg_job_fn *job_fn;
25 25 bsg_timeout_fn *timeout_fn;
26 + unsigned int reply_len;
26 27 };
27 28
28 29 static int bsg_transport_sg_io_fn(struct request_queue *q, struct sg_io_v4 *hdr,
29 30 bool open_for_write, unsigned int timeout)
30 31 {
32 + struct bsg_set *bset =
33 + container_of(q->tag_set, struct bsg_set, tag_set);
31 34 struct bsg_job *job;
32 35 struct request *rq;
33 36 struct bio *bio;
@@ -50,7 +53,7 @@ static int bsg_transport_sg_io_fn(struct request_queue *q, struct sg_io_v4 *hdr,
50 53 reply = job->reply;
51 54 memset(job, 0, sizeof(*job));
52 55 job->reply = reply;
53 - job->reply_len = SCSI_SENSE_BUFFERSIZE;
56 + job->reply_len = bset->reply_len;
54 57 job->dd_data = job + 1;
55 58
56 59 job->request_len = hdr->request_len;
@@ -301,9 +304,10 @@ out:
301 304 static int bsg_init_rq(struct blk_mq_tag_set *set, struct request *req,
302 305 unsigned int hctx_idx, int numa_node)
303 306 {
307 + struct bsg_set *bset = container_of(set, struct bsg_set, tag_set);
304 308 struct bsg_job *job = blk_mq_rq_to_pdu(req);
305 309
306 - job->reply = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
310 + job->reply = kzalloc(bset->reply_len, GFP_KERNEL);
307 311 if (!job->reply)
308 312 return -ENOMEM;
309 313 return 0;
@@ -358,10 +362,12 @@ static const struct blk_mq_ops bsg_mq_ops = {
358 362 * @job_fn: bsg job handler
359 363 * @timeout: timeout handler function pointer
360 364 * @dd_job_size: size of LLD data needed for each job
365 + * @reply_len: size of the reply buffer needed for each job
361 366 */
362 367 struct request_queue *bsg_setup_queue(struct device *dev, const char *name,
363 368 struct queue_limits *lim, bsg_job_fn *job_fn,
364 - bsg_timeout_fn *timeout, int dd_job_size)
369 + bsg_timeout_fn *timeout, int dd_job_size,
370 + unsigned int reply_len)
365 371 {
366 372 struct bsg_set *bset;
367 373 struct blk_mq_tag_set *set;
@@ -374,6 +380,7 @@ struct request_queue *bsg_setup_queue(struct device *dev, const char *name,
374 380
375 381 bset->job_fn = job_fn;
376 382 bset->timeout_fn = timeout;
383 + bset->reply_len = reply_len;
377 384
378 385 set = &bset->tag_set;
379 386 set->ops = &bsg_mq_ops;
modified drivers/scsi/mpi3mr/mpi3mr_app.c
@@ -3053,7 +3053,7 @@ void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc)
3053 3053 }
3054 3054
3055 3055 q = bsg_setup_queue(bsg_dev, dev_name(bsg_dev), &lim,
3056 - mpi3mr_bsg_request, NULL, 0);
3056 + mpi3mr_bsg_request, NULL, 0, SCSI_SENSE_BUFFERSIZE);
3057 3057 if (IS_ERR(q)) {
3058 3058 ioc_err(mrioc, "%s: bsg registration failed\n",
3059 3059 dev_name(bsg_dev));
modified drivers/scsi/scsi_transport_fc.c
@@ -4345,7 +4345,8 @@ fc_bsg_hostadd(struct Scsi_Host *shost, struct fc_host_attrs *fc_host)
4345 4345 scsi_init_limits(shost, &lim);
4346 4346 lim.max_segments = min_not_zero(lim.max_segments, i->f->max_bsg_segments);
4347 4347 q = bsg_setup_queue(dev, bsg_name, &lim, fc_bsg_dispatch,
4348 - fc_bsg_job_timeout, i->f->dd_bsg_size);
4348 + fc_bsg_job_timeout, i->f->dd_bsg_size,
4349 + SCSI_SENSE_BUFFERSIZE);
4349 4350 if (IS_ERR(q)) {
4350 4351 dev_err(dev,
4351 4352 "fc_host%d: bsg interface failed to initialize - setup queue\n",
@@ -4378,7 +4379,8 @@ fc_bsg_rportadd(struct Scsi_Host *shost, struct fc_rport *rport)
4378 4379 scsi_init_limits(shost, &lim);
4379 4380 lim.max_segments = min_not_zero(lim.max_segments, i->f->max_bsg_segments);
4380 4381 q = bsg_setup_queue(dev, dev_name(dev), &lim, fc_bsg_dispatch_prep,
4381 - fc_bsg_job_timeout, i->f->dd_bsg_size);
4382 + fc_bsg_job_timeout, i->f->dd_bsg_size,
4383 + SCSI_SENSE_BUFFERSIZE);
4382 4384 if (IS_ERR(q)) {
4383 4385 dev_err(dev, "failed to setup bsg queue\n");
4384 4386 return PTR_ERR(q);
modified drivers/scsi/scsi_transport_iscsi.c
@@ -1545,7 +1545,7 @@ iscsi_bsg_host_add(struct Scsi_Host *shost, struct iscsi_cls_host *ihost)
1545 1545 snprintf(bsg_name, sizeof(bsg_name), "iscsi_host%d", shost->host_no);
1546 1546 scsi_init_limits(shost, &lim);
1547 1547 q = bsg_setup_queue(dev, bsg_name, &lim, iscsi_bsg_host_dispatch, NULL,
1548 - 0);
1548 + 0, SCSI_SENSE_BUFFERSIZE);
1549 1549 if (IS_ERR(q)) {
1550 1550 shost_printk(KERN_ERR, shost, "bsg interface failed to "
1551 1551 "initialize - no request queue\n");
modified drivers/scsi/scsi_transport_sas.c
@@ -199,7 +199,8 @@ static int sas_bsg_initialize(struct Scsi_Host *shost, struct sas_rphy *rphy)
199 199
200 200 if (rphy) {
201 201 q = bsg_setup_queue(&rphy->dev, dev_name(&rphy->dev), NULL,
202 - sas_smp_dispatch, NULL, 0);
202 + sas_smp_dispatch, NULL, 0,
203 + SCSI_SENSE_BUFFERSIZE);
203 204 if (IS_ERR(q))
204 205 return PTR_ERR(q);
205 206 rphy->q = q;
@@ -208,7 +209,8 @@ static int sas_bsg_initialize(struct Scsi_Host *shost, struct sas_rphy *rphy)
208 209
209 210 snprintf(name, sizeof(name), "sas_host%d", shost->host_no);
210 211 q = bsg_setup_queue(&shost->shost_gendev, name, NULL,
211 - sas_smp_dispatch, NULL, 0);
212 + sas_smp_dispatch, NULL, 0,
213 + SCSI_SENSE_BUFFERSIZE);
212 214 if (IS_ERR(q))
213 215 return PTR_ERR(q);
214 216 to_sas_host_attrs(shost)->q = q;
modified drivers/ufs/core/ufs_bsg.c
@@ -258,7 +258,7 @@ int ufs_bsg_probe(struct ufs_hba *hba)
258 258 goto out;
259 259
260 260 q = bsg_setup_queue(bsg_dev, dev_name(bsg_dev), NULL, ufs_bsg_request,
261 - NULL, 0);
261 + NULL, 0, sizeof(struct ufs_rpmb_reply));
262 262 if (IS_ERR(q)) {
263 263 ret = PTR_ERR(q);
264 264 device_del(bsg_dev);
modified include/linux/bsg-lib.h
@@ -66,7 +66,8 @@ void bsg_job_done(struct bsg_job *job, int result,
66 66 unsigned int reply_payload_rcv_len);
67 67 struct request_queue *bsg_setup_queue(struct device *dev, const char *name,
68 68 struct queue_limits *lim, bsg_job_fn *job_fn,
69 - bsg_timeout_fn *timeout, int dd_job_size);
69 + bsg_timeout_fn *timeout, int dd_job_size,
70 + unsigned int reply_len);
70 71 void bsg_remove_queue(struct request_queue *q);
71 72 void bsg_job_put(struct bsg_job *job);
72 73 int __must_check bsg_job_get(struct bsg_job *job);