From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 099FB32D441; Tue, 24 Mar 2026 07:33:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774337613; cv=none; b=er0EsgUmaimmKU9dJ6NcyyWD/zLANmNM/unLQTX9HnGCuFLcJ22y00SHNe9qzacDaMZpwqjl78N8NMiao1ok/Fw9SWNfZ+edu1zupASjjyJ8aCZD7r96Y4qdAX6vVFYvCdHCjq+WEktmWDZQLFxap2bt3cnnz+HzdA4NbI+wDzM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774337613; c=relaxed/simple; bh=WiAQ+4I4qCQUiHm0p1DT3+91TOXNEvDqdWg8BriPpVU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Ay4hPsOS2ifwkH1v62Hm+pYcbtriW24gkoc299ST5soCKnowlGMXaCPVheE7XBJze2mpDvZfe2OITt4I9doVZNpjvfm4ulEqhEr0NuIf1g11sJVCORFbWkkOFVfrR/LnMsmdFnPAHKXerRYJH9ROkjwMabKWxja42wFsz7i79Hs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h7MeUX3E; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="h7MeUX3E" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3A8AC19424; Tue, 24 Mar 2026 07:33:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774337612; bh=WiAQ+4I4qCQUiHm0p1DT3+91TOXNEvDqdWg8BriPpVU=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=h7MeUX3E5ObxKZv/m6SMsQ6+Qn/Q+4droqSYSjtzmAjVRLZMHdkcC1Fmlqj6wdwRc tWRh6IylSjCQCw8boOax0c+RR+4NNPjyfe3+/TQdEdV6vG3pM51qbkBaVG9Nbc7hFB gbVUpdHEYNWaivvAhpsaWyaRH7XlNgeP0tg4MH9kiqITI99O0PDmQcPPwqpQ5wYNdf MneSYJCmjPciXB/9rfk+wBCOU2cPRCsepDgmJGTfDBXLlIuj4T5xxtj6pvNcuHiI5I VvMrzaFJipLsfN+ttu87HcVJc4felWR4T97eM5Q5KhxiltgiTW/Nod0tWormPCNo0h 0cpQSQNVeaRfw== Message-ID: <47346263-ee56-4a78-b55d-7f28c617c673@kernel.org> Date: Tue, 24 Mar 2026 08:33:27 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm/memory: fix PMD/PUD checks in follow_pfnmap_start() To: "David Hildenbrand (Arm)" , linux-kernel@vger.kernel.org Cc: Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Peter Xu , linux-mm@kvack.org, Alex Williamson , Max Boone , stable@vger.kernel.org References: <20260323-follow_pfnmap_fix-v1-1-5b0ec10872b3@kernel.org> From: "Vlastimil Babka (SUSE)" Content-Language: en-US In-Reply-To: <20260323-follow_pfnmap_fix-v1-1-5b0ec10872b3@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 3/23/26 21:20, David Hildenbrand (Arm) wrote: > follow_pfnmap_start() suffers from two problems: > > (1) We are not re-fetching the pmd/pud after taking the PTL > > Therefore, we are not properly stabilizing what the lock lock actually > protects. If there is concurrent zapping, we would indicate to the > caller that we found an entry, however, that entry might already have > been invalidated, or contain a different PFN after taking the lock. > > Properly use pmdp_get() / pudp_get() after taking the lock. > > (2) pmd_leaf() / pud_leaf() are not well defined on non-present entries > > pmd_leaf()/pud_leaf() could wrongly trigger on non-present entries. > > There is no real guarantee that pmd_leaf()/pud_leaf() returns something > reasonable on non-present entries. Most architectures indeed either > perform a present check or make it work by smart use of flags. > > However, for example loongarch checks the _PAGE_HUGE flag in pmd_leaf(), > and always sets the _PAGE_HUGE flag in __swp_entry_to_pmd(). Whereby > pmd_trans_huge() explicitly checks pmd_present(), pmd_leaf() does not > do that. > > Let's check pmd_present()/pud_present() before assuming "the is a > present PMD leaf" when spotting pmd_leaf()/pud_leaf(), like other page > table handling code that traverses user page tables does. > > Given that non-present PMD entries are likely rare in VM_IO|VM_PFNMAP, > (1) is likely more relevant than (2). It is questionable how often (1) > would actually trigger, but let's CC stable to be sure. > > This was found by code inspection. > > Fixes: 6da8e9634bb7 ("mm: new follow_pfnmap API") > Cc: stable@vger.kernel.org > Signed-off-by: David Hildenbrand (Arm) Acked-by: Vlastimil Babka (SUSE) Should we also convert pgd_none() and p4d_none() checks to X_present() checks?