From: Jiang Liu <liuj97@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Nitin Gupta <ngupta@vflare.org>, Minchan Kim <minchan@kernel.org>,
Jerome Marchand <jmarchan@redhat.com>
Cc: Jiang Liu <jiang.liu@huawei.com>,
devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: [PATCH v3 02/10] zram: use zram->lock to protect zram_free_page() in swap free notify path
Date: Fri, 7 Jun 2013 00:07:23 +0800 [thread overview]
Message-ID: <1370534851-26056-3-git-send-email-jiang.liu@huawei.com> (raw)
In-Reply-To: <1370534851-26056-1-git-send-email-jiang.liu@huawei.com>
zram_slot_free_notify() is free-running without any protection from
concurrent operations. So there are race conditions between
zram_bvec_read()/zram_bvec_write() and zram_slot_free_notify(),
and possible consequences include:
1) Trigger BUG_ON(!handle) on zram_bvec_write() side.
2) Access to freed pages on zram_bvec_read() side.
3) Break some fields (bad_compress, good_compress, pages_stored)
in zram->stats if the swap layer makes concurrently call to
zram_slot_free_notify().
So enhance zram_slot_free_notify() to acquire writer lock on zram->lock
before calling zram_free_page().
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Cc: stable@vger.kernel.org
---
drivers/staging/zram/zram_drv.c | 2 ++
drivers/staging/zram/zram_drv.h | 5 +++--
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
index ee6b67d..0738f6c 100644
--- a/drivers/staging/zram/zram_drv.c
+++ b/drivers/staging/zram/zram_drv.c
@@ -582,7 +582,9 @@ static void zram_slot_free_notify(struct block_device *bdev,
struct zram *zram;
zram = bdev->bd_disk->private_data;
+ down_write(&zram->lock);
zram_free_page(zram, index);
+ up_write(&zram->lock);
zram_stat64_inc(zram, &zram->stats.notify_free);
}
diff --git a/drivers/staging/zram/zram_drv.h b/drivers/staging/zram/zram_drv.h
index 2d1a3f1..d542eee 100644
--- a/drivers/staging/zram/zram_drv.h
+++ b/drivers/staging/zram/zram_drv.h
@@ -93,8 +93,9 @@ struct zram_meta {
struct zram {
struct zram_meta *meta;
spinlock_t stat64_lock; /* protect 64-bit stats */
- struct rw_semaphore lock; /* protect compression buffers and table
- * against concurrent read and writes */
+ struct rw_semaphore lock; /* protect compression buffers, table,
+ * 32bit stat counters against concurrent
+ * notifications, reads and writes */
struct request_queue *queue;
struct gendisk *disk;
int init_done;
--
1.8.1.2
next prev parent reply other threads:[~2013-06-06 16:11 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-06 16:07 [PATCH v2 00/10] Bugfixes and minor improvements for zram Jiang Liu
2013-06-06 16:07 ` [PATCH v3 01/10] zram: avoid invalid memory access in zram_exit() Jiang Liu
2013-06-07 7:58 ` Minchan Kim
2013-06-07 9:29 ` Jerome Marchand
2013-06-06 16:07 ` Jiang Liu [this message]
2013-06-07 8:05 ` [PATCH v3 02/10] zram: use zram->lock to protect zram_free_page() in swap free notify path Minchan Kim
2013-06-07 9:32 ` Jerome Marchand
2013-06-06 16:07 ` [PATCH v3 03/10] zram: destroy all devices on error recovery path in zram_init() Jiang Liu
2013-06-06 16:07 ` [PATCH v3 04/10] zram: avoid double free in function zram_bvec_write() Jiang Liu
2013-06-07 8:06 ` Minchan Kim
2013-06-06 16:07 ` [PATCH v3 05/10] zram: avoid access beyond the zram device Jiang Liu
2013-06-07 8:09 ` Minchan Kim
2013-06-07 9:40 ` Jerome Marchand
2013-06-07 9:43 ` Jiang Liu
2013-06-06 16:07 ` [PATCH v3 06/10] zram: protect sysfs handler from invalid memory access Jiang Liu
2013-06-07 9:41 ` Jerome Marchand
2013-06-06 16:07 ` [PATCH v3 07/10] zram: simplify and optimize dev_to_zram() Jiang Liu
2013-06-06 16:07 ` [PATCH v3 08/10] zram: kill unused zram_get_num_devices() Jiang Liu
2013-06-06 16:07 ` [PATCH v3 09/10] zram: optimize memory operations with clear_page()/copy_page() Jiang Liu
2013-06-06 16:07 ` [PATCH v3 10/10] zram: use atomic64_xxx() to replace zram_stat64_xxx() Jiang Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1370534851-26056-3-git-send-email-jiang.liu@huawei.com \
--to=liuj97@gmail.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=jiang.liu@huawei.com \
--cc=jmarchan@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=minchan@kernel.org \
--cc=ngupta@vflare.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®