From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E01D34DCE3; Mon, 10 Aug 2026 08:40:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786351222; cv=none; b=Ax5qCR/OhFsulpw1WNp102YkVJW7mIpDbnW9Y+PGkVgsuiI+2pJxIzvI1fPHpHz674ibSODNGI/a9pEbZdjfKCP8iOXJ8V1+zLCjRJksHpwsJrb6AOm60ETZU+SYgJLF9mXTEaIxS4Xf1lDIb5OUTarT7cEwNZrlcmnP7+LaLOU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786351222; c=relaxed/simple; bh=OoE2ABdkhBCOOhXw3w+Oo6y1L2B9PUhLd0DoRAk/r7g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Yfh/CTxjC+qA0J79lGppPhUlXmrc1vR/534zkPDn8nH9oqKo0E0j29tYj/kRlsWORw7ZeGBLBPRMVVMpld2D72ZkJhbxzDdpnucMOmEJou2g4jIhzhv2Rzb0mwlB3t5fUqPuAxIRCHhGHAf/pgYCY7QhZmKFOZDEPc8n50iIuj8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JKo9vEdD; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JKo9vEdD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15B481F000E9; Mon, 10 Aug 2026 08:40:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786351221; bh=pqefW5WYGaVGXBp1EcWnADXqL4SSTTp93r2Me4s4EHs=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=JKo9vEdDRY9kEpH19pzoxMjPpB+BwegkZ/hk4gIse31W3/UahgMnQa9xh4JjiQFgo vyAT1sLy2fN77hi3ktVZitRAApigE7usTNwPtrxSB+xZCKedho76MmsOO/kaNwnbCG G3vVVXUDdlBbR1BRn+wmJtYxwXZyV17hCm0IC+Cr7LvHqWPryov+rSycK1U6Sf07Q1 a7K8Tx1IL6pcLFaXbOdwrOnccNyiajONZXrnTfr9FsiSjC5tGcxHcAlw+KE9+lCQDw I5B2NwM1a16Nkb4aClNBGjXSL3P4mApb8jLLnQeWlG5EA6ipQr7F/Z059iZBFNYRbF tXXNVEkrpiKjA== Date: Mon, 10 Aug 2026 09:39:47 +0100 From: "Lorenzo Stoakes (ARM)" To: Suren Baghdasaryan Cc: Andrew Morton , David Hildenbrand , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Michal Hocko , Jann Horn , Pedro Falcato , "Matthew Wilcox (Oracle)" , Jan Kara , Miaohe Lin , Naoya Horiguchi , Rik van Riel , Harry Yoo , Lance Yang , Kees Cook , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Usama Arif , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Peter Xu , Xu Xin , Chengming Zhou , Arnd Bergmann , Greg Kroah-Hartman , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Sven Schnelle , Alex Deucher , Christian =?utf-8?B?S8O2bmln?= , David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Boris Brezillon , Steven Price , Liviu Dudau , Huang Rui , Matthew Auld , Thomas =?utf-8?Q?Hellstr=C3=B6m?= , Rodrigo Vivi , Masami Hiramatsu , Oleg Nesterov , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Jason Gunthorpe , John Hubbard , Muchun Song , Oscar Salvador , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , Youngjun Park , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-s390@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org, linux-perf-users@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: Re: [PATCH v4 03/20] mm: introduce linear_anon_page_index() Message-ID: References: <20260806-b4-scalable-cow-virt-pgoff-v4-0-ab318a350404@kernel.org> <20260806-b4-scalable-cow-virt-pgoff-v4-3-ab318a350404@kernel.org> Precedence: bulk X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Sat, Aug 08, 2026 at 05:49:48PM -0700, Suren Baghdasaryan wrote: > On Thu, Aug 6, 2026 at 1:23 PM Lorenzo Stoakes (ARM) wrote: > > > > This function provides the anonymous equivalent of linear_page_index(), > > instead offsetting based on the anonymous page offset of the VMA. > > > > It is valid only for anonymous or MAP_PRIVATE file-backed mappings, in > > other words CoW mappings. > > > > For pure anon VMAs, this will be equal to linear_page_index(). > > > > Assert that both of these invariants are true In linear_anon_page_index() > > s/In/in Ack. I ran these patches through claude several times and it didn't get this ;) the machines are not taking over just yet... Andrew - could you change this in-place? Thanks! > > diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h > > index c6fc783aaee5..0adfa6605653 100644 > > --- a/include/linux/pagemap.h > > +++ b/include/linux/pagemap.h > > @@ -1094,10 +1094,44 @@ static inline pgoff_t linear_page_delta(const struct vm_area_struct *vma, > > static inline pgoff_t linear_page_index(const struct vm_area_struct *vma, > > const unsigned long address) > > { > > - pgoff_t pgoff; > > + return linear_page_delta(vma, address) + vma_start_pgoff(vma); > > +} > > + > > +static inline pgoff_t __linear_anon_page_index(const struct vm_area_struct *vma, > > + const unsigned long address) > > +{ > > + return linear_page_delta(vma, address) + vma_start_anon_pgoff(vma); > > +} > > + > > +/** > > + * linear_anon_page_index() - Determine the absolute anonymous page offset of > > + * @address within @vma. > > + * @vma: An anonymous or MAP_PRIVATE file-backed VMA in which @address resides. > > + * @address: The address whose absolute page offset is required. > > + * > > + * This returns the anonymous page offset of @address, which is the page offset > > + * the address possessed at the time the VMA was first faulted. > > + * > > + * For anonymous mappings, this returns the same value as linear_page_index(). > > + * > > + * For MAP_PRIVATE file-backed mappings, this returns the anonymous page offset > > + * of @address, which is the page offset the address possessed at the time the > > + * VMA was first faulted. > > + * > > + * It is not valid to call this function for shared file-backed mappings. > > + * > > + * Returns: The absolute anonymous page offset of @address within @vma. > > + */ > > +static inline pgoff_t linear_anon_page_index(const struct vm_area_struct *vma, > > + const unsigned long address) > > +{ > > + const pgoff_t pgoff = __linear_anon_page_index(vma, address); > > + > > + VM_WARN_ON_ONCE(!vma_is_cow_mapping(vma)); > > As discussed off the list, this assertion works even for read-only > anon mappings because, as you said, "there's no such thing as a pure > anon mapping that is !VMA_MAYWRITE_BIT, there is no way to achieve > that." > It took me some time to see that after reading your discussion with > David at [1] and [2], and I don't think it's very intuitive. Could you > please add a comment explaining that? Maybe add a comment at > vma_is_cow_mapping() definition since you are using the same assertion > in another patch of this series? Sure will do! It is very confusing stuff (and I was duly confused also at first). To save a respin (unless there's more stuff I need to address) I will probably reply to the relevant patch with a proposed new comment. > > [1] https://lore.kernel.org/linux-mm/anBjpdMicqaGADr-@lucifer/ > [2] https://lore.kernel.org/linux-mm/anLyhaI6kW-EWk13@lucifer/ -- Cheers, Lorenzo