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=1795043793; b=CeSNg5OH/HMs67gQr49kKRalvraikPRLW0insEVc0tW8uihsa9D1fho+ktaXx7eje112 Vwi8YRc6hifzUYyTmzxIU2XM2lbtdyLM2Q7IGBs7FVrb/P1fvBeUt1+cMKHySWoizabfc s2uQIB7TMWvI99xryAYmDMvesiW5Gq0pO/+5plm9BwmGWir4cKhMqnZkgobUSX/KbqnQC MlVF4aMIqG7HpvR880EHLPGr/aTiE/xXvns73P2pN/QL03B/GNGVT2I/oSCVNbM6Gi27N fqtNG1/142d2soH38lLNbtQ8Z9eAuGJ44FPOlRP+JzjqS1PO/+TPzGhuIhoNPI4GHNQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795043793; 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=fNr33101vE835S1PYB+AbqoF24/SVV8q79M68B83RpY=; b=Bs7TeBMStYaqrxVCCHdA+RWzJhgBUPE7OER4p/FdpnfHt/2t2M+im3C6bsXWtypQV4go 1a0QNnhJ//VokBq+iUkLDCffBHuIvhVHgsOxFvPA7iAjs3d1/raCk6Q1NrqtBy7bg0L3M hlnlVMIWQ4kB8wZJkQUkMkFlB23cdhtM6KNCVy7AjwX4H6QuhtQBB+cW4bGwbGqXuK2KI Zpmkjsta2cRmVkptu6vE5r+hFcXxe9Rsb9FQWSkAldNO+bxRonAgVqOaMY5zAZuA5Aj0m yKEoU3SKyD6EVWHOxA/l0qGxy6i0nWGOJ9cpFB1ua+ayNjnsI1NfEMiDsVQKt922QGg== 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=B19x2ATg; 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 89A93606A33A; Wed, 18 Nov 2026 23:16:33 +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=B19x2ATg Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF7B81F000C7; Wed, 18 Nov 2026 23:16:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795043793; bh=fNr33101vE835S1PYB+AbqoF24/SVV8q79M68B83RpY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=B19x2ATgk2sdDL/kF94cFemkSvVvFLRoHeQbGGywa9mw0D0/hKmKNnrYQUE8rUNhm vdaBoctUexmdLBL5u9lxCN1iyONLMxNHC6S9k6jzC3P+oLo23hDVTFjg2JvMtt0607 yXJ83rV/Un2DXjWUdkJyWEka8R1BQHDCbbNXVV3w= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Dev Jain , David Hildenbrand , Muchun Song , Alistair Popple , Andi Kleen , Anshuman Khandual , Byungchul Park , Catalin Marinas , Dave Hansen , Gregory Price , Harry Yoo , "Huang, Ying" , Jann Horn , Josh Poimboeuf , Joshua Hahn , =?UTF-8?q?Junichi=20 Nick =20Nomura?= , Kiryl Shutsemau , Lance Yang , "Liam R. Howlett" , Lorenzo Stoakes , Matthew Brost , Mel Gorman , Naoya Horiguchi , Oscar Salvador , Pedro Falcato , Rakie Kim , Ralph Campbell , Rik van Riel , Ryan Roberts , Vlastimil Babka , Will Deacon , Zi Yan , Andrew Morton , Sasha Levin Subject: [PATCH 6.1 0338/2857] mm/rmap: use huge_ptep_get() in try_to_unmap_one() Date: Wed, 18 Nov 2026 15:22:52 +0100 Message-ID: <20261118150213.609199831@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150201.293410965@linuxfoundation.org> References: <20261118150201.293410965@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 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dev Jain [ Upstream commit f5407e9b697c940e78b27ff63c6e14d8d171adc3 ] Patch series "Fix incorrect access of hugetlb pte entries", v3. There are various places which use ptep_get() to get the pte entry corresponding to a hugetlb folio. Some arches (like s390) have special handling to compute the pteval, so they provide huge_ptep_get(). Use this helper consistently. Additionally, some code paths may provide huge_ptep_get with an unaligned address. This is a problem on arm64 (I checked other arches and it looks fine for them), which is fixed in patch 1. The fix is made to be backport-friendly: the cleaner fix would be to perhaps pass the hstate to huge_ptep_get() - that is wider churn and we can do that later. This patch (of 5): try_to_unmap_one() handles hugetlb folios when memory failure needs to replace a poisoned hugetlb mapping with a hwpoison entry. In that case page_vma_mapped_walk() returns the pte pointer to the hugetlb folio in pvmw.pte, but the code reads it with ptep_get(). On arches which provide their own huge_ptep_get() to dereference a huge pte pointer, accessing via ptep_get() would cause pte_pfn(), pte_present() etc to misbehave. It is not clear whether this has a trivially visible effect to userspace. Just use huge_ptep_get() for dereferencing a huge pte pointer. Link: https://lore.kernel.org/20260703114202.365553-1-dev.jain@arm.com Link: https://lore.kernel.org/20260703114202.365553-3-dev.jain@arm.com Fixes: c7ab0d2fdc84 ("mm: convert try_to_unmap_one() to use page_vma_mapped_walk()") Signed-off-by: Dev Jain Reported-by: David Hildenbrand Reviewed-by: Muchun Song Acked-by: David Hildenbrand (Arm) Cc: Alistair Popple Cc: Andi Kleen Cc: Anshuman Khandual Cc: Byungchul Park Cc: Catalin Marinas Cc: Dave Hansen Cc: Gregory Price Cc: Harry Yoo Cc: "Huang, Ying" Cc: Jann Horn Cc: Josh Poimboeuf Cc: Joshua Hahn Cc: Jun'ichi "Nick" Nomura Cc: Kiryl Shutsemau Cc: Lance Yang Cc: Liam R. Howlett Cc: Lorenzo Stoakes Cc: Matthew Brost Cc: Mel Gorman Cc: Naoya Horiguchi Cc: Oscar Salvador Cc: Pedro Falcato Cc: Rakie Kim Cc: Ralph Campbell Cc: Rik van Riel Cc: Ryan Roberts Cc: Vlastimil Babka Cc: Will Deacon Cc: Zi Yan Cc: Signed-off-by: Andrew Morton [ sashal: Reworked the hugetlb pte read to fit the older code, using huge_ptep_get()/ptep_get() into pteval for subpage and declaring huge_ptep_get(ptep) with one argument. ] Signed-off-by: Sasha Levin --- include/linux/hugetlb.h | 2 ++ mm/rmap.c | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 6b78a0f457d95..aa089e58bc41f 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -1199,6 +1199,8 @@ static inline void hugetlb_count_sub(long l, struct mm_struct *mm) { } +pte_t huge_ptep_get(pte_t *ptep); + static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) { diff --git a/mm/rmap.c b/mm/rmap.c index 8e74d143433ae..7c89abdabad50 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1531,9 +1531,14 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, break; } - subpage = folio_page(folio, - pte_pfn(*pvmw.pte) - folio_pfn(folio)); address = pvmw.address; + if (folio_test_hugetlb(folio)) + pteval = huge_ptep_get(pvmw.pte); + else + pteval = ptep_get(pvmw.pte); + + subpage = folio_page(folio, + pte_pfn(pteval) - folio_pfn(folio)); anon_exclusive = folio_test_anon(folio) && PageAnonExclusive(subpage); -- 2.53.0