Skip to contentSkip to conversation

fsverity: remove fsverity_verify_page()

PATCH Superseded Eric Biggers 3 participants 7 messages Feb 14 – Feb 15

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Eric Biggers

author maintainer
#0 lore raw

v2 cover fsverity: remove fsverity_verify_page()

This series removes the non-large-folio-aware function fsverity_verify_page(), which is no longer needed.

Changed in v2:
- Made one specific part of f2fs_verify_cluster() large-folio-aware.

Eric Biggers (2):
f2fs: use fsverity_verify_blocks() instead of fsverity_verify_page()
fsverity: remove fsverity_verify_page()

 fs/f2fs/compress.c       | 6 +++++-
 fs/verity/verify.c       | 4 ++--
 include/linux/fsverity.h | 6 ------
 3 files changed, 7 insertions(+), 9 deletions(-)

base-commit: 3e48a11675c50698374d4ac596fb506736eb1c53

Signature · 1 line
2.53.0
author maintainer
#1 lore raw

PATCH v2 1/2 f2fs: use fsverity_verify_blocks() instead of fsverity_verify_page()

Replace the only remaining caller of fsverity_verify_page() with a direct call to fsverity_verify_blocks(). This will allow fsverity_verify_page() to be removed.

Make it large-folio-aware by using the page's offset in the folio instead of 0, though the rest of f2fs_verify_cluster() and f2fs decompression as a whole still assumes small folios.

---
 fs/f2fs/compress.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/f2fs/compress.c +5 -1
index 006a80acd1de..11c4de515f98 100644
@@ -1811,15 +1811,19 @@ static void f2fs_verify_cluster(struct work_struct *work)
 	int i;
 
 	/* Verify, update, and unlock the decompressed pages. */
 	for (i = 0; i < dic->cluster_size; i++) {
 		struct page *rpage = dic->rpages[i];
+		struct folio *rfolio;
+		size_t offset;
 
 		if (!rpage)
 			continue;
+		rfolio = page_folio(rpage);
+		offset = folio_page_idx(rfolio, rpage) * PAGE_SIZE;
 
-		if (fsverity_verify_page(dic->vi, rpage))
+		if (fsverity_verify_blocks(dic->vi, rfolio, PAGE_SIZE, offset))
 			SetPageUptodate(rpage);
 		else
 			ClearPageUptodate(rpage);
 		unlock_page(rpage);
 	}
Signature · 1 line
2.53.0
author maintainer
#6 lore raw

PATCH v2 2/2 fsverity: remove fsverity_verify_page()

In reply to Eric Biggers

Now that fsverity_verify_page() has no callers, remove it.

---
 fs/verity/verify.c       | 4 ++--
 include/linux/fsverity.h | 6 ------
 2 files changed, 2 insertions(+), 8 deletions(-)
