From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379661; b=IC0nhKkmqvsTu1kZFX9GyiKcY/SQHuxujlx5xuPl78oqG426/nVNATFW/LBlhJLAOF7s 8EKRCD/Ok50WS+4keSpqAwpX+AhakGfYfvkA4LdaOiLlmUXHRkKarOPYynl5ehaM3BJSO tCiWzFDSScMFr0P95zKoKBZvwu6sqEuPsWPPm4suoXpaolwbVfcFzF83BowVXUVhfLFIB GA+SvaM46EfA7qhXzbeI9X1Yop38Rt04i7ccf11N6C3j4ROeqbyIUZS2W4TGZgpd8hpwd SI8Z34D8r0ax2BHHlTUJJ9v02HL9JOXzUzIaO+blqNeRdeRYI1DiyAPR/nyvP+2T2Wg== 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=gR1CJqM1wdM875K/SKu/vr9QLXrgKsXUaFJe23gjYoYOkNfCtqeMrOlws5F+SuHalKT/ ndtXsThfI1qQuepXMqRBM0sp7skXxAqJjhyHngDdTfGGscaCQ7NWXvIvFV8ihnrC/us42 j9JlhcZrKRtsT90AJx6SA7q34qiI16ankmnJhH89ogywJioHDSds1KDqGeCrv4AQr1kFV /SB7J9yUYeubac9Rus3hlAmFIBqbniBovJ2fhsmNaBBgWGyWTdCFWVZ9BU9QcHwihzTvg 6y213QOJwr8dSgNZppD+pyMbdExDWs2+R98MeS6ayQ4WJ6AF5CjgS3TqoNBcpBlKgVg== 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.45 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.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 9C893606A333 for ; Fri, 4 Dec 2026 10:21:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9C893606A333 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-f45.google.com with SMTP id ffacd0b85a97d-491971ac844so687191f8f.2 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=QwfmKoNGo8XE7Eqm1uTMRyaJylz9s+LFQd22WIMqfiLkoCZ9UNfPREyVKqWjP8kv2N OLGaDIidlKZdlc13aEIDNK4WuJvvekPDxBD0Gfj+ewvZpotibvKu39ZltHaOqFETcazP pypndjtodoGEX7GllrKopgw3PGcUAVe2UQtQEgDX72MIMi0QDwDwCkwxiyLZEXqZGd91 CvAzzQ9zFuS2iGXOFt9TpEWtWWtvkc1ipb93/Cm06D6y1W9TFPz8KUu72v1ZNg9q/Lul ZyfjcG+DkolEnwyzWzavXWLWrXCWNyKf8bS7jAWLQ6+MgS2RZhPvomTZxvqnOIzhzvVk 4stQ== X-Forwarded-Encrypted: i=1; AL+hErGNqEk1BEmgLhpPpnhhkAdqIVEW+G0p+NFFNDv04DYW8JKqW/HdLsVBinSfjw1PjQxbzSeyDUg=@vger.kernel.org X-Gm-Message-State: APuU4Z/GOOFNE/x4l3eeEoN5D9ePrdpALBLEMUWlkn+sYnJi5Y12CLNr VguAgYZOSRqSHdN+jMZNHPy3sPWfULXoJByFeyPlt+FASERuWpwe0r33 X-Gm-Gg: AZFdTZdQQLJYTfFXoriW3PyUeBJOOtDj4hGFAZVatoES6bXJY87TGmAf3hvS04OL2UX Y905gOqAirHUmoUCr7i4VSW7rCa27seRLEBMDyd8lbCIM16iwayqbXc9scA+icnCKFBVJtGdJLs Z4nW25mgOtpDhKbsTzFtc5RfKye222qjyUeBpWIGVc0O6QWRcZSJHfAy/lg9VZe74SCOnqWFvVJ h5mpAi9ocS6cCvdoji9kq5VVbluzCQjuVc9WF+NgpN5yfAMYFGPZaqrlMI5TNI5CDhpAU9FVoh0 VE6awnDJp6Q2sTx19+8LGKCqryt/hgDaZHuL4NXSwdpug7q02cixNs9dRQ0aiu5h+X2F+yAPQ9Z f3nkd5qn47HyrVIcOqSMMRxCjKCY1Qi1MSTo32MxDD/rGOdTwSCStiu+e+/gqQQQk2xKuX2oHE9 RaEdk5Ibz6AyaymoFLvdDMAW2ZZfEu2V1e0XFzezIw3wq1EYI35hY1zdxPcbGgi67PeaYcAd7Wo Sa/UoxzkzPSJ3TKDlNOpNg0S9k1ShQ/z5dDKSL0wJwlTbv4laT9pMjd7HxMHu51PU0OQWBCU95N la8A0g9MPo19rpPJ3o7d4omx+pgG/NDu2aW7Dd9GgNkR6Z/IJ5DUouY= 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: 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 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