git: 48d01e24f9d5 - stable/13 - vm_addr_ok: add power2 invariant check
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 12 Jul 2022 17:32:36 UTC
The branch stable/13 has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=48d01e24f9d5673d47063fe7e8edfa540c85526f commit 48d01e24f9d5673d47063fe7e8edfa540c85526f Author: Doug Moore <dougm@FreeBSD.org> AuthorDate: 2022-01-10 07:17:25 +0000 Commit: Doug Moore <dougm@FreeBSD.org> CommitDate: 2022-07-12 16:26:12 +0000 vm_addr_ok: add power2 invariant check With INVARIANTS defined, have vm_addr_align_ok and vm_addr_bound_ok panic when passed an alignment/boundary parameter that is not a power of two. Reviewed by: alc Suggested by: kib, se Differential Revision: https://reviews.freebsd.org/D33725 (cherry picked from commit ae13829ddce0b5fbf12f2b240a26414b41def8ba) --- sys/vm/vm_extern.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sys/vm/vm_extern.h b/sys/vm/vm_extern.h index bc01e5a874f9..93c7118353ba 100644 --- a/sys/vm/vm_extern.h +++ b/sys/vm/vm_extern.h @@ -141,6 +141,11 @@ u_int vm_wait_count(void); static inline bool vm_addr_align_ok(vm_paddr_t pa, u_long alignment) { +#ifdef INVARIANTS + if (!powerof2(alignment)) + panic("%s: alignment is not a power of 2: %#lx", + __func__, alignment); +#endif return ((pa & (alignment - 1)) == 0); } @@ -151,6 +156,11 @@ vm_addr_align_ok(vm_paddr_t pa, u_long alignment) static inline bool vm_addr_bound_ok(vm_paddr_t pa, vm_paddr_t size, vm_paddr_t boundary) { +#ifdef INVARIANTS + if (!powerof2(boundary)) + panic("%s: boundary is not a power of 2: %#jx", + __func__, (uintmax_t)boundary); +#endif return (((pa ^ (pa + size - 1)) & -boundary) == 0); }