Print this page
13902 Fix for 13717 may break 8-disk raidz2
13915 installctx() blocking allocate causes problems
Portions contributed by: Jerry Jelinek <gjelinek@gmail.com>
Change-Id: I934d69946cec42630fc541fa8c7385b862b69ca2

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/disp/thread.c
          +++ new/usr/src/uts/common/disp/thread.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) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
  24      - * Copyright 2019 Joyent, Inc.
       24 + * Copyright 2021 Joyent, Inc.
  25   25   */
  26   26  
  27   27  #include <sys/types.h>
  28   28  #include <sys/param.h>
  29   29  #include <sys/sysmacros.h>
  30   30  #include <sys/signal.h>
  31   31  #include <sys/stack.h>
  32   32  #include <sys/pcb.h>
  33   33  #include <sys/user.h>
  34   34  #include <sys/systm.h>
↓ open down ↓ 988 lines elided ↑ open up ↑
1023 1023           * dropped the thread lock, we are guaranteed that anyone that could
1024 1024           * have seen this thread in a blocking chain can no longer see it.
1025 1025           */
1026 1026          thread_lock(t);
1027 1027          thread_unlock(t);
1028 1028  
1029 1029          mutex_exit(&reaplock);
1030 1030  }
1031 1031  
1032 1032  /*
     1033 + * Provide an allocation function for callers of installctx() that, for
     1034 + * reasons of incomplete context-op initialization, must call installctx()
     1035 + * in a kpreempt_disable() block.  The caller, therefore, must call this
     1036 + * without being in such a block.
     1037 + */
     1038 +struct ctxop *
     1039 +installctx_preallocate(void)
     1040 +{
     1041 +        /*
     1042 +         * NOTE: We could ASSERT/VERIFY that we are not in a place where
     1043 +         * a KM_SLEEP allocation could block indefinitely.
     1044 +         *
     1045 +         * ASSERT(curthread->t_preempt == 0);
     1046 +         */
     1047 +
     1048 +        return (kmem_alloc(sizeof (struct ctxop), KM_SLEEP));
     1049 +}
     1050 +
     1051 +/*
1033 1052   * Install thread context ops for the current thread.
     1053 + * The caller can pass in a preallocated struct ctxop, eliminating the need
     1054 + * for the requirement of entering with kernel preemption still enabled.
1034 1055   */
1035 1056  void
1036 1057  installctx(
1037 1058          kthread_t *t,
1038 1059          void    *arg,
1039 1060          void    (*save)(void *),
1040 1061          void    (*restore)(void *),
1041 1062          void    (*fork)(void *, void *),
1042 1063          void    (*lwp_create)(void *, void *),
1043 1064          void    (*exit)(void *),
1044      -        void    (*free)(void *, int))
     1065 +        void    (*free)(void *, int),
     1066 +        struct ctxop *ctx)
1045 1067  {
1046      -        struct ctxop *ctx;
     1068 +        if (ctx == NULL)
     1069 +                ctx = kmem_alloc(sizeof (struct ctxop), KM_SLEEP);
1047 1070  
1048      -        ctx = kmem_alloc(sizeof (struct ctxop), KM_SLEEP);
1049 1071          ctx->save_op = save;
1050 1072          ctx->restore_op = restore;
1051 1073          ctx->fork_op = fork;
1052 1074          ctx->lwp_create_op = lwp_create;
1053 1075          ctx->exit_op = exit;
1054 1076          ctx->free_op = free;
1055 1077          ctx->arg = arg;
1056 1078          ctx->save_ts = 0;
1057 1079          ctx->restore_ts = 0;
1058 1080  
↓ open down ↓ 1251 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX