Page MenuHomeFreeBSD

phys_alloc_seg_contig: don't allocate past seg->end
ClosedPublic

Authored by dougm on Jan 12 2022, 5:47 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Apr 26, 3:16 AM
Unknown Object (File)
Thu, Apr 18, 8:15 PM
Unknown Object (File)
Wed, Apr 17, 8:49 PM
Unknown Object (File)
Mar 30 2024, 1:03 PM
Unknown Object (File)
Mar 30 2024, 1:03 PM
Unknown Object (File)
Mar 30 2024, 1:03 PM
Unknown Object (File)
Mar 30 2024, 1:03 PM
Unknown Object (File)
Jan 12 2024, 8:01 AM
Subscribers

Details

Summary

In vm_phys_alloc_seg_contig, check alignment before checking orders of multiple memory blocks, to avoid such deeply nested code. In checking multiple memory blocks, check seg->end only once, against pa_end because there's no need to repeat the test for consecutive values of pa, and because the current code, in the case that pa reaches pa_end and passes seg->end in the same iteration, proceeds to allocate that memory.

Diff Detail

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

Event Timeline

dougm requested review of this revision.Jan 12 2022, 5:47 PM
dougm created this revision.

Undo change involving fictitious seg.

dougm edited the summary of this revision. (Show Details)

Remove some offensive parts.

Update, rearrange comments.

sys/vm/vm_phys.c
1456

insert a blank before the block comment

1462

pa += 1 << (PAGE_SHIFT + VM_NFREEORDER - 1);

then you are shifting by a constant and the compiler will warn if overflow occurs

1463

oind -> VM_NFREEORDER - 1

1465–1466

put this inside the loop

dougm marked 4 inline comments as done.

Accept all proffered advice.

This revision is now accepted and ready to land.Jan 18 2022, 6:05 PM
This revision was automatically updated to reflect the committed changes.