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)
Sun, Feb 2, 11:59 AM
Unknown Object (File)
Mon, Jan 27, 5:02 PM
Unknown Object (File)
Mon, Jan 27, 4:59 PM
Unknown Object (File)
Mon, Jan 27, 4:48 PM
Unknown Object (File)
Mon, Jan 27, 6:13 AM
Unknown Object (File)
Mon, Jan 27, 4:13 AM
Unknown Object (File)
Sun, Jan 26, 8:10 AM
Unknown Object (File)
Sun, Jan 26, 1:13 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

Lint
Lint Skipped
Unit
Tests Skipped

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.