2 * Copyright (c) 1990 The Regents of the University of California.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * from: @(#)sys_machdep.c 5.5 (Berkeley) 1/19/91
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include "opt_kstack_pages.h"
38 #include <sys/param.h>
39 #include <sys/systm.h>
41 #include <sys/malloc.h>
42 #include <sys/mutex.h>
46 #include <sys/sysproto.h>
50 #include <vm/vm_map.h>
51 #include <vm/vm_extern.h>
53 #include <machine/cpu.h>
54 #include <machine/pcb.h>
55 #include <machine/pcb_ext.h>
56 #include <machine/proc.h>
57 #include <machine/sysarch.h>
59 #include <security/audit/audit.h>
62 #include <machine/xen/xenfunc.h>
64 void i386_reset_ldt(struct proc_ldt *pldt);
67 i386_reset_ldt(struct proc_ldt *pldt)
69 xen_set_ldt((vm_offset_t)pldt->ldt_base, pldt->ldt_len);
72 #define i386_reset_ldt(x)
75 #include <vm/vm_kern.h> /* for kernel_map */
78 #define LD_PER_PAGE 512
79 #define NEW_MAX_LD(num) ((num + LD_PER_PAGE) & ~(LD_PER_PAGE-1))
80 #define SIZE_FROM_LARGEST_LD(num) (NEW_MAX_LD(num) << 3)
81 #define NULL_LDT_BASE ((caddr_t)NULL)
84 static void set_user_ldt_rv(struct vmspace *vmsp);
86 static int i386_set_ldt_data(struct thread *, int start, int num,
87 union descriptor *descs);
88 static int i386_ldt_grow(struct thread *td, int len);
90 #ifndef _SYS_SYSPROTO_H_
100 register struct sysarch_args *uap;
103 union descriptor *lp;
105 struct i386_ldt_args largs;
106 struct i386_ioperm_args iargs;
109 struct segment_descriptor sd, *sdp;
111 AUDIT_ARG(cmd, uap->op);
113 case I386_GET_IOPERM:
114 case I386_SET_IOPERM:
115 if ((error = copyin(uap->parms, &kargs.iargs,
116 sizeof(struct i386_ioperm_args))) != 0)
121 if ((error = copyin(uap->parms, &kargs.largs,
122 sizeof(struct i386_ldt_args))) != 0)
124 if (kargs.largs.num > MAX_LD || kargs.largs.num <= 0)
133 error = i386_get_ldt(td, &kargs.largs);
136 if (kargs.largs.descs != NULL) {
137 lp = (union descriptor *)kmem_alloc(kernel_map,
138 kargs.largs.num * sizeof(union descriptor));
143 error = copyin(kargs.largs.descs, lp,
144 kargs.largs.num * sizeof(union descriptor));
146 error = i386_set_ldt(td, &kargs.largs, lp);
147 kmem_free(kernel_map, (vm_offset_t)lp,
148 kargs.largs.num * sizeof(union descriptor));
150 error = i386_set_ldt(td, &kargs.largs, NULL);
153 case I386_GET_IOPERM:
154 error = i386_get_ioperm(td, &kargs.iargs);
156 error = copyout(&kargs.iargs, uap->parms,
157 sizeof(struct i386_ioperm_args));
159 case I386_SET_IOPERM:
160 error = i386_set_ioperm(td, &kargs.iargs);
163 error = vm86_sysarch(td, uap->parms);
165 case I386_GET_FSBASE:
166 sdp = &td->td_pcb->pcb_fsd;
167 base = sdp->sd_hibase << 24 | sdp->sd_lobase;
168 error = copyout(&base, uap->parms, sizeof(base));
170 case I386_SET_FSBASE:
171 error = copyin(uap->parms, &base, sizeof(base));
174 * Construct a descriptor and store it in the pcb for
175 * the next context switch. Also store it in the gdt
176 * so that the load of tf_fs into %fs will activate it
177 * at return to userland.
179 sd.sd_lobase = base & 0xffffff;
180 sd.sd_hibase = (base >> 24) & 0xff;
182 /* need to do nosegneg like Linux */
183 sd.sd_lolimit = (HYPERVISOR_VIRT_START >> 12) & 0xffff;
185 sd.sd_lolimit = 0xffff; /* 4GB limit, wraps around */
188 sd.sd_type = SDT_MEMRWA;
195 td->td_pcb->pcb_fsd = sd;
197 HYPERVISOR_update_descriptor(vtomach(&PCPU_GET(fsgs_gdt)[0]),
200 PCPU_GET(fsgs_gdt)[0] = sd;
203 td->td_frame->tf_fs = GSEL(GUFS_SEL, SEL_UPL);
206 case I386_GET_GSBASE:
207 sdp = &td->td_pcb->pcb_gsd;
208 base = sdp->sd_hibase << 24 | sdp->sd_lobase;
209 error = copyout(&base, uap->parms, sizeof(base));
211 case I386_SET_GSBASE:
212 error = copyin(uap->parms, &base, sizeof(base));
215 * Construct a descriptor and store it in the pcb for
216 * the next context switch. Also store it in the gdt
217 * because we have to do a load_gs() right now.
219 sd.sd_lobase = base & 0xffffff;
220 sd.sd_hibase = (base >> 24) & 0xff;
223 /* need to do nosegneg like Linux */
224 sd.sd_lolimit = (HYPERVISOR_VIRT_START >> 12) & 0xffff;
226 sd.sd_lolimit = 0xffff; /* 4GB limit, wraps around */
229 sd.sd_type = SDT_MEMRWA;
236 td->td_pcb->pcb_gsd = sd;
238 HYPERVISOR_update_descriptor(vtomach(&PCPU_GET(fsgs_gdt)[1]),
241 PCPU_GET(fsgs_gdt)[1] = sd;
244 load_gs(GSEL(GUGS_SEL, SEL_UPL));
255 i386_extend_pcb(struct thread *td)
260 struct soft_segment_descriptor ssd = {
261 0, /* segment base address (overwritten) */
262 ctob(IOPAGES + 1) - 1, /* length */
263 SDT_SYS386TSS, /* segment type */
264 0, /* priority level */
265 1, /* descriptor present */
267 0, /* default 32 size */
271 ext = (struct pcb_ext *)kmem_alloc(kernel_map, ctob(IOPAGES+1));
274 bzero(ext, sizeof(struct pcb_ext));
275 /* -16 is so we can convert a trapframe into vm86trapframe inplace */
276 ext->ext_tss.tss_esp0 = td->td_kstack + ctob(KSTACK_PAGES) -
277 sizeof(struct pcb) - 16;
278 ext->ext_tss.tss_ss0 = GSEL(GDATA_SEL, SEL_KPL);
280 * The last byte of the i/o map must be followed by an 0xff byte.
281 * We arbitrarily allocate 16 bytes here, to keep the starting
282 * address on a doubleword boundary.
284 offset = PAGE_SIZE - 16;
285 ext->ext_tss.tss_ioopt =
286 (offset - ((unsigned)&ext->ext_tss - (unsigned)ext)) << 16;
287 ext->ext_iomap = (caddr_t)ext + offset;
288 ext->ext_vm86.vm86_intmap = (caddr_t)ext + offset - 32;
290 addr = (u_long *)ext->ext_vm86.vm86_intmap;
291 for (i = 0; i < (ctob(IOPAGES) + 32 + 16) / sizeof(u_long); i++)
294 ssd.ssd_base = (unsigned)&ext->ext_tss;
295 ssd.ssd_limit -= ((unsigned)&ext->ext_tss - (unsigned)ext);
296 ssdtosd(&ssd, &ext->ext_tssd);
298 KASSERT(td == curthread, ("giving TSS to !curthread"));
299 KASSERT(td->td_pcb->pcb_ext == 0, ("already have a TSS!"));
301 /* Switch to the new TSS. */
303 td->td_pcb->pcb_ext = ext;
304 PCPU_SET(private_tss, 1);
305 *PCPU_GET(tss_gdt) = ext->ext_tssd;
306 ltr(GSEL(GPROC0_SEL, SEL_KPL));
313 i386_set_ioperm(td, uap)
315 struct i386_ioperm_args *uap;
320 if ((error = priv_check(td, PRIV_IO)) != 0)
322 if ((error = securelevel_gt(td->td_ucred, 0)) != 0)
326 * While this is restricted to root, we should probably figure out
327 * whether any other driver is using this i/o address, as so not to
328 * cause confusion. This probably requires a global 'usage registry'.
331 if (td->td_pcb->pcb_ext == 0)
332 if ((error = i386_extend_pcb(td)) != 0)
334 iomap = (char *)td->td_pcb->pcb_ext->ext_iomap;
336 if (uap->start + uap->length > IOPAGES * PAGE_SIZE * NBBY)
339 for (i = uap->start; i < uap->start + uap->length; i++) {
341 iomap[i >> 3] &= ~(1 << (i & 7));
343 iomap[i >> 3] |= (1 << (i & 7));
349 i386_get_ioperm(td, uap)
351 struct i386_ioperm_args *uap;
356 if (uap->start >= IOPAGES * PAGE_SIZE * NBBY)
359 if (td->td_pcb->pcb_ext == 0) {
364 iomap = (char *)td->td_pcb->pcb_ext->ext_iomap;
367 state = (iomap[i >> 3] >> (i & 7)) & 1;
368 uap->enable = !state;
371 for (i = uap->start + 1; i < IOPAGES * PAGE_SIZE * NBBY; i++) {
372 if (state != ((iomap[i >> 3] >> (i & 7)) & 1))
382 * Update the GDT entry pointing to the LDT to point to the LDT of the
383 * current process. Manage dt_lock holding/unholding autonomously.
386 set_user_ldt(struct mdproc *mdp)
388 struct proc_ldt *pldt;
392 if (!mtx_owned(&dt_lock)) {
393 mtx_lock_spin(&dt_lock);
399 i386_reset_ldt(pldt);
400 PCPU_SET(currentldt, (int)pldt);
403 gdt[PCPU_GET(cpuid) * NGDT + GUSERLDT_SEL].sd = pldt->ldt_sd;
405 gdt[GUSERLDT_SEL].sd = pldt->ldt_sd;
407 lldt(GSEL(GUSERLDT_SEL, SEL_KPL));
408 PCPU_SET(currentldt, GSEL(GUSERLDT_SEL, SEL_KPL));
411 mtx_unlock_spin(&dt_lock);
416 set_user_ldt_rv(struct vmspace *vmsp)
421 if (vmsp != td->td_proc->p_vmspace)
424 set_user_ldt(&td->td_proc->p_md);
431 * dt_lock must be held. Returns with dt_lock held.
434 user_ldt_alloc(struct mdproc *mdp, int len)
436 struct proc_ldt *pldt, *new_ldt;
438 mtx_assert(&dt_lock, MA_OWNED);
439 mtx_unlock_spin(&dt_lock);
440 MALLOC(new_ldt, struct proc_ldt *, sizeof(struct proc_ldt),
441 M_SUBPROC, M_WAITOK);
443 new_ldt->ldt_len = len = NEW_MAX_LD(len);
444 new_ldt->ldt_base = (caddr_t)kmem_alloc(kernel_map,
445 round_page(len * sizeof(union descriptor)));
446 if (new_ldt->ldt_base == NULL) {
447 FREE(new_ldt, M_SUBPROC);
448 mtx_lock_spin(&dt_lock);
451 new_ldt->ldt_refcnt = 1;
452 new_ldt->ldt_active = 0;
454 if ((pldt = mdp->md_ldt)) {
455 if (len > pldt->ldt_len)
457 bcopy(pldt->ldt_base, new_ldt->ldt_base,
458 len * sizeof(union descriptor));
460 bcopy(ldt, new_ldt->ldt_base, PAGE_SIZE);
462 pmap_map_readonly(kernel_pmap, (vm_offset_t)new_ldt->ldt_base,
463 new_ldt->ldt_len*sizeof(union descriptor));
468 * dt_lock must be held. Returns with dt_lock held.
471 user_ldt_alloc(struct mdproc *mdp, int len)
473 struct proc_ldt *pldt, *new_ldt;
475 mtx_assert(&dt_lock, MA_OWNED);
476 mtx_unlock_spin(&dt_lock);
477 MALLOC(new_ldt, struct proc_ldt *, sizeof(struct proc_ldt),
478 M_SUBPROC, M_WAITOK);
480 new_ldt->ldt_len = len = NEW_MAX_LD(len);
481 new_ldt->ldt_base = (caddr_t)kmem_alloc(kernel_map,
482 len * sizeof(union descriptor));
483 if (new_ldt->ldt_base == NULL) {
484 FREE(new_ldt, M_SUBPROC);
485 mtx_lock_spin(&dt_lock);
488 new_ldt->ldt_refcnt = 1;
489 new_ldt->ldt_active = 0;
491 mtx_lock_spin(&dt_lock);
492 gdt_segs[GUSERLDT_SEL].ssd_base = (unsigned)new_ldt->ldt_base;
493 gdt_segs[GUSERLDT_SEL].ssd_limit = len * sizeof(union descriptor) - 1;
494 ssdtosd(&gdt_segs[GUSERLDT_SEL], &new_ldt->ldt_sd);
496 if ((pldt = mdp->md_ldt) != NULL) {
497 if (len > pldt->ldt_len)
499 bcopy(pldt->ldt_base, new_ldt->ldt_base,
500 len * sizeof(union descriptor));
502 bcopy(ldt, new_ldt->ldt_base, sizeof(ldt));
509 * Must be called with dt_lock held. Returns with dt_lock unheld.
512 user_ldt_free(struct thread *td)
514 struct mdproc *mdp = &td->td_proc->p_md;
515 struct proc_ldt *pldt;
517 mtx_assert(&dt_lock, MA_OWNED);
518 if ((pldt = mdp->md_ldt) == NULL) {
519 mtx_unlock_spin(&dt_lock);
523 if (td == PCPU_GET(curthread)) {
525 PCPU_SET(currentldt, _default_ldt);
529 user_ldt_deref(pldt);
533 user_ldt_deref(struct proc_ldt *pldt)
536 mtx_assert(&dt_lock, MA_OWNED);
537 if (--pldt->ldt_refcnt == 0) {
538 mtx_unlock_spin(&dt_lock);
539 kmem_free(kernel_map, (vm_offset_t)pldt->ldt_base,
540 pldt->ldt_len * sizeof(union descriptor));
541 FREE(pldt, M_SUBPROC);
543 mtx_unlock_spin(&dt_lock);
547 * Note for the authors of compat layers (linux, etc): copyout() in
548 * the function below is not a problem since it presents data in
549 * arch-specific format (i.e. i386-specific in this case), not in
550 * the OS-specific one.
553 i386_get_ldt(td, uap)
555 struct i386_ldt_args *uap;
558 struct proc_ldt *pldt;
560 union descriptor *lp;
563 printf("i386_get_ldt: start=%d num=%d descs=%p\n",
564 uap->start, uap->num, (void *)uap->descs);
567 mtx_lock_spin(&dt_lock);
568 if ((pldt = td->td_proc->p_md.md_ldt) != NULL) {
569 nldt = pldt->ldt_len;
570 lp = &((union descriptor *)(pldt->ldt_base))[uap->start];
571 mtx_unlock_spin(&dt_lock);
572 num = min(uap->num, nldt);
574 mtx_unlock_spin(&dt_lock);
575 nldt = sizeof(ldt)/sizeof(ldt[0]);
576 num = min(uap->num, nldt);
577 lp = &ldt[uap->start];
580 if ((uap->start > (unsigned int)nldt) ||
581 ((unsigned int)num > (unsigned int)nldt) ||
582 ((unsigned int)(uap->start + num) > (unsigned int)nldt))
585 error = copyout(lp, uap->descs, num * sizeof(union descriptor));
587 td->td_retval[0] = num;
593 i386_set_ldt(td, uap, descs)
595 struct i386_ldt_args *uap;
596 union descriptor *descs;
600 struct mdproc *mdp = &td->td_proc->p_md;
601 struct proc_ldt *pldt;
602 union descriptor *dp;
605 printf("i386_set_ldt: start=%d num=%d descs=%p\n",
606 uap->start, uap->num, (void *)uap->descs);
610 /* Free descriptors */
611 if (uap->start == 0 && uap->num == 0) {
613 * Treat this as a special case, so userland needn't
614 * know magic number NLDT.
617 uap->num = MAX_LD - NLDT;
621 mtx_lock_spin(&dt_lock);
622 if ((pldt = mdp->md_ldt) == NULL ||
623 uap->start >= pldt->ldt_len) {
624 mtx_unlock_spin(&dt_lock);
627 largest_ld = uap->start + uap->num;
628 if (largest_ld > pldt->ldt_len)
629 largest_ld = pldt->ldt_len;
630 i = largest_ld - uap->start;
631 bzero(&((union descriptor *)(pldt->ldt_base))[uap->start],
632 sizeof(union descriptor) * i);
633 mtx_unlock_spin(&dt_lock);
637 if (!(uap->start == LDT_AUTO_ALLOC && uap->num == 1)) {
638 /* verify range of descriptors to modify */
639 largest_ld = uap->start + uap->num;
640 if (uap->start >= MAX_LD ||
641 uap->num < 0 || largest_ld > MAX_LD) {
646 /* Check descriptors for access violations */
647 for (i = 0; i < uap->num; i++) {
650 switch (dp->sd.sd_type) {
651 case SDT_SYSNULL: /* system null */
654 case SDT_SYS286TSS: /* system 286 TSS available */
655 case SDT_SYSLDT: /* system local descriptor table */
656 case SDT_SYS286BSY: /* system 286 TSS busy */
657 case SDT_SYSTASKGT: /* system task gate */
658 case SDT_SYS286IGT: /* system 286 interrupt gate */
659 case SDT_SYS286TGT: /* system 286 trap gate */
660 case SDT_SYSNULL2: /* undefined by Intel */
661 case SDT_SYS386TSS: /* system 386 TSS available */
662 case SDT_SYSNULL3: /* undefined by Intel */
663 case SDT_SYS386BSY: /* system 386 TSS busy */
664 case SDT_SYSNULL4: /* undefined by Intel */
665 case SDT_SYS386IGT: /* system 386 interrupt gate */
666 case SDT_SYS386TGT: /* system 386 trap gate */
667 case SDT_SYS286CGT: /* system 286 call gate */
668 case SDT_SYS386CGT: /* system 386 call gate */
669 /* I can't think of any reason to allow a user proc
670 * to create a segment of these types. They are
676 /* memory segment types */
677 case SDT_MEMEC: /* memory execute only conforming */
678 case SDT_MEMEAC: /* memory execute only accessed conforming */
679 case SDT_MEMERC: /* memory execute read conforming */
680 case SDT_MEMERAC: /* memory execute read accessed conforming */
681 /* Must be "present" if executable and conforming. */
682 if (dp->sd.sd_p == 0)
685 case SDT_MEMRO: /* memory read only */
686 case SDT_MEMROA: /* memory read only accessed */
687 case SDT_MEMRW: /* memory read write */
688 case SDT_MEMRWA: /* memory read write accessed */
689 case SDT_MEMROD: /* memory read only expand dwn limit */
690 case SDT_MEMRODA: /* memory read only expand dwn lim accessed */
691 case SDT_MEMRWD: /* memory read write expand dwn limit */
692 case SDT_MEMRWDA: /* memory read write expand dwn lim acessed */
693 case SDT_MEME: /* memory execute only */
694 case SDT_MEMEA: /* memory execute only accessed */
695 case SDT_MEMER: /* memory execute read */
696 case SDT_MEMERA: /* memory execute read accessed */
703 /* Only user (ring-3) descriptors may be present. */
704 if ((dp->sd.sd_p != 0) && (dp->sd.sd_dpl != SEL_UPL))
708 if (uap->start == LDT_AUTO_ALLOC && uap->num == 1) {
709 /* Allocate a free slot */
710 mtx_lock_spin(&dt_lock);
711 if ((pldt = mdp->md_ldt) == NULL) {
712 if ((error = i386_ldt_grow(td, NLDT + 1))) {
713 mtx_unlock_spin(&dt_lock);
720 * start scanning a bit up to leave room for NVidia and
721 * Wine, which still user the "Blat" method of allocation.
723 dp = &((union descriptor *)(pldt->ldt_base))[NLDT];
724 for (i = NLDT; i < pldt->ldt_len; ++i) {
725 if (dp->sd.sd_type == SDT_SYSNULL)
729 if (i >= pldt->ldt_len) {
730 if ((error = i386_ldt_grow(td, pldt->ldt_len+1))) {
731 mtx_unlock_spin(&dt_lock);
737 error = i386_set_ldt_data(td, i, 1, descs);
738 mtx_unlock_spin(&dt_lock);
740 largest_ld = uap->start + uap->num;
741 mtx_lock_spin(&dt_lock);
742 if (!(error = i386_ldt_grow(td, largest_ld))) {
743 error = i386_set_ldt_data(td, uap->start, uap->num,
746 mtx_unlock_spin(&dt_lock);
749 td->td_retval[0] = uap->start;
754 i386_set_ldt_data(struct thread *td, int start, int num,
755 union descriptor *descs)
757 struct mdproc *mdp = &td->td_proc->p_md;
758 struct proc_ldt *pldt = mdp->md_ldt;
760 mtx_assert(&dt_lock, MA_OWNED);
764 &((union descriptor *)(pldt->ldt_base))[start],
765 num * sizeof(union descriptor));
770 i386_set_ldt_data(struct thread *td, int start, int num,
771 union descriptor *descs)
773 struct mdproc *mdp = &td->td_proc->p_md;
774 struct proc_ldt *pldt = mdp->md_ldt;
776 mtx_assert(&dt_lock, MA_OWNED);
780 &((union descriptor *)(pldt->ldt_base))[start],
781 num * sizeof(union descriptor));
787 i386_ldt_grow(struct thread *td, int len)
789 struct mdproc *mdp = &td->td_proc->p_md;
790 struct proc_ldt *new_ldt, *pldt;
791 caddr_t old_ldt_base = NULL_LDT_BASE;
794 mtx_assert(&dt_lock, MA_OWNED);
801 /* Allocate a user ldt. */
802 if ((pldt = mdp->md_ldt) == NULL || len > pldt->ldt_len) {
803 new_ldt = user_ldt_alloc(mdp, len);
809 if (new_ldt->ldt_len <= pldt->ldt_len) {
811 * We just lost the race for allocation, so
812 * free the new object and return.
814 mtx_unlock_spin(&dt_lock);
815 kmem_free(kernel_map,
816 (vm_offset_t)new_ldt->ldt_base,
817 new_ldt->ldt_len * sizeof(union descriptor));
818 FREE(new_ldt, M_SUBPROC);
819 mtx_lock_spin(&dt_lock);
824 * We have to substitute the current LDT entry for
825 * curproc with the new one since its size grew.
827 old_ldt_base = pldt->ldt_base;
828 old_ldt_len = pldt->ldt_len;
829 pldt->ldt_sd = new_ldt->ldt_sd;
830 pldt->ldt_base = new_ldt->ldt_base;
831 pldt->ldt_len = new_ldt->ldt_len;
833 mdp->md_ldt = pldt = new_ldt;
836 * Signal other cpus to reload ldt. We need to unlock dt_lock
837 * here because other CPU will contest on it since their
838 * curthreads won't hold the lock and will block when trying
841 mtx_unlock_spin(&dt_lock);
842 smp_rendezvous(NULL, (void (*)(void *))set_user_ldt_rv,
843 NULL, td->td_proc->p_vmspace);
845 set_user_ldt(&td->td_proc->p_md);
846 mtx_unlock_spin(&dt_lock);
848 if (old_ldt_base != NULL_LDT_BASE) {
849 kmem_free(kernel_map, (vm_offset_t)old_ldt_base,
850 old_ldt_len * sizeof(union descriptor));
851 FREE(new_ldt, M_SUBPROC);
853 mtx_lock_spin(&dt_lock);