Commit 0d508c1f authored by ZhangPeng's avatar ZhangPeng Committed by Andrew Morton

userfaultfd: use kmap_local_page() in copy_huge_page_from_user()

kmap() and kmap_atomic() are being deprecated in favor of
kmap_local_page() which is appropriate for any thread local context.[1]

Let's replace the kmap() and kmap_atomic() with kmap_local_page() in
copy_huge_page_from_user().  When allow_pagefault is false, disable page
faults to prevent potential deadlock.[2]

[1] https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com/
[2] https://lkml.kernel.org/r/20221025220136.2366143-1-ira.weiny@intel.com

Link: https://lkml.kernel.org/r/20230410133932.32288-3-zhangpeng362@huawei.comSigned-off-by: default avatarZhangPeng <zhangpeng362@huawei.com>
Reviewed-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Nanyong Sun <sunnanyong@huawei.com>
Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Cc: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 07e6d409
...@@ -5880,16 +5880,14 @@ long copy_huge_page_from_user(struct page *dst_page, ...@@ -5880,16 +5880,14 @@ long copy_huge_page_from_user(struct page *dst_page,
for (i = 0; i < pages_per_huge_page; i++) { for (i = 0; i < pages_per_huge_page; i++) {
subpage = nth_page(dst_page, i); subpage = nth_page(dst_page, i);
if (allow_pagefault) page_kaddr = kmap_local_page(subpage);
page_kaddr = kmap(subpage); if (!allow_pagefault)
else pagefault_disable();
page_kaddr = kmap_atomic(subpage);
rc = copy_from_user(page_kaddr, rc = copy_from_user(page_kaddr,
usr_src + i * PAGE_SIZE, PAGE_SIZE); usr_src + i * PAGE_SIZE, PAGE_SIZE);
if (allow_pagefault) if (!allow_pagefault)
kunmap(subpage); pagefault_enable();
else kunmap_local(page_kaddr);
kunmap_atomic(page_kaddr);
ret_val -= (PAGE_SIZE - rc); ret_val -= (PAGE_SIZE - rc);
if (rc) if (rc)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment