From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379661; b=Fh+vJOtKBkwcEdggnUuFF93xpZEheAbuUtttAANkfEvW5uzkEx8wMtV8Ldyk7JhOBahx 4Neue8P6Kd2lU7/BVq0SeZW2VBqXtkC4ViVGW75yVc139dOl9qU0IV1DyR4fxKyVySIe1 2Wgs6/ooOkBcIjyxE+FRHfAH9RzgcA1mMh+ejEQ7roXCq2uywdplMzZpGzIYwBbt2TJrN beC1tOqKsGL6rDC0on3mZyKSd/qUIx3lEkbEC1PLD0mbuxzfnl1HNtmjJshv+f3zcNmR2 4N9jjhKgacd6hIB0265u3v9ozQ6YC1KOJqvhH7U37EJhRVYhkj8UCE+zm4sh0Vj6Obw== 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=pkYBqj++pKeoo8g5lU4NOO3IJGu/hmsfsifW0nP9U6hFjo3g097rkc3mpiBFNkR2ShZO e1d1nbeO96gXEQuCiv+2hiZcvWQDnTkPnMne12YeuENArgmMdK8FHTBl+0bEyJgBaLt6i 2bGymUYJcFo1ho+YLUY4wSHf/ENGMj06q8XL08KXFCrtwiW3iSEdd8HMLg/LMOJhfHg5m lYkVvoox9uQPLV3ynudrgxWRRqRfV6yACk866B1GTClCMeDwh0Z8wb23lDLQ6eSRqVA/R tmG5/+NBZTwWFhoZZoiSIvDIKB+Kh5xvEsyW4feB3YSHFbYjOH+q5iwITkJ1b0AN3yg== 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.43 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.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 99431606A332 for ; Fri, 4 Dec 2026 10:21:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 99431606A332 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-f43.google.com with SMTP id ffacd0b85a97d-498f5fa4f70so700491f8f.0 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=2FgSRpYs0rtBaygz3FHpLDLJHVFSmzoHnTo5j1LjVV9NUUymfimzLIG4EVfprxC1+R kOCJ3QJr2o4P5ww5x0dyrlE5ZxYWCShG6pvGg5Su8GrA9arotqByXjxEIuQ8Gd9l4lvt JTwtKGG+UMNmSB4rSNPzspxQXwDqdirVKzcdW0YEssc8jmfkHpizwUWUefeth7Q2MJW/ oNA8uiRtjVJOr0jJJup23sdBUYOjGwMpE77zXLdD35MjH9mtA7sTFLkolO8F0dABzBeB ogFoRQt3XURFDVm9TxtodLpnwY66ZYUNfuyqsfy0THwE3tZxRG2hsJ1AniaO0SpSMhJ6 fGGw== X-Forwarded-Encrypted: i=1; AL+hErHuNC86oSH7wTewcCqGZMv2s6c1LzyEnip4w/wxRZGUT6gGYZ4zpssnrZaDrzt5W+LQL/kmpzdj/tiP0/s=@vger.kernel.org X-Gm-Message-State: APuU4Z866WihI/I6befz+BrVpxbV4/HBo3eBCqLLhcmjtinHyvfeY6Rb jze3QjzhC8NUePsvls6W9F7/QzuGi9Z868buwvPaEC9NHqFckHBjazCA X-Gm-Gg: AZFdTZdf0UHhKjyAw0hrA67uec4Cowm6h7agcX8XUyPfsvrdci5XYO+F9tvaKh4uaSJ km5T01goYad9PTiv8SWbiDsrQHa/WW7XtdGBVHPdWmkF2zzt/ThrCkMXKCe6Uf0Q5iNFQn0Dt3R iKtIzydbc03jDocjPAhkVExF3duaHCY4Fa5KU5LfjaPYAHC/hGEJMK5rRV5H9Q48CRpUrnuQAAS G/6fq2nVCTniIzL+H2aK5lNamVdaKv03LlOeqzve1VL3I+2jCyCa0v8M8y8hqsekY1JLfHpEyhQ OB95IsPLuX8Y7eQybNC1S6Tmqg8RIaV5S2PazxMjB1av1VOV91OWe4k6eDLbGamSM11Cwp7GajJ Pl8vzMUsYdqlSYCSw+XYm66Sx9JTe/fBboBg9cteFpbiA2feLV8gV8PuZTLxezeuB4/JAC6bxxE 0mM9xZry8RBVT9cdwvvQKfjMsnjCEZW7grYyMh2e4wIkGVeUTP8dzr+jCD90GF7mYJc83COJIiY 1Wxe/nRpL5GEqZh5toWbT4OT/O+UH0nnDcsX2JEsQKTwlPc6g5sIj9XRT1AicsKZD8/g5Yhnp7N wrhK66/REktLYd2pPz0c1GKob7/PDXBTP6xRmvXZjqDJpCHB/SV7Ft8= 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-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 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