From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380184; b=TOPwSL3zr9lSq/uqfNeOzuUIYhnFkZ/kMPsjjIGmLzgmE7yXlP5EMGU4LrfG63Kn3jlv KEW0KWHa+SSudX++mmen/CpFLNwO2L7uri+UXZfCGXj03ti/8v95de4xqcx+fqXA0yumt EZLebn7nIFxrz6HKXTvIlHpZfWf1h0ZVJaaZ9ZZzMiPlabtkxxi5WSXjBY5kZ3kTUpYXO r4LieNTuqzxU7dQm8n9o7rCx4wF1BTFVwq6Iw0CeKgoyrnifBcfvEBkOOAGRyNYEYEL05 XbjIiArAUHo2vhMIBosZCOveQzMlHbD5rzfAXy/Cq06BufrirwIuViEKwsZISpiS+ag== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380184; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=bcjxztZBC7nt7uOggykie7EuspGP2TjmJyfugNHmRJE=; b=29zV+Za687Z93PNFMkf/xNCtwZ+U3s5caruIDdABR8PsO7M3mo5kTRQcrQvXiHWgVBPE EOtmXDglUH6bxTeXq7EOIEl16AXUdrytsVRopK5StPLFtrihgtoB30Zz+sGhku17zDNWz 8dDnB3H/I8S9fRxlY3PQOD2tvtB1Wc9kyVpjvxi5a2P3VZ2KKyDqtYhaag2ojcsMQNK9h X8cppevVtZpom3VX+8PqwTzoCS0hTlrhPLmfeo90v69aDxhuZYpwWoV/eDbvwuJVe7ivK 6xMa9ndnPrkqWVERnLs3D48FrVyoEnGB129ZhbIyrTPiClnOq0ey2Aaq17E8ggYOrJQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Y3UkkTgS; arc=none smtp.remote-ip=209.85.128.49 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 77C46606A33C for ; Fri, 4 Dec 2026 10:29:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 77C46606A33C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Y3UkkTgS Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4bb6c7b6dbdso7227805e9.0 for ; Fri, 04 Dec 2026 02:29:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796380183; x=1796984983; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=bcjxztZBC7nt7uOggykie7EuspGP2TjmJyfugNHmRJE=; b=Y3UkkTgSusGJcvbikpgCWp5ZkO7blnqf0F3csilAYCU1j5f1ex4jE5GLbApF6vVhGi D9jOF1RyDiP7XQTgq81ATgvTDuebfuzIyzgj+1h6i2JO+SPMymr2VejVuH4ire8n+b+j oBKlLYbi5SI3CaVbBjN2QUtq3ApI56AhobJhrHopGyZB7pQqPxLzRdldrp7rvdzr9aLW oen5cfr/iAtk0gdYZlIZb6qmpfB+qO4nFwTc9PFrrv/DKPKIWj+Ym2uKSjm7GAiRAlvi xD8hOzyiGAJpwzyVjMMVs+rNgSKdGtMKXYyruzuIfPN0LjkbpaRszoNKP84FQa7/y26N aBxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796380183; x=1796984983; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=bcjxztZBC7nt7uOggykie7EuspGP2TjmJyfugNHmRJE=; b=s8natJgRCWOAu1FQiMTP2FKXp4uj/ba8E8rBuYQqlx0C4Fk/hV7bT9rxeITNXzXHfd U+0rR3pQQr/BaWURvEmBwekhk560ipsywqUgJSnHnIclB0UxeTCmBsWf0hZIG+F0SL13 CB80AB0OklvFKjHfWumVmhxjf4Njh4ribeBfsyEWKqOqkR1FN2OWP0w07U0j2Djgj8Er 7odhZkro82NAFHGgyWYNr7/7r47VN2AbJ2VHOM/1toVlkEnKWFZFqrseS+FekEgUKI7h 6ZeGop0BP+KxKgsFDPX+NEkjlNGukjZDx2oPEreRchTp9RnBK/j6A2Bn5mkXhNitYZPO f3Hw== X-Forwarded-Encrypted: i=1; AL+hErFTf4mXt6sEyUl8ZmXywseiPpEDkH9NxDTL1pVzSlU+nKg1glI39IRV26Ww1AD3jgbIqC/wAS5KyPAeV/+U@vger.kernel.org X-Gm-Message-State: APuU4Z+eIBEyVIrz1r+EH2HkviGGFOq9cqJkJP5bQ/Ki8DNgdXRx82bF fVe+qeri2pWVi5BCJbkwNSMHQmOyS65M1/Bm6q6TUlhnWQurNIqdePcJ X-Gm-Gg: AZFdTZcprdhgCBV+I/urwcSSFPWhsgHBNEVO6lhLXd7ynPrUO/g90JsycDNw5W+qqNb rGwszHVmIWJN8w3XO0hLp1cBKPuZDI0cL8N2ZH9sJskRCsF5pdSVCOpyOA+KzFN58KT88yVsxbz iuOe8ZyLy3XgxRlIusjvxKxzucFxojGiKnHooR/TzHD5T9cWFLfvP42N7ufkxusNNxmNYp1SyhA 72IabpySMbf+HDgtf8lrfivlEX1ZKTofb6at9f6Hy8RjMI75/0D4tv+OefqzHM3eyGpSrnx8ZAc 9YSmX5K95FS55WeXIS5A7R5RRbtyvY+ee2AmHJc9bXYJaF4EZ4AdSfxJuK2ZDaJMgmFOLuUSWQ8 OR8X0q+Rm++ubd8VCoquz8R4dPF7Sk2j0qhdFGgvH3ov1pyPHuDEvfR8PUlby4HRmsavbTmzzle qsFnrSEKcDjOAA4a5zudMAYh7K4u1kC8Iq+7jmEx+V3VluGkYk6c0Fd7rUdoxJZNqB1AHFMirRD LBmJsX8iD9Yh7c8F6l4euUUYARbSWd8P0BUnOWMO6bLJt1sP/A8IcFhzZjBGms7WC4qtB1upYcl gYtTEUNl9sqavwNC4Htk+HxQc+qz/Fa4ysierblQLfZXzRyhSfBpIWY= X-Received: by 2002:a05:600c:c163:b0:4a3:5aee:2c25 with SMTP id 5b1f17b1804b1-4bbeb8d09d6mr30005375e9.31.1796380182883; Fri, 04 Dec 2026 02:29:42 -0800 (PST) Received: from [192.168.1.22] ([83.231.69.9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbe00792c9sm151759815e9.3.2026.12.04.02.29.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Dec 2026 02:29:42 -0800 (PST) Message-ID: Date: Fri, 4 Dec 2026 11:29:39 +0100 X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 05/35] mm/hugetlb: report reservations that we actually added from hugetlb_reserve_pages() To: "David Hildenbrand (Arm)" , 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" Cc: 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 References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> <20261203-hugetlb_fixes_2-v2-5-9bbeabb555d2@kernel.org> Content-Language: en-US From: "Jose A. Perez de Azpillaga" In-Reply-To: <20261203-hugetlb_fixes_2-v2-5-9bbeabb555d2@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/3/26 12:37 PM, 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) LGTM: Reviewed-by: Jose A. Perez de Azpillaga -- cheers, jose a. p-a