@@ -133,6 +133,17 @@ __ro_after_init struct vl_info vl_info[ARM64_VEC_MAX] = {
133
133
#endif
134
134
};
135
135
136
+ static unsigned int vec_vl_inherit_flag (enum vec_type type )
137
+ {
138
+ switch (type ) {
139
+ case ARM64_VEC_SVE :
140
+ return TIF_SVE_VL_INHERIT ;
141
+ default :
142
+ WARN_ON_ONCE (1 );
143
+ return 0 ;
144
+ }
145
+ }
146
+
136
147
struct vl_config {
137
148
int __default_vl ; /* Default VL for tasks */
138
149
};
@@ -239,24 +250,27 @@ static void sve_free(struct task_struct *task)
239
250
__sve_free (task );
240
251
}
241
252
242
- unsigned int task_get_sve_vl (const struct task_struct * task )
253
+ unsigned int task_get_vl (const struct task_struct * task , enum vec_type type )
243
254
{
244
- return task -> thread .sve_vl ;
255
+ return task -> thread .vl [ type ] ;
245
256
}
246
257
247
- void task_set_sve_vl (struct task_struct * task , unsigned long vl )
258
+ void task_set_vl (struct task_struct * task , enum vec_type type ,
259
+ unsigned long vl )
248
260
{
249
- task -> thread .sve_vl = vl ;
261
+ task -> thread .vl [ type ] = vl ;
250
262
}
251
263
252
- unsigned int task_get_sve_vl_onexec (const struct task_struct * task )
264
+ unsigned int task_get_vl_onexec (const struct task_struct * task ,
265
+ enum vec_type type )
253
266
{
254
- return task -> thread .sve_vl_onexec ;
267
+ return task -> thread .vl_onexec [ type ] ;
255
268
}
256
269
257
- void task_set_sve_vl_onexec (struct task_struct * task , unsigned long vl )
270
+ void task_set_vl_onexec (struct task_struct * task , enum vec_type type ,
271
+ unsigned long vl )
258
272
{
259
- task -> thread .sve_vl_onexec = vl ;
273
+ task -> thread .vl_onexec [ type ] = vl ;
260
274
}
261
275
262
276
/*
@@ -1074,10 +1088,43 @@ void fpsimd_thread_switch(struct task_struct *next)
1074
1088
__put_cpu_fpsimd_context ();
1075
1089
}
1076
1090
1077
- void fpsimd_flush_thread ( void )
1091
+ static void fpsimd_flush_thread_vl ( enum vec_type type )
1078
1092
{
1079
1093
int vl , supported_vl ;
1080
1094
1095
+ /*
1096
+ * Reset the task vector length as required. This is where we
1097
+ * ensure that all user tasks have a valid vector length
1098
+ * configured: no kernel task can become a user task without
1099
+ * an exec and hence a call to this function. By the time the
1100
+ * first call to this function is made, all early hardware
1101
+ * probing is complete, so __sve_default_vl should be valid.
1102
+ * If a bug causes this to go wrong, we make some noise and
1103
+ * try to fudge thread.sve_vl to a safe value here.
1104
+ */
1105
+ vl = task_get_vl_onexec (current , type );
1106
+ if (!vl )
1107
+ vl = get_default_vl (type );
1108
+
1109
+ if (WARN_ON (!sve_vl_valid (vl )))
1110
+ vl = SVE_VL_MIN ;
1111
+
1112
+ supported_vl = find_supported_vector_length (type , vl );
1113
+ if (WARN_ON (supported_vl != vl ))
1114
+ vl = supported_vl ;
1115
+
1116
+ task_set_vl (current , type , vl );
1117
+
1118
+ /*
1119
+ * If the task is not set to inherit, ensure that the vector
1120
+ * length will be reset by a subsequent exec:
1121
+ */
1122
+ if (!test_thread_flag (vec_vl_inherit_flag (type )))
1123
+ task_set_vl_onexec (current , type , 0 );
1124
+ }
1125
+
1126
+ void fpsimd_flush_thread (void )
1127
+ {
1081
1128
if (!system_supports_fpsimd ())
1082
1129
return ;
1083
1130
@@ -1090,37 +1137,7 @@ void fpsimd_flush_thread(void)
1090
1137
if (system_supports_sve ()) {
1091
1138
clear_thread_flag (TIF_SVE );
1092
1139
sve_free (current );
1093
-
1094
- /*
1095
- * Reset the task vector length as required.
1096
- * This is where we ensure that all user tasks have a valid
1097
- * vector length configured: no kernel task can become a user
1098
- * task without an exec and hence a call to this function.
1099
- * By the time the first call to this function is made, all
1100
- * early hardware probing is complete, so __sve_default_vl
1101
- * should be valid.
1102
- * If a bug causes this to go wrong, we make some noise and
1103
- * try to fudge thread.sve_vl to a safe value here.
1104
- */
1105
- vl = task_get_sve_vl_onexec (current );
1106
- if (!vl )
1107
- vl = get_sve_default_vl ();
1108
-
1109
- if (WARN_ON (!sve_vl_valid (vl )))
1110
- vl = SVE_VL_MIN ;
1111
-
1112
- supported_vl = find_supported_vector_length (ARM64_VEC_SVE , vl );
1113
- if (WARN_ON (supported_vl != vl ))
1114
- vl = supported_vl ;
1115
-
1116
- task_set_sve_vl (current , vl );
1117
-
1118
- /*
1119
- * If the task is not set to inherit, ensure that the vector
1120
- * length will be reset by a subsequent exec:
1121
- */
1122
- if (!test_thread_flag (TIF_SVE_VL_INHERIT ))
1123
- task_set_sve_vl_onexec (current , 0 );
1140
+ fpsimd_flush_thread_vl (ARM64_VEC_SVE );
1124
1141
}
1125
1142
1126
1143
put_cpu_fpsimd_context ();
0 commit comments