Skip to contentSkip to conversation

nvmet: fix FID 82h status codes for invalid NSIDs

PATCH Superseded Guixin Liu 2 participants 6 messages Sep 18 – Sep 20

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Guixin Liu

author
#0 lore raw

cover nvmet: fix FID 82h status codes for invalid NSIDs

The Reservation Notification Mask feature (FID 82h) defines its own status code for NSIDs that do not name a namespace supporting reservations:

"A Get Features command that uses a namespace ID of FFFFFFFFh shall be aborted with status code of Invalid Field in Command. [...] If a Set Features command or a Get Features command attempts to access the Reservation Notification Mask on a namespace that does not support reservations or is invalid, then that command is aborted with status code of Invalid Field in Command."

-- NVMe Base Specification, section 5.2.26.1.33

nvmet routes the namespace lookup of both handlers through nvmet_req_find_ns(), which returns Invalid Namespace or Format for an unknown NSID. That is the correct status for the generic namespace-scoped admin commands, but not for this feature. A Set Features 82h naming a nonexistent NSID, a Get Features 82h naming a nonexistent NSID, and a Get Features 82h using the broadcast NSID are all aborted with Invalid Namespace or Format instead of Invalid Field in Command.

Each patch fixes one handler and translates the lookup failure to Invalid Field in Command. The Set Features broadcast, the namespace-without-reservations case, the disabled namespace path (Internal Path Error, commit 505363957fad ("nvmet: fix nvme status code when namespace is disabled")) and everything else keep their current behavior.

Verified with two hosts (distinct host identifiers) connected over NVMe/TCP to an nvmet subsystem exporting two reservation-enabled null_blk namespaces: all three rejected cases now return 0x6002, while Set/Get Features on an active namespace, the Set Features broadcast and the reservation commands behave as before, with no splat in dmesg.

Guixin Liu (2):
nvmet: return Invalid Field for invalid NSIDs in Set Features 82h
nvmet: return Invalid Field for invalid NSIDs in Get Features 82h

 drivers/nvme/target/pr.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.7
author
#1 lore raw

PATCH 1/2 nvmet: return Invalid Field for invalid NSIDs in Set Features 82h

The Reservation Notification Mask feature (FID 82h) defines its own status code for namespaces that do not support reservations:

"If a Set Features command or a Get Features command attempts to access the Reservation Notification Mask on a namespace that does not support reservations or is invalid, then that command is aborted with status code of Invalid Field in Command."

-- NVMe Base Specification, section 5.2.26.1.33

The Set Features handler routes the namespace lookup through nvmet_req_find_ns(), which returns Invalid Namespace or Format for an unknown NSID. That is the correct status for the generic namespace-scoped admin commands, but not for this feature: a Set Features 82h naming a nonexistent NSID is aborted with Invalid Namespace or Format instead of Invalid Field in Command.

Translate the lookup failure to Invalid Field in Command. The broadcast NSID, the namespace-without-reservations case and everything else keep their current behavior.

Fixes 5a47c2080a73 ("nvmet: support reservation feature")
---
 drivers/nvme/target/pr.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/nvme/target/pr.c +5 -1
