Skip to content

Commit ff88562

Browse files
committed
Merge tag 'block-6.15-20250411' of git://git.kernel.dk/linux
Pull more block fixes from Jens Axboe: "Apparently my internal clock was off, or perhaps it was just wishful thinking, but I sent out block fixes yesterday as my brain assumed it was Friday. Subsequently, that missed the NVMe fixes that should go into this weeks release as well. Hence, here's a followup with those, and another simple fix. - NVMe pull request via Christoph: - nvmet fc/fcloop refcounting fixes (Daniel Wagner) - fix missed namespace/ANA scans (Hannes Reinecke) - fix a use after free in the new TCP netns support (Kuniyuki Iwashima) - fix a NULL instead of false review in multipath (Uday Shankar) - Use strscpy() for null_blk disk name copy" * tag 'block-6.15-20250411' of git://git.kernel.dk/linux: null_blk: Use strscpy() instead of strscpy_pad() in null_add_dev() nvmet-fc: put ref when assoc->del_work is already scheduled nvmet-fc: take tgtport reference only once nvmet-fc: update tgtport ref per assoc nvmet-fc: inline nvmet_fc_free_hostport nvmet-fc: inline nvmet_fc_delete_assoc nvmet-fcloop: add ref counting to lport nvmet-fcloop: replace kref with refcount nvmet-fcloop: swap list_add_tail arguments nvme-tcp: fix use-after-free of netns by kernel TCP socket. nvme: multipath: fix return value of nvme_available_path nvme: re-read ANA log page after ns scan completes nvme: requeue namespace scan on missed AENs
2 parents 023e62c + 3b607b7 commit ff88562

File tree

6 files changed

+73
-76
lines changed

6 files changed

+73
-76
lines changed

drivers/block/null_blk/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,7 @@ static int null_add_dev(struct nullb_device *dev)
20312031
nullb->disk->minors = 1;
20322032
nullb->disk->fops = &null_ops;
20332033
nullb->disk->private_data = nullb;
2034-
strscpy_pad(nullb->disk->disk_name, nullb->disk_name, DISK_NAME_LEN);
2034+
strscpy(nullb->disk->disk_name, nullb->disk_name);
20352035

20362036
if (nullb->dev->zoned) {
20372037
rv = null_register_zoned_dev(nullb);

drivers/nvme/host/core.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4295,6 +4295,15 @@ static void nvme_scan_work(struct work_struct *work)
42954295
nvme_scan_ns_sequential(ctrl);
42964296
}
42974297
mutex_unlock(&ctrl->scan_lock);
4298+
4299+
/* Requeue if we have missed AENs */
4300+
if (test_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events))
4301+
nvme_queue_scan(ctrl);
4302+
#ifdef CONFIG_NVME_MULTIPATH
4303+
else
4304+
/* Re-read the ANA log page to not miss updates */
4305+
queue_work(nvme_wq, &ctrl->ana_work);
4306+
#endif
42984307
}
42994308

43004309
/*

drivers/nvme/host/multipath.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ static bool nvme_available_path(struct nvme_ns_head *head)
427427
struct nvme_ns *ns;
428428

429429
if (!test_bit(NVME_NSHEAD_DISK_LIVE, &head->flags))
430-
return NULL;
430+
return false;
431431

432432
list_for_each_entry_srcu(ns, &head->list, siblings,
433433
srcu_read_lock_held(&head->srcu)) {

drivers/nvme/host/tcp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,8 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,
18031803
ret = PTR_ERR(sock_file);
18041804
goto err_destroy_mutex;
18051805
}
1806+
1807+
sk_net_refcnt_upgrade(queue->sock->sk);
18061808
nvme_tcp_reclassify_socket(queue->sock);
18071809

18081810
/* Single syn retry */

drivers/nvme/target/fc.c

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -995,16 +995,6 @@ nvmet_fc_hostport_get(struct nvmet_fc_hostport *hostport)
995995
return kref_get_unless_zero(&hostport->ref);
996996
}
997997

