Skip to content

Commit 980205e

Browse files
committed
scftorture: Add smp_call_function_many() memory-ordering checks
This commit adds checks for memory misordering across calls to and returns from smp_call_function_many() 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 b93e21a commit 980205e

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

kernel/scftorture.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,11 @@ static void scf_handler(void *scfc_in)
240240
unsigned long r = torture_random(this_cpu_ptr(&scf_torture_rand));
241241
struct scf_check *scfcp = scfc_in;
242242

243-
if (likely(scfcp) && WARN_ON_ONCE(unlikely(!READ_ONCE(scfcp->scfc_in))))
244-
atomic_inc(&n_mb_in_errs);
243+
if (likely(scfcp)) {
244+
WRITE_ONCE(scfcp->scfc_out, false); // For multiple receivers.
245+
if (WARN_ON_ONCE(unlikely(!READ_ONCE(scfcp->scfc_in))))
246+
atomic_inc(&n_mb_in_errs);
247+
}
245248
this_cpu_inc(scf_invoked_count);
246249
if (longwait <= 0) {
247250
if (!(r & 0xffc0))
@@ -325,11 +328,28 @@ static void scftorture_invoke_one(struct scf_statistics *scfp, struct torture_ra
325328
}
326329
break;
327330
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+
}
328336
if (scfsp->scfs_wait)
329337
scfp->n_many_wait++;
330338
else
331339
scfp->n_many++;
332-
smp_call_function_many(cpu_online_mask, scf_handler, NULL, scfsp->scfs_wait);
340+
if (scfcp) {
341+
scfcp->scfc_cpu = -1;
342+
scfcp->scfc_wait = true;
343+
scfcp->scfc_out = false;
344+
scfcp->scfc_in = true;
345+
}
346+
smp_call_function_many(cpu_online_mask, scf_handler, scfcp, scfsp->scfs_wait);
347+
if (scfcp) {
348+
if (WARN_ON_ONCE(!scfcp->scfc_out))
349+
atomic_inc(&n_mb_out_errs); // Leak rather than trash!
350+
else
351+
kfree(scfcp);
352+
}
333353
break;
334354
case SCF_PRIM_ALL:
335355
if (scfsp->scfs_wait)

0 commit comments

Comments
 (0)