From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (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 DF3E13D1702 for ; Fri, 10 Jul 2026 21:27:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783718829; cv=none; b=J1uoTI8ssGLHrIi0TzPJXtDv4oaldRzgI6I80c5S5ZcHUVR4RiLCHhDsq4sGTTG2p+keVaEsGTKv10YMlQeHJWcsCu8qKEDAsPlD0cb9uj/PKNQ3EhBQjpnzcnL/iLwv8j2/SpqQgpxhBe5ToRgS3dl8NX1i1YhL3XgiJGX5OQU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783718829; c=relaxed/simple; bh=WA59mEPQS2KZpz5hwZRIhAuqwWCApokXv9AsxSKOvQ4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kVDhtWstUGe8ZWSvdGDyrqlznz/GbkkfWfnCFQPKwKSCMs9jpOMMqPzHRu5OVf8YGIIh3YKWvJa72cvSsWbPB2hmdx1UFWrCxXn2PHacGPzY6AvT7B11+FZz9D1mdtyeWdcGpgOARh+bpMbSWpS1cfrl76aw/NxGiUkWoYgcXX8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=nhYo0OJh; arc=none smtp.client-ip=209.85.222.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="nhYo0OJh" Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-92e65e18969so106584785a.1 for ; Fri, 10 Jul 2026 14:27:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1783718826; x=1784323626; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=oXHpiDgBaIEeQKnuJdWSZ8rFz2G2XIdWbRFpuwAJIiw=; b=nhYo0OJhcjieVg+GLl0VaGACf2wtApb6p5NFoPYfJ3MFB81Uk0jAT93VGbHD/HYzFx x0iIlnHKm+fPHeNvTkVRG+kydtCkqPqdRQjIzjZK4+F6R7+zS4vdg5Eiq37/IA0jTvim MWPOtrLGN6TsW5SBj2HQjmjOht63fZLw/WSbMPV+QOplWYLd/Fg26t1gz4Lw6jXPqkEZ 6jJwsPu8eyupguGAmDz/agVlqsi3IeXJw1+TLWsvJjCKG8m06B26W6DrWPV5AjCUSLRD mTxzsXm6lp6swrGkIhY4q6XvE3FhBpZmFy6EutES3L0lQJrwD8S0oXfy7XwNV5XXViRT klXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783718826; x=1784323626; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=oXHpiDgBaIEeQKnuJdWSZ8rFz2G2XIdWbRFpuwAJIiw=; b=UXy7MHAClpFJ1hWHs1iSM407xrHl+JDxtDgDW44/G22u5+syQXwBsYllqSYNpJy176 ho3MXhVm9zz1xGMGUAzJ3sYJ81S07CkvCpZM5BGbdZvD8FsIZsTWCfNN7FaaALDT6u67 ZlNIpiu+hlmXG/EJMHnWiJx9x7oDqhsPN99HyIrSfsMMPOMBx8xTgm+OPH9LkBKzSlo3 ho1wXU4Wf3MCQ/HPCxUOzT4AoekblbuuU83bT1cIe9avHGXe6bmpADHnasoExbSWPdKO uuyiOn2iIthw0inzHsTzz4gbdOAN2Fo+v9ZL0xclliUEGPNcKAqSjYkdMP9521Z89ymW TaxQ== X-Forwarded-Encrypted: i=1; AHgh+Ro+CE2nQLdr7/RBuqjxKJ3FXGUbJ6o8mWptFfncjBatQuDoaeuU4aEqbuDUkTsEadA6VTei3hb2DGOPMck=@vger.kernel.org X-Gm-Message-State: AOJu0YzlxYycDjgDn+QC2FMWMkqPJkMAmCT/H1sJy6h1T1P0e2L3f7JO qHPDLAHz07gR9hJ4j3a/DkfiRQ+ge8/miG56DwJgKfoUeyLG0piERDSlKQ90kPTg540= X-Gm-Gg: AfdE7cleXxP/YPxyfMtMwfXc/NLI0Ne4plR/bfKGLZ+nTYcUzOIQ6/vRM4aNB/Opk62 4LCUN3iTXB6Q4zFXB18HA+wbUwSuuSoUH2rwVJcBUWPqlyZqiCb1vsr94JKIETYz2cbXUQbfVNp yqQM14KkyXx1ZmXozeWfmAvfxDMZjDUK99qGg8553aimm39LFxsoTYzD8PA3WhHjLMIDM8+7gNa VyUAMepLOEsa9ZRpdgwb1O3IHroJrihS2mhYPfFqz3QLRYElYG51AXAF88pzmflDyq2SFaWrUp/ wYtnuP/n9byKigsWYpFj/Bf3YyFvLok9uy2vfO6wn4W2yjcSy5TBzW+RMiV+XEdQzhe5zRTcTKE /H80HOpB1YkXeJGBqr4Paj76tqV1GizXm9JqGPppDfw3rTVoGgkyG8DMjena8kvM8vEyZ9tYq8a n9zIZE6kVLQUp4jtj4cc8DvVqfaCTC/e25bAIJdNSGsSVjzLRreXxXjcVAiERPaNtTpAKS X-Received: by 2002:a05:620a:4008:b0:92b:856f:3c14 with SMTP id af79cd13be357-92ef3d1792cmr55468485a.11.1783718825767; Fri, 10 Jul 2026 14:27:05 -0700 (PDT) Received: from gourry-fedora-PF4VCD3F (pool-173-79-60-52.washdc.fios.verizon.net. [173.79.60.52]) by smtp.gmail.com with ESMTPSA id af79cd13be357-92ee5d2d68bsm289148485a.33.2026.07.10.14.27.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2026 14:27:04 -0700 (PDT) Date: Fri, 10 Jul 2026 17:26:59 -0400 From: Gregory Price To: Lorenzo Stoakes Cc: Andrew Morton , David Hildenbrand , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Rik van Riel , Harry Yoo , Jann Horn , Lance Yang , Pedro Falcato , Russell King , Dinh Nguyen , Simon Schuster , "James E.J. Bottomley" , Helge Deller , Alexander Viro , Christian Brauner , Jan Kara , Dan Williams , Matthew Wilcox , Muchun Song , Oscar Salvador , Masami Hiramatsu , Oleg Nesterov , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Thomas Gleixner , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Ian Abbott , H Hartley Sweeten , Lucas Stach , Christian Gmeiner , David Airlie , Simona Vetter , Patrik Jakobsson , Maarten Lankhorst , Shameer Kolothum , Kevin Tian , Ankit Agrawal , Alex Williamson , Paolo Bonzini , Shakeel Butt , Usama Arif , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-parisc@vger.kernel.org, linux-fsdevel@vger.kernel.org, nvdimm@lists.linux.dev, linux-perf-users@vger.kernel.org, linux-trace-kernel@vger.kernel.org, damon@lists.linux.dev, iommu@lists.linux.dev, kasan-dev@googlegroups.com, linux-sgx@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, linux-tegra@vger.kernel.org, kvm@vger.kernel.org, Russell King Subject: Re: [PATCH v2 29/33] mm/vma: introduce and use vma_set_pgoff() Message-ID: References: <20260710-b4-pre-scalable-cow-v2-0-2a5aa403d977@kernel.org> <20260710-b4-pre-scalable-cow-v2-29-2a5aa403d977@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260710-b4-pre-scalable-cow-v2-29-2a5aa403d977@kernel.org> On Fri, Jul 10, 2026 at 09:17:10PM +0100, Lorenzo Stoakes wrote: > In order to lay the foundation for work that permits us to track the > virtual page offset of MAP_PRIVATE file-backed mappings, we abstract the > assignment of vma->vm_pgoff to vma_set_pgoff(). > > We additionally add a lock check here using the newly introduced > vma_assert_can_modify(). This asserts the VMA write lock if the VMA is > attached. > > We also assert that, if this is an anonymous VMA and unfaulted, that its > (virtual) page offset is equal to the page offset of the VMA's address. > > We must be careful about MAP_PRIVATE-/dev/zero which violates fundamental > assumptions about anonymous memory, so we check for !vma->vm_file after > using vma_is_anonymous() which these mappings satisfy. > > Additionally, we only perform the assert if CONFIG_MMU is defined, as nommu > does not set vma->vm_pgoff = addr >> PAGE_SHIFT. This isn't really relevant > to rmap as it has no anon rmap (nor needs it), but we must avoid it > asserting falsely. > > All of this logic is kept in assert_sane_pgoff() to keep things clear. > > In order to maintain correctness given this assert, we also update > __install_special_mapping() to invoke vma_set_range() after it's set > vma->vm_ops (which determine whether the VMA is anonymous or not). > > We do not use vma_set_pgoff() in vm_area_init_from(), as at the point of > forking, we don't necessarily have correct locking state. > > Updating vma_set_range() covers most cases, but in addition to this we also > update insert_vm_struct(), compat_set_vma_from_desc() and nommu callers. > > We also update vma_add_pgoff() and vma_sub_pgoff() to use vma_set_pgoff(). > > While we're here, we drop a BUG_ON() and update insert_vm_struct()'s > comment to reflect the fact anonymous mappings can be added here. > > Finally, we update the CONFIG_MMU, CONFIG_PER_VMA_LOCK defines in the VMA > userland tests so IS_ENABLED() will work correctly with them. > > No functional change intended. > > Reviewed-by: Pedro Falcato > Signed-off-by: Lorenzo Stoakes carry-over from v1 Reviewed-by: Gregory Price