From patchwork Mon Jul 1 08:46:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13717669 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 EBBBFC30653 for ; Mon, 1 Jul 2024 08:48:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 85A696B00A7; Mon, 1 Jul 2024 04:48:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 80A4E6B00A8; Mon, 1 Jul 2024 04:48:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6AA6F6B00A9; Mon, 1 Jul 2024 04:48:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4DDED6B00A7 for ; Mon, 1 Jul 2024 04:48:20 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 036281C31E6 for ; Mon, 1 Jul 2024 08:48:19 +0000 (UTC) X-FDA: 82290557160.01.5C9A0F3 Received: from mail-oa1-f43.google.com (mail-oa1-f43.google.com [209.85.160.43]) by imf06.hostedemail.com (Postfix) with ESMTP id 3E66618000A for ; Mon, 1 Jul 2024 08:48:18 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=UZC6kGdr; spf=none (imf06.hostedemail.com: domain of zhengqi.arch@bytedance.com has no SPF policy when checking 209.85.160.43) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719823687; a=rsa-sha256; cv=none; b=UFdDmugaUNzOMU8fsuCDuY1yJgEprWqgrRVvu00BvLS3YS2sycU5fOpsGU821NJOWOKtpz UQTp/nBm0Q8z2V2nmm6bhiTU8dEh9O4LUsAIjBqJ23/oUpi9e9NXN3BOJ7PfQcPkYIjRv2 MK+p6El0rOK6JzBwIO+yY7ZvoM/fFYU= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=UZC6kGdr; spf=none (imf06.hostedemail.com: domain of zhengqi.arch@bytedance.com has no SPF policy when checking 209.85.160.43) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719823687; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=heRFBrzmiSFbf80Ldx88bwYUpXRT+UgzgGRtnFqgbfo=; b=Ee2/7b/p1wEF/TxB2XptbclshaL2CybrRCRBjgmT5YHnBTeo0iTjNpKHXLJPQQA5KVSBiI I4EGbtmKzb1CQPPiJTVD07jYc7yCbNu2ORVQet2hvmVplyZ0gVVbBSTmQQ1D8g3CkoLzeW FpHFlzF690aeV1LbmdWY34bv8ZF6UDM= Received: by mail-oa1-f43.google.com with SMTP id 586e51a60fabf-25989f87e20so416515fac.1 for ; Mon, 01 Jul 2024 01:48:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1719823697; x=1720428497; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=heRFBrzmiSFbf80Ldx88bwYUpXRT+UgzgGRtnFqgbfo=; b=UZC6kGdrfKhJF2f5fS5EWHDILOeRqPYONGMTUN+8GXvNBWnbcBsFakux/Z/wss3XzQ ewx4DS7+HfskuzK17SBCKE6NlFfyCywP6DlWP/kk04rqy5z0VONIpa8ONW6ilD4zTLv+ QUFtONBDuYRryz8GQtj4VBgFOTqblPQ2Z7d5rGdegSiGmOIo4sJNfTgHAwup6hT5/3BQ 92zWpPgYIYjFkv+7tEqhXj8I3TH54x11IGiwCMRNidL7ZU/NQ24QDoWeo0IkXHzOxnd5 JAVLJc0yOF8aV+2fedwsj4nOLJm1XCqPAQ3jT/+KQ3h2U1Dx91nBYvK0ygRiqci3axJK 0GgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719823697; x=1720428497; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=heRFBrzmiSFbf80Ldx88bwYUpXRT+UgzgGRtnFqgbfo=; b=h/OYYl10qou+y0uYH+Ogtk6TRQGHUQ4HO6k+x2uIP0YfcP7uhPH3CpeCqlxvRsLLA4 3+CWQpm8KHmlEL28gWJ5lbRUaol6Xa+OASD3qrJRdegbL0+Itel1uQ2qJc+HXHtgT6lp rippqpSdWbVrCLALsCQ9hTZQaLzApi7l3pLwCbzGwqB4TvJIpwJ9fnSwyNOn+9TvMj6F jV6BMsJ+ls/12rDTPtVgp+yEw2A+Jt2U4djdtrTMgLTaPIo0GVtmwKj/XsHRZs4ZLvVw KKIBvZPesLSedQe2aAVg+ewXjgid2JLtVtS24u/tGlacxxeRrmLFDl0ApIqeeIM/bCQv m5wg== X-Gm-Message-State: AOJu0Yx2EMkSvlQEqv3aeEkJPdwTVWqZnvHVUf11piGuVuSc4UFxjn+o rlQ2xaxV1oXbdalmjRbDrEk94v7spBmOKRaGfXjFVk+c0BXmr3A8f27KFKOpv5Q= X-Google-Smtp-Source: AGHT+IFFB2WixvwXraavN9qiwzLbm4r9XSaP2jQhzM0/LqY8bBCt0wrI3ZybaGE0lHA7u/jpjEN+uQ== X-Received: by 2002:a05:6870:3751:b0:254:affe:5a08 with SMTP id 586e51a60fabf-25db340a2d2mr4729423fac.2.1719823697112; Mon, 01 Jul 2024 01:48:17 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.241]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70804a7e7e0sm5932374b3a.204.2024.07.01.01.48.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 01:48:16 -0700 (PDT) From: Qi Zheng To: david@redhat.com, hughd@google.com, willy@infradead.org, mgorman@suse.de, muchun.song@linux.dev, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qi Zheng Subject: [RFC PATCH 3/7] mm: pass address information to pmd_install() Date: Mon, 1 Jul 2024 16:46:44 +0800 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: 8o9j86rxe6w9y3izuhhd6y8szad7quww X-Rspamd-Queue-Id: 3E66618000A X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1719823698-397857 X-HE-Meta: U2FsdGVkX1+1D6bHfsF7F8kob3nRrmeEarH3eTEC/xhiiTQhHS6SSknVvDM5RwvYptYtmVw8hhlmNVLy8baO+jx6G8mDMUpOIpqju4b4EsObARgoL2N23Nu537c6Sz+GzZaHJobVJRY2yf4kgJpzxnNnA0jm4wgIaooZdyQ6IDqXwFsUZ/ftJFU0/M40MVjm0KYT3eGCA94npOCcEELYL6IrPBqHpMZiy93/3wSUQlTrzidemXmnTMntfibxGMbGDpwCMlF5V3DL8qy4lXMwwwB2uEkSRFKNgPGgNo/wkqspfMtqxWudsAknfbIWapngALKg2RiHDY1v7oZLWjzcG/0p1KqFQsz00zrBJhnEqj6r/P73/SVGa1Hli022VgmYBvJqVM/Wilssb3YTSmmTfNz5VcdT2ASb3zFSG2mdB6Qaxm8RamnqvjrH5K2uMmnnEppAgDVg/W5kZK0YT+bR7pNFA0C1gi9Hz3USqJ1ndv7OTwebhap725259Xt/Vjj/+7cpcs08H96P/Y674GhK1Okfqa4eSkVe1YlZJwho2RqRPPvaByzxDp1DwfYVLO6rDHCmkolAogY3BY5Xe16Fc7ci23Au7NCUXNEC/AD3RkiwTgreh6DvcUNzWVTY7qhc/o4DH/MKQBGSYmdBFdw2woaJ9GQpVl9L6PAZM8k5rFmri0NvW3qOQ0Gpc9IkCUI/JusKn21UKqUQjtZohaHe0dyZsfvbgz2Spl18AfZphO+2xt0/bh8wuv7+PPjwrNUBcWcA8Jlhr45rSqbaZAcnAOkmqMvTvyI7VZ+sjUTX2PxFiRyf5PUBHJ+CakJk6EdfkXk1sfy7Wb38XD0dW88eO/qopW/sDDoGkWTPb23YTIXsTHAOAinbidXoUKPBFMKe921CmkyEu6wqF3HtwzjE0oqavid6EDwIVkUs1MygIS8riC2XzjXYfBra465XzFNSnNp+qlzY8iJkKHDJvQg ZnPSk9zK ZHWmH6n5gR/GWNIlETVLJbQKhvmrC787xvDCnKu92a/X76e2FAfRHD2A0JfFU21qik8XVr2DxHirCT/OSfZL+GnQpnxUjfiFbR0jDLMttOZJQFNF+efjQUeWhoRLpTz2/rSOSjVlDD4otxDO8NyOO8clBBO5E7NXtA4FJeh79eeFd6pfFTbJKPJtqhc2jPoZBkcfJc6Lpw9qRauQYLTSJ4H5Pfklfe1UACkNu4SbAdSyZmSignbVBbnT+jlbCFyd7BCPfQ3mxA0xTVRmBarxi8WEbFMokMhEJRUcKrqGLM6KE/vI6J1/HwLWPlinX4ZMwds31CN6HsKZUrio8UdLqW7BfnNWzwAi1az4Q 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: List-Subscribe: List-Unsubscribe: In the subsequent implementation of freeing empty page table pages, we need the address information to flush tlb, so pass address to pmd_install() in advance. No functional changes. Signed-off-by: Qi Zheng --- include/linux/hugetlb.h | 2 +- include/linux/mm.h | 9 +++++---- mm/debug_vm_pgtable.c | 2 +- mm/filemap.c | 2 +- mm/gup.c | 2 +- mm/internal.h | 3 ++- mm/memory.c | 15 ++++++++------- mm/migrate_device.c | 2 +- mm/mprotect.c | 8 ++++---- mm/mremap.c | 2 +- mm/userfaultfd.c | 6 +++--- 11 files changed, 28 insertions(+), 25 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index a951c0d06061..55715eb5cb34 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -198,7 +198,7 @@ static inline pte_t *pte_offset_huge(pmd_t *pmd, unsigned long address) static inline pte_t *pte_alloc_huge(struct mm_struct *mm, pmd_t *pmd, unsigned long address) { - return pte_alloc(mm, pmd) ? NULL : pte_offset_huge(pmd, address); + return pte_alloc(mm, pmd, address) ? NULL : pte_offset_huge(pmd, address); } #endif diff --git a/include/linux/mm.h b/include/linux/mm.h index 396bdc3b3726..880100a8b472 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2800,7 +2800,7 @@ static inline void mm_inc_nr_ptes(struct mm_struct *mm) {} static inline void mm_dec_nr_ptes(struct mm_struct *mm) {} #endif -int __pte_alloc(struct mm_struct *mm, pmd_t *pmd); +int __pte_alloc(struct mm_struct *mm, pmd_t *pmd, unsigned long addr); int __pte_alloc_kernel(pmd_t *pmd); #if defined(CONFIG_MMU) @@ -2987,13 +2987,14 @@ pte_t *pte_offset_map_nolock(struct mm_struct *mm, pmd_t *pmd, pmd_t *pmdvalp, pte_unmap(pte); \ } while (0) -#define pte_alloc(mm, pmd) (unlikely(pmd_none(*(pmd))) && __pte_alloc(mm, pmd)) +#define pte_alloc(mm, pmd, addr) \ + (unlikely(pmd_none(*(pmd))) && __pte_alloc(mm, pmd, addr)) #define pte_alloc_map(mm, pmd, address) \ - (pte_alloc(mm, pmd) ? NULL : pte_offset_map(pmd, address)) + (pte_alloc(mm, pmd, address) ? NULL : pte_offset_map(pmd, address)) #define pte_alloc_map_lock(mm, pmd, address, ptlp) \ - (pte_alloc(mm, pmd) ? \ + (pte_alloc(mm, pmd, address) ? \ NULL : pte_offset_map_lock(mm, pmd, address, ptlp)) #define pte_alloc_kernel(pmd, address) \ diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index e4969fb54da3..18375744e184 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -1246,7 +1246,7 @@ static int __init init_args(struct pgtable_debug_args *args) args->start_pmdp = pmd_offset(args->pudp, 0UL); WARN_ON(!args->start_pmdp); - if (pte_alloc(args->mm, args->pmdp)) { + if (pte_alloc(args->mm, args->pmdp, args->vaddr)) { pr_err("Failed to allocate pte entries\n"); ret = -ENOMEM; goto error; diff --git a/mm/filemap.c b/mm/filemap.c index 35bbba960447..d8b936d87eb4 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3453,7 +3453,7 @@ static bool filemap_map_pmd(struct vm_fault *vmf, struct folio *folio, } if (pmd_none(*vmf->pmd) && vmf->prealloc_pte) - pmd_install(mm, vmf->pmd, &vmf->prealloc_pte); + pmd_install(mm, vmf->pmd, vmf->address, &vmf->prealloc_pte); return false; } diff --git a/mm/gup.c b/mm/gup.c index 8bea9ad80984..b87b1ea9d008 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1105,7 +1105,7 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma, spin_unlock(ptl); split_huge_pmd(vma, pmd, address); /* If pmd was left empty, stuff a page table in there quickly */ - return pte_alloc(mm, pmd) ? ERR_PTR(-ENOMEM) : + return pte_alloc(mm, pmd, address) ? ERR_PTR(-ENOMEM) : follow_page_pte(vma, address, pmd, flags, &ctx->pgmap); } page = follow_huge_pmd(vma, address, pmd, flags, ctx); diff --git a/mm/internal.h b/mm/internal.h index 2ea9a88dcb95..1dfdad110a9a 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -320,7 +320,8 @@ void folio_activate(struct folio *folio); void free_pgtables(struct mmu_gather *tlb, struct ma_state *mas, struct vm_area_struct *start_vma, unsigned long floor, unsigned long ceiling, bool mm_wr_locked); -void pmd_install(struct mm_struct *mm, pmd_t *pmd, pgtable_t *pte); +void pmd_install(struct mm_struct *mm, pmd_t *pmd, unsigned long addr, + pgtable_t *pte); struct zap_details; void unmap_page_range(struct mmu_gather *tlb, diff --git a/mm/memory.c b/mm/memory.c index 1c9068b0b067..09db2c97cc5c 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -417,7 +417,8 @@ void free_pgtables(struct mmu_gather *tlb, struct ma_state *mas, } while (vma); } -void pmd_install(struct mm_struct *mm, pmd_t *pmd, pgtable_t *pte) +void pmd_install(struct mm_struct *mm, pmd_t *pmd, unsigned long addr, + pgtable_t *pte) { spinlock_t *ptl = pmd_lock(mm, pmd); @@ -443,13 +444,13 @@ void pmd_install(struct mm_struct *mm, pmd_t *pmd, pgtable_t *pte) spin_unlock(ptl); } -int __pte_alloc(struct mm_struct *mm, pmd_t *pmd) +int __pte_alloc(struct mm_struct *mm, pmd_t *pmd, unsigned long addr) { pgtable_t new = pte_alloc_one(mm); if (!new) return -ENOMEM; - pmd_install(mm, pmd, &new); + pmd_install(mm, pmd, addr, &new); if (new) pte_free(mm, new); return 0; @@ -2115,7 +2116,7 @@ static int insert_pages(struct vm_area_struct *vma, unsigned long addr, /* Allocate the PTE if necessary; takes PMD lock once only. */ ret = -ENOMEM; - if (pte_alloc(mm, pmd)) + if (pte_alloc(mm, pmd, addr)) goto out; while (pages_to_write_in_pmd) { @@ -4521,7 +4522,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) * Use pte_alloc() instead of pte_alloc_map(), so that OOM can * be distinguished from a transient failure of pte_offset_map(). */ - if (pte_alloc(vma->vm_mm, vmf->pmd)) + if (pte_alloc(vma->vm_mm, vmf->pmd, vmf->address)) return VM_FAULT_OOM; /* Use the zero-page for reads */ @@ -4868,8 +4869,8 @@ vm_fault_t finish_fault(struct vm_fault *vmf) } if (vmf->prealloc_pte) - pmd_install(vma->vm_mm, vmf->pmd, &vmf->prealloc_pte); - else if (unlikely(pte_alloc(vma->vm_mm, vmf->pmd))) + pmd_install(vma->vm_mm, vmf->pmd, vmf->address, &vmf->prealloc_pte); + else if (unlikely(pte_alloc(vma->vm_mm, vmf->pmd, vmf->address))) return VM_FAULT_OOM; } diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 6d66dc1c6ffa..e4d2e19e6611 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -598,7 +598,7 @@ static void migrate_vma_insert_page(struct migrate_vma *migrate, goto abort; if (pmd_trans_huge(*pmdp) || pmd_devmap(*pmdp)) goto abort; - if (pte_alloc(mm, pmdp)) + if (pte_alloc(mm, pmdp, addr)) goto abort; if (unlikely(anon_vma_prepare(vma))) goto abort; diff --git a/mm/mprotect.c b/mm/mprotect.c index 222ab434da54..1a1537ddffe4 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -330,11 +330,11 @@ pgtable_populate_needed(struct vm_area_struct *vma, unsigned long cp_flags) * allocation failures during page faults by kicking OOM and returning * error. */ -#define change_pmd_prepare(vma, pmd, cp_flags) \ +#define change_pmd_prepare(vma, pmd, addr, cp_flags) \ ({ \ long err = 0; \ if (unlikely(pgtable_populate_needed(vma, cp_flags))) { \ - if (pte_alloc(vma->vm_mm, pmd)) \ + if (pte_alloc(vma->vm_mm, pmd, addr)) \ err = -ENOMEM; \ } \ err; \ @@ -375,7 +375,7 @@ static inline long change_pmd_range(struct mmu_gather *tlb, again: next = pmd_addr_end(addr, end); - ret = change_pmd_prepare(vma, pmd, cp_flags); + ret = change_pmd_prepare(vma, pmd, addr, cp_flags); if (ret) { pages = ret; break; @@ -402,7 +402,7 @@ static inline long change_pmd_range(struct mmu_gather *tlb, * cleared; make sure pmd populated if * necessary, then fall-through to pte level. */ - ret = change_pmd_prepare(vma, pmd, cp_flags); + ret = change_pmd_prepare(vma, pmd, addr, cp_flags); if (ret) { pages = ret; break; diff --git a/mm/mremap.c b/mm/mremap.c index f672d0218a6f..7723d11e77cd 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -628,7 +628,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma, } if (pmd_none(*old_pmd)) continue; - if (pte_alloc(new_vma->vm_mm, new_pmd)) + if (pte_alloc(new_vma->vm_mm, new_pmd, new_addr)) break; if (move_ptes(vma, old_pmd, old_addr, old_addr + extent, new_vma, new_pmd, new_addr, need_rmap_locks) < 0) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 61c1d228d239..e1674580b54f 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -796,7 +796,7 @@ static __always_inline ssize_t mfill_atomic(struct userfaultfd_ctx *ctx, break; } if (unlikely(pmd_none(dst_pmdval)) && - unlikely(__pte_alloc(dst_mm, dst_pmd))) { + unlikely(__pte_alloc(dst_mm, dst_pmd, dst_addr))) { err = -ENOMEM; break; } @@ -1713,13 +1713,13 @@ ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start, err = -ENOENT; break; } - if (unlikely(__pte_alloc(mm, src_pmd))) { + if (unlikely(__pte_alloc(mm, src_pmd, src_addr))) { err = -ENOMEM; break; } } - if (unlikely(pte_alloc(mm, dst_pmd))) { + if (unlikely(pte_alloc(mm, dst_pmd, dst_addr))) { err = -ENOMEM; break; }