From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF9712F0C7F for ; Fri, 9 Jan 2026 08:08:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767946102; cv=none; b=DJGdu30ieVrAb2WkSmtvz4mdV2aQDxnh9hCISUFmKwv6LjwcSv9jMoUQ/11GmX26QhNoenlyHeHlmcGBtMBCf77DXby9sjswUr9VxPnXhdL5zQpbDvWI4O+8njrpe5mrLP/fv3luzfDx/6K5VQCYn19CVDqSd+r058uKmqyLvOU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767946102; c=relaxed/simple; bh=/qlb0GV7Kfvu5s2kH7z2maufXE2LgLYgrz+/h6+/aC4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SUX0RFR2Uc/wh0j24SQQvpLYLJ7Z0f37Vett/HSqtH92GMzf+wg/k52Ke8qPhlVoxl/pac2NaxaAGxFHQxL/C0nrtT1r3PeyXSn7EWjtvIabiJsImKXeNx3lLQrw6KufY4CeifRn3+xBCwEXHCuQMeuslxMv+Wv2cRslc6nMgzo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Do24N345; arc=none smtp.client-ip=209.85.216.43 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.b="Do24N345" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-34c718c5481so2403887a91.3 for ; Fri, 09 Jan 2026 00:08:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767946100; x=1768550900; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=qpHrGhMAzP5cZ/pwyDMDFj8ircdSPNgtbyAQqaGMd28=; b=Do24N345LPEVnaUeTV5vcfNQZVcxbJYi9Ti2PHdaz2kb9tdvOFztqYbCLMl8pKwQ61 kmH4b4/tIpzc0YKpNkULjEDs6pjFlQaLQN2xHPR8eG652wfkdTMuBcb6runzxp5wvlD8 lW46wSNxgkRguSo8thE66TMayUAYHJaos3t105gDh3oFALyiyOqz8Epwpx545DcbH1uh ejngvfH2HX2/19lOus2yi+mziEdaCGEgCSWlcYUdj2o4o/QqQqM9kUTKwwH3sgpWvmec Xtq5Eh3DwbehVLnLnHO9tN068s3iKYKBbpgNCtFs0ZlsNk2EnghDZTX5XDPltSc0VoEK RdWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767946100; x=1768550900; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qpHrGhMAzP5cZ/pwyDMDFj8ircdSPNgtbyAQqaGMd28=; b=I8cbCxbpFyP79aP7PzzUjGYzzYvnlQeeO5jSipMERISPhNKLTPQfOwhI/W+Gf8pRT+ NnyjS92hCETC1tG3FY1behhYu/6RMOQFkVYojx/LUShlpgyq/Seg+MfadyGvgLGuq8Pb Re98ugxQf14XfCF9IpbnTvnPR3gcpVIf/ysd9vdRWcx7zgjK3aImHF0avfusnoWliWWV bChpyQ6D8v0dXLCjbHL2cO03Y7IQGAi0RvYq1152Os2+7MN0HZYXCCxXuXmjjZjlopNk OBHFmaa7wNMqCtaMoMwUO4XMZXpZcdGo3Wtu335t2O3LnbpmHW0Bl16OvdQg4zqcnu4r HfpA== X-Forwarded-Encrypted: i=1; AJvYcCVDRzYVjrzz68IQfELz4G9v74iQgJCTE2T4N81zKXXqXUiI0wXZ1kaiMkry4GJWqViIfjOmfMtB0AT9r48=@vger.kernel.org X-Gm-Message-State: AOJu0YwgJTm2ITqkiXleIWWgKhQVUTkVUTttYSp9d2B3VBBKaUEOdOFY ggmjE0XnNY0WRIv54U50d/++15Vh/dU1NrrWzMUZQw13xat6wZsmoaXj X-Gm-Gg: AY/fxX7/lh43x0pM46c8qNapBtOBnsYV30QrXHoDCQT1BiATrB+kJB2WC8Dk633BVLo kWSB1ptHhtbQiQjaD2oa4A9w3u+aH1Cu6Q0huc3e6hV+BKf/iD3kI7vb1uqs7JKlOF+QITHLWiu s146cCKK8Zg+pfvgiObE7y+ORmQgrtA3D1WzcNJ/NNQXaU1yX0U3sLOy28b1gtGe4CeftiM9lB5 MonhuzkVNDOEYo+OxB4vAG9cJYQmbFXJMeRDOA0LOCgZPi8ZOdHtFtEHboHXIHNDYKrGJTicf6g xrlT5/duH+24U1hJAICc+oewM/jKGXB0DDSsB+ct3E7RgX39dz5X0pBPj6IGTCqLRhF8tIW+2hM Mdc2h1dMqPuprl0z8LRFa93SHyQ4zRG/NyRTd8UPboHbsgPhD/1D06c5rqg8p/JAcRpijB+M1vI HPFFk= X-Google-Smtp-Source: AGHT+IHLsrX/ZJegdYBv464UAGUVk+R0PGOxDzqPUVHf8M+cVk3HCEFoQ0UpsEjquRvIdlE4srvO5w== X-Received: by 2002:a17:90b:568d:b0:34c:4c6e:beb3 with SMTP id 98e67ed59e1d1-34f68c00199mr8920162a91.18.1767946099887; Fri, 09 Jan 2026 00:08:19 -0800 (PST) Received: from localhost ([2a12:a304:100::105b]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-34f6b95a081sm2513700a91.11.2026.01.09.00.08.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jan 2026 00:08:19 -0800 (PST) Date: Fri, 9 Jan 2026 16:08:15 +0800 From: Jinchao Wang To: "Huang, Ying" Cc: Matthew Wilcox , Andrew Morton , David Hildenbrand , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Alistair Popple , linux-mm@kvack.org, linux-kernel@vger.kernel.org, syzbot+2d9c96466c978346b55f@syzkaller.appspotmail.com Subject: Re: [PATCH] mm/migrate: fix hugetlbfs deadlock by respecting lock ordering Message-ID: References: <20260109034723.1342798-1-wangjinchao600@gmail.com> <87secfqok7.fsf@DESKTOP-5N7EMDA> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87secfqok7.fsf@DESKTOP-5N7EMDA> On Fri, Jan 09, 2026 at 02:37:28PM +0800, Huang, Ying wrote: > Jinchao Wang writes: > > > Fix an AB-BA deadlock between hugetlbfs_punch_hole() and page migration. > > > > The deadlock occurs because migration violates the lock ordering defined > > in mm/rmap.c for hugetlbfs: > > > > * hugetlbfs PageHuge() take locks in this order: > > * hugetlb_fault_mutex > > * vma_lock > > * mapping->i_mmap_rwsem > > * folio_lock > > > > The following trace illustrates the inversion: > > > > Task A (punch_hole): Task B (migration): > > -------------------- ------------------- > > 1. i_mmap_lock_write(mapping) 1. folio_lock(folio) > > 2. folio_lock(folio) 2. i_mmap_lock_read(mapping) > > (blocks waiting for B) (blocks waiting for A) > > > > Task A is blocked in the punch-hole path: > > hugetlbfs_fallocate > > hugetlbfs_punch_hole > > hugetlbfs_zero_partial_page > > folio_lock > > > > Task B is blocked in the migration path: > > migrate_pages > > unmap_and_move_huge_page > > remove_migration_ptes > > __rmap_walk_file > > i_mmap_lock_read > > > > To fix this, adjust unmap_and_move_huge_page() to respect the established > > hierarchy. If i_mmap_rwsem is acquired during try_to_migrate(), hold it > > until remove_migration_ptes() completes. > > > > This utilizes the existing retry logic, which unlocks the folio and > > returns -EAGAIN if hugetlb_folio_mapping_lock_write() fails. > > > > Link: https://lore.kernel.org/all/68e9715a.050a0220.1186a4.000d.GAE@google.com/ > > Link: https://lore.kernel.org/all/20260108123957.1123502-2-wangjinchao600@gmail.com > > Reported-by: syzbot+2d9c96466c978346b55f@syzkaller.appspotmail.com > > Suggested-by: Matthew Wilcox > > Signed-off-by: Jinchao Wang > > Can you provide a "Fixes:" tag? That is helpful for backporting the bug > fix. Thanks for the suggestion. The deadlock appears to be caused by a violation of the lock ordering introduced in commit 336bf30eb765 ("hugetlbfs: fix anon huge page migration race"). Although commit 68d32527d340 ("hugetlbfs: zero partial pages during fallocate hole punch") was the one that first triggered the crash, I believe the 336bf30eb765 commit is the root cause. I will add the following tag to v2: Fixes: 336bf30eb765 ("hugetlbfs: fix anon huge page migration race") > > --- > Best Regards, > Huang, Ying