* [PATCH 1/7] hw/nvme: get feature - return invalid field if sel is reserved
2026-11-18 15:01 [PATCH 0/7] hw/nvme get-/set feature fixes (FDP-related) Jesper Devantier
@ 2026-11-18 15:01 ` Jesper Devantier
2026-11-18 21:54 ` Klaus Jensen
2026-11-18 15:01 ` [PATCH 2/7] hw/nvme: get feature - fix and revamp NS/NSID checks Jesper Devantier
` (5 subsequent siblings)
6 siblings, 1 reply; 12+ messages in thread
From: Jesper Devantier @ 2026-11-18 15:01 UTC (permalink / raw)
To: qemu-devel, Keith Busch, Klaus Jensen, Jesper Devantier,
qemu-block
Cc: Jesper Wendel Devantier
From: Jesper Wendel Devantier <j.devantier@samsung.com>
Base 2.4, figure 198, bits 10:08.
Get feature will now return invalid field if the value of sel
is in the reserved range.
Signed-off-by: Jesper Wendel Devantier <j.devantier@samsung.com>
---
hw/nvme/ctrl.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 71c24dc02b6..ee670481876 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -6462,6 +6462,8 @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeRequest *req)
case NVME_GETFEAT_SELECT_CAP:
result = nvme_feature_cap[fid];
goto out;
+ default:
+ return NVME_INVALID_FIELD | NVME_DNR;
}
switch (fid) {
--
2.51.2
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 1/7] hw/nvme: get feature - return invalid field if sel is reserved
2026-11-18 15:01 ` [PATCH 1/7] hw/nvme: get feature - return invalid field if sel is reserved Jesper Devantier
@ 2026-11-18 21:54 ` Klaus Jensen
0 siblings, 0 replies; 12+ messages in thread
From: Klaus Jensen @ 2026-11-18 21:54 UTC (permalink / raw)
To: Jesper Devantier
Cc: qemu-devel, Keith Busch, qemu-block, Jesper Wendel Devantier
[-- Attachment #1: Type: text/plain, Size: 1019 bytes --]
On Nov 18 16:01, Jesper Devantier wrote:
> From: Jesper Wendel Devantier <j.devantier@samsung.com>
>
> Base 2.4, figure 198, bits 10:08.
> Get feature will now return invalid field if the value of sel
> is in the reserved range.
>
> Signed-off-by: Jesper Wendel Devantier <j.devantier@samsung.com>
Fixes: 7c46310d298d ("hw/block/nvme: support the get/set features select and save fields")
Cc: qemu-stable@nongnu.org
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
> ---
> hw/nvme/ctrl.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
> index 71c24dc02b6..ee670481876 100644
> --- a/hw/nvme/ctrl.c
> +++ b/hw/nvme/ctrl.c
> @@ -6462,6 +6462,8 @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeRequest *req)
> case NVME_GETFEAT_SELECT_CAP:
> result = nvme_feature_cap[fid];
> goto out;
> + default:
> + return NVME_INVALID_FIELD | NVME_DNR;
> }
>
> switch (fid) {
>
> --
> 2.51.2
>
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 2/7] hw/nvme: get feature - fix and revamp NS/NSID checks
2026-11-18 15:01 [PATCH 0/7] hw/nvme get-/set feature fixes (FDP-related) Jesper Devantier
2026-11-18 15:01 ` [PATCH 1/7] hw/nvme: get feature - return invalid field if sel is reserved Jesper Devantier
@ 2026-11-18 15:01 ` Jesper Devantier
2026-11-18 15:01 ` [PATCH 3/7] hw/nvme: fdp enabled helper Jesper Devantier
` (4 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Jesper Devantier @ 2026-11-18 15:01 UTC (permalink / raw)
To: qemu-devel, Keith Busch, Klaus Jensen, Jesper Devantier,
qemu-block
Cc: Jesper Wendel Devantier
From: Jesper Wendel Devantier <j.devantier@samsung.com>
From the 2.4 Base specification, section 4.4 - RUH-scoped features'
get feature command should return Invalid Field if NSID is set to
the broadcast value.
NS-scoped features' get features command should, unless otherwise
specified in section 5.2.30, return Invalid Namespace or Format.
This patch
- reorders the checks
- ensures FID 1Eh (FDP events) correctly abort with Invalid Field
if a broadcast NSID is provided
- handles this special check in a switch-case, to provide for
other special cases - such as other RUH-scoped features or
exceptions from 5.2.30
- saves the returned `NvmeNamespace *` from `nvme_ns` to `ns`
- removes duplicate checks for NVME_ERROR_RECOVERY and
NVME_FDP_EVENTS
Signed-off-by: Jesper Wendel Devantier <j.devantier@samsung.com>
---
hw/nvme/ctrl.c | 42 ++++++++++++++++--------------------------
1 file changed, 16 insertions(+), 26 deletions(-)
diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index ee670481876..c8da01f11d0 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -6436,18 +6436,26 @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeRequest *req)
}
if (nvme_feature_cap[fid] & NVME_FEAT_CAP_NS) {
- if (!nvme_nsid_valid(n, nsid) || nsid == NVME_NSID_BROADCAST) {
+ if (nsid == NVME_NSID_BROADCAST) {
/*
- * The Reservation Notification Mask and Reservation Persistence
- * features require a status code of Invalid Field in Command when
- * NSID is FFFFFFFFh. Since the device does not support those
- * features we can always return Invalid Namespace or Format as we
- * should do for all other features.
+ * Base 2.4, section 4.4, if broadcast NSID:
+ * - If feature is RUH-scoped:
+ * abort with Invalid field
+ * - If feature is NS-scoped:
+ * Unless otherwise stated in 5.2.30, abort with
+ * status Invalid Namespace or Format
*/
+ switch (fid) {
+ case NVME_FDP_EVENTS:
+ return NVME_INVALID_FIELD | NVME_DNR;
+ default:
+ return NVME_INVALID_NSID | NVME_DNR;
+ }
+ } else if (!nvme_nsid_valid(n, nsid)) {
return NVME_INVALID_NSID | NVME_DNR;
}
-
- if (!nvme_ns(n, nsid)) {
+ ns = nvme_ns(n, nsid);
+ if (!ns) {
return NVME_INVALID_FIELD | NVME_DNR;
}
}
@@ -6489,15 +6497,6 @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeRequest *req)
return NVME_INVALID_FIELD | NVME_DNR;
case NVME_ERROR_RECOVERY:
- if (!nvme_nsid_valid(n, nsid)) {
- return NVME_INVALID_NSID | NVME_DNR;
- }
-
- ns = nvme_ns(n, nsid);
- if (unlikely(!ns)) {
- return NVME_INVALID_FIELD | NVME_DNR;
- }
-
result = ns->features.err_rec;
goto out;
case NVME_VOLATILE_WRITE_CACHE:
@@ -6536,15 +6535,6 @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeRequest *req)
}
goto out;
case NVME_FDP_EVENTS:
- if (!nvme_nsid_valid(n, nsid)) {
- return NVME_INVALID_NSID | NVME_DNR;
- }
-
- ns = nvme_ns(n, nsid);
- if (unlikely(!ns)) {
- return NVME_INVALID_FIELD | NVME_DNR;
- }
-
ret = nvme_get_feature_fdp_events(n, ns, req, &result);
if (ret) {
return ret;
--
2.51.2
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 3/7] hw/nvme: fdp enabled helper
2026-11-18 15:01 [PATCH 0/7] hw/nvme get-/set feature fixes (FDP-related) Jesper Devantier
2026-11-18 15:01 ` [PATCH 1/7] hw/nvme: get feature - return invalid field if sel is reserved Jesper Devantier
2026-11-18 15:01 ` [PATCH 2/7] hw/nvme: get feature - fix and revamp NS/NSID checks Jesper Devantier
@ 2026-11-18 15:01 ` Jesper Devantier
2026-11-18 21:54 ` Klaus Jensen
2026-11-18 15:01 ` [PATCH 4/7] hw/nvme: get fdp events, use helper Jesper Devantier
` (3 subsequent siblings)
6 siblings, 1 reply; 12+ messages in thread
From: Jesper Devantier @ 2026-11-18 15:01 UTC (permalink / raw)
To: qemu-devel, Keith Busch, Klaus Jensen, Jesper Devantier,
qemu-block
Cc: Jesper Wendel Devantier
From: Jesper Wendel Devantier <j.devantier@samsung.com>
Signed-off-by: Jesper Wendel Devantier <j.devantier@samsung.com>
---
hw/nvme/ctrl.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index c8da01f11d0..5d4122309ea 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -385,6 +385,11 @@ static inline bool nvme_parse_pid(NvmeNamespace *ns, uint16_t pid,
return nvme_ph_valid(ns, *ph) && nvme_rg_valid(ns->endgrp, *rg);
}
+static inline bool nvme_fdp_enabled(NvmeCtrl *n)
+{
+ return n->subsys && n->subsys->endgrp.fdp.enabled;
+}
+
static void nvme_assign_zone_state(NvmeNamespace *ns, NvmeZone *zone,
NvmeZoneState state)
{
--
2.51.2
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 3/7] hw/nvme: fdp enabled helper
2026-11-18 15:01 ` [PATCH 3/7] hw/nvme: fdp enabled helper Jesper Devantier
@ 2026-11-18 21:54 ` Klaus Jensen
0 siblings, 0 replies; 12+ messages in thread
From: Klaus Jensen @ 2026-11-18 21:54 UTC (permalink / raw)
To: Jesper Devantier
Cc: qemu-devel, Keith Busch, qemu-block, Jesper Wendel Devantier
[-- Attachment #1: Type: text/plain, Size: 913 bytes --]
On Nov 18 16:01, Jesper Devantier wrote:
> From: Jesper Wendel Devantier <j.devantier@samsung.com>
>
> Signed-off-by: Jesper Wendel Devantier <j.devantier@samsung.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
> ---
> hw/nvme/ctrl.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
> index c8da01f11d0..5d4122309ea 100644
> --- a/hw/nvme/ctrl.c
> +++ b/hw/nvme/ctrl.c
> @@ -385,6 +385,11 @@ static inline bool nvme_parse_pid(NvmeNamespace *ns, uint16_t pid,
> return nvme_ph_valid(ns, *ph) && nvme_rg_valid(ns->endgrp, *rg);
> }
>
> +static inline bool nvme_fdp_enabled(NvmeCtrl *n)
> +{
> + return n->subsys && n->subsys->endgrp.fdp.enabled;
> +}
> +
> static void nvme_assign_zone_state(NvmeNamespace *ns, NvmeZone *zone,
> NvmeZoneState state)
> {
>
> --
> 2.51.2
>
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 4/7] hw/nvme: get fdp events, use helper
2026-11-18 15:01 [PATCH 0/7] hw/nvme get-/set feature fixes (FDP-related) Jesper Devantier
` (2 preceding siblings ...)
2026-11-18 15:01 ` [PATCH 3/7] hw/nvme: fdp enabled helper Jesper Devantier
@ 2026-11-18 15:01 ` Jesper Devantier
2026-11-18 21:55 ` Klaus Jensen
2026-11-18 15:01 ` [PATCH 5/7] hw/nvme: get feature FDP (1Dh) fixes Jesper Devantier
` (2 subsequent siblings)
6 siblings, 1 reply; 12+ messages in thread
From: Jesper Devantier @ 2026-11-18 15:01 UTC (permalink / raw)
To: qemu-devel, Keith Busch, Klaus Jensen, Jesper Devantier,
qemu-block
Cc: Jesper Wendel Devantier
From: Jesper Wendel Devantier <j.devantier@samsung.com>
Signed-off-by: Jesper Wendel Devantier <j.devantier@samsung.com>
---
hw/nvme/ctrl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 5d4122309ea..8fc0884fcda 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -6372,7 +6372,7 @@ static uint16_t nvme_get_feature_fdp_events(NvmeCtrl *n, NvmeNamespace *ns,
NvmeRuHandle *ruh;
NvmeFdpEventDescr *s_event;
- if (!n->subsys || !n->subsys->endgrp.fdp.enabled) {
+ if (!nvme_fdp_enabled(n)) {
return NVME_FDP_DISABLED | NVME_DNR;
}
--
2.51.2
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 4/7] hw/nvme: get fdp events, use helper
2026-11-18 15:01 ` [PATCH 4/7] hw/nvme: get fdp events, use helper Jesper Devantier
@ 2026-11-18 21:55 ` Klaus Jensen
0 siblings, 0 replies; 12+ messages in thread
From: Klaus Jensen @ 2026-11-18 21:55 UTC (permalink / raw)
To: Jesper Devantier
Cc: qemu-devel, Keith Busch, qemu-block, Jesper Wendel Devantier
[-- Attachment #1: Type: text/plain, Size: 809 bytes --]
On Nov 18 16:01, Jesper Devantier wrote:
> From: Jesper Wendel Devantier <j.devantier@samsung.com>
>
> Signed-off-by: Jesper Wendel Devantier <j.devantier@samsung.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
> ---
> hw/nvme/ctrl.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
> index 5d4122309ea..8fc0884fcda 100644
> --- a/hw/nvme/ctrl.c
> +++ b/hw/nvme/ctrl.c
> @@ -6372,7 +6372,7 @@ static uint16_t nvme_get_feature_fdp_events(NvmeCtrl *n, NvmeNamespace *ns,
> NvmeRuHandle *ruh;
> NvmeFdpEventDescr *s_event;
>
> - if (!n->subsys || !n->subsys->endgrp.fdp.enabled) {
> + if (!nvme_fdp_enabled(n)) {
> return NVME_FDP_DISABLED | NVME_DNR;
> }
>
>
> --
> 2.51.2
>
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 5/7] hw/nvme: get feature FDP (1Dh) fixes
2026-11-18 15:01 [PATCH 0/7] hw/nvme get-/set feature fixes (FDP-related) Jesper Devantier
` (3 preceding siblings ...)
2026-11-18 15:01 ` [PATCH 4/7] hw/nvme: get fdp events, use helper Jesper Devantier
@ 2026-11-18 15:01 ` Jesper Devantier
2026-11-18 16:36 ` Klaus Jensen
2026-11-18 15:01 ` [PATCH 6/7] hw/nvme: set feature FDP (1Dh) fix Jesper Devantier
2026-11-18 15:01 ` [PATCH 7/7] hw/nvme: get feature FDP events (1Eh) - return supported events Jesper Devantier
6 siblings, 1 reply; 12+ messages in thread
From: Jesper Devantier @ 2026-11-18 15:01 UTC (permalink / raw)
To: qemu-devel, Keith Busch, Klaus Jensen, Jesper Devantier,
qemu-block
Cc: Jesper Wendel Devantier
From: Jesper Wendel Devantier <j.devantier@samsung.com>
- endurance group is 16 bits, mask appropriately
- support reporting current/default values correctly
- use fdp enabled helper
Signed-off-by: Jesper Wendel Devantier <j.devantier@samsung.com>
---
hw/nvme/ctrl.c | 25 +++++++------------------
1 file changed, 7 insertions(+), 18 deletions(-)
diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 8fc0884fcda..d82ff6793ff 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -6342,16 +6342,17 @@ static uint16_t nvme_get_feature_timestamp(NvmeCtrl *n, NvmeRequest *req)
return nvme_c2h(n, (uint8_t *)×tamp, sizeof(timestamp), req);
}
-static int nvme_get_feature_fdp(NvmeCtrl *n, uint32_t endgrpid,
+static int nvme_get_feature_fdp(NvmeCtrl *n, uint16_t endgrpid,
+ bool current,
uint32_t *result)
{
*result = 0;
- if (!n->subsys || !n->subsys->endgrp.fdp.enabled) {
+ if (!nvme_fdp_enabled(n) || endgrpid != 0x1) {
return NVME_INVALID_FIELD | NVME_DNR;
}
- *result = FIELD_DP16(0, FEAT_FDP, FDPE, 1);
+ *result = FIELD_DP16(0, FEAT_FDP, FDPE, current ? 1 : 0);
*result = FIELD_DP16(*result, FEAT_FDP, CONF_NDX, 0);
return NVME_SUCCESS;
@@ -6428,7 +6429,7 @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeRequest *req)
uint16_t iv;
NvmeNamespace *ns;
int i;
- uint16_t endgrpid = 0, ret = NVME_SUCCESS;
+ uint16_t ret = NVME_SUCCESS;
static const uint32_t nvme_feature_default[NVME_FID_MAX] = {
[NVME_ARBITRATION] = NVME_ARB_AB_NOLIMIT,
@@ -6528,13 +6529,7 @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeRequest *req)
return nvme_c2h(n, (uint8_t *)&n->features.hbs,
sizeof(n->features.hbs), req);
case NVME_FDP_MODE:
- endgrpid = dw11 & 0xff;
-
- if (endgrpid != 0x1) {
- return NVME_INVALID_FIELD | NVME_DNR;
- }
-
- ret = nvme_get_feature_fdp(n, endgrpid, &result);
+ ret = nvme_get_feature_fdp(n, dw11 & 0xffff, true, &result);
if (ret) {
return ret;
}
@@ -6579,13 +6574,7 @@ defaults:
}
break;
case NVME_FDP_MODE:
- endgrpid = dw11 & 0xff;
-
- if (endgrpid != 0x1) {
- return NVME_INVALID_FIELD | NVME_DNR;
- }
-
- ret = nvme_get_feature_fdp(n, endgrpid, &result);
+ ret = nvme_get_feature_fdp(n, dw11 & 0xffff, false, &result);
if (ret) {
return ret;
}
--
2.51.2
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 5/7] hw/nvme: get feature FDP (1Dh) fixes
2026-11-18 15:01 ` [PATCH 5/7] hw/nvme: get feature FDP (1Dh) fixes Jesper Devantier
@ 2026-11-18 16:36 ` Klaus Jensen
0 siblings, 0 replies; 12+ messages in thread
From: Klaus Jensen @ 2026-11-18 16:36 UTC (permalink / raw)
To: Jesper Devantier
Cc: qemu-devel, Keith Busch, qemu-block, Jesper Wendel Devantier
[-- Attachment #1: Type: text/plain, Size: 1109 bytes --]
On Nov 18 16:01, Jesper Devantier wrote:
> From: Jesper Wendel Devantier <j.devantier@samsung.com>
>
> - endurance group is 16 bits, mask appropriately
> - support reporting current/default values correctly
> - use fdp enabled helper
>
> Signed-off-by: Jesper Wendel Devantier <j.devantier@samsung.com>
> ---
> hw/nvme/ctrl.c | 25 +++++++------------------
> 1 file changed, 7 insertions(+), 18 deletions(-)
>
> diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
> index 8fc0884fcda..d82ff6793ff 100644
> --- a/hw/nvme/ctrl.c
> +++ b/hw/nvme/ctrl.c
> @@ -6342,16 +6342,17 @@ static uint16_t nvme_get_feature_timestamp(NvmeCtrl *n, NvmeRequest *req)
> return nvme_c2h(n, (uint8_t *)×tamp, sizeof(timestamp), req);
> }
>
> -static int nvme_get_feature_fdp(NvmeCtrl *n, uint32_t endgrpid,
> +static int nvme_get_feature_fdp(NvmeCtrl *n, uint16_t endgrpid,
> + bool current,
> uint32_t *result)
Minor nit. Since we are changing the function signature here, we should
change that int return value to uint16_t.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 6/7] hw/nvme: set feature FDP (1Dh) fix
2026-11-18 15:01 [PATCH 0/7] hw/nvme get-/set feature fixes (FDP-related) Jesper Devantier
` (4 preceding siblings ...)
2026-11-18 15:01 ` [PATCH 5/7] hw/nvme: get feature FDP (1Dh) fixes Jesper Devantier
@ 2026-11-18 15:01 ` Jesper Devantier
2026-11-18 15:01 ` [PATCH 7/7] hw/nvme: get feature FDP events (1Eh) - return supported events Jesper Devantier
6 siblings, 0 replies; 12+ messages in thread
From: Jesper Devantier @ 2026-11-18 15:01 UTC (permalink / raw)
To: qemu-devel, Keith Busch, Klaus Jensen, Jesper Devantier,
qemu-block
Cc: Jesper Wendel Devantier
From: Jesper Wendel Devantier <j.devantier@samsung.com>
Shall only return command sequence error if the set feature command
attempts to change the current configuration AND the endurance group
has namespaces, still.
Additionally, check that the FDP configuration index and endurance
group IDs are correct as well.
Finally, if FDP is not enabled, thus not supported, return invalid
field (invalid feature).
Signed-off-by: Jesper Wendel Devantier <j.devantier@samsung.com>
---
hw/nvme/ctrl.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index d82ff6793ff..95affb25c18 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -6877,8 +6877,25 @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeRequest *req)
}
break;
case NVME_FDP_MODE:
- /* spec: abort with cmd seq err if there's one or more NS' in endgrp */
- return NVME_CMD_SEQ_ERROR | NVME_DNR;
+ {
+ uint32_t dw12 = le32_to_cpu(cmd->cdw12);
+ bool fdpe = (bool) FIELD_EX32(dw12, FEAT_FDP, FDPE);
+ uint8_t cidx = (uint8_t) FIELD_EX32(dw12, FEAT_FDP, CONF_NDX);
+ uint16_t endgrpid = dw11 & 0xffff;
+
+ if (!nvme_fdp_enabled(n) || cidx != 0 || endgrpid != 0x1) {
+ return NVME_INVALID_FIELD | NVME_DNR;
+ } else if (fdpe != 1) {
+ /*
+ * if call attempts to toggle FDP or change configuration while
+ * endurance group has one or more namespaces exist, return
+ * command sequence error (2.4 Base, 8.1.12.1)
+ */
+ return NVME_CMD_SEQ_ERROR | NVME_DNR;
+ } else {
+ return NVME_SUCCESS;
+ }
+ }
case NVME_FDP_EVENTS:
return nvme_set_feature_fdp_events(n, ns, req);
case NVME_WRITE_ATOMICITY:
--
2.51.2
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 7/7] hw/nvme: get feature FDP events (1Eh) - return supported events
2026-11-18 15:01 [PATCH 0/7] hw/nvme get-/set feature fixes (FDP-related) Jesper Devantier
` (5 preceding siblings ...)
2026-11-18 15:01 ` [PATCH 6/7] hw/nvme: set feature FDP (1Dh) fix Jesper Devantier
@ 2026-11-18 15:01 ` Jesper Devantier
6 siblings, 0 replies; 12+ messages in thread
From: Jesper Devantier @ 2026-11-18 15:01 UTC (permalink / raw)
To: qemu-devel, Keith Busch, Klaus Jensen, Jesper Devantier,
qemu-block
Cc: Jesper Wendel Devantier
From: Jesper Wendel Devantier <j.devantier@samsung.com>
- support reading saved (default) values
- rewrite, command should ignore dw11.NOET (and dw12.FDPE).
Instead, must return a list with one descriptor per supported
FDP event type.
Signed-off-by: Jesper Wendel Devantier <j.devantier@samsung.com>
---
hw/nvme/ctrl.c | 52 ++++++++++++++++++++++++----------------------------
1 file changed, 24 insertions(+), 28 deletions(-)
diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 95affb25c18..04a43867dcd 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -6359,19 +6359,16 @@ static int nvme_get_feature_fdp(NvmeCtrl *n, uint16_t endgrpid,
}
static uint16_t nvme_get_feature_fdp_events(NvmeCtrl *n, NvmeNamespace *ns,
- NvmeRequest *req, uint32_t *result)
+ NvmeRequest *req, bool current,
+ uint32_t *result)
{
+ NvmeFdpEventDescr evds[FDP_EVT_MAX + 1] = {0};
NvmeCmd *cmd = &req->cmd;
+ NvmeRuHandle *ruh;
uint32_t cdw11 = le32_to_cpu(cmd->cdw11);
uint16_t ph = cdw11 & 0xffff;
- uint8_t noet = (cdw11 >> 16) & 0xff;
uint16_t ruhid, ret;
- uint32_t nentries = 0;
- uint8_t s_events_ndx = 0;
- size_t s_events_siz = sizeof(NvmeFdpEventDescr) * noet;
- g_autofree NvmeFdpEventDescr *s_events = g_malloc0(s_events_siz);
- NvmeRuHandle *ruh;
- NvmeFdpEventDescr *s_event;
+ uint8_t noet = 0;
if (!nvme_fdp_enabled(n)) {
return NVME_FDP_DISABLED | NVME_DNR;
@@ -6386,34 +6383,27 @@ static uint16_t nvme_get_feature_fdp_events(NvmeCtrl *n, NvmeNamespace *ns,
assert(ruh);
- if (unlikely(noet == 0)) {
- return NVME_INVALID_FIELD | NVME_DNR;
- }
+ /* Saved selectors fall back to the default because nothing is saved. */
+ uint64_t event_filter = current ? ruh->event_filter : 0;
- for (uint8_t event_type = 0; event_type < FDP_EVT_MAX; event_type++) {
- uint8_t shift = nvme_fdp_evf_shifts[event_type];
- if (!shift && event_type) {
+ for (uint8_t evt = 0; evt < FDP_EVT_MAX; evt++) {
+ uint8_t shift = nvme_fdp_evf_shifts[evt];
+ if (!shift && evt) {
continue;
}
-
- nentries++;
-
- s_event = &s_events[s_events_ndx];
- s_event->evt = event_type;
- s_event->evta = (ruh->event_filter >> shift) & 0x1;
-
- /* break if all `noet` entries are filled */
- if ((++s_events_ndx) == noet) {
- break;
- }
+ evds[noet] = (NvmeFdpEventDescr){
+ .evt = evt,
+ .evta = (event_filter >> shift) & 0x1,
+ };
+ noet++;
}
- ret = nvme_c2h(n, s_events, s_events_siz, req);
+ ret = nvme_c2h(n, &evds, noet * sizeof(evds[0]), req);
if (ret) {
return ret;
}
- *result = nentries;
+ *result = noet;
return NVME_SUCCESS;
}
@@ -6535,7 +6525,7 @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeRequest *req)
}
goto out;
case NVME_FDP_EVENTS:
- ret = nvme_get_feature_fdp_events(n, ns, req, &result);
+ ret = nvme_get_feature_fdp_events(n, ns, req, true, &result);
if (ret) {
return ret;
}
@@ -6579,6 +6569,12 @@ defaults:
return ret;
}
break;
+ case NVME_FDP_EVENTS:
+ ret = nvme_get_feature_fdp_events(n, ns, req, false, &result);
+ if (ret) {
+ return ret;
+ }
+ break;
case NVME_WRITE_ATOMICITY:
result = n->dn;
--
2.51.2
^ permalink raw reply related [flat|nested] 12+ messages in thread