Skip to contentSkip to conversation

nvme-cli connect regression

DISCUSSION Daniel Wagner 5 participants 17 messages Apr 1, 2025 – Apr 18, 2025 NVMe

lore
Share & tools
lore
#0 lore raw

Hi,

Luca reported that "occasional failures in the systemd integration test that uses nvme-cli:" [1]

[   10.378713] TEST-84-STORAGETM.sh[316]: + nvme connect-all -t tcp -a 127.0.0.1 -s 16858 --hostid=95fe8041-3f53-415b-bc40-1bbd8932e7e8
[   10.397892] nvme_tcp: queue 0: failed to receive icresp, error -4
[   10.397326] TEST-84-STORAGETM.sh[340]: failed to add controller, error failed to write to nvme-fabrics device

I was not able to identify any changes in nvme-cli v2.12 which could explain this problem. The kernel in question is a stable kernel (6.13.7) which got following commit back ported:

578539e09690 ("nvme-tcp: fix connect failure on receiving partial ICResp PDU").

The change itself looks okay but I think introduces a behavior change for the initial connect attempt.

The error code is EINTR, should the kernel retry here, or is userland in charge to retry? Assuming we should retry... Thoughts?

Thanks,
Daniel

[1] https://github.com/linux-nvme/nvme-cli/issues/2760

maintainer
#1 lore raw
Quoted 13 lines · Daniel Wagner

Hi,

Luca reported that "occasional failures in the systemd integration test that uses nvme-cli:" [1]

[   10.378713] TEST-84-STORAGETM.sh[316]: + nvme connect-all -t tcp -a 127.0.0.1 -s 16858 --hostid=95fe8041-3f53-415b-bc40-1bbd8932e7e8
[   10.397892] nvme_tcp: queue 0: failed to receive icresp, error -4
[   10.397326] TEST-84-STORAGETM.sh[340]: failed to add controller, error failed to write to nvme-fabrics device

I was not able to identify any changes in nvme-cli v2.12 which could explain this problem. The kernel in question is a stable kernel (6.13.7) which got following commit back ported:

Quoted 5 lines

578539e09690 ("nvme-tcp: fix connect failure on receiving partial ICResp PDU").

The change itself looks okay but I think introduces a behavior change for the initial connect attempt.

Does reverting the commit fix the regression? It looks like the only kernel change in this area, but still would be nice to confirm.

#2 lore raw
Quoted 8 lines · Keith Busch
Quoted 5 lines

578539e09690 ("nvme-tcp: fix connect failure on receiving partial ICResp PDU").

The change itself looks okay but I think introduces a behavior change for the initial connect attempt.

Does reverting the commit fix the regression? It looks like the only kernel change in this area, but still would be nice to confirm.

Luca can't simply replace the kernel. I would need to build one and package it up for Arch I think, which I don't have running here...

#3 lore raw
In reply to Daniel Wagner
Quoted 17 lines · Daniel Wagner

Hi,

Luca reported that "occasional failures in the systemd integration test that uses nvme-cli:" [1]

[   10.378713] TEST-84-STORAGETM.sh[316]: + nvme connect-all -t tcp -a 127.0.0.1 -s 16858 --hostid=95fe8041-3f53-415b-bc40-1bbd8932e7e8
[   10.397892] nvme_tcp: queue 0: failed to receive icresp, error -4
[   10.397326] TEST-84-STORAGETM.sh[340]: failed to add controller, error failed to write to nvme-fabrics device

I was not able to identify any changes in nvme-cli v2.12 which could explain this problem. The kernel in question is a stable kernel (6.13.7) which got following commit back ported:

578539e09690 ("nvme-tcp: fix connect failure on receiving partial ICResp PDU").

Quoted 8 lines

The change itself looks okay but I think introduces a behavior change for the initial connect attempt.

The error code is EINTR, should the kernel retry here, or is userland in charge to retry? Assuming we should retry... Thoughts?

Thanks,
Daniel

I am not sure what an error code of EINTR means in the kernel. It looks like the kernel_recvmsg() is performed on the thread that writes to /dev/nvme-fabrics, so it's possible that there is a signal pending for the userspace thread (i.e. nvme-cli)?
The kernel_recvmsg() should block until it receives all 128 bytes of the ICResp PDU. It can also time out if the data is not received before sk_rcvtimeo = 10 * HZ. But I would expect it to return EAGAIN in that case. I was going to say it doesn't look like 10 seconds had passed yet in the quoted logs, but they also show time going backwards, so I am not sure what to make of the timestamps...

Best,
Caleb

#4 lore raw
Quoted 4 lines · Caleb Sander Mateos

I am not sure what an error code of EINTR means in the kernel. It looks like the kernel_recvmsg() is performed on the thread that writes to /dev/nvme-fabrics, so it's possible that there is a signal pending for the userspace thread (i.e. nvme-cli)?

nvme-cli has only on place where signals are used (to interrupt a self test). libnvme doesn't use signals at all. No idea where the signal is coming from but it looks very unlikely to be from nvme-cli/libnvme.

