* [PATCH v2 0/4] gfs2: stop using struct page in the log code
@ 2026-11-24 21:04 Tal Zussman
2026-11-24 21:04 ` [PATCH v2 1/4] gfs2: make the log page pool per superblock Tal Zussman
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Tal Zussman @ 2026-11-24 21:04 UTC (permalink / raw)
To: Andreas Gruenbacher
Cc: gfs2, linux-kernel, Matthew Wilcox (Oracle), Tal Zussman
This series gets rid of the remaining struct page usage in the gfs2 log
code.
The log headers, descriptors, revoke blocks, and escaped block copies
are allocated as pages from a mempool, and they end up in the same bios
as the page cache buffers being journaled. The completion handler then
calls page_folio() on every segment to figure out which kind it is
looking at. That won't work once memdescs land and those pool pages are
no longer folios.
Patch 1 gives each superblock its own mempool for these blocks in place
of the global one. Patch 2 moves the blocks over to block-sized kmalloc
buffers from that pool, with their own bios and completion handler. As a
result each descriptor block is now submitted as its own bio, so patch 3
adds a plug around the log flush to let the block layer merge them back
together. Patch 4 cleans up the leftover page references in the log
code.
Tested with fio 4K write+fsync on gfs2 over virtio-blk and null_blk.
Without an I/O scheduler, patch 2 adds one write request per log flush
(196.7k to 229.5k for 32k fsyncs) and ~10 us to the p99.9 fsync latency
on null_blk (41 us to 51 us); the plug in patch 3 merges them and
restores both performance numbers to the baseline. With mq-deadline
nothing changes.
With a 1k block size on 4k pages the result is the same. Patch 1 changes
nothing by itself, patch 2 takes the write requests for 32k fsyncs from
199.5k to 232.3k, and patch 3 brings them back to 199.5k.
---
Changes in v2:
- Patch 1 (new): Make the mempool per-superblock, per Andreas.
- Patch 2: Make the per-superblock mempool be block-sized, rather than
page-sized, per Andreas.
- Link to v1: https://patch.msgid.link/20261117-gfs2-log-folio-v1-0-35db3db42e35@columbia.edu
---
Tal Zussman (4):
gfs2: make the log page pool per superblock
gfs2: stop using pages for log buffers
gfs2: plug the log writes of a flush
gfs2: remove the remaining page references in the log code
fs/gfs2/bmap.h | 1 -
fs/gfs2/incore.h | 2 +
fs/gfs2/log.c | 19 ++---
fs/gfs2/lops.c | 222 +++++++++++++++++++++++++++++++--------------------
fs/gfs2/lops.h | 6 +-
fs/gfs2/main.c | 8 --
fs/gfs2/ops_fstype.c | 6 ++
fs/gfs2/util.c | 1 -
fs/gfs2/util.h | 3 -
9 files changed, 157 insertions(+), 111 deletions(-)
---
base-commit: a009501c151f7d19519312ccfa2070d30d62b249
change-id: 20261014-gfs2-log-folio-274b84f5cc07
Best regards,
--
Tal Zussman <tz2294@columbia.edu>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/4] gfs2: make the log page pool per superblock
2026-11-24 21:04 [PATCH v2 0/4] gfs2: stop using struct page in the log code Tal Zussman
@ 2026-11-24 21:04 ` Tal Zussman
2026-11-24 21:16 ` sashiko-bot
2026-11-24 21:04 ` [PATCH v2 2/4] gfs2: stop using pages for log buffers Tal Zussman
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Tal Zussman @ 2026-11-24 21:04 UTC (permalink / raw)
To: Andreas Gruenbacher
Cc: gfs2, linux-kernel, Matthew Wilcox (Oracle), Tal Zussman
The log headers, descriptors, revoke blocks, and escaped block copies
come from gfs2_page_pool, a single mempool shared by every mounted
filesystem. Give each superblock a pool of its own, sd_log_buf_pool. A
per-superblock pool can hold buffers of the filesystem's block size,
which a global one cannot.
The pool is set up in gfs2_fill_super() once the superblock has been
read and is destroyed in free_sbd(). Its elements are still pages, so
each mount now reserves 64 pages of its own.
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
fs/gfs2/incore.h | 2 ++
fs/gfs2/log.c | 2 +-
fs/gfs2/lops.c | 10 +++++-----
fs/gfs2/main.c | 8 --------
fs/gfs2/ops_fstype.c | 5 +++++
fs/gfs2/util.c | 1 -
fs/gfs2/util.h | 3 ---
7 files changed, 13 insertions(+), 18 deletions(-)
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index 1ff19f87d3bd..60748b99d39a 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -21,6 +21,7 @@
#include <linux/lockref.h>
#include <linux/rhashtable.h>
#include <linux/mutex.h>
+#include <linux/mempool.h>
#define DIO_WAIT 0x00000010
#define DIO_METADATA 0x00000020
@@ -846,6 +847,7 @@ struct gfs2_sbd {
struct rw_semaphore sd_log_flush_lock;
atomic_t sd_log_in_flight;
wait_queue_head_t sd_log_flush_wait;
+ mempool_t sd_log_buf_pool;
int sd_log_error; /* First log error */
unsigned int sd_log_tail;
diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index 1baaaf30c4fa..e7076db3ba46 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -850,7 +850,7 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
if (gfs2_withdrawn(sdp))
return;
- page = mempool_alloc(gfs2_page_pool, GFP_NOIO);
+ page = mempool_alloc(&sdp->sd_log_buf_pool, GFP_NOIO);
lh = page_address(page);
clear_page(lh);
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index 657edd406dd1..7a2c29652fec 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -229,7 +229,7 @@ static void gfs2_end_log_write(struct bio *bio)
gfs2_end_log_write_bh(sdp, folio, bvec->bv_offset,
bvec->bv_len, bio->bi_status);
else
- mempool_free(page, gfs2_page_pool);
+ mempool_free(page, &sdp->sd_log_buf_pool);
}
bio_put(bio);
@@ -377,7 +377,7 @@ static void gfs2_log_write_bh(struct gfs2_sbd *sdp, struct buffer_head *bh)
* @page: The struct page
*
* This writes the first block-sized part of the page into the log. Note
- * that the page must have been allocated from the gfs2_page_pool mempool
+ * that the page must have been allocated from the sd_log_buf_pool mempool
* and that after this has been called, ownership has been transferred and
* the page may be freed at any time.
*/
@@ -607,7 +607,7 @@ int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head)
static struct page *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type,
u32 ld_length, u32 ld_data1)
{
- struct page *page = mempool_alloc(gfs2_page_pool, GFP_NOIO);
+ struct page *page = mempool_alloc(&sdp->sd_log_buf_pool, GFP_NOIO);
struct gfs2_log_descriptor *ld = page_address(page);
clear_page(ld);
ld->ld_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
@@ -696,7 +696,7 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
if (buffer_escaped(bd2->bd_bh)) {
void *p;
- page = mempool_alloc(gfs2_page_pool, GFP_NOIO);
+ page = mempool_alloc(&sdp->sd_log_buf_pool, GFP_NOIO);
p = page_address(page);
memcpy_from_folio(p, bd2->bd_bh->b_folio,
bh_offset(bd2->bd_bh),
@@ -872,7 +872,7 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
if (offset + sizeof(u64) > sdp->sd_sb.sb_bsize) {
gfs2_log_write_page(sdp, page);
- page = mempool_alloc(gfs2_page_pool, GFP_NOIO);
+ page = mempool_alloc(&sdp->sd_log_buf_pool, GFP_NOIO);
mh = page_address(page);
clear_page(mh);
mh->mh_magic = cpu_to_be32(GFS2_MAGIC);
diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c
index a607e98eb45f..8a45b2e9b618 100644
--- a/fs/gfs2/main.c
+++ b/fs/gfs2/main.c
@@ -16,7 +16,6 @@
#include <linux/rcupdate.h>
#include <linux/rculist_bl.h>
#include <linux/atomic.h>
-#include <linux/mempool.h>
#include "gfs2.h"
#include "incore.h"
@@ -166,10 +165,6 @@ static int __init init_gfs2_fs(void)
if (!gfs2_freeze_wq)
goto fail_wq3;
- gfs2_page_pool = mempool_create_page_pool(64, 0);
- if (!gfs2_page_pool)
- goto fail_mempool;
-
gfs2_register_debugfs();
error = register_filesystem(&gfs2_fs_type);
if (error)
@@ -187,8 +182,6 @@ static int __init init_gfs2_fs(void)
fail_fs2:
unregister_filesystem(&gfs2_fs_type);
fail_fs1:
- mempool_destroy(gfs2_page_pool);
-fail_mempool:
destroy_workqueue(gfs2_freeze_wq);
fail_wq3:
destroy_workqueue(gfs2_control_wq);
@@ -240,7 +233,6 @@ static void __exit exit_gfs2_fs(void)
rcu_barrier();
- mempool_destroy(gfs2_page_pool);
kmem_cache_destroy(gfs2_trans_cachep);
kmem_cache_destroy(gfs2_qadata_cachep);
kmem_cache_destroy(gfs2_quotad_cachep);
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 6ec47376aecf..f62a893ce5a2 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -67,6 +67,7 @@ void free_sbd(struct gfs2_sbd *sdp)
{
struct super_block *sb = sdp->sd_vfs;
+ mempool_exit(&sdp->sd_log_buf_pool);
free_percpu(sdp->sd_lkstats);
sb->s_fs_info = NULL;
kfree(sdp);
@@ -1218,6 +1219,10 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
if (error)
goto fail_locking;
+ error = mempool_init_page_pool(&sdp->sd_log_buf_pool, 64, 0);
+ if (error)
+ goto fail_sb;
+
/* Turn rgrplvb on by default if fs format is recent enough */
if (!sdp->sd_args.ar_got_rgrplvb && sdp->sd_sb.sb_fs_format > 1801)
sdp->sd_args.ar_rgrplvb = 1;
diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c
index 529c3ec37a18..d42db8a9f5aa 100644
--- a/fs/gfs2/util.c
+++ b/fs/gfs2/util.c
@@ -34,7 +34,6 @@ struct kmem_cache *gfs2_rgrpd_cachep __read_mostly;
struct kmem_cache *gfs2_quotad_cachep __read_mostly;
struct kmem_cache *gfs2_qadata_cachep __read_mostly;
struct kmem_cache *gfs2_trans_cachep __read_mostly;
-mempool_t *gfs2_page_pool __read_mostly;
void gfs2_assert_i(struct gfs2_sbd *sdp)
{
diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h
index ffcc47d6b0b4..0179ddcd4c22 100644
--- a/fs/gfs2/util.h
+++ b/fs/gfs2/util.h
@@ -12,8 +12,6 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#endif
-#include <linux/mempool.h>
-
#include "incore.h"
#define fs_emerg(fs, fmt, ...) \
@@ -165,7 +163,6 @@ extern struct kmem_cache *gfs2_rgrpd_cachep;
extern struct kmem_cache *gfs2_quotad_cachep;
extern struct kmem_cache *gfs2_qadata_cachep;
extern struct kmem_cache *gfs2_trans_cachep;
-extern mempool_t *gfs2_page_pool;
extern struct workqueue_struct *gfs2_control_wq;
static inline unsigned int gfs2_tune_get_i(struct gfs2_tune *gt,
--
2.39.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/4] gfs2: stop using pages for log buffers
2026-11-24 21:04 [PATCH v2 0/4] gfs2: stop using struct page in the log code Tal Zussman
2026-11-24 21:04 ` [PATCH v2 1/4] gfs2: make the log page pool per superblock Tal Zussman
@ 2026-11-24 21:04 ` Tal Zussman
2026-11-24 21:21 ` sashiko-bot
2026-11-24 21:04 ` [PATCH v2 3/4] gfs2: plug the log writes of a flush Tal Zussman
2026-11-24 21:04 ` [PATCH v2 4/4] gfs2: remove the remaining page references in the log code Tal Zussman
3 siblings, 1 reply; 8+ messages in thread
From: Tal Zussman @ 2026-11-24 21:04 UTC (permalink / raw)
To: Andreas Gruenbacher
Cc: gfs2, linux-kernel, Matthew Wilcox (Oracle), Tal Zussman
The log headers, descriptors, revoke blocks, and escaped block copies
come from a mempool of pages and share a bio with the buffer heads being
journaled. The completion handler tells the two apart by checking each
segment for buffers, which treats a pool page as a folio. That won't
work once memdescs give these pages a type of their own.
Make the per-superblock pool a kmalloc mempool of block-sized buffers
instead, and add them to the bio with bio_add_virt_nofail(). Give the
pool blocks their own completion handler, and start a new bio whenever
the handler changes so that a bio only holds one kind of segment.
gfs2_log_write() now takes a folio, so the log write path no longer uses
struct page.
Each descriptor and each escaped block copy is now a bio of its own.
They are contiguous and merge under an I/O scheduler, but the flush
path doesn't plug, so without a scheduler they reach the device as
separate writes.
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
fs/gfs2/log.c | 10 +--
fs/gfs2/lops.c | 204 ++++++++++++++++++++++++++++++++-------------------
fs/gfs2/lops.h | 6 +-
fs/gfs2/ops_fstype.c | 3 +-
4 files changed, 136 insertions(+), 87 deletions(-)
diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index e7076db3ba46..2f9f20b40adc 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -841,7 +841,6 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
{
struct gfs2_log_header *lh;
u32 hash, crc;
- struct page *page;
struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
struct timespec64 tv;
struct super_block *sb = sdp->sd_vfs;
@@ -850,9 +849,8 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
if (gfs2_withdrawn(sdp))
return;
- page = mempool_alloc(&sdp->sd_log_buf_pool, GFP_NOIO);
- lh = page_address(page);
- clear_page(lh);
+ lh = mempool_alloc(&sdp->sd_log_buf_pool, GFP_NOIO);
+ memset(lh, 0, sb->s_blocksize);
lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH);
@@ -905,8 +903,8 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
sb->s_blocksize - LH_V1_SIZE - 4);
lh->lh_crc = cpu_to_be32(crc);
- gfs2_log_write(sdp, jd, page, sb->s_blocksize, 0, dblock,
- REQ_OP_WRITE | op_flags);
+ gfs2_log_write_buf(sdp, jd, lh, sb->s_blocksize, dblock,
+ REQ_OP_WRITE | op_flags);
gfs2_log_submit_write(&jd->jd_log_bio);
}
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index 7a2c29652fec..156d7c6341ca 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -196,45 +196,70 @@ static void gfs2_end_log_write_bh(struct gfs2_sbd *sdp, struct folio *folio,
} while (bh && size);
}
+static void gfs2_log_write_error(struct bio *bio)
+{
+ struct gfs2_sbd *sdp = bio->bi_private;
+ int err = blk_status_to_errno(bio->bi_status);
+
+ if (!cmpxchg(&sdp->sd_log_error, 0, err))
+ fs_err(sdp, "Error %d writing to journal, jid=%u\n",
+ err, sdp->sd_jdesc->jd_jid);
+ gfs2_withdraw(sdp);
+}
+
+static void gfs2_log_write_done(struct bio *bio)
+{
+ struct gfs2_sbd *sdp = bio->bi_private;
+
+ bio_put(bio);
+ if (atomic_dec_and_test(&sdp->sd_log_in_flight))
+ wake_up(&sdp->sd_log_flush_wait);
+}
+
/**
- * gfs2_end_log_write - end of i/o to the log
+ * gfs2_end_log_write - end of I/O to the log for buffers
* @bio: The bio
*
- * Each bio_vec contains either data from the pagecache or data
- * relating to the log itself. Here we iterate over the bio_vec
- * array, processing both kinds of data.
- *
+ * Every folio in the bio comes from the page cache. Unlock the buffers
+ * that were written.
*/
static void gfs2_end_log_write(struct bio *bio)
{
struct gfs2_sbd *sdp = bio->bi_private;
- struct bio_vec *bvec;
- struct bvec_iter_all iter_all;
+ struct folio_iter fi;
- if (bio->bi_status) {
- int err = blk_status_to_errno(bio->bi_status);
+ if (bio->bi_status)
+ gfs2_log_write_error(bio);
- if (!cmpxchg(&sdp->sd_log_error, 0, err))
- fs_err(sdp, "Error %d writing to journal, jid=%u\n",
- err, sdp->sd_jdesc->jd_jid);
- gfs2_withdraw(sdp);
- }
+ bio_for_each_folio_all(fi, bio)
+ gfs2_end_log_write_bh(sdp, fi.folio, fi.offset, fi.length,
+ bio->bi_status);
- bio_for_each_segment_all(bvec, bio, iter_all) {
- struct page *page = bvec->bv_page;
- struct folio *folio = page_folio(page);
+ gfs2_log_write_done(bio);
+}
- if (folio && folio_buffers(folio))
- gfs2_end_log_write_bh(sdp, folio, bvec->bv_offset,
- bvec->bv_len, bio->bi_status);
- else
- mempool_free(page, &sdp->sd_log_buf_pool);
- }
+/**
+ * gfs2_end_log_write_buf - end of I/O to the log for log blocks
+ * @bio: The bio
+ *
+ * Every segment in the bio is a block from the log buffer mempool.
+ * Return them to the pool.
+ */
- bio_put(bio);
- if (atomic_dec_and_test(&sdp->sd_log_in_flight))
- wake_up(&sdp->sd_log_flush_wait);
+static void gfs2_end_log_write_buf(struct bio *bio)
+{
+ struct gfs2_sbd *sdp = bio->bi_private;
+ struct bio_vec *bvec;
+ struct bvec_iter_all iter_all;
+
+ if (bio->bi_status)
+ gfs2_log_write_error(bio);
+
+ bio_for_each_segment_all(bvec, bio, iter_all)
+ mempool_free(bvec_virt(bvec), &sdp->sd_log_buf_pool);
+
+ gfs2_log_write_done(bio);
}
/**
@@ -291,9 +316,9 @@ static struct bio *gfs2_log_alloc_bio(struct gfs2_sbd *sdp, u64 blkno,
* @flush: Always flush the current bio and allocate a new one?
*
* If there is a cached bio, then if the next block number is sequential
- * with the previous one, return it, otherwise flush the bio to the
- * device. If there is no cached bio, or we just flushed it, then
- * allocate a new one.
+ * with the previous one and the bio has the same completion handler,
+ * return it, otherwise flush the bio to the device. If there is no
+ * cached bio, or we just flushed it, then allocate a new one.
*
* Returns: The bio to use for log writes
*/
@@ -309,7 +334,7 @@ static struct bio *gfs2_log_get_bio(struct gfs2_sbd *sdp, u64 blkno,
nblk = bio_end_sector(bio);
nblk >>= sdp->sd_fsb2bb_shift;
- if (blkno == nblk && !flush)
+ if (blkno == nblk && bio->bi_end_io == end_io && !flush)
return bio;
gfs2_log_submit_write(biop);
}
@@ -319,38 +344,63 @@ static struct bio *gfs2_log_get_bio(struct gfs2_sbd *sdp, u64 blkno,
}
/**
- * gfs2_log_write - write to log
+ * gfs2_log_write - write a folio segment to the log
* @sdp: the filesystem
* @jd: The journal descriptor
- * @page: the page to write
+ * @folio: the folio to write
* @size: the size of the data to write
- * @offset: the offset within the page
+ * @offset: the offset within the folio
* @blkno: block number of the log entry
* @opf: REQ_OP | op_flags
*
- * Try and add the page segment to the current bio. If that fails,
+ * Try and add the folio segment to the current bio. If that fails,
* submit the current bio to the device and create a new one, and
- * then add the page segment to that.
+ * then add the folio segment to that.
*/
-void gfs2_log_write(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
- struct page *page, unsigned size, unsigned offset,
- u64 blkno, blk_opf_t opf)
+static void gfs2_log_write(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
+ struct folio *folio, unsigned int size,
+ unsigned int offset, u64 blkno, blk_opf_t opf)
{
struct bio *bio;
- int ret;
bio = gfs2_log_get_bio(sdp, blkno, &jd->jd_log_bio, opf,
gfs2_end_log_write, false);
- ret = bio_add_page(bio, page, size, offset);
- if (ret == 0) {
+ if (!bio_add_folio(bio, folio, size, offset)) {
bio = gfs2_log_get_bio(sdp, blkno, &jd->jd_log_bio,
opf, gfs2_end_log_write, true);
- ret = bio_add_page(bio, page, size, offset);
- WARN_ON(ret == 0);
+ WARN_ON(!bio_add_folio(bio, folio, size, offset));
}
}
+/**
+ * gfs2_log_write_buf - write a log buffer to the log
+ * @sdp: the filesystem
+ * @jd: The journal descriptor
+ * @buf: the buffer to write, from the log buffer mempool
+ * @size: the size of the data to write
+ * @blkno: block number of the log entry
+ * @opf: REQ_OP | op_flags
+ *
+ * Like gfs2_log_write(), for a block allocated from sd_log_buf_pool.
+ * Ownership of the buffer passes to the bio, which returns it to the
+ * pool on completion.
+ */
+
+void gfs2_log_write_buf(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
+ void *buf, unsigned int size, u64 blkno,
+ blk_opf_t opf)
+{
+ struct bio *bio;
+
+ bio = gfs2_log_get_bio(sdp, blkno, &jd->jd_log_bio, opf,
+ gfs2_end_log_write_buf, false);
+ if (bio->bi_vcnt >= bio->bi_max_vecs)
+ bio = gfs2_log_get_bio(sdp, blkno, &jd->jd_log_bio,
+ opf, gfs2_end_log_write_buf, true);
+ bio_add_virt_nofail(bio, buf, size);
+}
+
/**
* gfs2_log_write_bh - write a buffer's content to the log
* @sdp: The super block
@@ -367,30 +417,30 @@ static void gfs2_log_write_bh(struct gfs2_sbd *sdp, struct buffer_head *bh)
dblock = gfs2_log_bmap(sdp->sd_jdesc, sdp->sd_log_flush_head);
gfs2_log_incr_head(sdp);
- gfs2_log_write(sdp, sdp->sd_jdesc, folio_page(bh->b_folio, 0),
- bh->b_size, bh_offset(bh), dblock, REQ_OP_WRITE);
+ gfs2_log_write(sdp, sdp->sd_jdesc, bh->b_folio, bh->b_size,
+ bh_offset(bh), dblock, REQ_OP_WRITE);
}
/**
- * gfs2_log_write_page - write one block stored in a page, into the log
+ * gfs2_log_write_block - write one block stored in a log buffer, into the log
* @sdp: The superblock
- * @page: The struct page
+ * @buf: The buffer
*
- * This writes the first block-sized part of the page into the log. Note
- * that the page must have been allocated from the sd_log_buf_pool mempool
- * and that after this has been called, ownership has been transferred and
- * the page may be freed at any time.
+ * This writes the first block-sized part of the buffer into the log. Note
+ * that the buffer must have been allocated from the sd_log_buf_pool
+ * mempool and that after this has been called, ownership has been
+ * transferred and the buffer may be freed at any time.
*/
-static void gfs2_log_write_page(struct gfs2_sbd *sdp, struct page *page)
+static void gfs2_log_write_block(struct gfs2_sbd *sdp, void *buf)
{
struct super_block *sb = sdp->sd_vfs;
u64 dblock;
dblock = gfs2_log_bmap(sdp->sd_jdesc, sdp->sd_log_flush_head);
gfs2_log_incr_head(sdp);
- gfs2_log_write(sdp, sdp->sd_jdesc, page, sb->s_blocksize, 0, dblock,
- REQ_OP_WRITE);
+ gfs2_log_write_buf(sdp, sdp->sd_jdesc, buf, sb->s_blocksize, dblock,
+ REQ_OP_WRITE);
}
/**
@@ -604,12 +654,14 @@ int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head)
return ret;
}
-static struct page *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type,
- u32 ld_length, u32 ld_data1)
+static struct gfs2_log_descriptor *gfs2_get_log_desc(struct gfs2_sbd *sdp,
+ u32 ld_type, u32 ld_length,
+ u32 ld_data1)
{
- struct page *page = mempool_alloc(&sdp->sd_log_buf_pool, GFP_NOIO);
- struct gfs2_log_descriptor *ld = page_address(page);
- clear_page(ld);
+ struct gfs2_log_descriptor *ld;
+
+ ld = mempool_alloc(&sdp->sd_log_buf_pool, GFP_NOIO);
+ memset(ld, 0, sdp->sd_sb.sb_bsize);
ld->ld_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
ld->ld_header.mh_type = cpu_to_be32(GFS2_METATYPE_LD);
ld->ld_header.mh_format = cpu_to_be32(GFS2_FORMAT_LD);
@@ -617,7 +669,7 @@ static struct page *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type,
ld->ld_length = cpu_to_be32(ld_length);
ld->ld_data1 = cpu_to_be32(ld_data1);
ld->ld_data2 = 0;
- return page;
+ return ld;
}
static void gfs2_check_magic(struct buffer_head *bh)
@@ -652,7 +704,6 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
{
struct gfs2_log_descriptor *ld;
struct gfs2_bufdata *bd1 = NULL, *bd2;
- struct page *page;
unsigned int num;
unsigned n;
__be64 *ptr;
@@ -665,10 +716,9 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
if (total > limit)
num = limit;
spin_unlock(&sdp->sd_log_lock);
- page = gfs2_get_log_desc(sdp,
- is_databuf ? GFS2_LOG_DESC_JDATA :
- GFS2_LOG_DESC_METADATA, num + 1, num);
- ld = page_address(page);
+ ld = gfs2_get_log_desc(sdp,
+ is_databuf ? GFS2_LOG_DESC_JDATA :
+ GFS2_LOG_DESC_METADATA, num + 1, num);
spin_lock(&sdp->sd_log_lock);
ptr = (__be64 *)(ld + 1);
@@ -684,7 +734,7 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
}
spin_unlock(&sdp->sd_log_lock);
- gfs2_log_write_page(sdp, page);
+ gfs2_log_write_block(sdp, ld);
spin_lock(&sdp->sd_log_lock);
n = 0;
@@ -696,8 +746,7 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
if (buffer_escaped(bd2->bd_bh)) {
void *p;
- page = mempool_alloc(&sdp->sd_log_buf_pool, GFP_NOIO);
- p = page_address(page);
+ p = mempool_alloc(&sdp->sd_log_buf_pool, GFP_NOIO);
memcpy_from_folio(p, bd2->bd_bh->b_folio,
bh_offset(bd2->bd_bh),
bd2->bd_bh->b_size);
@@ -705,7 +754,7 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
clear_buffer_escaped(bd2->bd_bh);
unlock_buffer(bd2->bd_bh);
brelse(bd2->bd_bh);
- gfs2_log_write_page(sdp, page);
+ gfs2_log_write_block(sdp, p);
} else {
gfs2_log_write_bh(sdp, bd2->bd_bh);
}
@@ -856,7 +905,7 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
struct gfs2_meta_header *mh;
unsigned int offset;
struct gfs2_bufdata *bd;
- struct page *page;
+ void *buf;
unsigned int length;
gfs2_flush_revokes(sdp);
@@ -864,29 +913,30 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
return;
length = gfs2_struct2blk(sdp, sdp->sd_log_num_revoke);
- page = gfs2_get_log_desc(sdp, GFS2_LOG_DESC_REVOKE, length, sdp->sd_log_num_revoke);
+ buf = gfs2_get_log_desc(sdp, GFS2_LOG_DESC_REVOKE, length,
+ sdp->sd_log_num_revoke);
offset = sizeof(struct gfs2_log_descriptor);
list_for_each_entry(bd, &sdp->sd_log_revokes, bd_list) {
sdp->sd_log_num_revoke--;
if (offset + sizeof(u64) > sdp->sd_sb.sb_bsize) {
- gfs2_log_write_page(sdp, page);
- page = mempool_alloc(&sdp->sd_log_buf_pool, GFP_NOIO);
- mh = page_address(page);
- clear_page(mh);
+ gfs2_log_write_block(sdp, buf);
+ buf = mempool_alloc(&sdp->sd_log_buf_pool, GFP_NOIO);
+ mh = buf;
+ memset(mh, 0, sdp->sd_sb.sb_bsize);
mh->mh_magic = cpu_to_be32(GFS2_MAGIC);
mh->mh_type = cpu_to_be32(GFS2_METATYPE_LB);
mh->mh_format = cpu_to_be32(GFS2_FORMAT_LB);
offset = sizeof(struct gfs2_meta_header);
}
- *(__be64 *)(page_address(page) + offset) = cpu_to_be64(bd->bd_blkno);
+ *(__be64 *)(buf + offset) = cpu_to_be64(bd->bd_blkno);
offset += sizeof(u64);
}
gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke);
- gfs2_log_write_page(sdp, page);
+ gfs2_log_write_block(sdp, buf);
}
void gfs2_drain_revokes(struct gfs2_sbd *sdp)
diff --git a/fs/gfs2/lops.h b/fs/gfs2/lops.h
index 772557b63b48..c1d9e6fef7ac 100644
--- a/fs/gfs2/lops.h
+++ b/fs/gfs2/lops.h
@@ -14,9 +14,9 @@ extern const struct gfs2_log_operations *gfs2_log_ops[];
void gfs2_log_incr_head(struct gfs2_sbd *sdp);
u64 gfs2_log_bmap(struct gfs2_jdesc *jd, unsigned int lbn);
-void gfs2_log_write(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
- struct page *page, unsigned size, unsigned offset,
- u64 blkno, blk_opf_t opf);
+void gfs2_log_write_buf(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
+ void *buf, unsigned int size, u64 blkno,
+ blk_opf_t opf);
void gfs2_log_submit_write(struct bio **biop);
void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh);
int gfs2_find_jhead(struct gfs2_jdesc *jd,
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index f62a893ce5a2..f71174273abf 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -1219,7 +1219,8 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
if (error)
goto fail_locking;
- error = mempool_init_page_pool(&sdp->sd_log_buf_pool, 64, 0);
+ error = mempool_init_kmalloc_pool(&sdp->sd_log_buf_pool, 64,
+ sdp->sd_sb.sb_bsize);
if (error)
goto fail_sb;
--
2.39.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 3/4] gfs2: plug the log writes of a flush
2026-11-24 21:04 [PATCH v2 0/4] gfs2: stop using struct page in the log code Tal Zussman
2026-11-24 21:04 ` [PATCH v2 1/4] gfs2: make the log page pool per superblock Tal Zussman
2026-11-24 21:04 ` [PATCH v2 2/4] gfs2: stop using pages for log buffers Tal Zussman
@ 2026-11-24 21:04 ` Tal Zussman
2026-11-24 21:04 ` [PATCH v2 4/4] gfs2: remove the remaining page references in the log code Tal Zussman
3 siblings, 0 replies; 8+ messages in thread
From: Tal Zussman @ 2026-11-24 21:04 UTC (permalink / raw)
To: Andreas Gruenbacher
Cc: gfs2, linux-kernel, Matthew Wilcox (Oracle), Tal Zussman
__gfs2_log_flush() submits the log blocks of a transaction as several
bios. lops_before_commit() starts a new bio whenever the next block is
not contiguous with the last one or has a different completion handler,
so each descriptor block is a bio of its own. Most of these bios are
contiguous on disk, but the flush does not plug, so without an I/O
scheduler each of them reaches the device as a separate write.
Plug around lops_before_commit() and the submission of the last bio, so
that the block layer can merge the contiguous bios into fewer requests.
The log header is still written after the plug is finished.
With fio 4K write+fsync and no I/O scheduler, this takes the write
requests for 32k fsyncs from 229.5k back to 196.7k, and the p99.9 fsync
latency on null_blk from 51 us back to 41 us.
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
fs/gfs2/log.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index 2f9f20b40adc..f7bcbb51ebe3 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -1088,6 +1088,7 @@ static void __gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl,
bool frozen = test_bit(SDF_FROZEN, &sdp->sd_flags);
unsigned int first_log_head;
unsigned int reserved_revokes = 0;
+ struct blk_plug plug;
trace_gfs2_log_flush(sdp, 1, flags);
@@ -1148,11 +1149,13 @@ static void __gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl,
gfs2_ordered_write(sdp);
if (gfs2_withdrawn(sdp))
goto out_withdraw;
+
+ /* Plug so that the contiguous log bios merge into fewer requests. */
+ blk_start_plug(&plug);
lops_before_commit(sdp, tr);
- if (gfs2_withdrawn(sdp))
- goto out_withdraw;
- if (sdp->sd_jdesc)
+ if (!gfs2_withdrawn(sdp) && sdp->sd_jdesc)
gfs2_log_submit_write(&sdp->sd_jdesc->jd_log_bio);
+ blk_finish_plug(&plug);
if (gfs2_withdrawn(sdp))
goto out_withdraw;
--
2.39.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 4/4] gfs2: remove the remaining page references in the log code
2026-11-24 21:04 [PATCH v2 0/4] gfs2: stop using struct page in the log code Tal Zussman
` (2 preceding siblings ...)
2026-11-24 21:04 ` [PATCH v2 3/4] gfs2: plug the log writes of a flush Tal Zussman
@ 2026-11-24 21:04 ` Tal Zussman
3 siblings, 0 replies; 8+ messages in thread
From: Tal Zussman @ 2026-11-24 21:04 UTC (permalink / raw)
To: Andreas Gruenbacher
Cc: gfs2, linux-kernel, Matthew Wilcox (Oracle), Tal Zussman
gfs2_jhead_process_page() takes a folio, and the comments around it and
gfs2_end_log_read() still describe folios as pages. Rename it to
gfs2_jhead_process_folio() and update the comments.
Drop the struct page forward declaration from bmap.h as well, which has
had no user since the unstuff path was converted.
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
fs/gfs2/bmap.h | 1 -
fs/gfs2/lops.c | 18 +++++++++---------
2 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/fs/gfs2/bmap.h b/fs/gfs2/bmap.h
index e3d6efdfd890..7b44cc9c742c 100644
--- a/fs/gfs2/bmap.h
+++ b/fs/gfs2/bmap.h
@@ -13,7 +13,6 @@
struct inode;
struct gfs2_inode;
-struct page;
/**
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index 156d7c6341ca..000be5ec54a3 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -447,7 +447,7 @@ static void gfs2_log_write_block(struct gfs2_sbd *sdp, void *buf)
* gfs2_end_log_read - end I/O callback for reads from the log
* @bio: The bio
*
- * Simply unlock the pages in the bio. The main thread will wait on them and
+ * Simply unlock the folios in the bio. The main thread will wait on them and
* process them in order as necessary.
*/
static void gfs2_end_log_read(struct bio *bio)
@@ -465,7 +465,7 @@ static void gfs2_end_log_read(struct bio *bio)
}
/**
- * gfs2_jhead_folio_search - Look for the journal head in a given page.
+ * gfs2_jhead_folio_search - Look for the journal head in a given folio.
* @jd: The journal descriptor
* @head: The journal head to start from
* @folio: The folio to look in
@@ -499,9 +499,9 @@ static bool gfs2_jhead_folio_search(struct gfs2_jdesc *jd,
}
/**
- * gfs2_jhead_process_page - Search/cleanup a page
+ * gfs2_jhead_process_folio - Search/cleanup a folio
* @jd: The journal descriptor
- * @index: Index of the page to look into
+ * @index: Index of the folio to look into
* @head: The journal head to start from
* @done: If set, perform only cleanup, else search and set if found.
*
@@ -518,9 +518,9 @@ static bool gfs2_jhead_folio_search(struct gfs2_jdesc *jd,
* our references to the folio.
*/
-static void gfs2_jhead_process_page(struct gfs2_jdesc *jd, unsigned long index,
- struct gfs2_log_header_host *head,
- bool *done)
+static void gfs2_jhead_process_folio(struct gfs2_jdesc *jd, unsigned long index,
+ struct gfs2_log_header_host *head,
+ bool *done)
{
struct folio *folio;
@@ -631,7 +631,7 @@ int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head)
continue;
}
- gfs2_jhead_process_page(jd, blocks_read >> shift, head, &done);
+ gfs2_jhead_process_folio(jd, blocks_read >> shift, head, &done);
blocks_read += PAGE_SIZE >> bsize_shift;
if (done)
goto out; /* found */
@@ -642,7 +642,7 @@ int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head)
if (bio)
submit_bio(bio);
while (blocks_read < block) {
- gfs2_jhead_process_page(jd, blocks_read >> shift, head, &done);
+ gfs2_jhead_process_folio(jd, blocks_read >> shift, head, &done);
blocks_read += PAGE_SIZE >> bsize_shift;
}
--
2.39.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/4] gfs2: make the log page pool per superblock
2026-11-24 21:04 ` [PATCH v2 1/4] gfs2: make the log page pool per superblock Tal Zussman
@ 2026-11-24 21:16 ` sashiko-bot
2026-11-24 21:55 ` Tal Zussman
0 siblings, 1 reply; 8+ messages in thread
From: sashiko-bot @ 2026-11-24 21:16 UTC (permalink / raw)
To: Tal Zussman, Andreas Gruenbacher; +Cc: gfs2, Matthew Wilcox (Oracle)
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] gfs2: use-after-free on sd_log_buf_pool in gfs2_end_log_write()
after free_sbd()
--
commit 6dc37dfa05bee3bb13ea4a43812ebcbe3533794a
Author: Tal Zussman <tz2294@columbia.edu>
gfs2: make the log page pool per superblock
This commit replaces the global gfs2_page_pool mempool with a
per-superblock sd_log_buf_pool initialized in gfs2_fill_super() and
destroyed in free_sbd().
> diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
> index 6ec47376aecf2..f62a893ce5a2b 100644
> --- a/fs/gfs2/ops_fstype.c
> +++ b/fs/gfs2/ops_fstype.c
> @@ -67,6 +67,7 @@ void free_sbd(struct gfs2_sbd *sdp)
> {
> struct super_block *sb = sdp->sd_vfs;
>
> + mempool_exit(&sdp->sd_log_buf_pool);
> free_percpu(sdp->sd_lkstats);
> sb->s_fs_info = NULL;
> kfree(sdp);
[Severity: High]
Can free_sbd() destroy sdp->sd_log_buf_pool and free sdp while log bios
carrying pages from sd_log_buf_pool are still in flight?
Previously, gfs2_end_log_write() returned pages to the global
gfs2_page_pool, which stayed alive until module unload. Now it calls
mempool_free(page, &sdp->sd_log_buf_pool), while free_sbd() runs
mempool_exit(&sdp->sd_log_buf_pool) and kfree(sdp) without waiting for
sdp->sd_log_in_flight via log_flush_wait(sdp).
Two paths can reach free_sbd() with log bios still in flight:
1. During journal recovery, clean_journal() calls gfs2_write_log_header(),
which allocates a page from sdp->sd_log_buf_pool and submits
jd->jd_log_bio asynchronously via gfs2_log_submit_write() without
calling log_flush_wait(sdp). If a subsequent step in gfs2_fill_super()
fails after journal replay, or a read-only mount that replayed a
journal is unmounted (where gfs2_put_super() skips gfs2_make_fs_ro()),
free_sbd() runs without log_flush_wait(sdp).
2. In __gfs2_log_flush(), if the filesystem is withdrawn after
lops_before_commit() or gfs2_log_submit_write() has submitted bios
with pages from sdp->sd_log_buf_pool, it jumps to out_withdraw and
skips log_write_header() and log_flush_wait(sdp):
fs/gfs2/log.c:__gfs2_log_flush() {
...
lops_before_commit(sdp, tr);
if (gfs2_withdrawn(sdp))
goto out_withdraw;
if (sdp->sd_jdesc)
gfs2_log_submit_write(&sdp->sd_jdesc->jd_log_bio);
if (gfs2_withdrawn(sdp))
goto out_withdraw;
...
}
Subsequent unmount flushes return early because the filesystem is
withdrawn, so free_sbd() is reached while those bios are still in
flight.
When the bio completes after free_sbd(), gfs2_end_log_write() hits a
use-after-free on sdp and sdp->sd_log_buf_pool (or dereferences NULL
pool->elements inside mempool_free()). Calling log_flush_wait(sdp)
before mempool_exit() in free_sbd() would ensure all in-flight log bios
have completed.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-gfs2-log-folio-v2-0-f229e90c8285@columbia.edu?part=1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/4] gfs2: stop using pages for log buffers
2026-11-24 21:04 ` [PATCH v2 2/4] gfs2: stop using pages for log buffers Tal Zussman
@ 2026-11-24 21:21 ` sashiko-bot
0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-24 21:21 UTC (permalink / raw)
To: Tal Zussman, Andreas Gruenbacher; +Cc: gfs2, Matthew Wilcox (Oracle)
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] gfs2: use-after-free of sdp in gfs2_end_log_write_buf() on
teardown
--
commit f7b4eeef3695e09c06bd25c0916b1f82335a68b3
Author: Tal Zussman <tz2294@columbia.edu>
gfs2: stop using pages for log buffers
This commit replaces the per-superblock page mempool for log buffers with a
kmalloc mempool of block-sized buffers and gives pool blocks their own bio
completion handler, gfs2_end_log_write_buf(), splitting bios whenever the
completion handler changes.
> diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
> index 7a2c29652feca..156d7c6341ca1 100644
> --- a/fs/gfs2/lops.c
> +++ b/fs/gfs2/lops.c
> @@ -196,45 +196,70 @@ static void gfs2_end_log_write_bh(struct gfs2_sbd *sdp, struct folio *folio,
> } while (bh && size);
> }
>
[ ... ]
> +static void gfs2_end_log_write_buf(struct bio *bio)
> +{
> + struct gfs2_sbd *sdp = bio->bi_private;
> + struct bio_vec *bvec;
> + struct bvec_iter_all iter_all;
> +
> + if (bio->bi_status)
> + gfs2_log_write_error(bio);
> +
> + bio_for_each_segment_all(bvec, bio, iter_all)
> + mempool_free(bvec_virt(bvec), &sdp->sd_log_buf_pool);
> +
> + gfs2_log_write_done(bio);
> }
>
> /**
> @@ -291,9 +316,9 @@ static struct bio *gfs2_log_alloc_bio(struct gfs2_sbd *sdp, u64 blkno,
> * @flush: Always flush the current bio and allocate a new one?
> *
> * If there is a cached bio, then if the next block number is sequential
> - * with the previous one, return it, otherwise flush the bio to the
> - * device. If there is no cached bio, or we just flushed it, then
> - * allocate a new one.
> + * with the previous one and the bio has the same completion handler,
> + * return it, otherwise flush the bio to the device. If there is no
> + * cached bio, or we just flushed it, then allocate a new one.
> *
> * Returns: The bio to use for log writes
> */
> @@ -309,7 +334,7 @@ static struct bio *gfs2_log_get_bio(struct gfs2_sbd *sdp, u64 blkno,
>
> nblk = bio_end_sector(bio);
> nblk >>= sdp->sd_fsb2bb_shift;
> - if (blkno == nblk && !flush)
> + if (blkno == nblk && bio->bi_end_io == end_io && !flush)
> return bio;
> gfs2_log_submit_write(biop);
> }
[Severity: Medium]
Can gfs2_end_log_write_buf() and gfs2_log_write_done() use sdp after
free_sbd() has freed it?
Because gfs2_log_get_bio() now submits the current bio whenever
bio->bi_end_io changes between gfs2_end_log_write_buf and
gfs2_end_log_write, lops_before_commit() submits log bios before
__gfs2_log_flush() checks for withdraw:
fs/gfs2/log.c:__gfs2_log_flush() {
...
lops_before_commit(sdp, tr);
if (gfs2_withdrawn(sdp))
goto out_withdraw;
if (sdp->sd_jdesc)
gfs2_log_submit_write(&sdp->sd_jdesc->jd_log_bio);
if (gfs2_withdrawn(sdp))
goto out_withdraw;
...
}
Jumping to out_withdraw skips log_write_header() and log_flush_wait(sdp),
and clean_journal() likewise submits a log header bio via
gfs2_write_log_header() without calling log_flush_wait(sdp). Neither the
withdrawn unmount path nor free_sbd() waits for sdp->sd_log_in_flight to
reach zero before calling mempool_exit(&sdp->sd_log_buf_pool) and
kfree(sdp):
CPU0 CPU1 (bio completion)
__gfs2_log_flush()
lops_before_commit()
...
gfs2_log_get_bio()
gfs2_log_submit_write()
if (gfs2_withdrawn(sdp))
goto out_withdraw;
...
deactivate_locked_super()
...
free_sbd(sdp)
mempool_exit(&sdp->sd_log_buf_pool)
kfree(sdp)
gfs2_end_log_write_buf(bio)
mempool_free(...,
&sdp->sd_log_buf_pool)
<-- use-after-free
gfs2_log_write_done(bio)
atomic_dec_and_test(
&sdp->sd_log_in_flight)
Waiting on log_flush_wait(sdp) before mempool_exit(&sdp->sd_log_buf_pool)
in free_sbd() (and in out_withdraw) would ensure all in-flight log bios
have completed before sdp is torn down.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-gfs2-log-folio-v2-0-f229e90c8285@columbia.edu?part=2
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/4] gfs2: make the log page pool per superblock
2026-11-24 21:16 ` sashiko-bot
@ 2026-11-24 21:55 ` Tal Zussman
0 siblings, 0 replies; 8+ messages in thread
From: Tal Zussman @ 2026-11-24 21:55 UTC (permalink / raw)
To: sashiko-reviews, Andreas Gruenbacher; +Cc: gfs2, Matthew Wilcox (Oracle)
On 11/24/26 4:16 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [High] gfs2: use-after-free on sd_log_buf_pool in gfs2_end_log_write()
> after free_sbd()
> --
>
> commit 6dc37dfa05bee3bb13ea4a43812ebcbe3533794a
> Author: Tal Zussman <tz2294@columbia.edu>
>
> gfs2: make the log page pool per superblock
>
> This commit replaces the global gfs2_page_pool mempool with a
> per-superblock sd_log_buf_pool initialized in gfs2_fill_super() and
> destroyed in free_sbd().
>
>> diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
>> index 6ec47376aecf2..f62a893ce5a2b 100644
>> --- a/fs/gfs2/ops_fstype.c
>> +++ b/fs/gfs2/ops_fstype.c
>> @@ -67,6 +67,7 @@ void free_sbd(struct gfs2_sbd *sdp)
>> {
>> struct super_block *sb = sdp->sd_vfs;
>>
>> + mempool_exit(&sdp->sd_log_buf_pool);
>> free_percpu(sdp->sd_lkstats);
>> sb->s_fs_info = NULL;
>> kfree(sdp);
>
> [Severity: High]
> Can free_sbd() destroy sdp->sd_log_buf_pool and free sdp while log bios
> carrying pages from sd_log_buf_pool are still in flight?
>
> Previously, gfs2_end_log_write() returned pages to the global
> gfs2_page_pool, which stayed alive until module unload. Now it calls
> mempool_free(page, &sdp->sd_log_buf_pool), while free_sbd() runs
> mempool_exit(&sdp->sd_log_buf_pool) and kfree(sdp) without waiting for
> sdp->sd_log_in_flight via log_flush_wait(sdp).
>
> Two paths can reach free_sbd() with log bios still in flight:
>
> 1. During journal recovery, clean_journal() calls gfs2_write_log_header(),
> which allocates a page from sdp->sd_log_buf_pool and submits
> jd->jd_log_bio asynchronously via gfs2_log_submit_write() without
> calling log_flush_wait(sdp). If a subsequent step in gfs2_fill_super()
> fails after journal replay, or a read-only mount that replayed a
> journal is unmounted (where gfs2_put_super() skips gfs2_make_fs_ro()),
> free_sbd() runs without log_flush_wait(sdp).
>
> 2. In __gfs2_log_flush(), if the filesystem is withdrawn after
> lops_before_commit() or gfs2_log_submit_write() has submitted bios
> with pages from sdp->sd_log_buf_pool, it jumps to out_withdraw and
> skips log_write_header() and log_flush_wait(sdp):
>
> fs/gfs2/log.c:__gfs2_log_flush() {
> ...
> lops_before_commit(sdp, tr);
> if (gfs2_withdrawn(sdp))
> goto out_withdraw;
> if (sdp->sd_jdesc)
> gfs2_log_submit_write(&sdp->sd_jdesc->jd_log_bio);
> if (gfs2_withdrawn(sdp))
> goto out_withdraw;
> ...
> }
>
> Subsequent unmount flushes return early because the filesystem is
> withdrawn, so free_sbd() is reached while those bios are still in
> flight.
>
> When the bio completes after free_sbd(), gfs2_end_log_write() hits a
> use-after-free on sdp and sdp->sd_log_buf_pool (or dereferences NULL
> pool->elements inside mempool_free()). Calling log_flush_wait(sdp)
> before mempool_exit() in free_sbd() would ensure all in-flight log bios
> have completed.
>
This is mostly pre-existing (and the same issue as the other Sashiko
report), but I can add a patch at the beginning of the series to fix it.
I think adding a log_flush_wait() at the start of gfs2_jindex_free() should
be sufficient.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-24 21:55 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 21:04 [PATCH v2 0/4] gfs2: stop using struct page in the log code Tal Zussman
2026-11-24 21:04 ` [PATCH v2 1/4] gfs2: make the log page pool per superblock Tal Zussman
2026-11-24 21:16 ` sashiko-bot
2026-11-24 21:55 ` Tal Zussman
2026-11-24 21:04 ` [PATCH v2 2/4] gfs2: stop using pages for log buffers Tal Zussman
2026-11-24 21:21 ` sashiko-bot
2026-11-24 21:04 ` [PATCH v2 3/4] gfs2: plug the log writes of a flush Tal Zussman
2026-11-24 21:04 ` [PATCH v2 4/4] gfs2: remove the remaining page references in the log code Tal Zussman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox