Page MenuHomeFreeBSD

vm_phys; fix uncalled free_contig
ClosedPublic

Authored by dougm on Dec 4 2023, 5:16 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Nov 5, 10:09 AM
Unknown Object (File)
Fri, Nov 1, 4:24 AM
Unknown Object (File)
Sat, Oct 19, 10:52 PM
Unknown Object (File)
Tue, Oct 15, 4:18 PM
Unknown Object (File)
Sep 30 2024, 9:01 AM
Unknown Object (File)
Sep 27 2024, 12:11 PM
Unknown Object (File)
Sep 19 2024, 8:33 PM
Unknown Object (File)
Sep 19 2024, 3:23 PM
Subscribers

Details

Summary

Function vm_phys_free_contig does not always free memory properly when that memory was just allocated with vm_phys_alloc_contig. Change it to free memory properly in all cases.

vm_phys_free_contig was defined, and invoked, in a case when the npages parameter was necessarily bigger than the number of pages in the largest free block of the allocator, but neither its name nor its documentation suggested that it was broken for smaller values of npages. Since then, changes have removed all the calls to this function, so it's correctness doesn't matter much, but testing with a dynamically loaded module that calls vm_phys_free_contig with a too-small npages parameter corrupts memory management structures and should be corrected.

Test Plan

It takes dynamically loading a module I've written to test it. Tests that broke the kernel no longer do so.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

dougm requested review of this revision.Dec 4 2023, 5:16 AM
dougm created this revision.
sys/vm/vm_phys.c
1230

The more common spelling in this file is atop(VM_PAGE_TO_PHYS(m)).

1231

If npages is 1, we'll compute max_order = min(flsll(0) - 1, VM_NFREEORDER - 1) and get max_order = VM_NFREEORDER - 1, but that's not correct.

This revision is now accepted and ready to land.Dec 20 2023, 3:00 PM
This revision was automatically updated to reflect the committed changes.