Print this page
9736 kmdb tortures via single-step miscellaneous trap
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@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  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.

  24  */
  25 
  26 #pragma ident   "%Z%%M% %I%     %E% SMI"
  27 
  28 /*
  29  * The main CPU-control loops, used to control masters and slaves.
  30  */
  31 
  32 #include <sys/types.h>
  33 
  34 #include <kmdb/kaif.h>
  35 #include <kmdb/kaif_start.h>
  36 #include <kmdb/kmdb_asmutil.h>
  37 #include <kmdb/kmdb_dpi_impl.h>
  38 #include <kmdb/kmdb_kdi.h>
  39 
  40 #define KAIF_SLAVE_CMD_SPIN     0
  41 #define KAIF_SLAVE_CMD_SWITCH   1
  42 #define KAIF_SLAVE_CMD_RESUME   2
  43 #define KAIF_SLAVE_CMD_FLUSH    3
  44 #define KAIF_SLAVE_CMD_REBOOT   4
  45 #if defined(__sparc)
  46 #define KAIF_SLAVE_CMD_ACK      5
  47 #endif


 275                 kaif_slave_cmd = KAIF_SLAVE_CMD_SPIN;
 276 
 277                 membar_producer();
 278 
 279                 kmdb_kdi_stop_slaves(cpusave->krs_cpu_id, 1);
 280         } else {
 281                 /* The master was already chosen - go be a slave */
 282                 cpusave->krs_cpu_state = KAIF_CPU_STATE_SLAVE;
 283                 membar_producer();
 284         }
 285 
 286         kaif_lock_exit(&kaif_master_lock);
 287 }
 288 
 289 int
 290 kaif_main_loop(kaif_cpusave_t *cpusave)
 291 {
 292         int cmd;
 293 
 294         if (kaif_master_cpuid == KAIF_MASTER_CPUID_UNSET) {






 295                 if (!kmdb_dpi_resume_requested &&
 296                     kmdb_kdi_get_unload_request()) {




 297                         /*
 298                          * Special case: Unload requested before first debugger
 299                          * entry.  Don't stop the world, as there's nothing to
 300                          * clean up that can't be handled by the running kernel.







 301                          */

 302                         cpusave->krs_cpu_state = KAIF_CPU_STATE_NONE;
 303                         return (KAIF_CPU_CMD_RESUME);
 304                 }
 305 
 306                 kaif_select_master(cpusave);
 307 
 308 #ifdef __sparc
 309                 if (kaif_master_cpuid == cpusave->krs_cpu_id) {
 310                         /*
 311                          * Everyone has arrived, so we can disarm the post-PROM
 312                          * entry point.
 313                          */
 314                         *kaif_promexitarmp = 0;
 315                         membar_producer();
 316                 }
 317 #endif
 318         } else if (kaif_master_cpuid == cpusave->krs_cpu_id) {
 319                 cpusave->krs_cpu_state = KAIF_CPU_STATE_MASTER;
 320         } else {
 321                 cpusave->krs_cpu_state = KAIF_CPU_STATE_SLAVE;




   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  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  * Copyright 2018 Joyent, Inc.
  25  */
  26 


  27 /*
  28  * The main CPU-control loops, used to control masters and slaves.
  29  */
  30 
  31 #include <sys/types.h>
  32 
  33 #include <kmdb/kaif.h>
  34 #include <kmdb/kaif_start.h>
  35 #include <kmdb/kmdb_asmutil.h>
  36 #include <kmdb/kmdb_dpi_impl.h>
  37 #include <kmdb/kmdb_kdi.h>
  38 
  39 #define KAIF_SLAVE_CMD_SPIN     0
  40 #define KAIF_SLAVE_CMD_SWITCH   1
  41 #define KAIF_SLAVE_CMD_RESUME   2
  42 #define KAIF_SLAVE_CMD_FLUSH    3
  43 #define KAIF_SLAVE_CMD_REBOOT   4
  44 #if defined(__sparc)
  45 #define KAIF_SLAVE_CMD_ACK      5
  46 #endif


 274                 kaif_slave_cmd = KAIF_SLAVE_CMD_SPIN;
 275 
 276                 membar_producer();
 277 
 278                 kmdb_kdi_stop_slaves(cpusave->krs_cpu_id, 1);
 279         } else {
 280                 /* The master was already chosen - go be a slave */
 281                 cpusave->krs_cpu_state = KAIF_CPU_STATE_SLAVE;
 282                 membar_producer();
 283         }
 284 
 285         kaif_lock_exit(&kaif_master_lock);
 286 }
 287 
 288 int
 289 kaif_main_loop(kaif_cpusave_t *cpusave)
 290 {
 291         int cmd;
 292 
 293         if (kaif_master_cpuid == KAIF_MASTER_CPUID_UNSET) {
 294 
 295                 /*
 296                  * Special case: Unload requested before first debugger entry.
 297                  * Don't stop the world, as there's nothing to clean up that
 298                  * can't be handled by the running kernel.
 299                  */
 300                 if (!kmdb_dpi_resume_requested &&
 301                     kmdb_kdi_get_unload_request()) {
 302                         cpusave->krs_cpu_state = KAIF_CPU_STATE_NONE;
 303                         return (KAIF_CPU_CMD_RESUME);
 304                 }
 305 
 306                 /*
 307                  * We're a slave with no master, so just resume.  This can
 308                  * happen if, prior to this, two CPUs both raced through
 309                  * kdi_cmnint() - for example, a breakpoint on a frequently
 310                  * called function.  The loser will be redirected to the slave
 311                  * loop; note that the event itself is lost at this point.
 312                  *
 313                  * The winner will then cross-call that slave, but it won't
 314                  * actually be received until the slave returns to the kernel
 315                  * and enables interrupts.  We'll then come back in via
 316                  * kdi_slave_entry() and hit this path.
 317                  */
 318                 if (cpusave->krs_cpu_state == KAIF_CPU_STATE_SLAVE) {
 319                         cpusave->krs_cpu_state = KAIF_CPU_STATE_NONE;
 320                         return (KAIF_CPU_CMD_RESUME);
 321                 }
 322 
 323                 kaif_select_master(cpusave);
 324 
 325 #ifdef __sparc
 326                 if (kaif_master_cpuid == cpusave->krs_cpu_id) {
 327                         /*
 328                          * Everyone has arrived, so we can disarm the post-PROM
 329                          * entry point.
 330                          */
 331                         *kaif_promexitarmp = 0;
 332                         membar_producer();
 333                 }
 334 #endif
 335         } else if (kaif_master_cpuid == cpusave->krs_cpu_id) {
 336                 cpusave->krs_cpu_state = KAIF_CPU_STATE_MASTER;
 337         } else {
 338                 cpusave->krs_cpu_state = KAIF_CPU_STATE_SLAVE;