All of lore.kernel.org
 help / color / mirror / Atom feed
* [nvme-4.13 V2] nvme: Implement NS Optimal IO Boundary from 1.3 Spec
@ 2017-06-15 15:47 Scott Bauer
  2017-06-15 15:52 ` Scott Bauer
  2017-06-15 16:57 ` Keith Busch
  0 siblings, 2 replies; 5+ messages in thread
From: Scott Bauer @ 2017-06-15 15:47 UTC (permalink / raw)


The NVMe 1.3 spec introduces Namespace Optimal IO Boundaries (NOIOB),
which standardizes the stripe mechanism we currently have quirks for.
This patch implements the necessary logic to handle this new feature.

Signed-off-by: Scott Bauer <scott.bauer at intel.com>
---
 drivers/nvme/host/core.c | 9 +++++++++
 drivers/nvme/host/nvme.h | 1 +
 include/linux/nvme.h     | 2 +-
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 4ff5114f467d..dfa72bb2ef0c 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1080,6 +1080,12 @@ static void nvme_init_integrity(struct nvme_ns *ns)
 }
 #endif /* CONFIG_BLK_DEV_INTEGRITY */
 
+static void nvme_set_chunk_size(struct nvme_ns *ns)
+{
+	unsigned int chunk_size = (((u32)ns->noiob) << ns->lba_shift) >> 9;
+	blk_queue_chunk_sectors(ns->queue, rounddown_pow_of_two(chunk_size));
+}
+
 static void nvme_config_discard(struct nvme_ns *ns)
 {
 	struct nvme_ctrl *ctrl = ns->ctrl;
@@ -1139,12 +1145,15 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
 	if (ns->lba_shift == 0)
 		ns->lba_shift = 9;
 	bs = 1 << ns->lba_shift;
+	ns->noiob = le16_to_cpu(id->noiob);
 
 	blk_mq_freeze_queue(disk->queue);
 
 	if (ns->ctrl->ops->flags & NVME_F_METADATA_SUPPORTED)
 		nvme_prep_integrity(disk, id, bs);
 	blk_queue_logical_block_size(ns->queue, bs);
+	if(ns->noiob)
+		nvme_set_chunk_size(ns);
 	if (ns->ms && !blk_get_integrity(disk) && !ns->ext)
 		nvme_init_integrity(ns);
 	if (ns->ms && !(ns->ms == 8 && ns->pi_type) && !blk_get_integrity(disk))
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index f27c58b860f4..ec8c7363934d 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -202,6 +202,7 @@ struct nvme_ns {
 	bool ext;
 	u8 pi_type;
 	unsigned long flags;
+	u16 noiob;
 
 #define NVME_NS_REMOVING 0
 #define NVME_NS_DEAD     1
diff --git a/include/linux/nvme.h b/include/linux/nvme.h
index 6d476f242ee6..291587a0743f 100644
--- a/include/linux/nvme.h
+++ b/include/linux/nvme.h
@@ -282,7 +282,7 @@ struct nvme_id_ns {
 	__le16			nabsn;
 	__le16			nabo;
 	__le16			nabspf;
-	__u16			rsvd46;
+	__le16			noiob;
 	__u8			nvmcap[16];
 	__u8			rsvd64[40];
 	__u8			nguid[16];
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [nvme-4.13 V2] nvme: Implement NS Optimal IO Boundary from 1.3 Spec
  2017-06-15 15:47 [nvme-4.13 V2] nvme: Implement NS Optimal IO Boundary from 1.3 Spec Scott Bauer
@ 2017-06-15 15:52 ` Scott Bauer
  2017-06-15 16:08   ` Christoph Hellwig
  2017-06-15 16:57 ` Keith Busch
  1 sibling, 1 reply; 5+ messages in thread
From: Scott Bauer @ 2017-06-15 15:52 UTC (permalink / raw)


On Thu, Jun 15, 2017@09:47:26AM -0600, Scott Bauer wrote:
> The NVMe 1.3 spec introduces Namespace Optimal IO Boundaries (NOIOB),
> which standardizes the stripe mechanism we currently have quirks for.
> This patch implements the necessary logic to handle this new feature.
> 
> Signed-off-by: Scott Bauer <scott.bauer at intel.com>
> ---
>  drivers/nvme/host/core.c | 9 +++++++++
>  drivers/nvme/host/nvme.h | 1 +
>  include/linux/nvme.h     | 2 +-
>  3 files changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 4ff5114f467d..dfa72bb2ef0c 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -1080,6 +1080,12 @@ static void nvme_init_integrity(struct nvme_ns *ns)
>  }
>  #endif /* CONFIG_BLK_DEV_INTEGRITY */
>  
> +static void nvme_set_chunk_size(struct nvme_ns *ns)
> +{
> +	unsigned int chunk_size = (((u32)ns->noiob) << ns->lba_shift) >> 9;
> +	blk_queue_chunk_sectors(ns->queue, rounddown_pow_of_two(chunk_size));
> +}
> +
>  static void nvme_config_discard(struct nvme_ns *ns)
>  {
>  	struct nvme_ctrl *ctrl = ns->ctrl;
> @@ -1139,12 +1145,15 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
>  	if (ns->lba_shift == 0)
>  		ns->lba_shift = 9;
>  	bs = 1 << ns->lba_shift;
> +	ns->noiob = le16_to_cpu(id->noiob);

I need to re-spin this one more time. I forgot to add the 1.3 version check before accessing the
register here.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [nvme-4.13 V2] nvme: Implement NS Optimal IO Boundary from 1.3 Spec
  2017-06-15 15:52 ` Scott Bauer
@ 2017-06-15 16:08   ` Christoph Hellwig
  0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2017-06-15 16:08 UTC (permalink / raw)


On Thu, Jun 15, 2017@09:52:52AM -0600, Scott Bauer wrote:
> I need to re-spin this one more time. I forgot to add the 1.3 version check before accessing the
> register here.

NVMe TPs also apply to older versions, so we should be fine without
the check.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [nvme-4.13 V2] nvme: Implement NS Optimal IO Boundary from 1.3 Spec
  2017-06-15 15:47 [nvme-4.13 V2] nvme: Implement NS Optimal IO Boundary from 1.3 Spec Scott Bauer
  2017-06-15 15:52 ` Scott Bauer
@ 2017-06-15 16:57 ` Keith Busch
  2017-06-15 17:03   ` Keith Busch
  1 sibling, 1 reply; 5+ messages in thread
From: Keith Busch @ 2017-06-15 16:57 UTC (permalink / raw)


On Thu, Jun 15, 2017@09:47:26AM -0600, Scott Bauer wrote:
> The NVMe 1.3 spec introduces Namespace Optimal IO Boundaries (NOIOB),
> which standardizes the stripe mechanism we currently have quirks for.
> This patch implements the necessary logic to handle this new feature.
> 
> Signed-off-by: Scott Bauer <scott.bauer at intel.com>
> ---
>  drivers/nvme/host/core.c | 9 +++++++++
>  drivers/nvme/host/nvme.h | 1 +
>  include/linux/nvme.h     | 2 +-
>  3 files changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 4ff5114f467d..dfa72bb2ef0c 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -1080,6 +1080,12 @@ static void nvme_init_integrity(struct nvme_ns *ns)
>  }
>  #endif /* CONFIG_BLK_DEV_INTEGRITY */
>  
> +static void nvme_set_chunk_size(struct nvme_ns *ns)
> +{
> +	unsigned int chunk_size = (((u32)ns->noiob) << ns->lba_shift) >> 9;

Let's say we've a large noiob (16k) with a 4k block size. The above would
shift beyond 32-bits, so I would rewrite this as:

	unsigned int chunk_size = (((u32)ns->noiob) << (ns->lba_shift - 9));

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [nvme-4.13 V2] nvme: Implement NS Optimal IO Boundary from 1.3 Spec
  2017-06-15 16:57 ` Keith Busch
@ 2017-06-15 17:03   ` Keith Busch
  0 siblings, 0 replies; 5+ messages in thread
From: Keith Busch @ 2017-06-15 17:03 UTC (permalink / raw)


On Thu, Jun 15, 2017@12:57:31PM -0400, Keith Busch wrote:
> Let's say we've a large noiob (16k) with a 4k block size. The above would
> shift beyond 32-bits, so I would rewrite this as:
> 
> 	unsigned int chunk_size = (((u32)ns->noiob) << (ns->lba_shift - 9));

Oops, please disregard the fact I'm can't count overflow correctly...

I still prefer the alternate shift calculation, though.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-06-15 17:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-15 15:47 [nvme-4.13 V2] nvme: Implement NS Optimal IO Boundary from 1.3 Spec Scott Bauer
2017-06-15 15:52 ` Scott Bauer
2017-06-15 16:08   ` Christoph Hellwig
2017-06-15 16:57 ` Keith Busch
2017-06-15 17:03   ` Keith Busch

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.