998-
static void
999-
nvmet_fc_free_hostport(struct nvmet_fc_hostport *hostport)
1000-
{
1001-
/* if LLDD not implemented, leave as NULL */
1002-
if (!hostport || !hostport->hosthandle)
1003-
return;
1004-
1005-
nvmet_fc_hostport_put(hostport);
1006-
}
1007-
1008998
static struct nvmet_fc_hostport *
1009999
nvmet_fc_match_hostport(struct nvmet_fc_tgtport *tgtport, void *hosthandle)
10101000
{
@@ -1028,33 +1018,24 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tgtport, void *hosthandle)
10281018
struct nvmet_fc_hostport *newhost, *match = NULL;
10291019
unsigned long flags;
10301020

1021+
/*
1022+
* Caller holds a reference on tgtport.
1023+
*/
1024+
10311025
/* if LLDD not implemented, leave as NULL */
10321026
if (!hosthandle)
10331027
return NULL;
10341028

1035-
/*
1036-
* take reference for what will be the newly allocated hostport if
1037-
* we end up using a new allocation
1038-
*/
1039-
if (!nvmet_fc_tgtport_get(tgtport))
1040-
return ERR_PTR(-EINVAL);
1041-
10421029
spin_lock_irqsave(&tgtport->lock, flags);
10431030
match = nvmet_fc_match_hostport(tgtport, hosthandle);
10441031
spin_unlock_irqrestore(&tgtport->lock, flags);
10451032

1046-
if (match) {
1047-
/* no new allocation - release reference */
1048-
nvmet_fc_tgtport_put(tgtport);
1033+
if (match)
10491034
return match;
1050-
}
10511035

10521036
newhost = kzalloc(sizeof(*newhost), GFP_KERNEL);
1053-
if (!newhost) {
1054-
/* no new allocation - release reference */
1055-
nvmet_fc_tgtport_put(tgtport);
1037+
if (!newhost)
10561038
return ERR_PTR(-ENOMEM);
1057-
}
10581039

10591040
spin_lock_irqsave(&tgtport->lock, flags);
10601041
match = nvmet_fc_match_hostport(tgtport, hosthandle);
@@ -1063,6 +1044,7 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tgtport, void *hosthandle)
10631044
kfree(newhost);
10641045
newhost = match;
10651046
} else {
1047+
nvmet_fc_tgtport_get(tgtport);
10661048
newhost->tgtport = tgtport;
10671049
newhost->hosthandle = hosthandle;
10681050
INIT_LIST_HEAD(&newhost->host_list);
@@ -1075,29 +1057,24 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tgtport, void *hosthandle)
10751057
return newhost;
10761058
}
10771059

1078-
static void
1079-
nvmet_fc_delete_assoc(struct nvmet_fc_tgt_assoc *assoc)
1080-
{
1081-
nvmet_fc_delete_target_assoc(assoc);
1082-
nvmet_fc_tgt_a_put(assoc);
1083-
}
1084-
10851060
static void
10861061
nvmet_fc_delete_assoc_work(struct work_struct *work)
10871062
{
10881063
struct nvmet_fc_tgt_assoc *assoc =
10891064
container_of(work, struct nvmet_fc_tgt_assoc, del_work);
10901065
struct nvmet_fc_tgtport *tgtport = assoc->tgtport;
10911066

1092-
nvmet_fc_delete_assoc(assoc);
1067+
nvmet_fc_delete_target_assoc(assoc);
1068+
nvmet_fc_tgt_a_put(assoc);
10931069
nvmet_fc_tgtport_put(tgtport);
10941070
}
10951071

10961072
static void
10971073
nvmet_fc_schedule_delete_assoc(struct nvmet_fc_tgt_assoc *assoc)
10981074
{
10991075
nvmet_fc_tgtport_get(assoc->tgtport);
1100-
queue_work(nvmet_wq, &assoc->del_work);
1076+
if (!queue_work(nvmet_wq, &assoc->del_work))
1077+
nvmet_fc_tgtport_put(assoc->tgtport);
11011078
}
11021079

11031080
static bool
@@ -1143,6 +1120,7 @@ nvmet_fc_alloc_target_assoc(struct nvmet_fc_tgtport *tgtport, void *hosthandle)
11431120
goto out_ida;
11441121

11451122
assoc->tgtport = tgtport;
1123+
nvmet_fc_tgtport_get(tgtport);
11461124
assoc->a_id = idx;
11471125
INIT_LIST_HEAD(&assoc->a_list);
11481126
kref_init(&assoc->ref);
@@ -1190,7 +1168,7 @@ nvmet_fc_target_assoc_free(struct kref *ref)
11901168
/* Send Disconnect now that all i/o has completed */
11911169
nvmet_fc_xmt_disconnect_assoc(assoc);
11921170

1193-
nvmet_fc_free_hostport(assoc->hostport);
1171+
nvmet_fc_hostport_put(assoc->hostport);
11941172
spin_lock_irqsave(&tgtport->lock, flags);
11951173
oldls = assoc->rcv_disconn;
11961174
spin_unlock_irqrestore(&tgtport->lock, flags);
@@ -1244,6 +1222,8 @@ nvmet_fc_delete_target_assoc(struct nvmet_fc_tgt_assoc *assoc)
12441222
dev_info(tgtport->dev,
12451223
"{%d:%d} Association deleted\n",
12461224
tgtport->fc_target_port.port_num, assoc->a_id);
1225+
1226+
nvmet_fc_tgtport_put(tgtport);
12471227
}
12481228

12491229
static struct nvmet_fc_tgt_assoc *
@@ -1455,11 +1435,6 @@ nvmet_fc_free_tgtport(struct kref *ref)
14551435
struct nvmet_fc_tgtport *tgtport =
14561436
container_of(ref, struct nvmet_fc_tgtport, ref);
14571437
struct device *dev = tgtport->dev;
1458-
unsigned long flags;
1459-
1460-
spin_lock_irqsave(&nvmet_fc_tgtlock, flags);
1461-
list_del(&tgtport->tgt_list);
1462-
spin_unlock_irqrestore(&nvmet_fc_tgtlock, flags);
14631438

14641439
nvmet_fc_free_ls_iodlist(tgtport);
14651440

@@ -1620,6 +1595,11 @@ int
16201595
nvmet_fc_unregister_targetport(struct nvmet_fc_target_port *target_port)
16211596
{
16221597
struct nvmet_fc_tgtport *tgtport = targetport_to_tgtport(target_port);
1598+
unsigned long flags;
1599+
1600+
spin_lock_irqsave(&nvmet_fc_tgtlock, flags);
1601+
list_del(&tgtport->tgt_list);
1602+
spin_unlock_irqrestore(&nvmet_fc_tgtlock, flags);
16231603

16241604
nvmet_fc_portentry_unbind_tgt(tgtport);
16251605

drivers/nvme/target/fcloop.c

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ struct fcloop_lport {
208208
struct nvme_fc_local_port *localport;
209209
struct list_head lport_list;
210210
struct completion unreg_done;
211+
refcount_t ref;
211212
};
212213

213214
struct fcloop_lport_priv {
@@ -239,7 +240,7 @@ struct fcloop_nport {
239240
struct fcloop_tport *tport;
240241
struct fcloop_lport *lport;
241242
struct list_head nport_list;
242-
struct kref ref;
243+
refcount_t ref;
243244
u64 node_name;
244245
u64 port_name;
245246
u32 port_role;
@@ -274,7 +275,7 @@ struct fcloop_fcpreq {
274275
u32 inistate;
275276
bool active;
276277
bool aborted;
277-
struct kref ref;
278+
refcount_t ref;
278279
struct work_struct fcp_rcv_work;
279280
struct work_struct abort_rcv_work;
280281
struct work_struct tio_done_work;
@@ -478,7 +479,7 @@ fcloop_t2h_xmt_ls_rsp(struct nvme_fc_local_port *localport,
478479
if (targetport) {
479480
tport = targetport->private;
480481
spin_lock(&tport->lock);
481-
list_add_tail(&tport->ls_list, &tls_req->ls_list);
482+
list_add_tail(&tls_req->ls_list, &tport->ls_list);
482483
spin_unlock(&tport->lock);
483484
queue_work(nvmet_wq, &tport->ls_work);
484485
}
@@ -534,24 +535,18 @@ fcloop_tgt_discovery_evt(struct nvmet_fc_target_port *tgtport)
534535
}
535536

536537
static void
537-
fcloop_tfcp_req_free(struct kref *ref)
538+
fcloop_tfcp_req_put(struct fcloop_fcpreq *tfcp_req)
538539
{
539-
struct fcloop_fcpreq *tfcp_req =
540-
container_of(ref, struct fcloop_fcpreq, ref);
540+
if (!refcount_dec_and_test(&tfcp_req->ref))
541+
return;
541542

542543
kfree(tfcp_req);
543544
}
544545

545-
static void
546-
fcloop_tfcp_req_put(struct fcloop_fcpreq *tfcp_req)
547-
{
548-
kref_put(&tfcp_req->ref, fcloop_tfcp_req_free);
549-
}
550-
551546
static int
552547
fcloop_tfcp_req_get(struct fcloop_fcpreq *tfcp_req)
553548
{
554-
return kref_get_unless_zero(&tfcp_req->ref);
549+
return refcount_inc_not_zero(&tfcp_req->ref);
555550
}
556551

557552
static void
@@ -748,7 +743,7 @@ fcloop_fcp_req(struct nvme_fc_local_port *localport,
748743
INIT_WORK(&tfcp_req->fcp_rcv_work, fcloop_fcp_recv_work);
749744
INIT_WORK(&tfcp_req->abort_rcv_work, fcloop_fcp_abort_recv_work);
750745
INIT_WORK(&tfcp_req->tio_done_work, fcloop_tgt_fcprqst_done_work);
751-
kref_init(&tfcp_req->ref);
746+
refcount_set(&tfcp_req->ref, 1);
752747

753748
queue_work(nvmet_wq, &tfcp_req->fcp_rcv_work);
754749

@@ -1001,24 +996,39 @@ fcloop_fcp_abort(struct nvme_fc_local_port *localport,
1001996
}
1002997

1003998
static void
1004-
fcloop_nport_free(struct kref *ref)
999+
fcloop_lport_put(struct fcloop_lport *lport)
10051000
{
1006-
struct fcloop_nport *nport =
1007-
container_of(ref, struct fcloop_nport, ref);
1001+
unsigned long flags;
10081002

1009-
kfree(nport);
1003+
if (!refcount_dec_and_test(&lport->ref))
1004+
return;
1005+
1006+
spin_lock_irqsave(&fcloop_lock, flags);
1007+
list_del(&lport->lport_list);
1008+
spin_unlock_irqrestore(&fcloop_lock, flags);
1009+
1010+
kfree(lport);
1011+
}
1012+
1013+
static int
1014+
fcloop_lport_get(struct fcloop_lport *lport)
1015+
{
1016+
return refcount_inc_not_zero(&lport->ref);
10101017
}
10111018

10121019
static void
10131020
fcloop_nport_put(struct fcloop_nport *nport)
10141021
{
1015-
kref_put(&nport->ref, fcloop_nport_free);
1022+
if (!refcount_dec_and_test(&nport->ref))
1023+
return;
1024+
1025+
kfree(nport);
10161026
}
10171027

10181028
static int
10191029
fcloop_nport_get(struct fcloop_nport *nport)
10201030
{
1021-
return kref_get_unless_zero(&nport->ref);
1031+
return refcount_inc_not_zero(&nport->ref);
10221032
}
10231033

10241034
static void
@@ -1029,6 +1039,8 @@ fcloop_localport_delete(struct nvme_fc_local_port *localport)
10291039

10301040
/* release any threads waiting for the unreg to complete */
10311041
complete(&lport->unreg_done);
1042+
1043+
fcloop_lport_put(lport);
10321044
}
10331045

10341046
static void
@@ -1140,6 +1152,7 @@ fcloop_create_local_port(struct device *dev, struct device_attribute *attr,
11401152

11411153
lport->localport = localport;
11421154
INIT_LIST_HEAD(&lport->lport_list);
1155+
refcount_set(&lport->ref, 1);
11431156

11441157
spin_lock_irqsave(&fcloop_lock, flags);
11451158
list_add_tail(&lport->lport_list, &fcloop_lports);
@@ -1156,13 +1169,6 @@ fcloop_create_local_port(struct device *dev, struct device_attribute *attr,
11561169
return ret ? ret : count;
11571170
}
11581171

1159-
1160-
static void
1161-
__unlink_local_port(struct fcloop_lport *lport)
1162-
{
1163-
list_del(&lport->lport_list);
1164-
}
1165-
11661172
static int
11671173
__wait_localport_unreg(struct fcloop_lport *lport)
11681174
{
@@ -1175,8 +1181,6 @@ __wait_localport_unreg(struct fcloop_lport *lport)
11751181
if (!ret)
11761182
wait_for_completion(&lport->unreg_done);
11771183

1178-
kfree(lport);
1179-
11801184
return ret;
11811185
}
11821186

@@ -1199,8 +1203,9 @@ fcloop_delete_local_port(struct device *dev, struct device_attribute *attr,
11991203
list_for_each_entry(tlport, &fcloop_lports, lport_list) {
12001204
if (tlport->localport->node_name == nodename &&
12011205
tlport->localport->port_name == portname) {
1206+
if (!fcloop_lport_get(tlport))
1207+
break;
12021208
lport = tlport;
1203-
__unlink_local_port(lport);
12041209
break;
12051210
}
12061211
}
@@ -1210,6 +1215,7 @@ fcloop_delete_local_port(struct device *dev, struct device_attribute *attr,
12101215
return -ENOENT;
12111216

12121217
ret = __wait_localport_unreg(lport);
1218+
fcloop_lport_put(lport);
12131219

12141220
return ret ? ret : count;
12151221
}
@@ -1249,7 +1255,7 @@ fcloop_alloc_nport(const char *buf, size_t count, bool remoteport)
12491255
newnport->port_role = opts->roles;
12501256
if (opts->mask & NVMF_OPT_FCADDR)
12511257
newnport->port_id = opts->fcaddr;
1252-
kref_init(&newnport->ref);
1258+
refcount_set(&newnport->ref, 1);
12531259

12541260
spin_lock_irqsave(&fcloop_lock, flags);
12551261

@@ -1637,17 +1643,17 @@ static void __exit fcloop_exit(void)
16371643
for (;;) {
16381644
lport = list_first_entry_or_null(&fcloop_lports,
16391645
typeof(*lport), lport_list);
1640-
if (!lport)
1646+
if (!lport || !fcloop_lport_get(lport))
16411647
break;
16421648

1643-
__unlink_local_port(lport);
1644-
16451649
spin_unlock_irqrestore(&fcloop_lock, flags);
16461650

16471651
ret = __wait_localport_unreg(lport);
16481652
if (ret)
16491653
pr_warn("%s: Failed deleting local port\n", __func__);
16501654

1655+
fcloop_lport_put(lport);
1656+
16511657
spin_lock_irqsave(&fcloop_lock, flags);
16521658
}
16531659

0 commit comments

Comments
 (0)