Changeset View
Changeset View
Standalone View
Standalone View
sys/vm/vm_glue.c
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | |||||
#include "opt_vm.h" | #include "opt_vm.h" | ||||
#include "opt_kstack_pages.h" | #include "opt_kstack_pages.h" | ||||
#include "opt_kstack_max_pages.h" | #include "opt_kstack_max_pages.h" | ||||
#include "opt_kstack_usage_prof.h" | #include "opt_kstack_usage_prof.h" | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <sys/asan.h> | |||||
#include <sys/domainset.h> | #include <sys/domainset.h> | ||||
#include <sys/limits.h> | #include <sys/limits.h> | ||||
#include <sys/lock.h> | #include <sys/lock.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/mutex.h> | #include <sys/mutex.h> | ||||
#include <sys/proc.h> | #include <sys/proc.h> | ||||
#include <sys/racct.h> | #include <sys/racct.h> | ||||
#include <sys/refcount.h> | #include <sys/refcount.h> | ||||
#include <sys/resourcevar.h> | #include <sys/resourcevar.h> | ||||
#include <sys/rwlock.h> | #include <sys/rwlock.h> | ||||
#include <sys/sched.h> | #include <sys/sched.h> | ||||
#include <sys/sf_buf.h> | #include <sys/sf_buf.h> | ||||
#include <sys/shm.h> | #include <sys/shm.h> | ||||
#include <sys/smp.h> | #include <sys/smp.h> | ||||
#include <sys/vmmeter.h> | #include <sys/vmmeter.h> | ||||
#include <sys/vmem.h> | #include <sys/vmem.h> | ||||
#include <sys/sx.h> | #include <sys/sx.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <sys/eventhandler.h> | |||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/ktr.h> | #include <sys/ktr.h> | ||||
#include <sys/unistd.h> | #include <sys/unistd.h> | ||||
#include <vm/uma.h> | #include <vm/uma.h> | ||||
#include <vm/vm.h> | #include <vm/vm.h> | ||||
#include <vm/vm_param.h> | #include <vm/vm_param.h> | ||||
#include <vm/pmap.h> | #include <vm/pmap.h> | ||||
▲ Show 20 Lines • Show All 248 Lines • ▼ Show 20 Lines | for (i = 0; i < pages; i++) { | ||||
m = vm_page_lookup(kstack_object, pindex + i); | m = vm_page_lookup(kstack_object, pindex + i); | ||||
if (m == NULL) | if (m == NULL) | ||||
panic("%s: kstack already missing?", __func__); | panic("%s: kstack already missing?", __func__); | ||||
vm_page_xbusy_claim(m); | vm_page_xbusy_claim(m); | ||||
vm_page_unwire_noq(m); | vm_page_unwire_noq(m); | ||||
vm_page_free(m); | vm_page_free(m); | ||||
} | } | ||||
VM_OBJECT_WUNLOCK(kstack_object); | VM_OBJECT_WUNLOCK(kstack_object); | ||||
kasan_mark((void *)ks, ptoa(pages), ptoa(pages), 0); | |||||
kva_free(ks - (KSTACK_GUARD_PAGES * PAGE_SIZE), | kva_free(ks - (KSTACK_GUARD_PAGES * PAGE_SIZE), | ||||
(pages + KSTACK_GUARD_PAGES) * PAGE_SIZE); | (pages + KSTACK_GUARD_PAGES) * PAGE_SIZE); | ||||
} | } | ||||
/* | /* | ||||
* Allocate the kernel stack for a new thread. | * Allocate the kernel stack for a new thread. | ||||
*/ | */ | ||||
int | int | ||||
Show All 18 Lines | vm_thread_new(struct thread *td, int pages) | ||||
*/ | */ | ||||
if (ks == 0) | if (ks == 0) | ||||
ks = vm_thread_stack_create(DOMAINSET_PREF(PCPU_GET(domain)), | ks = vm_thread_stack_create(DOMAINSET_PREF(PCPU_GET(domain)), | ||||
pages); | pages); | ||||
if (ks == 0) | if (ks == 0) | ||||
return (0); | return (0); | ||||
td->td_kstack = ks; | td->td_kstack = ks; | ||||
td->td_kstack_pages = pages; | td->td_kstack_pages = pages; | ||||
kasan_mark((void *)ks, ptoa(pages), ptoa(pages), 0); | |||||
return (1); | return (1); | ||||
} | } | ||||
/* | /* | ||||
* Dispose of a thread's kernel stack. | * Dispose of a thread's kernel stack. | ||||
*/ | */ | ||||
void | void | ||||
vm_thread_dispose(struct thread *td) | vm_thread_dispose(struct thread *td) | ||||
{ | { | ||||
vm_offset_t ks; | vm_offset_t ks; | ||||
int pages; | int pages; | ||||
pages = td->td_kstack_pages; | pages = td->td_kstack_pages; | ||||
ks = td->td_kstack; | ks = td->td_kstack; | ||||
td->td_kstack = 0; | td->td_kstack = 0; | ||||
td->td_kstack_pages = 0; | td->td_kstack_pages = 0; | ||||
kasan_mark((void *)ks, 0, ptoa(pages), KASAN_KSTACK_FREED); | |||||
if (pages == kstack_pages) | if (pages == kstack_pages) | ||||
uma_zfree(kstack_cache, (void *)ks); | uma_zfree(kstack_cache, (void *)ks); | ||||
else | else | ||||
vm_thread_stack_dispose(ks, pages); | vm_thread_stack_dispose(ks, pages); | ||||
} | } | ||||
/* | /* | ||||
* Allocate physical pages, following the specified NUMA policy, to back a | * Allocate physical pages, following the specified NUMA policy, to back a | ||||
▲ Show 20 Lines • Show All 193 Lines • Show Last 20 Lines |