Print this page
9441 kmdb should stash %cr3 in kdiregs
Reviewed by: John Levon <john.levon@joyent.com>
8956 Implement KPTI
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>


   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 2007 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 /*
  27  * Copyright (c) 2012, Joyent, Inc.  All rights reserved.
  28  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
  29  * Copyright (c) 2013 by Delphix. All rights reserved.
  30  */
  31 
  32 #include <sys/types.h>
  33 #include <sys/reg.h>
  34 #include <sys/privregs.h>
  35 #include <sys/stack.h>
  36 #include <sys/frame.h>
  37 
  38 #include <mdb/mdb_target_impl.h>
  39 #include <mdb/mdb_kreg_impl.h>
  40 #include <mdb/mdb_debug.h>
  41 #include <mdb/mdb_modapi.h>
  42 #include <mdb/mdb_amd64util.h>
  43 #include <mdb/mdb_ctf.h>
  44 #include <mdb/mdb_err.h>
  45 #include <mdb/mdb.h>
  46 
  47 #include <saveargs.h>


 116         { "r14l", KREG_R14, MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
 117         { "r15", KREG_R15, MDB_TGT_R_EXPORT },
 118         { "r15d", KREG_R15, MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
 119         { "r15w", KREG_R15, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
 120         { "r15l", KREG_R15, MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
 121         { "ds", KREG_DS, MDB_TGT_R_EXPORT },
 122         { "es", KREG_ES, MDB_TGT_R_EXPORT },
 123         { "fs", KREG_FS, MDB_TGT_R_EXPORT },
 124         { "gs", KREG_GS, MDB_TGT_R_EXPORT },
 125         { "trapno", KREG_TRAPNO, MDB_TGT_R_EXPORT | MDB_TGT_R_PRIV },
 126         { "err", KREG_ERR, MDB_TGT_R_EXPORT | MDB_TGT_R_PRIV },
 127         { "rip", KREG_RIP, MDB_TGT_R_EXPORT },
 128         { "cs", KREG_CS, MDB_TGT_R_EXPORT },
 129         { "rflags", KREG_RFLAGS, MDB_TGT_R_EXPORT },
 130         { "eflags", KREG_RFLAGS, MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
 131         { "rsp", KREG_RSP, MDB_TGT_R_EXPORT },
 132         { "esp", KREG_RSP, MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
 133         { "sp",  KREG_RSP, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
 134         { "spl", KREG_RSP, MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
 135         { "ss", KREG_SS, MDB_TGT_R_EXPORT },




 136         { NULL, 0, 0 }
 137 };
 138 
 139 void
 140 mdb_amd64_printregs(const mdb_tgt_gregset_t *gregs)
 141 {
 142         const kreg_t *kregs = &gregs->kregs[0];
 143         kreg_t rflags = kregs[KREG_RFLAGS];
 144 
 145 #define GETREG2(x) ((uintptr_t)kregs[(x)]), ((uintptr_t)kregs[(x)])
 146 
 147         mdb_printf("%%rax = 0x%0?p %15A %%r9  = 0x%0?p %A\n",
 148             GETREG2(KREG_RAX), GETREG2(KREG_R9));
 149         mdb_printf("%%rbx = 0x%0?p %15A %%r10 = 0x%0?p %A\n",
 150             GETREG2(KREG_RBX), GETREG2(KREG_R10));
 151         mdb_printf("%%rcx = 0x%0?p %15A %%r11 = 0x%0?p %A\n",
 152             GETREG2(KREG_RCX), GETREG2(KREG_R11));
 153         mdb_printf("%%rdx = 0x%0?p %15A %%r12 = 0x%0?p %A\n",
 154             GETREG2(KREG_RDX), GETREG2(KREG_R12));
 155         mdb_printf("%%rsi = 0x%0?p %15A %%r13 = 0x%0?p %A\n",


 169             (rflags & KREG_EFLAGS_ID_MASK) >> KREG_EFLAGS_ID_SHIFT,
 170             (rflags & KREG_EFLAGS_VIP_MASK) >> KREG_EFLAGS_VIP_SHIFT,
 171             (rflags & KREG_EFLAGS_VIF_MASK) >> KREG_EFLAGS_VIF_SHIFT,
 172             (rflags & KREG_EFLAGS_AC_MASK) >> KREG_EFLAGS_AC_SHIFT,
 173             (rflags & KREG_EFLAGS_VM_MASK) >> KREG_EFLAGS_VM_SHIFT,
 174             (rflags & KREG_EFLAGS_RF_MASK) >> KREG_EFLAGS_RF_SHIFT,
 175             (rflags & KREG_EFLAGS_NT_MASK) >> KREG_EFLAGS_NT_SHIFT,
 176             (rflags & KREG_EFLAGS_IOPL_MASK) >> KREG_EFLAGS_IOPL_SHIFT);
 177 
 178         mdb_printf("  status=<%s,%s,%s,%s,%s,%s,%s,%s,%s>\n\n",
 179             (rflags & KREG_EFLAGS_OF_MASK) ? "OF" : "of",
 180             (rflags & KREG_EFLAGS_DF_MASK) ? "DF" : "df",
 181             (rflags & KREG_EFLAGS_IF_MASK) ? "IF" : "if",
 182             (rflags & KREG_EFLAGS_TF_MASK) ? "TF" : "tf",
 183             (rflags & KREG_EFLAGS_SF_MASK) ? "SF" : "sf",
 184             (rflags & KREG_EFLAGS_ZF_MASK) ? "ZF" : "zf",
 185             (rflags & KREG_EFLAGS_AF_MASK) ? "AF" : "af",
 186             (rflags & KREG_EFLAGS_PF_MASK) ? "PF" : "pf",
 187             (rflags & KREG_EFLAGS_CF_MASK) ? "CF" : "cf");
 188 
 189         mdb_printf("%24s%%cs = 0x%04x\t%%ds = 0x%04x\t%%es = 0x%04x\n",
 190             " ", kregs[KREG_CS], kregs[KREG_DS], kregs[KREG_ES]);
 191 
 192         mdb_printf("%%trapno = 0x%x\t\t%%fs = 0x%04x\t%%gs = 0x%04x\n",
 193             kregs[KREG_TRAPNO], (kregs[KREG_FS] & 0xffff),
 194             (kregs[KREG_GS] & 0xffff));
 195         mdb_printf("   %%err = 0x%x\n", kregs[KREG_ERR]);

 196 }
 197 
 198 int
 199 mdb_amd64_kvm_stack_iter(mdb_tgt_t *t, const mdb_tgt_gregset_t *gsp,
 200     mdb_tgt_stack_f *func, void *arg)
 201 {
 202         mdb_tgt_gregset_t gregs;
 203         kreg_t *kregs = &gregs.kregs[0];
 204         int got_pc = (gsp->kregs[KREG_RIP] != 0);
 205         uint_t argc, reg_argc;
 206         long fr_argv[32];
 207         int start_index; /* index to save_instr where to start comparison */
 208         int err;
 209         int i;
 210 
 211         struct fr {
 212                 uintptr_t fr_savfp;
 213                 uintptr_t fr_savpc;
 214         } fr;
 215 




   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 2007 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 /*
  27  * Copyright (c) 2018, Joyent, Inc.  All rights reserved.
  28  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
  29  * Copyright (c) 2013 by Delphix. All rights reserved.
  30  */
  31 
  32 #include <sys/types.h>
  33 #include <sys/reg.h>
  34 #include <sys/privregs.h>
  35 #include <sys/stack.h>
  36 #include <sys/frame.h>
  37 
  38 #include <mdb/mdb_target_impl.h>
  39 #include <mdb/mdb_kreg_impl.h>
  40 #include <mdb/mdb_debug.h>
  41 #include <mdb/mdb_modapi.h>
  42 #include <mdb/mdb_amd64util.h>
  43 #include <mdb/mdb_ctf.h>
  44 #include <mdb/mdb_err.h>
  45 #include <mdb/mdb.h>
  46 
  47 #include <saveargs.h>


 116         { "r14l", KREG_R14, MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
 117         { "r15", KREG_R15, MDB_TGT_R_EXPORT },
 118         { "r15d", KREG_R15, MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
 119         { "r15w", KREG_R15, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
 120         { "r15l", KREG_R15, MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
 121         { "ds", KREG_DS, MDB_TGT_R_EXPORT },
 122         { "es", KREG_ES, MDB_TGT_R_EXPORT },
 123         { "fs", KREG_FS, MDB_TGT_R_EXPORT },
 124         { "gs", KREG_GS, MDB_TGT_R_EXPORT },
 125         { "trapno", KREG_TRAPNO, MDB_TGT_R_EXPORT | MDB_TGT_R_PRIV },
 126         { "err", KREG_ERR, MDB_TGT_R_EXPORT | MDB_TGT_R_PRIV },
 127         { "rip", KREG_RIP, MDB_TGT_R_EXPORT },
 128         { "cs", KREG_CS, MDB_TGT_R_EXPORT },
 129         { "rflags", KREG_RFLAGS, MDB_TGT_R_EXPORT },
 130         { "eflags", KREG_RFLAGS, MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
 131         { "rsp", KREG_RSP, MDB_TGT_R_EXPORT },
 132         { "esp", KREG_RSP, MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
 133         { "sp",  KREG_RSP, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
 134         { "spl", KREG_RSP, MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
 135         { "ss", KREG_SS, MDB_TGT_R_EXPORT },
 136         { "gsbase", KREG_GSBASE, MDB_TGT_R_EXPORT },
 137         { "kgsbase", KREG_KGSBASE, MDB_TGT_R_EXPORT },
 138         { "cr2", KREG_CR2, MDB_TGT_R_EXPORT },
 139         { "cr3", KREG_CR3, MDB_TGT_R_EXPORT },
 140         { NULL, 0, 0 }
 141 };
 142 
 143 void
 144 mdb_amd64_printregs(const mdb_tgt_gregset_t *gregs)
 145 {
 146         const kreg_t *kregs = &gregs->kregs[0];
 147         kreg_t rflags = kregs[KREG_RFLAGS];
 148 
 149 #define GETREG2(x) ((uintptr_t)kregs[(x)]), ((uintptr_t)kregs[(x)])
 150 
 151         mdb_printf("%%rax = 0x%0?p %15A %%r9  = 0x%0?p %A\n",
 152             GETREG2(KREG_RAX), GETREG2(KREG_R9));
 153         mdb_printf("%%rbx = 0x%0?p %15A %%r10 = 0x%0?p %A\n",
 154             GETREG2(KREG_RBX), GETREG2(KREG_R10));
 155         mdb_printf("%%rcx = 0x%0?p %15A %%r11 = 0x%0?p %A\n",
 156             GETREG2(KREG_RCX), GETREG2(KREG_R11));
 157         mdb_printf("%%rdx = 0x%0?p %15A %%r12 = 0x%0?p %A\n",
 158             GETREG2(KREG_RDX), GETREG2(KREG_R12));
 159         mdb_printf("%%rsi = 0x%0?p %15A %%r13 = 0x%0?p %A\n",


 173             (rflags & KREG_EFLAGS_ID_MASK) >> KREG_EFLAGS_ID_SHIFT,
 174             (rflags & KREG_EFLAGS_VIP_MASK) >> KREG_EFLAGS_VIP_SHIFT,
 175             (rflags & KREG_EFLAGS_VIF_MASK) >> KREG_EFLAGS_VIF_SHIFT,
 176             (rflags & KREG_EFLAGS_AC_MASK) >> KREG_EFLAGS_AC_SHIFT,
 177             (rflags & KREG_EFLAGS_VM_MASK) >> KREG_EFLAGS_VM_SHIFT,
 178             (rflags & KREG_EFLAGS_RF_MASK) >> KREG_EFLAGS_RF_SHIFT,
 179             (rflags & KREG_EFLAGS_NT_MASK) >> KREG_EFLAGS_NT_SHIFT,
 180             (rflags & KREG_EFLAGS_IOPL_MASK) >> KREG_EFLAGS_IOPL_SHIFT);
 181 
 182         mdb_printf("  status=<%s,%s,%s,%s,%s,%s,%s,%s,%s>\n\n",
 183             (rflags & KREG_EFLAGS_OF_MASK) ? "OF" : "of",
 184             (rflags & KREG_EFLAGS_DF_MASK) ? "DF" : "df",
 185             (rflags & KREG_EFLAGS_IF_MASK) ? "IF" : "if",
 186             (rflags & KREG_EFLAGS_TF_MASK) ? "TF" : "tf",
 187             (rflags & KREG_EFLAGS_SF_MASK) ? "SF" : "sf",
 188             (rflags & KREG_EFLAGS_ZF_MASK) ? "ZF" : "zf",
 189             (rflags & KREG_EFLAGS_AF_MASK) ? "AF" : "af",
 190             (rflags & KREG_EFLAGS_PF_MASK) ? "PF" : "pf",
 191             (rflags & KREG_EFLAGS_CF_MASK) ? "CF" : "cf");
 192 
 193         mdb_printf("%%cs = 0x%04x\t%%ds = 0x%04x\t"
 194             "%%es = 0x%04x\t%%fs = 0x%04x\n", kregs[KREG_CS], kregs[KREG_DS],
 195             kregs[KREG_ES], kregs[KREG_FS] & 0xffff);
 196         mdb_printf("%%gs = 0x%04x\t%%gsbase = 0x%lx\t%%kgsbase = 0x%lx\n",
 197             kregs[KREG_GS] & 0xffff, kregs[KREG_GSBASE], kregs[KREG_KGSBASE]);
 198         mdb_printf("%%trapno = 0x%x\t%%err = 0x%x\t%%cr2 = 0x%lx\t"
 199             "%%cr3 = 0x%lx\n", kregs[KREG_TRAPNO], kregs[KREG_ERR],
 200             kregs[KREG_CR2], kregs[KREG_CR3]);
 201 }
 202 
 203 int
 204 mdb_amd64_kvm_stack_iter(mdb_tgt_t *t, const mdb_tgt_gregset_t *gsp,
 205     mdb_tgt_stack_f *func, void *arg)
 206 {
 207         mdb_tgt_gregset_t gregs;
 208         kreg_t *kregs = &gregs.kregs[0];
 209         int got_pc = (gsp->kregs[KREG_RIP] != 0);
 210         uint_t argc, reg_argc;
 211         long fr_argv[32];
 212         int start_index; /* index to save_instr where to start comparison */
 213         int err;
 214         int i;
 215 
 216         struct fr {
 217                 uintptr_t fr_savfp;
 218                 uintptr_t fr_savpc;
 219         } fr;
 220