From: Tang Yizhou tangyizhou@huawei.com
ascend inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I4EUVI CVE: NA
-------------------------------------------------
The max num of sp_group in the system is MAX_GROUP_FOR_SYSTEM.
Signed-off-by: Tang Yizhou tangyizhou@huawei.com Reviewed-by: Weilong Chen chenweilong@huawei.com Reviewed-by: Ding Tianhong dingtianhong@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- mm/share_pool.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/mm/share_pool.c b/mm/share_pool.c index 1a01e90e6b102..48f8af0e254cf 100644 --- a/mm/share_pool.c +++ b/mm/share_pool.c @@ -80,6 +80,8 @@ int sysctl_share_pool_map_lock_enable;
static int share_pool_group_mode = SINGLE_GROUP_MODE;
+static int system_group_count; + /* idr of all sp_groups */ static DEFINE_IDR(sp_group_idr); /* rw semaphore for sp_group_idr and mm->sp_group_master */ @@ -380,6 +382,8 @@ static void free_sp_group(struct sp_group *spg) up_write(&sp_group_sem); free_sp_group_id((unsigned int)spg->id); kfree(spg); + system_group_count--; + WARN(system_group_count < 0, "unexpected group count\n"); }
static void sp_group_drop(struct sp_group *spg) @@ -514,6 +518,11 @@ static struct sp_group *find_or_alloc_sp_group(int spg_id) struct user_struct *user = NULL; int hsize_log = MAP_HUGE_2MB >> MAP_HUGE_SHIFT;
+ if (unlikely(system_group_count + 1 == MAX_GROUP_FOR_SYSTEM)) { + pr_err_ratelimited("share pool: reach system max group num\n"); + return ERR_PTR(-ENOSPC); + } + spg = kzalloc(sizeof(*spg), GFP_KERNEL); if (spg == NULL) { pr_err_ratelimited("share pool: alloc spg failed due to lack of memory\n"); @@ -559,6 +568,8 @@ static struct sp_group *find_or_alloc_sp_group(int spg_id) ret = PTR_ERR(spg->file_hugetlb); goto out_fput; } + + system_group_count++; } else { down_read(&spg->rw_lock); if (!spg_valid(spg)) {