Skip to contentSkip to conversation

IOSQE_IO_LINK vs. short send of SOCK_STREAM

DISCUSSION Ming Lei 3 participants 14 messages Jan 11, 2023 – Jan 14, 2023 io_uring

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

Hello Guy,

Per my understanding, a short send on SOCK_STREAM should terminate the remainder of the SQE chain built by IOSQE_IO_LINK.

But from my observation, this point isn't true when using io_sendmsg or io_sendmsg_zc on TCP socket, and the other remainder of the chain still can be completed after one short send is found. MSG_WAITALL is off.

For SOCK_STREAM, IOSQE_IO_LINK probably is the only way of io_uring for sending data correctly in batch. However, it depends on the assumption of chain termination by short send.

Appreciate any comment.

Thanks,
Ming

maintainer
#1 lore raw
Quoted 5 lines · Ming Lei

Hello Guy,

Per my understanding, a short send on SOCK_STREAM should terminate the remainder of the SQE chain built by IOSQE_IO_LINK.

Quoted 7 lines

But from my observation, this point isn't true when using io_sendmsg or io_sendmsg_zc on TCP socket, and the other remainder of the chain still can be completed after one short send is found. MSG_WAITALL is off.

For SOCK_STREAM, IOSQE_IO_LINK probably is the only way of io_uring for sending data correctly in batch. However, it depends on the assumption of chain termination by short send.

That is the intended behavior, maybe there are some cases where it's not being set and req_set_fail() not being called? Do you have a test case that I can try? If not, might be easier if you poke at io_uring/net.c:io_sendmsg(). If we send less than what was asked for and we don't retry, req_set_fail() should be called.

Signature · 1 line
Jens Axboe
#2 lore raw
In reply to Ming Lei

Hi Ming,

Quoted 6 lines

Per my understanding, a short send on SOCK_STREAM should terminate the remainder of the SQE chain built by IOSQE_IO_LINK.

But from my observation, this point isn't true when using io_sendmsg or io_sendmsg_zc on TCP socket, and the other remainder of the chain still can be completed after one short send is found. MSG_WAITALL is off.

This is due to legacy reasons, you need pass MSG_WAITALL explicitly in order to a retry or an error on a short write...
It should work for send, sendmsg, sendmsg_zc, recv and recvmsg.

For recv and recvmsg MSG_WAITALL also fails the link for MSG_TRUNC and MSG_CTRUNC.

metze

maintainer
#3 lore raw
Quoted 5 lines · Stefan Metzmacher

Hi Ming,

Quoted 3 lines

Per my understanding, a short send on SOCK_STREAM should terminate the remainder of the SQE chain built by IOSQE_IO_LINK.

Quoted 7 lines
Quoted 3 lines

But from my observation, this point isn't true when using io_sendmsg or io_sendmsg_zc on TCP socket, and the other remainder of the chain still can be completed after one short send is found. MSG_WAITALL is off.

This is due to legacy reasons, you need pass MSG_WAITALL explicitly in order to a retry or an error on a short write...
It should work for send, sendmsg, sendmsg_zc, recv and recvmsg.

Dylan and I were just discussing this OOB and was hoping you'd chime in, as I had some recollection that you were involved with this one.

We should probably ensure this is adequately documented, as it isn't immediately obvious that you'd need WAITALL for links to work with receives.

Quoted 4 lines

For recv and recvmsg MSG_WAITALL also fails the link for MSG_TRUNC and MSG_CTRUNC.

metze

Signature · 1 line
Jens Axboe
author
#4 lore raw
In reply to Stefan Metzmacher

Hi Stefan and Jens,

Thanks for the help.

BTW, the issue is observed when I write ublk-nbd:

https://github.com/ming1/ubdsrv/commits/nbd

and it isn't completed yet(multiple send sqe chains not serialized yet), the issue is triggered when writing big chunk data to ublk-nbd.

Quoted 5 lines · Stefan Metzmacher

Hi Ming,

Quoted 3 lines

Per my understanding, a short send on SOCK_STREAM should terminate the remainder of the SQE chain built by IOSQE_IO_LINK.

Quoted 7 lines
Quoted 3 lines

But from my observation, this point isn't true when using io_sendmsg or io_sendmsg_zc on TCP socket, and the other remainder of the chain still can be completed after one short send is found. MSG_WAITALL is off.

This is due to legacy reasons, you need pass MSG_WAITALL explicitly in order to a retry or an error on a short write...
It should work for send, sendmsg, sendmsg_zc, recv and recvmsg.

Turns out there is another application bug in which recv sqe may cut in the send sqe chain.

After the issue is fixed, if MSG_WAITALL is set, short send can't be observed any more. But if MSG_WAITALL isn't set, short send can be observed and the send io chain still won't be terminated.

So if MSG_WAITALL is set, will io_uring be responsible for retry in case of short send, and application needn't to take care of it?

Quoted 2 lines

For recv and recvmsg MSG_WAITALL also fails the link for MSG_TRUNC and MSG_CTRUNC.

OK, thanks for the sharing of recvmsg MSG_WAITALL.

Thanks,
Ming

maintainer
#5 lore raw
Quoted 10 lines · Ming Lei

Hi Stefan and Jens,

Thanks for the help.

BTW, the issue is observed when I write ublk-nbd:

https://github.com/ming1/ubdsrv/commits/nbd

and it isn't completed yet(multiple send sqe chains not serialized yet), the issue is triggered when writing big chunk data to ublk-nbd.

Gotcha

Quoted 14 lines · Stefan Metzmacher
Quoted 5 lines

Hi Ming,

Quoted 3 lines

Per my understanding, a short send on SOCK_STREAM should terminate the remainder of the SQE chain built by IOSQE_IO_LINK.

Quoted 7 lines
Quoted 3 lines

But from my observation, this point isn't true when using io_sendmsg or io_sendmsg_zc on TCP socket, and the other remainder of the chain still can be completed after one short send is found. MSG_WAITALL is off.

This is due to legacy reasons, you need pass MSG_WAITALL explicitly in order to a retry or an error on a short write...
It should work for send, sendmsg, sendmsg_zc, recv and recvmsg.

Quoted 6 lines

Turns out there is another application bug in which recv sqe may cut in the send sqe chain.

After the issue is fixed, if MSG_WAITALL is set, short send can't be observed any more. But if MSG_WAITALL isn't set, short send can be observed and the send io chain still won't be terminated.

Right, if MSG_WAITALL is set, then the whole thing will be written. If we get a short send, it's retried appropriately. Unless an error occurs, it should send the whole thing.

Quoted 2 lines

So if MSG_WAITALL is set, will io_uring be responsible for retry in case of short send, and application needn't to take care of it?

Correct. I did add a note about that in the liburing man pages after your email earlier:

https://git.kernel.dk/cgit/liburing/commit/?id=8d056db7c0e58f45f7c474a6627f83270bb8f00e

since that wasn't documented as far as I can tell.

Signature · 1 line
Jens Axboe
#6 lore raw

Am 12.01.23 um 04:40 schrieb Jens Axboe:

Quoted 31 lines · Ming Lei
Quoted 10 lines

Hi Stefan and Jens,

Thanks for the help.

BTW, the issue is observed when I write ublk-nbd:

https://github.com/ming1/ubdsrv/commits/nbd

and it isn't completed yet(multiple send sqe chains not serialized yet), the issue is triggered when writing big chunk data to ublk-nbd.

Gotcha

Quoted 17 lines · Stefan Metzmacher
Quoted 5 lines

Hi Ming,

Quoted 3 lines

Per my understanding, a short send on SOCK_STREAM should terminate the remainder of the SQE chain built by IOSQE_IO_LINK.

Quoted 7 lines
Quoted 3 lines

But from my observation, this point isn't true when using io_sendmsg or io_sendmsg_zc on TCP socket, and the other remainder of the chain still can be completed after one short send is found. MSG_WAITALL is off.

This is due to legacy reasons, you need pass MSG_WAITALL explicitly in order to a retry or an error on a short write...
It should work for send, sendmsg, sendmsg_zc, recv and recvmsg.

Turns out there is another application bug in which recv sqe may cut in the send sqe chain.

Quoted 10 lines
Quoted 3 lines

After the issue is fixed, if MSG_WAITALL is set, short send can't be observed any more. But if MSG_WAITALL isn't set, short send can be observed and the send io chain still won't be terminated.

Right, if MSG_WAITALL is set, then the whole thing will be written. If we get a short send, it's retried appropriately. Unless an error occurs, it should send the whole thing.

Quoted 2 lines

So if MSG_WAITALL is set, will io_uring be responsible for retry in case of short send, and application needn't to take care of it?

