From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.164 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796364546; b=05H15Ma/s/EHg/7uSIaOe0sZpv+zEse755IoAF9Nt2b8Is8yuTu2dDxopVem1QctFZcp tGwkAbm9g7oYDBCYHPlaJ8IBg/X7EzUoglp4lJuQeQfw+Em2h3AfQej58Mne1FjjPUBcb eoBftxgDWpjAPZxLhVq8jpUJtyTmg8/ZqsyFHXYW2djOo48waFoUO7cHwQW2Qc97x3gh5 lOqujIW5dchzBO1kEA/kHZHrcGS0Rb4d4N3Rl/NASXsy1X4zKJFoPgm8O/2NOUAUF8JmU /slrSDvuZ0tSb0Yb0yBuq/Ml3Fw4mtzvpuhp4vhQqLhDSmKgly7/Zap7kpC2H1hPmTw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796364546; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Content-Type:Mime-Version:Subject:From: In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References: To:X-Mailer; bh=IaOzCnKCkzv3IMjGZye/03ZRfdKziSQwqPI4hTHuG5o=; b=dKuwV7NDnWhqZUs2STAkUl19FQi/01lQPD+hciZLZ7hFEwW74fhp+MKeWYdhblEGA4+k TkgXzYTLwnsuG6X9lV5HN50SBUIbhMetyMTk9HxUIDpIGFmnDYi+faye2+1399LpX+1ys cO3WP44s9sdMVsO6w1KKEjLC9t+6fSyIsZh6GKdw1YvgHQdDb7we6SasWnnnPc55ImWqE TFjC5PrIr70GxIHybJIc6eQlmGj1ayiO5PxEynLqAbmMEZtSJQ/612NzXGJBGowE1HlC2 NnIbdq1TfLrHB+v+kWrsbj+eguIottYUt3tgN69GaGEMzelCar9Ebg939VlfkLBXMfQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=WsGT0ouy; arc=none smtp.remote-ip=95.215.58.164 Received: from mta1.migadu.com (out-164.mta1.migadu.com [95.215.58.164]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09B4E606A32C for ; Fri, 4 Dec 2026 06:09:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 09B4E606A32C 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, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=WsGT0ouy X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=HSS15Gom3XJ9Q9BwxFm9HJkkF6nlYEMC74kmeekzf2I=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796364544; v=1; x=1796969344; b=WsGT0ouyBfRLZn0/nEhreKJjP/bVwBTTHnk3NNuFbghI/UZoj3JfBiFQ/NmLAJPv0IUmG7t2 BKsDW1kWE2xKeA+rDnXR4RRaUsuhYHzE/1BO7+2/br3KPmsJrNRyx3XkcLZM5vcxoX0RJ86udWE Rq4IFvUUE9Rd3ZDgFVDDGFXg= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 77fc720296ff5aa5; Fri, 04 Dec 2026 06:09:03 +0000 X-Mizu-Trace-ID: 77fc720296ff5aa5 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset=us-ascii X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3901.200.71.1.16\)) Subject: Re: [PATCH v2 05/35] mm/hugetlb: report reservations that we actually added from hugetlb_reserve_pages() From: Muchun Song In-Reply-To: <20261203-hugetlb_fixes_2-v2-5-9bbeabb555d2@kernel.org> Date: Fri, 4 Dec 2026 14:08:36 +0800 Cc: Muchun Song , Oscar Salvador , Andrew Morton , Hongfu Li , Jinmeng Zhou , Mina Almasry , Davidlohr Bueso , Naoya Horiguchi , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Michal Hocko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Vivek Kasireddy , Mel Gorman , Hugh Dickins , Baolin Wang , Dave Airlie , Jason Gunthorpe , Andy Whitcroft , Roman Gushchin , Barry Song , Andrea Arcangeli , Lorenzo Stoakes , Suren Baghdasaryan , Shakeel Butt , Pedro Falcato , Jann Horn , Guillaume Morin , Yang Shi , James Houghton , Rik van Riel , Harry Yoo , Lance Yang , Axel Rasmussen , Peter Xu , Sasha Levin , Kiryl Shutsemau , Christian Brauner , "Steven Rostedt (Google)" , Hongbo Li , Gregory Price , Zi Yan , Joshua Hahn , Rakie Kim , Ying Huang , Matthew Brost , Byungchul Park , Alistair Popple , Andi Kleen , David Rientjes , Joern Engel , "Aneesh Kumar K.V" , linux-mm@kvack.org, linux-doc@vger.kernel.org, Gerd Hoffmann , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Johannes Weiner , Chris Mason , Jiaqi Yan , Sashiko , stable@vger.kernel.org Content-Transfer-Encoding: 7bit Message-Id: References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> <20261203-hugetlb_fixes_2-v2-5-9bbeabb555d2@kernel.org> To: "David Hildenbrand (Arm)" X-Mailer: Apple Mail (2.3901.200.71.1.16) > On Dec 3, 2026, at 19:37, David Hildenbrand (Arm) wrote: > > memfd_alloc_folio() uses hugetlb_reserve_pages() to reserve the index > of the folio it is about to allocate. If allocating the folio or adding > it to the page cache fails, it undoes that reservation, but only if > hugetlb_reserve_pages() reported that it actually performed the > reservation. > > If the index was already reserved, for example through an mmap() of the > same file, memfd_alloc_folio() must not undo that reservation. > > However, if hugetlb_reserve_pages() races with another reservation for > the same index, region_add_limited() can reserve fewer pages than > region_chg() counted. hugetlb_reserve_pages() will then hand back the > surplus charges, but still report the number of pages that region_chg() > counted. > > Consequently, after racing with hugetlbfs_file_mmap() reserving the same > index, memfd_alloc_folio() will undo the reservation of the mmap() caller > on error, and a later fault at that index can fail with SIGBUS. > > Reproduced by artificially delaying hugetlb_reserve_pages() after > region_chg() during IOMMU_IOAS_MAP_FILE of a hugetlb memfd, while another > process mmap()s the memfd, and failing the page cache insertion with > fault injection. Once all unreserved huge pages are in use, the mmap() > caller gets SIGBUS on fault. > > Let's fix it by only reporting the reservations that we actually added. > Other callers are not affected, as they only care about error vs. > success, not the actual number of reserved pages. > > This has low urgency, as it requires an allocation failure after racing > with an mmap() of the same file. > > Fixes: 717cf9357325 ("mm/memfd: reserve hugetlb folios before allocation") > Reported-by: Sashiko > Cc: stable@vger.kernel.org > Signed-off-by: David Hildenbrand (Arm) Acked-by: Muchun Song (ByteDance) Thanks.