Zero page->private when freeing pages
Subsystems (13)
Zi Yan
reviewercover Zero page->private when freeing pages
Hi all,
Based on a recent discussion with David Hildenbrand on page->private is not zero when a page is freed[1], this patchset is trying to fix all users do not zero ->private when freeing a page and add checks to make sure all freed pages have ->private set to zero. For compound pages, both head page and tail pages need to have ->private set to zero.
People are only cc'd on the cover letter and related patches. Mailing lists get all patches.
Patch 1 to 9: fix all users do not zero ->private upon freeing pages. I only tested part of them, so would like to get reviews to make sure I did the right thing.
Patch 10 : restores page->private check in folio split code, since
the code was removed in a prior commit without a proper reason.
Patch 11 : adds checks in page freeing path, __free_pages_prepare(),
to make sure freed pages have zeroed ->prviate.
Any comment or suggestion is welcome.
Thanks.
# MM - THP
Cc: David Hildenbrand <[email protected]>
Cc: Lorenzo Stoakes <[email protected]>
Cc: Baolin Wang <[email protected]>
Cc: "Liam R. Howlett" <[email protected]>
Cc: Nico Pache <[email protected]>
Cc: Ryan Roberts <[email protected]>
Cc: Dev Jain <[email protected]>
Cc: Barry Song <[email protected]>
Cc: Lance Yang <[email protected]>
# MM - page allocator
Cc: Suren Baghdasaryan <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Brendan Jackman <[email protected]>
Cc: Johannes Weiner <[email protected]>
# relay Cc: Jason Xing <[email protected]> Cc: Yushan Zhou <[email protected]> Cc: "Masami Hiramatsu (Google)" <[email protected]>
# MM - slub
Cc: Vlastimil Babka <[email protected]>
Cc: Christoph Lameter <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Roman Gushchin <[email protected]>
Cc: Harry Yoo <[email protected]>
# DRM TTM
Cc: Christian Koenig <[email protected]>
Cc: Huang Rui <[email protected]>
Cc: Matthew Auld <[email protected]>
Cc: Matthew Brost <[email protected]>
Cc: Maarten Lankhorst <[email protected]>
Cc: Maxime Ripard <[email protected]>
Cc: Thomas Zimmermann <[email protected]>
Cc: David Airlie <[email protected]>
Cc: Simona Vetter <[email protected]>
# Block
Cc: Jens Axboe <[email protected]>
# watch queue Cc: Christian Brauner <[email protected]> Cc: K Prateek Nayak <[email protected]> Cc: Davidlohr Bueso <[email protected]> Cc: Eric Sandeen <[email protected]>
# binder Cc: Greg Kroah-Hartman <[email protected]> Cc: "Arve Hjønnevåg" <[email protected]> Cc: Todd Kjos <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Carlos Llamas <[email protected]> Cc: Alice Ryhl <[email protected]>
# null_blk Cc: Damien Le Moal <[email protected]> Cc: Johannes Thumshirn <[email protected]>
# percpu Cc: Dennis Zhou <[email protected]> Cc: Tejun Heo <[email protected]> Cc: Christoph Lameter <[email protected]>
# erofs Cc: Gao Xiang <[email protected]> Cc: Yue Hu <[email protected]> Cc: Jeffle Xu <[email protected]> Cc: Sandeep Dhavale <[email protected]> Cc: Hongbo Li <[email protected]> Cc: Chunhai Guo <[email protected]>
# lists Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected]
Zi Yan (11):
relay: zero page->private when freeing pages mm/slub: zero page->private when freeing pages drm/ttm: zero page->private when freeing pages
blk-mq: zero page->private when freeing pages
watch_queue: zero page->private when freeing pages
binder: zero page->private when freeing pages
null_blk: zero page->private when freeing pages
percpu: zero page->private when freeing pages
erofs: zero page->private when freeing pages mm/huge_memory: add page->private check back in
__split_folio_to_order()
mm/page_alloc: check page->private upon page free
block/blk-mq-tag.c | 6 +++++- drivers/android/binder_alloc.c | 1 + drivers/block/null_blk/main.c | 1 + drivers/gpu/drm/ttm/ttm_pool.c | 1 + fs/erofs/zutil.c | 1 + kernel/relay.c | 8 ++++++-- kernel/watch_queue.c | 8 ++++++-- mm/huge_memory.c | 10 ++++++++++ mm/page_alloc.c | 3 ++- mm/percpu-vm.c | 4 +++- mm/slub.c | 1 + 11 files changed, 37 insertions(+), 7 deletions(-)
Signature · 1 line
2.51.0
Zi Yan
reviewerPATCH 1/11 relay: zero page->private when freeing pages
This prepares for upcoming page->private checks in page freeing path.
--- kernel/relay.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/relay.c +6 -2
@@ -131,8 +131,10 @@ static void *relay_alloc_buf(struct rchan_buf *buf, size_t *size)return mem; depopulate: -for (j =0 ; j < i; j++) +for (j =0 ; j < i; j++) { +set_page_private (buf->page_array[i],0 );__free_page (buf->page_array[j]); + }relay_free_page_array (buf->page_array);return NULL ; }
@@ -196,8 +198,10 @@ static void relay_destroy_buf(struct rchan_buf *buf)if (likely (buf->start)) {vunmap (buf->start); -for (i =0 ; i < buf->page_count; i++) +for (i =0 ; i < buf->page_count; i++) { +set_page_private (buf->page_array[i],0 );__free_page (buf->page_array[i]); + }relay_free_page_array (buf->page_array); } *per_cpu_ptr (chan->buf, buf->cpu) =NULL ;
Signature · 1 line
2.51.0
Usama Arif
reviewerRe: [PATCH v1 01/11] relay: zero page->private when freeing pages
Quoted 15 lines · On Sun, 22 Feb 2026 22:26:31 -0500 Zi Yan <[email protected]> wrote:
This prepares for upcoming
page->privatechecks in page freeing path.Signed-off-by Zi Yan <[email protected]>Cc Jason Xing <[email protected]>Cc Yushan Zhou <[email protected]>Cc "Masami Hiramatsu (Google)" <[email protected]>--- kernel/relay.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)kernel/relay.c +0
-0
kernel/relay.c static void *relay_alloc_buf(struct rchan_buf *buf, size_t *size) · line 135
Quoted 6 lines
kernel/relay.c +2
-1@@ -131,8 +131,10 @@ static void *relay_alloc_buf(struct rchan_buf *buf, size_t *size)return mem; depopulate: -for (j =0 ; j < i; j++) +for (j =0 ; j < i; j++) { +set_page_private (buf->page_array[i],0 );
Hi Zi,
Should the index into page_array be j and not i over here?
Quoted 21 lines
kernel/relay.c +4
-1__free_page (buf->page_array[j]); + }relay_free_page_array (buf->page_array);return NULL ; }@@ -196,8 +198,10 @@ static void relay_destroy_buf(struct rchan_buf *buf)if (likely (buf->start)) {vunmap (buf->start); -for (i =0 ; i < buf->page_count; i++) +for (i =0 ; i < buf->page_count; i++) { +set_page_private (buf->page_array[i],0 );__free_page (buf->page_array[i]); + }relay_free_page_array (buf->page_array); } *per_cpu_ptr (chan->buf, buf->cpu) =NULL ;Signature · 1 line
2.51.0
Zi Yan
reviewerPATCH 2/11 mm/slub: zero page->private when freeing pages
In reply to Zi YanThis prepares for upcoming checks in page freeing path.
--- mm/slub.c | 1 + 1 file changed, 1 insertion(+)
mm/slub.c +1 -0
@@ -3511,6 +3511,7 @@ static void __free_slab(struct kmem_cache *s, struct slab *slab, bool allow_spin__slab_clear_pfmemalloc (slab); page->mapping =NULL ; +set_page_private (page,0 );__ClearPageSlab (page);mm_account_reclaimed_pages (pages);unaccount_slab (slab, order, s, allow_spin);
Signature · 1 line
2.51.0
Zi Yan
reviewerPATCH 3/11 drm/ttm: zero page->private when freeing pages
In reply to Zi YanThis prepares upcoming checks in page freeing path.
--- drivers/gpu/drm/ttm/ttm_pool.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/ttm/ttm_pool.c +1 -0
@@ -210,6 +210,7 @@ static void ttm_pool_free_page(struct ttm_pool *pool, enum ttm_caching caching,#endif if (!pool || !ttm_pool_uses_dma_alloc (pool)) { +set_page_private (p,0 );__free_pages (p, order);return ; }
Signature · 1 line
2.51.0
Re: [PATCH v1 03/11] drm/ttm: zero page->private when freeing pages
Quoted 13 lines · Zi Yan
This prepares upcoming checks in page freeing path.
Signed-off-by Zi Yan <[email protected]>Cc Christian Koenig <[email protected]>Cc Huang Rui <[email protected]>Cc Matthew Auld <[email protected]>Cc Matthew Brost <[email protected]>Cc Maarten Lankhorst <[email protected]>Cc Maxime Ripard <[email protected]>Cc Thomas Zimmermann <[email protected]>Cc David Airlie <[email protected]>Cc Simona Vetter <[email protected]>
Question (which was potentially already discussed) why isn't __free_pages() doing that?
Regards,
Christian.
Quoted 16 lines
--- drivers/gpu/drm/ttm/ttm_pool.c | 1 + 1 file changed, 1 insertion(+)drivers/gpu/drm/ttm/ttm_pool.c +1
-0@@ -210,6 +210,7 @@ static void ttm_pool_free_page(struct ttm_pool *pool, enum ttm_caching caching,#endif if (!pool || !ttm_pool_uses_dma_alloc (pool)) { +set_page_private (p,0 );__free_pages (p, order);return ; }
Zi Yan
reviewerPATCH 4/11 blk-mq: zero page->private when freeing pages
In reply to Zi YanThis prepares for upcoming checks in page freeing path.
--- block/blk-mq-tag.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
block/blk-mq-tag.c +5 -1
@@ -589,14 +589,18 @@ static void blk_mq_free_tags_callback(struct rcu_head *head)struct page *page;while (!list_empty (&tags->page_list)) { +int order; + page = list_first_entry(&tags->page_list, struct page, lru);list_del_init (&page->lru); + order = page->private;/* * Remove kmemleak object previously allocated in * blk_mq_alloc_rqs(). */ kmemleak_free (page_address (page)); -__free_pages (page, page->private); +set_page_private (page,0 ); +__free_pages (page, order); }kfree (tags); }
Signature · 1 line
2.51.0
Zi Yan
reviewerPATCH 5/11 watch_queue: zero page->private when freeing pages
In reply to Zi YanThis prepares for upcoming checks in page freeing path.
--- kernel/watch_queue.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/watch_queue.c +6 -2
@@ -301,8 +301,10 @@ long watch_queue_set_size(struct pipe_inode_info *pipe, unsigned int nr_notes)return 0 ; error_p: -while (--i >=0 ) +while (--i >=0 ) { +set_page_private (pages[i],0 );__free_page (pages[i]); + }kfree (pages); error: (void )account_pipe_buffers (pipe->user, nr_pages, pipe->nr_accounted);
@@ -398,8 +400,10 @@ static void __put_watch_queue(struct kref *kref)struct watch_filter *wfilter;int i; -for (i =0 ; i < wqueue->nr_pages; i++) +for (i =0 ; i < wqueue->nr_pages; i++) { +set_page_private (wqueue->notes[i],0 );__free_page (wqueue->notes[i]); + }kfree (wqueue->notes);bitmap_free (wqueue->notes_bitmap);
Signature · 1 line
2.51.0
Zi Yan
reviewerPATCH 6/11 binder: zero page->private when freeing pages
In reply to Zi YanThis prepares for upcoming checks in page freeing path.
--- drivers/android/binder_alloc.c | 1 + 1 file changed, 1 insertion(+)
drivers/android/binder_alloc.c +1 -0
@@ -306,6 +306,7 @@ static struct page *binder_page_alloc(struct binder_alloc *alloc,static void binder_free_page (struct page *page) {kfree ((struct binder_shrinker_mdata *)page_private (page)); +set_page_private (page,0 );__free_page (page); }
Signature · 1 line
2.51.0
Zi Yan
reviewerPATCH 7/11 null_blk: zero page->private when freeing pages
In reply to Zi YanThis prepares for upcoming checks in page freeing path.
--- drivers/block/null_blk/main.c | 1 + 1 file changed, 1 insertion(+)
drivers/block/null_blk/main.c +1 -0
@@ -886,6 +886,7 @@ static void null_free_page(struct nullb_page *t_page)__set_bit (NULLB_PAGE_FREE , t_page->bitmap);if (test_bit (NULLB_PAGE_LOCK , t_page->bitmap))return ; +set_page_private (t_page->page,0 );__free_page (t_page->page);kfree (t_page); }
Signature · 1 line
2.51.0
Zi Yan
reviewerPATCH 8/11 percpu: zero page->private when freeing pages
In reply to Zi YanThis prepares for upcoming checks in page freeing path.
--- mm/percpu-vm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
mm/percpu-vm.c +3 -1
@@ -61,8 +61,10 @@ static void pcpu_free_pages(struct pcpu_chunk *chunk,for (i = page_start; i < page_end; i++) {struct page *page = pages[pcpu_page_idx (cpu, i)]; -if (page) +if (page) { +set_page_private (page,0 );__free_page (page); + } } } }
Signature · 1 line
2.51.0
Zi Yan
reviewerPATCH 9/11 erofs: zero page->private when freeing pages
In reply to Zi YanThis prepares for upcoming checks in page freeing path.
--- fs/erofs/zutil.c | 1 + 1 file changed, 1 insertion(+)
fs/erofs/zutil.c +1 -0
@@ -210,6 +210,7 @@ void erofs_release_pages(struct page **pagepool) }spin_unlock (&z_erofs_rsvbuf->lock); } +set_page_private (page,0 );put_page (page); } }
Signature · 1 line
2.51.0
Zi Yan
reviewerPATCH 10/11 mm/huge_memory: add page->private check back in __split_folio_to_order()
In reply to Zi Yanpage->private should not be set in tail pages. Commit 4265d67e405a ("mm/migrate_device: add THP splitting during migration") removed it without a proper reason. Add it back.
--- mm/huge_memory.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
mm/huge_memory.c +10 -0
@@ -3548,6 +3548,16 @@ static void __split_folio_to_order(struct folio *folio, int old_order, new_folio->mapping = folio->mapping; new_folio->index = folio->index + i; +/* +* page->private should not be set in tail pages. Fix up and warn once +* if private is unexpectedly set. Do it before swap.val assignment +* since private overlaps with swap.val. +*/ +if (unlikely (new_folio->private)) { +VM_WARN_ON_ONCE_PAGE (true, new_head); + new_folio->private =NULL ; + } +if (folio_test_swapcache (folio)) new_folio->swap.val = folio->swap.val + i;
Signature · 1 line
2.51.0
Zi Yan
reviewerPATCH 11/11 mm/page_alloc: check page->private upon page free
In reply to Zi YanAny user is supposed to zero their allocated page->private at free time, including both head and tail pages if the freed page is compound. Add VM_WARN_ON_ONCE to check page->private.
Whoever encountering warnings from this commit needs to fix code that does not zero ->private when freeing a page/folio.
--- mm/page_alloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/page_alloc.c +2 -1
@@ -1410,6 +1410,7 @@ __always_inline bool __free_pages_prepare(struct page *page, } } (page + i)->flags.f &= ~PAGE_FLAGS_CHECK_AT_PREP ; +VM_WARN_ON_ONCE ((page + i)->private); } }if (folio_test_anon (folio)) {
@@ -1429,7 +1430,7 @@ __always_inline bool __free_pages_prepare(struct page *page,page_cpupid_reset_last (page); page->flags.f &= ~PAGE_FLAGS_CHECK_AT_PREP ; - page->private =0 ; +VM_WARN_ON_ONCE (page->private);reset_page_owner (page, order);page_table_check_free (page, order);pgalloc_tag_sub (page,1 << order);
Signature · 1 line
2.51.0
Quoted 5 lines · Zi Yan
Based on a recent discussion with David Hildenbrand on
page->privateis not zero when a page is freed[1], this patchset is trying to fix all users do not zero ->private when freeing a page and add checks to make sure all freed pages have ->private set to zero. For compound pages, both head page and tail pages need to have ->private set to zero.
Sorry, I didn't notice this conversation. It seems entirely unnecessary to me to zero out page->private before freeing.
I'm a bit confused that ac1ea219590c was needed too; I thought we cleared page->private in the allocation path, and I don't see why it needs to be cleared in the freeing path. split_page() should be clearing page->private.
Can we discuss this at the THP Cabal meeting on Wednesday? I don't think that introducing this new rule that page->private must be cleared by the users is a good idea.
David Hildenbrand (Arm)
maintainerQuoted 7 lines · Matthew Wilcox
Quoted 5 lines · Zi Yan
Based on a recent discussion with David Hildenbrand on
page->privateis not zero when a page is freed[1], this patchset is trying to fix all users do not zero ->private when freeing a page and add checks to make sure all freed pages have ->private set to zero. For compound pages, both head page and tail pages need to have ->private set to zero.
Quoted 7 lines
Sorry, I didn't notice this conversation. It seems entirely unnecessary to me to zero out
page->privatebefore freeing.I'm a bit confused that
ac1ea219590cwas needed too; I thought we clearedpage->privatein the allocation path, and I don't see why it needs to be cleared in the freeing path.split_page()should be clearingpage->private.
See discussion at https://lore.kernel.org/linux-mm/[email protected]/
Quoted 4 lines
Can we discuss this at the THP Cabal meeting on Wednesday? I don't think that introducing this new rule that
page->privatemust be cleared by the users is a good idea.
The benefit is that only the users that really use page->private will also zero it out.
This implies that all pages that enter+leave the page allocator will have page->private initialized and we can also likely do:
mm/internal.h +0 -1
@@ -724,7 +724,6 @@ static inline void prep_compound_tail(struct page *head, int tail_idx) p->mapping =TAIL_MAPPING ;set_compound_head (p, head); -set_page_private (p,0 ); }extern void prep_compound_page (struct page *page,unsigned int order);
Which is rather nice.
Signature · 3 lines
Cheers, David
syzbot ci has tested the following series
syzbot ci has tested the following series
[v1] Zero page->private when freeing pages
https://lore.kernel.org/all/[email protected]
* [PATCH v1 01/11] relay: zero page->private when freeing pages
* [PATCH v1 02/11] mm/slub: zero page->private when freeing pages
* [PATCH v1 03/11] drm/ttm: zero page->private when freeing pages
* [PATCH v1 04/11] blk-mq: zero page->private when freeing pages
* [PATCH v1 05/11] watch_queue: zero page->private when freeing pages
* [PATCH v1 06/11] binder: zero page->private when freeing pages
* [PATCH v1 07/11] null_blk: zero page->private when freeing pages
* [PATCH v1 08/11] percpu: zero page->private when freeing pages
* [PATCH v1 09/11] erofs: zero page->private when freeing pages
* [PATCH v1 10/11] mm/huge_memory: add page->private check back in __split_folio_to_order()
* [PATCH v1 11/11] mm/page_alloc: check page->private upon page free
and found the following issue:
WARNING in __free_frozen_pages
Full report is available here:
https://ci.syzbot.org/series/10f470ac-46ac-4e38-902d-dc86ae743494
***
WARNING in __free_frozen_pages
tree: mm-new URL: https://kernel.googlesource.com/pub/scm/linux/kernel/git/akpm/mm.git base: a6fdc327de4678e54b5122441c970371014117b0 arch: amd64 compiler: Debian clang version 21.1.8 (++20251221033036+2078da43e25a-1~exp1~20251221153213.50), Debian LLD 21.1.8 config: https://ci.syzbot.org/builds/0586347c-8ef1-427f-8a9c-7f6c08b616a9/config
Bluetooth: RFCOMM ver 1.11
Bluetooth: BNEP (Ethernet Emulation) ver 1.3
Bluetooth: BNEP filters: protocol multicast
Bluetooth: BNEP socket layer initialized
Bluetooth: HIDP (Human Interface Emulation) ver 1.2
Bluetooth: HIDP socket layer initialized
NET: Registered PF_RXRPC protocol family
Key type rxrpc registered
Key type rxrpc_s registered
NET: Registered PF_KCM protocol family
lec:lane_module_init: lec.c: initialized
mpoa:atm_mpoa_init: mpc.c: initializedl2tp_core: L2TP core driver, V2.0l2tp_ppp: PPPoL2TP kernel driver, V2.0l2tp_ip: L2TP IP encapsulation support (L2TPv3)l2tp_netlink: L2TP netlink interfacel2tp_eth: L2TP ethernet pseudowire support (L2TPv3)l2tp_ip6: L2TP IP encapsulation support for IPv6 (L2TPv3)
NET: Registered PF_PHONET protocol family
8021q: 802.1Q VLAN Support v1.8
sctp: Hash tables configured (bind 32/56)
NET: Registered PF_RDS protocol family
Registered RDS/infiniband transport
Registered RDS/tcp transport
tipc: Activated (version 2.0.0)
NET: Registered PF_TIPC protocol family
tipc: Started in single node mode
smc: adding smcd device lo without pnetid
NET: Registered PF_SMC protocol family
9pnet: Installing 9P2000 support
NET: Registered PF_CAIF protocol family
NET: Registered PF_IEEE802154 protocol family
Key type dns_resolver registered
Key type ceph registered
libceph: loaded (mon/osd proto 15/24)batman_adv: B.A.T.M.A.N. advanced 2025.5 (compatibility version 15) loaded
openvswitch: Open vSwitch switching datapath
NET: Registered PF_VSOCK protocol familympls_gso: MPLS GSO support
IPI shorthand broadcast: enabledsched_clock: Marking stable (19970046340, 93374727)->(20073238384, -9817317) registered taskstats version 1
Loading compiled-in X.509 certificates
Loaded X.509 cert 'Build time autogenerated kernel key: 98092a222e11368da223b039d625e21c3e2e069c'
zswap: loaded using pool 842
Demotion targets for Node 0: null
Demotion targets for Node 1: nulldebug_vm_pgtable: [debug_vm_pgtable ]: Validating architecture page table helpers
------------[ cut here ]------------ page->private WARNING: mm/page_alloc.c:1433 at __free_frozen_pages+0x78e/0xe10, CPU#0: swapper/0/1 Modules linked in: CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted syzkaller #0 PREEMPT(full) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 RIP: 0010:__free_frozen_pages+0x78e/0xe10 Code: 5f 5d e9 05 1e 00 00 48 b8 00 00 00 00 00 fc ff df 0f b6 44 05 00 84 c0 0f 85 d7 02 00 00 c7 03 ff ff ff ff e9 22 fc ff ff 90 <0f> 0b 90 e9 8d fc ff ff bd 01 00 00 00 83 f8 05 0f 85 bb fe ff ff RSP: 0000:ffffc900000676e0 EFLAGS: 00010282 RAX: 1ffffd4000bad935 RBX: ffffea0005d6c9a8 RCX: dffffc0000000000 RDX: 0000000000000000 RSI: 0000000000000004 RDI: ffffea0005d6c9b4 RBP: ffffea0005d6c9b8 R08: ffffea0005d6c9b7 R09: 1ffffd4000bad936 R10: dffffc0000000000 R11: fffff94000bad937 R12: ffffea0005d6c980 R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff88818de64000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffff88823ffff000 CR3: 000000000e54c000 CR4: 00000000000006f0 Call Trace: <TASK> destroy_args+0x15d/0x570 debug_vm_pgtable+0x3f8/0x410 do_one_initcall+0x250/0x8d0 do_initcall_level+0x104/0x190 do_initcalls+0x59/0xa0 kernel_init_freeable+0x2a6/0x3e0 kernel_init+0x1d/0x1d0 ret_from_fork+0x51e/0xb90 ret_from_fork_asm+0x1a/0x30 </TASK>
***
If these findings have caused you to resend the series or submit a separate fix, please add the following tag to your commit message:
---
This report is generated by a bot. It may contain errors. syzbot ci engineers can be reached at [email protected].
Quoted 7 lines · Zi Yan
Hi all,
Based on a recent discussion with David Hildenbrand on
page->privateis not zero when a page is freed[1], this patchset is trying to fix all users do not zero ->private when freeing a page and add checks to make sure all freed pages have ->private set to zero. For compound pages, both head page and tail pages need to have ->private set to zero.
Requiring the user to clear a field before freeing is just a way to awkward interface. Don't do that.
Zi Yan
reviewerQuoted 11 lines · Christoph Hellwig
Quoted 7 lines · Zi Yan
Hi all,
Based on a recent discussion with David Hildenbrand on
page->privateis not zero when a page is freed[1], this patchset is trying to fix all users do not zero ->private when freeing a page and add checks to make sure all freed pages have ->private set to zero. For compound pages, both head page and tail pages need to have ->private set to zero.Requiring the user to clear a field before freeing is just a way to awkward interface. Don't do that.
Page allocator hands the user a zero ->private. I think it is reasonable to require the user to return a zero ->private. Restoring things back to their original states is a common standard, isn't it? And most of users do that.
Do you have any example that shows doing such a thing is difficult, if not impossible?
--
Best Regards,
Yan, Zi
Quoted 6 lines · Zi Yan
Quoted 1 line
awkward interface. Don't do that.
Page allocator hands the user a zero ->private. I think it is reasonable to require the user to return a zero ->private. Restoring things back to their original states is a common standard, isn't it? And most of users do that.
No other relevant interface requires private data pointers, as that would be silly and cause tons of bugs.
Zi Yan
reviewerQuoted 10 lines · Christoph Hellwig
Quoted 6 lines · Zi Yan
Quoted 1 line
awkward interface. Don't do that.
Page allocator hands the user a zero ->private. I think it is reasonable to require the user to return a zero ->private. Restoring things back to their original states is a common standard, isn't it? And most of users do that.
No other relevant interface requires private data pointers, as that would be silly and cause tons of bugs.
filesystems use ->private and zero it before freeing a page. Can you provide a concrete example showing that requirement will cause bugs or make other functions hard to implement? With good examples, we can document them and make sure MM handle them properly (i.e., zeroing ->private for them).
--
Best Regards,
Yan, Zi
Quoted 11 lines · Christoph Hellwig
Quoted 7 lines · Zi Yan
Hi all,
Based on a recent discussion with David Hildenbrand on
page->privateis not zero when a page is freed[1], this patchset is trying to fix all users do not zero ->private when freeing a page and add checks to make sure all freed pages have ->private set to zero. For compound pages, both head page and tail pages need to have ->private set to zero.Requiring the user to clear a field before freeing is just a way to awkward interface. Don't do that.
Completely agree. This is just asking for trouble.
The cache line(s) backing this struct page are most likely accessed anyway on free/alloc. So I don't see much extra overhead.
Regards,
Christian.
David Hildenbrand (Arm)
maintainerQuoted 10 lines · Christian König
Quoted 9 lines · Christoph Hellwig
Quoted 7 lines · Zi Yan
Hi all,
Based on a recent discussion with David Hildenbrand on
page->privateis not zero when a page is freed[1], this patchset is trying to fix all users do not zero ->private when freeing a page and add checks to make sure all freed pages have ->private set to zero. For compound pages, both head page and tail pages need to have ->private set to zero.
Quoted 6 lines
Quoted 2 lines
Requiring the user to clear a field before freeing is just a way to awkward interface. Don't do that.
Completely agree. This is just asking for trouble.
The cache line(s) backing this struct page are most likely accessed anyway on free/alloc. So I don't see much extra overhead.
I think the question is more around handling non-head pages when freeing larger orders. But maybe the overhead of zeroing page->private it there as well in __free_pages_prepare() is tolerable.
I'll note, though, that we already require page->mapping and page->memcg_data of pages to be zeroed by the caller, so it's not completely crazy. (see page_expected_state)
Signature · 3 lines
Cheers, David
Quoted 11 lines · David Hildenbrand (Arm)
Quoted 10 lines · Christian König
Quoted 9 lines · Christoph Hellwig
Quoted 7 lines · Zi Yan
Hi all,
Based on a recent discussion with David Hildenbrand on
page->privateis not zero when a page is freed[1], this patchset is trying to fix all users do not zero ->private when freeing a page and add checks to make sure all freed pages have ->private set to zero. For compound pages, both head page and tail pages need to have ->private set to zero.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Requiring the user to clear a field before freeing is just a way to awkward interface. Don't do that.
Completely agree. This is just asking for trouble.
The cache line(s) backing this struct page are most likely accessed anyway on free/alloc. So I don't see much extra overhead.
I think the question is more around handling non-head pages when freeing larger orders. But maybe the overhead of zeroing
page->privateit there as well in__free_pages_prepare()is tolerable.
Good point, sounds like that is a bit more than I thought it would be.
Quoted 1 line
I'll note, though, that we already require
page->mappingandpage->memcg_dataof pages to be zeroed by the caller, so it's not completely crazy. (seepage_expected_state)
Well that's not defensive at all, basically everybody which forgets to do that can cause hard to debug trouble. Maybe that practice should be reconsidered.
Regards,
Christian.
David Hildenbrand (Arm)
maintainerQuoted 10 lines · Christian König
Quoted 7 lines · David Hildenbrand (Arm)
Quoted 4 lines · Christian König
Completely agree. This is just asking for trouble.
The cache line(s) backing this struct page are most likely accessed anyway on free/alloc. So I don't see much extra overhead.
I think the question is more around handling non-head pages when freeing larger orders. But maybe the overhead of zeroing
page->privateit there as well in__free_pages_prepare()is tolerable.Good point, sounds like that is a bit more than I thought it would be.
Right. We already iterate over all "tail" pages in __free_pages_prepare() to clear page flags
(page + i)->flags.f &= ~PAGE_FLAGS_CHECK_AT_PREP;
Maybe zeroing page->private there is not too bad.
Quoted 4 lines
Quoted 2 lines
I'll note, though, that we already require
page->mappingandpage->memcg_dataof pages to be zeroed by the caller, so it's not completely crazy. (seepage_expected_state)Well that's not defensive at all, basically everybody which forgets to do that can cause hard to debug trouble. Maybe that practice should be reconsidered.
Right, we do have check_pages= to activate the page_expected_state() checks, where we will detect such problems.
(including the mapcount being -1 etc.)
Signature · 3 lines
Cheers, David