index 0948a690a1c0..927e3c44952b 100644
@@ -51,8 +51,12 @@ u16 nvmet_set_feat_resv_notif_mask(struct nvmet_req *req, u32 mask)
 
 	if (nsid != U32_MAX) {
 		status = nvmet_req_find_ns(req);
-		if (status)
+		if (status) {
+			/* 82h is Invalid Field for invalid NSIDs, not Invalid NS */
+			if (status == (NVME_SC_INVALID_NS | NVME_STATUS_DNR))
+				status = NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;
 			return status;
+		}
 		if (!req->ns->pr.enable)
 			return NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;
 
Signature · 1 line
2.43.7
#2 lore raw

Re: [PATCH 1/2] nvmet: return Invalid Field for invalid NSIDs in Set Features 82h

drivers/nvme/target/pr.c u16 nvmet_set_feat_resv_notif_mask(struct nvmet_req *req, u32 mask) · line 55

Quoted 3 lines · Guixin Liu
drivers/nvme/target/pr.c +2 -1
-		if (status)
+		if (status) {
+			/* 82h is Invalid Field for invalid NSIDs, not Invalid NS */

Overly long line, but I don't this comment is very helpful as-is anyway. For one mentioning the value while the code uses symbolic names is confusing, but otherwise it also doesn't really say why we care. IMHO we can just drop it?

drivers/nvme/target/pr.c u16 nvmet_set_feat_resv_notif_mask(struct nvmet_req *req, u32 mask) · line 56

Quoted 1 line
drivers/nvme/target/pr.c +1 -0
+			if (status == (NVME_SC_INVALID_NS | NVME_STATUS_DNR))

no need for the braces.

drivers/nvme/target/pr.c u16 nvmet_set_feat_resv_notif_mask(struct nvmet_req *req, u32 mask) · line 57

Quoted 1 line
drivers/nvme/target/pr.c +1 -0
+				status = NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;

Another overly long line. Easily fixed by just directly returning:

				return NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;
author
#3 lore raw

Re: [PATCH 1/2] nvmet: return Invalid Field for invalid NSIDs in Set Features 82h

Quoted 8 lines · Christoph Hellwig

drivers/nvme/target/pr.c u16 nvmet_set_feat_resv_notif_mask(struct nvmet_req *req, u32 mask) · line 55

Quoted 3 lines · Guixin Liu
drivers/nvme/target/pr.c +2 -1
-		if (status)
+		if (status) {
+			/* 82h is Invalid Field for invalid NSIDs, not Invalid NS */

Overly long line, but I don't this comment is very helpful as-is anyway. For one mentioning the value while the code uses symbolic names is confusing, but otherwise it also doesn't really say why we care. IMHO we can just drop it?

Yeah, sure, removed in v2.

Quoted 3 lines

drivers/nvme/target/pr.c u16 nvmet_set_feat_resv_notif_mask(struct nvmet_req *req, u32 mask) · line 56

Quoted 2 lines
drivers/nvme/target/pr.c +1 -0
+			if (status == (NVME_SC_INVALID_NS | NVME_STATUS_DNR))

no need for the braces.

Sure.

Quoted 5 lines

drivers/nvme/target/pr.c u16 nvmet_set_feat_resv_notif_mask(struct nvmet_req *req, u32 mask) · line 57

Quoted 2 lines
drivers/nvme/target/pr.c +1 -0
+				status = NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;

Another overly long line. Easily fixed by just directly returning:

				return NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;

Changed in v2, and also in patch2, thanks.

Best Regards,
Guixin Liu

author
#4 lore raw

PATCH 2/2 nvmet: return Invalid Field for invalid NSIDs in Get Features 82h

In reply to Guixin Liu

The Reservation Notification Mask feature (FID 82h) rejects the same NSIDs for Get Features as for Set Features, plus the broadcast NSID:

"A Get Features command that uses a namespace ID of FFFFFFFFh shall be aborted with status code of Invalid Field in Command. If a Set Features command or a Get Features command attempts to access the Reservation Notification Mask on a namespace that does not support reservations or is invalid, then that command is aborted with status code of Invalid Field in Command."

-- NVMe Base Specification, section 5.2.26.1.33

The Get Features handler routes the namespace lookup through nvmet_req_find_ns(), which returns Invalid Namespace or Format for an unknown NSID. Both rejected cases land there: a nonexistent NSID fails the lookup, and so does the broadcast NSID, which never names a namespace. Both are aborted with Invalid Namespace or Format instead of Invalid Field in Command.

Translate the lookup failure to Invalid Field in Command, as was done for Set Features.

Fixes 5a47c2080a73 ("nvmet: support reservation feature")
---
 drivers/nvme/target/pr.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/nvme/target/pr.c +5 -1
index 927e3c44952b..8762ef64aa46 100644
@@ -79,8 +79,12 @@ u16 nvmet_get_feat_resv_notif_mask(struct nvmet_req *req)
 	u16 status;
 
 	status = nvmet_req_find_ns(req);
-	if (status)
+	if (status) {
+		/* 82h is Invalid Field for invalid and broadcast NSIDs */
+		if (status == (NVME_SC_INVALID_NS | NVME_STATUS_DNR))
+			status = NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;
 		return status;
+	}
 
 	if (!req->ns->pr.enable)
 		return NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;
Signature · 1 line
2.43.7
#5 lore raw

Re: [PATCH 2/2] nvmet: return Invalid Field for invalid NSIDs in Get Features 82h

Quoted 33 lines · Guixin Liu

The Reservation Notification Mask feature (FID 82h) rejects the same NSIDs for Get Features as for Set Features, plus the broadcast NSID:

"A Get Features command that uses a namespace ID of FFFFFFFFh shall be aborted with status code of Invalid Field in Command. If a Set Features command or a Get Features command attempts to access the Reservation Notification Mask on a namespace that does not support reservations or is invalid, then that command is aborted with status code of Invalid Field in Command."

-- NVMe Base Specification, section 5.2.26.1.33

The Get Features handler routes the namespace lookup through nvmet_req_find_ns(), which returns Invalid Namespace or Format for an unknown NSID. Both rejected cases land there: a nonexistent NSID fails the lookup, and so does the broadcast NSID, which never names a namespace. Both are aborted with Invalid Namespace or Format instead of Invalid Field in Command.

Translate the lookup failure to Invalid Field in Command, as was done for Set Features.

Fixes 5a47c2080a73 ("nvmet: support reservation feature")
---
 drivers/nvme/target/pr.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/nvme/target/pr.c +0 -0
index 927e3c44952b..8762ef64aa46 100644

drivers/nvme/target/pr.c u16 nvmet_get_feat_resv_notif_mask(struct nvmet_req *req) · line 87

Quoted 10 lines
drivers/nvme/target/pr.c +5 -1
@@ -79,8 +79,12 @@ u16 nvmet_get_feat_resv_notif_mask(struct nvmet_req *req)
 	u16 status;
 
 	status = nvmet_req_find_ns(req);
-	if (status)
+	if (status) {
+		/* 82h is Invalid Field for invalid and broadcast NSIDs */
+		if (status == (NVME_SC_INVALID_NS | NVME_STATUS_DNR))
+			status = NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;
 		return status;
+	}

Same thing about the comment, and I guess a direct return would also make this a tiny bit more readable.