With new kernels yes, but the application should be prepared to have retry logic in order to be compatible with older kernels.

It was added for recv* in 5.18 and send* in 5.19.

The MSG_WAITALL logic for failing links was added with 5.12. (It was backported to v5.10.28)
As the 5.15 code was backported to v5.10.162, it's safe to assume it's available with IORING_FEAT_NATIVE_WORKERS.

Quoted 7 lines

Correct. I did add a note about that in the liburing man pages after your email earlier:

https://git.kernel.dk/cgit/liburing/commit/?id=8d056db7c0e58f45f7c474a6627f83270bb8f00e

since that wasn't documented as far as I can tell.

author
#7 lore raw

Hello,

Quoted 40 lines · Stefan Metzmacher

Am 12.01.23 um 04:40 schrieb Jens Axboe:

Quoted 39 lines · Ming Lei
Quoted 10 lines

Hi Stefan and Jens,

Thanks for the help.

BTW, the issue is observed when I write ublk-nbd:

https://github.com/ming1/ubdsrv/commits/nbd

and it isn't completed yet(multiple send sqe chains not serialized yet), the issue is triggered when writing big chunk data to ublk-nbd.

Gotcha

Quoted 14 lines · Stefan Metzmacher
Quoted 5 lines

Hi Ming,

Quoted 3 lines

Per my understanding, a short send on SOCK_STREAM should terminate the remainder of the SQE chain built by IOSQE_IO_LINK.

Quoted 7 lines
Quoted 3 lines

But from my observation, this point isn't true when using io_sendmsg or io_sendmsg_zc on TCP socket, and the other remainder of the chain still can be completed after one short send is found. MSG_WAITALL is off.

This is due to legacy reasons, you need pass MSG_WAITALL explicitly in order to a retry or an error on a short write...
It should work for send, sendmsg, sendmsg_zc, recv and recvmsg.

Quoted 6 lines

Turns out there is another application bug in which recv sqe may cut in the send sqe chain.

After the issue is fixed, if MSG_WAITALL is set, short send can't be observed any more. But if MSG_WAITALL isn't set, short send can be observed and the send io chain still won't be terminated.

Right, if MSG_WAITALL is set, then the whole thing will be written. If we get a short send, it's retried appropriately. Unless an error occurs, it should send the whole thing.

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

So if MSG_WAITALL is set, will io_uring be responsible for retry in case of short send, and application needn't to take care of it?

With new kernels yes, but the application should be prepared to have retry logic in order to be compatible with older kernels.

Now ublk-nbd can be played, mkfs/mount and fio starts to work.

But short send still can be observed sometimes when sending nbd write request, which is done by sendmsg(), and the message includes two vectors, (the 1st is the nbd_request, another one is the data to be written to disk).

Short send is reported by cqe in which cqe->res is always 28, which is size of 'struct nbd_request', also the length of the 1st io vec. And not see send cqe failure message.

And MSG_WAITALL is set for all ublk-nbd io actually.

Follows the steps:

1) install liburing 2.0+

2) build ublk & reproduce the issue:

- git clone https://github.com/ming1/ubdsrv.git -b nbd

- cd ubdsrv

- vim build_with_liburing_src && set LIBURING_DIR to your liburing dir

- ./build_with_liburing_src&& make -j4

3) run the nbd test
- cd ubdsrv
- make test T=nbd

Sometimes the test hangs, and the following log can be observed in syslog:

nbd_send_req_done: short send/receive tag 2 op 1 8000000000800002, len 524316 written 28 cqe flags 0
...

Thanks,
Ming

maintainer
#8 lore raw
Quoted 79 lines · Ming Lei

Hello,

Quoted 40 lines · Stefan Metzmacher

Am 12.01.23 um 04:40 schrieb Jens Axboe:

Quoted 39 lines · Ming Lei
Quoted 10 lines

Hi Stefan and Jens,

Thanks for the help.

BTW, the issue is observed when I write ublk-nbd:

https://github.com/ming1/ubdsrv/commits/nbd

and it isn't completed yet(multiple send sqe chains not serialized yet), the issue is triggered when writing big chunk data to ublk-nbd.

Gotcha

Quoted 14 lines · Stefan Metzmacher
Quoted 5 lines

Hi Ming,

Quoted 3 lines

Per my understanding, a short send on SOCK_STREAM should terminate the remainder of the SQE chain built by IOSQE_IO_LINK.

