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 <sys/cdefs.h>
-__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, &kva, 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)) {

Reply via email to