[PATCH v5 1/1] nvme-tcp: expose per-queue socket addresses via sysfs
Nilay Shroff
nilay at linux.ibm.com
Wed Dec 2 05:49:38 PST 2026
On 12/1/26 3:34 PM, sashiko-bot at kernel.org wrote:
> 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.
>
Yes, that's correct. However, IMO, emitting %0 as the scope ID for the
unscoped IPv6 address should be acceptable.
First, I doubt there are many use cases where a host connects to a
link-local target address using a non-link-local source address. Even
if such a configuration exists, a parser consuming this sysfs attribute
can simply treat a scope-id of 0 as no scope-id.
On another note, the kernel also supports the %pISsc printk format specifier
to print an IPv6 address along with its scope ID. This would similarly print
%0 when the scope ID is zero.
That said, it is possible to avoid printing the scope-id for an endpoint
when it is zero. However, doing so would require additional conditional
formatting logic, making the code slightly more complicated.
If others feel that we should omit the scope-id when it is zero, I'm happy
to make that change.
Thanks,
--Nilay
More information about the Linux-nvme
mailing list