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 2EF81442133 for ; Wed, 15 Jul 2026 10:36:29 +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=1784111790; cv=none; b=RlaWpSpbHWoCxxaGBbdMaYFfgMH99CBcbJ6CSMH3S/EsfRWzqQ3s7F8fAalS/eNvmU5ySahgucYpXggYDgw32zRMBAtnnOatAizx1CSIs5nyLplY+/72vhTgv+gh5DM5L98Tg8prQTWK/NVa2KokhV0ZO0sxXj7OMs/j2KfeCYE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784111790; c=relaxed/simple; bh=/aq+i8O9CzJ+ZmRHBaY9TyImuS1xwSYnvShsBnrjxso=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QCqHSDqxNmjtU7nkT40lXBa+4diy7Gk/z+daEzAsQMo7upOW0RX3srDecpyWuu4zoRN2Ak9gdZfaCXEs690NiupLuLd7MOEUuXIKeguMYBc9bn69RIk733qxp9M5SmI4VfuKkm0VL5+qypjlV4R2sUWw1AiPvMFIikIQbfiIotA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bnZ19469; 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="bnZ19469" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C2E31F00A3A; Wed, 15 Jul 2026 10:36:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784111788; bh=SGc4wLtrcKFcbhoINTj74T+3qOdK6ANKsLr4fj0Hk3A=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=bnZ19469YhZeYDpeyL6D0njcuIEVUlNV8xaZPdx4Wv2g2llZ6KtIs3UIIygTumOUb l+cwxB2A7PICphDlPyE6wZMdhDFkKKg9q3moF6U2KyrAKXqsJOj1Flv6eRw9MyEwIH tJhhbkMpCk/YNyTzBBc4IpTn5DdrSJkLQkQumDOOtPhXPcynGpZzHE102rOWo7LD5N 56o74i5t2pPRwvzSNAe2e1169ofKYjMwkuSx1lceloXmCtqpot1iqEGOPw4IIqQs4/ 1uXVxKHAcXoKlqg7CbUCFymnbWnw6NeGNkQC/idZnGatxcK3lT1HA9DEFeX3/sgL0e pluXygxbaYEIg== Received: from phl-compute-11.internal (phl-compute-11.internal [10.202.2.51]) by mailfauth.phl.internal (Postfix) with ESMTP id 66559F40066; Wed, 15 Jul 2026 06:36:27 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Wed, 15 Jul 2026 06:36:27 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFoH2pQZa2MB7F8P1KNkzYrZ2FYupTRLNJuIuUdKMkzQz8rOl/YdOFBjeV64/eFiz grneVbhOZ/mzsgLWmb97Z2MXlENOxDXRl0cjegtXKlxj7YYlu4P2rypydA+jQG17m5ZjrR uLA1BH2IYxm64puaRDdrEUMLMhexkcckKs1sEKyml2zpBfIOSacHHPCSa4mrPwXtsA2S2d n0AJWgO4Aw1zfMMWmrVVxIux3bA1rGhvs7yymGF6naIGts5DplcBRYFDrF2cdeaP8bZG8h uqCwtISn/RjBCphxWoCiq60O2Gpp2nzA6uqQaHx3NgXSiS8IQjohJzFr1kWpEVdFieI5W+ zSj+F2tRIKbdZ2G88GOn9AR08ypKHMcQnabYwnXiXOn5vdgj+TTtPEjU77Mr2BjBI6Urjw 1vmC7n/u6OnMBgowj8zJPICTT4s5l+RuxGFGLXG0NLSHoz4timfc4hGSlksoUVvKCK3QUn RativehZ1FvH6M7cZDGxQzTgn3rOMiMnL7PWTwdxApBc83z7CgVqOahJ9cYkPoN2O0N7no Uk56UlfKVpn5B5rZ9K92JX11zIjWvcbS3QkUU2KCY1FkHuzb23XDwrGqdb2unwf6VuN9av S+AKROKDhvXXTxODKw/rsrmVUYvXwVOH78t1sU2BP4CBslU/925LAlXUL9+w X-ME-Proxy: Feedback-ID: i10464835:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 Jul 2026 06:36:26 -0400 (EDT) Date: Wed, 15 Jul 2026 11:36:25 +0100 From: Kiryl Shutsemau To: Lorenzo Stoakes Cc: Andrew Morton , Suren Baghdasaryan , "Liam R. Howlett" , Vlastimil Babka , Shakeel Butt , David Hildenbrand , Mike Rapoport , Michal Hocko , Uladzislau Rezki , Toshi Kani , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Catalin Marinas , Will Deacon , Dev Jain , Ryan Roberts , David Carlier , linux-mm@kvack.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, stable@vger.kernel.org Subject: Re: [PATCH mm-hotfixes v3 3/4] mm/ptdump: always stabilise against page table freeing using init_mm Message-ID: References: <20260714-series-vmap-race-fix-v3-0-b812eccfa0f9@kernel.org> <20260714-series-vmap-race-fix-v3-3-b812eccfa0f9@kernel.org> Precedence: bulk X-Mailing-List: bpf@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: <20260714-series-vmap-race-fix-v3-3-b812eccfa0f9@kernel.org> On Tue, Jul 14, 2026 at 06:24:25PM +0100, Lorenzo Stoakes wrote: > Previous commits have established the invariant that kernel page table > freeing is performed while an mmap read lock on init_mm is held, which > fixes races between ptdump and kernel page table freeing over init_mm. > > However, x86 and arm64 can perform a ptdump over an mm other than init_mm > via ptdump_walk_pgd() and since kernel memory ranges are shared across > non-kernel mm's, this means that the race still exists for these cases. > > Fix this by acquiring a nested mmap write lock for init_mm in > ptdump_walk_pgd(). > > This is safe as we take this after mmap write locking the mm, and nothing > acquires the init_mm lock first before locking an arbitrary mm, so no > deadlock is possible. > > Also update walk_page_range_debug() to assert that init_mm is write locked, > add a comment explaining why and remove some redundant code, and eliminate > the unnecessary and confusing invocation of walk_kernel_page_table_range(). > > We can safely remove the non-NULL check for walk.mm, as the mmap lock > asserts would NULL pointer deref if it was (and of course no callers do > this). > > The first point at which ptdump can race kernel page table freeing is > commit b6bdb7517c3d ("mm/vmalloc: add interfaces to free unmapped page > table"), so we target this in the Fixes tag. > > Fixes: b6bdb7517c3d ("mm/vmalloc: add interfaces to free unmapped page table") > Cc: stable@vger.kernel.org > Reviewed-by: Mike Rapoport (Microsoft) > Signed-off-by: Lorenzo Stoakes Reviewed-by: Kiryl Shutsemau Thanks! -- Kiryl Shutsemau / Kirill A. Shutemov