From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795079502; b=U2OzCsAgrsMhQ9R3oDqKmhd96aI0GfEZxe/H5aYEo4xRnEnAws4JaEhykXPLbY5GsZP2 RL/vO9K9+xNeAXcjXJq7M5+4xUsvTOPhWAMTSwhThvSWKbiH1v0HTJMaHdZojdQ+rORyM w0dQCWGnqpNVtShhEdw1RiyoEkOV5aDiDKgh6MgzdmVz3iVTN7HJlijb/ZU/Co6lOyp74 VjZgf4tcvYddhkn6MukJATFPishDmWffplgSMqg2nOmP7OqkyKEEIaj8toww6lqoDk+O0 dE56mdeV/dupJFHMM5p14D8o8s1bt7NBtM3c4i8yU6Se3+PK1SToWLzC65BUApO5B6Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795079502; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=+ob3yII6XgPfaGzBlNNgVC1u1nxxTdD3c2/x1BrWMGM=; b=SkeiGIVOrmzV/TYkj90NFsbdeiLeMz9cPTTlqpz4a6KYsKvkoVb7Xn1inbLxZ6U3oVOl 3N9SM/MousinL4SIYqe2sWsORrCHmwGILqv9BD6IBl6kllr3aBRF6MSkLwJqZFzSRGl2J XYQyZFnD0CKafcyY3xZtwluZT4SHImSub3gdITIWlJeue8YfZ+npR+lqa1uFFcMm5OPHv ufV0M2xfKrRbUTXkhMzj6bPMvK4Esd6e3RcuYiZZQeSGoM8CxVz7zZTPKsic+E9Tc/Jw+ zZItS81dwokoj53K8RzqqsOeJk8sxjRaR+DKoE9YmJoXZ++xoIFVCG/oPhDvUO+dFFg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oCAqElg+; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 121AE606A320; Thu, 19 Nov 2026 09:11:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oCAqElg+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id C28301F000C4; Thu, 19 Nov 2026 09:11:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795079501; bh=+ob3yII6XgPfaGzBlNNgVC1u1nxxTdD3c2/x1BrWMGM=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=oCAqElg+jHpUv5NZi3+X5pT71z2hb8IbZEPK5BleYGMiMxx+phX6OjUT/P/4JUK2Q gHVX8e7WqtiDEHBKb5OeG3+JgdTndcnYo+GJ4u74ENd96k6WZheR7PExY00+0aU+fN oTV78DY/bCF6fuGrMLPl96Z2obRF3NzoMJzPTDcBtla5/DdGBhEyFt4AGOfdP2jkyn wgW8UBwgVdqvAGib+vgTEmLFnEg4B6mqeSe1TfYDkZ1XM1hOX+fI3Qjn0gkajd6TLh U5sKOqVa8tgXrJoD6aa8iOCHtuoYt75M1hI6VQVHKNjM3LzrR800nK0vZnwiwLPZFb Wfp9a+v0hoLhA== Date: Thu, 19 Nov 2026 10:11:30 +0100 From: "Oscar Salvador (SUSE)" To: "David Hildenbrand (Arm)" Cc: Muchun Song , Oscar Salvador , Naoya Horiguchi , Andrew Morton , Mel Gorman , Andy Whitcroft , Miaohe Lin , Michal Hocko , Rik van Riel , Hugh Dickins , Baolin Wang , Vivek Kasireddy , Dave Airlie , Jason Gunthorpe , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Jonathan Corbet , Shuah Khan , Randy Dunlap , Peter Xu , Breno Leitao , Will Deacon , "Aneesh Kumar K.V" , Nick Piggin , Peter Zijlstra , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Arnd Bergmann , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Gerd Hoffmann , linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, Josef Bacik Subject: Re: [PATCH v2 09/15] mm/memfd: recheck the page cache before allocating a hugetlb folio Message-ID: References: <20261116-fixes_hugetlb-v2-0-4dd9e94ea9ac@kernel.org> <20261116-fixes_hugetlb-v2-9-4dd9e94ea9ac@kernel.org> X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261116-fixes_hugetlb-v2-9-4dd9e94ea9ac@kernel.org> On Mon, Nov 16, 2026 at 07:29:30PM +0100, David Hildenbrand (Arm) wrote: > A concurrent fault or PIN request can populate the page cache > after memfd_pin_folios() misses it in the page cache but before > memfd_alloc_folio() takes the fault mutex. The latter still tries to > allocate another folio and can return -ENOMEM even though the requested > folio is already cached. > > In particular, hugetlb_reserve_pages() finds the existing reservation-map > entry and reserves nothing. If no global reservations remain, > alloc_hugetlb_folio_reserve() fails even when the pool has free pages, > effectively failing memfd_pin_folios(). > > Recheck the page cache before reserving or allocating. If the folio is > present, drop the lookup reference and return -EEXIST so > memfd_pin_folios() retries its lookup. > > This is probably not worth backporting to stable. > > Fixes: 89c1905d9c14 ("mm/gup: introduce memfd_pin_folios() for pinning memfd folios") > Reported-by: Josef Bacik > Acked-by: Muchun Song > Signed-off-by: David Hildenbrand (Arm) Acked-by: Oscar Salvador (SUSE) -- Oscar Salvador SUSE Labs