sys_machdep.c (328322) | sys_machdep.c (329462) |
---|---|
1/*- 2 * Copyright (c) 2003 Peter Wemm. 3 * Copyright (c) 1990 The Regents of the University of California. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 17 unchanged lines hidden (view full) --- 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 * from: @(#)sys_machdep.c 5.5 (Berkeley) 1/19/91 31 */ 32 33#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2003 Peter Wemm. 3 * Copyright (c) 1990 The Regents of the University of California. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 17 unchanged lines hidden (view full) --- 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 * from: @(#)sys_machdep.c 5.5 (Berkeley) 1/19/91 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: stable/11/sys/amd64/amd64/sys_machdep.c 328322 2018-01-24 10:50:21Z kib $"); | 34__FBSDID("$FreeBSD: stable/11/sys/amd64/amd64/sys_machdep.c 329462 2018-02-17 18:00:01Z kib $"); |
35 36#include "opt_capsicum.h" 37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/capsicum.h> 41#include <sys/kernel.h> 42#include <sys/lock.h> --- 314 unchanged lines hidden (view full) --- 357 * XXX 358 * While this is restricted to root, we should probably figure out 359 * whether any other driver is using this i/o address, as so not to 360 * cause confusion. This probably requires a global 'usage registry'. 361 */ 362 pcb = td->td_pcb; 363 if (pcb->pcb_tssp == NULL) { 364 tssp = (struct amd64tss *)kmem_malloc(kernel_arena, | 35 36#include "opt_capsicum.h" 37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/capsicum.h> 41#include <sys/kernel.h> 42#include <sys/lock.h> --- 314 unchanged lines hidden (view full) --- 357 * XXX 358 * While this is restricted to root, we should probably figure out 359 * whether any other driver is using this i/o address, as so not to 360 * cause confusion. This probably requires a global 'usage registry'. 361 */ 362 pcb = td->td_pcb; 363 if (pcb->pcb_tssp == NULL) { 364 tssp = (struct amd64tss *)kmem_malloc(kernel_arena, |
365 ctob(IOPAGES+1), M_WAITOK); | 365 ctob(IOPAGES + 1), M_WAITOK); 366 pmap_pti_add_kva((vm_offset_t)tssp, (vm_offset_t)tssp + 367 ctob(IOPAGES + 1), false); |
366 iomap = (char *)&tssp[1]; 367 memset(iomap, 0xff, IOPERM_BITMAP_SIZE); 368 critical_enter(); 369 /* Takes care of tss_rsp0. */ 370 memcpy(tssp, &common_tss[PCPU_GET(cpuid)], 371 sizeof(struct amd64tss)); 372 tssp->tss_iobase = sizeof(*tssp); 373 pcb->pcb_tssp = tssp; --- 72 unchanged lines hidden (view full) --- 446} 447 448struct proc_ldt * 449user_ldt_alloc(struct proc *p, int force) 450{ 451 struct proc_ldt *pldt, *new_ldt; 452 struct mdproc *mdp; 453 struct soft_segment_descriptor sldt; | 368 iomap = (char *)&tssp[1]; 369 memset(iomap, 0xff, IOPERM_BITMAP_SIZE); 370 critical_enter(); 371 /* Takes care of tss_rsp0. */ 372 memcpy(tssp, &common_tss[PCPU_GET(cpuid)], 373 sizeof(struct amd64tss)); 374 tssp->tss_iobase = sizeof(*tssp); 375 pcb->pcb_tssp = tssp; --- 72 unchanged lines hidden (view full) --- 448} 449 450struct proc_ldt * 451user_ldt_alloc(struct proc *p, int force) 452{ 453 struct proc_ldt *pldt, *new_ldt; 454 struct mdproc *mdp; 455 struct soft_segment_descriptor sldt; |
456 vm_offset_t sva; 457 vm_size_t sz; |
|
454 455 mtx_assert(&dt_lock, MA_OWNED); 456 mdp = &p->p_md; 457 if (!force && mdp->md_ldt != NULL) 458 return (mdp->md_ldt); 459 mtx_unlock(&dt_lock); 460 new_ldt = malloc(sizeof(struct proc_ldt), M_SUBPROC, M_WAITOK); | 458 459 mtx_assert(&dt_lock, MA_OWNED); 460 mdp = &p->p_md; 461 if (!force && mdp->md_ldt != NULL) 462 return (mdp->md_ldt); 463 mtx_unlock(&dt_lock); 464 new_ldt = malloc(sizeof(struct proc_ldt), M_SUBPROC, M_WAITOK); |
461 new_ldt->ldt_base = (caddr_t)kmem_malloc(kernel_arena, 462 max_ldt_segment * sizeof(struct user_segment_descriptor), 463 M_WAITOK | M_ZERO); | 465 sz = max_ldt_segment * sizeof(struct user_segment_descriptor); 466 sva = kmem_malloc(kernel_arena, sz, M_WAITOK | M_ZERO); 467 new_ldt->ldt_base = (caddr_t)sva; 468 pmap_pti_add_kva(sva, sva + sz, false); |
464 new_ldt->ldt_refcnt = 1; | 469 new_ldt->ldt_refcnt = 1; |
465 sldt.ssd_base = (uint64_t)new_ldt->ldt_base; 466 sldt.ssd_limit = max_ldt_segment * 467 sizeof(struct user_segment_descriptor) - 1; | 470 sldt.ssd_base = sva; 471 sldt.ssd_limit = sz - 1; |
468 sldt.ssd_type = SDT_SYSLDT; 469 sldt.ssd_dpl = SEL_KPL; 470 sldt.ssd_p = 1; 471 sldt.ssd_long = 0; 472 sldt.ssd_def32 = 0; 473 sldt.ssd_gran = 0; 474 mtx_lock(&dt_lock); 475 pldt = mdp->md_ldt; 476 if (pldt != NULL && !force) { | 472 sldt.ssd_type = SDT_SYSLDT; 473 sldt.ssd_dpl = SEL_KPL; 474 sldt.ssd_p = 1; 475 sldt.ssd_long = 0; 476 sldt.ssd_def32 = 0; 477 sldt.ssd_gran = 0; 478 mtx_lock(&dt_lock); 479 pldt = mdp->md_ldt; 480 if (pldt != NULL && !force) { |
477 kmem_free(kernel_arena, (vm_offset_t)new_ldt->ldt_base, 478 max_ldt_segment * sizeof(struct user_segment_descriptor)); | 481 pmap_pti_remove_kva(sva, sva + sz); 482 kmem_free(kernel_arena, sva, sz); |
479 free(new_ldt, M_SUBPROC); 480 return (pldt); 481 } 482 483 if (pldt != NULL) { 484 bcopy(pldt->ldt_base, new_ldt->ldt_base, max_ldt_segment * 485 sizeof(struct user_segment_descriptor)); 486 user_ldt_derefl(pldt); --- 30 unchanged lines hidden (view full) --- 517 lldt(GSEL(GNULL_SEL, SEL_KPL)); 518 critical_exit(); 519 user_ldt_deref(pldt); 520} 521 522static void 523user_ldt_derefl(struct proc_ldt *pldt) 524{ | 483 free(new_ldt, M_SUBPROC); 484 return (pldt); 485 } 486 487 if (pldt != NULL) { 488 bcopy(pldt->ldt_base, new_ldt->ldt_base, max_ldt_segment * 489 sizeof(struct user_segment_descriptor)); 490 user_ldt_derefl(pldt); --- 30 unchanged lines hidden (view full) --- 521 lldt(GSEL(GNULL_SEL, SEL_KPL)); 522 critical_exit(); 523 user_ldt_deref(pldt); 524} 525 526static void 527user_ldt_derefl(struct proc_ldt *pldt) 528{ |
529 vm_offset_t sva; 530 vm_size_t sz; |
|
525 526 if (--pldt->ldt_refcnt == 0) { | 531 532 if (--pldt->ldt_refcnt == 0) { |
527 kmem_free(kernel_arena, (vm_offset_t)pldt->ldt_base, 528 max_ldt_segment * sizeof(struct user_segment_descriptor)); | 533 sva = (vm_offset_t)pldt->ldt_base; 534 sz = max_ldt_segment * sizeof(struct user_segment_descriptor); 535 pmap_pti_remove_kva(sva, sva + sz); 536 kmem_free(kernel_arena, sva, sz); |
529 free(pldt, M_SUBPROC); 530 } 531} 532 533static void 534user_ldt_deref(struct proc_ldt *pldt) 535{ 536 --- 213 unchanged lines hidden --- | 537 free(pldt, M_SUBPROC); 538 } 539} 540 541static void 542user_ldt_deref(struct proc_ldt *pldt) 543{ 544 --- 213 unchanged lines hidden --- |