From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.195 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796366447; b=EZJa+2A39gbkA1AZDPNwqqYOOgWfmL64qQLghujc2a7XvWd0mc592pB9HJzAmG4u4e8k hjlH1j4R3LxVt+oSW1Jd90Jvaouez3ofJT7myQ0FoH1U95Pb8zvmsZiUWHQ7B7Xv2uVTJ RDQRGCw80pPvFaLlJaLcz1wPanPNxPhhsQVYYgogM0He9QzuVZ8JdfYL6F7DL3x8l5aOO /pWWbcpYsw9YbOVakz54MkhVfoqpszxDfVq+9xS8goow5T6noBYaq9RCrPUibtO2UN8MB aBP8QPLXU8EQRy/PuHAAHw9mtxFqC1+ZoxavIt6EH4/gZxPuapWops0t4m/Y+ouPYtg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796366447; 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=wSkCZ9ZzOSPsW/VcTHD3+dANl64QHLisB++o0dg9p24=; b=TMpJQ0/hEs8fayy05+bLQlPHMdpJCtIjzOTy0aCn+F3zH8AqSjUUrzRop8Iz8qsAGM81 UoHSnujx0CPGtvqf0YY9Pb5zmDsoGrVaAoNak6KcaVi14+DGo2kQ+nNtLcaXI45FIJcTe 6P7PhkVBpbkzkm3EdIURr9/mreIkCQpY4MUxwZ9QQYPrVYLykElEDkM7//m3AjstvZ0Su a8+WLQ43shEpoZZO9W/REOZTmAEfz4AcQ52Ul1VncqZhHsDbYjLM5mP4ccEoIcYV72YbJ gQkejNhuz5fV8WqKl3LNAO25vZ9nvoknXWRkZWOCjCC1KnDr2IpciG5pRuMaOAFXPWg== 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=T0Ft6Hl0; arc=none smtp.remote-ip=95.215.58.195 Received: from mta1.migadu.com (out-195.mta1.migadu.com [95.215.58.195]) (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 F342B606A32D for ; Fri, 4 Dec 2026 06:40:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F342B606A32D 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=T0Ft6Hl0 X-Envelope-To: linux-doc@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=0TjfBM4eSq6WHc2m3ZDDr2kzaIBFNyAVWZwOqAFOInM=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796366444; v=1; x=1796971244; b=T0Ft6Hl0kLIKKBinhryyi3lcNtKj/fzy+bRIRUEPJ62WDKvi5uauonRsZL1+BOXP/lap163W gd2e0+LkviD/6jwEEYBr0QqKxQ/U09Ce2gbL8J67Y/ZWJ1XK8SAUZyayQXobIWmZ214N2PHlst+ PcQAEI2G0Pcp7H3NALz8qrMs= X-Envelope-To: linux-doc@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 15280984329fc7a8; Fri, 04 Dec 2026 06:40:42 +0000 X-Mizu-Trace-ID: 15280984329fc7a8 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 16/35] hugetlbfs: fix deadlock between hole punching and memory failure From: Muchun Song In-Reply-To: <20261203-hugetlb_fixes_2-v2-16-9bbeabb555d2@kernel.org> Date: Fri, 4 Dec 2026 14:17:51 +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 , stable@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <6055BAF3-0936-4442-95DC-C93F83DF98C9@linux.dev> References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> <20261203-hugetlb_fixes_2-v2-16-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 > From: Chris Mason >=20 > Punching a hole that isn't aligned to the huge page size can deadlock > against memory_failure() on a mapped folio at the edge of the hole. >=20 > hugetlbfs_punch_hole() locks and zeroes the partial folios with > i_mmap_rwsem held for write, following the hugetlbfs locking order > documented in mm/rmap.c: i_mmap_rwsem before the folio lock. >=20 > However, try_memory_failure_hugetlb() locks the folio first, and then > collects the processes to kill under i_mmap_rwsem: >=20 > hugetlbfs_punch_hole() try_memory_failure_hugetlb() > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D > i_mmap_lock_write() > folio_lock() > hugetlbfs_zero_partial_page() hwpoison_user_mappings() > filemap_lock_hugetlb_folio() collect_procs_file() > waits for the folio lock i_mmap_lock_read() > waits for the writer >=20 > In fact, the documentation is outdated: hugetlbfs_punch_hole() is the > *only* one that still takes i_mmap_rwsem before the folio lock. All > other scenarios always take the folio lock before the i_mmap_rwsem. >=20 > Only memory failure can deadlock with the hole punch: >=20 > * truncation and hole punching of full folios are serialized against = it > through the inode lock > * unmap_ref_private() holds the lock of an anon folio, not of a page > cache folio that the hole punch zeroes > * migration only tries to take the i_mmap_rwsem. >=20 > There is no need to zero the partial folios under i_mmap_rwsem. The = lock > only protects the VMA tree and PMD table sharing, nothing about = zeroing; > the inode lock and the folio lock are sufficient. >=20 > Let's fix it by only holding i_mmap_rwsem while unmapping the full > folios of the hole. >=20 > Update the documented locking order in mm/rmap.c and the function > comment above hugetlb_folio_mapping_lock_write(). > hugetlb_folio_mapping_lock_write() could now take the lock > unconditionally, but we leave that for a separate change. >=20 > The order of the folio lock and i_mmap_rwsem now matches the one for > other folios, which is nice. >=20 > This has low urgency, as the race shouldn't really happen all that = often > in practice (never seen). >=20 > Fixes: 68d32527d340 ("hugetlbfs: zero partial pages during fallocate = hole punch") > Cc: > Signed-off-by: Chris Mason > [ david: adjust comment and description ] > Signed-off-by: David Hildenbrand (Arm) Acked-by: Muchun Song (ByteDance) THanks.