From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380184; b=IywRXItha2qy9JLvIrFabAg7nj+vOIAt424yttLrSF1BP2lZ5ApYhd6ENjiP8hhbXu93 wu/MnJZe0GWrTgKkOMdv93Z3T+Bo7CuGbVdZaA3CsaMENYbhNiCbYyScK1kP1N0WZ+h9P fFGwszlnoll8rNrRD8ZQqAjD+Jbeid6ilnvVhKws6gMewH8707Jkennxz5r1nWd9rLKj+ nwjzMrpkczyiYIMVWKDIOim2gv/PvC5+h3q6K+ldFMRKO6HWLhm+V2lTrcpJ7U8lwBTyx vPgdLrenuXlpXVejkO66cNrxPk98E9etSxNotJqs7WoGjPWYsRq/ySHGCFVlXO4S3nw== 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=UNBnSqGyblVYl2VmGSk2YBQhvysWSg4IkBZ+3dRL76OpoJAlN0VFAMnoScLdK/gXV2H6 Xg06HP3ZKmgf0V9RTH617XqFrIbXihxPO7KLAqJKre2cOErvPvP8nt4t3HhMUUSUC0CRk dHH+ExjhnXC9IjhmoOLTtkWQoOPm/o+CyXTnZxQEzrwqZrDjokAfZs7RQN9c3/n3QGBQF 3dJ1yuM0lyoA+CewRNAdKaN8JXQBxbtd2dvpC3HXC+dOh8F7v2iKjRQ6mAcvchd+FFyC1 f+5aUdm5OLjjjcYAmLmTNIx/g1VF6R1guwAxtiS/F94oyrloeOLcURr8CLl78MGWHDg== 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.221.43 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 6A9DF606A338 for ; Fri, 4 Dec 2026 10:29:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6A9DF606A338 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-wr1-f43.google.com with SMTP id ffacd0b85a97d-4acb44dcd7bso858939f8f.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=dDCW4d2XpCOjvTGdEuXCdtBH82aFYlFXNgTW8dyW9ZSwn18Mw3iXZhh5b2at3AxUhv cBW4ORekmyyCIlbzuAESxjZg7xls4qiEGoSJyz83bEj4aQ/dicpB2nZ0d/H5Lz/iw5VT u9eb5VgUmm3N9lFHPhZphejeXrDibyf7YPSOIvx/dfYY3zhIkGwZgv80v2quZmMiDPay I5jjPtWL5umzXGiHDJjUl7KMCYIor5Ovkx2tP03VLXAFPLzQkeb9MSjrLIXC3ozFSuGs t7b6ilw6cn+vb5yiYaoYK5UrfAuiyIbBokrJDWhYnYF/pc4coxbmh49kp7oHn7wGWe0o Uqyw== X-Forwarded-Encrypted: i=1; AL+hErGky5zv42KiOX40LG/5JJiJGhXtRX1jXOY4IFl6jFBrGbHfA9mLqPZI+QvrRyq5d/KG76K6xcw=@vger.kernel.org X-Gm-Message-State: APuU4Z+FRYWCGnqMTmEo8VeIOzLiJXvaZap0Q3XatTuI4ybZkYPDtlAx tQCVCvADcU9iydCSCMzELFLb5kL61+WBbVinhet3JcPbcq3ga4zv23DJ X-Gm-Gg: AZFdTZfSNC2I6QgeQvq9fGTbBZM8Jcv7hUTU5lg+IEoICanM3pw71eTZTXpXh4zJYZg CyLh8PE9OmZvECDbU1DT3TXq5WOPMcp+1HxwpfVCnha/rybu4Xr8JnuEu5HGWbfeAg584Dw5a88 JxRQXbIRajoOFPUJ7FPl7mLt9hxxLjAbOchoSpNuPLJsjwbOYJjCB2g8w0juv0F4aqk3jjCf4GN bS6lPO0fZlI84wQsZ0Nf5aPZRmM05+IN10O68z6JpepztD2sv3it4mkVH1Rq4Ekcq9njZZh5kex kiqIdZ5MvkOC/Vlt8KFxduAvI/OLsrD2gpWzo1O77xgd1Pl6j4/RbT8w1q075iZLPI7182ECw92 3gfAesNrpyPapmZMx+HlNUUwyFi+0V8BJ5haACe9JT85V0Vi2En+zOekuBHw/bZaJeXvRXMFUYM 9palPHeTR5tC1ZO1ZivW3iU1eNTbBf6ENi3wgWyBayDQ9zHCDEASAo01+Um6YjmVmz3axoBGiep qMaVqjAyollC9+wKzgEqXNhYBcXi89A5B9dr0pvJlQyiccYqVzDgyAtlgF67z8etKgoIpP+JJH4 PY6EcFNNBTrM+FLJmsfagibALw1wdcra7NBk+FCwLxt4aJjUQZb8neE= 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: stable@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