From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6D325F01828 for ; Fri, 6 Mar 2026 11:51:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D7F616B0092; Fri, 6 Mar 2026 06:51:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D3FBF6B0093; Fri, 6 Mar 2026 06:51:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C83246B0095; Fri, 6 Mar 2026 06:51:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id BA8696B0092 for ; Fri, 6 Mar 2026 06:51:13 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6A2A9160319 for ; Fri, 6 Mar 2026 11:51:13 +0000 (UTC) X-FDA: 84515472426.15.423E8DC Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) by imf13.hostedemail.com (Postfix) with ESMTP id AF18720006 for ; Fri, 6 Mar 2026 11:51:11 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf13.hostedemail.com: domain of hui.zhu@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=hui.zhu@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1772797871; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tRryoNWHbDmWo07p6jg9/dMBlY5zaIRR554kEcFC/KQ=; b=BNY4OsdhWs+R1bWwBtmAll1VUCiLmUsPuRvHci+CqsJHlONX5mIOo7UYv2kyt5F7fyhvvJ LzV05puZ4sp4mxu5kW4Mh7Mg4GksLC67kCDSGQBeow/AbryVYKbdW+YN+/4HNpoDj0KCEH 2mOM6zeLC3F5uCkt0ZUw5LepJtsZRbk= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf13.hostedemail.com: domain of hui.zhu@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=hui.zhu@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1772797871; a=rsa-sha256; cv=none; b=aWS9sfCosaNaMSoXrR47dnUYJsED9/9as6efAeUB9TDnOO6o/9Z72veSDR1YP4Pq8D5Gcg ThwEo7j6u51GyRheqDqcgUWUm+tDDwYzPEpxpAO9NpMXpBEy6DjmNDrpp1dN8sl40OkBp0 fzgw6LvgzBMLvdSV7Pt1LG1s6TQyqG8= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Hui Zhu To: Andrew Morton , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Hui Zhu Subject: [PATCH 1/2] mm/swap: fix missing locks in swap_reclaim_work() Date: Fri, 6 Mar 2026 19:50:36 +0800 Message-ID: <02f5912caa6c427705bf8da43497801caf3b102f.1772797581.git.zhuhui@kylinos.cn> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: AF18720006 X-Stat-Signature: womskeorwj9hq3rkaj1p3nz3cx9ohbm8 X-Rspam-User: X-HE-Tag: 1772797871-163996 X-HE-Meta: U2F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Xn0PjURDtpbgxdUWdTc= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 the swap_reclaim_work() path fails to acquire percpu_swap_cluster.lock and, for non-SWP_SOLIDSTATE devices, si->global_cluster_lock. This patch fixes the issue by ensuring swap_reclaim_work() properly acquires the required locks before proceeding with the swap cluster allocation. Signed-off-by: Hui Zhu --- mm/swapfile.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/swapfile.c b/mm/swapfile.c index 94af29d1de88..2e8717f84ba3 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1031,7 +1031,15 @@ static void swap_reclaim_work(struct work_struct *work) si = container_of(work, struct swap_info_struct, reclaim_work); + local_lock(&percpu_swap_cluster.lock); + if (!(si->flags & SWP_SOLIDSTATE)) + spin_lock(&si->global_cluster_lock); + swap_reclaim_full_clusters(si, true); + + if (!(si->flags & SWP_SOLIDSTATE)) + spin_unlock(&si->global_cluster_lock); + local_unlock(&percpu_swap_cluster.lock); } /* -- 2.43.0