[PATCH v5 1/1] nvme-tcp: expose per-queue socket addresses via sysfs
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Tue Dec 1 02:04:04 PST 2026
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] nvme-tcp: address_show() emits %0 scope ID when one IPv6
endpoint is unscoped
--
commit cef888fe89d146daf5915c1274fff0343c037eb2
Author: Nilay Shroff <nilay at linux.ibm.com>
nvme-tcp: expose per-queue socket addresses via sysfs
This commit adds a read-only per-queue sysfs attribute named "address" to
expose the local and peer socket endpoint addresses for each NVMe/TCP I/O
queue, and documents it in Documentation/ABI/stable/sysfs-nvme.
> diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
> index cf3c98b188bd1..05cf7000ef678 100644
> --- a/drivers/nvme/host/tcp.c
> +++ b/drivers/nvme/host/tcp.c
> @@ -2127,14 +2127,73 @@ static ssize_t managed_show(struct kobject *kobj, struct kobj_attribute *attr,
> !test_bit(NVME_TCP_Q_IO_CPU_USER, &queue->flags));
> }
>
> +static ssize_t address_show(struct kobject *kobj, struct kobj_attribute *attr,
> + char *buf)
> +{
> + struct nvme_tcp_queue *queue = nvme_queue_info_data(kobj);
> + struct sockaddr_storage src, dst;
> + int ret = 0;
> +
> + mutex_lock(&queue->queue_lock);
> +
> + if (!test_bit(NVME_TCP_Q_LIVE, &queue->flags))
> + goto out;
> +
> + ret = kernel_getsockname(queue->sock, (struct sockaddr *)&src);
> + if (ret <= 0)
> + goto out;
> +
> + ret = kernel_getpeername(queue->sock, (struct sockaddr *)&dst);
> + if (ret <= 0)
> + goto out;
> +
> + if (src.ss_family != dst.ss_family) {
> + ret = -EAFNOSUPPORT;
> + goto out;
> + }
> +
> + if (src.ss_family == AF_INET) {
> + struct sockaddr_in *sip = (struct sockaddr_in *)&src;
> + struct sockaddr_in *dip = (struct sockaddr_in *)&dst;
> +
> + ret = sysfs_emit(buf, "sip=%pI4,sport=%hu,dip=%pI4,dport=%hu\n",
> + &sip->sin_addr.s_addr, ntohs(sip->sin_port),
> + &dip->sin_addr.s_addr, ntohs(dip->sin_port));
> + } else if (src.ss_family == AF_INET6) {
> + struct sockaddr_in6 *sip6 = (struct sockaddr_in6 *)&src;
> + struct sockaddr_in6 *dip6 = (struct sockaddr_in6 *)&dst;
> +
> + if (sip6->sin6_scope_id || dip6->sin6_scope_id)
> + ret = sysfs_emit(buf, "sip=%pI6c%%%u,sport=%hu,dip=%pI6c%%%u,dport=%hu\n",
> + &sip6->sin6_addr, sip6->sin6_scope_id,
> + ntohs(sip6->sin6_port),
> + &dip6->sin6_addr, dip6->sin6_scope_id,
> + ntohs(dip6->sin6_port));
[Severity: Medium]
Does this emit a "%0" suffix on the unscoped endpoint when only one of
sip6->sin6_scope_id or dip6->sin6_scope_id is non-zero?
inet6_getname() sets sin6_scope_id via ipv6_iface_scope_id(), which only
returns sk->sk_bound_dev_if for addresses that need a scope ID (such as
link-local addresses) and returns 0 for global or unique-local addresses.
If one side of the connection uses a link-local address and the other uses
a global or unique-local address, formatting both with "%%%u" appends "%0"
to the unscoped address.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201095146.510810-3-nilay@linux.ibm.com?part=1
More information about the Linux-nvme
mailing list