Print this page
OS-8347 Update SmartOS to support illumos 13917

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/brand/lx/os/lx_misc.c
          +++ new/usr/src/uts/common/brand/lx/os/lx_misc.c
↓ open down ↓ 16 lines elided ↑ open up ↑
  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   25  
  26   26  /*
  27      - * Copyright 2019 Joyent, Inc.
       27 + * Copyright 2022 Joyent, Inc.
  28   28   */
  29   29  
  30   30  #include <sys/errno.h>
  31   31  #include <sys/systm.h>
  32   32  #include <sys/archsystm.h>
  33   33  #include <sys/privregs.h>
  34   34  #include <sys/exec.h>
  35   35  #include <sys/lwp.h>
  36   36  #include <sys/sem.h>
  37   37  #include <sys/brand.h>
↓ open down ↓ 12 lines elided ↑ open up ↑
  50   50  #include <lx_syscall.h>
  51   51  #include <sys/proc.h>
  52   52  #include <sys/procfs.h>
  53   53  #include <net/if.h>
  54   54  #include <inet/ip6.h>
  55   55  #include <sys/sunddi.h>
  56   56  #include <sys/dlpi.h>
  57   57  #include <sys/sysmacros.h>
  58   58  
  59   59  /* Linux specific functions and definitions */
  60      -static void lx_save(klwp_t *);
  61      -static void lx_restore(klwp_t *);
       60 +static void lx_save(void *);
       61 +static void lx_restore(void *);
  62   62  
       63 +/* Context op template. */
       64 +static const struct ctxop_template lx_ctxop_template = {
       65 +        .ct_rev         = CTXOP_TPL_REV,
       66 +        .ct_save        = lx_save,
       67 +        .ct_restore     = lx_restore,
       68 +        .ct_exit        = lx_save,
       69 +};
       70 +
  63   71  /*
  64   72   * Set the return code for the forked child, always zero
  65   73   */
  66   74  /*ARGSUSED*/
  67   75  void
  68   76  lx_setrval(klwp_t *lwp, int v1, int v2)
  69   77  {
  70   78          lwptoregs(lwp)->r_r0 = 0;
  71   79  }
  72   80  
↓ open down ↓ 40 lines elided ↑ open up ↑
 113  121          lwpd->br_ntv_gsbase = (uintptr_t)NULL;
 114  122  
 115  123          /*
 116  124           * Clear the native stack flags.  This will be reinitialised by
 117  125           * lx_init() in the new process image.
 118  126           */
 119  127          lwpd->br_stack_mode = LX_STACK_MODE_PREINIT;
 120  128          lwpd->br_ntv_stack = 0;
 121  129          lwpd->br_ntv_stack_current = 0;
 122  130  
 123      -        installctx(lwptot(lwp), lwp, lx_save, lx_restore, NULL, NULL, lx_save,
 124      -            NULL, NULL);
      131 +        ctxop_install(lwptot(lwp), &lx_ctxop_template, lwp);
 125  132  
 126  133          /*
 127  134           * clear out the tls array
 128  135           */
 129  136          bzero(lwpd->br_tls, sizeof (lwpd->br_tls));
 130  137  
 131  138          /*
 132  139           * reset the tls entries in the gdt
 133  140           */
 134  141          kpreempt_disable();
