From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379490; b=rKbme+V3KVckRL8Iyb7wi/wkjci9YsRhbipE+/OjU7YZ7AhtETkZ//0yoHQurx9sryGd GYZxPod+rempgrwYvvolcpXh5VjP9gvw8Mp8Pg1hr/hUWgoCNt1kAO93vZRRpNob7exWA YgHj/rjaYVtt4EFxAwSbvZR0qIDMiUMdBtuqJNDu5iNREIVLuC5Ogj/ScEDPwLoQ/jlYP yeLPQUt6s/SOrmbaRrcfsOd9NZk/Wb8Xvu8IciuRcS931rT0nsuzE++gcxQJp1WJziqu4 sTvNkznAlbWvEiKsGryBWEQa3QqnTn3+dSIJFU7z74H7v4LMNwguQ87Bd3U1/Mp7m+A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379490; 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=GoJ6nwF+2t79uo4gr7r61nyf3PWq72TsZ367NX5FyvI=; b=e1kZ9Rc2MczwaDfF2FOpig2IKcnZvmQwVPiBty/smCfUSqXpW7aFi1SX4M65b0DtAQOf rUz6wyZ1YyhA8yEZwLlndJjPco6abWZaq75eZoPCwX9c75vn5vmtqIOtvC5/Z3dJruM4W /v912IwhgoHDfipfp9SKwgALXginhP3aWLT2wf6k1Xtu0yLg9ToOcKG9ivxXUT2N5ypBN iBNf1trK3QsThJLYeMCHYX++iLXZBYDHzakSc70MW+1Xfm6leSD0c4I09kH/8eb56XTKV 87EmdJWVv8T/dce9C4f4aGf/xFkpQ6k+7kV/jU/T7Sjn0n+AdIOPq0364M66d46BeJg== 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=Q+ufRuo9; arc=none smtp.remote-ip=209.85.128.41 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 F2E81606A333 for ; Fri, 4 Dec 2026 10:18:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F2E81606A333 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=Q+ufRuo9 Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4bb72b44a97so5183815e9.0 for ; Fri, 04 Dec 2026 02:18:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796379487; x=1796984287; 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=GoJ6nwF+2t79uo4gr7r61nyf3PWq72TsZ367NX5FyvI=; b=Q+ufRuo93L0bG5JUY3fIDCX66dxErfM9L6YUYoYPzKuNCbIb5h4BCVVabQ6+wHQtuD cct5YLx3BDdSYlSKQfg7wVlE3yahlBieU045i7eNKglFJyhws7SQMPPAD8x3dV3RMEFx D6893P2ASgwLXr2ICHzf2ZaiGVyVXhJLa7ZtOofrFbubtf2di3IuqI7ys9k+BPDSQnUY 2EuP/py4Jy6yhBFU/VNyKQnK1F9kejLt1WoI/i2TTFqtXhZ2vvzDHgL826C+mzRrPxs+ +vfO5cIuVRJRb2j2dyAPPJIgyEDg9IzbEW4dI7QQq8xgVsaUL/IUf/GWNVHDGSmR3DrC kgxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796379487; x=1796984287; 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=GoJ6nwF+2t79uo4gr7r61nyf3PWq72TsZ367NX5FyvI=; b=AqeBSCJM8BBgitTlz8yVr5sh49WcRRNbnG304I5JxGLqpkp8pX3oeHtFpaD8JFA/VT J//1bw2qlxsYQC43bAXYKon8MM3FUw+wmifm8YGO6d43frrtpkCzs7Qp1nExj+nrHDfn 6LD/zw5ZLoOMRa4glONvjpKH3p1V49Ad1TV6WS5teTaSM20HqYF3gbVOX5lFpEjzMs55 3CaxVhUOCB7AiiYX8DefAgPR05kmt7ztgrfCzFUe8hyQZeFKv5grRmbQBJS1eUupgTfl V8lAXo0/wM1i+4285Jb+Eo5BppMG075bH9avrhw2UcmQa9JXHIos/cdFwk6RlrcEGGy8 uPcQ== X-Forwarded-Encrypted: i=1; AL+hErF2gIOZudIlDZ8MmQMmVoIvFhWEz7Rv2igSlr84+KLilfOdcZzYBDSy7dzMEDpFEt3rAjHj9+rkbuMdy54=@vger.kernel.org X-Gm-Message-State: APuU4Z/yR4HOFkVLhY7gceYg4zWMJZpYFkAfhDELbiIHVxXQlL6zceyU 8FJV2seepE37+TjhL1UkkoNz2Ok0uHtFTR0FGh5+Qlk/fnMENg7U+Wse X-Gm-Gg: AZFdTZfsNRz8MNsDk/rLvIKPbwSfNuNmPOyl8iEVxFzseCdxy3Sf+tkacID0WRvVEmU tj4peGY/J5Tez3kvDGXSS0nZ7rwNLpItDFjoYGrqGisdPQJT/JjbQ0Pt9s0LbjED8hQbQ/gYLX5 agUahavSS7+xtxYUS+adCIFYGe0H0f6aBF792pQ8RiECxTd/zE66t1EZofksbfZEwi24S77QRfV 5upd36wW1xE4ciFoTNAVpSUZKcu6j2VOPb+VJ4rIGu1RbBgV1OAQrX4U6E1qpXapPqOFUnmz5OH eoiEHsHO3XtRSXDLWidD+Qi4R+VyPjUVLGAPKjfufSVsA06kq6ADr5kvugrbBoeNePCuQC9LYNk 5LVBojg6UsDcJR2fa/RrVNcgNEc+pNLV+S7eJc72M+V2kJZY9nToSbLX9BqzUfI9+pg/oqT54Fu j/m5tyUur5jSGmxyWSHOxl7Dptgav8n+pbXiz5eyhMGnQyqbfnAJzDHddOPPnwbLuXEiG1fQ7nD 7zBCiCCBG8KeCpbJJS0YQWU3nBDgYPNNNebui2tVxn/OKP0UYtFkB8G+Mi4NhDzjFxS3bUDNF46 HlSXWIm2jcp/2ZNjIwvYdnY5GY9f8rYtRve7AFFc6rCGN/yFb58fcvg= X-Received: by 2002:a05:600c:4fd3:b0:4bb:c0b7:6cb4 with SMTP id 5b1f17b1804b1-4bbeb8bd744mr28232665e9.11.1796379487079; Fri, 04 Dec 2026 02:18:07 -0800 (PST) Received: from [192.168.1.22] ([83.231.69.9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbe003108asm138183625e9.1.2026.12.04.02.18.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Dec 2026 02:18:06 -0800 (PST) Message-ID: <8cfc46d9-2679-4704-adf2-8f7ccf85a7e7@gmail.com> Date: Fri, 4 Dec 2026 11:18:02 +0100 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 02/35] mm/hugetlb: restore the reservation if vma_needs_reservation() fails 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-2-9bbeabb555d2@kernel.org> Content-Language: en-US From: "Jose A. Perez de Azpillaga" In-Reply-To: <20261203-hugetlb_fixes_2-v2-2-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: > When we fault in a folio in a shared hugetlb mapping at an index that is > not reserved yet, for example because the mapping was created with > MAP_NORESERVE, alloc_hugetlb_folio() is responsible for performing the > hugetlb reservation for the folio's index in the reserve map. > > If something goes wrong before adding the folio to the page cache, > restore_reserve_on_error() will call vma_needs_reservation(), which can > fail to allocate a file_region in corner cases. > > In that case, we will leave the reserve map unchanged and free the folio > without HPG_restore_reserve. Consequently, nothing backs the reservation. > The same happens on a min_size= mount if alloc_hugetlb_folio() took the > reservation from the subpool minimum: the folio then has > HPG_restore_reserve, but we clear it when vma_needs_reservation() fails. > > When we later try again to allocate+populate the page cache, we will > consume the reservation for that index in the reserve map, although we > never accounted for a reservation. This will underflow resv_huge_pages > and the subpool usage. > > Reproduced both cases with fault-injection, failing the file_region > allocation in restore_reserve_on_error() when the first UFFDIO_COPY > attempt into a MAP_SHARED|MAP_NORESERVE mapping fails: > > (1) memfd, after the retry: > > HugePages_Rsvd: 0 -> 18446744073709551615 > > (2) hugetlbfs mount with min_size=, after unmounting: > > HugePages_Rsvd: 0 -> 18446744073709551615 > > Let's fix it by setting or keeping HPG_restore_reserve for folios in > shared mappings in this unlikely error case, such that free_huge_folio() > will restore the reservation. > > Restructure the code to make it at least a little bit easier to > understand. > > This has low urgency, as the file_region allocation is very unlikely to > fail. > > Fixes: 846be08578ed ("mm/hugetlb: expand restore_reserve_on_error functionality") > 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