Skip to content

Commit 34e8c48

Browse files
committed
scftorture: Add smp_call_function() memory-ordering checks
This commit adds checks for memory misordering across calls to and returns from smp_call_function() in the case where the caller waits. Misordering results in a splat. Note that in contrast to smp_call_function_single(), this code does not test memory ordering into the handler in the no-wait case because none of the handlers would be able to free the scf_check structure without introducing heavy synchronization to work out which was last. [ paulmck: s/GFP_KERNEL/GFP_ATOMIC/ per kernel test robot feedback. ] Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
1 parent 980205e commit 34e8c48

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

kernel/scftorture.c

+17-8
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,13 @@ static void scftorture_invoke_one(struct scf_statistics *scfp, struct torture_ra
297297
cpus_read_lock();
298298
else
299299
preempt_disable();
300-
switch (scfsp->scfs_prim) {
301-
case SCF_PRIM_SINGLE:
300+
if (scfsp->scfs_prim == SCF_PRIM_SINGLE || scfsp->scfs_wait) {
302301
scfcp = kmalloc(sizeof(*scfcp), GFP_ATOMIC);
303302
if (WARN_ON_ONCE(!scfcp))
304303
atomic_inc(&n_alloc_errs);
304+
}
305+
switch (scfsp->scfs_prim) {
306+
case SCF_PRIM_SINGLE:
305307
cpu = torture_random(trsp) % nr_cpu_ids;
306308
if (scfsp->scfs_wait)
307309
scfp->n_single_wait++;
@@ -328,11 +330,6 @@ static void scftorture_invoke_one(struct scf_statistics *scfp, struct torture_ra
328330
}
329331
break;
330332
case SCF_PRIM_MANY:
331-
if (scfsp->scfs_wait) {
332-
scfcp = kmalloc(sizeof(*scfcp), GFP_ATOMIC);
333-
if (WARN_ON_ONCE(!scfcp))
334-
atomic_inc(&n_alloc_errs);
335-
}
336333
if (scfsp->scfs_wait)
337334
scfp->n_many_wait++;
338335
else
@@ -356,7 +353,19 @@ static void scftorture_invoke_one(struct scf_statistics *scfp, struct torture_ra
356353
scfp->n_all_wait++;
357354
else
358355
scfp->n_all++;
359-
smp_call_function(scf_handler, NULL, scfsp->scfs_wait);
356+
if (scfcp) {
357+
scfcp->scfc_cpu = -1;
358+
scfcp->scfc_wait = true;
359+
scfcp->scfc_out = false;
360+
scfcp->scfc_in = true;
361+
}
362+
smp_call_function(scf_handler, scfcp, scfsp->scfs_wait);
363+
if (scfcp) {
364+
if (WARN_ON_ONCE(!scfcp->scfc_out))
365+
atomic_inc(&n_mb_out_errs); // Leak rather than trash!
366+
else
367+
kfree(scfcp);
368+
}
360369
break;
361370
}
362371
if (use_cpus_read_lock)

0 commit comments

Comments
 (0)