Date: Sat, 23 Mar 2019 11:43:41 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r345445 - in stable/12/sys: amd64/amd64 amd64/include arm/arm arm64/arm64 i386/i386 kern mips/mips powerpc/powerpc riscv/riscv sparc64/sparc64 sys Message-ID: <201903231143.x2NBhfLs029075@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Sat Mar 23 11:43:41 2019 New Revision: 345445 URL: https://svnweb.freebsd.org/changeset/base/345445 Log: MFC r345227: amd64: Add md process flags and first P_MD_PTI flag. Modified: stable/12/sys/amd64/amd64/pmap.c stable/12/sys/amd64/amd64/vm_machdep.c stable/12/sys/amd64/include/proc.h stable/12/sys/arm/arm/vm_machdep.c stable/12/sys/arm64/arm64/vm_machdep.c stable/12/sys/i386/i386/vm_machdep.c stable/12/sys/kern/kern_exec.c stable/12/sys/mips/mips/vm_machdep.c stable/12/sys/powerpc/powerpc/vm_machdep.c stable/12/sys/riscv/riscv/vm_machdep.c stable/12/sys/sparc64/sparc64/vm_machdep.c stable/12/sys/sys/proc.h Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/amd64/amd64/pmap.c ============================================================================== --- stable/12/sys/amd64/amd64/pmap.c Sat Mar 23 10:38:28 2019 (r345444) +++ stable/12/sys/amd64/amd64/pmap.c Sat Mar 23 11:43:41 2019 (r345445) @@ -2858,6 +2858,7 @@ pmap_unuse_pt(pmap_t pmap, vm_offset_t va, pd_entry_t void pmap_pinit0(pmap_t pmap) { + struct proc *p; int i; PMAP_LOCK_INIT(pmap); @@ -2876,6 +2877,12 @@ pmap_pinit0(pmap_t pmap) pmap->pm_pcids[i].pm_gen = 1; } pmap_activate_boot(pmap); + if (pti) { + p = curproc; + PROC_LOCK(p); + p->p_amd64_md_flags |= P_MD_KPTI; + PROC_UNLOCK(p); + } if ((cpu_stdext_feature2 & CPUID_STDEXT2_PKU) != 0) { pmap_pkru_ranges_zone = uma_zcreate("pkru ranges", @@ -2962,7 +2969,7 @@ pmap_pinit_type(pmap_t pmap, enum pmap_type pm_type, i if (pm_type == PT_X86) { pmap->pm_cr3 = pml4phys; pmap_pinit_pml4(pml4pg); - if (pti) { + if ((curproc->p_amd64_md_flags & P_MD_KPTI) != 0) { pml4pgu = vm_page_alloc(NULL, 0, VM_ALLOC_NORMAL | VM_ALLOC_NOOBJ | VM_ALLOC_WIRED | VM_ALLOC_WAITOK); pmap->pm_pml4u = (pml4_entry_t *)PHYS_TO_DMAP( Modified: stable/12/sys/amd64/amd64/vm_machdep.c ============================================================================== --- stable/12/sys/amd64/amd64/vm_machdep.c Sat Mar 23 10:38:28 2019 (r345444) +++ stable/12/sys/amd64/amd64/vm_machdep.c Sat Mar 23 11:43:41 2019 (r345445) @@ -181,6 +181,7 @@ cpu_fork(struct thread *td1, struct proc *p2, struct t /* Point mdproc and then copy over td1's contents */ mdp2 = &p2->p_md; bcopy(&p1->p_md, mdp2, sizeof(*mdp2)); + p2->p_amd64_md_flags = p1->p_amd64_md_flags; /* * Create a new fresh stack for the new process. @@ -367,6 +368,14 @@ cpu_thread_free(struct thread *td) { cpu_thread_clean(td); +} + +bool +cpu_exec_vmspace_reuse(struct proc *p, vm_map_t map) +{ + + return (((curproc->p_amd64_md_flags & P_MD_KPTI) != 0) == + (vm_map_pmap(map)->pm_ucr3 != PMAP_NO_CR3)); } void Modified: stable/12/sys/amd64/include/proc.h ============================================================================== --- stable/12/sys/amd64/include/proc.h Sat Mar 23 10:38:28 2019 (r345444) +++ stable/12/sys/amd64/include/proc.h Sat Mar 23 11:43:41 2019 (r345445) @@ -40,7 +40,8 @@ /* * List of locks - * k - only accessed by curthread + * c - proc lock + * k - only accessed by curthread * pp - pmap.c:invl_gen_mtx */ @@ -70,6 +71,8 @@ struct mdproc { struct proc_ldt *md_ldt; /* (t) per-process ldt */ struct system_segment_descriptor md_ldt_sd; }; + +#define P_MD_KPTI 0x00000001 /* Enable KPTI on exec */ #define KINFO_PROC_SIZE 1088 #define KINFO_PROC32_SIZE 768 Modified: stable/12/sys/arm/arm/vm_machdep.c ============================================================================== --- stable/12/sys/arm/arm/vm_machdep.c Sat Mar 23 10:38:28 2019 (r345444) +++ stable/12/sys/arm/arm/vm_machdep.c Sat Mar 23 11:43:41 2019 (r345445) @@ -347,3 +347,10 @@ cpu_exit(struct thread *td) { } +bool +cpu_exec_vmspace_reuse(struct proc *p __unused, vm_map_t map __unused) +{ + + return (true); +} + Modified: stable/12/sys/arm64/arm64/vm_machdep.c ============================================================================== --- stable/12/sys/arm64/arm64/vm_machdep.c Sat Mar 23 10:38:28 2019 (r345444) +++ stable/12/sys/arm64/arm64/vm_machdep.c Sat Mar 23 11:43:41 2019 (r345445) @@ -264,6 +264,13 @@ cpu_exit(struct thread *td) { } +bool +cpu_exec_vmspace_reuse(struct proc *p __unused, vm_map_t map __unused) +{ + + return (true); +} + void swi_vm(void *v) { Modified: stable/12/sys/i386/i386/vm_machdep.c ============================================================================== --- stable/12/sys/i386/i386/vm_machdep.c Sat Mar 23 10:38:28 2019 (r345444) +++ stable/12/sys/i386/i386/vm_machdep.c Sat Mar 23 11:43:41 2019 (r345445) @@ -386,6 +386,13 @@ cpu_thread_free(struct thread *td) cpu_thread_clean(td); } +bool +cpu_exec_vmspace_reuse(struct proc *p __unused, vm_map_t map __unused) +{ + + return (true); +} + void cpu_set_syscall_retval(struct thread *td, int error) { Modified: stable/12/sys/kern/kern_exec.c ============================================================================== --- stable/12/sys/kern/kern_exec.c Sat Mar 23 10:38:28 2019 (r345444) +++ stable/12/sys/kern/kern_exec.c Sat Mar 23 11:43:41 2019 (r345445) @@ -1100,7 +1100,8 @@ exec_new_vmspace(struct image_params *imgp, struct sys else sv_minuser = MAX(sv->sv_minuser, PAGE_SIZE); if (vmspace->vm_refcnt == 1 && vm_map_min(map) == sv_minuser && - vm_map_max(map) == sv->sv_maxuser) { + vm_map_max(map) == sv->sv_maxuser && + cpu_exec_vmspace_reuse(p, map)) { shmexit(vmspace); pmap_remove_pages(vmspace_pmap(vmspace)); vm_map_remove(map, vm_map_min(map), vm_map_max(map)); Modified: stable/12/sys/mips/mips/vm_machdep.c ============================================================================== --- stable/12/sys/mips/mips/vm_machdep.c Sat Mar 23 10:38:28 2019 (r345444) +++ stable/12/sys/mips/mips/vm_machdep.c Sat Mar 23 11:43:41 2019 (r345445) @@ -455,6 +455,13 @@ cpu_set_upcall(struct thread *td, void (*entry)(void * */ } +bool +cpu_exec_vmspace_reuse(struct proc *p __unused, vm_map_t map __unused) +{ + + return (true); +} + /* * Software interrupt handler for queued VM system processing. */ Modified: stable/12/sys/powerpc/powerpc/vm_machdep.c ============================================================================== --- stable/12/sys/powerpc/powerpc/vm_machdep.c Sat Mar 23 10:38:28 2019 (r345444) +++ stable/12/sys/powerpc/powerpc/vm_machdep.c Sat Mar 23 11:43:41 2019 (r345445) @@ -249,3 +249,10 @@ cpu_thread_swapout(struct thread *td) } +bool +cpu_exec_vmspace_reuse(struct proc *p __unused, vm_map_t map __unused) +{ + + return (true); +} + Modified: stable/12/sys/riscv/riscv/vm_machdep.c ============================================================================== --- stable/12/sys/riscv/riscv/vm_machdep.c Sat Mar 23 10:38:28 2019 (r345444) +++ stable/12/sys/riscv/riscv/vm_machdep.c Sat Mar 23 11:43:41 2019 (r345445) @@ -267,6 +267,13 @@ cpu_exit(struct thread *td) { } +bool +cpu_exec_vmspace_reuse(struct proc *p __unused, vm_map_t map __unused) +{ + + return (true); +} + void swi_vm(void *v) { Modified: stable/12/sys/sparc64/sparc64/vm_machdep.c ============================================================================== --- stable/12/sys/sparc64/sparc64/vm_machdep.c Sat Mar 23 10:38:28 2019 (r345444) +++ stable/12/sys/sparc64/sparc64/vm_machdep.c Sat Mar 23 11:43:41 2019 (r345445) @@ -373,6 +373,13 @@ cpu_fork_kthread_handler(struct thread *td, void (*fun fp->fr_local[1] = (u_long)arg; } +bool +cpu_exec_vmspace_reuse(struct proc *p __unused, vm_map_t map __unused) +{ + + return (true); +} + int is_physical_memory(vm_paddr_t addr) { Modified: stable/12/sys/sys/proc.h ============================================================================== --- stable/12/sys/sys/proc.h Sat Mar 23 10:38:28 2019 (r345444) +++ stable/12/sys/sys/proc.h Sat Mar 23 11:43:41 2019 (r345445) @@ -682,6 +682,7 @@ struct proc { LIST_ENTRY(proc) p_orphan; /* (e) List of orphan processes. */ LIST_HEAD(, proc) p_orphans; /* (e) Pointer to list of orphans. */ uint32_t p_fctl0; /* (x) ABI feature control, ELF note */ + u_int p_amd64_md_flags; /* (c) md process flags P_MD */ }; #define p_session p_pgrp->pg_session @@ -1083,6 +1084,7 @@ void userret(struct thread *, struct trapframe *); void cpu_exit(struct thread *); void exit1(struct thread *, int, int) __dead2; void cpu_copy_thread(struct thread *td, struct thread *td0); +bool cpu_exec_vmspace_reuse(struct proc *p, struct vm_map *map); int cpu_fetch_syscall_args(struct thread *td); void cpu_fork(struct thread *, struct proc *, struct thread *, int); void cpu_fork_kthread_handler(struct thread *, void (*)(void *), void *);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201903231143.x2NBhfLs029075>