* [PATCH v2 1/2] UBI: Fastmap: free unused fastmap anchor peb during detach
@ 2020-02-10 13:26 Hou Tao
2020-02-10 13:26 ` [PATCH v2 2/2] UBI: fastmap: only produce the initial anchor PEB when fastmap is used Hou Tao
2020-03-30 21:33 ` [PATCH v2 1/2] UBI: Fastmap: free unused fastmap anchor peb during detach Richard Weinberger
0 siblings, 2 replies; 3+ messages in thread
From: Hou Tao @ 2020-02-10 13:26 UTC (permalink / raw)
To: linux-mtd, richard, s.hauer; +Cc: houtao1, vigneshr, miquel.raynal
When CONFIG_MTD_UBI_FASTMAP is enabled, fm_anchor will be assigned
a free PEB during ubi_wl_init() or ubi_update_fastmap(). However
if fastmap is not used or disabled on the MTD device, ubi_wl_entry
related with the PEB will not be freed during detach.
So Fix it by freeing the unused fastmap anchor during detach.
Fixes: f9c34bb52997 ("ubi: Fix producing anchor PEBs")
Reported-by: syzbot+f317896aae32eb281a58@syzkaller.appspotmail.com
Reviewed-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Hou Tao <houtao1@huawei.com>
---
drivers/mtd/ubi/fastmap-wl.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
---
v2: patch splitting as suggested by Sascha
diff --git a/drivers/mtd/ubi/fastmap-wl.c b/drivers/mtd/ubi/fastmap-wl.c
index 426820ab9afe..b486250923c5 100644
--- a/drivers/mtd/ubi/fastmap-wl.c
+++ b/drivers/mtd/ubi/fastmap-wl.c
@@ -39,6 +39,13 @@ static struct ubi_wl_entry *find_anchor_wl_entry(struct rb_root *root)
return victim;
}
+static inline void return_unused_peb(struct ubi_device *ubi,
+ struct ubi_wl_entry *e)
+{
+ wl_tree_add(e, &ubi->free);
+ ubi->free_count++;
+}
+
/**
* return_unused_pool_pebs - returns unused PEB to the free tree.
* @ubi: UBI device description object
@@ -52,8 +59,7 @@ static void return_unused_pool_pebs(struct ubi_device *ubi,
for (i = pool->used; i < pool->size; i++) {
e = ubi->lookuptbl[pool->pebs[i]];
- wl_tree_add(e, &ubi->free);
- ubi->free_count++;
+ return_unused_peb(ubi, e);
}
}
@@ -361,6 +367,11 @@ static void ubi_fastmap_close(struct ubi_device *ubi)
return_unused_pool_pebs(ubi, &ubi->fm_pool);
return_unused_pool_pebs(ubi, &ubi->fm_wl_pool);
+ if (ubi->fm_anchor) {
+ return_unused_peb(ubi, ubi->fm_anchor);
+ ubi->fm_anchor = NULL;
+ }
+
if (ubi->fm) {
for (i = 0; i < ubi->fm->used_blocks; i++)
kfree(ubi->fm->e[i]);
--
2.22.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v2 2/2] UBI: fastmap: only produce the initial anchor PEB when fastmap is used
2020-02-10 13:26 [PATCH v2 1/2] UBI: Fastmap: free unused fastmap anchor peb during detach Hou Tao
@ 2020-02-10 13:26 ` Hou Tao
2020-03-30 21:33 ` [PATCH v2 1/2] UBI: Fastmap: free unused fastmap anchor peb during detach Richard Weinberger
1 sibling, 0 replies; 3+ messages in thread
From: Hou Tao @ 2020-02-10 13:26 UTC (permalink / raw)
To: linux-mtd, richard, s.hauer; +Cc: houtao1, vigneshr, miquel.raynal
Don't produce the initial anchor PEB when ubi device is read-only
or fastmap is disabled, else the resulting PEB will be unusable
to any volume.
Signed-off-by: Hou Tao <houtao1@huawei.com>
---
drivers/mtd/ubi/wl.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index af2fe77eb66f..87ff4e51cb8c 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -1879,7 +1879,8 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
goto out_free;
#ifdef CONFIG_MTD_UBI_FASTMAP
- ubi_ensure_anchor_pebs(ubi);
+ if (!ubi->ro_mode && !ubi->fm_disabled)
+ ubi_ensure_anchor_pebs(ubi);
#endif
return 0;
--
2.22.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2 1/2] UBI: Fastmap: free unused fastmap anchor peb during detach
2020-02-10 13:26 [PATCH v2 1/2] UBI: Fastmap: free unused fastmap anchor peb during detach Hou Tao
2020-02-10 13:26 ` [PATCH v2 2/2] UBI: fastmap: only produce the initial anchor PEB when fastmap is used Hou Tao
@ 2020-03-30 21:33 ` Richard Weinberger
1 sibling, 0 replies; 3+ messages in thread
From: Richard Weinberger @ 2020-03-30 21:33 UTC (permalink / raw)
To: Hou Tao
Cc: Richard Weinberger, Sascha Hauer, linux-mtd, Vignesh Raghavendra,
Miquel Raynal
On Mon, Feb 10, 2020 at 2:20 PM Hou Tao <houtao1@huawei.com> wrote:
>
> When CONFIG_MTD_UBI_FASTMAP is enabled, fm_anchor will be assigned
> a free PEB during ubi_wl_init() or ubi_update_fastmap(). However
> if fastmap is not used or disabled on the MTD device, ubi_wl_entry
> related with the PEB will not be freed during detach.
>
> So Fix it by freeing the unused fastmap anchor during detach.
>
> Fixes: f9c34bb52997 ("ubi: Fix producing anchor PEBs")
> Reported-by: syzbot+f317896aae32eb281a58@syzkaller.appspotmail.com
> Reviewed-by: Sascha Hauer <s.hauer@pengutronix.de>
> Signed-off-by: Hou Tao <houtao1@huawei.com>
> ---
> drivers/mtd/ubi/fastmap-wl.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
> ---
> v2: patch splitting as suggested by Sascha
Both applied, thanks a lot!
--
Thanks,
//richard
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-03-30 21:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-10 13:26 [PATCH v2 1/2] UBI: Fastmap: free unused fastmap anchor peb during detach Hou Tao
2020-02-10 13:26 ` [PATCH v2 2/2] UBI: fastmap: only produce the initial anchor PEB when fastmap is used Hou Tao
2020-03-30 21:33 ` [PATCH v2 1/2] UBI: Fastmap: free unused fastmap anchor peb during detach Richard Weinberger
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).