Skip to content

Commit 9d0e852

Browse files
committed
Merge tag 'nvme-6.9-2024-04-04' of git://git.infradead.org/nvme into block-6.9
Pull NVMe fixes from Keith: "nvme fixes for Linux 6.9 - Atomic queue limits fixes (Christoph) - Fabrics fixes (Hannes, Daniel)" * tag 'nvme-6.9-2024-04-04' of git://git.infradead.org/nvme: nvme-fc: rename free_ctrl callback to match name pattern nvmet-fc: move RCU read lock to nvmet_fc_assoc_exists nvmet: implement unique discovery NQN nvme: don't create a multipath node for zero capacity devices nvme: split nvme_update_zone_info nvme-multipath: don't inherit LBA-related fields for the multipath node
2 parents 22d24a5 + 205fb5f commit 9d0e852

File tree

7 files changed

+128
-33
lines changed

7 files changed

+128
-33
lines changed

drivers/nvme/host/core.c

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,6 +2076,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
20762076
bool vwc = ns->ctrl->vwc & NVME_CTRL_VWC_PRESENT;
20772077
struct queue_limits lim;
20782078
struct nvme_id_ns_nvm *nvm = NULL;
2079+
struct nvme_zone_info zi = {};
20792080
struct nvme_id_ns *id;
20802081
sector_t capacity;
20812082
unsigned lbaf;
@@ -2088,18 +2089,25 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
20882089
if (id->ncap == 0) {
20892090
/* namespace not allocated or attached */
20902091
info->is_removed = true;
2091-
ret = -ENODEV;
2092+
ret = -ENXIO;
20922093
goto out;
20932094
}
2095+
lbaf = nvme_lbaf_index(id->flbas);
20942096

20952097
if (ns->ctrl->ctratt & NVME_CTRL_ATTR_ELBAS) {
20962098
ret = nvme_identify_ns_nvm(ns->ctrl, info->nsid, &nvm);
20972099
if (ret < 0)
20982100
goto out;
20992101
}
21002102

2103+
if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) &&
2104+
ns->head->ids.csi == NVME_CSI_ZNS) {
2105+
ret = nvme_query_zone_info(ns, lbaf, &zi);
2106+
if (ret < 0)
2107+
goto out;
2108+
}
2109+
21012110
blk_mq_freeze_queue(ns->disk->queue);
2102-
lbaf = nvme_lbaf_index(id->flbas);
21032111
ns->head->lba_shift = id->lbaf[lbaf].ds;
21042112
ns->head->nuse = le64_to_cpu(id->nuse);
21052113
capacity = nvme_lba_to_sect(ns->head, le64_to_cpu(id->nsze));
@@ -2112,13 +2120,8 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
21122120
capacity = 0;
21132121
nvme_config_discard(ns, &lim);
21142122
if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) &&
2115-
ns->head->ids.csi == NVME_CSI_ZNS) {
2116-
ret = nvme_update_zone_info(ns, lbaf, &lim);
2117-
if (ret) {
2118-
blk_mq_unfreeze_queue(ns->disk->queue);
2119-
goto out;
2120-
}
2121-
}
2123+
ns->head->ids.csi == NVME_CSI_ZNS)
2124+
nvme_update_zone_info(ns, &lim, &zi);
21222125
ret = queue_limits_commit_update(ns->disk->queue, &lim);
21232126
if (ret) {
21242127
blk_mq_unfreeze_queue(ns->disk->queue);
@@ -2201,6 +2204,7 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info)
22012204
}
22022205

22032206
if (!ret && nvme_ns_head_multipath(ns->head)) {
2207+
struct queue_limits *ns_lim = &ns->disk->queue->limits;
22042208
struct queue_limits lim;
22052209

22062210
blk_mq_freeze_queue(ns->head->disk->queue);
@@ -2212,7 +2216,26 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info)
22122216
set_disk_ro(ns->head->disk, nvme_ns_is_readonly(ns, info));
22132217
nvme_mpath_revalidate_paths(ns);
22142218

