git: cffe8054a61c - stable/13 - riscv: add an assert to pmap_remove_pages()

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Thu, 13 Oct 2022 14:09:56 UTC
The branch stable/13 has been updated by mhorne:

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

commit cffe8054a61ca435256f8fe2498ad14d2f61d570
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2022-08-25 20:08:20 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2022-10-13 14:05:21 +0000

    riscv: add an assert to pmap_remove_pages()
    
    Similar checks exist for both arm64 and amd64, but note that for amd64
    it is a bare panic().
    
    Reviewed by:    markj
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D36564
    
    (cherry picked from commit 99fe523778af8cd0db3a17b253adb77a980176be)
---
 sys/riscv/riscv/pmap.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sys/riscv/riscv/pmap.c b/sys/riscv/riscv/pmap.c
index d72b989f8f38..a3a26a8a883d 100644
--- a/sys/riscv/riscv/pmap.c
+++ b/sys/riscv/riscv/pmap.c
@@ -3908,6 +3908,10 @@ pmap_remove_pages(pmap_t pmap)
 				ptepde = pmap_load(pte);
 				pte = pmap_l1_to_l2(pte, pv->pv_va);
 				tpte = pmap_load(pte);
+
+				KASSERT((tpte & PTE_V) != 0,
+				    ("L2 PTE is invalid... bogus PV entry? "
+				    "va=%#lx, pte=%#lx", pv->pv_va, tpte));
 				if ((tpte & PTE_RWX) != 0) {
 					superpage = true;
 				} else {