Staging: zram: Replace mutex lock by a R/W semaphore
authorJerome Marchand <jmarchan@redhat.com>
Fri, 10 Jun 2011 13:28:49 +0000 (15:28 +0200)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 5 Jul 2011 17:07:13 +0000 (10:07 -0700)
commitc5bde2388e5b77b39db1b615e2deda2c535f6f60
tree41ac3693f6dc9ea0f789a81b6d0ca3f4c57516a2
parent924bd88d703e53d30f393fac6117f8f1bc79aab6
Staging: zram: Replace mutex lock by a R/W semaphore

Currently, nothing protects zram table from concurrent access.
For instance, ZRAM_UNCOMPRESSED bit can be cleared by zram_free_page()
called from a concurrent write between the time ZRAM_UNCOMPRESSED has
been set and the time it is tested to unmap KM_USER0 in
zram_bvec_write(). This ultimately leads to kernel panic.

Also, a read request can occurs when the page has been freed by a
running write request and before it has been updated, leading to
zero filled block being incorrectly read and "Read before write"
error message.

This patch replace the current mutex by a rw_semaphore. It extends
the protection to zram table (currently, only compression buffers are
protected) and read requests (currently, only write requests are
protected).

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/zram/zram_drv.c
drivers/staging/zram/zram_drv.h