Quoted 7 lines
Quoted 3 lines

But from my observation, this point isn't true when using io_sendmsg or io_sendmsg_zc on TCP socket, and the other remainder of the chain still can be completed after one short send is found. MSG_WAITALL is off.

This is due to legacy reasons, you need pass MSG_WAITALL explicitly in order to a retry or an error on a short write...
It should work for send, sendmsg, sendmsg_zc, recv and recvmsg.

Quoted 6 lines

Turns out there is another application bug in which recv sqe may cut in the send sqe chain.

After the issue is fixed, if MSG_WAITALL is set, short send can't be observed any more. But if MSG_WAITALL isn't set, short send can be observed and the send io chain still won't be terminated.

Right, if MSG_WAITALL is set, then the whole thing will be written. If we get a short send, it's retried appropriately. Unless an error occurs, it should send the whole thing.

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

So if MSG_WAITALL is set, will io_uring be responsible for retry in case of short send, and application needn't to take care of it?

With new kernels yes, but the application should be prepared to have retry logic in order to be compatible with older kernels.

Now ublk-nbd can be played, mkfs/mount and fio starts to work.

But short send still can be observed sometimes when sending nbd write request, which is done by sendmsg(), and the message includes two vectors, (the 1st is the nbd_request, another one is the data to be written to disk).

Short send is reported by cqe in which cqe->res is always 28, which is size of 'struct nbd_request', also the length of the 1st io vec. And not see send cqe failure message.

And MSG_WAITALL is set for all ublk-nbd io actually.

Follows the steps:

1) install liburing 2.0+

2) build ublk & reproduce the issue:

- git clone https://github.com/ming1/ubdsrv.git -b nbd

- cd ubdsrv

- vim build_with_liburing_src && set LIBURING_DIR to your liburing dir

- ./build_with_liburing_src&& make -j4

3) run the nbd test
- cd ubdsrv
- make test T=nbd

Quoted 6 lines

Sometimes the test hangs, and the following log can be observed in syslog:

nbd_send_req_done: short send/receive tag 2 op 1 8000000000800002, len 524316 written 28 cqe flags 0
...

I can reproduce this, but it's a SEND that ends up being triggered, not a SENDMSG. Should the payload carrying op not be a SENDMSG? I'm assuming two vecs for that one.

Signature · 1 line
Jens Axboe
maintainer
#9 lore raw
Quoted 83 lines · Jens Axboe
Quoted 82 lines · Ming Lei

Hello,

Quoted 40 lines · Stefan Metzmacher

Am 12.01.23 um 04:40 schrieb Jens Axboe:

Quoted 39 lines · Ming Lei
Quoted 10 lines

Hi Stefan and Jens,

Thanks for the help.

BTW, the issue is observed when I write ublk-nbd:

https://github.com/ming1/ubdsrv/commits/nbd

and it isn't completed yet(multiple send sqe chains not serialized yet), the issue is triggered when writing big chunk data to ublk-nbd.

Gotcha

Quoted 14 lines · Stefan Metzmacher
Quoted 5 lines

Hi Ming,

Quoted 3 lines

Per my understanding, a short send on SOCK_STREAM should terminate the remainder of the SQE chain built by IOSQE_IO_LINK.

Quoted 7 lines
Quoted 3 lines

But from my observation, this point isn't true when using io_sendmsg or io_sendmsg_zc on TCP socket, and the other remainder of the chain still can be completed after one short send is found. MSG_WAITALL is off.

This is due to legacy reasons, you need pass MSG_WAITALL explicitly in order to a retry or an error on a short write...
It should work for send, sendmsg, sendmsg_zc, recv and recvmsg.

Quoted 6 lines

Turns out there is another application bug in which recv sqe may cut in the send sqe chain.

After the issue is fixed, if MSG_WAITALL is set, short send can't be observed any more. But if MSG_WAITALL isn't set, short send can be observed and the send io chain still won't be terminated.

Right, if MSG_WAITALL is set, then the whole thing will be written. If we get a short send, it's retried appropriately. Unless an error occurs, it should send the whole thing.

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

So if MSG_WAITALL is set, will io_uring be responsible for retry in case of short send, and application needn't to take care of it?

With new kernels yes, but the application should be prepared to have retry logic in order to be compatible with older kernels.

Now ublk-nbd can be played, mkfs/mount and fio starts to work.

