From mboxrd@z Thu Jan 1 00:00:00 1970 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F3057C5AC82 for ; Mon, 10 Aug 2026 08:40:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4B9D010E72B; Mon, 10 Aug 2026 08:40:23 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="JKo9vEdD"; dkim-atps=neutral Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9623A10E727; Mon, 10 Aug 2026 08:40:21 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 4969543BC1; Mon, 10 Aug 2026 08:40:21 +0000 (UTC) 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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" 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