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=1796298169; b=bj809xeUsXAH/LhBjUj0BfCzepzxiPJHWhXkc07ZESRpcGbPJ8vntkWC0SmIu5ZZY4ep 79nNnysdpHnspaSytLS0YGhzzhaD0uaOTQD2gQIQnr9ECTbS26h3FlyHDLQPGDs5IzNZf eJfPondHB5ILkq/0rt4DA5/x7i5t5FR580mj7b+21ghvnZcByp/3wD8zb6UtOO/62xeNn 9xgpQffcxU0YLYwOYkfRP5XNUMjoFMsv84uMqKgiFW2z7yRMdq4Hc6frNywvgBHiWzkO/ O9NB6NGUbRzq/ddJI2qJJnmNvjKwMC/yUTiNAJmc/wlPQXBz0jHEk7xin4GHumUN0Hw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796298169; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=S1WjgDyi48GfByx+3khLaAqVFtChzCMum2jdBZPs+go=; b=EyU3HIubPn1lzAlyWyfFtIBv0S2GwpUkWrDB2Buj9P15k683/1dWpdW9p7w/G+37cHA5 1v2pGAiAEcyxOhkO93BI1jmHrWDufIQT7fdRnf9IzKwbQeKIHgbIGDxMN895NfSLRvFtb tBggt5nMNTEyjEdg9C8qV80eiiY5PIouw4oDxFgdoLt+9gRJ39UeLr7YwxSoipU4uaExd Kq3HFTTL74MJ3egElZzOAwQO1/xX17sIlWL9wpQdapP2k9Y0RGrv8St65ndMfh0EjK8lS 3VVFDb8+FqbEEqlji8p/Z3k5w+vDEBctSY6t7E+jxLDbmrU47AF2bv4t1Nu0q73iDIw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NbvA1kRT; 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 DB3D3606A335; Thu, 3 Dec 2026 11:42:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NbvA1kRT Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F89E1F000C1; Thu, 3 Dec 2026 11:42:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796298169; bh=S1WjgDyi48GfByx+3khLaAqVFtChzCMum2jdBZPs+go=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=NbvA1kRTSksvW3Dp6WPwH0R1yLaXGD0tVLwsqf4swwTYYcEh3KTWhbvoFlEKQR2jv E+qs2L6UBwob7/ILXaI1ytLv5o+wFjPpeGXXsDHhzcqf6gRZXAyDbpKZE+41WWq0e+ yenUr1f1IwJJCR4RtpctPWAgYBi9byEoY0x0Q3E8pRagAVaU5RQX4pWc1H5ELKIhxR disKOuvFzYblW/qQng3tlacuN51KBOHsbMA0GyWX0O9L7UetgNGdNiarW6uAkXhOs6 W5PgSP1jWbzjF5WAFyB9XwrFRB4b++0U3Fih0Rk0/nYtw3XAtUncfwVDnmwUen8C/g eI/5gKQMMn/fA== From: "David Hildenbrand (Arm)" Date: Thu, 03 Dec 2026 12:37:43 +0100 Subject: [PATCH v2 20/35] mm/hugetlb: don't zap non-present entries when unmapping a folio X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261203-hugetlb_fixes_2-v2-20-9bbeabb555d2@kernel.org> References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> In-Reply-To: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> To: Muchun Song , Oscar Salvador , Andrew Morton , Hongfu Li , Jinmeng Zhou , Mina Almasry , Davidlohr Bueso , Naoya Horiguchi , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Michal Hocko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Vivek Kasireddy , Mel Gorman , Hugh Dickins , Baolin Wang , Dave Airlie , Jason Gunthorpe , Andy Whitcroft , Roman Gushchin , Barry Song , Andrea Arcangeli , Lorenzo Stoakes , Suren Baghdasaryan , Shakeel Butt , Pedro Falcato , Jann Horn , Guillaume Morin , Yang Shi , James Houghton , Rik van Riel , Harry Yoo , Lance Yang , Axel Rasmussen , Peter Xu , Sasha Levin , Kiryl Shutsemau , Christian Brauner , "Steven Rostedt (Google)" , Hongbo Li , Gregory Price , Zi Yan , Joshua Hahn , Rakie Kim , Ying Huang , Matthew Brost , Byungchul Park , Alistair Popple , Andi Kleen , David Rientjes , Joern Engel , "Aneesh Kumar K.V" Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, Gerd Hoffmann , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Johannes Weiner , Chris Mason , Jiaqi Yan , "David Hildenbrand (Arm)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1920; i=david@kernel.org; h=from:subject:message-id; bh=nMEW2YTap+8rJF7UkUT3IMEXOshLb0uGQpyK3ytQDoM=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIFQ2qYIg4Itkuy9wvIHzeMaLs+58Ss48F3F2j8FrQ8Y nLyHnNoRykLgxgHg6yYIktQ8H2Dly/X1Va78THDzGFlAhnCwMUpABOZqMjwP+d0Y1mwsVjs4UhR yQhHRbdT8tIrDC+x32h7I9lzw5TvCsP/wnmaU8088yV/fey6rBKUYmQhY5pm36EsWizFczzBlZ0 RAA== X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A From: Chris Mason When the owner of a private hugetlb mapping fails to allocate a folio for COW, unmap_ref_private() unmaps the old folio from the forked children, and marks them with HPAGE_RESV_UNMAPPED, so they get a SIGBUS on their next access. hugetlb_unmap_range() is supposed to only unmap that folio, but it clears non-present page table entries unconditionally. A child can silently lose its COWed folio while it is getting migrated, or a hwpoison entry or uffd poison marker, without HPAGE_RESV_UNMAPPED getting set. Consequently, it would not SIGBUS on the next access. Let's fix it by ignoring non-present entries when unmapping a folio. As the folio is locked, migration entries of that folio do not apply. This has low urgency, as it requires a failing COW allocation in the owner racing with migration or memory failure in the child. Let's not CC stable. Fixes: 8c4894c6bc79 ("hwpoison, hugetlbfs: fix "bad pmd" warning in unmapping hwpoisoned hugepage") Signed-off-by: Chris Mason [ david: adjust comment and description ] Reviewed-by: Muchun Song (ByteDance) Signed-off-by: David Hildenbrand (Arm) --- mm/hugetlb.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 72d912f488fdc..1555a326efe4c 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5479,6 +5479,14 @@ static void hugetlb_unmap_range(struct mmu_gather *tlb, * unmapped and its refcount is dropped, so just clear pte here. */ if (unlikely(!pte_present(pte))) { + /* + * If we have a folio provided, we only care about + * present page table entries (folio is locked). + */ + if (folio_provided) { + spin_unlock(ptl); + continue; + } /* * If the pte was wr-protected by uffd-wp in any of the * swap forms, meanwhile the caller does not want to -- 2.56.1