Source-Changes-HG archive

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

[src/trunk]: src/sys/uvm Update uvm_pglistalloc_[cs]_ps to return EINVAL if [...



details:   https://anonhg.NetBSD.org/src/rev/7bad7cb71635
branches:  trunk
changeset: 1029081:7bad7cb71635
user:      skrll <skrll%NetBSD.org@localhost>
date:      Tue Dec 21 08:27:49 2021 +0000

description:
Update uvm_pglistalloc_[cs]_ps to return EINVAL if [low, high] doesn't
match any memory.

Useful for bus_dmamem_alloc where a tag might not cover any memory.
This will be used in an update to ehci.

"looks good" from chuq@

diffstat:

 sys/uvm/uvm_pglist.c |  33 ++++++++++++++++++++++++++-------
 1 files changed, 26 insertions(+), 7 deletions(-)

diffs (103 lines):

diff -r c6f42576031b -r 7bad7cb71635 sys/uvm/uvm_pglist.c
--- a/sys/uvm/uvm_pglist.c      Tue Dec 21 07:11:02 2021 +0000
+++ b/sys/uvm/uvm_pglist.c      Tue Dec 21 08:27:49 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_pglist.c,v 1.89 2021/12/20 22:40:46 skrll Exp $    */
+/*     $NetBSD: uvm_pglist.c,v 1.90 2021/12/21 08:27:49 skrll Exp $    */
 
 /*-
  * Copyright (c) 1997, 2019 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_pglist.c,v 1.89 2021/12/20 22:40:46 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_pglist.c,v 1.90 2021/12/21 08:27:49 skrll Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -131,7 +131,7 @@
         */
        if (high <= uvm_physseg_get_avail_start(psi) ||
            low >= uvm_physseg_get_avail_end(psi))
-               return 0;
+               return -1;
 
        /*
         * We start our search at the just after where the last allocation
@@ -456,6 +456,7 @@
 
        /* Default to "lose". */
        error = ENOMEM;
+       bool valid = false;
 
        /*
         * Block all memory allocation and lock the free list.
@@ -477,8 +478,12 @@
                        if (uvm_physseg_get_free_list(psi) != fl)
                                continue;
 
-                       num -= uvm_pglistalloc_c_ps(psi, num, low, high,
-                                                   alignment, boundary, rlist);
+                       int done = uvm_pglistalloc_c_ps(psi, num, low, high,
+                           alignment, boundary, rlist);
+                       if (done >= 0) {
+                               valid = true;
+                               num -= done;
+                       }
                        if (num == 0) {
 #ifdef PGALLOC_VERBOSE
                                printf("pgalloc: %"PRIxMAX"-%"PRIxMAX"\n",
@@ -490,6 +495,10 @@
                        }
                }
        }
+       if (!valid) {
+               uvm_pgfl_unlock();
+               return EINVAL;
+       }
 
 out:
        uvm_pgfl_unlock();
@@ -534,7 +543,7 @@
         */
        if (high <= uvm_physseg_get_avail_start(psi) ||
            low >= uvm_physseg_get_avail_end(psi))
-               return 0;
+               return -1;
 
        todo = num;
        candidate = uimax(low, uvm_physseg_get_avail_start(psi) +
@@ -609,6 +618,7 @@
 
        /* Default to "lose". */
        error = ENOMEM;
+       bool valid = false;
 
 again:
        /*
@@ -632,7 +642,12 @@
                        if (uvm_physseg_get_free_list(psi) != fl)
                                continue;
 
-                       num -= uvm_pglistalloc_s_ps(psi, num, low, high, rlist);
+                       int done = uvm_pglistalloc_s_ps(psi, num, low, high,
+                            rlist);
+                       if (done >= 0) {
+                               valid = true;
+                               num -= done;
+                       }
                        if (num == 0) {
                                error = 0;
                                goto out;
@@ -640,6 +655,10 @@
                }
 
        }
+       if (!valid) {
+               uvm_pgfl_unlock();
+               return EINVAL;
+       }
 
 out:
        /*



Home | Main Index | Thread Index | Old Index