Skip to content

False positive in LKMM race detection? #35

@db7

Description

@db7

GenMC 0.7 detects a race in the following code with LKMM. I am unsure whether that is a real race or something else:

#include <lkmm.h>
int spin, lock;

T0( ) {
	spin = 0;
	smp_wmb();
	WRITE_ONCE(lock, 1);
}

T1( ) {
	if (READ_ONCE(lock) != 0) {
		smp_mb();
		spin = 1;
	}
}

GenMC detects a race between both updates of spin (line number wont match, sorry):

$ genmc -lkmm test.c 
WARNING: LKMM support is still at an experimental stage!
Error detected: Non-Atomic race!
Event (1, 3) conflicts with event (0, 2) in graph:
<-1, 0> main:
        (0, 0): B
        (0, 1): TC [forks 1] L.39
        (0, 2): Wna (spin, 0) L.9
        (0, 3): Fwmb L.11
        (0, 4): Wrlx (lock, 1) L.12
        (0, 5): TJ L.41
<0, 1> run1:
        (1, 0): B
        (1, 1): Rrlx (lock, 1) [(0, 4)] L.25
        (1, 2): Fmb L.26
        (1, 3): Wna (spin, 1) L.27

Number of complete executions explored: 0
Number of blocked executions seen: 1
Total wall-clock time: 0.01s

The issue can be fixed if T0 writes to lock with smp_store_release or if we use smp_mb() instead of smp_wmb(), but I thought the smp_wmb() should guarantee the order of both writes.

Here is a gist with the complete code and a few other variants.

PS: The data race is also detected in GenMC 0.6.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions