km_alloc(9) is still not a full replacement for uvm_km_alloc(9).  The
latter allows the protections of the allocation to be changed to
PROT_EXEC via uvm_map_protect(9).  This is needed at least by the sti(4)
driver.

Diff below changes km_alloc(9) to allow PROT_EXEC in maxprot.  With this
it is possible to convert sti(4).

However this implies that all current allocations can now have their
protection changed to be executable.  This might not be what we want, in
such case I'd suggest adding a new `kp_protexec' to "struct kmem_pa_mode"
and set it specifically in dev/ic/sti.c.

Comments?

Index: uvm/uvm_km.c
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_km.c,v
retrieving revision 1.132
diff -u -p -r1.132 uvm_km.c
--- uvm/uvm_km.c        18 Jul 2019 23:47:33 -0000      1.132
+++ uvm/uvm_km.c        2 Nov 2019 21:15:55 -0000
@@ -813,7 +813,7 @@ km_alloc(size_t sz, const struct kmem_va
        struct vm_page *pg;
        struct pglist pgl;
        int mapflags = 0;
-       vm_prot_t prot;
+       vm_prot_t prot, maxprot;
        paddr_t pla_align;
        int pla_flags;
        int pla_maxseg;
@@ -862,6 +862,7 @@ km_alloc(size_t sz, const struct kmem_va
 #endif
 alloc_va:
        prot = PROT_READ | PROT_WRITE;
+       maxprot = prot | PROT_EXEC;
 
        if (kp->kp_pageable) {
                KASSERT(kp->kp_object);
@@ -906,7 +907,7 @@ try_map:
                map = *kv->kv_map;
                va = vm_map_min(map);
                if (uvm_map(map, &va, sz, uobj, kd->kd_prefer,
-                   kv->kv_align, UVM_MAPFLAG(prot, prot, MAP_INHERIT_NONE,
+                   kv->kv_align, UVM_MAPFLAG(prot, maxprot, MAP_INHERIT_NONE,
                    MADV_RANDOM, mapflags))) {
                        if (kv->kv_wait && kd->kd_waitok) {
                                tsleep(map, PVM, "km_allocva", 0);

Reply via email to