Skip to content

Commit bcddf52

Browse files
Zhihao Chengrichardweinberger
authored andcommitted
ubi: fastmap: Fix duplicate slab cache names while attaching
Since commit 4c39529 ("slab: Warn on duplicate cache names when DEBUG_VM=y"), the duplicate slab cache names can be detected and a kernel WARNING is thrown out. In UBI fast attaching process, alloc_ai() could be invoked twice with the same slab cache name 'ubi_aeb_slab_cache', which will trigger following warning messages: kmem_cache of name 'ubi_aeb_slab_cache' already exists WARNING: CPU: 0 PID: 7519 at mm/slab_common.c:107 __kmem_cache_create_args+0x100/0x5f0 Modules linked in: ubi(+) nandsim [last unloaded: nandsim] CPU: 0 UID: 0 PID: 7519 Comm: modprobe Tainted: G 6.12.0-rc2 RIP: 0010:__kmem_cache_create_args+0x100/0x5f0 Call Trace: __kmem_cache_create_args+0x100/0x5f0 alloc_ai+0x295/0x3f0 [ubi] ubi_attach+0x3c3/0xcc0 [ubi] ubi_attach_mtd_dev+0x17cf/0x3fa0 [ubi] ubi_init+0x3fb/0x800 [ubi] do_init_module+0x265/0x7d0 __x64_sys_finit_module+0x7a/0xc0 The problem could be easily reproduced by loading UBI device by fastmap with CONFIG_DEBUG_VM=y. Fix it by using different slab names for alloc_ai() callers. Fixes: d2158f6 ("UBI: Remove alloc_ai() slab name from parameter list") Fixes: fdf10ed ("ubi: Rework Fastmap attach base code") Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent 8214951 commit bcddf52

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/mtd/ubi/attach.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,7 @@ static int scan_all(struct ubi_device *ubi, struct ubi_attach_info *ai,
14471447
return err;
14481448
}
14491449

1450-
static struct ubi_attach_info *alloc_ai(void)
1450+
static struct ubi_attach_info *alloc_ai(const char *slab_name)
14511451
{
14521452
struct ubi_attach_info *ai;
14531453

@@ -1461,7 +1461,7 @@ static struct ubi_attach_info *alloc_ai(void)
14611461
INIT_LIST_HEAD(&ai->alien);
14621462
INIT_LIST_HEAD(&ai->fastmap);
14631463
ai->volumes = RB_ROOT;
1464-
ai->aeb_slab_cache = kmem_cache_create("ubi_aeb_slab_cache",
1464+
ai->aeb_slab_cache = kmem_cache_create(slab_name,
14651465
sizeof(struct ubi_ainf_peb),
14661466
0, 0, NULL);
14671467
if (!ai->aeb_slab_cache) {
@@ -1491,7 +1491,7 @@ static int scan_fast(struct ubi_device *ubi, struct ubi_attach_info **ai)
14911491

14921492
err = -ENOMEM;
14931493

1494-
scan_ai = alloc_ai();
1494+
scan_ai = alloc_ai("ubi_aeb_slab_cache_fastmap");
14951495
if (!scan_ai)
14961496
goto out;
14971497

@@ -1557,7 +1557,7 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
15571557
int err;
15581558
struct ubi_attach_info *ai;
15591559

1560-
ai = alloc_ai();
1560+
ai = alloc_ai("ubi_aeb_slab_cache");
15611561
if (!ai)
15621562
return -ENOMEM;
15631563

@@ -1575,7 +1575,7 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
15751575
if (err > 0 || mtd_is_eccerr(err)) {
15761576
if (err != UBI_NO_FASTMAP) {
15771577
destroy_ai(ai);
1578-
ai = alloc_ai();
1578+
ai = alloc_ai("ubi_aeb_slab_cache");
15791579
if (!ai)
15801580
return -ENOMEM;
15811581

@@ -1614,7 +1614,7 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
16141614
if (ubi->fm && ubi_dbg_chk_fastmap(ubi)) {
16151615
struct ubi_attach_info *scan_ai;
16161616

1617-
scan_ai = alloc_ai();
1617+
scan_ai = alloc_ai("ubi_aeb_slab_cache_dbg_chk_fastmap");
16181618
if (!scan_ai) {
16191619
err = -ENOMEM;
16201620
goto out_wl;

0 commit comments

Comments
 (0)