> Note that NetBSD also calls pmap_kenter_pa(9) in this case. So maybe
> there's a fix for landisk out there. Anyone care about landisk?
I'm not sure of this, but to begin with, it appears we lack that fix,
which I am testing at the moment (without the asserts), diff at the
end of this mail.
revision 1.86
date: 2021-09-02 07:55:56 +0000; author: rin; state: Exp; lines: +14 -5;
commitid: wUuIRmZIbubS0m7D;
PR port-sh3/56381
pmap_enter() returns ENOMEM if __pmap_pte_alloc() fails and PMAP_CANFAIL
flag is specified. In this case, remove pv via __pmap_pv_remove() if it is
added to p-v map list via __pmap_pv_enter().
Otherwise, pmap becomes an inconsistent state, which results in an infinite
loop in pmap_page_protect(), as reported in the PR.
Also, KASSERT's are added for sure, in order to detect the infinite loops.
Great thanks to chs@ for finding out this bug!!
Index: pmap.c
===================================================================
RCS file: /OpenBSD/src/sys/arch/sh/sh/pmap.c,v
diff -u -p -r1.30 pmap.c
--- pmap.c 1 Jan 2023 19:49:17 -0000 1.30
+++ pmap.c 11 Sep 2025 17:10:04 -0000
@@ -357,8 +357,11 @@ pmap_enter(pmap_t pmap, vaddr_t va, padd
else {
pte = __pmap_pte_alloc(pmap, va);
if (pte == NULL) {
- if (flags & PMAP_CANFAIL)
+ if (flags & PMAP_CANFAIL) {
+ if (pg != NULL)
+ __pmap_pv_remove(pmap, pg, va);
return ENOMEM;
+ }
panic("pmap_enter: cannot allocate pte");
}
}