Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 22 Jul 2024 21:06:46 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 43d45f26413a - main - nvmf_tcp: Don't require a data digest for PDUs without data
Message-ID:  <202407222106.46ML6kJl063106@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=43d45f26413aa98e41994d0d0f06c49c7eca430e

commit 43d45f26413aa98e41994d0d0f06c49c7eca430e
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2024-07-22 19:38:12 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-07-22 21:05:55 +0000

    nvmf_tcp: Don't require a data digest for PDUs without data
    
    If a PDU (such as a Command Capsule PDU) on a connection that has
    enabled data digests does not have a data section, it will not have
    the the PDU data digest flag set.  The previous check was requiring
    this flag to be present on all PDU types that support data sections
    even if no data was included in the PDU.
    
    Sponsored by:   Chelsio Communications
---
 sys/dev/nvmf/nvmf_tcp.h | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/sys/dev/nvmf/nvmf_tcp.h b/sys/dev/nvmf/nvmf_tcp.h
index 78d6cf17a977..c60be0bc1024 100644
--- a/sys/dev/nvmf/nvmf_tcp.h
+++ b/sys/dev/nvmf/nvmf_tcp.h
@@ -41,6 +41,13 @@ nvmf_tcp_validate_pdu_header(const struct nvme_tcp_common_pdu_hdr *ch,
 	uint8_t digest_flags, valid_flags;
 
 	plen = le32toh(ch->plen);
+	full_hlen = ch->hlen;
+	if ((ch->flags & NVME_TCP_CH_FLAGS_HDGSTF) != 0)
+		full_hlen += sizeof(uint32_t);
+	if (plen == full_hlen)
+		data_len = 0;
+	else
+		data_len = plen - ch->pdo;
 
 	/*
 	 * Errors must be reported for the lowest incorrect field
@@ -125,11 +132,15 @@ nvmf_tcp_validate_pdu_header(const struct nvme_tcp_common_pdu_hdr *ch,
 		return (EBADMSG);
 	}
 
-	/* Verify that digests are present iff enabled. */
+	/*
+	 * Verify that digests are present iff enabled.  Note that the
+	 * data digest will not be present if there is no data
+	 * payload.
+	 */
 	digest_flags = 0;
 	if (header_digests)
 		digest_flags |= NVME_TCP_CH_FLAGS_HDGSTF;
-	if (data_digests)
+	if (data_digests && data_len != 0)
 		digest_flags |= NVME_TCP_CH_FLAGS_DDGSTF;
 	if ((digest_flags & valid_flags) !=
 	    (ch->flags & (NVME_TCP_CH_FLAGS_HDGSTF |
@@ -184,9 +195,6 @@ nvmf_tcp_validate_pdu_header(const struct nvme_tcp_common_pdu_hdr *ch,
 	}
 
 	/* Validate pdo. */
-	full_hlen = ch->hlen;
-	if ((ch->flags & NVME_TCP_CH_FLAGS_HDGSTF) != 0)
-		full_hlen += sizeof(uint32_t);
 	switch (ch->pdu_type) {
 	default:
 		__assert_unreachable();
@@ -207,7 +215,7 @@ nvmf_tcp_validate_pdu_header(const struct nvme_tcp_common_pdu_hdr *ch,
 	case NVME_TCP_PDU_TYPE_H2C_DATA:
 	case NVME_TCP_PDU_TYPE_C2H_DATA:
 		/* Permit PDO of 0 if there is no data. */
-		if (full_hlen == plen && ch->pdo == 0)
+		if (data_len == 0 && ch->pdo == 0)
 			break;
 
 		if (ch->pdo < full_hlen || ch->pdo > plen ||
@@ -229,10 +237,6 @@ nvmf_tcp_validate_pdu_header(const struct nvme_tcp_common_pdu_hdr *ch,
 		return (EBADMSG);
 	}
 
-	if (plen == full_hlen)
-		data_len = 0;
-	else
-		data_len = plen - ch->pdo;
 	switch (ch->pdu_type) {
 	default:
 		__assert_unreachable();



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202407222106.46ML6kJl063106>