linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] [md/bitmap] md_bitmap_read_sb uses wrong bitmap blocks
@ 2020-10-05 16:00 Zhao Heming
  2020-10-05 16:00 ` [PATCH v2 2/2] [md/bitmap] md_bitmap_get_counter returns wrong blocks Zhao Heming
  2020-10-08  6:35 ` [PATCH v2 1/2] [md/bitmap] md_bitmap_read_sb uses wrong bitmap blocks Song Liu
  0 siblings, 2 replies; 3+ messages in thread
From: Zhao Heming @ 2020-10-05 16:00 UTC (permalink / raw)
  To: linux-raid, song; +Cc: Zhao Heming, guoqing.jiang

The patched code is used to get chunks number, should use
round-up div to replace current sector_div.
The same code is in md_bitmap_resize():
```
chunks = DIV_ROUND_UP_SECTOR_T(blocks, 1 << chunkshift);
```

Signed-off-by: Zhao Heming <heming.zhao@suse.com>
---
v2:
- change grammar mistake in patch Subject
- fix code syntax error 

---
 drivers/md/md-bitmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index b10c51988c8e..553b6406ba1c 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -605,8 +605,8 @@ static int md_bitmap_read_sb(struct bitmap *bitmap)
 	if (bitmap->cluster_slot >= 0) {
 		sector_t bm_blocks = bitmap->mddev->resync_max_sectors;
 
-		sector_div(bm_blocks,
-			   bitmap->mddev->bitmap_info.chunksize >> 9);
+		bm_blocks = DIV_ROUND_UP_SECTOR_T(bm_blocks,
+			   (bitmap->mddev->bitmap_info.chunksize >> 9));
 		/* bits to bytes */
 		bm_blocks = ((bm_blocks+7) >> 3) + sizeof(bitmap_super_t);
 		/* to 4k blocks */
-- 
2.27.0


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

* [PATCH v2 2/2] [md/bitmap] md_bitmap_get_counter returns wrong blocks
  2020-10-05 16:00 [PATCH v2 1/2] [md/bitmap] md_bitmap_read_sb uses wrong bitmap blocks Zhao Heming
@ 2020-10-05 16:00 ` Zhao Heming
  2020-10-08  6:35 ` [PATCH v2 1/2] [md/bitmap] md_bitmap_read_sb uses wrong bitmap blocks Song Liu
  1 sibling, 0 replies; 3+ messages in thread
From: Zhao Heming @ 2020-10-05 16:00 UTC (permalink / raw)
  To: linux-raid, song; +Cc: Zhao Heming, guoqing.jiang

md_bitmap_get_counter() has code:

```
    if (bitmap->bp[page].hijacked ||
        bitmap->bp[page].map == NULL)
        csize = ((sector_t)1) << (bitmap->chunkshift +
                      PAGE_COUNTER_SHIFT - 1);
```

the minus 1 is wrong, this branch should report 2048 bits of space.
with "-1" action, this only report 1024 bit of space.

this bug code returns wrong blocks, but it doesn't inflence bitmap logic:
1. most callers focus this function return value (the counter of offset),
   not the parameter blocks.
2. the bug is only triggered when hijacked is true or map is NULL.
   the hijacked true condition is very rare.
   the "map == null" only true when array is creating or resizing.
3. even the caller gets wrong blocks, current code makes caller just to
   call md_bitmap_get_counter() one more time.

Signed-off-by: Zhao Heming <heming.zhao@suse.com>
---
v2:
- shorten patch Subject

---
 drivers/md/md-bitmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 553b6406ba1c..11c75e727b49 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1367,7 +1367,7 @@ __acquires(bitmap->lock)
 	if (bitmap->bp[page].hijacked ||
 	    bitmap->bp[page].map == NULL)
 		csize = ((sector_t)1) << (bitmap->chunkshift +
-					  PAGE_COUNTER_SHIFT - 1);
+					  PAGE_COUNTER_SHIFT);
 	else
 		csize = ((sector_t)1) << bitmap->chunkshift;
 	*blocks = csize - (offset & (csize - 1));
-- 
2.27.0


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

* Re: [PATCH v2 1/2] [md/bitmap] md_bitmap_read_sb uses wrong bitmap blocks
  2020-10-05 16:00 [PATCH v2 1/2] [md/bitmap] md_bitmap_read_sb uses wrong bitmap blocks Zhao Heming
  2020-10-05 16:00 ` [PATCH v2 2/2] [md/bitmap] md_bitmap_get_counter returns wrong blocks Zhao Heming
@ 2020-10-08  6:35 ` Song Liu
  1 sibling, 0 replies; 3+ messages in thread
From: Song Liu @ 2020-10-08  6:35 UTC (permalink / raw)
  To: Zhao Heming; +Cc: linux-raid, Guoqing Jiang

On Mon, Oct 5, 2020 at 9:02 AM Zhao Heming <heming.zhao@suse.com> wrote:
>
> The patched code is used to get chunks number, should use
> round-up div to replace current sector_div.
> The same code is in md_bitmap_resize():
> ```
> chunks = DIV_ROUND_UP_SECTOR_T(blocks, 1 << chunkshift);
> ```
>
> Signed-off-by: Zhao Heming <heming.zhao@suse.com>

Applied both patches to md-next.

Thanks,
Song

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

end of thread, other threads:[~2020-10-08  6:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-05 16:00 [PATCH v2 1/2] [md/bitmap] md_bitmap_read_sb uses wrong bitmap blocks Zhao Heming
2020-10-05 16:00 ` [PATCH v2 2/2] [md/bitmap] md_bitmap_get_counter returns wrong blocks Zhao Heming
2020-10-08  6:35 ` [PATCH v2 1/2] [md/bitmap] md_bitmap_read_sb uses wrong bitmap blocks Song Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).