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 26A173939B9; Wed, 8 Jul 2026 22:12:54 +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=1783548774; cv=none; b=cI4XaK9RPJFvwJjBRD4wh/OFpWhUgBMEYmNcwDXfWTb9qrZfpsmHqdEHJWHixspoQ6LSOajolP5klEJfWc4ugU0YxeLzzaUsrw7ptFaL9tPWv7sACTZ+OJx1buXpPRrRZiuxmKiSPWkZh39tjqIKNrY/QAARhQ3EL+9mY7LKE0k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783548774; c=relaxed/simple; bh=69AY4ocHUaVliMTNSwskxx27mtLaUjKa3eI4hfXhBvo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Q34iEDqmHPTuPks2gK6PNo7mXE4YdhqYA04O3ZANYBK5Vua0CDpOmlEk/VIh0qVc0hPwMnD87turalvd/8PPNO5F2UK/24FEREYZzxPZBu05YUUKb/pNf9bkniNKDuJtoEstbvi4BW0VHuqnFNTbMTnsovr0vH2ttBRH2OfoBT0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hSKU7svD; 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="hSKU7svD" Received: by smtp.kernel.org (Postfix) with ESMTPS id EC6D4C2BCF4; Wed, 8 Jul 2026 22:12:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1783548774; bh=69AY4ocHUaVliMTNSwskxx27mtLaUjKa3eI4hfXhBvo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=hSKU7svDBslpur3gfD1oOP5CBgiuO35zxafM/UXjUXu+5rzkTdUTQobmvuRAAd2vr XvZSZNPUlOAWXh7X/HD1OhELAhgDnbN0STJvz/19nfTXIazDtx1x/ZZhU73j4rMrtF QaiOv95z/RzHHqTV5u9I3yISNNTJA4S/qot6PhHAkykbh5ANVlE9pFp4OUgnUt4TUB KH3wJzcdJI1lh5q74wACwsJzlJEJfXyIOuoYv/V+9lLdCWnh+bX6aRzECd0SZJ/gJz RnCw1+T1gsLpTlxilTZrhnA5sGsDeNdbsNYTAyuxo79LPRHE91RgBr0dX9IjbE8xSu Nhb0USqLF2f5g== 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 D26DCC44508; Wed, 8 Jul 2026 22:12:53 +0000 (UTC) From: Ackerley Tng via B4 Relay Date: Wed, 08 Jul 2026 15:12:52 -0700 Subject: [PATCH v2 4/5] mm: hugetlb: Return -ENOSPC 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: <20260708-hugetlb-alloc-failure-fixes-v2-4-c7f27cbb462b@google.com> References: <20260708-hugetlb-alloc-failure-fixes-v2-0-c7f27cbb462b@google.com> In-Reply-To: <20260708-hugetlb-alloc-failure-fixes-v2-0-c7f27cbb462b@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, jthoughton@google.com Cc: vannapurve@google.com, erdemaktas@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ackerley Tng , stable@vger.kernel.org X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1783548773; l=2177; i=ackerleytng@google.com; s=20260225; h=from:subject:message-id; bh=ATDEFmXVx2084y3k2D/X0eSSvzPLxfpRzdf7vni2gz8=; b=whjYrYebXAkYbMWBoCoWQO4eHHsGErO3ZYnQYeeOZV3idySVzaxov0v7Qk5ursaHnFiAv7Zlf rjMcQxMzBmQBqzPEMm8GK46Ebh8T8XnSWXnxppCLYFsxMSuLwGJR2EI 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() fails with -ENOMEM, alloc_hugetlb_folio() currently propagates this error. This results in the page fault handler returning VM_FAULT_OOM. Because HugeTLB allocations are high-order and use __GFP_RETRY_MAYFAIL, they bypass the OOM killer. Returning VM_FAULT_OOM to the #PF handler without triggering the OOM killer (or having it make progress) leads to an infinite loop of retrying the fault. Avoid this loop by returning -ENOSPC when charging fails, which maps to VM_FAULT_SIGBUS, terminating the process cleanly. Make mem_cgroup_charge_hugetlb() fault handling use a common error handling path, the same handling used for hugetlb_cgroup_uncharge_cgroup{,_rsvd}(), which also don't trigger the OOM killer and hence opt to terminate the process with a SIGBUS. Fixes: 991135774c0e0 ("memcg/hugetlb: introduce mem_cgroup_charge_hugetlb") Cc: stable@vger.kernel.org Signed-off-by: Ackerley Tng Reviewed-by: Muchun Song --- mm/hugetlb.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 1f3f4b964b153..3e1d99f03c70e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2991,7 +2991,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, if (ret == -ENOMEM) { folio_put(folio); - return ERR_PTR(-ENOMEM); + goto err; } return folio; @@ -3014,6 +3014,17 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, out_end_reservation: if (map_chg != MAP_CHG_ENFORCED) vma_end_reservation(h, vma, addr); +err: + /* + * Return -ENOSPC when this function fails to allocate or + * charge a huge page. If a standard (PAGE_SIZE) page + * allocation fails, the OOM killer is given a chance to run, + * which may resolve the failure on retry. However, for + * HugeTLB allocations, the OOM killer is not triggered. + * Returning -ENOMEM (or anything resulting in VM_FAULT_OOM) + * would leak to the #PF handler, causing it to loop + * indefinitely retrying the fault. + */ return ERR_PTR(-ENOSPC); } -- 2.55.0.795.g602f6c329a-goog