Print this page
9059 Simplify SMAP relocations with krtld
Portions contributed by: John Levon <john.levon@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/i86pc/os/machdep.c
          +++ new/usr/src/uts/i86pc/os/machdep.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
  24      - * Copyright 2017, Joyent, Inc.
       24 + * Copyright 2020 Joyent, Inc.
  25   25   */
  26   26  /*
  27   27   * Copyright (c) 2010, Intel Corporation.
  28   28   * All rights reserved.
  29   29   */
  30   30  
  31   31  #include <sys/types.h>
  32   32  #include <sys/t_lock.h>
  33   33  #include <sys/param.h>
  34   34  #include <sys/segments.h>
↓ open down ↓ 148 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