Skip to content

Commit ffec85d

Browse files
ebiggerstytso
authored andcommitted
ext4: fix cgroup writeback accounting with fs-layer encryption
When writing a page from an encrypted file that is using filesystem-layer encryption (not inline encryption), ext4 encrypts the pagecache page into a bounce page, then writes the bounce page. It also passes the bounce page to wbc_account_cgroup_owner(). That's incorrect, because the bounce page is a newly allocated temporary page that doesn't have the memory cgroup of the original pagecache page. This makes wbc_account_cgroup_owner() not account the I/O to the owner of the pagecache page as it should. Fix this by always passing the pagecache page to wbc_account_cgroup_owner(). Fixes: 001e4a8 ("ext4: implement cgroup writeback support") Cc: [email protected] Reported-by: Matthew Wilcox (Oracle) <[email protected]> Signed-off-by: Eric Biggers <[email protected]> Acked-by: Tejun Heo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent e3645d7 commit ffec85d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

fs/ext4/page-io.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,8 @@ static void io_submit_init_bio(struct ext4_io_submit *io,
409409

410410
static void io_submit_add_bh(struct ext4_io_submit *io,
411411
struct inode *inode,
412-
struct page *page,
412+
struct page *pagecache_page,
413+
struct page *bounce_page,
413414
struct buffer_head *bh)
414415
{
415416
int ret;
@@ -421,10 +422,11 @@ static void io_submit_add_bh(struct ext4_io_submit *io,
421422
}
422423
if (io->io_bio == NULL)
423424
io_submit_init_bio(io, bh);
424-
ret = bio_add_page(io->io_bio, page, bh->b_size, bh_offset(bh));
425+
ret = bio_add_page(io->io_bio, bounce_page ?: pagecache_page,
426+
bh->b_size, bh_offset(bh));
425427
if (ret != bh->b_size)
426428
goto submit_and_retry;
427-
wbc_account_cgroup_owner(io->io_wbc, page, bh->b_size);
429+
wbc_account_cgroup_owner(io->io_wbc, pagecache_page, bh->b_size);
428430
io->io_next_block++;
429431
}
430432

@@ -561,8 +563,7 @@ int ext4_bio_write_page(struct ext4_io_submit *io,
561563
do {
562564
if (!buffer_async_write(bh))
563565
continue;
564-
io_submit_add_bh(io, inode,
565-
bounce_page ? bounce_page : page, bh);
566+
io_submit_add_bh(io, inode, page, bounce_page, bh);
566567
} while ((bh = bh->b_this_page) != head);
567568
unlock:
568569
unlock_page(page);

0 commit comments

Comments
 (0)