From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796382306; b=PVLb7wEK3mVMskTuNiUINXmx0fokVugYPZp3qoZ6JSVMVrFV/G0wam57jHemZXxkEW7I qsSQxtUkidDFjZkIjwDYdMisKO014Xa3wMN2M8aYbytldW5BWXuxvzt5gXMTzflLC9C9J E8HgM+5J5Tdqy9lkpwvRCQDYOgPgdIOlC66TUKCksCRA+iXGG6F2voTcrsYh10+x0ki+9 b1vaWz1RGsPga/ztDd9SBPXhNHnZh4zB1BSki7HvG93cEmTfx9hr/v96+sO/3dpVcI4Dy RbUy2zN422OKuJwFGcrLt9PkYbnl4XPT2oDOhSizKT1ivwkJrg/9uy+gr7rjIdRCh9w== 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=L2Y9GkBoHhg1iU5TDbs8u2MMMes22YBxzBp+NDnT9REyCGNCWKuh2e48lQDGvKfzmJvP MqnP5i5j/W8BtKqBFOBcl7IO0Tj10H5votFRaWihmD0X2eM/8ES2zVukBcsWrxspDcsGg 9MI+EtZolD3rnDZX8QOXePe1735nRHowrgJpz01MWF4vufYoWxu3IWt+qpxZ2KiIyezwI 1n+q6PdPpKxhV4W1bnIgpZIAxKXY3tErjpTUgWM26MkHyftVsFGUTjyvJ9nwN7oMfAQfy YjFbgqOsizPgjUfo7WcmjKPvCzAxseJL7g9dmI5lLKLUfJHIB3uTB2k3L68p2XhtuTw== 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.49 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 E2578606A32C for ; Fri, 4 Dec 2026 11:05:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E2578606A32C 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-f49.google.com with SMTP id 5b1f17b1804b1-4a207b02a2cso6093805e9.1 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=TzGXupfNiUS0E/5OEaD2BdtVq/5QXWTbF8KFYwUTfLltsRXYQIXDlnD0pQdA3QuaBy 4XmmuUwHtg7iTxmkf1l61KaFEgfK+I4im6/xtQKDCwUZxJ50i3BeEYQS4DJrBco4u0Rh kSOMlLYnBTvWlE5zpCEb3aQPqhy/IVeZ7reW/PdE7T0r6pLgpyZYRKpxrBp3IgSMDUTm Z849apttYXJ27hio5WvbSdMsq8kJjm3Aoqt6XvAtE2Onb0/xxZ9BD59Fvu35GydyIQqJ Fs2vXyruEumNNd+Vip6gl5uUUddseVux6j8ULukfLFLzIoFXjgGL5zKgZgF+7ctJMhgs WLig== X-Forwarded-Encrypted: i=1; AL+hErHj2b1iFPvduc3C/hgM6ySmcC/mAf7QZWOqeSyj7BscFb9ZAdJdP1/Nw67/nOaE+AR/wxufzSI=@vger.kernel.org X-Gm-Message-State: APuU4Z8eRkpk/UGizTZxbEFY6k2YyCYu5yf5bhCsL05k8W+8sKccvoYP f5D6te6SdOVpGUaBy4xCd+4hAZP5LC8nbGuxNF45k07pDuhFRBrSFVxD X-Gm-Gg: AZFdTZe+EYpEHy+7q7v9HTg2tsjII5//ceAniCWQlvbaz3rjcQDoW88auuAwH22mR+h pb743X9MK07qqiO3y7xxoeCWSDuU1g4GUbcuhv4qS2CVxSBvyAUK02CTtE2CIs+BMHsxf6NxnyZ 167GljhEBqMA+RrGyPi4KGvUA91WXD9URrZXFc1ex8Kg11H9CmW8PHuymTs5+sqflPKinWv2BbM 1NUjrTSRgGFTasvmyvKCv3JLLaEY01H3VbZ7Y2ep3An4kWTktCgnU8ejG7Npp7sOvECybZOB8fr stJnoEW+O0kl/Or2Zpp5bR5FJCnewhfDUwHAbW0JJzbrwu8Bbb1P0KJlzmbx9wtp+z9GbNNQpJ/ ilwZspQ3xD/At/y80vhGCZdFQl1pFrZvBeYOJ0oDhUG3b0I8G8xJPy6mneg6YCeggp0wxPxhVw+ R2qVNLtdm7UgsGjnLPADyY/6VAzHAS+dTEnUotj2zzYmgsufZ9yP4CgTEEAd+1sCRCcnxzN8gVw 6Ijz9uU8g3CguC9OCL47KpB2GmFXKvu5Fr433izDUUV2fue6wxoPF3V79vQrSTXWqSPOCijFohY fn6mB6jei9MCSCSdp3FPW5uoIlik7rOAG5B2EuUJ0v2vv9cCHysgI48= 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: stable@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