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 ED5333B8BC9 for ; Mon, 30 Mar 2026 10:08:08 +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=1774865289; cv=none; b=i7c4GjwAI2SfgJ5rlBX5qkJQlf1V9Yf78jfLdbs4Kh4zSHYd8rtbA+qfuul1v9r+AKaHIiWPoXf1jUe0Tk/8h1pes0bV8L25rRUpRQUclQddg8hD8LxkmUzlg9NRqvuXNoGS8bnpyCS9fKdaLbh+vg6a+aD+9lEdDvbKw5XnSAM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774865289; c=relaxed/simple; bh=zSuk3YAaNeoWA1+jafoCnRALi+4LW8X0F4l7zk/vIdg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=u7VCkC+e2GNfYU9oBWt9t1AymhCP2XmvWdHwUM8RbHm8prbL/BlpIT69kPNooz0xHNaFGw9QTdpN7cJlKAlFmoaU+nncqMfARjgwHOx7d/CmfW8vfWK8GRUUn8ntoOP0cfcjI6UZC0Vb7fHYWNkBwgHKi+gNfZ3PWlcqQJ73taI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uZzBIToK; 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="uZzBIToK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC87AC2BC9E; Mon, 30 Mar 2026 10:08:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774865288; bh=zSuk3YAaNeoWA1+jafoCnRALi+4LW8X0F4l7zk/vIdg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=uZzBIToKXeQigJM8i1OsF+igq7IET4IErXdbLhvYE+FfHmcnV4Hhxw7mgurSKMGhS pHW/2ShcyHg+HYJJeWb2WaJGTLoZzwT6jYqB5BfM/oKExvqqmCSdk1cGics8iRFyWn n1IHvYOAKDChsT2Zdh+e0tk1uP6gGGcflNibyHm6g9lwPMDQOpoZmwAoHfb/1Lzwq8 TcV29cqHcxV6WqCDkfX+xGI06Z6CuJNZ61ro6OYAKD+bNsCsdE3ChNflvtJYnbOMtN mabZPAwnSoVs+L9fSr9+d1LULt/04ijBf9E9vLuO2hUwAB3k5omN62JHNgoO9MrJ0c 437As3WiQj0fg== Date: Mon, 30 Mar 2026 11:08:02 +0100 From: "Lorenzo Stoakes (Oracle)" To: Suren Baghdasaryan Cc: Andrew Morton , David Hildenbrand , Zi Yan , Baolin Wang , "Liam R . Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Vlastimil Babka , Mike Rapoport , Michal Hocko , Kiryl Shutsemau , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 04/13] mm/huge_memory: handle buggy PMD entry in zap_huge_pmd() Message-ID: <21d21f2f-addf-417b-a9f6-6458340761d9@lucifer.local> References: 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Sat, Mar 28, 2026 at 12:05:08PM -0700, Suren Baghdasaryan wrote: > On Fri, Mar 20, 2026 at 11:07 AM Lorenzo Stoakes (Oracle) > wrote: > > > > A recent bug I analysed managed to, through a bug in the userfaultfd > > implementation, reach an invalid point in the zap_huge_pmd() code where > > the PMD was none of: > > > > - A non-DAX, PFN or mixed map. > > - The huge zero folio > > - A present PMD entry > > - A softleaf entry > > > > The code at this point calls folio_test_anon() on a known-NULL folio. > > Having logic like this explicitly NULL dereference in the code is hard to > > understand, and makes debugging potentially more difficult. > > > > Add an else branch to handle this case and WARN(). > > > > No functional change intended. > > > > Link: https://lore.kernel.org/all/6b3d7ad7-49e1-407a-903d-3103704160d8@lucifer.local/ > > Reviewed-by: Baolin Wang > > Signed-off-by: Lorenzo Stoakes (Oracle) > > Overall LGTM, just a question below. > > Reviewed-by: Suren Baghdasaryan Thanks! > > > --- > > mm/huge_memory.c | 4 ++++ > > 1 file changed, 4 insertions(+) > > > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > > index 3c9e2ebaacfa..0056ac27ec9a 100644 > > --- a/mm/huge_memory.c > > +++ b/mm/huge_memory.c > > @@ -2385,6 +2385,10 @@ bool zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, > > > > if (!thp_migration_supported()) > > WARN_ONCE(1, "Non present huge pmd without pmd migration enabled!"); > > + } else { > > + WARN_ON_ONCE(true); > > + spin_unlock(ptl); > > + return true; > > Apologies if this was already discussed in earlier versions but why do > we return "true" for this case which would be interpreted as > "success"? Perhaps because we still managed to do > tlb_remove_pmd_tlb_entry()? If we return false it can result in a potential loop in the caller I believe. Basically the caller won't handle this case properly. It was raised on review, previously I was returning false :) > > > } > > > > if (folio_test_anon(folio)) { > > -- > > 2.53.0 > > Cheers, Lorenzo