
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I8T2RT -------------------------------- Fix the crash caused by mounting the resctrl filesystem on a platform that does not support any RDT resources. WARNING: CPU: 0 PID: 13291 at mm/page_alloc.c:4780 __alloc_pages Call Trace: __kmalloc_large_node+0x8f/0x190 __kmalloc+0xb8/0x120 closid_init+0x4a/0x90 rdt_get_tree+0x109/0x400 vfs_get_tree+0x25/0xe0 do_new_mount+0x164/0x1c0 __se_sys_mount+0x165/0x1d0 do_syscall_64+0x56/0x100 Fixes: 1e7284b7981c ("fs/resctrl: Remove the limit on the number of CLOSID") Signed-off-by: Zeng Heng <zengheng4@huawei.com> --- fs/resctrl/rdtgroup.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 9eab69ddc688..79334b36798f 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -148,7 +148,7 @@ int closids_supported(void) return closid_free_map_len; } -static void closid_init(void) +static int closid_init(void) { struct resctrl_schema *s; u32 rdt_min_closid = ~0; @@ -157,12 +157,20 @@ static void closid_init(void) list_for_each_entry(s, &resctrl_schema_all, list) rdt_min_closid = min(rdt_min_closid, s->num_closid); + if (rdt_min_closid == ~0) + return -EOPNOTSUPP; + closid_free_map = bitmap_alloc(rdt_min_closid, GFP_KERNEL); + if (!closid_free_map) + return -ENOMEM; + bitmap_fill(closid_free_map, rdt_min_closid); /* RESCTRL_RESERVED_CLOSID is always reserved for the default group */ __clear_bit(RESCTRL_RESERVED_CLOSID, closid_free_map); closid_free_map_len = rdt_min_closid; + + return 0; } static void closid_exit(void) @@ -2769,7 +2777,9 @@ static int rdt_get_tree(struct fs_context *fc) if (ret) goto out_schemata_free; - closid_init(); + ret = closid_init(); + if (ret) + goto out_schemata_free; if (resctrl_arch_mon_capable()) flags |= RFTYPE_MON; -- 2.25.1