From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 533C01A6831 for ; Fri, 22 May 2026 08:19:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779437947; cv=none; b=TxKEExPLrs6AdrdLU1uuhNhXMWlynaRNd8yVXLlbxx5/FLQEe4HIobcf3XblAfuvV24iFz0FoBMPPw1ADM+fXLUitahtn+q9hA9OS/Ykb2N50R7s3yHgrDQ5Egs0AkgmkJcDuaUtWA+K86RBqbcLed7tVtVDNBSYf2HZlifsgI8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779437947; c=relaxed/simple; bh=Cq5yBkZVKtWO0/ic4Fm0sfqpbcYoqyukQhaeQinZklI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=uHHf6WvPa5KXI1g7B3/nWnBZtZtXWXtXi8guoC4cGaaLkW90KJr3OodCUF4mC/YlNf4aAoyYyTsKkWw7dYG8zjPYtX7UPhbKjySrPujI/JEtupZiBwOofnaQ28KxJsmreoCk37mtCAmoWfha6FF1zg4xB9IioW0fq3DGJHfYVIo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WWpL2KLZ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WWpL2KLZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 601CF1F000E9; Fri, 22 May 2026 08:19:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779437946; bh=CNPgc/AtB0Jee2xxiWKuQgkW16i9+QRUo+cQrRJrVkI=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=WWpL2KLZnHVA8zr0yUIoVdMVNKhwiJ+wfE8fRSCG6iBcgtP4Vt4D2NVKhc8gyhCZt 7Br7sd7FZTzXFy1jB/ecY8BN1Dnfy8yI9HxSvLv+uAxjI1K4HZi/FuL0jPWjRSHWG+ vFLXE/0TdqZvPTB61z5ew1k2gy/FnhtmYvU/yX0OOVWoy2UPcoPs0+IaNzbVCwXE1G Iyr/uW5pIk+xQ2qFbeJlLT6CdCebz3IpTz7sVzq8tYoepPzaPVw0ABZqGaP4OSaeLn mKqECRs0aQGLKbI8fvlRiyJ0YVDqSiZEkbV0xIWmuYb3VT1LsuA7s6zXiEebqX7OS8 CjAPQtkhp5fUw== Date: Fri, 22 May 2026 10:18:59 +0200 From: "Oscar Salvador (SUSE)" To: Wupeng Ma Cc: muchun.song@linux.dev, osalvador@suse.de, david@kernel.org, akpm@linux-foundation.org, ljs@kernel.org, Liam.Howlett@oracle.com, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, linmiaohe@huawei.com, nao.horiguchi@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH resend] mm/memory-failure: fix hugetlb_lock AA deadlock in get_huge_page_for_hwpoison Message-ID: References: <20260522010305.4099834-1-mawupeng1@huawei.com> 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: <20260522010305.4099834-1-mawupeng1@huawei.com> On Fri, May 22, 2026 at 09:03:05AM +0800, Wupeng Ma wrote: > Two concurrent madvise(MADV_HWPOISON) calls on the same hugetlb page > can trigger a recursive spinlock self-deadlock (AA deadlock) on > hugetlb_lock when racing with a concurrent unmap: > > thread#0 thread#1 > -------- -------- > madvise(folio, MADV_HWPOISON) > -> poisons the folio successfully > madvise(folio, MADV_HWPOISON) unmap(folio) > try_memory_failure_hugetlb > get_huge_page_for_hwpoison > spin_lock_irq(&hugetlb_lock) <- held > __get_huge_page_for_hwpoison > hugetlb_update_hwpoison() > -> MF_HUGETLB_FOLIO_PRE_POISONED > goto out: > folio_put() > refcount: 1 -> 0 > free_huge_folio() > spin_lock_irqsave(&hugetlb_lock) > -> AA DEADLOCK! > > The out: path in __get_huge_page_for_hwpoison() calls folio_put() to > drop the GUP reference while the hugetlb_lock is still held by the > hugetlb.c wrapper get_huge_page_for_hwpoison(). If concurrent unmap > has released the page table mapping reference, folio_put() drops the > folio refcount to zero, triggering free_huge_folio() which attempts > to re-acquire the non-recursive hugetlb_lock. > > Fix this by moving hugetlb_lock acquisition from the hugetlb.c wrapper > into get_huge_page_for_hwpoison(). Place spin_unlock_irq() before the > folio_put() at the out: label so the folio is always released outside > the lock. > > Fixes: 405ce051236c ("mm/hwpoison: fix race between hugetlb free/demotion and memory_failure_hugetlb()") > Signed-off-by: Wupeng Ma I was also able to hit this with two threads and adding some delays. Acked-by: Oscar Salvador (SUSE) -- Oscar Salvador SUSE Labs