Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 31 Jul 2021 13:54:13 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 041b7317f75e - main - Add pmap_vm_page_alloc_check()
Message-ID:  <202107311354.16VDsDNn033408@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=041b7317f75ecc5e1629e2dd6786c8bdbe1b19eb

commit 041b7317f75ecc5e1629e2dd6786c8bdbe1b19eb
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2021-07-10 19:53:41 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2021-07-31 13:53:42 +0000

    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
---
 sys/amd64/include/pmap.h   | 4 ++++
 sys/arm/include/pmap.h     | 2 ++
 sys/arm64/include/pmap.h   | 2 ++
 sys/i386/include/pmap.h    | 2 ++
 sys/mips/include/pmap.h    | 2 ++
 sys/powerpc/include/pmap.h | 2 ++
 sys/riscv/include/pmap.h   | 2 ++
 sys/vm/vm_page.c           | 1 +
 8 files changed, 17 insertions(+)

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);
 }
 
 /*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202107311354.16VDsDNn033408>