Quoted 6 lines

The kernel_recvmsg() should block until it receives all 128 bytes of the ICResp PDU. It can also time out if the data is not received before sk_rcvtimeo = 10 * HZ. But I would expect it to return EAGAIN in that case. I was going to say it doesn't look like 10 seconds had passed yet in the quoted logs, but they also show time going backwards, so I am not sure what to make of the timestamps...

Not sure if I am looking at the right code in networking. tcp_recvmsg_locked seems to be the place where the operation happens and this function is able to return EINTR

if (signal_pending)
sock_intr_errno
return -EINTR

And if I read sock_intr_errno correctly, this is the case when sk_rcvtimeo is set.

Back to my original question, what should happen in this case? Usually for userpace seing a EINTR means to retry. No problem addding this to libnvme, just wanted to confirm this is the right thing to do.

Thanks,
Daniel

#5 lore raw
Quoted 9 lines · Daniel Wagner
Quoted 4 lines · Caleb Sander Mateos

I am not sure what an error code of EINTR means in the kernel. It looks like the kernel_recvmsg() is performed on the thread that writes to /dev/nvme-fabrics, so it's possible that there is a signal pending for the userspace thread (i.e. nvme-cli)?

nvme-cli has only on place where signals are used (to interrupt a self test). libnvme doesn't use signals at all. No idea where the signal is coming from but it looks very unlikely to be from nvme-cli/libnvme.

Maybe an operation on a socket that has been closed by the other side (SIGPIPE) ?

Maurizio

#6 lore raw
Quoted 7 lines · Maurizio Lombardi
Quoted 6 lines · Daniel Wagner
Quoted 4 lines · Caleb Sander Mateos

I am not sure what an error code of EINTR means in the kernel. It looks like the kernel_recvmsg() is performed on the thread that writes to /dev/nvme-fabrics, so it's possible that there is a signal pending for the userspace thread (i.e. nvme-cli)?

Quoted 5 lines
Quoted 3 lines

nvme-cli has only on place where signals are used (to interrupt a self test). libnvme doesn't use signals at all. No idea where the signal is coming from but it looks very unlikely to be from nvme-cli/libnvme.

Maybe an operation on a socket that has been closed by the other side (SIGPIPE) ?

Could be.

Anyway, no one has really said it's a stupid idea to retry when the syscall returns EINTR, so I am going to add it to libnvme now.

#8 lore raw
Quoted 1 line · Sagi Grimberg

Was this resolved?

I've added a retry loop in libnvme when the write to /dev/nvme-fabrics returns EINTR. It takes a few days until the newly version hits the test frameworks and we know for sure that is handled.

Quoted 1 line

Couldn't follow where the issue was - kernel/userspace?

  [ 10.397892] nvme_tcp: queue 0: failed to receive icresp, error -4

Stable kernels started to return EINTR and one change which touches this area is:

578539e09690 ("nvme-tcp: fix connect failure on receiving partial ICResp PDU")

Unfortunately, it's not easy for Luca to build a test kernel. If we provide one for his distro, he would be willing to tests.

maintainer
#9 lore raw
Quoted 9 lines · Daniel Wagner
Quoted 1 line · Sagi Grimberg

Was this resolved?

I've added a retry loop in libnvme when the write to /dev/nvme-fabrics returns EINTR. It takes a few days until the newly version hits the test frameworks and we know for sure that is handled.

Quoted 1 line

Couldn't follow where the issue was - kernel/userspace?

   [ 10.397892] nvme_tcp: queue 0: failed to receive icresp, error -4
Quoted 7 lines

Stable kernels started to return EINTR and one change which touches this area is:

578539e09690 ("nvme-tcp: fix connect failure on receiving partial ICResp PDU")

Unfortunately, it's not easy for Luca to build a test kernel. If we provide one for his distro, he would be willing to tests.

Its not great that we now get sporadic EINTR errors. I am wandering what is triggering this?

Caleb, did you see this?

#10 lore raw
Quoted 18 lines · Sagi Grimberg
Quoted 14 lines · Daniel Wagner
Quoted 1 line · Sagi Grimberg

Was this resolved?

I've added a retry loop in libnvme when the write to /dev/nvme-fabrics returns EINTR. It takes a few days until the newly version hits the test frameworks and we know for sure that is handled.

Quoted 1 line

Couldn't follow where the issue was - kernel/userspace?

   [ 10.397892] nvme_tcp: queue 0: failed to receive icresp, error -4

Stable kernels started to return EINTR and one change which touches this area is:

578539e09690 ("nvme-tcp: fix connect failure on receiving partial ICResp PDU")

Quoted 7 lines
Quoted 2 lines

Unfortunately, it's not easy for Luca to build a test kernel. If we provide one for his distro, he would be willing to tests.

Its not great that we now get sporadic EINTR errors. I am wandering what is triggering this?

Caleb, did you see this?

