Re: [PATCH bpf-next v4 3/3] bpf, arena: check range_tree_set return in arena_free_pages and arena_free_worker
| Newsgroups | org.kernel.vger.bpf,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <0610a5be7e77a201576eb392be5a60e7a18f83ea3ce3d830ddb16630b853a282@mail.kernel.org> |
> bpf, arena: check range_tree_set return in arena_free_pages and arena_free_worker > > arena_free_pages() and arena_free_worker() now handle range_tree_set() > errors. arena_free_pages() aborts the free on error, and > arena_free_worker() moves range_tree_set() before PTE clearing so that a > failed tree update leaves the PTEs intact instead of freeing pages that > the arena free tree does not track. > > Also check the range_tree_set() return value in arena_alloc_pages()'s > error path, which restores the unpopulated tail of a partially allocated > range; log a warning instead of silently leaking the virtual range when > the tree update fails. > > range_tree_set() is failure-atomic (it pre-allocates the node before > touching the tree), so on -ENOMEM the range stays tracked as allocated > and the pages remain mapped and accessible. A failed free is therefore > retryable, and arena_map_free() reclaims any retained pages at map > destruction; aborting the free avoids clearing PTEs for pages the arena > free tree does not track. > > In arena_free_worker() a failed tree update used to leave the span in > the drained list, where the second loop would still flush TLB entries, > zap user VMAs, and free the span itself: the free request was dropped, > user mappings were destroyed for a free that never happened, and the > pages stayed mapped until map destruction. Keep failed spans on > arena->free_spans instead and retry them on a later worker run; only > spans whose PTE clearing actually ran are flushed, zapped, and released. > > Suggested-by: Emil Tsalapatis <[email protected]> > Signed-off-by: Yuan Chen <[email protected]> This looks like a bug fix for error handling in the arena code introduced in an earlier commit. Should this include a Fixes: tag pointing to: Fixes: dc11a4dba246 ("bpf: Recover arena kernel faults with scratch page") --- AI reviewed your patch. Please fix the bug or email reply why it's not a bug. See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md CI run summary: https://github.com/kernel-patches/bpf/actions/runs/32736729475