From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.7 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796366447; b=HecTJov7nACOULx1+Ij2reVbyS5cLp1s5uN/Q9lpkNu6gVnIHjKejZStdFsdvKUGSh81 ZGk0eCF2kr/tp1++uEEfwecChPTRBwwkEzbu6GMvsO6vZEHQGKwR1V2jXt/coO7VXdq2A KKY0XHT/npItAdikbt4wz4FZ7IWbsSloZF68yCMS9ZMYrNN5Be8Danfyty66Pv3evytMy O0FQjRobBEhEqV4j7gdMtmxrN2QnUmAG/33+mY+hAtClWWXbjliOkukj5HCaiI2AVzVv5 GtzhndrhJaLGegzMm9Uy4rqabr0IzeXDQgktWwfEUOqSra761rTjVA7qNW4tnqjKq8g== 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=LomS/JPuok4qk5OXxGaihm2t3Zhbld0mv2ouJ4YwJGqFTVMOH/3/+cKpcNtIbD3DJgQv CK1Cmm8Szwbq4U8FYoSCmRnlaCHxA+PtVSpyWfi9/cyk4P/p83fQSKuoe4wBRYEW9AzJr B4s1gJK5bV4iExvVy9C2WAoFay24x1mnhVCGsfNKFv8pLKBLDUnibWw2ziDb1OgjUwqxy UePuO9ql5aIt8xPgok83Ou20tXE9H9iYrZo0Nzwm6Wmff6Wf5ji0lZ/IGaLggTPKWPYQu hb0/JP7Ks/dSUK5Ux1QCajCwtMfTIKoN49cq8Tuz8fckRxDIgREqG0Er1Tb1GL+gPOA== 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=91.218.175.7 Received: from mta0.migadu.com (out-7.mta0.migadu.com [91.218.175.7]) (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 5A0F6606A32F for ; Fri, 4 Dec 2026 06:40:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5A0F6606A32F 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: stable@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: stable@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: stable@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.