From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794585715; b=JENjXSra/wRRMe5r08UcmR7LB1L+dk6jagQOQRqI7JJIqsgByMb5rnNErTpNlLqAOd1L DeiwQk3zg6opixlJ6q/m9C+j6CDr2eN0IH2U8/c1RkXC3MVhGcxF/KyeoZWDEAejlvvVY yjPfatWOlgTjC5intCz//OZKwBJrUSB8oUNS73sZ5JWaOO4joHFDqNm8vBlEoD+6R0kMd Z5dOi+iJsQjRpHHGxc93C0+1yKufkBCvO7C49zB3Kytsysi32eBqyWtss3zaQruZYehP4 Y9bHXU0Sl5ylCcA2J9D/bPspNoUc18WmiB0jdkhW8k2s6xO+PJ7CC1AEyPnKw1QHhug== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794585715; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=430EnprLnPoA7Iesg+HSjwdzifkDOravzBuPENRjHgI=; b=kgvS6kF7w2JXSzANVNRWhbpHNIhOjWnSilrHQBzIXWk7V3sz/Fj6vAwA3S5IDZcNCJAk RMdlA01fjdcLDC0suOlxwGMbHBtZ7VdX+j67JcuMW0ShR1RYAUcN/jAhYb50IE1K/2uUn VLXla6z0ROgnhe6EQay183aLjS/J3/xiUp7Olv7bwMLf6VTILVL6Tq3KDJ6IOFFyN0ZdP KsT1b4ifBfAPbg7aj/HvhqDmxSVdbHdujQMwuf6nMIk/huZwmLK8GQBYCty3ncM3pSDan kqLAbnfeHc/8sUK6ArfNH6pW9vWWs+bZfHxlcNVQxNPaLv1wKGmPElbtrqbX2DBTxHg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Y0O2120b; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 474D760A383B; Fri, 13 Nov 2026 16:01:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Y0O2120b Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC98C1F000C5; Fri, 13 Nov 2026 16:01:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794585715; bh=430EnprLnPoA7Iesg+HSjwdzifkDOravzBuPENRjHgI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Y0O2120bwDRimK1zBRvyrvLiP1p1VQqQNUzknAd6FXO7e2gicAi8bP691qSI5qg6p HAfy3fWJWgnM0/XTRiYIAYHPEnCFqzBPwQFHCHC4M2RzAyw6Sbry8oMr5kTrgHDRFv blinvm4wZVD3yjUkeu1u2GzZ5JWuD4eldHCQeRwY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Lorenzo Stoakes (ARM)" , Pedro Falcato , Muhammad Usama Anjum , Lance Yang , "David Hildenbrand (Arm)" , Sasha Levin Subject: [PATCH 7.3 317/507] mm/mremap: recheck PUDs under the page table lock Date: Fri, 13 Nov 2026 10:50:21 -0500 Message-ID: <20261113153806.168579035@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261113153753.358973689@linuxfoundation.org> References: <20261113153753.358973689@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Hildenbrand (Arm) [ Upstream commit 402882943dfa8bab5c2bcc66189f9fb2828f248e ] Once get_old_pud() is fixed to accept PUD leaves, unmap_mapping_range() can clear a leaf between the lookup and the move. Holding mmap_lock in write mode does not prevent this. If the zap happens before move_page_tables() tests the entry, an empty PUD can reach move_normal_pud(), where pud_populate() turns it into a present page table entry. If it happens after the test, move_huge_pud() can instead try to move an empty entry, triggering CONFIG_DEBUG_VM warnings on powerpc. Recheck the source under the page table lock in both helpers. Treat an empty source in move_normal_pud() as a completed move, and use __pud_trans_huge_lock() in move_huge_pud(). In the future we should likely have the code lookup a PUD/PMD lockless once, instead of multiple times, because one of the problematic bits here is the: pud_trans_huge(*old_pud) Fixes: 0881ace292b6 ("mm/mremap: use pmd/pud_poplulate to update page table entries") Cc: stable@vger.kernel.org Reviewed-by: Lorenzo Stoakes (ARM) Reviewed-by: Pedro Falcato Tested-by: Muhammad Usama Anjum Link: https://patch.msgid.link/20261031-fixes_core-v3-31-d6437171ecc3@kernel.org Reviewed-by: Lance Yang Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Sasha Levin --- mm/mremap.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mm/mremap.c b/mm/mremap.c index 961569eaa8d7c..fd4da262ea13c 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -461,14 +461,18 @@ static bool move_normal_pud(struct pagetable_move_control *pmc, if (new_ptl != old_ptl) spin_lock_nested(new_ptl, SINGLE_DEPTH_NESTING); - /* Clear the pud */ pud = *old_pud; + if (unlikely(pud_none(pud))) + goto out_unlock; + + /* Clear the pud */ pud_clear(old_pud); VM_BUG_ON(!pud_none(*new_pud)); pud_populate(mm, new_pud, pud_pgtable(pud)); flush_tlb_range(vma, pmc->old_addr, pmc->old_addr + PUD_SIZE); +out_unlock: if (new_ptl != old_ptl) spin_unlock(new_ptl); spin_unlock(old_ptl); @@ -503,7 +507,9 @@ static bool move_huge_pud(struct pagetable_move_control *pmc, * We don't have to worry about the ordering of src and dst * ptlocks because exclusive mmap_lock prevents deadlock. */ - old_ptl = pud_lock(mm, old_pud); + old_ptl = __pud_trans_huge_lock(old_pud, vma); + if (unlikely(!old_ptl)) + return false; new_ptl = pud_lockptr(mm, new_pud); if (new_ptl != old_ptl) spin_lock_nested(new_ptl, SINGLE_DEPTH_NESTING); -- 2.53.0