But short send still can be observed sometimes when sending nbd write request, which is done by sendmsg(), and the message includes two vectors, (the 1st is the nbd_request, another one is the data to be written to disk).

Short send is reported by cqe in which cqe->res is always 28, which is size of 'struct nbd_request', also the length of the 1st io vec. And not see send cqe failure message.

And MSG_WAITALL is set for all ublk-nbd io actually.

Follows the steps:

1) install liburing 2.0+

2) build ublk & reproduce the issue:

- git clone https://github.com/ming1/ubdsrv.git -b nbd

- cd ubdsrv

- vim build_with_liburing_src && set LIBURING_DIR to your liburing dir

- ./build_with_liburing_src&& make -j4

3) run the nbd test
- cd ubdsrv
- make test T=nbd

Sometimes the test hangs, and the following log can be observed in syslog:

Quoted 7 lines
Quoted 3 lines

nbd_send_req_done: short send/receive tag 2 op 1 8000000000800002, len 524316 written 28 cqe flags 0
...

I can reproduce this, but it's a SEND that ends up being triggered, not a SENDMSG. Should the payload carrying op not be a SENDMSG? I'm assuming two vecs for that one.

Added some debug and it looks like the request was indeed send up and is using IORING_OP_SEND and that the 28 is what was requested. But the completion side seems to think it's a SENDMSG and we should've received more?

I think this needs a bit of debugging on the userspace side first.

Signature · 1 line
Jens Axboe
author
#10 lore raw
Quoted 92 lines · Jens Axboe
Quoted 83 lines · Jens Axboe
Quoted 82 lines · Ming Lei

Hello,

Quoted 40 lines · Stefan Metzmacher

Am 12.01.23 um 04:40 schrieb Jens Axboe:

Quoted 39 lines · Ming Lei
Quoted 10 lines

Hi Stefan and Jens,

Thanks for the help.

BTW, the issue is observed when I write ublk-nbd:

https://github.com/ming1/ubdsrv/commits/nbd

and it isn't completed yet(multiple send sqe chains not serialized yet), the issue is triggered when writing big chunk data to ublk-nbd.

Gotcha

Quoted 14 lines · Stefan Metzmacher
Quoted 5 lines

Hi Ming,

Quoted 3 lines

Per my understanding, a short send on SOCK_STREAM should terminate the remainder of the SQE chain built by IOSQE_IO_LINK.

Quoted 7 lines
Quoted 3 lines

But from my observation, this point isn't true when using io_sendmsg or io_sendmsg_zc on TCP socket, and the other remainder of the chain still can be completed after one short send is found. MSG_WAITALL is off.

This is due to legacy reasons, you need pass MSG_WAITALL explicitly in order to a retry or an error on a short write...
It should work for send, sendmsg, sendmsg_zc, recv and recvmsg.

Quoted 6 lines

Turns out there is another application bug in which recv sqe may cut in the send sqe chain.

After the issue is fixed, if MSG_WAITALL is set, short send can't be observed any more. But if MSG_WAITALL isn't set, short send can be observed and the send io chain still won't be terminated.

Right, if MSG_WAITALL is set, then the whole thing will be written. If we get a short send, it's retried appropriately. Unless an error occurs, it should send the whole thing.

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

So if MSG_WAITALL is set, will io_uring be responsible for retry in case of short send, and application needn't to take care of it?

With new kernels yes, but the application should be prepared to have retry logic in order to be compatible with older kernels.

Now ublk-nbd can be played, mkfs/mount and fio starts to work.

But short send still can be observed sometimes when sending nbd write request, which is done by sendmsg(), and the message includes two vectors, (the 1st is the nbd_request, another one is the data to be written to disk).

Short send is reported by cqe in which cqe->res is always 28, which is size of 'struct nbd_request', also the length of the 1st io vec. And not see send cqe failure message.

And MSG_WAITALL is set for all ublk-nbd io actually.

Follows the steps:

1) install liburing 2.0+

2) build ublk & reproduce the issue:

- git clone https://github.com/ming1/ubdsrv.git -b nbd

- cd ubdsrv

- vim build_with_liburing_src && set LIBURING_DIR to your liburing dir

- ./build_with_liburing_src&& make -j4

3) run the nbd test
- cd ubdsrv
- make test T=nbd

Sometimes the test hangs, and the following log can be observed in syslog:

Quoted 7 lines
Quoted 3 lines

nbd_send_req_done: short send/receive tag 2 op 1 8000000000800002, len 524316 written 28 cqe flags 0
...

I can reproduce this, but it's a SEND that ends up being triggered, not a SENDMSG. Should the payload carrying op not be a SENDMSG? I'm assuming two vecs for that one.

Quoted 6 lines

Added some debug and it looks like the request was indeed send up and is using IORING_OP_SEND and that the 28 is what was requested. But the completion side seems to think it's a SENDMSG and we should've received more?

I think this needs a bit of debugging on the userspace side first.

Yeah, turns out it is indeed one userspace bug, IOSQE_IO_LINK is cleared wrong, and now the issue can't be triggered with the following fix:

https://github.com/ming1/ubdsrv/commit/175ffd14ae2f8fa562134edfd4ac949f8050c108

Thanks,
Ming

author
#11 lore raw
Quoted 98 lines · Ming Lei
Quoted 97 lines · Jens Axboe
Quoted 83 lines · Jens Axboe
Quoted 82 lines · Ming Lei

Hello,

Quoted 40 lines · Stefan Metzmacher

Am 12.01.23 um 04:40 schrieb Jens Axboe:

Quoted 39 lines · Ming Lei
Quoted 10 lines

Hi Stefan and Jens,

Thanks for the help.

BTW, the issue is observed when I write ublk-nbd:

https://github.com/ming1/ubdsrv/commits/nbd

and it isn't completed yet(multiple send sqe chains not serialized yet), the issue is triggered when writing big chunk data to ublk-nbd.

Gotcha

Quoted 14 lines · Stefan Metzmacher
Quoted 5 lines

Hi Ming,

Quoted 3 lines

Per my understanding, a short send on SOCK_STREAM should terminate the remainder of the SQE chain built by IOSQE_IO_LINK.

Quoted 7 lines
Quoted 3 lines

But from my observation, this point isn't true when using io_sendmsg or io_sendmsg_zc on TCP socket, and the other remainder of the chain still can be completed after one short send is found. MSG_WAITALL is off.

This is due to legacy reasons, you need pass MSG_WAITALL explicitly in order to a retry or an error on a short write...
It should work for send, sendmsg, sendmsg_zc, recv and recvmsg.

Quoted 6 lines

Turns out there is another application bug in which recv sqe may cut in the send sqe chain.

After the issue is fixed, if MSG_WAITALL is set, short send can't be observed any more. But if MSG_WAITALL isn't set, short send can be observed and the send io chain still won't be terminated.

Right, if MSG_WAITALL is set, then the whole thing will be written. If we get a short send, it's retried appropriately. Unless an error occurs, it should send the whole thing.

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

So if MSG_WAITALL is set, will io_uring be responsible for retry in case of short send, and application needn't to take care of it?

With new kernels yes, but the application should be prepared to have retry logic in order to be compatible with older kernels.

Now ublk-nbd can be played, mkfs/mount and fio starts to work.

But short send still can be observed sometimes when sending nbd write request, which is done by sendmsg(), and the message includes two vectors, (the 1st is the nbd_request, another one is the data to be written to disk).

Short send is reported by cqe in which cqe->res is always 28, which is size of 'struct nbd_request', also the length of the 1st io vec. And not see send cqe failure message.

And MSG_WAITALL is set for all ublk-nbd io actually.

Follows the steps:

1) install liburing 2.0+

2) build ublk & reproduce the issue:

- git clone https://github.com/ming1/ubdsrv.git -b nbd

- cd ubdsrv

- vim build_with_liburing_src && set LIBURING_DIR to your liburing dir

- ./build_with_liburing_src&& make -j4

3) run the nbd test
- cd ubdsrv
- make test T=nbd

Sometimes the test hangs, and the following log can be observed in syslog:

Quoted 7 lines
Quoted 3 lines

nbd_send_req_done: short send/receive tag 2 op 1 8000000000800002, len 524316 written 28 cqe flags 0
...

I can reproduce this, but it's a SEND that ends up being triggered, not a SENDMSG. Should the payload carrying op not be a SENDMSG? I'm assuming two vecs for that one.

Added some debug and it looks like the request was indeed send up and is using IORING_OP_SEND and that the 28 is what was requested. But the completion side seems to think it's a SENDMSG and we should've received more?

Quoted 6 lines
Quoted 1 line

I think this needs a bit of debugging on the userspace side first.

