From nobody Thu Apr 9 13:39:07 2026 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) (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 2580636B066 for ; Mon, 9 Mar 2026 08:06:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773043591; cv=none; b=AEGX14MGLCicLHTT/csgwIwPfgP69U4CuibW9QNTOu36v5ogXxRbR2IkGXjyiFMuY1it0GRllfy2bqRZj53DJtpsDOIVhihU93igsKJ0V/sqYEVCyQADgKhqnXRY4w35pL5O+69S35bCAO0+WG7QbvJ8KRGiw3xwYi9+HwldK+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773043591; c=relaxed/simple; bh=0tSCq7mCJ1EUOSyAkfuImXp40SwSGFG17z7IOfD6/hE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BiydVDHryOjv9MrqOv1BpanspEZeOcebkAqkFz/CItTLUJ7ZAhdpEEBWNd1vL6qGfYFYIfZaDuznr4HglLbmlNdxBpOY3l9/osZbw0dILsXjz6TKPFBLo9skWT52IVZC36sEX8vtjOsUNTg9Wb4xkjFNazCSFgmx4XN4ce4/dXM= 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=j6SXWado; arc=none smtp.client-ip=95.215.58.177 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="j6SXWado" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1773043587; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/9qkGX4IQsoz4+saQxr+Ks9qPbIOEkiQZre8PPkbRL0=; b=j6SXWado97/8h7663KF4D0acF7r5B6e90za3CBZQyfPGwi6sOZtNxEb3ZgDIQ1T7sdDyHf 3Ps1c345JS1zAKGSuW0pOBd6Wik1EjnvFi4mN427itu/V7iCnRQfbHwAZW1nunTB+/P5Fz vvZbOXTVY1MSXuu33AH+4VX+gtj7zLo= From: Hui Zhu To: Andrew Morton , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , YoungJun Park , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Hui Zhu Subject: [PATCH v2 1/2] mm/swap: Add VM_WARN_ON to isolate_lock_cluster() Date: Mon, 9 Mar 2026 16:05:41 +0800 Message-ID: <25c1be6b4a54a69d4b57189fd84c7502c4412d7a.1773040982.git.zhuhui@kylinos.cn> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Hui Zhu swap_cluster_alloc_table() assumes that the caller holds the following locks: ci->lock percpu_swap_cluster.lock si->global_cluster_lock (required for non-SWP_SOLIDSTATE devices) There are five call paths leading to swap_cluster_alloc_table(): swap_alloc_hibernation_slot->cluster_alloc_swap_entry ->alloc_swap_scan_list->isolate_lock_cluster->swap_cluster_alloc_table swap_alloc_slow->cluster_alloc_swap_entry->alloc_swap_scan_list ->isolate_lock_cluster->swap_cluster_alloc_table swap_alloc_hibernation_slot->cluster_alloc_swap_entry ->swap_reclaim_full_clusters->isolate_lock_cluster ->swap_cluster_alloc_table swap_alloc_slow->cluster_alloc_swap_entry->swap_reclaim_full_clusters ->isolate_lock_cluster->swap_cluster_alloc_table swap_reclaim_work->swap_reclaim_full_clusters->isolate_lock_cluster ->swap_cluster_alloc_table Other paths correctly acquire the necessary locks before calling swap_cluster_alloc_table(). But swap_reclaim_work() doesn't need do that because swap_reclaim_full_clusters() just isolate si->full_clusters that the tables of it must be allocated. Then isolate_lock_cluster() that is called by swap_reclaim_full_clusters() will never call swap_cluster_alloc_table(). This patch add a VM_WARN_ON to warning if a fill cluster will be handle by swap_cluster_alloc_table() Signed-off-by: Hui Zhu --- mm/swapfile.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/swapfile.c b/mm/swapfile.c index 94af29d1de88..3fc2eb30c187 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -596,6 +596,9 @@ static struct swap_cluster_info *isolate_lock_cluster( spin_unlock(&si->lock); =20 if (found && !cluster_table_is_alloced(found)) { + /* Table of full cluster must be allocated. */ + VM_WARN_ON(ci->flags =3D=3D CLUSTER_FLAG_FULL); + /* Only an empty free cluster's swap table can be freed. */ VM_WARN_ON_ONCE(list !=3D &si->free_clusters); VM_WARN_ON_ONCE(!cluster_is_empty(found)); --=20 2.43.0