@@ -702,10 +702,29 @@ static void ssb_select_mitigation(void)
702
702
#undef pr_fmt
703
703
#define pr_fmt (fmt ) "Speculation prctl: " fmt
704
704
705
- static int ssb_prctl_set (struct task_struct * task , unsigned long ctrl )
705
+ static void task_update_spec_tif (struct task_struct * tsk , int tifbit , bool on )
706
706
{
707
707
bool update ;
708
708
709
+ if (on )
710
+ update = !test_and_set_tsk_thread_flag (tsk , tifbit );
711
+ else
712
+ update = test_and_clear_tsk_thread_flag (tsk , tifbit );
713
+
714
+ /*
715
+ * Immediately update the speculation control MSRs for the current
716
+ * task, but for a non-current task delay setting the CPU
717
+ * mitigation until it is scheduled next.
718
+ *
719
+ * This can only happen for SECCOMP mitigation. For PRCTL it's
720
+ * always the current task.
721
+ */
722
+ if (tsk == current && update )
723
+ speculation_ctrl_update_current ();
724
+ }
725
+
726
+ static int ssb_prctl_set (struct task_struct * task , unsigned long ctrl )
727
+ {
709
728
if (ssb_mode != SPEC_STORE_BYPASS_PRCTL &&
710
729
ssb_mode != SPEC_STORE_BYPASS_SECCOMP )
711
730
return - ENXIO ;
@@ -716,28 +735,20 @@ static int ssb_prctl_set(struct task_struct *task, unsigned long ctrl)
716
735
if (task_spec_ssb_force_disable (task ))
717
736
return - EPERM ;
718
737
task_clear_spec_ssb_disable (task );
719
- update = test_and_clear_tsk_thread_flag (task , TIF_SSBD );
738
+ task_update_spec_tif (task , TIF_SSBD , false );
720
739
break ;
721
740
case PR_SPEC_DISABLE :
722
741
task_set_spec_ssb_disable (task );
723
- update = ! test_and_set_tsk_thread_flag (task , TIF_SSBD );
742
+ task_update_spec_tif (task , TIF_SSBD , true );
724
743
break ;
725
744
case PR_SPEC_FORCE_DISABLE :
726
745
task_set_spec_ssb_disable (task );
727
746
task_set_spec_ssb_force_disable (task );
728
- update = ! test_and_set_tsk_thread_flag (task , TIF_SSBD );
747
+ task_update_spec_tif (task , TIF_SSBD , true );
729
748
break ;
730
749
default :
731
750
return - ERANGE ;
732
751
}
733
-
734
- /*
735
- * If being set on non-current task, delay setting the CPU
736
- * mitigation until it is next scheduled.
737
- */
738
- if (task == current && update )
739
- speculation_ctrl_update_current ();
740
-
741
752
return 0 ;
742
753
}
743
754
0 commit comments