1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #pragma ident "%Z%%M% %I% %E% SMI" 27 28 #include <sys/types.h> 29 #include <sys/thread.h> 30 #include <sys/cpuvar.h> 31 #include <sys/t_lock.h> 32 #include <sys/param.h> 33 #include <sys/proc.h> 34 #include <sys/disp.h> 35 #include <sys/mmu.h> 36 #include <sys/class.h> 37 #include <sys/cmn_err.h> 38 #include <sys/debug.h> 39 #include <sys/asm_linkage.h> 40 #include <sys/x_call.h> 41 #include <sys/systm.h> 42 #include <sys/var.h> 43 #include <sys/vtrace.h> 44 #include <vm/hat.h> 45 #include <sys/mmu.h> 46 #include <vm/as.h> 47 #include <vm/seg_kmem.h> 48 #include <sys/segments.h> 49 #include <sys/kmem.h> 50 #include <sys/stack.h> 51 #include <sys/smp_impldefs.h> 52 #include <sys/x86_archext.h> 53 #include <sys/machsystm.h> 54 #include <sys/traptrace.h> 55 #include <sys/clock.h> 56 #include <sys/cpc_impl.h> 57 #include <sys/chip.h> 58 #include <sys/dtrace.h> 59 #include <sys/archsystm.h> 60 #include <sys/fp.h> 61 #include <sys/reboot.h> 62 #include <sys/kdi.h> 63 #include <vm/hat_i86.h> 64 #include <sys/memnode.h> 65 #include <sys/pci_cfgspace.h> 66 #include <sys/cpu_module.h> 67 68 struct cpu cpus[1]; /* CPU data */ 69 struct cpu *cpu[NCPU] = {&cpus[0]}; /* pointers to all CPUs */ 70 cpu_core_t cpu_core[NCPU]; /* cpu_core structures */ 71 72 /* 73 * Useful for disabling MP bring-up for an MP capable kernel 74 * (a kernel that was built with MP defined) 75 */ 76 int use_mp = 1; 77 78 /* 79 * To be set by a PSM to indicate what CPUs are available on the system. 80 */ 81 cpuset_t mp_cpus = 1; 82 83 /* 84 * This variable is used by the hat layer to decide whether or not 85 * critical sections are needed to prevent race conditions. For sun4m, 86 * this variable is set once enough MP initialization has been done in 87 * order to allow cross calls. 88 */ 89 int flushes_require_xcalls = 0; 90 cpuset_t cpu_ready_set = 1; 91 92 extern void real_mode_start(void); 93 extern void real_mode_end(void); 94 static void mp_startup(void); 95 96 static void cpu_sep_enable(void); 97 static void cpu_sep_disable(void); 98 static void cpu_asysc_enable(void); 99 static void cpu_asysc_disable(void); 100 101 extern int tsc_gethrtime_enable; 102 103 /* 104 * Init CPU info - get CPU type info for processor_info system call. 105 */ 106 void 107 init_cpu_info(struct cpu *cp) 108 { 109 processor_info_t *pi = &cp->cpu_type_info; 110 char buf[CPU_IDSTRLEN]; 111 112 /* 113 * Get clock-frequency property for the CPU. 114 */ 115 pi->pi_clock = cpu_freq; 116 117 (void) strcpy(pi->pi_processor_type, "i386"); 118 if (fpu_exists) 119 (void) strcpy(pi->pi_fputypes, "i387 compatible"); 120 121 (void) cpuid_getidstr(cp, buf, sizeof (buf)); 122 123 cp->cpu_idstr = kmem_alloc(strlen(buf) + 1, KM_SLEEP); 124 (void) strcpy(cp->cpu_idstr, buf); 125 126 cmn_err(CE_CONT, "?cpu%d: %s\n", cp->cpu_id, cp->cpu_idstr); 127 128 (void) cpuid_getbrandstr(cp, buf, sizeof (buf)); 129 cp->cpu_brandstr = kmem_alloc(strlen(buf) + 1, KM_SLEEP); 130 (void) strcpy(cp->cpu_brandstr, buf); 131 132 cmn_err(CE_CONT, "?cpu%d: %s\n", cp->cpu_id, cp->cpu_brandstr); 133 } 134 135 /* 136 * Configure syscall support on this CPU. 137 */ 138 /*ARGSUSED*/ 139 static void 140 init_cpu_syscall(struct cpu *cp) 141 { 142 kpreempt_disable(); 143 144 #if defined(__amd64) 145 if (x86_feature & X86_ASYSC) { 146 147 #if !defined(__lint) 148 /* 149 * The syscall instruction imposes a certain ordering on 150 * segment selectors, so we double-check that ordering 151 * here. 152 */ 153 ASSERT(KDS_SEL == KCS_SEL + 8); 154 ASSERT(UDS_SEL == U32CS_SEL + 8); 155 ASSERT(UCS_SEL == U32CS_SEL + 16); 156 #endif 157 /* 158 * Turn syscall/sysret extensions on. 159 */ 160 cpu_asysc_enable(); 161 162 /* 163 * Program the magic registers .. 164 */ 165 wrmsr(MSR_AMD_STAR, ((uint64_t)(U32CS_SEL << 16 | KCS_SEL)) << 166 32); 167 wrmsr(MSR_AMD_LSTAR, (uint64_t)(uintptr_t)sys_syscall); 168 wrmsr(MSR_AMD_CSTAR, (uint64_t)(uintptr_t)sys_syscall32); 169 170 /* 171 * This list of flags is masked off the incoming 172 * %rfl when we enter the kernel. 173 */ 174 wrmsr(MSR_AMD_SFMASK, (uint64_t)(uintptr_t)(PS_IE | PS_T)); 175 } 176 #endif 177 178 /* 179 * On 32-bit kernels, we use sysenter/sysexit because it's too 180 * hard to use syscall/sysret, and it is more portable anyway. 181 * 182 * On 64-bit kernels on Nocona machines, the 32-bit syscall 183 * variant isn't available to 32-bit applications, but sysenter is. 184 */ 185 if (x86_feature & X86_SEP) { 186 187 #if !defined(__lint) 188 /* 189 * The sysenter instruction imposes a certain ordering on 190 * segment selectors, so we double-check that ordering 191 * here. See "sysenter" in Intel document 245471-012, "IA-32 192 * Intel Architecture Software Developer's Manual Volume 2: 193 * Instruction Set Reference" 194 */ 195 ASSERT(KDS_SEL == KCS_SEL + 8); 196 197 ASSERT32(UCS_SEL == ((KCS_SEL + 16) | 3)); 198 ASSERT32(UDS_SEL == UCS_SEL + 8); 199 200 ASSERT64(U32CS_SEL == ((KCS_SEL + 16) | 3)); 201 ASSERT64(UDS_SEL == U32CS_SEL + 8); 202 #endif 203 204 cpu_sep_enable(); 205 206 /* 207 * resume() sets this value to the base of the threads stack 208 * via a context handler. 209 */ 210 wrmsr(MSR_INTC_SEP_ESP, 0ULL); 211 wrmsr(MSR_INTC_SEP_EIP, (uint64_t)(uintptr_t)sys_sysenter); 212 } 213 214 kpreempt_enable(); 215 } 216 217 /* 218 * Multiprocessor initialization. 219 * 220 * Allocate and initialize the cpu structure, TRAPTRACE buffer, and the 221 * startup and idle threads for the specified CPU. 222 */ 223 static void 224 mp_startup_init(int cpun) 225 { 226 #if defined(__amd64) 227 extern void *long_mode_64(void); 228 #endif /* __amd64 */ 229 230 struct cpu *cp; 231 struct tss *ntss; 232 kthread_id_t tp; 233 caddr_t sp; 234 int size; 235 proc_t *procp; 236 extern void idle(); 237 238 struct cpu_tables *tablesp; 239 rm_platter_t *real_mode_platter = (rm_platter_t *)rm_platter_va; 240 241 #ifdef TRAPTRACE 242 trap_trace_ctl_t *ttc = &trap_trace_ctl[cpun]; 243 #endif 244 245 ASSERT(cpun < NCPU && cpu[cpun] == NULL); 246 247 if ((cp = kmem_zalloc(sizeof (*cp), KM_NOSLEEP)) == NULL) { 248 panic("mp_startup_init: cpu%d: " 249 "no memory for cpu structure", cpun); 250 /*NOTREACHED*/ 251 } 252 procp = curthread->t_procp; 253 254 mutex_enter(&cpu_lock); 255 /* 256 * Initialize the dispatcher first. 257 */ 258 disp_cpu_init(cp); 259 mutex_exit(&cpu_lock); 260 261 cpu_vm_data_init(cp); 262 263 /* 264 * Allocate and initialize the startup thread for this CPU. 265 * Interrupt and process switch stacks get allocated later 266 * when the CPU starts running. 267 */ 268 tp = thread_create(NULL, 0, NULL, NULL, 0, procp, 269 TS_STOPPED, maxclsyspri); 270 271 /* 272 * Set state to TS_ONPROC since this thread will start running 273 * as soon as the CPU comes online. 274 * 275 * All the other fields of the thread structure are setup by 276 * thread_create(). 277 */ 278 THREAD_ONPROC(tp, cp); 279 tp->t_preempt = 1; 280 tp->t_bound_cpu = cp; 281 tp->t_affinitycnt = 1; 282 tp->t_cpu = cp; 283 tp->t_disp_queue = cp->cpu_disp; 284 285 /* 286 * Setup thread to start in mp_startup. 287 */ 288 sp = tp->t_stk; 289 tp->t_pc = (uintptr_t)mp_startup; 290 tp->t_sp = (uintptr_t)(sp - MINFRAME); 291 292 cp->cpu_id = cpun; 293 cp->cpu_self = cp; 294 cp->cpu_thread = tp; 295 cp->cpu_lwp = NULL; 296 cp->cpu_dispthread = tp; 297 cp->cpu_dispatch_pri = DISP_PRIO(tp); 298 299 /* 300 * cpu_base_spl must be set explicitly here to prevent any blocking 301 * operations in mp_startup from causing the spl of the cpu to drop 302 * to 0 (allowing device interrupts before we're ready) in resume(). 303 * cpu_base_spl MUST remain at LOCK_LEVEL until the cpu is CPU_READY. 304 * As an extra bit of security on DEBUG kernels, this is enforced with 305 * an assertion in mp_startup() -- before cpu_base_spl is set to its 306 * proper value. 307 */ 308 cp->cpu_base_spl = ipltospl(LOCK_LEVEL); 309 310 /* 311 * Now, initialize per-CPU idle thread for this CPU. 312 */ 313 tp = thread_create(NULL, PAGESIZE, idle, NULL, 0, procp, TS_ONPROC, -1); 314 315 cp->cpu_idle_thread = tp; 316 317 tp->t_preempt = 1; 318 tp->t_bound_cpu = cp; 319 tp->t_affinitycnt = 1; 320 tp->t_cpu = cp; 321 tp->t_disp_queue = cp->cpu_disp; 322 323 /* 324 * Bootstrap the CPU for CMT aware scheduling 325 * The rest of the initialization will happen from 326 * mp_startup() 327 */ 328 chip_bootstrap_cpu(cp); 329 330 /* 331 * Perform CPC intialization on the new CPU. 332 */ 333 kcpc_hw_init(cp); 334 335 /* 336 * Allocate virtual addresses for cpu_caddr1 and cpu_caddr2 337 * for each CPU. 338 */ 339 340 setup_vaddr_for_ppcopy(cp); 341 342 /* 343 * Allocate space for page directory, stack, tss, gdt and idt. 344 * This assumes that kmem_alloc will return memory which is aligned 345 * to the next higher power of 2 or a page(if size > MAXABIG) 346 * If this assumption goes wrong at any time due to change in 347 * kmem alloc, things may not work as the page directory has to be 348 * page aligned 349 */ 350 if ((tablesp = kmem_zalloc(sizeof (*tablesp), KM_NOSLEEP)) == NULL) 351 panic("mp_startup_init: cpu%d cannot allocate tables", cpun); 352 353 if ((uintptr_t)tablesp & ~MMU_STD_PAGEMASK) { 354 kmem_free(tablesp, sizeof (struct cpu_tables)); 355 size = sizeof (struct cpu_tables) + MMU_STD_PAGESIZE; 356 tablesp = kmem_zalloc(size, KM_NOSLEEP); 357 tablesp = (struct cpu_tables *) 358 (((uintptr_t)tablesp + MMU_STD_PAGESIZE) & 359 MMU_STD_PAGEMASK); 360 } 361 362 ntss = cp->cpu_tss = &tablesp->ct_tss; 363 364 if ((tablesp->ct_gdt = kmem_zalloc(PAGESIZE, KM_NOSLEEP)) == NULL) 365 panic("mp_startup_init: cpu%d cannot allocate GDT", cpun); 366 cp->cpu_gdt = tablesp->ct_gdt; 367 bcopy(CPU->cpu_gdt, cp->cpu_gdt, NGDT * (sizeof (user_desc_t))); 368 369 #if defined(__amd64) 370 371 /* 372 * #DF (double fault). 373 */ 374 ntss->tss_ist1 = 375 (uint64_t)&tablesp->ct_stack[sizeof (tablesp->ct_stack)]; 376 377 #elif defined(__i386) 378 379 ntss->tss_esp0 = ntss->tss_esp1 = ntss->tss_esp2 = ntss->tss_esp = 380 (uint32_t)&tablesp->ct_stack[sizeof (tablesp->ct_stack)]; 381 382 ntss->tss_ss0 = ntss->tss_ss1 = ntss->tss_ss2 = ntss->tss_ss = KDS_SEL; 383 384 ntss->tss_eip = (uint32_t)mp_startup; 385 386 ntss->tss_cs = KCS_SEL; 387 ntss->tss_fs = KFS_SEL; 388 ntss->tss_gs = KGS_SEL; 389 390 /* 391 * setup kernel %gs. 392 */ 393 set_usegd(&cp->cpu_gdt[GDT_GS], cp, sizeof (struct cpu) -1, SDT_MEMRWA, 394 SEL_KPL, 0, 1); 395 396 #endif /* __i386 */ 397 398 /* 399 * Set I/O bit map offset equal to size of TSS segment limit 400 * for no I/O permission map. This will cause all user I/O 401 * instructions to generate #gp fault. 402 */ 403 ntss->tss_bitmapbase = sizeof (*ntss); 404 405 /* 406 * setup kernel tss. 407 */ 408 set_syssegd((system_desc_t *)&cp->cpu_gdt[GDT_KTSS], cp->cpu_tss, 409 sizeof (*cp->cpu_tss) -1, SDT_SYSTSS, SEL_KPL); 410 411 /* 412 * If we have more than one node, each cpu gets a copy of IDT 413 * local to its node. If this is a Pentium box, we use cpu 0's 414 * IDT. cpu 0's IDT has been made read-only to workaround the 415 * cmpxchgl register bug 416 */ 417 cp->cpu_idt = CPU->cpu_idt; 418 if (system_hardware.hd_nodes && x86_type != X86_TYPE_P5) { 419 cp->cpu_idt = kmem_alloc(sizeof (idt0), KM_SLEEP); 420 bcopy(idt0, cp->cpu_idt, sizeof (idt0)); 421 } 422 423 /* 424 * Get interrupt priority data from cpu 0 425 */ 426 cp->cpu_pri_data = CPU->cpu_pri_data; 427 428 hat_cpu_online(cp); 429 430 /* Should remove all entries for the current process/thread here */ 431 432 /* 433 * Fill up the real mode platter to make it easy for real mode code to 434 * kick it off. This area should really be one passed by boot to kernel 435 * and guaranteed to be below 1MB and aligned to 16 bytes. Should also 436 * have identical physical and virtual address in paged mode. 437 */ 438 real_mode_platter->rm_idt_base = cp->cpu_idt; 439 real_mode_platter->rm_idt_lim = sizeof (idt0) - 1; 440 real_mode_platter->rm_gdt_base = cp->cpu_gdt; 441 real_mode_platter->rm_gdt_lim = sizeof (gdt0) -1; 442 real_mode_platter->rm_pdbr = getcr3(); 443 real_mode_platter->rm_cpu = cpun; 444 real_mode_platter->rm_x86feature = x86_feature; 445 real_mode_platter->rm_cr4 = cr4_value; 446 447 #if defined(__amd64) 448 if (getcr3() > 0xffffffffUL) 449 panic("Cannot initialize CPUs; kernel's 64-bit page tables\n" 450 "located above 4G in physical memory (@ 0x%llx).", 451 (unsigned long long)getcr3()); 452 453 /* 454 * Setup pseudo-descriptors for temporary GDT and IDT for use ONLY 455 * by code in real_mode_start(): 456 * 457 * GDT[0]: NULL selector 458 * GDT[1]: 64-bit CS: Long = 1, Present = 1, bits 12, 11 = 1 459 * 460 * Clear the IDT as interrupts will be off and a limit of 0 will cause 461 * the CPU to triple fault and reset on an NMI, seemingly as reasonable 462 * a course of action as any other, though it may cause the entire 463 * platform to reset in some cases... 464 */ 465 real_mode_platter->rm_temp_gdt[0] = 0ULL; 466 real_mode_platter->rm_temp_gdt[TEMPGDT_KCODE64] = 0x20980000000000ULL; 467 468 real_mode_platter->rm_temp_gdt_lim = (ushort_t) 469 (sizeof (real_mode_platter->rm_temp_gdt) - 1); 470 real_mode_platter->rm_temp_gdt_base = rm_platter_pa + 471 (uint32_t)(&((rm_platter_t *)0)->rm_temp_gdt); 472 473 real_mode_platter->rm_temp_idt_lim = 0; 474 real_mode_platter->rm_temp_idt_base = 0; 475 476 /* 477 * Since the CPU needs to jump to protected mode using an identity 478 * mapped address, we need to calculate it here. 479 */ 480 real_mode_platter->rm_longmode64_addr = rm_platter_pa + 481 ((uint32_t)long_mode_64 - (uint32_t)real_mode_start); 482 #endif /* __amd64 */ 483 484 #ifdef TRAPTRACE 485 /* 486 * If this is a TRAPTRACE kernel, allocate TRAPTRACE buffers for this 487 * CPU. 488 */ 489 ttc->ttc_first = (uintptr_t)kmem_zalloc(trap_trace_bufsize, KM_SLEEP); 490 ttc->ttc_next = ttc->ttc_first; 491 ttc->ttc_limit = ttc->ttc_first + trap_trace_bufsize; 492 #endif 493 494 /* 495 * Record that we have another CPU. 496 */ 497 mutex_enter(&cpu_lock); 498 /* 499 * Initialize the interrupt threads for this CPU 500 */ 501 cpu_intr_alloc(cp, NINTR_THREADS); 502 /* 503 * Add CPU to list of available CPUs. It'll be on the active list 504 * after mp_startup(). 505 */ 506 cpu_add_unit(cp); 507 mutex_exit(&cpu_lock); 508 } 509 510 /* 511 * Apply workarounds for known errata, and warn about those that are absent. 512 * 513 * System vendors occasionally create configurations which contain different 514 * revisions of the CPUs that are almost but not exactly the same. At the 515 * time of writing, this meant that their clock rates were the same, their 516 * feature sets were the same, but the required workaround were -not- 517 * necessarily the same. So, this routine is invoked on -every- CPU soon 518 * after starting to make sure that the resulting system contains the most 519 * pessimal set of workarounds needed to cope with *any* of the CPUs in the 520 * system. 521 * 522 * workaround_errata is invoked early in mlsetup() for CPU 0, and in 523 * mp_startup() for all slave CPUs. Slaves process workaround_errata prior 524 * to acknowledging their readiness to the master, so this routine will 525 * never be executed by multiple CPUs in parallel, thus making updates to 526 * global data safe. 527 * 528 * These workarounds are based on Rev 3.57 of the Revision Guide for 529 * AMD Athlon(tm) 64 and AMD Opteron(tm) Processors, August 2005. 530 */ 531 532 #if defined(OPTERON_ERRATUM_91) 533 int opteron_erratum_91; /* if non-zero -> at least one cpu has it */ 534 #endif 535 536 #if defined(OPTERON_ERRATUM_93) 537 int opteron_erratum_93; /* if non-zero -> at least one cpu has it */ 538 #endif 539 540 #if defined(OPTERON_ERRATUM_100) 541 int opteron_erratum_100; /* if non-zero -> at least one cpu has it */ 542 #endif 543 544 #if defined(OPTERON_ERRATUM_109) 545 int opteron_erratum_109; /* if non-zero -> at least one cpu has it */ 546 #endif 547 548 #if defined(OPTERON_ERRATUM_121) 549 int opteron_erratum_121; /* if non-zero -> at least one cpu has it */ 550 #endif 551 552 #if defined(OPTERON_ERRATUM_122) 553 int opteron_erratum_122; /* if non-zero -> at least one cpu has it */ 554 #endif 555 556 #if defined(OPTERON_ERRATUM_123) 557 int opteron_erratum_123; /* if non-zero -> at least one cpu has it */ 558 #endif 559 560 #if defined(OPTERON_ERRATUM_131) 561 int opteron_erratum_131; /* if non-zero -> at least one cpu has it */ 562 #endif 563 564 #if defined(OPTERON_WORKAROUND_6336786) 565 int opteron_workaround_6336786; /* non-zero -> WA relevant and applied */ 566 int opteron_workaround_6336786_UP = 0; /* Not needed for UP */ 567 #endif 568 569 #if defined(OPTERON_WORKAROUND_6323525) 570 int opteron_workaround_6323525; /* if non-zero -> at least one cpu has it */ 571 #endif 572 573 #define WARNING(cpu, n) \ 574 cmn_err(CE_WARN, "cpu%d: no workaround for erratum %d", \ 575 (cpu)->cpu_id, (n)) 576 577 uint_t 578 workaround_errata(struct cpu *cpu) 579 { 580 uint_t missing = 0; 581 582 ASSERT(cpu == CPU); 583 584 /*LINTED*/ 585 if (cpuid_opteron_erratum(cpu, 88) > 0) { 586 /* 587 * SWAPGS May Fail To Read Correct GS Base 588 */ 589 #if defined(OPTERON_ERRATUM_88) 590 /* 591 * The workaround is an mfence in the relevant assembler code 592 */ 593 #else 594 WARNING(cpu, 88); 595 missing++; 596 #endif 597 } 598 599 if (cpuid_opteron_erratum(cpu, 91) > 0) { 600 /* 601 * Software Prefetches May Report A Page Fault 602 */ 603 #if defined(OPTERON_ERRATUM_91) 604 /* 605 * fix is in trap.c 606 */ 607 opteron_erratum_91++; 608 #else 609 WARNING(cpu, 91); 610 missing++; 611 #endif 612 } 613 614 if (cpuid_opteron_erratum(cpu, 93) > 0) { 615 /* 616 * RSM Auto-Halt Restart Returns to Incorrect RIP 617 */ 618 #if defined(OPTERON_ERRATUM_93) 619 /* 620 * fix is in trap.c 621 */ 622 opteron_erratum_93++; 623 #else 624 WARNING(cpu, 93); 625 missing++; 626 #endif 627 } 628 629 /*LINTED*/ 630 if (cpuid_opteron_erratum(cpu, 95) > 0) { 631 /* 632 * RET Instruction May Return to Incorrect EIP 633 */ 634 #if defined(OPTERON_ERRATUM_95) 635 #if defined(_LP64) 636 /* 637 * Workaround this by ensuring that 32-bit user code and 638 * 64-bit kernel code never occupy the same address 639 * range mod 4G. 640 */ 641 if (_userlimit32 > 0xc0000000ul) 642 *(uintptr_t *)&_userlimit32 = 0xc0000000ul; 643 644 /*LINTED*/ 645 ASSERT((uint32_t)COREHEAP_BASE == 0xc0000000u); 646 #endif /* _LP64 */ 647 #else 648 WARNING(cpu, 95); 649 missing++; 650 #endif /* OPTERON_ERRATUM_95 */ 651 } 652 653 if (cpuid_opteron_erratum(cpu, 100) > 0) { 654 /* 655 * Compatibility Mode Branches Transfer to Illegal Address 656 */ 657 #if defined(OPTERON_ERRATUM_100) 658 /* 659 * fix is in trap.c 660 */ 661 opteron_erratum_100++; 662 #else 663 WARNING(cpu, 100); 664 missing++; 665 #endif 666 } 667 668 /*LINTED*/ 669 if (cpuid_opteron_erratum(cpu, 108) > 0) { 670 /* 671 * CPUID Instruction May Return Incorrect Model Number In 672 * Some Processors 673 */ 674 #if defined(OPTERON_ERRATUM_108) 675 /* 676 * (Our cpuid-handling code corrects the model number on 677 * those processors) 678 */ 679 #else 680 WARNING(cpu, 108); 681 missing++; 682 #endif 683 } 684 685 /*LINTED*/ 686 if (cpuid_opteron_erratum(cpu, 109) > 0) { 687 /* 688 * Certain Reverse REP MOVS May Produce Unpredictable Behaviour 689 */ 690 #if defined(OPTERON_ERRATUM_109) 691 692 /* workaround is to print a warning to upgrade BIOS */ 693 if (rdmsr(MSR_AMD_PATCHLEVEL) == 0) 694 opteron_erratum_109++; 695 #else 696 WARNING(cpu, 109); 697 missing++; 698 #endif 699 } 700 /*LINTED*/ 701 if (cpuid_opteron_erratum(cpu, 121) > 0) { 702 /* 703 * Sequential Execution Across Non_Canonical Boundary Caused 704 * Processor Hang 705 */ 706 #if defined(OPTERON_ERRATUM_121) 707 static int lma; 708 709 if (opteron_erratum_121) 710 opteron_erratum_121++; 711 712 /* 713 * Erratum 121 is only present in long (64 bit) mode. 714 * Workaround is to include the page immediately before the 715 * va hole to eliminate the possibility of system hangs due to 716 * sequential execution across the va hole boundary. 717 */ 718 if (lma == 0) { 719 /* 720 * check LMA once: assume all cpus are in long mode 721 * or not. 722 */ 723 lma = 1; 724 725 if (rdmsr(MSR_AMD_EFER) & AMD_EFER_LMA) { 726 if (hole_start) { 727 hole_start -= PAGESIZE; 728 } else { 729 /* 730 * hole_start not yet initialized by 731 * mmu_init. Initialize hole_start 732 * with value to be subtracted. 733 */ 734 hole_start = PAGESIZE; 735 } 736 opteron_erratum_121++; 737 } 738 } 739 #else 740 WARNING(cpu, 121); 741 missing++; 742 #endif 743 } 744 745 /*LINTED*/ 746 if (cpuid_opteron_erratum(cpu, 122) > 0) { 747 /* 748 * TLB Flush Filter May Cause Cohenrency Problem in 749 * Multiprocessor Systems 750 */ 751 #if defined(OPTERON_ERRATUM_122) 752 /* 753 * Erratum 122 is only present in MP configurations (multi-core 754 * or multi-processor). 755 */ 756 757 if (opteron_erratum_122 || lgrp_plat_node_cnt > 1 || 758 cpuid_get_ncpu_per_chip(cpu) > 1) { 759 /* disable TLB Flush Filter */ 760 wrmsr(MSR_AMD_HWCR, rdmsr(MSR_AMD_HWCR) | 761 (uint64_t)(uintptr_t)AMD_HWCR_FFDIS); 762 opteron_erratum_122++; 763 } 764 765 #else 766 WARNING(cpu, 122); 767 missing++; 768 #endif 769 } 770 771 #if defined(OPTERON_ERRATUM_123) 772 /*LINTED*/ 773 if (cpuid_opteron_erratum(cpu, 123) > 0) { 774 /* 775 * Bypassed Reads May Cause Data Corruption of System Hang in 776 * Dual Core Processors 777 */ 778 /* 779 * Erratum 123 applies only to multi-core cpus. 780 */ 781 782 if (cpuid_get_ncpu_per_chip(cpu) > 1) { 783 /* workaround is to print a warning to upgrade BIOS */ 784 if (rdmsr(MSR_AMD_PATCHLEVEL) == 0) 785 opteron_erratum_123++; 786 } 787 } 788 #endif 789 790 #if defined(OPTERON_ERRATUM_131) 791 /*LINTED*/ 792 if (cpuid_opteron_erratum(cpu, 131) > 0) { 793 /* 794 * Multiprocessor Systems with Four or More Cores May Deadlock 795 * Waiting for a Probe Response 796 */ 797 /* 798 * Erratum 131 applies to any system with four or more cores. 799 */ 800 if ((opteron_erratum_131 == 0) && ((lgrp_plat_node_cnt * 801 cpuid_get_ncpu_per_chip(cpu)) >= 4)) { 802 uint64_t nbcfg; 803 uint64_t wabits; 804 805 /* 806 * Print a warning if neither of the workarounds 807 * for Erratum 131 is present. 808 */ 809 810 wabits = AMD_NB_CFG_SRQ_HEARTBEAT | 811 AMD_NB_CFG_SRQ_SPR; 812 813 nbcfg = rdmsr(MSR_AMD_NB_CFG); 814 if ((nbcfg & wabits) == 0) { 815 opteron_erratum_131++; 816 } else { 817 /* cannot have both workarounds set */ 818 ASSERT((nbcfg & wabits) != wabits); 819 } 820 } 821 } 822 #endif 823 824 #if defined(OPTERON_WORKAROUND_6336786) 825 /* 826 * This isn't really erratum, but for convenience the 827 * detection/workaround code lives here and in cpuid_opteron_erratum. 828 */ 829 if (cpuid_opteron_erratum(cpu, 6336786) > 0) { 830 int node; 831 uint8_t data; 832 833 /* 834 * Disable C1-Clock ramping on multi-core/multi-processor 835 * K8 platforms to guard against TSC drift. 836 */ 837 if (opteron_workaround_6336786) { 838 opteron_workaround_6336786++; 839 } else if ((lgrp_plat_node_cnt * 840 cpuid_get_ncpu_per_chip(cpu) >= 2) || 841 opteron_workaround_6336786_UP) { 842 for (node = 0; node < lgrp_plat_node_cnt; node++) { 843 /* 844 * Clear PMM7[1:0] (function 3, offset 0x87) 845 * Northbridge device is the node id + 24. 846 */ 847 data = pci_getb_func(0, node + 24, 3, 0x87); 848 data &= 0xFC; 849 pci_putb_func(0, node + 24, 3, 0x87, data); 850 } 851 opteron_workaround_6336786++; 852 } 853 } 854 #endif 855 856 #if defined(OPTERON_WORKAROUND_6323525) 857 /*LINTED*/ 858 /* 859 * Mutex primitives don't work as expected. 860 */ 861 if (cpuid_opteron_erratum(cpu, 6323525) > 0) { 862 863 /* 864 * problem only occurs with 2 or more cores. If bit in 865 * MSR_BU_CFG set, then not applicable. The workaround 866 * is to patch the semaphone routines with the lfence 867 * instruction to provide necessary load memory barrier with 868 * possible subsequent read-modify-write ops. 869 * 870 * It is too early in boot to call the patch routine so 871 * set erratum variable to be done in startup_end(). 872 */ 873 if (opteron_workaround_6323525) { 874 opteron_workaround_6323525++; 875 } else if ((x86_feature & X86_SSE2) && ((lgrp_plat_node_cnt * 876 cpuid_get_ncpu_per_chip(cpu)) >= 2)) { 877 if ((xrdmsr(MSR_BU_CFG) & 0x02) == 0) 878 opteron_workaround_6323525++; 879 } 880 } 881 #endif 882 return (missing); 883 } 884 885 void 886 workaround_errata_end() 887 { 888 #if defined(OPTERON_ERRATUM_109) 889 if (opteron_erratum_109) { 890 cmn_err(CE_WARN, 891 "BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)" 892 " processor\nerratum 109 was not detected; updating your" 893 " system's BIOS to a version\ncontaining this" 894 " microcode patch is HIGHLY recommended or erroneous" 895 " system\noperation may occur.\n"); 896 } 897 #endif /* OPTERON_ERRATUM_109 */ 898 #if defined(OPTERON_ERRATUM_123) 899 if (opteron_erratum_123) { 900 cmn_err(CE_WARN, 901 "BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)" 902 " processor\nerratum 123 was not detected; updating your" 903 " system's BIOS to a version\ncontaining this" 904 " microcode patch is HIGHLY recommended or erroneous" 905 " system\noperation may occur.\n"); 906 } 907 #endif /* OPTERON_ERRATUM_123 */ 908 #if defined(OPTERON_ERRATUM_131) 909 if (opteron_erratum_131) { 910 cmn_err(CE_WARN, 911 "BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)" 912 " processor\nerratum 131 was not detected; updating your" 913 " system's BIOS to a version\ncontaining this" 914 " microcode patch is HIGHLY recommended or erroneous" 915 " system\noperation may occur.\n"); 916 } 917 #endif /* OPTERON_ERRATUM_131 */ 918 } 919 920 static ushort_t *mp_map_warm_reset_vector(); 921 static void mp_unmap_warm_reset_vector(ushort_t *warm_reset_vector); 922 923 static cpuset_t procset = 1; 924 925 /*ARGSUSED*/ 926 void 927 start_other_cpus(int cprboot) 928 { 929 unsigned int who; 930 int skipped = 0; 931 int cpuid = 0; 932 int delays = 0; 933 int started_cpu; 934 ushort_t *warm_reset_vector = NULL; 935 936 /* 937 * Initialize our own cpu_info. 938 */ 939 init_cpu_info(CPU); 940 941 /* 942 * Initialize our syscall handlers 943 */ 944 init_cpu_syscall(CPU); 945 946 /* 947 * if only 1 cpu or not using MP, skip the rest of this 948 */ 949 if (CPUSET_ISEQUAL(mp_cpus, cpu_ready_set) || use_mp == 0) { 950 if (use_mp == 0) 951 cmn_err(CE_CONT, "?***** Not in MP mode\n"); 952 goto done; 953 } 954 955 /* 956 * perform such initialization as is needed 957 * to be able to take CPUs on- and off-line. 958 */ 959 cpu_pause_init(); 960 961 xc_init(); /* initialize processor crosscalls */ 962 963 /* 964 * Copy the real mode code at "real_mode_start" to the 965 * page at rm_platter_va. 966 */ 967 warm_reset_vector = mp_map_warm_reset_vector(); 968 if (warm_reset_vector == NULL) 969 goto done; 970 971 bcopy((caddr_t)real_mode_start, 972 (caddr_t)((rm_platter_t *)rm_platter_va)->rm_code, 973 (size_t)real_mode_end - (size_t)real_mode_start); 974 975 flushes_require_xcalls = 1; 976 977 affinity_set(CPU_CURRENT); 978 979 for (who = 0; who < NCPU; who++) { 980 if (who == cpuid) 981 continue; 982 if (!CPU_IN_SET(mp_cpus, who)) 983 continue; 984 985 if (ncpus >= max_ncpus) { 986 skipped = who; 987 continue; 988 } 989 990 mp_startup_init(who); 991 started_cpu = 1; 992 (*cpu_startf)(who, rm_platter_pa); 993 994 while (!CPU_IN_SET(procset, who)) { 995 996 delay(1); 997 if (++delays > (20 * hz)) { 998 999 cmn_err(CE_WARN, 1000 "cpu%d failed to start", who); 1001 1002 mutex_enter(&cpu_lock); 1003 cpu[who]->cpu_flags = 0; 1004 cpu_vm_data_destroy(cpu[who]); 1005 cpu_del_unit(who); 1006 mutex_exit(&cpu_lock); 1007 1008 started_cpu = 0; 1009 break; 1010 } 1011 } 1012 if (!started_cpu) 1013 continue; 1014 if (tsc_gethrtime_enable) 1015 tsc_sync_master(who); 1016 1017 if (dtrace_cpu_init != NULL) { 1018 /* 1019 * DTrace CPU initialization expects cpu_lock 1020 * to be held. 1021 */ 1022 mutex_enter(&cpu_lock); 1023 (*dtrace_cpu_init)(who); 1024 mutex_exit(&cpu_lock); 1025 } 1026 } 1027 1028 affinity_clear(); 1029 1030 for (who = 0; who < NCPU; who++) { 1031 if (who == cpuid) 1032 continue; 1033 1034 if (!CPU_IN_SET(procset, who)) 1035 continue; 1036 1037 while (!CPU_IN_SET(cpu_ready_set, who)) 1038 delay(1); 1039 } 1040 1041 if (skipped) { 1042 cmn_err(CE_NOTE, 1043 "System detected %d CPU(s), but " 1044 "only %d CPU(s) were enabled during boot.", 1045 skipped + 1, ncpus); 1046 cmn_err(CE_NOTE, 1047 "Use \"boot-ncpus\" parameter to enable more CPU(s). " 1048 "See eeprom(1M)."); 1049 } 1050 1051 done: 1052 workaround_errata_end(); 1053 1054 if (warm_reset_vector != NULL) 1055 mp_unmap_warm_reset_vector(warm_reset_vector); 1056 hat_unload(kas.a_hat, (caddr_t)(uintptr_t)rm_platter_pa, MMU_PAGESIZE, 1057 HAT_UNLOAD); 1058 1059 cmi_post_mpstartup(); 1060 } 1061 1062 /* 1063 * Dummy functions - no i86pc platforms support dynamic cpu allocation. 1064 */ 1065 /*ARGSUSED*/ 1066 int 1067 mp_cpu_configure(int cpuid) 1068 { 1069 return (ENOTSUP); /* not supported */ 1070 } 1071 1072 /*ARGSUSED*/ 1073 int 1074 mp_cpu_unconfigure(int cpuid) 1075 { 1076 return (ENOTSUP); /* not supported */ 1077 } 1078 1079 /* 1080 * Startup function for 'other' CPUs (besides boot cpu). 1081 * Called from real_mode_start (after *ap_mlsetup). 1082 * 1083 * WARNING: until CPU_READY is set, mp_startup and routines called by 1084 * mp_startup should not call routines (e.g. kmem_free) that could call 1085 * hat_unload which requires CPU_READY to be set. 1086 */ 1087 void 1088 mp_startup(void) 1089 { 1090 struct cpu *cp = CPU; 1091 uint_t new_x86_feature; 1092 1093 new_x86_feature = cpuid_pass1(cp); 1094 1095 /* 1096 * We need to Sync MTRR with cpu0's MTRR. We have to do 1097 * this with interrupts disabled. 1098 */ 1099 if (x86_feature & X86_MTRR) 1100 mtrr_sync(); 1101 1102 /* 1103 * Initialize this CPU's syscall handlers 1104 */ 1105 init_cpu_syscall(cp); 1106 1107 /* 1108 * Enable interrupts with spl set to LOCK_LEVEL. LOCK_LEVEL is the 1109 * highest level at which a routine is permitted to block on 1110 * an adaptive mutex (allows for cpu poke interrupt in case 1111 * the cpu is blocked on a mutex and halts). Setting LOCK_LEVEL blocks 1112 * device interrupts that may end up in the hat layer issuing cross 1113 * calls before CPU_READY is set. 1114 */ 1115 (void) splx(ipltospl(LOCK_LEVEL)); 1116 1117 /* 1118 * Do a sanity check to make sure this new CPU is a sane thing 1119 * to add to the collection of processors running this system. 1120 * 1121 * XXX Clearly this needs to get more sophisticated, if x86 1122 * systems start to get built out of heterogenous CPUs; as is 1123 * likely to happen once the number of processors in a configuration 1124 * gets large enough. 1125 */ 1126 if ((x86_feature & new_x86_feature) != x86_feature) { 1127 cmn_err(CE_CONT, "?cpu%d: %b\n", 1128 cp->cpu_id, new_x86_feature, FMT_X86_FEATURE); 1129 cmn_err(CE_WARN, "cpu%d feature mismatch", cp->cpu_id); 1130 } 1131 1132 /* 1133 * We could be more sophisticated here, and just mark the CPU 1134 * as "faulted" but at this point we'll opt for the easier 1135 * answer of dieing horribly. Provided the boot cpu is ok, 1136 * the system can be recovered by booting with use_mp set to zero. 1137 */ 1138 if (workaround_errata(cp) != 0) 1139 panic("critical workaround(s) missing for cpu%d", cp->cpu_id); 1140 1141 cpuid_pass2(cp); 1142 cpuid_pass3(cp); 1143 (void) cpuid_pass4(cp); 1144 1145 init_cpu_info(cp); 1146 1147 mutex_enter(&cpu_lock); 1148 CPUSET_ADD(procset, cp->cpu_id); 1149 mutex_exit(&cpu_lock); 1150 1151 if (tsc_gethrtime_enable) 1152 tsc_sync_slave(); 1153 1154 mutex_enter(&cpu_lock); 1155 /* 1156 * It's unfortunate that chip_cpu_init() has to be called here. 1157 * It really belongs in cpu_add_unit(), but unfortunately it is 1158 * dependent on the cpuid probing, which must be done in the 1159 * context of the current CPU. Care must be taken on x86 to ensure 1160 * that mp_startup can safely block even though chip_cpu_init() and 1161 * cpu_add_active() have not yet been called. 1162 */ 1163 chip_cpu_init(cp); 1164 chip_cpu_startup(cp); 1165 1166 cp->cpu_flags |= CPU_RUNNING | CPU_READY | CPU_ENABLE | CPU_EXISTS; 1167 cpu_add_active(cp); 1168 mutex_exit(&cpu_lock); 1169 1170 add_cpunode2devtree(cp->cpu_id, cp->cpu_m.mcpu_cpi); 1171 1172 /* The base spl should still be at LOCK LEVEL here */ 1173 ASSERT(cp->cpu_base_spl == ipltospl(LOCK_LEVEL)); 1174 set_base_spl(); /* Restore the spl to its proper value */ 1175 1176 (void) spl0(); /* enable interrupts */ 1177 1178 /* 1179 * Set up the CPU module for this CPU. This can't be done before 1180 * this CPU is made CPU_READY, because we may (in heterogeneous systems) 1181 * need to go load another CPU module. The act of attempting to load 1182 * a module may trigger a cross-call, which will ASSERT unless this 1183 * cpu is CPU_READY. 1184 */ 1185 cmi_init(); 1186 1187 if (x86_feature & X86_MCA) 1188 cmi_mca_init(); 1189 1190 if (boothowto & RB_DEBUG) 1191 kdi_dvec_cpu_init(cp); 1192 1193 /* 1194 * Setting the bit in cpu_ready_set must be the last operation in 1195 * processor initialization; the boot CPU will continue to boot once 1196 * it sees this bit set for all active CPUs. 1197 */ 1198 CPUSET_ATOMIC_ADD(cpu_ready_set, cp->cpu_id); 1199 1200 /* 1201 * Because mp_startup() gets fired off after init() starts, we 1202 * can't use the '?' trick to do 'boot -v' printing - so we 1203 * always direct the 'cpu .. online' messages to the log. 1204 */ 1205 cmn_err(CE_CONT, "!cpu%d initialization complete - online\n", 1206 cp->cpu_id); 1207 1208 /* 1209 * Now we are done with the startup thread, so free it up. 1210 */ 1211 thread_exit(); 1212 panic("mp_startup: cannot return"); 1213 /*NOTREACHED*/ 1214 } 1215 1216 1217 /* 1218 * Start CPU on user request. 1219 */ 1220 /* ARGSUSED */ 1221 int 1222 mp_cpu_start(struct cpu *cp) 1223 { 1224 ASSERT(MUTEX_HELD(&cpu_lock)); 1225 return (0); 1226 } 1227 1228 /* 1229 * Stop CPU on user request. 1230 */ 1231 /* ARGSUSED */ 1232 int 1233 mp_cpu_stop(struct cpu *cp) 1234 { 1235 extern int cbe_psm_timer_mode; 1236 ASSERT(MUTEX_HELD(&cpu_lock)); 1237 1238 /* 1239 * If TIMER_PERIODIC mode is used, CPU0 is the one running it; 1240 * can't stop it. (This is true only for machines with no TSC.) 1241 */ 1242 1243 if ((cbe_psm_timer_mode == TIMER_PERIODIC) && (cp->cpu_id == 0)) 1244 return (1); 1245 1246 return (0); 1247 } 1248 1249 /* 1250 * Power on CPU. 1251 */ 1252 /* ARGSUSED */ 1253 int 1254 mp_cpu_poweron(struct cpu *cp) 1255 { 1256 ASSERT(MUTEX_HELD(&cpu_lock)); 1257 return (ENOTSUP); /* not supported */ 1258 } 1259 1260 /* 1261 * Power off CPU. 1262 */ 1263 /* ARGSUSED */ 1264 int 1265 mp_cpu_poweroff(struct cpu *cp) 1266 { 1267 ASSERT(MUTEX_HELD(&cpu_lock)); 1268 return (ENOTSUP); /* not supported */ 1269 } 1270 1271 1272 /* 1273 * Take the specified CPU out of participation in interrupts. 1274 */ 1275 int 1276 cpu_disable_intr(struct cpu *cp) 1277 { 1278 if (psm_disable_intr(cp->cpu_id) != DDI_SUCCESS) 1279 return (EBUSY); 1280 1281 cp->cpu_flags &= ~CPU_ENABLE; 1282 return (0); 1283 } 1284 1285 /* 1286 * Allow the specified CPU to participate in interrupts. 1287 */ 1288 void 1289 cpu_enable_intr(struct cpu *cp) 1290 { 1291 ASSERT(MUTEX_HELD(&cpu_lock)); 1292 cp->cpu_flags |= CPU_ENABLE; 1293 psm_enable_intr(cp->cpu_id); 1294 } 1295 1296 1297 1298 static ushort_t * 1299 mp_map_warm_reset_vector() 1300 { 1301 ushort_t *warm_reset_vector; 1302 1303 if (!(warm_reset_vector = (ushort_t *)psm_map_phys(WARM_RESET_VECTOR, 1304 sizeof (ushort_t *), PROT_READ|PROT_WRITE))) 1305 return (NULL); 1306 1307 /* 1308 * setup secondary cpu bios boot up vector 1309 */ 1310 *warm_reset_vector = (ushort_t)((caddr_t) 1311 ((struct rm_platter *)rm_platter_va)->rm_code - rm_platter_va 1312 + ((ulong_t)rm_platter_va & 0xf)); 1313 warm_reset_vector++; 1314 *warm_reset_vector = (ushort_t)(rm_platter_pa >> 4); 1315 1316 --warm_reset_vector; 1317 return (warm_reset_vector); 1318 } 1319 1320 static void 1321 mp_unmap_warm_reset_vector(ushort_t *warm_reset_vector) 1322 { 1323 psm_unmap_phys((caddr_t)warm_reset_vector, sizeof (ushort_t *)); 1324 } 1325 1326 void 1327 mp_cpu_faulted_enter(struct cpu *cp) 1328 { 1329 cmi_faulted_enter(cp); 1330 } 1331 1332 void 1333 mp_cpu_faulted_exit(struct cpu *cp) 1334 { 1335 cmi_faulted_exit(cp); 1336 } 1337 1338 /* 1339 * The following two routines are used as context operators on threads belonging 1340 * to processes with a private LDT (see sysi86). Due to the rarity of such 1341 * processes, these routines are currently written for best code readability and 1342 * organization rather than speed. We could avoid checking x86_feature at every 1343 * context switch by installing different context ops, depending on the 1344 * x86_feature flags, at LDT creation time -- one for each combination of fast 1345 * syscall feature flags. 1346 */ 1347 1348 /*ARGSUSED*/ 1349 void 1350 cpu_fast_syscall_disable(void *arg) 1351 { 1352 if (x86_feature & X86_SEP) 1353 cpu_sep_disable(); 1354 if (x86_feature & X86_ASYSC) 1355 cpu_asysc_disable(); 1356 } 1357 1358 /*ARGSUSED*/ 1359 void 1360 cpu_fast_syscall_enable(void *arg) 1361 { 1362 if (x86_feature & X86_SEP) 1363 cpu_sep_enable(); 1364 if (x86_feature & X86_ASYSC) 1365 cpu_asysc_enable(); 1366 } 1367 1368 static void 1369 cpu_sep_enable(void) 1370 { 1371 ASSERT(x86_feature & X86_SEP); 1372 ASSERT(curthread->t_preempt || getpil() >= LOCK_LEVEL); 1373 1374 wrmsr(MSR_INTC_SEP_CS, (uint64_t)(uintptr_t)KCS_SEL); 1375 } 1376 1377 static void 1378 cpu_sep_disable(void) 1379 { 1380 ASSERT(x86_feature & X86_SEP); 1381 ASSERT(curthread->t_preempt || getpil() >= LOCK_LEVEL); 1382 1383 /* 1384 * Setting the SYSENTER_CS_MSR register to 0 causes software executing 1385 * the sysenter or sysexit instruction to trigger a #gp fault. 1386 */ 1387 wrmsr(MSR_INTC_SEP_CS, 0ULL); 1388 } 1389 1390 static void 1391 cpu_asysc_enable(void) 1392 { 1393 ASSERT(x86_feature & X86_ASYSC); 1394 ASSERT(curthread->t_preempt || getpil() >= LOCK_LEVEL); 1395 1396 wrmsr(MSR_AMD_EFER, rdmsr(MSR_AMD_EFER) | 1397 (uint64_t)(uintptr_t)AMD_EFER_SCE); 1398 } 1399 1400 static void 1401 cpu_asysc_disable(void) 1402 { 1403 ASSERT(x86_feature & X86_ASYSC); 1404 ASSERT(curthread->t_preempt || getpil() >= LOCK_LEVEL); 1405 1406 /* 1407 * Turn off the SCE (syscall enable) bit in the EFER register. Software 1408 * executing syscall or sysret with this bit off will incur a #ud trap. 1409 */ 1410 wrmsr(MSR_AMD_EFER, rdmsr(MSR_AMD_EFER) & 1411 ~((uint64_t)(uintptr_t)AMD_EFER_SCE)); 1412 } 1413