Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/uvm mmap(2): If we fail with a hint, try again without it.



details:   https://anonhg.NetBSD.org/src/rev/0abe0319b08a
branches:  trunk
changeset: 365701:0abe0319b08a
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Tue Apr 19 01:34:52 2022 +0000

description:
mmap(2): If we fail with a hint, try again without it.

`Hint' here means nonzero addr, but no MAP_FIXED or MAP_TRYFIXED.

This is suboptimal -- we could teach uvm_mmap to do a fancier search
using the address as a hint.  But this should do for now.

Candidate fix for PR kern/55533.

ok chs@

diffstat:

 sys/uvm/uvm_mmap.c |  26 ++++++++++++++++++++++----
 1 files changed, 22 insertions(+), 4 deletions(-)

diffs (64 lines):

diff -r c88e92e133f9 -r 0abe0319b08a sys/uvm/uvm_mmap.c
--- a/sys/uvm/uvm_mmap.c        Mon Apr 18 19:46:35 2022 +0000
+++ b/sys/uvm/uvm_mmap.c        Tue Apr 19 01:34:52 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_mmap.c,v 1.177 2022/03/27 20:18:05 hannken Exp $   */
+/*     $NetBSD: uvm_mmap.c,v 1.178 2022/04/19 01:34:52 riastradh Exp $ */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -46,7 +46,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_mmap.c,v 1.177 2022/03/27 20:18:05 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_mmap.c,v 1.178 2022/04/19 01:34:52 riastradh Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_pax.h"
@@ -277,7 +277,8 @@
        vsize_t size, pageoff, newsize;
        vm_prot_t prot, maxprot, extraprot;
        int flags, fd, advice;
-       vaddr_t defaddr;
+       vaddr_t defaddr = 0;    /* XXXGCC */
+       bool addrhint = false;
        struct file *fp = NULL;
        struct uvm_object *uobj;
        int error;
@@ -349,6 +350,12 @@
                        addr = MAX(addr, defaddr);
                else
                        addr = MIN(addr, defaddr);
+
+               /*
+                * If addr is nonzero and not the default, then the
+                * address is a hint.
+                */
+               addrhint = (addr != 0 && addr != defaddr);
        }
 
        /*
@@ -401,10 +408,21 @@
        /*
         * now let kernel internal function uvm_mmap do the work.
         */
-
        error = uvm_mmap(&p->p_vmspace->vm_map, &addr, size, prot, maxprot,
            flags, advice, uobj, pos, p->p_rlimit[RLIMIT_MEMLOCK].rlim_cur);
 
+       /*
+        * If the user provided a hint, and we couldn't satisfy that
+        * hint, try again with the default address.
+        */
+       if (error && addrhint) {
+               addr = defaddr;
+               pax_aslr_mmap(l, &addr, orig_addr, flags);
+               error = uvm_mmap(&p->p_vmspace->vm_map, &addr, size, prot,
+                   maxprot, flags, advice, uobj, pos,
+                   p->p_rlimit[RLIMIT_MEMLOCK].rlim_cur);
+       }
+
        /* remember to add offset */
        *retval = (register_t)(addr + pageoff);
 



Home | Main Index | Thread Index | Old Index