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.
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.
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]
23 * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
26 * Copyright (c) 2010, Intel Corporation.
27 * All rights reserved.
30 * Copyright 2016 Joyent, Inc.
31 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
34 #include <sys/types.h>
35 #include <sys/thread.h>
36 #include <sys/cpuvar.h>
38 #include <sys/t_lock.h>
39 #include <sys/param.h>
42 #include <sys/class.h>
43 #include <sys/cmn_err.h>
44 #include <sys/debug.h>
46 #include <sys/asm_linkage.h>
47 #include <sys/x_call.h>
48 #include <sys/systm.h>
50 #include <sys/vtrace.h>
53 #include <vm/seg_kmem.h>
54 #include <vm/seg_kp.h>
55 #include <sys/segments.h>
57 #include <sys/stack.h>
58 #include <sys/smp_impldefs.h>
59 #include <sys/x86_archext.h>
60 #include <sys/machsystm.h>
61 #include <sys/traptrace.h>
62 #include <sys/clock.h>
63 #include <sys/cpc_impl.h>
66 #include <sys/dtrace.h>
67 #include <sys/archsystm.h>
69 #include <sys/reboot.h>
70 #include <sys/kdi_machimpl.h>
71 #include <vm/hat_i86.h>
72 #include <vm/vm_dep.h>
73 #include <sys/memnode.h>
74 #include <sys/pci_cfgspace.h>
75 #include <sys/mach_mmu.h>
76 #include <sys/sysmacros.h>
78 #include <sys/hypervisor.h>
80 #include <sys/cpu_module.h>
81 #include <sys/ontrap.h>
83 struct cpu cpus
[1]; /* CPU data */
84 struct cpu
*cpu
[NCPU
] = {&cpus
[0]}; /* pointers to all CPUs */
85 struct cpu
*cpu_free_list
; /* list for released CPUs */
86 cpu_core_t cpu_core
[NCPU
]; /* cpu_core structures */
88 #define cpu_next_free cpu_prev
91 * Useful for disabling MP bring-up on a MP capable system.
96 * to be set by a PSM to indicate what cpus
97 * are sitting around on the system.
102 * This variable is used by the hat layer to decide whether or not
103 * critical sections are needed to prevent race conditions. For sun4m,
104 * this variable is set once enough MP initialization has been done in
105 * order to allow cross calls.
107 int flushes_require_xcalls
;
109 cpuset_t cpu_ready_set
; /* initialized in startup() */
111 static void mp_startup_boot(void);
112 static void mp_startup_hotplug(void);
114 static void cpu_sep_enable(void);
115 static void cpu_sep_disable(void);
116 static void cpu_asysc_enable(void);
117 static void cpu_asysc_disable(void);
120 * Init CPU info - get CPU type info for processor_info system call.
123 init_cpu_info(struct cpu
*cp
)
125 processor_info_t
*pi
= &cp
->cpu_type_info
;
128 * Get clock-frequency property for the CPU.
130 pi
->pi_clock
= cpu_freq
;
133 * Current frequency in Hz.
135 cp
->cpu_curr_clock
= cpu_freq_hz
;
138 * Supported frequencies.
140 if (cp
->cpu_supp_freqs
== NULL
) {
141 cpu_set_supp_freqs(cp
, NULL
);
144 (void) strcpy(pi
->pi_processor_type
, "i386");
146 (void) strcpy(pi
->pi_fputypes
, "i387 compatible");
148 cp
->cpu_idstr
= kmem_zalloc(CPU_IDSTRLEN
, KM_SLEEP
);
149 cp
->cpu_brandstr
= kmem_zalloc(CPU_IDSTRLEN
, KM_SLEEP
);
152 * If called for the BSP, cp is equal to current CPU.
153 * For non-BSPs, cpuid info of cp is not ready yet, so use cpuid info
154 * of current CPU as default values for cpu_idstr and cpu_brandstr.
155 * They will be corrected in mp_startup_common() after cpuid_pass1()
156 * has been invoked on target CPU.
158 (void) cpuid_getidstr(CPU
, cp
->cpu_idstr
, CPU_IDSTRLEN
);
159 (void) cpuid_getbrandstr(CPU
, cp
->cpu_brandstr
, CPU_IDSTRLEN
);
163 * Configure syscall support on this CPU.
167 init_cpu_syscall(struct cpu
*cp
)
172 if (is_x86_feature(x86_featureset
, X86FSET_MSR
) &&
173 is_x86_feature(x86_featureset
, X86FSET_ASYSC
)) {
178 * The syscall instruction imposes a certain ordering on
179 * segment selectors, so we double-check that ordering
182 ASSERT(KDS_SEL
== KCS_SEL
+ 8);
183 ASSERT(UDS_SEL
== U32CS_SEL
+ 8);
184 ASSERT(UCS_SEL
== U32CS_SEL
+ 16);
187 * Turn syscall/sysret extensions on.
192 * Program the magic registers ..
195 ((uint64_t)(U32CS_SEL
<< 16 | KCS_SEL
)) << 32);
196 wrmsr(MSR_AMD_LSTAR
, (uint64_t)(uintptr_t)sys_syscall
);
197 wrmsr(MSR_AMD_CSTAR
, (uint64_t)(uintptr_t)sys_syscall32
);
200 * This list of flags is masked off the incoming
201 * %rfl when we enter the kernel.
203 flags
= PS_IE
| PS_T
;
204 if (is_x86_feature(x86_featureset
, X86FSET_SMAP
) == B_TRUE
)
206 wrmsr(MSR_AMD_SFMASK
, flags
);
211 * On 32-bit kernels, we use sysenter/sysexit because it's too
212 * hard to use syscall/sysret, and it is more portable anyway.
214 * On 64-bit kernels on Nocona machines, the 32-bit syscall
215 * variant isn't available to 32-bit applications, but sysenter is.
217 if (is_x86_feature(x86_featureset
, X86FSET_MSR
) &&
218 is_x86_feature(x86_featureset
, X86FSET_SEP
)) {
222 * The sysenter instruction imposes a certain ordering on
223 * segment selectors, so we double-check that ordering
224 * here. See "sysenter" in Intel document 245471-012, "IA-32
225 * Intel Architecture Software Developer's Manual Volume 2:
226 * Instruction Set Reference"
228 ASSERT(KDS_SEL
== KCS_SEL
+ 8);
230 ASSERT32(UCS_SEL
== ((KCS_SEL
+ 16) | 3));
231 ASSERT32(UDS_SEL
== UCS_SEL
+ 8);
233 ASSERT64(U32CS_SEL
== ((KCS_SEL
+ 16) | 3));
234 ASSERT64(UDS_SEL
== U32CS_SEL
+ 8);
240 * resume() sets this value to the base of the threads stack
241 * via a context handler.
243 wrmsr(MSR_INTC_SEP_ESP
, 0);
244 wrmsr(MSR_INTC_SEP_EIP
, (uint64_t)(uintptr_t)sys_sysenter
);
252 * Configure per-cpu ID GDT
255 init_cpu_id_gdt(struct cpu
*cp
)
257 /* Write cpu_id into limit field of GDT for usermode retrieval */
259 set_usegd(&cp
->cpu_gdt
[GDT_CPUID
], SDP_SHORT
, NULL
, cp
->cpu_id
,
260 SDT_MEMRODA
, SEL_UPL
, SDP_BYTES
, SDP_OP32
);
261 #elif defined(__i386)
262 set_usegd(&cp
->cpu_gdt
[GDT_CPUID
], NULL
, cp
->cpu_id
, SDT_MEMRODA
,
263 SEL_UPL
, SDP_BYTES
, SDP_OP32
);
266 #endif /* !defined(__xpv) */
269 * Multiprocessor initialization.
271 * Allocate and initialize the cpu structure, TRAPTRACE buffer, and the
272 * startup and idle threads for the specified CPU.
273 * Parameter boot is true for boot time operations and is false for CPU
277 mp_cpu_configure_common(int cpun
, boolean_t boot
)
284 extern int idle_cpu_prefer_mwait
;
285 extern void cpu_idle_mwait();
288 extern void cpu_idle();
291 trap_trace_ctl_t
*ttc
= &trap_trace_ctl
[cpun
];
294 ASSERT(MUTEX_HELD(&cpu_lock
));
295 ASSERT(cpun
< NCPU
&& cpu
[cpun
] == NULL
);
297 if (cpu_free_list
== NULL
) {
298 cp
= kmem_zalloc(sizeof (*cp
), KM_SLEEP
);
301 cpu_free_list
= cp
->cpu_next_free
;
304 cp
->cpu_m
.mcpu_istamp
= cpun
<< 16;
306 /* Create per CPU specific threads in the process p0. */
310 * Initialize the dispatcher first.
314 cpu_vm_data_init(cp
);
317 * Allocate and initialize the startup thread for this CPU.
318 * Interrupt and process switch stacks get allocated later
319 * when the CPU starts running.
321 tp
= thread_create(NULL
, 0, NULL
, NULL
, 0, procp
,
322 TS_STOPPED
, maxclsyspri
);
325 * Set state to TS_ONPROC since this thread will start running
326 * as soon as the CPU comes online.
328 * All the other fields of the thread structure are setup by
331 THREAD_ONPROC(tp
, cp
);
333 tp
->t_bound_cpu
= cp
;
334 tp
->t_affinitycnt
= 1;
336 tp
->t_disp_queue
= cp
->cpu_disp
;
339 * Setup thread to start in mp_startup_common.
342 tp
->t_sp
= (uintptr_t)(sp
- MINFRAME
);
344 tp
->t_sp
-= STACK_ENTRY_ALIGN
; /* fake a call */
347 * Setup thread start entry point for boot or hotplug.
350 tp
->t_pc
= (uintptr_t)mp_startup_boot
;
352 tp
->t_pc
= (uintptr_t)mp_startup_hotplug
;
359 cp
->cpu_dispthread
= tp
;
360 cp
->cpu_dispatch_pri
= DISP_PRIO(tp
);
363 * cpu_base_spl must be set explicitly here to prevent any blocking
364 * operations in mp_startup_common from causing the spl of the cpu
365 * to drop to 0 (allowing device interrupts before we're ready) in
367 * cpu_base_spl MUST remain at LOCK_LEVEL until the cpu is CPU_READY.
368 * As an extra bit of security on DEBUG kernels, this is enforced with
369 * an assertion in mp_startup_common() -- before cpu_base_spl is set
370 * to its proper value.
372 cp
->cpu_base_spl
= ipltospl(LOCK_LEVEL
);
375 * Now, initialize per-CPU idle thread for this CPU.
377 tp
= thread_create(NULL
, PAGESIZE
, idle
, NULL
, 0, procp
, TS_ONPROC
, -1);
379 cp
->cpu_idle_thread
= tp
;
382 tp
->t_bound_cpu
= cp
;
383 tp
->t_affinitycnt
= 1;
385 tp
->t_disp_queue
= cp
->cpu_disp
;
388 * Bootstrap the CPU's PG data
390 pg_cpu_bootstrap(cp
);
393 * Perform CPC initialization on the new CPU.
398 * Allocate virtual addresses for cpu_caddr1 and cpu_caddr2
401 setup_vaddr_for_ppcopy(cp
);
404 * Allocate page for new GDT and initialize from current GDT.
407 ASSERT((sizeof (*cp
->cpu_gdt
) * NGDT
) <= PAGESIZE
);
409 cp
->cpu_gdt
= kmem_zalloc(PAGESIZE
, KM_SLEEP
);
410 bcopy(CPU
->cpu_gdt
, cp
->cpu_gdt
, (sizeof (*cp
->cpu_gdt
) * NGDT
));
416 set_usegd(&cp
->cpu_gdt
[GDT_GS
], cp
, sizeof (struct cpu
) -1, SDT_MEMRWA
,
421 * If we have more than one node, each cpu gets a copy of IDT
422 * local to its node. If this is a Pentium box, we use cpu 0's
423 * IDT. cpu 0's IDT has been made read-only to workaround the
424 * cmpxchgl register bug
426 if (system_hardware
.hd_nodes
&& x86_type
!= X86_TYPE_P5
) {
428 ASSERT((sizeof (*CPU
->cpu_idt
) * NIDT
) <= PAGESIZE
);
430 cp
->cpu_idt
= kmem_zalloc(PAGESIZE
, KM_SLEEP
);
431 bcopy(CPU
->cpu_idt
, cp
->cpu_idt
, PAGESIZE
);
433 cp
->cpu_idt
= CPU
->cpu_idt
;
437 * alloc space for cpuid info
439 cpuid_alloc_space(cp
);
441 if (is_x86_feature(x86_featureset
, X86FSET_MWAIT
) &&
442 idle_cpu_prefer_mwait
) {
443 cp
->cpu_m
.mcpu_mwait
= cpuid_mwait_alloc(cp
);
444 cp
->cpu_m
.mcpu_idle_cpu
= cpu_idle_mwait
;
447 cp
->cpu_m
.mcpu_idle_cpu
= cpu_idle
;
456 * alloc space for ucode_info
458 ucode_alloc_space(cp
);
464 * If this is a TRAPTRACE kernel, allocate TRAPTRACE buffers
466 ttc
->ttc_first
= (uintptr_t)kmem_zalloc(trap_trace_bufsize
, KM_SLEEP
);
467 ttc
->ttc_next
= ttc
->ttc_first
;
468 ttc
->ttc_limit
= ttc
->ttc_first
+ trap_trace_bufsize
;
472 * Record that we have another CPU.
475 * Initialize the interrupt threads for this CPU
477 cpu_intr_alloc(cp
, NINTR_THREADS
);
479 cp
->cpu_flags
= CPU_OFFLINE
| CPU_QUIESCED
| CPU_POWEROFF
;
483 * Add CPU to list of available CPUs. It'll be on the active list
484 * after mp_startup_common().
492 * Undo what was done in mp_cpu_configure_common
495 mp_cpu_unconfigure_common(struct cpu
*cp
, int error
)
497 ASSERT(MUTEX_HELD(&cpu_lock
));
500 * Remove the CPU from the list of available CPUs.
502 cpu_del_unit(cp
->cpu_id
);
504 if (error
== ETIMEDOUT
) {
506 * The cpu was started, but never *seemed* to run any
507 * code in the kernel; it's probably off spinning in its
508 * own private world, though with potential references to
509 * our kmem-allocated IDTs and GDTs (for example).
511 * Worse still, it may actually wake up some time later,
512 * so rather than guess what it might or might not do, we
513 * leave the fundamental data structures intact.
520 * At this point, the only threads bound to this CPU should
521 * special per-cpu threads: it's idle thread, it's pause threads,
522 * and it's interrupt threads. Clean these up.
524 cpu_destroy_bound_threads(cp
);
525 cp
->cpu_idle_thread
= NULL
;
528 * Free the interrupt stack.
531 cp
->cpu_intr_stack
- (INTR_STACK_SIZE
- SA(MINFRAME
)));
532 cp
->cpu_intr_stack
= NULL
;
536 * Discard the trap trace buffer
539 trap_trace_ctl_t
*ttc
= &trap_trace_ctl
[cp
->cpu_id
];
541 kmem_free((void *)ttc
->ttc_first
, trap_trace_bufsize
);
542 ttc
->ttc_first
= NULL
;
548 ucode_free_space(cp
);
550 /* Free CPU ID string and brand string. */
552 kmem_free(cp
->cpu_idstr
, CPU_IDSTRLEN
);
553 cp
->cpu_idstr
= NULL
;
555 if (cp
->cpu_brandstr
) {
556 kmem_free(cp
->cpu_brandstr
, CPU_IDSTRLEN
);
557 cp
->cpu_brandstr
= NULL
;
561 if (cp
->cpu_m
.mcpu_mwait
!= NULL
) {
562 cpuid_mwait_free(cp
);
563 cp
->cpu_m
.mcpu_mwait
= NULL
;
566 cpuid_free_space(cp
);
568 if (cp
->cpu_idt
!= CPU
->cpu_idt
)
569 kmem_free(cp
->cpu_idt
, PAGESIZE
);
572 kmem_free(cp
->cpu_gdt
, PAGESIZE
);
575 if (cp
->cpu_supp_freqs
!= NULL
) {
576 size_t len
= strlen(cp
->cpu_supp_freqs
) + 1;
577 kmem_free(cp
->cpu_supp_freqs
, len
);
578 cp
->cpu_supp_freqs
= NULL
;
581 teardown_vaddr_for_ppcopy(cp
);
585 cp
->cpu_dispthread
= NULL
;
586 cp
->cpu_thread
= NULL
; /* discarded by cpu_destroy_bound_threads() */
588 cpu_vm_data_destroy(cp
);
594 bzero(cp
, sizeof (*cp
));
595 cp
->cpu_next_free
= cpu_free_list
;
600 * Apply workarounds for known errata, and warn about those that are absent.
602 * System vendors occasionally create configurations which contain different
603 * revisions of the CPUs that are almost but not exactly the same. At the
604 * time of writing, this meant that their clock rates were the same, their
605 * feature sets were the same, but the required workaround were -not-
606 * necessarily the same. So, this routine is invoked on -every- CPU soon
607 * after starting to make sure that the resulting system contains the most
608 * pessimal set of workarounds needed to cope with *any* of the CPUs in the
611 * workaround_errata is invoked early in mlsetup() for CPU 0, and in
612 * mp_startup_common() for all slave CPUs. Slaves process workaround_errata
613 * prior to acknowledging their readiness to the master, so this routine will
614 * never be executed by multiple CPUs in parallel, thus making updates to
617 * These workarounds are based on Rev 3.57 of the Revision Guide for
618 * AMD Athlon(tm) 64 and AMD Opteron(tm) Processors, August 2005.
621 #if defined(OPTERON_ERRATUM_88)
622 int opteron_erratum_88
; /* if non-zero -> at least one cpu has it */
625 #if defined(OPTERON_ERRATUM_91)
626 int opteron_erratum_91
; /* if non-zero -> at least one cpu has it */
629 #if defined(OPTERON_ERRATUM_93)
630 int opteron_erratum_93
; /* if non-zero -> at least one cpu has it */
633 #if defined(OPTERON_ERRATUM_95)
634 int opteron_erratum_95
; /* if non-zero -> at least one cpu has it */
637 #if defined(OPTERON_ERRATUM_100)
638 int opteron_erratum_100
; /* if non-zero -> at least one cpu has it */
641 #if defined(OPTERON_ERRATUM_108)
642 int opteron_erratum_108
; /* if non-zero -> at least one cpu has it */
645 #if defined(OPTERON_ERRATUM_109)
646 int opteron_erratum_109
; /* if non-zero -> at least one cpu has it */
649 #if defined(OPTERON_ERRATUM_121)
650 int opteron_erratum_121
; /* if non-zero -> at least one cpu has it */
653 #if defined(OPTERON_ERRATUM_122)
654 int opteron_erratum_122
; /* if non-zero -> at least one cpu has it */
657 #if defined(OPTERON_ERRATUM_123)
658 int opteron_erratum_123
; /* if non-zero -> at least one cpu has it */
661 #if defined(OPTERON_ERRATUM_131)
662 int opteron_erratum_131
; /* if non-zero -> at least one cpu has it */
665 #if defined(OPTERON_WORKAROUND_6336786)
666 int opteron_workaround_6336786
; /* non-zero -> WA relevant and applied */
667 int opteron_workaround_6336786_UP
= 0; /* Not needed for UP */
670 #if defined(OPTERON_WORKAROUND_6323525)
671 int opteron_workaround_6323525
; /* if non-zero -> at least one cpu has it */
674 #if defined(OPTERON_ERRATUM_298)
675 int opteron_erratum_298
;
678 #if defined(OPTERON_ERRATUM_721)
679 int opteron_erratum_721
;
683 workaround_warning(cpu_t
*cp
, uint_t erratum
)
685 cmn_err(CE_WARN
, "cpu%d: no workaround for erratum %u",
686 cp
->cpu_id
, erratum
);
690 workaround_applied(uint_t erratum
)
692 if (erratum
> 1000000)
693 cmn_err(CE_CONT
, "?workaround applied for cpu issue #%d\n",
696 cmn_err(CE_CONT
, "?workaround applied for cpu erratum #%d\n",
701 msr_warning(cpu_t
*cp
, const char *rw
, uint_t msr
, int error
)
703 cmn_err(CE_WARN
, "cpu%d: couldn't %smsr 0x%x, error %d",
704 cp
->cpu_id
, rw
, msr
, error
);
708 * Determine the number of nodes in a Hammer / Greyhound / Griffin family
712 opteron_get_nnodes(void)
714 static uint_t nnodes
= 0;
721 * This routine uses a PCI config space based mechanism
722 * for retrieving the number of nodes in the system.
723 * Device 24, function 0, offset 0x60 as used here is not
724 * AMD processor architectural, and may not work on processor
725 * families other than those listed below.
727 * Callers of this routine must ensure that we're running on
728 * a processor which supports this mechanism.
729 * The assertion below is meant to catch calls on unsupported
732 family
= cpuid_getfamily(CPU
);
733 ASSERT(family
== 0xf || family
== 0x10 || family
== 0x11);
737 * Obtain the number of nodes in the system from
738 * bits [6:4] of the Node ID register on node 0.
740 * The actual node count is NodeID[6:4] + 1
742 * The Node ID register is accessed via function 0,
743 * offset 0x60. Node 0 is device 24.
745 nnodes
= ((pci_getl_func(0, 24, 0, 0x60) & 0x70) >> 4) + 1;
751 do_erratum_298(struct cpu
*cpu
)
753 static int osvwrc
= -3;
754 extern int osvw_opteron_erratum(cpu_t
*, uint_t
);
757 * L2 Eviction May Occur During Processor Operation To Set
758 * Accessed or Dirty Bit.
761 osvwrc
= osvw_opteron_erratum(cpu
, 298);
763 /* osvw return codes should be consistent for all cpus */
764 ASSERT(osvwrc
== osvw_opteron_erratum(cpu
, 298));
768 case 0: /* erratum is not present: do nothing */
770 case 1: /* erratum is present: BIOS workaround applied */
772 * check if workaround is actually in place and issue warning
775 if (((rdmsr(MSR_AMD_HWCR
) & AMD_HWCR_TLBCACHEDIS
) == 0) ||
776 ((rdmsr(MSR_AMD_BU_CFG
) & AMD_BU_CFG_E298
) == 0)) {
777 #if defined(OPTERON_ERRATUM_298)
778 opteron_erratum_298
++;
780 workaround_warning(cpu
, 298);
785 case -1: /* cannot determine via osvw: check cpuid */
786 if ((cpuid_opteron_erratum(cpu
, 298) > 0) &&
787 (((rdmsr(MSR_AMD_HWCR
) & AMD_HWCR_TLBCACHEDIS
) == 0) ||
788 ((rdmsr(MSR_AMD_BU_CFG
) & AMD_BU_CFG_E298
) == 0))) {
789 #if defined(OPTERON_ERRATUM_298)
790 opteron_erratum_298
++;
792 workaround_warning(cpu
, 298);
802 workaround_errata(struct cpu
*cpu
)
809 if (cpuid_opteron_erratum(cpu
, 88) > 0) {
811 * SWAPGS May Fail To Read Correct GS Base
813 #if defined(OPTERON_ERRATUM_88)
815 * The workaround is an mfence in the relevant assembler code
817 opteron_erratum_88
++;
819 workaround_warning(cpu
, 88);
824 if (cpuid_opteron_erratum(cpu
, 91) > 0) {
826 * Software Prefetches May Report A Page Fault
828 #if defined(OPTERON_ERRATUM_91)
832 opteron_erratum_91
++;
834 workaround_warning(cpu
, 91);
839 if (cpuid_opteron_erratum(cpu
, 93) > 0) {
841 * RSM Auto-Halt Restart Returns to Incorrect RIP
843 #if defined(OPTERON_ERRATUM_93)
847 opteron_erratum_93
++;
849 workaround_warning(cpu
, 93);
855 if (cpuid_opteron_erratum(cpu
, 95) > 0) {
857 * RET Instruction May Return to Incorrect EIP
859 #if defined(OPTERON_ERRATUM_95)
862 * Workaround this by ensuring that 32-bit user code and
863 * 64-bit kernel code never occupy the same address
866 if (_userlimit32
> 0xc0000000ul
)
867 *(uintptr_t *)&_userlimit32
= 0xc0000000ul
;
870 ASSERT((uint32_t)COREHEAP_BASE
== 0xc0000000u
);
871 opteron_erratum_95
++;
874 workaround_warning(cpu
, 95);
879 if (cpuid_opteron_erratum(cpu
, 100) > 0) {
881 * Compatibility Mode Branches Transfer to Illegal Address
883 #if defined(OPTERON_ERRATUM_100)
887 opteron_erratum_100
++;
889 workaround_warning(cpu
, 100);
895 if (cpuid_opteron_erratum(cpu
, 108) > 0) {
897 * CPUID Instruction May Return Incorrect Model Number In
900 #if defined(OPTERON_ERRATUM_108)
902 * (Our cpuid-handling code corrects the model number on
906 workaround_warning(cpu
, 108);
912 if (cpuid_opteron_erratum(cpu
, 109) > 0) do {
914 * Certain Reverse REP MOVS May Produce Unpredictable Behavior
916 #if defined(OPTERON_ERRATUM_109)
918 * The "workaround" is to print a warning to upgrade the BIOS
921 const uint_t msr
= MSR_AMD_PATCHLEVEL
;
924 if ((err
= checked_rdmsr(msr
, &value
)) != 0) {
925 msr_warning(cpu
, "rd", msr
, err
);
926 workaround_warning(cpu
, 109);
930 opteron_erratum_109
++;
932 workaround_warning(cpu
, 109);
935 /*CONSTANTCONDITION*/
939 if (cpuid_opteron_erratum(cpu
, 121) > 0) {
941 * Sequential Execution Across Non_Canonical Boundary Caused
944 #if defined(OPTERON_ERRATUM_121)
947 * Erratum 121 is only present in long (64 bit) mode.
948 * Workaround is to include the page immediately before the
949 * va hole to eliminate the possibility of system hangs due to
950 * sequential execution across the va hole boundary.
952 if (opteron_erratum_121
)
953 opteron_erratum_121
++;
956 hole_start
-= PAGESIZE
;
959 * hole_start not yet initialized by
960 * mmu_init. Initialize hole_start
961 * with value to be subtracted.
963 hole_start
= PAGESIZE
;
965 opteron_erratum_121
++;
969 workaround_warning(cpu
, 121);
975 if (cpuid_opteron_erratum(cpu
, 122) > 0) do {
977 * TLB Flush Filter May Cause Coherency Problem in
978 * Multiprocessor Systems
980 #if defined(OPTERON_ERRATUM_122)
982 const uint_t msr
= MSR_AMD_HWCR
;
986 * Erratum 122 is only present in MP configurations (multi-core
987 * or multi-processor).
990 if (!DOMAIN_IS_INITDOMAIN(xen_info
))
992 if (!opteron_erratum_122
&& xpv_nr_phys_cpus() == 1)
995 if (!opteron_erratum_122
&& opteron_get_nnodes() == 1 &&
996 cpuid_get_ncpu_per_chip(cpu
) == 1)
999 /* disable TLB Flush Filter */
1001 if ((error
= checked_rdmsr(msr
, &value
)) != 0) {
1002 msr_warning(cpu
, "rd", msr
, error
);
1003 workaround_warning(cpu
, 122);
1006 value
|= (uint64_t)AMD_HWCR_FFDIS
;
1007 if ((error
= checked_wrmsr(msr
, value
)) != 0) {
1008 msr_warning(cpu
, "wr", msr
, error
);
1009 workaround_warning(cpu
, 122);
1013 opteron_erratum_122
++;
1015 workaround_warning(cpu
, 122);
1018 /*CONSTANTCONDITION*/
1022 if (cpuid_opteron_erratum(cpu
, 123) > 0) do {
1024 * Bypassed Reads May Cause Data Corruption of System Hang in
1025 * Dual Core Processors
1027 #if defined(OPTERON_ERRATUM_123)
1029 const uint_t msr
= MSR_AMD_PATCHLEVEL
;
1033 * Erratum 123 applies only to multi-core cpus.
1035 if (cpuid_get_ncpu_per_chip(cpu
) < 2)
1038 if (!DOMAIN_IS_INITDOMAIN(xen_info
))
1042 * The "workaround" is to print a warning to upgrade the BIOS
1044 if ((err
= checked_rdmsr(msr
, &value
)) != 0) {
1045 msr_warning(cpu
, "rd", msr
, err
);
1046 workaround_warning(cpu
, 123);
1050 opteron_erratum_123
++;
1052 workaround_warning(cpu
, 123);
1056 /*CONSTANTCONDITION*/
1060 if (cpuid_opteron_erratum(cpu
, 131) > 0) do {
1062 * Multiprocessor Systems with Four or More Cores May Deadlock
1063 * Waiting for a Probe Response
1065 #if defined(OPTERON_ERRATUM_131)
1067 const uint_t msr
= MSR_AMD_NB_CFG
;
1068 const uint64_t wabits
=
1069 AMD_NB_CFG_SRQ_HEARTBEAT
| AMD_NB_CFG_SRQ_SPR
;
1073 * Erratum 131 applies to any system with four or more cores.
1075 if (opteron_erratum_131
)
1078 if (!DOMAIN_IS_INITDOMAIN(xen_info
))
1080 if (xpv_nr_phys_cpus() < 4)
1083 if (opteron_get_nnodes() * cpuid_get_ncpu_per_chip(cpu
) < 4)
1087 * Print a warning if neither of the workarounds for
1088 * erratum 131 is present.
1090 if ((error
= checked_rdmsr(msr
, &nbcfg
)) != 0) {
1091 msr_warning(cpu
, "rd", msr
, error
);
1092 workaround_warning(cpu
, 131);
1094 } else if ((nbcfg
& wabits
) == 0) {
1095 opteron_erratum_131
++;
1097 /* cannot have both workarounds set */
1098 ASSERT((nbcfg
& wabits
) != wabits
);
1101 workaround_warning(cpu
, 131);
1104 /*CONSTANTCONDITION*/
1108 * This isn't really an erratum, but for convenience the
1109 * detection/workaround code lives here and in cpuid_opteron_erratum.
1111 if (cpuid_opteron_erratum(cpu
, 6336786) > 0) {
1112 #if defined(OPTERON_WORKAROUND_6336786)
1114 * Disable C1-Clock ramping on multi-core/multi-processor
1115 * K8 platforms to guard against TSC drift.
1117 if (opteron_workaround_6336786
) {
1118 opteron_workaround_6336786
++;
1120 } else if ((DOMAIN_IS_INITDOMAIN(xen_info
) &&
1121 xpv_nr_phys_cpus() > 1) ||
1122 opteron_workaround_6336786_UP
) {
1124 * XXPV Hmm. We can't walk the Northbridges on
1125 * the hypervisor; so just complain and drive
1126 * on. This probably needs to be fixed in
1127 * the hypervisor itself.
1129 opteron_workaround_6336786
++;
1130 workaround_warning(cpu
, 6336786);
1132 } else if ((opteron_get_nnodes() *
1133 cpuid_get_ncpu_per_chip(cpu
) > 1) ||
1134 opteron_workaround_6336786_UP
) {
1136 uint_t node
, nnodes
;
1139 nnodes
= opteron_get_nnodes();
1140 for (node
= 0; node
< nnodes
; node
++) {
1142 * Clear PMM7[1:0] (function 3, offset 0x87)
1143 * Northbridge device is the node id + 24.
1145 data
= pci_getb_func(0, node
+ 24, 3, 0x87);
1147 pci_putb_func(0, node
+ 24, 3, 0x87, data
);
1149 opteron_workaround_6336786
++;
1153 workaround_warning(cpu
, 6336786);
1160 * Mutex primitives don't work as expected.
1162 if (cpuid_opteron_erratum(cpu
, 6323525) > 0) {
1163 #if defined(OPTERON_WORKAROUND_6323525)
1165 * This problem only occurs with 2 or more cores. If bit in
1166 * MSR_AMD_BU_CFG set, then not applicable. The workaround
1167 * is to patch the semaphone routines with the lfence
1168 * instruction to provide necessary load memory barrier with
1169 * possible subsequent read-modify-write ops.
1171 * It is too early in boot to call the patch routine so
1172 * set erratum variable to be done in startup_end().
1174 if (opteron_workaround_6323525
) {
1175 opteron_workaround_6323525
++;
1177 } else if (is_x86_feature(x86_featureset
, X86FSET_SSE2
)) {
1178 if (DOMAIN_IS_INITDOMAIN(xen_info
)) {
1180 * XXPV Use dom0_msr here when extended
1181 * operations are supported?
1183 if (xpv_nr_phys_cpus() > 1)
1184 opteron_workaround_6323525
++;
1187 * We have no way to tell how many physical
1188 * cpus there are, or even if this processor
1189 * has the problem, so enable the workaround
1190 * unconditionally (at some performance cost).
1192 opteron_workaround_6323525
++;
1195 } else if (is_x86_feature(x86_featureset
, X86FSET_SSE2
) &&
1196 ((opteron_get_nnodes() *
1197 cpuid_get_ncpu_per_chip(cpu
)) > 1)) {
1198 if ((xrdmsr(MSR_AMD_BU_CFG
) & (UINT64_C(1) << 33)) == 0)
1199 opteron_workaround_6323525
++;
1203 workaround_warning(cpu
, 6323525);
1208 missing
+= do_erratum_298(cpu
);
1210 if (cpuid_opteron_erratum(cpu
, 721) > 0) {
1211 #if defined(OPTERON_ERRATUM_721)
1214 if (!on_trap(&otd
, OT_DATA_ACCESS
))
1215 wrmsr(MSR_AMD_DE_CFG
,
1216 rdmsr(MSR_AMD_DE_CFG
) | AMD_DE_CFG_E721
);
1219 opteron_erratum_721
++;
1221 workaround_warning(cpu
, 721);
1234 workaround_errata_end()
1236 #if defined(OPTERON_ERRATUM_88)
1237 if (opteron_erratum_88
)
1238 workaround_applied(88);
1240 #if defined(OPTERON_ERRATUM_91)
1241 if (opteron_erratum_91
)
1242 workaround_applied(91);
1244 #if defined(OPTERON_ERRATUM_93)
1245 if (opteron_erratum_93
)
1246 workaround_applied(93);
1248 #if defined(OPTERON_ERRATUM_95)
1249 if (opteron_erratum_95
)
1250 workaround_applied(95);
1252 #if defined(OPTERON_ERRATUM_100)
1253 if (opteron_erratum_100
)
1254 workaround_applied(100);
1256 #if defined(OPTERON_ERRATUM_108)
1257 if (opteron_erratum_108
)
1258 workaround_applied(108);
1260 #if defined(OPTERON_ERRATUM_109)
1261 if (opteron_erratum_109
) {
1263 "BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)"
1264 " processor\nerratum 109 was not detected; updating your"
1265 " system's BIOS to a version\ncontaining this"
1266 " microcode patch is HIGHLY recommended or erroneous"
1267 " system\noperation may occur.\n");
1270 #if defined(OPTERON_ERRATUM_121)
1271 if (opteron_erratum_121
)
1272 workaround_applied(121);
1274 #if defined(OPTERON_ERRATUM_122)
1275 if (opteron_erratum_122
)
1276 workaround_applied(122);
1278 #if defined(OPTERON_ERRATUM_123)
1279 if (opteron_erratum_123
) {
1281 "BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)"
1282 " processor\nerratum 123 was not detected; updating your"
1283 " system's BIOS to a version\ncontaining this"
1284 " microcode patch is HIGHLY recommended or erroneous"
1285 " system\noperation may occur.\n");
1288 #if defined(OPTERON_ERRATUM_131)
1289 if (opteron_erratum_131
) {
1291 "BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)"
1292 " processor\nerratum 131 was not detected; updating your"
1293 " system's BIOS to a version\ncontaining this"
1294 " microcode patch is HIGHLY recommended or erroneous"
1295 " system\noperation may occur.\n");
1298 #if defined(OPTERON_WORKAROUND_6336786)
1299 if (opteron_workaround_6336786
)
1300 workaround_applied(6336786);
1302 #if defined(OPTERON_WORKAROUND_6323525)
1303 if (opteron_workaround_6323525
)
1304 workaround_applied(6323525);
1306 #if defined(OPTERON_ERRATUM_298)
1307 if (opteron_erratum_298
) {
1309 "BIOS microcode patch for AMD 64/Opteron(tm)"
1310 " processor\nerratum 298 was not detected; updating your"
1311 " system's BIOS to a version\ncontaining this"
1312 " microcode patch is HIGHLY recommended or erroneous"
1313 " system\noperation may occur.\n");
1316 #if defined(OPTERON_ERRATUM_721)
1317 if (opteron_erratum_721
)
1318 workaround_applied(721);
1323 * The procset_slave and procset_master are used to synchronize
1324 * between the control CPU and the target CPU when starting CPUs.
1326 static cpuset_t procset_slave
, procset_master
;
1329 mp_startup_wait(cpuset_t
*sp
, processorid_t cpuid
)
1333 for (tempset
= *sp
; !CPU_IN_SET(tempset
, cpuid
);
1334 tempset
= *(volatile cpuset_t
*)sp
) {
1337 CPUSET_ATOMIC_DEL(*(cpuset_t
*)sp
, cpuid
);
1341 mp_startup_signal(cpuset_t
*sp
, processorid_t cpuid
)
1345 CPUSET_ATOMIC_ADD(*(cpuset_t
*)sp
, cpuid
);
1346 for (tempset
= *sp
; CPU_IN_SET(tempset
, cpuid
);
1347 tempset
= *(volatile cpuset_t
*)sp
) {
1353 mp_start_cpu_common(cpu_t
*cp
, boolean_t boot
)
1355 _NOTE(ARGUNUSED(boot
));
1361 processorid_t cpuid
;
1363 extern void cpupm_init(cpu_t
*);
1368 ctx
= mach_cpucontext_alloc(cp
);
1371 "cpu%d: failed to allocate context", cp
->cpu_id
);
1374 error
= mach_cpu_start(cp
, ctx
);
1377 "cpu%d: failed to start, error %d", cp
->cpu_id
, error
);
1378 mach_cpucontext_free(cp
, ctx
, error
);
1382 for (delays
= 0, tempset
= procset_slave
; !CPU_IN_SET(tempset
, cpuid
);
1384 if (delays
== 500) {
1386 * After five seconds, things are probably looking
1387 * a bit bleak - explain the hang.
1389 cmn_err(CE_NOTE
, "cpu%d: started, "
1390 "but not running in the kernel yet", cpuid
);
1391 } else if (delays
> 2000) {
1393 * We waited at least 20 seconds, bail ..
1396 cmn_err(CE_WARN
, "cpu%d: timed out", cpuid
);
1397 mach_cpucontext_free(cp
, ctx
, error
);
1402 * wait at least 10ms, then check again..
1404 delay(USEC_TO_TICK_ROUNDUP(10000));
1405 tempset
= *((volatile cpuset_t
*)&procset_slave
);
1407 CPUSET_ATOMIC_DEL(procset_slave
, cpuid
);
1409 mach_cpucontext_free(cp
, ctx
, 0);
1412 if (tsc_gethrtime_enable
)
1413 tsc_sync_master(cpuid
);
1416 if (dtrace_cpu_init
!= NULL
) {
1417 (*dtrace_cpu_init
)(cpuid
);
1421 * During CPU DR operations, the cpu_lock is held by current
1422 * (the control) thread. We can't release the cpu_lock here
1423 * because that will break the CPU DR logic.
1424 * On the other hand, CPUPM and processor group initialization
1425 * routines need to access the cpu_lock. So we invoke those
1426 * routines here on behalf of mp_startup_common().
1428 * CPUPM and processor group initialization routines depend
1429 * on the cpuid probing results. Wait for mp_startup_common()
1430 * to signal that cpuid probing is done.
1432 mp_startup_wait(&procset_slave
, cpuid
);
1436 (void) pg_cpu_init(cp
, B_FALSE
);
1438 mp_startup_signal(&procset_master
, cpuid
);
1444 * Start a single cpu, assuming that the kernel context is available
1445 * to successfully start another cpu.
1447 * (For example, real mode code is mapped into the right place
1448 * in memory and is ready to be run.)
1451 start_cpu(processorid_t who
)
1460 * Check if there's at least a Mbyte of kmem available
1461 * before attempting to start the cpu.
1463 if (kmem_avail() < 1024 * 1024) {
1465 * Kick off a reap in case that helps us with
1473 * First configure cpu.
1475 cp
= mp_cpu_configure_common(who
, B_TRUE
);
1481 error
= mp_start_cpu_common(cp
, B_TRUE
);
1483 mp_cpu_unconfigure_common(cp
, error
);
1487 mutex_exit(&cpu_lock
);
1488 tempset
= cpu_ready_set
;
1489 while (!CPU_IN_SET(tempset
, who
)) {
1491 tempset
= *((volatile cpuset_t
*)&cpu_ready_set
);
1493 mutex_enter(&cpu_lock
);
1499 start_other_cpus(int cprboot
)
1501 _NOTE(ARGUNUSED(cprboot
));
1504 uint_t bootcpuid
= 0;
1507 * Initialize our own cpu_info.
1512 init_cpu_id_gdt(CPU
);
1515 cmn_err(CE_CONT
, "?cpu%d: %s\n", CPU
->cpu_id
, CPU
->cpu_idstr
);
1516 cmn_err(CE_CONT
, "?cpu%d: %s\n", CPU
->cpu_id
, CPU
->cpu_brandstr
);
1519 * Initialize our syscall handlers
1521 init_cpu_syscall(CPU
);
1524 * Take the boot cpu out of the mp_cpus set because we know
1525 * it's already running. Add it to the cpu_ready_set for
1526 * precisely the same reason.
1528 CPUSET_DEL(mp_cpus
, bootcpuid
);
1529 CPUSET_ADD(cpu_ready_set
, bootcpuid
);
1532 * skip the rest of this if
1533 * . only 1 cpu dectected and system isn't hotplug-capable
1536 if ((CPUSET_ISNULL(mp_cpus
) && plat_dr_support_cpu() == 0) ||
1539 cmn_err(CE_CONT
, "?***** Not in MP mode\n");
1544 * perform such initialization as is needed
1545 * to be able to take CPUs on- and off-line.
1549 xc_init_cpu(CPU
); /* initialize processor crosscalls */
1551 if (mach_cpucontext_init() != 0)
1554 flushes_require_xcalls
= 1;
1557 * We lock our affinity to the master CPU to ensure that all slave CPUs
1558 * do their TSC syncs with the same CPU.
1560 affinity_set(CPU_CURRENT
);
1562 for (who
= 0; who
< NCPU
; who
++) {
1563 if (!CPU_IN_SET(mp_cpus
, who
))
1565 ASSERT(who
!= bootcpuid
);
1567 mutex_enter(&cpu_lock
);
1568 if (start_cpu(who
) != 0)
1569 CPUSET_DEL(mp_cpus
, who
);
1570 cpu_state_change_notify(who
, CPU_SETUP
);
1571 mutex_exit(&cpu_lock
);
1574 /* Free the space allocated to hold the microcode file */
1579 mach_cpucontext_fini();
1582 if (get_hwenv() == HW_NATIVE
)
1583 workaround_errata_end();
1584 cmi_post_mpstartup();
1586 if (use_mp
&& ncpus
!= boot_max_ncpus
) {
1588 "System detected %d cpus, but "
1589 "only %d cpu(s) were enabled during boot.",
1590 boot_max_ncpus
, ncpus
);
1592 "Use \"boot-ncpus\" parameter to enable more CPU(s). "
1598 mp_cpu_configure(int cpuid
)
1602 if (use_mp
== 0 || plat_dr_support_cpu() == 0) {
1606 cp
= cpu_get(cpuid
);
1612 * Check if there's at least a Mbyte of kmem available
1613 * before attempting to start the cpu.
1615 if (kmem_avail() < 1024 * 1024) {
1617 * Kick off a reap in case that helps us with
1624 cp
= mp_cpu_configure_common(cpuid
, B_FALSE
);
1625 ASSERT(cp
!= NULL
&& cpu_get(cpuid
) == cp
);
1627 return (cp
!= NULL
? 0 : EAGAIN
);
1631 mp_cpu_unconfigure(int cpuid
)
1635 if (use_mp
== 0 || plat_dr_support_cpu() == 0) {
1637 } else if (cpuid
< 0 || cpuid
>= max_ncpus
) {
1641 cp
= cpu_get(cpuid
);
1645 mp_cpu_unconfigure_common(cp
, 0);
1651 * Startup function for 'other' CPUs (besides boot cpu).
1652 * Called from real_mode_start.
1654 * WARNING: until CPU_READY is set, mp_startup_common and routines called by
1655 * mp_startup_common should not call routines (e.g. kmem_free) that could call
1656 * hat_unload which requires CPU_READY to be set.
1659 mp_startup_common(boolean_t boot
)
1662 uchar_t new_x86_featureset
[BT_SIZEOFMAP(NUM_X86_FEATURES
)];
1663 extern void cpu_event_init_cpu(cpu_t
*);
1666 * We need to get TSC on this proc synced (i.e., any delta
1667 * from cpu0 accounted for) as soon as we can, because many
1668 * many things use gethrtime/pc_gethrestime, including
1669 * interrupts, cmn_err, etc. Before we can do that, we want to
1670 * clear TSC if we're on a buggy Sandy/Ivy Bridge CPU, so do that
1673 bzero(new_x86_featureset
, BT_SIZEOFMAP(NUM_X86_FEATURES
));
1674 cpuid_pass1(cp
, new_x86_featureset
);
1676 if (boot
&& get_hwenv() == HW_NATIVE
&&
1677 cpuid_getvendor(CPU
) == X86_VENDOR_Intel
&&
1678 cpuid_getfamily(CPU
) == 6 &&
1679 (cpuid_getmodel(CPU
) == 0x2d || cpuid_getmodel(CPU
) == 0x3e) &&
1680 is_x86_feature(new_x86_featureset
, X86FSET_TSC
)) {
1681 (void) wrmsr(REG_TSC
, 0UL);
1684 /* Let the control CPU continue into tsc_sync_master() */
1685 mp_startup_signal(&procset_slave
, cp
->cpu_id
);
1688 if (tsc_gethrtime_enable
)
1693 * Once this was done from assembly, but it's safer here; if
1694 * it blocks, we need to be able to swtch() to and from, and
1695 * since we get here by calling t_pc, we need to do that call
1696 * before swtch() overwrites it.
1698 (void) (*ap_mlsetup
)();
1702 * Program this cpu's PAT
1708 * Set up TSC_AUX to contain the cpuid for this processor
1709 * for the rdtscp instruction.
1711 if (is_x86_feature(x86_featureset
, X86FSET_TSCP
))
1712 (void) wrmsr(MSR_AMD_TSCAUX
, cp
->cpu_id
);
1715 * Initialize this CPU's syscall handlers
1717 init_cpu_syscall(cp
);
1720 * Enable interrupts with spl set to LOCK_LEVEL. LOCK_LEVEL is the
1721 * highest level at which a routine is permitted to block on
1722 * an adaptive mutex (allows for cpu poke interrupt in case
1723 * the cpu is blocked on a mutex and halts). Setting LOCK_LEVEL blocks
1724 * device interrupts that may end up in the hat layer issuing cross
1725 * calls before CPU_READY is set.
1727 splx(ipltospl(LOCK_LEVEL
));
1731 * Do a sanity check to make sure this new CPU is a sane thing
1732 * to add to the collection of processors running this system.
1734 * XXX Clearly this needs to get more sophisticated, if x86
1735 * systems start to get built out of heterogenous CPUs; as is
1736 * likely to happen once the number of processors in a configuration
1737 * gets large enough.
1739 if (compare_x86_featureset(x86_featureset
, new_x86_featureset
) ==
1741 cmn_err(CE_CONT
, "cpu%d: featureset\n", cp
->cpu_id
);
1742 print_x86_featureset(new_x86_featureset
);
1743 cmn_err(CE_WARN
, "cpu%d feature mismatch", cp
->cpu_id
);
1747 * There exists a small subset of systems which expose differing
1748 * MWAIT/MONITOR support between CPUs. If MWAIT support is absent from
1749 * the boot CPU, but is found on a later CPU, the system continues to
1750 * operate as if no MWAIT support is available.
1752 * The reverse case, where MWAIT is available on the boot CPU but not
1753 * on a subsequently initialized CPU, is not presently allowed and will
1754 * result in a panic.
1756 if (is_x86_feature(x86_featureset
, X86FSET_MWAIT
) !=
1757 is_x86_feature(new_x86_featureset
, X86FSET_MWAIT
)) {
1758 if (!is_x86_feature(x86_featureset
, X86FSET_MWAIT
)) {
1759 remove_x86_feature(new_x86_featureset
, X86FSET_MWAIT
);
1761 panic("unsupported mixed cpu mwait support detected");
1766 * We could be more sophisticated here, and just mark the CPU
1767 * as "faulted" but at this point we'll opt for the easier
1768 * answer of dying horribly. Provided the boot cpu is ok,
1769 * the system can be recovered by booting with use_mp set to zero.
1771 if (workaround_errata(cp
) != 0)
1772 panic("critical workaround(s) missing for cpu%d", cp
->cpu_id
);
1775 * We can touch cpu_flags here without acquiring the cpu_lock here
1776 * because the cpu_lock is held by the control CPU which is running
1777 * mp_start_cpu_common().
1778 * Need to clear CPU_QUIESCED flag before calling any function which
1779 * may cause thread context switching, such as kmem_alloc() etc.
1780 * The idle thread checks for CPU_QUIESCED flag and loops for ever if
1781 * it's set. So the startup thread may have no chance to switch back
1782 * again if it's switched away with CPU_QUIESCED set.
1784 cp
->cpu_flags
&= ~(CPU_POWEROFF
| CPU_QUIESCED
);
1787 * Setup this processor for XSAVE.
1789 if (fp_save_mech
== FP_XSAVE
) {
1790 xsave_setup_msr(cp
);
1795 cpuid_pass4(cp
, NULL
);
1798 * Correct cpu_idstr and cpu_brandstr on target CPU after
1799 * cpuid_pass1() is done.
1801 (void) cpuid_getidstr(cp
, cp
->cpu_idstr
, CPU_IDSTRLEN
);
1802 (void) cpuid_getbrandstr(cp
, cp
->cpu_brandstr
, CPU_IDSTRLEN
);
1804 cp
->cpu_flags
|= CPU_RUNNING
| CPU_READY
| CPU_EXISTS
;
1806 post_startup_cpu_fixups();
1808 cpu_event_init_cpu(cp
);
1811 * Enable preemption here so that contention for any locks acquired
1812 * later in mp_startup_common may be preempted if the thread owning
1813 * those locks is continuously executing on other CPUs (for example,
1814 * this CPU must be preemptible to allow other CPUs to pause it during
1815 * their startup phases). It's safe to enable preemption here because
1816 * the CPU state is pretty-much fully constructed.
1818 curthread
->t_preempt
= 0;
1820 /* The base spl should still be at LOCK LEVEL here */
1821 ASSERT(cp
->cpu_base_spl
== ipltospl(LOCK_LEVEL
));
1822 set_base_spl(); /* Restore the spl to its proper value */
1824 pghw_physid_create(cp
);
1826 * Delegate initialization tasks, which need to access the cpu_lock,
1827 * to mp_start_cpu_common() because we can't acquire the cpu_lock here
1828 * during CPU DR operations.
1830 mp_startup_signal(&procset_slave
, cp
->cpu_id
);
1831 mp_startup_wait(&procset_master
, cp
->cpu_id
);
1832 pg_cmt_cpu_startup(cp
);
1835 mutex_enter(&cpu_lock
);
1836 cp
->cpu_flags
&= ~CPU_OFFLINE
;
1837 cpu_enable_intr(cp
);
1839 mutex_exit(&cpu_lock
);
1842 /* Enable interrupts */
1846 * Fill out cpu_ucode_info. Update microcode if necessary.
1853 * Set up the CPU module for this CPU. This can't be done
1854 * before this CPU is made CPU_READY, because we may (in
1855 * heterogeneous systems) need to go load another CPU module.
1856 * The act of attempting to load a module may trigger a
1857 * cross-call, which will ASSERT unless this cpu is CPU_READY.
1861 if ((hdl
= cmi_init(CMI_HDL_NATIVE
, cmi_ntv_hwchipid(CPU
),
1862 cmi_ntv_hwcoreid(CPU
), cmi_ntv_hwstrandid(CPU
))) != NULL
) {
1863 if (is_x86_feature(x86_featureset
, X86FSET_MCA
))
1865 cp
->cpu_m
.mcpu_cmi_hdl
= hdl
;
1870 if (boothowto
& RB_DEBUG
)
1874 * Setting the bit in cpu_ready_set must be the last operation in
1875 * processor initialization; the boot CPU will continue to boot once
1876 * it sees this bit set for all active CPUs.
1878 CPUSET_ATOMIC_ADD(cpu_ready_set
, cp
->cpu_id
);
1880 (void) mach_cpu_create_device_node(cp
, NULL
);
1882 cmn_err(CE_CONT
, "?cpu%d: %s\n", cp
->cpu_id
, cp
->cpu_idstr
);
1883 cmn_err(CE_CONT
, "?cpu%d: %s\n", cp
->cpu_id
, cp
->cpu_brandstr
);
1884 cmn_err(CE_CONT
, "?cpu%d initialization complete - online\n",
1888 * Now we are done with the startup thread, so free it up.
1891 panic("mp_startup: cannot return");
1896 * Startup function for 'other' CPUs at boot time (besides boot cpu).
1899 mp_startup_boot(void)
1901 mp_startup_common(B_TRUE
);
1905 * Startup function for hotplug CPUs at runtime.
1908 mp_startup_hotplug(void)
1910 mp_startup_common(B_FALSE
);
1914 * Start CPU on user request.
1918 mp_cpu_start(struct cpu
*cp
)
1920 ASSERT(MUTEX_HELD(&cpu_lock
));
1925 * Stop CPU on user request.
1928 mp_cpu_stop(struct cpu
*cp
)
1930 extern int cbe_psm_timer_mode
;
1931 ASSERT(MUTEX_HELD(&cpu_lock
));
1935 * We can't offline vcpu0.
1937 if (cp
->cpu_id
== 0)
1942 * If TIMER_PERIODIC mode is used, CPU0 is the one running it;
1943 * can't stop it. (This is true only for machines with no TSC.)
1946 if ((cbe_psm_timer_mode
== TIMER_PERIODIC
) && (cp
->cpu_id
== 0))
1953 * Take the specified CPU out of participation in interrupts.
1956 cpu_disable_intr(struct cpu
*cp
)
1958 if (psm_disable_intr(cp
->cpu_id
) != DDI_SUCCESS
)
1961 cp
->cpu_flags
&= ~CPU_ENABLE
;
1966 * Allow the specified CPU to participate in interrupts.
1969 cpu_enable_intr(struct cpu
*cp
)
1971 ASSERT(MUTEX_HELD(&cpu_lock
));
1972 cp
->cpu_flags
|= CPU_ENABLE
;
1973 psm_enable_intr(cp
->cpu_id
);
1977 mp_cpu_faulted_enter(struct cpu
*cp
)
1980 _NOTE(ARGUNUSED(cp
));
1982 cmi_hdl_t hdl
= cp
->cpu_m
.mcpu_cmi_hdl
;
1987 hdl
= cmi_hdl_lookup(CMI_HDL_NATIVE
, cmi_ntv_hwchipid(cp
),
1988 cmi_ntv_hwcoreid(cp
), cmi_ntv_hwstrandid(cp
));
1991 cmi_faulted_enter(hdl
);
1998 mp_cpu_faulted_exit(struct cpu
*cp
)
2001 _NOTE(ARGUNUSED(cp
));
2003 cmi_hdl_t hdl
= cp
->cpu_m
.mcpu_cmi_hdl
;
2008 hdl
= cmi_hdl_lookup(CMI_HDL_NATIVE
, cmi_ntv_hwchipid(cp
),
2009 cmi_ntv_hwcoreid(cp
), cmi_ntv_hwstrandid(cp
));
2012 cmi_faulted_exit(hdl
);
2019 * The following two routines are used as context operators on threads belonging
2020 * to processes with a private LDT (see sysi86). Due to the rarity of such
2021 * processes, these routines are currently written for best code readability and
2022 * organization rather than speed. We could avoid checking x86_featureset at
2023 * every context switch by installing different context ops, depending on
2024 * x86_featureset, at LDT creation time -- one for each combination of fast
2030 cpu_fast_syscall_disable(void *arg
)
2032 if (is_x86_feature(x86_featureset
, X86FSET_MSR
) &&
2033 is_x86_feature(x86_featureset
, X86FSET_SEP
))
2035 if (is_x86_feature(x86_featureset
, X86FSET_MSR
) &&
2036 is_x86_feature(x86_featureset
, X86FSET_ASYSC
))
2037 cpu_asysc_disable();
2042 cpu_fast_syscall_enable(void *arg
)
2044 if (is_x86_feature(x86_featureset
, X86FSET_MSR
) &&
2045 is_x86_feature(x86_featureset
, X86FSET_SEP
))
2047 if (is_x86_feature(x86_featureset
, X86FSET_MSR
) &&
2048 is_x86_feature(x86_featureset
, X86FSET_ASYSC
))
2053 cpu_sep_enable(void)
2055 ASSERT(is_x86_feature(x86_featureset
, X86FSET_SEP
));
2056 ASSERT(curthread
->t_preempt
|| getpil() >= LOCK_LEVEL
);
2058 wrmsr(MSR_INTC_SEP_CS
, (uint64_t)(uintptr_t)KCS_SEL
);
2062 cpu_sep_disable(void)
2064 ASSERT(is_x86_feature(x86_featureset
, X86FSET_SEP
));
2065 ASSERT(curthread
->t_preempt
|| getpil() >= LOCK_LEVEL
);
2068 * Setting the SYSENTER_CS_MSR register to 0 causes software executing
2069 * the sysenter or sysexit instruction to trigger a #gp fault.
2071 wrmsr(MSR_INTC_SEP_CS
, 0);
2075 cpu_asysc_enable(void)
2077 ASSERT(is_x86_feature(x86_featureset
, X86FSET_ASYSC
));
2078 ASSERT(curthread
->t_preempt
|| getpil() >= LOCK_LEVEL
);
2080 wrmsr(MSR_AMD_EFER
, rdmsr(MSR_AMD_EFER
) |
2081 (uint64_t)(uintptr_t)AMD_EFER_SCE
);
2085 cpu_asysc_disable(void)
2087 ASSERT(is_x86_feature(x86_featureset
, X86FSET_ASYSC
));
2088 ASSERT(curthread
->t_preempt
|| getpil() >= LOCK_LEVEL
);
2091 * Turn off the SCE (syscall enable) bit in the EFER register. Software
2092 * executing syscall or sysret with this bit off will incur a #ud trap.
2094 wrmsr(MSR_AMD_EFER
, rdmsr(MSR_AMD_EFER
) &
2095 ~((uint64_t)(uintptr_t)AMD_EFER_SCE
));