From e1fd8b91ccb583ed6f98f5baa0e7fc197735b919 Mon Sep 17 00:00:00 2001 From: kettenis Date: Tue, 12 Oct 2021 18:06:15 +0000 Subject: [PATCH] Add (minimal) accounting for wired pages in userland pmaps. This enables enforcing of RLIMIT_MEMLOCK on powerpc64. ok mpi@ --- sys/arch/powerpc64/include/pmap.h | 3 ++- sys/arch/powerpc64/powerpc64/pmap.c | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/sys/arch/powerpc64/include/pmap.h b/sys/arch/powerpc64/include/pmap.h index bb6c29dd926..c7f4c9e257b 100644 --- a/sys/arch/powerpc64/include/pmap.h +++ b/sys/arch/powerpc64/include/pmap.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pmap.h,v 1.17 2021/05/30 15:08:08 visa Exp $ */ +/* $OpenBSD: pmap.h,v 1.18 2021/10/12 18:06:15 kettenis Exp $ */ /* * Copyright (c) 2020 Mark Kettenis @@ -62,6 +62,7 @@ extern struct pmap kernel_pmap_store; #define pmap_kernel() (&kernel_pmap_store) #define pmap_resident_count(pm) ((pm)->pm_stats.resident_count) +#define pmap_wired_count(pm) ((pm)->pm_stats.wired_count) #define pmap_unuse_final(p) #define pmap_remove_holes(vm) diff --git a/sys/arch/powerpc64/powerpc64/pmap.c b/sys/arch/powerpc64/powerpc64/pmap.c index f18c919049e..9d19c54295a 100644 --- a/sys/arch/powerpc64/powerpc64/pmap.c +++ b/sys/arch/powerpc64/powerpc64/pmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pmap.c,v 1.56 2021/05/11 18:21:12 kettenis Exp $ */ +/* $OpenBSD: pmap.c,v 1.57 2021/10/12 18:06:15 kettenis Exp $ */ /* * Copyright (c) 2015 Martin Pieuchot @@ -217,6 +217,12 @@ PTED_MANAGED(struct pte_desc *pted) return !!(pted->pted_va & PTED_VA_MANAGED_M); } +static inline int +PTED_WIRED(struct pte_desc *pted) +{ + return !!(pted->pted_va & PTED_VA_WIRED_M); +} + static inline int PTED_VALID(struct pte_desc *pted) { @@ -858,6 +864,11 @@ pmap_remove_pted(pmap_t pm, struct pte_desc *pted) pm->pm_stats.resident_count--; + if (PTED_WIRED(pted)) { + pm->pm_stats.wired_count--; + pted->pted_va &= ~PTED_VA_WIRED_M; + } + PMAP_HASH_LOCK(s); if ((pte = pmap_ptedinhash(pted)) != NULL) pte_zap(pte, pted); @@ -1085,6 +1096,10 @@ pmap_enter(pmap_t pm, vaddr_t va, paddr_t pa, vm_prot_t prot, int flags) prot &= ~PROT_WRITE; pmap_fill_pte(pm, va, pa, pted, prot, cache); + if (flags & PMAP_WIRED) { + pted->pted_va |= PTED_VA_WIRED_M; + pm->pm_stats.wired_count++; + } if (pg != NULL) { pmap_enter_pv(pted, pg); /* only managed mem */ @@ -1438,6 +1453,15 @@ pmap_deactivate(struct proc *p) void pmap_unwire(pmap_t pm, vaddr_t va) { + struct pte_desc *pted; + + PMAP_VP_LOCK(pm); + pted = pmap_vp_lookup(pm, va); + if (pted && PTED_WIRED(pted)) { + pm->pm_stats.wired_count--; + pted->pted_va &= ~PTED_VA_WIRED_M; + } + PMAP_VP_UNLOCK(pm); } void -- 2.20.1