public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCHv3] nvme: module parameter to disable pi with offsets
@ 2024-10-24 15:49 Keith Busch
  2024-10-24 15:53 ` Christoph Hellwig
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Keith Busch @ 2024-10-24 15:49 UTC (permalink / raw)
  To: linux-nvme, hch; +Cc: martin.petersen, joshi.k, Keith Busch, David Wei

From: Keith Busch <kbusch@kernel.org>

A recent commit enables integrity checks for formats the previous kernel
versions registered with the "nop" integrity profile. This means
namespaces using that format become unreadable when upgrading the kernel
past that commit.

Introduce a module parameter to restore the "nop" integrity profile so
that storage can be readable once again. This could be a boot device, so
the setting needs to happen at module load time.

Fixes: 921e81db524d17 ("nvme: allow integrity when PI is not in first bytes")
Reported-by: David Wei <dw@davidwei.uk>
Signed-off-by: Keith Busch <kbusch@kernel.org>
---
v2->v3:

  Updated name and added a comment to explain why the parameter exists
 
 drivers/nvme/host/core.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 84cb859a911d0..4ae878b86f2ba 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -91,6 +91,17 @@ module_param(apst_secondary_latency_tol_us, ulong, 0644);
 MODULE_PARM_DESC(apst_secondary_latency_tol_us,
 	"secondary APST latency tolerance in us");
 
+/*
+ * Older kernels didn't enable protection information if it was at an offset.
+ * Newer kernels do, so it breaks reads on the upgrade if such formats were
+ * used in prior kernels since the metadata written did not contain a valid
+ * checksum.
+ */
+static bool disable_pi_offsets = false;
+module_param(disable_pi_offsets, bool, 0444);
+MODULE_PARM_DESC(disable_pi_offsets,
+	"disable protection information if it has an offset");
+
 /*
  * nvme_wq - hosts nvme related works that are not reset or delete
  * nvme_reset_wq - hosts nvme reset works
@@ -1915,6 +1926,8 @@ static void nvme_configure_metadata(struct nvme_ctrl *ctrl,
 		head->pi_type = id->dps & NVME_NS_DPS_PI_MASK;
 	if (!(id->dps & NVME_NS_DPS_PI_FIRST))
 		info->pi_offset = head->ms - head->pi_size;
+	if (info->pi_offset && disable_pi)
+		head->pi_type = 0;
 
 	if (ctrl->ops->flags & NVME_F_FABRICS) {
 		/*
-- 
2.43.5



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

* Re: [PATCHv3] nvme: module parameter to disable pi with offsets
  2024-10-24 15:49 [PATCHv3] nvme: module parameter to disable pi with offsets Keith Busch
@ 2024-10-24 15:53 ` Christoph Hellwig
  2024-10-24 16:44 ` Keith Busch
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2024-10-24 15:53 UTC (permalink / raw)
  To: Keith Busch
  Cc: linux-nvme, hch, martin.petersen, joshi.k, Keith Busch, David Wei

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>



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

* Re: [PATCHv3] nvme: module parameter to disable pi with offsets
  2024-10-24 15:49 [PATCHv3] nvme: module parameter to disable pi with offsets Keith Busch
  2024-10-24 15:53 ` Christoph Hellwig
@ 2024-10-24 16:44 ` Keith Busch
  2024-10-24 17:29   ` Kanchan Joshi
  2024-10-24 18:11   ` Chaitanya Kulkarni
  2024-10-24 19:08 ` Tokunori Ikegami
  2024-10-30 14:18 ` Keith Busch
  3 siblings, 2 replies; 7+ messages in thread
From: Keith Busch @ 2024-10-24 16:44 UTC (permalink / raw)
  To: Keith Busch; +Cc: linux-nvme, hch, martin.petersen, joshi.k, David Wei

On Thu, Oct 24, 2024 at 08:49:23AM -0700, Keith Busch wrote:
> +	if (info->pi_offset && disable_pi)
> +		head->pi_type = 0;

Added to nvme-6.12, with the typo fix: should be "disable_pi_offsets"


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

* Re: [PATCHv3] nvme: module parameter to disable pi with offsets
  2024-10-24 16:44 ` Keith Busch
@ 2024-10-24 17:29   ` Kanchan Joshi
  2024-10-24 18:11   ` Chaitanya Kulkarni
  1 sibling, 0 replies; 7+ messages in thread
From: Kanchan Joshi @ 2024-10-24 17:29 UTC (permalink / raw)
  To: Keith Busch, Keith Busch; +Cc: linux-nvme, hch, martin.petersen, David Wei

On 10/24/2024 10:14 PM, Keith Busch wrote:
> On Thu, Oct 24, 2024 at 08:49:23AM -0700, Keith Busch wrote:
>> +	if (info->pi_offset && disable_pi)
>> +		head->pi_type = 0;
> Added to nvme-6.12, with the typo fix: should be "disable_pi_offsets"

With that change

Reviewed-by: Kanchan Joshi <joshi.k@samsung.com>


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

* Re: [PATCHv3] nvme: module parameter to disable pi with offsets
  2024-10-24 16:44 ` Keith Busch
  2024-10-24 17:29   ` Kanchan Joshi
@ 2024-10-24 18:11   ` Chaitanya Kulkarni
  1 sibling, 0 replies; 7+ messages in thread
From: Chaitanya Kulkarni @ 2024-10-24 18:11 UTC (permalink / raw)
  To: Keith Busch, Keith Busch
  Cc: linux-nvme@lists.infradead.org, hch@lst.de,
	martin.petersen@oracle.com, joshi.k@samsung.com, David Wei

On 10/24/24 09:44, Keith Busch wrote:
> On Thu, Oct 24, 2024 at 08:49:23AM -0700, Keith Busch wrote:
>> +	if (info->pi_offset && disable_pi)
>> +		head->pi_type = 0;
> Added to nvme-6.12, with the typo fix: should be "disable_pi_offsets"

Indeed.


Looks good. Please add my tag :-

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck



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

* Re: [PATCHv3] nvme: module parameter to disable pi with offsets
  2024-10-24 15:49 [PATCHv3] nvme: module parameter to disable pi with offsets Keith Busch
  2024-10-24 15:53 ` Christoph Hellwig
  2024-10-24 16:44 ` Keith Busch
@ 2024-10-24 19:08 ` Tokunori Ikegami
  2024-10-30 14:18 ` Keith Busch
  3 siblings, 0 replies; 7+ messages in thread
From: Tokunori Ikegami @ 2024-10-24 19:08 UTC (permalink / raw)
  To: Keith Busch, linux-nvme, hch
  Cc: martin.petersen, joshi.k, Keith Busch, David Wei

On 2024/10/25 0:49, Keith Busch wrote:
> From: Keith Busch <kbusch@kernel.org>
>
> +module_param(disable_pi_offsets, bool, 0444);

About the naming "disable" is negative meaning so seems better to be a 
positive parameter like as "use_pi_offsets", etc. for example. By the 
way the permission 0444 is only for reads so is it needed to change the 
value by any code change, etc.?




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

* Re: [PATCHv3] nvme: module parameter to disable pi with offsets
  2024-10-24 15:49 [PATCHv3] nvme: module parameter to disable pi with offsets Keith Busch
                   ` (2 preceding siblings ...)
  2024-10-24 19:08 ` Tokunori Ikegami
@ 2024-10-30 14:18 ` Keith Busch
  3 siblings, 0 replies; 7+ messages in thread
From: Keith Busch @ 2024-10-30 14:18 UTC (permalink / raw)
  To: Keith Busch; +Cc: linux-nvme, hch, martin.petersen, joshi.k, David Wei

On Thu, Oct 24, 2024 at 08:49:23AM -0700, Keith Busch wrote:
> +/*
> + * Older kernels didn't enable protection information if it was at an offset.
> + * Newer kernels do, so it breaks reads on the upgrade if such formats were
> + * used in prior kernels since the metadata written did not contain a valid
> + * checksum.
> + */
> +static bool disable_pi_offsets = false;
> +module_param(disable_pi_offsets, bool, 0444);
> +MODULE_PARM_DESC(disable_pi_offsets,
> +	"disable protection information if it has an offset");
> +
>  /*
>   * nvme_wq - hosts nvme related works that are not reset or delete
>   * nvme_reset_wq - hosts nvme reset works
> @@ -1915,6 +1926,8 @@ static void nvme_configure_metadata(struct nvme_ctrl *ctrl,
>  		head->pi_type = id->dps & NVME_NS_DPS_PI_MASK;
>  	if (!(id->dps & NVME_NS_DPS_PI_FIRST))
>  		info->pi_offset = head->ms - head->pi_size;
> +	if (info->pi_offset && disable_pi)
> +		head->pi_type = 0;

I need to rework this yet again. The old code didn't look for offsets.
It looked for the "first" flag. If you have MS == PI_SIZE, "first" and
"last" mean the exact same thing: there is no offset. But the old code
didn't care, it just wanted to see the PI_FIRST flag.

The part needs to look like this:

---
@@ -1937,10 +1937,12 @@ static void nvme_configure_metadata(struct nvme_ctrl *ctrl,

        if (head->pi_size && head->ms >= head->pi_size)
                head->pi_type = id->dps & NVME_NS_DPS_PI_MASK;
-       if (!(id->dps & NVME_NS_DPS_PI_FIRST))
-               info->pi_offset = head->ms - head->pi_size;
+       if (!(id->dps & NVME_NS_DPS_PI_FIRST)) {
+               if (disable_pi_offsets)
+                       head->pi_type = 0;
+               else
+                       info->pi_offset = head->ms - head->pi_size;
+       }
--


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

end of thread, other threads:[~2024-10-30 14:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-24 15:49 [PATCHv3] nvme: module parameter to disable pi with offsets Keith Busch
2024-10-24 15:53 ` Christoph Hellwig
2024-10-24 16:44 ` Keith Busch
2024-10-24 17:29   ` Kanchan Joshi
2024-10-24 18:11   ` Chaitanya Kulkarni
2024-10-24 19:08 ` Tokunori Ikegami
2024-10-30 14:18 ` Keith Busch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox