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 567D23C65EE for ; Thu, 19 Mar 2026 10:58:48 +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=1773917929; cv=none; b=NLzpYInWPDaJPPmntbj0T49TIKBX7TVWw847fmmSqih/878fBLmgVKWd+4HXC/ceTh650pCFqfL2bOldVHNqAjXOSpv1FaRE9n1bfyR0cGtjvFKwRZxFHXKrWHCwcGAbITPuoqUUbTOL8DQHNtcl6Z7vIsZ4TWY4fUuaT6iNV+M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773917929; c=relaxed/simple; bh=G4IGN215QkvAF0BgeVUwJVOFGBt23hN0qlN9K0glx6c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mFLRZEQgiwzq1+crXoqayTOdnPn8MqXZZBrvzvWJ3vQm3yMtCfUvL/3yHwRYS5DL8aBUCMDLM5UWpnh9gSOzinoKIsChqx678b4ekdWe2l8uKTeIG47TZhfZqF30FbKViFpG5ZV1VNUXyYBLR7qXwnv/ulgi2ZOaAnksB0x8rRM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F7Del1p6; 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="F7Del1p6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 744B3C2BC87; Thu, 19 Mar 2026 10:58:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773917928; bh=G4IGN215QkvAF0BgeVUwJVOFGBt23hN0qlN9K0glx6c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=F7Del1p6fgL9fUUqhXIf8URe5vpBMbMGeLFuK5fZU90T8Z0BXqCdaDrf8+W8Cpf3+ QywkuBqQb2kgaBrPix70vYwM1A4SP0AtjqQjcahw0dphnL9gsKq2kRjaKIOyzvOPC7 cMefUiNo9085lQW0nwVGa5WdUzRXa8S9pU/3GBqL0NOsgEflAWxxNYr7ppEg3Hf+mv F2O/lIMOcwp5ssF9+Dn1SQIq6GNO72/+kvqYouUJ+xyBhH3TgEbgONQgF6+j6Fc4R4 CrUZUR7WUA0MBd2w0/UPKcY06Br6ZCuupjP5wG7lc4yXfEyLBkwrgDjHzUOi0XeoPl kkz04/QFvVL3A== Date: Thu, 19 Mar 2026 10:58:41 +0000 From: "Lorenzo Stoakes (Oracle)" To: Baolin Wang Cc: Andrew Morton , David Hildenbrand , Zi Yan , "Liam R . Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 4/8] mm/huge_memory: handle buggy PMD entry in zap_huge_pmd() Message-ID: References: <8ffa393ad86b9b0ecd9b001ca88706ce2f9fe003.1773865827.git.ljs@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: On Thu, Mar 19, 2026 at 03:00:17PM +0800, Baolin Wang wrote: > > > On 3/19/26 4:39 AM, Lorenzo Stoakes (Oracle) wrote: > > A recent bug I analysed [0] 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() and exit indicating > > failure. > > > > [0]:https://lore.kernel.org/all/6b3d7ad7-49e1-407a-903d-3103704160d8@lucifer.local/ > > > > Signed-off-by: Lorenzo Stoakes (Oracle) > > --- > > mm/huge_memory.c | 4 ++++ > > 1 file changed, 4 insertions(+) > > > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > > index bba1ba1f6b67..8e6b7ba11448 100644 > > --- a/mm/huge_memory.c > > +++ b/mm/huge_memory.c > > @@ -2478,6 +2478,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); > > The warning looks reasonable to me, but ... > > > + return false; > > IIUC, if we return false here, the caller zap_pmd_range() will fall back to > call zap_pte_range(). Since pmd_trans_huge(pmd) returns true, > zap_pte_range() will simply return 'addr', causing an infinite loop in > zap_pmd_range(), right? You mean because: start_pte = pte = pte_offset_map_lock(mm, pmd, addr, &ptl); if (!pte) return addr; In any case it looks like it degrades a false to potentially carrying on forever: addr = zap_pte_range(tlb, vma, pmd, addr, next, details); if (addr != next) pmd--; So yeah, this should be a true, annoyingly. Will fix thanks! Cheers, Lorenzo