未验证 提交 d2e17ab3 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!1115 userswap bugfix

Merge Pull Request from: @ci-robot 
 
PR sync from:  Peng Zhang <zhangpeng362@huawei.com>
 https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/thread/GRJWIT22G2QJFYJL64FIBD6E7V5TTDY5/ 
From: ZhangPeng <zhangpeng362@huawei.com>

Fix Fuzz test BUG_ON and failure to swap out large memory. Two userswap
bugfixes synchronized from hulk5.10.

ZhangPeng (2):
  userswap: fix BUG_ON in userfaultfd_release()
  userswap: fix kmalloc ENOMEM failed for a large memory


-- 
2.25.1
 
 
Link:https://gitee.com/openeuler/kernel/pulls/1115 

Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com> 
Signed-off-by: Jialin Zhang <zhangjialin11@huawei.com> 
......@@ -873,12 +873,12 @@ static int userfaultfd_release(struct inode *inode, struct file *file)
prev = NULL;
for (vma = mm->mmap; vma; vma = vma->vm_next) {
userfault_flags = VM_UFFD_MISSING | VM_UFFD_WP;
#ifdef CONFIG_USERSWAP
uswap_release(&userfault_flags);
#endif
cond_resched();
BUG_ON(!!vma->vm_userfaultfd_ctx.ctx ^
!!(vma->vm_flags & userfault_flags));
#ifdef CONFIG_USERSWAP
uswap_release(&userfault_flags);
#endif
if (vma->vm_userfaultfd_ctx.ctx != ctx) {
prev = vma;
continue;
......
......@@ -86,7 +86,7 @@ static unsigned long pages_can_be_swapped(struct mm_struct *mm,
*ppages = NULL;
pages = kmalloc(sizeof(struct page *) * (len / PAGE_SIZE), GFP_KERNEL);
pages = kvzalloc(sizeof(struct page *) * (len / PAGE_SIZE), GFP_KERNEL);
if (!pages)
return -ENOMEM;
......@@ -153,7 +153,7 @@ static unsigned long pages_can_be_swapped(struct mm_struct *mm,
out_err:
for (i = 0; i < page_num; i++)
put_page(pages[i]);
kfree(pages);
kvfree(pages);
return ret;
}
......@@ -299,10 +299,9 @@ static unsigned long do_user_swap(struct mm_struct *mm,
unsigned long i = 0, j;
int ret;
ptes = kmalloc(sizeof(pte_t) * (len / PAGE_SIZE), GFP_KERNEL);
ptes = kvzalloc(sizeof(pte_t) * (len / PAGE_SIZE), GFP_KERNEL);
if (!ptes)
return -ENOMEM;
memset(ptes, 0, sizeof(pte_t) * (len / PAGE_SIZE));
lru_add_drain();
for (j = 0; j < len; j += PAGE_SIZE) {
page = pages[i];
......@@ -350,12 +349,12 @@ static unsigned long do_user_swap(struct mm_struct *mm,
if (pages_dirty)
new_addr_start = new_addr_start | USWAP_PAGES_DIRTY;
kfree(ptes);
kvfree(ptes);
return new_addr_start;
out_recover:
uswapout_recover(mm, old_addr_start, i, pages, new_addr_start, ptes);
kfree(ptes);
kvfree(ptes);
return ret;
}
......@@ -401,7 +400,7 @@ unsigned long uswap_mremap(unsigned long old_addr, unsigned long old_len,
for (i = 0; i < len / PAGE_SIZE; i++)
if (pages[i])
put_page(pages[i]);
kfree(pages);
kvfree(pages);
return ret;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册