summaryrefslogtreecommitdiff
path: root/sys/uvm
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2024-11-05 18:35:15 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2024-11-05 18:35:15 +0000
commit23ce98f91a129d63a82968c407dda03d138aa218 (patch)
tree1426a2f9bdb0fcd352395ad4db6b057efa144171 /sys/uvm
parent7083b9526bdbf1120aef6718a4123f099388691a (diff)
Protect the page daemon memory reserve from allocations in interrupt contexts.
ok miod@, kettenis@
Diffstat (limited to 'sys/uvm')
-rw-r--r--sys/uvm/uvm_pmemrange.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/sys/uvm/uvm_pmemrange.c b/sys/uvm/uvm_pmemrange.c
index 9351ebf99be..0e9aa8dc64e 100644
--- a/sys/uvm/uvm_pmemrange.c
+++ b/sys/uvm/uvm_pmemrange.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uvm_pmemrange.c,v 1.71 2024/11/05 18:27:24 mpi Exp $ */
+/* $OpenBSD: uvm_pmemrange.c,v 1.72 2024/11/05 18:35:14 mpi Exp $ */
/*
* Copyright (c) 2024 Martin Pieuchot <mpi@openbsd.org>
@@ -81,6 +81,21 @@ int uvm_pmr_pg_to_memtype(struct vm_page *);
void uvm_pmr_print(void);
#endif
+static inline int
+in_pagedaemon(int allowsyncer)
+{
+#if !defined(__sparc64__)
+ if (curcpu()->ci_idepth > 0)
+ return 0;
+#endif
+ if (curproc == uvm.pagedaemon_proc)
+ return 1;
+ /* XXX why is the syncer allowed to use the pagedaemon's reserve? */
+ if (allowsyncer && (curproc == syncerproc))
+ return 1;
+ return 0;
+}
+
/*
* Memory types. The page flags are used to derive what the current memory
* type of a page is.
@@ -967,8 +982,8 @@ again:
}
if ((uvmexp.free <= (uvmexp.reserve_pagedaemon + count)) &&
- (curproc != uvm.pagedaemon_proc) && (curproc != syncerproc)) {
- uvm_unlock_fpageq();
+ !in_pagedaemon(1)) {
+ uvm_unlock_fpageq();
if (flags & UVM_PLA_WAITOK) {
uvm_wait("uvm_pmr_getpages");
goto again;
@@ -2095,6 +2110,10 @@ uvm_wait_pla(paddr_t low, paddr_t high, paddr_t size, int failok)
struct uvm_pmalloc pma;
const char *wmsg = "pmrwait";
+#if !defined(__sparc64__)
+ KASSERT(curcpu()->ci_idepth == 0);
+#endif
+
if (curproc == uvm.pagedaemon_proc) {
/*
* This is not that uncommon when the pagedaemon is trying