From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lgeamrelo03.lge.com (lgeamrelo03.lge.com [156.147.51.102]) (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 5D74A342177 for ; Fri, 6 Mar 2026 13:52:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.147.51.102 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772805187; cv=none; b=KkPeqMiHpDGvndJ8Fb4HgGiQQ6IQaPZVgVRxjKkuqdiXN2sKnRyoazS7T8pfGfarbc9O5lFRzk0ooJkfw0HJ8d1mSIojjHze2OYcQNmrEP3wa27jDoH7J0Mq4jojo0bgtF6Qgas8k8Y52a/OL7ixxkQySA8BV6gh9tM6BfY1yTA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772805187; c=relaxed/simple; bh=QjIulhtS/pbbqTejgVH97vxsV6+tuHiJyhUflVMg2d8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pJgSaVXGIi3fBWdNqvFOXXRY/UpbtJVb3aK1gdFX5iov0Rli0LyD58WB2j6E+VUbx7GFFn1ijiqlYTXZUk3C3r5JTxhLWVDSRxbCX2e0OA0DXv9UBPjGoHDVLeoToZd25X6NekDBB9NJlucJ0Jab8XuMRjlIPl01NRxB8/jOPkk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com; spf=pass smtp.mailfrom=lge.com; arc=none smtp.client-ip=156.147.51.102 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lge.com Received: from unknown (HELO yjaykim-PowerEdge-T330) (10.177.112.156) by 156.147.51.102 with ESMTP; 6 Mar 2026 22:52:35 +0900 X-Original-SENDERIP: 10.177.112.156 X-Original-MAILFROM: youngjun.park@lge.com Date: Fri, 6 Mar 2026 22:52:08 +0900 From: YoungJun Park To: Hui Zhu Cc: Andrew Morton , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hui Zhu Subject: Re: [PATCH 1/2] mm/swap: fix missing locks in swap_reclaim_work() Message-ID: References: <02f5912caa6c427705bf8da43497801caf3b102f.1772797581.git.zhuhui@kylinos.cn> 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: <02f5912caa6c427705bf8da43497801caf3b102f.1772797581.git.zhuhui@kylinos.cn> On Fri, Mar 06, 2026 at 07:50:36PM +0800, Hui Zhu wrote: > From: Hui Zhu Hello 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 Can isolate_lock_cluster() actually invoke swap_cluster_alloc_table() on a full cluster? My understanding is that full clusters already have a swap_table allocated, and swap_cluster_alloc_table() is only called for free clusters that need a new allocation. If isolate_lock_cluster() checks !cluster_table_is_alloced() before calling swap_cluster_alloc_table(), wouldn't the full-cluster reclaim path skip that allocation entirely? > 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. If my assumtion is right, table is not alloced so synchronization is not need. Also, percpu_swap_cluster.lock and si->global_cluster_lock appear to protect the percpu cluster cache and global cluster state, not the allocation table itself as I think. Best Regards Youngjun Park > 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 > >