2219+
/*
2220+
* queue_limits mixes values that are the hardware limitations
2221+
* for bio splitting with what is the device configuration.
2222+
*
2223+
* For NVMe the device configuration can change after e.g. a
2224+
* Format command, and we really want to pick up the new format
2225+
* value here. But we must still stack the queue limits to the
2226+
* least common denominator for multipathing to split the bios
2227+
* properly.
2228+
*
2229+
* To work around this, we explicitly set the device
2230+
* configuration to those that we just queried, but only stack
2231+
* the splitting limits in to make sure we still obey possibly
2232+
* lower limitations of other controllers.
2233+
*/
22152234
lim = queue_limits_start_update(ns->head->disk->queue);
2235+
lim.logical_block_size = ns_lim->logical_block_size;
2236+
lim.physical_block_size = ns_lim->physical_block_size;
2237+
lim.io_min = ns_lim->io_min;
2238+
lim.io_opt = ns_lim->io_opt;
22162239
queue_limits_stack_bdev(&lim, ns->disk->part0, 0,
22172240
ns->head->disk->disk_name);
22182241
ret = queue_limits_commit_update(ns->head->disk->queue, &lim);

drivers/nvme/host/fc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,7 +2428,7 @@ nvme_fc_ctrl_get(struct nvme_fc_ctrl *ctrl)
24282428
* controller. Called after last nvme_put_ctrl() call
24292429
*/
24302430
static void
2431-
nvme_fc_nvme_ctrl_freed(struct nvme_ctrl *nctrl)
2431+
nvme_fc_free_ctrl(struct nvme_ctrl *nctrl)
24322432
{
24332433
struct nvme_fc_ctrl *ctrl = to_fc_ctrl(nctrl);
24342434

@@ -3384,7 +3384,7 @@ static const struct nvme_ctrl_ops nvme_fc_ctrl_ops = {
33843384
.reg_read32 = nvmf_reg_read32,
33853385
.reg_read64 = nvmf_reg_read64,
33863386
.reg_write32 = nvmf_reg_write32,
3387-
.free_ctrl = nvme_fc_nvme_ctrl_freed,
3387+
.free_ctrl = nvme_fc_free_ctrl,
33883388
.submit_async_event = nvme_fc_submit_async_event,
33893389
.delete_ctrl = nvme_fc_delete_ctrl,
33903390
.get_address = nvmf_get_address,

drivers/nvme/host/nvme.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,10 +1036,18 @@ static inline bool nvme_disk_is_ns_head(struct gendisk *disk)
10361036
}
10371037
#endif /* CONFIG_NVME_MULTIPATH */
10381038

1039+
struct nvme_zone_info {
1040+
u64 zone_size;
1041+
unsigned int max_open_zones;
1042+
unsigned int max_active_zones;
1043+
};
1044+
10391045
int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
10401046
unsigned int nr_zones, report_zones_cb cb, void *data);
1041-
int nvme_update_zone_info(struct nvme_ns *ns, unsigned lbaf,
1042-
struct queue_limits *lim);
1047+
int nvme_query_zone_info(struct nvme_ns *ns, unsigned lbaf,
1048+
struct nvme_zone_info *zi);
1049+
void nvme_update_zone_info(struct nvme_ns *ns, struct queue_limits *lim,
1050+
struct nvme_zone_info *zi);
10431051
#ifdef CONFIG_BLK_DEV_ZONED
10441052
blk_status_t nvme_setup_zone_mgmt_send(struct nvme_ns *ns, struct request *req,
10451053
struct nvme_command *cmnd,

drivers/nvme/host/zns.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ static int nvme_set_max_append(struct nvme_ctrl *ctrl)
3535
return 0;
3636
}
3737

