Jiri Slaby 026495
From: Eric Biggers <ebiggers@google.com>
Jiri Slaby 026495
Date: Thu, 2 Feb 2023 16:55:03 -0800
Jiri Slaby 026495
Subject: [PATCH] ext4: fix cgroup writeback accounting with fs-layer
Jiri Slaby 026495
 encryption
Jiri Slaby 026495
References: bsc#1012628
Jiri Slaby 026495
Patch-mainline: 6.2.7
Jiri Slaby 026495
Git-commit: ffec85d53d0f39ee4680a2cf0795255e000e1feb
Jiri Slaby 026495
Jiri Slaby 026495
commit ffec85d53d0f39ee4680a2cf0795255e000e1feb upstream.
Jiri Slaby 026495
Jiri Slaby 026495
When writing a page from an encrypted file that is using
Jiri Slaby 026495
filesystem-layer encryption (not inline encryption), ext4 encrypts the
Jiri Slaby 026495
pagecache page into a bounce page, then writes the bounce page.
Jiri Slaby 026495
Jiri Slaby 026495
It also passes the bounce page to wbc_account_cgroup_owner().  That's
Jiri Slaby 026495
incorrect, because the bounce page is a newly allocated temporary page
Jiri Slaby 026495
that doesn't have the memory cgroup of the original pagecache page.
Jiri Slaby 026495
This makes wbc_account_cgroup_owner() not account the I/O to the owner
Jiri Slaby 026495
of the pagecache page as it should.
Jiri Slaby 026495
Jiri Slaby 026495
Fix this by always passing the pagecache page to
Jiri Slaby 026495
wbc_account_cgroup_owner().
Jiri Slaby 026495
Jiri Slaby 026495
Fixes: 001e4a8775f6 ("ext4: implement cgroup writeback support")
Jiri Slaby 026495
Cc: stable@vger.kernel.org
Jiri Slaby 026495
Reported-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Jiri Slaby 026495
Signed-off-by: Eric Biggers <ebiggers@google.com>
Jiri Slaby 026495
Acked-by: Tejun Heo <tj@kernel.org>
Jiri Slaby 026495
Link: https://lore.kernel.org/r/20230203005503.141557-1-ebiggers@kernel.org
Jiri Slaby 026495
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Jiri Slaby 026495
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Jiri Slaby 026495
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Jiri Slaby 026495
---
Jiri Slaby 026495
 fs/ext4/page-io.c | 11 ++++++-----
Jiri Slaby 026495
 1 file changed, 6 insertions(+), 5 deletions(-)
Jiri Slaby 026495
Jiri Slaby 026495
diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
Jiri Slaby 026495
index beaec6d8..1e4db96a 100644
Jiri Slaby 026495
--- a/fs/ext4/page-io.c
Jiri Slaby 026495
+++ b/fs/ext4/page-io.c
Jiri Slaby 026495
@@ -409,7 +409,8 @@ static void io_submit_init_bio(struct ext4_io_submit *io,
Jiri Slaby 026495
 
Jiri Slaby 026495
 static void io_submit_add_bh(struct ext4_io_submit *io,
Jiri Slaby 026495
 			     struct inode *inode,
Jiri Slaby 026495
-			     struct page *page,
Jiri Slaby 026495
+			     struct page *pagecache_page,
Jiri Slaby 026495
+			     struct page *bounce_page,
Jiri Slaby 026495
 			     struct buffer_head *bh)
Jiri Slaby 026495
 {
Jiri Slaby 026495
 	int ret;
Jiri Slaby 026495
@@ -421,10 +422,11 @@ static void io_submit_add_bh(struct ext4_io_submit *io,
Jiri Slaby 026495
 	}
Jiri Slaby 026495
 	if (io->io_bio == NULL)
Jiri Slaby 026495
 		io_submit_init_bio(io, bh);
Jiri Slaby 026495
-	ret = bio_add_page(io->io_bio, page, bh->b_size, bh_offset(bh));
Jiri Slaby 026495
+	ret = bio_add_page(io->io_bio, bounce_page ?: pagecache_page,
Jiri Slaby 026495
+			   bh->b_size, bh_offset(bh));
Jiri Slaby 026495
 	if (ret != bh->b_size)
Jiri Slaby 026495
 		goto submit_and_retry;
Jiri Slaby 026495
-	wbc_account_cgroup_owner(io->io_wbc, page, bh->b_size);
Jiri Slaby 026495
+	wbc_account_cgroup_owner(io->io_wbc, pagecache_page, bh->b_size);
Jiri Slaby 026495
 	io->io_next_block++;
Jiri Slaby 026495
 }
Jiri Slaby 026495
 
Jiri Slaby 026495
@@ -561,8 +563,7 @@ int ext4_bio_write_page(struct ext4_io_submit *io,
Jiri Slaby 026495
 	do {
Jiri Slaby 026495
 		if (!buffer_async_write(bh))
Jiri Slaby 026495
 			continue;
Jiri Slaby 026495
-		io_submit_add_bh(io, inode,
Jiri Slaby 026495
-				 bounce_page ? bounce_page : page, bh);
Jiri Slaby 026495
+		io_submit_add_bh(io, inode, page, bounce_page, bh);
Jiri Slaby 026495
 	} while ((bh = bh->b_this_page) != head);
Jiri Slaby 026495
 unlock:
Jiri Slaby 026495
 	unlock_page(page);
Jiri Slaby 026495
-- 
Jiri Slaby 026495
2.35.3
Jiri Slaby 026495