From patchwork Tue Mar 14 22:12:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Rasmussen X-Patchwork-Id: 13175061 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 806E7C6FD1F for ; Tue, 14 Mar 2023 22:13:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 247AA6B0078; Tue, 14 Mar 2023 18:13:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D0D66B007B; Tue, 14 Mar 2023 18:13:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 098FB6B007D; Tue, 14 Mar 2023 18:13:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id EFCA46B0078 for ; Tue, 14 Mar 2023 18:13:11 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BBC371C5D03 for ; Tue, 14 Mar 2023 22:13:11 +0000 (UTC) X-FDA: 80568905382.24.E6B2B15 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf17.hostedemail.com (Postfix) with ESMTP id ECC9540005 for ; Tue, 14 Mar 2023 22:13:09 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=MI0DIqw5; spf=pass (imf17.hostedemail.com: domain of 3dfEQZA0KCMIi5mtzi0u200mvowwotm.kwutqv25-uus3iks.wzo@flex--axelrasmussen.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3dfEQZA0KCMIi5mtzi0u200mvowwotm.kwutqv25-uus3iks.wzo@flex--axelrasmussen.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678831990; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=tLH8n4YXArkUQffQbzzj3eK/Q2WLoaxfMp0XyWUCAx0=; b=mCtT7sy8VXgZGZmj8ZY1KH0+ums9tjYnTbKFKh84Laq3ElcPMLNba5O6oIOThoUBa6oNZt sqd8QlejleMwOHIapXwYt6qTHmV3BDRrHFMr4QA8kE4RSswjncIYGevdg1BfIXpaJvluYF w0V7FXSzMZ75gHIAemGKpqBRc4zsxZM= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=MI0DIqw5; spf=pass (imf17.hostedemail.com: domain of 3dfEQZA0KCMIi5mtzi0u200mvowwotm.kwutqv25-uus3iks.wzo@flex--axelrasmussen.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3dfEQZA0KCMIi5mtzi0u200mvowwotm.kwutqv25-uus3iks.wzo@flex--axelrasmussen.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678831990; a=rsa-sha256; cv=none; b=LdEURd2teDWSeNFM4JyjF8MkJONIYCUr3Ib8xgYiFdKCyu1XaaCwx/dx6IQV1/+9+nE448 0MU5hKGSw9hiY2utw2Z6VzokZafzLcDh1b1s0Du24xegQi09CmSvePrQ4yz11US5LFvv2d SX9r1cbje/ACZnHfLYL84OyzrOPJcjo= Received: by mail-yb1-f202.google.com with SMTP id w5-20020a253005000000b00aedd4305ff2so18569758ybw.13 for ; Tue, 14 Mar 2023 15:13:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678831989; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=tLH8n4YXArkUQffQbzzj3eK/Q2WLoaxfMp0XyWUCAx0=; b=MI0DIqw5o1kZ1LidUuNaCJMA1DxP0NtutTXWrUU8amV1STMNMqNO2OPPS9//RZuv3A zzB0FueU6Jqwgkt3s73/teOAXyeLiYzeAhcfl72HJAz9vcXG4WiP4Cl6pwvUeooTLu8X qLDXXeOJ5LFaOKHGQ4BrfEnF6FOPwA1/isprSDTO7hbDxWSQ8EueIhnqKeM5j7T/C9Ht w3RMJcxALYuduZmuu/mzmTD0DbkgnvmNEvul75x9RGDTSACOgQ54D+7BARCdmMU8K6oe 7MiOfSGSiV9f+yhGhCKUbtBNj06VNFw1ccDp2m/3PInTQvkDFM7rN0LFb/AlNiFMhgvu 5b9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678831989; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tLH8n4YXArkUQffQbzzj3eK/Q2WLoaxfMp0XyWUCAx0=; b=dkS9gssIgsDffjCDdZtnLoFsPV4Ll4iUqm5IosbL4gEjsa6j5uLmXgQt/v76pkDXhn ZwhkxrssK1CXSvyPmF7v1br2l50xKEm1w3DqdCI/2ZAuBG2fL/2c9QQPxXalz5XgsVTZ 3mZslOvH/Y0+heA7Zw5SOKqREb+LjVRzlnu287oAg+60oCjTkewfvyxj0G1LTc6KQ/ea gX7mj/Yp4W/IkWHUqAih0nRuEH1uQ5CRN0Xbj+Qk9GTQiIPc4zWKcTdeikOTWh9EE/en n+XUUOIdE5mJZ7GFMvoHbsoNhP7iKDWFra1ZlR9SD+8eIUbaqv3ngfBzR6QoL9G9eeBT pZvg== X-Gm-Message-State: AO0yUKXHiy63fSwBsBbQwVff7/9hS2yTUdWvF9O5e7U2Ek2tol18YSpZ x9PY3WQwi1Ykmlli/pJbrm/qc278brALE/CueANC X-Google-Smtp-Source: AK7set8X8Ot/dtqhk3gU8wbWHExODdLNpBgnH2rdmHFOGldWEBXjs/mUM1rQq6qsmvaLIXxgbT15ZCWXxNsrjbSSl02K X-Received: from axel.svl.corp.google.com ([2620:15c:2d4:203:21ce:bab3:17ec:2276]) (user=axelrasmussen job=sendgmr) by 2002:a81:ad66:0:b0:52e:e8b1:d51e with SMTP id l38-20020a81ad66000000b0052ee8b1d51emr11451580ywk.1.1678831989108; Tue, 14 Mar 2023 15:13:09 -0700 (PDT) Date: Tue, 14 Mar 2023 15:12:48 -0700 In-Reply-To: <20230314221250.682452-1-axelrasmussen@google.com> Mime-Version: 1.0 References: <20230314221250.682452-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Message-ID: <20230314221250.682452-3-axelrasmussen@google.com> Subject: [PATCH v5 2/4] mm: userfaultfd: don't pass around both mm and vma From: Axel Rasmussen To: Alexander Viro , Andrew Morton , Hugh Dickins , Jan Kara , "Liam R. Howlett" , Matthew Wilcox , Mike Kravetz , Mike Rapoport , Muchun Song , Nadav Amit , Peter Xu , Shuah Khan Cc: James Houghton , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Axel Rasmussen X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: ECC9540005 X-Stat-Signature: amdzi6uzg7sbo1yro5ewzokpan5s39yi X-HE-Tag: 1678831989-167881 X-HE-Meta: U2FsdGVkX1+8jCc+ALIGuFHsj7k3p8w7k4ldPjnCW8tuvlGnU3VImlkfIgMRzGexO+fQH5Vv/0RcUb26KWFX+vfhJcXIwNybhCfpW5Tqo+O1AyxEo4B6/ht+zRUn/b6BCRVhsz78GksTYHhLperZZYPuP23Oi4GgGBfaNU2FhUZP/vVfH8/ofwVFY9lC5PXAzqgT+YKo0K/bpo0RRzXmFBVQVYciCkavKbZiJHhF8TPBnqyWuL77jDZVpr1h74VzLZZQwXAjoeMfy8bTFFBv4KEK4qLvhljTblSwXJR8p4NQmbozzU3Onq4WAlfbAKFZ9OIHNJYgk9FLXquzcpoukVFuyi3LsEsU8aMENr6RwqB0ZlSN+HDRZxrnfxcgWKctBLWWawGFyIx9R9g+v8SyytO9HQmOKed1ndh8U1s1SwDkm9pGgIvnefzCzTaIZog9w74rH8D7uqh/HLhrImEWzE8/mxYLO+xqdBo6TxiBWQegv+MUjFgghFXC0hbiC465eYldzbEokbmuoXUy0V6vAKcYqH5HfTm8LK2u2O8AWa1u/ihrrD665QGzGV/teDgndko24xoe83Eh9fHck3rHD+D7q/eDgL11vQezKZsyG8gdGQ8U0vVtvNyqduXjVb3XXqJWtou2CufQ4Lismdx+RfvAw0DKTpVubglXEMUBMZhgNusNrXQmutKLWgZ61eHCWK0mWCVru0A4W8t6C/eQl8FJsH2/QG+VduFW31d2c3w9890o5oKcd+UXfGivTMObrL70gT9gdw828cgORDT30PzqgodV8hlLb21WQ4iGk4CEJ4KNVtYcreRdM73oESHOxnsiX+/6e6QoUiLa4h1k/AD/au9k+hIyeP/lDK3I1e1En/YwrpX4eELUqWBFHQ4xSS8zZzCQ6+f2PbZ91q/MTgqdBSakfvsN3o9lLI4h07crSzCxk4j9UwYk8Tg+FjsPW9jUNjengkHkZ7r0A28 jtNjrmtn GaKWcecJ6zYGBu0xTjnymcUxRDTR08RnXb5CxPwh0MP9yazTDpRfisokJEY6JS9ZLm7I9ECLy/MYApUMeorIODcV6K2ANy5r5ePDpvo9zSg3strfCP6LF3+YHL0VND0WkK3+EbfNSjGm26HBLJJk+BV9wnSZ5VUKIsiLwMZaaMAiyg9JBrPYRB+fSo9ADiB3mqfLRzSR+TcNvKO1jLIltgxOD+4pJnLj78swFOZsFEgCBZDuxNHdHDdm/uIm1a5+mwDGuj8or1z3o1AsZBEKRrpI9Rt6b7M1Kom0sJmfvMZt0cCqmFkt/O1F2zoI/L7WHZ+jyTw6Tl5vh9v/sThDGUEjpkbRppIuHbd07E8fDWb4PU8wLHeHC79pdPOniRoNKlevS0k0PHj33Wt80s95Y8obtxzy8WFUVh1DGX1cFNsoM+OZONezFkpuymuNB0LGHWAQtAyYma+Aw5kiij6Pg3XkPtNZxnc0HcWN35nNw4dabtQKcQvqi/Bk6TSJQKRY9WEJHm9gTry6iqyLqqvScO5IPTLIIUvFv5YHIgxjwJ4HEFfyUUnF/GgFTL4Sj52ggs96JukWSo0kPJ80gVSHA2Ca0eRLGm0dEZ19M1qtBMprXlt2F/ze67E7FUBbLcxubfTKB/K9uO6ahXvPu4DyC0PrggmAWvRFOrQJnMuT9Rp3Piei+F5hAJwjPWvSYWILI1QK2bExfKGnwsZQ3ufFY9rtYlGhMWyUrVjWbUj87JX0mPuulzfiwzYFPPzUaHGLErBJgo4HhrTfsW7k= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Quite a few userfaultfd functions took both mm and vma pointers as arguments. Since the mm is trivially accessible via vma->vm_mm, there's no reason to pass both; it just needlessly extends the already long argument list. Get rid of the mm pointer, where possible, to shorten the argument list. Acked-by: Peter Xu Acked-by: Mike Rapoport (IBM) Signed-off-by: Axel Rasmussen --- fs/userfaultfd.c | 2 +- include/linux/hugetlb.h | 5 ++- include/linux/shmem_fs.h | 4 +-- include/linux/userfaultfd_k.h | 4 +-- mm/hugetlb.c | 4 +-- mm/shmem.c | 7 ++-- mm/userfaultfd.c | 61 +++++++++++++++++------------------ 7 files changed, 41 insertions(+), 46 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 365bf00dd8dd..84d5d402214a 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1629,7 +1629,7 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx, /* Reset ptes for the whole vma range if wr-protected */ if (userfaultfd_wp(vma)) - uffd_wp_range(mm, vma, start, vma_end - start, false); + uffd_wp_range(vma, start, vma_end - start, false); new_flags = vma->vm_flags & ~__VM_UFFD_FLAGS; prev = vma_merge(&vmi, mm, prev, start, vma_end, new_flags, diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 8f0467bf1cbd..8b9325f77ac3 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -158,7 +158,7 @@ unsigned long hugetlb_total_pages(void); vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long address, unsigned int flags); #ifdef CONFIG_USERFAULTFD -int hugetlb_mfill_atomic_pte(struct mm_struct *dst_mm, pte_t *dst_pte, +int hugetlb_mfill_atomic_pte(pte_t *dst_pte, struct vm_area_struct *dst_vma, unsigned long dst_addr, unsigned long src_addr, @@ -393,8 +393,7 @@ static inline void hugetlb_free_pgd_range(struct mmu_gather *tlb, } #ifdef CONFIG_USERFAULTFD -static inline int hugetlb_mfill_atomic_pte(struct mm_struct *dst_mm, - pte_t *dst_pte, +static inline int hugetlb_mfill_atomic_pte(pte_t *dst_pte, struct vm_area_struct *dst_vma, unsigned long dst_addr, unsigned long src_addr, diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 103d1000a5a2..b82916c25e61 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -151,14 +151,14 @@ extern void shmem_uncharge(struct inode *inode, long pages); #ifdef CONFIG_USERFAULTFD #ifdef CONFIG_SHMEM -extern int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, pmd_t *dst_pmd, +extern int shmem_mfill_atomic_pte(pmd_t *dst_pmd, struct vm_area_struct *dst_vma, unsigned long dst_addr, unsigned long src_addr, bool zeropage, bool wp_copy, struct page **pagep); #else /* !CONFIG_SHMEM */ -#define shmem_mfill_atomic_pte(dst_mm, dst_pmd, dst_vma, dst_addr, \ +#define shmem_mfill_atomic_pte(dst_pmd, dst_vma, dst_addr, \ src_addr, zeropage, wp_copy, pagep) ({ BUG(); 0; }) #endif /* CONFIG_SHMEM */ #endif /* CONFIG_USERFAULTFD */ diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h index 468080125612..ba79e296fcc7 100644 --- a/include/linux/userfaultfd_k.h +++ b/include/linux/userfaultfd_k.h @@ -56,7 +56,7 @@ enum mcopy_atomic_mode { MCOPY_ATOMIC_CONTINUE, }; -extern int mfill_atomic_install_pte(struct mm_struct *dst_mm, pmd_t *dst_pmd, +extern int mfill_atomic_install_pte(pmd_t *dst_pmd, struct vm_area_struct *dst_vma, unsigned long dst_addr, struct page *page, bool newly_allocated, bool wp_copy); @@ -73,7 +73,7 @@ extern ssize_t mfill_atomic_continue(struct mm_struct *dst_mm, unsigned long dst extern int mwriteprotect_range(struct mm_struct *dst_mm, unsigned long start, unsigned long len, bool enable_wp, atomic_t *mmap_changing); -extern long uffd_wp_range(struct mm_struct *dst_mm, struct vm_area_struct *vma, +extern long uffd_wp_range(struct vm_area_struct *vma, unsigned long start, unsigned long len, bool enable_wp); /* mm helpers */ diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 4c9276549394..fe043034ab46 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6157,8 +6157,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, * Used by userfaultfd UFFDIO_* ioctls. Based on userfaultfd's mfill_atomic_pte * with modifications for hugetlb pages. */ -int hugetlb_mfill_atomic_pte(struct mm_struct *dst_mm, - pte_t *dst_pte, +int hugetlb_mfill_atomic_pte(pte_t *dst_pte, struct vm_area_struct *dst_vma, unsigned long dst_addr, unsigned long src_addr, @@ -6166,6 +6165,7 @@ int hugetlb_mfill_atomic_pte(struct mm_struct *dst_mm, struct page **pagep, bool wp_copy) { + struct mm_struct *dst_mm = dst_vma->vm_mm; bool is_continue = (mode == MCOPY_ATOMIC_CONTINUE); struct hstate *h = hstate_vma(dst_vma); struct address_space *mapping = dst_vma->vm_file->f_mapping; diff --git a/mm/shmem.c b/mm/shmem.c index 448f393d8ab2..1d751b6cf1ac 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2415,8 +2415,7 @@ static struct inode *shmem_get_inode(struct mnt_idmap *idmap, struct super_block } #ifdef CONFIG_USERFAULTFD -int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, - pmd_t *dst_pmd, +int shmem_mfill_atomic_pte(pmd_t *dst_pmd, struct vm_area_struct *dst_vma, unsigned long dst_addr, unsigned long src_addr, @@ -2506,11 +2505,11 @@ int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, goto out_release; ret = shmem_add_to_page_cache(folio, mapping, pgoff, NULL, - gfp & GFP_RECLAIM_MASK, dst_mm); + gfp & GFP_RECLAIM_MASK, dst_vma->vm_mm); if (ret) goto out_release; - ret = mfill_atomic_install_pte(dst_mm, dst_pmd, dst_vma, dst_addr, + ret = mfill_atomic_install_pte(dst_pmd, dst_vma, dst_addr, &folio->page, true, wp_copy); if (ret) goto out_delete_from_cache; diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 84db5b2fad3a..4fc373476739 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -55,12 +55,13 @@ struct vm_area_struct *find_dst_vma(struct mm_struct *dst_mm, * This function handles both MCOPY_ATOMIC_NORMAL and _CONTINUE for both shmem * and anon, and for both shared and private VMAs. */ -int mfill_atomic_install_pte(struct mm_struct *dst_mm, pmd_t *dst_pmd, +int mfill_atomic_install_pte(pmd_t *dst_pmd, struct vm_area_struct *dst_vma, unsigned long dst_addr, struct page *page, bool newly_allocated, bool wp_copy) { int ret; + struct mm_struct *dst_mm = dst_vma->vm_mm; pte_t _dst_pte, *dst_pte; bool writable = dst_vma->vm_flags & VM_WRITE; bool vm_shared = dst_vma->vm_flags & VM_SHARED; @@ -127,8 +128,7 @@ int mfill_atomic_install_pte(struct mm_struct *dst_mm, pmd_t *dst_pmd, return ret; } -static int mfill_atomic_pte_copy(struct mm_struct *dst_mm, - pmd_t *dst_pmd, +static int mfill_atomic_pte_copy(pmd_t *dst_pmd, struct vm_area_struct *dst_vma, unsigned long dst_addr, unsigned long src_addr, @@ -190,10 +190,10 @@ static int mfill_atomic_pte_copy(struct mm_struct *dst_mm, __SetPageUptodate(page); ret = -ENOMEM; - if (mem_cgroup_charge(page_folio(page), dst_mm, GFP_KERNEL)) + if (mem_cgroup_charge(page_folio(page), dst_vma->vm_mm, GFP_KERNEL)) goto out_release; - ret = mfill_atomic_install_pte(dst_mm, dst_pmd, dst_vma, dst_addr, + ret = mfill_atomic_install_pte(dst_pmd, dst_vma, dst_addr, page, true, wp_copy); if (ret) goto out_release; @@ -204,8 +204,7 @@ static int mfill_atomic_pte_copy(struct mm_struct *dst_mm, goto out; } -static int mfill_atomic_pte_zeropage(struct mm_struct *dst_mm, - pmd_t *dst_pmd, +static int mfill_atomic_pte_zeropage(pmd_t *dst_pmd, struct vm_area_struct *dst_vma, unsigned long dst_addr) { @@ -217,7 +216,7 @@ static int mfill_atomic_pte_zeropage(struct mm_struct *dst_mm, _dst_pte = pte_mkspecial(pfn_pte(my_zero_pfn(dst_addr), dst_vma->vm_page_prot)); - dst_pte = pte_offset_map_lock(dst_mm, dst_pmd, dst_addr, &ptl); + dst_pte = pte_offset_map_lock(dst_vma->vm_mm, dst_pmd, dst_addr, &ptl); if (dst_vma->vm_file) { /* the shmem MAP_PRIVATE case requires checking the i_size */ inode = dst_vma->vm_file->f_inode; @@ -230,7 +229,7 @@ static int mfill_atomic_pte_zeropage(struct mm_struct *dst_mm, ret = -EEXIST; if (!pte_none(*dst_pte)) goto out_unlock; - set_pte_at(dst_mm, dst_addr, dst_pte, _dst_pte); + set_pte_at(dst_vma->vm_mm, dst_addr, dst_pte, _dst_pte); /* No need to invalidate - it was non-present before */ update_mmu_cache(dst_vma, dst_addr, dst_pte); ret = 0; @@ -240,8 +239,7 @@ static int mfill_atomic_pte_zeropage(struct mm_struct *dst_mm, } /* Handles UFFDIO_CONTINUE for all shmem VMAs (shared or private). */ -static int mfill_atomic_pte_continue(struct mm_struct *dst_mm, - pmd_t *dst_pmd, +static int mfill_atomic_pte_continue(pmd_t *dst_pmd, struct vm_area_struct *dst_vma, unsigned long dst_addr, bool wp_copy) @@ -269,7 +267,7 @@ static int mfill_atomic_pte_continue(struct mm_struct *dst_mm, goto out_release; } - ret = mfill_atomic_install_pte(dst_mm, dst_pmd, dst_vma, dst_addr, + ret = mfill_atomic_install_pte(dst_pmd, dst_vma, dst_addr, page, false, wp_copy); if (ret) goto out_release; @@ -310,7 +308,7 @@ static pmd_t *mm_alloc_pmd(struct mm_struct *mm, unsigned long address) * mfill_atomic processing for HUGETLB vmas. Note that this routine is * called with mmap_lock held, it will release mmap_lock before returning. */ -static __always_inline ssize_t mfill_atomic_hugetlb(struct mm_struct *dst_mm, +static __always_inline ssize_t mfill_atomic_hugetlb( struct vm_area_struct *dst_vma, unsigned long dst_start, unsigned long src_start, @@ -318,6 +316,7 @@ static __always_inline ssize_t mfill_atomic_hugetlb(struct mm_struct *dst_mm, enum mcopy_atomic_mode mode, bool wp_copy) { + struct mm_struct *dst_mm = dst_vma->vm_mm; int vm_shared = dst_vma->vm_flags & VM_SHARED; ssize_t err; pte_t *dst_pte; @@ -411,7 +410,7 @@ static __always_inline ssize_t mfill_atomic_hugetlb(struct mm_struct *dst_mm, goto out_unlock; } - err = hugetlb_mfill_atomic_pte(dst_mm, dst_pte, dst_vma, + err = hugetlb_mfill_atomic_pte(dst_pte, dst_vma, dst_addr, src_addr, mode, &page, wp_copy); @@ -463,17 +462,15 @@ static __always_inline ssize_t mfill_atomic_hugetlb(struct mm_struct *dst_mm, } #else /* !CONFIG_HUGETLB_PAGE */ /* fail at build time if gcc attempts to use this */ -extern ssize_t mfill_atomic_hugetlb(struct mm_struct *dst_mm, - struct vm_area_struct *dst_vma, - unsigned long dst_start, - unsigned long src_start, - unsigned long len, - enum mcopy_atomic_mode mode, - bool wp_copy); +extern ssize_t mfill_atomic_hugetlb(struct vm_area_struct *dst_vma, + unsigned long dst_start, + unsigned long src_start, + unsigned long len, + enum mcopy_atomic_mode mode, + bool wp_copy); #endif /* CONFIG_HUGETLB_PAGE */ -static __always_inline ssize_t mfill_atomic_pte(struct mm_struct *dst_mm, - pmd_t *dst_pmd, +static __always_inline ssize_t mfill_atomic_pte(pmd_t *dst_pmd, struct vm_area_struct *dst_vma, unsigned long dst_addr, unsigned long src_addr, @@ -484,7 +481,7 @@ static __always_inline ssize_t mfill_atomic_pte(struct mm_struct *dst_mm, ssize_t err; if (mode == MCOPY_ATOMIC_CONTINUE) { - return mfill_atomic_pte_continue(dst_mm, dst_pmd, dst_vma, + return mfill_atomic_pte_continue(dst_pmd, dst_vma, dst_addr, wp_copy); } @@ -500,14 +497,14 @@ static __always_inline ssize_t mfill_atomic_pte(struct mm_struct *dst_mm, */ if (!(dst_vma->vm_flags & VM_SHARED)) { if (mode == MCOPY_ATOMIC_NORMAL) - err = mfill_atomic_pte_copy(dst_mm, dst_pmd, dst_vma, + err = mfill_atomic_pte_copy(dst_pmd, dst_vma, dst_addr, src_addr, page, wp_copy); else - err = mfill_atomic_pte_zeropage(dst_mm, dst_pmd, + err = mfill_atomic_pte_zeropage(dst_pmd, dst_vma, dst_addr); } else { - err = shmem_mfill_atomic_pte(dst_mm, dst_pmd, dst_vma, + err = shmem_mfill_atomic_pte(dst_pmd, dst_vma, dst_addr, src_addr, mode != MCOPY_ATOMIC_NORMAL, wp_copy, page); @@ -588,7 +585,7 @@ static __always_inline ssize_t mfill_atomic(struct mm_struct *dst_mm, * If this is a HUGETLB vma, pass off to appropriate routine */ if (is_vm_hugetlb_page(dst_vma)) - return mfill_atomic_hugetlb(dst_mm, dst_vma, dst_start, + return mfill_atomic_hugetlb(dst_vma, dst_start, src_start, len, mcopy_mode, wp_copy); @@ -641,7 +638,7 @@ static __always_inline ssize_t mfill_atomic(struct mm_struct *dst_mm, BUG_ON(pmd_none(*dst_pmd)); BUG_ON(pmd_trans_huge(*dst_pmd)); - err = mfill_atomic_pte(dst_mm, dst_pmd, dst_vma, dst_addr, + err = mfill_atomic_pte(dst_pmd, dst_vma, dst_addr, src_addr, &page, mcopy_mode, wp_copy); cond_resched(); @@ -710,7 +707,7 @@ ssize_t mfill_atomic_continue(struct mm_struct *dst_mm, unsigned long start, mmap_changing, 0); } -long uffd_wp_range(struct mm_struct *dst_mm, struct vm_area_struct *dst_vma, +long uffd_wp_range(struct vm_area_struct *dst_vma, unsigned long start, unsigned long len, bool enable_wp) { unsigned int mm_cp_flags; @@ -730,7 +727,7 @@ long uffd_wp_range(struct mm_struct *dst_mm, struct vm_area_struct *dst_vma, */ if (!enable_wp && vma_wants_manual_pte_write_upgrade(dst_vma)) mm_cp_flags |= MM_CP_TRY_CHANGE_WRITABLE; - tlb_gather_mmu(&tlb, dst_mm); + tlb_gather_mmu(&tlb, dst_vma->vm_mm); ret = change_protection(&tlb, dst_vma, start, start + len, mm_cp_flags); tlb_finish_mmu(&tlb); @@ -782,7 +779,7 @@ int mwriteprotect_range(struct mm_struct *dst_mm, unsigned long start, goto out_unlock; } - err = uffd_wp_range(dst_mm, dst_vma, start, len, enable_wp); + err = uffd_wp_range(dst_vma, start, len, enable_wp); /* Return 0 on success, <0 on failures */ if (err > 0)