nvme-tcp: add IPv6 traffic class support
Subsystems (5)
Geliang Tang
reviewerv3 cover nvme-tcp: add IPv6 traffic class support
From: Geliang Tang <[email protected]>
This series adds IPv6 traffic class (tclass) support to the NVMe/TCP fabrics stack, mirroring the existing IPv4 TOS configuration.
The current code path only handles IPv4: nvme-fabrics exposes a 'tos' option, the host (nvme-tcp) applies IP_TOS to each queue socket, and the target (nvmet-tcp) reflects the value received on the wire. This leaves no way to control or observe the IPv6 traffic class for NVMe/TCP connections, which is a real gap for deployments running over IPv6 that need a non-default tclass.
The series also refactors the socket option configuration on both host and target sides to use the generic do_sock_setsockopt() helper. This change eliminates the need for protocol-specific helpers and decouples the configuration from the underlying transport protocol, laying the groundwork for future protocol extensions such as MPTCP.
The series is split into two logical parts: the do_sock_setsockopt refactoring (patches 1-2) and the IPv6 traffic class support (patches 3-4), following the natural host/target layering.
This was tested with the selftests mptcp_nvme.sh [1] to pass "--tos" on the host side and validate that the value is reflected on the wire by the target.
[1]
https://patchwork.kernel.org/project/linux-nvme/cover/[email protected]/
v3:
- add two patches to unify socket option configuration using do_sock_setsockopt on both host and target sides.
- use do_sock_setsockopt for IPV6_TCLASS rather than exporting and calling ip6_sock_set_tclass, as suggested by Jakub.
- reuse the existing NVMF_OPT_TOS for IPv6 sockets instead of adding a new NVMF_OPT_TCLASS option, as suggested by Stanislav.
v2:
- Export and use the ip6_sock_set_tclass() helper in both target and host
paths, aligning with the existing ip_sock_set_tos() usage.
- Add CONFIG_IPV6 and AF_INET6 guards to avoid build failures when IPv6
is disabled.
- Use rcv_flowinfo from the target socket instead of np->tclass.
- https://patchwork.kernel.org/project/linux-nvme/cover/[email protected]/
v1:
- https://patchwork.kernel.org/project/linux-nvme/cover/[email protected]/
Geliang Tang (4):
nvmet-tcp: unify sockopt with do_sock_setsockopt
nvme-tcp: unify sockopt with do_sock_setsockopt
nvmet-tcp: support IPv6 traffic class
nvme-tcp: support IPv6 traffic class
drivers/nvme/host/tcp.c | 68 +++++++++++++++++++++++++++++++++------ drivers/nvme/target/tcp.c | 68 ++++++++++++++++++++++++++++++++++----- 2 files changed, 119 insertions(+), 17 deletions(-)
Signature · 1 line
2.53.0
Geliang Tang
reviewerPATCH v3 1/4 nvmet-tcp: unify sockopt with do_sock_setsockopt
From: Geliang Tang <[email protected]>
This patch consolidates socket option settings in nvmet-tcp by utilizing the generic do_sock_setsockopt() helper for options including SO_LINGER, SO_PRIORITY, SO_REUSEADDR, TCP_NODELAY, and IP_TOS. This change eliminates the need to export and use specialized helpers for each individual socket option.
A key benefit of this refactoring is that it decouples the socket option configuration from the underlying transport protocol. This makes it easier to extend nvmet-tcp to support other protocols, such as MPTCP, in the future, as do_sock_setsockopt() abstracts away protocol-specific differences without requiring per-option protocol-specific wrappers.
--- drivers/nvme/target/tcp.c | 53 +++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 8 deletions(-)
drivers/nvme/target/tcp.c +45 -8
@@ -1696,10 +1696,48 @@ static void nvmet_tcp_state_change(struct sock *sk)read_unlock_bh (&sk->sk_callback_lock); } +static void nvmet_tcp_sock_no_linger (struct sock *sk) +{ +struct linger ling = { .l_onoff =1 , .l_linger =0 }; + +do_sock_setsockopt (sk->sk_socket, false,SOL_SOCKET ,SO_LINGER , +KERNEL_SOCKPTR (&ling),sizeof (ling)); +} + +static void nvmet_tcp_sock_set_priority (struct sock *sk,u32 priority) +{ +do_sock_setsockopt (sk->sk_socket, false,SOL_SOCKET ,SO_PRIORITY , +KERNEL_SOCKPTR (&priority),sizeof (priority)); +} + +static void nvmet_tcp_sock_set_reuseaddr (struct sock *sk) +{ +int val =SK_CAN_REUSE ; + +do_sock_setsockopt (sk->sk_socket, false,SOL_SOCKET ,SO_REUSEADDR , +KERNEL_SOCKPTR (&val),sizeof (val)); +} + +static void nvmet_tcp_sock_set_nodelay (struct sock *sk) +{ +int val =1 ; + +do_sock_setsockopt (sk->sk_socket, false,SOL_TCP ,TCP_NODELAY , +KERNEL_SOCKPTR (&val),sizeof (val)); +} + +static void nvmet_tcp_sock_set_tos (struct sock *sk) +{ +u8 tos =inet_sk (sk)->rcv_tos; + +if (tos >0 ) +do_sock_setsockopt (sk->sk_socket, false,SOL_IP ,IP_TOS , +KERNEL_SOCKPTR (&tos),sizeof (tos)); +} +static int nvmet_tcp_set_queue_sock (struct nvmet_tcp_queue *queue) {struct socket *sock = queue->sock; -struct inet_sock *inet =inet_sk (sock->sk);int ret; ret = kernel_getsockname(sock,
@@ -1717,14 +1755,13 @@ static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_queue *queue)* close. This is done to prevent stale data from being sent should * the network connection be restored before TCP times out. */ -sock_no_linger (sock->sk); +nvmet_tcp_sock_no_linger (sock->sk);if (so_priority >0 ) -sock_set_priority (sock->sk, so_priority); +nvmet_tcp_sock_set_priority (sock->sk, so_priority);/* Set socket type of service */ -if (inet->rcv_tos >0 ) -ip_sock_set_tos (sock->sk, inet->rcv_tos); +nvmet_tcp_sock_set_tos (sock->sk); ret =0 ;write_lock_bh (&sock->sk->sk_callback_lock);
@@ -2098,10 +2135,10 @@ static int nvmet_tcp_add_port(struct nvmet_port *nport) port->sock->sk->sk_user_data = port; port->data_ready = port->sock->sk->sk_data_ready; port->sock->sk->sk_data_ready = nvmet_tcp_listen_data_ready; -sock_set_reuseaddr (port->sock->sk); -tcp_sock_set_nodelay (port->sock->sk); +nvmet_tcp_sock_set_reuseaddr (port->sock->sk); +nvmet_tcp_sock_set_nodelay (port->sock->sk);if (so_priority >0 ) -sock_set_priority (port->sock->sk, so_priority); +nvmet_tcp_sock_set_priority (port->sock->sk, so_priority); ret =kernel_bind (port->sock, (struct sockaddr_unsized *)&port->addr,sizeof (port->addr));
Signature · 1 line
2.53.0
Re: [PATCH v3 1/4] nvmet-tcp: unify sockopt with do_sock_setsockopt
Quoted 14 lines · Geliang Tang
From: Geliang Tang <[email protected]>
This patch consolidates socket option settings in nvmet-tcp by utilizing the generic
do_sock_setsockopt()helper for options includingSO_LINGER,SO_PRIORITY,SO_REUSEADDR,TCP_NODELAY, andIP_TOS. This change eliminates the need to export and use specialized helpers for each individual socket option.A key benefit of this refactoring is that it decouples the socket option configuration from the underlying transport protocol. This makes it easier to extend nvmet-tcp to support other protocols, such as MPTCP, in the future, as
do_sock_setsockopt()abstracts away protocol-specific differences without requiring per-option protocol-specific wrappers.
Quoted 5 lines
Signed-off-by Geliang Tang <[email protected]>--- drivers/nvme/target/tcp.c | 53 +++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 8 deletions(-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Geliang Tang
reviewerPATCH v3 2/4 nvme-tcp: unify sockopt with do_sock_setsockopt
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch consolidates socket option settings in nvme-tcp by utilizing the generic do_sock_setsockopt() helper for options including SO_LINGER, SO_PRIORITY, TCP_NODELAY, IP_TOS, SO_BINDTODEVICE, and TCP_SYNCNT.
Compared to the target-side implementation, this patch additionally converts SO_BINDTODEVICE and TCP_SYNCNT to use the same unified mechanism. This change eliminates the need to export and use specialized helpers for each individual socket option.
--- drivers/nvme/host/tcp.c | 55 +++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 8 deletions(-)
drivers/nvme/host/tcp.c +47 -8
@@ -1774,6 +1774,47 @@ static int nvme_tcp_start_tls(struct nvme_ctrl *nctrl,return ret; } +static void nvme_tcp_sock_no_linger (struct sock *sk) +{ +struct linger ling = { .l_onoff =1 , .l_linger =0 }; + +do_sock_setsockopt (sk->sk_socket, false,SOL_SOCKET ,SO_LINGER , +KERNEL_SOCKPTR (&ling),sizeof (ling)); +} + +static void nvme_tcp_sock_set_priority (struct sock *sk,u32 priority) +{ +do_sock_setsockopt (sk->sk_socket, false,SOL_SOCKET ,SO_PRIORITY , +KERNEL_SOCKPTR (&priority),sizeof (priority)); +} + +static int nvme_tcp_sock_set_bindtodevice (struct sock *sk,char *iface) +{ +return do_sock_setsockopt (sk->sk_socket, false,SOL_SOCKET , +SO_BINDTODEVICE ,KERNEL_SOCKPTR (iface), +strlen (iface)); +} + +static void nvme_tcp_sock_set_nodelay (struct sock *sk) +{ +int val =1 ; + +do_sock_setsockopt (sk->sk_socket, false,SOL_TCP ,TCP_NODELAY , +KERNEL_SOCKPTR (&val),sizeof (val)); +} + +static int nvme_tcp_sock_set_syncnt (struct sock *sk,int val) +{ +return do_sock_setsockopt (sk->sk_socket, false,SOL_TCP ,TCP_SYNCNT , +KERNEL_SOCKPTR (&val),sizeof (val)); +} + +static void nvme_tcp_sock_set_tos (struct sock *sk,int tos) +{ +do_sock_setsockopt (sk->sk_socket, false,SOL_IP ,IP_TOS , +KERNEL_SOCKPTR (&tos),sizeof (tos)); +} +static int nvme_tcp_alloc_queue (struct nvme_ctrl *nctrl,int qid,key_serial_t pskid) {
@@ -1819,24 +1860,24 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,#endif /* Single syn retry */ -tcp_sock_set_syncnt (queue->sock->sk,1 ); +nvme_tcp_sock_set_syncnt (queue->sock->sk,1 );/* Set TCP no delay */ -tcp_sock_set_nodelay (queue->sock->sk); +nvme_tcp_sock_set_nodelay (queue->sock->sk);/* * Cleanup whatever is sitting in the TCP transmit queue on socket * close. This is done to prevent stale data from being sent should * the network connection be restored before TCP times out. */ -sock_no_linger (queue->sock->sk); +nvme_tcp_sock_no_linger (queue->sock->sk);if (so_priority >0 ) -sock_set_priority (queue->sock->sk, so_priority); +nvme_tcp_sock_set_priority (queue->sock->sk, so_priority);/* Set socket type of service */ if (nctrl->opts->tos >=0 ) -ip_sock_set_tos (queue->sock->sk, nctrl->opts->tos); +nvme_tcp_sock_set_tos (queue->sock->sk, nctrl->opts->tos);/* Set 10 seconds timeout for icresp recvmsg */ queue->sock->sk->sk_rcvtimeo =10 *HZ ;
@@ -1864,10 +1905,8 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,if (nctrl->opts->mask &NVMF_OPT_HOST_IFACE ) {char *iface = nctrl->opts->host_iface; -sockptr_t optval =KERNEL_SOCKPTR (iface); - ret =sock_setsockopt (queue->sock,SOL_SOCKET ,SO_BINDTODEVICE , - optval,strlen (iface)); + ret =nvme_tcp_sock_set_bindtodevice (queue->sock->sk, iface);if (ret) { dev_err(nctrl->device, "failed to bind to interface %s queue %d err %d\n",
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 2/4] nvme-tcp: unify sockopt with do_sock_setsockopt
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Routing internal kernel socket configuration through user-facing do_sock_setsockopt() ignores…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Routing internal kernel socket configuration through user-facing do_sock_setsockopt() ignores return values and subjects critical NVMe settings to userspace BPF hooks. --
--- Patch [2]: [PATCH v3 2/4] nvme-tcp: unify sockopt with do_sock_setsockopt --- commit 2f6cd2b103bf52f5964e62f02552a246d7faa461
Author: Geliang Tang <[email protected]>
nvme-tcp: unify sockopt with do_sock_setsockopt
This patch consolidates socket option settings in nvme-tcp by utilizing the generic do_sock_setsockopt() helper. It converts several direct socket configuration calls to this unified mechanism.
Quoted 5 lines
drivers/nvme/host/tcp.c +0
-0
drivers/nvme/host/tcp.c static int nvme_tcp_start_tls(struct nvme_ctrl *nctrl, · line 1783
Quoted 10 lines
drivers/nvme/host/tcp.c +7
-0@@ -1774,6 +1774,47 @@ static int nvme_tcp_start_tls(struct nvme_ctrl *nctrl,return ret; } +static void nvme_tcp_sock_no_linger (struct sock *sk) +{ +struct linger ling = { .l_onoff =1 , .l_linger =0 }; + +do_sock_setsockopt (sk->sk_socket, false,SOL_SOCKET ,SO_LINGER , +KERNEL_SOCKPTR (&ling),sizeof (ling)); +}
[Severity: High]
Does routing internal socket configuration through do_sock_setsockopt() expose these settings to userspace BPF hooks and LSMs?
Since the kernel socket inherits the calling process's cgroup, a BPF_CGROUP_SETSOCKOPT hook or LSM rule could intercept and deny the operation. Because the return value is ignored here, would this silently fail to apply SO_LINGER?
[ ... ]
drivers/nvme/host/tcp.c static int nvme_tcp_start_tls(struct nvme_ctrl *nctrl, · line 1804
Quoted 7 lines
drivers/nvme/host/tcp.c +7
-0+static void nvme_tcp_sock_set_nodelay (struct sock *sk) +{ +int val =1 ; + +do_sock_setsockopt (sk->sk_socket, false,SOL_TCP ,TCP_NODELAY , +KERNEL_SOCKPTR (&val),sizeof (val)); +}
[Severity: High]
If do_sock_setsockopt() is intercepted or fails, this also ignores the return value. Could this leave Nagle's algorithm enabled on a storage protocol, leading to severe performance regressions?
[ ... ]
drivers/nvme/host/tcp.c static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid, · line 1866
Quoted 10 lines
drivers/nvme/host/tcp.c +2
-2@@ -1819,24 +1860,24 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,#endif /* Single syn retry */ -tcp_sock_set_syncnt (queue->sock->sk,1 ); +nvme_tcp_sock_set_syncnt (queue->sock->sk,1 );/* Set TCP no delay */ -tcp_sock_set_nodelay (queue->sock->sk); +nvme_tcp_sock_set_nodelay (queue->sock->sk);
[Severity: High]
Executing these wrappers in sequence without checking for errors means that failures are silently ignored. Can this result in an incorrectly configured socket being used for NVMe over TCP connections?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v3 2/4] nvme-tcp: unify sockopt with do_sock_setsockopt
In reply to Geliang TangQuoted 11 lines · Geliang Tang
From: Geliang Tang <[email protected]>
This patch consolidates socket option settings in nvme-tcp by utilizing the generic
do_sock_setsockopt()helper for options includingSO_LINGER,SO_PRIORITY,TCP_NODELAY,IP_TOS,SO_BINDTODEVICE, andTCP_SYNCNT.Compared to the target-side implementation, this patch additionally converts
SO_BINDTODEVICEandTCP_SYNCNTto use the same unified mechanism. This change eliminates the need to export and use specialized helpers for each individual socket option.
Quoted 5 lines
Signed-off-by Geliang Tang <[email protected]>--- drivers/nvme/host/tcp.c | 55 +++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 8 deletions(-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Geliang Tang
reviewerPATCH v3 3/4 nvmet-tcp: support IPv6 traffic class
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
Currently, nvmet-tcp only applies the received IPv4 TOS value when setting up a queue socket, but does not handle the IPv6 traffic class.
Extend the queue socket setup to handle AF_INET6 sockets. Obtain the traffic class from the IPv6 socket's rcv_flowinfo and apply it through IPV6_TCLASS using do_sock_setsockopt().
--- drivers/nvme/target/tcp.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/nvme/target/tcp.c +15 -0
@@ -1735,6 +1735,20 @@ static void nvmet_tcp_sock_set_tos(struct sock *sk) KERNEL_SOCKPTR(&tos), sizeof(tos)); } +static void nvmet_tcp_sock_set_tclass (struct sock *sk) +{ +#if IS_ENABLED (CONFIG_IPV6 ) +if (sk->sk_family ==AF_INET6 ) { +u8 tclass =ip6_tclass (inet6_sk (sk)->rcv_flowinfo); + +if (tclass >0 ) +do_sock_setsockopt (sk->sk_socket, false,SOL_IPV6 , +IPV6_TCLASS ,KERNEL_SOCKPTR (&tclass), +sizeof (tclass)); + } +#endif +} +static int nvmet_tcp_set_queue_sock (struct nvmet_tcp_queue *queue) {struct socket *sock = queue->sock;
@@ -1762,6 +1776,7 @@ static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_queue *queue)/* Set socket type of service */ nvmet_tcp_sock_set_tos (sock->sk); +nvmet_tcp_sock_set_tclass (sock->sk); ret =0 ;write_lock_bh (&sock->sk->sk_callback_lock);
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 3/4] nvmet-tcp: support IPv6 traffic class
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The nvmet_tcp_sock_set_tclass function attempts to configure the IPv6 Traffic Class by passing a…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The nvmet_tcp_sock_set_tclass function attempts to configure the IPv6 Traffic Class by passing a 1-byte length to do_sock_setsockopt. However, do_ipv6_setsockopt rigidly requires the option length to be at least 4 bytes for IPV6_TCLASS. As a result, the operation fails with -EINVAL, which is silently ignored, and the traffic class is never applied. --
--- Patch [3]: [PATCH v3 3/4] nvmet-tcp: support IPv6 traffic class --- commit 97f9471c35e4e1cd4f5b7c6f1f3a6b3f8e13683a
Author: Geliang Tang <[email protected]>
nvmet-tcp: support IPv6 traffic class
Currently, nvmet-tcp only applies the received IPv4 TOS value when setting up a queue socket, but does not handle the IPv6 traffic class. This patch extends the queue socket setup to handle AF_INET6 sockets.
Quoted 8 lines
drivers/nvme/target/tcp.c +0
-0@@ -1735,6 +1735,20 @@ static void nvmet_tcp_sock_set_tos(struct sock *sk) KERNEL_SOCKPTR(&tos), sizeof(tos)); }
drivers/nvme/target/tcp.c static void nvmet_tcp_sock_set_tos(struct sock *sk) · line 1747
Quoted 10 lines
drivers/nvme/target/tcp.c +10
-0+static void nvmet_tcp_sock_set_tclass (struct sock *sk) +{ +#if IS_ENABLED (CONFIG_IPV6 ) +if (sk->sk_family ==AF_INET6 ) { +u8 tclass =ip6_tclass (inet6_sk (sk)->rcv_flowinfo); + +if (tclass >0 ) +do_sock_setsockopt (sk->sk_socket, false,SOL_IPV6 , +IPV6_TCLASS ,KERNEL_SOCKPTR (&tclass), +sizeof (tclass));
[Severity: Medium]
Will this silently fail to set the traffic class?
Looking at do_ipv6_setsockopt() in net/ipv6/ipv6_sockglue.c, the IPV6_TCLASS handler explicitly requires a minimum optlen of sizeof(int):
case IPV6_TCLASS:
if (optlen < sizeof(int))
goto e_inval;
Since tclass is a u8, sizeof(tclass) is 1. This causes the internal setsockopt implementation to reject the option with -EINVAL, leaving the traffic class unset.
Would it be better to store the traffic class in an int variable before passing it to do_sock_setsockopt()?
Quoted 4 lines
drivers/nvme/target/tcp.c +4
-0+ } +#endif +} +
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH v3 3/4] nvmet-tcp: support IPv6 traffic class
In reply to Geliang TangQuoted 5 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Currently, nvmet-tcp only applies the received IPv4 TOS value when setting up a queue socket, but does not handle the IPv6 traffic class.
Quoted 9 lines
Extend the queue socket setup to handle
AF_INET6sockets. Obtain the traffic class from the IPv6 socket'srcv_flowinfoand apply it throughIPV6_TCLASSusingdo_sock_setsockopt().Signed-off-by Geliang Tang <[email protected]>--- drivers/nvme/target/tcp.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Geliang Tang
reviewerPATCH v3 4/4 nvme-tcp: support IPv6 traffic class
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
Currently, nvme-tcp host only supports setting the IPv4 TOS value when a TOS is specified, but does not handle the IPv6 traffic class.
Extend the queue socket setup to handle AF_INET6 sockets by applying the TOS value to both IPv4 and IPv6 sockets. For IPv6, the TOS value is set as the IPv6 traffic class via IPV6_TCLASS using do_sock_setsockopt().
--- drivers/nvme/host/tcp.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/nvme/host/tcp.c +12 -1
@@ -1815,6 +1815,15 @@ static void nvme_tcp_sock_set_tos(struct sock *sk, int tos) KERNEL_SOCKPTR(&tos), sizeof(tos)); } +static void nvme_tcp_sock_set_tclass (struct sock *sk,int tclass) +{ +#if IS_ENABLED (CONFIG_IPV6 ) +if (sk->sk_family ==AF_INET6 ) +do_sock_setsockopt (sk->sk_socket, false,SOL_IPV6 ,IPV6_TCLASS , +KERNEL_SOCKPTR (&tclass),sizeof (tclass)); +#endif +} +static int nvme_tcp_alloc_queue (struct nvme_ctrl *nctrl,int qid,key_serial_t pskid) {
@@ -1876,8 +1885,10 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,nvme_tcp_sock_set_priority (queue->sock->sk, so_priority);/* Set socket type of service */ -if (nctrl->opts->tos >=0 ) +if (nctrl->opts->tos >=0 ) {nvme_tcp_sock_set_tos (queue->sock->sk, nctrl->opts->tos); +nvme_tcp_sock_set_tclass (queue->sock->sk, nctrl->opts->tos); + }/* Set 10 seconds timeout for icresp recvmsg */ queue->sock->sk->sk_rcvtimeo =10 *HZ ;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 4/4] nvme-tcp: support IPv6 traffic class
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The NVMe TCP target silently fails to set the IPv6 traffic class because it passes a 1-byte…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The NVMe TCP target silently fails to set the IPv6 traffic class because it passes a 1-byte option length for IPV6_TCLASS. --
--- Patch [4]: [PATCH v3 4/4] nvme-tcp: support IPv6 traffic class --- commit f06d75be38a565495a1d84b7e856f1a1a552b88e
Author: Geliang Tang <[email protected]>
nvme-tcp: support IPv6 traffic class
This commit extends the NVMe TCP host queue socket setup to support the IPv6 traffic class. It applies the TOS value to IPv6 sockets via the IPV6_TCLASS socket option.
Quoted 4 lines
drivers/nvme/host/tcp.c +0
-0
[ ... ]
drivers/nvme/host/tcp.c static void nvme_tcp_sock_set_tos(struct sock *sk, int tos) · line 1823
Quoted 10 lines
drivers/nvme/host/tcp.c +6
-0@@ -1815,6 +1815,15 @@ static void nvme_tcp_sock_set_tos(struct sock *sk, int tos) KERNEL_SOCKPTR(&tos), sizeof(tos)); } +static void nvme_tcp_sock_set_tclass (struct sock *sk,int tclass) +{ +#if IS_ENABLED (CONFIG_IPV6 ) +if (sk->sk_family ==AF_INET6 ) +do_sock_setsockopt (sk->sk_socket, false,SOL_IPV6 ,IPV6_TCLASS , +KERNEL_SOCKPTR (&tclass),sizeof (tclass));
While reviewing this patch, I noticed a related bug in the target implementation which handles this exact same logic.
In drivers/nvme/target/tcp.c:nvmet_tcp_sock_set_tclass():
u8 tclass = ip6_tclass(inet6_sk(sk)->rcv_flowinfo);
if (tclass > 0)
do_sock_setsockopt(sk->sk_socket, false, SOL_IPV6,
IPV6_TCLASS, KERNEL_SOCKPTR(&tclass),
sizeof(tclass));
^^^^^^^^^^^^^^[Severity: Medium]
Will this setsockopt call fail silently in the target code?
The tclass variable is declared as a u8, so sizeof(tclass) evaluates to 1. The IPv6 networking core strictly requires an option length of at least 4 bytes for IPV6_TCLASS.
Passing sizeof(u8) causes do_ipv6_setsockopt() to return -EINVAL, which means the IPv6 traffic class is silently ignored instead of being applied to the socket, leading to incorrect QoS behavior without alerting the user.
Does the target code need to be updated to pass a 4-byte length?
Quoted 3 lines
drivers/nvme/host/tcp.c +3
-0+#endif +} +
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v3 4/4] nvme-tcp: support IPv6 traffic class
In reply to Geliang TangQuoted 5 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Currently, nvme-tcp host only supports setting the IPv4 TOS value when a TOS is specified, but does not handle the IPv6 traffic class.
Quoted 9 lines
Extend the queue socket setup to handle
AF_INET6sockets by applying the TOS value to both IPv4 and IPv6 sockets. For IPv6, the TOS value is set as the IPv6 traffic class viaIPV6_TCLASSusingdo_sock_setsockopt().Signed-off-by Geliang Tang <[email protected]>--- drivers/nvme/host/tcp.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Hi Geliang,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal (except selftest_mptcp_join): Success! ✅
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Success! ✅
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/31919377372
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/58af0bc691a8
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1146638
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normalFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)