Yeah, turns out it is indeed one userspace bug, IOSQE_IO_LINK is cleared wrong, and now the issue can't be triggered with the following fix:

https://github.com/ming1/ubdsrv/commit/175ffd14ae2f8fa562134edfd4ac949f8050c108

Turns out the two are different issues, it is understandable that the above commit fixes io hang.

But just checked syslog, the short send warning is still logged, will investigate further.

thanks,
Ming

author
#12 lore raw
In reply to Ming Lei
Quoted 98 lines · Ming Lei
Quoted 97 lines · Jens Axboe
Quoted 83 lines · Jens Axboe
Quoted 82 lines · Ming Lei

Hello,

Quoted 40 lines · Stefan Metzmacher

Am 12.01.23 um 04:40 schrieb Jens Axboe:

Quoted 39 lines · Ming Lei
Quoted 10 lines

Hi Stefan and Jens,

Thanks for the help.

BTW, the issue is observed when I write ublk-nbd:

https://github.com/ming1/ubdsrv/commits/nbd

and it isn't completed yet(multiple send sqe chains not serialized yet), the issue is triggered when writing big chunk data to ublk-nbd.

Gotcha

Quoted 14 lines · Stefan Metzmacher
Quoted 5 lines

Hi Ming,

Quoted 3 lines

Per my understanding, a short send on SOCK_STREAM should terminate the remainder of the SQE chain built by IOSQE_IO_LINK.

Quoted 7 lines
Quoted 3 lines

But from my observation, this point isn't true when using io_sendmsg or io_sendmsg_zc on TCP socket, and the other remainder of the chain still can be completed after one short send is found. MSG_WAITALL is off.

This is due to legacy reasons, you need pass MSG_WAITALL explicitly in order to a retry or an error on a short write...
It should work for send, sendmsg, sendmsg_zc, recv and recvmsg.

Quoted 6 lines

Turns out there is another application bug in which recv sqe may cut in the send sqe chain.

After the issue is fixed, if MSG_WAITALL is set, short send can't be observed any more. But if MSG_WAITALL isn't set, short send can be observed and the send io chain still won't be terminated.

Right, if MSG_WAITALL is set, then the whole thing will be written. If we get a short send, it's retried appropriately. Unless an error occurs, it should send the whole thing.

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

So if MSG_WAITALL is set, will io_uring be responsible for retry in case of short send, and application needn't to take care of it?

With new kernels yes, but the application should be prepared to have retry logic in order to be compatible with older kernels.

Now ublk-nbd can be played, mkfs/mount and fio starts to work.

But short send still can be observed sometimes when sending nbd write request, which is done by sendmsg(), and the message includes two vectors, (the 1st is the nbd_request, another one is the data to be written to disk).

Short send is reported by cqe in which cqe->res is always 28, which is size of 'struct nbd_request', also the length of the 1st io vec. And not see send cqe failure message.

And MSG_WAITALL is set for all ublk-nbd io actually.

Follows the steps:

1) install liburing 2.0+

2) build ublk & reproduce the issue:

- git clone https://github.com/ming1/ubdsrv.git -b nbd

- cd ubdsrv

- vim build_with_liburing_src && set LIBURING_DIR to your liburing dir

- ./build_with_liburing_src&& make -j4

3) run the nbd test
- cd ubdsrv
- make test T=nbd

Sometimes the test hangs, and the following log can be observed in syslog:

Quoted 7 lines
Quoted 3 lines

nbd_send_req_done: short send/receive tag 2 op 1 8000000000800002, len 524316 written 28 cqe flags 0
...

I can reproduce this, but it's a SEND that ends up being triggered, not a SENDMSG. Should the payload carrying op not be a SENDMSG? I'm assuming two vecs for that one.

Added some debug and it looks like the request was indeed send up and is using IORING_OP_SEND and that the 28 is what was requested. But the completion side seems to think it's a SENDMSG and we should've received more?

Quoted 6 lines
Quoted 1 line

I think this needs a bit of debugging on the userspace side first.

Yeah, turns out it is indeed one userspace bug, IOSQE_IO_LINK is cleared wrong, and now the issue can't be triggered with the following fix:

https://github.com/ming1/ubdsrv/commit/175ffd14ae2f8fa562134edfd4ac949f8050c108

Figured out, it is still one userspace issue.

For nbd request sent to server, the cqe could come after the ublk io request is completed which is triggered by nbd reply from server, then if new ublk io req is submitted to same slot, the new data length and op code could be read in nbd_send_req_done(), and the warning is triggered.

Thanks,
Ming

maintainer
#13 lore raw
Quoted 106 lines · Ming Lei
Quoted 98 lines · Ming Lei
Quoted 97 lines · Jens Axboe
Quoted 83 lines · Jens Axboe
Quoted 82 lines · Ming Lei

Hello,

Quoted 40 lines · Stefan Metzmacher

Am 12.01.23 um 04:40 schrieb Jens Axboe:

Quoted 39 lines · Ming Lei
Quoted 10 lines

Hi Stefan and Jens,

Thanks for the help.

BTW, the issue is observed when I write ublk-nbd:

https://github.com/ming1/ubdsrv/commits/nbd

and it isn't completed yet(multiple send sqe chains not serialized yet), the issue is triggered when writing big chunk data to ublk-nbd.

Gotcha

Quoted 14 lines · Stefan Metzmacher
Quoted 5 lines

Hi Ming,

Quoted 3 lines

Per my understanding, a short send on SOCK_STREAM should terminate the remainder of the SQE chain built by IOSQE_IO_LINK.

Quoted 7 lines
Quoted 3 lines

But from my observation, this point isn't true when using io_sendmsg or io_sendmsg_zc on TCP socket, and the other remainder of the chain still can be completed after one short send is found. MSG_WAITALL is off.

This is due to legacy reasons, you need pass MSG_WAITALL explicitly in order to a retry or an error on a short write...
It should work for send, sendmsg, sendmsg_zc, recv and recvmsg.

Quoted 6 lines

Turns out there is another application bug in which recv sqe may cut in the send sqe chain.

After the issue is fixed, if MSG_WAITALL is set, short send can't be observed any more. But if MSG_WAITALL isn't set, short send can be observed and the send io chain still won't be terminated.

Right, if MSG_WAITALL is set, then the whole thing will be written. If we get a short send, it's retried appropriately. Unless an error occurs, it should send the whole thing.

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

So if MSG_WAITALL is set, will io_uring be responsible for retry in case of short send, and application needn't to take care of it?

With new kernels yes, but the application should be prepared to have retry logic in order to be compatible with older kernels.

Now ublk-nbd can be played, mkfs/mount and fio starts to work.

But short send still can be observed sometimes when sending nbd write request, which is done by sendmsg(), and the message includes two vectors, (the 1st is the nbd_request, another one is the data to be written to disk).

Short send is reported by cqe in which cqe->res is always 28, which is size of 'struct nbd_request', also the length of the 1st io vec. And not see send cqe failure message.

And MSG_WAITALL is set for all ublk-nbd io actually.

Follows the steps:

1) install liburing 2.0+

2) build ublk & reproduce the issue:

- git clone https://github.com/ming1/ubdsrv.git -b nbd

- cd ubdsrv

- vim build_with_liburing_src && set LIBURING_DIR to your liburing dir

- ./build_with_liburing_src&& make -j4

3) run the nbd test
- cd ubdsrv
- make test T=nbd

Sometimes the test hangs, and the following log can be observed in syslog:

Quoted 7 lines
Quoted 3 lines

nbd_send_req_done: short send/receive tag 2 op 1 8000000000800002, len 524316 written 28 cqe flags 0
...

I can reproduce this, but it's a SEND that ends up being triggered, not a SENDMSG. Should the payload carrying op not be a SENDMSG? I'm assuming two vecs for that one.

Added some debug and it looks like the request was indeed send up and is using IORING_OP_SEND and that the 28 is what was requested. But the completion side seems to think it's a SENDMSG and we should've received more?

Quoted 6 lines
Quoted 1 line

I think this needs a bit of debugging on the userspace side first.

Yeah, turns out it is indeed one userspace bug, IOSQE_IO_LINK is cleared wrong, and now the issue can't be triggered with the following fix:

https://github.com/ming1/ubdsrv/commit/175ffd14ae2f8fa562134edfd4ac949f8050c108

Quoted 7 lines

Figured out, it is still one userspace issue.

For nbd request sent to server, the cqe could come after the ublk io request is completed which is triggered by nbd reply from server, then if new ublk io req is submitted to same slot, the new data length and op code could be read in nbd_send_req_done(), and the warning is triggered.

Figured it was some kind of data reuse issue, as it is consistent with that. Glad you got it figured out.

Signature · 1 line
Jens Axboe