From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.194 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796364476; b=NPOA8Heh3K9aFq67wPeIyrMoUh3xQTPUTi/MZcBwfavvVboJPs+KvNTOKws5NMPKPdwZ nwenDBRu0vLKJzTn5TyJsOqZCZBPc+Q91ORXp214q8gy4ixb49vJ9dKWbKHbxWAIDOeEB h8i0ppDov506ZPqC2Rz4+/VD4PGaDcOoYh/dXEqBqsiqECcQ1n22Hyk97HMxS90YjL9qC n4rB/gLyGp1kmO0lgiYNj0VDOJAsbBMsR0W2dk1oVw389CPsGZI90DtVwG0L+3qCvEXPD mvhr75TBo/NVoyDB3ZyczFbhghRcgqJXiRtwf3p1IGLnm9Wc19htPvOrZ68aNvrYJkA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796364476; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Content-Type:Mime-Version:Subject:From: In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References: To:X-Mailer; bh=oj7ttRfr76Nva7TAkaGYKcQ1y2/49N5c7qpVNFIACOE=; b=W3cIqEbLReutI2cqYGZAypmlBO19DThaUA9qOU5ufDQvbWhysujp8pjPpWetghwD3dOu 8IdC/z2fu0Sm+KRT/xhqHYXTFv1z9ojUGyqk4B8f4pCjc6TfIK6cNDTT4w3r3sYS5HVmm 1ozkgc77swLJseOaQGT97QxzfWujBgadf1zdaVJsOCOUZ/6pmrsXgStDCsFVVcfbUlQ2c HW+WYcI0Co6aGxJ8h0gCQGzUt1GFkXaqMsGqTJmWRrRbQCBlI9HXUDQDq39T8C/U6eXC8 5sD+bK7WlDKmDDHEIgRc1i7cz0i54e1jLuIQMSb6Y8wKn0E1QL3YymMlblrQHQZHtVQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=gRkDn+eh; arc=none smtp.remote-ip=91.218.175.194 Received: from mta0.migadu.com (out-194.mta0.migadu.com [91.218.175.194]) (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 8CD82606A335 for ; Fri, 4 Dec 2026 06:07:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8CD82606A335 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev 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 X-Envelope-To: linux-doc@vger.kernel.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-doc@vger.kernel.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-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 (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) > 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.=