On Fri, 24 Dec 2010, Mark Kettenis wrote:

> Well, changing NLDT to 17 should defenitely be tested, but leaving it
> at 17 is a bit odd.  I'm actually wondering whether the default LDT is
> necessary at all now that LBSDICALLS_SEL is gone.  Then NLDT can go
> completely.

>From a brief look, eliminating the default entirely just makes things more 
complicated, but we can shrink it down to 1.  I switched things over to 
using malloc instead of uvm_km_alloc because there's no reason to allocate 
full pages for tiny things.

This will need more testing, of course.

Index: i386/machdep.c
===================================================================
RCS file: /cvs/src/sys/arch/i386/i386/machdep.c,v
retrieving revision 1.485
diff -u -r1.485 machdep.c
--- i386/machdep.c      2 Oct 2010 23:31:34 -0000       1.485
+++ i386/machdep.c      24 Dec 2010 21:35:04 -0000
@@ -2868,7 +2868,7 @@
        union descriptor *cpu_ldt;
        size_t len = sizeof(ldt);
 
-       cpu_ldt = (union descriptor *)uvm_km_alloc(kernel_map, len);
+       cpu_ldt = malloc(len, M_DEVBUF, M_WAITOK);
        bcopy(ldt, cpu_ldt, len);
        ci->ci_ldt = cpu_ldt;
        ci->ci_ldt_len = len;
Index: i386/pmap.c
===================================================================
RCS file: /cvs/src/sys/arch/i386/i386/pmap.c,v
retrieving revision 1.151
diff -u -r1.151 pmap.c
--- i386/pmap.c 30 Nov 2010 19:28:59 -0000      1.151
+++ i386/pmap.c 24 Dec 2010 21:35:06 -0000
@@ -1547,8 +1547,7 @@
                 * we're the last one to use it.
                 */
                ldt_free(pmap);
-               uvm_km_free(kernel_map, (vaddr_t)pmap->pm_ldt,
-                           pmap->pm_ldt_len * sizeof(union descriptor));
+               free(pmap->pm_ldt, M_DEVBUF);
        }
 #endif
        pool_put(&pmap_pmap_pool, pmap);
@@ -1586,11 +1585,7 @@
                size_t len;
 
                len = pmap1->pm_ldt_len * sizeof(union descriptor);
-               new_ldt = (union descriptor *)uvm_km_alloc(kernel_map, len);
-               if (new_ldt == NULL) {
-                       /* XXX needs to be able to fail properly */
-                       panic("pmap_fork: out of kva");
-               }
+               new_ldt = malloc(len, M_DEVBUF, M_WAITOK);
                bcopy(pmap1->pm_ldt, new_ldt, len);
                pmap2->pm_ldt = new_ldt;
                pmap2->pm_ldt_len = pmap1->pm_ldt_len;
@@ -1642,7 +1637,7 @@
        simple_unlock(&pmap->pm_obj.vmobjlock);
 
        if (old_ldt != NULL)
-               uvm_km_free(kernel_map, (vaddr_t)old_ldt, len);
+               free(old_ldt, M_DEVBUF);
 }
 #endif /* USER_LDT */
 
Index: i386/sys_machdep.c
===================================================================
RCS file: /cvs/src/sys/arch/i386/i386/sys_machdep.c,v
retrieving revision 1.27
diff -u -r1.27 sys_machdep.c
--- i386/sys_machdep.c  20 Nov 2010 20:21:13 -0000      1.27
+++ i386/sys_machdep.c  24 Dec 2010 21:35:06 -0000
@@ -262,8 +262,7 @@
                new_len = ldt_len * sizeof(union descriptor);
 
                simple_unlock(&pmap->pm_lock);
-               new_ldt = (union descriptor *)uvm_km_alloc(kernel_map,
-                   new_len);
+               new_ldt = malloc(new_len, M_DEVBUF, M_WAITOK);
                if (new_ldt == NULL) {
                        error = ENOMEM;
                        goto out;
@@ -279,7 +278,7 @@
                         * hey.. not our problem if user applications
                         * have race conditions like that.
                         */
-                       uvm_km_free(kernel_map, (vaddr_t)new_ldt, new_len);
+                       free(new_ldt, M_DEVBUF);
                        goto copy;
                }
 
@@ -296,7 +295,7 @@
                memset((caddr_t)new_ldt + old_len, 0, new_len - old_len);
 
                if (old_ldt != ldt)
-                       uvm_km_free(kernel_map, (vaddr_t)old_ldt, old_len);
+                       free(old_ldt, M_DEVBUF);
 
                pmap->pm_ldt = new_ldt;
                pmap->pm_ldt_len = ldt_len;
Index: include/segments.h
===================================================================
RCS file: /cvs/src/sys/arch/i386/include/segments.h,v
retrieving revision 1.18
diff -u -r1.18 segments.h
--- include/segments.h  24 Dec 2010 20:26:30 -0000      1.18
+++ include/segments.h  24 Dec 2010 21:35:06 -0000
@@ -227,7 +227,8 @@
 
 /*
  * Entries in the Local Descriptor Table (LDT)
+ * (not normally used)
  */
-#define        NLDT            17
+#define        NLDT            1
 
 #endif /* _I386_SEGMENTS_H_ */

Reply via email to