Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2635582rbb; Wed, 28 Feb 2024 07:58:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU52fYSEWvHy2knOeANz+0vxA1PRebxjei53a1jft0MzzSECXUWIuRXHN8jhzp7Iq0LYxeKBWBRg3QWScn4MScDmii2EqQO5EJPIsIF2g== X-Google-Smtp-Source: AGHT+IH3zvr1oMU+hc7dEhMlDICv5X7mncAwDIjMg8ofhDUXYH/oLwZUO633hNv0L+AxicZMYMjd X-Received: by 2002:aa7:d716:0:b0:565:8e3a:5af2 with SMTP id t22-20020aa7d716000000b005658e3a5af2mr9004244edq.13.1709135904028; Wed, 28 Feb 2024 07:58:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709135904; cv=pass; d=google.com; s=arc-20160816; b=vNRrTtFgKeeN7MTydDIjN20atbKXtqel1vUrrVYtRPSxu38n0SQft/pm4eavS3MhGn 6SO4BJwc4uNNNn/SMAk5U2Phtvh0aLJ22ZylHxB/cNE7t0mTnisAgI64XuKcKyIdzXfi qc/tDMhNqu9jJSy7pWZFP5DKG2HzeGHnmzoGxPVhllRrxgXxCreqcR/FPbGW4LF5zgDt pfDkYwYxiFl4/IDOwAwlr9ZHNLYZUtyni5894DJPdx0WJJ0hU2uGKlfJgE81/LCmwFPi 3XAkIJixJSMISQ5+T1Ia+hd5625ytnMS4d0WD1Duk+NTb2CdA4uaVlcbZfgJK+F1FZcK hn8A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=kTVSWQckrG1uhUwf4yE6louRKCzZfuwwkT2CYEv4alg=; fh=d6GBuWMJv8OcnQyGWgk+cbt3qjd98yfFU47zuQsRck0=; b=y459PDb/TV42O59VEM2WK6QqGWCcrIF0EMg9BaNlAy1spCJMg0WAuiDaIrL+Z9Ylhu wwrFixq87258oz9K0kOBzP6ZG+ptmkwE9RgECcL8xb8KkNgndA1zYvfyGt/AmtJf08ot oQduPzgXW9di3vWjAG4kJD+3pCRSEuVePt7UZpJLws9E2wm2L3gC+/CyY4kjXmlGDigt pyQHpmrcDK31OoYf6EFVQPeArWLlPsS2bthNzWCRUdbHj4BnpaNFCgJZbURJb4ALNe3f FIVDNvnS6f8cuIm4zxS4YYY/yjEd0p5GrcZbL1q0crrRC/yQxhzkQJTRtQwwU3THMmK/ 7E0A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Z6a2dbqw; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-85300-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85300-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id cz8-20020a0564021ca800b00564511aa945si1780824edb.266.2024.02.28.07.58.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 07:58:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85300-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Z6a2dbqw; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-85300-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85300-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5104D1F2CCFF for ; Wed, 28 Feb 2024 15:50:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DCE2715CD76; Wed, 28 Feb 2024 15:50:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Z6a2dbqw" 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 237DC15B98C for ; Wed, 28 Feb 2024 15:50:06 +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=1709135409; cv=none; b=ZcoTEEaihkunkV7elw+XWCq6hX2gHfsqGSLbQdTMCo/06zVjEud1VZ8LQUUH6RtR7Zq42xbWLW7F97PoDhvYDLrxrx1fEMrxWbaA6JVAqZMUdHDJ2TVLiX7uSewuHN/5YJbypwtZ+9QQgc0iKxbv6H/+SCNJRKSQnvqSb1/UPQM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709135409; c=relaxed/simple; bh=A0aGELFfeQuryHSNoJxyQ82EHvZ+zG0MT55ob0nOeus=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YgAxFZUDdCeu/E2VQhw53xWBrcK8hbgMyExt6c2jDx99JHygyGMa1x5aQqAf1Zjejb0QyQHnQk3xnQBmUmhPfr0ppg+Ymk+NphXsXx6MewLTRDnSNdnqRD6aeWi0MIV7TWXnhRLaHPI3/AzQa/vKzrNiyOYUkl1/4R/IjcLwnxw= 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=Z6a2dbqw; 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 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=1709135405; 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=kTVSWQckrG1uhUwf4yE6louRKCzZfuwwkT2CYEv4alg=; b=Z6a2dbqwPm+KvT5A7tdVD+WC4yALKy9n7LbrvTyh9XpbDmn84qGxgCAiTe7mTvXHiMOdBg oIvs/mWxCVlXRJRwsAT3BJtv2L6nQDdTEoGPbz01rkkgKyPiMGbBUTEakx3wG+RbyUV51o xzEIlWuWUWspGgy0Z9yIIAxlL/F6G90= From: Chengming Zhou To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, yosryahmed@google.com, nphamcs@gmail.com, willy@infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chengming Zhou Subject: [PATCH mm-unstable v2] mm/zswap: fix zswap_pools_lock usages after changing to percpu_ref Date: Wed, 28 Feb 2024 15:49:54 +0000 Message-Id: <20240228154954.3028626-1-chengming.zhou@linux.dev> In-Reply-To: <20240210-zswap-global-lru-v3-2-200495333595@bytedance.com> References: <20240210-zswap-global-lru-v3-2-200495333595@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Now the release of zswap pool is controlled by percpu_ref, its release callback (__zswap_pool_empty()) will be called when percpu_ref hit 0. But this release callback may potentially be called from RCU callback context by percpu_ref_kill(), which maybe from the softirq context. So we need to use spin_lock/unlock_bh() to avoid potential deadlock. This problem is introduced by the commit f3da427e82c4 ("mm/zswap: change zswap_pool kref to percpu_ref"), which is in mm-unstable branch now. It can be reproduced by testing kernel build in tmpfs with zswap and CONFIG_LOCKDEP enabled, meanwhile changing the zswap compressor setting dynamically. Signed-off-by: Chengming Zhou --- v2: - Change to use spin_lock/unlock_bh(), per Matthew. --- mm/zswap.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 011e068eb355..da90933c6d20 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -459,7 +459,7 @@ static void __zswap_pool_empty(struct percpu_ref *ref) pool = container_of(ref, typeof(*pool), ref); - spin_lock(&zswap_pools_lock); + spin_lock_bh(&zswap_pools_lock); WARN_ON(pool == zswap_pool_current()); @@ -468,7 +468,7 @@ static void __zswap_pool_empty(struct percpu_ref *ref) INIT_WORK(&pool->release_work, __zswap_pool_release); schedule_work(&pool->release_work); - spin_unlock(&zswap_pools_lock); + spin_unlock_bh(&zswap_pools_lock); } static int __must_check zswap_pool_get(struct zswap_pool *pool) @@ -598,7 +598,7 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp, return -EINVAL; } - spin_lock(&zswap_pools_lock); + spin_lock_bh(&zswap_pools_lock); pool = zswap_pool_find_get(type, compressor); if (pool) { @@ -607,7 +607,7 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp, list_del_rcu(&pool->list); } - spin_unlock(&zswap_pools_lock); + spin_unlock_bh(&zswap_pools_lock); if (!pool) pool = zswap_pool_create(type, compressor); @@ -628,7 +628,7 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp, else ret = -EINVAL; - spin_lock(&zswap_pools_lock); + spin_lock_bh(&zswap_pools_lock); if (!ret) { put_pool = zswap_pool_current(); @@ -643,7 +643,7 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp, put_pool = pool; } - spin_unlock(&zswap_pools_lock); + spin_unlock_bh(&zswap_pools_lock); if (!zswap_has_pool && !pool) { /* if initial pool creation failed, and this pool creation also -- 2.40.1