From: "Hillf Danton" <hillf.zj@alibaba-inc.com>
To: 'Mike Rapoport' <rppt@linux.vnet.ibm.com>
Cc: linux-mm@kvack.org
Subject: Re: [PATCH 2/7] userfaultfd: shmem: add shmem_mcopy_atomic_pte for userfaultfd support
Date: Thu, 04 Aug 2016 17:37:16 +0800 [thread overview]
Message-ID: <004401d1ee33$c9b748f0$5d25dad0$@alibaba-inc.com> (raw)
In-Reply-To: <004301d1ee32$fc583630$f508a290$@alibaba-inc.com>
>
> +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)
> +{
> + struct inode *inode = file_inode(dst_vma->vm_file);
> + struct shmem_inode_info *info = SHMEM_I(inode);
> + struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);
> + struct address_space *mapping = inode->i_mapping;
> + gfp_t gfp = mapping_gfp_mask(mapping);
> + pgoff_t pgoff = linear_page_index(dst_vma, dst_addr);
> + struct mem_cgroup *memcg;
> + spinlock_t *ptl;
> + void *page_kaddr;
> + struct page *page;
> + pte_t _dst_pte, *dst_pte;
> + int ret;
> +
> + if (!*pagep) {
> + ret = -ENOMEM;
> + if (shmem_acct_block(info->flags))
> + goto out;
> + if (sbinfo->max_blocks) {
> + if (percpu_counter_compare(&sbinfo->used_blocks,
> + sbinfo->max_blocks) >= 0)
> + goto out_unacct_blocks;
> + percpu_counter_inc(&sbinfo->used_blocks);
> + }
> +
> + page = shmem_alloc_page(gfp, info, pgoff);
> + if (!page)
> + goto out_dec_used_blocks;
> +
> + page_kaddr = kmap_atomic(page);
> + ret = copy_from_user(page_kaddr, (const void __user *)src_addr,
> + PAGE_SIZE);
> + kunmap_atomic(page_kaddr);
> +
> + /* fallback to copy_from_user outside mmap_sem */
> + if (unlikely(ret)) {
> + *pagep = page;
> + /* don't free the page */
> + return -EFAULT;
> + }
> + } else {
> + page = *pagep;
> + *pagep = NULL;
> + }
> +
> + _dst_pte = mk_pte(page, dst_vma->vm_page_prot);
> + if (dst_vma->vm_flags & VM_WRITE)
> + _dst_pte = pte_mkwrite(pte_mkdirty(_dst_pte));
> +
> + ret = -EEXIST;
> + dst_pte = pte_offset_map_lock(dst_mm, dst_pmd, dst_addr, &ptl);
> + if (!pte_none(*dst_pte))
> + goto out_release_uncharge_unlock;
> +
> + __SetPageUptodate(page);
> +
> + ret = mem_cgroup_try_charge(page, dst_mm, gfp, &memcg,
> + false);
> + if (ret)
> + goto out_release_uncharge_unlock;
> + ret = radix_tree_maybe_preload(gfp & GFP_RECLAIM_MASK);
You have to load radix tree without &ptl held.
Hillf
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next parent reply other threads:[~2016-08-04 9:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <004301d1ee32$fc583630$f508a290$@alibaba-inc.com>
2016-08-04 9:37 ` Hillf Danton [this message]
2016-08-04 13:18 ` Mike Rapoport
2016-08-04 8:14 [PATCH 0/7] userfaultfd: add support for shared memory Mike Rapoport
2016-08-04 8:14 ` [PATCH 2/7] userfaultfd: shmem: add shmem_mcopy_atomic_pte for userfaultfd support Mike Rapoport
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='004401d1ee33$c9b748f0$5d25dad0$@alibaba-inc.com' \
--to=hillf.zj@alibaba-inc.com \
--cc=linux-mm@kvack.org \
--cc=rppt@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox