diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c index b2c381634393d23855086c9886e459065b4ad66d..ad1e14359662ceae9828c0f1e8e1cdda765614c7 100644 --- a/io_uring/kbuf.c +++ b/io_uring/kbuf.c @@ -70,9 +70,15 @@ void io_kbuf_recycle_legacy(struct io_kiocb *req, unsigned issue_flags) buf = req->kbuf; bl = io_buffer_get_list(ctx, buf->bgid); - list_add(&buf->list, &bl->buf_list); + /* + * If the buffer list was upgraded to a ring-based one, or removed, + * while the request was in-flight in io-wq, drop it. + */ + if (bl && !bl->is_mapped) + list_add(&buf->list, &bl->buf_list); req->flags &= ~REQ_F_BUFFER_SELECTED; req->buf_index = buf->bgid; + req->kbuf = NULL; io_ring_submit_unlock(ctx, issue_flags); return;