From patchwork Wed Feb 28 15:49:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 207903 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3431325dyb; Wed, 28 Feb 2024 07:51:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVlgfJBfo4TLQxEcMt453hTASoCnN2gzSoUdkcgJDQNsch59Msx6cyb6PLPYcdFUB46D/bSdrhEd3aLNETlKVFRZnN+EA== X-Google-Smtp-Source: AGHT+IEnQeVCY4iPca6tYC+frzd91AIn47QnYwdFYZwXg9Hzn1h29tbnIjaDFUppQgM7fIaDnpsC X-Received: by 2002:a17:90a:b97:b0:299:7a52:8c1d with SMTP id 23-20020a17090a0b9700b002997a528c1dmr54941pjr.30.1709135496184; Wed, 28 Feb 2024 07:51:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709135496; cv=pass; d=google.com; s=arc-20160816; b=f+cL2J3Zg+AkrNeGYhoDyGLgQ60GS8tk16Bwl8PiuRGykd1f/FjvsXDvbw6h/XD6xr mUVscSQdMNdLHFQJG+wO2QsQ9biVZPKNOb3GfhcJDCCTqIZ2iSYllJiiI42OlfadyzdR kQAEwPoO8Y1iQFXhDLp8+svvmAQYrknjgrJCgXn71lGawA0e3UwFLbzvUti8ch9NN0ye jgNn/1QY94is0sxpjdJZz/0JwndNA1wtGTHhcIWsWJ02P6NfxcYHCprt5qskMJ6SnlOT 1KzRVvbcxZTMcCUwkbjmPElXk6yh3T3pkTMCWD+934D3UTGnGuPTnVETnIspTKnLfc0Z RqFA== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85300-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id v7-20020a17090a458700b0029a48def500si1548466pjg.144.2024.02.28.07.51.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 07:51:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85300-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85300-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 546992846CB for ; Wed, 28 Feb 2024 15:50:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BC25015D5A0; Wed, 28 Feb 2024 15:50:12 +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 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792156427076752628 X-GMAIL-MSGID: 1792158461914402334 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