↓ open down ↓ 204 lines elided ↑ open up ↑
 339  346           * here in lx_freelwp.  When the second call is redundant, the
 340  347           * resources will already be freed and no work will be needed.
 341  348           */
 342  349          lx_cleanlwp(lwp, p);
 343  350  
 344  351          /*
 345  352           * Remove our system call interposer.
 346  353           */
 347  354          lwp->lwp_brand_syscall = NULL;
 348  355  
 349      -        (void) removectx(lwptot(lwp), lwp, lx_save, lx_restore, NULL, NULL,
 350      -            lx_save, NULL);
      356 +        /*
      357 +         * If this process is being de-branded during an exec(),
      358 +         * the LX ctxops may have already been removed, so the result
      359 +         * from ctxop_remove is irrelevant.
      360 +         */
      361 +        (void) ctxop_remove(lwptot(lwp), &lx_ctxop_template, lwp);
 351  362          if (lwpd->br_pid != 0) {
 352  363                  lx_pid_rele(lwptoproc(lwp)->p_pid, lwptot(lwp)->t_tid);
 353  364          }
 354  365  
 355  366          /*
 356  367           * Discard the affinity mask.
 357  368           */
 358  369          VERIFY(lwpd->br_affinitymask != NULL);
 359  370          cpuset_free(lwpd->br_affinitymask);
 360  371          lwpd->br_affinitymask = NULL;
↓ open down ↓ 130 lines elided ↑ open up ↑
 491  502          VERIFY(lwpd->br_lpid->lxp_pidp != NULL || p->p_lwpcnt == 0);
 492  503  
 493  504          lx_pid_assign(tp, lwpd->br_lpid);
 494  505          lwpd->br_tgid = lwpd->br_pid;
 495  506          /*
 496  507           * Having performed the lx pid assignement, the lpid reference is no
 497  508           * longer needed.  The underlying data will be freed during lx_freelwp.
 498  509           */
 499  510          lwpd->br_lpid = NULL;
 500  511  
 501      -        installctx(lwptot(lwp), lwp, lx_save, lx_restore, NULL, NULL,
 502      -            lx_save, NULL, NULL);
      512 +        ctxop_install(lwptot(lwp), &lx_ctxop_template, lwp);
 503  513  
 504  514          /*
 505  515           * Install branded system call hooks for this LWP:
 506  516           */
 507  517          lwp->lwp_brand_syscall = lx_syscall_enter;
 508  518  
 509  519          /*
 510  520           * The new LWP inherits the parent LWP cgroup ID.
 511  521           */
 512  522          if (plwpd != NULL) {
↓ open down ↓ 93 lines elided ↑ open up ↑
 606  616                  /* clone group no longer pending on this thread */
 607  617                  src->br_clone_grp_flags = 0;
 608  618          }
 609  619  }
 610  620  
 611  621  /*
 612  622   * When switching a Linux process off the CPU, clear its GDT entries.
 613  623   */
 614  624  /* ARGSUSED */
 615  625  static void
 616      -lx_save(klwp_t *t)
      626 +lx_save(void *arg)
 617  627  {
      628 +        klwp_t *t = (klwp_t *)arg;
 618  629          int i;
 619  630  
 620  631  #if defined(__amd64)
 621  632          reset_sregs();
 622  633  #endif
 623  634          for (i = 0; i < LX_TLSNUM; i++)
 624  635                  gdt_update_usegd(GDT_TLSMIN + i, &null_udesc);
 625  636  }
 626  637  
 627  638  /*
 628  639   * When switching a Linux process on the CPU, set its GDT entries.
 629  640   *
 630  641   * For 64-bit code we don't have to worry about explicitly setting the
 631  642   * %fsbase via wrmsr(MSR_AMD_FSBASE) here. Instead, that should happen
 632  643   * automatically in update_sregs if we are executing in user-land. If this
 633  644   * is the case then pcb_rupdate should be set.
 634  645   */
 635  646  static void
 636      -lx_restore(klwp_t *t)
      647 +lx_restore(void *arg)
 637  648  {
      649 +        klwp_t *t = (klwp_t *)arg;
 638  650          struct lx_lwp_data *lwpd = lwptolxlwp(t);
 639  651          user_desc_t *tls;
 640  652          int i;
 641  653  
 642  654          ASSERT(lwpd);
 643  655  
 644  656          tls = lwpd->br_tls;
 645  657          for (i = 0; i < LX_TLSNUM; i++)
 646  658                  gdt_update_usegd(GDT_TLSMIN + i, &tls[i]);
 647  659  }
↓ open down ↓ 478 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX