From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (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 C17723B47CB for ; Fri, 22 May 2026 09:04:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779440691; cv=none; b=ZpcT54uYc/g5isGFnaaVyh0dsprjp1Ifdg2GM3BjA6nOS7nU04aic6RB3XEeIEcvKrjaZ2ST63R8KWbJZzqENn4Zd7u+GNm+4CmldT0ATHpZ/v/q8nkULaNXFvj6H1fBcw+vXlKTaFWwM7JpVOe6u6sfS+923WwkH4iV93dLKUU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779440691; c=relaxed/simple; bh=Z/qyeRBUyGvcZxJL6y2KT66XSfkOnxQSaqs2fUy7Dgc=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=XOgNsNC5lBR3Jzw+jzLzz20Avjn62kGn6UMiAL5eChfJZiBEW97zgPQZnBHFrFdZ1TeQ5Xk+fUTyGG+OP9qqM6mu0/TWjV88GFtWjXtPOCYZgJ47hsIDQI6W/ni6hv/VZ4IJB5m/6XYVJYIYsPxKfAjZRlSJg/xxe9kQMY7eDnI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=lVZCshpg; arc=none smtp.client-ip=91.218.175.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="lVZCshpg" Content-Type: text/plain; charset=us-ascii DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1779440686; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BzN8uRS+evEkzfkM8F8EjSO1FodLBhyOMwCLeG/oLWA=; b=lVZCshpg/wXpcUjXldiM/ceIfpT8/xor9I1dRcT0WEh3xmaFx5Qv5Uu+2wey8wNFAAqegz 6Pj+K8IiKHvG9PjsDn0zp4zAwoBSMRmwjszCmdME8CzWJliRY1GWvWxPVSzKa+8YrwO+No +OlsQ3Qmkc/X7uby0Un8upZhogPXOZc= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.600.51.1.1\)) Subject: Re: [PATCH resend] mm/memory-failure: fix hugetlb_lock AA deadlock in get_huge_page_for_hwpoison X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <20260522010305.4099834-1-mawupeng1@huawei.com> Date: Fri, 22 May 2026 17:03:57 +0800 Cc: 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 Content-Transfer-Encoding: quoted-printable Message-Id: References: <20260522010305.4099834-1-mawupeng1@huawei.com> To: Wupeng Ma X-Migadu-Flow: FLOW_OUT > On May 22, 2026, at 09:03, Wupeng Ma wrote: >=20 > 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: >=20 > 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! >=20 > 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. >=20 > 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. >=20 > Fixes: 405ce051236c ("mm/hwpoison: fix race between hugetlb = free/demotion and memory_failure_hugetlb()") > Signed-off-by: Wupeng Ma Acked-by: Muchun Song Thanks.