Page MenuHomeFreeBSD

linuxkpi: Assert that "order" is sane
Needs ReviewPublic

Authored by markj on Jun 2 2023, 7:35 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Feb 25, 10:46 AM
Unknown Object (File)
Fri, Feb 14, 4:15 PM
Unknown Object (File)
Thu, Feb 6, 2:22 PM
Unknown Object (File)
Dec 28 2024, 10:10 AM
Unknown Object (File)
Dec 27 2024, 7:00 AM
Unknown Object (File)
Dec 11 2024, 8:02 AM
Unknown Object (File)
Nov 21 2024, 9:39 AM
Unknown Object (File)
Oct 1 2024, 10:24 PM
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 ?