From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (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 9C9282F3C3E for ; Wed, 20 May 2026 06:16:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779257819; cv=none; b=eyRv7argrPYxaUB9UixVzI1KopKz3xJaz0gCeOMIY1aKCNOuYrtdrO7vM/KP5LAmax2UeWNnYSU4N88VDG3tujR9SZ9gvSyqKxZ/IrNK/OI9PFa4qsMd/+fmHI/AXdarFNjlOnUbURpWBp7RcAPa9Vdg7FATQLVcb/k0mP3B/bE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779257819; c=relaxed/simple; bh=hH6UERnyWAOkGelJXDPeaNa6VtwgwWte4hecOa/8dgA=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=m/JfBzFX649MDUf86nfpNr6fUInAJjpFbJgWEMs4lh3orF8+9SjOU5PQQlNhy1hxXlFLH7Y72J7ZpWZ5Nwvq99/MSQLMBZVq23X9F/OxtocVdVzZHorvGFiB76+xK+Efn4sWp+e7y8jQXPKEiMqOrwc6V38Z2EnhRQRPhigaroU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=hy47G6KX; arc=none smtp.client-ip=91.218.175.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="hy47G6KX" Content-Type: text/plain; charset=us-ascii DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1779257815; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sp2pJ+82XHyKehOHniPHwM9kegm9WKiZRGipSAFGfRU=; b=hy47G6KXzrCGiCNcSHgbc/erLXASNRjikzSb1Zx4XJo3mU2UlRDtXANw3L+qlTCLFz6LQJ lvHczjf3rHYuF/wOTg990Pn8owSdQba9VFWJaP3f7XAGn4sw/ayhKhTKhGwhccHGEicS4G 9Cl2k8QJfc3hQ4GtG8sEC2ZyzE77cXg= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.500.181\)) Subject: Re: [PATCH v3] mm/hugetlb: restore reservation on error in hugetlb folio copy paths X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <20260520044912.6751-1-devnexen@gmail.com> Date: Wed, 20 May 2026 14:16:07 +0800 Cc: akpm@linux-foundation.org, 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 Content-Transfer-Encoding: quoted-printable Message-Id: References: <20260519230503.121293-1-devnexen@gmail.com> <20260520044912.6751-1-devnexen@gmail.com> To: David Carlier X-Migadu-Flow: FLOW_OUT > On May 20, 2026, at 12:49, David Carlier wrote: >=20 > 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: >=20 > - 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) >=20 > 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. >=20 > Add the missing restore_reserve_on_error() call before folio_put() > on both error paths. >=20 > Fixes: 1cb9dc4b475c ("mm: hwpoison: support recovery from HugePage = copy-on-write faults") > Cc: > Signed-off-by: David Carlier Reviewed-by: Muchun Song Thanks.