Print this page
9685 KPTI %cr3 handling needs fixes

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/intel/kdi/kdi_idt.c
          +++ new/usr/src/uts/intel/kdi/kdi_idt.c
↓ open down ↓ 156 lines elided ↑ open up ↑
 157  157  #if !defined(__xpv)
 158  158          { T_DBLFLT, 0,          syserrtrap, NULL },
 159  159  #endif
 160  160          { T_EXTOVRFLT, 0,       kdi_trap9, NULL },
 161  161          { T_TSSFLT, 0,          kdi_traperr10, NULL },
 162  162          { T_SEGFLT, 0,          kdi_traperr11, NULL },
 163  163          { T_STKFLT, 0,          kdi_traperr12, NULL },
 164  164          { T_GPFLT, 0,           kdi_traperr13, NULL },
 165  165          { T_PGFLT, 0,           kdi_traperr14, NULL },
 166  166          { 15, 0,                kdi_invaltrap, NULL },
 167      -        { T_EXTERRFLT, 0,       kdi_trap16, NULL },
 168      -        { T_ALIGNMENT, 0,       kdi_traperr17, NULL },
      167 +        { T_EXTERRFLT, 0,       kdi_trap16, NULL },
      168 +        { T_ALIGNMENT, 0,       kdi_traperr17, NULL },
 169  169          { T_MCE, 0,             kdi_trap18, NULL },
 170  170          { T_SIMDFPE, 0,         kdi_trap19, NULL },
 171  171          { T_DBGENTR, 0,         kdi_trap20, NULL },
 172  172          { 21, 31,               kdi_invaltrap, NULL },
 173  173          { 32, 255,              kdi_ivct32, &kdi_ivct_size },
 174  174          { 0, 0, NULL },
 175  175  };
 176  176  
 177  177  void
 178  178  kdi_idt_init(selector_t sel)
↓ open down ↓ 180 lines elided ↑ open up ↑
 359  359  kdi_deactivate(void)
 360  360  {
 361  361          cpuset_t cpuset;
 362  362          CPUSET_ALL(cpuset);
 363  363  
 364  364          xc_call(0, 0, 0, CPUSET2BV(cpuset), (xc_func_t)kdi_cpu_deactivate);
 365  365          kdi_nmemranges = 0;
 366  366  }
 367  367  
 368  368  /*
 369      - * We receive all breakpoints and single step traps.  Some of them,
 370      - * including those from userland and those induced by DTrace providers,
 371      - * are intended for the kernel, and must be processed there.  We adopt
 372      - * this ours-until-proven-otherwise position due to the painful
 373      - * consequences of sending the kernel an unexpected breakpoint or
 374      - * single step.  Unless someone can prove to us that the kernel is
 375      - * prepared to handle the trap, we'll assume there's a problem and will
 376      - * give the user a chance to debug it.
      369 + * We receive all breakpoints and single step traps.  Some of them, including
      370 + * those from userland and those induced by DTrace providers, are intended for
      371 + * the kernel, and must be processed there.  We adopt this
      372 + * ours-until-proven-otherwise position due to the painful consequences of
      373 + * sending the kernel an unexpected breakpoint or single step.  Unless someone
      374 + * can prove to us that the kernel is prepared to handle the trap, we'll assume
      375 + * there's a problem and will give the user a chance to debug it.
      376 + *
      377 + * If we return 2, then the calling code should restore the trap-time %cr3: that
      378 + * is, it really is a kernel-originated trap.
 377  379   */
 378  380  int
 379  381  kdi_trap_pass(kdi_cpusave_t *cpusave)
 380  382  {
 381  383          greg_t tt = cpusave->krs_gregs[KDIREG_TRAPNO];
 382  384          greg_t pc = cpusave->krs_gregs[KDIREG_PC];
 383  385          greg_t cs = cpusave->krs_gregs[KDIREG_CS];
 384  386  
 385  387          if (USERMODE(cs))
 386  388                  return (1);
 387  389  
 388  390          if (tt != T_BPTFLT && tt != T_SGLSTP)
 389  391                  return (0);
 390  392  
 391  393          if (tt == T_BPTFLT && kdi_dtrace_get_state() ==
 392  394              KDI_DTSTATE_DTRACE_ACTIVE)
 393      -                return (1);
      395 +                return (2);
 394  396  
 395  397          /*
 396  398           * See the comments in the kernel's T_SGLSTP handler for why we need to
 397  399           * do this.
 398  400           */
 399  401  #if !defined(__xpv)
 400  402          if (tt == T_SGLSTP &&
 401  403              (pc == (greg_t)sys_sysenter || pc == (greg_t)brand_sys_sysenter ||
 402  404              pc == (greg_t)tr_sys_sysenter ||
 403  405              pc == (greg_t)tr_brand_sys_sysenter)) {
↓ open down ↓ 27 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX