On Tue, May 06, 2025 at 04:55:20PM +0200, Andrey Ryabinin wrote:
- if (likely(pte_none(ptep_get(ptep)))) {
- if (likely(pte_none(ptep_get(ptep)))) set_pte_at(&init_mm, addr, ptep, pte);
page = 0;
With this patch, now if the pte is already set, the page is leaked?
Yes. But currently it is leaked for previously allocated pages anyway, so no change in behaviour (unless I misread the code).
Current code doesn't even allocate page if pte set, and if set pte discovered only after taking spinlock, the page will be freed, not leaked.
Oh, right. I rather meant pages that are leaked in case of a failure. My bad.
Whereas, this patch leaks page for every single !pte_none case. This will build up over time as long as vmalloc called.
Should we set data->pages[PFN_DOWN(addr - data->start)] = NULL and free non-null elements later in __kasan_populate_vmalloc()?
Should the allocation fail on boot, the kernel would not fly anyway.
This is not boot code, it's called from vmalloc() code path.
FWIW, it is called from rest_init() too.
If for whatever reason we want to free, that should be a follow-up change, as far as I am concerned.
We want to free it, because we don't want unbound memory leak.
Will send v5.
Thanks!