38-
int nvme_update_zone_info(struct nvme_ns *ns, unsigned lbaf,
39-
struct queue_limits *lim)
38+
int nvme_query_zone_info(struct nvme_ns *ns, unsigned lbaf,
39+
struct nvme_zone_info *zi)
4040
{
4141
struct nvme_effects_log *log = ns->head->effects;
4242
struct nvme_command c = { };
@@ -89,27 +89,34 @@ int nvme_update_zone_info(struct nvme_ns *ns, unsigned lbaf,
8989
goto free_data;
9090
}
9191

92-
ns->head->zsze =
93-
nvme_lba_to_sect(ns->head, le64_to_cpu(id->lbafe[lbaf].zsze));
94-
if (!is_power_of_2(ns->head->zsze)) {
92+
zi->zone_size = le64_to_cpu(id->lbafe[lbaf].zsze);
93+
if (!is_power_of_2(zi->zone_size)) {
9594
dev_warn(ns->ctrl->device,
96-
"invalid zone size:%llu for namespace:%u\n",
97-
ns->head->zsze, ns->head->ns_id);
95+
"invalid zone size: %llu for namespace: %u\n",
96+
zi->zone_size, ns->head->ns_id);
9897
status = -ENODEV;
9998
goto free_data;
10099
}
100+
zi->max_open_zones = le32_to_cpu(id->mor) + 1;
101+
zi->max_active_zones = le32_to_cpu(id->mar) + 1;
101102

102-
blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, ns->queue);
103-
lim->zoned = 1;
104-
lim->max_open_zones = le32_to_cpu(id->mor) + 1;
105-
lim->max_active_zones = le32_to_cpu(id->mar) + 1;
106-
lim->chunk_sectors = ns->head->zsze;
107-
lim->max_zone_append_sectors = ns->ctrl->max_zone_append;
108103
free_data:
109104
kfree(id);
110105
return status;
111106
}
112107

108+
void nvme_update_zone_info(struct nvme_ns *ns, struct queue_limits *lim,
109+
struct nvme_zone_info *zi)
110+
{
111+
lim->zoned = 1;
112+
lim->max_open_zones = zi->max_open_zones;
113+
lim->max_active_zones = zi->max_active_zones;
114+
lim->max_zone_append_sectors = ns->ctrl->max_zone_append;
115+
lim->chunk_sectors = ns->head->zsze =
116+
nvme_lba_to_sect(ns->head, zi->zone_size);
117+
blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, ns->queue);
118+
}
119+
113120
static void *nvme_zns_alloc_report_buffer(struct nvme_ns *ns,
114121
unsigned int nr_zones, size_t *buflen)
115122
{

drivers/nvme/target/configfs.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,11 @@ static struct config_group *nvmet_subsys_make(struct config_group *group,
16131613
return ERR_PTR(-EINVAL);
16141614
}
16151615

1616+
if (sysfs_streq(name, nvmet_disc_subsys->subsysnqn)) {
1617+
pr_err("can't create subsystem using unique discovery NQN\n");
1618+
return ERR_PTR(-EINVAL);
1619+
}
1620+
16161621
subsys = nvmet_subsys_alloc(name, NVME_NQN_NVME);
16171622
if (IS_ERR(subsys))
16181623
return ERR_CAST(subsys);
@@ -2159,7 +2164,49 @@ static const struct config_item_type nvmet_hosts_type = {
21592164

21602165
static struct config_group nvmet_hosts_group;
21612166

2167+
static ssize_t nvmet_root_discovery_nqn_show(struct config_item *item,
2168+
char *page)
2169+
{
2170+
return snprintf(page, PAGE_SIZE, "%s\n", nvmet_disc_subsys->subsysnqn);
2171+
}
2172+
2173+
static ssize_t nvmet_root_discovery_nqn_store(struct config_item *item,
2174+
const char *page, size_t count)
2175+
{
2176+
struct list_head *entry;
2177+
size_t len;
2178+
2179+
len = strcspn(page, "\n");
2180+
if (!len || len > NVMF_NQN_FIELD_LEN - 1)
2181+
return -EINVAL;
2182+
2183+
down_write(&nvmet_config_sem);
2184+
list_for_each(entry, &nvmet_subsystems_group.cg_children) {
2185+
struct config_item *item =
2186+
container_of(entry, struct config_item, ci_entry);
2187+
2188+
if (!strncmp(config_item_name(item), page, len)) {
2189+
pr_err("duplicate NQN %s\n", config_item_name(item));
2190+
up_write(&nvmet_config_sem);
2191+
return -EINVAL;
2192+
}
2193+
}
2194+
memset(nvmet_disc_subsys->subsysnqn, 0, NVMF_NQN_FIELD_LEN);
2195+
memcpy(nvmet_disc_subsys->subsysnqn, page, len);
2196+
up_write(&nvmet_config_sem);
2197+
2198+
return len;
2199+
}
2200+
2201+
CONFIGFS_ATTR(nvmet_root_, discovery_nqn);
2202+
2203+
static struct configfs_attribute *nvmet_root_attrs[] = {
2204+
&nvmet_root_attr_discovery_nqn,
2205+
NULL,
2206+
};
2207+
21622208
static const struct config_item_type nvmet_root_type = {
2209+
.ct_attrs = nvmet_root_attrs,
21632210
.ct_owner = THIS_MODULE,
21642211
};
21652212

drivers/nvme/target/core.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,13 @@ static struct nvmet_subsys *nvmet_find_get_subsys(struct nvmet_port *port,
15411541
}
15421542

15431543
down_read(&nvmet_config_sem);
1544+
if (!strncmp(nvmet_disc_subsys->subsysnqn, subsysnqn,
1545+
NVMF_NQN_SIZE)) {
1546+
if (kref_get_unless_zero(&nvmet_disc_subsys->ref)) {
1547+
up_read(&nvmet_config_sem);
1548+
return nvmet_disc_subsys;
1549+
}
1550+
}
15441551
list_for_each_entry(p, &port->subsystems, entry) {
15451552
if (!strncmp(p->subsys->subsysnqn, subsysnqn,
15461553
NVMF_NQN_SIZE)) {

drivers/nvme/target/fc.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,16 +1115,21 @@ nvmet_fc_schedule_delete_assoc(struct nvmet_fc_tgt_assoc *assoc)
11151115
}
11161116

11171117
static bool
1118-
nvmet_fc_assoc_exits(struct nvmet_fc_tgtport *tgtport, u64 association_id)
1118+
nvmet_fc_assoc_exists(struct nvmet_fc_tgtport *tgtport, u64 association_id)
11191119
{
11201120
struct nvmet_fc_tgt_assoc *a;
1121+
bool found = false;
11211122

1123+
rcu_read_lock();
11221124
list_for_each_entry_rcu(a, &tgtport->assoc_list, a_list) {
1123-
if (association_id == a->association_id)
1124-
return true;
1125+
if (association_id == a->association_id) {
1126+
found = true;
1127+
break;
1128+
}
11251129
}
1130+
rcu_read_unlock();
11261131

1127-
return false;
1132+
return found;
11281133
}
11291134

11301135
static struct nvmet_fc_tgt_assoc *
@@ -1164,13 +1169,11 @@ nvmet_fc_alloc_target_assoc(struct nvmet_fc_tgtport *tgtport, void *hosthandle)
11641169
ran = ran << BYTES_FOR_QID_SHIFT;
11651170

11661171
spin_lock_irqsave(&tgtport->lock, flags);
1167-
rcu_read_lock();
1168-
if (!nvmet_fc_assoc_exits(tgtport, ran)) {
1172+
if (!nvmet_fc_assoc_exists(tgtport, ran)) {
11691173
assoc->association_id = ran;
11701174
list_add_tail_rcu(&assoc->a_list, &tgtport->assoc_list);
11711175
done = true;
11721176
}
1173-
rcu_read_unlock();
11741177
spin_unlock_irqrestore(&tgtport->lock, flags);
11751178
} while (!done);
11761179

0 commit comments

Comments
 (0)