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


   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.
   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 /*
  23  * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2017, Joyent, Inc.
  25  */
  26 /*
  27  * Copyright (c) 2010, Intel Corporation.
  28  * All rights reserved.
  29  */
  30 
  31 #include <sys/types.h>
  32 #include <sys/t_lock.h>
  33 #include <sys/param.h>
  34 #include <sys/segments.h>
  35 #include <sys/sysmacros.h>
  36 #include <sys/signal.h>
  37 #include <sys/systm.h>
  38 #include <sys/user.h>
  39 #include <sys/mman.h>
  40 #include <sys/vm.h>
  41 
  42 #include <sys/disp.h>
  43 #include <sys/class.h>
  44 


 173  */
 174 int maxphys = 56 * 1024;    /* XXX See vm_subr.c - max b_count in physio */
 175 int klustsize = 56 * 1024;
 176 
 177 caddr_t p0_va;          /* Virtual address for accessing physical page 0 */
 178 
 179 /*
 180  * defined here, though unused on x86,
 181  * to make kstat_fr.c happy.
 182  */
 183 int vac;
 184 
 185 void debug_enter(char *);
 186 
 187 extern void pm_cfb_check_and_powerup(void);
 188 extern void pm_cfb_rele(void);
 189 
 190 extern fastboot_info_t newkernel;
 191 
 192 /*






 193  * Machine dependent code to reboot.
 194  * "mdep" is interpreted as a character pointer; if non-null, it is a pointer
 195  * to a string to be used as the argument string when rebooting.
 196  *
 197  * "invoke_cb" is a boolean. It is set to true when mdboot() can safely
 198  * invoke CB_CL_MDBOOT callbacks before shutting the system down, i.e. when
 199  * we are in a normal shutdown sequence (interrupts are not blocked, the
 200  * system is not panic'ing or being suspended).
 201  */
 202 /*ARGSUSED*/
 203 void
 204 mdboot(int cmd, int fcn, char *mdep, boolean_t invoke_cb)
 205 {
 206         processorid_t bootcpuid = 0;
 207         static int is_first_quiesce = 1;
 208         static int is_first_reset = 1;
 209         int reset_status = 0;
 210         static char fallback_str[] = "Falling back to regular reboot.\n";
 211 
 212         if (fcn == AD_FASTREBOOT && !newkernel.fi_valid)


1437 {
1438         return (plat_dr_options & PLAT_DR_FEATURE_CPU);
1439 }
1440 
1441 boolean_t
1442 plat_dr_support_memory(void)
1443 {
1444         return (plat_dr_options & PLAT_DR_FEATURE_MEMORY);
1445 }
1446 
1447 void
1448 plat_dr_enable_capability(uint64_t features)
1449 {
1450         atomic_or_64(&plat_dr_options, features);
1451 }
1452 
1453 void
1454 plat_dr_disable_capability(uint64_t features)
1455 {
1456         atomic_and_64(&plat_dr_options, ~features);


































1457 }


   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.
   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 /*
  23  * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2020 Joyent, Inc.
  25  */
  26 /*
  27  * Copyright (c) 2010, Intel Corporation.
  28  * All rights reserved.
  29  */
  30 
  31 #include <sys/types.h>
  32 #include <sys/t_lock.h>
  33 #include <sys/param.h>
  34 #include <sys/segments.h>
  35 #include <sys/sysmacros.h>
  36 #include <sys/signal.h>
  37 #include <sys/systm.h>
  38 #include <sys/user.h>
  39 #include <sys/mman.h>
  40 #include <sys/vm.h>
  41 
  42 #include <sys/disp.h>
  43 #include <sys/class.h>
  44 


 173  */
 174 int maxphys = 56 * 1024;    /* XXX See vm_subr.c - max b_count in physio */
 175 int klustsize = 56 * 1024;
 176 
 177 caddr_t p0_va;          /* Virtual address for accessing physical page 0 */
 178 
 179 /*
 180  * defined here, though unused on x86,
 181  * to make kstat_fr.c happy.
 182  */
 183 int vac;
 184 
 185 void debug_enter(char *);
 186 
 187 extern void pm_cfb_check_and_powerup(void);
 188 extern void pm_cfb_rele(void);
 189 
 190 extern fastboot_info_t newkernel;
 191 
 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 /*
 199  * Machine dependent code to reboot.
 200  * "mdep" is interpreted as a character pointer; if non-null, it is a pointer
 201  * to a string to be used as the argument string when rebooting.
 202  *
 203  * "invoke_cb" is a boolean. It is set to true when mdboot() can safely
 204  * invoke CB_CL_MDBOOT callbacks before shutting the system down, i.e. when
 205  * we are in a normal shutdown sequence (interrupts are not blocked, the
 206  * system is not panic'ing or being suspended).
 207  */
 208 /*ARGSUSED*/
 209 void
 210 mdboot(int cmd, int fcn, char *mdep, boolean_t invoke_cb)
 211 {
 212         processorid_t bootcpuid = 0;
 213         static int is_first_quiesce = 1;
 214         static int is_first_reset = 1;
 215         int reset_status = 0;
 216         static char fallback_str[] = "Falling back to regular reboot.\n";
 217 
 218         if (fcn == AD_FASTREBOOT && !newkernel.fi_valid)


1443 {
1444         return (plat_dr_options & PLAT_DR_FEATURE_CPU);
1445 }
1446 
1447 boolean_t
1448 plat_dr_support_memory(void)
1449 {
1450         return (plat_dr_options & PLAT_DR_FEATURE_MEMORY);
1451 }
1452 
1453 void
1454 plat_dr_enable_capability(uint64_t features)
1455 {
1456         atomic_or_64(&plat_dr_options, features);
1457 }
1458 
1459 void
1460 plat_dr_disable_capability(uint64_t features)
1461 {
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         }
1497 }