Skip to content

Commit c286c21

Browse files
committed
Merge tag 'block-6.10-20240614' of git://git.kernel.dk/linux
Pull block fixes from Jens Axboe: - NVMe pull request via Keith: - Discard double free on error conditions (Chunguang) - Target Fixes (Daniel) - Namespace detachment regression fix (Keith) - Fix for an issue with flush requests and queuelist reuse (Chengming) - nbd sparse annotation fixes (Christoph) - unmap and free bio mapped data via submitter (Anuj) - loop discard/fallocate unsupported fix (Cyril) - Fix for the zoned write plugging added in this release (Damien) - sed-opal wrong address fix (Su) * tag 'block-6.10-20240614' of git://git.kernel.dk/linux: loop: Disable fallocate() zero and discard if not supported nvme: fix namespace removal list nbd: Remove __force casts nvmet: always initialize cqe.result nvmet-passthru: propagate status from id override functions nvme: avoid double free special payload block: unmap and free user mapped integrity via submitter block: fix request.queuelist usage in flush block: Optimize disk zone resource cleanup block: sed-opal: avoid possible wrong address reference in read_sed_opal_key()
2 parents ac3cb72 + 5f75e08 commit c286c21

File tree

13 files changed

+100
-53
lines changed

13 files changed

+100
-53
lines changed

block/bio-integrity.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,38 @@ void bio_integrity_free(struct bio *bio)
144144
struct bio_integrity_payload *bip = bio_integrity(bio);
145145
struct bio_set *bs = bio->bi_pool;
146146

147+
if (bip->bip_flags & BIP_INTEGRITY_USER)
148+
return;
147149
if (bip->bip_flags & BIP_BLOCK_INTEGRITY)
148150
kfree(bvec_virt(bip->bip_vec));
149-
else if (bip->bip_flags & BIP_INTEGRITY_USER)
150-
bio_integrity_unmap_user(bip);
151151

152152
__bio_integrity_free(bs, bip);
153153
bio->bi_integrity = NULL;
154154
bio->bi_opf &= ~REQ_INTEGRITY;
155155
}
156156

157+
/**
158+
* bio_integrity_unmap_free_user - Unmap and free bio user integrity payload
159+
* @bio: bio containing bip to be unmapped and freed
160+
*
161+
* Description: Used to unmap and free the user mapped integrity portion of a
162+
* bio. Submitter attaching the user integrity buffer is responsible for
163+
* unmapping and freeing it during completion.
164+
*/
165+
void bio_integrity_unmap_free_user(struct bio *bio)
166+
{
167+
struct bio_integrity_payload *bip = bio_integrity(bio);
168+
struct bio_set *bs = bio->bi_pool;
169+
170+
if (WARN_ON_ONCE(!(bip->bip_flags & BIP_INTEGRITY_USER)))
171+
return;
172+
bio_integrity_unmap_user(bip);
173+
__bio_integrity_free(bs, bip);
174+
bio->bi_integrity = NULL;
175+
bio->bi_opf &= ~REQ_INTEGRITY;
176+
}
177+
EXPORT_SYMBOL(bio_integrity_unmap_free_user);
178+
157179
/**
158180
* bio_integrity_add_page - Attach integrity metadata
159181
* @bio: bio to update

block/blk-flush.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ static void blk_flush_complete_seq(struct request *rq,
185185
/* queue for flush */
186186
if (list_empty(pending))
187187
fq->flush_pending_since = jiffies;
188-
list_move_tail(&rq->queuelist, pending);
188+
list_add_tail(&rq->queuelist, pending);
189189
break;
190190

191191
case REQ_FSEQ_DATA:
@@ -263,6 +263,7 @@ static enum rq_end_io_ret flush_end_io(struct request *flush_rq,
263263
unsigned int seq = blk_flush_cur_seq(rq);
264264

265265
BUG_ON(seq != REQ_FSEQ_PREFLUSH && seq != REQ_FSEQ_POSTFLUSH);
266+
list_del_init(&rq->queuelist);
266267
blk_flush_complete_seq(rq, fq, seq, error);
267268
}
268269

block/blk-zoned.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,9 @@ static void disk_destroy_zone_wplugs_hash_table(struct gendisk *disk)
15521552

15531553
void disk_free_zone_resources(struct gendisk *disk)
15541554
{
1555+
if (!disk->zone_wplugs_pool)
1556+
return;
1557+
15551558
cancel_work_sync(&disk->zone_wplugs_work);
15561559

15571560
if (disk->zone_wplugs_wq) {

block/sed-opal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ static int read_sed_opal_key(const char *key_name, u_char *buffer, int buflen)
314314
&key_type_user, key_name, true);
315315

316316
if (IS_ERR(kref))
317-
ret = PTR_ERR(kref);
317+
return PTR_ERR(kref);
318318

319319
key = key_ref_to_ptr(kref);
320320
down_read(&key->sem);

drivers/block/loop.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,21 @@ static int lo_read_simple(struct loop_device *lo, struct request *rq,
302302
return 0;
303303
}
304304

305+
static void loop_clear_limits(struct loop_device *lo, int mode)
306+
{
307+
struct queue_limits lim = queue_limits_start_update(lo->lo_queue);
308+
309+
if (mode & FALLOC_FL_ZERO_RANGE)
310+
lim.max_write_zeroes_sectors = 0;
311+
312+
if (mode & FALLOC_FL_PUNCH_HOLE) {
313+
lim.max_hw_discard_sectors = 0;
314+
lim.discard_granularity = 0;
315+
}
316+
317+
queue_limits_commit_update(lo->lo_queue, &lim);
318+
}
319+
305320
static int lo_fallocate(struct loop_device *lo, struct request *rq, loff_t pos,
306321
int mode)
307322
{
@@ -320,6 +335,14 @@ static int lo_fallocate(struct loop_device *lo, struct request *rq, loff_t pos,
320335
ret = file->f_op->fallocate(file, mode, pos, blk_rq_bytes(rq));
321336
if (unlikely(ret && ret != -EINVAL && ret != -EOPNOTSUPP))
322337
return -EIO;
338+
339+
/*
340+
* We initially configure the limits in a hope that fallocate is
341+
* supported and clear them here if that turns out not to be true.
342+
*/
343+
if (unlikely(ret == -EOPNOTSUPP))
344+
loop_clear_limits(lo, mode);
345+
323346
return ret;
324347
}
325348

drivers/block/nbd.c

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -589,10 +589,11 @@ static inline int was_interrupted(int result)
589589
}
590590

591591
/*
592-
* Returns BLK_STS_RESOURCE if the caller should retry after a delay. Returns
593-
* -EAGAIN if the caller should requeue @cmd. Returns -EIO if sending failed.
592+
* Returns BLK_STS_RESOURCE if the caller should retry after a delay.
593+
* Returns BLK_STS_IOERR if sending failed.
594594
*/
595-
static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
595+
static blk_status_t nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd,
596+
int index)
596597
{
597598
struct request *req = blk_mq_rq_from_pdu(cmd);
598599
struct nbd_config *config = nbd->config;
@@ -614,13 +615,13 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
614615

615616
type = req_to_nbd_cmd_type(req);
616617
if (type == U32_MAX)
617-
return -EIO;
618+
return BLK_STS_IOERR;
618619

619620
if (rq_data_dir(req) == WRITE &&
620621
(config->flags & NBD_FLAG_READ_ONLY)) {
621622
dev_err_ratelimited(disk_to_dev(nbd->disk),
622623
"Write on read-only\n");
623-
return -EIO;
624+
return BLK_STS_IOERR;
624625
}
625626

626627
if (req->cmd_flags & REQ_FUA)
@@ -674,11 +675,11 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
674675
nsock->sent = sent;
675676
}
676677
set_bit(NBD_CMD_REQUEUED, &cmd->flags);
677-
return (__force int)BLK_STS_RESOURCE;
678+
return BLK_STS_RESOURCE;
678679
}
679680
dev_err_ratelimited(disk_to_dev(nbd->disk),
680681
"Send control failed (result %d)\n", result);
681-
return -EAGAIN;
682+
goto requeue;
682683
}
683684
send_pages:
684685
if (type != NBD_CMD_WRITE)
@@ -715,12 +716,12 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
715716
nsock->pending = req;
716717
nsock->sent = sent;
717718
set_bit(NBD_CMD_REQUEUED, &cmd->flags);
718-
return (__force int)BLK_STS_RESOURCE;
719+
return BLK_STS_RESOURCE;
719720
}
720721
dev_err(disk_to_dev(nbd->disk),
721722
"Send data failed (result %d)\n",
722723
result);
723-
return -EAGAIN;
724+
goto requeue;
724725
}
725726
/*
726727
* The completion might already have come in,
@@ -737,7 +738,16 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
737738
trace_nbd_payload_sent(req, handle);
738739
nsock->pending = NULL;
739740
nsock->sent = 0;
740-
return 0;
741+
__set_bit(NBD_CMD_INFLIGHT, &cmd->flags);
742+
return BLK_STS_OK;
743+
744+
requeue:
745+
/* retry on a different socket */
746+
dev_err_ratelimited(disk_to_dev(nbd->disk),
747+
"Request send failed, requeueing\n");
748+
nbd_mark_nsock_dead(nbd, nsock, 1);
749+
nbd_requeue_cmd(cmd);
750+
return BLK_STS_OK;
741751
}
742752

743753
static int nbd_read_reply(struct nbd_device *nbd, struct socket *sock,
@@ -1018,7 +1028,7 @@ static blk_status_t nbd_handle_cmd(struct nbd_cmd *cmd, int index)
10181028
struct nbd_device *nbd = cmd->nbd;
10191029
struct nbd_config *config;
10201030
struct nbd_sock *nsock;
1021-
int ret;
1031+
blk_status_t ret;
10221032

10231033
lockdep_assert_held(&cmd->lock);
10241034

@@ -1072,28 +1082,11 @@ static blk_status_t nbd_handle_cmd(struct nbd_cmd *cmd, int index)
10721082
ret = BLK_STS_OK;
10731083
goto out;
10741084
}
1075-
/*
1076-
* Some failures are related to the link going down, so anything that
1077-
* returns EAGAIN can be retried on a different socket.
1078-
*/
10791085
ret = nbd_send_cmd(nbd, cmd, index);
1080-
/*
1081-
* Access to this flag is protected by cmd->lock, thus it's safe to set
1082-
* the flag after nbd_send_cmd() succeed to send request to server.
1083-
*/
1084-
if (!ret)
1085-
__set_bit(NBD_CMD_INFLIGHT, &cmd->flags);
1086-
else if (ret == -EAGAIN) {
1087-
dev_err_ratelimited(disk_to_dev(nbd->disk),
1088-
"Request send failed, requeueing\n");
1089-
nbd_mark_nsock_dead(nbd, nsock, 1);
1090-
nbd_requeue_cmd(cmd);
1091-
ret = BLK_STS_OK;
1092-
}
10931086
out:
10941087
mutex_unlock(&nsock->tx_lock);
10951088
nbd_config_put(nbd);
1096-
return ret < 0 ? BLK_STS_IOERR : (__force blk_status_t)ret;
1089+
return ret;
10971090
}
10981091

10991092
static blk_status_t nbd_queue_rq(struct blk_mq_hw_ctx *hctx,

drivers/nvme/host/core.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,7 @@ void nvme_cleanup_cmd(struct request *req)
998998
clear_bit_unlock(0, &ctrl->discard_page_busy);
999999
else
10001000
kfree(bvec_virt(&req->special_vec));
1001+
req->rq_flags &= ~RQF_SPECIAL_PAYLOAD;
10011002
}
10021003
}
10031004
EXPORT_SYMBOL_GPL(nvme_cleanup_cmd);
@@ -3959,12 +3960,13 @@ static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,
39593960

39603961
mutex_lock(&ctrl->namespaces_lock);
39613962
list_for_each_entry_safe(ns, next, &ctrl->namespaces, list) {
3962-
if (ns->head->ns_id > nsid)
3963-
list_splice_init_rcu(&ns->list, &rm_list,
3964-
synchronize_rcu);
3963+
if (ns->head->ns_id > nsid) {
3964+
list_del_rcu(&ns->list);
3965+
synchronize_srcu(&ctrl->srcu);
3966+
list_add_tail_rcu(&ns->list, &rm_list);
3967+
}
39653968
}
39663969
mutex_unlock(&ctrl->namespaces_lock);
3967-
synchronize_srcu(&ctrl->srcu);
39683970

