[PATCH v2 2/2] nvme: decode the FDP Get Features result as a dword

From: shao.mingyin

Date: Sun Nov 22 2026 - 09:48:51 EST


From: Shao Mingyin <shao.mingyin@xxxxxxxxxx>

nvme_get_features() returns completion dword 0 as a CPU-endian u32.
nvme_query_fdp_info() reads the result through a byte-ordered structure.
On a big-endian host it reads the high byte for the FDP enable bit and
the wrong byte for the configuration index, so FDP can be skipped or
configured using the wrong descriptor.

Read the result into a u32 and extract the enable bit and configuration
index from the dword. Remove the now-unused result structure.

Fixes: 30b5f20bb2dd ("nvme: register fdp parameters with the block layer")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
---
Changes in v2:
- Remove struct nvme_fdp_config now that its only user is gone (Christoph).

The v1 QEMU test used an emulated FDP target over nvme-loop. On s390x
the namespace gained one write stream after the fix. On x86_64 it had
one stream with and without the fix. The core.c change is unchanged.

v1: https://lore.kernel.org/r/202611150127572887TC7vHzVUFLZ6nyW1NuhU@xxxxxxxxxx

drivers/nvme/host/core.c | 6 +++---
include/linux/nvme.h | 6 +-----
2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f43582e5f6c4a989669f8a92343467932a80b820..eddad69a4abee0322111fd8784898a658cb42bf6 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2339,8 +2339,8 @@ static int nvme_query_fdp_info(struct nvme_ns *ns, struct nvme_ns_info *info)
struct nvme_ns_head *head = ns->head;
struct nvme_ctrl *ctrl = ns->ctrl;
struct nvme_fdp_ruh_status *ruhs;
- struct nvme_fdp_config fdp;
struct nvme_command c = {};
+ u32 fdp;
size_t size;
int i, ret;

@@ -2351,10 +2351,10 @@ static int nvme_query_fdp_info(struct nvme_ns *ns, struct nvme_ns_info *info)
return ret;
}

- if (!(fdp.flags & FDPCFG_FDPE))
+ if (!(fdp & FDPCFG_FDPE))
return 0;

- ret = nvme_query_fdp_granularity(ctrl, info, fdp.fdpcidx);
+ ret = nvme_query_fdp_granularity(ctrl, info, (fdp >> 8) & 0xff);
if (!info->runs)
return ret;

diff --git a/include/linux/nvme.h b/include/linux/nvme.h
index 6248711784b37030e82c8a1ff8579c2d669da0ba..a75f3e5f6210792348d34bdba38b20a24e54202e 100644
--- a/include/linux/nvme.h
+++ b/include/linux/nvme.h
@@ -701,12 +701,8 @@ struct nvme_rotational_media_log {
__u8 rsvd24[488];
};

-struct nvme_fdp_config {
- __u8 flags;
+/* FDP Get Features result (completion dword 0). */
#define FDPCFG_FDPE (1U << 0)
- __u8 fdpcidx;
- __le16 reserved;
-};

struct nvme_fdp_ruh_desc {
__u8 ruht;

base-commit: 909ef7a9a30fa139e69e555e3606680f5cca7726
--
2.43.0