Print this page
10908 Simplify SMAP relocations with krtld

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/i86pc/os/machdep.c
          +++ new/usr/src/uts/i86pc/os/machdep.c
↓ open down ↓ 182 lines elided ↑ open up ↑
 183  183  int vac;
 184  184  
 185  185  void debug_enter(char *);
 186  186  
 187  187  extern void pm_cfb_check_and_powerup(void);
 188  188  extern void pm_cfb_rele(void);
 189  189  
 190  190  extern fastboot_info_t newkernel;
 191  191  
 192  192  /*
      193 + * Instructions to enable or disable SMAP, respectively.
      194 + */
      195 +static const uint8_t clac_instr[3] = { 0x0f, 0x01, 0xca };
      196 +static const uint8_t stac_instr[3] = { 0x0f, 0x01, 0xcb };
      197 +
      198 +/*
 193  199   * Machine dependent code to reboot.
 194  200   * "mdep" is interpreted as a character pointer; if non-null, it is a pointer
 195  201   * to a string to be used as the argument string when rebooting.
 196  202   *
 197  203   * "invoke_cb" is a boolean. It is set to true when mdboot() can safely
 198  204   * invoke CB_CL_MDBOOT callbacks before shutting the system down, i.e. when
 199  205   * we are in a normal shutdown sequence (interrupts are not blocked, the
 200  206   * system is not panic'ing or being suspended).
 201  207   */
 202  208  /*ARGSUSED*/
↓ open down ↓ 1244 lines elided ↑ open up ↑
1447 1453  void
1448 1454  plat_dr_enable_capability(uint64_t features)
1449 1455  {
1450 1456          atomic_or_64(&plat_dr_options, features);
1451 1457  }
1452 1458  
1453 1459  void
1454 1460  plat_dr_disable_capability(uint64_t features)
1455 1461  {
1456 1462          atomic_and_64(&plat_dr_options, ~features);
     1463 +}
     1464 +
     1465 +/*
     1466 + * If SMAP is supported, look through hi_calls and inline
     1467 + * calls to smap_enable() to clac and smap_disable() to stac.
     1468 + */
     1469 +void
     1470 +hotinline_smap(hotinline_desc_t *hid)
     1471 +{
     1472 +        if (is_x86_feature(x86_featureset, X86FSET_SMAP) == B_FALSE)
     1473 +                return;
     1474 +
     1475 +        if (strcmp(hid->hid_symname, "smap_enable") == 0) {
     1476 +                bcopy(clac_instr, (void *)hid->hid_instr_offset,
     1477 +                    sizeof (clac_instr));
     1478 +        } else if (strcmp(hid->hid_symname, "smap_disable") == 0) {
     1479 +                bcopy(stac_instr, (void *)hid->hid_instr_offset,
     1480 +                    sizeof (stac_instr));
     1481 +        }
     1482 +}
     1483 +
     1484 +/*
     1485 + * Loop through hi_calls and hand off the inlining to
     1486 + * the appropriate calls.
     1487 + */
     1488 +void
     1489 +do_hotinlines(struct module *mp)
     1490 +{
     1491 +        for (hotinline_desc_t *hid = mp->hi_calls; hid != NULL;
     1492 +            hid = hid->hid_next) {
     1493 +#if !defined(__xpv)
     1494 +                hotinline_smap(hid);
     1495 +#endif  /* __xpv */
     1496 +        }
1457 1497  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX