public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND] zram: correct offset usage in zram_bio_discard
@ 2014-04-23  8:41 Weijie Yang
  2014-04-24  2:06 ` Minchan Kim
  0 siblings, 1 reply; 4+ messages in thread
From: Weijie Yang @ 2014-04-23  8:41 UTC (permalink / raw)
  To: 'Andrew Morton'
  Cc: 'Minchan Kim', 'Nitin Gupta', iamjoonsoo.kim,
	'Sergey Senozhatsky', 'Bob Liu', weijie.yang.kh,
	'linux-kernel'

We want to skip the physical block(PAGE_SIZE) which is partially
covered by the discard bio, so we check the remaining size and
subtract it if there is a need to goto the next physical block.

The current offset usage in zram_bio_discard is incorrect, it will
cause its upper filesystem breakdown.
Consider the following scenario:
on some architecture or config, PAGE_SIZE is 64K for example,
filesystem is set up on zram disk without PAGE_SIZE aligned,
a discard bio leads to a offset = 4K and size=72K,
normally, it should not really discard any physical block as it
partially cover two physical blocks.
However, with the current offset usage, it will discard the second
physical block and free its memory, which will cause filesystem breakdown.

This patch corrects the offset usage in zram_bio_discard.

Signed-off-by: Weijie Yang <weijie.yang@samsung.com>
Acked-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
---
 drivers/block/zram/zram_drv.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 9849b52..48eccb3 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -572,10 +572,10 @@ static void zram_bio_discard(struct zram *zram, u32 index,
 	 * skipping this logical block is appropriate here.
 	 */
 	if (offset) {
-		if (n < offset)
+		if (n <= (PAGE_SIZE - offset))
 			return;
 
-		n -= offset;
+		n -= (PAGE_SIZE - offset);
 		index++;
 	}
 
-- 
1.7.10.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-04-25  3:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-23  8:41 [PATCH RESEND] zram: correct offset usage in zram_bio_discard Weijie Yang
2014-04-24  2:06 ` Minchan Kim
2014-04-24  7:31   ` Sergey Senozhatsky
2014-04-25  3:39     ` Weijie Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox