From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796364547; b=gYchRT6OrY+LHqDlhOx46voBOPJ3UB2dhRpHtf1WLD3AsXE9UKLtJEuua65TUQlm35nU W9w78oU2XyeaAf+6DVa0PW8kentt5zP65VcTHSHbx498KHad5BHjkz8QY0X42lt0Lnqhu sOeoZZiTGCToeb22ivgtsV4q2N9g1yycJozt7hL43X9N91DG0XgncWp/B5kq5z1BUGoeJ Hg8bqTqgD49CKhfHVnhCamUnMbu5Iy16odWaFSNNazt2JgCyEQHNTEnr9Evy9khGHb/OP GhdRRWIlQJjGJ7qHbPOFGPobk2Yqc4IRLaCrP90YenunAi39egBUKiA8JTP2eBp8kqA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796364547; 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=pyFliT8SdSrufsx+ETUll9vYZZNNvezJAtSdsqUI3kOfZjz8pHPX2yX39/SxflTtzgY+ MynY5wS0+wD4VE0KODJXxb6UU8YqFlesUUXZYF+LjuGJt+5iQ3/vUFVZ3ODeN5dmMO6QZ N2j2qdhfuojXYcxohd/oWhWJi+P7jH9/Du9rG8xA6W8kylbiifuHMSTM33TbS9h5ax9RF wAJ45vR9IvZORP9hxHyggizWj7qiKrcR2VfiGrPG7NQdmv0NfchsX3OyOT58AFshOlDA6 6QCVr01GXsXzkMCEcuUHcocFhHO0KZLualyDwxosiYVbojngHkxOsZDU3Rnd3Ef1dvw== 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.169 Received: from mta1.migadu.com (out-169.mta1.migadu.com [95.215.58.169]) (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 786C1606A334 for ; Fri, 4 Dec 2026 06:09:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 786C1606A334 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: stable@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: stable@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: stable@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.