virtio_fs_send_req() enqueues with GFP_ATOMIC, because it may be called
with fc->chan->bg_lock held. copy_args_to_argbuf() allocates the bounce
buffer with those flags, so under memory pressure a request can be
failed with -ENOMEM even though nothing is wrong with it. The buffer is
as large as the request arguments, so this is not limited to tiny
allocations: FUSE_REMOVEMAPPING, for example, can ask for just over
4 KiB, an order-1 allocation out of the atomic reserves with no reclaim.
A virtqueue that is merely full is already handled gracefully: -ENOSPC
puts the request on fsvq->queued_reqs and virtio_fs_request_dispatch_work()
retries it with GFP_KERNEL under memalloc_nofs_save(). A failed atomic
allocation is just as transient, so treat it the same way instead of
ending the request. Unlike -ENOSPC there is no completion to kick the
worker afterwards, so schedule it here.
virtio_fs_enqueue_req() queues on -ENOSPC only after checking
fsvq->connected under fsvq->lock; do the same here and fail the request
with -ENOTCONN if the queue is gone. req->argbuf has already been freed
and cleared on the error path, so the retry reallocates it.
Fixes: a62a8ef9d97d ("virtio-fs: add virtiofs filesystem")
Signed-off-by: Miklos Szeredi <[email protected]>
---
fs/fuse/virtio_fs.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
index 8bd63c6165d2..6ddb2f181a16 100644
--- a/fs/fuse/virtio_fs.c
+++ b/fs/fuse/virtio_fs.c
@@ -1586,6 +1586,23 @@ static void virtio_fs_send_req(struct fuse_iqueue *fiq,
struct fuse_req *req)
*/
return;
}
+ if (ret == -ENOMEM) {
+ /*
+ * Only the GFP_ATOMIC allocation failed. Hand the
+ * request to the dispatch worker, which retries with
+ * GFP_KERNEL, rather than failing it outright.
+ */
+ spin_lock(&fsvq->lock);
+ if (fsvq->connected) {
+ list_add_tail(&req->list, &fsvq->queued_reqs);
+ inc_in_flight_req(fsvq);
+ schedule_work(&fsvq->dispatch_work);
+ spin_unlock(&fsvq->lock);
+ return;
+ }
+ spin_unlock(&fsvq->lock);
+ ret = -ENOTCONN;
+ }
req->out.h.error = ret;
pr_err("virtio-fs: virtio_fs_enqueue_req() failed %d\n", ret);
--
2.56.1