aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Moore <dougm@FreeBSD.org>2022-01-10 07:17:25 +0000
committerDoug Moore <dougm@FreeBSD.org>2022-07-12 16:26:12 +0000
commit48d01e24f9d5673d47063fe7e8edfa540c85526f (patch)
tree397d781e173c178763f9dbcf1ad38c73e8c3554d
parent01f79c9da806b7e64fc250c516b04e9e12a8d7bb (diff)
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)
-rw-r--r--sys/vm/vm_extern.h10
1 files changed, 10 insertions, 0 deletions
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);
}