fs/verity/verify.c +2 -2
index 31797f9b24d0..3e38749fbc82 100644
@@ -431,12 +431,12 @@ EXPORT_SYMBOL_GPL(fsverity_verify_blocks);
  * verification, then bio->bi_status is set to an error status.
  *
  * This is a helper function for use by the ->readahead() method of filesystems
  * that issue bios to read data directly into the page cache.  Filesystems that
  * populate the page cache without issuing bios (e.g. non block-based
- * filesystems) must instead call fsverity_verify_page() directly on each page.
- * All filesystems must also call fsverity_verify_page() on holes.
+ * filesystems) must instead call fsverity_verify_blocks() directly.  All
+ * filesystems must also call fsverity_verify_blocks() on holes.
  */
 void fsverity_verify_bio(struct fsverity_info *vi, struct bio *bio)
 {
 	struct fsverity_verification_context ctx;
 	struct folio_iter fi;
include/linux/fsverity.h +0 -6
index fed91023bea9..6de3ddf0b148 100644
@@ -280,16 +280,10 @@ static inline bool fsverity_verify_folio(struct fsverity_info *vi,
 					 struct folio *folio)
 {
 	return fsverity_verify_blocks(vi, folio, folio_size(folio), 0);
 }
 
-static inline bool fsverity_verify_page(struct fsverity_info *vi,
-					struct page *page)
-{
-	return fsverity_verify_blocks(vi, page_folio(page), PAGE_SIZE, 0);
-}
-
 /**
  * fsverity_file_open() - prepare to open a verity file
  * @inode: the inode being opened
  * @filp: the struct file being set up
  *
Signature · 1 line
2.53.0
author maintainer
#2 lore raw

Re: [PATCH v2 1/2] f2fs: use fsverity_verify_blocks() instead of fsverity_verify_page()

In reply to Eric Biggers
Quoted 28 lines · Eric Biggers

Replace the only remaining caller of fsverity_verify_page() with a direct call to fsverity_verify_blocks(). This will allow fsverity_verify_page() to be removed.

Make it large-folio-aware by using the page's offset in the folio instead of 0, though the rest of f2fs_verify_cluster() and f2fs decompression as a whole still assumes small folios.

---
 fs/f2fs/compress.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/f2fs/compress.c +2 -0
index 006a80acd1de..11c4de515f98 100644
@@ -1811,15 +1811,19 @@ static void f2fs_verify_cluster(struct work_struct *work)
 	int i;
 
 	/* Verify, update, and unlock the decompressed pages. */
 	for (i = 0; i < dic->cluster_size; i++) {
 		struct page *rpage = dic->rpages[i];
+		struct folio *rfolio;
+		size_t offset;
 
 		if (!rpage)

fs/f2fs/compress.c static void f2fs_verify_cluster(struct work_struct *work) · line 1828

Quoted 10 lines
fs/f2fs/compress.c +3 -1
 			continue;
+		rfolio = page_folio(rpage);
+		offset = folio_page_idx(rfolio, rpage) * PAGE_SIZE;
 
-		if (fsverity_verify_page(dic->vi, rpage))
+		if (fsverity_verify_blocks(dic->vi, rfolio, PAGE_SIZE, offset))
 			SetPageUptodate(rpage);
 		else
 			ClearPageUptodate(rpage);
 		unlock_page(rpage);

Let me know if you'd prefer that we verified the whole folio here instead. Either way, the behavior will be still incorrect if this function is passed a large folio (which it's not). Either we'd mark the whole folio up-to-date after verifying only one page in it, or we'd access pages that were not in the array of pages passed to the function.

- Eric

#3 lore raw

Re: [PATCH v2 1/2] f2fs: use fsverity_verify_blocks() instead of fsverity_verify_page()

Quoted 3 lines · Eric Biggers

Let me know if you'd prefer that we verified the whole folio here instead.

This looks good to me.

And hopefully some day that "rpages" becomes "rfolio" (and this can all go away and it becomes fsverity_verify_folio() and simpler).

It does look like the "cluster size" thing could maybe be made to simply be the size of one folio for those things, and then being a single folio of size "PAGE_SIZE << i_log_cluster_size" might simplify other code too.

Then instead of walking multiple pages, you'd always have exactly one folio (just different sizes depending on cluster size).

But that's just from a very quick look, and I might mis-understand the code I saw...

Linus

#4 lore raw

Re: [PATCH v2 1/2] f2fs: use fsverity_verify_blocks() instead of fsverity_verify_page()

In reply to Eric Biggers
Quoted 11 lines · Eric Biggers
Quoted 10 lines · Eric Biggers

+++ b/fs/f2fs/compress.c

fs/f2fs/compress.c +2 -0
@@ -1811,15 +1811,19 @@ static void f2fs_verify_cluster(struct work_struct *work)
 	int i;
 
 	/* Verify, update, and unlock the decompressed pages. */
 	for (i = 0; i < dic->cluster_size; i++) {
 		struct page *rpage = dic->rpages[i];
+		struct folio *rfolio;
+		size_t offset;
 
Quoted 8 lines

fs/f2fs/compress.c static void f2fs_verify_cluster(struct work_struct *work) · line 1825

Quoted 8 lines
fs/f2fs/compress.c +3 -1
 		if (!rpage)
 			continue;
+		rfolio = page_folio(rpage);
+		offset = folio_page_idx(rfolio, rpage) * PAGE_SIZE;
 
-		if (fsverity_verify_page(dic->vi, rpage))
+		if (fsverity_verify_blocks(dic->vi, rfolio, PAGE_SIZE, offset))
 			SetPageUptodate(rpage);

Yeah, no.

		if (fsverity_verify_blocks(dic->vi, rfolio,
				folio_size(rfolio), 0));
			folio_mark_uptodate(rfolio);
Quoted 2 lines

fs/f2fs/compress.c static void f2fs_verify_cluster(struct work_struct *work) · line 1827

Quoted 2 lines
fs/f2fs/compress.c +0 -0
 		else
 			ClearPageUptodate(rpage);

This never needed to be here. The folio must already be !uptodate. Just delete these two lines.

Quoted 1 line

fs/f2fs/compress.c static void f2fs_verify_cluster(struct work_struct *work) · line 1828

Quoted 1 line
fs/f2fs/compress.c +0 -0
 		unlock_page(rpage);

folio_unlock(rfolio);

author maintainer
#5 lore raw

Re: [PATCH v2 1/2] f2fs: use fsverity_verify_blocks() instead of fsverity_verify_page()

Quoted 30 lines · Matthew Wilcox
Quoted 11 lines · Eric Biggers
Quoted 10 lines · Eric Biggers

+++ b/fs/f2fs/compress.c

fs/f2fs/compress.c +2 -0
@@ -1811,15 +1811,19 @@ static void f2fs_verify_cluster(struct work_struct *work)
 	int i;
 
 	/* Verify, update, and unlock the decompressed pages. */
 	for (i = 0; i < dic->cluster_size; i++) {
 		struct page *rpage = dic->rpages[i];
+		struct folio *rfolio;
+		size_t offset;
 
Quoted 8 lines

fs/f2fs/compress.c static void f2fs_verify_cluster(struct work_struct *work) · line 1825

Quoted 8 lines
fs/f2fs/compress.c +3 -1
 		if (!rpage)
 			continue;
+		rfolio = page_folio(rpage);
+		offset = folio_page_idx(rfolio, rpage) * PAGE_SIZE;
 
-		if (fsverity_verify_page(dic->vi, rpage))
+		if (fsverity_verify_blocks(dic->vi, rfolio, PAGE_SIZE, offset))
 			SetPageUptodate(rpage);

Yeah, no.

		if (fsverity_verify_blocks(dic->vi, rfolio,
				folio_size(rfolio), 0));
			folio_mark_uptodate(rfolio);
Quoted 2 lines

fs/f2fs/compress.c static void f2fs_verify_cluster(struct work_struct *work) · line 1827

Quoted 2 lines
fs/f2fs/compress.c +0 -0
 		else
 			ClearPageUptodate(rpage);
Quoted 6 lines

This never needed to be here. The folio must already be !uptodate. Just delete these two lines.

Quoted 1 line

fs/f2fs/compress.c static void f2fs_verify_cluster(struct work_struct *work) · line 1828

Quoted 1 line
fs/f2fs/compress.c +0 -0
 		unlock_page(rpage);

folio_unlock(rfolio);

Sure. This kind of scope creep is why I wanted to just do the straightforward conversion for now.

- Eric