From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta1.migadu.com (out-61.mta1.migadu.com [95.215.58.61]) (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 50B0D2FFFA4 for ; Tue, 25 Aug 2026 05:43:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.61 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787636589; cv=none; b=eW/kz8bCMp1G1VYqDhnabGoNAOgv5LYXGI7TRI7BlrwcZZ0ewzzwH+JTxMf/u8GKHfGAm8l64ksTjfpOxdbfaTEQldMqTbo1IhJCaEqZlekvhEhuOwei6WlyFAgUh+T0KywjYQ1gAvsGxAn3gkMAiTM8/q/AXJzyJDQtvMWToPs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787636589; c=relaxed/simple; bh=gcjl2N5K2V0WQZAdyJmxOIbWiWEmkbZR/Ri2p1CGi5w=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=DmWSxZlMlh0FNHTjcb7xTsSAK+iwA7+tb7IVbnDVt5sSPjLEv/Br24u0KHBGyVzeJvDeETP0kkWYZw2O5JDrOHeSDOUNHxRy9mk5cX1TolENLhV5Ue5AOOG//iJGxd0uILqxPCdzIFfmZHnivmT9T5TqdZbdn9l336+sznh4Guw= 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=VzMIlPI1; arc=none smtp.client-ip=95.215.58.61 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="VzMIlPI1" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=gcjl2N5K2V0WQZAdyJmxOIbWiWEmkbZR/Ri2p1CGi5w=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787636582; v=1; x=1788241382; b=VzMIlPI1jfvaFMQkZTsPfPuUM3Xk+x7Drlbv4lGTX3p8HhISpJ6mVrFRS+ZQim02phh+HBuV /KqMti5jpBmwS5ycCkl9Oa8Sid2FoQoeQQwUKwJtx167uARd8IzrAsPKIVhzeFnEGnthcGl5SH/ 1YQYso81ur+dY/DrF3ThpAUc= X-Envelope-To: linux-kernel@vger.kernel.org Received: from smtpclient.apple (114.251.196.101) by mta10.migadu.com with ESMTPS id 9570901acead3ed9; Tue, 25 Aug 2026 05:42:52 +0000 X-Mizu-Trace-ID: 9570901acead3ed9 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset=us-ascii 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.600.51.1.1\)) Subject: Re: [PATCH] mm/hugetlb: fix resv_huge_pages double decrement in memfd error path From: Muchun Song In-Reply-To: <20260825021013.25672-1-hongfu.li@linux.dev> Date: Tue, 25 Aug 2026 13:42:33 +0800 Cc: osalvador@suse.de, david@kernel.org, akpm@linux-foundation.org, steven.sistare@oracle.com, vivek.kasireddy@intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hongfu Li Content-Transfer-Encoding: quoted-printable Message-Id: <6C152511-DA9E-4047-B1AA-94887F7CBEA5@linux.dev> References: <20260825021013.25672-1-hongfu.li@linux.dev> To: Hongfu Li X-Mailer: Apple Mail (2.3864.600.51.1.1) > On Aug 25, 2026, at 10:10, Hongfu Li wrote: >=20 > From: Hongfu Li >=20 > alloc_hugetlb_folio_reserve() decrements h->resv_huge_pages when > dequeuing a folio, but unlike the use_global_reservation handling in > hugetlb_alloc_folio(), it does not set HPageRestoreReserve on the = folio. >=20 > Its sole caller memfd_alloc_folio() pre-allocates a reservation via > hugetlb_reserve_pages() before allocating. When = hugetlb_add_to_page_cache() > fails, folio_put() drops the folio without HPageRestoreReserve set, so > free_huge_folio() does not restore the reservation. The subsequent > hugetlb_unreserve_pages() on the err_unresv path decrements the = counter > a second time, leaving resv_huge_pages off by one for every failed > allocation. >=20 > Set HPageRestoreReserve when consuming the reservation in > alloc_hugetlb_folio_reserve(). On the error path, free_huge_folio() = then > restores the reservation before hugetlb_unreserve_pages() releases it. > The success path is unaffected, as hugetlb_add_to_page_cache() clears > the flag once the folio is added to the page cache. >=20 > Fixes: 26a8ea80929c ("mm/hugetlb: fix memfd_pin_folios resv_huge_pages = leak") > Signed-off-by: Hongfu Li Reviewed-by: Muchun Song Thanks.