Page MenuHomeFreeBSD

linuxkpi: Assert that "order" is sane
AbandonedPublic

Authored by markj on Jun 2 2023, 7:35 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Nov 26, 6:10 AM
Unknown Object (File)
Sat, Nov 22, 11:26 PM
Unknown Object (File)
Tue, Nov 11, 1:11 AM
Unknown Object (File)
Sun, Nov 9, 2:12 AM
Unknown Object (File)
Nov 7 2025, 12:25 AM
Unknown Object (File)
Nov 4 2025, 2:51 AM
Unknown Object (File)
Oct 28 2025, 4:52 AM
Unknown Object (File)
Oct 20 2025, 3:48 AM
Subscribers

Details

Reviewers
hselasky
Group Reviewers
linuxkpi
Summary

Suggested by: hselasky

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 51904
Build 48795: arc lint + arc unit

Event Timeline

markj requested review of this revision.Jun 2 2023, 7:35 PM

I wonder if sizeof(uintptr_t) rather than sizeof(size_t) would be better?

sys/compat/linuxkpi/common/src/linux_page.c
189

We should probably move the assignment below the KASSERT?

markj marked an inline comment as done.Jun 4 2023, 3:09 PM
In D40398#919802, @bz wrote:

I wonder if sizeof(uintptr_t) rather than sizeof(size_t) would be better?

Well, we want 1 << order to fit in a type used to represent sizes, so I think size_t is correct. Consider that on CHERI, sizeof(uintptr_t) is 16, but we still want order <= 63.

sys/compat/linuxkpi/common/src/linux_page.c
189

Good catch, thank you.

markj marked an inline comment as done.

Assert on "order" before using it.

sys/compat/linuxkpi/common/src/linux_page.c
192

Should we subtract PAGE_SHIFT ?
order < sizeof(size_t) * NBBY - PAGE_SHIFT

Then it would never overflow?

markj marked an inline comment as done.

Tighten the check in one place that shifts PAGE_MASK instead of 1.

sys/compat/linuxkpi/common/src/linux_page.c
106

Same here.

164

Same here.

208

Can you verify the actual value of PAGE_MASK here? Because we have this:

/usr/src/sys/compat/linuxkpi/common/include/linux/page.h:#undef	PAGE_MASK
/usr/src/sys/compat/linuxkpi/common/include/linux/page.h:#define	PAGE_MASK	(~(PAGE_SIZE-1))

Linux's PAGE_MASK is not FreeBSD's PAGE_MASK and maybe not use it?

sys/compat/linuxkpi/common/src/linux_page.c
106

Why? There is no code here which computes (1ul << order) * PAGE_SIZE. npages is passed directly to the page allocator.

164

Same as above.

208

Oof, thank you.

sys/compat/linuxkpi/common/src/linux_page.c
106

I was just thinking that if you cannot allocate a certain amount, you cannot free it either. Maybe just define the limit as a macro / enum ?