Print this page
OS-7125 Need mitigation of L1TF (CVE-2018-3646)
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>


   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) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2017 by Delphix. All rights reserved.
  24  */
  25 
  26 #include <sys/types.h>
  27 #include <sys/systm.h>
  28 #include <sys/cmn_err.h>
  29 #include <sys/cpuvar.h>
  30 #include <sys/thread.h>
  31 #include <sys/disp.h>
  32 #include <sys/kmem.h>
  33 #include <sys/debug.h>
  34 #include <sys/cpupart.h>
  35 #include <sys/pset.h>
  36 #include <sys/var.h>
  37 #include <sys/cyclic.h>
  38 #include <sys/lgrp.h>
  39 #include <sys/pghw.h>
  40 #include <sys/loadavg.h>
  41 #include <sys/class.h>
  42 #include <sys/fss.h>
  43 #include <sys/pool.h>


 553                                  */
 554 
 555                                 if (!LGRP_CPUS_IN_PART(t->t_lpl->lpl_lgrpid,
 556                                     t->t_cpupart)) {
 557                                         lgrp_move_thread(t,
 558                                             lgrp_choose(t, t->t_cpupart), 0);
 559                                 }
 560 
 561                                 /*
 562                                  * make sure lpl points to our own partition
 563                                  */
 564                                 ASSERT(t->t_lpl >= t->t_cpupart->cp_lgrploads &&
 565                                     (t->t_lpl < t->t_cpupart->cp_lgrploads +
 566                                     t->t_cpupart->cp_nlgrploads));
 567 
 568                                 ASSERT(t->t_lpl->lpl_ncpu > 0);
 569 
 570                                 /* Update CPU last ran on if it was this CPU */
 571                                 if (t->t_cpu == cp && t->t_cpupart == oldpp &&
 572                                     t->t_bound_cpu != cp) {
 573                                         t->t_cpu = disp_lowpri_cpu(ncp,
 574                                             t->t_lpl, t->t_pri, NULL);
 575                                 }
 576                                 t = t->t_forw;
 577                         } while (t != p->p_tlist);
 578 
 579                         /*
 580                          * Didn't find any threads in the same lgroup as this
 581                          * CPU with a different lpl, so remove the lgroup from
 582                          * the process lgroup bitmask.
 583                          */
 584 
 585                         if (lgrp_diff_lpl)
 586                                 klgrpset_del(p->p_lgrpset, lgrpid);
 587                 }
 588 
 589                 /*
 590                  * Walk thread list looking for threads that need to be
 591                  * rehomed, since there are some threads that are not in
 592                  * their process's p_tlist.
 593                  */
 594 


 606                          * since there may be an lgroup with more
 607                          * affinity available after moving CPUs
 608                          * around.
 609                          */
 610                         if (!LGRP_CPUS_IN_PART(t->t_lpl->lpl_lgrpid,
 611                             t->t_cpupart) || t->t_lgrp_affinity) {
 612                                 lgrp_move_thread(t,
 613                                     lgrp_choose(t, t->t_cpupart), 1);
 614                         }
 615 
 616                         /* make sure lpl points to our own partition */
 617                         ASSERT((t->t_lpl >= t->t_cpupart->cp_lgrploads) &&
 618                             (t->t_lpl < t->t_cpupart->cp_lgrploads +
 619                             t->t_cpupart->cp_nlgrploads));
 620 
 621                         ASSERT(t->t_lpl->lpl_ncpu > 0);
 622 
 623                         /* Update CPU last ran on if it was this CPU */
 624                         if (t->t_cpu == cp && t->t_cpupart == oldpp &&
 625                             t->t_bound_cpu != cp) {
 626                                 t->t_cpu = disp_lowpri_cpu(ncp, t->t_lpl,
 627                                     t->t_pri, NULL);
 628                         }
 629 
 630                         t = t->t_next;
 631                 } while (t != curthread);
 632 
 633                 /*
 634                  * Clear off the CPU's run queue, and the kp queue if the
 635                  * partition is now empty.
 636                  */
 637                 disp_cpu_inactive(cp);
 638 
 639                 /*
 640                  * Make cp switch to a thread from the new partition.
 641                  */
 642                 cp->cpu_runrun = 1;
 643                 cp->cpu_kprunrun = 1;
 644         }
 645 
 646         cpu_inmotion = NULL;
 647         start_cpus();




   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) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright 2018 Joyent, Inc.
  24  */
  25 
  26 #include <sys/types.h>
  27 #include <sys/systm.h>
  28 #include <sys/cmn_err.h>
  29 #include <sys/cpuvar.h>
  30 #include <sys/thread.h>
  31 #include <sys/disp.h>
  32 #include <sys/kmem.h>
  33 #include <sys/debug.h>
  34 #include <sys/cpupart.h>
  35 #include <sys/pset.h>
  36 #include <sys/var.h>
  37 #include <sys/cyclic.h>
  38 #include <sys/lgrp.h>
  39 #include <sys/pghw.h>
  40 #include <sys/loadavg.h>
  41 #include <sys/class.h>
  42 #include <sys/fss.h>
  43 #include <sys/pool.h>


 553                                  */
 554 
 555                                 if (!LGRP_CPUS_IN_PART(t->t_lpl->lpl_lgrpid,
 556                                     t->t_cpupart)) {
 557                                         lgrp_move_thread(t,
 558                                             lgrp_choose(t, t->t_cpupart), 0);
 559                                 }
 560 
 561                                 /*
 562                                  * make sure lpl points to our own partition
 563                                  */
 564                                 ASSERT(t->t_lpl >= t->t_cpupart->cp_lgrploads &&
 565                                     (t->t_lpl < t->t_cpupart->cp_lgrploads +
 566                                     t->t_cpupart->cp_nlgrploads));
 567 
 568                                 ASSERT(t->t_lpl->lpl_ncpu > 0);
 569 
 570                                 /* Update CPU last ran on if it was this CPU */
 571                                 if (t->t_cpu == cp && t->t_cpupart == oldpp &&
 572                                     t->t_bound_cpu != cp) {
 573                                         t->t_cpu = disp_lowpri_cpu(ncp, t,
 574                                             t->t_pri);
 575                                 }
 576                                 t = t->t_forw;
 577                         } while (t != p->p_tlist);
 578 
 579                         /*
 580                          * Didn't find any threads in the same lgroup as this
 581                          * CPU with a different lpl, so remove the lgroup from
 582                          * the process lgroup bitmask.
 583                          */
 584 
 585                         if (lgrp_diff_lpl)
 586                                 klgrpset_del(p->p_lgrpset, lgrpid);
 587                 }
 588 
 589                 /*
 590                  * Walk thread list looking for threads that need to be
 591                  * rehomed, since there are some threads that are not in
 592                  * their process's p_tlist.
 593                  */
 594 


 606                          * since there may be an lgroup with more
 607                          * affinity available after moving CPUs
 608                          * around.
 609                          */
 610                         if (!LGRP_CPUS_IN_PART(t->t_lpl->lpl_lgrpid,
 611                             t->t_cpupart) || t->t_lgrp_affinity) {
 612                                 lgrp_move_thread(t,
 613                                     lgrp_choose(t, t->t_cpupart), 1);
 614                         }
 615 
 616                         /* make sure lpl points to our own partition */
 617                         ASSERT((t->t_lpl >= t->t_cpupart->cp_lgrploads) &&
 618                             (t->t_lpl < t->t_cpupart->cp_lgrploads +
 619                             t->t_cpupart->cp_nlgrploads));
 620 
 621                         ASSERT(t->t_lpl->lpl_ncpu > 0);
 622 
 623                         /* Update CPU last ran on if it was this CPU */
 624                         if (t->t_cpu == cp && t->t_cpupart == oldpp &&
 625                             t->t_bound_cpu != cp) {
 626                                 t->t_cpu = disp_lowpri_cpu(ncp, t,
 627                                     t->t_pri);
 628                         }
 629 
 630                         t = t->t_next;
 631                 } while (t != curthread);
 632 
 633                 /*
 634                  * Clear off the CPU's run queue, and the kp queue if the
 635                  * partition is now empty.
 636                  */
 637                 disp_cpu_inactive(cp);
 638 
 639                 /*
 640                  * Make cp switch to a thread from the new partition.
 641                  */
 642                 cp->cpu_runrun = 1;
 643                 cp->cpu_kprunrun = 1;
 644         }
 645 
 646         cpu_inmotion = NULL;
 647         start_cpus();