CVS commit: src/sys/arch/i386/i386
Module Name:src Committed By: maxv Date: Mon Jul 25 15:18:41 UTC 2016 Modified Files: src/sys/arch/i386/i386: locore.S Log Message: This needs to be page-aligned anyway. To generate a diff of this commit: cvs rdiff -u -r1.135 -r1.136 src/sys/arch/i386/i386/locore.S Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/i386/i386/locore.S diff -u src/sys/arch/i386/i386/locore.S:1.135 src/sys/arch/i386/i386/locore.S:1.136 --- src/sys/arch/i386/i386/locore.S:1.135 Sat Jul 9 06:58:06 2016 +++ src/sys/arch/i386/i386/locore.S Mon Jul 25 15:18:41 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.135 2016/07/09 06:58:06 maxv Exp $ */ +/* $NetBSD: locore.S,v 1.136 2016/07/25 15:18:41 maxv Exp $ */ /* * Copyright-o-rama! @@ -128,7 +128,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.135 2016/07/09 06:58:06 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.136 2016/07/25 15:18:41 maxv Exp $"); #include "opt_compat_oldboot.h" #include "opt_copy_symtab.h" @@ -273,11 +273,7 @@ __KERNEL_RCSID(0, "$NetBSD: locore.S,v 1 .globl _C_LABEL(lapic_tpr) #if NLAPIC > 0 -#ifdef __ELF__ .align PAGE_SIZE -#else - .align 12 -#endif .globl _C_LABEL(local_apic) .globl _C_LABEL(lapic_id)
CVS commit: src/sys/arch/amd64/amd64
Module Name:src Committed By: maxv Date: Mon Jul 25 15:29:06 UTC 2016 Modified Files: src/sys/arch/amd64/amd64: mptramp.S Log Message: Unused. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/sys/arch/amd64/amd64/mptramp.S Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/mptramp.S diff -u src/sys/arch/amd64/amd64/mptramp.S:1.22 src/sys/arch/amd64/amd64/mptramp.S:1.23 --- src/sys/arch/amd64/amd64/mptramp.S:1.22 Thu May 12 09:40:23 2016 +++ src/sys/arch/amd64/amd64/mptramp.S Mon Jul 25 15:29:06 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: mptramp.S,v 1.22 2016/05/12 09:40:23 maxv Exp $ */ +/* $NetBSD: mptramp.S,v 1.23 2016/07/25 15:29:06 maxv Exp $ */ /* * Copyright (c) 2000, 2016 The NetBSD Foundation, Inc. @@ -116,7 +116,6 @@ .global _C_LABEL(cpu_spinup_trampoline_end) .global _C_LABEL(cpu_hatch) .global _C_LABEL(mp_pdirpa) - .global _C_LABEL(local_apic) .text .align 4,0x0
CVS commit: src/sys/uvm
Module Name:src Committed By: maxv Date: Wed Jul 27 16:45:00 UTC 2016 Modified Files: src/sys/uvm: uvm_km.c Log Message: Use UVM_PROT_ALL only if UVM_KMF_EXEC is given as argument. Otherwise, if UVM_KMF_PAGEABLE is also given as argument, only the VA is allocated and UVM waits for the page to fault before kentering it. When kentering it, it will use the UVM_PROT_ flag that was passed to uvm_map; which means that it will kenter it as RWX. With this change, the number of RWX pages in the amd64 kernel reaches strictly zero. To generate a diff of this commit: cvs rdiff -u -r1.140 -r1.141 src/sys/uvm/uvm_km.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/uvm/uvm_km.c diff -u src/sys/uvm/uvm_km.c:1.140 src/sys/uvm/uvm_km.c:1.141 --- src/sys/uvm/uvm_km.c:1.140 Wed Jul 20 12:38:43 2016 +++ src/sys/uvm/uvm_km.c Wed Jul 27 16:45:00 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: uvm_km.c,v 1.140 2016/07/20 12:38:43 maxv Exp $ */ +/* $NetBSD: uvm_km.c,v 1.141 2016/07/27 16:45:00 maxv Exp $ */ /* * Copyright (c) 1997 Charles D. Cranor and Washington University. @@ -152,7 +152,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uvm_km.c,v 1.140 2016/07/20 12:38:43 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uvm_km.c,v 1.141 2016/07/27 16:45:00 maxv Exp $"); #include "opt_uvmhist.h" @@ -593,7 +593,7 @@ uvm_km_alloc(struct vm_map *map, vsize_t struct vm_page *pg; struct uvm_object *obj; int pgaflags; - vm_prot_t prot; + vm_prot_t prot, vaprot; UVMHIST_FUNC(__func__); UVMHIST_CALLED(maphist); KASSERT(vm_map_pmap(map) == pmap_kernel()); @@ -617,8 +617,9 @@ uvm_km_alloc(struct vm_map *map, vsize_t * allocate some virtual space */ + vaprot = (flags & UVM_KMF_EXEC) ? UVM_PROT_ALL : UVM_PROT_RW; if (__predict_false(uvm_map(map, , size, obj, UVM_UNKNOWN_OFFSET, - align, UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL, UVM_INH_NONE, + align, UVM_MAPFLAG(vaprot, UVM_PROT_ALL, UVM_INH_NONE, UVM_ADV_RANDOM, (flags & (UVM_KMF_TRYLOCK | UVM_KMF_NOWAIT | UVM_KMF_WAITVA | UVM_KMF_COLORMATCH != 0)) {
CVS commit: src/sys/arch
Module Name:src Committed By: maxv Date: Sun Jul 24 13:04:58 UTC 2016 Modified Files: src/sys/arch/amd64/acpi: acpi_wakecode.S acpi_wakeup_low.S src/sys/arch/i386/acpi: acpi_wakecode.S acpi_wakeup_low.S Log Message: KNF, and reduce the diff between amd64 and i386. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/sys/arch/amd64/acpi/acpi_wakecode.S cvs rdiff -u -r1.4 -r1.5 src/sys/arch/amd64/acpi/acpi_wakeup_low.S cvs rdiff -u -r1.16 -r1.17 src/sys/arch/i386/acpi/acpi_wakecode.S cvs rdiff -u -r1.5 -r1.6 src/sys/arch/i386/acpi/acpi_wakeup_low.S Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/acpi/acpi_wakecode.S diff -u src/sys/arch/amd64/acpi/acpi_wakecode.S:1.12 src/sys/arch/amd64/acpi/acpi_wakecode.S:1.13 --- src/sys/arch/amd64/acpi/acpi_wakecode.S:1.12 Wed Jan 15 22:24:41 2014 +++ src/sys/arch/amd64/acpi/acpi_wakecode.S Sun Jul 24 13:04:58 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_wakecode.S,v 1.12 2014/01/15 22:24:41 joerg Exp $ */ +/* $NetBSD: acpi_wakecode.S,v 1.13 2016/07/24 13:04:58 maxv Exp $ */ /*- * Copyright (c) 2007 Joerg Sonnenberger@@ -31,7 +31,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ - /* * This code is derived from FreeBSD. Original copyrights: * @@ -144,7 +143,7 @@ wakeup_16: data32 addr32 lgdt tmp_gdt #endif - /* Enable protected mode w/o paging */ + /* Enable protected mode without paging */ mov %cr0,%eax orl $(CR0_PE),%eax mov %eax,%cr0 @@ -164,10 +163,10 @@ wakeup_32: /* * Switched to protected mode w/o paging */ - nop + /* Set up segment registers and initial stack for protected mode */ - movw $0x10, %ax + movw $0x10,%ax movw %ax,%ds movw %ax,%ss @@ -193,7 +192,7 @@ wakeup_32: movl WAKEUP_efer + ACPI_WAKEUP_ADDR,%ebx movl $MSR_EFER,%ecx rdmsr - orl $EFER_LME, %eax + orl $EFER_LME,%eax wrmsr /* Load temporary PML4, code will switch to full PML4 later */ @@ -204,9 +203,11 @@ wakeup_32: movl %cr0,%eax orl $(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_MP|CR0_WP|CR0_AM),%eax movl %eax,%cr0 - /* Flush prefetch queue */ + + /* Flush the prefetch queue */ jmp 1f 1: + /* Switch to temporary 64bit GDT */ lgdt tmp_gdt64 + ACPI_WAKEUP_ADDR @@ -220,7 +221,7 @@ wakeup_64: * Load the normal system value of MSR EFER. This includes * enabling the SYSCALL extension and NXE (if supported). */ - movl %ebx, %eax + movl %ebx,%eax movl $MSR_EFER,%ecx wrmsr @@ -228,6 +229,7 @@ wakeup_64: movw $GSEL(GDATA_SEL, SEL_KPL),%ax movw %ax,%ds + /* Restore registers */ movq WAKEUP_curcpu + ACPI_WAKEUP_ADDR,%r8 movq WAKEUP_restorecpu + ACPI_WAKEUP_ADDR,%rbx @@ -270,7 +272,7 @@ WAKEUP_restorecpu: .quad 0 .global WAKEUP_vbios_reset WAKEUP_vbios_reset: .byte 0 .global WAKEUP_vesa_modenum -WAKEUP_vesa_modenum:.word 0 +WAKEUP_vesa_modenum: .word 0 .global WAKEUP_beep_on_reset WAKEUP_beep_on_reset: .byte 0 Index: src/sys/arch/amd64/acpi/acpi_wakeup_low.S diff -u src/sys/arch/amd64/acpi/acpi_wakeup_low.S:1.4 src/sys/arch/amd64/acpi/acpi_wakeup_low.S:1.5 --- src/sys/arch/amd64/acpi/acpi_wakeup_low.S:1.4 Sun May 11 15:32:20 2008 +++ src/sys/arch/amd64/acpi/acpi_wakeup_low.S Sun Jul 24 13:04:58 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_wakeup_low.S,v 1.4 2008/05/11 15:32:20 ad Exp $ */ +/* $NetBSD: acpi_wakeup_low.S,v 1.5 2016/07/24 13:04:58 maxv Exp $ */ /*- * Copyright (c) 2007 Joerg Sonnenberger @@ -80,7 +80,7 @@ acpi_md_sleep_exit: movq ACPI_SUSPEND_CR0(%r8),%rax movq %rax,%cr0 - jmp 1f + jmp 1f 1: movq CPUVAR(GDT),%rax @@ -88,7 +88,7 @@ acpi_md_sleep_exit: andq $~0x0200,4(%rax,%rdx, 1) ltr %dx - lldt ACPI_SUSPEND_LDT(%r8) + lldt ACPI_SUSPEND_LDT(%r8) lidt ACPI_SUSPEND_IDT(%r8) movq ACPI_SUSPEND_REG+(0*8)(%r8),%rsp Index: src/sys/arch/i386/acpi/acpi_wakecode.S diff -u src/sys/arch/i386/acpi/acpi_wakecode.S:1.16 src/sys/arch/i386/acpi/acpi_wakecode.S:1.17 --- src/sys/arch/i386/acpi/acpi_wakecode.S:1.16 Sun Feb 2 22:41:20 2014 +++ src/sys/arch/i386/acpi/acpi_wakecode.S Sun Jul 24 13:04:58 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_wakecode.S,v 1.16 2014/02/02 22:41:20 dsl Exp $ */ +/* $NetBSD: acpi_wakecode.S,v 1.17 2016/07/24 13:04:58 maxv Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -29,7 +29,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ - /* * This code is derived from FreeBSD. Original copyrights: * @@ -136,14 +135,13 @@ wakeup_16: /* Load GDT while non-paging */ lgdt tmp_gdt - /* Enable protected mode */ + /* Enable protected mode without paging */ mov %cr0,%eax orl $(CR0_PE),%eax mov %eax,%cr0 /* Switch to protected mode by intersegmental jump */ - ljmpl $0x8,$wakeup_32 + ACPI_WAKEUP_ADDR - + ljmpl $0x8,$wakeup_32 + ACPI_WAKEUP_ADDR .code32 .align 16 @@ -151,19 +149,21 @@ wakeup_32: /* * Switched to protected mode w/o paging */ - nop + /*
CVS commit: src/sys/arch
Module Name:src Committed By: maxv Date: Sun Jul 24 14:09:22 UTC 2016 Modified Files: src/sys/arch/i386/acpi: acpi_wakecode.S acpi_wakeup_low.S src/sys/arch/x86/acpi: acpi_wakeup.c Log Message: The MSR EFER state is not saved and restored when sleeping on i386. On PAE, the CPU crashes right after waking up, since it needs to access NOX-ed pages, which are to be enabled in an MSR. Fix this by properly saving and restoring the EFER MSR. It's a little tricky since the wakeup code uses %edx, but rdmsr overwrites it. We just save it in %esi. Now, the CPU sleeps properly on PAE kernels. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/sys/arch/i386/acpi/acpi_wakecode.S cvs rdiff -u -r1.6 -r1.7 src/sys/arch/i386/acpi/acpi_wakeup_low.S cvs rdiff -u -r1.39 -r1.40 src/sys/arch/x86/acpi/acpi_wakeup.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/i386/acpi/acpi_wakecode.S diff -u src/sys/arch/i386/acpi/acpi_wakecode.S:1.17 src/sys/arch/i386/acpi/acpi_wakecode.S:1.18 --- src/sys/arch/i386/acpi/acpi_wakecode.S:1.17 Sun Jul 24 13:04:58 2016 +++ src/sys/arch/i386/acpi/acpi_wakecode.S Sun Jul 24 14:09:22 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_wakecode.S,v 1.17 2016/07/24 13:04:58 maxv Exp $ */ +/* $NetBSD: acpi_wakecode.S,v 1.18 2016/07/24 14:09:22 maxv Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -159,6 +159,13 @@ wakeup_32: movl WAKEUP_r_cr4 + ACPI_WAKEUP_ADDR,%eax movl %eax,%cr4 + /* + * Load the correct MSR EFER value now to not depend on the + * data segment register. After this point, no instruction is + * allowed to clobber %ebx until wrmsr. + */ + movl WAKEUP_efer + ACPI_WAKEUP_ADDR,%ebx + /* Load temporary page table, we will switch to full page table later */ movl WAKEUP_r_cr3 + ACPI_WAKEUP_ADDR,%eax movl %eax,%cr3 @@ -175,6 +182,15 @@ wakeup_32: nop + /* + * Load the normal system value of MSR EFER. This includes + * enabling NXE (if supported). + */ + movl %ebx,%eax + movl $0,%edx + movl $MSR_EFER,%ecx + wrmsr + /* Restore registers */ movl WAKEUP_curcpu + ACPI_WAKEUP_ADDR,%edx movl WAKEUP_restorecpu + ACPI_WAKEUP_ADDR,%ebx @@ -209,6 +225,8 @@ WAKEUP_r_cr4: .long 0 WAKEUP_curcpu: .long 0 .global WAKEUP_restorecpu WAKEUP_restorecpu: .long 0 + .global WAKEUP_efer +WAKEUP_efer: .long 0 .global WAKEUP_vbios_reset WAKEUP_vbios_reset: .byte 0 Index: src/sys/arch/i386/acpi/acpi_wakeup_low.S diff -u src/sys/arch/i386/acpi/acpi_wakeup_low.S:1.6 src/sys/arch/i386/acpi/acpi_wakeup_low.S:1.7 --- src/sys/arch/i386/acpi/acpi_wakeup_low.S:1.6 Sun Jul 24 13:04:58 2016 +++ src/sys/arch/i386/acpi/acpi_wakeup_low.S Sun Jul 24 14:09:22 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_wakeup_low.S,v 1.6 2016/07/24 13:04:58 maxv Exp $ */ +/* $NetBSD: acpi_wakeup_low.S,v 1.7 2016/07/24 14:09:22 maxv Exp $ */ /*- * Copyright (c) 2007 Joerg Sonnenberger@@ -29,10 +29,11 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: acpi_wakeup_low.S,v 1.6 2016/07/24 13:04:58 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_wakeup_low.S,v 1.7 2016/07/24 14:09:22 maxv Exp $"); #include "assym.h" #include +#include .text .p2align 2, 0x90 @@ -51,6 +52,13 @@ acpi_md_sleep_exit: movw ACPI_SUSPEND_GS(%edx),%ax movw %ax,%gs + movl $MSR_EFER,%ecx + movl ACPI_SUSPEND_EFER(%edx),%eax + movl %edx,%esi + movl $0,%edx + wrmsr + movl %esi,%edx + movl ACPI_SUSPEND_CR2(%edx),%eax movl %eax,%cr2 movl ACPI_SUSPEND_CR4(%edx),%eax @@ -96,6 +104,11 @@ acpi_md_sleep_prepare: movl %ebp,ACPI_SUSPEND_REG+(3*4)(%edx) movl %esp,ACPI_SUSPEND_REG+(4*4)(%edx) + movl $MSR_EFER,%ecx + rdmsr + movl CPUVAR(SELF),%edx + movl %eax,ACPI_SUSPEND_EFER(%edx) + movl %cr0,%eax movl %eax,ACPI_SUSPEND_CR0(%edx) movl %cr2,%eax Index: src/sys/arch/x86/acpi/acpi_wakeup.c diff -u src/sys/arch/x86/acpi/acpi_wakeup.c:1.39 src/sys/arch/x86/acpi/acpi_wakeup.c:1.40 --- src/sys/arch/x86/acpi/acpi_wakeup.c:1.39 Tue Aug 18 10:42:41 2015 +++ src/sys/arch/x86/acpi/acpi_wakeup.c Sun Jul 24 14:09:22 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_wakeup.c,v 1.39 2015/08/18 10:42:41 christos Exp $ */ +/* $NetBSD: acpi_wakeup.c,v 1.40 2016/07/24 14:09:22 maxv Exp $ */ /*- * Copyright (c) 2002, 2011 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: acpi_wakeup.c,v 1.39 2015/08/18 10:42:41 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_wakeup.c,v 1.40 2016/07/24 14:09:22 maxv Exp $"); /*- * Copyright (c) 2001 Takanori Watanabe @@ -62,7 +62,7 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_wakeup. */ #include -__KERNEL_RCSID(0, "$NetBSD: acpi_wakeup.c,v 1.39 2015/08/18 10:42:41 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_wakeup.c,v 1.40 2016/07/24 14:09:22 maxv Exp $"); #include #include @@ -165,10 +165,8 @@ acpi_md_sleep_patch(struct cpu_info *ci)
CVS commit: src/sys/kern
Module Name:src Committed By: maxv Date: Mon Aug 1 15:41:05 UTC 2016 Modified Files: src/sys/kern: subr_kobj.c Log Message: Don't fail if a module does not have a data or rodata section. Small modules don't have data. To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 src/sys/kern/subr_kobj.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/subr_kobj.c diff -u src/sys/kern/subr_kobj.c:1.57 src/sys/kern/subr_kobj.c:1.58 --- src/sys/kern/subr_kobj.c:1.57 Wed Jul 20 13:36:19 2016 +++ src/sys/kern/subr_kobj.c Mon Aug 1 15:41:05 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_kobj.c,v 1.57 2016/07/20 13:36:19 maxv Exp $ */ +/* $NetBSD: subr_kobj.c,v 1.58 2016/08/01 15:41:05 maxv Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.57 2016/07/20 13:36:19 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.58 2016/08/01 15:41:05 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_modular.h" @@ -424,16 +424,38 @@ kobj_load(kobj_t ko) error = ENOEXEC; goto out; } - if (map_data_size == 0) { - kobj_error(ko, "no data/bss"); - error = ENOEXEC; - goto out; - } - if (map_rodata_size == 0) { - kobj_error(ko, "no rodata"); - error = ENOEXEC; - goto out; - } + + if (map_data_size != 0) { + map_data_base = uvm_km_alloc(module_map, round_page(map_data_size), + 0, UVM_KMF_WIRED); + if (map_data_base == 0) { + kobj_error(ko, "out of memory"); + error = ENOMEM; + goto out; + } + ko->ko_data_address = map_data_base; + ko->ko_data_size = map_data_size; + } else { + map_data_base = 0; + ko->ko_data_address = 0; + ko->ko_data_size = 0; + } + + if (map_rodata_size != 0) { + map_rodata_base = uvm_km_alloc(module_map, round_page(map_rodata_size), + 0, UVM_KMF_WIRED); + if (map_rodata_base == 0) { + kobj_error(ko, "out of memory"); + error = ENOMEM; + goto out; + } + ko->ko_rodata_address = map_rodata_base; + ko->ko_rodata_size = map_rodata_size; + } else { + map_rodata_base = 0; + ko->ko_rodata_address = 0; + ko->ko_rodata_size = 0; + } map_text_base = uvm_km_alloc(module_map, round_page(map_text_size), 0, UVM_KMF_WIRED | UVM_KMF_EXEC); @@ -445,26 +467,6 @@ kobj_load(kobj_t ko) ko->ko_text_address = map_text_base; ko->ko_text_size = map_text_size; - map_data_base = uvm_km_alloc(module_map, round_page(map_data_size), - 0, UVM_KMF_WIRED); - if (map_data_base == 0) { - kobj_error(ko, "out of memory"); - error = ENOMEM; - goto out; - } - ko->ko_data_address = map_data_base; - ko->ko_data_size = map_data_size; - - map_rodata_base = uvm_km_alloc(module_map, round_page(map_rodata_size), - 0, UVM_KMF_WIRED); - if (map_rodata_base == 0) { - kobj_error(ko, "out of memory"); - error = ENOMEM; - goto out; - } - ko->ko_rodata_address = map_rodata_base; - ko->ko_rodata_size = map_rodata_size; - /* * Now load code/data(progbits), zero bss(nobits), allocate space * for and load relocs @@ -649,16 +651,22 @@ kobj_unload(kobj_t ko) if (error != 0) kobj_error(ko, "machine dependent deinit failed (text) %d", error); - error = kobj_machdep(ko, (void *)ko->ko_data_address, - ko->ko_data_size, false); - if (error != 0) - kobj_error(ko, "machine dependent deinit failed (data) %d", - error); - error = kobj_machdep(ko, (void *)ko->ko_rodata_address, - ko->ko_rodata_size, false); - if (error != 0) - kobj_error(ko, "machine dependent deinit failed (rodata) %d", - error); + + if (ko->ko_data_address != 0) { + error = kobj_machdep(ko, (void *)ko->ko_data_address, + ko->ko_data_size, false); + if (error != 0) +kobj_error(ko, "machine dependent deinit failed" +"(data) %d", error); + } + + if (ko->ko_rodata_address != 0) { + error = kobj_machdep(ko, (void *)ko->ko_rodata_address, + ko->ko_rodata_size, false); + if (error != 0) +kobj_error(ko, "machine dependent deinit failed" +"(rodata) %d", error); + } } if (ko->ko_text_address != 0) { uvm_km_free(module_map, ko->ko_text_address, @@ -752,8 +760,11 @@ kobj_affix(kobj_t ko, const char *name) /* Change the memory protections, when needed. */ uvm_km_protect(module_map, ko->ko_text_address, ko->ko_text_size, VM_PROT_READ|VM_PROT_EXECUTE); - uvm_km_protect(module_map, ko->ko_rodata_address, ko->ko_rodata_size, - VM_PROT_READ); + if (ko->ko_rodata_address != 0) { + uvm_km_protect(module_map, ko->ko_rodata_address, + ko->ko_rodata_size, VM_PROT_READ); + } + /* * Notify MD code that a module has been loaded. @@ -766,16 +777,23 @@ kobj_affix(kobj_t ko, const char *name) if (error != 0) kobj_error(ko, "machine dependent init failed (text) %d", error); - error = kobj_machdep(ko, (void *)ko->ko_data_address, - ko->ko_data_size, true); - if (error != 0) -
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Mon Aug 1 16:07:39 UTC 2016 Modified Files: src/sys/arch/x86/x86: x86_machdep.c Log Message: This panic is wrong. There could be two consecutive clusters below avail_start. To generate a diff of this commit: cvs rdiff -u -r1.74 -r1.75 src/sys/arch/x86/x86/x86_machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/x86_machdep.c diff -u src/sys/arch/x86/x86/x86_machdep.c:1.74 src/sys/arch/x86/x86/x86_machdep.c:1.75 --- src/sys/arch/x86/x86/x86_machdep.c:1.74 Sun Jul 17 10:46:43 2016 +++ src/sys/arch/x86/x86/x86_machdep.c Mon Aug 1 16:07:39 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: x86_machdep.c,v 1.74 2016/07/17 10:46:43 maxv Exp $ */ +/* $NetBSD: x86_machdep.c,v 1.75 2016/08/01 16:07:39 maxv Exp $ */ /*- * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi, @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.74 2016/07/17 10:46:43 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.75 2016/08/01 16:07:39 maxv Exp $"); #include "opt_modular.h" #include "opt_physmem.h" @@ -881,8 +881,6 @@ init_x86_vm(paddr_t pa_kend) continue; if (seg_start <= avail_start && avail_start < seg_end) { - if (seg_start != 0) -panic("init_x86_64: memory doesn't start at 0"); seg_start = avail_start; if (seg_start == seg_end) continue;
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Wed Jul 27 12:08:46 UTC 2016 Modified Files: src/sys/arch/x86/x86: pmap.c Log Message: Re-enable large pages on the data segment, but don't map the first page, and add a comment to explain why. We will have to move the LAPIC VA. The large page support is technically the same as before my last commit, since in practice, the first page of .data is never mapped with large pages. To generate a diff of this commit: cvs rdiff -u -r1.217 -r1.218 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.217 src/sys/arch/x86/x86/pmap.c:1.218 --- src/sys/arch/x86/x86/pmap.c:1.217 Mon Jul 25 12:11:40 2016 +++ src/sys/arch/x86/x86/pmap.c Wed Jul 27 12:08:46 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.217 2016/07/25 12:11:40 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.218 2016/07/27 12:08:46 maxv Exp $ */ /*- * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.217 2016/07/25 12:11:40 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.218 2016/07/27 12:08:46 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -1573,9 +1573,7 @@ pmap_remap_largepages(void) { extern char __rodata_start; extern char __data_start; -#if 0 extern char __kernel_end; -#endif pd_entry_t *pde; vaddr_t kva, kva_end; paddr_t pa; @@ -1606,9 +1604,13 @@ pmap_remap_largepages(void) tlbflushg(); } -#if 0 /* Remap the kernel data+bss using large pages. */ - kva = roundup((vaddr_t)&__data_start, NBPD_L2); + /* + * XXX: we need to make sure the first page (PAGE_SIZE) of .data is not + * mapped with a large page. As bizarre as it might seem, this first + * page is used as the VA for the LAPIC page. + */ + kva = roundup((vaddr_t)&__data_start+PAGE_SIZE, NBPD_L2); kva_end = rounddown((vaddr_t)&__kernel_end, NBPD_L1); pa = kva - KERNBASE; for (/* */; kva + NBPD_L2 <= kva_end; kva += NBPD_L2, pa += NBPD_L2) { @@ -1616,7 +1618,6 @@ pmap_remap_largepages(void) *pde = pa | pmap_pg_g | PG_PS | pmap_pg_nx | PG_KW | PG_V; tlbflushg(); } -#endif } #endif /* !XEN */
CVS commit: src/sys/arch/x86/acpi
Module Name:src Committed By: maxv Date: Wed Jul 27 13:04:29 UTC 2016 Modified Files: src/sys/arch/x86/acpi: acpi_wakeup.c Log Message: Call cpu_init_msrs on i386 when waking up. Currently it does not change anything, since MSR_EFER is already enabled earlier. But if we add new MSRs in the future, we will want them when waking up as well. To generate a diff of this commit: cvs rdiff -u -r1.40 -r1.41 src/sys/arch/x86/acpi/acpi_wakeup.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/acpi/acpi_wakeup.c diff -u src/sys/arch/x86/acpi/acpi_wakeup.c:1.40 src/sys/arch/x86/acpi/acpi_wakeup.c:1.41 --- src/sys/arch/x86/acpi/acpi_wakeup.c:1.40 Sun Jul 24 14:09:22 2016 +++ src/sys/arch/x86/acpi/acpi_wakeup.c Wed Jul 27 13:04:28 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_wakeup.c,v 1.40 2016/07/24 14:09:22 maxv Exp $ */ +/* $NetBSD: acpi_wakeup.c,v 1.41 2016/07/27 13:04:28 maxv Exp $ */ /*- * Copyright (c) 2002, 2011 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: acpi_wakeup.c,v 1.40 2016/07/24 14:09:22 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_wakeup.c,v 1.41 2016/07/27 13:04:28 maxv Exp $"); /*- * Copyright (c) 2001 Takanori Watanabe@@ -62,7 +62,7 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_wakeup. */ #include -__KERNEL_RCSID(0, "$NetBSD: acpi_wakeup.c,v 1.40 2016/07/24 14:09:22 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_wakeup.c,v 1.41 2016/07/27 13:04:28 maxv Exp $"); #include #include @@ -262,10 +262,9 @@ acpi_cpu_sleep(struct cpu_info *ci) return; /* Execute Wakeup */ -#ifndef __i386__ cpu_init_msrs(ci, false); -#endif fpuinit(ci); + #if NLAPIC > 0 lapic_enable(); lapic_set_lvt();
CVS commit: src/sys/arch
Module Name:src Committed By: maxv Date: Mon Jul 25 16:03:38 UTC 2016 Modified Files: src/sys/arch/amd64/amd64: locore.S src/sys/arch/i386/i386: locore.S Log Message: Remove lapic_id, lapic_ppr and lapic_isr. We need to be careful though: the offset of lapic_tpr must not change, and the whole area must be exactly one page. To generate a diff of this commit: cvs rdiff -u -r1.107 -r1.108 src/sys/arch/amd64/amd64/locore.S cvs rdiff -u -r1.136 -r1.137 src/sys/arch/i386/i386/locore.S Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/locore.S diff -u src/sys/arch/amd64/amd64/locore.S:1.107 src/sys/arch/amd64/amd64/locore.S:1.108 --- src/sys/arch/amd64/amd64/locore.S:1.107 Mon Jul 11 14:52:54 2016 +++ src/sys/arch/amd64/amd64/locore.S Mon Jul 25 16:03:38 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.107 2016/07/11 14:52:54 maxv Exp $ */ +/* $NetBSD: locore.S,v 1.108 2016/07/25 16:03:38 maxv Exp $ */ /* * Copyright-o-rama! @@ -316,30 +316,16 @@ #if NLAPIC > 0 .align PAGE_SIZE .globl _C_LABEL(local_apic) - .globl _C_LABEL(lapic_id) .globl _C_LABEL(lapic_tpr) .type _C_LABEL(local_apic), @object LABEL(local_apic) - .space LAPIC_ID + .space LAPIC_TPRI END(local_apic) - .type _C_LABEL(lapic_id), @object -LABEL(lapic_id) - .long 0x - .space LAPIC_TPRI-(LAPIC_ID+4) -END(lapic_id) .type _C_LABEL(lapic_tpr), @object LABEL(lapic_tpr) - .space LAPIC_PPRI-LAPIC_TPRI + .space PAGE_SIZE-LAPIC_TPRI END(lapic_tpr) - .type _C_LABEL(lapic_ppr), @object -_C_LABEL(lapic_ppr): - .space LAPIC_ISR-LAPIC_PPRI -END(lapic_ppr) - .type _C_LABEL(lapic_isr), @object -_C_LABEL(lapic_isr): - .space PAGE_SIZE-LAPIC_ISR -END(lapic_isr) #endif /* NLAPIC > 0 */ .globl _C_LABEL(tablesize) Index: src/sys/arch/i386/i386/locore.S diff -u src/sys/arch/i386/i386/locore.S:1.136 src/sys/arch/i386/i386/locore.S:1.137 --- src/sys/arch/i386/i386/locore.S:1.136 Mon Jul 25 15:18:41 2016 +++ src/sys/arch/i386/i386/locore.S Mon Jul 25 16:03:38 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.136 2016/07/25 15:18:41 maxv Exp $ */ +/* $NetBSD: locore.S,v 1.137 2016/07/25 16:03:38 maxv Exp $ */ /* * Copyright-o-rama! @@ -128,7 +128,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.136 2016/07/25 15:18:41 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.137 2016/07/25 16:03:38 maxv Exp $"); #include "opt_compat_oldboot.h" #include "opt_copy_symtab.h" @@ -275,29 +275,15 @@ __KERNEL_RCSID(0, "$NetBSD: locore.S,v 1 #if NLAPIC > 0 .align PAGE_SIZE .globl _C_LABEL(local_apic) - .globl _C_LABEL(lapic_id) .type _C_LABEL(local_apic), @object LABEL(local_apic) - .space LAPIC_ID + .space LAPIC_TPRI END(local_apic) - .type _C_LABEL(lapic_id), @object -LABEL(lapic_id) - .long 0x - .space LAPIC_TPRI-(LAPIC_ID+4) -END(lapic_id) .type _C_LABEL(lapic_tpr), @object LABEL(lapic_tpr) - .space LAPIC_PPRI-LAPIC_TPRI + .space PAGE_SIZE-LAPIC_TPRI END(lapic_tpr) - .type _C_LABEL(lapic_ppr), @object -_C_LABEL(lapic_ppr): - .space LAPIC_ISR-LAPIC_PPRI -END(lapic_ppr) - .type _C_LABEL(lapic_isr), @object -_C_LABEL(lapic_isr): - .space PAGE_SIZE-LAPIC_ISR -END(lapic_isr) #else .type _C_LABEL(lapic_tpr), @object LABEL(lapic_tpr)
CVS commit: src/sys/arch/xen/x86
Module Name:src Committed By: maxv Date: Tue Aug 2 13:25:56 UTC 2016 Modified Files: src/sys/arch/xen/x86: x86_xpmap.c Log Message: KNF, and use PAGE_SIZE instead of NBPG. To generate a diff of this commit: cvs rdiff -u -r1.54 -r1.55 src/sys/arch/xen/x86/x86_xpmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/x86/x86_xpmap.c diff -u src/sys/arch/xen/x86/x86_xpmap.c:1.54 src/sys/arch/xen/x86/x86_xpmap.c:1.55 --- src/sys/arch/xen/x86/x86_xpmap.c:1.54 Sun May 29 17:06:17 2016 +++ src/sys/arch/xen/x86/x86_xpmap.c Tue Aug 2 13:25:56 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: x86_xpmap.c,v 1.54 2016/05/29 17:06:17 bouyer Exp $ */ +/* $NetBSD: x86_xpmap.c,v 1.55 2016/08/02 13:25:56 maxv Exp $ */ /* * Copyright (c) 2006 Mathieu Ropert@@ -69,7 +69,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.54 2016/05/29 17:06:17 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.55 2016/08/02 13:25:56 maxv Exp $"); #include "opt_xen.h" #include "opt_ddb.h" @@ -571,8 +571,8 @@ xpq_debug_dump(void) extern volatile struct xencons_interface *xencons_interface; /* XXX */ extern struct xenstore_domain_interface *xenstore_interface; /* XXX */ -static void xen_bt_set_readonly (vaddr_t); -static void xen_bootstrap_tables (vaddr_t, vaddr_t, int, int, int); +static void xen_bt_set_readonly(vaddr_t); +static void xen_bootstrap_tables(vaddr_t, vaddr_t, int, int, int); /* How many PDEs ? */ #if L2_SLOT_KERNBASE > 0 @@ -587,7 +587,7 @@ static void xen_bootstrap_tables (vaddr_ * we get rid of Xen pagetables */ -vaddr_t xen_pmap_bootstrap (void); +vaddr_t xen_pmap_bootstrap(void); /* * Function to get rid of Xen bootstrap tables @@ -616,7 +616,7 @@ xen_pmap_bootstrap(void) xen_init_features(); - memset(xpq_idx_array, 0, sizeof xpq_idx_array); + memset(xpq_idx_array, 0, sizeof(xpq_idx_array)); xpmap_phys_to_machine_mapping = (unsigned long *)xen_start_info.mfn_list; @@ -639,12 +639,12 @@ xen_pmap_bootstrap(void) * - early_zerop * - ISA I/O mem (if needed) */ - mapsize += UPAGES * NBPG; + mapsize += UPAGES * PAGE_SIZE; #ifdef __x86_64__ - mapsize += NBPG; + mapsize += PAGE_SIZE; #endif - mapsize += NBPG; - mapsize += NBPG; + mapsize += PAGE_SIZE; + mapsize += PAGE_SIZE; #ifdef DOM0OPS if (xendomain_is_dom0()) { @@ -652,7 +652,7 @@ xen_pmap_bootstrap(void) mapsize += IOM_SIZE; } #endif - /* at this point mapsize doens't include the table size */ + /* at this point mapsize doesn't include the table size */ #ifdef __x86_64__ count = TABLE_L2_ENTRIES; @@ -709,7 +709,7 @@ bootstrap_again: /* zero out free space after tables */ memset((void *)(init_tables + ((count + l2_4_count) * PAGE_SIZE)), 0, - (UPAGES + 1) * NBPG); + (UPAGES + 1) * PAGE_SIZE); /* Finally, flush TLB. */ xpq_queue_tlb_flush(); @@ -718,14 +718,14 @@ bootstrap_again: } /* - * Build a new table and switch to it - * old_count is # of old tables (including PGD, PDTPE and PDE) - * new_count is # of new tables (PTE only) - * we assume areas don't overlap + * Build a new table and switch to it. + * old_count is # of old tables (including PGD, PDTPE and PDE). + * new_count is # of new tables (PTE only). + * We assume the areas don't overlap. */ static void -xen_bootstrap_tables (vaddr_t old_pgd, vaddr_t new_pgd, - int old_count, int new_count, int final) +xen_bootstrap_tables(vaddr_t old_pgd, vaddr_t new_pgd, +int old_count, int new_count, int final) { pd_entry_t *pdtpe, *pde, *pte; pd_entry_t *bt_pgd; @@ -739,26 +739,28 @@ xen_bootstrap_tables (vaddr_t old_pgd, v " %d, %d)\n", old_pgd, new_pgd, old_count, new_count)); text_end = ((vaddr_t)&__data_start) & ~PAGE_MASK; + /* * size of R/W area after kernel text: - * xencons_interface (if present) - * xenstore_interface (if present) - * table pages (new_count + l2_4_count entries) + * xencons_interface (if present) + * xenstore_interface (if present) + * table pages (new_count + l2_4_count entries) * extra mappings (only when final is true): - * UAREA - * dummy user PGD (x86_64 only)/gdt page (i386 only) - * HYPERVISOR_shared_info - * early_zerop - * ISA I/O mem (if needed) + * UAREA + * dummy user PGD (x86_64 only)/gdt page (i386 only) + * HYPERVISOR_shared_info + * early_zerop + * ISA I/O mem (if needed) */ - map_end = new_pgd + ((new_count + l2_4_count) * NBPG); + map_end = new_pgd + ((new_count + l2_4_count) * PAGE_SIZE); if (final) { - map_end += (UPAGES + 1) * NBPG; + map_end += (UPAGES + 1) * PAGE_SIZE; HYPERVISOR_shared_info = (shared_info_t *)map_end; - map_end += NBPG; + map_end += PAGE_SIZE; early_zerop = (char *)map_end; - map_end += NBPG; + map_end += PAGE_SIZE; } + /* * we always set atdevbase, as it's used by init386 to find the first *
CVS commit: src/sys/arch
Module Name:src Committed By: maxv Date: Tue Aug 2 14:03:34 UTC 2016 Modified Files: src/sys/arch/amd64/conf: kern.ldscript.Xen src/sys/arch/i386/conf: kern.ldscript.Xen Log Message: Align the segments properly, and split text+rodata in two separate segments on Xen. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/sys/arch/amd64/conf/kern.ldscript.Xen cvs rdiff -u -r1.12 -r1.13 src/sys/arch/i386/conf/kern.ldscript.Xen Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/conf/kern.ldscript.Xen diff -u src/sys/arch/amd64/conf/kern.ldscript.Xen:1.12 src/sys/arch/amd64/conf/kern.ldscript.Xen:1.13 --- src/sys/arch/amd64/conf/kern.ldscript.Xen:1.12 Fri May 13 05:45:13 2016 +++ src/sys/arch/amd64/conf/kern.ldscript.Xen Tue Aug 2 14:03:34 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: kern.ldscript.Xen,v 1.12 2016/05/13 05:45:13 maxv Exp $ */ +/* $NetBSD: kern.ldscript.Xen,v 1.13 2016/08/02 14:03:34 maxv Exp $ */ #include "assym.h" @@ -7,24 +7,26 @@ __PAGE_SIZE = 0x1000 ; ENTRY(_start) SECTIONS { - /* Read-only sections, merged into text segment: */ .text : { *(.text) *(.text.*) *(.stub) - *(.rodata) } _etext = . ; PROVIDE (etext = .) ; - /* - * Adjust the address for the data segment. We want to adjust up to - * the same address within the page on the next page up. - */ - . = ALIGN(0x10) + (. & (0x10 - 1)); + . = ALIGN(__PAGE_SIZE); __rodata_start = . ; + .rodata : + { + *(.rodata) + *(.rodata.*) + } + + . = ALIGN(__PAGE_SIZE); + __data_start = . ; .data : { @@ -53,7 +55,12 @@ SECTIONS *(COMMON) . = ALIGN(64 / 8); } - . = ALIGN(64 / 8); + + . = ALIGN(__PAGE_SIZE); + + /* End of the kernel image */ + __kernel_end = . ; + _end = . ; PROVIDE (end = .) ; .note.netbsd.ident : Index: src/sys/arch/i386/conf/kern.ldscript.Xen diff -u src/sys/arch/i386/conf/kern.ldscript.Xen:1.12 src/sys/arch/i386/conf/kern.ldscript.Xen:1.13 --- src/sys/arch/i386/conf/kern.ldscript.Xen:1.12 Fri May 13 05:45:13 2016 +++ src/sys/arch/i386/conf/kern.ldscript.Xen Tue Aug 2 14:03:34 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: kern.ldscript.Xen,v 1.12 2016/05/13 05:45:13 maxv Exp $ */ +/* $NetBSD: kern.ldscript.Xen,v 1.13 2016/08/02 14:03:34 maxv Exp $ */ #include "assym.h" @@ -6,7 +6,6 @@ __PAGE_SIZE = 0x1000 ; SECTIONS { - /* Read-only sections, merged into text segment: */ .text : { *(.text) @@ -16,19 +15,17 @@ SECTIONS _etext = . ; PROVIDE (etext = .) ; + . = ALIGN(__PAGE_SIZE); + + __rodata_start = . ; .rodata : { *(.rodata) *(.rodata.*) } - /* - * Adjust the address for the data segment. We want to adjust up to - * the same address within the page on the next page up. - */ - . = ALIGN(0x1000) + (. & (0x1000 - 1)); + . = ALIGN(__PAGE_SIZE); - __rodata_start = . ; __data_start = . ; .data : { @@ -46,8 +43,8 @@ SECTIONS *(.data.read_mostly) } . = ALIGN(COHERENCY_UNIT); - _edata = . ; + _edata = . ; PROVIDE (edata = .) ; __bss_start = . ; .bss : @@ -57,7 +54,12 @@ SECTIONS *(COMMON) . = ALIGN(32 / 8); } - . = ALIGN(32 / 8); + + . = ALIGN(__PAGE_SIZE); + + /* End of the kernel image */ + __kernel_end = . ; + _end = . ; PROVIDE (end = .) ; .note.netbsd.ident :
CVS commit: src/sys/arch/xen/x86
Module Name:src Committed By: maxv Date: Tue Aug 2 13:29:35 UTC 2016 Modified Files: src/sys/arch/xen/x86: x86_xpmap.c Log Message: Use PG_RO instead of a magic zero. To generate a diff of this commit: cvs rdiff -u -r1.55 -r1.56 src/sys/arch/xen/x86/x86_xpmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/x86/x86_xpmap.c diff -u src/sys/arch/xen/x86/x86_xpmap.c:1.55 src/sys/arch/xen/x86/x86_xpmap.c:1.56 --- src/sys/arch/xen/x86/x86_xpmap.c:1.55 Tue Aug 2 13:25:56 2016 +++ src/sys/arch/xen/x86/x86_xpmap.c Tue Aug 2 13:29:35 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: x86_xpmap.c,v 1.55 2016/08/02 13:25:56 maxv Exp $ */ +/* $NetBSD: x86_xpmap.c,v 1.56 2016/08/02 13:29:35 maxv Exp $ */ /* * Copyright (c) 2006 Mathieu Ropert@@ -69,7 +69,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.55 2016/08/02 13:25:56 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.56 2016/08/02 13:29:35 maxv Exp $"); #include "opt_xen.h" #include "opt_ddb.h" @@ -910,15 +910,15 @@ xen_bootstrap_tables(vaddr_t old_pgd, va pte[pl1_pi(page)] |= PG_k | PG_V; if (page < text_end) { /* map kernel text RO */ -pte[pl1_pi(page)] |= 0; +pte[pl1_pi(page)] |= PG_RO; } else if (page >= old_pgd && page < old_pgd + (old_count * PAGE_SIZE)) { /* map old page tables RO */ -pte[pl1_pi(page)] |= 0; +pte[pl1_pi(page)] |= PG_RO; } else if (page >= new_pgd && page < new_pgd + ((new_count + l2_4_count) * PAGE_SIZE)) { /* map new page tables RO */ -pte[pl1_pi(page)] |= 0; +pte[pl1_pi(page)] |= PG_RO; #ifdef i386 } else if (page == (vaddr_t)tmpgdt) { /*
CVS commit: src/sys/arch/xen/x86
Module Name:src Committed By: maxv Date: Tue Aug 2 14:21:53 UTC 2016 Modified Files: src/sys/arch/xen/x86: x86_xpmap.c Log Message: Map the kernel text, rodata and data+bss independently on Xen, with respectively RX, R and RW. To generate a diff of this commit: cvs rdiff -u -r1.56 -r1.57 src/sys/arch/xen/x86/x86_xpmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/x86/x86_xpmap.c diff -u src/sys/arch/xen/x86/x86_xpmap.c:1.56 src/sys/arch/xen/x86/x86_xpmap.c:1.57 --- src/sys/arch/xen/x86/x86_xpmap.c:1.56 Tue Aug 2 13:29:35 2016 +++ src/sys/arch/xen/x86/x86_xpmap.c Tue Aug 2 14:21:53 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: x86_xpmap.c,v 1.56 2016/08/02 13:29:35 maxv Exp $ */ +/* $NetBSD: x86_xpmap.c,v 1.57 2016/08/02 14:21:53 maxv Exp $ */ /* * Copyright (c) 2006 Mathieu Ropert@@ -69,7 +69,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.56 2016/08/02 13:29:35 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.57 2016/08/02 14:21:53 maxv Exp $"); #include "opt_xen.h" #include "opt_ddb.h" @@ -730,15 +730,24 @@ xen_bootstrap_tables(vaddr_t old_pgd, va pd_entry_t *pdtpe, *pde, *pte; pd_entry_t *bt_pgd; paddr_t addr; - vaddr_t page, avail, text_end, map_end; + vaddr_t page, avail, map_end; int i; + extern char __rodata_start; extern char __data_start; + extern char __kernel_end; extern char *early_zerop; /* from pmap.c */ + pt_entry_t pg_nx; + u_int descs[4]; __PRINTK(("xen_bootstrap_tables(%#" PRIxVADDR ", %#" PRIxVADDR "," " %d, %d)\n", old_pgd, new_pgd, old_count, new_count)); - text_end = ((vaddr_t)&__data_start) & ~PAGE_MASK; + + /* + * Set the NX/XD bit, if available. descs[3] = %edx. + */ + x86_cpuid(0x8001, descs); + pg_nx = (descs[3] & CPUID_NOX) ? PG_NX : 0; /* * size of R/W area after kernel text: @@ -776,8 +785,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va } #endif /* DOM0OPS */ - __PRINTK(("xen_bootstrap_tables text_end 0x%lx map_end 0x%lx\n", - text_end, map_end)); + __PRINTK(("xen_bootstrap_tables map_end 0x%lx\n", map_end)); __PRINTK(("console %#lx ", xen_start_info.console_mfn)); __PRINTK(("xenstore %#" PRIx32 "\n", xen_start_info.store_mfn)); @@ -907,10 +915,19 @@ xen_bootstrap_tables(vaddr_t old_pgd, va IOM_BEGIN + (page - (vaddr_t)atdevbase); } #endif + pte[pl1_pi(page)] |= PG_k | PG_V; - if (page < text_end) { -/* map kernel text RO */ + if (page < (vaddr_t)&__rodata_start) { +/* Map kernel text RX. */ pte[pl1_pi(page)] |= PG_RO; + } else if (page >= (vaddr_t)&__rodata_start && + page < (vaddr_t)&__data_start) { +/* Map the kernel rodata R. */ +pte[pl1_pi(page)] |= PG_RO | pg_nx; + } else if (page >= (vaddr_t)&__data_start && + page < (vaddr_t)&__kernel_end) { +/* Map the kernel data+bss RW. */ +pte[pl1_pi(page)] |= PG_RW | pg_nx; } else if (page >= old_pgd && page < old_pgd + (old_count * PAGE_SIZE)) { /* map old page tables RO */
CVS commit: src/sys/arch/xen/x86
Module Name:src Committed By: maxv Date: Wed Aug 3 11:51:18 UTC 2016 Modified Files: src/sys/arch/xen/x86: x86_xpmap.c Log Message: Map the recursive slot and page table pages as non-executable on Xen. Same as normal x86. To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 src/sys/arch/xen/x86/x86_xpmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/x86/x86_xpmap.c diff -u src/sys/arch/xen/x86/x86_xpmap.c:1.57 src/sys/arch/xen/x86/x86_xpmap.c:1.58 --- src/sys/arch/xen/x86/x86_xpmap.c:1.57 Tue Aug 2 14:21:53 2016 +++ src/sys/arch/xen/x86/x86_xpmap.c Wed Aug 3 11:51:18 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: x86_xpmap.c,v 1.57 2016/08/02 14:21:53 maxv Exp $ */ +/* $NetBSD: x86_xpmap.c,v 1.58 2016/08/03 11:51:18 maxv Exp $ */ /* * Copyright (c) 2006 Mathieu Ropert@@ -69,7 +69,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.57 2016/08/02 14:21:53 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.58 2016/08/03 11:51:18 maxv Exp $"); #include "opt_xen.h" #include "opt_ddb.h" @@ -918,7 +918,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va pte[pl1_pi(page)] |= PG_k | PG_V; if (page < (vaddr_t)&__rodata_start) { -/* Map kernel text RX. */ +/* Map the kernel text RX. */ pte[pl1_pi(page)] |= PG_RO; } else if (page >= (vaddr_t)&__rodata_start && page < (vaddr_t)&__data_start) { @@ -930,12 +930,12 @@ xen_bootstrap_tables(vaddr_t old_pgd, va pte[pl1_pi(page)] |= PG_RW | pg_nx; } else if (page >= old_pgd && page < old_pgd + (old_count * PAGE_SIZE)) { -/* map old page tables RO */ -pte[pl1_pi(page)] |= PG_RO; +/* Map the old page tables R. */ +pte[pl1_pi(page)] |= PG_RO | pg_nx; } else if (page >= new_pgd && page < new_pgd + ((new_count + l2_4_count) * PAGE_SIZE)) { -/* map new page tables RO */ -pte[pl1_pi(page)] |= PG_RO; +/* Map the new page tables R. */ +pte[pl1_pi(page)] |= PG_RO | pg_nx; #ifdef i386 } else if (page == (vaddr_t)tmpgdt) { /* @@ -1028,15 +1028,19 @@ xen_bootstrap_tables(vaddr_t old_pgd, va xpq_queue_pin_l2_table(xpmap_ptom_masked(addr)); #endif #else /* PAE */ - /* recursive entry in higher-level per-cpu PD and pmap_kernel() */ - bt_pgd[PDIR_SLOT_PTE] = xpmap_ptom_masked((paddr_t)bt_pgd - KERNBASE) | PG_k | PG_V; + + /* Recursive entry in pmap_kernel(). */ + bt_pgd[PDIR_SLOT_PTE] = xpmap_ptom_masked((paddr_t)bt_pgd - KERNBASE) + | PG_k | PG_RO | PG_V | pg_nx; #ifdef __x86_64__ - bt_cpu_pgd[PDIR_SLOT_PTE] = - xpmap_ptom_masked((paddr_t)bt_cpu_pgd - KERNBASE) | PG_k | PG_V; -#endif /* __x86_64__ */ + /* Recursive entry in higher-level per-cpu PD. */ + bt_cpu_pgd[PDIR_SLOT_PTE] = xpmap_ptom_masked((paddr_t)bt_cpu_pgd - KERNBASE) + | PG_k | PG_RO | PG_V | pg_nx; +#endif __PRINTK(("bt_pgd[PDIR_SLOT_PTE] va %#" PRIxVADDR " pa %#" PRIxPADDR " entry %#" PRIxPADDR "\n", new_pgd, (paddr_t)new_pgd - KERNBASE, bt_pgd[PDIR_SLOT_PTE])); + /* Mark tables RO */ xen_bt_set_readonly((vaddr_t) pde); #endif @@ -1046,6 +1050,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va #if PTP_LEVELS > 3 xen_bt_set_readonly(new_pgd); #endif + /* Pin the PGD */ __PRINTK(("pin PGD: %"PRIxVADDR"\n", new_pgd - KERNBASE)); #ifdef __x86_64__
CVS commit: src/sys/arch
Module Name:src Committed By: maxv Date: Thu Aug 11 14:58:29 UTC 2016 Modified Files: src/sys/arch/amd64/amd64: trap.c src/sys/arch/i386/i386: trap.c Log Message: Reduce the diff, and typo. To generate a diff of this commit: cvs rdiff -u -r1.83 -r1.84 src/sys/arch/amd64/amd64/trap.c cvs rdiff -u -r1.276 -r1.277 src/sys/arch/i386/i386/trap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/trap.c diff -u src/sys/arch/amd64/amd64/trap.c:1.83 src/sys/arch/amd64/amd64/trap.c:1.84 --- src/sys/arch/amd64/amd64/trap.c:1.83 Sun Dec 13 15:53:05 2015 +++ src/sys/arch/amd64/amd64/trap.c Thu Aug 11 14:58:29 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: trap.c,v 1.83 2015/12/13 15:53:05 maxv Exp $ */ +/* $NetBSD: trap.c,v 1.84 2016/08/11 14:58:29 maxv Exp $ */ /*- * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc. @@ -68,7 +68,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.83 2015/12/13 15:53:05 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.84 2016/08/11 14:58:29 maxv Exp $"); #include "opt_ddb.h" #include "opt_kgdb.h" @@ -374,7 +374,7 @@ kernelfault: case 0x848e: /* mov 0xa8(%rsp),%es (8e 84 24 a8 00 00 00) */ case 0x9c8e: /* mov 0xb0(%rsp),%ds (8e 9c 24 b0 00 00 00) */ /* - * We faulted loading one if the user segment registers. + * We faulted loading one of the user segment registers. * The stack frame containing the user registers is * still valid and pointed to by tf_rsp. * Maybe we should check the iretq follows. Index: src/sys/arch/i386/i386/trap.c diff -u src/sys/arch/i386/i386/trap.c:1.276 src/sys/arch/i386/i386/trap.c:1.277 --- src/sys/arch/i386/i386/trap.c:1.276 Wed Dec 16 18:54:03 2015 +++ src/sys/arch/i386/i386/trap.c Thu Aug 11 14:58:29 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: trap.c,v 1.276 2015/12/16 18:54:03 maxv Exp $ */ +/* $NetBSD: trap.c,v 1.277 2016/08/11 14:58:29 maxv Exp $ */ /*- * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -68,7 +68,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.276 2015/12/16 18:54:03 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.277 2016/08/11 14:58:29 maxv Exp $"); #include "opt_ddb.h" #include "opt_kgdb.h" @@ -116,7 +116,7 @@ __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.2 #include /* - * This is a hook which is initialised by the dtrace module + * This is a hook which is initialized by the dtrace module * to handle traps which might occur during DTrace probe * execution. */ @@ -291,8 +291,7 @@ trap(struct trapframe *frame) trap_print(frame, l); } #endif - if (type != T_NMI && - !KERNELMODE(frame->tf_cs, frame->tf_eflags)) { + if (type != T_NMI && !KERNELMODE(frame->tf_cs, frame->tf_eflags)) { type |= T_USER; l->l_md.md_regs = frame; pcb->pcb_cr2 = 0; @@ -322,9 +321,6 @@ trap(struct trapframe *frame) switch (type) { - case T_ASTFLT: - /*FALLTHROUGH*/ - default: we_re_toast: if (type == T_TRCTRAP) @@ -409,7 +405,7 @@ kernelfault: goto we_re_toast; } /* - * We faulted loading one if the user segment registers. + * We faulted loading one of the user segment registers. * The stack frame containing the user registers is * still valid and is just below the %eip:%cs:%fl of * the kernel fault frame.
CVS commit: src/sys/arch/amd64/include
Module Name:src Committed By: maxv Date: Thu Aug 11 15:45:39 UTC 2016 Modified Files: src/sys/arch/amd64/include: i82093reg.h Log Message: Use absolute addressing mode, just like the rest. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/arch/amd64/include/i82093reg.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/include/i82093reg.h diff -u src/sys/arch/amd64/include/i82093reg.h:1.5 src/sys/arch/amd64/include/i82093reg.h:1.6 --- src/sys/arch/amd64/include/i82093reg.h:1.5 Thu Jul 3 14:02:25 2008 +++ src/sys/arch/amd64/include/i82093reg.h Thu Aug 11 15:45:39 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: i82093reg.h,v 1.5 2008/07/03 14:02:25 drochner Exp $ */ +/* $NetBSD: i82093reg.h,v 1.6 2016/08/11 15:45:39 maxv Exp $ */ #include @@ -9,7 +9,7 @@ #endif #define ioapic_asm_ack(num) \ - movl $0,(_C_LABEL(local_apic)+LAPIC_EOI)(%rip) + movl $0,_C_LABEL(local_apic)+LAPIC_EOI #ifdef MULTIPROCESSOR
CVS commit: src/sys/arch/xen/x86
Module Name:src Committed By: maxv Date: Thu Aug 11 15:35:10 UTC 2016 Modified Files: src/sys/arch/xen/x86: x86_xpmap.c Log Message: Make the I/O area non-executable on Xen. To generate a diff of this commit: cvs rdiff -u -r1.58 -r1.59 src/sys/arch/xen/x86/x86_xpmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/x86/x86_xpmap.c diff -u src/sys/arch/xen/x86/x86_xpmap.c:1.58 src/sys/arch/xen/x86/x86_xpmap.c:1.59 --- src/sys/arch/xen/x86/x86_xpmap.c:1.58 Wed Aug 3 11:51:18 2016 +++ src/sys/arch/xen/x86/x86_xpmap.c Thu Aug 11 15:35:10 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: x86_xpmap.c,v 1.58 2016/08/03 11:51:18 maxv Exp $ */ +/* $NetBSD: x86_xpmap.c,v 1.59 2016/08/11 15:35:10 maxv Exp $ */ /* * Copyright (c) 2006 Mathieu Ropert@@ -69,7 +69,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.58 2016/08/03 11:51:18 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.59 2016/08/11 15:35:10 maxv Exp $"); #include "opt_xen.h" #include "opt_ddb.h" @@ -913,6 +913,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va page < (vaddr_t)atdevbase + IOM_SIZE) { pte[pl1_pi(page)] = IOM_BEGIN + (page - (vaddr_t)atdevbase); +pte[pl1_pi(page)] |= pg_nx; } #endif
CVS commit: src/sys/arch/i386/i386
Module Name:src Committed By: maxv Date: Thu Aug 11 15:03:23 UTC 2016 Modified Files: src/sys/arch/i386/i386: trap.c Log Message: This should be VM_MIN_KERNEL_ADDRESS, not KERNBASE. To generate a diff of this commit: cvs rdiff -u -r1.277 -r1.278 src/sys/arch/i386/i386/trap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/i386/i386/trap.c diff -u src/sys/arch/i386/i386/trap.c:1.277 src/sys/arch/i386/i386/trap.c:1.278 --- src/sys/arch/i386/i386/trap.c:1.277 Thu Aug 11 14:58:29 2016 +++ src/sys/arch/i386/i386/trap.c Thu Aug 11 15:03:23 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: trap.c,v 1.277 2016/08/11 14:58:29 maxv Exp $ */ +/* $NetBSD: trap.c,v 1.278 2016/08/11 15:03:23 maxv Exp $ */ /*- * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -68,7 +68,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.277 2016/08/11 14:58:29 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.278 2016/08/11 15:03:23 maxv Exp $"); #include "opt_ddb.h" #include "opt_kgdb.h" @@ -582,7 +582,7 @@ faultcommon: * The last can occur during an exec() copyin where the * argument space is lazy-allocated. */ - if (type == T_PAGEFLT && va >= KERNBASE) + if (type == T_PAGEFLT && va >= VM_MIN_KERNEL_ADDRESS) map = kernel_map; else map = >vm_map;
CVS commit: src/sys/netsmb
Module Name:src Committed By: maxv Date: Mon Aug 15 08:17:35 UTC 2016 Modified Files: src/sys/netsmb: smb_rq.c Log Message: Uninitialized vars, found by brainy To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/sys/netsmb/smb_rq.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/netsmb/smb_rq.c diff -u src/sys/netsmb/smb_rq.c:1.34 src/sys/netsmb/smb_rq.c:1.35 --- src/sys/netsmb/smb_rq.c:1.34 Fri Dec 17 13:05:29 2010 +++ src/sys/netsmb/smb_rq.c Mon Aug 15 08:17:35 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: smb_rq.c,v 1.34 2010/12/17 13:05:29 pooka Exp $ */ +/* $NetBSD: smb_rq.c,v 1.35 2016/08/15 08:17:35 maxv Exp $ */ /* * Copyright (c) 2000-2001, Boris Popov @@ -35,7 +35,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: smb_rq.c,v 1.34 2010/12/17 13:05:29 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: smb_rq.c,v 1.35 2016/08/15 08:17:35 maxv Exp $"); #include #include @@ -343,8 +343,8 @@ smb_rq_reply(struct smb_rq *rqp) { struct mdchain *mdp = >sr_rp; int error; - u_int8_t errclass; - u_int16_t serror; + u_int8_t errclass = 0; + u_int16_t serror = 0; error = smb_iod_waitrq(rqp); if (error)
CVS commit: src/sys/arch/evbsh3/stand/mesboot/src
Module Name:src Committed By: maxv Date: Mon Aug 15 08:32:46 UTC 2016 Modified Files: src/sys/arch/evbsh3/stand/mesboot/src: mesboot.c Log Message: Uninitialized var, found by brainy; not tested, but obvious enough To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbsh3/stand/mesboot/src/mesboot.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/evbsh3/stand/mesboot/src/mesboot.c diff -u src/sys/arch/evbsh3/stand/mesboot/src/mesboot.c:1.1 src/sys/arch/evbsh3/stand/mesboot/src/mesboot.c:1.2 --- src/sys/arch/evbsh3/stand/mesboot/src/mesboot.c:1.1 Tue Apr 6 15:54:30 2010 +++ src/sys/arch/evbsh3/stand/mesboot/src/mesboot.c Mon Aug 15 08:32:46 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: mesboot.c,v 1.1 2010/04/06 15:54:30 nonaka Exp $ */ +/* $NetBSD: mesboot.c,v 1.2 2016/08/15 08:32:46 maxv Exp $ */ #include #include @@ -25,7 +25,7 @@ usage(void) int main(int argc, char **argv) { - char *kernel; + char *kernel = NULL; char *ptr, *mem, *rdptr; void (*func)(); int fd, size, c;
CVS commit: src/sys/dev/microcode/aic7xxx
Module Name:src Committed By: maxv Date: Mon Aug 15 08:52:33 UTC 2016 Modified Files: src/sys/dev/microcode/aic7xxx: aicasm.c Log Message: This thing is completely buggy. There is a use-after-free and NULL pointer dereference. Just fix the uaf, and add a comment. Not tested, but obvious enough; found by brainy. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/sys/dev/microcode/aic7xxx/aicasm.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/microcode/aic7xxx/aicasm.c diff -u src/sys/dev/microcode/aic7xxx/aicasm.c:1.8 src/sys/dev/microcode/aic7xxx/aicasm.c:1.9 --- src/sys/dev/microcode/aic7xxx/aicasm.c:1.8 Sun Dec 27 16:03:49 2009 +++ src/sys/dev/microcode/aic7xxx/aicasm.c Mon Aug 15 08:52:33 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: aicasm.c,v 1.8 2009/12/27 16:03:49 jakllsch Exp $ */ +/* $NetBSD: aicasm.c,v 1.9 2016/08/15 08:52:33 maxv Exp $ */ /* * Aic7xxx SCSI host adapter firmware asssembler @@ -43,7 +43,7 @@ */ #include -__RCSID("$NetBSD: aicasm.c,v 1.8 2009/12/27 16:03:49 jakllsch Exp $"); +__RCSID("$NetBSD: aicasm.c,v 1.9 2016/08/15 08:52:33 maxv Exp $"); #include #include @@ -595,6 +595,7 @@ output_listing(char *ifilename) putchar(input); } free(func_values); + func_values = NULL; fprintf(stdout, "\nThanks!\n"); } @@ -604,6 +605,11 @@ output_listing(char *ifilename) cur_instr != NULL; cur_instr = STAILQ_NEXT(cur_instr, links), instrcount++) { + /* + * XXX XXX XXX: What exactly are we trying to do here? + * 'func_values' is always NULL, so check_patch will + * necessarily crash. + */ if (check_patch(_patch, instrcount, _addr, func_values) == 0) { /* Don't count this instruction as it is in a patch
CVS commit: src/sys/arch/ia64/stand/ia64/ski
Module Name:src Committed By: maxv Date: Mon Aug 15 09:06:40 UTC 2016 Modified Files: src/sys/arch/ia64/stand/ia64/ski: devicename.c Log Message: Two uninitialized vars, found by brainy. The former is similar to the one I fixed in ia64/stand/efi/libefi/devicename.c. I don't know how to fix the latter, so just add a comment. I will probably file a PR for this one. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sys/arch/ia64/stand/ia64/ski/devicename.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/ia64/stand/ia64/ski/devicename.c diff -u src/sys/arch/ia64/stand/ia64/ski/devicename.c:1.7 src/sys/arch/ia64/stand/ia64/ski/devicename.c:1.8 --- src/sys/arch/ia64/stand/ia64/ski/devicename.c:1.7 Tue Apr 8 21:51:06 2014 +++ src/sys/arch/ia64/stand/ia64/ski/devicename.c Mon Aug 15 09:06:39 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: devicename.c,v 1.7 2014/04/08 21:51:06 martin Exp $ */ +/* $NetBSD: devicename.c,v 1.8 2016/08/15 09:06:39 maxv Exp $ */ /*- * Copyright (c) 1998 Michael Smith@@ -91,7 +91,7 @@ ski_parsedev(struct ski_devdesc **dev, c struct devsw *dv; int dv_type; int i, unit, slice, partition, err; - char *cp; + char *cp = NULL; const char *np; /* minimum length check */ @@ -146,6 +146,10 @@ ski_parsedev(struct ski_devdesc **dev, c cp++; } } + if (cp == NULL) { + err = EINVAL; + goto fail; + } if (*cp && (*cp != ':')) { err = EINVAL; goto fail; @@ -169,6 +173,10 @@ ski_parsedev(struct ski_devdesc **dev, c goto fail; } } + if (cp == NULL) { + err = EINVAL; + goto fail; + } if (*cp && (*cp != ':')) { err = EINVAL; goto fail; @@ -228,6 +236,7 @@ ski_fmtdev(void *vdev) break; case DEVT_NET: + /* XXX XXX XXX: Yay, 'len' is not initialized here */ snprintf(buf, buflen - len, "%s%d:", dev->d_dev->dv_name, dev->d_kind.netif.unit); break; }
CVS commit: src/sys/compat/linux/common
Module Name:src Committed By: maxv Date: Mon Aug 15 09:20:11 UTC 2016 Modified Files: src/sys/compat/linux/common: linux_futex.c Log Message: Uninitialized var, found by brainy; not tested, but obvious enough To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/sys/compat/linux/common/linux_futex.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/compat/linux/common/linux_futex.c diff -u src/sys/compat/linux/common/linux_futex.c:1.34 src/sys/compat/linux/common/linux_futex.c:1.35 --- src/sys/compat/linux/common/linux_futex.c:1.34 Fri May 20 13:54:34 2016 +++ src/sys/compat/linux/common/linux_futex.c Mon Aug 15 09:20:11 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: linux_futex.c,v 1.34 2016/05/20 13:54:34 chs Exp $ */ +/* $NetBSD: linux_futex.c,v 1.35 2016/08/15 09:20:11 maxv Exp $ */ /*- * Copyright (c) 2005 Emmanuel Dreyfus, all rights reserved. @@ -32,7 +32,7 @@ */ #include -__KERNEL_RCSID(1, "$NetBSD: linux_futex.c,v 1.34 2016/05/20 13:54:34 chs Exp $"); +__KERNEL_RCSID(1, "$NetBSD: linux_futex.c,v 1.35 2016/08/15 09:20:11 maxv Exp $"); #include #include @@ -769,6 +769,7 @@ release_futexes(struct lwp *l) return; head.futex_offset = (unsigned long)u32; + futex_offset = head.futex_offset; } else #endif if (copyin(_offset, _offset, sizeof(unsigned long)))
CVS commit: src/sys/dev/if_ndis
Module Name:src Committed By: maxv Date: Mon Aug 15 08:12:32 UTC 2016 Modified Files: src/sys/dev/if_ndis: if_ndis.c Log Message: Uninitialized var, found by brainy To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 src/sys/dev/if_ndis/if_ndis.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/if_ndis/if_ndis.c diff -u src/sys/dev/if_ndis/if_ndis.c:1.36 src/sys/dev/if_ndis/if_ndis.c:1.37 --- src/sys/dev/if_ndis/if_ndis.c:1.36 Fri Jun 10 13:27:14 2016 +++ src/sys/dev/if_ndis/if_ndis.c Mon Aug 15 08:12:32 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: if_ndis.c,v 1.36 2016/06/10 13:27:14 ozaki-r Exp $ */ +/* $NetBSD: if_ndis.c,v 1.37 2016/08/15 08:12:32 maxv Exp $ */ /*- * Copyright (c) 2003 @@ -37,7 +37,7 @@ __FBSDID("$FreeBSD: src/sys/dev/if_ndis/if_ndis.c,v 1.69.2.6 2005/03/31 04:24:36 wpaul Exp $"); #endif #ifdef __NetBSD__ -__KERNEL_RCSID(0, "$NetBSD: if_ndis.c,v 1.36 2016/06/10 13:27:14 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_ndis.c,v 1.37 2016/08/15 08:12:32 maxv Exp $"); #endif @@ -1967,7 +1967,7 @@ ndis_getstate_80211(struct ndis_softc *s break; default: aprint_error_dev(sc->ndis_dev, "unknown nettype %d\n", - arg); +(int)bs->nwbx_nettype); break; } free(bs, M_TEMP);
CVS commit: src/sys/dev/bluetooth
Module Name:src Committed By: maxv Date: Mon Aug 15 08:20:11 UTC 2016 Modified Files: src/sys/dev/bluetooth: bcsp.c Log Message: Curious typo, found by mootja To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 src/sys/dev/bluetooth/bcsp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/bluetooth/bcsp.c diff -u src/sys/dev/bluetooth/bcsp.c:1.29 src/sys/dev/bluetooth/bcsp.c:1.30 --- src/sys/dev/bluetooth/bcsp.c:1.29 Thu Aug 20 14:40:17 2015 +++ src/sys/dev/bluetooth/bcsp.c Mon Aug 15 08:20:11 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: bcsp.c,v 1.29 2015/08/20 14:40:17 christos Exp $ */ +/* $NetBSD: bcsp.c,v 1.30 2016/08/15 08:20:11 maxv Exp $ */ /* * Copyright (c) 2007 KIYOHARA Takashi * All rights reserved. @@ -26,7 +26,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: bcsp.c,v 1.29 2015/08/20 14:40:17 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bcsp.c,v 1.30 2016/08/15 08:20:11 maxv Exp $"); #include #include @@ -780,7 +780,7 @@ bcsp_pktintegrity_receive(struct bcsp_so u_int pldlen; int discard = 0; uint16_t crc = 0x; - const char *errstr + const char *errstr; DPRINTFN(3, ("%s: pi receive\n", device_xname(sc->sc_dev))); #ifdef BCSP_DEBUG
CVS commit: src/sys/arch/ia64/stand/common
Module Name:src Committed By: maxv Date: Mon Aug 15 08:24:05 UTC 2016 Modified Files: src/sys/arch/ia64/stand/common: load_elf64.c Log Message: Uninitialized var, found by brainy; not tested, but obvious enough To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/arch/ia64/stand/common/load_elf64.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/ia64/stand/common/load_elf64.c diff -u src/sys/arch/ia64/stand/common/load_elf64.c:1.2 src/sys/arch/ia64/stand/common/load_elf64.c:1.3 --- src/sys/arch/ia64/stand/common/load_elf64.c:1.2 Sat Apr 22 07:58:53 2006 +++ src/sys/arch/ia64/stand/common/load_elf64.c Mon Aug 15 08:24:05 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: load_elf64.c,v 1.2 2006/04/22 07:58:53 cherry Exp $ */ +/* $NetBSD: load_elf64.c,v 1.3 2016/08/15 08:24:05 maxv Exp $ */ /*- * Copyright (c) 1998 Michael Smith@@ -75,8 +75,10 @@ elf64_loadfile(char *filename, u_int64_t marks[MARK_START] = dest; -if ((fd = loadfile(filename, marks, LOAD_KERNEL)) == -1) +if ((fd = loadfile(filename, marks, LOAD_KERNEL)) == -1) { + err = EPERM; goto oerr; +} close(fd); dest = marks[MARK_ENTRY];
CVS commit: src/sys/arch/sparc/stand/ofwboot
Module Name:src Committed By: maxv Date: Mon Aug 15 08:29:34 UTC 2016 Modified Files: src/sys/arch/sparc/stand/ofwboot: loadfile_machdep.c Log Message: Uninitialized var, found by brainy; not tested, but obvious enough To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 \ src/sys/arch/sparc/stand/ofwboot/loadfile_machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/sparc/stand/ofwboot/loadfile_machdep.c diff -u src/sys/arch/sparc/stand/ofwboot/loadfile_machdep.c:1.14 src/sys/arch/sparc/stand/ofwboot/loadfile_machdep.c:1.15 --- src/sys/arch/sparc/stand/ofwboot/loadfile_machdep.c:1.14 Sun Jun 14 16:20:44 2015 +++ src/sys/arch/sparc/stand/ofwboot/loadfile_machdep.c Mon Aug 15 08:29:34 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: loadfile_machdep.c,v 1.14 2015/06/14 16:20:44 martin Exp $ */ +/* $NetBSD: loadfile_machdep.c,v 1.15 2016/08/15 08:29:34 maxv Exp $ */ /*- * Copyright (c) 2005 The NetBSD Foundation, Inc. @@ -216,6 +216,7 @@ tlb_init_sun4u(void) phandle_t child; phandle_t root; char buf[128]; + bool foundcpu = false; u_int bootcpu; u_int cpu; @@ -236,10 +237,13 @@ tlb_init_sun4u(void) sizeof(cpu)) == -1 && _prom_getprop(child, "portid", , sizeof(cpu)) == -1) panic("tlb_init: prom_getprop"); + foundcpu = true; if (cpu == bootcpu) break; } } + if (!foundcpu) + panic("tlb_init: no cpu found!"); if (cpu != bootcpu) panic("tlb_init: no node for bootcpu?!?!"); if (_prom_getprop(child, "#dtlb-entries", _slot_max,
CVS commit: src/sys/dev/if_ndis
Module Name:src Committed By: maxv Date: Mon Aug 15 08:40:23 UTC 2016 Modified Files: src/sys/dev/if_ndis: if_ndis_pccard.c Log Message: Uninitialized var, found by brainy. FreeBSD fixed it this way four years ago. I haven't tested this change, but it is rather obvious, as the FreeBSD commit indicates, that sc->ndis_io_rid should be used instead. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/if_ndis/if_ndis_pccard.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/if_ndis/if_ndis_pccard.c diff -u src/sys/dev/if_ndis/if_ndis_pccard.c:1.4 src/sys/dev/if_ndis/if_ndis_pccard.c:1.5 --- src/sys/dev/if_ndis/if_ndis_pccard.c:1.4 Sat Mar 14 15:36:18 2009 +++ src/sys/dev/if_ndis/if_ndis_pccard.c Mon Aug 15 08:40:23 2016 @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_ndis_pccard.c,v 1.4 2009/03/14 15:36:18 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_ndis_pccard.c,v 1.5 2016/08/15 08:40:23 maxv Exp $"); #ifdef __FreeBSD__ __FBSDID("$FreeBSD: src/sys/dev/if_ndis/if_ndis_pccard.c,v 1.6.2.3 2005/03/31 04:24:36 wpaul Exp $"); #endif @@ -209,7 +209,7 @@ ndis_attach_pccard(device_t dev) goto fail; } sc->ndis_rescnt++; - resource_list_add(>ndis_rl, SYS_RES_IOPORT, rid, + resource_list_add(>ndis_rl, SYS_RES_IOPORT, sc->ndis_io_rid, rman_get_start(sc->ndis_res_io), rman_get_end(sc->ndis_res_io), rman_get_size(sc->ndis_res_io));
CVS commit: src/sys/arch/sparc/sparc
Module Name:src Committed By: maxv Date: Mon Aug 15 08:43:19 UTC 2016 Modified Files: src/sys/arch/sparc/sparc: emul.c Log Message: Return zero instead of error, otherwise it looks like it is supposed to return an error; found by brainy. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/sys/arch/sparc/sparc/emul.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/sparc/sparc/emul.c diff -u src/sys/arch/sparc/sparc/emul.c:1.18 src/sys/arch/sparc/sparc/emul.c:1.19 --- src/sys/arch/sparc/sparc/emul.c:1.18 Fri Nov 27 13:45:17 2015 +++ src/sys/arch/sparc/sparc/emul.c Mon Aug 15 08:43:19 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: emul.c,v 1.18 2015/11/27 13:45:17 joerg Exp $ */ +/* $NetBSD: emul.c,v 1.19 2016/08/15 08:43:19 maxv Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.18 2015/11/27 13:45:17 joerg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.19 2016/08/15 08:43:19 maxv Exp $"); #include #include @@ -84,7 +84,7 @@ writegpreg(struct trapframe *tf, int i, int error = 0; if (i == 0) - return error; + return 0; else if (i < 16) GPR(tf, i) = *(const int32_t *) val; else
CVS commit: src/sys/arch/ia64/stand/efi/libefi
Module Name:src Committed By: maxv Date: Mon Aug 15 09:00:52 UTC 2016 Modified Files: src/sys/arch/ia64/stand/efi/libefi: devicename.c Log Message: Uninitialized var, found by brainy. I haven't tested this change, and it may not be the perfect way to fix it. But it seems correct enough. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/sys/arch/ia64/stand/efi/libefi/devicename.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/ia64/stand/efi/libefi/devicename.c diff -u src/sys/arch/ia64/stand/efi/libefi/devicename.c:1.8 src/sys/arch/ia64/stand/efi/libefi/devicename.c:1.9 --- src/sys/arch/ia64/stand/efi/libefi/devicename.c:1.8 Tue Apr 8 21:51:06 2014 +++ src/sys/arch/ia64/stand/efi/libefi/devicename.c Mon Aug 15 09:00:52 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: devicename.c,v 1.8 2014/04/08 21:51:06 martin Exp $ */ +/* $NetBSD: devicename.c,v 1.9 2016/08/15 09:00:52 maxv Exp $ */ /*- * Copyright (c) 1998 Michael Smith@@ -95,7 +95,7 @@ efi_parsedev(struct efi_devdesc **dev, c struct devsw *dv; int dv_type; int i, unit, slice, partition, err; - char *cp; + char *cp = NULL; const char *np; /* minimum length check */ @@ -151,6 +151,10 @@ efi_parsedev(struct efi_devdesc **dev, c cp++; } } + if (cp == NULL) { + err = EINVAL; + goto fail; + } if (*cp && (*cp != ':')) { err = EINVAL; goto fail; @@ -174,6 +178,10 @@ efi_parsedev(struct efi_devdesc **dev, c goto fail; } } + if (cp == NULL) { + err = EINVAL; + goto fail; + } if (*cp && (*cp != ':')) { err = EINVAL; goto fail;
CVS commit: src/sys/net
Module Name:src Committed By: maxv Date: Mon Aug 15 09:14:12 UTC 2016 Modified Files: src/sys/net: if_ieee1394subr.c Log Message: Memory leak, found by brainy; not tested, but obvious enough To generate a diff of this commit: cvs rdiff -u -r1.56 -r1.57 src/sys/net/if_ieee1394subr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_ieee1394subr.c diff -u src/sys/net/if_ieee1394subr.c:1.56 src/sys/net/if_ieee1394subr.c:1.57 --- src/sys/net/if_ieee1394subr.c:1.56 Wed Jun 22 10:44:32 2016 +++ src/sys/net/if_ieee1394subr.c Mon Aug 15 09:14:12 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: if_ieee1394subr.c,v 1.56 2016/06/22 10:44:32 knakahara Exp $ */ +/* $NetBSD: if_ieee1394subr.c,v 1.57 2016/08/15 09:14:12 maxv Exp $ */ /* * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_ieee1394subr.c,v 1.56 2016/06/22 10:44:32 knakahara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_ieee1394subr.c,v 1.57 2016/08/15 09:14:12 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -288,8 +288,10 @@ ieee1394_fragment(struct ifnet *ifp, str ifh->ifh_dgl = htons(ic->ic_dgl); ifh->ifh_reserved = 0; m->m_next = m_copy(m0, sizeof(*ifh) + off, fraglen); - if (m->m_next == NULL) + if (m->m_next == NULL) { + m_freem(m); goto bad; + } m->m_pkthdr.len = sizeof(*ifh) + fraglen; off += fraglen; *mp = m;
CVS commit: src/sys/dev/pci
Module Name:src Committed By: maxv Date: Mon Aug 15 09:30:22 UTC 2016 Modified Files: src/sys/dev/pci: cmpci.c Log Message: Use the exact same argument for kmem_alloc and kmem_free; from brainy To generate a diff of this commit: cvs rdiff -u -r1.48 -r1.49 src/sys/dev/pci/cmpci.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/pci/cmpci.c diff -u src/sys/dev/pci/cmpci.c:1.48 src/sys/dev/pci/cmpci.c:1.49 --- src/sys/dev/pci/cmpci.c:1.48 Thu Jul 7 06:55:41 2016 +++ src/sys/dev/pci/cmpci.c Mon Aug 15 09:30:22 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: cmpci.c,v 1.48 2016/07/07 06:55:41 msaitoh Exp $ */ +/* $NetBSD: cmpci.c,v 1.49 2016/08/15 09:30:22 maxv Exp $ */ /* * Copyright (c) 2000, 2001, 2008 The NetBSD Foundation, Inc. @@ -43,7 +43,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cmpci.c,v 1.48 2016/07/07 06:55:41 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cmpci.c,v 1.49 2016/08/15 09:30:22 maxv Exp $"); #if defined(AUDIO_DEBUG) || defined(DEBUG) #define DPRINTF(x) if (cmpcidebug) printf x @@ -1016,7 +1016,7 @@ cmpci_alloc_dmamem(struct cmpci_softc *s struct cmpci_dmanode *n; error = 0; - n = kmem_alloc(sizeof(struct cmpci_dmanode), KM_SLEEP); + n = kmem_alloc(sizeof(*n), KM_SLEEP); if (n == NULL) { error = ENOMEM; goto quit;
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Sun Jul 17 10:46:43 UTC 2016 Modified Files: src/sys/arch/x86/x86: x86_machdep.c Log Message: Simplify x86_add_cluster. To generate a diff of this commit: cvs rdiff -u -r1.73 -r1.74 src/sys/arch/x86/x86/x86_machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/x86_machdep.c diff -u src/sys/arch/x86/x86/x86_machdep.c:1.73 src/sys/arch/x86/x86/x86_machdep.c:1.74 --- src/sys/arch/x86/x86/x86_machdep.c:1.73 Sat Jul 16 17:13:25 2016 +++ src/sys/arch/x86/x86/x86_machdep.c Sun Jul 17 10:46:43 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: x86_machdep.c,v 1.73 2016/07/16 17:13:25 maxv Exp $ */ +/* $NetBSD: x86_machdep.c,v 1.74 2016/07/17 10:46:43 maxv Exp $ */ /*- * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi, @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.73 2016/07/16 17:13:25 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.74 2016/07/17 10:46:43 maxv Exp $"); #include "opt_modular.h" #include "opt_physmem.h" @@ -501,8 +501,7 @@ x86_select_freelist(uint64_t maxaddr) } static int -x86_add_cluster(phys_ram_seg_t *seg_clusters, int seg_cluster_cnt, -struct extent *iomem_ex, uint64_t seg_start, uint64_t seg_end, +x86_add_cluster(struct extent *iomem_ex, uint64_t seg_start, uint64_t seg_end, uint32_t type) { uint64_t new_physmem = 0; @@ -523,7 +522,7 @@ x86_add_cluster(phys_ram_seg_t *seg_clus aprint_verbose("WARNING: skipping large memory map entry: " "0x%"PRIx64"/0x%"PRIx64"/0x%x\n", seg_start, (seg_end - seg_start), type); - return seg_cluster_cnt; + return 0; } /* @@ -533,16 +532,16 @@ x86_add_cluster(phys_ram_seg_t *seg_clus seg_end -= PAGE_SIZE; if (seg_end <= seg_start) - return seg_cluster_cnt; + return 0; - for (i = 0; i < seg_cluster_cnt; i++) { - cluster = _clusters[i]; + for (i = 0; i < mem_cluster_cnt; i++) { + cluster = _clusters[i]; if ((cluster->start == round_page(seg_start)) && (cluster->size == trunc_page(seg_end) - cluster->start)) { #ifdef DEBUG_MEMLOAD printf("WARNING: skipping duplicate segment entry\n"); #endif - return seg_cluster_cnt; + return 0; } } @@ -566,24 +565,22 @@ x86_add_cluster(phys_ram_seg_t *seg_clus "(0x%"PRIx64"/0x%"PRIx64"/0x%x) FROM " "IOMEM EXTENT MAP!\n", seg_start, seg_end - seg_start, type); - return seg_cluster_cnt; + return 0; } } - /* - * If it's not free memory, skip it. - */ + /* If it's not free memory, skip it. */ if (type != BIM_Memory) - return seg_cluster_cnt; + return 0; - /* XXX XXX XXX */ - if (seg_cluster_cnt >= VM_PHYSSEG_MAX) + if (mem_cluster_cnt >= VM_PHYSSEG_MAX) { panic("%s: too many memory segments (increase VM_PHYSSEG_MAX)", __func__); + } #ifdef PHYSMEM_MAX_ADDR if (seg_start >= MBTOB(PHYSMEM_MAX_ADDR)) - return seg_cluster_cnt; + return 0; if (seg_end > MBTOB(PHYSMEM_MAX_ADDR)) seg_end = MBTOB(PHYSMEM_MAX_ADDR); #endif @@ -592,9 +589,9 @@ x86_add_cluster(phys_ram_seg_t *seg_clus seg_end = trunc_page(seg_end); if (seg_start == seg_end) - return seg_cluster_cnt; + return 0; - cluster = _clusters[seg_cluster_cnt]; + cluster = _clusters[mem_cluster_cnt]; cluster->start = seg_start; if (iomem_ex != NULL) new_physmem = physmem + atop(seg_end - seg_start); @@ -602,7 +599,7 @@ x86_add_cluster(phys_ram_seg_t *seg_clus #ifdef PHYSMEM_MAX_SIZE if (iomem_ex != NULL) { if (physmem >= atop(MBTOB(PHYSMEM_MAX_SIZE))) - return seg_cluster_cnt; + return 0; if (new_physmem > atop(MBTOB(PHYSMEM_MAX_SIZE))) { seg_end = seg_start + MBTOB(PHYSMEM_MAX_SIZE) - ptoa(physmem); new_physmem = atop(MBTOB(PHYSMEM_MAX_SIZE)); @@ -617,9 +614,9 @@ x86_add_cluster(phys_ram_seg_t *seg_clus avail_end = seg_end; physmem = new_physmem; } - seg_cluster_cnt++; + mem_cluster_cnt++; - return seg_cluster_cnt; + return 0; } static int @@ -680,16 +677,10 @@ x86_parse_clusters(struct btinfo_memmap "0x%"PRIx64"/0x%"PRIx64"/0x%x\n", seg_start, seg_end - seg_start, type); - mem_cluster_cnt = x86_add_cluster(mem_clusters, - mem_cluster_cnt, iomem_ex, seg_start, 0xa, - type); - mem_cluster_cnt = x86_add_cluster(mem_clusters, - mem_cluster_cnt, iomem_ex, 0x10, seg_end, - type); + x86_add_cluster(iomem_ex, seg_start, 0xa, type); + x86_add_cluster(iomem_ex, 0x10, seg_end, type); } else { - mem_cluster_cnt = x86_add_cluster(mem_clusters, - mem_cluster_cnt, iomem_ex, seg_start, seg_end, - type); + x86_add_cluster(iomem_ex, seg_start, seg_end, type); } }
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Tue Jul 19 18:54:45 UTC 2016 Modified Files: src/sys/arch/x86/x86: pmap.c Log Message: This loop makes no sense at all. To generate a diff of this commit: cvs rdiff -u -r1.211 -r1.212 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.211 src/sys/arch/x86/x86/pmap.c:1.212 --- src/sys/arch/x86/x86/pmap.c:1.211 Mon Jul 11 14:18:16 2016 +++ src/sys/arch/x86/x86/pmap.c Tue Jul 19 18:54:45 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.211 2016/07/11 14:18:16 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.212 2016/07/19 18:54:45 maxv Exp $ */ /*- * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.211 2016/07/11 14:18:16 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.212 2016/07/19 18:54:45 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -3910,7 +3910,7 @@ pmap_write_protect(struct pmap *pmap, va kpreempt_disable(); pmap_map_ptes(pmap, , , ); - for (va = sva ; va < eva ; va = blockend) { + for (va = sva ; va < eva; va = blockend) { pt_entry_t *spte, *epte; int i; @@ -3926,8 +3926,8 @@ pmap_write_protect(struct pmap *pmap, va * with APTE). then we can set VM_MAXUSER_ADDRESS to * be VM_MAX_ADDRESS. */ - /* XXXCDC: ugly hack to avoid freeing PDP here */ + /* XXX: this loop makes no sense at all */ for (i = 0; i < PDP_SIZE; i++) { if (pl_i(va, PTP_LEVELS) == PDIR_SLOT_PTE+i) continue; @@ -3942,7 +3942,7 @@ pmap_write_protect(struct pmap *pmap, va spte = [pl1_i(va)]; epte = [pl1_i(blockend)]; - for (/*null */; spte < epte ; spte++) { + for (/* */; spte < epte; spte++) { pt_entry_t opte, npte; do {
CVS commit: src/sys/arch/amd64/amd64
Module Name:src Committed By: maxv Date: Wed Jul 20 13:49:18 UTC 2016 Modified Files: src/sys/arch/amd64/amd64: machdep.c Log Message: This comment is wrong. In fact, we are in low physical memory, but in high virtual memory, and only the latter matters. I'm not exactly sure why, but it appears that the kernel modules must be placed above the kernel image. Just make this comment more ambiguous, in case the next passer-by gets inspired. To generate a diff of this commit: cvs rdiff -u -r1.224 -r1.225 src/sys/arch/amd64/amd64/machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/machdep.c diff -u src/sys/arch/amd64/amd64/machdep.c:1.224 src/sys/arch/amd64/amd64/machdep.c:1.225 --- src/sys/arch/amd64/amd64/machdep.c:1.224 Sat Jul 16 17:02:34 2016 +++ src/sys/arch/amd64/amd64/machdep.c Wed Jul 20 13:49:17 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.224 2016/07/16 17:02:34 maxv Exp $ */ +/* $NetBSD: machdep.c,v 1.225 2016/07/20 13:49:17 maxv Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011 @@ -111,7 +111,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.224 2016/07/16 17:02:34 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.225 2016/07/20 13:49:17 maxv Exp $"); /* #define XENDEBUG_LOW */ @@ -377,9 +377,8 @@ cpu_startup(void) * created in locore.S, which is not big enough if we want to load many * modules dynamically. We really should be using kernel_map instead. * - * But because of the R_X86_64_32 relocations that are usually present - * in dynamic modules, the module map must be in low memory, and this - * wouldn't been guaranteed if we were using kernel_map. + * But the modules must be located above the kernel image, and that + * wouldn't be guaranteed if we were using kernel_map. */ uvm_map_setup(_map_store, module_start, module_end, 0); module_map_store.pmap = pmap_kernel();
CVS commit: src/sys/kern
Module Name:src Committed By: maxv Date: Wed Jul 20 13:11:58 UTC 2016 Modified Files: src/sys/kern: subr_kobj.c Log Message: Change the protection of the kernel modules segments once we are done relocating them. The text is allocated as RWX, and then mprotected to RW. There is a bug that prevents us from doing RW->RX on amd64 and perhaps sparc64. On x86, the pmap waits for the page to fault before granting it the X permission. But in the trap handler, such a page is considered as belonging to kernel_map, while it actually belongs to module_map. The kernel then finds out the page is not present in kernel_map, and panics. In all cases, module_map is non pageable, so even if the trap were handled properly, it still wouldn't work. Therefore, there is a small window in which the segment is RWX. But that's fine enough, for now. To generate a diff of this commit: cvs rdiff -u -r1.55 -r1.56 src/sys/kern/subr_kobj.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/subr_kobj.c diff -u src/sys/kern/subr_kobj.c:1.55 src/sys/kern/subr_kobj.c:1.56 --- src/sys/kern/subr_kobj.c:1.55 Sat Jul 9 07:25:00 2016 +++ src/sys/kern/subr_kobj.c Wed Jul 20 13:11:58 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_kobj.c,v 1.55 2016/07/09 07:25:00 maxv Exp $ */ +/* $NetBSD: subr_kobj.c,v 1.56 2016/07/20 13:11:58 maxv Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.55 2016/07/09 07:25:00 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.56 2016/07/20 13:11:58 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_modular.h" @@ -706,6 +706,10 @@ kobj_affix(kobj_t ko, const char *name) /* Jettison unneeded memory post-link. */ kobj_jettison(ko); + /* Change the memory protections, when needed. */ + uvm_km_protect(module_map, ko->ko_text_address, ko->ko_text_size, + VM_PROT_READ|VM_PROT_EXECUTE); + /* * Notify MD code that a module has been loaded. *
CVS commit: src/sys
Module Name:src Committed By: maxv Date: Wed Jul 20 13:36:19 UTC 2016 Modified Files: src/sys/kern: subr_kobj.c subr_kobj_vfs.c src/sys/sys: kobj_impl.h Log Message: Split the data+bss+rodata segment in two data+bss and rodata segments. The latter is made read-only. To generate a diff of this commit: cvs rdiff -u -r1.56 -r1.57 src/sys/kern/subr_kobj.c cvs rdiff -u -r1.9 -r1.10 src/sys/kern/subr_kobj_vfs.c cvs rdiff -u -r1.4 -r1.5 src/sys/sys/kobj_impl.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/subr_kobj.c diff -u src/sys/kern/subr_kobj.c:1.56 src/sys/kern/subr_kobj.c:1.57 --- src/sys/kern/subr_kobj.c:1.56 Wed Jul 20 13:11:58 2016 +++ src/sys/kern/subr_kobj.c Wed Jul 20 13:36:19 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_kobj.c,v 1.56 2016/07/20 13:11:58 maxv Exp $ */ +/* $NetBSD: subr_kobj.c,v 1.57 2016/07/20 13:36:19 maxv Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.56 2016/07/20 13:11:58 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.57 2016/07/20 13:36:19 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_modular.h" @@ -162,8 +162,10 @@ kobj_load(kobj_t ko) Elf_Sym *es; vaddr_t map_text_base; vaddr_t map_data_base; + vaddr_t map_rodata_base; size_t map_text_size; size_t map_data_size; + size_t map_rodata_size; int error; int symtabindex; int symstrindex; @@ -396,6 +398,7 @@ kobj_load(kobj_t ko) alignmask = 0; map_text_size = 0; map_data_size = 0; + map_rodata_size = 0; for (i = 0; i < hdr->e_shnum; i++) { if (shdr[i].sh_type != SHT_PROGBITS && shdr[i].sh_type != SHT_NOBITS) @@ -405,6 +408,10 @@ kobj_load(kobj_t ko) map_text_size += alignmask; map_text_size &= ~alignmask; map_text_size += shdr[i].sh_size; + } else if (!(shdr[i].sh_flags & SHF_WRITE)) { + map_rodata_size += alignmask; + map_rodata_size &= ~alignmask; + map_rodata_size += shdr[i].sh_size; } else { map_data_size += alignmask; map_data_size &= ~alignmask; @@ -422,6 +429,11 @@ kobj_load(kobj_t ko) error = ENOEXEC; goto out; } + if (map_rodata_size == 0) { + kobj_error(ko, "no rodata"); + error = ENOEXEC; + goto out; + } map_text_base = uvm_km_alloc(module_map, round_page(map_text_size), 0, UVM_KMF_WIRED | UVM_KMF_EXEC); @@ -443,6 +455,16 @@ kobj_load(kobj_t ko) ko->ko_data_address = map_data_base; ko->ko_data_size = map_data_size; + map_rodata_base = uvm_km_alloc(module_map, round_page(map_rodata_size), + 0, UVM_KMF_WIRED); + if (map_rodata_base == 0) { + kobj_error(ko, "out of memory"); + error = ENOMEM; + goto out; + } + ko->ko_rodata_address = map_rodata_base; + ko->ko_rodata_size = map_rodata_size; + /* * Now load code/data(progbits), zero bss(nobits), allocate space * for and load relocs @@ -461,6 +483,11 @@ kobj_load(kobj_t ko) map_text_base &= ~alignmask; addr = (void *)map_text_base; map_text_base += shdr[i].sh_size; + } else if (!(shdr[i].sh_flags & SHF_WRITE)) { +map_rodata_base += alignmask; +map_rodata_base &= ~alignmask; +addr = (void *)map_rodata_base; +map_rodata_base += shdr[i].sh_size; } else { map_data_base += alignmask; map_data_base &= ~alignmask; @@ -572,6 +599,13 @@ kobj_load(kobj_t ko) (long)ko->ko_data_address, (long)map_data_size, (long)ko->ko_data_address + map_data_size); } + if (map_rodata_base != ko->ko_rodata_address + map_rodata_size) { + panic("%s:%d: %s: map_rodata_base 0x%lx != address %lx " + "+ map_rodata_size %ld (0x%lx)\n", + __func__, __LINE__, ko->ko_name, (long)map_rodata_base, + (long)ko->ko_rodata_address, (long)map_rodata_size, + (long)ko->ko_rodata_address + map_rodata_size); + } /* * Perform local relocations only. Relocations relating to global @@ -620,6 +654,11 @@ kobj_unload(kobj_t ko) if (error != 0) kobj_error(ko, "machine dependent deinit failed (data) %d", error); + error = kobj_machdep(ko, (void *)ko->ko_rodata_address, + ko->ko_rodata_size, false); + if (error != 0) + kobj_error(ko, "machine dependent deinit failed (rodata) %d", + error); } if (ko->ko_text_address != 0) { uvm_km_free(module_map, ko->ko_text_address, @@ -629,6 +668,10 @@ kobj_unload(kobj_t ko) uvm_km_free(module_map, ko->ko_data_address, round_page(ko->ko_data_size), UVM_KMF_WIRED); } + if (ko->ko_rodata_address != 0) { + uvm_km_free(module_map, ko->ko_rodata_address, + round_page(ko->ko_rodata_size), UVM_KMF_WIRED); + } if (ko->ko_ksyms == true) { ksyms_modunload(ko->ko_name); } @@ -709,6 +752,8 @@ kobj_affix(kobj_t ko, const char *name) /* Change the memory protections, when needed. */ uvm_km_protect(module_map, ko->ko_text_address, ko->ko_text_size, VM_PROT_READ|VM_PROT_EXECUTE); +
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Wed Jul 20 12:33:59 UTC 2016 Modified Files: src/sys/arch/x86/x86: pmap.c Log Message: There is a huge bug in the way a uvm_map_protect is processed on x86. When mprotecting a page, the kernel updates the uvm protection associated with the page, and then gives control to the x86 pmap which splits the procedure in two: if we are restricting the permissions it updates the page tree right away, and if we are increasing the permissions it just waits for the page to fault. In the first case, it forgets to take care of the X permission. Which means that if we allocate an executable page, it is impossible to remove the X permission on it, this being true regardless of whether the mprotect call comes from the kernel or from userland. It is not possible to make sure the page is non executable either, since the only holder of the permission information is uvm, and no track is kept at the pmap level of the actual permissions enforced. In short, the kernel believes the page is non executable, while the cpu knows it is. Fix this by properly taking care of the !VM_PROT_EXECUTE case. Since the bit manipulation is a little tricky we use two vars: bit_rem (remove) and bit_put. To generate a diff of this commit: cvs rdiff -u -r1.212 -r1.213 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.212 src/sys/arch/x86/x86/pmap.c:1.213 --- src/sys/arch/x86/x86/pmap.c:1.212 Tue Jul 19 18:54:45 2016 +++ src/sys/arch/x86/x86/pmap.c Wed Jul 20 12:33:59 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.212 2016/07/19 18:54:45 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.213 2016/07/20 12:33:59 maxv Exp $ */ /*- * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.212 2016/07/19 18:54:45 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.213 2016/07/20 12:33:59 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -3896,6 +3896,7 @@ pmap_pv_clear_attrs(paddr_t pa, unsigned void pmap_write_protect(struct pmap *pmap, vaddr_t sva, vaddr_t eva, vm_prot_t prot) { + pt_entry_t bit_rem, bit_put; pt_entry_t *ptes; pt_entry_t * const *pdes; struct pmap *pmap2; @@ -3903,6 +3904,14 @@ pmap_write_protect(struct pmap *pmap, va KASSERT(curlwp->l_md.md_gc_pmap != pmap); + bit_rem = 0; + if (!(prot & VM_PROT_WRITE)) + bit_rem = PG_RW; + + bit_put = 0; + if (!(prot & VM_PROT_EXECUTE)) + bit_put = pmap_pg_nx; + sva &= PG_FRAME; eva &= PG_FRAME; @@ -3947,10 +3956,10 @@ pmap_write_protect(struct pmap *pmap, va do { opte = *spte; -if ((~opte & (PG_RW | PG_V)) != 0) { +if (!pmap_valid_entry(opte)) { goto next; } -npte = opte & ~PG_RW; +npte = (opte & ~bit_rem) | bit_put; } while (pmap_pte_cas(spte, opte, npte) != opte); if ((opte & PG_M) != 0) {
CVS commit: src/sys/uvm
Module Name:src Committed By: maxv Date: Wed Jul 20 12:38:44 UTC 2016 Modified Files: src/sys/uvm: uvm_extern.h uvm_km.c Log Message: Introduce uvm_km_protect. To generate a diff of this commit: cvs rdiff -u -r1.197 -r1.198 src/sys/uvm/uvm_extern.h cvs rdiff -u -r1.139 -r1.140 src/sys/uvm/uvm_km.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/uvm/uvm_extern.h diff -u src/sys/uvm/uvm_extern.h:1.197 src/sys/uvm/uvm_extern.h:1.198 --- src/sys/uvm/uvm_extern.h:1.197 Wed May 25 17:43:58 2016 +++ src/sys/uvm/uvm_extern.h Wed Jul 20 12:38:43 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: uvm_extern.h,v 1.197 2016/05/25 17:43:58 christos Exp $ */ +/* $NetBSD: uvm_extern.h,v 1.198 2016/07/20 12:38:43 maxv Exp $ */ /* * Copyright (c) 1997 Charles D. Cranor and Washington University. @@ -627,6 +627,8 @@ int uvm_io(struct vm_map *, struct uio /* uvm_km.c */ vaddr_t uvm_km_alloc(struct vm_map *, vsize_t, vsize_t, uvm_flag_t); +int uvm_km_protect(struct vm_map *, vaddr_t, vsize_t, + vm_prot_t); void uvm_km_free(struct vm_map *, vaddr_t, vsize_t, uvm_flag_t); Index: src/sys/uvm/uvm_km.c diff -u src/sys/uvm/uvm_km.c:1.139 src/sys/uvm/uvm_km.c:1.140 --- src/sys/uvm/uvm_km.c:1.139 Fri Feb 6 18:19:22 2015 +++ src/sys/uvm/uvm_km.c Wed Jul 20 12:38:43 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: uvm_km.c,v 1.139 2015/02/06 18:19:22 maxv Exp $ */ +/* $NetBSD: uvm_km.c,v 1.140 2016/07/20 12:38:43 maxv Exp $ */ /* * Copyright (c) 1997 Charles D. Cranor and Washington University. @@ -152,7 +152,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uvm_km.c,v 1.139 2015/02/06 18:19:22 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uvm_km.c,v 1.140 2016/07/20 12:38:43 maxv Exp $"); #include "opt_uvmhist.h" @@ -708,6 +708,16 @@ uvm_km_alloc(struct vm_map *map, vsize_t } /* + * uvm_km_protect: change the protection of an allocated area + */ + +int +uvm_km_protect(struct vm_map *map, vaddr_t addr, vsize_t size, vm_prot_t prot) +{ + return uvm_map_protect(map, addr, addr + round_page(size), prot, false); +} + +/* * uvm_km_free: free an area of kernel memory */
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Sat Jul 16 14:51:45 UTC 2016 Modified Files: src/sys/arch/x86/x86: x86_machdep.c Log Message: Introduce x86_load_region(), and explain a little what we are doing. To generate a diff of this commit: cvs rdiff -u -r1.70 -r1.71 src/sys/arch/x86/x86/x86_machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/x86_machdep.c diff -u src/sys/arch/x86/x86/x86_machdep.c:1.70 src/sys/arch/x86/x86/x86_machdep.c:1.71 --- src/sys/arch/x86/x86/x86_machdep.c:1.70 Thu Jan 28 06:52:55 2016 +++ src/sys/arch/x86/x86/x86_machdep.c Sat Jul 16 14:51:45 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: x86_machdep.c,v 1.70 2016/01/28 06:52:55 jnemeth Exp $ */ +/* $NetBSD: x86_machdep.c,v 1.71 2016/07/16 14:51:45 maxv Exp $ */ /*- * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi, @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.70 2016/01/28 06:52:55 jnemeth Exp $"); +__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.71 2016/07/16 14:51:45 maxv Exp $"); #include "opt_modular.h" #include "opt_physmem.h" @@ -773,6 +773,49 @@ x86_select_freelist(uint64_t maxaddr) panic("no freelist for maximum address %"PRIx64, maxaddr); } +/* + * Load the physical memory region from seg_start to seg_end into the VM + * system. + */ +static void +x86_load_region(uint64_t seg_start, uint64_t seg_end) +{ + unsigned int i; + uint64_t tmp; + + i = __arraycount(x86_freelists); + while (i--) { + if (x86_freelists[i].limit <= seg_start) + continue; + if (x86_freelists[i].freelist == VM_FREELIST_DEFAULT) + continue; + tmp = MIN(x86_freelists[i].limit, seg_end); + if (tmp == seg_start) + continue; + +#ifdef DEBUG_MEMLOAD + printf("loading freelist %d 0x%"PRIx64"-0x%"PRIx64 + " (0x%"PRIx64"-0x%"PRIx64")\n", x86_freelists[i].freelist, + seg_start, tmp, (uint64_t)atop(seg_start), + (uint64_t)atop(tmp)); +#endif + + uvm_page_physload(atop(seg_start), atop(tmp), atop(seg_start), + atop(tmp), x86_freelists[i].freelist); + seg_start = tmp; + } + + if (seg_start != seg_end) { +#ifdef DEBUG_MEMLOAD + printf("loading default 0x%"PRIx64"-0x%"PRIx64 + " (0x%"PRIx64"-0x%"PRIx64")\n", seg_start, seg_end, + (uint64_t)atop(seg_start), (uint64_t)atop(seg_end)); +#endif + uvm_page_physload(atop(seg_start), atop(seg_end), + atop(seg_start), atop(seg_end), VM_FREELIST_DEFAULT); + } +} + int initx86_load_memmap(paddr_t first_avail) { @@ -796,11 +839,11 @@ initx86_load_memmap(paddr_t first_avail) #endif /* - * Now, load the memory clusters (which have already been - * rounded and truncated) into the VM system. + * Now, load the memory clusters (which have already been rounded and + * truncated) into the VM system. * - * NOTE: WE ASSUME THAT MEMORY STARTS AT 0 AND THAT THE KERNEL - * IS LOADED AT IOM_END (1M). + * NOTE: we assume that memory starts at 0 and that the kernel is + * loaded at IOM_END (1MB). */ for (x = 0; x < mem_cluster_cnt; x++) { const phys_ram_seg_t *cluster = _clusters[x]; @@ -810,13 +853,11 @@ initx86_load_memmap(paddr_t first_avail) seg_start1 = 0; seg_end1 = 0; - /* - * Skip memory before our available starting point. - */ + /* Skip memory before our available starting point. */ if (seg_end <= avail_start) continue; - if (avail_start >= seg_start && avail_start < seg_end) { + if (seg_start <= avail_start && avail_start < seg_end) { if (seg_start != 0) panic("init_x86_64: memory doesn't start at 0"); seg_start = avail_start; @@ -825,8 +866,8 @@ initx86_load_memmap(paddr_t first_avail) } /* - * If this segment contains the kernel, split it - * in two, around the kernel. + * If this segment contains the kernel, split it in two, around + * the kernel. */ if (seg_start <= IOM_END && first_avail <= seg_end) { seg_start1 = first_avail; @@ -837,92 +878,19 @@ initx86_load_memmap(paddr_t first_avail) /* First hunk */ if (seg_start != seg_end) { - i = __arraycount(x86_freelists); - while (i--) { -uint64_t tmp; - -if (x86_freelists[i].limit <= seg_start) - continue; -if (x86_freelists[i].freelist == -VM_FREELIST_DEFAULT) - continue; -tmp = MIN(x86_freelists[i].limit, seg_end); -if (tmp == seg_start) - continue; -#ifdef DEBUG_MEMLOAD -printf("loading freelist %d" -" 0x%"PRIx64"-0x%"PRIx64 -" (0x%"PRIx64"-0x%"PRIx64")\n", -x86_freelists[i].freelist, seg_start, tmp, -(uint64_t)atop(seg_start), -(uint64_t)atop(tmp)); -#endif -uvm_page_physload(atop(seg_start), atop(tmp), -atop(seg_start), atop(tmp), -x86_freelists[i].freelist); -seg_start = tmp; - } - - if (seg_start != seg_end) { -#ifdef DEBUG_MEMLOAD -printf("loading default 0x%"PRIx64"-0x%"PRIx64 -" (0x%"PRIx64"-0x%"PRIx64")\n", -
CVS commit: src/sys/arch
Module Name:src Committed By: maxv Date: Sat Jul 16 17:02:35 UTC 2016 Modified Files: src/sys/arch/amd64/amd64: machdep.c src/sys/arch/i386/i386: machdep.c src/sys/arch/x86/include: machdep.h src/sys/arch/x86/x86: x86_machdep.c Log Message: Simplify the way physical pages are internalized into the VM system on x86. Only two functions are called now: init_x86_clusters, which initializes the memory clusters from the bootinfo, and init_x86_vm, which inserts the pages from the clusters into VM. To generate a diff of this commit: cvs rdiff -u -r1.223 -r1.224 src/sys/arch/amd64/amd64/machdep.c cvs rdiff -u -r1.758 -r1.759 src/sys/arch/i386/i386/machdep.c cvs rdiff -u -r1.7 -r1.8 src/sys/arch/x86/include/machdep.h cvs rdiff -u -r1.71 -r1.72 src/sys/arch/x86/x86/x86_machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/machdep.c diff -u src/sys/arch/amd64/amd64/machdep.c:1.223 src/sys/arch/amd64/amd64/machdep.c:1.224 --- src/sys/arch/amd64/amd64/machdep.c:1.223 Wed Jul 13 15:53:26 2016 +++ src/sys/arch/amd64/amd64/machdep.c Sat Jul 16 17:02:34 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.223 2016/07/13 15:53:26 maxv Exp $ */ +/* $NetBSD: machdep.c,v 1.224 2016/07/16 17:02:34 maxv Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011 @@ -111,7 +111,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.223 2016/07/13 15:53:26 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.224 2016/07/16 17:02:34 maxv Exp $"); /* #define XENDEBUG_LOW */ @@ -1537,10 +1537,6 @@ init_x86_64(paddr_t first_avail) int x; #ifndef XEN int ist; - extern struct extent *iomem_ex; -#if !defined(REALEXTMEM) && !defined(REALBASEMEM) - struct btinfo_memmap *bim; -#endif #endif /* !XEN */ #ifdef XEN @@ -1589,23 +1585,8 @@ init_x86_64(paddr_t first_avail) */ avail_start = 8 * PAGE_SIZE; -#if !defined(REALBASEMEM) && !defined(REALEXTMEM) - /* - * Check to see if we have a memory map from the BIOS (passed to us by - * the boot program). - */ - bim = lookup_bootinfo(BTINFO_MEMMAP); - if (bim != NULL && bim->num > 0) - initx86_parse_memmap(bim, iomem_ex); -#endif /* ! REALBASEMEM && ! REALEXTMEM */ - - /* - * If initx86_parse_memmap didn't find any valid segment, fall back to - * former code. - */ - if (mem_cluster_cnt == 0) - initx86_fake_memmap(iomem_ex); - + /* Initialize the memory clusters (needed in pmap_boostrap). */ + init_x86_clusters(); #else /* XEN */ /* Parse Xen command line (replace bootinfo) */ xen_parse_cmdline(XEN_PARSE_BOOTFLAGS, NULL); @@ -1629,7 +1610,8 @@ init_x86_64(paddr_t first_avail) pmap_prealloc_lowmem_ptps(); #ifndef XEN - initx86_load_memmap(first_avail); + /* Internalize the physical pages into the VM system. */ + init_x86_vm(first_avail); #else /* XEN */ kern_end = KERNBASE + first_avail; physmem = xen_start_info.nr_pages; Index: src/sys/arch/i386/i386/machdep.c diff -u src/sys/arch/i386/i386/machdep.c:1.758 src/sys/arch/i386/i386/machdep.c:1.759 --- src/sys/arch/i386/i386/machdep.c:1.758 Wed Jul 13 15:53:27 2016 +++ src/sys/arch/i386/i386/machdep.c Sat Jul 16 17:02:34 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.758 2016/07/13 15:53:27 maxv Exp $ */ +/* $NetBSD: machdep.c,v 1.759 2016/07/16 17:02:34 maxv Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009 @@ -67,7 +67,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.758 2016/07/13 15:53:27 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.759 2016/07/16 17:02:34 maxv Exp $"); #include "opt_beep.h" #include "opt_compat_ibcs2.h" @@ -1129,9 +1129,7 @@ init386(paddr_t first_avail) int x; #ifndef XEN union descriptor *tgdt; - extern struct extent *iomem_ex; struct region_descriptor region; - struct btinfo_memmap *bim; #endif #if NBIOSCALL > 0 extern int biostramp_image_size; @@ -1246,24 +1244,11 @@ init386(paddr_t first_avail) pmap_bootstrap((vaddr_t)atdevbase + IOM_SIZE); #ifndef XEN - /* - * Check to see if we have a memory map from the BIOS (passed to us by - * the boot program). - */ - bim = lookup_bootinfo(BTINFO_MEMMAP); - if ((biosmem_implicit || (biosbasemem == 0 && biosextmem == 0)) && - bim != NULL && bim->num > 0) - initx86_parse_memmap(bim, iomem_ex); - - /* - * If initx86_parse_memmap didn't find any valid segment, fall back to - * former code. - */ - if (mem_cluster_cnt == 0) - initx86_fake_memmap(iomem_ex); - - initx86_load_memmap(first_avail); + /* Initialize the memory clusters. */ + init_x86_clusters(); + /* Internalize the physical pages into the VM system. */ + init_x86_vm(first_avail); #else /* !XEN */ XENPRINTK(("load the memory cluster 0x%" PRIx64 " (%" PRId64 ") - " "0x%" PRIx64 " (%" PRId64 ")\n", Index: src/sys/arch/x86/include/machdep.h diff -u src/sys/arch/x86/include/machdep.h:1.7
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Sat Jul 16 17:13:25 UTC 2016 Modified Files: src/sys/arch/x86/x86: x86_machdep.c Log Message: KNF, and rename. To generate a diff of this commit: cvs rdiff -u -r1.72 -r1.73 src/sys/arch/x86/x86/x86_machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/x86_machdep.c diff -u src/sys/arch/x86/x86/x86_machdep.c:1.72 src/sys/arch/x86/x86/x86_machdep.c:1.73 --- src/sys/arch/x86/x86/x86_machdep.c:1.72 Sat Jul 16 17:02:34 2016 +++ src/sys/arch/x86/x86/x86_machdep.c Sat Jul 16 17:13:25 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: x86_machdep.c,v 1.72 2016/07/16 17:02:34 maxv Exp $ */ +/* $NetBSD: x86_machdep.c,v 1.73 2016/07/16 17:13:25 maxv Exp $ */ /*- * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi, @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.72 2016/07/16 17:02:34 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.73 2016/07/16 17:13:25 maxv Exp $"); #include "opt_modular.h" #include "opt_physmem.h" @@ -459,12 +459,51 @@ x86_cpu_idle_set(void (*func)(void), con #define KBTOB(x) ((size_t)(x) * 1024UL) #define MBTOB(x) ((size_t)(x) * 1024UL * 1024UL) +static struct { + int freelist; + uint64_t limit; +} x86_freelists[VM_NFREELIST] = { + { VM_FREELIST_DEFAULT, 0 }, +#ifdef VM_FREELIST_FIRST1T + /* 40-bit addresses needed for modern graphics. */ + { VM_FREELIST_FIRST1T, 1ULL * 1024 * 1024 * 1024 * 1024 }, +#endif +#ifdef VM_FREELIST_FIRST64G + /* 36-bit addresses needed for oldish graphics. */ + { VM_FREELIST_FIRST64G, 64ULL * 1024 * 1024 * 1024 }, +#endif +#ifdef VM_FREELIST_FIRST4G + /* 32-bit addresses needed for PCI 32-bit DMA and old graphics. */ + { VM_FREELIST_FIRST4G, 4ULL * 1024 * 1024 * 1024 }, +#endif + /* 30-bit addresses needed for ancient graphics. */ + { VM_FREELIST_FIRST1G, 1ULL * 1024 * 1024 * 1024 }, + /* 24-bit addresses needed for ISA DMA. */ + { VM_FREELIST_FIRST16, 16 * 1024 * 1024 }, +}; + extern paddr_t avail_start, avail_end; +int +x86_select_freelist(uint64_t maxaddr) +{ + unsigned int i; + + if (avail_end <= maxaddr) + return VM_NFREELIST; + + for (i = 0; i < __arraycount(x86_freelists); i++) { + if ((x86_freelists[i].limit - 1) <= maxaddr) + return x86_freelists[i].freelist; + } + + panic("no freelist for maximum address %"PRIx64, maxaddr); +} + static int -add_mem_cluster(phys_ram_seg_t *seg_clusters, int seg_cluster_cnt, - struct extent *iomem_ex, - uint64_t seg_start, uint64_t seg_end, uint32_t type) +x86_add_cluster(phys_ram_seg_t *seg_clusters, int seg_cluster_cnt, +struct extent *iomem_ex, uint64_t seg_start, uint64_t seg_end, +uint32_t type) { uint64_t new_physmem = 0; phys_ram_seg_t *cluster; @@ -483,15 +522,12 @@ add_mem_cluster(phys_ram_seg_t *seg_clus if (seg_end > TOPLIMIT) { aprint_verbose("WARNING: skipping large memory map entry: " "0x%"PRIx64"/0x%"PRIx64"/0x%x\n", - seg_start, - (seg_end - seg_start), - type); + seg_start, (seg_end - seg_start), type); return seg_cluster_cnt; } /* - * XXX Chop the last page off the size so that - * XXX it can fit in avail_end. + * XXX: Chop the last page off the size so that it can fit in avail_end. */ if (seg_end == TOPLIMIT) seg_end -= PAGE_SIZE; @@ -501,9 +537,8 @@ add_mem_cluster(phys_ram_seg_t *seg_clus for (i = 0; i < seg_cluster_cnt; i++) { cluster = _clusters[i]; - if ((cluster->start == round_page(seg_start)) - && (cluster->size == trunc_page(seg_end) - cluster->start)) - { + if ((cluster->start == round_page(seg_start)) && + (cluster->size == trunc_page(seg_end) - cluster->start)) { #ifdef DEBUG_MEMLOAD printf("WARNING: skipping duplicate segment entry\n"); #endif @@ -512,9 +547,8 @@ add_mem_cluster(phys_ram_seg_t *seg_clus } /* - * Allocate the physical addresses used by RAM - * from the iomem extent map. This is done before - * the addresses are page rounded just to make + * Allocate the physical addresses used by RAM from the iomem extent + * map. This is done before the addresses are page rounded just to make * sure we get them all. */ if (seg_start < 0x1ULL) { @@ -589,7 +623,7 @@ add_mem_cluster(phys_ram_seg_t *seg_clus } static int -initx86_parse_memmap(struct btinfo_memmap *bim, struct extent *iomem_ex) +x86_parse_clusters(struct btinfo_memmap *bim, struct extent *iomem_ex) { uint64_t seg_start, seg_end; uint64_t addr, size; @@ -602,6 +636,7 @@ initx86_parse_memmap(struct btinfo_memma #ifdef DEBUG_MEMLOAD printf("BIOS MEMORY MAP (%d ENTRIES):\n", bim->num); #endif + for (x = 0; x < bim->num; x++) { addr = bim->entry[x].addr; size = bim->entry[x].size; @@ -611,9 +646,7 @@ initx86_parse_memmap(struct btinfo_memma addr, size, type); #endif - /* - * If the segment is not memory, skip it. - */ + /* If the segment is not memory, skip
CVS commit: src/sys/arch/x86/include
Module Name:src Committed By: maxv Date: Sat Jul 16 13:47:01 UTC 2016 Modified Files: src/sys/arch/x86/include: specialreg.h Log Message: Add the cr4 flags for PKE and UMIP. To generate a diff of this commit: cvs rdiff -u -r1.87 -r1.88 src/sys/arch/x86/include/specialreg.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/include/specialreg.h diff -u src/sys/arch/x86/include/specialreg.h:1.87 src/sys/arch/x86/include/specialreg.h:1.88 --- src/sys/arch/x86/include/specialreg.h:1.87 Wed Apr 27 08:51:32 2016 +++ src/sys/arch/x86/include/specialreg.h Sat Jul 16 13:47:01 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: specialreg.h,v 1.87 2016/04/27 08:51:32 msaitoh Exp $ */ +/* $NetBSD: specialreg.h,v 1.88 2016/07/16 13:47:01 maxv Exp $ */ /*- * Copyright (c) 1991 The Regents of the University of California. @@ -81,6 +81,7 @@ #define CR4_PCE 0x0100 /* enable RDPMC instruction for all cpls */ #define CR4_OSFXSR 0x0200 /* enable fxsave/fxrestor and SSE */ #define CR4_OSXMMEXCPT 0x0400 /* enable unmasked SSE exceptions */ +#define CR4_UMIP 0x0800 /* user-mode instruction prevention */ #define CR4_VMXE 0x2000 /* enable VMX operations */ #define CR4_SMXE 0x4000 /* enable SMX operations */ #define CR4_FSGSBASE 0x0001 /* enable *FSBASE and *GSBASE instructions */ @@ -88,6 +89,7 @@ #define CR4_OSXSAVE 0x0004 /* enable xsave and xrestore */ #define CR4_SMEP 0x0010 /* enable SMEP support */ #define CR4_SMAP 0x0020 /* enable SMAP support */ +#define CR4_PKE 0x0040 /* protection key enable */ /* * Extended Control Register XCR0
CVS commit: src/sys/arch
Module Name:src Committed By: maxv Date: Wed Jul 13 15:35:56 UTC 2016 Modified Files: src/sys/arch/amd64/amd64: machdep.c src/sys/arch/i386/i386: machdep.c Log Message: KNF To generate a diff of this commit: cvs rdiff -u -r1.220 -r1.221 src/sys/arch/amd64/amd64/machdep.c cvs rdiff -u -r1.755 -r1.756 src/sys/arch/i386/i386/machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/machdep.c diff -u src/sys/arch/amd64/amd64/machdep.c:1.220 src/sys/arch/amd64/amd64/machdep.c:1.221 --- src/sys/arch/amd64/amd64/machdep.c:1.220 Sat Jul 2 07:22:09 2016 +++ src/sys/arch/amd64/amd64/machdep.c Wed Jul 13 15:35:56 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.220 2016/07/02 07:22:09 maxv Exp $ */ +/* $NetBSD: machdep.c,v 1.221 2016/07/13 15:35:56 maxv Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011 @@ -111,7 +111,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.220 2016/07/02 07:22:09 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.221 2016/07/13 15:35:56 maxv Exp $"); /* #define XENDEBUG_LOW */ @@ -217,25 +217,22 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v char machine[] = "amd64"; /* CPU "architecture" */ char machine_arch[] = "x86_64"; /* machine == machine_arch */ -extern struct bi_devmatch *x86_alldisks; -extern int x86_ndisks; - #ifdef CPURESET_DELAY -int cpureset_delay = CPURESET_DELAY; +int cpureset_delay = CPURESET_DELAY; #else -int cpureset_delay = 2000; /* default to 2s */ +int cpureset_delay = 2000; /* default to 2s */ #endif -int cpu_class = CPUCLASS_686; +int cpu_class = CPUCLASS_686; #ifdef MTRR struct mtrr_funcs *mtrr_funcs; #endif -uint64_t dumpmem_low; -uint64_t dumpmem_high; -int cpu_class; -int use_pae; +uint64_t dumpmem_low; +uint64_t dumpmem_high; +int cpu_class; +int use_pae; #ifndef NO_SPARSE_DUMP int sparse_dump = 1; @@ -255,7 +252,7 @@ size_t dump_npages; size_t dump_header_size; size_t dump_totalbytesleft; -vaddr_t msgbuf_vaddr; +vaddr_t msgbuf_vaddr; paddr_t msgbuf_paddr; struct { @@ -263,9 +260,9 @@ struct { psize_t sz; } msgbuf_p_seg[VM_PHYSSEG_MAX]; unsigned int msgbuf_p_cnt = 0; - -vaddr_t idt_vaddr; -paddr_t idt_paddr; + +vaddr_t idt_vaddr; +paddr_t idt_paddr; vaddr_t module_start, module_end; static struct vm_map module_map_store; @@ -274,9 +271,9 @@ vaddr_t kern_end; struct vm_map *phys_map = NULL; -extern paddr_t avail_start, avail_end; +extern paddr_t avail_start, avail_end; #ifdef XEN -extern paddr_t pmap_pa_start, pmap_pa_end; +extern paddr_t pmap_pa_start, pmap_pa_end; #endif #ifndef XEN @@ -292,15 +289,15 @@ void (*initclock_func)(void) = xen_initc * Size of memory segments, before any memory is stolen. */ phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX]; -int mem_cluster_cnt; +int mem_cluster_cnt; -char x86_64_doubleflt_stack[4096]; +char x86_64_doubleflt_stack[4096]; -int cpu_dump(void); -int cpu_dumpsize(void); -u_long cpu_dump_mempagecnt(void); -void dodumpsys(void); -void dumpsys(void); +int cpu_dump(void); +int cpu_dumpsize(void); +u_long cpu_dump_mempagecnt(void); +void dodumpsys(void); +void dumpsys(void); extern int time_adjusted; /* XXX no common header */ @@ -323,7 +320,7 @@ int dump_header_finish(void); int dump_seg_count_range(paddr_t, paddr_t); int dumpsys_seg(paddr_t, paddr_t); -void init_x86_64(paddr_t); +void init_x86_64(paddr_t); static int valid_user_selector(struct lwp *, uint64_t); @@ -351,8 +348,7 @@ cpu_startup(void) for (x = 0, sz = 0; x < msgbuf_p_cnt; sz += msgbuf_p_seg[x++].sz) continue; - msgbuf_vaddr = uvm_km_alloc(kernel_map, sz, 0, - UVM_KMF_VAONLY); + msgbuf_vaddr = uvm_km_alloc(kernel_map, sz, 0, UVM_KMF_VAONLY); if (msgbuf_vaddr == 0) panic("failed to valloc msgbuf_vaddr"); @@ -360,8 +356,8 @@ cpu_startup(void) for (y = 0, sz = 0; y < msgbuf_p_cnt; y++) { for (x = 0; x < btoc(msgbuf_p_seg[y].sz); x++, sz += PAGE_SIZE) pmap_kenter_pa((vaddr_t)msgbuf_vaddr + sz, - msgbuf_p_seg[y].paddr + x * PAGE_SIZE, - VM_PROT_READ | VM_PROT_WRITE, 0); + msgbuf_p_seg[y].paddr + x * PAGE_SIZE, + VM_PROT_READ|VM_PROT_WRITE, 0); } pmap_update(pmap_kernel()); @@ -1598,8 +1594,8 @@ init_x86_64(paddr_t first_avail) #if !defined(REALBASEMEM) && !defined(REALEXTMEM) /* - * Check to see if we have a memory map from the BIOS (passed - * to us by the boot program. + * Check to see if we have a memory map from the BIOS (passed to us by + * the boot program). */ bim = lookup_bootinfo(BTINFO_MEMMAP); if (bim != NULL && bim->num > 0) @@ -1607,14 +1603,14 @@ init_x86_64(paddr_t first_avail) #endif /* ! REALBASEMEM && ! REALEXTMEM */ /* - * If the loop above didn't find any valid segment, fall back to + * If initx86_parse_memmap didn't find any valid segment, fall back to * former code. */ if
CVS commit: src/sys/arch
Module Name:src Committed By: maxv Date: Wed Jul 13 15:39:33 UTC 2016 Modified Files: src/sys/arch/amd64/amd64: machdep.c src/sys/arch/i386/i386: machdep.c Log Message: Remove msgbuf_paddr. To generate a diff of this commit: cvs rdiff -u -r1.221 -r1.222 src/sys/arch/amd64/amd64/machdep.c cvs rdiff -u -r1.756 -r1.757 src/sys/arch/i386/i386/machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/machdep.c diff -u src/sys/arch/amd64/amd64/machdep.c:1.221 src/sys/arch/amd64/amd64/machdep.c:1.222 --- src/sys/arch/amd64/amd64/machdep.c:1.221 Wed Jul 13 15:35:56 2016 +++ src/sys/arch/amd64/amd64/machdep.c Wed Jul 13 15:39:33 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.221 2016/07/13 15:35:56 maxv Exp $ */ +/* $NetBSD: machdep.c,v 1.222 2016/07/13 15:39:33 maxv Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011 @@ -111,7 +111,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.221 2016/07/13 15:35:56 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.222 2016/07/13 15:39:33 maxv Exp $"); /* #define XENDEBUG_LOW */ @@ -253,7 +253,6 @@ size_t dump_header_size; size_t dump_totalbytesleft; vaddr_t msgbuf_vaddr; -paddr_t msgbuf_paddr; struct { paddr_t paddr; @@ -352,7 +351,6 @@ cpu_startup(void) if (msgbuf_vaddr == 0) panic("failed to valloc msgbuf_vaddr"); - /* msgbuf_paddr was init'd in pmap */ for (y = 0, sz = 0; y < msgbuf_p_cnt; y++) { for (x = 0; x < btoc(msgbuf_p_seg[y].sz); x++, sz += PAGE_SIZE) pmap_kenter_pa((vaddr_t)msgbuf_vaddr + sz, Index: src/sys/arch/i386/i386/machdep.c diff -u src/sys/arch/i386/i386/machdep.c:1.756 src/sys/arch/i386/i386/machdep.c:1.757 --- src/sys/arch/i386/i386/machdep.c:1.756 Wed Jul 13 15:35:56 2016 +++ src/sys/arch/i386/i386/machdep.c Wed Jul 13 15:39:33 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.756 2016/07/13 15:35:56 maxv Exp $ */ +/* $NetBSD: machdep.c,v 1.757 2016/07/13 15:39:33 maxv Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009 @@ -67,7 +67,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.756 2016/07/13 15:35:56 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.757 2016/07/13 15:39:33 maxv Exp $"); #include "opt_beep.h" #include "opt_compat_ibcs2.h" @@ -433,7 +433,6 @@ cpu_startup(void) if (msgbuf_vaddr == 0) panic("failed to valloc msgbuf_vaddr"); - /* msgbuf_paddr was init'd in pmap */ for (y = 0, sz = 0; y < msgbuf_p_cnt; y++) { for (x = 0; x < btoc(msgbuf_p_seg[y].sz); x++, sz += PAGE_SIZE) pmap_kenter_pa((vaddr_t)msgbuf_vaddr + sz,
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Sat Jul 9 08:05:47 UTC 2016 Modified Files: src/sys/arch/x86/x86: pmap.c Log Message: When a user pmap is created, it is populated with the higher kernel slots, which become accessible upon kernel entry (syscall, cpu switch, or whatever). Put the NOX bit in the user recursive slot, so the whole tree does not appear as executable in kernel mode. This is already what is done in the kernel pmap. To generate a diff of this commit: cvs rdiff -u -r1.207 -r1.208 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.207 src/sys/arch/x86/x86/pmap.c:1.208 --- src/sys/arch/x86/x86/pmap.c:1.207 Sat Jul 9 07:47:25 2016 +++ src/sys/arch/x86/x86/pmap.c Sat Jul 9 08:05:46 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.207 2016/07/09 07:47:25 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.208 2016/07/09 08:05:46 maxv Exp $ */ /*- * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.207 2016/07/09 07:47:25 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.208 2016/07/09 08:05:46 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -2164,7 +2164,8 @@ pmap_pdp_ctor(void *arg, void *v, int fl (void)pmap_extract(pmap_kernel(), object, ); /* Put in recursive PDE to map the PTEs */ - pdir[PDIR_SLOT_PTE + i] = pmap_pa2pte(pdirpa) | PG_V; + pdir[PDIR_SLOT_PTE + i] = pmap_pa2pte(pdirpa) | PG_V | + pmap_pg_nx; #ifndef XEN pdir[PDIR_SLOT_PTE + i] |= PG_KW; #endif
CVS commit: src/sys
Module Name:src Committed By: maxv Date: Sat Jul 9 07:25:00 UTC 2016 Modified Files: src/sys/kern: subr_kobj.c subr_kobj_vfs.c src/sys/sys: kobj_impl.h Log Message: When loading a module from VFS and from the bootloader, the kernel packs up the module segments into one big RWX chunk. Split this chunk into two different text and data+bss+rodata chunks. The latter is made non- executable. This also provides some kind of ASLR, since the chunks are not necessarily contiguous. To generate a diff of this commit: cvs rdiff -u -r1.54 -r1.55 src/sys/kern/subr_kobj.c cvs rdiff -u -r1.8 -r1.9 src/sys/kern/subr_kobj_vfs.c cvs rdiff -u -r1.3 -r1.4 src/sys/sys/kobj_impl.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/subr_kobj.c diff -u src/sys/kern/subr_kobj.c:1.54 src/sys/kern/subr_kobj.c:1.55 --- src/sys/kern/subr_kobj.c:1.54 Fri Jul 8 08:55:48 2016 +++ src/sys/kern/subr_kobj.c Sat Jul 9 07:25:00 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_kobj.c,v 1.54 2016/07/08 08:55:48 maxv Exp $ */ +/* $NetBSD: subr_kobj.c,v 1.55 2016/07/09 07:25:00 maxv Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.54 2016/07/08 08:55:48 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.55 2016/07/09 07:25:00 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_modular.h" @@ -160,8 +160,10 @@ kobj_load(kobj_t ko) Elf_Ehdr *hdr; Elf_Shdr *shdr; Elf_Sym *es; - vaddr_t mapbase; - size_t mapsize; + vaddr_t map_text_base; + vaddr_t map_data_base; + size_t map_text_size; + size_t map_data_size; int error; int symtabindex; int symstrindex; @@ -392,40 +394,54 @@ kobj_load(kobj_t ko) * Size up code/data(progbits) and bss(nobits). */ alignmask = 0; - mapsize = 0; + map_text_size = 0; + map_data_size = 0; for (i = 0; i < hdr->e_shnum; i++) { - switch (shdr[i].sh_type) { - case SHT_PROGBITS: - case SHT_NOBITS: - alignmask = shdr[i].sh_addralign - 1; - mapsize += alignmask; - mapsize &= ~alignmask; - mapsize += shdr[i].sh_size; - break; + if (shdr[i].sh_type != SHT_PROGBITS && + shdr[i].sh_type != SHT_NOBITS) + continue; + alignmask = shdr[i].sh_addralign - 1; + if ((shdr[i].sh_flags & SHF_EXECINSTR)) { + map_text_size += alignmask; + map_text_size &= ~alignmask; + map_text_size += shdr[i].sh_size; + } else { + map_data_size += alignmask; + map_data_size &= ~alignmask; + map_data_size += shdr[i].sh_size; } } - /* - * We know how much space we need for the text/data/bss/etc. - * This stuff needs to be in a single chunk so that profiling etc - * can get the bounds and gdb can associate offsets with modules. - */ - if (mapsize == 0) { - kobj_error(ko, "no text/data/bss"); + if (map_text_size == 0) { + kobj_error(ko, "no text"); + error = ENOEXEC; + goto out; + } + if (map_data_size == 0) { + kobj_error(ko, "no data/bss"); error = ENOEXEC; goto out; } - mapbase = uvm_km_alloc(module_map, round_page(mapsize), + map_text_base = uvm_km_alloc(module_map, round_page(map_text_size), 0, UVM_KMF_WIRED | UVM_KMF_EXEC); - if (mapbase == 0) { + if (map_text_base == 0) { kobj_error(ko, "out of memory"); error = ENOMEM; goto out; } + ko->ko_text_address = map_text_base; + ko->ko_text_size = map_text_size; - ko->ko_address = mapbase; - ko->ko_size = mapsize; + map_data_base = uvm_km_alloc(module_map, round_page(map_data_size), + 0, UVM_KMF_WIRED); + if (map_data_base == 0) { + kobj_error(ko, "out of memory"); + error = ENOMEM; + goto out; + } + ko->ko_data_address = map_data_base; + ko->ko_data_size = map_data_size; /* * Now load code/data(progbits), zero bss(nobits), allocate space @@ -440,10 +456,17 @@ kobj_load(kobj_t ko) case SHT_PROGBITS: case SHT_NOBITS: alignmask = shdr[i].sh_addralign - 1; - mapbase += alignmask; - mapbase &= ~alignmask; - addr = (void *)mapbase; - mapbase += shdr[i].sh_size; + if ((shdr[i].sh_flags & SHF_EXECINSTR)) { +map_text_base += alignmask; +map_text_base &= ~alignmask; +addr = (void *)map_text_base; +map_text_base += shdr[i].sh_size; + } else { +map_data_base += alignmask; +map_data_base &= ~alignmask; +addr = (void *)map_data_base; +map_data_base += shdr[i].sh_size; + } ko->ko_progtab[pb].addr = addr; if (shdr[i].sh_type == SHT_PROGBITS) { @@ -535,12 +558,19 @@ kobj_load(kobj_t ko) panic("%s:%d: %s: lost rela", __func__, __LINE__, ko->ko_name); } - if (mapbase != ko->ko_address + mapsize) { - panic("%s:%d: %s: " - "mapbase 0x%lx != address %lx + mapsize %ld (0x%lx)\n", - __func__, __LINE__, ko->ko_name, - (long)mapbase, (long)ko->ko_address, (long)mapsize, - (long)ko->ko_address + mapsize); + if (map_text_base != ko->ko_text_address + map_text_size) { + panic("%s:%d: %s:
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Sat Jul 9 09:25:44 UTC 2016 Modified Files: src/sys/arch/x86/x86: pmap.c Log Message: Use pmap_bootstrap_palloc. To generate a diff of this commit: cvs rdiff -u -r1.208 -r1.209 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.208 src/sys/arch/x86/x86/pmap.c:1.209 --- src/sys/arch/x86/x86/pmap.c:1.208 Sat Jul 9 08:05:46 2016 +++ src/sys/arch/x86/x86/pmap.c Sat Jul 9 09:25:44 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.208 2016/07/09 08:05:46 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.209 2016/07/09 09:25:44 maxv Exp $ */ /*- * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.208 2016/07/09 08:05:46 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.209 2016/07/09 09:25:44 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -1399,8 +1399,7 @@ pmap_bootstrap(vaddr_t kva_start) * will still consider it active. So we set user PGD to this one to lift * all protection on the now inactive page tables set. */ - xen_dummy_user_pgd = avail_start; - avail_start += PAGE_SIZE; + xen_dummy_user_pgd = pmap_bootstrap_palloc(1); /* Zero fill it, the less checks in Xen it requires the better */ memset((void *) (xen_dummy_user_pgd + KERNBASE), 0, PAGE_SIZE); @@ -1637,8 +1636,8 @@ pmap_prealloc_lowmem_ptps(void) pdes = pmap_kernel()->pm_pdir; level = PTP_LEVELS; for (;;) { - newp = avail_start; - avail_start += PAGE_SIZE; + newp = pmap_bootstrap_palloc(1); + #ifdef __HAVE_DIRECT_MAP memset((void *)PMAP_DIRECT_MAP(newp), 0, PAGE_SIZE); #else
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Sat Jul 9 09:33:21 UTC 2016 Modified Files: src/sys/arch/x86/x86: pmap.c Log Message: Simplify pmap_get_physpage. To generate a diff of this commit: cvs rdiff -u -r1.209 -r1.210 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.209 src/sys/arch/x86/x86/pmap.c:1.210 --- src/sys/arch/x86/x86/pmap.c:1.209 Sat Jul 9 09:25:44 2016 +++ src/sys/arch/x86/x86/pmap.c Sat Jul 9 09:33:21 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.209 2016/07/09 09:25:44 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.210 2016/07/09 09:33:21 maxv Exp $ */ /*- * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.209 2016/07/09 09:25:44 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.210 2016/07/09 09:33:21 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -571,7 +571,7 @@ static bool pmap_remove_pte(struct pmap static void pmap_remove_ptes(struct pmap *, struct vm_page *, vaddr_t, vaddr_t, vaddr_t, struct pv_entry **); -static bool pmap_get_physpage(vaddr_t, int, paddr_t *); +static paddr_t pmap_get_physpage(void); static void pmap_alloc_level(pd_entry_t * const *, vaddr_t, int, long *); static bool pmap_reactivate(struct pmap *); @@ -4241,33 +4241,33 @@ out2: return error; } -static bool -pmap_get_physpage(vaddr_t va, int level, paddr_t *paddrp) +static paddr_t +pmap_get_physpage(void) { struct vm_page *ptp; struct pmap *kpm = pmap_kernel(); + paddr_t pa; if (!uvm.page_init_done) { - /* - * we're growing the kernel pmap early (from - * uvm_pageboot_alloc()). this case must be + * We're growing the kernel pmap early (from + * uvm_pageboot_alloc()). This case must be * handled a little differently. */ - if (!uvm_page_physget(paddrp)) + if (!uvm_page_physget()) panic("pmap_get_physpage: out of memory"); #if defined(__HAVE_DIRECT_MAP) - pagezero(PMAP_DIRECT_MAP(*paddrp)); + pagezero(PMAP_DIRECT_MAP(pa)); #else #if defined(XEN) if (XEN_VERSION_SUPPORTED(3, 4)) { - xen_pagezero(*paddrp); - return true; + xen_pagezero(pa); + return pa; } #endif kpreempt_disable(); - pmap_pte_set(early_zero_pte, pmap_pa2pte(*paddrp) | PG_V | + pmap_pte_set(early_zero_pte, pmap_pa2pte(pa) | PG_V | PG_RW | pmap_pg_nx | PG_k); pmap_pte_flush(); pmap_update_pg((vaddr_t)early_zerop); @@ -4286,10 +4286,11 @@ pmap_get_physpage(vaddr_t va, int level, panic("pmap_get_physpage: out of memory"); ptp->flags &= ~PG_BUSY; ptp->wire_count = 1; - *paddrp = VM_PAGE_TO_PHYS(ptp); + pa = VM_PAGE_TO_PHYS(ptp); } pmap_stats_update(kpm, 1, 0); - return true; + + return pa; } /* @@ -4327,7 +4328,7 @@ pmap_alloc_level(pd_entry_t * const *pde pt_entry_t pte; KASSERT(!pmap_valid_entry(pdep[i])); - pmap_get_physpage(va, level - 1, ); + pa = pmap_get_physpage(); pte = pmap_pa2pte(pa) | PG_k | PG_V | PG_RW; #ifdef XEN pmap_pte_set([i], pte);
CVS commit: src/sys/arch
Module Name:src Committed By: maxv Date: Sat Jul 9 06:58:06 UTC 2016 Modified Files: src/sys/arch/amd64/amd64: locore.S src/sys/arch/i386/i386: locore.S Log Message: The CPU considers a given va as executable if none of its levels have the NOX bit. With the top level recursive slot, however, several levels are recursively omitted, which implies that each entry that is not the child of NOX-ed parents actually appears somewhere in the virtual space as executable via this slot, even if it is followed by an underlying entry that has the NOX bit. This recursive slot is only used to edit the page tree itself. Make it non-executable. To generate a diff of this commit: cvs rdiff -u -r1.105 -r1.106 src/sys/arch/amd64/amd64/locore.S cvs rdiff -u -r1.134 -r1.135 src/sys/arch/i386/i386/locore.S Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/locore.S diff -u src/sys/arch/amd64/amd64/locore.S:1.105 src/sys/arch/amd64/amd64/locore.S:1.106 --- src/sys/arch/amd64/amd64/locore.S:1.105 Fri Jul 8 09:15:38 2016 +++ src/sys/arch/amd64/amd64/locore.S Sat Jul 9 06:58:06 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.105 2016/07/08 09:15:38 maxv Exp $ */ +/* $NetBSD: locore.S,v 1.106 2016/07/09 06:58:06 maxv Exp $ */ /* * Copyright-o-rama! @@ -777,12 +777,12 @@ no_NOX: movl $NKL4_KIMG_ENTRIES,%ecx fillkpt - /* Install recursive top level PDE */ + /* Install recursive top level PDE (one entry) */ leal (PROC0_PML4_OFF + PDIR_SLOT_PTE * PDE_SIZE)(%esi),%ebx leal (PROC0_PML4_OFF)(%esi),%eax orl $(PG_V|PG_KW),%eax - movl %eax,(%ebx) - movl $0,(PDE_SIZE-4)(%ebx) + movl $1,%ecx + fillkpt_nox /* * Startup checklist: Index: src/sys/arch/i386/i386/locore.S diff -u src/sys/arch/i386/i386/locore.S:1.134 src/sys/arch/i386/i386/locore.S:1.135 --- src/sys/arch/i386/i386/locore.S:1.134 Fri Jul 8 09:15:38 2016 +++ src/sys/arch/i386/i386/locore.S Sat Jul 9 06:58:06 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.134 2016/07/08 09:15:38 maxv Exp $ */ +/* $NetBSD: locore.S,v 1.135 2016/07/09 06:58:06 maxv Exp $ */ /* * Copyright-o-rama! @@ -128,7 +128,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.134 2016/07/08 09:15:38 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.135 2016/07/09 06:58:06 maxv Exp $"); #include "opt_compat_oldboot.h" #include "opt_copy_symtab.h" @@ -776,12 +776,12 @@ no_NOX: movl RELOC(nkptp)+1*4,%ecx fillkpt - /* Install a PDE recursively mapping page directory as a page table! */ + /* Install recursive top level PDE */ leal (PROC0_PDIR_OFF + PDIR_SLOT_PTE * PDE_SIZE)(%esi),%ebx leal (PROC0_PDIR_OFF)(%esi),%eax orl $(PG_V|PG_KW),%eax movl $PDP_SIZE,%ecx - fillkpt + fillkpt_nox #ifdef PAE /*
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Sat Jul 9 07:47:25 UTC 2016 Modified Files: src/sys/arch/x86/x86: pmap.c Log Message: KNF this function a little To generate a diff of this commit: cvs rdiff -u -r1.206 -r1.207 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.206 src/sys/arch/x86/x86/pmap.c:1.207 --- src/sys/arch/x86/x86/pmap.c:1.206 Fri Jul 1 12:36:43 2016 +++ src/sys/arch/x86/x86/pmap.c Sat Jul 9 07:47:25 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.206 2016/07/01 12:36:43 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.207 2016/07/09 07:47:25 maxv Exp $ */ /*- * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.206 2016/07/01 12:36:43 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.207 2016/07/09 07:47:25 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -2107,7 +2107,7 @@ pmap_get_ptp(struct pmap *pmap, vaddr_t } /* - * p m a p l i f e c y c l e f u n c t i o n s + * p m a p l i f e c y c l e f u n c t i o n s */ /* @@ -2117,7 +2117,7 @@ static int pmap_pdp_ctor(void *arg, void *v, int flags) { pd_entry_t *pdir = v; - paddr_t pdirpa = 0; /* XXX: GCC */ + paddr_t pdirpa = 0; vaddr_t object; int i; @@ -2133,60 +2133,63 @@ pmap_pdp_ctor(void *arg, void *v, int fl */ #if defined(XEN) && defined(__x86_64__) - /* fetch the physical address of the page directory. */ - (void) pmap_extract(pmap_kernel(), (vaddr_t) pdir, ); + /* Fetch the physical address of the page directory */ + (void)pmap_extract(pmap_kernel(), (vaddr_t)pdir, ); + + /* Zero the area */ + memset(pdir, 0, PAGE_SIZE); /* Xen wants a clean page */ - /* zero init area */ - memset (pdir, 0, PAGE_SIZE); /* Xen wants a clean page */ /* - * this pdir will NEVER be active in kernel mode - * so mark recursive entry invalid + * This pdir will NEVER be active in kernel mode, so mark + * recursive entry invalid. */ pdir[PDIR_SLOT_PTE] = pmap_pa2pte(pdirpa) | PG_u; + /* - * PDP constructed this way won't be for kernel, - * hence we don't put kernel mappings on Xen. - * But we need to make pmap_create() happy, so put a dummy (without - * PG_V) value at the right place. + * PDP constructed this way won't be for the kernel, hence we + * don't put kernel mappings on Xen. + * + * But we need to make pmap_create() happy, so put a dummy + * (without PG_V) value at the right place. */ pdir[PDIR_SLOT_KERN + nkptp[PTP_LEVELS - 1] - 1] = (pd_entry_t)-1 & PG_FRAME; #else /* XEN && __x86_64__*/ - /* zero init area */ + /* Zero the area */ memset(pdir, 0, PDIR_SLOT_PTE * sizeof(pd_entry_t)); object = (vaddr_t)v; for (i = 0; i < PDP_SIZE; i++, object += PAGE_SIZE) { - /* fetch the physical address of the page directory. */ - (void) pmap_extract(pmap_kernel(), object, ); - /* put in recursive PDE to map the PTEs */ + /* Fetch the physical address of the page directory */ + (void)pmap_extract(pmap_kernel(), object, ); + + /* Put in recursive PDE to map the PTEs */ pdir[PDIR_SLOT_PTE + i] = pmap_pa2pte(pdirpa) | PG_V; #ifndef XEN pdir[PDIR_SLOT_PTE + i] |= PG_KW; #endif } - /* copy kernel's PDE */ + /* Copy the kernel's top level PDE */ npde = nkptp[PTP_LEVELS - 1]; memcpy([PDIR_SLOT_KERN], _BASE[PDIR_SLOT_KERN], npde * sizeof(pd_entry_t)); - /* zero the rest */ + /* Zero the rest */ memset([PDIR_SLOT_KERN + npde], 0, (PAGE_SIZE * PDP_SIZE) - (PDIR_SLOT_KERN + npde) * sizeof(pd_entry_t)); if (VM_MIN_KERNEL_ADDRESS != KERNBASE) { int idx = pl_i(KERNBASE, PTP_LEVELS); - pdir[idx] = PDP_BASE[idx]; } #ifdef __HAVE_DIRECT_MAP pdir[PDIR_SLOT_DIRECT] = PDP_BASE[PDIR_SLOT_DIRECT]; #endif - #endif /* XEN && __x86_64__*/ + #ifdef XEN s = splvm(); object = (vaddr_t)v;
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Mon Jul 11 14:18:16 UTC 2016 Modified Files: src/sys/arch/x86/x86: pmap.c Log Message: KNF and simplify a little. To generate a diff of this commit: cvs rdiff -u -r1.210 -r1.211 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.210 src/sys/arch/x86/x86/pmap.c:1.211 --- src/sys/arch/x86/x86/pmap.c:1.210 Sat Jul 9 09:33:21 2016 +++ src/sys/arch/x86/x86/pmap.c Mon Jul 11 14:18:16 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.210 2016/07/09 09:33:21 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.211 2016/07/11 14:18:16 maxv Exp $ */ /*- * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.210 2016/07/09 09:33:21 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.211 2016/07/11 14:18:16 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -1656,7 +1656,6 @@ pmap_prealloc_lowmem_ptps(void) HYPERVISOR_update_va_mapping (newp + KERNBASE, xpmap_ptom_masked(newp) | PG_u | PG_V, UVMF_INVLPG); - if (level == PTP_LEVELS) { /* Top level pde is per-cpu */ pd_entry_t *kpm_pdir; /* Reach it via recursive mapping */ @@ -4305,7 +4304,6 @@ pmap_alloc_level(pd_entry_t * const *pde long *needed_ptps) { unsigned long i; - vaddr_t va; paddr_t pa; unsigned long index, endindex; int level; @@ -4319,20 +4317,18 @@ pmap_alloc_level(pd_entry_t * const *pde pdep = pmap_kernel()->pm_pdir; else pdep = pdes[level - 2]; - va = kva; index = pl_i_roundup(kva, level); endindex = index + needed_ptps[level - 1] - 1; - for (i = index; i <= endindex; i++) { pt_entry_t pte; KASSERT(!pmap_valid_entry(pdep[i])); pa = pmap_get_physpage(); pte = pmap_pa2pte(pa) | PG_k | PG_V | PG_RW; -#ifdef XEN pmap_pte_set([i], pte); -#if defined(PAE) || defined(__x86_64__) + +#if defined(XEN) && (defined(PAE) || defined(__x86_64__)) if (level == PTP_LEVELS && i >= PDIR_SLOT_KERN) { if (__predict_true( cpu_info_primary.ci_flags & CPUF_PRESENT)) { @@ -4354,14 +4350,11 @@ pmap_alloc_level(pd_entry_t * const *pde pmap_pte_set(cpu_pdep, pte); } } -#endif /* PAE || __x86_64__ */ -#else /* XEN */ - pdep[i] = pte; -#endif /* XEN */ +#endif /* XEN && (PAE || __x86_64__) */ + KASSERT(level != PTP_LEVELS || nkptp[level - 1] + pl_i(VM_MIN_KERNEL_ADDRESS, level) == i); nkptp[level - 1]++; - va += nbpd[level - 1]; } pmap_pte_flush(); } @@ -4403,16 +4396,11 @@ pmap_growkernel(vaddr_t maxkvaddr) old = nkptp[PTP_LEVELS - 1]; #endif - /* - * This loop could be optimized more, but pmap_growkernel() - * is called infrequently. - */ + /* Initialize needed_kptp. */ for (i = PTP_LEVELS - 1; i >= 1; i--) { target_nptp = pl_i_roundup(maxkvaddr, i + 1) - pl_i_roundup(VM_MIN_KERNEL_ADDRESS, i + 1); - /* - * XXX only need to check toplevel. - */ + if (target_nptp > nkptpmax[i]) panic("out of KVA space"); KASSERT(target_nptp >= nkptp[i]); @@ -4422,8 +4410,7 @@ pmap_growkernel(vaddr_t maxkvaddr) pmap_alloc_level(normal_pdes, pmap_maxkvaddr, PTP_LEVELS, needed_kptp); /* - * If the number of top level entries changed, update all - * pmaps. + * If the number of top level entries changed, update all pmaps. */ if (needed_kptp[PTP_LEVELS - 1] != 0) { #ifdef XEN @@ -4433,7 +4420,7 @@ pmap_growkernel(vaddr_t maxkvaddr) mutex_enter(_lock); LIST_FOREACH(pm, , pm_list) { int pdkidx; - for (pdkidx = PDIR_SLOT_KERN + old; + for (pdkidx = PDIR_SLOT_KERN + old; pdkidx < PDIR_SLOT_KERN + nkptp[PTP_LEVELS - 1]; pdkidx++) { pmap_pte_set(>pm_pdir[pdkidx], @@ -4449,8 +4436,8 @@ pmap_growkernel(vaddr_t maxkvaddr) mutex_enter(_lock); LIST_FOREACH(pm, , pm_list) { memcpy(>pm_pdir[PDIR_SLOT_KERN + old], - >pm_pdir[PDIR_SLOT_KERN + old], - newpdes * sizeof (pd_entry_t)); + >pm_pdir[PDIR_SLOT_KERN + old], + newpdes * sizeof (pd_entry_t)); } mutex_exit(_lock); #endif
CVS commit: src/sys/arch/amd64/amd64
Module Name:src Committed By: maxv Date: Mon Jul 11 14:52:54 UTC 2016 Modified Files: src/sys/arch/amd64/amd64: locore.S Log Message: KNF and simplify. To generate a diff of this commit: cvs rdiff -u -r1.106 -r1.107 src/sys/arch/amd64/amd64/locore.S Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/locore.S diff -u src/sys/arch/amd64/amd64/locore.S:1.106 src/sys/arch/amd64/amd64/locore.S:1.107 --- src/sys/arch/amd64/amd64/locore.S:1.106 Sat Jul 9 06:58:06 2016 +++ src/sys/arch/amd64/amd64/locore.S Mon Jul 11 14:52:54 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.106 2016/07/09 06:58:06 maxv Exp $ */ +/* $NetBSD: locore.S,v 1.107 2016/07/11 14:52:54 maxv Exp $ */ /* * Copyright-o-rama! @@ -985,10 +985,9 @@ longmode_hi: movq %rsi,%rdi addq $USPACE,%rdi subq $KERNBASE,%rdi /* init_x86_64 wants a physical address */ - #endif /* XEN */ - call _C_LABEL(init_x86_64) + call _C_LABEL(init_x86_64) call _C_LABEL(main) END(start) @@ -1175,9 +1174,10 @@ skip_CR0: /* The 32bit LWPs are handled differently. */ testl $PCB_COMPAT32,PCB_FLAGS(%r14) - jne 32f + jne lwp_64bit - /* Zero out %fs/%gs registers and GDT descriptors. */ +lwp_32bit: + /* Zero out %fs/%gs registers. */ xorq %rax,%rax movw %ax,%fs CLI(cx) @@ -1186,6 +1186,7 @@ skip_CR0: SWAPGS STI(cx) + /* Zero out GDT descriptors. */ movq CPUVAR(GDT),%rcx movq %rax,(GUFS_SEL*8)(%rcx) movq %rax,(GUGS_SEL*8)(%rcx) @@ -1199,9 +1200,10 @@ skip_CR0: movl PCB_GS(%r14),%eax movl 4+PCB_GS(%r14),%edx wrmsr + jmp switch_return -32: +lwp_64bit: /* Reload %fs/%gs GDT descriptors. */ movq CPUVAR(GDT),%rcx movq PCB_FS(%r14),%rax @@ -1259,14 +1261,16 @@ IDTVEC_END(syscall32) IDTVEC(syscall) #ifndef XEN /* - * The user %rip is in %rcx and the user %flags in %r11. - * The kernel %cs and %ss are loaded, but nothing else is. - * The 'swapgs' gives us access to cpu-specific memory where - * we can save a user register and then read the lwps - * kernel stack pointer, - * This code doesn't seem to set %ds, this may not matter since it - * is ignored in 64bit mode, OTOH the syscall instruction sets %ss - * and that is ignored as well. + * The user %rip is in %rcx and the user %flags in %r11. The kernel %cs + * and %ss are loaded, but nothing else is. + * + * The 'swapgs' instruction gives us access to cpu-specific memory where + * we can save a user register and then read the LWP's kernel stack + * pointer. + * + * This code doesn't seem to set %ds, this may not matter since it is + * ignored in 64bit mode, OTOH the syscall instruction sets %ss and that + * is ignored as well. */ swapgs movq %r15,CPUVAR(SCRATCH) @@ -1276,19 +1280,19 @@ IDTVEC(syscall) /* Make stack look like an 'int nn' frame */ #define SP(x) (x)-(TF_SS+8)(%r15) - movq $(LSEL(LUDATA_SEL, SEL_UPL)), SP(TF_SS) /* user %ss */ - movq %rsp, SP(TF_RSP) /* User space rsp */ + movq $(LSEL(LUDATA_SEL, SEL_UPL)),SP(TF_SS) /* user %ss */ + movq %rsp,SP(TF_RSP) /* User space rsp */ - movq %r11, SP(TF_RFLAGS) /* old rflags from syscall insn */ - movq $(LSEL(LUCODE_SEL, SEL_UPL)), SP(TF_CS) - movq %rcx, SP(TF_RIP) /* syscall saves rip in rcx */ + movq %r11,SP(TF_RFLAGS) /* old rflags from syscall insn */ + movq $(LSEL(LUCODE_SEL, SEL_UPL)),SP(TF_CS) + movq %rcx,SP(TF_RIP) /* syscall saves rip in rcx */ leaq SP(0),%rsp /* %rsp now valid after frame */ movq CPUVAR(SCRATCH),%r15 #undef SP movq $2,TF_ERR(%rsp) /* syscall instruction size */ - movq $T_ASTFLT, TF_TRAPNO(%rsp) + movq $T_ASTFLT,TF_TRAPNO(%rsp) movw %es,TF_ES(%rsp) sti @@ -1328,27 +1332,29 @@ do_syscall: */ CLI(si) /* Check for ASTs on exit to user mode. */ - movl L_MD_ASTPENDING(%r14), %eax - orl CPUVAR(WANT_PMAPLOAD), %eax + movl L_MD_ASTPENDING(%r14),%eax + orl CPUVAR(WANT_PMAPLOAD),%eax jnz 9f + #ifdef DIAGNOSTIC cmpl $IPL_NONE,CPUVAR(ILEVEL) - jne 3f + jne spl_error #endif - testl $(MDL_IRET | MDL_COMPAT32), L_MD_FLAGS(%r14) + + testl $(MDL_IRET|MDL_COMPAT32),L_MD_FLAGS(%r14) INTR_RESTORE_GPRS movw TF_ES(%rsp),%es SWAPGS jnz 2f #ifndef XEN - movq TF_RIP(%rsp), %rcx /* %rip for sysret */ - movq TF_RFLAGS(%rsp), %r11 /* %flags for sysret */ - movw TF_DS(%rsp), %ds - movq TF_RSP(%rsp), %rsp + movq TF_RIP(%rsp),%rcx /* %rip for sysret */ + movq TF_RFLAGS(%rsp),%r11 /* %flags for sysret */ + movw TF_DS(%rsp),%ds + movq TF_RSP(%rsp),%rsp sysretq #else - movw TF_DS(%rsp), %ds - addq $TF_RIP, %rsp + movw TF_DS(%rsp),%ds + addq $TF_RIP,%rsp pushq $256 /* VGCF_IN_SYSCALL */ jmp HYPERVISOR_iret #endif @@ -1360,13 +1366,14 @@ do_syscall: * then a SIGSEGV will be signalled. */ 2: - movw TF_DS(%rsp), %ds - addq $TF_RIP, %rsp + movw TF_DS(%rsp),%ds + addq $TF_RIP,%rsp iretq -/* Report SPL error */ #ifdef DIAGNOSTIC -3: movabsq $4f, %rdi + /* Report SPL error */ +spl_error: + movabsq $4f,%rdi
CVS commit: src/sys/kern
Module Name:src Committed By: maxv Date: Fri Jul 8 08:55:48 UTC 2016 Modified Files: src/sys/kern: subr_kobj.c Log Message: Force the kernel to dynamically reallocate the preloaded modules. To generate a diff of this commit: cvs rdiff -u -r1.53 -r1.54 src/sys/kern/subr_kobj.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/subr_kobj.c diff -u src/sys/kern/subr_kobj.c:1.53 src/sys/kern/subr_kobj.c:1.54 --- src/sys/kern/subr_kobj.c:1.53 Thu Jul 7 06:55:43 2016 +++ src/sys/kern/subr_kobj.c Fri Jul 8 08:55:48 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_kobj.c,v 1.53 2016/07/07 06:55:43 msaitoh Exp $ */ +/* $NetBSD: subr_kobj.c,v 1.54 2016/07/08 08:55:48 maxv Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.53 2016/07/07 06:55:43 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.54 2016/07/08 08:55:48 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_modular.h" @@ -392,14 +392,11 @@ kobj_load(kobj_t ko) * Size up code/data(progbits) and bss(nobits). */ alignmask = 0; - mapbase = 0; mapsize = 0; for (i = 0; i < hdr->e_shnum; i++) { switch (shdr[i].sh_type) { case SHT_PROGBITS: case SHT_NOBITS: - if (mapbase == 0) -mapbase = shdr[i].sh_offset; alignmask = shdr[i].sh_addralign - 1; mapsize += alignmask; mapsize &= ~alignmask; @@ -416,19 +413,17 @@ kobj_load(kobj_t ko) if (mapsize == 0) { kobj_error(ko, "no text/data/bss"); error = ENOEXEC; + goto out; + } + + mapbase = uvm_km_alloc(module_map, round_page(mapsize), + 0, UVM_KMF_WIRED | UVM_KMF_EXEC); + if (mapbase == 0) { + kobj_error(ko, "out of memory"); + error = ENOMEM; goto out; } - if (ko->ko_type == KT_MEMORY) { - mapbase += (vaddr_t)ko->ko_source; - } else { - mapbase = uvm_km_alloc(module_map, round_page(mapsize), - 0, UVM_KMF_WIRED | UVM_KMF_EXEC); - if (mapbase == 0) { - kobj_error(ko, "out of memory"); - error = ENOMEM; - goto out; - } - } + ko->ko_address = mapbase; ko->ko_size = mapsize; @@ -445,21 +440,11 @@ kobj_load(kobj_t ko) case SHT_PROGBITS: case SHT_NOBITS: alignmask = shdr[i].sh_addralign - 1; - if (ko->ko_type == KT_MEMORY) { -addr = (void *)(shdr[i].sh_offset + -(vaddr_t)ko->ko_source); -if (((vaddr_t)addr & alignmask) != 0) { - kobj_error(ko, - "section %d not aligned", i); - error = ENOEXEC; - goto out; -} - } else { -mapbase += alignmask; -mapbase &= ~alignmask; -addr = (void *)mapbase; -mapbase += shdr[i].sh_size; - } + mapbase += alignmask; + mapbase &= ~alignmask; + addr = (void *)mapbase; + mapbase += shdr[i].sh_size; + ko->ko_progtab[pb].addr = addr; if (shdr[i].sh_type == SHT_PROGBITS) { ko->ko_progtab[pb].name = "<>"; @@ -469,16 +454,11 @@ kobj_load(kobj_t ko) kobj_error(ko, "read failed %d", error); goto out; } - } else if (ko->ko_type == KT_MEMORY && - shdr[i].sh_size != 0) { -kobj_error(ko, "non-loadable BSS " -"section in pre-loaded module"); -error = ENOEXEC; -goto out; - } else { + } else { /* SHT_NOBITS */ ko->ko_progtab[pb].name = "<>"; memset(addr, 0, shdr[i].sh_size); } + ko->ko_progtab[pb].size = shdr[i].sh_size; ko->ko_progtab[pb].sec = i; if (ko->ko_shstrtab != NULL && shdr[i].sh_name != 0) { @@ -555,7 +535,7 @@ kobj_load(kobj_t ko) panic("%s:%d: %s: lost rela", __func__, __LINE__, ko->ko_name); } - if (ko->ko_type != KT_MEMORY && mapbase != ko->ko_address + mapsize) { + if (mapbase != ko->ko_address + mapsize) { panic("%s:%d: %s: " "mapbase 0x%lx != address %lx + mapsize %ld (0x%lx)\n", __func__, __LINE__, ko->ko_name, @@ -606,7 +586,7 @@ kobj_unload(kobj_t ko) kobj_error(ko, "machine dependent deinit failed %d", error); } - if (ko->ko_address != 0 && ko->ko_type != KT_MEMORY) { + if (ko->ko_address != 0) { uvm_km_free(module_map, ko->ko_address, round_page(ko->ko_size), UVM_KMF_WIRED); } @@ -1023,23 +1003,29 @@ kobj_read_mem(kobj_t ko, void **basep, s void *base = *basep; int error; + KASSERT(ko->ko_source != NULL); + if (ko->ko_memsize != -1 && off + size > ko->ko_memsize) { kobj_error(ko, "preloaded object short"); error = EINVAL; base = NULL; } else if (allocate) { - base = (uint8_t *)ko->ko_source + off; + base = kmem_alloc(size, KM_SLEEP); error = 0; - } else if ((uint8_t *)base != (uint8_t *)ko->ko_source + off) { - kobj_error(ko, "object not aligned"); - kobj_error(ko, "source=%p base=%p off=%d " - "size=%zu", ko->ko_source, base, (int)off, size); - error = EINVAL; } else { - /* Nothing to do. Loading in-situ. */ error = 0; } + if (error == 0) { + /* Copy the section */ + memcpy(base, (uint8_t *)ko->ko_source + off, size); + } + +
CVS commit: src/sys/arch
Module Name:src Committed By: maxv Date: Fri Jul 8 09:15:38 UTC 2016 Modified Files: src/sys/arch/amd64/amd64: locore.S src/sys/arch/i386/i386: locore.S Log Message: The preloaded modules are now reallocated dynamically by the kernel. This area does not need to be executable anymore. To generate a diff of this commit: cvs rdiff -u -r1.104 -r1.105 src/sys/arch/amd64/amd64/locore.S cvs rdiff -u -r1.133 -r1.134 src/sys/arch/i386/i386/locore.S Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/locore.S diff -u src/sys/arch/amd64/amd64/locore.S:1.104 src/sys/arch/amd64/amd64/locore.S:1.105 --- src/sys/arch/amd64/amd64/locore.S:1.104 Mon Jul 4 07:56:07 2016 +++ src/sys/arch/amd64/amd64/locore.S Fri Jul 8 09:15:38 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.104 2016/07/04 07:56:07 maxv Exp $ */ +/* $NetBSD: locore.S,v 1.105 2016/07/08 09:15:38 maxv Exp $ */ /* * Copyright-o-rama! @@ -703,13 +703,13 @@ no_NOX: orl $(PG_V|PG_KW),%eax fillkpt_nox - /* Map [SYMS]+[PRELOADED MODULES] RWX. */ + /* Map [SYMS]+[PRELOADED MODULES] RW. */ movl $RELOC(__kernel_end),%eax movl %esi,%ecx /* start of BOOTSTRAP TABLES */ subl %eax,%ecx shrl $PGSHIFT,%ecx orl $(PG_V|PG_KW),%eax - fillkpt + fillkpt_nox /* Map the BOOTSTRAP TABLES RW. */ movl %esi,%eax /* start of BOOTSTRAP TABLES */ Index: src/sys/arch/i386/i386/locore.S diff -u src/sys/arch/i386/i386/locore.S:1.133 src/sys/arch/i386/i386/locore.S:1.134 --- src/sys/arch/i386/i386/locore.S:1.133 Mon Jul 4 07:56:07 2016 +++ src/sys/arch/i386/i386/locore.S Fri Jul 8 09:15:38 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.133 2016/07/04 07:56:07 maxv Exp $ */ +/* $NetBSD: locore.S,v 1.134 2016/07/08 09:15:38 maxv Exp $ */ /* * Copyright-o-rama! @@ -128,7 +128,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.133 2016/07/04 07:56:07 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.134 2016/07/08 09:15:38 maxv Exp $"); #include "opt_compat_oldboot.h" #include "opt_copy_symtab.h" @@ -738,13 +738,13 @@ no_NOX: orl $(PG_V|PG_KW),%eax fillkpt_nox - /* Map [SYMS]+[PRELOADED MODULES] RWX. */ + /* Map [SYMS]+[PRELOADED MODULES] RW. */ movl $RELOC(__kernel_end),%eax movl %esi,%ecx /* start of BOOTSTRAP TABLES */ subl %eax,%ecx shrl $PGSHIFT,%ecx orl $(PG_V|PG_KW),%eax - fillkpt + fillkpt_nox /* Map the BOOTSTRAP TABLES RW. */ movl %esi,%eax /* start of BOOTSTRAP TABLES */
CVS commit: src/sys/arch/amd64/amd64
Module Name:src Committed By: maxv Date: Sun Aug 7 09:04:55 UTC 2016 Modified Files: src/sys/arch/amd64/amd64: amd64_trap.S Log Message: Explain a little. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/arch/amd64/amd64/amd64_trap.S Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/amd64_trap.S diff -u src/sys/arch/amd64/amd64/amd64_trap.S:1.3 src/sys/arch/amd64/amd64/amd64_trap.S:1.4 --- src/sys/arch/amd64/amd64/amd64_trap.S:1.3 Sun Nov 22 13:41:24 2015 +++ src/sys/arch/amd64/amd64/amd64_trap.S Sun Aug 7 09:04:55 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: amd64_trap.S,v 1.3 2015/11/22 13:41:24 maxv Exp $ */ +/* $NetBSD: amd64_trap.S,v 1.4 2016/08/07 09:04:55 maxv Exp $ */ /*- * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc. @@ -66,7 +66,7 @@ #if 0 #include -__KERNEL_RCSID(0, "$NetBSD: amd64_trap.S,v 1.3 2015/11/22 13:41:24 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: amd64_trap.S,v 1.4 2016/08/07 09:04:55 maxv Exp $"); #endif /* @@ -229,28 +229,36 @@ IDTVEC_END(trap0a) IDTVEC(trap0b) /* #NP() Segment not present */ TRAP_NJ(T_SEGNPFLT) jmp check_swapgs -IDTVEC_END(trap0b) /* #NP() Segment not present */ +IDTVEC_END(trap0b) IDTVEC(trap0c) /* #SS() Stack exception */ TRAP_NJ(T_STKFLT) jmp check_swapgs -IDTVEC_END(trap0c) /* #SS() Stack exception */ +IDTVEC_END(trap0c) IDTVEC(trap0d) /* #GP() General protection */ TRAP_NJ(T_PROTFLT) #ifdef check_swapgs jmp check_swapgs #else -/* We need to worry about traps while the kernel %gs_base isn't loaded. - * These are either loads to %gs (only 32bit) or faults on iret during - * return to user. */ +/* + * We need to worry about traps in kernel mode while the kernel %gs isn't + * loaded. These are either faults on iretq during return to user or loads to + * %gs. + * + * When such traps happen, we have CPL=0 and %gs=userland, and we must perform + * an additional swapgs to get %gs=kernel. + */ check_swapgs: INTRENTRY_L(3f,1:) -2: sti +2: + sti jmp calltrap 3: - /* Trap in kernel mode. */ - /* If faulting instruction is 'iret' we may need to do a 'swapgs'. */ + /* + * Trap in kernel mode. + */ + /* Case 1: fault on iretq? */ movq TF_RIP(%rsp),%rax cmpw $0xcf48,(%rax) /* Faulting instruction is iretq ? */ jne 5f /* Jump if not */ @@ -259,7 +267,8 @@ check_swapgs: je 2b /* jump if iret was to kernel */ jmp 1b /* to user - must restore %gs */ 5: - /* Not 'iret', all moves to %gs also need a swapgs */ + + /* Case 2: move to %gs? */ movw (%rax),%ax andb $070,%ah /* mask mod/rm from mod/reg/rm */ cmpw $0x8e+050*256,%ax /* Any move to %gs (reg 5) */
CVS commit: src/sys
Module Name:src Committed By: maxv Date: Sat Aug 6 15:13:14 UTC 2016 Modified Files: src/sys/compat/linux32/common: linux32_exec_elf32.c src/sys/compat/netbsd32: netbsd32_exec_aout.c netbsd32_exec_elf32.c src/sys/kern: kern_exec.c src/sys/sys: exec.h src/sys/uvm: uvm_map.c Log Message: The way the kernel tries to prevent a userland process from allocating page zero is hugely flawed. It is easy to demonstrate that one can trick UVM into chosing a NULL hint after the user_va0_disable check from uvm_map. Such a bypass allows kernel NULL pointer dereferences to be exploitable on architectures with a shared userland<->kernel VA, like amd64. Fix this by increasing the limit of the vm space made available for userland processes. This way, UVM will never chose a NULL hint, since it would be outside of the vm space. The user_va0_disable sysctl still controls this feature. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/sys/compat/linux32/common/linux32_exec_elf32.c cvs rdiff -u -r1.29 -r1.30 src/sys/compat/netbsd32/netbsd32_exec_aout.c cvs rdiff -u -r1.39 -r1.40 src/sys/compat/netbsd32/netbsd32_exec_elf32.c cvs rdiff -u -r1.435 -r1.436 src/sys/kern/kern_exec.c cvs rdiff -u -r1.150 -r1.151 src/sys/sys/exec.h cvs rdiff -u -r1.340 -r1.341 src/sys/uvm/uvm_map.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/compat/linux32/common/linux32_exec_elf32.c diff -u src/sys/compat/linux32/common/linux32_exec_elf32.c:1.18 src/sys/compat/linux32/common/linux32_exec_elf32.c:1.19 --- src/sys/compat/linux32/common/linux32_exec_elf32.c:1.18 Fri Mar 20 20:36:27 2015 +++ src/sys/compat/linux32/common/linux32_exec_elf32.c Sat Aug 6 15:13:13 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: linux32_exec_elf32.c,v 1.18 2015/03/20 20:36:27 maxv Exp $ */ +/* $NetBSD: linux32_exec_elf32.c,v 1.19 2016/08/06 15:13:13 maxv Exp $ */ /*- * Copyright (c) 1995, 1998, 2000, 2001,2006 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: linux32_exec_elf32.c,v 1.18 2015/03/20 20:36:27 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux32_exec_elf32.c,v 1.19 2016/08/06 15:13:13 maxv Exp $"); #define ELFSIZE 32 @@ -93,7 +93,7 @@ ELFNAME2(linux32,probe)(struct lwp *l, s #endif epp->ep_flags |= EXEC_32 | EXEC_FORCEAUX; - epp->ep_vm_minaddr = VM_MIN_ADDRESS; + epp->ep_vm_minaddr = exec_vm_minaddr(VM_MIN_ADDRESS); epp->ep_vm_maxaddr = USRSTACK32; return 0; Index: src/sys/compat/netbsd32/netbsd32_exec_aout.c diff -u src/sys/compat/netbsd32/netbsd32_exec_aout.c:1.29 src/sys/compat/netbsd32/netbsd32_exec_aout.c:1.30 --- src/sys/compat/netbsd32/netbsd32_exec_aout.c:1.29 Fri Dec 5 22:21:47 2014 +++ src/sys/compat/netbsd32/netbsd32_exec_aout.c Sat Aug 6 15:13:13 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_exec_aout.c,v 1.29 2014/12/05 22:21:47 christos Exp $ */ +/* $NetBSD: netbsd32_exec_aout.c,v 1.30 2016/08/06 15:13:13 maxv Exp $ */ /* from: NetBSD: exec_aout.c,v 1.15 1996/09/26 23:34:46 cgd Exp */ /* @@ -57,7 +57,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: netbsd32_exec_aout.c,v 1.29 2014/12/05 22:21:47 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_exec_aout.c,v 1.30 2016/08/06 15:13:13 maxv Exp $"); #include #include @@ -164,7 +164,7 @@ netbsd32_exec_aout_prep_zmagic(struct lw epp->ep_daddr = epp->ep_taddr + execp->a_text; epp->ep_dsize = execp->a_data + execp->a_bss; epp->ep_entry = execp->a_entry; - epp->ep_vm_minaddr = VM_MIN_ADDRESS; + epp->ep_vm_minaddr = exec_vm_minaddr(VM_MIN_ADDRESS); epp->ep_vm_maxaddr = VM_MAXUSER_ADDRESS32; error = vn_marktext(epp->ep_vp); @@ -205,7 +205,7 @@ netbsd32_exec_aout_prep_nmagic(struct lw epp->ep_daddr = roundup(epp->ep_taddr + execp->a_text, AOUT_LDPGSZ); epp->ep_dsize = execp->a_data + execp->a_bss; epp->ep_entry = execp->a_entry; - epp->ep_vm_minaddr = VM_MIN_ADDRESS; + epp->ep_vm_minaddr = exec_vm_minaddr(VM_MIN_ADDRESS); epp->ep_vm_maxaddr = VM_MAXUSER_ADDRESS32; /* set up command for text segment */ @@ -244,7 +244,7 @@ netbsd32_exec_aout_prep_omagic(struct lw epp->ep_daddr = epp->ep_taddr + execp->a_text; epp->ep_dsize = execp->a_data + execp->a_bss; epp->ep_entry = execp->a_entry; - epp->ep_vm_minaddr = VM_MIN_ADDRESS; + epp->ep_vm_minaddr = exec_vm_minaddr(VM_MIN_ADDRESS); epp->ep_vm_maxaddr = VM_MAXUSER_ADDRESS32; /* set up command for text and data segments */ @@ -294,7 +294,7 @@ netbsd32_exec_aout_prep_oldzmagic(struct epp->ep_daddr = epp->ep_taddr + execp->a_text; epp->ep_dsize = execp->a_data + execp->a_bss; epp->ep_entry = execp->a_entry; - epp->ep_vm_minaddr = VM_MIN_ADDRESS; + epp->ep_vm_minaddr = exec_vm_minaddr(VM_MIN_ADDRESS); epp->ep_vm_maxaddr = VM_MAXUSER_ADDRESS32; error = vn_marktext(epp->ep_vp); @@ -342,7 +342,7 @@ netbsd32_exec_aout_prep_oldnmagic(struct epp->ep_daddr =
CVS commit: src/sys/arch/i386/acpi
Module Name:src Committed By: maxv Date: Sat Aug 6 14:54:25 UTC 2016 Modified Files: src/sys/arch/i386/acpi: acpi_wakeup_low.S Log Message: Use the stack to save %edx. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sys/arch/i386/acpi/acpi_wakeup_low.S Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/i386/acpi/acpi_wakeup_low.S diff -u src/sys/arch/i386/acpi/acpi_wakeup_low.S:1.7 src/sys/arch/i386/acpi/acpi_wakeup_low.S:1.8 --- src/sys/arch/i386/acpi/acpi_wakeup_low.S:1.7 Sun Jul 24 14:09:22 2016 +++ src/sys/arch/i386/acpi/acpi_wakeup_low.S Sat Aug 6 14:54:25 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_wakeup_low.S,v 1.7 2016/07/24 14:09:22 maxv Exp $ */ +/* $NetBSD: acpi_wakeup_low.S,v 1.8 2016/08/06 14:54:25 maxv Exp $ */ /*- * Copyright (c) 2007 Joerg Sonnenberger@@ -29,7 +29,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: acpi_wakeup_low.S,v 1.7 2016/07/24 14:09:22 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_wakeup_low.S,v 1.8 2016/08/06 14:54:25 maxv Exp $"); #include "assym.h" #include @@ -105,8 +105,9 @@ acpi_md_sleep_prepare: movl %esp,ACPI_SUSPEND_REG+(4*4)(%edx) movl $MSR_EFER,%ecx - rdmsr - movl CPUVAR(SELF),%edx + pushl %edx + rdmsr /* overwrites %edx */ + popl %edx movl %eax,ACPI_SUSPEND_EFER(%edx) movl %cr0,%eax
CVS commit: src/sys/arch
Module Name:src Committed By: maxv Date: Sun Aug 7 10:17:32 UTC 2016 Modified Files: src/sys/arch/amd64/amd64: vector.S src/sys/arch/i386/i386: vector.S Log Message: KNF a little. To generate a diff of this commit: cvs rdiff -u -r1.45 -r1.46 src/sys/arch/amd64/amd64/vector.S cvs rdiff -u -r1.64 -r1.65 src/sys/arch/i386/i386/vector.S Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/vector.S diff -u src/sys/arch/amd64/amd64/vector.S:1.45 src/sys/arch/amd64/amd64/vector.S:1.46 --- src/sys/arch/amd64/amd64/vector.S:1.45 Sun Nov 22 13:41:24 2015 +++ src/sys/arch/amd64/amd64/vector.S Sun Aug 7 10:17:32 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: vector.S,v 1.45 2015/11/22 13:41:24 maxv Exp $ */ +/* $NetBSD: vector.S,v 1.46 2016/08/07 10:17:32 maxv Exp $ */ /*- * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc. @@ -107,7 +107,6 @@ * If the interrupt frame is made more flexible, INTR can push %eax first and * decide the ipending case with less overhead, e.g., by avoiding loading the * segment registers. - * */ /* XXX See comment in locore.s */ @@ -121,16 +120,16 @@ #ifdef MULTIPROCESSOR IDTVEC(recurse_lapic_ipi) INTR_RECURSE_HWFRAME - pushq $0 + pushq $0 pushq $T_ASTFLT - INTRENTRY + INTRENTRY jmp 1f IDTVEC_END(recurse_lapic_ipi) IDTVEC(intr_lapic_ipi) - pushq $0 + pushq $0 pushq $T_ASTFLT - INTRENTRY + INTRENTRY movl $0,_C_LABEL(local_apic)+LAPIC_EOI movl CPUVAR(ILEVEL),%ebx cmpl $IPL_HIGH,%ebx @@ -166,22 +165,22 @@ IDTVEC(intrddb) IDTVEC_END(intrddb) #endif /* DDB */ #endif /* MULTIPROCESSOR */ - + /* * Interrupt from the local APIC timer. */ IDTVEC(recurse_lapic_ltimer) INTR_RECURSE_HWFRAME - pushq $0 + pushq $0 pushq $T_ASTFLT - INTRENTRY + INTRENTRY jmp 1f IDTVEC_END(recurse_lapic_ltimer) IDTVEC(intr_lapic_ltimer) - pushq $0 + pushq $0 pushq $T_ASTFLT - INTRENTRY + INTRENTRY movl $0,_C_LABEL(local_apic)+LAPIC_EOI movl CPUVAR(ILEVEL),%ebx cmpl $IPL_CLOCK,%ebx @@ -211,7 +210,7 @@ IDTVEC(intr_lapic_tlb) pushq $0 pushq $T_ASTFLT INTRENTRY - movl $0, _C_LABEL(local_apic)+LAPIC_EOI + movl $0,_C_LABEL(local_apic)+LAPIC_EOI callq _C_LABEL(pmap_tlb_intr) INTRFASTEXIT IDTVEC_END(intr_lapic_tlb) @@ -236,14 +235,14 @@ IDTVEC(recurse_ ## name ## num) ;\ IDTVEC(resume_ ## name ## num) \ movq $IREENT_MAGIC,TF_ERR(%rsp);\ movl %ebx,%r13d ;\ - movq CPUVAR(ISOURCES) + (num) * 8, %r14 ;\ + movq CPUVAR(ISOURCES) + (num) * 8,%r14 ;\ movl IS_MAXLEVEL(%r14),%ebx ;\ jmp 1f ;\ IDTVEC(intr_ ## name ## num) ;\ pushq $0 /* dummy error code */ ;\ pushq $T_ASTFLT /* trap # for doing ASTs */ ;\ INTRENTRY ;\ - movq CPUVAR(ISOURCES) + (num) * 8, %r14 ;\ + movq CPUVAR(ISOURCES) + (num) * 8,%r14 ;\ mask(num) /* mask it in hardware */ ;\ early_ack(num) /* and allow other intrs */ ;\ testq %r14,%r14 ;\ @@ -279,14 +278,14 @@ IDTVEC(intr_ ## name ## num) ;\ jmp _C_LABEL(Xdoreti) /* lower spl and do ASTs */ ;\ 7: \ cli;\ - orl $(1 << num),CPUVAR(IPENDING);\ + orl $(1 << num),CPUVAR(IPENDING);\ level_mask(num) ;\ late_ack(num) ;\ sti;\ jmp _C_LABEL(Xdoreti) /* lower spl and do ASTs */ ;\ 10: \ cli;\ - orl $(1 << num),CPUVAR(IPENDING);\ + orl $(1 << num),CPUVAR(IPENDING);\ level_mask(num) ;\ late_ack(num) ;\ INTRFASTEXIT ;\ @@ -581,39 +580,39 @@ END(ioapic_level_stubs) /* Resume/recurse procedures for spl() */ #define XENINTRSTUB(name, num, early_ack, late_ack, mask, unmask, level_mask) \ IDTVEC(recurse_ ## name ## num) ;\ - INTR_RECURSE_HWFRAME ;\ - subq $8,%rsp ;\ - pushq $T_ASTFLT /* trap # for doing ASTs */ ;\ - INTRENTRY ;\ + INTR_RECURSE_HWFRAME ;\ + subq $8,%rsp ;\ + pushq $T_ASTFLT /* trap # for doing ASTs */ ;\ + INTRENTRY ;\ IDTVEC(resume_ ## name ## num) \ - movq $IREENT_MAGIC,TF_ERR(%rsp);\ - movl %ebx,%r13d ;\ - movq CPUVAR(ISOURCES) + (num) * 8, %r14 ;\ + movq $IREENT_MAGIC,TF_ERR(%rsp);\ + movl %ebx,%r13d ;\ + movq CPUVAR(ISOURCES) + (num) * 8,%r14 ;\ 1: \ - pushq %r13 ;\ - movl $num,CPUVAR(ILEVEL) ;\ - STI(si);\ - incl CPUVAR(IDEPTH) ;\ - movq IS_HANDLERS(%r14),%rbx ;\ + pushq %r13 ;\ + movl $num,CPUVAR(ILEVEL) ;\ + STI(si);\ + incl CPUVAR(IDEPTH) ;\ + movq IS_HANDLERS(%r14),%rbx ;\ 6: \ - movq IH_ARG(%rbx),%rdi ;\ - movq %rsp,%rsi ;\ - call *IH_FUN(%rbx) /* call it */ ;\ - movq IH_IPL_NEXT(%rbx),%rbx /* next handler in chain */ ;\ - testq %rbx,%rbx ;\ - jnz 6b ;\ + movq IH_ARG(%rbx),%rdi ;\ + movq %rsp,%rsi ;\ + call *IH_FUN(%rbx) /* call it */ ;\ + movq IH_IPL_NEXT(%rbx),%rbx /*
CVS commit: src/sys/uvm
Module Name:src Committed By: maxv Date: Sun Aug 7 09:55:18 UTC 2016 Modified Files: src/sys/uvm: uvm_mmap.c Log Message: Explicitly return syscall-specific error codes, instead of the ones given by range_test. This fixes msync, mlock and munlock, which all return EINVAL instead of ENOMEM if the address is not in the va space. It should also fix the recent ATF failures. To generate a diff of this commit: cvs rdiff -u -r1.159 -r1.160 src/sys/uvm/uvm_mmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/uvm/uvm_mmap.c diff -u src/sys/uvm/uvm_mmap.c:1.159 src/sys/uvm/uvm_mmap.c:1.160 --- src/sys/uvm/uvm_mmap.c:1.159 Wed Jun 1 12:14:08 2016 +++ src/sys/uvm/uvm_mmap.c Sun Aug 7 09:55:18 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: uvm_mmap.c,v 1.159 2016/06/01 12:14:08 pgoyette Exp $ */ +/* $NetBSD: uvm_mmap.c,v 1.160 2016/08/07 09:55:18 maxv Exp $ */ /* * Copyright (c) 1997 Charles D. Cranor and Washington University. @@ -46,7 +46,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uvm_mmap.c,v 1.159 2016/06/01 12:14:08 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uvm_mmap.c,v 1.160 2016/08/07 09:55:18 maxv Exp $"); #include "opt_compat_netbsd.h" #include "opt_pax.h" @@ -489,7 +489,7 @@ sys___msync13(struct lwp *l, const struc error = range_test(map, addr, size, false); if (error) - return error; + return ENOMEM; /* * XXXCDC: do we really need this semantic? @@ -571,7 +571,7 @@ sys_munmap(struct lwp *l, const struct s error = range_test(map, addr, size, false); if (error) - return error; + return EINVAL; /* * interesting system call semantic: make sure entire range is @@ -630,7 +630,7 @@ sys_mprotect(struct lwp *l, const struct error = range_test(>p_vmspace->vm_map, addr, size, false); if (error) - return error; + return EINVAL; error = uvm_map_protect(>p_vmspace->vm_map, addr, addr + size, prot, false); @@ -671,7 +671,7 @@ sys_minherit(struct lwp *l, const struct error = range_test(>p_vmspace->vm_map, addr, size, false); if (error) - return error; + return EINVAL; error = uvm_map_inherit(>p_vmspace->vm_map, addr, addr + size, inherit); @@ -712,7 +712,7 @@ sys_madvise(struct lwp *l, const struct error = range_test(>p_vmspace->vm_map, addr, size, false); if (error) - return error; + return EINVAL; switch (advice) { case MADV_NORMAL: @@ -812,7 +812,7 @@ sys_mlock(struct lwp *l, const struct sy error = range_test(>p_vmspace->vm_map, addr, size, false); if (error) - return error; + return ENOMEM; if (atop(size) + uvmexp.wired > uvmexp.wiredmax) return (EAGAIN); @@ -863,7 +863,7 @@ sys_munlock(struct lwp *l, const struct error = range_test(>p_vmspace->vm_map, addr, size, false); if (error) - return error; + return ENOMEM; error = uvm_map_pageable(>p_vmspace->vm_map, addr, addr+size, true, 0);
CVS commit: src/sys/uvm
Module Name:src Committed By: maxv Date: Sun Aug 7 10:07:58 UTC 2016 Modified Files: src/sys/uvm: uvm_mmap.c Log Message: KNF a little. To generate a diff of this commit: cvs rdiff -u -r1.160 -r1.161 src/sys/uvm/uvm_mmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/uvm/uvm_mmap.c diff -u src/sys/uvm/uvm_mmap.c:1.160 src/sys/uvm/uvm_mmap.c:1.161 --- src/sys/uvm/uvm_mmap.c:1.160 Sun Aug 7 09:55:18 2016 +++ src/sys/uvm/uvm_mmap.c Sun Aug 7 10:07:58 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: uvm_mmap.c,v 1.160 2016/08/07 09:55:18 maxv Exp $ */ +/* $NetBSD: uvm_mmap.c,v 1.161 2016/08/07 10:07:58 maxv Exp $ */ /* * Copyright (c) 1997 Charles D. Cranor and Washington University. @@ -46,7 +46,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uvm_mmap.c,v 1.160 2016/08/07 09:55:18 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uvm_mmap.c,v 1.161 2016/08/07 10:07:58 maxv Exp $"); #include "opt_compat_netbsd.h" #include "opt_pax.h" @@ -64,7 +64,7 @@ __KERNEL_RCSID(0, "$NetBSD: uvm_mmap.c,v #include static int uvm_mmap(struct vm_map *, vaddr_t *, vsize_t, vm_prot_t, vm_prot_t, - int, int, struct uvm_object *, voff_t, vsize_t); +int, int, struct uvm_object *, voff_t, vsize_t); static int range_test(struct vm_map *map, vaddr_t addr, vsize_t size, bool ismmap) @@ -104,7 +104,7 @@ sys_sbrk(struct lwp *l, const struct sys syscallarg(intptr_t) incr; } */ - return (ENOSYS); + return ENOSYS; } /* @@ -119,7 +119,7 @@ sys_sstk(struct lwp *l, const struct sys syscallarg(int) incr; } */ - return (ENOSYS); + return ENOSYS; } /* @@ -155,11 +155,11 @@ sys_mincore(struct lwp *l, const struct vec = SCARG(uap, vec); if (start & PAGE_MASK) - return (EINVAL); + return EINVAL; len = round_page(len); end = start + len; if (end <= start) - return (EINVAL); + return EINVAL; /* * Lock down vec, so our returned status isn't outdated by @@ -259,7 +259,7 @@ sys_mincore(struct lwp *l, const struct out: vm_map_unlock_read(map); uvm_vsunlock(p->p_vmspace, SCARG(uap, vec), npgs); - return (error); + return error; } /* @@ -328,7 +328,7 @@ sys_mmap(struct lwp *l, const struct sys #endif } if ((flags & (MAP_SHARED|MAP_PRIVATE)) == (MAP_SHARED|MAP_PRIVATE)) - return (EINVAL); + return EINVAL; /* * align file position and save offset. adjust size. @@ -340,26 +340,23 @@ sys_mmap(struct lwp *l, const struct sys newsize = (vsize_t)round_page(newsize); /* round up */ if (newsize < size) - return (ENOMEM); + return ENOMEM; size = newsize; /* * now check (MAP_FIXED) or get (!MAP_FIXED) the "addr" */ if (flags & MAP_FIXED) { - /* ensure address and file offset are aligned properly */ addr -= pageoff; if (addr & PAGE_MASK) - return (EINVAL); + return EINVAL; error = range_test(>p_vmspace->vm_map, addr, size, true); if (error) { return error; } - } else if (addr == 0 || !(flags & MAP_TRYFIXED)) { - /* * not fixed: make sure we skip over the largest * possible heap for non-topdown mapping arrangements. @@ -371,8 +368,7 @@ sys_mmap(struct lwp *l, const struct sys (vaddr_t)p->p_vmspace->vm_daddr, size, p->p_vmspace->vm_map.flags & VM_MAP_TOPDOWN); - if (addr == 0 || - !(p->p_vmspace->vm_map.flags & VM_MAP_TOPDOWN)) + if (addr == 0 || !(p->p_vmspace->vm_map.flags & VM_MAP_TOPDOWN)) addr = MAX(addr, defaddr); else addr = MIN(addr, defaddr); @@ -385,14 +381,14 @@ sys_mmap(struct lwp *l, const struct sys advice = UVM_ADV_NORMAL; if ((flags & MAP_ANON) == 0) { if ((fp = fd_getfile(fd)) == NULL) - return (EBADF); + return EBADF; if (fp->f_ops->fo_mmap == NULL) { error = ENODEV; goto out; } error = (*fp->f_ops->fo_mmap)(fp, , size, prot, , - , , ); + , , ); if (error) { goto out; } @@ -407,7 +403,7 @@ sys_mmap(struct lwp *l, const struct sys * XXX What do we do about (MAP_SHARED|MAP_PRIVATE) == 0? */ if (fd != -1) - return (EINVAL); + return EINVAL; is_anon: /* label for SunOS style /dev/zero */ uobj = NULL; @@ -430,10 +426,10 @@ sys_mmap(struct lwp *l, const struct sys *retval = (register_t)(addr + pageoff); out: - if (fp != NULL) + if (fp != NULL) fd_putfile(fd); - return (error); + return error; } /* @@ -468,7 +464,7 @@ sys___msync13(struct lwp *l, const struc if ((flags & ~(MS_ASYNC | MS_SYNC | MS_INVALIDATE)) != 0 || (flags & (MS_ASYNC | MS_SYNC | MS_INVALIDATE)) == 0 || (flags & (MS_ASYNC | MS_SYNC)) == (MS_ASYNC | MS_SYNC)) - return (EINVAL); + return EINVAL; if ((flags & (MS_ASYNC | MS_SYNC)) == 0) flags |= MS_SYNC; @@ -513,7 +509,7 @@ sys___msync13(struct lwp *l, const struc } vm_map_unlock_read(map); if (rv == false) - return (EINVAL); + return EINVAL; } /* @@ -565,7 +561,7 @@ sys_munmap(struct lwp *l, const
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Fri Jul 22 12:36:04 UTC 2016 Modified Files: src/sys/arch/x86/x86: pmap.c Log Message: Unused. To generate a diff of this commit: cvs rdiff -u -r1.213 -r1.214 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.213 src/sys/arch/x86/x86/pmap.c:1.214 --- src/sys/arch/x86/x86/pmap.c:1.213 Wed Jul 20 12:33:59 2016 +++ src/sys/arch/x86/x86/pmap.c Fri Jul 22 12:36:03 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.213 2016/07/20 12:33:59 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.214 2016/07/22 12:36:03 maxv Exp $ */ /*- * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.213 2016/07/20 12:33:59 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.214 2016/07/22 12:36:03 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -492,10 +492,7 @@ static struct pool_cache pmap_cache; */ static struct pool_cache pmap_pv_cache; -#ifdef __HAVE_DIRECT_MAP -extern phys_ram_seg_t mem_clusters[]; -extern int mem_cluster_cnt; -#else +#ifndef __HAVE_DIRECT_MAP /* * MULTIPROCESSOR: special VAs and PTEs are actually allocated inside a * (maxcpus * NPTECL) array of PTE, to avoid cache line thrashing due to
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Fri Jul 22 13:01:44 UTC 2016 Modified Files: src/sys/arch/x86/x86: pmap.c Log Message: Simplify pmap_alloc_level. It is designed to work only with normal_pdes and PTP_LEVELS, so don't pass them as argument. While here, explain what we are doing. To generate a diff of this commit: cvs rdiff -u -r1.214 -r1.215 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.214 src/sys/arch/x86/x86/pmap.c:1.215 --- src/sys/arch/x86/x86/pmap.c:1.214 Fri Jul 22 12:36:03 2016 +++ src/sys/arch/x86/x86/pmap.c Fri Jul 22 13:01:43 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.214 2016/07/22 12:36:03 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.215 2016/07/22 13:01:43 maxv Exp $ */ /*- * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.214 2016/07/22 12:36:03 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.215 2016/07/22 13:01:43 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -569,7 +569,7 @@ static void pmap_remove_ptes(struct pmap vaddr_t, struct pv_entry **); static paddr_t pmap_get_physpage(void); -static void pmap_alloc_level(pd_entry_t * const *, vaddr_t, int, long *); +static void pmap_alloc_level(vaddr_t, long *); static bool pmap_reactivate(struct pmap *); @@ -4299,15 +4299,15 @@ pmap_get_physpage(void) } /* - * Allocate the amount of specified ptps for a ptp level, and populate - * all levels below accordingly, mapping virtual addresses starting at - * kva. + * Expand the page tree with the specified amount of PTPs, mapping virtual + * addresses starting at kva. We populate all the levels but the last one + * (L1). The nodes of the tree are created as RWX, but the pages covered + * will be kentered in L1, with proper permissions. * - * Used by pmap_growkernel. + * Used only by pmap_growkernel. */ static void -pmap_alloc_level(pd_entry_t * const *pdes, vaddr_t kva, int lvl, -long *needed_ptps) +pmap_alloc_level(vaddr_t kva, long *needed_ptps) { unsigned long i; paddr_t pa; @@ -4318,11 +4318,11 @@ pmap_alloc_level(pd_entry_t * const *pde int s = splvm(); /* protect xpq_* */ #endif - for (level = lvl; level > 1; level--) { + for (level = PTP_LEVELS; level > 1; level--) { if (level == PTP_LEVELS) pdep = pmap_kernel()->pm_pdir; else - pdep = pdes[level - 2]; + pdep = normal_pdes[level - 2]; index = pl_i_roundup(kva, level); endindex = index + needed_ptps[level - 1] - 1; @@ -4370,10 +4370,10 @@ pmap_alloc_level(pd_entry_t * const *pde } /* - * pmap_growkernel: increase usage of KVM space + * pmap_growkernel: increase usage of KVM space. * * => we allocate new PTPs for the kernel and install them in all - * the pmaps on the system. + *the pmaps on the system. */ vaddr_t @@ -4413,7 +4413,7 @@ pmap_growkernel(vaddr_t maxkvaddr) needed_kptp[i] = target_nptp - nkptp[i]; } - pmap_alloc_level(normal_pdes, pmap_maxkvaddr, PTP_LEVELS, needed_kptp); + pmap_alloc_level(pmap_maxkvaddr, needed_kptp); /* * If the number of top level entries changed, update all pmaps.
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Fri Jul 1 11:57:11 UTC 2016 Modified Files: src/sys/arch/x86/x86: pmap.c Log Message: We use only one L4 slot for the direct map, which means that we cannot map more than 512GB. Panic properly if this limit is reached. To generate a diff of this commit: cvs rdiff -u -r1.202 -r1.203 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.202 src/sys/arch/x86/x86/pmap.c:1.203 --- src/sys/arch/x86/x86/pmap.c:1.202 Fri Jul 1 11:44:05 2016 +++ src/sys/arch/x86/x86/pmap.c Fri Jul 1 11:57:10 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.202 2016/07/01 11:44:05 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.203 2016/07/01 11:57:10 maxv Exp $ */ /*- * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.202 2016/07/01 11:44:05 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.203 2016/07/01 11:57:10 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -1509,6 +1509,14 @@ pmap_init_directmap(struct pmap *kpm) lastpa = MAX(lastpa, mc->start + mc->size); } + /* + * We allocate only one L4 entry for the direct map (PDIR_SLOT_DIRECT), + * so we cannot map more than 512GB. + */ + if (lastpa > NBPD_L4) { + panic("RAM limit reached: > 512GB not supported"); + } + /* Allocate L3. */ dm_pdp = pmap_bootstrap_palloc(1);
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Fri Jul 1 12:36:43 UTC 2016 Modified Files: src/sys/arch/x86/x86: pmap.c Log Message: There is no direct map on i386, and therefore we always need to use temporary VAs and PTEs when mapping an area. These temporary VAs don't need to be executable. Put the NOX bit on them. To generate a diff of this commit: cvs rdiff -u -r1.205 -r1.206 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.205 src/sys/arch/x86/x86/pmap.c:1.206 --- src/sys/arch/x86/x86/pmap.c:1.205 Fri Jul 1 12:18:34 2016 +++ src/sys/arch/x86/x86/pmap.c Fri Jul 1 12:36:43 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.205 2016/07/01 12:18:34 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.206 2016/07/01 12:36:43 maxv Exp $ */ /*- * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.205 2016/07/01 12:18:34 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.206 2016/07/01 12:36:43 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -1642,7 +1642,8 @@ pmap_prealloc_lowmem_ptps(void) #ifdef __HAVE_DIRECT_MAP memset((void *)PMAP_DIRECT_MAP(newp), 0, PAGE_SIZE); #else - pmap_pte_set(early_zero_pte, pmap_pa2pte(newp) | pteflags); + pmap_pte_set(early_zero_pte, pmap_pa2pte(newp) | pteflags | + pmap_pg_nx); pmap_pte_flush(); pmap_update_pg((vaddr_t)early_zerop); memset(early_zerop, 0, PAGE_SIZE); @@ -1671,8 +1672,8 @@ pmap_prealloc_lowmem_ptps(void) pmap_pte_set(_pdir[pl_i(0, PTP_LEVELS)], pmap_pa2pte(newp) | pteflags); } - #endif /* XEN */ + pmap_pte_set([pl_i(0, level)], pmap_pa2pte(newp) | pteflags); @@ -3081,6 +3082,9 @@ pmap_zero_page(paddr_t pa) void *zerova; int id; + const pd_entry_t pteflags = PG_V | PG_RW | pmap_pg_nx | PG_M | PG_U | + PG_k; + kpreempt_disable(); id = cpu_number(); zpte = PTESLEW(zero_pte, id); @@ -3091,7 +3095,7 @@ pmap_zero_page(paddr_t pa) panic("pmap_zero_page: lock botch"); #endif - pmap_pte_set(zpte, pmap_pa2pte(pa) | PG_V | PG_RW | PG_M | PG_U | PG_k); + pmap_pte_set(zpte, pmap_pa2pte(pa) | pteflags); pmap_pte_flush(); pmap_update_pg((vaddr_t)zerova); /* flush TLB */ @@ -3101,6 +3105,7 @@ pmap_zero_page(paddr_t pa) pmap_pte_set(zpte, 0);/* zap ! */ pmap_pte_flush(); #endif + kpreempt_enable(); #endif /* defined(__HAVE_DIRECT_MAP) */ } @@ -3123,6 +3128,9 @@ pmap_pageidlezero(paddr_t pa) bool rv; int id; + const pd_entry_t pteflags = PG_V | PG_RW | pmap_pg_nx | PG_M | PG_U | + PG_k; + id = cpu_number(); zpte = PTESLEW(zero_pte, id); zerova = VASLEW(zerop, id); @@ -3130,7 +3138,7 @@ pmap_pageidlezero(paddr_t pa) KASSERT(cpu_feature[0] & CPUID_SSE2); KASSERT(*zpte == 0); - pmap_pte_set(zpte, pmap_pa2pte(pa) | PG_V | PG_RW | PG_M | PG_U | PG_k); + pmap_pte_set(zpte, pmap_pa2pte(pa) | pteflags); pmap_pte_flush(); pmap_update_pg((vaddr_t)zerova); /* flush TLB */ @@ -3170,6 +3178,8 @@ pmap_copy_page(paddr_t srcpa, paddr_t ds void *cdstva; int id; + const pd_entry_t pteflags = PG_V | PG_RW | pmap_pg_nx | PG_U | PG_k; + kpreempt_disable(); id = cpu_number(); spte = PTESLEW(csrc_pte,id); @@ -3179,9 +3189,8 @@ pmap_copy_page(paddr_t srcpa, paddr_t ds KASSERT(*spte == 0 && *dpte == 0); - pmap_pte_set(spte, pmap_pa2pte(srcpa) | PG_V | PG_RW | PG_U | PG_k); - pmap_pte_set(dpte, - pmap_pa2pte(dstpa) | PG_V | PG_RW | PG_M | PG_U | PG_k); + pmap_pte_set(spte, pmap_pa2pte(srcpa) | pteflags); + pmap_pte_set(dpte, pmap_pa2pte(dstpa) | pteflags | PG_M); pmap_pte_flush(); pmap_update_2pg((vaddr_t)csrcva, (vaddr_t)cdstva); @@ -3192,6 +3201,7 @@ pmap_copy_page(paddr_t srcpa, paddr_t ds pmap_pte_set(dpte, 0); pmap_pte_flush(); #endif + kpreempt_enable(); #endif /* defined(__HAVE_DIRECT_MAP) */ } @@ -3208,16 +3218,18 @@ pmap_map_ptp(struct vm_page *ptp) KASSERT(kpreempt_disabled()); +#ifndef XEN + const pd_entry_t pteflags = PG_V | PG_RW | pmap_pg_nx | PG_U | PG_M | + PG_k; +#else + const pd_entry_t pteflags = PG_V | pmap_pg_nx | PG_U | PG_M | PG_k; +#endif + id = cpu_number(); ptppte = PTESLEW(ptp_pte, id); ptpva = VASLEW(ptpp, id); -#if !defined(XEN) - pmap_pte_set(ptppte, pmap_pa2pte(VM_PAGE_TO_PHYS(ptp)) | PG_V | PG_M | - PG_RW | PG_U | PG_k); -#else - pmap_pte_set(ptppte, pmap_pa2pte(VM_PAGE_TO_PHYS(ptp)) | PG_V | PG_M | - PG_U | PG_k); -#endif + pmap_pte_set(ptppte, pmap_pa2pte(VM_PAGE_TO_PHYS(ptp)) | pteflags); + pmap_pte_flush(); pmap_update_pg((vaddr_t)ptpva); @@ -4252,8 +4264,8 @@ pmap_get_physpage(vaddr_t va, int level, } #endif kpreempt_disable(); - pmap_pte_set(early_zero_pte, - pmap_pa2pte(*paddrp) | PG_V | PG_RW | PG_k); + pmap_pte_set(early_zero_pte, pmap_pa2pte(*paddrp) | PG_V | +
CVS commit: src/sys/arch/amd64/amd64
Module Name:src Committed By: maxv Date: Fri Jul 1 12:41:28 UTC 2016 Modified Files: src/sys/arch/amd64/amd64: machdep.c Log Message: Don't confuse between VM_PROT and UVM_PROT. This should be VM_PROT. To generate a diff of this commit: cvs rdiff -u -r1.218 -r1.219 src/sys/arch/amd64/amd64/machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/machdep.c diff -u src/sys/arch/amd64/amd64/machdep.c:1.218 src/sys/arch/amd64/amd64/machdep.c:1.219 --- src/sys/arch/amd64/amd64/machdep.c:1.218 Fri Jul 1 10:20:10 2016 +++ src/sys/arch/amd64/amd64/machdep.c Fri Jul 1 12:41:28 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.218 2016/07/01 10:20:10 maxv Exp $ */ +/* $NetBSD: machdep.c,v 1.219 2016/07/01 12:41:28 maxv Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011 @@ -111,7 +111,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.218 2016/07/01 10:20:10 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.219 2016/07/01 12:41:28 maxv Exp $"); /* #define XENDEBUG_LOW */ @@ -361,7 +361,7 @@ cpu_startup(void) for (x = 0; x < btoc(msgbuf_p_seg[y].sz); x++, sz += PAGE_SIZE) pmap_kenter_pa((vaddr_t)msgbuf_vaddr + sz, msgbuf_p_seg[y].paddr + x * PAGE_SIZE, - VM_PROT_READ | UVM_PROT_WRITE, 0); + VM_PROT_READ | VM_PROT_WRITE, 0); } pmap_update(pmap_kernel());
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Fri Jul 1 11:39:46 UTC 2016 Modified Files: src/sys/arch/x86/x86: pmap.c Log Message: Create the direct map in a separate function. While here, add some comments to explain what we are doing. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.200 -r1.201 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.200 src/sys/arch/x86/x86/pmap.c:1.201 --- src/sys/arch/x86/x86/pmap.c:1.200 Fri Jul 1 11:28:18 2016 +++ src/sys/arch/x86/x86/pmap.c Fri Jul 1 11:39:45 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.200 2016/07/01 11:28:18 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.201 2016/07/01 11:39:45 maxv Exp $ */ /*- * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.200 2016/07/01 11:28:18 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.201 2016/07/01 11:39:45 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -561,6 +561,10 @@ extern vaddr_t pentium_idt_vaddr; * local prototypes */ +#ifdef __HAVE_DIRECT_MAP +static void pmap_init_directmap(struct pmap *); +#endif + #ifndef XEN static void pmap_remap_largepages(void); #endif @@ -1219,19 +1223,12 @@ void pmap_bootstrap(vaddr_t kva_start) { struct pmap *kpm; - pt_entry_t *pte; int i; vaddr_t kva; #ifndef XEN unsigned long p1i; vaddr_t kva_end; #endif -#ifdef __HAVE_DIRECT_MAP - phys_ram_seg_t *mc; - long ndmpdp; - paddr_t lastpa, dmpd, dmpdp, pdp; - vaddr_t tmpva; -#endif pmap_pg_nx = (cpu_feature[2] & CPUID_NOX ? PG_NX : 0); @@ -1343,77 +1340,7 @@ pmap_bootstrap(vaddr_t kva_start) #endif /* !XEN */ #ifdef __HAVE_DIRECT_MAP - - pd_entry_t *pde; - - tmpva = (KERNBASE + NKL2_KIMG_ENTRIES * NBPD_L2); - pte = PTE_BASE + pl1_i(tmpva); - - /* - * Map the direct map RW. Use 1GB pages if they are available, - * otherwise use 2MB pages. Note that the unused parts of - * PTPs * must be zero outed, as they might be accessed due - * to speculative execution. Also, PG_G is not allowed on - * non-leaf PTPs. - */ - - lastpa = 0; - for (i = 0; i < mem_cluster_cnt; i++) { - mc = _clusters[i]; - lastpa = MAX(lastpa, mc->start + mc->size); - } - - ndmpdp = (lastpa + NBPD_L3 - 1) >> L3_SHIFT; - dmpdp = avail_start; avail_start += PAGE_SIZE; - - *pte = dmpdp | PG_V | PG_RW | pmap_pg_nx; - pmap_update_pg(tmpva); - memset((void *)tmpva, 0, PAGE_SIZE); - - if (cpu_feature[2] & CPUID_P1GB) { - for (i = 0; i < ndmpdp; i++) { - pdp = (paddr_t)&(((pd_entry_t *)dmpdp)[i]); - *pte = (pdp & PG_FRAME) | PG_V | PG_RW | pmap_pg_nx; - pmap_update_pg(tmpva); - - pde = (pd_entry_t *)(tmpva + (pdp & ~PG_FRAME)); - *pde = ((paddr_t)i << L3_SHIFT) | PG_RW | pmap_pg_nx | - PG_V | PG_U | PG_PS | PG_G; - } - } else { - dmpd = avail_start; avail_start += ndmpdp * PAGE_SIZE; - - for (i = 0; i < ndmpdp; i++) { - pdp = dmpd + i * PAGE_SIZE; - *pte = (pdp & PG_FRAME) | PG_V | PG_RW | pmap_pg_nx; - pmap_update_pg(tmpva); - - memset((void *)tmpva, 0, PAGE_SIZE); - } - for (i = 0; i < NPDPG * ndmpdp; i++) { - pdp = (paddr_t)&(((pd_entry_t *)dmpd)[i]); - *pte = (pdp & PG_FRAME) | PG_V | PG_RW | pmap_pg_nx; - pmap_update_pg(tmpva); - - pde = (pd_entry_t *)(tmpva + (pdp & ~PG_FRAME)); - *pde = ((paddr_t)i << L2_SHIFT) | PG_RW | pmap_pg_nx | - PG_V | PG_U | PG_PS | PG_G; - } - for (i = 0; i < ndmpdp; i++) { - pdp = (paddr_t)&(((pd_entry_t *)dmpdp)[i]); - *pte = (pdp & PG_FRAME) | PG_V | PG_RW | pmap_pg_nx; - pmap_update_pg((vaddr_t)tmpva); - - pde = (pd_entry_t *)(tmpva + (pdp & ~PG_FRAME)); - *pde = (dmpd + (i << PAGE_SHIFT)) | PG_RW | pmap_pg_nx | - PG_V | PG_U; - } - } - - kpm->pm_pdir[PDIR_SLOT_DIRECT] = dmpdp | PG_KW | pmap_pg_nx | PG_V | PG_U; - - tlbflush(); - + pmap_init_directmap(kpm); #else if (VM_MIN_KERNEL_ADDRESS != KERNBASE) { /* @@ -1439,7 +1366,7 @@ pmap_bootstrap(vaddr_t kva_start) * mapping. */ - pte = PTE_BASE + pl1_i(virtual_avail); + pt_entry_t *pte = PTE_BASE + pl1_i(virtual_avail); #ifdef MULTIPROCESSOR /* @@ -1480,11 +1407,6 @@ pmap_bootstrap(vaddr_t kva_start) } #endif - /* - * Nothing after this point actually needs pte. - */ - pte = (void *)0xdeadbeef; - #ifdef XEN #ifdef __x86_64__ /* @@ -1561,6 +1483,101 @@ pmap_bootstrap(vaddr_t kva_start) pmap_maxkvaddr = kva; } + +#ifdef __HAVE_DIRECT_MAP +/* + * Create the amd64 direct map. Called only once at boot time. + */ +static void +pmap_init_directmap(struct pmap *kpm) +{ + extern phys_ram_seg_t mem_clusters[]; + extern int mem_cluster_cnt; + + paddr_t lastpa, dm_pd, dm_pdp, pdp; + vaddr_t tmpva; + pt_entry_t *pte; + pd_entry_t *pde; + phys_ram_seg_t *mc; + long n_dm_pdp; + int i; + + const pd_entry_t pteflags = PG_V | PG_KW |
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Fri Jul 1 11:44:05 UTC 2016 Modified Files: src/sys/arch/x86/x86: pmap.c Log Message: Use pmap_bootstrap_valloc and pmap_bootstrap_palloc under XEN at least once, for these not to appear as unused functions (not tested, but I guess). To generate a diff of this commit: cvs rdiff -u -r1.201 -r1.202 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.201 src/sys/arch/x86/x86/pmap.c:1.202 --- src/sys/arch/x86/x86/pmap.c:1.201 Fri Jul 1 11:39:45 2016 +++ src/sys/arch/x86/x86/pmap.c Fri Jul 1 11:44:05 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.201 2016/07/01 11:39:45 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.202 2016/07/01 11:44:05 maxv Exp $ */ /*- * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.201 2016/07/01 11:39:45 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.202 2016/07/01 11:44:05 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -1426,14 +1426,12 @@ pmap_bootstrap(vaddr_t kva_start) /* Pin as L4 */ xpq_queue_pin_l4_table(xpmap_ptom_masked(xen_dummy_user_pgd)); #endif /* __x86_64__ */ - idt_vaddr = virtual_avail; /* don't need pte */ - idt_paddr = avail_start;/* steal a page */ /* - * Xen require one more page as we can't store - * GDT and LDT on the same page + * Xen requires one more page as we can't store GDT and LDT on the same + * page. */ - virtual_avail += 3 * PAGE_SIZE; - avail_start += 3 * PAGE_SIZE; + idt_vaddr = pmap_bootstrap_valloc(3); + idt_paddr = pmap_bootstrap_palloc(3); #else /* XEN */ #if defined(__x86_64__)
CVS commit: src/sys/kern
Module Name:src Committed By: maxv Date: Fri Jul 1 12:49:22 UTC 2016 Modified Files: src/sys/kern: kern_ras.c Log Message: Ensure the restartable atomic sequence is in userland, for real. To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 src/sys/kern/kern_ras.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_ras.c diff -u src/sys/kern/kern_ras.c:1.36 src/sys/kern/kern_ras.c:1.37 --- src/sys/kern/kern_ras.c:1.36 Sat Sep 14 20:46:27 2013 +++ src/sys/kern/kern_ras.c Fri Jul 1 12:49:22 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_ras.c,v 1.36 2013/09/14 20:46:27 martin Exp $ */ +/* $NetBSD: kern_ras.c,v 1.37 2016/07/01 12:49:22 maxv Exp $ */ /*- * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_ras.c,v 1.36 2013/09/14 20:46:27 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_ras.c,v 1.37 2016/07/01 12:49:22 maxv Exp $"); #include #include @@ -197,18 +197,19 @@ ras_install(void *addr, size_t len) int nras, error; proc_t *p; + if (len == 0) + return EINVAL; + endaddr = (char *)addr + len; - /* do not warn about < NULL pointer comparision */ + /* Do not warn about < NULL pointer comparison */ __WARNING_PUSH_LESS_NULL_PTR - if (addr < (void *)VM_MIN_ADDRESS || - endaddr > (void *)VM_MAXUSER_ADDRESS) - return (EINVAL); + if (addr < (void *)VM_MIN_ADDRESS || addr > (void *)VM_MAXUSER_ADDRESS) + return EINVAL; + if (endaddr < addr) + return EINVAL; __WARNING_POP_LESS_NULL_PTR - if (len <= 0) - return (EINVAL); - newrp = kmem_alloc(sizeof(*newrp), KM_SLEEP); newrp->ras_startaddr = addr; newrp->ras_endaddr = endaddr; @@ -278,7 +279,6 @@ ras_purge(void *addr, size_t len) int sys_rasctl(struct lwp *l, const struct sys_rasctl_args *uap, register_t *retval) { - #if defined(__HAVE_RAS) /* { syscallarg(void *) addr; @@ -317,11 +317,7 @@ sys_rasctl(struct lwp *l, const struct s } return (error); - #else - return (EOPNOTSUPP); - #endif - }
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Fri Jul 1 12:12:06 UTC 2016 Modified Files: src/sys/arch/x86/x86: pmap.c Log Message: KNF a little, remove some stupid comments, and add some when needed. To generate a diff of this commit: cvs rdiff -u -r1.203 -r1.204 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.203 src/sys/arch/x86/x86/pmap.c:1.204 --- src/sys/arch/x86/x86/pmap.c:1.203 Fri Jul 1 11:57:10 2016 +++ src/sys/arch/x86/x86/pmap.c Fri Jul 1 12:12:06 2016 @@ -1,11 +1,11 @@ -/* $NetBSD: pmap.c,v 1.203 2016/07/01 11:57:10 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.204 2016/07/01 12:12:06 maxv Exp $ */ /*- - * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. + * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Andrew Doran. + * by Andrew Doran, and by Maxime Villard. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.203 2016/07/01 11:57:10 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.204 2016/07/01 12:12:06 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -366,7 +366,7 @@ struct evcnt pmap_ldt_evcnt; static bool cpu_pat_enabled __read_mostly = false; /* - * global data structures + * Global data structures */ static struct pmap kernel_pmap_store; /* the kernel's pmap (proc0) */ @@ -388,7 +388,7 @@ pd_entry_t pmap_pg_g __read_mostly = 0; * pmap_largepages: if our processor supports PG_PS and we are * using it, this is set to true. */ -int pmap_largepages __read_mostly; +int pmap_largepages __read_mostly = 0; /* * i386 physical memory comes in a big contig chunk with a small @@ -466,48 +466,41 @@ pvhash_remove(struct pv_hash_head *hh, s } /* - * other data structures + * Other data structures */ -static pt_entry_t protection_codes[8] __read_mostly; /* maps MI prot to i386 - prot code */ +static pt_entry_t protection_codes[8] __read_mostly; + static bool pmap_initialized __read_mostly = false; /* pmap_init done yet? */ /* - * the following two vaddr_t's are used during system startup - * to keep track of how much of the kernel's VM space we have used. - * once the system is started, the management of the remaining kernel - * VM space is turned over to the kernel_map vm_map. + * The following two vaddr_t's are used during system startup to keep track of + * how much of the kernel's VM space we have used. Once the system is started, + * the management of the remaining kernel VM space is turned over to the + * kernel_map vm_map. */ - static vaddr_t virtual_avail __read_mostly; /* VA of first free KVA */ static vaddr_t virtual_end __read_mostly; /* VA of last free KVA */ /* * pool that pmap structures are allocated from */ - static struct pool_cache pmap_cache; /* * pv_entry cache */ - static struct pool_cache pmap_pv_cache; #ifdef __HAVE_DIRECT_MAP - extern phys_ram_seg_t mem_clusters[]; extern int mem_cluster_cnt; - #else - /* - * MULTIPROCESSOR: special VA's/ PTE's are actually allocated inside a - * maxcpus*NPTECL array of PTE's, to avoid cache line thrashing - * due to false sharing. + * MULTIPROCESSOR: special VAs and PTEs are actually allocated inside a + * (maxcpus * NPTECL) array of PTE, to avoid cache line thrashing due to + * false sharing. */ - #ifdef MULTIPROCESSOR #define PTESLEW(pte, id) ((pte)+(id)*NPTECL) #define VASLEW(va,id) ((va)+(id)*NPTECL*PAGE_SIZE) @@ -517,7 +510,7 @@ extern int mem_cluster_cnt; #endif /* - * special VAs and the PTEs that map them + * Special VAs and the PTEs that map them */ static pt_entry_t *csrc_pte, *cdst_pte, *zero_pte, *ptp_pte, *early_zero_pte; static char *csrcp, *cdstp, *zerop, *ptpp; @@ -546,7 +539,7 @@ static struct pool_allocator pmap_pdp_al }; #endif /* PAE */ -extern vaddr_t idt_vaddr; /* we allocate IDT early */ +extern vaddr_t idt_vaddr; extern paddr_t idt_paddr; extern int end; @@ -556,38 +549,32 @@ extern int end; extern vaddr_t pentium_idt_vaddr; #endif - /* - * local prototypes + * Local prototypes */ #ifdef __HAVE_DIRECT_MAP static void pmap_init_directmap(struct pmap *); #endif - #ifndef XEN static void pmap_remap_largepages(void); #endif -static struct vm_page *pmap_get_ptp(struct pmap *, vaddr_t, - pd_entry_t * const *); -static struct vm_page *pmap_find_ptp(struct pmap *, vaddr_t, paddr_t, int); -static void pmap_freepage(struct pmap *, struct vm_page *, int); -static void pmap_free_ptp(struct pmap *, struct vm_page *, - vaddr_t, pt_e
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Fri Jul 1 12:18:35 UTC 2016 Modified Files: src/sys/arch/x86/x86: pmap.c Log Message: Surprisingly enough, the kernel expects the CPU to support large pages when creating the direct map on amd64. Therefore, the amd64 CPUs that do not support large pages basically don't work on NetBSD. It looks like it has always been this way; add a KASSERT to panic properly in case we come across one of these CPUs. To generate a diff of this commit: cvs rdiff -u -r1.204 -r1.205 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.204 src/sys/arch/x86/x86/pmap.c:1.205 --- src/sys/arch/x86/x86/pmap.c:1.204 Fri Jul 1 12:12:06 2016 +++ src/sys/arch/x86/x86/pmap.c Fri Jul 1 12:18:34 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.204 2016/07/01 12:12:06 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.205 2016/07/01 12:18:34 maxv Exp $ */ /*- * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.204 2016/07/01 12:12:06 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.205 2016/07/01 12:18:34 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -1537,6 +1537,9 @@ pmap_init_directmap(struct pmap *kpm) memset((void *)tmpva, 0, PAGE_SIZE); } + KASSERT(pmap_largepages != 0); + + /* Large pages are supported. Just create L2. */ for (i = 0; i < NPDPG * n_dm_pdp; i++) { pdp = (paddr_t)&(((pd_entry_t *)dm_pd)[i]); *pte = (pdp & PG_FRAME) | pteflags;
CVS commit: src/sys/arch/x86
Module Name:src Committed By: maxv Date: Fri Jul 1 11:10:48 UTC 2016 Modified Files: src/sys/arch/x86/include: pmap.h src/sys/arch/x86/x86: pmap.c Log Message: Define pmap_pg_nx globally. Will be used soon. To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 src/sys/arch/x86/include/pmap.h cvs rdiff -u -r1.197 -r1.198 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/include/pmap.h diff -u src/sys/arch/x86/include/pmap.h:1.57 src/sys/arch/x86/include/pmap.h:1.58 --- src/sys/arch/x86/include/pmap.h:1.57 Wed Nov 11 08:20:22 2015 +++ src/sys/arch/x86/include/pmap.h Fri Jul 1 11:10:48 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.h,v 1.57 2015/11/11 08:20:22 skrll Exp $ */ +/* $NetBSD: pmap.h,v 1.58 2016/07/01 11:10:48 maxv Exp $ */ /* * Copyright (c) 1997 Charles D. Cranor and Washington University. @@ -208,7 +208,7 @@ struct pmap { */ extern u_long PDPpaddr; -extern int pmap_pg_g; /* do we support PG_G? */ +extern pd_entry_t pmap_pg_g; /* do we support PG_G? */ extern long nkptp[PTP_LEVELS]; /* Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.197 src/sys/arch/x86/x86/pmap.c:1.198 --- src/sys/arch/x86/x86/pmap.c:1.197 Fri Jul 1 10:20:10 2016 +++ src/sys/arch/x86/x86/pmap.c Fri Jul 1 11:10:48 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.197 2016/07/01 10:20:10 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.198 2016/07/01 11:10:48 maxv Exp $ */ /*- * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.197 2016/07/01 10:20:10 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.198 2016/07/01 11:10:48 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -373,17 +373,21 @@ static struct pmap kernel_pmap_store; /* struct pmap *const kernel_pmap_ptr = _pmap_store; /* + * pmap_pg_nx: if our processor supports PG_NX in the PTE then we + * set pmap_pg_nx to PG_NX (otherwise it is zero). + */ +pd_entry_t pmap_pg_nx __read_mostly = 0; + +/* * pmap_pg_g: if our processor supports PG_G in the PTE then we * set pmap_pg_g to PG_G (otherwise it is zero). */ - -int pmap_pg_g __read_mostly = 0; +pd_entry_t pmap_pg_g __read_mostly = 0; /* * pmap_largepages: if our processor supports PG_PS and we are * using it, this is set to true. */ - int pmap_largepages __read_mostly; /* @@ -1199,7 +1203,7 @@ pmap_bootstrap(vaddr_t kva_start) vaddr_t tmpva; #endif - pt_entry_t pg_nx = (cpu_feature[2] & CPUID_NOX ? PG_NX : 0); + pmap_pg_nx = (cpu_feature[2] & CPUID_NOX ? PG_NX : 0); /* * set up our local static global vars that keep track of the @@ -1215,13 +1219,13 @@ pmap_bootstrap(vaddr_t kva_start) * we can jam into a i386 PTE. */ - protection_codes[VM_PROT_NONE] = pg_nx; /* --- */ + protection_codes[VM_PROT_NONE] = pmap_pg_nx; /* --- */ protection_codes[VM_PROT_EXECUTE] = PG_RO | PG_X; /* --x */ - protection_codes[VM_PROT_READ] = PG_RO | pg_nx; /* -r- */ + protection_codes[VM_PROT_READ] = PG_RO | pmap_pg_nx; /* -r- */ protection_codes[VM_PROT_READ|VM_PROT_EXECUTE] = PG_RO | PG_X;/* -rx */ - protection_codes[VM_PROT_WRITE] = PG_RW | pg_nx; /* w-- */ + protection_codes[VM_PROT_WRITE] = PG_RW | pmap_pg_nx; /* w-- */ protection_codes[VM_PROT_WRITE|VM_PROT_EXECUTE] = PG_RW | PG_X;/* w-x */ - protection_codes[VM_PROT_WRITE|VM_PROT_READ] = PG_RW | pg_nx; + protection_codes[VM_PROT_WRITE|VM_PROT_READ] = PG_RW | pmap_pg_nx; /* wr- */ protection_codes[VM_PROT_ALL] = PG_RW | PG_X; /* wrx */ @@ -1338,7 +1342,7 @@ pmap_bootstrap(vaddr_t kva_start) for (/* */; kva + NBPD_L2 <= kva_end; kva += NBPD_L2, pa += NBPD_L2) { pde = _BASE[pl2_i(kva)]; - *pde = pa | pmap_pg_g | PG_PS | pg_nx | PG_KR | PG_V; + *pde = pa | pmap_pg_g | PG_PS | pmap_pg_nx | PG_KR | PG_V; tlbflushg(); } @@ -1349,7 +1353,7 @@ pmap_bootstrap(vaddr_t kva_start) for (/* */; kva + NBPD_L2 <= kva_end; kva += NBPD_L2, pa += NBPD_L2) { pde = _BASE[pl2_i(kva)]; - *pde = pa | pmap_pg_g | PG_PS | pg_nx | PG_KW | PG_V; + *pde = pa | pmap_pg_g | PG_PS | pmap_pg_nx | PG_KW | PG_V; tlbflushg(); } } @@ -1377,18 +1381,18 @@ pmap_bootstrap(vaddr_t kva_start) ndmpdp = (lastpa + NBPD_L3 - 1) >> L3_SHIFT; dmpdp = avail_start; avail_start += PAGE_SIZE; - *pte = dmpdp | PG_V | PG_RW | pg_nx; + *pte = dmpdp | PG_V | PG_RW | pmap_pg_nx; pmap_update_pg(tmpva); memset((void *)tmpva, 0, PAGE_SIZE); if (cpu_feature[2] & CPUID_P1GB) { for (i = 0; i < ndmpdp; i++) { pdp = (paddr_t)&(((pd_entry_t *)dmpdp)[i]); - *pte = (pdp & PG_FRAME) | PG_V | PG_RW | pg_nx; + *pte = (pdp & PG_FRAME) | PG_V | PG_RW | pmap_pg_nx; pmap_update_pg(tmpva); pde = (pd_entry_t *)(tmpva + (pdp & ~PG_FRAME)); - *pde = ((paddr_t)i << L3_SHIFT) | PG_RW | pg_nx | + *pde =
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Fri Jul 1 11:20:02 UTC 2016 Modified Files: src/sys/arch/x86/x86: pmap.c Log Message: Put the code in charge of remapping the kernel segments with large pages into another function. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.198 -r1.199 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.198 src/sys/arch/x86/x86/pmap.c:1.199 --- src/sys/arch/x86/x86/pmap.c:1.198 Fri Jul 1 11:10:48 2016 +++ src/sys/arch/x86/x86/pmap.c Fri Jul 1 11:20:01 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.198 2016/07/01 11:10:48 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.199 2016/07/01 11:20:01 maxv Exp $ */ /*- * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.198 2016/07/01 11:10:48 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.199 2016/07/01 11:20:01 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -561,6 +561,10 @@ extern vaddr_t pentium_idt_vaddr; * local prototypes */ +#ifndef XEN +static void pmap_remap_largepages(void); +#endif + static struct vm_page *pmap_get_ptp(struct pmap *, vaddr_t, pd_entry_t * const *); static struct vm_page *pmap_find_ptp(struct pmap *, vaddr_t, paddr_t, int); @@ -1297,65 +1301,18 @@ pmap_bootstrap(vaddr_t kva_start) * Enable large pages if they are supported. */ if (cpu_feature[0] & CPUID_PSE) { - paddr_t pa; - extern char __rodata_start; - extern char __data_start; - extern char __kernel_end; - lcr4(rcr4() | CR4_PSE); /* enable hardware (via %cr4) */ pmap_largepages = 1; /* enable software */ /* - * The TLB must be flushed after enabling large pages - * on Pentium CPUs, according to section 3.6.2.2 of - * "Intel Architecture Software Developer's Manual, - * Volume 3: System Programming". + * The TLB must be flushed after enabling large pages on Pentium + * CPUs, according to section 3.6.2.2 of "Intel Architecture + * Software Developer's Manual, Volume 3: System Programming". */ tlbflushg(); - /* - * Now, we remap several kernel segments with large pages. We - * cover as many pages as we can. - */ - - /* Remap the kernel text using large pages. */ - kva = KERNBASE; - kva_end = rounddown((vaddr_t)&__rodata_start, NBPD_L1); - pa = kva - KERNBASE; - for (/* */; kva + NBPD_L2 <= kva_end; kva += NBPD_L2, - pa += NBPD_L2) { - pde = _BASE[pl2_i(kva)]; - *pde = pa | pmap_pg_g | PG_PS | PG_KR | PG_V; - tlbflushg(); - } -#if defined(DEBUG) - aprint_normal("kernel text is mapped with %" PRIuPSIZE " large " - "pages and %" PRIuPSIZE " normal pages\n", - howmany(kva - KERNBASE, NBPD_L2), - howmany((vaddr_t)&__rodata_start - kva, NBPD_L1)); -#endif /* defined(DEBUG) */ - - /* Remap the kernel rodata using large pages. */ - kva = roundup((vaddr_t)&__rodata_start, NBPD_L2); - kva_end = rounddown((vaddr_t)&__data_start, NBPD_L1); - pa = kva - KERNBASE; - for (/* */; kva + NBPD_L2 <= kva_end; kva += NBPD_L2, - pa += NBPD_L2) { - pde = _BASE[pl2_i(kva)]; - *pde = pa | pmap_pg_g | PG_PS | pmap_pg_nx | PG_KR | PG_V; - tlbflushg(); - } - - /* Remap the kernel data+bss using large pages. */ - kva = roundup((vaddr_t)&__data_start, NBPD_L2); - kva_end = rounddown((vaddr_t)&__kernel_end, NBPD_L1); - pa = kva - KERNBASE; - for (/* */; kva + NBPD_L2 <= kva_end; kva += NBPD_L2, - pa += NBPD_L2) { - pde = _BASE[pl2_i(kva)]; - *pde = pa | pmap_pg_g | PG_PS | pmap_pg_nx | PG_KW | PG_V; - tlbflushg(); - } + /* Remap the kernel. */ + pmap_remap_largepages(); } #endif /* !XEN */ @@ -1576,6 +1533,59 @@ pmap_bootstrap(vaddr_t kva_start) pmap_maxkvaddr = kva; } +#ifndef XEN +/* + * Remap several kernel segments with large pages. We cover as many pages as we + * can. Called only once at boot time, if the CPU supports large pages. + */ +static void +pmap_remap_largepages(void) +{ + extern char __rodata_start; + extern char __data_start; + extern char __kernel_end; + pd_entry_t *pde; + vaddr_t kva, kva_end; + paddr_t pa; + + /* Remap the kernel text using large pages. */ + kva = KERNBASE; + kva_end = rounddown((vaddr_t)&__rodata_start, NBPD_L1); + pa = kva - KERNBASE; + for (/* */; kva + NBPD_L2 <= kva_end; kva += NBPD_L2, pa += NBPD_L2) { + pde = _BASE[pl2_i(kva)]; + *pde = pa | pmap_pg_g | PG_PS | PG_KR | PG_V; + tlbflushg(); + } +#if defined(DEBUG) + aprint_normal("kernel text is mapped with %" PRIuPSIZE " large " + "pages and %" PRIuPSIZE " normal pages\n", + howmany(kva - KERNBASE, NBPD_L2), + howmany((vaddr_t)&__rodata_start - kva, NBPD_L1)); +#endif /* defined(DEBUG) */ + + /* Remap the kernel rodata using large pages. */ + kva = roundup((vaddr_t)&__rodata_start, NBPD_L2); +
CVS commit: src/sys/arch
Module Name:src Committed By: maxv Date: Fri Jul 1 10:20:10 UTC 2016 Modified Files: src/sys/arch/amd64/amd64: machdep.c src/sys/arch/x86/x86: pmap.c Log Message: Remove this area (unused). To generate a diff of this commit: cvs rdiff -u -r1.217 -r1.218 src/sys/arch/amd64/amd64/machdep.c cvs rdiff -u -r1.196 -r1.197 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/machdep.c diff -u src/sys/arch/amd64/amd64/machdep.c:1.217 src/sys/arch/amd64/amd64/machdep.c:1.218 --- src/sys/arch/amd64/amd64/machdep.c:1.217 Sun May 15 10:35:54 2016 +++ src/sys/arch/amd64/amd64/machdep.c Fri Jul 1 10:20:10 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.217 2016/05/15 10:35:54 maxv Exp $ */ +/* $NetBSD: machdep.c,v 1.218 2016/07/01 10:20:10 maxv Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011 @@ -111,7 +111,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.217 2016/05/15 10:35:54 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.218 2016/07/01 10:20:10 maxv Exp $"); /* #define XENDEBUG_LOW */ @@ -267,9 +267,6 @@ unsigned int msgbuf_p_cnt = 0; vaddr_t idt_vaddr; paddr_t idt_paddr; -vaddr_t lo32_vaddr; -paddr_t lo32_paddr; - vaddr_t module_start, module_end; static struct vm_map module_map_store; extern struct vm_map *module_map; @@ -1657,7 +1654,6 @@ init_x86_64(paddr_t first_avail) pmap_kenter_pa(idt_vaddr + 2 * PAGE_SIZE, idt_paddr + 2 * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, 0); #endif - pmap_kenter_pa(lo32_vaddr, lo32_paddr, VM_PROT_READ|VM_PROT_WRITE, 0); pmap_update(pmap_kernel()); #ifndef XEN Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.196 src/sys/arch/x86/x86/pmap.c:1.197 --- src/sys/arch/x86/x86/pmap.c:1.196 Sat May 21 07:15:56 2016 +++ src/sys/arch/x86/x86/pmap.c Fri Jul 1 10:20:10 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.196 2016/05/21 07:15:56 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.197 2016/07/01 10:20:10 maxv Exp $ */ /*- * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.196 2016/05/21 07:15:56 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.197 2016/07/01 10:20:10 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -545,11 +545,6 @@ static struct pool_allocator pmap_pdp_al extern vaddr_t idt_vaddr; /* we allocate IDT early */ extern paddr_t idt_paddr; -#ifdef _LP64 -extern vaddr_t lo32_vaddr; -extern vaddr_t lo32_paddr; -#endif - extern int end; #ifdef i386 @@ -1543,17 +1538,6 @@ pmap_bootstrap(vaddr_t kva_start) #endif /* defined(__x86_64__) */ #endif /* XEN */ -#ifdef _LP64 - /* - * Grab a page below 4G for things that need it (i.e. - * having an initial %cr3 for the MP trampoline). - */ - lo32_vaddr = virtual_avail; - virtual_avail += PAGE_SIZE; - lo32_paddr = avail_start; - avail_start += PAGE_SIZE; -#endif - /* * now we reserve some VM for mapping pages when doing a crash dump */
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Fri Jul 1 11:28:18 UTC 2016 Modified Files: src/sys/arch/x86/x86: pmap.c Log Message: Introduce pmap_bootstrap_valloc and pmap_bootstrap_palloc, that are used to allocate a virtual/physical address before the VM system has been set up. Start using it. To generate a diff of this commit: cvs rdiff -u -r1.199 -r1.200 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.199 src/sys/arch/x86/x86/pmap.c:1.200 --- src/sys/arch/x86/x86/pmap.c:1.199 Fri Jul 1 11:20:01 2016 +++ src/sys/arch/x86/x86/pmap.c Fri Jul 1 11:28:18 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.199 2016/07/01 11:20:01 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.200 2016/07/01 11:28:18 maxv Exp $ */ /*- * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.199 2016/07/01 11:20:01 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.200 2016/07/01 11:28:18 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -1179,6 +1179,34 @@ pmap_kremove_local(vaddr_t sva, vsize_t */ /* + * pmap_bootstrap_valloc: allocate a virtual address in the bootstrap area. + * This function is to be used before any VM system has been set up. + * + * The va is taken from virtual_avail. + */ +static vaddr_t +pmap_bootstrap_valloc(size_t npages) +{ + vaddr_t va = virtual_avail; + virtual_avail += npages * PAGE_SIZE; + return va; +} + +/* + * pmap_bootstrap_palloc: allocate a physical address in the bootstrap area. + * This function is to be used before any VM system has been set up. + * + * The pa is taken from avail_start. + */ +static paddr_t +pmap_bootstrap_palloc(size_t npages) +{ + paddr_t pa = avail_start; + avail_start += npages * PAGE_SIZE; + return pa; +} + +/* * pmap_bootstrap: get the system in a state where it can run with VM * properly enabled (called before main()). the VM system is * fully init'd later... @@ -1187,7 +1215,6 @@ pmap_kremove_local(vaddr_t sva, vsize_t * a PDP for the kernel, and nkpde PTP's for the kernel. * => kva_start is the first free virtual address in kernel space */ - void pmap_bootstrap(vaddr_t kva_start) { @@ -1196,7 +1223,6 @@ pmap_bootstrap(vaddr_t kva_start) int i; vaddr_t kva; #ifndef XEN - pd_entry_t *pde; unsigned long p1i; vaddr_t kva_end; #endif @@ -1318,6 +1344,8 @@ pmap_bootstrap(vaddr_t kva_start) #ifdef __HAVE_DIRECT_MAP + pd_entry_t *pde; + tmpva = (KERNBASE + NKL2_KIMG_ENTRIES * NBPD_L2); pte = PTE_BASE + pl1_i(tmpva); @@ -1485,18 +1513,18 @@ pmap_bootstrap(vaddr_t kva_start) virtual_avail += 3 * PAGE_SIZE; avail_start += 3 * PAGE_SIZE; #else /* XEN */ - idt_vaddr = virtual_avail; /* don't need pte */ - idt_paddr = avail_start; /* steal a page */ + #if defined(__x86_64__) - virtual_avail += 2 * PAGE_SIZE; - avail_start += 2 * PAGE_SIZE; -#else /* defined(__x86_64__) */ - virtual_avail += PAGE_SIZE; - avail_start += PAGE_SIZE; + idt_vaddr = pmap_bootstrap_valloc(2); + idt_paddr = pmap_bootstrap_palloc(2); +#else + idt_vaddr = pmap_bootstrap_valloc(1); + idt_paddr = pmap_bootstrap_palloc(1); + /* pentium f00f bug stuff */ - pentium_idt_vaddr = virtual_avail; /* don't need pte */ - virtual_avail += PAGE_SIZE; -#endif /* defined(__x86_64__) */ + pentium_idt_vaddr = pmap_bootstrap_valloc(1); +#endif + #endif /* XEN */ /*
CVS commit: src/sys/arch
Module Name:src Committed By: maxv Date: Fri Jul 1 13:11:21 UTC 2016 Modified Files: src/sys/arch/amd64/amd64: locore.S src/sys/arch/i386/i386: locore.S Log Message: Try to make this part more readable. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.102 -r1.103 src/sys/arch/amd64/amd64/locore.S cvs rdiff -u -r1.131 -r1.132 src/sys/arch/i386/i386/locore.S Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/locore.S diff -u src/sys/arch/amd64/amd64/locore.S:1.102 src/sys/arch/amd64/amd64/locore.S:1.103 --- src/sys/arch/amd64/amd64/locore.S:1.102 Sat Jun 4 10:48:11 2016 +++ src/sys/arch/amd64/amd64/locore.S Fri Jul 1 13:11:21 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.102 2016/06/04 10:48:11 maxv Exp $ */ +/* $NetBSD: locore.S,v 1.103 2016/07/01 13:11:21 maxv Exp $ */ /* * Copyright-o-rama! @@ -1072,7 +1072,7 @@ END(dumpsys) /* * struct lwp *cpu_switchto(struct lwp *oldlwp, struct lwp *newlwp, - * bool returning) + * bool returning) * * 1. if (oldlwp != NULL), save its context. * 2. then, restore context of newlwp. @@ -1091,18 +1091,19 @@ ENTRY(cpu_switchto) movq %rdi,%r13 /* oldlwp */ movq %rsi,%r12 /* newlwp */ - testq %r13,%r13 - jz 1f + testq %r13,%r13 /* oldlwp = NULL ? */ + jz skip_save /* Save old context. */ movq L_PCB(%r13),%rax movq %rsp,PCB_RSP(%rax) movq %rbp,PCB_RBP(%rax) +skip_save: /* Switch to newlwp's stack. */ -1: movq L_PCB(%r12),%r14 + movq L_PCB(%r12),%r14 #ifdef XEN /* XXX debug code */ - cmpq $0, PCB_RSP(%r14) + cmpq $0,PCB_RSP(%r14) jne 999f callq _C_LABEL(cpu_Debugger); 999: @@ -1118,21 +1119,21 @@ ENTRY(cpu_switchto) xchgq %rcx,CPUVAR(CURLWP) /* Skip the rest if returning to a pinned LWP. */ - testb %dl,%dl - jnz 4f + testb %dl,%dl /* returning = true ? */ + jnz switch_return /* Switch ring0 stack */ #ifndef XEN movq PCB_RSP0(%r14),%rax movq %rax,CPUVAR(RSP0) #else - movq %r14, %rdi + movq %r14,%rdi callq _C_LABEL(x86_64_switch_context); #endif /* Don't bother with the rest if switching to a system process. */ testl $LW_SYSTEM,L_FLAG(%r12) - jnz 4f + jnz switch_return /* Is this process using RAS (restartable atomic sequences)? */ movq L_PROC(%r12),%rdi @@ -1154,65 +1155,68 @@ ENTRY(cpu_switchto) * set CR0_TS so we'll trap rather than reuse bogus state. */ cmpq CPUVAR(FPCURLWP),%r12 - je 3f + je skip_TS orq $CR0_TS,%rcx +skip_TS: /* Reloading CR0 is very expensive - avoid if possible. */ -3: cmpq %rdx,%rcx - je 6f + cmpq %rdx,%rcx + je skip_CR0 movq %rcx,%cr0 +skip_CR0: -6: testl $PCB_COMPAT32, PCB_FLAGS(%r14) + /* The 32bit LWPs are handled differently. */ + testl $PCB_COMPAT32,PCB_FLAGS(%r14) jne 32f /* Zero out %fs/%gs registers and GDT descriptors. */ - xorq %rax, %rax - movw %ax, %fs + xorq %rax,%rax + movw %ax,%fs CLI(cx) SWAPGS - movw %ax, %gs + movw %ax,%gs SWAPGS STI(cx) movq CPUVAR(GDT),%rcx - movq %rax, (GUFS_SEL*8)(%rcx) - movq %rax, (GUGS_SEL*8)(%rcx) + movq %rax,(GUFS_SEL*8)(%rcx) + movq %rax,(GUGS_SEL*8)(%rcx) /* Reload 64-bit %fs/%gs MSRs. */ - movl $MSR_FSBASE, %ecx - movl PCB_FS(%r14), %eax - movl 4+PCB_FS(%r14), %edx + movl $MSR_FSBASE,%ecx + movl PCB_FS(%r14),%eax + movl 4+PCB_FS(%r14),%edx wrmsr - movl $MSR_KERNELGSBASE, %ecx - movl PCB_GS(%r14), %eax - movl 4+PCB_GS(%r14), %edx + movl $MSR_KERNELGSBASE,%ecx + movl PCB_GS(%r14),%eax + movl 4+PCB_GS(%r14),%edx wrmsr - jmp 4f + jmp switch_return 32: /* Reload %fs/%gs GDT descriptors. */ movq CPUVAR(GDT),%rcx - movq PCB_FS(%r14), %rax - movq %rax, (GUFS_SEL*8)(%rcx) - movq PCB_GS(%r14), %rax - movq %rax, (GUGS_SEL*8)(%rcx) + movq PCB_FS(%r14),%rax + movq %rax,(GUFS_SEL*8)(%rcx) + movq PCB_GS(%r14),%rax + movq %rax,(GUGS_SEL*8)(%rcx) /* Reload %fs and %gs */ - movq L_MD_REGS(%r12), %rbx - movw TF_FS(%rbx), %fs + movq L_MD_REGS(%r12),%rbx + movw TF_FS(%rbx),%fs CLI(ax) SWAPGS - movw TF_GS(%rbx), %gs + movw TF_GS(%rbx),%gs SWAPGS STI(ax) - #else movq %r12,%rdi callq _C_LABEL(x86_64_tls_switch) #endif +switch_return: /* Return to the new LWP, returning 'oldlwp' in %rax. */ -4: movq %r13,%rax + movq %r13,%rax popq %r15 popq %r14 popq %r13 Index: src/sys/arch/i386/i386/locore.S diff -u src/sys/arch/i386/i386/locore.S:1.131 src/sys/arch/i386/i386/locore.S:1.132 --- src/sys/arch/i386/i386/locore.S:1.131 Sat Jun 4 10:48:11 2016 +++ src/sys/arch/i386/i386/locore.S Fri Jul 1 13:11:21 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.131 2016/06/04 10:48:11 maxv Exp $ */ +/* $NetBSD: locore.S,v 1.132 2016/07/01 13:11:21 maxv Exp $ */ /* * Copyright-o-rama! @@ -128,7 +128,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.131 2016/06/04 10:48:11 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.132 2016/07/01 13:11:21 maxv Exp $"); #include "opt_compat_oldboot.h"
CVS commit: src/sys/arch/amd64/amd64
Module Name:src Committed By: maxv Date: Sat Jul 2 07:22:10 UTC 2016 Modified Files: src/sys/arch/amd64/amd64: machdep.c Log Message: Explain why we should use kernel_map instead of module_map, and why we can't. We should probably add some GCC flags in the modules makefiles to make sure the relocations generated are not 32bit. Related to PR/43438. To generate a diff of this commit: cvs rdiff -u -r1.219 -r1.220 src/sys/arch/amd64/amd64/machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/machdep.c diff -u src/sys/arch/amd64/amd64/machdep.c:1.219 src/sys/arch/amd64/amd64/machdep.c:1.220 --- src/sys/arch/amd64/amd64/machdep.c:1.219 Fri Jul 1 12:41:28 2016 +++ src/sys/arch/amd64/amd64/machdep.c Sat Jul 2 07:22:09 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.219 2016/07/01 12:41:28 maxv Exp $ */ +/* $NetBSD: machdep.c,v 1.220 2016/07/02 07:22:09 maxv Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011 @@ -111,7 +111,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.219 2016/07/01 12:41:28 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.220 2016/07/02 07:22:09 maxv Exp $"); /* #define XENDEBUG_LOW */ @@ -371,11 +371,22 @@ cpu_startup(void) minaddr = 0; /* - * Allocate a submap for physio + * Allocate a submap for physio. */ phys_map = uvm_km_suballoc(kernel_map, , , - VM_PHYS_SIZE, 0, false, NULL); + VM_PHYS_SIZE, 0, false, NULL); + /* + * Create the module map. + * + * XXX: the module map is taken as what is left of the bootstrap memory + * created in locore.S, which is not big enough if we want to load many + * modules dynamically. We really should be using kernel_map instead. + * + * But because of the R_X86_64_32 relocations that are usually present + * in dynamic modules, the module map must be in low memory, and this + * wouldn't been guaranteed if we were using kernel_map. + */ uvm_map_setup(_map_store, module_start, module_end, 0); module_map_store.pmap = pmap_kernel(); module_map = _map_store;
CVS commit: src/sys
Module Name:src Committed By: maxv Date: Mon Jul 4 07:56:07 UTC 2016 Modified Files: src/sys/arch/amd64/amd64: locore.S src/sys/arch/i386/i386: locore.S src/sys/kern: kern_ras.c Log Message: Make the execution flow canonical instead of jumping back and forth, and complete the userland check. To generate a diff of this commit: cvs rdiff -u -r1.103 -r1.104 src/sys/arch/amd64/amd64/locore.S cvs rdiff -u -r1.132 -r1.133 src/sys/arch/i386/i386/locore.S cvs rdiff -u -r1.37 -r1.38 src/sys/kern/kern_ras.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/locore.S diff -u src/sys/arch/amd64/amd64/locore.S:1.103 src/sys/arch/amd64/amd64/locore.S:1.104 --- src/sys/arch/amd64/amd64/locore.S:1.103 Fri Jul 1 13:11:21 2016 +++ src/sys/arch/amd64/amd64/locore.S Mon Jul 4 07:56:07 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.103 2016/07/01 13:11:21 maxv Exp $ */ +/* $NetBSD: locore.S,v 1.104 2016/07/04 07:56:07 maxv Exp $ */ /* * Copyright-o-rama! @@ -1138,13 +1138,21 @@ skip_save: /* Is this process using RAS (restartable atomic sequences)? */ movq L_PROC(%r12),%rdi cmpq $0,P_RASLIST(%rdi) - jne 5f + je no_RAS + + /* Handle restartable atomic sequences (RAS). */ + movq L_MD_REGS(%r12),%rbx + movq TF_RIP(%rbx),%rsi + call _C_LABEL(ras_lookup) + cmpq $-1,%rax + je no_RAS + movq %rax,TF_RIP(%rbx) +no_RAS: /* * Restore cr0 including FPU state (may have CR0_TS set). Note that * IPL_SCHED prevents from FPU interrupt altering the LWP's saved cr0. */ -2: #ifndef XEN movl $IPL_HIGH,CPUVAR(ILEVEL) movl PCB_CR0(%r14),%ecx /* has CR0_TS clear */ @@ -1223,15 +1231,6 @@ switch_return: popq %r12 popq %rbx ret - - /* Check for restartable atomic sequences (RAS). */ -5: movq L_MD_REGS(%r12),%rbx - movq TF_RIP(%rbx),%rsi - call _C_LABEL(ras_lookup) - cmpq $-1,%rax - je 2b - movq %rax,TF_RIP(%rbx) - jmp 2b END(cpu_switchto) /* Index: src/sys/arch/i386/i386/locore.S diff -u src/sys/arch/i386/i386/locore.S:1.132 src/sys/arch/i386/i386/locore.S:1.133 --- src/sys/arch/i386/i386/locore.S:1.132 Fri Jul 1 13:11:21 2016 +++ src/sys/arch/i386/i386/locore.S Mon Jul 4 07:56:07 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.132 2016/07/01 13:11:21 maxv Exp $ */ +/* $NetBSD: locore.S,v 1.133 2016/07/04 07:56:07 maxv Exp $ */ /* * Copyright-o-rama! @@ -128,7 +128,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.132 2016/07/01 13:11:21 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.133 2016/07/04 07:56:07 maxv Exp $"); #include "opt_compat_oldboot.h" #include "opt_copy_symtab.h" @@ -1191,14 +1191,25 @@ skip_save: /* Is this process using RAS (restartable atomic sequences)? */ movl L_PROC(%edi),%eax cmpl $0,P_RASLIST(%eax) - jne 5f + je no_RAS + + /* Handle restartable atomic sequences (RAS). */ + movl L_MD_REGS(%edi),%ecx + pushl TF_EIP(%ecx) + pushl %eax + call _C_LABEL(ras_lookup) + addl $8,%esp + cmpl $-1,%eax + je no_RAS + movl L_MD_REGS(%edi),%ecx + movl %eax,TF_EIP(%ecx) +no_RAS: /* * Restore cr0 (including FPU state). Raise the IPL to IPL_HIGH. * FPU IPIs can alter the LWP's saved cr0. Dropping the priority * is deferred until mi_switch(), when cpu_switchto() returns. */ -2: #ifdef XEN pushl %edi call _C_LABEL(i386_tls_switch) @@ -1231,18 +1242,6 @@ switch_return: popl %ebx ret - /* Check for restartable atomic sequences (RAS). */ -5: movl L_MD_REGS(%edi),%ecx - pushl TF_EIP(%ecx) - pushl %eax - call _C_LABEL(ras_lookup) - addl $8,%esp - cmpl $-1,%eax - je 2b - movl L_MD_REGS(%edi),%ecx - movl %eax,TF_EIP(%ecx) - jmp 2b - .Lcopy_iobitmap: /* Copy I/O bitmap. */ incl _C_LABEL(pmap_iobmp_evcnt)+EV_COUNT Index: src/sys/kern/kern_ras.c diff -u src/sys/kern/kern_ras.c:1.37 src/sys/kern/kern_ras.c:1.38 --- src/sys/kern/kern_ras.c:1.37 Fri Jul 1 12:49:22 2016 +++ src/sys/kern/kern_ras.c Mon Jul 4 07:56:07 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_ras.c,v 1.37 2016/07/01 12:49:22 maxv Exp $ */ +/* $NetBSD: kern_ras.c,v 1.38 2016/07/04 07:56:07 maxv Exp $ */ /*- * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_ras.c,v 1.37 2016/07/01 12:49:22 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_ras.c,v 1.38 2016/07/04 07:56:07 maxv Exp $"); #include #include @@ -206,6 +206,8 @@ ras_install(void *addr, size_t len) __WARNING_PUSH_LESS_NULL_PTR if (addr < (void *)VM_MIN_ADDRESS || addr > (void *)VM_MAXUSER_ADDRESS) return EINVAL; + if (endaddr > (void *)VM_MAXUSER_ADDRESS) + return EINVAL; if (endaddr < addr) return EINVAL; __WARNING_POP_LESS_NULL_PTR
CVS commit: src/sys/arch
Module Name:src Committed By: maxv Date: Thu Feb 2 19:09:08 UTC 2017 Modified Files: src/sys/arch/amd64/conf: Makefile.amd64 src/sys/arch/amd64/include: param.h src/sys/arch/xen/conf: Makefile.xen Log Message: Increase KERNTEXTOFF from 1MB to 2MB on amd64. [1MB; 2MB[ is now handled by UVM, so there is no physical loss. On amd64 we always remap the kernel text with 2MB pages, and because of the 1MB start address we were forced to map [0MB; 2MB[ inside the first large page. The problem is, the lower half is used by UVM to allocate physical pages, and it is possible that some of these could be used by userland. We could end up with userland-controllable data mapped into the kernel text on a privileged page, which is far from being a good idea from a security pov. I am not fixing i386 yet, because the large page size depends on PAE, and we probably don't want to have a text located at 4MB on low-memory systems. (note: I didn't introduce this issue, it was already there when I came in) To generate a diff of this commit: cvs rdiff -u -r1.55 -r1.56 src/sys/arch/amd64/conf/Makefile.amd64 cvs rdiff -u -r1.20 -r1.21 src/sys/arch/amd64/include/param.h cvs rdiff -u -r1.40 -r1.41 src/sys/arch/xen/conf/Makefile.xen Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/conf/Makefile.amd64 diff -u src/sys/arch/amd64/conf/Makefile.amd64:1.55 src/sys/arch/amd64/conf/Makefile.amd64:1.56 --- src/sys/arch/amd64/conf/Makefile.amd64:1.55 Fri Apr 29 02:17:25 2016 +++ src/sys/arch/amd64/conf/Makefile.amd64 Thu Feb 2 19:09:08 2017 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.amd64,v 1.55 2016/04/29 02:17:25 christos Exp $ +# $NetBSD: Makefile.amd64,v 1.56 2017/02/02 19:09:08 maxv Exp $ # Makefile for NetBSD # @@ -60,7 +60,7 @@ KERN_AS= library ## ## (5) link settings ## -TEXTADDR?= 0x8010 +TEXTADDR?= 0x8020 EXTRA_LINKFLAGS= -z max-page-size=0x10 LINKFLAGS_NORMAL= -X KERNLDSCRIPT?= ${AMD64}/conf/kern.ldscript Index: src/sys/arch/amd64/include/param.h diff -u src/sys/arch/amd64/include/param.h:1.20 src/sys/arch/amd64/include/param.h:1.21 --- src/sys/arch/amd64/include/param.h:1.20 Fri Jan 20 00:29:28 2017 +++ src/sys/arch/amd64/include/param.h Thu Feb 2 19:09:08 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: param.h,v 1.20 2017/01/20 00:29:28 maya Exp $ */ +/* $NetBSD: param.h,v 1.21 2017/02/02 19:09:08 maxv Exp $ */ #ifdef __x86_64__ @@ -34,11 +34,11 @@ * config info into account. */ #define KERNBASE 0x8000 /* start of kernel virtual space */ -#define KERNTEXTOFF 0x8010 /* start of kernel text */ +#define KERNTEXTOFF 0x8020 /* start of kernel text */ #define BTOPKERNBASE ((u_long)KERNBASE >> PGSHIFT) #define KERNTEXTOFF_HI 0x -#define KERNTEXTOFF_LO 0x8010 +#define KERNTEXTOFF_LO 0x8020 #define KERNBASE_HI 0x #define KERNBASE_LO 0x8000 Index: src/sys/arch/xen/conf/Makefile.xen diff -u src/sys/arch/xen/conf/Makefile.xen:1.40 src/sys/arch/xen/conf/Makefile.xen:1.41 --- src/sys/arch/xen/conf/Makefile.xen:1.40 Mon Aug 24 14:04:25 2015 +++ src/sys/arch/xen/conf/Makefile.xen Thu Feb 2 19:09:08 2017 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.xen,v 1.40 2015/08/24 14:04:25 uebayasi Exp $ +# $NetBSD: Makefile.xen,v 1.41 2017/02/02 19:09:08 maxv Exp $ # NetBSD: Makefile.i386,v 1.132 2003/07/05 16:56:10 simonb Exp # Makefile for NetBSD @@ -105,7 +105,7 @@ vector.o: $S/arch/${XEN_BUILD}/${XEN_BUI .if ${XEN_BUILD} == i386 TEXTADDR?= 0xc010 .elif ${XEN_BUILD} == amd64 -TEXTADDR?= 0x8010 +TEXTADDR?= 0x8020 .endif LINKFLAGS_NORMAL= -X KERNLDSCRIPT?= $S/arch/${XEN_BUILD}/conf/kern.ldscript.Xen
CVS commit: src/sys/arch
Module Name:src Committed By: maxv Date: Thu Feb 2 19:12:09 UTC 2017 Modified Files: src/sys/arch/amd64/amd64: locore.S src/sys/arch/i386/i386: locore.S Log Message: Fix these comments, we probably won't want to keep them up to date. To generate a diff of this commit: cvs rdiff -u -r1.118 -r1.119 src/sys/arch/amd64/amd64/locore.S cvs rdiff -u -r1.144 -r1.145 src/sys/arch/i386/i386/locore.S Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/locore.S diff -u src/sys/arch/amd64/amd64/locore.S:1.118 src/sys/arch/amd64/amd64/locore.S:1.119 --- src/sys/arch/amd64/amd64/locore.S:1.118 Sat Dec 17 13:49:05 2016 +++ src/sys/arch/amd64/amd64/locore.S Thu Feb 2 19:12:09 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.118 2016/12/17 13:49:05 maxv Exp $ */ +/* $NetBSD: locore.S,v 1.119 2017/02/02 19:12:09 maxv Exp $ */ /* * Copyright-o-rama! @@ -647,7 +647,7 @@ no_NOX: */ leal (PROC0_PTP1_OFF)(%esi),%ebx - /* Skip the first MB. */ + /* Skip the area below the kernel text. */ movl $(KERNTEXTOFF_LO - KERNBASE_LO),%ecx shrl $PGSHIFT,%ecx fillkpt_blank Index: src/sys/arch/i386/i386/locore.S diff -u src/sys/arch/i386/i386/locore.S:1.144 src/sys/arch/i386/i386/locore.S:1.145 --- src/sys/arch/i386/i386/locore.S:1.144 Fri Jan 6 08:36:56 2017 +++ src/sys/arch/i386/i386/locore.S Thu Feb 2 19:12:09 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.144 2017/01/06 08:36:56 maxv Exp $ */ +/* $NetBSD: locore.S,v 1.145 2017/02/02 19:12:09 maxv Exp $ */ /* * Copyright-o-rama! @@ -128,7 +128,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.144 2017/01/06 08:36:56 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.145 2017/02/02 19:12:09 maxv Exp $"); #include "opt_compat_oldboot.h" #include "opt_copy_symtab.h" @@ -671,7 +671,7 @@ no_NOX: */ leal (PROC0_PTP1_OFF)(%esi),%ebx - /* Skip the first MB. */ + /* Skip the area below the kernel text. */ movl $(KERNTEXTOFF - KERNBASE),%ecx shrl $PGSHIFT,%ecx fillkpt_blank
CVS commit: src/sys/arch
Module Name:src Committed By: maxv Date: Thu Feb 2 08:57:04 UTC 2017 Modified Files: src/sys/arch/x86/x86: cpu.c identcpu.c pmap.c src/sys/arch/xen/x86: cpu.c x86_xpmap.c Log Message: Use __read_mostly on these variables, to reduce the probability of false sharing. To generate a diff of this commit: cvs rdiff -u -r1.121 -r1.122 src/sys/arch/x86/x86/cpu.c cvs rdiff -u -r1.51 -r1.52 src/sys/arch/x86/x86/identcpu.c cvs rdiff -u -r1.237 -r1.238 src/sys/arch/x86/x86/pmap.c cvs rdiff -u -r1.106 -r1.107 src/sys/arch/xen/x86/cpu.c cvs rdiff -u -r1.70 -r1.71 src/sys/arch/xen/x86/x86_xpmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/cpu.c diff -u src/sys/arch/x86/x86/cpu.c:1.121 src/sys/arch/x86/x86/cpu.c:1.122 --- src/sys/arch/x86/x86/cpu.c:1.121 Sun Oct 16 10:24:58 2016 +++ src/sys/arch/x86/x86/cpu.c Thu Feb 2 08:57:04 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.c,v 1.121 2016/10/16 10:24:58 maxv Exp $ */ +/* $NetBSD: cpu.c,v 1.122 2017/02/02 08:57:04 maxv Exp $ */ /*- * Copyright (c) 2000-2012 NetBSD Foundation, Inc. @@ -62,7 +62,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.121 2016/10/16 10:24:58 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.122 2017/02/02 08:57:04 maxv Exp $"); #include "opt_ddb.h" #include "opt_mpbios.h" /* for MPDEBUG */ @@ -177,7 +177,7 @@ static void tss_init(struct i386tss *, v static void cpu_init_idle_lwp(struct cpu_info *); -uint32_t cpu_feature[7]; /* X86 CPUID feature bits */ +uint32_t cpu_feature[7] __read_mostly; /* X86 CPUID feature bits */ /* [0] basic features cpuid.1:%edx * [1] basic features cpuid.1:%ecx (CPUID2_xxx bits) * [2] extended features cpuid:8001:%edx Index: src/sys/arch/x86/x86/identcpu.c diff -u src/sys/arch/x86/x86/identcpu.c:1.51 src/sys/arch/x86/x86/identcpu.c:1.52 --- src/sys/arch/x86/x86/identcpu.c:1.51 Sat Dec 17 15:23:08 2016 +++ src/sys/arch/x86/x86/identcpu.c Thu Feb 2 08:57:04 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: identcpu.c,v 1.51 2016/12/17 15:23:08 maxv Exp $ */ +/* $NetBSD: identcpu.c,v 1.52 2017/02/02 08:57:04 maxv Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.51 2016/12/17 15:23:08 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.52 2017/02/02 08:57:04 maxv Exp $"); #include "opt_xen.h" @@ -61,9 +61,9 @@ static const struct x86_cache_info amd_c int cpu_vendor; char cpu_brand_string[49]; -int x86_fpu_save = FPU_SAVE_FSAVE; -unsigned int x86_fpu_save_size = 512; -uint64_t x86_xsave_features = 0; +int x86_fpu_save __read_mostly = FPU_SAVE_FSAVE; +unsigned int x86_fpu_save_size __read_mostly = 512; +uint64_t x86_xsave_features __read_mostly = 0; /* * Note: these are just the ones that may not have a cpuid instruction. Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.237 src/sys/arch/x86/x86/pmap.c:1.238 --- src/sys/arch/x86/x86/pmap.c:1.237 Sun Jan 22 20:04:35 2017 +++ src/sys/arch/x86/x86/pmap.c Thu Feb 2 08:57:04 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.237 2017/01/22 20:04:35 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.238 2017/02/02 08:57:04 maxv Exp $ */ /*- * Copyright (c) 2008, 2010, 2016, 2017 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.237 2017/01/22 20:04:35 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.238 2017/02/02 08:57:04 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -480,8 +480,8 @@ static vaddr_t virtual_end __read_mostly /* * LAPIC virtual address, and fake physical address. */ -volatile vaddr_t local_apic_va; -paddr_t local_apic_pa; +volatile vaddr_t local_apic_va __read_mostly; +paddr_t local_apic_pa __read_mostly; #endif /* Index: src/sys/arch/xen/x86/cpu.c diff -u src/sys/arch/xen/x86/cpu.c:1.106 src/sys/arch/xen/x86/cpu.c:1.107 --- src/sys/arch/xen/x86/cpu.c:1.106 Sun Jan 22 19:42:48 2017 +++ src/sys/arch/xen/x86/cpu.c Thu Feb 2 08:57:04 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.c,v 1.106 2017/01/22 19:42:48 maxv Exp $ */ +/* $NetBSD: cpu.c,v 1.107 2017/02/02 08:57:04 maxv Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -65,7 +65,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.106 2017/01/22 19:42:48 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.107 2017/02/02 08:57:04 maxv Exp $"); #include "opt_ddb.h" #include "opt_multiprocessor.h" @@ -171,7 +171,7 @@ struct cpu_info phycpu_info_primary __al struct cpu_info *cpu_info_list = _info_primary; struct cpu_info *phycpu_info_list = _info_primary; -uint32_t cpu_feature[7]; /* X86 CPUID feature bits +uint32_t cpu_feature[7] __read_mostly; /* X86 CPUID feature bits * [0] basic features %edx * [1] basic features %ecx * [2] extended features
CVS commit: src/sys/net
Module Name:src Committed By: maxv Date: Tue Jan 31 17:13:36 UTC 2017 Modified Files: src/sys/net: if_ecosubr.c if_tokensubr.c Log Message: Correctly handle the return value of arpresolve, otherwise we either leak memory or use some we already freed. Sent on tech-net, ok christos To generate a diff of this commit: cvs rdiff -u -r1.50 -r1.51 src/sys/net/if_ecosubr.c cvs rdiff -u -r1.80 -r1.81 src/sys/net/if_tokensubr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_ecosubr.c diff -u src/sys/net/if_ecosubr.c:1.50 src/sys/net/if_ecosubr.c:1.51 --- src/sys/net/if_ecosubr.c:1.50 Tue Jan 24 18:37:20 2017 +++ src/sys/net/if_ecosubr.c Tue Jan 31 17:13:36 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_ecosubr.c,v 1.50 2017/01/24 18:37:20 maxv Exp $ */ +/* $NetBSD: if_ecosubr.c,v 1.51 2017/01/31 17:13:36 maxv Exp $ */ /*- * Copyright (c) 2001 Ben Harris @@ -58,7 +58,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_ecosubr.c,v 1.50 2017/01/24 18:37:20 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_ecosubr.c,v 1.51 2017/01/31 17:13:36 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -194,12 +194,11 @@ eco_output(struct ifnet *ifp, struct mbu #ifdef INET case AF_INET: if (m->m_flags & M_BCAST) - memcpy(ehdr.eco_dhost, eco_broadcastaddr, - ECO_ADDR_LEN); + memcpy(ehdr.eco_dhost, eco_broadcastaddr, ECO_ADDR_LEN); + else if ((error = arpresolve(ifp, rt, m, dst, ehdr.eco_dhost, + sizeof(ehdr.eco_dhost))) != 0) + return error == EWOULDBLOCK ? 0 : error; - else if (!arpresolve(ifp, rt, m, dst, ehdr.eco_dhost, - sizeof(ehdr.eco_dhost))) - return (0); /* if not yet resolved */ /* If broadcasting on a simplex interface, loopback a copy */ if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX)) mcopy = m_copy(m, 0, (int)M_COPYALL); Index: src/sys/net/if_tokensubr.c diff -u src/sys/net/if_tokensubr.c:1.80 src/sys/net/if_tokensubr.c:1.81 --- src/sys/net/if_tokensubr.c:1.80 Tue Jan 24 18:37:20 2017 +++ src/sys/net/if_tokensubr.c Tue Jan 31 17:13:36 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_tokensubr.c,v 1.80 2017/01/24 18:37:20 maxv Exp $ */ +/* $NetBSD: if_tokensubr.c,v 1.81 2017/01/31 17:13:36 maxv Exp $ */ /* * Copyright (c) 1982, 1989, 1993 @@ -92,7 +92,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_tokensubr.c,v 1.80 2017/01/24 18:37:20 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_tokensubr.c,v 1.81 2017/01/31 17:13:36 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -222,8 +222,11 @@ token_output(struct ifnet *ifp0, struct */ else { struct llentry *la; - if (!arpresolve(ifp, rt, m, dst, edst, sizeof(edst))) -return (0); /* if not yet resolved */ + + error = arpresolve(ifp, rt, m, dst, edst, sizeof(edst)); + if (error != 0) +return error == EWOULDBLOCK ? 0 : error; + la = rt->rt_llinfo; KASSERT(la != NULL); TOKEN_RIF_LLE_ASSERT(la);
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Tue Jan 31 17:38:54 UTC 2017 Modified Files: src/sys/arch/x86/x86: tprof_amdpmi.c Log Message: Update the URLs, and add the DC_refills_ flags (from the spec, not present on my cpu). To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/arch/x86/x86/tprof_amdpmi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/tprof_amdpmi.c diff -u src/sys/arch/x86/x86/tprof_amdpmi.c:1.4 src/sys/arch/x86/x86/tprof_amdpmi.c:1.5 --- src/sys/arch/x86/x86/tprof_amdpmi.c:1.4 Fri Nov 15 08:47:55 2013 +++ src/sys/arch/x86/x86/tprof_amdpmi.c Tue Jan 31 17:38:54 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: tprof_amdpmi.c,v 1.4 2013/11/15 08:47:55 msaitoh Exp $ */ +/* $NetBSD: tprof_amdpmi.c,v 1.5 2017/01/31 17:38:54 maxv Exp $ */ /*- * Copyright (c)2008,2009 YAMAMOTO Takashi, @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tprof_amdpmi.c,v 1.4 2013/11/15 08:47:55 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tprof_amdpmi.c,v 1.5 2017/01/31 17:38:54 maxv Exp $"); #include #include @@ -45,7 +45,7 @@ __KERNEL_RCSID(0, "$NetBSD: tprof_amdpmi #include #include -#include /* CPUVENDER_* */ +#include /* CPUVENDOR_* */ #include /* cpu_vendor */ #include #include @@ -73,16 +73,22 @@ __KERNEL_RCSID(0, "$NetBSD: tprof_amdpmi /* bit 42-63 reserved */ /* - * parameters - * - * XXX should not hardcode - * - * http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/32559.pdf - * http://developer.amd.com/Assets/Basic_Performance_Measurements.pdf + * Documents: + * http://support.amd.com/TechDocs/32559.pdf + * http://developer.amd.com/wordpress/media/2012/10/Basic_Performance_Measurements.pdf */ -static uint32_t event = 0x76; /* CPU Clocks not Halted */ -static uint32_t unit = 0; +/* Event flags - abbreviations as found in the documents */ +#define CPU_clocks__EVENT 0x76 +#define CPU_clocks__UNIT 0x00 +#define DC_refills_L2__EVENT 0x42 +#define DC_refills_L2__UNIT 0x1E +#define DC_refills_sys__EVENT 0x43 +#define DC_refills_sys__UNIT 0x1E + +/* Hardcode your counter here */ +static uint32_t event = CPU_clocks__EVENT; +static uint32_t unit = CPU_clocks__UNIT; static int ctrno = 0; static uint64_t counter_val = 500;
CVS commit: src/sys/net
Module Name:src Committed By: maxv Date: Wed Feb 1 17:58:47 UTC 2017 Modified Files: src/sys/net: if_pppoe.c Log Message: Not sure what we are trying to achieve here, but there are two issues; error can be printed while it is not initialized, and if m_pulldown fails m is freed and reused. Quickly reviewed by christos and martin To generate a diff of this commit: cvs rdiff -u -r1.123 -r1.124 src/sys/net/if_pppoe.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/net/if_pppoe.c diff -u src/sys/net/if_pppoe.c:1.123 src/sys/net/if_pppoe.c:1.124 --- src/sys/net/if_pppoe.c:1.123 Tue Dec 27 01:31:06 2016 +++ src/sys/net/if_pppoe.c Wed Feb 1 17:58:47 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_pppoe.c,v 1.123 2016/12/27 01:31:06 christos Exp $ */ +/* $NetBSD: if_pppoe.c,v 1.124 2017/02/01 17:58:47 maxv Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.123 2016/12/27 01:31:06 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.124 2017/02/01 17:58:47 maxv Exp $"); #ifdef _KERNEL_OPT #include "pppoe.h" @@ -621,19 +621,21 @@ pppoe_dispatch_disc_pkt(struct mbuf *m, case PPPOE_TAG_ACNAME: error = NULL; if (sc != NULL && len > 0) { -error = malloc(len+1, M_TEMP, M_NOWAIT); -if (error) { - n = m_pulldown(m, off + sizeof(*pt), - len, ); - if (n) { - strlcpy(error, - mtod(n, char*) + noff, - len); - } - printf("%s: connected to %s\n", - devname, error); +error = malloc(len + 1, M_TEMP, M_NOWAIT); +if (error == NULL) + break; + +n = m_pulldown(m, off + sizeof(*pt), len, +); +if (!n) { + m = NULL; free(error, M_TEMP); + goto done; } + +strlcpy(error, mtod(n, char*) + noff, len + 1); +printf("%s: connected to %s\n", devname, error); +free(error, M_TEMP); } break; /* ignored */ case PPPOE_TAG_HUNIQUE: { @@ -704,12 +706,15 @@ pppoe_dispatch_disc_pkt(struct mbuf *m, if (err_msg) { error = NULL; if (errortag && len) { -error = malloc(len+1, M_TEMP, M_NOWAIT); +error = malloc(len + 1, M_TEMP, +M_NOWAIT|M_ZERO); n = m_pulldown(m, off + sizeof(*pt), len, ); -if (n && error) { - strlcpy(error, - mtod(n, char *) + noff, len); +if (!n) { + m = NULL; +} else if (error) { + strlcpy(error, mtod(n, char *) + noff, + len + 1); } } if (error) {
CVS commit: src/sys/arch/amd64/amd64
Module Name:src Committed By: maxv Date: Sun Feb 5 08:36:08 UTC 2017 Modified Files: src/sys/arch/amd64/amd64: machdep.c Log Message: Now that valid_user_selector only checks for LDT selectors, remove it. A user may legitimately want to have one register in the GDT, and another in the LDT. Pass 2/2. To generate a diff of this commit: cvs rdiff -u -r1.250 -r1.251 src/sys/arch/amd64/amd64/machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/machdep.c diff -u src/sys/arch/amd64/amd64/machdep.c:1.250 src/sys/arch/amd64/amd64/machdep.c:1.251 --- src/sys/arch/amd64/amd64/machdep.c:1.250 Sun Feb 5 08:19:05 2017 +++ src/sys/arch/amd64/amd64/machdep.c Sun Feb 5 08:36:08 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.250 2017/02/05 08:19:05 maxv Exp $ */ +/* $NetBSD: machdep.c,v 1.251 2017/02/05 08:36:08 maxv Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011 @@ -111,7 +111,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.250 2017/02/05 08:19:05 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.251 2017/02/05 08:36:08 maxv Exp $"); /* #define XENDEBUG_LOW */ @@ -320,8 +320,6 @@ int dumpsys_seg(paddr_t, paddr_t); void init_x86_64(paddr_t); -static int valid_user_selector(struct lwp *, uint64_t); - /* * Machine-dependent startup code */ @@ -1902,12 +1900,11 @@ cpu_setmcontext(struct lwp *l, const mco int cpu_mcontext_validate(struct lwp *l, const mcontext_t *mcp) { - const __greg_t *gr; - uint16_t sel; - int error; struct pmap *pmap = l->l_proc->p_vmspace->vm_map.pmap; struct proc *p = l->l_proc; struct trapframe *tf = l->l_md.md_regs; + const __greg_t *gr; + uint16_t sel; gr = mcp->__gregs; @@ -1915,31 +1912,12 @@ cpu_mcontext_validate(struct lwp *l, con return EINVAL; if (__predict_false(pmap->pm_ldt != NULL)) { - error = valid_user_selector(l, gr[_REG_ES]); - if (error != 0) - return error; - - error = valid_user_selector(l, gr[_REG_FS]); - if (error != 0) - return error; - - error = valid_user_selector(l, gr[_REG_GS]); - if (error != 0) - return error; - + /* Only when the LDT is user-set (with USER_LDT) */ if ((gr[_REG_DS] & 0x) == 0) return EINVAL; - error = valid_user_selector(l, gr[_REG_DS]); - if (error != 0) - return error; - #ifndef XEN if ((gr[_REG_SS] & 0x) == 0) return EINVAL; - error = valid_user_selector(l, gr[_REG_SS]); - if (error != 0) - return error; - if (!USERMODE(gr[_REG_CS], gr[_REG_RFLAGS])) return EINVAL; #endif @@ -1991,27 +1969,6 @@ cpu_initclocks(void) (*initclock_func)(); } -/* - * Called only when the LDT is user-set (USER_LDT). - */ -static int -valid_user_selector(struct lwp *l, uint64_t seg) -{ - seg &= 0x; - if (seg == 0) - return 0; - - if (!(seg & SEL_LDT)) { - CTASSERT(GUDATA_SEL & SEL_LDT); - KASSERT(seg != GUDATA_SEL); - CTASSERT(GUDATA32_SEL & SEL_LDT); - KASSERT(seg != GUDATA32_SEL); - return EINVAL; - } - - return 0; -} - int mm_md_kernacc(void *ptr, vm_prot_t prot, bool *handled) {
CVS commit: src/sys
Module Name:src Committed By: maxv Date: Sun Feb 5 08:52:12 UTC 2017 Modified Files: src/sys/arch/amd64/amd64: netbsd32_machdep.c src/sys/compat/linux32/arch/amd64: linux32_machdep.c Log Message: Remove #if 0 on USER_LDT. To generate a diff of this commit: cvs rdiff -u -r1.98 -r1.99 src/sys/arch/amd64/amd64/netbsd32_machdep.c cvs rdiff -u -r1.37 -r1.38 \ src/sys/compat/linux32/arch/amd64/linux32_machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/netbsd32_machdep.c diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.98 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.99 --- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.98 Thu Dec 15 12:04:17 2016 +++ src/sys/arch/amd64/amd64/netbsd32_machdep.c Sun Feb 5 08:52:11 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_machdep.c,v 1.98 2016/12/15 12:04:17 kamil Exp $ */ +/* $NetBSD: netbsd32_machdep.c,v 1.99 2017/02/05 08:52:11 maxv Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.98 2016/12/15 12:04:17 kamil Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.99 2017/02/05 08:52:11 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -115,7 +115,7 @@ netbsd32_setregs(struct lwp *l, struct e pcb = lwp_getpcb(l); -#if defined(USER_LDT) && 0 +#if defined(USER_LDT) pmap_ldt_cleanup(l); #endif Index: src/sys/compat/linux32/arch/amd64/linux32_machdep.c diff -u src/sys/compat/linux32/arch/amd64/linux32_machdep.c:1.37 src/sys/compat/linux32/arch/amd64/linux32_machdep.c:1.38 --- src/sys/compat/linux32/arch/amd64/linux32_machdep.c:1.37 Fri Sep 2 07:51:05 2016 +++ src/sys/compat/linux32/arch/amd64/linux32_machdep.c Sun Feb 5 08:52:11 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: linux32_machdep.c,v 1.37 2016/09/02 07:51:05 maxv Exp $ */ +/* $NetBSD: linux32_machdep.c,v 1.38 2017/02/05 08:52:11 maxv Exp $ */ /*- * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved. @@ -31,7 +31,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__KERNEL_RCSID(0, "$NetBSD: linux32_machdep.c,v 1.37 2016/09/02 07:51:05 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux32_machdep.c,v 1.38 2017/02/05 08:52:11 maxv Exp $"); #include #include @@ -275,7 +275,7 @@ linux32_setregs(struct lwp *l, struct ex struct trapframe *tf; struct proc *p = l->l_proc; -#if defined(USER_LDT) && 0 +#if defined(USER_LDT) pmap_ldt_cleanup(l); #endif
CVS commit: src/sys/compat/linux/arch/amd64
Module Name:src Committed By: maxv Date: Sun Feb 5 08:42:49 UTC 2017 Modified Files: src/sys/compat/linux/arch/amd64: linux_machdep.c Log Message: Missing pmap_ldt_cleanup. To generate a diff of this commit: cvs rdiff -u -r1.48 -r1.49 src/sys/compat/linux/arch/amd64/linux_machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/compat/linux/arch/amd64/linux_machdep.c diff -u src/sys/compat/linux/arch/amd64/linux_machdep.c:1.48 src/sys/compat/linux/arch/amd64/linux_machdep.c:1.49 --- src/sys/compat/linux/arch/amd64/linux_machdep.c:1.48 Wed Feb 19 20:50:56 2014 +++ src/sys/compat/linux/arch/amd64/linux_machdep.c Sun Feb 5 08:42:49 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: linux_machdep.c,v 1.48 2014/02/19 20:50:56 dsl Exp $ */ +/* $NetBSD: linux_machdep.c,v 1.49 2017/02/05 08:42:49 maxv Exp $ */ /*- * Copyright (c) 2005 Emmanuel Dreyfus, all rights reserved. @@ -33,7 +33,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: linux_machdep.c,v 1.48 2014/02/19 20:50:56 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_machdep.c,v 1.49 2017/02/05 08:42:49 maxv Exp $"); #include #include @@ -84,6 +84,10 @@ linux_setregs(struct lwp *l, struct exec struct pcb *pcb = lwp_getpcb(l); struct trapframe *tf; +#ifdef USER_LDT + pmap_ldt_cleanup(l); +#endif + fpu_save_area_clear(l, __NetBSD_NPXCW__); pcb->pcb_flags = 0;
CVS commit: src/sys/arch/amd64/include
Module Name:src Committed By: maxv Date: Sun Feb 5 08:58:39 UTC 2017 Modified Files: src/sys/arch/amd64/include: segments.h Log Message: Remove misleading comment; these macros should not be used if a user LDT is active. To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/sys/arch/amd64/include/segments.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/include/segments.h diff -u src/sys/arch/amd64/include/segments.h:1.28 src/sys/arch/amd64/include/segments.h:1.29 --- src/sys/arch/amd64/include/segments.h:1.28 Fri Sep 2 08:52:12 2016 +++ src/sys/arch/amd64/include/segments.h Sun Feb 5 08:58:39 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: segments.h,v 1.28 2016/09/02 08:52:12 maxv Exp $ */ +/* $NetBSD: segments.h,v 1.29 2017/02/05 08:58:39 maxv Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -386,9 +386,7 @@ void cpu_fsgs_reload(struct lwp *, int, #define LSYSRETBASE_SEL LUCODE32_SEL /* - * Checks for valid user selectors. If USER_LDT ever gets implemented - * for amd64, these must check the ldt length and SEL_UPL if a user - * ldt is active. + * Checks for valid user selectors. */ #define VALID_USER_DSEL32(s) \ (((s) & 0x) == GSEL(GUDATA32_SEL, SEL_UPL) || \
CVS commit: src/sys/arch/amd64/amd64
Module Name:src Committed By: maxv Date: Sun Feb 5 08:19:05 UTC 2017 Modified Files: src/sys/arch/amd64/amd64: machdep.c Log Message: In cpu_mcontext_validate, treat %cs differently depending on whether a user LDT is set; just check the permission without checking the location (which may change). In valid_user_selector, don't check the length of the LDT. This is racy because pm_ldt_len could be updated by another thread, and useless since the length is already referenced in ldtr (ldt_alloc), which means that any overflow will fault in userland. Also, don't check the permission of the segment pointed to; this too is racy, and we don't care either since the permissions are checked earlier in x86_set_ldt1. Pass 1/2. To generate a diff of this commit: cvs rdiff -u -r1.249 -r1.250 src/sys/arch/amd64/amd64/machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/machdep.c diff -u src/sys/arch/amd64/amd64/machdep.c:1.249 src/sys/arch/amd64/amd64/machdep.c:1.250 --- src/sys/arch/amd64/amd64/machdep.c:1.249 Sun Feb 5 06:26:06 2017 +++ src/sys/arch/amd64/amd64/machdep.c Sun Feb 5 08:19:05 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.249 2017/02/05 06:26:06 maya Exp $ */ +/* $NetBSD: machdep.c,v 1.250 2017/02/05 08:19:05 maxv Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011 @@ -111,7 +111,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.249 2017/02/05 06:26:06 maya Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.250 2017/02/05 08:19:05 maxv Exp $"); /* #define XENDEBUG_LOW */ @@ -1939,23 +1939,28 @@ cpu_mcontext_validate(struct lwp *l, con error = valid_user_selector(l, gr[_REG_SS]); if (error != 0) return error; + + if (!USERMODE(gr[_REG_CS], gr[_REG_RFLAGS])) + return EINVAL; #endif } else { #define VUD(sel) \ ((p->p_flag & PK_32) ? VALID_USER_DSEL32(sel) : VALID_USER_DSEL(sel)) +#define VUF(sel) /* XXX: Shouldn't this be FSEL32? */ \ +((p->p_flag & PK_32) ? VALID_USER_DSEL32(sel) : VALID_USER_DSEL(sel)) +#define VUG(sel) \ +((p->p_flag & PK_32) ? VALID_USER_GSEL32(sel) : VALID_USER_DSEL(sel)) +#define VUC(sel) \ +((p->p_flag & PK_32) ? VALID_USER_CSEL32(sel) : VALID_USER_CSEL(sel)) + sel = gr[_REG_ES] & 0x; if (sel != 0 && !VUD(sel)) return EINVAL; -/* XXX: Shouldn't this be FSEL32? */ -#define VUF(sel) \ -((p->p_flag & PK_32) ? VALID_USER_DSEL32(sel) : VALID_USER_DSEL(sel)) sel = gr[_REG_FS] & 0x; if (sel != 0 && !VUF(sel)) return EINVAL; -#define VUG(sel) \ -((p->p_flag & PK_32) ? VALID_USER_GSEL32(sel) : VALID_USER_DSEL(sel)) sel = gr[_REG_GS] & 0x; if (sel != 0 && !VUG(sel)) return EINVAL; @@ -1968,17 +1973,12 @@ cpu_mcontext_validate(struct lwp *l, con sel = gr[_REG_SS] & 0x; if (!VUD(sel)) return EINVAL; -#endif - - } -#ifndef XEN -#define VUC(sel) \ -((p->p_flag & PK_32) ? VALID_USER_CSEL32(sel) : VALID_USER_CSEL(sel)) - sel = gr[_REG_CS] & 0x; - if (!VUC(sel)) - return EINVAL; + sel = gr[_REG_CS] & 0x; + if (!VUC(sel)) + return EINVAL; #endif + } if (gr[_REG_RIP] >= VM_MAXUSER_ADDRESS) return EINVAL; @@ -1991,34 +1991,17 @@ cpu_initclocks(void) (*initclock_func)(); } +/* + * Called only when the LDT is user-set (USER_LDT). + */ static int valid_user_selector(struct lwp *l, uint64_t seg) { - int off, len; - char *dt; - struct mem_segment_descriptor *sdp; - struct proc *p = l->l_proc; - struct pmap *pmap= p->p_vmspace->vm_map.pmap; - uint64_t base; - seg &= 0x; - if (seg == 0) return 0; - off = (seg & 0xfff8); - if (seg & SEL_LDT) { - if (pmap->pm_ldt != NULL) { - len = pmap->pm_ldt_len; /* XXX broken */ - dt = (char *)pmap->pm_ldt; - } else { - dt = ldtstore; - len = LDT_SIZE; - } - - if (off > (len - 8)) - return EINVAL; - } else { + if (!(seg & SEL_LDT)) { CTASSERT(GUDATA_SEL & SEL_LDT); KASSERT(seg != GUDATA_SEL); CTASSERT(GUDATA32_SEL & SEL_LDT); @@ -2026,17 +2009,6 @@ valid_user_selector(struct lwp *l, uint6 return EINVAL; } - sdp = (struct mem_segment_descriptor *)(dt + off); - if (sdp->sd_type < SDT_MEMRO || sdp->sd_p == 0) - return EINVAL; - - base = ((uint64_t)sdp->sd_hibase << 32) | ((uint64_t)sdp->sd_lobase); - if (sdp->sd_gran == 1) - base <<= PAGE_SHIFT; - - if (base >= VM_MAXUSER_ADDRESS) - return EINVAL; - return 0; }
CVS commit: src/sys
Module Name:src Committed By: maxv Date: Sun Feb 5 10:42:22 UTC 2017 Modified Files: src/sys/arch/i386/i386: gdt.c machdep.c src/sys/arch/i386/include: segments.h src/sys/arch/x86/x86: sys_machdep.c src/sys/arch/xen/x86: cpu.c xenfunc.c src/sys/compat/linux/arch/i386: linux_machdep.c Log Message: Rename ldt->ldtstore and gdt->gdtstore on i386. It reduces the diff with amd64, and makes it easier to track down these variables on nxr - 'ldt' and 'gdt' being common keywords. To generate a diff of this commit: cvs rdiff -u -r1.56 -r1.57 src/sys/arch/i386/i386/gdt.c cvs rdiff -u -r1.777 -r1.778 src/sys/arch/i386/i386/machdep.c cvs rdiff -u -r1.57 -r1.58 src/sys/arch/i386/include/segments.h cvs rdiff -u -r1.30 -r1.31 src/sys/arch/x86/x86/sys_machdep.c cvs rdiff -u -r1.107 -r1.108 src/sys/arch/xen/x86/cpu.c cvs rdiff -u -r1.15 -r1.16 src/sys/arch/xen/x86/xenfunc.c cvs rdiff -u -r1.162 -r1.163 src/sys/compat/linux/arch/i386/linux_machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/i386/i386/gdt.c diff -u src/sys/arch/i386/i386/gdt.c:1.56 src/sys/arch/i386/i386/gdt.c:1.57 --- src/sys/arch/i386/i386/gdt.c:1.56 Sat Dec 17 14:27:53 2016 +++ src/sys/arch/i386/i386/gdt.c Sun Feb 5 10:42:21 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: gdt.c,v 1.56 2016/12/17 14:27:53 maxv Exp $ */ +/* $NetBSD: gdt.c,v 1.57 2017/02/05 10:42:21 maxv Exp $ */ /*- * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.56 2016/12/17 14:27:53 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.57 2017/02/05 10:42:21 maxv Exp $"); #include "opt_multiprocessor.h" #include "opt_xen.h" @@ -85,7 +85,7 @@ void setgdt(int sel, const void *base, size_t limit, int type, int dpl, int def32, int gran) { - struct segment_descriptor *sd = [sel].sd; + struct segment_descriptor *sd = [sel].sd; CPU_INFO_ITERATOR cii; struct cpu_info *ci; @@ -115,8 +115,8 @@ gdt_init(void) vaddr_t va; struct cpu_info *ci = _info_primary; - max_len = MAXGDTSIZ * sizeof(gdt[0]); - min_len = MINGDTSIZ * sizeof(gdt[0]); + max_len = MAXGDTSIZ * sizeof(gdtstore[0]); + min_len = MINGDTSIZ * sizeof(gdtstore[0]); gdt_size[0] = MINGDTSIZ; gdt_count[0] = NGDT; @@ -130,10 +130,11 @@ gdt_init(void) gdt_free[1] = GNULL_SEL; #endif - old_gdt = gdt; - gdt = (union descriptor *)uvm_km_alloc(kernel_map, max_len, + old_gdt = gdtstore; + gdtstore = (union descriptor *)uvm_km_alloc(kernel_map, max_len, 0, UVM_KMF_VAONLY); - for (va = (vaddr_t)gdt; va < (vaddr_t)gdt + min_len; va += PAGE_SIZE) { + for (va = (vaddr_t)gdtstore; va < (vaddr_t)gdtstore + min_len; + va += PAGE_SIZE) { pg = uvm_pagealloc(NULL, 0, NULL, UVM_PGA_ZERO); if (pg == NULL) { panic("gdt_init: no pages"); @@ -142,8 +143,8 @@ gdt_init(void) VM_PROT_READ | VM_PROT_WRITE, 0); } pmap_update(pmap_kernel()); - memcpy(gdt, old_gdt, NGDT * sizeof(gdt[0])); - ci->ci_gdt = gdt; + memcpy(gdtstore, old_gdt, NGDT * sizeof(gdtstore[0])); + ci->ci_gdt = gdtstore; setsegment(>ci_gdt[GCPU_SEL].sd, ci, sizeof(struct cpu_info) - 1, SDT_MEMRWA, SEL_KPL, 1, 0); @@ -156,8 +157,8 @@ gdt_init(void) void gdt_alloc_cpu(struct cpu_info *ci) { - int max_len = MAXGDTSIZ * sizeof(gdt[0]); - int min_len = MINGDTSIZ * sizeof(gdt[0]); + int max_len = MAXGDTSIZ * sizeof(gdtstore[0]); + int min_len = MINGDTSIZ * sizeof(gdtstore[0]); struct vm_page *pg; vaddr_t va; @@ -174,7 +175,7 @@ gdt_alloc_cpu(struct cpu_info *ci) } pmap_update(pmap_kernel()); memset(ci->ci_gdt, 0, min_len); - memcpy(ci->ci_gdt, gdt, gdt_count[0] * sizeof(gdt[0])); + memcpy(ci->ci_gdt, gdtstore, gdt_count[0] * sizeof(gdtstore[0])); setsegment(>ci_gdt[GCPU_SEL].sd, ci, sizeof(struct cpu_info) - 1, SDT_MEMRWA, SEL_KPL, 1, 0); } @@ -191,11 +192,11 @@ gdt_init_cpu(struct cpu_info *ci) struct region_descriptor region; size_t max_len; - max_len = MAXGDTSIZ * sizeof(gdt[0]); + max_len = MAXGDTSIZ * sizeof(gdtstore[0]); setregion(, ci->ci_gdt, max_len - 1); lgdt(); #else - size_t len = gdt_size[0] * sizeof(gdt[0]); + size_t len = gdt_size[0] * sizeof(gdtstore[0]); unsigned long frames[len >> PAGE_SHIFT]; vaddr_t va; pt_entry_t *ptp; @@ -233,7 +234,7 @@ gdt_reload_cpu(struct cpu_info *ci) struct region_descriptor region; size_t max_len; - max_len = MAXGDTSIZ * sizeof(gdt[0]); + max_len = MAXGDTSIZ * sizeof(gdtstore[0]); setregion(, ci->ci_gdt, max_len - 1); lgdt(); } @@ -252,16 +253,16 @@ gdt_grow(int which) struct vm_page *pg; vaddr_t va; - old_len = gdt_size[which] * sizeof(gdt[0]); + old_len = gdt_size[which] * sizeof(gdtstore[0]); gdt_size[which] <<= 1; new_len = old_len << 1; #ifdef XEN if (which != 0) { - size_t max_len = MAXGDTSIZ * sizeof(gdt[0]); + size_t max_len = MAXGDTSIZ * sizeof(gdtstore[0]); if
CVS commit: src/sys/arch/amd64
Module Name:src Committed By: maxv Date: Mon Feb 6 16:02:18 UTC 2017 Modified Files: src/sys/arch/amd64/amd64: netbsd32_machdep.c src/sys/arch/amd64/include: netbsd32_machdep.h Log Message: Add the USER_LDT sysarch options in netbsd32. We don't translate 'desc', since if we ever implement USER_LDT we will only allow 8-byte-sized entries, which have the same layout on amd64 and i386. To generate a diff of this commit: cvs rdiff -u -r1.99 -r1.100 src/sys/arch/amd64/amd64/netbsd32_machdep.c cvs rdiff -u -r1.20 -r1.21 src/sys/arch/amd64/include/netbsd32_machdep.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/netbsd32_machdep.c diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.99 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.100 --- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.99 Sun Feb 5 08:52:11 2017 +++ src/sys/arch/amd64/amd64/netbsd32_machdep.c Mon Feb 6 16:02:17 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_machdep.c,v 1.99 2017/02/05 08:52:11 maxv Exp $ */ +/* $NetBSD: netbsd32_machdep.c,v 1.100 2017/02/06 16:02:17 maxv Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.99 2017/02/05 08:52:11 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.100 2017/02/06 16:02:17 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -50,6 +50,7 @@ __KERNEL_RCSID(0, "$NetBSD: netbsd32_mac #include #include #include +#include #include #include #include @@ -83,6 +84,14 @@ __KERNEL_RCSID(0, "$NetBSD: netbsd32_mac const char machine32[] = "i386"; const char machine_arch32[] = "i386"; +#ifdef USER_LDT +static int x86_64_get_ldt32(struct lwp *, void *, register_t *); +static int x86_64_set_ldt32(struct lwp *, void *, register_t *); +#else +#define x86_64_get_ldt32(x, y, z) ENOSYS +#define x86_64_set_ldt32(x, y, z) ENOSYS +#endif + #ifdef MTRR static int x86_64_get_mtrr32(struct lwp *, void *, register_t *); static int x86_64_set_mtrr32(struct lwp *, void *, register_t *); @@ -575,6 +584,14 @@ netbsd32_sysarch(struct lwp *l, const st error = x86_iopl(l, NETBSD32PTR64(SCARG(uap, parms)), retval); break; + case X86_GET_LDT: + error = x86_64_get_ldt32(l, + NETBSD32PTR64(SCARG(uap, parms)), retval); + break; + case X86_SET_LDT: + error = x86_64_set_ldt32(l, + NETBSD32PTR64(SCARG(uap, parms)), retval); + break; case X86_GET_MTRR: error = x86_64_get_mtrr32(l, NETBSD32PTR64(SCARG(uap, parms)), retval); @@ -590,6 +607,70 @@ netbsd32_sysarch(struct lwp *l, const st return error; } +#ifdef USER_LDT +static int +x86_64_set_ldt32(struct lwp *l, void *args, register_t *retval) +{ + struct x86_set_ldt_args32 ua32; + struct x86_set_ldt_args ua; + union descriptor *descv; + int error; + + if ((error = copyin(args, , sizeof(ua32))) != 0) + return (error); + + ua.start = ua32.start; + ua.num = ua32.num; + + if (ua.num < 0 || ua.num > 8192) + return EINVAL; + + descv = malloc(sizeof(*descv) * ua.num, M_TEMP, M_NOWAIT); + if (descv == NULL) + return ENOMEM; + + error = copyin((void *)(uintptr_t)ua32.desc, descv, + sizeof(*descv) * ua.num); + if (error == 0) + error = x86_set_ldt1(l, , descv); + *retval = ua.start; + + free(descv, M_TEMP); + return error; +} + +static int +x86_64_get_ldt32(struct lwp *l, void *args, register_t *retval) +{ + struct x86_get_ldt_args32 ua32; + struct x86_get_ldt_args ua; + union descriptor *cp; + int error; + + if ((error = copyin(args, , sizeof(ua32))) != 0) + return error; + + ua.start = ua32.start; + ua.num = ua32.num; + + if (ua.num < 0 || ua.num > 8192) + return EINVAL; + + cp = malloc(ua.num * sizeof(union descriptor), M_TEMP, M_WAITOK); + if (cp == NULL) + return ENOMEM; + + error = x86_get_ldt1(l, , cp); + *retval = ua.num; + if (error == 0) + error = copyout(cp, (void *)(uintptr_t)ua32.desc, + ua.num * sizeof(*cp)); + + free(cp, M_TEMP); + return error; +} +#endif + #ifdef MTRR static int x86_64_get_mtrr32(struct lwp *l, void *args, register_t *retval) Index: src/sys/arch/amd64/include/netbsd32_machdep.h diff -u src/sys/arch/amd64/include/netbsd32_machdep.h:1.20 src/sys/arch/amd64/include/netbsd32_machdep.h:1.21 --- src/sys/arch/amd64/include/netbsd32_machdep.h:1.20 Wed Oct 19 09:44:00 2016 +++ src/sys/arch/amd64/include/netbsd32_machdep.h Mon Feb 6 16:02:17 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_machdep.h,v 1.20 2016/10/19 09:44:00 skrll Exp $ */ +/* $NetBSD: netbsd32_machdep.h,v 1.21 2017/02/06 16:02:17 maxv Exp $ */ #ifndef _MACHINE_NETBSD32_H_ #define _MACHINE_NETBSD32_H_ @@ -114,6 +114,18 @@ struct fpreg32 { char __data[108]; }; +struct x86_get_ldt_args32 { + int32_t start; + uint32_t desc; + int32_t num; +}; + +struct x86_set_ldt_args32 { + int32_t start; + uint32_t desc; + int32_t num; +}; + struct mtrr32 { uint64_t
CVS commit: src/sys/arch/amd64/amd64
Module Name:src Committed By: maxv Date: Mon Feb 6 16:34:37 UTC 2017 Modified Files: src/sys/arch/amd64/amd64: netbsd32_machdep.c Log Message: In cpu_mcontext32_validate, allow the registers to have different locations if the LDT is user-set. I am intentionally not allowing this in check_sigcontext32, because I don't think Wine uses it. To generate a diff of this commit: cvs rdiff -u -r1.100 -r1.101 src/sys/arch/amd64/amd64/netbsd32_machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/netbsd32_machdep.c diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.100 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.101 --- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.100 Mon Feb 6 16:02:17 2017 +++ src/sys/arch/amd64/amd64/netbsd32_machdep.c Mon Feb 6 16:34:37 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_machdep.c,v 1.100 2017/02/06 16:02:17 maxv Exp $ */ +/* $NetBSD: netbsd32_machdep.c,v 1.101 2017/02/06 16:34:37 maxv Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.100 2017/02/06 16:02:17 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.101 2017/02/06 16:34:37 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -1016,6 +1016,7 @@ check_sigcontext32(struct lwp *l, const int cpu_mcontext32_validate(struct lwp *l, const mcontext32_t *mcp) { + struct pmap *pmap = l->l_proc->p_vmspace->vm_map.pmap; const __greg32_t *gr; struct trapframe *tf; struct pcb *pcb; @@ -1024,22 +1025,31 @@ cpu_mcontext32_validate(struct lwp *l, c tf = l->l_md.md_regs; pcb = lwp_getpcb(l); - if (((gr[_REG32_EFL] ^ tf->tf_rflags) & PSL_USERSTATIC) != 0 || - !VALID_USER_CSEL32(gr[_REG32_CS])) - return EINVAL; - if (gr[_REG32_FS] != 0 && !VALID_USER_DSEL32(gr[_REG32_FS]) && - !(VALID_USER_FSEL32(gr[_REG32_FS]) && pcb->pcb_fs != 0)) - return EINVAL; - if (gr[_REG32_GS] != 0 && !VALID_USER_DSEL32(gr[_REG32_GS]) && - !(VALID_USER_GSEL32(gr[_REG32_GS]) && pcb->pcb_gs != 0)) - return EINVAL; - if (gr[_REG32_ES] != 0 && !VALID_USER_DSEL32(gr[_REG32_ES])) - return EINVAL; - if (!VALID_USER_DSEL32(gr[_REG32_DS]) || - !VALID_USER_DSEL32(gr[_REG32_SS])) - return EINVAL; - if (gr[_REG32_EIP] >= VM_MAXUSER_ADDRESS32) + if (((gr[_REG32_EFL] ^ tf->tf_rflags) & PSL_USERSTATIC) != 0) return EINVAL; + + if (__predict_false(pmap->pm_ldt != NULL)) { + /* Only when the LDT is user-set (with USER_LDT) */ + if (!USERMODE(gr[_REG32_CS], gr[_REG32_EFL])) + return EINVAL; + } else { + if (!VALID_USER_CSEL32(gr[_REG32_CS])) + return EINVAL; + if (gr[_REG32_FS] != 0 && !VALID_USER_DSEL32(gr[_REG32_FS]) && + !(VALID_USER_FSEL32(gr[_REG32_FS]) && pcb->pcb_fs != 0)) + return EINVAL; + if (gr[_REG32_GS] != 0 && !VALID_USER_DSEL32(gr[_REG32_GS]) && + !(VALID_USER_GSEL32(gr[_REG32_GS]) && pcb->pcb_gs != 0)) + return EINVAL; + if (gr[_REG32_ES] != 0 && !VALID_USER_DSEL32(gr[_REG32_ES])) + return EINVAL; + if (!VALID_USER_DSEL32(gr[_REG32_DS]) || + !VALID_USER_DSEL32(gr[_REG32_SS])) + return EINVAL; + if (gr[_REG32_EIP] >= VM_MAXUSER_ADDRESS32) + return EINVAL; + } + return 0; }
CVS commit: src/sys/arch
Module Name:src Committed By: maxv Date: Wed Feb 8 10:08:26 UTC 2017 Modified Files: src/sys/arch/amd64/amd64: gdt.c src/sys/arch/amd64/include: gdt.h src/sys/arch/i386/i386: gdt.c src/sys/arch/i386/include: gdt.h src/sys/arch/x86/x86: ipi.c Log Message: Remove gdt_reload_cpu. GDTR takes a VA as base, and in our x86 implementation this VA is per-cpu and does not change; there is therefore no need to remotely reload GDTR. To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/sys/arch/amd64/amd64/gdt.c cvs rdiff -u -r1.9 -r1.10 src/sys/arch/amd64/include/gdt.h cvs rdiff -u -r1.58 -r1.59 src/sys/arch/i386/i386/gdt.c cvs rdiff -u -r1.14 -r1.15 src/sys/arch/i386/include/gdt.h cvs rdiff -u -r1.26 -r1.27 src/sys/arch/x86/x86/ipi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/gdt.c diff -u src/sys/arch/amd64/amd64/gdt.c:1.35 src/sys/arch/amd64/amd64/gdt.c:1.36 --- src/sys/arch/amd64/amd64/gdt.c:1.35 Wed Feb 8 09:39:32 2017 +++ src/sys/arch/amd64/amd64/gdt.c Wed Feb 8 10:08:26 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: gdt.c,v 1.35 2017/02/08 09:39:32 maxv Exp $ */ +/* $NetBSD: gdt.c,v 1.36 2017/02/08 10:08:26 maxv Exp $ */ /*- * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.35 2017/02/08 09:39:32 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.36 2017/02/08 10:08:26 maxv Exp $"); #include "opt_multiprocessor.h" #include "opt_xen.h" @@ -208,21 +208,6 @@ gdt_init_cpu(struct cpu_info *ci) lgdt(); } -#ifdef MULTIPROCESSOR -void -gdt_reload_cpu(struct cpu_info *ci) -{ - struct region_descriptor region; - -#ifndef XEN - setregion(, ci->ci_gdt, MAXGDTSIZ - 1); -#else - setregion(, ci->ci_gdt, gdt_size - 1); -#endif - lgdt(); -} -#endif - #if !defined(XEN) || defined(USER_LDT) /* * Grow the GDT. The GDT is present on each CPU, so we need to iterate over all Index: src/sys/arch/amd64/include/gdt.h diff -u src/sys/arch/amd64/include/gdt.h:1.9 src/sys/arch/amd64/include/gdt.h:1.10 --- src/sys/arch/amd64/include/gdt.h:1.9 Wed Feb 8 09:39:32 2017 +++ src/sys/arch/amd64/include/gdt.h Wed Feb 8 10:08:26 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: gdt.h,v 1.9 2017/02/08 09:39:32 maxv Exp $ */ +/* $NetBSD: gdt.h,v 1.10 2017/02/08 10:08:26 maxv Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -35,7 +35,6 @@ struct pmap; void gdt_init(void); void gdt_init_cpu(struct cpu_info *); -void gdt_reload_cpu(struct cpu_info *); void gdt_alloc_cpu(struct cpu_info *); struct x86_64_tss; Index: src/sys/arch/i386/i386/gdt.c diff -u src/sys/arch/i386/i386/gdt.c:1.58 src/sys/arch/i386/i386/gdt.c:1.59 --- src/sys/arch/i386/i386/gdt.c:1.58 Wed Feb 8 09:39:32 2017 +++ src/sys/arch/i386/i386/gdt.c Wed Feb 8 10:08:26 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: gdt.c,v 1.58 2017/02/08 09:39:32 maxv Exp $ */ +/* $NetBSD: gdt.c,v 1.59 2017/02/08 10:08:26 maxv Exp $ */ /*- * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.58 2017/02/08 09:39:32 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.59 2017/02/08 10:08:26 maxv Exp $"); #include "opt_multiprocessor.h" #include "opt_xen.h" @@ -231,19 +231,6 @@ gdt_init_cpu(struct cpu_info *ci) #endif } -#if defined(MULTIPROCESSOR) && !defined(XEN) -void -gdt_reload_cpu(struct cpu_info *ci) -{ - struct region_descriptor region; - size_t max_len; - - max_len = MAXGDTSIZ * sizeof(gdtstore[0]); - setregion(, ci->ci_gdt, max_len - 1); - lgdt(); -} -#endif - /* * Grow the GDT. The GDT is present on each CPU, so we need to iterate over all * of them. We already have the virtual memory, we only need to grow the Index: src/sys/arch/i386/include/gdt.h diff -u src/sys/arch/i386/include/gdt.h:1.14 src/sys/arch/i386/include/gdt.h:1.15 --- src/sys/arch/i386/include/gdt.h:1.14 Sat Aug 20 16:05:48 2016 +++ src/sys/arch/i386/include/gdt.h Wed Feb 8 10:08:26 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: gdt.h,v 1.14 2016/08/20 16:05:48 maxv Exp $ */ +/* $NetBSD: gdt.h,v 1.15 2017/02/08 10:08:26 maxv Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -36,7 +36,6 @@ struct pmap; void gdt_init(void); void gdt_init_cpu(struct cpu_info *); -void gdt_reload_cpu(struct cpu_info *); void gdt_alloc_cpu(struct cpu_info *); int tss_alloc(const struct i386tss *); void tss_free(int); Index: src/sys/arch/x86/x86/ipi.c diff -u src/sys/arch/x86/x86/ipi.c:1.26 src/sys/arch/x86/x86/ipi.c:1.27 --- src/sys/arch/x86/x86/ipi.c:1.26 Sun Jul 20 15:48:54 2014 +++ src/sys/arch/x86/x86/ipi.c Wed Feb 8 10:08:26 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: ipi.c,v 1.26 2014/07/20 15:48:54 uebayasi Exp $ */ +/* $NetBSD: ipi.c,v 1.27 2017/02/08 10:08:26 maxv Exp $ */ /*- * Copyright (c) 2000, 2008, 2009 The NetBSD Foundation,
CVS commit: src/sys/arch
Module Name:src Committed By: maxv Date: Wed Feb 8 09:39:32 UTC 2017 Modified Files: src/sys/arch/amd64/amd64: gdt.c src/sys/arch/amd64/include: gdt.h src/sys/arch/i386/i386: gdt.c src/sys/arch/i386/include: segments.h Log Message: Localify, add a comment and merge some others. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/sys/arch/amd64/amd64/gdt.c cvs rdiff -u -r1.8 -r1.9 src/sys/arch/amd64/include/gdt.h cvs rdiff -u -r1.57 -r1.58 src/sys/arch/i386/i386/gdt.c cvs rdiff -u -r1.58 -r1.59 src/sys/arch/i386/include/segments.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/gdt.c diff -u src/sys/arch/amd64/amd64/gdt.c:1.34 src/sys/arch/amd64/amd64/gdt.c:1.35 --- src/sys/arch/amd64/amd64/gdt.c:1.34 Sun Aug 21 10:42:33 2016 +++ src/sys/arch/amd64/amd64/gdt.c Wed Feb 8 09:39:32 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: gdt.c,v 1.34 2016/08/21 10:42:33 maxv Exp $ */ +/* $NetBSD: gdt.c,v 1.35 2017/02/08 09:39:32 maxv Exp $ */ /*- * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.34 2016/08/21 10:42:33 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.35 2017/02/08 09:39:32 maxv Exp $"); #include "opt_multiprocessor.h" #include "opt_xen.h" @@ -63,6 +63,7 @@ int gdt_dynavail; int gdt_next; /* next available slot for sweeping */ int gdt_free; /* next free slot; terminated with GNULL_SEL */ +static void set_sys_gdt(int, void *, size_t, int, int, int); void gdt_init(void); void @@ -84,7 +85,10 @@ update_descriptor(void *tp, void *ep) #endif } -void +/* + * Called on a newly-allocated GDT slot, so no race between CPUs. + */ +static void set_sys_gdt(int slot, void *base, size_t limit, int type, int dpl, int gran) { union { Index: src/sys/arch/amd64/include/gdt.h diff -u src/sys/arch/amd64/include/gdt.h:1.8 src/sys/arch/amd64/include/gdt.h:1.9 --- src/sys/arch/amd64/include/gdt.h:1.8 Sat Aug 20 18:31:06 2016 +++ src/sys/arch/amd64/include/gdt.h Wed Feb 8 09:39:32 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: gdt.h,v 1.8 2016/08/20 18:31:06 maxv Exp $ */ +/* $NetBSD: gdt.h,v 1.9 2017/02/08 09:39:32 maxv Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -44,8 +44,6 @@ void tss_free(int); int ldt_alloc(void *, size_t); void ldt_free(int); - -void set_sys_gdt(int, void *, size_t, int, int, int); #endif #define MINGDTSIZ PAGE_SIZE Index: src/sys/arch/i386/i386/gdt.c diff -u src/sys/arch/i386/i386/gdt.c:1.57 src/sys/arch/i386/i386/gdt.c:1.58 --- src/sys/arch/i386/i386/gdt.c:1.57 Sun Feb 5 10:42:21 2017 +++ src/sys/arch/i386/i386/gdt.c Wed Feb 8 09:39:32 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: gdt.c,v 1.57 2017/02/05 10:42:21 maxv Exp $ */ +/* $NetBSD: gdt.c,v 1.58 2017/02/08 09:39:32 maxv Exp $ */ /*- * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.57 2017/02/05 10:42:21 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.58 2017/02/08 09:39:32 maxv Exp $"); #include "opt_multiprocessor.h" #include "opt_xen.h" @@ -60,6 +60,7 @@ int gdt_free[2]; /* next free slot; term static int ldt_count; /* number of LDTs */ static int ldt_max = 1000;/* max number of LDTs */ +static void setgdt(int, const void *, size_t, int, int, int, int); void gdt_init(void); static void gdt_grow(int); static int gdt_get_slot1(int); @@ -81,7 +82,10 @@ update_descriptor(union descriptor *tabl #endif } -void +/* + * Called on a newly-allocated GDT slot, so no race between CPUs. + */ +static void setgdt(int sel, const void *base, size_t limit, int type, int dpl, int def32, int gran) { @@ -104,7 +108,8 @@ setgdt(int sel, const void *base, size_t } /* - * Initialize the GDT subsystem. Called from autoconf(). + * Initialize the GDT. We already have a gdtstore, which was temporarily used + * by the bootstrap code. Now, we allocate a new gdtstore, and put it in cpu0. */ void gdt_init(void) @@ -152,7 +157,8 @@ gdt_init(void) } /* - * Allocate shadow GDT for a slave CPU. + * Allocate shadow GDT for a secondary CPU. It contains the same values as the + * GDT present in cpu0 (gdtstore). */ void gdt_alloc_cpu(struct cpu_info *ci) @@ -180,10 +186,9 @@ gdt_alloc_cpu(struct cpu_info *ci) sizeof(struct cpu_info) - 1, SDT_MEMRWA, SEL_KPL, 1, 0); } - /* - * Load appropriate gdt descriptor; we better be running on *ci - * (for the most part, this is how a CPU knows who it is). + * Load appropriate GDT descriptor into the currently running CPU, which must + * be ci. */ void gdt_init_cpu(struct cpu_info *ci) @@ -227,7 +232,6 @@ gdt_init_cpu(struct cpu_info *ci) } #if defined(MULTIPROCESSOR) && !defined(XEN) - void gdt_reload_cpu(struct cpu_info *ci) { @@ -240,9 +244,10 @@ gdt_reload_cpu(struct cpu_info *ci)
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Thu Feb 2 17:37:49 UTC 2017 Modified Files: src/sys/arch/x86/x86: pmap.c Log Message: The first va should depend on the text offset, not the kernel base. Use rounddown. Note: this value is still wrong, it should be roundup. But that's another issue that will be fixed in amd64 soon. To generate a diff of this commit: cvs rdiff -u -r1.238 -r1.239 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.238 src/sys/arch/x86/x86/pmap.c:1.239 --- src/sys/arch/x86/x86/pmap.c:1.238 Thu Feb 2 08:57:04 2017 +++ src/sys/arch/x86/x86/pmap.c Thu Feb 2 17:37:49 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.238 2017/02/02 08:57:04 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.239 2017/02/02 17:37:49 maxv Exp $ */ /*- * Copyright (c) 2008, 2010, 2016, 2017 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.238 2017/02/02 08:57:04 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.239 2017/02/02 17:37:49 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -1595,7 +1595,7 @@ pmap_remap_largepages(void) paddr_t pa; /* Remap the kernel text using large pages. */ - kva = KERNBASE; + kva = rounddown((vaddr_t)KERNTEXTOFF, NBPD_L2); kva_end = rounddown((vaddr_t)&__rodata_start, NBPD_L1); pa = kva - KERNBASE; for (/* */; kva + NBPD_L2 <= kva_end; kva += NBPD_L2, pa += NBPD_L2) {
CVS commit: src/sys/arch/xen/x86
Module Name:src Committed By: maxv Date: Sun Jan 22 19:24:52 UTC 2017 Modified Files: src/sys/arch/xen/x86: x86_xpmap.c Log Message: Export xpmap_pg_nx, and put it in the page table pages. It does not change anything, since Xen removes the X bit on these; but it is better for consistency. To generate a diff of this commit: cvs rdiff -u -r1.69 -r1.70 src/sys/arch/xen/x86/x86_xpmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/x86/x86_xpmap.c diff -u src/sys/arch/xen/x86/x86_xpmap.c:1.69 src/sys/arch/xen/x86/x86_xpmap.c:1.70 --- src/sys/arch/xen/x86/x86_xpmap.c:1.69 Fri Jan 6 08:32:26 2017 +++ src/sys/arch/xen/x86/x86_xpmap.c Sun Jan 22 19:24:51 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: x86_xpmap.c,v 1.69 2017/01/06 08:32:26 maxv Exp $ */ +/* $NetBSD: x86_xpmap.c,v 1.70 2017/01/22 19:24:51 maxv Exp $ */ /* * Copyright (c) 2006 Mathieu Ropert@@ -66,7 +66,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.69 2017/01/06 08:32:26 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.70 2017/01/22 19:24:51 maxv Exp $"); #include "opt_xen.h" #include "opt_ddb.h" @@ -105,6 +105,8 @@ unsigned long *xpmap_phys_to_machine_map kmutex_t pte_lock; vaddr_t xen_dummy_page; +pt_entry_t xpmap_pg_nx; + void xen_failsafe_handler(void); #define HYPERVISOR_mmu_update_self(req, count, success_count) \ @@ -609,6 +611,7 @@ xen_locore(void) { size_t count, oldcount, mapsize; vaddr_t bootstrap_tables, init_tables; + u_int descs[4]; xen_init_features(); @@ -617,6 +620,10 @@ xen_locore(void) xpmap_phys_to_machine_mapping = (unsigned long *)xen_start_info.mfn_list; + /* Set the NX/XD bit, if available. descs[3] = %edx. */ + x86_cpuid(0x8001, descs); + xpmap_pg_nx = (descs[3] & CPUID_NOX) ? PG_NX : 0; + /* Space after Xen boostrap tables should be free */ init_tables = xen_start_info.pt_base; bootstrap_tables = init_tables + @@ -738,14 +745,6 @@ xen_bootstrap_tables(vaddr_t old_pgd, va extern char __data_start; extern char __kernel_end; extern char *early_zerop; /* from pmap.c */ - pt_entry_t pg_nx; - u_int descs[4]; - - /* - * Set the NX/XD bit, if available. descs[3] = %edx. - */ - x86_cpuid(0x8001, descs); - pg_nx = (descs[3] & CPUID_NOX) ? PG_NX : 0; /* * Layout of RW area after the kernel image: @@ -895,7 +894,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va page < (vaddr_t)atdevbase + IOM_SIZE) { pte[pl1_pi(page)] = IOM_BEGIN + (page - (vaddr_t)atdevbase); -pte[pl1_pi(page)] |= pg_nx; +pte[pl1_pi(page)] |= xpmap_pg_nx; } #endif @@ -906,15 +905,15 @@ xen_bootstrap_tables(vaddr_t old_pgd, va } else if (page >= (vaddr_t)&__rodata_start && page < (vaddr_t)&__data_start) { /* Map the kernel rodata R. */ -pte[pl1_pi(page)] |= PG_RO | pg_nx; +pte[pl1_pi(page)] |= PG_RO | xpmap_pg_nx; } else if (page >= old_pgd && page < old_pgd + (old_count * PAGE_SIZE)) { /* Map the old page tables R. */ -pte[pl1_pi(page)] |= PG_RO | pg_nx; +pte[pl1_pi(page)] |= PG_RO | xpmap_pg_nx; } else if (page >= new_pgd && page < new_pgd + ((new_count + l2_4_count) * PAGE_SIZE)) { /* Map the new page tables R. */ -pte[pl1_pi(page)] |= PG_RO | pg_nx; +pte[pl1_pi(page)] |= PG_RO | xpmap_pg_nx; #ifdef i386 } else if (page == (vaddr_t)tmpgdt) { /* @@ -928,10 +927,10 @@ xen_bootstrap_tables(vaddr_t old_pgd, va } else if (page >= (vaddr_t)&__data_start && page < (vaddr_t)&__kernel_end) { /* Map the kernel data+bss RW. */ -pte[pl1_pi(page)] |= PG_RW | pg_nx; +pte[pl1_pi(page)] |= PG_RW | xpmap_pg_nx; } else { /* Map the page RW. */ -pte[pl1_pi(page)] |= PG_RW | pg_nx; +pte[pl1_pi(page)] |= PG_RW | xpmap_pg_nx; } page += PAGE_SIZE; @@ -962,7 +961,7 @@ xen_bootstrap_tables(vaddr_t old_pgd, va addr = (u_long)pde - KERNBASE; for (i = 0; i < 3; i++, addr += PAGE_SIZE) { pde[PDIR_SLOT_PTE + i] = xpmap_ptom_masked(addr) | PG_k | PG_V | - pg_nx; + xpmap_pg_nx; } /* Mark tables RO, and pin L2 KERN SHADOW. */ @@ -978,11 +977,11 @@ xen_bootstrap_tables(vaddr_t old_pgd, va /* Recursive entry in pmap_kernel(). */ bt_pgd[PDIR_SLOT_PTE] = xpmap_ptom_masked((paddr_t)bt_pgd - KERNBASE) - | PG_k | PG_RO | PG_V | pg_nx; + | PG_k | PG_RO | PG_V | xpmap_pg_nx; #ifdef __x86_64__ /* Recursive entry in higher-level per-cpu PD. */ bt_cpu_pgd[PDIR_SLOT_PTE] = xpmap_ptom_masked((paddr_t)bt_cpu_pgd - KERNBASE) - | PG_k | PG_RO | PG_V | pg_nx; + | PG_k | PG_RO | PG_V | xpmap_pg_nx; #endif /* Mark tables RO */ @@ -1061,23 +1060,16 @@ xen_bootstrap_tables(vaddr_t old_pgd, va xpq_flush_queue(); } - /* - * Bootstrap helper functions + * Mark a page read-only, assuming vaddr = paddr + KERNBASE. */ - -/* - * Mark a page readonly - * XXX:
CVS commit: src/sys/arch/x86/x86
Module Name:src Committed By: maxv Date: Sun Jan 22 20:04:35 UTC 2017 Modified Files: src/sys/arch/x86/x86: pmap.c Log Message: Put pmap_pg_nx into the dummy Xen page. While here, do some KNF and localify a bit. To generate a diff of this commit: cvs rdiff -u -r1.236 -r1.237 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.236 src/sys/arch/x86/x86/pmap.c:1.237 --- src/sys/arch/x86/x86/pmap.c:1.236 Fri Jan 6 09:04:06 2017 +++ src/sys/arch/x86/x86/pmap.c Sun Jan 22 20:04:35 2017 @@ -1,7 +1,7 @@ -/* $NetBSD: pmap.c,v 1.236 2017/01/06 09:04:06 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.237 2017/01/22 20:04:35 maxv Exp $ */ /*- - * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc. + * Copyright (c) 2008, 2010, 2016, 2017 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -171,7 +171,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.236 2017/01/06 09:04:06 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.237 2017/01/22 20:04:35 maxv Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -398,13 +398,9 @@ paddr_t avail_start __read_mostly; /* PA paddr_t avail_end __read_mostly; /* PA of last available physical page */ #ifdef XEN -#ifdef __x86_64__ -/* Dummy PGD for user cr3, used between pmap_deactivate() and pmap_activate() */ -static paddr_t xen_dummy_user_pgd; -#endif /* __x86_64__ */ paddr_t pmap_pa_start; /* PA of first physical page for this domain */ paddr_t pmap_pa_end; /* PA of last physical page for this domain */ -#endif /* XEN */ +#endif #define VM_PAGE_TO_PP(pg) (&(pg)->mdpage.mp_pp) @@ -1390,10 +1386,12 @@ pmap_bootstrap(vaddr_t kva_start) #if defined(XEN) && defined(__x86_64__) extern vaddr_t xen_dummy_page; + paddr_t xen_dummy_user_pgd; + /* - * We want a dummy page directory for Xen: when deactivating a pmap, Xen - * will still consider it active. So we set user PGD to this one to lift - * all protection on the now inactive page tables set. + * We want a dummy page directory for Xen: when deactivating a pmap, + * Xen will still consider it active. So we set user PGD to this one + * to lift all protection on the now inactive page tables set. */ xen_dummy_user_pgd = xen_dummy_page - KERNBASE; @@ -1401,7 +1399,8 @@ pmap_bootstrap(vaddr_t kva_start) memset((void *)(xen_dummy_user_pgd + KERNBASE), 0, PAGE_SIZE); /* Mark read-only */ HYPERVISOR_update_va_mapping(xen_dummy_user_pgd + KERNBASE, - pmap_pa2pte(xen_dummy_user_pgd) | PG_u | PG_V, UVMF_INVLPG); + pmap_pa2pte(xen_dummy_user_pgd) | PG_u | PG_V | pmap_pg_nx, + UVMF_INVLPG); /* Pin as L4 */ xpq_queue_pin_l4_table(xpmap_ptom_masked(xen_dummy_user_pgd)); #endif
CVS commit: src/sys/arch/xen/x86
Module Name:src Committed By: maxv Date: Sun Jan 22 19:42:48 UTC 2017 Modified Files: src/sys/arch/xen/x86: cpu.c Log Message: Import xpmap_pg_nx, and put it in the per-cpu recursive slot on amd64. To generate a diff of this commit: cvs rdiff -u -r1.105 -r1.106 src/sys/arch/xen/x86/cpu.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/x86/cpu.c diff -u src/sys/arch/xen/x86/cpu.c:1.105 src/sys/arch/xen/x86/cpu.c:1.106 --- src/sys/arch/xen/x86/cpu.c:1.105 Fri Nov 25 12:20:03 2016 +++ src/sys/arch/xen/x86/cpu.c Sun Jan 22 19:42:48 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.c,v 1.105 2016/11/25 12:20:03 maxv Exp $ */ +/* $NetBSD: cpu.c,v 1.106 2017/01/22 19:42:48 maxv Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -65,7 +65,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.105 2016/11/25 12:20:03 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.106 2017/01/22 19:42:48 maxv Exp $"); #include "opt_ddb.h" #include "opt_multiprocessor.h" @@ -1218,20 +1218,19 @@ pmap_cpu_init_late(struct cpu_info *ci) KASSERT(ci->ci_kpm_pdirpa != 0); #if defined(__x86_64__) - /* - * Copy over the pmap_kernel() shadow L4 entries - */ + extern pt_entry_t xpmap_pg_nx; + /* Copy over the pmap_kernel() shadow L4 entries */ memcpy(ci->ci_kpm_pdir, pmap_kernel()->pm_pdir, PAGE_SIZE); /* Recursive kernel mapping */ ci->ci_kpm_pdir[PDIR_SLOT_PTE] = xpmap_ptom_masked(ci->ci_kpm_pdirpa) - | PG_k | PG_V; + | PG_k | PG_V | xpmap_pg_nx; #elif defined(PAE) - /* Copy over the pmap_kernel() shadow L2 entries that map the kernel */ + /* Copy over the pmap_kernel() shadow L2 entries */ memcpy(ci->ci_kpm_pdir, pmap_kernel()->pm_pdir + PDIR_SLOT_KERN, nkptp[PTP_LEVELS - 1] * sizeof(pd_entry_t)); -#endif /* __x86_64__ else PAE */ +#endif /* Xen wants a RO pdir. */ pmap_protect(pmap_kernel(), (vaddr_t)ci->ci_kpm_pdir,
CVS commit: src/sys/arch/i386/i386
Module Name:src Committed By: maxv Date: Sun Jan 22 20:17:10 UTC 2017 Modified Files: src/sys/arch/i386/i386: machdep.c Log Message: Use xpmap_pg_nx. Not tested (due to some unrelated panic I'm getting), but obvious enough. To generate a diff of this commit: cvs rdiff -u -r1.776 -r1.777 src/sys/arch/i386/i386/machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/i386/i386/machdep.c diff -u src/sys/arch/i386/i386/machdep.c:1.776 src/sys/arch/i386/i386/machdep.c:1.777 --- src/sys/arch/i386/i386/machdep.c:1.776 Mon Dec 26 17:54:06 2016 +++ src/sys/arch/i386/i386/machdep.c Sun Jan 22 20:17:10 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.776 2016/12/26 17:54:06 cherry Exp $ */ +/* $NetBSD: machdep.c,v 1.777 2017/01/22 20:17:10 maxv Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009 @@ -67,7 +67,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.776 2016/12/26 17:54:06 cherry Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.777 2017/01/22 20:17:10 maxv Exp $"); #include "opt_beep.h" #include "opt_compat_ibcs2.h" @@ -1006,11 +1006,11 @@ initgdt(union descriptor *tgdt) * which are in the callpath of pmap_kenter_pa(). * So we mash up our own - this is MD code anyway. */ + extern pt_entry_t xpmap_pg_nx; pt_entry_t pte; - pt_entry_t pg_nx = (cpu_feature[2] & CPUID_NOX ? PG_NX : 0); pte = pmap_pa2pte((vaddr_t)gdt - KERNBASE); - pte |= PG_k | PG_RO | pg_nx | PG_V; + pte |= PG_k | PG_RO | xpmap_pg_nx | PG_V; if (HYPERVISOR_update_va_mapping((vaddr_t)gdt, pte, UVMF_INVLPG) < 0) { panic("gdt page RO update failed.\n"); @@ -1208,11 +1208,11 @@ init386(paddr_t first_avail) /* Reclaim the boot gdt page - see locore.s */ { + extern pt_entry_t xpmap_pg_nx; pt_entry_t pte; - pt_entry_t pg_nx = (cpu_feature[2] & CPUID_NOX ? PG_NX : 0); pte = pmap_pa2pte((vaddr_t)tmpgdt - KERNBASE); - pte |= PG_k | PG_RW | pg_nx | PG_V; + pte |= PG_k | PG_RW | xpmap_pg_nx | PG_V; if (HYPERVISOR_update_va_mapping((vaddr_t)tmpgdt, pte, UVMF_INVLPG) < 0) { panic("tmpgdt page relaim RW update failed.\n");