linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pagemap: Add alert to mapping_set_release_always() for mapping with no release_folio
@ 2025-12-10 20:01 Deepakkumar Karn
  2025-12-10 21:36 ` Matthew Wilcox
  0 siblings, 1 reply; 7+ messages in thread
From: Deepakkumar Karn @ 2025-12-10 20:01 UTC (permalink / raw)
  To: willy
  Cc: Andrew Morton, David Hildenbrand, Lorenzo Stoakes, Liam.Howlett,
	Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
	Jan Kara, linux-fsdevel, linux-mm, linux-kernel, Deepakkumar Karn

AS_RELEASE_ALWAYS tells the memory management code to always call
->release_folio() when releasing a folio, even if it has no private
data. Setting this flag without providing release_folio callback
leads to try_to_free_buffers() being called on folios without
buffer_heads, causing a NULL pointer dereference.

Add a VM_WARN_ONCE() alert to mapping_set_release_always() to catch
this programming error early and help prevent similar bugs in other
filesystems.

Suggested-by: Jan Kara <jack@suse.cz>
Signed-off-by: Deepakkumar Karn <dkarn@redhat.com>
---
 include/linux/pagemap.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 31a848485ad9..cc352e87ac2d 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -296,6 +296,9 @@ static inline bool mapping_release_always(const struct address_space *mapping)
 
 static inline void mapping_set_release_always(struct address_space *mapping)
 {
+	/* Alert while setting the flag with no release_folio callback */
+	VM_WARN_ONCE(!mapping->a_ops->release_folio,
+		     "Setting AS_RELEASE_ALWAYS with no release_folio");
 	set_bit(AS_RELEASE_ALWAYS, &mapping->flags);
 }
 
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-12-12 18:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-10 20:01 [PATCH] pagemap: Add alert to mapping_set_release_always() for mapping with no release_folio Deepakkumar Karn
2025-12-10 21:36 ` Matthew Wilcox
2025-12-11  9:23   ` Jan Kara
2025-12-12  9:37     ` Deepak Karn
2025-12-12 12:18     ` Matthew Wilcox
2025-12-12 17:47       ` Jan Kara
2025-12-12 18:38         ` Deepak Karn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).