From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379489; b=AmuTTv25DVjSfsoPkl3FaFAdYOOfhM3iZAVqLHmpAuwrjFzkoICPIBrXw7Jodecq69B5 b02woRjDRtYtLHuMgtPT6b7hg7Fw01pPsxhGXj9svBTTn7kWpSo5uerI/TaUhupSBdTXo hGBU1jrDhYSOdkFoTe1i6lruVQKZPV4ui7QeAd2Y28IYHwc0i2qKazHGj5/zYRDQg247y Bb+rH4sKSjobdjEogf7vtDMY5zIzAO/6IuxIO95Pp/4wPPoa6OT+5sdBaXTwRUxXGuQMt BktAALyBSeaeWWDrzcZPOm+tscud8c1yQVV933zm4qdYhs74l3bqE79hh3I+O5Xe+RQ== 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=hpWNXrkWI+SXWB9g9MrvydqrTI2gEHTFadPUGjTJbC8hniHCykTCo4xQmiDdnTS7Tt8v HBos4/vNrATGBgVVq/Nwb5THADZ/X3gJGarLWW7FU+VvrZW9l2hA8RknBPpokrn5u/bDp DWcCnnY3Uycbdk9qNStNzlT4HSIzx13U8m/N/vaMTfKt2OyKotYtXHAdVg4VIkmko1cL3 02vuAMIOpoJS7+APPcOmnDkpEui8tY59Ymo6q0aoiCrDD3HJfHN96RAeEkHjlcLlUXxet ij63Nupk9nNGu+BKbyObcUZq2BPKFi1dWyD/L/K0+UqujF49RUDlIW5fjUXE4awcWWg== 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.43 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.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 F0C6C606A32D for ; Fri, 4 Dec 2026 10:18:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F0C6C606A32D 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-f43.google.com with SMTP id 5b1f17b1804b1-4bb72b44a97so5183835e9.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=sbX+RW7QsyHJlWurEN7M8kdCwqV0nE908ynG7b0KtyZ5YbpL4TbyA8QNiI9qZmD9Di Xqu5mRVy91G+E4qwxDwEMbFwNJGu+cHPuwvQ4BAKLdvBeTbGBcNSm+Lra7IffqBWoBx8 1W0R2paMl3efNZM6xJQzefvrgJf3YQ0JODacDkAJi8QqH4NSt46CIUPRw5CJwOfjNOws NahgPOHFQu0G3K6DZta0WxyqMSi10Nf4yPlGnticUIFBSO6tz7kyaWxfnx1Iz0erLYxA wuHxPYosTuOozGDsD6WcSa8KyMPLA1gAnzftIJknD9NM7N1fzFCG8X44yPAbRrvnVFrc PhVQ== X-Forwarded-Encrypted: i=1; AL+hErG6KOpIHiPyShQCAqAvuK1Y1Qudby7CjDfm+HVFb9aUepkqXCfmBPeJbaGzSEPvi8IRaLSdAoR5YbQ=@vger.kernel.org X-Gm-Message-State: APuU4Z8i07kPx/Iboruq/uKwaT9aJ5KqSixN9FpCph56yuKKfpa5w5sf qqkqdb4C0V0xm+/Zze1NgWlVflTZCodD/zuN4JkwZc9wtQ6m1IWSRDaY X-Gm-Gg: AZFdTZePTnCPoDkU+wNFEusar6UeGR8TQg6GOZ2QJFVEUdRHIbTtiOlMJyCwqaTT7Se rHsM7iIptzryEzhrCrDZ9rzd0QTsCwspRhwrxeGEq1glC1+uM2XOjlYt3uZG1kIPvvn3KGh9iEA o0D9Ns6hZuTQQaj4DfnamyYlHMr+xsgVyPkAypvvKw7p0Bn0/3uYRFqPLZyTl/g3jZUEQXIfpmB rPuMnphOCvmfbgcsc3eEWzKUw5GDI7G0T66Zy7fuq80abeUZVq6y4ZtDyU5fmzGJJT7XjwoHL6M 1M7qgfeZ8zUXQXfxESExO+mkIrt4ha+tVIkXhlDB7O7CCCTkqO3qMcVkRr6UK2H+69CBBPM8tWD x9V7I5BeLB0e671pdamxtHWBwymFzJxsLAq4O03e4054QkCBknVthE+r69H1M1PCeUEZO3YqnpT e8vgndtWqXERvxpiGy56EhY1jAen72wcdru4dp1UPxGiuEacJ2rlNoU9FkTAiwe02LFto8kNeO+ UoAw3gsGjbIErMyxpZe7hmAlvPjMsajax2bY13rGF7Nu0kjNngYhht7Twubl3oDv5Bfbn0Mxa0B OSonscu7OMK4qtyZ9s2XO7ba2D52K6cXW1Ohz8HmSZq6C8QA4OEBKig= 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-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 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