From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379661; b=Fag+CE4fo5qN5ia6gmwWqE+hoWHLg/tvDtWsZISQB0X55gkHlKB21B5WaJb3RyIwG14u wvH76pH49L1imGlsq2gTsSw9Y8l4rztBHHFUpcwKLKafLEbFJyAZ0WH4xXXeGbI9/606P XQquHSZ1ejOwQlpJGgVQZgUGbIIK8U0mW61O+f0CpK8mVjUsqVQzM/51/LBIkGncdgWXj pXrWzxUIfu2Xf37ffbofhF9ScVqDUrzf8ZS9s52QEs6Etcgnr4uX6OZ9L3Jhug6EBZwxP FgGdLHk2pk28zlIbyuknkxLaQ+c2whyQQsm9ehjxhthJ9JryFS5+F90rM0wHWUUfnlA== 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=s5QOK0notUrgEscIdaZVOciYEwu9MEPYBzQsie80SOiafBlbOQvspcQUpJO/F8PzVPL0 6XYsHsi+SmFmKnz5toCXvRQmHx0SmNXl2Xkm5jKnK82qdr+sYNstH+4XvogIdltaDn35H KDwSy+Ps3Gnc+Tn0eHVsIMJxNdooJn5Y19ZtmwrD5u5IZiL6ILrYrLwXxdSSLbYQNS/MR yDlOs6+o1jR4tW5RcmG5BnQxUuuw91kNT4eaeIu2yvM/dDpqupMnVsn4ZipxYFyFK9lfA 4rEuH62kJSjJf4cg4cq32t3PyelrYsT2F3CBdeCxIaUH3xLEzIoiCxxUYVV2Ayb1p6A== 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.128.49 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 975DE606A330 for ; Fri, 4 Dec 2026 10:21:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 975DE606A330 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-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4a2d6d01ecbso4054655e9.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=m3zSp1hlE+fAFv+QRhJ8AFOlGo2AC8KSVO3e5epM2N9vgHra150Avnxg3YBEMQyqzx NTbWZ+qxYbk9wqjuJA43FG/0URo45coLeORM8NJdXQp2GeFfq18k3Iktjf9RzPOYC9rd Cr2mkU+jv6Hl8bVj56P5AHr4dzanYmIR2Aj8qwMVbnDpwj7LtFi69e/vbTKZMDyMZ1Sv tZ/x95HJrfo/2kYqF8gbmQx+oJDnwQwuZE7OQ7QM8lNx4rKLQnV54RW+hq/bd9UZjsfV oV9ic+jwSnsTtGAkKPbxJSDalxVTSYej5a7zdwzUF0ixgiQ7lhEgJPc5lT9AwsrqboXm p5DA== X-Forwarded-Encrypted: i=1; AL+hErEOCD0M9cW8xwp4i45OWKQQRGhTE4G8tbA8VFAK3vRx4gBvDgqdZScJvetQFoVZqSW0GZg4QLRuEI4=@vger.kernel.org X-Gm-Message-State: APuU4Z96mJSlzKUMvc+gr/hB2peaumHXtYfn8O1+1bywlCeiVOQ6na/k AUbgR1D7gwyfFZfNzK8BeesgE9f5QnJeinPPri9XKyYISC63If7iB/HW X-Gm-Gg: AZFdTZc3Lv08I1HStQ2mnP4SGBNSHrlEOy8Idl66PD1UVHbsox0Te30h1nzFYNJTRSG VyMmauWghmevLXR6Mi19ATS9MwSxVVJEl/zhgY7HGdvqsuQ8dRrLrbgBlfpQOP/QQ3uacYa4BJm HlGLWFi2D26+Ucf0uFeiKjv6seWkGbXXxaQ2625Hl7GLe+9VyL4DjBietZIf9Izf1YPbcxCyPJp dnMMvtzlNrwypZgLA3Yo46gJw7hkGO84DBEraaaUeNXJr1w1EKX+VJFqPFax0Sopw2CGGpT8C1a s7Ax8O0wfBprNuiMsB2PNLhBxS59BxhFY9U6fuiyB3nvP5waZWDyt1khmx7luzfLns0SJ9pYhPg SfRrRNtx0F1MeZt3/ChMihiIiXTru9SJquES34Ec6PZGI8vg4UjIsEOrnzLZBnEMm1abeX0gM8m P8QQgfzFY2tz/l0i+BXFtJ67jDeQSaJh3IqNRAjMOgZF94uDWuiHi/gRKN9AdXk28sMXCdtWO+/ apuG/wVkXj0B3JQBhfRbkGoIvxbtz66Z5tw5t1qpQi2MVVjWrr0+QRuaoTD5bEzAm9RYhQC7cQn Naz4/O+MGR4qxpzVdjzJP9qAOXIknODGR9vWtJvzkTd1BNy0hT03IhE= 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-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 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