From nobody Wed Oct 8 00:56:21 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (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 F2F22248880; Fri, 4 Jul 2025 04:23:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751603026; cv=none; b=DRBnEaC1SSoVHVB52QozWHC1VyBbqj7COUxNwEUqKHy93L8rxWtn3vZAFCbGpU/2222dvCO3vT+LjcITB/gr4LE5EGRwWXuqs0nZr1m95PbboS2t/ifbPxAlWFhRNkDcMbisYQMah/mz5D8ZA7uq4jkvAlg7TN4J6Z77AVJZyxk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751603026; c=relaxed/simple; bh=7hLKbUN5kQeQK56uPMIyZTaySLLTjyeQiMgA6j/1jP8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RHD04ry8Z5C9o2ilFVnGSi3NLciYOE+80QYc9e9H3JBa6WhxQtzeA/OpAl/Wb4OoDrFH7DK0pMXC23xtxgfiAGa/lBj66d+Ykd/5tveB/KD0SsMBKJBuIAGq8VrYW9mPzn9SEsRNa5ICJo/Bmk9b1EIHjyI600Caog2WC9nLnGE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=fVNmpjXb; arc=none smtp.client-ip=198.175.65.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="fVNmpjXb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1751603023; x=1783139023; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7hLKbUN5kQeQK56uPMIyZTaySLLTjyeQiMgA6j/1jP8=; b=fVNmpjXbv68Vm8Z+ocj5BlFZKdP4/0MV2FZSRIUbvkW7+Q96Zuq0G9Tt 7RxA0fRKX1JUGOyRGRz41wm08RQOnxnEF3w2THLqMRBif2gkkcnhVu/jp eEp4prZxOfJFXR1QPzs8RLzab/zjh+qLm4TyfiMeHo4WVnBhuHMx9suY3 Sew3Pol64XUx77p2ZwhB/i8MmJs44DNE7fI1a7CUiaDadj1QhWaqaP++k LcI5mcAmvj0zgL0woJPG4j5UtybEG6yIIqMGjUjmgtDwY/v3wQtiXRtMa xT2j44pEobXIfL0mUglUBrDK79qYksI6CZIQrEXOEJ4wHWZtRJUh/PuEm A==; X-CSE-ConnectionGUID: IA72LfnOQqua9GMmW3WZoA== X-CSE-MsgGUID: /IUcJfU+SRyx5GMSxhCCyQ== X-IronPort-AV: E=McAfee;i="6800,10657,11483"; a="53909210" X-IronPort-AV: E=Sophos;i="6.16,286,1744095600"; d="scan'208";a="53909210" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jul 2025 21:23:27 -0700 X-CSE-ConnectionGUID: GjbEcBklR36CThGPEXY4DQ== X-CSE-MsgGUID: VbYWktfqQmWWPuf0NL91CA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,286,1744095600"; d="scan'208";a="153968721" Received: from jf5300-b11a338t.jf.intel.com ([10.242.51.115]) by orviesa006.jf.intel.com with ESMTP; 03 Jul 2025 21:23:27 -0700 From: Kanchana P Sridhar To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, hannes@cmpxchg.org, yosry.ahmed@linux.dev, nphamcs@gmail.com, chengming.zhou@linux.dev, usamaarif642@gmail.com, ryan.roberts@arm.com, 21cnbao@gmail.com, ying.huang@linux.alibaba.com, akpm@linux-foundation.org, senozhatsky@chromium.org, linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au, davem@davemloft.net, clabbe@baylibre.com, ardb@kernel.org, ebiggers@google.com, surenb@google.com, kristen.c.accardi@intel.com, vinicius.gomes@intel.com Cc: wajdi.k.feghali@intel.com, vinodh.gopal@intel.com, kanchana.p.sridhar@intel.com Subject: [PATCH v10 20/25] mm: zswap: Move the CPU hotplug procedures under "pool functions". Date: Thu, 3 Jul 2025 21:23:18 -0700 Message-Id: <20250704042323.10318-21-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20250704042323.10318-1-kanchana.p.sridhar@intel.com> References: <20250704042323.10318-1-kanchana.p.sridhar@intel.com> 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 Content-Type: text/plain; charset="utf-8" This patch merely moves zswap_cpu_comp_prepare() and zswap_cpu_comp_dead() to be in the "pool functions" section because these functions are invoked upon pool creation/deletion. Signed-off-by: Kanchana P Sridhar --- mm/zswap.c | 188 ++++++++++++++++++++++++++--------------------------- 1 file changed, 94 insertions(+), 94 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 3c0fd8a137182..3538ecaed5e16 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -248,6 +248,100 @@ static inline struct xarray *swap_zswap_tree(swp_entr= y_t swp) **********************************/ static void __zswap_pool_empty(struct percpu_ref *ref); =20 +static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *nod= e) +{ + struct zswap_pool *pool =3D hlist_entry(node, struct zswap_pool, node); + struct crypto_acomp_ctx *acomp_ctx =3D per_cpu_ptr(pool->acomp_ctx, cpu); + struct crypto_acomp *acomp =3D NULL; + struct acomp_req *req =3D NULL; + u8 *buffer =3D NULL; + int ret; + + buffer =3D kmalloc_node(PAGE_SIZE * 2, GFP_KERNEL, cpu_to_node(cpu)); + if (!buffer) { + ret =3D -ENOMEM; + goto fail; + } + + acomp =3D crypto_alloc_acomp_node(pool->tfm_name, 0, 0, cpu_to_node(cpu)); + if (IS_ERR(acomp)) { + pr_err("could not alloc crypto acomp %s : %ld\n", + pool->tfm_name, PTR_ERR(acomp)); + ret =3D PTR_ERR(acomp); + goto fail; + } + + req =3D acomp_request_alloc(acomp); + if (!req) { + pr_err("could not alloc crypto acomp_request %s\n", + pool->tfm_name); + ret =3D -ENOMEM; + goto fail; + } + + /* + * Only hold the mutex after completing allocations, otherwise we may + * recurse into zswap through reclaim and attempt to hold the mutex + * again resulting in a deadlock. + */ + mutex_lock(&acomp_ctx->mutex); + crypto_init_wait(&acomp_ctx->wait); + + /* + * if the backend of acomp is async zip, crypto_req_done() will wakeup + * crypto_wait_req(); if the backend of acomp is scomp, the callback + * won't be called, crypto_wait_req() will return without blocking. + */ + acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, + crypto_req_done, &acomp_ctx->wait); + + acomp_ctx->buffer =3D buffer; + acomp_ctx->acomp =3D acomp; + acomp_ctx->is_sleepable =3D acomp_is_async(acomp); + acomp_ctx->req =3D req; + mutex_unlock(&acomp_ctx->mutex); + return 0; + +fail: + if (acomp) + crypto_free_acomp(acomp); + kfree(buffer); + return ret; +} + +static int zswap_cpu_comp_dead(unsigned int cpu, struct hlist_node *node) +{ + struct zswap_pool *pool =3D hlist_entry(node, struct zswap_pool, node); + struct crypto_acomp_ctx *acomp_ctx =3D per_cpu_ptr(pool->acomp_ctx, cpu); + struct acomp_req *req; + struct crypto_acomp *acomp; + u8 *buffer; + + if (IS_ERR_OR_NULL(acomp_ctx)) + return 0; + + mutex_lock(&acomp_ctx->mutex); + req =3D acomp_ctx->req; + acomp =3D acomp_ctx->acomp; + buffer =3D acomp_ctx->buffer; + acomp_ctx->req =3D NULL; + acomp_ctx->acomp =3D NULL; + acomp_ctx->buffer =3D NULL; + mutex_unlock(&acomp_ctx->mutex); + + /* + * Do the actual freeing after releasing the mutex to avoid subtle + * locking dependencies causing deadlocks. + */ + if (!IS_ERR_OR_NULL(req)) + acomp_request_free(req); + if (!IS_ERR_OR_NULL(acomp)) + crypto_free_acomp(acomp); + kfree(buffer); + + return 0; +} + static struct zswap_pool *zswap_pool_create(char *type, char *compressor) { struct zswap_pool *pool; @@ -818,100 +912,6 @@ static void zswap_entry_free(struct zswap_entry *entr= y) /********************************* * compressed storage functions **********************************/ -static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *nod= e) -{ - struct zswap_pool *pool =3D hlist_entry(node, struct zswap_pool, node); - struct crypto_acomp_ctx *acomp_ctx =3D per_cpu_ptr(pool->acomp_ctx, cpu); - struct crypto_acomp *acomp =3D NULL; - struct acomp_req *req =3D NULL; - u8 *buffer =3D NULL; - int ret; - - buffer =3D kmalloc_node(PAGE_SIZE * 2, GFP_KERNEL, cpu_to_node(cpu)); - if (!buffer) { - ret =3D -ENOMEM; - goto fail; - } - - acomp =3D crypto_alloc_acomp_node(pool->tfm_name, 0, 0, cpu_to_node(cpu)); - if (IS_ERR(acomp)) { - pr_err("could not alloc crypto acomp %s : %ld\n", - pool->tfm_name, PTR_ERR(acomp)); - ret =3D PTR_ERR(acomp); - goto fail; - } - - req =3D acomp_request_alloc(acomp); - if (!req) { - pr_err("could not alloc crypto acomp_request %s\n", - pool->tfm_name); - ret =3D -ENOMEM; - goto fail; - } - - /* - * Only hold the mutex after completing allocations, otherwise we may - * recurse into zswap through reclaim and attempt to hold the mutex - * again resulting in a deadlock. - */ - mutex_lock(&acomp_ctx->mutex); - crypto_init_wait(&acomp_ctx->wait); - - /* - * if the backend of acomp is async zip, crypto_req_done() will wakeup - * crypto_wait_req(); if the backend of acomp is scomp, the callback - * won't be called, crypto_wait_req() will return without blocking. - */ - acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - crypto_req_done, &acomp_ctx->wait); - - acomp_ctx->buffer =3D buffer; - acomp_ctx->acomp =3D acomp; - acomp_ctx->is_sleepable =3D acomp_is_async(acomp); - acomp_ctx->req =3D req; - mutex_unlock(&acomp_ctx->mutex); - return 0; - -fail: - if (acomp) - crypto_free_acomp(acomp); - kfree(buffer); - return ret; -} - -static int zswap_cpu_comp_dead(unsigned int cpu, struct hlist_node *node) -{ - struct zswap_pool *pool =3D hlist_entry(node, struct zswap_pool, node); - struct crypto_acomp_ctx *acomp_ctx =3D per_cpu_ptr(pool->acomp_ctx, cpu); - struct acomp_req *req; - struct crypto_acomp *acomp; - u8 *buffer; - - if (IS_ERR_OR_NULL(acomp_ctx)) - return 0; - - mutex_lock(&acomp_ctx->mutex); - req =3D acomp_ctx->req; - acomp =3D acomp_ctx->acomp; - buffer =3D acomp_ctx->buffer; - acomp_ctx->req =3D NULL; - acomp_ctx->acomp =3D NULL; - acomp_ctx->buffer =3D NULL; - mutex_unlock(&acomp_ctx->mutex); - - /* - * Do the actual freeing after releasing the mutex to avoid subtle - * locking dependencies causing deadlocks. - */ - if (!IS_ERR_OR_NULL(req)) - acomp_request_free(req); - if (!IS_ERR_OR_NULL(acomp)) - crypto_free_acomp(acomp); - kfree(buffer); - - return 0; -} - static struct crypto_acomp_ctx *acomp_ctx_get_cpu_lock(struct zswap_pool *= pool) { struct crypto_acomp_ctx *acomp_ctx; --=20 2.27.0