39693971
list_for_each_entry_safe(ns, next, &rm_list, list)
39703972
nvme_ns_remove(ns);

drivers/nvme/host/ioctl.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ static struct request *nvme_alloc_user_request(struct request_queue *q,
111111
return req;
112112
}
113113

114+
static void nvme_unmap_bio(struct bio *bio)
115+
{
116+
if (bio_integrity(bio))
117+
bio_integrity_unmap_free_user(bio);
118+
blk_rq_unmap_user(bio);
119+
}
120+
114121
static int nvme_map_user_request(struct request *req, u64 ubuffer,
115122
unsigned bufflen, void __user *meta_buffer, unsigned meta_len,
116123
u32 meta_seed, struct io_uring_cmd *ioucmd, unsigned int flags)
@@ -157,7 +164,7 @@ static int nvme_map_user_request(struct request *req, u64 ubuffer,
157164

158165
out_unmap:
159166
if (bio)
160-
blk_rq_unmap_user(bio);
167+
nvme_unmap_bio(bio);
161168
out:
162169
blk_mq_free_request(req);
163170
return ret;
@@ -195,7 +202,7 @@ static int nvme_submit_user_cmd(struct request_queue *q,
195202
if (result)
196203
*result = le64_to_cpu(nvme_req(req)->result.u64);
197204
if (bio)
198-
blk_rq_unmap_user(bio);
205+
nvme_unmap_bio(bio);
199206
blk_mq_free_request(req);
200207

201208
if (effects)
@@ -406,7 +413,7 @@ static void nvme_uring_task_cb(struct io_uring_cmd *ioucmd,
406413
struct nvme_uring_cmd_pdu *pdu = nvme_uring_cmd_pdu(ioucmd);
407414

408415
if (pdu->bio)
409-
blk_rq_unmap_user(pdu->bio);
416+
nvme_unmap_bio(pdu->bio);
410417
io_uring_cmd_done(ioucmd, pdu->status, pdu->result, issue_flags);
411418
}
412419

@@ -432,7 +439,7 @@ static enum rq_end_io_ret nvme_uring_cmd_end_io(struct request *req,
432439
*/
433440
if (blk_rq_is_poll(req)) {
434441
if (pdu->bio)
435-
blk_rq_unmap_user(pdu->bio);
442+
nvme_unmap_bio(pdu->bio);
436443
io_uring_cmd_iopoll_done(ioucmd, pdu->result, pdu->status);
437444
} else {
438445
io_uring_cmd_do_in_task_lazy(ioucmd, nvme_uring_task_cb);

drivers/nvme/target/core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@ bool nvmet_req_init(struct nvmet_req *req, struct nvmet_cq *cq,
957957
req->metadata_sg_cnt = 0;
958958
req->transfer_len = 0;
959959
req->metadata_len = 0;
960+
req->cqe->result.u64 = 0;
960961
req->cqe->status = 0;
961962
req->cqe->sq_head = 0;
962963
req->ns = NULL;

drivers/nvme/target/fabrics-cmd-auth.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ void nvmet_execute_auth_send(struct nvmet_req *req)
333333
pr_debug("%s: ctrl %d qid %d nvme status %x error loc %d\n",
334334
__func__, ctrl->cntlid, req->sq->qid,
335335
status, req->error_loc);
336-
req->cqe->result.u64 = 0;
337336
if (req->sq->dhchap_step != NVME_AUTH_DHCHAP_MESSAGE_SUCCESS2 &&
338337
req->sq->dhchap_step != NVME_AUTH_DHCHAP_MESSAGE_FAILURE2) {
339338
unsigned long auth_expire_secs = ctrl->kato ? ctrl->kato : 120;
@@ -516,8 +515,6 @@ void nvmet_execute_auth_receive(struct nvmet_req *req)
516515
status = nvmet_copy_to_sgl(req, 0, d, al);
517516
kfree(d);
518517
done:
519-
req->cqe->result.u64 = 0;
520-
521518
if (req->sq->dhchap_step == NVME_AUTH_DHCHAP_MESSAGE_SUCCESS2)
522519
nvmet_auth_sq_free(req->sq);
523520
else if (req->sq->dhchap_step == NVME_AUTH_DHCHAP_MESSAGE_FAILURE1) {

0 commit comments

Comments
 (0)