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=kGVCjBrQ0oyg+SVX57pORs88WodjjoH1JOT5vIUCokEYE7zSLANUFp2CUvHUYFYZ4t0y NTKh3c/0jtQXP9eUaLhcy3HWw6H7lBNZ3o+czwIzHOprYTf8SSAoBtpDNC/+qIrIsRHwj XliNrhcClE7ranqyHyHP2WU8w0M0oeINcJRSzCWMZTd/JXlJuPUBbpqARkLQdEuVbQqAD LUJbdFdv+8tx6kth7WMW58d9sqtCoGAxh5s8+R5MIIdQL6xNL4hTE95z4XpHczd5xkQy6 /JC/JZk5/0YUmaw7FeuQle9htFf2+pZcfke4G3Fjxuv4VMl+cg3wuQqblS+FHWgZIpA== 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=XJyua6dVvCGTLBTU1kAahTYGhXf56mBGN29qF615nr3odGw1zodVgoo+ijUxR6LG2V61 gILptFkAu6/KLb/SU7g4MwwOWJzAVXtaSs/b2F5WFrIE0HY7nr2xk9zNxyZfOh8RkKp9/ ufpUgULDS2JzdfqqSbK6UcLixKwoDKhRcd2M6k1mhtw2+q7Y9gf0irzh2fDmNnZAOwZl6 7LopRVVl1T3QvT9b58aguELYFw41R7EsoS+UZUBPPVGChTejflTv3sjjtf6Hh5XzjpGYL b0hDwwskBi/8l/cpvIMYAPXuIAla/uV+b19hOe3yaewax9Jjc3wonogPB/DZKSFk27Q== 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 ECC21606A32F for ; Fri, 4 Dec 2026 11:05:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org ECC21606A32F 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-4bb6ba3b244so6028545e9.3 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=tS54l+QNwCHyew4RA3sNE4XEIWNERkR3ZAEXsh6/gLTvLYhkP0S1ZW6znF+qqLUDyx joj1No24XcWbblCUFoStWRkvoh2vuoGuJeRfvL0kVd8E8E62OVz5waFfZvB1lc3eLCCT GUILXEiZ7kwIfeZ2dgFpa7miGTi6mAlh0+HUBEeQyzSjLDXBdEGOOXBXRybLMUDFFvy3 SxWJMxpYDXFcIzr13mNnTJ4fRyfrQ18GLnupS25EqDSS1/ip4rpgIPY4Ch7btxtgtPz0 GrKEiVfFluOE7pGxnugNxAFVmD5fx9DNFtmSaijNLywtrZWyU9tGTPYmFc40mf7EpLav 5Cig== X-Forwarded-Encrypted: i=1; AL+hErG1/PDzpdb9/mt8yxRwkXlcWqfM6hOWg/FCI1XRWr+C1zRnvLgjcLTLl8G1xxOZWm+QHBZHHm6psrY=@vger.kernel.org X-Gm-Message-State: APuU4Z8Dt14DkQ7I7JeWDf/N5ZpTZG/n4wP3csbjdVV26vcQ9RLkhr7N dIVL2wkYC6uIMtLPjdm35g+83abQidUh9DwkNpY/0nxcAkTEJhDTciVR X-Gm-Gg: AZFdTZehV/mkHe92kbCZxXDMj9bOJyDr4uvTyMbolSiw+9jB2i4gltiJsi2iB1x2SDx jHKaUar8krf34g1toNi1HA7AjQqxLeVXvmIcAUdu0CJBDnv37BFvoVXCAGk42FXBeneBcWrY88V ax/Ts5e5EESxujyf6s5t+1W5SX03plvR6TJFhX/4CKNKYkOcSKLrhvI3lXVEDAcDwSA8r5smtMK Tv3tmGsX4FwN+rLV/DpwxDBgNP4UeR9Tvr2HE6C8uoMQn5ROiLU8gm50wZ7dIHwqNwlXpNv3W7g mFPoNfsZDqs7KhAxiNplYmuPM//JNcAYaHyOydJ/LY8lr5J4gVuiQ1lzViRKNhWP91EU5r9+GzS fcs8WoDYyEeuyqWW1b7L01f1fmiYx6gUR0LQJjnotlDvh0AnuEbRBS6kFCKOacSO2X7WTQz6ZKC cHIcx0CCcHRpfmYLQIG0+eVEU0lwYSw5dahAvPBJIVwy5UQHAPNHhPSz2ZgJoQlYlqVclBFXof7 /8UItwHSxoM9CiQzlcHX5fUsOSm/FGWzf1//BfzywDkr0nagT2lGHU08e89nh69iOok7DH2c4HV PBleDij7O/9qWnr+wuF8t1c7ai8rOyTcSknP2+3cMf0POMoTERm0D4U= 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-doc@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