From: Miklos Szeredi <mszeredi@redhat.com>
To: fuse-devel@lists.linux.dev, virtualization@lists.linux.dev
Cc: Li Wang <liwang@kylinos.cn>,
German Maglione <gmaglione@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [PATCH v2 3/4] virtiofs: retry request submission from the worker on -ENOMEM
Date: Mon, 30 Nov 2026 15:37:19 +0100 [thread overview]
Message-ID: <20261130143728.326871-3-mszeredi@redhat.com> (raw)
In-Reply-To: <20261130143728.326871-1-mszeredi@redhat.com>
virtio_fs_send_req() enqueues with GFP_ATOMIC, because it may be called
with fc->chan->bg_lock held. The sg arrays and, via
copy_args_to_argbuf(), the bounce buffer are allocated 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.
virtqueue_add_sgs() can also report -ENOMEM, but only for a DMA mapping
failure, which the retry will not fix (failure to allocate the indirect
descriptor table falls back to direct descriptors and does not return
-ENOMEM). Such a request is retried once and then ended with -ENOMEM by
the worker, so the two cases are not worth telling apart.
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")
Reviewed-by: Li Wang <liwang@kylinos.cn>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
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
next prev parent reply other threads:[~2026-11-30 14:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 14:37 [PATCH v2 1/4] virtiofs: fix DAX range leak on unmount Miklos Szeredi
2026-11-30 14:37 ` [PATCH v2 2/4] virtiofs: don't abort DAX removemapping on allocation failure Miklos Szeredi
2026-12-01 8:11 ` Li Wang
2026-12-01 9:03 ` Miklos Szeredi
2026-11-30 14:37 ` Miklos Szeredi [this message]
2026-11-30 14:37 ` [PATCH v2 4/4] virtiofs: fix forget leak on submount unmount Miklos Szeredi
2026-11-30 14:54 ` sashiko-bot
2026-11-30 14:54 ` [PATCH v2 1/4] virtiofs: fix DAX range leak on unmount sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130143728.326871-3-mszeredi@redhat.com \
--to=mszeredi@redhat.com \
--cc=fuse-devel@lists.linux.dev \
--cc=gmaglione@redhat.com \
--cc=liwang@kylinos.cn \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.