From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379661; b=2EBwT0d5eFoQ9SsNGT4pEHO+q6uyzJCR+ARVqlODy+FCZFrl4/UWA8gGQ/lEzO5e1XGo Mzavo78fBj9ROhnL/jaIbwtiJ+F3JlGJIp7YWCJRMibJ0qY5LRnhvx5I1ny/QnM/pqqLz EZKic3V2ENNqBx0b2TU4IHaPo/Dc/Z8qS6ODSX5AOyJBqEpVY43wGUVWlCNzZk+mFNnw7 +lptPNkZf/3nNF0N4xZXDpS67FaUKFc3hASjtJDfXxMUK5SbQmWru2ff6MobR+7o9TOEd 05Sj4p6k/6UEGHIohENCKmu0rlVCfJ94V0gQokZlX84YpGQX/FhDfI6ntJWozgDiYew== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379661; 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=z4qVy/ovfwOQiv/UE33C/yyTv6t9d+fmwD0cwZvnpFY=; b=zT3H6kAf88VakrYtjGhtuJcSH5NrRHsa0KNQpWhi+AKaOd6o+gmKKb4Hwr+JvZKe0s+G HVqBrzCs2IrKGhCDYHkaDK8DYoIutZ38VwJMshB0UevuwVj4MIxP6L+yoMuWjlnLaq20y 2Y+n4csJ6nxVxqGTtLs6FUcZzf4zl1L7bcXQ4iKZAjUyGvBUol9PdwGdHCatZ8G8JtXAU iSX3T+Gz4OwwX2Uw+OWOkK7GTXb+VZpSQH5TK1gB+omVFN7JSFjIaV5F7Vb/4zZm8IK6b G8XPwgs0E4cVBECiG3tOfMw+6Zwx6K/0Exv27mUSt0gJ2AhQINzXacPKSPbFyGJ9tsQ== 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=TE4Ngupc; arc=none smtp.remote-ip=209.85.221.42 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 95667606A32F for ; Fri, 4 Dec 2026 10:21:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 95667606A32F 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=TE4Ngupc Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-4ac08f4a0b2so627561f8f.3 for ; Fri, 04 Dec 2026 02:21:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796379659; x=1796984459; 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=z4qVy/ovfwOQiv/UE33C/yyTv6t9d+fmwD0cwZvnpFY=; b=TE4Ngupc6NLjm7QMG7hIDVjujPq90a137XHGVAGt+5Jw5XiG2z1aPEjU0Uy4gF59vJ 8lBtij7podqald1HFlibH+58S1zAtFLmXFywV4CjzRFyzkIyxvp+qwNyjkEh1Gwa4LWa 7fGX1E5NXoJ3tUKSjNe9lxcLKLzGnGYtU8+n07+hdPcrqZI1v63dTNbPMyNVIUFQCq7F hk6FLeLoV/B3KI01mPJidioFtDeY485/tyC7X1ivmhEnFm7CyrCAnuKposDQQG2ZBM4a H8h9bwWDcUlwM1JDtk+EyC9fM8OjOd53Hmdjo+4epHbyVCcQsKu3qXoeXWp0C58sC8wH 7NXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796379659; x=1796984459; 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=z4qVy/ovfwOQiv/UE33C/yyTv6t9d+fmwD0cwZvnpFY=; b=x+tPzEnfKeX9Spv8Dtf25ETRv6FcYK3eO8coPLc0JaSNeXpNWUDOllO2+mi6MtaA4s s6ouODNZd1wDv3P4QaCqfiSwndXB7spO4rY4OMSxkMni39WTvC9lR/Xy6Y9+eHLDtIA1 wN9fH+GdGdLrfWG3BbTaaotQxnousTFCdWvyp73VDulHA7qUpayDCzav3h8KtYW8VGM5 MBzpqgJbwkM4b0KPNzjKSomd02vHI6mso3U1RyuhIqhrYorvtKZEZkAejztI4KZS7Swl TJpIIUuk3zbOpPuDKQJJKMruYic3D8Gld14owug9iH/r3b4BOeruMBAt9D9zWVxdVlFq 7bPw== X-Forwarded-Encrypted: i=1; AL+hErFwX0Xy7h8LYTGtjjSLgnpQo2W8mZb/wM5s4usSUvJ3qQ8ODqaFuTKLbZOJ6U1bfyE9BbQdZkDa7DOec/LW@vger.kernel.org X-Gm-Message-State: APuU4Z9d8Kf0XJzRois02zC7MR/iD4psAm0ERY/8WAsu3ihD+YbVdbH9 jF6TP2O9PwYtTHU0BVHXPDDKpwnv85PJiLFYtLUk0yGQB31JLqmRGsjt X-Gm-Gg: AZFdTZeWUGb3NG3hyy7LWGz8tbl54UrEV9DRhgGGDHmLkEOrbJ/8DJGM6mB8ZBf4/42 CRVkPIDXPDe6l5dGFG07Ql+ei57w08QEWg/HCX5WOqzhM2PXay+98m/qyKCNdP0gph7AtZRLr6g PI7LSUsOo1ALgUA4EuskAaUXouKyDXT4wGepIQ1S3k5RhQGXESR+KNwvc4tei/H2d/LHNnaJQX0 ceMeyz2d4nDVAO2mIZWxWe6yiMDyxm9q8So8ZMRZHlQDnQgDpizggTUEIW4bmQ6E7/xPTcdoA1L arz+YDC38ahwI71rnTk/okniuH7BK4yx8PWh6td9e8ztj1KorjabBTIVtpeyJ5zA4G1seNTjssJ 8g9bo5/w3AzxNFsDrSMaNdMTyfbbTqkUZZsIBf/EN9L2lpVJdh2JDErnC7YdTgWVPuWFzUW+Kyw R3NdwoycqfOGiTzPEs/SiEYgch41jp4VtcyXYg4ICmzbMNL80dvPDIMGh5J3bpnw+uZak2esTJn z0LtF3ZEkljiXK72rYbVl2KAc4wBTRKiWDJLVchNYK6HVim/mkHMOXmIfF+1TZBQU2L+LUivED+ FQbiil9H2jY0V/4zDr2mPGB9eTaEf4o08y8M2CbbL1s7pMK/smA33ew= X-Received: by 2002:a05:600c:8b10:b0:4bb:5de1:e92c with SMTP id 5b1f17b1804b1-4bbeb8bf30amr26676455e9.26.1796379658792; Fri, 04 Dec 2026 02:20:58 -0800 (PST) Received: from [192.168.1.22] ([83.231.69.9]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d17435dbccsm4619349f8f.47.2026.12.04.02.20.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Dec 2026 02:20:58 -0800 (PST) Message-ID: <8a76df6a-de51-493d-8a79-61a6222ddff9@gmail.com> Date: Fri, 4 Dec 2026 11:20:54 +0100 X-Mailing-List: linux-fsdevel@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 03/35] mm/hugetlb: restore the reservation when racing with another reservation 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-3-9bbeabb555d2@kernel.org> Content-Language: en-US From: "Jose A. Perez de Azpillaga" In-Reply-To: <20261203-hugetlb_fixes_2-v2-3-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, alloc_hugetlb_folio() can race with > hugetlb_reserve_pages() reserving that index, for example, because > another process mmap()s the same file without MAP_NORESERVE. > > vma_commit_reservation() will then find the racing reservation in the > reserve map after allocating the folio, and we consume that reservation > instead: we return our subpool charge, drop a global reservation and > uncharge the cgroup reservation of the folio. However, we don't set > HPG_restore_reserve on the folio. > > If we then hit an error before the folio gets added to the page cache, > restore_reserve_on_error() assumes that alloc_hugetlb_folio() performed > the reservation in the reserve map and removes it, and free_huge_folio() > doesn't restore the global reservation. The reservation of the racing > mmap() is then gone, and a later fault at that index can fail with > SIGBUS. > > Reproduced by artificially delaying alloc_hugetlb_folio() right before > vma_commit_reservation() during a failing UFFDIO_COPY, while another > process mmap()s the same file: once all unreserved huge pages are in > use, that process gets SIGBUS when touching its page. > > Let's fix it by setting HPG_restore_reserve, so the error path keeps the > reservation in the reserve map and free_huge_folio() restores the global > reservation. On success, adding the folio to the page cache clears the > flag. > > This has low urgency, as it requires an error after racing with another > mapping reserving the same index. > > Fixes: 33039678c8da ("mm/hugetlb: handle races in alloc_huge_page and hugetlb_reserve_pages") > 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