Re: [PATCH v2] netfs: fix writeback ENOMEM by using __GFP_NOFAIL for rolling buffer
David Howells <[email protected]> Mon, 27 Jul 2026 11:03:32 +0100
| Newsgroups | dev.linux.lists.netfs,org.kernel.vger.linux-fsdevel,org.kernel.vger.linux-kernel |
|---|---|
| Organization | Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 |
| Message-ID | <[email protected]> |
Yun Zhou <[email protected]> wrote: > rolling_buffer_init() uses plain GFP_NOFS for its folio_queue allocation. > In the writeback path this can fail and trigger WARN_ON_ONCE(folio !=3D N= ULL) > in netfs_writepages() when writeback_iter() returns additional dirty foli= os > left unhandled. >=20 > Writeback must not fail with -ENOMEM. Fix this by adding a gfp_t paramete= r > to rolling_buffer_init() and passing GFP_NOFS | __GFP_NOFAIL from the > writeback path, ensuring the allocation always succeeds. Read paths > continue to use plain GFP_NOFS. I don't think this is the correct solution. I think you're right that a gf= p_t needs to be passed into rolling_buffer*(), but I think we need a mempool as well. I have most of the patch for that, but I think I need adjust things so that the read path uses GFP_KERNEL, not GFP_NOFS. David --- commit 3cc9160c12645c38c860e748845cb63b15115078 Author: David Howells <[email protected]> Date: Fri Jul 24 10:24:30 2026 +0100 netfs: Fix folio_queue ENOMEM in writeback by adding a mempool =20 Fix the handling of folio_queue allocation failure in writeback by addi= ng a mempool. The failure caused: =20 folio !=3D NULL WARNING: fs/netfs/write_issue.c:603 at netfs_writepages+0x883/0xa10= fs/netfs/write_issue.c:603, CPU#3: syz.0.17/5919 =20 Fixes: cd0277ed0c18 ("netfs: Use new folio_queue data type and iterator= instead of xarray iter") Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=3D0da43efa72f88bd3a8af Signed-off-by: David Howells <[email protected]> Tested-by: [email protected] cc: Paulo Alcantara <[email protected]> cc: Yun Zhou <[email protected]> cc: Matthew Wilcox <[email protected]> cc: Christoph Hellwig <[email protected]> cc: [email protected] cc: [email protected] diff --git a/fs/netfs/internal.h b/fs/netfs/internal.h index d889caa401dc..420ee7b26580 100644 --- a/fs/netfs/internal.h +++ b/fs/netfs/internal.h @@ -43,6 +43,7 @@ extern struct list_head netfs_io_requests; extern spinlock_t netfs_proc_lock; extern mempool_t netfs_request_pool; extern mempool_t netfs_subrequest_pool; +extern mempool_t netfs_folioq_pool; =20 #ifdef CONFIG_PROC_FS static inline void netfs_proc_add_rreq(struct netfs_io_request *rreq) diff --git a/fs/netfs/main.c b/fs/netfs/main.c index 73da6c9f5777..927badf3989d 100644 --- a/fs/netfs/main.c +++ b/fs/netfs/main.c @@ -28,6 +28,7 @@ static struct kmem_cache *netfs_request_slab; static struct kmem_cache *netfs_subrequest_slab; mempool_t netfs_request_pool; mempool_t netfs_subrequest_pool; +mempool_t netfs_folioq_pool; =20 #ifdef CONFIG_PROC_FS LIST_HEAD(netfs_io_requests); @@ -108,6 +109,9 @@ static int __init netfs_init(void) { =09int ret =3D -ENOMEM; =20 +=09if (mempool_init_kmalloc_pool(&netfs_folioq_pool, 100, sizeof(struct fo= lio_queue)) < 0) +=09=09goto error_folioq_pool; + =09netfs_request_slab =3D kmem_cache_create("netfs_request", =09=09=09=09=09 sizeof(struct netfs_io_request), 0, =09=09=09=09=09 SLAB_HWCACHE_ALIGN | SLAB_ACCOUNT, @@ -160,6 +164,8 @@ static int __init netfs_init(void) error_reqpool: =09kmem_cache_destroy(netfs_request_slab); error_req: +=09mempool_exit(&netfs_folioq_pool); +error_folioq_pool: =09return ret; } fs_initcall(netfs_init); @@ -172,5 +178,6 @@ static void __exit netfs_exit(void) =09kmem_cache_destroy(netfs_subrequest_slab); =09mempool_exit(&netfs_request_pool); =09kmem_cache_destroy(netfs_request_slab); +=09mempool_exit(&netfs_folioq_pool); } module_exit(netfs_exit); diff --git a/fs/netfs/rolling_buffer.c b/fs/netfs/rolling_buffer.c index a17fbf9853a4..48052d77567b 100644 --- a/fs/netfs/rolling_buffer.c +++ b/fs/netfs/rolling_buffer.c @@ -27,7 +27,7 @@ struct folio_queue *netfs_folioq_alloc(unsigned int rreq_= id, gfp_t gfp, { =09struct folio_queue *fq; =20 -=09fq =3D kmalloc_obj(*fq, gfp); +=09fq =3D mempool_alloc(&netfs_folioq_pool, gfp); =09if (fq) { =09=09netfs_stat(&netfs_n_folioq); =09=09folioq_init(fq, rreq_id); @@ -50,7 +50,7 @@ void netfs_folioq_free(struct folio_queue *folioq, { =09trace_netfs_folioq(folioq, trace); =09netfs_stat_d(&netfs_n_folioq); -=09kfree(folioq); +=09mempool_free(folioq, &netfs_folioq_pool); } EXPORT_SYMBOL(netfs_folioq_free); =20