From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta0.migadu.com (out-120.mta0.migadu.com [91.218.175.120]) (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 B0EA648C403 for ; Thu, 13 Aug 2026 16:40:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.120 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786639233; cv=none; b=JPMScAWF1QPr/aOAu0SnpAU4dX2chVZHJqiC3oIaSZJmMSeV1kiCgoUbtXUIcgnRMLE4OJoK9lXG4dnA8NxuFQ+hgSNP7TbnKqNyZttRhCYLQqwIHQGA1ymlb9KbUIKiVyi/q+C2eoHTK7Op345lz/9Hb8cwp+856C8eLEKdoos= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786639233; c=relaxed/simple; bh=2xHRkVg+2QruCbn/49OFRRcW/C+6DJzcQqzEfAggLy0=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=JAAtXJrfKSonyc9jX44NTT8TUghP2NEuhqT3zzh/QnlZD9tv1ltO+hsxzSajxGpXaicejmLwOGSfra7pBtkO4WhC/kBrgsmsBmscrSJe0aWwzEeLFmw8+B7fhbWVk0xFQFcI1GG9GwW0SaAuIsYW45lh1cKb9zEhs5tEDsfuLnE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=tFCtmhFX; arc=none smtp.client-ip=91.218.175.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="tFCtmhFX" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=2xHRkVg+2QruCbn/49OFRRcW/C+6DJzcQqzEfAggLy0=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1786639218; v=1; x=1787244018; b=tFCtmhFXOIyUSImdJsntpW6QEZIEYdhdFhrWGeHE17FQZUj4nJhhYdtHGbHulYC1X00hkrSj hu81o0Hi7gy3LX5FNlqRtKSvkQDka5JGcbIc4xWpQEZtF1LACNl0v2sDZ4rf2KiyOUtgE6ArsTO cDXfytxvpzsjkzVGdNqMkjPs= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost (77.97.51.77) by smtp.migadu.com with ESMTPS id a52373bc50ec12e6; Thu, 13 Aug 2026 16:40:08 +0000 X-Migadu-Flow: FLOW_OUT Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 13 Aug 2026 17:40:03 +0100 Message-Id: Cc: "Borislav Petkov" , "Dave Hansen" , "Peter Zijlstra" , "Andrew Morton" , "David Hildenbrand" , "Vlastimil Babka" , "Mike Rapoport" , "Wei Xu" , "Johannes Weiner" , "Zi Yan" , "Lorenzo Stoakes" , , , , "Sumit Garg" , "Will Deacon" , , "Kalyazin, Nikita" , , "Itazuri, Takahiro" , "Andy Lutomirski" , "David Kaplan" , "Thomas Gleixner" , "Patrick Bellasi" , "Reiji Watanabe" , "Sean Christopherson" Subject: Re: [PATCH v3 10/26] mm: Add more flags for __apply_to_page_range() From: "Brendan Jackman" To: "Yosry Ahmed" , "Brendan Jackman" X-Mailer: aerc 0.21.0 References: <20260726-page_alloc-unmapped-v3-0-6f5729aa9832@google.com> <20260726-page_alloc-unmapped-v3-10-6f5729aa9832@google.com> In-Reply-To: On Tue Aug 4, 2026 at 1:08 AM BST, Yosry Ahmed wrote: > On Sun, Jul 26, 2026 at 10:22:43PM +0000, Brendan Jackman wrote: >> Add two flags to make this API more generic: >>=20 >> 1. Separate "create" into two levels - one to allow creating new >> mappings without allocating pagetables, and one for the current >> behaviour that allows both of these. >>=20 >> 2. Create a new flag to report that the caller has taken care of >> synchronization and no locks are required. >>=20 >> Both of these will serve to allow calling this API from restricted >> contexts where allocation and pagetable locking are not possible. >>=20 >> Signed-off-by: Brendan Jackman >> --- >> mm/internal.h | 26 +++++++++++++++++++++++++- >> mm/memory.c | 59 ++++++++++++++++++++++++++++++++++------------------= ------- >> 2 files changed, 59 insertions(+), 26 deletions(-) >>=20 >> diff --git a/mm/internal.h b/mm/internal.h >> index 395331a12d62d..5a237d9c5fa96 100644 >> --- a/mm/internal.h >> +++ b/mm/internal.h >> @@ -1662,9 +1662,33 @@ static inline bool can_spin_trylock(void) >> =20 >> /* >> * Create a mapping if it doesn't exist. (Otherwise, skip regions with = no >> - * existing mapping, and return an error for regions with no leaf paget= able). >> + * existing mapping). This doesn't allow allocating, most users will wa= nt >> + * PGRANGE_ALLOC. >> + * >> + * Do not test this bit directly as it is implied by PGRANGE_ALLOC, use >> + * pgrange_create() instead. >> */ >> #define PGRANGE_CREATE (1 << 0) >> +/* >> + * Allocate a pagetable if one is missing. (Otherwise, return an error = for >> + * regions with no leaf pagetable). Also implies PGRANGE_CREATE. >> + * >> + * Note that __apply_to_page_range() assumes that pagetables for the ar= ea are >> + * already initialised down to PMD level, so this only affects PTEs in = practice. >> + */ >> +#define PGRANGE_ALLOC (1 << 1) >> +/* >> + * Do not take any locks. This means the caller has taken care of >> + * synchronisation. This is incompatible with PGRANGE_ALLOC and also wi= th >> + * mm=3D&init_mm. >> + */ >> +#define PGRANGE_NOLOCK (1 << 2) > > I assume this is used by the mermap as locking is not required because > the mappings are per-CPU and migration is disabled while the mermap is > used? Exactly. > Also, why is this incompatible with init_mm? It actually seems like > apply_to_pte_range() is always lockless for init_mm (uses > pte_offset_kernel()), probably callers are also synchronizing in their > own way (e.g. exclusive access to a vmap area?). Hm. My initial reaction was that there was code like this somewhere: if (mm =3D=3D &init_mm) spin_lock(&pgd_lock); But I can't find it in these paths and neither can Fable. So yeah I think this bit about init_mm can just be dropped.