Skip to content

Commit

Permalink
io_uring/net: ensure async prep handlers always initialize ->done_io
Browse files Browse the repository at this point in the history
If we get a request with IOSQE_ASYNC set, then we first run the prep
async handlers. But if we then fail setting it up and want to post
a CQE with -EINVAL, we use ->done_io. This was previously guarded with
REQ_F_PARTIAL_IO, and the normal setup handlers do set it up before any
potential errors, but we need to cover the async setup too.

Fixes: 9817ad8 ("io_uring/net: remove dependency on REQ_F_PARTIAL_IO for sr->done_io")
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
axboe committed Mar 16, 2024
1 parent 2b35b8b commit f3a640c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion io_uring/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,10 @@ int io_send_prep_async(struct io_kiocb *req)
struct io_async_msghdr *io;
int ret;

if (!zc->addr || req_has_async_data(req))
if (req_has_async_data(req))
return 0;
zc->done_io = 0;
if (!zc->addr)
return 0;
io = io_msg_alloc_async_prep(req);
if (!io)
Expand All @@ -353,8 +356,10 @@ static int io_setup_async_addr(struct io_kiocb *req,

int io_sendmsg_prep_async(struct io_kiocb *req)
{
struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg);
int ret;

sr->done_io = 0;
if (!io_msg_alloc_async_prep(req))
return -ENOMEM;
ret = io_sendmsg_copy_hdr(req, req->async_data);
Expand Down Expand Up @@ -608,9 +613,11 @@ static int io_recvmsg_copy_hdr(struct io_kiocb *req,

int io_recvmsg_prep_async(struct io_kiocb *req)
{
struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg);
struct io_async_msghdr *iomsg;
int ret;

sr->done_io = 0;
if (!io_msg_alloc_async_prep(req))
return -ENOMEM;
iomsg = req->async_data;
Expand Down

0 comments on commit f3a640c

Please sign in to comment.