Skip to content

Commit d92f79a

Browse files
committed
Merge branch 'nvme-5.8' of git://git.infradead.org/nvme into for-5.8/drivers
Pull NVMe updates from Christoph: "The second large batch of nvme updates: - t10 protection information support for nvme-rdma and nvmet-rdma (Israel Rukshin and Max Gurtovoy) - target side AEN improvements (Chaitanya Kulkarni) - various fixes and minor improvements all over, icluding the nvme part of the lpfc driver" * 'nvme-5.8' of git://git.infradead.org/nvme: (38 commits) lpfc: Fix return value in __lpfc_nvme_ls_abort lpfc: fix axchg pointer reference after free and double frees lpfc: Fix pointer checks and comments in LS receive refactoring nvme: set dma alignment to qword nvmet: cleanups the loop in nvmet_async_events_process nvmet: fix memory leak when removing namespaces and controllers concurrently nvmet-rdma: add metadata/T10-PI support nvmet: add metadata support for block devices nvmet: add metadata/T10-PI support nvme: add Metadata Capabilities enumerations nvmet: rename nvmet_check_data_len to nvmet_check_transfer_len nvmet: rename nvmet_rw_len to nvmet_rw_data_len nvmet: add metadata characteristics for a namespace nvme-rdma: add metadata/T10-PI support nvme-rdma: introduce nvme_rdma_sgl structure nvme: introduce NVME_INLINE_METADATA_SG_CNT nvme: enforce extended LBA format for fabrics metadata nvme: introduce max_integrity_segments ctrl attribute nvme: make nvme_ns_has_pi accessible to transports nvme: introduce NVME_NS_METADATA_SUPPORTED flag ...
2 parents 263c615 + 6b6e896 commit d92f79a

File tree

24 files changed

+1116
-222
lines changed

24 files changed

+1116
-222
lines changed

drivers/nvme/host/core.c

Lines changed: 70 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <linux/pr.h>
2020
#include <linux/ptrace.h>
2121
#include <linux/nvme_ioctl.h>
22-
#include <linux/t10-pi.h>
2322
#include <linux/pm_qos.h>
2423
#include <asm/unaligned.h>
2524

@@ -204,11 +203,6 @@ static void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl)
204203
nvme_put_ctrl(ctrl);
205204
}
206205

