@@ -181,13 +181,16 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of,
181181/*
182182 * This is safe against intel_rdt_sched_in() called from __switch_to()
183183 * because __switch_to() is executed with interrupts disabled. A local call
184- * from rdt_update_closid () is proteced against __switch_to() because
184+ * from update_closid () is proteced against __switch_to() because
185185 * preemption is disabled.
186186 */
187- static void rdt_update_cpu_closid (void * closid )
187+ static void update_cpu_closid (void * info )
188188{
189- if (closid )
190- this_cpu_write (cpu_closid , * (int * )closid );
189+ struct rdtgroup * r = info ;
190+
191+ if (r )
192+ this_cpu_write (rdt_cpu_default .closid , r -> closid );
193+
191194 /*
192195 * We cannot unconditionally write the MSR because the current
193196 * executing task might have its own closid selected. Just reuse
@@ -199,28 +202,62 @@ static void rdt_update_cpu_closid(void *closid)
199202/*
200203 * Update the PGR_ASSOC MSR on all cpus in @cpu_mask,
201204 *
202- * Per task closids must have been set up before calling this function.
203- *
204- * The per cpu closids are updated with the smp function call, when @closid
205- * is not NULL. If @closid is NULL then all affected percpu closids must
206- * have been set up before calling this function.
205+ * Per task closids/rmids must have been set up before calling this function.
207206 */
208207static void
209- rdt_update_closid (const struct cpumask * cpu_mask , int * closid )
208+ update_closid (const struct cpumask * cpu_mask , struct rdtgroup * r )
210209{
211210 int cpu = get_cpu ();
212211
213212 if (cpumask_test_cpu (cpu , cpu_mask ))
214- rdt_update_cpu_closid ( closid );
215- smp_call_function_many (cpu_mask , rdt_update_cpu_closid , closid , 1 );
213+ update_cpu_closid ( r );
214+ smp_call_function_many (cpu_mask , update_cpu_closid , r , 1 );
216215 put_cpu ();
217216}
218217
218+ static int cpus_ctrl_write (struct rdtgroup * rdtgrp , cpumask_var_t newmask ,
219+ cpumask_var_t tmpmask )
220+ {
221+ struct rdtgroup * r ;
222+
223+ /* Check whether cpus are dropped from this group */
224+ cpumask_andnot (tmpmask , & rdtgrp -> cpu_mask , newmask );
225+ if (cpumask_weight (tmpmask )) {
226+ /* Can't drop from default group */
227+ if (rdtgrp == & rdtgroup_default )
228+ return - EINVAL ;
229+
230+ /* Give any dropped cpus to rdtgroup_default */
231+ cpumask_or (& rdtgroup_default .cpu_mask ,
232+ & rdtgroup_default .cpu_mask , tmpmask );
233+ update_closid (tmpmask , & rdtgroup_default );
234+ }
235+
236+ /*
237+ * If we added cpus, remove them from previous group that owned them
238+ * and update per-cpu closid
239+ */
240+ cpumask_andnot (tmpmask , newmask , & rdtgrp -> cpu_mask );
241+ if (cpumask_weight (tmpmask )) {
242+ list_for_each_entry (r , & rdt_all_groups , rdtgroup_list ) {
243+ if (r == rdtgrp )
244+ continue ;
245+ cpumask_andnot (& r -> cpu_mask , & r -> cpu_mask , tmpmask );
246+ }
247+ update_closid (tmpmask , rdtgrp );
248+ }
249+
250+ /* Done pushing/pulling - update this group with new mask */
251+ cpumask_copy (& rdtgrp -> cpu_mask , newmask );
252+
253+ return 0 ;
254+ }
255+
219256static ssize_t rdtgroup_cpus_write (struct kernfs_open_file * of ,
220257 char * buf , size_t nbytes , loff_t off )
221258{
222259 cpumask_var_t tmpmask , newmask ;
223- struct rdtgroup * rdtgrp , * r ;
260+ struct rdtgroup * rdtgrp ;
224261 int ret ;
225262
226263 if (!buf )
@@ -254,36 +291,10 @@ static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of,
254291 goto unlock ;
255292 }
256293
257- /* Check whether cpus are dropped from this group */
258- cpumask_andnot (tmpmask , & rdtgrp -> cpu_mask , newmask );
259- if (cpumask_weight (tmpmask )) {
260- /* Can't drop from default group */
261- if (rdtgrp == & rdtgroup_default ) {
262- ret = - EINVAL ;
263- goto unlock ;
264- }
265- /* Give any dropped cpus to rdtgroup_default */
266- cpumask_or (& rdtgroup_default .cpu_mask ,
267- & rdtgroup_default .cpu_mask , tmpmask );
268- rdt_update_closid (tmpmask , & rdtgroup_default .closid );
269- }
270-
271- /*
272- * If we added cpus, remove them from previous group that owned them
273- * and update per-cpu closid
274- */
275- cpumask_andnot (tmpmask , newmask , & rdtgrp -> cpu_mask );
276- if (cpumask_weight (tmpmask )) {
277- list_for_each_entry (r , & rdt_all_groups , rdtgroup_list ) {
278- if (r == rdtgrp )
279- continue ;
280- cpumask_andnot (& r -> cpu_mask , & r -> cpu_mask , tmpmask );
281- }
282- rdt_update_closid (tmpmask , & rdtgrp -> closid );
283- }
284-
285- /* Done pushing/pulling - update this group with new mask */
286- cpumask_copy (& rdtgrp -> cpu_mask , newmask );
294+ if (rdtgrp -> type == RDTCTRL_GROUP )
295+ ret = cpus_ctrl_write (rdtgrp , newmask , tmpmask );
296+ else
297+ ret = - EINVAL ;
287298
288299unlock :
289300 rdtgroup_kn_unlock (of -> kn );
@@ -1102,7 +1113,7 @@ static void rmdir_all_sub(void)
11021113 }
11031114 /* Notify online CPUs to update per cpu storage and PQR_ASSOC MSR */
11041115 get_online_cpus ();
1105- rdt_update_closid (cpu_online_mask , & rdtgroup_default . closid );
1116+ update_closid (cpu_online_mask , & rdtgroup_default );
11061117 put_online_cpus ();
11071118
11081119 kernfs_remove (kn_info );
@@ -1357,13 +1368,13 @@ static int rdtgroup_rmdir(struct kernfs_node *kn)
13571368
13581369 /* Update per cpu closid of the moved CPUs first */
13591370 for_each_cpu (cpu , & rdtgrp -> cpu_mask )
1360- per_cpu (cpu_closid , cpu ) = closid ;
1371+ per_cpu (rdt_cpu_default . closid , cpu ) = closid ;
13611372 /*
13621373 * Update the MSR on moved CPUs and CPUs which have moved
13631374 * task running on them.
13641375 */
13651376 cpumask_or (tmpmask , tmpmask , & rdtgrp -> cpu_mask );
1366- rdt_update_closid (tmpmask , NULL );
1377+ update_closid (tmpmask , NULL );
13671378
13681379 rdtgrp -> flags = RDT_DELETED ;
13691380 closid_free (rdtgrp -> closid );
0 commit comments