From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379489; b=lEFe3xoFK2Mo7hBg0LjPpvyZ3ueaTrlEunNhBQfL06A3K/JCnsUeOMaAzMIQ4mwsfIjg FBS5qrwzDfNsc80xp7ZujYrGX+EvNv8m32294ZdLNXSH0vn+OpDRyncRE2PYePlnWbODq 2hS9IlttaBpwDQA8+yFbYw0DC81wEIR+Ui3qR2gww/LAjBePyivmMm4duUOuSKnLFbDbF hpMOYn2L9ZAQpH5zEGvALWiJWnPejQ3txu2YC2K/islZyHqWrS92Mxb126JjBTyq01U/o omnJT/AUfh4T6o1KF1YdFxDjkqWaF6GtOfz1xb7ZL047H6ZipoMV/LBJW0xTMmf3lvQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379489; 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=RRaEQoxZS0qyIRHekrCF2aJSVCxV19eba0KCPPa1ydmco8r3e1emkGF5fkNNjq1nA+W7 fpWkvMw3Y7+VepI3CrYXaXlmd0NtMlygMIlXzke4Iah5i/s0H5LGRGntAij9Vgl80DD8f eDEjElXi0QbC7roix4GjF62Lfsliac3wotucZRhFFl+4kmdJsgrNW0kawogSqkjS+Ai+M +QaRfwE+AUmVvj1M5eAcPcAf5fQWCe0e71R6sBdS60yvT0bS3S+EJE4mc2g4noJj+oc+6 l9lvMyeRZ3bvstFtAqRsDKlu1UUX+ng8Rq2N89EXr2PqG7lMIm9ntEOoLwdthEkHsXw== 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.45 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 09F10606A334 for ; Fri, 4 Dec 2026 10:18:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 09F10606A334 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-f45.google.com with SMTP id 5b1f17b1804b1-4bb72b44a97so5183865e9.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=wrLoUGyppJ8VcxVUB3QWk/RTdUrHbRL7pyI6P0aJkhgmv689lC/g1btTW9Th78kRbM sMmTv4PtsTEHINoWQEIycc2IWDN2uMPy/0eVZVTTI6yxZz/EAlKmCKJ8g8ZI/+ohzzX6 yMWTW4iXBfyXV24jepeJHaBGgs0yS1tV00YUi9H6kiuZZvaxDSvN3Kp8uqErhTG7KnIn IbriO9Arb2/OTnocti/tpDT/B1NN/joxCwNUMAy6/5icfaozdXIZayteBTObH1nqCIMT L7bd+bA1cWg+0TMiX9NFK6AN+TUwDHzJL46WIuzXXWOnlr3vKFLeBZbjZcc9njhwRp14 sU3g== X-Forwarded-Encrypted: i=1; AL+hErELU751O2pMa1TKl7LDBJmFg3FVi4logrsfFdQMBFnWzN2sS09lFF4EvMdYYE4ct68s2tqMjA4=@vger.kernel.org X-Gm-Message-State: APuU4Z/I29wI2RoF4/9tyNGTbEHmTCOkNEGKS7ISclPYVTMKxAIwaPSQ RX7NMZQnfIWNHAE+58NFA2Dj4ucc2LLcbzuJig9QJz/aQaZtI6BXS5ru X-Gm-Gg: AZFdTZftLzgZ2QptAa3sAo5OKIkTdlAacqkBEd3kpSi9qfFTg2aPUmTxYTG1uJar56n Bft9wPAw8w2SHA0lVx9gCNUcm8B8/TYYem0oOQH/EzAm9VXJl1IJGfa1lYtwhmQEU2XAoxbA7Xu vlLHH36pBqqqIy6FIbPz4Gzn7k78M7mze0IKHlkxNTuvVJzLRs717J39GjGA71150kG9Df1wCIu ZjfRvxzeXsljwiZegOHTs9kIJTKETeT8YuQXdruhD6c6/P0Y86KCIOrbW0w/Ay+sQReq1JoHDu+ 4eM1/uSTHRZ8WqdBTFriVxQLiS+0szROjpd1SnlEIK6F1nnNFneqcHfwAOjF0Hm1ilD1oKgIHll NoilSf+EWIc4J47e8dRC0NrPIQloNFQXt5L+fnLtoMbbYRGR16XIUwtPIQgO0xQC1n34EsHGpjl DPFZQ++zubmd4OFPN4vw1sfsDryOB2MoYO76+nZNQwQfoVJb32WTDUxL63X0AM5jqzcr1sy3G2s q5QQkdfFbOJyv7HzhnFb6ngnF2yaPIVo+TYUooKDhXOtkemzzUvgbRhj220kN1SgqqTXaAp8+GY zeYqbJ0wfm58ovzj1m47TXsB8H8q7TlXY9BhFBq8VSqmZKF6JKoOWEU= 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: 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 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