Skip to contentSkip to conversation

v2 [PATCH] ocfs2: fix panic in failed foilio allocation

PATCH Mark Tinguely 3 participants 4 messages Apr 11, 2025 – May 19, 2025 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

In the page to order 0 folio conversion series, the commit 7e119cff9d0a, "ocfs2: convert w_pages to w_folios" and commit 9a5e08652dc4b, "ocfs2: use an array of folios instead of an array of pages", saves -ENOMEM in the folio array upon allocation failure and calls the folio array free code. The folio array free code expects either valid folio pointers or NULL. Finding the -ENOMEM will result in a panic. Fix by NULLing the error folio entry.

Cc Changwei Ge <[email protected]>
Cc Joel Becker <[email protected]>
Cc Junxiao Bi <[email protected]>
Cc Mark Fasheh <[email protected]>
Cc Matthew Wilcox <[email protected]>

---
v2: sorry, ocfs2_grab_folios() needs the same change.
the other callers do not need the change.

---
 fs/ocfs2/alloc.c | 1 +
 fs/ocfs2/aops.c  | 1 +
 2 files changed, 2 insertions(+)
fs/ocfs2/alloc.c +1 -0
index b8ac85b548c7..821cb7874685 100644
@@ -6918,6 +6918,7 @@ static int ocfs2_grab_folios(struct inode *inode, loff_t start, loff_t end,
 		if (IS_ERR(folios[numfolios])) {
 			ret = PTR_ERR(folios[numfolios]);
 			mlog_errno(ret);
+			folios[numfolios] = NULL;
 			goto out;
 		}
 diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c

index 40b6bce12951..89aadc6cdd87 100644

fs/ocfs2/aops.c +1 -0
@@ -1071,6 +1071,7 @@ static int ocfs2_grab_folios_for_write(struct address_space *mapping,
 			if (IS_ERR(wc->w_folios[i])) {
 				ret = PTR_ERR(wc->w_folios[i]);
 				mlog_errno(ret);
+				wc->w_folios[i] = NULL;
 				goto out;
 			}
 		}
Signature · 1 line
2.39.5 (Apple Git-154)
Reviewed-by
#2 lore raw
Quoted 9 lines · Mark Tinguely

In the page to order 0 folio conversion series, the commit 7e119cff9d0a, "ocfs2: convert w_pages to w_folios" and commit 9a5e08652dc4b, "ocfs2: use an array of folios instead of an array of pages", saves -ENOMEM in the folio array upon allocation failure and calls the folio array free code. The folio array free code expects either valid folio pointers or NULL. Finding the -ENOMEM will result in a panic. Fix by NULLing the error folio entry.

Quoted 7 lines
Cc Changwei Ge <[email protected]>
Cc Joel Becker <[email protected]>
Cc Junxiao Bi <[email protected]>
Cc Mark Fasheh <[email protected]>
Cc Matthew Wilcox <[email protected]>
maintainer Reviewed-by
#3 lore raw
In reply to Mark Tinguely
Quoted 10 lines · Mark Tinguely

In the page to order 0 folio conversion series, the commit 7e119cff9d0a, "ocfs2: convert w_pages to w_folios" and commit 9a5e08652dc4b, "ocfs2: use an array of folios instead of an array of pages", saves -ENOMEM in the folio array upon allocation failure and calls the folio array free code. The folio array free code expects either valid folio pointers or NULL. Finding the -ENOMEM will result in a panic. Fix by NULLing the error folio entry.

Fixes 7e119cff9d0a ("ocfs2: convert w_pages to w_folios")
Fixes 9a5e08652dc4b ("ocfs2: use an array of folios instead of an array of pages")
Quoted 37 lines
Cc Changwei Ge <[email protected]>
Cc Joel Becker <[email protected]>
Cc Junxiao Bi <[email protected]>
Cc Mark Fasheh <[email protected]>
Cc Matthew Wilcox <[email protected]>

---
v2: sorry, ocfs2_grab_folios() needs the same change. the other callers do not need the change.
---
 fs/ocfs2/alloc.c | 1 +
 fs/ocfs2/aops.c  | 1 +

 2 files changed, 2 insertions(+)
fs/ocfs2/alloc.c +1 -0
index b8ac85b548c7..821cb7874685 100644
@@ -6918,6 +6918,7 @@ static int ocfs2_grab_folios(struct inode *inode, loff_t start, loff_t end,
          if (IS_ERR(folios[numfolios])) {
              ret = PTR_ERR(folios[numfolios]);
              mlog_errno(ret);
+            folios[numfolios] = NULL;
              goto out;
          }

 diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index 40b6bce12951..89aadc6cdd87 100644

fs/ocfs2/aops.c +1 -0
@@ -1071,6 +1071,7 @@ static int ocfs2_grab_folios_for_write(struct address_space *mapping,
              if (IS_ERR(wc->w_folios[i])) {
                  ret = PTR_ERR(wc->w_folios[i]);
                  mlog_errno(ret);
+                wc->w_folios[i] = NULL;
                  goto out;
              }
          }
#4 lore raw
In reply to Mark Tinguely
Quoted 48 lines · Mark Tinguely

In the page to order 0 folio conversion series, the commit 7e119cff9d0a, "ocfs2: convert w_pages to w_folios" and commit 9a5e08652dc4b, "ocfs2: use an array of folios instead of an array of pages", saves -ENOMEM in the folio array upon allocation failure and calls the folio array free code. The folio array free code expects either valid folio pointers or NULL. Finding the -ENOMEM will result in a panic. Fix by NULLing the error folio entry.

Cc Changwei Ge <[email protected]>
Cc Joel Becker <[email protected]>
Cc Junxiao Bi <[email protected]>
Cc Mark Fasheh <[email protected]>
Cc Matthew Wilcox <[email protected]>

---
v2: sorry, ocfs2_grab_folios() needs the same change.
    the other callers do not need the change.

---
  fs/ocfs2/alloc.c | 1 +
  fs/ocfs2/aops.c  | 1 +
  2 files changed, 2 insertions(+)
fs/ocfs2/alloc.c +1 -0
index b8ac85b548c7..821cb7874685 100644
@@ -6918,6 +6918,7 @@ static int ocfs2_grab_folios(struct inode *inode, 
 loff_t start, loff_t end,
          if (IS_ERR(folios[numfolios])) {
              ret = PTR_ERR(folios[numfolios]);
              mlog_errno(ret);
+            folios[numfolios] = NULL;
              goto out;
          }

 diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index 40b6bce12951..89aadc6cdd87 100644

fs/ocfs2/aops.c +1 -0
@@ -1071,6 +1071,7 @@ static int ocfs2_grab_folios_for_write(struct 
 address_space *mapping,
              if (IS_ERR(wc->w_folios[i])) {
                  ret = PTR_ERR(wc->w_folios[i]);
                  mlog_errno(ret);
+                wc->w_folios[i] = NULL;
                  goto out;
              }
Quoted 1 line

         }

It appears the Linux commit:

commit 31d4cd4eb2f8d9b87ebfa6a5e443a59e3b3d7b8c

Author: Mark Tinguely <[email protected]>
Date:   Fri Apr 11 11:31:24 2025 -0500

ocfs2: fix panic in failed foilio allocation

made only the alloc.c change.