From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796382306; b=MrCapgtKhxZhmFNk+PTN8T8xMBEsDG6b69uCazzkXr/kqTB1paHXGHgI+PYuI7TMNO0o TYm3T5S9fQ9C4WrKZBOgwRDqB1ka2f0f63cEDzTrYP9XC301QfML+vYBJkY4WvcnEYhd4 qWy/G5Na4qunVKr1BxN3+pEHK7V9WBbTjNt+TI7lgIMcNSXnkBYzit24ZMj44Ctr50DG7 EhlUXJDZTZknkvauRabYG4j1WSyRAMNezQmLMcNj/L0YzyIP779MiJj6zsOuo28L+VlGO x4jylOTCjor4MaA0yvJKnmpx+6UjmYuZT582vZrBThiw4wcD+4AB7D0TsFmcEht2dUA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382306; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=FU6xSL+XUAbO79Yd3kUyNp0XYiPDoEGuvohe/48ZAw4=; b=P43lc8QYyJpF9j4oporc0Sy5VEOBUQ5Y7s5GhFmqs/ZBfOQahUg7bZLREm6tXGy7joCE ZCoRgrYqSpDVqa0/ycKwFe3CySakPy6RLyYJQrDV45/AyeQTXhULmox01nurbI4p5shpz COuL8FDgDQIaMdripqpBjtpQDEjjsiPWc5CQb5u5nsImSvFx1+EPD7DZ1HF3kpb4ZoA+m LWxkRFRaDVRPf1y2yKTj3N5ozz9Vv9q57JCiQ4iO+yO+8t2CvKAWPJUg4Re/6rOtqkrGm WdrEl8Q8QJp+butFPegg61dVyCu3sol+fqH4lZl5bqVRnvKLiGUPXgNK/2Go5IrAZng== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=VgViS4AB; arc=none smtp.remote-ip=209.85.128.41 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 ECE9D606A330 for ; Fri, 4 Dec 2026 11:05:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org ECE9D606A330 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.a=rsa-sha256 header.s=20260707 header.b=VgViS4AB Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4a35a60499eso4454005e9.0 for ; Fri, 04 Dec 2026 03:05:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796382304; x=1796987104; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=FU6xSL+XUAbO79Yd3kUyNp0XYiPDoEGuvohe/48ZAw4=; b=VgViS4ABuyFVdtwx7qddpt6Uf8zdG/E4ru9dtpxtarjfm98/alP3nrEAob0L6GlZhz CkvCVWZ7O/ayFbVZrZqMSqDPglBwoRVajSFBxnvrbZu9LURoebuG+Ipzv9ZYVzOfJ7v4 q3MFZjApGyRgWYNLnve/OXFv2NVi9uSpturi4oagf80X5obSEmmH/IBajeBYnta7T6P+ k/kbMGTcg3Dl9lZAtSWFgmJlnNjysZ0JCkqy526wEtXac+s4CnyzSyynYQqlq2Q11yj5 dSFe0L74lASmsTdjO3ov9xpG/4LL1SZamPezTpQd2y01qaQn7bpjR7mtowbM/tyzUT+R 4/1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796382304; x=1796987104; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=FU6xSL+XUAbO79Yd3kUyNp0XYiPDoEGuvohe/48ZAw4=; b=J5kBR954szokBWr91j6YLsPpHJlpInzDIFrNTvl7gmKXV5MOoIKsABu/zDMup0ZPHM fhZ/g61cs+GCmCEb919ck6X5tRCgAbY94cPYUgzoBk9OFfJR4mbZI9vHSEDFYwK8PUvT 7ohvKLhualcfMntFpqr5CXWhQSjGFtpE7q3BViCCBew8f6hSVUi04qZZHpnnb/m/FKoK HmZGR0w4iaFIe/Ej7J0em3th86Mv+DQSm3UC1fp0lwomZDutoxQJlwTbfCIs2lRTT8j5 y7hidl+87XW1Tuzi1yWJynYcYPGNySjixxL1E1wtiJf7rToToppkdSo0hv4MpD1q0MQu g64Q== X-Forwarded-Encrypted: i=1; AL+hErEwqDySV6EfiVpxx6Af1wjFwDKVkoCVzq2tcNYCwDzoMeWulbcyt/GzXTjeRWoFvxZg9N+NU36WmwR9hZc=@vger.kernel.org X-Gm-Message-State: APuU4Z86FMZglp0SvoAGv8vQLEqnqToDxVo/fJmes4TQnPOmUGiRMAQc 0Z6zsXbC5sTYI2lgPG009InmSa+ziXkSnBjvkYT0hh02CZycSsKcQU/o X-Gm-Gg: AZFdTZdzIkvUjKycNxYrgvBzKjYz1GbHjVcC/Ue2MTaPar6TrRV9hnk1YsvR+UOBtkV E35tT6FE8Ux2+xcx8Y/GWgySo9DcNGtTuZcyE+mgn4o1MlGJjGe7GAts0Bhw576pTXOhKLSFV8P 3G8zlxDn3gMo1WEqnhIXpbyLXoySjSsms9J9ESQBNih6Eq8+VOM8PRk3bXvl009PSV7QNxWr0q4 zZhGL/vO9Ic1SCPUT9hFznZy0Hmw6VA6Rnk0C4JTIIyxnsvA9TSbwLGPqf2CpOE5UBYuJA9Tm7+ OiKdr6F60SqgkHzuf8mVmCDc3/Q3/vfpxFKg9rcCostCNkeb5LTZfDqHjDZF2fPpF9IQtpg60lJ 0Jw/L9L4e+FGMWGjHy+kJWZZzttyLFryA+HyCKH7Yj9BREHLZJKW6cXxF/0CTXC4EF5k/yWhYJF Vo9CcpEVSXhXMT2TpDr7FX3gt4OG2Koa8V1XKAtrm9Ffe7o6nYg7Cq8qgjdUrZBNLPjNy4uBPpo NFKL5QzEXrQj/Vm5sygPC6gIwDCvzbOLzAnp50mZh72DyyhU2XRgIJRAs9mzQQfdCob0qRFmmVN jvdWLLIzJ0FqXLJGsfrBJo7LKTgzu0errrWdkLg82Zh+FNDhQB04ymA= X-Received: by 2002:a05:600c:8b67:b0:4bb:e1f0:1fd6 with SMTP id 5b1f17b1804b1-4bbeb6fbfa9mr31402305e9.4.1796382304289; Fri, 04 Dec 2026 03:05:04 -0800 (PST) Received: from [192.168.1.22] ([83.231.69.9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbea297f3fsm42914465e9.1.2026.12.04.03.05.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Dec 2026 03:05:03 -0800 (PST) Message-ID: Date: Fri, 4 Dec 2026 12:05:00 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 16/35] hugetlbfs: fix deadlock between hole punching and memory failure To: "David Hildenbrand (Arm)" , 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" Cc: 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 References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> <20261203-hugetlb_fixes_2-v2-16-9bbeabb555d2@kernel.org> Content-Language: en-US From: "Jose A. Perez de Azpillaga" In-Reply-To: <20261203-hugetlb_fixes_2-v2-16-9bbeabb555d2@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/3/26 12:37 PM, David Hildenbrand (Arm) wrote: > From: Chris Mason > > 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. > > 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. > > However, try_memory_failure_hugetlb() locks the folio first, and then > collects the processes to kill under i_mmap_rwsem: > > hugetlbfs_punch_hole() try_memory_failure_hugetlb() > ====================== ============================ > 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 > > 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. > > Only memory failure can deadlock with the hole punch: > > * 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. > > 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. > > Let's fix it by only holding i_mmap_rwsem while unmapping the full > folios of the hole. > > 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. > > The order of the folio lock and i_mmap_rwsem now matches the one for > other folios, which is nice. > > This has low urgency, as the race shouldn't really happen all that often > in practice (never seen). > > 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) LGTM: Reviewed-by: Jose A. Perez de Azpillaga -- cheers, jose a. p-a