From nobody Tue Dec 16 14:34:25 2025 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 E3EFD23D7C7; Fri, 5 Dec 2025 21:36:12 +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=1764970573; cv=none; b=ceCrSXlI6p1yEJiBrfuiXDefRvePMG+UEFOjJFS6/h2Xibx4gRw6DU2J8uQF7JYfCU41popLBD6VadxcWdWzrHAeA0UD77Tp0t52UAv58EJfhdEAZSWeZ0JwOPH9pRIPlyFW4xam4ozCwDqm5TwkaYVv/5FR3dUsdRi8OlXtfNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764970573; c=relaxed/simple; bh=8+3PE0lZoghyFccjBGOORkbaZfzCOnFQSwGHJ0dG7Nw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OUuK3B5H1mLciX7ihkVSHcfLPlMn3XMeBNw1LlWkIyWS7odnwe2mvbhoIkkU6xTsZLyODO6RzdLMhEfiAiqxdAnzDRmeTtaI0yZL0gog7qcqKnfMSNAPwX+/a7aQCX7Dmf0uCMaPB34bYD7ZVG16a2tVoI2ToLziNbPHew2p8nU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TQScRciw; 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="TQScRciw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC0B6C116B1; Fri, 5 Dec 2025 21:36:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764970572; bh=8+3PE0lZoghyFccjBGOORkbaZfzCOnFQSwGHJ0dG7Nw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TQScRciweFV75igopSCBmTYjX821Laicmf3q6LqdAmvGFsMgieDUeLyMJKTNyrRYe 14C+OFiYJOluVspijOX35hj+jk8gyjZ59Ucz+6I4aQOZatMBrZQKLb+dZyy37FM+S/ YQTpa+5Kzde0Anbrnzy++QjCyc3np0ZFFzQId6uUmAEctUdV3ytc4Wh9Wb4zdtwEjx sYRJpo0fxMhOISmPIQ36l4iU5dNKgMl8rWuJEPCumdeuzFoCfChdaJf1O0usLZNWZ8 QbSSqVSFC7cYd0iLNCZBRVhF6exH3C7y65890AB0OCZX4t68AhGw904+jMXiEQBY36 FSZreQdP747uw== From: "David Hildenbrand (Red Hat)" To: linux-kernel@vger.kernel.org Cc: linux-arch@vger.kernel.org, linux-mm@kvack.org, "David Hildenbrand (Red Hat)" , Will Deacon , "Aneesh Kumar K.V" , Andrew Morton , Nick Piggin , Peter Zijlstra , Arnd Bergmann , Muchun Song , Oscar Salvador , "Liam R. Howlett" , Lorenzo Stoakes , Vlastimil Babka , Jann Horn , Pedro Falcato , Rik van Riel , Harry Yoo , Laurence Oberman , Prakash Sangappa , Nadav Amit , stable@vger.kernel.org, Liu Shixin Subject: [PATCH v1 1/4] mm/hugetlb: fix hugetlb_pmd_shared() Date: Fri, 5 Dec 2025 22:35:55 +0100 Message-ID: <20251205213558.2980480-2-david@kernel.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251205213558.2980480-1-david@kernel.org> References: <20251205213558.2980480-1-david@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We switched from (wrongly) using the page count to an independent shared count. Now, shared page tables have a refcount of 1 (excluding speculative references) and instead use ptdesc->pt_share_count to identify sharing. We didn't convert hugetlb_pmd_shared(), so right now, we would never detect a shared PMD table as such, because sharing/unsharing no longer touches the refcount of a PMD table. Page migration, like mbind() or migrate_pages() would allow for migrating folios mapped into such shared PMD tables, even though the folios are not exclusive. In smaps we would account them as "private" although they are "shared", and we would be wrongly setting the PM_MMAP_EXCLUSIVE in the pagemap interface. Fix it by properly using ptdesc_pmd_is_shared() in hugetlb_pmd_shared(). Fixes: 59d9094df3d7 ("mm: hugetlb: independent PMD page table shared count") Cc: Cc: Liu Shixin Signed-off-by: David Hildenbrand (Red Hat) Acked-by: Oscar Salvador Reviewed-by: Harry Yoo Reviewed-by: Lance Yang Reviewed-by: Lance yang Reviewed-by: Lorenzo Stoakes Reviewed-by: Rik van Riel Tested-by: Lance Yang --- include/linux/hugetlb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 019a1c5281e4e..03c8725efa289 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -1326,7 +1326,7 @@ static inline __init void hugetlb_cma_reserve(int ord= er) #ifdef CONFIG_HUGETLB_PMD_PAGE_TABLE_SHARING static inline bool hugetlb_pmd_shared(pte_t *pte) { - return page_count(virt_to_page(pte)) > 1; + return ptdesc_pmd_is_shared(virt_to_ptdesc(pte)); } #else static inline bool hugetlb_pmd_shared(pte_t *pte) --=20 2.52.0