Commit 8d103963 authored by Mike Rapoport's avatar Mike Rapoport Committed by Linus Torvalds

userfaultfd: shmem: add shmem_mfill_zeropage_pte for userfaultfd support

shmem_mfill_zeropage_pte is the low level routine that implements the
userfaultfd UFFDIO_ZEROPAGE command.  Since for shmem mappings zero
pages are always allocated and accounted, the new method is a slight
extension of the existing shmem_mcopy_atomic_pte.

Link: http://lkml.kernel.org/r/1497939652-16528-4-git-send-email-rppt@linux.vnet.ibm.comSigned-off-by: default avatarMike Rapoport <rppt@linux.vnet.ibm.com>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Hillf Danton <hillf.zj@alibaba-inc.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 0f079694
...@@ -137,9 +137,15 @@ extern int shmem_mcopy_atomic_pte(struct mm_struct *dst_mm, pmd_t *dst_pmd, ...@@ -137,9 +137,15 @@ extern int shmem_mcopy_atomic_pte(struct mm_struct *dst_mm, pmd_t *dst_pmd,
unsigned long dst_addr, unsigned long dst_addr,
unsigned long src_addr, unsigned long src_addr,
struct page **pagep); struct page **pagep);
extern int shmem_mfill_zeropage_pte(struct mm_struct *dst_mm,
pmd_t *dst_pmd,
struct vm_area_struct *dst_vma,
unsigned long dst_addr);
#else #else
#define shmem_mcopy_atomic_pte(dst_mm, dst_pte, dst_vma, dst_addr, \ #define shmem_mcopy_atomic_pte(dst_mm, dst_pte, dst_vma, dst_addr, \
src_addr, pagep) ({ BUG(); 0; }) src_addr, pagep) ({ BUG(); 0; })
#define shmem_mfill_zeropage_pte(dst_mm, dst_pmd, dst_vma, \
dst_addr) ({ BUG(); 0; })
#endif #endif
#endif #endif
...@@ -2207,11 +2207,12 @@ bool shmem_mapping(struct address_space *mapping) ...@@ -2207,11 +2207,12 @@ bool shmem_mapping(struct address_space *mapping)
return mapping->a_ops == &shmem_aops; return mapping->a_ops == &shmem_aops;
} }
int shmem_mcopy_atomic_pte(struct mm_struct *dst_mm, static int shmem_mfill_atomic_pte(struct mm_struct *dst_mm,
pmd_t *dst_pmd, pmd_t *dst_pmd,
struct vm_area_struct *dst_vma, struct vm_area_struct *dst_vma,
unsigned long dst_addr, unsigned long dst_addr,
unsigned long src_addr, unsigned long src_addr,
bool zeropage,
struct page **pagep) struct page **pagep)
{ {
struct inode *inode = file_inode(dst_vma->vm_file); struct inode *inode = file_inode(dst_vma->vm_file);
...@@ -2235,8 +2236,10 @@ int shmem_mcopy_atomic_pte(struct mm_struct *dst_mm, ...@@ -2235,8 +2236,10 @@ int shmem_mcopy_atomic_pte(struct mm_struct *dst_mm,
if (!page) if (!page)
goto out_unacct_blocks; goto out_unacct_blocks;
if (!zeropage) { /* mcopy_atomic */
page_kaddr = kmap_atomic(page); page_kaddr = kmap_atomic(page);
ret = copy_from_user(page_kaddr, (const void __user *)src_addr, ret = copy_from_user(page_kaddr,
(const void __user *)src_addr,
PAGE_SIZE); PAGE_SIZE);
kunmap_atomic(page_kaddr); kunmap_atomic(page_kaddr);
...@@ -2247,6 +2250,9 @@ int shmem_mcopy_atomic_pte(struct mm_struct *dst_mm, ...@@ -2247,6 +2250,9 @@ int shmem_mcopy_atomic_pte(struct mm_struct *dst_mm,
/* don't free the page */ /* don't free the page */
return -EFAULT; return -EFAULT;
} }
} else { /* mfill_zeropage_atomic */
clear_highpage(page);
}
} else { } else {
page = *pagep; page = *pagep;
*pagep = NULL; *pagep = NULL;
...@@ -2311,6 +2317,28 @@ int shmem_mcopy_atomic_pte(struct mm_struct *dst_mm, ...@@ -2311,6 +2317,28 @@ int shmem_mcopy_atomic_pte(struct mm_struct *dst_mm,
goto out; goto out;
} }
int shmem_mcopy_atomic_pte(struct mm_struct *dst_mm,
pmd_t *dst_pmd,
struct vm_area_struct *dst_vma,
unsigned long dst_addr,
unsigned long src_addr,
struct page **pagep)
{
return shmem_mfill_atomic_pte(dst_mm, dst_pmd, dst_vma,
dst_addr, src_addr, false, pagep);
}
int shmem_mfill_zeropage_pte(struct mm_struct *dst_mm,
pmd_t *dst_pmd,
struct vm_area_struct *dst_vma,
unsigned long dst_addr)
{
struct page *page = NULL;
return shmem_mfill_atomic_pte(dst_mm, dst_pmd, dst_vma,
dst_addr, 0, true, &page);
}
#ifdef CONFIG_TMPFS #ifdef CONFIG_TMPFS
static const struct inode_operations shmem_symlink_inode_operations; static const struct inode_operations shmem_symlink_inode_operations;
static const struct inode_operations shmem_short_symlink_operations; static const struct inode_operations shmem_short_symlink_operations;
......
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