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 725F930C167 for ; Tue, 7 Jul 2026 20:46:17 +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=1783457177; cv=none; b=ripQeVkHKVp3MQr3BvRncf0TOw7N8C0cNz1FYD3QiK0foCGTPmsXrxAquwc/+9fXEdgpEIc3e+mcBZlXAMrNHab6Hc053DW5VoIGeKLR9VCbhhQvCcr22OfgNESB52OBc2s2GpV/LyNU4XZb3BGmDdi0Fh2+In2z0a+PItHFDt0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783457177; c=relaxed/simple; bh=QOjnxAE+GAvwVsekkkA6CouZPQD2lkrzTyRQz+n8Dx0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lxMPw1OnOrtnEKiyryt3Yw/ndU4j82WZLRAwmt0VM/afdH9qrXuci6bWRLZ/ZWBfyeBKQaqIdVtxg6N+DJlwlCK0ATOKIYUfhSeDpu7K9rU7hU1N/M5cCRW7x1ZCE77FDp41Jq1rkTmoMlwlcI5N3KepeTuJWdhkVLw+s2bk6eU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Qo6OO7Wt; 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="Qo6OO7Wt" Received: by smtp.kernel.org (Postfix) with ESMTPS id 33DA5C2BCB9; Tue, 7 Jul 2026 20:46:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1783457177; bh=QOjnxAE+GAvwVsekkkA6CouZPQD2lkrzTyRQz+n8Dx0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Qo6OO7WtnPpgJX4U4mLdz1WCADEMqSyz9q4d1reu0HNJyoy46IEA8jIvjpkIbsZHf bPOms5ORSU2qhPG8oCdI0LPcYlxrxKDDYFf91Os+EdrmwaKfO/sRI4d1S0eHf4sdYC y9YfWpML23Ga3Fx9nskRH0GkXG/LidXJlqzQSihfPTcvrgVDRxMfUL7MENB9WEfXe3 sDWuj9qrfaOttRnhJeTnISG2e5yZCYJElolWMdN+TEHW0wAIuLW5syL2WVZsNsuwyb Vf1+vXHqDulfU/i3Y3KyhLcOPWGsrtrlEG2Qd4d6QhtcVr4HO+8sM1U9/dhApAAUkB hCKsNzNdpJJbg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16F54C44503; Tue, 7 Jul 2026 20:46:17 +0000 (UTC) From: Ackerley Tng via B4 Relay Date: Tue, 07 Jul 2026 13:46:09 -0700 Subject: [PATCH 2/4] mm: hugetlb: Fix folio refcount mismatch on memcg charge failure 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="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260707-hugetlb-alloc-failure-fixes-v1-2-5bbd3a4b836d@google.com> References: <20260707-hugetlb-alloc-failure-fixes-v1-0-5bbd3a4b836d@google.com> In-Reply-To: <20260707-hugetlb-alloc-failure-fixes-v1-0-5bbd3a4b836d@google.com> To: Muchun Song , Oscar Salvador , David Hildenbrand , Joshua Hahn , Shakeel Butt , Nhat Pham , Andrew Morton , Peter Xu , Wupeng Ma , fvdl@google.com, rientjes@google.com Cc: vannapurve@google.com, erdemaktas@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ackerley Tng X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1783457176; l=1164; i=ackerleytng@google.com; s=20260225; h=from:subject:message-id; bh=Gg4M6FjBN0eERxpvlOF/a2TSmnqG64aUlMaqc3eGXmA=; b=mo8MGzg/gQfk0ae6VmaZKFXCoTWsQlyJ407ghMLd1hjVJcChz9T0tEkovJr6ocDcX3FYL4QuD Diqtdz/ne/bDRQiTioQvs1vad6FaVeIBuoIscs5e/Aba1WDKN5pwG6U X-Developer-Key: i=ackerleytng@google.com; a=ed25519; pk=sAZDYXdm6Iz8FHitpHeFlCMXwabodTm7p8/3/8xUxuU= X-Endpoint-Received: by B4 Relay for ackerleytng@google.com/20260225 with auth_id=649 X-Original-From: Ackerley Tng Reply-To: ackerleytng@google.com From: Ackerley Tng When mem_cgroup_charge_hugetlb(folio, gfp) returns -ENOMEM, the folio has its refcount set to 1 via folio_ref_unfreeze(folio, 1). The error path calls free_huge_folio(folio) directly, which expects a refcount of 0. Hence, VM_BUG_ON_FOLIO(folio_ref_count(folio), folio) is triggered. Even with CONFIG_DEBUG_VM disabled, returning a folio with refcount 1 to the freelist can corrupt allocator state later. Use folio_put(folio) instead of free_huge_folio(folio) to properly drop the reference before freeing it. Fixes: 991135774c0e0 ("memcg/hugetlb: introduce mem_cgroup_charge_hugetlb") Signed-off-by: Ackerley Tng --- mm/hugetlb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index e607dcbb2fc3e..46e8dfffcfa5d 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2996,7 +2996,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, lruvec_stat_mod_folio(folio, NR_HUGETLB, pages_per_huge_page(h)); if (ret == -ENOMEM) { - free_huge_folio(folio); + folio_put(folio); return ERR_PTR(-ENOMEM); } -- 2.55.0.795.g602f6c329a-goog