From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 025B9606A32C for ; Fri, 4 Dec 2026 06:07:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=gRkDn+eh Received: by kanga.kvack.org (Postfix) id 243906B05B2; Fri, 4 Dec 2026 01:07:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CD136B05B3; Fri, 4 Dec 2026 01:07:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0735A6B05B4; Fri, 4 Dec 2026 01:07:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id CE2E46B05B2 for ; Fri, 4 Dec 2026 01:07:57 -0500 (EST) Received: from smtpin02.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3D78212027C for ; Fri, 4 Dec 2026 06:07:57 +0000 (UTC) X-FDA: 85505269794.02.19EFAB7 Received: from mta1.migadu.com (out-135.mta1.migadu.com [95.215.58.135]) by imf12.hostedemail.com (Postfix) with ESMTP id 082A44000C for ; Fri, 4 Dec 2026 06:07:54 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=gRkDn+eh; spf=pass (imf12.hostedemail.com: domain of muchun.song@linux.dev designates 95.215.58.135 as permitted sender) smtp.mailfrom=muchun.song@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796364475; b=lIujHlKvAyoMREs6riixBVldzf3V63sJrjX8jzuNj9S5fVQy81gnt0GCAAP9NTSn/yfFjl seE+V58AAQiMJEFBrqyElStBua7OTtnh1K8CKsVohV8WP+M5KEr/aN7V4BhAinEtqhCEJN snO1jk9Tyo6MzuSNC2Pr1mhk6fuzzso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796364475; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oj7ttRfr76Nva7TAkaGYKcQ1y2/49N5c7qpVNFIACOE=; b=yo0WDA4bGy3CtU4fikgexDehmnLjFPm/6bn3RdKw8BFu4Z2PRzJPbmqezAldNpIV2dEoyJ vdts9mIQm3qdxzeR/LCfMVGYZEb70XTjj4p8VhhsvaEXxMFSb3SeN5K9cE82vxMru50Ujh i2MAH3glJGI0nwN5B4lvckrmRwxZEtg= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=gRkDn+eh; spf=pass (imf12.hostedemail.com: domain of muchun.song@linux.dev designates 95.215.58.135 as permitted sender) smtp.mailfrom=muchun.song@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Envelope-To: linux-mm@kvack.org DKIM-Signature: a=rsa-sha256; bh=oj7ttRfr76Nva7TAkaGYKcQ1y2/49N5c7qpVNFIACOE=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796364473; v=1; x=1796969273; b=gRkDn+ehic6C+/MGaIdga1iFdRJfxzAiBoJLzBtaCk8N5u1qq7Rlxh+GjHqKHmnli6E0Slh1 k6BRyIrXIxQxZed9CwjHhmUZLEQxv73tWnv0KfuQhHgMfVaha4v9SCOofaHtSCHDFFjCKVAnO8r foW8V4Unj/xteCmDlizIEeGk= X-Envelope-To: linux-mm@kvack.org Received: by smtp.migadu.com with ESMTPS id 344330138389be0e; Fri, 04 Dec 2026 06:07:52 +0000 X-Mizu-Trace-ID: 344330138389be0e X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset=us-ascii X-Archived-By: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3901.200.71.1.16\)) Subject: Re: [PATCH v2 03/35] mm/hugetlb: restore the reservation when racing with another reservation From: Muchun Song In-Reply-To: <20261203-hugetlb_fixes_2-v2-3-9bbeabb555d2@kernel.org> Date: Fri, 4 Dec 2026 14:07:28 +0800 Cc: 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" , 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 Content-Transfer-Encoding: quoted-printable Message-Id: <0A765535-0FF3-4E75-9DBB-A2F5EF95D586@linux.dev> References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> <20261203-hugetlb_fixes_2-v2-3-9bbeabb555d2@kernel.org> To: "David Hildenbrand (Arm)" X-Mailer: Apple Mail (2.3901.200.71.1.16) X-Rspam-User: X-Rspamd-Queue-Id: 082A44000C X-Rspamd-Server: rspam03 X-Stat-Signature: h4z4bauns3ky83ja9y1yaifhggwsxbg1 X-Spam-Status: No, score=-11.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796364474-986739 X-HE-Meta: U2FsdGVkX1+qljj3Xhow4AFCU5MU8v6cDZbzPATP8Dn7ey4gIkM8cyJs+eiL5JTYwGU6oaamC5FtvvpyjFZ8SVU2vpFaWLtoVpklcKhrFQdZDeVCjQWXQuWp7CFSinZ77GfQbBySwiAlI2jeqyaPbJZt8K4o9UcjIdfdNwyHNbfvoUTZvKWd2XsbR8ItMHyXI6L93eiPkBH7A8/DxXSWQodVnPNcSTVLMeChlHyYBMejq36iHpySJW9L+qX4Nl9rkhY5D3228Fc1W4quTV9Z3MphffnnrjGKb31Vbw1uQJ39n3eO44AGmYA/d1sA4mVCwlqP9zxcdzqcYnBIGl5LopVdjkcWUeqS3/EDQwukexK8uF4LXwaflADYOrmXas7KBb4I3vTZ5SjZN2mHqebfZkytOadQJwOo6FmA6w1II1El0ZN9jvRzwL14++8xNs2Wc/Iz/juj4DCueR5ltPhFsP6N6M1tuhQz56wLJ2EKrq/aNDpPYeoM7YrGifNa5xDEo8cXVPgcuXI6xzwRF83l01TZc9RnfKgqrfqp4xI/XcqcFxIgZqN5MOnI3Ps1H5248mQqcnq8imRwq17BWwzeNPZyzgE7ErZh1uV5Ifmmm7I4gvrZh5dNMW6p0wwAq56UZgnHBC0ccz2rZxwPOYT6s1h5JzdFtnzKMaaOzWd0b/XHjGhGqrJhpcTU8sCC0V1EP2pdK3phhFbIUSX09FN/wRLFqMuxCxMJxIXqB/9Iv447qLM4BYFHewq82+J00SDfo1uFym7aepdKfaCqlyaCf/FKCwKut04pR1Yj8BUOwglC6XSm4+Pda5ECfN+Vt+2hDAKMTvY/AijybvgqavUdb9XxOwYTRbYcbHX3FP+V0mSvtHwl8scWrvSIS8wlF/ETmC8CwaX6Y5TW/t2IbSB7Q0IArwMxPLhRhBRFysxQdqFHlkuT9EVL7ita1ZEycOahvxCz5I6JKV81cZ5llpu BsRnt4uG QCvrmlvdlSBd0qv82JZ3QcUe6PAYjb4Hh+r87eZkbtulnpp5x+zl68/2Lfm8zXk+JStZyWRyXx1fAQrQYW31Q9fiW1v75QUuUx8T2sFc+yR1xTst5UnGkvfJuxU3v9UP2sCS9P6VrUK+XUQfo8XVi/E7EEpqVFTL/i/KcY+9uX/Q1la1804vMTCrxtH0HcMHumgu6+DU00o6kF7TjTRY28sVpaiIwefU2uW/o7cSGK1gU3MffUFfVX8y3uzxREbL+wJumC7BxMS36ze8ShtmMAmqgWYaXY6mNbUhWvXMdT71TUMXdnVfRQW68BlE9l2Sly+W0x2paSgN6hOYstSJxg7M5QKOuEUrqqYRb/2meK2oKUpfLvZEfQ43fETNOze5M0KnxVCtmx5CdU85WtDphOqzBDWmxWvPQPyRBzRIHOPAyXt9ZccqWpxaic8pFl083xoroeAfC/rEg72upDedMnaQMoXuN/jcAgEhgqArW1O/XYvlIQFvGKMvve7e+ySmRRa/UDWhGJGCrj2Gag5/WkQku5JtS69S5wA5vTmo8d2kaQC8Zh5BEoEQS4FdLYiXUDCyJYh1W7+LCO7FQQHyE9jfvmSsqVTh+QvZrWYHgoHlqkDQ= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 > On Dec 3, 2026, at 19:37, David Hildenbrand (Arm) = wrote: >=20 > 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. >=20 > 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. >=20 > 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. >=20 > 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. >=20 > 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. >=20 > This has low urgency, as it requires an error after racing with = another > mapping reserving the same index. >=20 > 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) Acked-by: Muchun Song (ByteDance) Thanks.=