From nobody Thu Apr 9 12:06:18 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 From nobody Thu Apr 9 12:06:18 2026 Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) (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 BB35E367F27 for ; Mon, 9 Mar 2026 08:06:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.186 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773043594; cv=none; b=lk6WsVJDb5y00Pf+Yd3jAyV4IOh8GnaJEpDDXet577/468pZg6TfcTBtt56ZvCBHXohJYosrYy0IDjcr9SGoXxrjtpejQHN0HkuFX4XhnSExYn84uzqH8iADoioJu+nsnxR0SAc2m9BUS6Z88HCq81dZKCw2BOn6Xe8aCBjWD54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773043594; c=relaxed/simple; bh=ApWMQVBWooXdCYyjaw+zRE6xsU+5G2WqEojyFqHZ8tI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JWrQEgoP2kpsUMe82LtOKehHccCfRMGIpAiy9qWTjbk66l5J+CsFuQDh8A1Y5rmCSaSjwMTzU8oOMLhZq01Ha5U6U4PKejbo80yMl1VlxEQWLu7EW7mpoSkc50lHN/aq8Q8SRxGJWS2QXxpXn9xIifPDG+izgehaXXE6U08TmJU= 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=ZqEWk6yS; arc=none smtp.client-ip=95.215.58.186 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="ZqEWk6yS" 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=1773043591; 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=tpBsCDLcm2n1XrByJy4y0AKMK904EnYCVpywQiSZvCo=; b=ZqEWk6ySKPHVezXprH4LiiDhG4zpepfYXmtDqReWcGDqrt/yqnpRmsKUMckTzgguxd1FHp H70+NcvkMtCEmdgekuLrxqjTixhm6i/vpy+vXGuhLdu+crmhkyjWJKc1KAIDWbWEEikTCu 0I8JU1K4ChTGCMiAp3kN8SCRavBr1sw= 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 2/2] mm/swap: Add lockdep for si->global_cluster_lock in swap_cluster_alloc_table() Date: Mon, 9 Mar 2026 16:05:42 +0800 Message-ID: <879eff096e46c02f994de62dc210a95cc58e3f19.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 Add a lockdep_assert_held(&si->global_cluster_lock) in swap_cluster_alloc_table() for non-SWP_SOLIDSTATE devices. The function already requires the caller to hold both ci->lock and percpu_swap_cluster.lock. And it also necessitates si->global_cluster_lock when the device is not SWP_SOLIDSTATE. Adding this assertion ensures locking consistency and helps catch potential synchronization issues during development. Change the order of lockdep_assert_held() to match the actual lock acquisition order. Signed-off-by: Hui Zhu Reviewed-by: Youngjun Park --- mm/swapfile.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 3fc2eb30c187..b31b86263b89 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -476,8 +476,10 @@ swap_cluster_alloc_table(struct swap_info_struct *si, * Only cluster isolation from the allocator does table allocation. * Swap allocator uses percpu clusters and holds the local lock. */ - lockdep_assert_held(&ci->lock); lockdep_assert_held(&this_cpu_ptr(&percpu_swap_cluster)->lock); + if (!(si->flags & SWP_SOLIDSTATE)) + lockdep_assert_held(&si->global_cluster_lock); + lockdep_assert_held(&ci->lock); =20 /* The cluster must be free and was just isolated from the free list. */ VM_WARN_ON_ONCE(ci->flags || !cluster_is_empty(ci)); --=20 2.43.0