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


   3  *
   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 (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright 2018 Joyent, Inc.
  24  */
  25 
  26 /*      Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
  27 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T       */
  28 /*        All Rights Reserved   */
  29 
  30 /*      Copyright (c) 1987, 1988 Microsoft Corporation  */
  31 /*        All Rights Reserved   */
  32 
  33 #include <sys/param.h>
  34 #include <sys/types.h>
  35 #include <sys/sysmacros.h>
  36 #include <sys/systm.h>
  37 #include <sys/signal.h>
  38 #include <sys/errno.h>
  39 #include <sys/fault.h>
  40 #include <sys/syscall.h>
  41 #include <sys/cpuvar.h>
  42 #include <sys/sysi86.h>
  43 #include <sys/psw.h>


  76  * sysi86 System Call
  77  */
  78 
  79 /* ARGSUSED */
  80 int
  81 sysi86(short cmd, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3)
  82 {
  83         struct ssd ssd;
  84         int error = 0;
  85         int c;
  86         proc_t *pp = curproc;
  87 
  88         switch (cmd) {
  89 
  90         /*
  91          * The SI86V86 subsystem call of the SYSI86 system call
  92          * supports only one subcode -- V86SC_IOPL.
  93          */
  94         case SI86V86:
  95                 if (arg1 == V86SC_IOPL) {



  96                         struct regs *rp = lwptoregs(ttolwp(curthread));
  97                         greg_t oldpl = rp->r_ps & PS_IOPL;
  98                         greg_t newpl = arg2 & PS_IOPL;
  99 
 100                         /*
 101                          * Must be privileged to run this system call
 102                          * if giving more io privilege.
 103                          */
 104                         if (newpl > oldpl && (error =
 105                             secpolicy_sys_config(CRED(), B_FALSE)) != 0)
 106                                 return (set_errno(error));
 107 #if defined(__xpv)

 108                         kpreempt_disable();
 109                         installctx(curthread, NULL, xen_disable_user_iopl,
 110                             xen_enable_user_iopl, NULL, NULL,
 111                             xen_disable_user_iopl, NULL);
 112                         xen_enable_user_iopl();
 113                         kpreempt_enable();
 114 #else
 115                         rp->r_ps ^= oldpl ^ newpl;
 116 #endif
 117                 } else
 118                         error = EINVAL;
 119                 break;
 120 
 121         /*
 122          * Set a segment descriptor
 123          */
 124         case SI86DSCR:
 125                 /*
 126                  * There are considerable problems here manipulating
 127                  * resources shared by many running lwps.  Get everyone
 128                  * into a safe state before changing the LDT.
 129                  */
 130                 if (curthread != pp->p_agenttp && !holdlwps(SHOLDFORK1)) {
 131                         error = EINTR;




   3  *
   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 (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright 2021 Joyent, Inc.
  24  */
  25 
  26 /*      Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
  27 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T       */
  28 /*        All Rights Reserved   */
  29 
  30 /*      Copyright (c) 1987, 1988 Microsoft Corporation  */
  31 /*        All Rights Reserved   */
  32 
  33 #include <sys/param.h>
  34 #include <sys/types.h>
  35 #include <sys/sysmacros.h>
  36 #include <sys/systm.h>
  37 #include <sys/signal.h>
  38 #include <sys/errno.h>
  39 #include <sys/fault.h>
  40 #include <sys/syscall.h>
  41 #include <sys/cpuvar.h>
  42 #include <sys/sysi86.h>
  43 #include <sys/psw.h>


  76  * sysi86 System Call
  77  */
  78 
  79 /* ARGSUSED */
  80 int
  81 sysi86(short cmd, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3)
  82 {
  83         struct ssd ssd;
  84         int error = 0;
  85         int c;
  86         proc_t *pp = curproc;
  87 
  88         switch (cmd) {
  89 
  90         /*
  91          * The SI86V86 subsystem call of the SYSI86 system call
  92          * supports only one subcode -- V86SC_IOPL.
  93          */
  94         case SI86V86:
  95                 if (arg1 == V86SC_IOPL) {
  96 #if defined(__xpv)
  97                         struct ctxop *ctx;
  98 #endif
  99                         struct regs *rp = lwptoregs(ttolwp(curthread));
 100                         greg_t oldpl = rp->r_ps & PS_IOPL;
 101                         greg_t newpl = arg2 & PS_IOPL;
 102 
 103                         /*
 104                          * Must be privileged to run this system call
 105                          * if giving more io privilege.
 106                          */
 107                         if (newpl > oldpl && (error =
 108                             secpolicy_sys_config(CRED(), B_FALSE)) != 0)
 109                                 return (set_errno(error));
 110 #if defined(__xpv)
 111                         ctx = installctx_preallocate();
 112                         kpreempt_disable();
 113                         installctx(curthread, NULL, xen_disable_user_iopl,
 114                             xen_enable_user_iopl, NULL, NULL,
 115                             xen_disable_user_iopl, NULL, ctx);
 116                         xen_enable_user_iopl();
 117                         kpreempt_enable();
 118 #else
 119                         rp->r_ps ^= oldpl ^ newpl;
 120 #endif
 121                 } else
 122                         error = EINVAL;
 123                 break;
 124 
 125         /*
 126          * Set a segment descriptor
 127          */
 128         case SI86DSCR:
 129                 /*
 130                  * There are considerable problems here manipulating
 131                  * resources shared by many running lwps.  Get everyone
 132                  * into a safe state before changing the LDT.
 133                  */
 134                 if (curthread != pp->p_agenttp && !holdlwps(SHOLDFORK1)) {
 135                         error = EINTR;