X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=ipc%2Fsem.c;h=6115146563f94e5bfab0973be730b3388fb3fc59;hb=b3890e4704594fa23abe1395d1fafc97d3214be8;hp=53c3310f41c6867fd4b5f3f0493a150184b8c617;hpb=865566ed33f08637c3486b4d301e96a9064ad2eb;p=firefly-linux-kernel-4.4.55.git diff --git a/ipc/sem.c b/ipc/sem.c index 53c3310f41c6..6115146563f9 100644 --- a/ipc/sem.c +++ b/ipc/sem.c @@ -326,10 +326,17 @@ static inline int sem_lock(struct sem_array *sma, struct sembuf *sops, /* Then check that the global lock is free */ if (!spin_is_locked(&sma->sem_perm.lock)) { - /* spin_is_locked() is not a memory barrier */ - smp_mb(); + /* + * The ipc object lock check must be visible on all + * cores before rechecking the complex count. Otherwise + * we can race with another thread that does: + * complex_count++; + * spin_unlock(sem_perm.lock); + */ + smp_rmb(); - /* Now repeat the test of complex_count: + /* + * Now repeat the test of complex_count: * It can't change anymore until we drop sem->lock. * Thus: if is now 0, then it will stay 0. */