207-
static inline bool nvme_ns_has_pi(struct nvme_ns *ns)
208-
{
209-
return ns->pi_type && ns->ms == sizeof(struct t10_pi_tuple);
210-
}
211-
212206
static blk_status_t nvme_error_status(u16 status)
213207
{
214208
switch (status & 0x7ff) {
@@ -552,19 +546,22 @@ static int nvme_configure_directives(struct nvme_ctrl *ctrl)
552546

553547
ret = nvme_get_stream_params(ctrl, &s, NVME_NSID_ALL);
554548
if (ret)
555-
return ret;
549+
goto out_disable_stream;
556550

557551
ctrl->nssa = le16_to_cpu(s.nssa);
558552
if (ctrl->nssa < BLK_MAX_WRITE_HINTS - 1) {
559553
dev_info(ctrl->device, "too few streams (%u) available\n",
560554
ctrl->nssa);
561-
nvme_disable_streams(ctrl);
562-
return 0;
555+
goto out_disable_stream;
563556
}
564557

565558
ctrl->nr_streams = min_t(unsigned, ctrl->nssa, BLK_MAX_WRITE_HINTS - 1);
566559
dev_info(ctrl->device, "Using %u streams\n", ctrl->nr_streams);
567560
return 0;
561+
562+
out_disable_stream:
563+
nvme_disable_streams(ctrl);
564+
return ret;
568565
}
569566

570567
/*
@@ -1302,7 +1299,7 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
13021299
meta_len = (io.nblocks + 1) * ns->ms;
13031300
metadata = nvme_to_user_ptr(io.metadata);
13041301

1305-
if (ns->ext) {
1302+
if (ns->features & NVME_NS_EXT_LBAS) {
13061303
length += meta_len;
13071304
meta_len = 0;
13081305
} else if (meta_len) {
@@ -1696,7 +1693,8 @@ static int nvme_getgeo(struct block_device *bdev, struct hd_geometry *geo)
16961693
}
16971694

16981695
#ifdef CONFIG_BLK_DEV_INTEGRITY
1699-
static void nvme_init_integrity(struct gendisk *disk, u16 ms, u8 pi_type)
1696+
static void nvme_init_integrity(struct gendisk *disk, u16 ms, u8 pi_type,
1697+
u32 max_integrity_segments)
17001698
{
17011699
struct blk_integrity integrity;
17021700

@@ -1719,10 +1717,11 @@ static void nvme_init_integrity(struct gendisk *disk, u16 ms, u8 pi_type)
17191717
}
17201718
integrity.tuple_size = ms;
17211719
blk_integrity_register(disk, &integrity);
1722-
blk_queue_max_integrity_segments(disk->queue, 1);
1720+
blk_queue_max_integrity_segments(disk->queue, max_integrity_segments);
17231721
}
17241722
#else
1725-
static void nvme_init_integrity(struct gendisk *disk, u16 ms, u8 pi_type)
1723+
static void nvme_init_integrity(struct gendisk *disk, u16 ms, u8 pi_type,
1724+
u32 max_integrity_segments)
17261725
{
17271726
}
17281727
#endif /* CONFIG_BLK_DEV_INTEGRITY */
@@ -1842,7 +1841,7 @@ static void nvme_update_disk_info(struct gendisk *disk,
18421841
{
18431842
sector_t capacity = nvme_lba_to_sect(ns, le64_to_cpu(id->nsze));
18441843
unsigned short bs = 1 << ns->lba_shift;
1845-
u32 atomic_bs, phys_bs, io_opt;
1844+
u32 atomic_bs, phys_bs, io_opt = 0;
18461845

18471846
if (ns->lba_shift > PAGE_SHIFT) {
18481847
/* unsupported block size, set capacity to 0 later */
@@ -1851,7 +1850,7 @@ static void nvme_update_disk_info(struct gendisk *disk,
18511850
blk_mq_freeze_queue(disk->queue);
18521851
blk_integrity_unregister(disk);
18531852

1854-
atomic_bs = phys_bs = io_opt = bs;
1853+
atomic_bs = phys_bs = bs;
18551854
nvme_setup_streams_ns(ns->ctrl, ns, &phys_bs, &io_opt);
18561855
if (id->nabo == 0) {
18571856
/*
@@ -1882,13 +1881,28 @@ static void nvme_update_disk_info(struct gendisk *disk,
18821881
blk_queue_io_min(disk->queue, phys_bs);
18831882
blk_queue_io_opt(disk->queue, io_opt);
18841883

1885-
if (ns->ms && !ns->ext &&
1886-
(ns->ctrl->ops->flags & NVME_F_METADATA_SUPPORTED))
1887-
nvme_init_integrity(disk, ns->ms, ns->pi_type);
1888-
if ((ns->ms && !nvme_ns_has_pi(ns) && !blk_get_integrity(disk)) ||
1889-
ns->lba_shift > PAGE_SHIFT)
1884+
/*
1885+
* The block layer can't support LBA sizes larger than the page size
1886+
* yet, so catch this early and don't allow block I/O.
1887+
*/
1888+
if (ns->lba_shift > PAGE_SHIFT)
18901889
capacity = 0;
18911890

1891+
/*
1892+
* Register a metadata profile for PI, or the plain non-integrity NVMe
1893+
* metadata masquerading as Type 0 if supported, otherwise reject block
1894+
* I/O to namespaces with metadata except when the namespace supports
1895+
* PI, as it can strip/insert in that case.
1896+
*/
1897+
if (ns->ms) {
1898+
if (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) &&
1899+
(ns->features & NVME_NS_METADATA_SUPPORTED))
1900+
nvme_init_integrity(disk, ns->ms, ns->pi_type,
1901+
ns->ctrl->max_integrity_segments);
1902+
else if (!nvme_ns_has_pi(ns))
1903+
capacity = 0;
1904+
}
1905+
18921906
set_capacity_revalidate_and_notify(disk, capacity, false);
18931907

18941908
nvme_config_discard(disk, ns);
@@ -1902,9 +1916,10 @@ static void nvme_update_disk_info(struct gendisk *disk,
19021916
blk_mq_unfreeze_queue(disk->queue);
19031917
}
19041918

1905-
static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
1919+
static int __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
19061920
{
19071921
struct nvme_ns *ns = disk->private_data;
1922+
struct nvme_ctrl *ctrl = ns->ctrl;
19081923
u32 iob;
19091924

19101925
/*
@@ -1915,20 +1930,43 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
19151930
if (ns->lba_shift == 0)
19161931
ns->lba_shift = 9;
19171932

1918-
if ((ns->ctrl->quirks & NVME_QUIRK_STRIPE_SIZE) &&
1919-
is_power_of_2(ns->ctrl->max_hw_sectors))
1920-
iob = ns->ctrl->max_hw_sectors;
1933+
if ((ctrl->quirks & NVME_QUIRK_STRIPE_SIZE) &&
1934+
is_power_of_2(ctrl->max_hw_sectors))
1935+
iob = ctrl->max_hw_sectors;
19211936
else
19221937
iob = nvme_lba_to_sect(ns, le16_to_cpu(id->noiob));
19231938

1939+
ns->features = 0;
19241940
ns->ms = le16_to_cpu(id->lbaf[id->flbas & NVME_NS_FLBAS_LBA_MASK].ms);
1925-
ns->ext = ns->ms && (id->flbas & NVME_NS_FLBAS_META_EXT);
19261941
/* the PI implementation requires metadata equal t10 pi tuple size */
19271942
if (ns->ms == sizeof(struct t10_pi_tuple))
19281943
ns->pi_type = id->dps & NVME_NS_DPS_PI_MASK;
19291944
else
19301945
ns->pi_type = 0;
19311946

1947+
if (ns->ms) {
1948+
/*
1949+
* For PCIe only the separate metadata pointer is supported,
1950+
* as the block layer supplies metadata in a separate bio_vec
1951+
* chain. For Fabrics, only metadata as part of extended data
1952+
* LBA is supported on the wire per the Fabrics specification,
1953+
* but the HBA/HCA will do the remapping from the separate
1954+
* metadata buffers for us.
1955+
*/
1956+
if (id->flbas & NVME_NS_FLBAS_META_EXT) {
1957+
ns->features |= NVME_NS_EXT_LBAS;
1958+
if ((ctrl->ops->flags & NVME_F_FABRICS) &&
1959+
(ctrl->ops->flags & NVME_F_METADATA_SUPPORTED) &&
1960+
ctrl->max_integrity_segments)
1961+
ns->features |= NVME_NS_METADATA_SUPPORTED;
1962+
} else {
1963+
if (WARN_ON_ONCE(ctrl->ops->flags & NVME_F_FABRICS))
1964+
return -EINVAL;
1965+
if (ctrl->ops->flags & NVME_F_METADATA_SUPPORTED)
1966+
ns->features |= NVME_NS_METADATA_SUPPORTED;
1967+
}
1968+
}
1969+
19321970
if (iob)
19331971
blk_queue_chunk_sectors(ns->queue, rounddown_pow_of_two(iob));
19341972
nvme_update_disk_info(disk, ns, id);
@@ -1939,6 +1977,7 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
19391977
revalidate_disk(ns->head->disk);
19401978
}
19411979
#endif
1980+
return 0;
19421981
}
19431982

19441983
static int nvme_revalidate_disk(struct gendisk *disk)
@@ -1974,7 +2013,7 @@ static int nvme_revalidate_disk(struct gendisk *disk)
19742013
goto free_id;
19752014
}
19762015

1977-
__nvme_revalidate_disk(disk, id);
2016+
ret = __nvme_revalidate_disk(disk, id);
19782017
free_id:
19792018
kfree(id);
19802019
out:
@@ -2283,6 +2322,7 @@ static void nvme_set_queue_limits(struct nvme_ctrl *ctrl,
22832322
blk_queue_max_segments(q, min_t(u32, max_segments, USHRT_MAX));
22842323
}
22852324
blk_queue_virt_boundary(q, ctrl->page_size - 1);
2325+
blk_queue_dma_alignment(q, 7);
22862326
if (ctrl->vwc & NVME_CTRL_VWC_PRESENT)
22872327
vwc = true;
22882328
blk_queue_write_cache(q, vwc, vwc);
@@ -3628,7 +3668,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
36283668
memcpy(disk->disk_name, disk_name, DISK_NAME_LEN);
36293669
ns->disk = disk;
36303670

3631-
__nvme_revalidate_disk(disk, id);
3671+
if (__nvme_revalidate_disk(disk, id))
3672+
goto out_free_disk;
36323673

36333674
if ((ctrl->quirks & NVME_QUIRK_LIGHTNVM) && id->vs[0] == 0x1) {
36343675
ret = nvme_nvm_register(ns, disk_name, node);
@@ -3655,6 +3696,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
36553696
/* prevent double queue cleanup */
36563697
ns->disk->queue = NULL;
36573698
put_disk(ns->disk);
3699+
out_free_disk:
3700+
del_gendisk(ns->disk);
36583701
out_unlink_ns:
36593702
mutex_lock(&ctrl->subsys->lock);
36603703
list_del_rcu(&ns->siblings);

drivers/nvme/host/fc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct nvme_fc_fcp_op {
108108
struct nvme_fcp_op_w_sgl {
109109
struct nvme_fc_fcp_op op;
110110
struct scatterlist sgl[NVME_INLINE_SG_CNT];
111-
uint8_t priv[0];
111+
uint8_t priv[];
112112
};
113113

114114
struct nvme_fc_lport {
@@ -3246,7 +3246,9 @@ nvme_fc_reconnect_or_delete(struct nvme_fc_ctrl *ctrl, int status)
32463246
dev_warn(ctrl->ctrl.device,
32473247
"NVME-FC{%d}: dev_loss_tmo (%d) expired "
32483248
"while waiting for remoteport connectivity.\n",
3249-
ctrl->cnum, portptr->dev_loss_tmo);
3249+
ctrl->cnum, min_t(int, portptr->dev_loss_tmo,
3250+
(ctrl->ctrl.opts->max_reconnects *
3251+
ctrl->ctrl.opts->reconnect_delay)));
32503252
WARN_ON(nvme_delete_ctrl(&ctrl->ctrl));
32513253
}
32523254
}

drivers/nvme/host/lightnvm.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ struct nvme_nvm_bb_tbl {
171171
__le32 tdresv;
172172
__le32 thresv;
173173
__le32 rsvd2[8];
174-
__u8 blk[0];
174+
__u8 blk[];
175175
};
176176

177177
struct nvme_nvm_id20_addrf {
@@ -961,7 +961,10 @@ int nvme_nvm_register(struct nvme_ns *ns, char *disk_name, int node)
961961
geo = &dev->geo;
962962
geo->csecs = 1 << ns->lba_shift;
963963
geo->sos = ns->ms;
964-
geo->ext = ns->ext;
964+
if (ns->features & NVME_NS_EXT_LBAS)
965+
geo->ext = true;
966+
else
967+
geo->ext = false;
965968
geo->mdts = ns->ctrl->max_hw_sectors;
966969

967970
dev->q = q;

drivers/nvme/host/nvme.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/fault-inject.h>
1717
#include <linux/rcupdate.h>
1818
#include <linux/wait.h>
19+
#include <linux/t10-pi.h>
1920

2021
#include <trace/events/block.h>
2122

@@ -30,8 +31,10 @@ extern unsigned int admin_timeout;
3031

3132
#ifdef CONFIG_ARCH_NO_SG_CHAIN
3233
#define NVME_INLINE_SG_CNT 0
34+
#define NVME_INLINE_METADATA_SG_CNT 0
3335
#else
3436
#define NVME_INLINE_SG_CNT 2
37+
#define NVME_INLINE_METADATA_SG_CNT 1
3538
#endif
3639

3740
extern struct workqueue_struct *nvme_wq;
@@ -228,6 +231,7 @@ struct nvme_ctrl {
228231
u32 page_size;
229232
u32 max_hw_sectors;
230233
u32 max_segments;
234+
u32 max_integrity_segments;
231235
u16 crdt[3];
232236
u16 oncs;
233237
u16 oacs;
@@ -364,6 +368,11 @@ struct nvme_ns_head {
364368
#endif
365369
};
366370

371+
enum nvme_ns_features {
372+
NVME_NS_EXT_LBAS = 1 << 0, /* support extended LBA format */
373+
NVME_NS_METADATA_SUPPORTED = 1 << 1, /* support getting generated md */
374+
};
375+
367376
struct nvme_ns {
368377
struct list_head list;
369378

@@ -383,8 +392,8 @@ struct nvme_ns {
383392
u16 ms;
384393
u16 sgs;
385394
u32 sws;
386-
bool ext;
387395
u8 pi_type;
396+
unsigned long features;
388397
unsigned long flags;
389398
#define NVME_NS_REMOVING 0
390399
#define NVME_NS_DEAD 1
@@ -394,6 +403,12 @@ struct nvme_ns {
394403

395404
};
396405

406+
/* NVMe ns supports metadata actions by the controller (generate/strip) */
407+
static inline bool nvme_ns_has_pi(struct nvme_ns *ns)
408+
{
409+
return ns->pi_type && ns->ms == sizeof(struct t10_pi_tuple);
410+
}
411+
397412
struct nvme_ctrl_ops {
398413
const char *name;
399414
struct module *module;
@@ -497,7 +512,6 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
497512
void nvme_uninit_ctrl(struct nvme_ctrl *ctrl);
498513
void nvme_start_ctrl(struct nvme_ctrl *ctrl);
499514
void nvme_stop_ctrl(struct nvme_ctrl *ctrl);
500-
void nvme_put_ctrl(struct nvme_ctrl *ctrl);
501515
int nvme_init_identify(struct nvme_ctrl *ctrl);
502516

503517
void nvme_remove_namespaces(struct nvme_ctrl *ctrl);

0 commit comments

Comments
 (0)