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]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3942FC83030 for ; Fri, 4 Jul 2025 04:24:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 144F6440154; Fri, 4 Jul 2025 00:23:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A936440169; Fri, 4 Jul 2025 00:23:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB023440168; Fri, 4 Jul 2025 00:23:45 -0400 (EDT) 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 D9B63440154 for ; Fri, 4 Jul 2025 00:23:45 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 72A39BF0E8 for ; Fri, 4 Jul 2025 04:23:45 +0000 (UTC) X-FDA: 83625288810.21.D9FF01A Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by imf11.hostedemail.com (Postfix) with ESMTP id 53DFE40004 for ; Fri, 4 Jul 2025 04:23:43 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=FtgkxKvw; spf=pass (imf11.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 198.175.65.17 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751603023; 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:dkim-signature; bh=VhD/EyU9p0+nrc4rkijfLWMqG9nE7q+N65NwKuX5Bt0=; b=Ww0Echma+qTBnYJzBMG0cS05AsscjSjo0hSxRcVO8IIJM+nUig/SLGEI7pBYMVuZLZAigh Njkzh31iw7ors9MLi8QcaIpw5LQuY28lI6lr8sXAF+MNJiGPDQjVc8GeMKxuYRZS81sly8 39SnLVc2oTL5CZDATZGGacNRK0MF5fs= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=FtgkxKvw; spf=pass (imf11.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 198.175.65.17 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751603023; a=rsa-sha256; cv=none; b=qCJVQa1OxDERSrviO6f+GAWB5S7XQb2led4105zaQ7om2UdvDs3BIiVk0Pzr2L5I5NeGjt EBh/BeODbwAJVu8zBYwJDY+hdBDHDN2NX8WXhM5DARYjW513bggjf2LbE6e6lyNX8dQ6s1 Qv7NSME8KxJ1Mer0AB95Em2f8M27RjE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1751603024; x=1783139024; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7hLKbUN5kQeQK56uPMIyZTaySLLTjyeQiMgA6j/1jP8=; b=FtgkxKvwpF55+ssF/u442g/EsATDlDrI/hJZiOcP682zHQqMkzjoXVWE PmVIaxWwCBkfBFQqeyi/f0SZic7XNtURbNI35dAhCFPPEofABm31EpxWu if8YSxr9PQoYELU4pWLv3RDiotdhmuI4oFJcPDC6OVpanwuW/9xPwjSa6 M0DYyRTBdmBkHgZf+cKAhpmeRf5R4bTNa6Djrvmcw0s5J0ji4ag3f9ZC8 cQDHCtS+ZKHZAqIFVvEx4lGbjjSlkNiX8I9moLEHjnEUjDtd2jMlCrqHO BzTBbooZ5wVaicwBx0WCAG+mpBK0Aoygzs/uIH3lhTxyxw1zH9OrXVUp1 w==; X-CSE-ConnectionGUID: nnwUzQ0SRHGrpTGRtq+jtw== X-CSE-MsgGUID: hOsD1rXfTbW5oGyKn9JboQ== X-IronPort-AV: E=McAfee;i="6800,10657,11483"; a="53909213" X-IronPort-AV: E=Sophos;i="6.16,286,1744095600"; d="scan'208";a="53909213" 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> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Stat-Signature: y8ez5b68ezfkhxuzerrn7kpqae9kuwb7 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 53DFE40004 X-HE-Tag: 1751603023-372738 X-HE-Meta: U2FsdGVkX1/nkuCYv1hwxN7GhR696O7bwcXCaKdYwSAVKbTH5THmmWM1Wa1cYyxch9AwuFhVeaabrsamwSYd+rjCT1MNXUb52JonzyqhpK9CE9OR8ewtLw/dxMHYC4G65mT5F7S1h4GfqtmfEu6//EarMEuvzxm94xaL9AM+gkQvnMOMcrBjLIAqUphqFQc5B5WYblMug9i2fxaf/lTJG3sdAZp884pTiOJkhDW82leJA/hKfitqocIdWHbmsOiCK4RPgNhkm8/Y1l5FqR3twJEwocGEe10utw5gmfrcVH9JcStuP0L6Tysaaw1U70JASK5IZbUGb6dglE0ybJzw7SpYWVZNDTIWo4vGC3q5FM0+oBmWELG/IY1x8uadDnolUp+4MJX0MuV+SFMpy07548bnm6I2KpI7BPURM2u/BIbZyOvBJoS7GFmE/gPrcvNjFKtOZLPtxn8f7G8zmeIhjWFRnJgUPYeBL+5OA2XzfPKHWwxPBU/XsHE6W1uteGrZKNUaf1Bhg2XaLwxRahoNP2GPjkAVT1i/Gdc7LIlH99Ju9/JbLccjYduCn5IbFIBF3oXEgTtv8vMIQJDgmWc0oRXX943B8CZF3v/k9guGwDk61AoUcixF8SJcWUunu9igEhN8XPn2KREmGbk9pvvC47EKFB1DY3a4gd84LacHprofXSVE8t/dhgWMaTIAld7lU//dywvIUf8rhtdIAp/3mJ8bmsB4Czozpj/YXj1J0AXf/oCo0XM4G/m7wy28FaKYuBTLJSz7CpVfBidtkXmt5b0ioAcpKohMQ5GBnQmuB8LD7+dNlh6o0Y/NPxaEM3fyevOD2awE9CV2fFRXhm91/6M8bzuhychs1WkUrePGweW4blnjg5tiQm2nvUlbiNWvfyZy2UDYiRk6ZSm81XGrNwLqyXhb/YQXsj6tj6pjI8i25hXofMOPVs5v0AhlWRzDyfuWASJuH6P1d0tdoNk tDnXq3LY 4L1aINk2VDHe6mrDGc9hvlpf3xzdM7NZT6s+fV6dRL93/gKC5uaMD8BKLGkj7/mPMT+UCSsRUhQzyEUj8V6j1pE4BF9WB3SDQznFUUilbvYWOwTrQ60HHr6sXjmAIfCcxho8ilvTvg5Mj7CmFceW+/9HqxJd335Ej49OI/2cTOpXBuKphZ/pvs9dC5gyp9mVzrMtijjESKbiySbtc7Eo0tp9YGA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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_entry_t swp) **********************************/ static void __zswap_pool_empty(struct percpu_ref *ref); +static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node) +{ + struct zswap_pool *pool = hlist_entry(node, struct zswap_pool, node); + struct crypto_acomp_ctx *acomp_ctx = per_cpu_ptr(pool->acomp_ctx, cpu); + struct crypto_acomp *acomp = NULL; + struct acomp_req *req = NULL; + u8 *buffer = NULL; + int ret; + + buffer = kmalloc_node(PAGE_SIZE * 2, GFP_KERNEL, cpu_to_node(cpu)); + if (!buffer) { + ret = -ENOMEM; + goto fail; + } + + acomp = 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 = PTR_ERR(acomp); + goto fail; + } + + req = acomp_request_alloc(acomp); + if (!req) { + pr_err("could not alloc crypto acomp_request %s\n", + pool->tfm_name); + ret = -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 = buffer; + acomp_ctx->acomp = acomp; + acomp_ctx->is_sleepable = acomp_is_async(acomp); + acomp_ctx->req = 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 = hlist_entry(node, struct zswap_pool, node); + struct crypto_acomp_ctx *acomp_ctx = 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 = acomp_ctx->req; + acomp = acomp_ctx->acomp; + buffer = acomp_ctx->buffer; + acomp_ctx->req = NULL; + acomp_ctx->acomp = NULL; + acomp_ctx->buffer = 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 *entry) /********************************* * compressed storage functions **********************************/ -static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node) -{ - struct zswap_pool *pool = hlist_entry(node, struct zswap_pool, node); - struct crypto_acomp_ctx *acomp_ctx = per_cpu_ptr(pool->acomp_ctx, cpu); - struct crypto_acomp *acomp = NULL; - struct acomp_req *req = NULL; - u8 *buffer = NULL; - int ret; - - buffer = kmalloc_node(PAGE_SIZE * 2, GFP_KERNEL, cpu_to_node(cpu)); - if (!buffer) { - ret = -ENOMEM; - goto fail; - } - - acomp = 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 = PTR_ERR(acomp); - goto fail; - } - - req = acomp_request_alloc(acomp); - if (!req) { - pr_err("could not alloc crypto acomp_request %s\n", - pool->tfm_name); - ret = -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 = buffer; - acomp_ctx->acomp = acomp; - acomp_ctx->is_sleepable = acomp_is_async(acomp); - acomp_ctx->req = 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 = hlist_entry(node, struct zswap_pool, node); - struct crypto_acomp_ctx *acomp_ctx = 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 = acomp_ctx->req; - acomp = acomp_ctx->acomp; - buffer = acomp_ctx->buffer; - acomp_ctx->req = NULL; - acomp_ctx->acomp = NULL; - acomp_ctx->buffer = 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; -- 2.27.0