Skip to content

Commit ee7035d

Browse files
committed
scftorture: Prevent compiler from reducing race probabilities
Detecting smp_call_function() memory misordering requires close timing, so it is necessary to have the checks immediately before and after the call to the smp_call_function*() function under test. This commit therefore inserts barrier() calls to prevent the compiler from optimizing memory-misordering detection down into the zone of extreme improbability. Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
1 parent dbf83b6 commit ee7035d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

kernel/scftorture.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ static void scftorture_invoke_one(struct scf_statistics *scfp, struct torture_ra
322322
scfp->n_single++;
323323
if (scfcp) {
324324
scfcp->scfc_cpu = cpu;
325+
barrier(); // Prevent race-reduction compiler optimizations.
325326
scfcp->scfc_in = true;
326327
}
327328
ret = smp_call_function_single(cpu, scf_handler_1, (void *)scfcp, scfsp->scfs_wait);
@@ -339,17 +340,21 @@ static void scftorture_invoke_one(struct scf_statistics *scfp, struct torture_ra
339340
scfp->n_many_wait++;
340341
else
341342
scfp->n_many++;
342-
if (scfcp)
343+
if (scfcp) {
344+
barrier(); // Prevent race-reduction compiler optimizations.
343345
scfcp->scfc_in = true;
346+
}
344347
smp_call_function_many(cpu_online_mask, scf_handler, scfcp, scfsp->scfs_wait);
345348
break;
346349
case SCF_PRIM_ALL:
347350
if (scfsp->scfs_wait)
348351
scfp->n_all_wait++;
349352
else
350353
scfp->n_all++;
351-
if (scfcp)
354+
if (scfcp) {
355+
barrier(); // Prevent race-reduction compiler optimizations.
352356
scfcp->scfc_in = true;
357+
}
353358
smp_call_function(scf_handler, scfcp, scfsp->scfs_wait);
354359
break;
355360
}
@@ -358,6 +363,7 @@ static void scftorture_invoke_one(struct scf_statistics *scfp, struct torture_ra
358363
atomic_inc(&n_mb_out_errs); // Leak rather than trash!
359364
else
360365
kfree(scfcp);
366+
barrier(); // Prevent race-reduction compiler optimizations.
361367
}
362368
if (use_cpus_read_lock)
363369
cpus_read_unlock();

0 commit comments

Comments
 (0)