From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A75CC37A842 for ; Sun, 26 Jul 2026 22:23:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.69 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785104621; cv=none; b=rXiZYyOUgo0i+2KQfcqN3O+5+iXNS3yE0+3Onlflum+nWpFg1Qm1J0UmzpnhrnOlFBT3mscscLa8tsPBYBo4+RWA0Emz2vv1M6hp+mtEcwibHuHtz+I8OxC1Q1juThwgfm8vRljhXarHYmr8kCojVD0lQ5xikbKMaDZKjb61VLc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785104621; c=relaxed/simple; bh=8Hc0/CIB6xAsz4Xw0WNkfhY91Ys0/aAVQJOH4WOxAaQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UDtyFojVDJh6WPUjt0fL2br09xmmDytmZzV+/3vpPf7HG0w11hAikkSPG1OU+0ajqYU1B6jlgNAHmLOr5ZEG5UkOyg6Ng4JCoAEZLya/Md43vmzk31cnYT1CTpNn8dQnYG/eOfjtt8PF/ClT3Dl4GkFULuoTcrcybllfHCI2yX4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=vPZGI/3m; arc=none smtp.client-ip=209.85.128.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vPZGI/3m" Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-493a7fa8481so19145975e9.1 for ; Sun, 26 Jul 2026 15:23:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785104614; x=1785709414; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=pyOh9aeu8h8uSSc2SnxD7XE/Zp9/FI1sdExUOKQtsH0=; b=vPZGI/3mc253/yj5AldTUUNozeL7U0azi8ZX+OrwtrboYvju/tHj2YXrMF9Ila4xRR le3gH+ZToIVmRNsyjzhklIE77YIkiDLkQ8TKMt7toSYnNztsPgc0sTb0Oq5gkLmAkSVs +1ex9xCzLVLZgx7EBj46u6UQZSbXLP9jI9q/+eL7EV0RUsNk3OsZdMxaYnazGI35FtVB MzgxsR6BTDUt8GCu/cj5jC7au1epH4XdfgzqiifJRzJlUZLEyns93YDy5xIFoSOlG+ZH VCF/2WKnhtFEeaMHsOfkPGMzCKyYhNm9E7PYoU2G/SogjW/X7Grqs6Oxi/BHFtZB/DxB g5yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785104614; x=1785709414; h=content-type: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:content-type; bh=pyOh9aeu8h8uSSc2SnxD7XE/Zp9/FI1sdExUOKQtsH0=; b=GNvdrQk7ky7d0abnk5g76/yZcAjpf2zsaSxXvuhUQLwy3RJWGWA9g0SKfzOd64a2GP 9UhpECPTwxmVQMSSnF4orq6WlalBps01DXmoRWHRoXAd/FPiPdu6SDSIySBieaiS+z+l CwT2omt/M/cXMQTmUOyLwfQd4VwipKIM6EBnSyNNga7qwsQW75TjDY0JB66objQUL7zz N5v+fews07JEh40R1i/vuTLkTPTIlX0by2AH+1MCHQ2iwFZmu/45QjyaMUT6vL8oBwh4 91w9anXk9n4JlcNksyLXSmldkEs6uLscyQrEHHx0eIGexkP0LsftcGAx5GOPm4RnIaW4 KHQg== X-Forwarded-Encrypted: i=1; AHgh+RqjXOOGRXtlIfkqCFc2MBHp6EO2ck5kr4oyakQfpJvB6gkAtxxCCHSyHOwCkc5EPGDKmZTW1YEztVHT4jE=@vger.kernel.org X-Gm-Message-State: AOJu0YzM9vetioZ7GNhHHMOuy5Z21r1b67Q5cPy/MtIMx1KEXdiKOEXu 0N03PVwcztXG/CgVdZ2l6cIV/y9cE1g1y2vDO7mlR2PvLGd68XlvrzvU2N+4IP/GmH8I1R2336n xfef8V6jR3RflWw== X-Received: from wmsk6-n2.prod.google.com ([2002:a05:600d:8486:20b0:495:5bab:557]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3150:b0:495:4f84:7280 with SMTP id 5b1f17b1804b1-496b5b3b1d4mr83782625e9.4.1785104613513; Sun, 26 Jul 2026 15:23:33 -0700 (PDT) Date: Sun, 26 Jul 2026 22:22:42 +0000 In-Reply-To: <20260726-page_alloc-unmapped-v3-0-6f5729aa9832@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260726-page_alloc-unmapped-v3-0-6f5729aa9832@google.com> X-Mailer: b4 0.16-dev Message-ID: <20260726-page_alloc-unmapped-v3-9-6f5729aa9832@google.com> Subject: [PATCH v3 09/26] mm: Create flags arg for __apply_to_page_range() From: Brendan Jackman To: Borislav Petkov , Dave Hansen , Peter Zijlstra , Andrew Morton , David Hildenbrand , Vlastimil Babka , Mike Rapoport , Wei Xu , Johannes Weiner , Zi Yan , Lorenzo Stoakes Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, x86@kernel.org, rppt@kernel.org, Sumit Garg , Will Deacon , rientjes@google.com, "Kalyazin, Nikita" , patrick.roy@linux.dev, "Itazuri, Takahiro" , Andy Lutomirski , David Kaplan , Thomas Gleixner , Yosry Ahmed , Patrick Bellasi , Reiji Watanabe , Sean Christopherson , Brendan Jackman Content-Type: text/plain; charset="utf-8" Preparatory patch, no functional change intended. To prepare for making this function more generic, convert the boolean "create" arg into a flags arg with a single flag that has the same meaning. Signed-off-by: Brendan Jackman --- mm/internal.h | 10 ++++++++++ mm/memory.c | 29 +++++++++++++++++------------ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index f47f06c555481..395331a12d62d 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1660,4 +1660,14 @@ static inline bool can_spin_trylock(void) return true; } +/* + * Create a mapping if it doesn't exist. (Otherwise, skip regions with no + * existing mapping, and return an error for regions with no leaf pagetable). + */ +#define PGRANGE_CREATE (1 << 0) + +int __apply_to_page_range(struct mm_struct *mm, unsigned long addr, + unsigned long size, pte_fn_t fn, + void *data, unsigned int flags); + #endif /* __MM_INTERNAL_H */ diff --git a/mm/memory.c b/mm/memory.c index 789c65a6d6a0e..c4defefea1574 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3438,9 +3438,10 @@ EXPORT_SYMBOL(vm_iomap_memory); static int apply_to_pte_range(struct mm_struct *mm, pmd_t *pmd, unsigned long addr, unsigned long end, - pte_fn_t fn, void *data, bool create, + pte_fn_t fn, void *data, unsigned int flags, pgtbl_mod_mask *mask) { + bool create = flags & PGRANGE_CREATE; pte_t *pte, *mapped_pte; int err = 0; spinlock_t *ptl; @@ -3481,10 +3482,11 @@ static int apply_to_pte_range(struct mm_struct *mm, pmd_t *pmd, static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud, unsigned long addr, unsigned long end, - pte_fn_t fn, void *data, bool create, + pte_fn_t fn, void *data, unsigned int flags, pgtbl_mod_mask *mask) { pmd_t *pmd; + bool create = flags & PGRANGE_CREATE; unsigned long next; int err = 0; @@ -3509,7 +3511,7 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud, pmd_clear_bad(pmd); } err = apply_to_pte_range(mm, pmd, addr, next, - fn, data, create, mask); + fn, data, flags, mask); if (err) break; } while (pmd++, addr = next, addr != end); @@ -3519,10 +3521,11 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud, static int apply_to_pud_range(struct mm_struct *mm, p4d_t *p4d, unsigned long addr, unsigned long end, - pte_fn_t fn, void *data, bool create, + pte_fn_t fn, void *data, unsigned int flags, pgtbl_mod_mask *mask) { pud_t *pud; + bool create = flags & PGRANGE_CREATE; unsigned long next; int err = 0; @@ -3555,10 +3558,11 @@ static int apply_to_pud_range(struct mm_struct *mm, p4d_t *p4d, static int apply_to_p4d_range(struct mm_struct *mm, pgd_t *pgd, unsigned long addr, unsigned long end, - pte_fn_t fn, void *data, bool create, + pte_fn_t fn, void *data, unsigned int flags, pgtbl_mod_mask *mask) { p4d_t *p4d; + bool create = flags & PGRANGE_CREATE; unsigned long next; int err = 0; @@ -3581,7 +3585,7 @@ static int apply_to_p4d_range(struct mm_struct *mm, pgd_t *pgd, p4d_clear_bad(p4d); } err = apply_to_pud_range(mm, p4d, addr, next, - fn, data, create, mask); + fn, data, flags, mask); if (err) break; } while (p4d++, addr = next, addr != end); @@ -3589,11 +3593,12 @@ static int apply_to_p4d_range(struct mm_struct *mm, pgd_t *pgd, return err; } -static int __apply_to_page_range(struct mm_struct *mm, unsigned long addr, - unsigned long size, pte_fn_t fn, - void *data, bool create) +int __apply_to_page_range(struct mm_struct *mm, unsigned long addr, + unsigned long size, pte_fn_t fn, + void *data, unsigned int flags) { pgd_t *pgd; + bool create = flags & PGRANGE_CREATE; unsigned long start = addr, next; unsigned long end = addr + size; pgtbl_mod_mask mask = 0; @@ -3617,7 +3622,7 @@ static int __apply_to_page_range(struct mm_struct *mm, unsigned long addr, pgd_clear_bad(pgd); } err = apply_to_p4d_range(mm, pgd, addr, next, - fn, data, create, &mask); + fn, data, flags, &mask); if (err) break; } while (pgd++, addr = next, addr != end); @@ -3635,7 +3640,7 @@ static int __apply_to_page_range(struct mm_struct *mm, unsigned long addr, int apply_to_page_range(struct mm_struct *mm, unsigned long addr, unsigned long size, pte_fn_t fn, void *data) { - return __apply_to_page_range(mm, addr, size, fn, data, true); + return __apply_to_page_range(mm, addr, size, fn, data, PGRANGE_CREATE); } EXPORT_SYMBOL_GPL(apply_to_page_range); @@ -3649,7 +3654,7 @@ EXPORT_SYMBOL_GPL(apply_to_page_range); int apply_to_existing_page_range(struct mm_struct *mm, unsigned long addr, unsigned long size, pte_fn_t fn, void *data) { - return __apply_to_page_range(mm, addr, size, fn, data, false); + return __apply_to_page_range(mm, addr, size, fn, data, 0); } /* -- 2.54.0