Yes, I did see it. I don't understand where EINTR could come from aside from the userspace process receiving a signal while waiting for the ICResp (or hitting the 10 second timeout waiting to receive the PDU). I don't understand how the switch to MSG_WAITALL would affect this. A tcpdump might be helpful to understand whether the controller is actually sending the full ICResp timely.

Best,
Caleb

#11 lore raw
Quoted 4 lines · Caleb Sander Mateos
Quoted 3 lines · Sagi Grimberg

Its not great that we now get sporadic EINTR errors. I am wandering what is triggering this?

Quoted 8 lines
Quoted 1 line

Caleb, did you see this?

Yes, I did see it. I don't understand where EINTR could come from aside from the userspace process receiving a signal while waiting for the ICResp (or hitting the 10 second timeout waiting to receive the PDU). I don't understand how the switch to MSG_WAITALL would affect this. A tcpdump might be helpful to understand whether the controller is actually sending the full ICResp timely.

I think I can reproduce it. I have two connections and do a

while nvme read ....; do yes; done

and block one of the connections, when the error handler kicks in the id ns command fails with EINTR.

maintainer
#12 lore raw
Quoted 12 lines · Daniel Wagner
Quoted 11 lines · Caleb Sander Mateos
Quoted 4 lines · Sagi Grimberg

Its not great that we now get sporadic EINTR errors. I am wandering what is triggering this?

Caleb, did you see this?

Yes, I did see it. I don't understand where EINTR could come from aside from the userspace process receiving a signal while waiting for the ICResp (or hitting the 10 second timeout waiting to receive the PDU). I don't understand how the switch to MSG_WAITALL would affect this. A tcpdump might be helpful to understand whether the controller is actually sending the full ICResp timely.

Quoted 6 lines

I think I can reproduce it. I have two connections and do a

while nvme read ....; do yes; done

and block one of the connections, when the error handler kicks in the id ns command fails with EINTR.

What happens before Caleb's patch though?

#13 lore raw
Quoted 8 lines · Sagi Grimberg
Quoted 6 lines

I think I can reproduce it. I have two connections and do a

while nvme read ....; do yes; done

and block one of the connections, when the error handler kicks in the id ns command fails with EINTR.

What happens before Caleb's patch though?

I am able to reproduce it with the distro kernel 6.13.9 on my laptop (real hardware) but not with one of my test setups (qemu) and a strip down configuration. Neither HEAD, v6.14 or v6.13.8 is returning EINTR.

I will try the distro config in qemu as next.

#14 lore raw
Quoted 1 line · Daniel Wagner

I will try the distro config in qemu as next.

No success, can't reproduce it with this either.

maintainer
#15 lore raw
In reply to Daniel Wagner
Quoted 5 lines · Daniel Wagner
Quoted 4 lines · Sagi Grimberg
Quoted 4 lines

I think I can reproduce it. I have two connections and do a

while nvme read ....; do yes; done

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

and block one of the connections, when the error handler kicks in the id ns command fails with EINTR.

What happens before Caleb's patch though?

I am able to reproduce it with the distro kernel 6.13.9 on my laptop (real hardware) but not with one of my test setups (qemu) and a strip down configuration. Neither HEAD, v6.14 or v6.13.8 is returning EINTR.

I will try the distro config in qemu as next.

Does this change make the issue go away?

drivers/nvme/host/tcp.c +0 -0
index 5041cbfd8272..87177ec75e49 100644
@@ -1517,7 +1517,6 @@ static int nvme_tcp_init_connection(struct nvme_tcp_queue *queue)

                msg.msg_control = cbuf; msg.msg_controllen = sizeof(cbuf); }
-       msg.msg_flags = MSG_WAITALL;
        ret = kernel_recvmsg(queue->sock, &msg, &iov, 1, iov.iov_len, msg.msg_flags); if (ret >= 0 && ret < sizeof(*icresp))

maintainer
#16 lore raw
In reply to Sagi Grimberg
Quoted 15 lines · Sagi Grimberg
Quoted 12 lines · Daniel Wagner
Quoted 1 line · Sagi Grimberg

Was this resolved?

I've added a retry loop in libnvme when the write to /dev/nvme-fabrics returns EINTR. It takes a few days until the newly version hits the test frameworks and we know for sure that is handled.

Quoted 1 line

Couldn't follow where the issue was - kernel/userspace?

   [ 10.397892] nvme_tcp: queue 0: failed to receive icresp, error -4

Stable kernels started to return EINTR and one change which touches this area is:

Quoted 7 lines
Quoted 4 lines

578539e09690 ("nvme-tcp: fix connect failure on receiving partial ICResp PDU")

Unfortunately, it's not easy for Luca to build a test kernel. If we provide one for his distro, he would be willing to tests.

Its not great that we now get sporadic EINTR errors. I am wandering what is triggering this?

The only EINTR return value I can find in this path is from sock_intr_errno(). So something is signalling the nvme process, which could be anything.