From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A71B2606A33A for ; Fri, 4 Dec 2026 10:18:12 +0000 (UTC) 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=koL+niDX Received: by kanga.kvack.org (Postfix) id BCBD46B05BC; Fri, 4 Dec 2026 05:18:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BA3426B05BD; Fri, 4 Dec 2026 05:18:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB9636B05BE; Fri, 4 Dec 2026 05:18:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 74EA56B05BC for ; Fri, 4 Dec 2026 05:18:11 -0500 (EST) Received: from smtpin19.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D94831402EE for ; Fri, 4 Dec 2026 10:18:10 +0000 (UTC) X-FDA: 85505900340.19.E72CFE0 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by imf06.hostedemail.com (Postfix) with ESMTP id D5E6B180009 for ; Fri, 4 Dec 2026 10:18:08 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20260707 header.b=koL+niDX; spf=pass (imf06.hostedemail.com: domain of azpijr@gmail.com designates 209.85.128.48 as permitted sender) smtp.mailfrom=azpijr@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796379489; b=QgLAvgZRkbtYdDfJj9Ks7jWaIkGyxkle8N9Jn7M1K0CQ/ktnC8/pN9bGCufJfePAP3sWbr MjvwB0w6oVbL08zXkRYTw8VezO20Y11duQWaE4kvOtGsr4BnjNzdJD3IQGe556BfQqwcoe qMMVaiv+pzcgh+bfguIfXQW618dp89c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796379489; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GoJ6nwF+2t79uo4gr7r61nyf3PWq72TsZ367NX5FyvI=; b=AAUYX/bxEbCf4X3iPOw/3SeA7vgbqmcthVmpYGu+4PBGnMC3CpTZyF9yWhNKOe5v+34dzv nxJ20QgWTRBklikytcZDZsgLtCIjGbE3BorxVXs+jB3RCumthfwvuTTr1+PJ2zuGF77qnJ tE2lBSyJxj8ksCB4Jpbhe/60u5/ILDU= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20260707 header.b=koL+niDX; spf=pass (imf06.hostedemail.com: domain of azpijr@gmail.com designates 209.85.128.48 as permitted sender) smtp.mailfrom=azpijr@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4bb72b44a97so5183775e9.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=kvack.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=koL+niDXsLvyZiMGtp9lLR+qEfcxyDFj6gQ2zopOzdCRWYLKLuE3EaYXV8W/T6E2OQ NGGIxbn1fLc1V3+24yONYYOqUkBX5qw7cUKAcNP6vaJkBQBH2fvHIwfS4P9aTXMAP9dw d5dD/ZC7aeb2HU5lmRhNTh1DjjpkhAVEVRU5LmFtIiBOVPl8OL5EBib0FeTYjKVwTqUQ hFWYUnrVpX8W3m4WEU40nWjQNZ9DfDd0T9aempjoz/1HUVbufwwz8DgIzlvMgKCSjN23 erq+dr+NlIq9ObzPe5+n6d5fvk+kHP7lBez2WgVi3iL1BwjvLttlxELEBK8KKmsV4guI I/yg== 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=al099zF+KQ/c7XxWfVdmyt/6cuc9idEu46xRn/Cjh3FmpRO8iAZ0ZwKX98FqClFM04 JAVZNrY5sSjaL+BGD7pHyczj6BQTSKazmGkAHgKVBCgqcYMKCNTYLPUdcy+yfapyetAv hHmSLq/JIiEUl/IGpF5eqktkn1FZekccqM+ICNZSarPLMdIHrXDn+b7/Ffgo++ujuUZE GXd7qsSQtHc9PurRf5yEP+vzJvSgjvv9DmY7JyXyyv9BVQH5U5ByvsTH29p8Up7DSFy3 7lBvZsIjjnzX3081qOkFzeHUznfGK2O/cKl8VOJyTjCD2Dv5PEZ/V2deivCe8xo90zgj 43zQ== X-Gm-Message-State: APuU4Z8bEykKGPaP3ZkBcKBJ8RKaQ5NretQlukk9iencnpAYhIQtv01Z 5hkyfEsO7eAMU1TgCv8NqJl7KhHYcZeSw7Y1Fu/v4AaAJj5JDI6yCNsp X-Gm-Gg: AZFdTZdvAhZarK9Im66K6hj1MiI7FzuwcyZWQhf2b8SvsJGJ6pCGB04fb3Ysvz3R0IY CDBL7LPp0WD5lcA1dy8pHCBrcr3j8U47EvIO7L9t3NILrzXafXvVhCRdm8ZsQw/Sj6j7N8dm7Fl VeIsPJ5FI408hnc+ZN7w1QKrUKDs6VeRnsQG1MnTai5EyFsLOXKs8WUhI4KQ1uAnrlRM+LRUMda 2q9aRUSVe6cDtfhCRlFwFeo3rPjT7Dpd57DW+TEXLaunOcszdtVauZN5pW2gm6dc3rtNEt7pxEA vfSBurEsZAO8M8ihu4yXPvGWpZMQeZ5/QtwZJdoJ6Xmitc7KOljamDyxfkyvl/Osm2TkgpuaR6r brTHfpL4LAdT/ZbVkCureuUf4EZKWpbfZe2Ow/VRXhPl13l5miQh7pZondnGEwiHtBr/qXpttNi 9B1j3MgcAffBIWXv62WOLYd8FXIcZbAiP5nlPWMWzzpSd+f18eqlT3EbOSGFOGBFlcQC+G20ZnX pIx5kDr+Pcaun8eoVZyZ/xhrBmbLQDdZwLaqxruomQ1kPy5yLj0/NfsF89nL6e1citFrIOc7+6C 2/bA/nS62j0r25cnDFQ5n4Yai6BVJtCnxEtpQA6r07GfVPuLKOvfxhg= 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-Archived-By: 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 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D5E6B180009 X-Stat-Signature: rjj8657mti8ctomd8fx8qc8nx17nkzi1 X-Spam-Status: No, score=-9.5 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, SPF_HELO_PASS,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-HE-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bF2ihDfvM11syzS7KY6F0Vy2d8oUtesyyJ9Pvc99bgzN/lch2MndsNMfYIqDJc/Py77s06r9eByeMpc9OJvNMxfLd6YbRTDjC32vP64PnQ9QtjuaNbFbXTwcG9hJS7vhGgbN2mtv9CNmjEPDDZr+HSIhVzLWVefbffoBfaDIivICBnfSNSJJWZM/f4zdvyx2HeiyozMN/q81iX3dnGA7r+baRDwX3UzF0/pFlcVa+rt/SSQvj89hb6WnscgJW6aW7Nn4HLqJKEp2AXh2BOeFbrQgvmRVKC9FtfH7EzVZYJuouTxtIPSkR8viek7fmi82RS+s4Mrm9Cs9nCpuuHlfWeSfgmAA9WIgJ/bi9mK3gftzi652nOIH0TGHtuBLT72B6J79dFnZPk2XDYYat99e4G6ijB6WcLUoAa5EQyAPUzU/UA4OGBa4kWkr40AC7r6O2pcIZXpK2Lw2bxxJjgQik6E9vmpHLzWQRgl44Nz24rKq7x1MACZMB6p+FErm6ddVUcEodpEMkvJbUtA4x5vPI7dKwO0w30eWYnRgTwkJDLIgaV9hQ0WzqfoDa/i4Cl6jUA50MIGvpGHIrfeOJOwGfbVrQn/rIRp5tAG7n6X/u5dl0gyqFFl5gj/wZ8TUuJZrpKq0CvSZx1jjH6wmFpXJkY7PKtaO26KiuS5khGNqSq/W7+uyKR7vDEd34QUjW1WyF3EAoqL/TTZXbuF9VtzQcnFH+2XKtUXmGuGAjsLyJalA212KmxCDNeVLG/6mlrgamagLtAAfxNcIl2/Z8M3ggt Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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