Print this page
1925 stack overflow from mac code

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/io/mac/mac_sched.c
          +++ new/usr/src/uts/common/io/mac/mac_sched.c
↓ open down ↓ 14 lines elided ↑ open up ↑
  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   * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
       25 +/*
       26 + * Copyright 2011 Joyent, Inc.  All rights reserved.
       27 + */
  25   28  
  26   29  #include <sys/types.h>
  27   30  #include <sys/callb.h>
  28   31  #include <sys/sdt.h>
  29   32  #include <sys/strsubr.h>
  30   33  #include <sys/strsun.h>
  31   34  #include <sys/vlan.h>
       35 +#include <sys/stack.h>
       36 +#include <sys/archsystm.h>
  32   37  #include <inet/ipsec_impl.h>
  33   38  #include <inet/ip_impl.h>
  34   39  #include <inet/sadb.h>
  35   40  #include <inet/ipsecesp.h>
  36   41  #include <inet/ipsecah.h>
  37   42  #include <inet/ip6.h>
  38   43  
  39   44  #include <sys/mac_impl.h>
  40   45  #include <sys/mac_client_impl.h>
  41   46  #include <sys/mac_client_priv.h>
↓ open down ↓ 366 lines elided ↑ open up ↑
 408  413          cookie = (mac_tx_cookie_t)srs;                          \
 409  414  }
 410  415  
 411  416  #define MAC_TX_SET_NO_ENQUEUE(srs, mp_chain, ret_mp, cookie) {          \
 412  417          mac_srs->srs_state |= SRS_TX_WAKEUP_CLIENT;                     \
 413  418          cookie = (mac_tx_cookie_t)srs;                                  \
 414  419          *ret_mp = mp_chain;                                             \
 415  420  }
 416  421  
 417  422  /*
      423 + * MAC_RX_SRS_TOODEEP
      424 + *
      425 + * Macro called as part of receive-side processing to determine if handling
      426 + * can occur in situ (in the interrupt thread) or if it should be left to a
      427 + * worker thread.  Note that the constant used to make this determination is
      428 + * not entirely made-up, and is a result of some emprical validation. That
      429 + * said, the constant is left as a static variable to allow it to be
      430 + * dynamically tuned in the field if and as needed.
      431 + */
      432 +static uintptr_t mac_rx_srs_stack_needed = 10240;
      433 +static uint_t mac_rx_srs_stack_toodeep;
      434 +
      435 +#ifndef STACK_GROWTH_DOWN
      436 +#error Downward stack growth assumed.
      437 +#endif
      438 +
      439 +#define MAC_RX_SRS_TOODEEP() (STACK_BIAS + (uintptr_t)getfp() - \
      440 +        (uintptr_t)curthread->t_stkbase < mac_rx_srs_stack_needed && \
      441 +        ++mac_rx_srs_stack_toodeep)
      442 +
      443 +
      444 +/*
 418  445   * Drop the rx packet and advance to the next one in the chain.
 419  446   */
 420  447  static void
 421  448  mac_rx_drop_pkt(mac_soft_ring_set_t *srs, mblk_t *mp)
 422  449  {
 423  450          mac_srs_rx_t    *srs_rx = &srs->srs_rx;
 424  451  
 425  452          ASSERT(mp->b_next == NULL);
 426  453          mutex_enter(&srs->srs_lock);
 427  454          MAC_UPDATE_SRS_COUNT_LOCKED(srs, 1);
↓ open down ↓ 1984 lines elided ↑ open up ↑
2412 2439                  mutex_exit(&mac_bw->mac_bw_lock);
2413 2440                  freemsgchain(mp_chain);
2414 2441                  mutex_exit(&mac_srs->srs_lock);
2415 2442                  return;
2416 2443          }
2417 2444  
2418 2445          MAC_RX_SRS_ENQUEUE_CHAIN(mac_srs, mp_chain, tail, count, sz);
2419 2446  
2420 2447          if (!(mac_srs->srs_state & SRS_PROC)) {
2421 2448                  /*
2422      -                 * If we are coming via loopback or if we are not
2423      -                 * optimizing for latency, we should signal the
2424      -                 * worker thread.
     2449 +                 * If we are coming via loopback, if we are not optimizing for
     2450 +                 * latency, or if our stack is running deep, we should signal
     2451 +                 * the worker thread.
2425 2452                   */
2426      -                if (loopback || !(mac_srs->srs_state & SRS_LATENCY_OPT)) {
     2453 +                if (loopback || !(mac_srs->srs_state & SRS_LATENCY_OPT) ||
     2454 +                    MAC_RX_SRS_TOODEEP()) {
2427 2455                          /*
2428 2456                           * For loopback, We need to let the worker take
2429 2457                           * over as we don't want to continue in the same
2430 2458                           * thread even if we can. This could lead to stack
2431 2459                           * overflows and may also end up using
2432 2460                           * resources (cpu) incorrectly.
2433 2461                           */
2434 2462                          cv_signal(&mac_srs->srs_async);
2435 2463                  } else {
2436 2464                          /*
↓ open down ↓ 1571 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX