From nobody Mon May 25 01:12:46 2026 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A1E131F98C for ; Wed, 20 May 2026 04:49:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779252560; cv=none; b=Q6RQZjmON0apN1B+yVLIJQPx+4yK9grnFD4AnoPAci30SlSktzHxr1UcgLBEutZ5GiwKcQ2Vy2F7A0rRKY4cSa8tjFHNijfzNxgT83RzocTQ/ZcP8cX3dGQruDS2MaQNTgzjNSLgr3r36StyNZd1lFuI/nQ7dbZwWQ6p5QV8xAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779252560; c=relaxed/simple; bh=ziYccg4TdsqjbmtxPiu50UjxLrYVf0KsFRmerfX2hvk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cukvNBkEy6OCpoa2zGZKo7ulNGbceyTDZOFYZvkG7WhkCS6F8IbkF0NHi2waC5QpT/C4ZeHcnISzAKFL2DrQymwGbHlHEJCrqBu3WlpBR8sPeNsqkv03YRutA051iC9weyNTKc1W5E+4hgNOULGzGCvAO1DuiVnIKJPNnje/Z/o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LL+OjjAG; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LL+OjjAG" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4891b0786beso30202055e9.1 for ; Tue, 19 May 2026 21:49:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779252556; x=1779857356; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=57hoFoACkrjHC435/bCa26l7dMtPP1jCMndjVz0up2g=; b=LL+OjjAGzl8ZrwNnXeEFlBcEFHH0oC7SW5K8wCKoEjDRUw1aNmTHIPvfof9fUZVji7 s4ewLpBEdFCAKbFF8YFTXI90mPVx9LVBLPoV5kw9HDH12tk+1a85wCQfatqbrGP+Vrmu ocZmVHNKmQrRy1Eq+rcOtXpVyMnfwnk1m/g6qyY3tsKKLh74EYpKhOTN3UAnqHYw+vVk FWye4W121+Rqgs4b1iO9q8diI4kgO9mOnTFSUzDPL5CS8Ha9FScS9rRj+msF6h75//4R UiecdqmhJAtqL+05/C/KQe0wJGRuguyX+BrfjGFJLHn21sGXSmuRC+RDswrxnE2Y6r3n flyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779252556; x=1779857356; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=57hoFoACkrjHC435/bCa26l7dMtPP1jCMndjVz0up2g=; b=aMx83H+qVMbeXAXUmcavnfsm4nQ+GYkemj9LJoHOtjFbv4aZrISGYKn9JTv68cIYOm dqXPGu0+i025Csm5auzFUht7Pe9uRsJkDLc6a+pCLziX5D8J4MfdNx5+koGTXARv8Bgn EnJzf4i6U2AAFNnamH5ZEzt2tDoikHUOz2MSuyHV2jVRIcpVVPiPhFc7+XUFuJwFNk9A hLrTUp6u6pNqbIYuipiSIPFkKbi8myj7F/WRKLdptAl09N2RIqcZE2F5XJs+6nU80b+S HQMc6uZZ6UIDo1SvDLwo3Wpdy5iUdgS5IMThAgUS6OiJcZB3DMiOnrKTtziad66gHcc2 6izQ== X-Forwarded-Encrypted: i=1; AFNElJ+v7Xtd9TtOXE/l0yipyc8abbi++cQnuKKeKKM947gPM4m8zczl8wTxPRhrbA1t6ohgu3dsh206/udVF1E=@vger.kernel.org X-Gm-Message-State: AOJu0YyyneLgYACKiM1l7s5ekL5dPk/FnghgDxjPuS7czmrxUa74OsSB /T/6fXLiQBQTyIRDed3PsJ/Al+i5rbjLp/gye9r9HukUBUru4friyWzkqv58C1Q/Phc= X-Gm-Gg: Acq92OHF/bF+pGvMiccwsY2lzOlHTBYfjk6qIqHRoNZ3nIRgYr4q4naX662XpUzd/wq 6HZWjNJvR4TxjSYRtUP4TU0dzKSehEKEpX1Q5gK4YMYrW5edqr9xQlw1qN5tVTO0b52s0qWsG/j gNHjETPHLPYhDOIhTxOZTa2z/TnBLoN9Jbz9RTdcQ2YagJzUO29g61n0iHCn8Bn36Dq5xHwJwvT a5f+Z5l7BVVUw2ZzFdlcRkCl6BU39eH0LU973/FKAJToFvo7ZcRfTAS4+1Od1xftU1p9QUkaQ50 s1tK/txgJI1pEsOq7SSz/UEz8E2brMJR8lJ/2V3NvjzVZwrM2dePsHyFldM3u+9/SwcrB9hkF53 cZ0VIQCq3CUCC9ciHS0h7qKkKqFA/9zN8nHV9pMut6B1Dpn2GQhPx+aQf3UQLbaVocdHOosWl1G 2D8R7E1xw6q+p/w3wGUmNB5di3yUHXByTCjhXwpT6V23T5n0T9QxGF10bn1OVW7iinpOgt8FMi1 RAibkrkxDo= X-Received: by 2002:a05:600c:1f94:b0:489:1d23:4524 with SMTP id 5b1f17b1804b1-48fe60de736mr327397805e9.5.1779252556299; Tue, 19 May 2026 21:49:16 -0700 (PDT) Received: from dohko.chello.ie (188-141-5-72.dynamic.upc.ie. [188.141.5.72]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48fea52a0bfsm189071125e9.0.2026.05.19.21.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2026 21:49:15 -0700 (PDT) From: David Carlier To: akpm@linux-foundation.org Cc: muchun.song@linux.dev, david@kernel.org, almasrymina@google.com, osalvador@suse.de, yuehaibing@huawei.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, David Carlier Subject: [PATCH v3] mm/hugetlb: restore reservation on error in hugetlb folio copy paths Date: Wed, 20 May 2026 05:49:12 +0100 Message-ID: <20260520044912.6751-1-devnexen@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260519230503.121293-1-devnexen@gmail.com> References: <20260519230503.121293-1-devnexen@gmail.com> 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" Two sites in mm/hugetlb.c allocate a hugetlb folio via alloc_hugetlb_folio() (consuming a VMA reservation) and then call copy_user_large_folio(), which became int-returning in commit 1cb9dc4b475c ("mm: hwpoison: support recovery from HugePage copy-on-write faults") and can now fail (e.g. -EHWPOISON on a hwpoisoned source page). On the failure path, folio_put() restores the global hugetlb pool count through free_huge_folio(), but the per-VMA reservation map entry is left marked consumed: - hugetlb_mfill_atomic_pte() resubmission path (UFFDIO_COPY) - copy_hugetlb_page_range() fork-time CoW path when hugetlb_try_dup_anon_rmap() fails (rare: pinned hugetlb anon folio under fork) User-visible effect: on UFFDIO_COPY into a private hugetlb VMA where the resubmission copy fails, the reservation for that address is leaked from the VMA's reserve map. A subsequent fault at the same address takes the no-reservation path, and under hugetlb pool pressure the task is SIGBUSed at an address it had previously reserved. The fork-time CoW path leaks the same way in the child VMA's reserve map, though it requires the much rarer combination of pinned hugetlb anon page + hwpoisoned source. Add the missing restore_reserve_on_error() call before folio_put() on both error paths. Fixes: 1cb9dc4b475c ("mm: hwpoison: support recovery from HugePage copy-on-= write faults") Cc: Signed-off-by: David Carlier Reviewed-by: Muchun Song --- v3: - Fold the copy_hugetlb_page_range() sibling fix into this patch (per Muchun) -- same Fixes commit, same fix pattern, single backport unit for stable. - Reworded changelog to cover both sites. v2: https://lore.kernel.org/all/20260519230503.121293-1-devnexen@gmail.com/ v1: https://lore.kernel.org/all/20260322052120.14021-1-devnexen@gmail.com/ mm/hugetlb.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 4b80b167cc9c..ba7c3ed96835 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4974,6 +4974,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, st= ruct mm_struct *src, addr, dst_vma); folio_put(pte_folio); if (ret) { + restore_reserve_on_error(h, dst_vma, addr, new_folio); folio_put(new_folio); break; } @@ -6270,6 +6271,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, folio_put(*foliop); *foliop =3D NULL; if (ret) { + restore_reserve_on_error(h, dst_vma, dst_addr, folio); folio_put(folio); goto out; } --=20 2.53.0