Print this page
10597 would like a way to set NMI behavior at boot
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Andy Fiddaman <andy@omniosce.org>


   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 (c) 2012 Gary Mills
  23  *
  24  * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
  25  * Copyright (c) 2011 by Delphix. All rights reserved.
  26  * Copyright 2018 Joyent, Inc.
  27  */
  28 /*
  29  * Copyright (c) 2010, Intel Corporation.
  30  * All rights reserved.
  31  */
  32 
  33 #include <sys/types.h>
  34 #include <sys/sysmacros.h>
  35 #include <sys/disp.h>
  36 #include <sys/promif.h>
  37 #include <sys/clock.h>
  38 #include <sys/cpuvar.h>
  39 #include <sys/stack.h>
  40 #include <vm/as.h>
  41 #include <vm/hat.h>
  42 #include <sys/reboot.h>
  43 #include <sys/avintr.h>
  44 #include <sys/vtrace.h>
  45 #include <sys/proc.h>
  46 #include <sys/thread.h>
  47 #include <sys/cpupart.h>
  48 #include <sys/pset.h>
  49 #include <sys/copyops.h>
  50 #include <sys/pg.h>
  51 #include <sys/disp.h>
  52 #include <sys/debug.h>
  53 #include <sys/sunddi.h>
  54 #include <sys/x86_archext.h>
  55 #include <sys/privregs.h>
  56 #include <sys/machsystm.h>
  57 #include <sys/ontrap.h>
  58 #include <sys/bootconf.h>
  59 #include <sys/boot_console.h>
  60 #include <sys/kdi_machimpl.h>
  61 #include <sys/archsystm.h>
  62 #include <sys/promif.h>
  63 #include <sys/pci_cfgspace.h>


  64 #include <sys/bootvfs.h>
  65 #include <sys/tsc.h>
  66 #ifdef __xpv
  67 #include <sys/hypervisor.h>
  68 #else
  69 #include <sys/xpv_support.h>
  70 #endif
  71 
  72 /*
  73  * some globals for patching the result of cpuid
  74  * to solve problems w/ creative cpu vendors
  75  */
  76 
  77 extern uint32_t cpuid_feature_ecx_include;
  78 extern uint32_t cpuid_feature_ecx_exclude;
  79 extern uint32_t cpuid_feature_edx_include;
  80 extern uint32_t cpuid_feature_edx_exclude;
  81 


  82 /*
  83  * Set console mode
  84  */
  85 static void
  86 set_console_mode(uint8_t val)
  87 {
  88         struct bop_regs rp = {0};
  89 
  90         rp.eax.byte.ah = 0x0;
  91         rp.eax.byte.al = val;
  92         rp.ebx.word.bx = 0x0;
  93 
  94         BOP_DOINT(bootops, 0x10, &rp);
  95 }
  96 
  97 
  98 /*
  99  * Setup routine called right before main(). Interposing this function
 100  * before main() allows us to call it in a machine-independent fashion.
 101  */
 102 void
 103 mlsetup(struct regs *rp)
 104 {
 105         u_longlong_t prop_value;

 106         extern struct classfuncs sys_classfuncs;
 107         extern disp_t cpu0_disp;
 108         extern char t0stack[];
 109         extern int post_fastreboot;
 110         extern uint64_t plat_dr_options;
 111 
 112         ASSERT_STACK_ALIGNED();
 113 
 114         /*
 115          * initialize cpu_self
 116          */
 117         cpu[0]->cpu_self = cpu[0];
 118 
 119 #if defined(__xpv)
 120         /*
 121          * Point at the hypervisor's virtual cpu structure
 122          */
 123         cpu[0]->cpu_m.mcpu_vcpu_info = &HYPERVISOR_shared_info->vcpu_info[0];
 124 #endif
 125 


 132                 cpuid_feature_ecx_include = 0;
 133         else
 134                 cpuid_feature_ecx_include = (uint32_t)prop_value;
 135 
 136         if (bootprop_getval("cpuid_feature_ecx_exclude", &prop_value) != 0)
 137                 cpuid_feature_ecx_exclude = 0;
 138         else
 139                 cpuid_feature_ecx_exclude = (uint32_t)prop_value;
 140 
 141         if (bootprop_getval("cpuid_feature_edx_include", &prop_value) != 0)
 142                 cpuid_feature_edx_include = 0;
 143         else
 144                 cpuid_feature_edx_include = (uint32_t)prop_value;
 145 
 146         if (bootprop_getval("cpuid_feature_edx_exclude", &prop_value) != 0)
 147                 cpuid_feature_edx_exclude = 0;
 148         else
 149                 cpuid_feature_edx_exclude = (uint32_t)prop_value;
 150 
 151 #if !defined(__xpv)













 152         /*
 153          * Check to see if KPTI has been explicitly enabled or disabled.
 154          * We have to check this before init_desctbls().
 155          */
 156         if (bootprop_getval("kpti", &prop_value) == 0) {
 157                 kpti_enable = (uint64_t)(prop_value == 1);
 158                 prom_printf("unix: forcing kpti to %s due to boot argument\n",
 159                     (kpti_enable == 1) ? "ON" : "OFF");
 160         } else {
 161                 kpti_enable = 1;
 162         }
 163 
 164         if (bootprop_getval("pcid", &prop_value) == 0 && prop_value == 0) {
 165                 prom_printf("unix: forcing pcid to OFF due to boot argument\n");
 166                 x86_use_pcid = 0;
 167         } else if (kpti_enable != 1) {
 168                 x86_use_pcid = 0;
 169         }
 170 #endif
 171 




   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 (c) 2012 Gary Mills
  23  *
  24  * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
  25  * Copyright (c) 2011 by Delphix. All rights reserved.
  26  * Copyright 2019, Joyent, Inc.
  27  */
  28 /*
  29  * Copyright (c) 2010, Intel Corporation.
  30  * All rights reserved.
  31  */
  32 
  33 #include <sys/types.h>
  34 #include <sys/sysmacros.h>
  35 #include <sys/disp.h>
  36 #include <sys/promif.h>
  37 #include <sys/clock.h>
  38 #include <sys/cpuvar.h>
  39 #include <sys/stack.h>
  40 #include <vm/as.h>
  41 #include <vm/hat.h>
  42 #include <sys/reboot.h>
  43 #include <sys/avintr.h>
  44 #include <sys/vtrace.h>
  45 #include <sys/proc.h>
  46 #include <sys/thread.h>
  47 #include <sys/cpupart.h>
  48 #include <sys/pset.h>
  49 #include <sys/copyops.h>
  50 #include <sys/pg.h>
  51 #include <sys/disp.h>
  52 #include <sys/debug.h>
  53 #include <sys/sunddi.h>
  54 #include <sys/x86_archext.h>
  55 #include <sys/privregs.h>
  56 #include <sys/machsystm.h>
  57 #include <sys/ontrap.h>
  58 #include <sys/bootconf.h>
  59 #include <sys/boot_console.h>
  60 #include <sys/kdi_machimpl.h>
  61 #include <sys/archsystm.h>
  62 #include <sys/promif.h>
  63 #include <sys/pci_cfgspace.h>
  64 #include <sys/apic.h>
  65 #include <sys/apic_common.h>
  66 #include <sys/bootvfs.h>
  67 #include <sys/tsc.h>
  68 #ifdef __xpv
  69 #include <sys/hypervisor.h>
  70 #else
  71 #include <sys/xpv_support.h>
  72 #endif
  73 
  74 /*
  75  * some globals for patching the result of cpuid
  76  * to solve problems w/ creative cpu vendors
  77  */
  78 
  79 extern uint32_t cpuid_feature_ecx_include;
  80 extern uint32_t cpuid_feature_ecx_exclude;
  81 extern uint32_t cpuid_feature_edx_include;
  82 extern uint32_t cpuid_feature_edx_exclude;
  83 
  84 nmi_action_t nmi_action = NMI_ACTION_UNSET;
  85 
  86 /*
  87  * Set console mode
  88  */
  89 static void
  90 set_console_mode(uint8_t val)
  91 {
  92         struct bop_regs rp = {0};
  93 
  94         rp.eax.byte.ah = 0x0;
  95         rp.eax.byte.al = val;
  96         rp.ebx.word.bx = 0x0;
  97 
  98         BOP_DOINT(bootops, 0x10, &rp);
  99 }
 100 
 101 
 102 /*
 103  * Setup routine called right before main(). Interposing this function
 104  * before main() allows us to call it in a machine-independent fashion.
 105  */
 106 void
 107 mlsetup(struct regs *rp)
 108 {
 109         u_longlong_t prop_value;
 110         char prop_str[BP_MAX_STRLEN];
 111         extern struct classfuncs sys_classfuncs;
 112         extern disp_t cpu0_disp;
 113         extern char t0stack[];
 114         extern int post_fastreboot;
 115         extern uint64_t plat_dr_options;
 116 
 117         ASSERT_STACK_ALIGNED();
 118 
 119         /*
 120          * initialize cpu_self
 121          */
 122         cpu[0]->cpu_self = cpu[0];
 123 
 124 #if defined(__xpv)
 125         /*
 126          * Point at the hypervisor's virtual cpu structure
 127          */
 128         cpu[0]->cpu_m.mcpu_vcpu_info = &HYPERVISOR_shared_info->vcpu_info[0];
 129 #endif
 130 


 137                 cpuid_feature_ecx_include = 0;
 138         else
 139                 cpuid_feature_ecx_include = (uint32_t)prop_value;
 140 
 141         if (bootprop_getval("cpuid_feature_ecx_exclude", &prop_value) != 0)
 142                 cpuid_feature_ecx_exclude = 0;
 143         else
 144                 cpuid_feature_ecx_exclude = (uint32_t)prop_value;
 145 
 146         if (bootprop_getval("cpuid_feature_edx_include", &prop_value) != 0)
 147                 cpuid_feature_edx_include = 0;
 148         else
 149                 cpuid_feature_edx_include = (uint32_t)prop_value;
 150 
 151         if (bootprop_getval("cpuid_feature_edx_exclude", &prop_value) != 0)
 152                 cpuid_feature_edx_exclude = 0;
 153         else
 154                 cpuid_feature_edx_exclude = (uint32_t)prop_value;
 155 
 156 #if !defined(__xpv)
 157         if (bootprop_getstr("nmi", prop_str, sizeof (prop_str)) == 0) {
 158                 if (strcmp(prop_str, "ignore") == 0) {
 159                         nmi_action = NMI_ACTION_IGNORE;
 160                 } else if (strcmp(prop_str, "panic") == 0) {
 161                         nmi_action = NMI_ACTION_PANIC;
 162                 } else if (strcmp(prop_str, "kmdb") == 0) {
 163                         nmi_action = NMI_ACTION_KMDB;
 164                 } else {
 165                         prom_printf("unix: ignoring unknown nmi=%s\n",
 166                             prop_str);
 167                 }
 168         }
 169 
 170         /*
 171          * Check to see if KPTI has been explicitly enabled or disabled.
 172          * We have to check this before init_desctbls().
 173          */
 174         if (bootprop_getval("kpti", &prop_value) == 0) {
 175                 kpti_enable = (uint64_t)(prop_value == 1);
 176                 prom_printf("unix: forcing kpti to %s due to boot argument\n",
 177                     (kpti_enable == 1) ? "ON" : "OFF");
 178         } else {
 179                 kpti_enable = 1;
 180         }
 181 
 182         if (bootprop_getval("pcid", &prop_value) == 0 && prop_value == 0) {
 183                 prom_printf("unix: forcing pcid to OFF due to boot argument\n");
 184                 x86_use_pcid = 0;
 185         } else if (kpti_enable != 1) {
 186                 x86_use_pcid = 0;
 187         }
 188 #endif
 189