aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2021-07-10 19:53:41 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2021-07-31 13:53:42 +0000
commit041b7317f75ecc5e1629e2dd6786c8bdbe1b19eb (patch)
tree030e70a7a34c9921dbe97f062e6cb69e4faf8f05
parente18380e341410ce70d97560a22827591f4b2d373 (diff)
downloadsrc-041b7317f75ecc5e1629e2dd6786c8bdbe1b19eb.tar.gz
src-041b7317f75ecc5e1629e2dd6786c8bdbe1b19eb.zip
Add pmap_vm_page_alloc_check()
which is the place to put MD asserts about allocated pages. On amd64, verify that allocated page does not belong to the kernel (text, data) or early allocated pages. Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D31121
-rw-r--r--sys/amd64/include/pmap.h4
-rw-r--r--sys/arm/include/pmap.h2
-rw-r--r--sys/arm64/include/pmap.h2
-rw-r--r--sys/i386/include/pmap.h2
-rw-r--r--sys/mips/include/pmap.h2
-rw-r--r--sys/powerpc/include/pmap.h2
-rw-r--r--sys/riscv/include/pmap.h2
-rw-r--r--sys/vm/vm_page.c1
8 files changed, 17 insertions, 0 deletions
diff --git a/sys/amd64/include/pmap.h b/sys/amd64/include/pmap.h
index e9117481a41e..401eae0044f9 100644
--- a/sys/amd64/include/pmap.h
+++ b/sys/amd64/include/pmap.h
@@ -456,6 +456,10 @@ extern int invpcid_works;
#define pmap_page_is_write_mapped(m) (((m)->a.flags & PGA_WRITEABLE) != 0)
#define pmap_unmapbios(va, sz) pmap_unmapdev((va), (sz))
+#define pmap_vm_page_alloc_check(m) \
+ KASSERT(m->phys_addr < kernphys || m->phys_addr >= KERNend, \
+ ("allocating kernel page %p", m));
+
struct thread;
void pmap_activate_boot(pmap_t pmap);
diff --git a/sys/arm/include/pmap.h b/sys/arm/include/pmap.h
index 2f407a9c8760..d06d44d648d5 100644
--- a/sys/arm/include/pmap.h
+++ b/sys/arm/include/pmap.h
@@ -73,5 +73,7 @@ pmap_vmspace_copy(pmap_t dst_pmap __unused, pmap_t src_pmap __unused)
#define PMAP_ENTER_QUICK_LOCKED 0x10000000
+#define pmap_vm_page_alloc_check(m)
+
#endif /* _KERNEL */
#endif /* !_MACHINE_PMAP_H_ */
diff --git a/sys/arm64/include/pmap.h b/sys/arm64/include/pmap.h
index 61fba1e3c1f8..3b71e79f45ad 100644
--- a/sys/arm64/include/pmap.h
+++ b/sys/arm64/include/pmap.h
@@ -162,6 +162,8 @@ extern vm_offset_t virtual_end;
#define L1_MAPPABLE_P(va, pa, size) \
((((va) | (pa)) & L1_OFFSET) == 0 && (size) >= L1_SIZE)
+#define pmap_vm_page_alloc_check(m)
+
void pmap_activate_vm(pmap_t);
void pmap_bootstrap(vm_offset_t, vm_offset_t, vm_paddr_t, vm_size_t);
int pmap_change_attr(vm_offset_t va, vm_size_t size, int mode);
diff --git a/sys/i386/include/pmap.h b/sys/i386/include/pmap.h
index f2e65c829ff4..5ac99b92cad3 100644
--- a/sys/i386/include/pmap.h
+++ b/sys/i386/include/pmap.h
@@ -238,6 +238,8 @@ pmap_vmspace_copy(pmap_t dst_pmap __unused, pmap_t src_pmap __unused)
struct sf_buf;
+#define pmap_vm_page_alloc_check(m)
+
/*
* Only the following functions or macros may be used before pmap_bootstrap()
* is called: pmap_kenter(), pmap_kextract(), pmap_kremove(), vtophys(), and
diff --git a/sys/mips/include/pmap.h b/sys/mips/include/pmap.h
index 6678f8264ad7..fb186011bd85 100644
--- a/sys/mips/include/pmap.h
+++ b/sys/mips/include/pmap.h
@@ -166,6 +166,8 @@ extern vm_offset_t virtual_end;
#define pmap_page_is_mapped(m) (!TAILQ_EMPTY(&(m)->md.pv_list))
#define pmap_page_is_write_mapped(m) (((m)->a.flags & PGA_WRITEABLE) != 0)
+#define pmap_vm_page_alloc_check(m)
+
void pmap_bootstrap(void);
void *pmap_mapdev(vm_paddr_t, vm_size_t);
void *pmap_mapdev_attr(vm_paddr_t, vm_size_t, vm_memattr_t);
diff --git a/sys/powerpc/include/pmap.h b/sys/powerpc/include/pmap.h
index a292be660b09..2f1886a27093 100644
--- a/sys/powerpc/include/pmap.h
+++ b/sys/powerpc/include/pmap.h
@@ -301,6 +301,8 @@ extern struct pmap kernel_pmap_store;
#define pmap_page_is_write_mapped(m) (((m)->a.flags & PGA_WRITEABLE) != 0)
+#define pmap_vm_page_alloc_check(m)
+
void pmap_bootstrap(vm_offset_t, vm_offset_t);
void pmap_kenter(vm_offset_t va, vm_paddr_t pa);
void pmap_kenter_attr(vm_offset_t va, vm_paddr_t pa, vm_memattr_t);
diff --git a/sys/riscv/include/pmap.h b/sys/riscv/include/pmap.h
index 64b529e95887..599adfa4ce19 100644
--- a/sys/riscv/include/pmap.h
+++ b/sys/riscv/include/pmap.h
@@ -139,6 +139,8 @@ extern vm_offset_t virtual_end;
struct thread;
+#define pmap_vm_page_alloc_check(m)
+
void pmap_activate_boot(pmap_t);
void pmap_activate_sw(struct thread *);
void pmap_bootstrap(vm_offset_t, vm_paddr_t, vm_size_t);
diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c
index 953120e25b4e..d435b871b7cb 100644
--- a/sys/vm/vm_page.c
+++ b/sys/vm/vm_page.c
@@ -2416,6 +2416,7 @@ vm_page_alloc_check(vm_page_t m)
("page %p has unexpected memattr %d",
m, pmap_page_get_memattr(m)));
KASSERT(m->valid == 0, ("free page %p is valid", m));
+ pmap_vm_page_alloc_check(m);
}
/*