提交 f9234c02 编写于 作者: L Liu Shixin 提交者: Yongqiang Liu

dhugetlb: use mutex lock in update_reserve_pages()

hulk inclusion
category: bugfix
bugzilla: 46904, https://gitee.com/openeuler/kernel/issues/I6KOXL
CVE: NA

--------------------------------

When memory is fragmented, update_reserve_pages() may call migrate_pages()
to collect continuous memory. This function can sleep, so we should use
mutex lock instead of spin lock.

Fixes: 3eb69101b5e6 ("mm: Add two interface for dhugetlb")
Signed-off-by: NLiu Shixin <liushixin2@huawei.com>
Reviewed-by: NNanyong Sun <sunnanyong@huawei.com>
Reviewed-by: Ntong tiangen <tongtiangen@huawei.com>
Reviewed-by: NKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: NYongqiang Liu <liuyongqiang13@huawei.com>
上级 ead53ab7
...@@ -696,7 +696,7 @@ struct small_page_pool { ...@@ -696,7 +696,7 @@ struct small_page_pool {
struct dhugetlb_pool { struct dhugetlb_pool {
int nid; int nid;
spinlock_t lock; spinlock_t lock;
spinlock_t reserved_lock; struct mutex reserved_lock;
atomic_t refcnt; atomic_t refcnt;
struct mem_cgroup *attach_memcg; struct mem_cgroup *attach_memcg;
......
...@@ -3327,7 +3327,7 @@ struct dhugetlb_pool *hpool_alloc(unsigned long nid) ...@@ -3327,7 +3327,7 @@ struct dhugetlb_pool *hpool_alloc(unsigned long nid)
return NULL; return NULL;
spin_lock_init(&hpool->lock); spin_lock_init(&hpool->lock);
spin_lock_init(&hpool->reserved_lock); mutex_init(&hpool->reserved_lock);
hpool->nid = nid; hpool->nid = nid;
atomic_set(&hpool->refcnt, 1); atomic_set(&hpool->refcnt, 1);
INIT_LIST_HEAD(&hpool->dhugetlb_1G_freelists); INIT_LIST_HEAD(&hpool->dhugetlb_1G_freelists);
......
...@@ -4950,9 +4950,9 @@ static int update_reserve_pages(struct kernfs_open_file *of, ...@@ -4950,9 +4950,9 @@ static int update_reserve_pages(struct kernfs_open_file *of,
hpool = get_dhugetlb_pool_from_memcg(memcg); hpool = get_dhugetlb_pool_from_memcg(memcg);
if (!hpool) if (!hpool)
return -EINVAL; return -EINVAL;
spin_lock(&hpool->reserved_lock); mutex_lock(&hpool->reserved_lock);
dhugetlb_reserve_hugepages(hpool, size, gigantic); dhugetlb_reserve_hugepages(hpool, size, gigantic);
spin_unlock(&hpool->reserved_lock); mutex_unlock(&hpool->reserved_lock);
dhugetlb_pool_put(hpool); dhugetlb_pool_put(hpool);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册