From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380184; b=xg5y8UzklYYJ1Ci7DqMSuBhBcEOjL9qMvcSUZVQANWVDqBO54IDjcQNw/9vQ9Wb7SpWn 2H3+u5uTO2MsQugr2KYlCBGXm1Cxq9rwChQlKyOoX0rimWTFp0K89wQmBxk+O4+yyYq3H VMK7jpESHJwO5AB3jjYUlI8I274gqPyuv8nSGllOF56OH9gXwkM7ZKM1Bb+xWnUfbzZhK 6zKVBJLO65ZJ02LECUFmFeTCvy5Rpv0y+aLjY6lz5LVFPE+EKDprhDr7GQMDdPUGwBayj 0XEcY9ikwnG8DehxYJi2Tu4GFbA+2lsuCsCJBg/Hv4pPbx3SVnx4ijppvo68j1+2uxA== 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=mYVwSI+Dr0xxJPM7UXVDj8xxHO8KS40iSTxK9GWzyqiNhSmXs806sunfKMfS0TSj41Xs btZyXqWx5Vi6D5ekIRrgufpGFDA89GHyRVR/RAvIcvNc4fePzBAU7NE5DLuTMN+5JoEYC //TV30gmUD5gQVQFRcZuZ5JUnYQB9gHvZmaP3YtSo3SbecbiMSIAZl0ZOLzRJTE6gMIHd oV70Mk4RinCEcvHWbKyvhXv0ZfAw+IPc2CYqALRyGrIa3eAvWPLltqQTLwWHQAVvX4CDp ZLeCrwcuVTjKEJtwMgzQx2FB86BIkXD0aKkNHuVcHcdBJfS77qqTPyX3cw1DzKoLxwA== 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.53 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 78EF9606A33F for ; Fri, 4 Dec 2026 10:29:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 78EF9606A33F 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-f53.google.com with SMTP id 5b1f17b1804b1-4bb6c7b6dbdso7227865e9.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=rNk1aKSWPkhlwCrzHa6eeAY79cWoISqnzT2Wr0ZMzPjnc9QqVPP+hw34/2fY2SMwVg pK+ASsUln7dNbnPt79vouLMBTAsJDNLqTi7U1IJAnOSY0xLOpmb/Qs4OK0YDnqoor3Sm BEDd7f/mdcFOFqqFHP755Ay+BELBNp8392Gz5koe1mfTCrm/ERnCaQhdL58NiSSYKVqy 0vPkPk1C5RA6PYrNRP9G2R08yMLERDSKL9T6Pl1KTmwvXj4pXwOo56aCGkWX8+w97mpz TNVDA/LlGITtpBJHaPj6+jS6E7npyAlg85Drk5G61SXpIPLabbmg1Grpr/dPollX94WJ bkSQ== X-Forwarded-Encrypted: i=1; AL+hErERg+8ltQyYMWZb0ITA6PgOvxafq7y8JaPpWrIllAS+vx7LazzKfEfQz+Hj5h2I/RAXKpGnrLX0d74=@vger.kernel.org X-Gm-Message-State: APuU4Z+F749+G61QiyMAKeVpLIOrw1dr0pvfLy+g8SHLeuYXN+oujO8/ zGyzjhckA8DGXR0+s9+0ofm2ElH4J4nDYbhxqxctdN8ErbF3vTmw8cYL X-Gm-Gg: AZFdTZe5OxSkZ1l/1ejgFLrCZ4Hl+JSboNemcqnKl33+ikai6lw7lpHT/a/m5ngZVz/ Dwq3DpMp756fYGUxAtoVj8tnJEmEwX5Z0r+bSPCPzLt4zfab/33xfyPja6hyCwOM87gUm8UiHdr DD+jabn4Cz5MQlXHJmDYnFaxIPofbe6uxqnU7RX/uhmMrvJMiuzu2OLDzbrnUxCh8bChOwSyIJQ WvN9sbef7LjOGiHvUZZYgMtRon44jaSQas5La9sxfOZbM0fI3EIfHi2AoyLDVw91SbHBswy9+dE S0OYRZTHq/Ry2voFhG+a0H/dGSeom8RQieI8fMAlxWy9ZDXjyQFLMv2eVbSmeikONveE9zpG14X uzco9tbsJjBRVjwB3rZub8RaT+/nZqKSQgQZ3PJogSYVm/n9vLFIwbjFwPLjn2RD9+/oye9iOEi r5GN+8787K2+QBr+/KcK1XL64nhG+mENMqk178nVjDG6C3V8x9edCIBlFtvnrvFUvvDgVOoDUlA JMDnRkmQPUxtS+olQR6ntDGYTsnpthoH+jKcHqZjYrw4VPSJIRpBGZ2AxdG96Aq19sr75/x68ef rzHTPKpN0HaovfLQ0Tr8P3mUgRXfPQq/Guvw3jVMm42dgOhzLH1dZ3Q= 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-doc@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