[Patch] SysV SHM is broken on SMP in 2.3.32

Stephen C. Tweedie (sct@redhat.com)
Tue, 14 Dec 1999 15:11:47 GMT


Hi,

SHM on 2.3.32 SMP has broken locking which causes an immediate BUG() due
to the spinlock debugging.

sys_shmget() calls newseg() to get a new SHM segment and does an
ipc_addid() to install and spinlock the ID.

ipc_addid is where the breakage is. It selects a new ID to use, then
does an ipc_lock() on that ID, and then installs the new ID. However,
ipc_lock() aborts because the new ID is not yet installed, and ipc_addid
silently ignores the error. Oops, we don't have the spinlock that we
think we should. Once newseg() is finished and goes to unlock the
spinlock, the spinlock debugging BUG()s on the fact that the lock is not
held.

The patchlet below moves the installation of the new ID's table entry to
occur before we go for the lock. This _should_ be OK because we will
already hold the overall shm_ids semaphore at this point, and that
should protect us against anybody else getting the ID before we lock it.
I'd like somebody who has played with this code more recently to
double-check, though.

The BUG() if ipc_lock returns NULL cannot be any worse than the current
behaviour (which is to return silently without the spinlock if anything
goes wrong there).

--Stephen

----------------------------------------------------------------
--- ipc/util.c.~1~ Tue Dec 14 15:01:42 1999
+++ ipc/util.c Tue Dec 14 14:39:42 1999
@@ -130,8 +130,9 @@
if(ids->seq > ids->seq_max)
ids->seq = 0;

- ipc_lock(ids,id);
ids->entries[id].p = new;
+ if (!ipc_lock(ids,id))
+ BUG();
return id;
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/