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 D825DC3ABBE for ; Thu, 8 May 2025 19:42:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8D7C6B00B2; Thu, 8 May 2025 15:41:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B421B6B00B6; Thu, 8 May 2025 15:41:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F6DB6B00B5; Thu, 8 May 2025 15:41:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6931F6B00B2 for ; Thu, 8 May 2025 15:41:50 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 68D605EA55 for ; Thu, 8 May 2025 19:41:51 +0000 (UTC) X-FDA: 83420760822.30.0E65344 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) by imf21.hostedemail.com (Postfix) with ESMTP id 499191C0003 for ; Thu, 8 May 2025 19:41:49 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=RpG+K0mn; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf21.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 192.198.163.17 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1746733309; a=rsa-sha256; cv=none; b=zuPYtA0IPNo/k6Q+R3KBBi/tARc2waa78ndQbrEEG3dtCGofNQsQsWxDlpvtFNFz4C9M6W AVGJYKpGKg/54+xcj4jEpc4hXnazi2K5TEZeySaVNoP0VT7lWTfVT/THjuGTZ/0xsBHNoY nBm658mzXtwGG0Q+h5On4Ofi47afMrY= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=RpG+K0mn; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf21.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 192.198.163.17 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1746733309; 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=jVagB6zoblHUTkkzaBUtvedqQcHq8jggyMmaz/faOpY=; b=uncBnzFJMFEm0BmiZw9p21beNfHXCaBsMgp5LhuquKHpWl8c0KDPbi4dSFddkwGktujovN Shgcfd4MWiwD+Eq4yJT9zb7xWhRrrJbnr8ls215xnvflrSXXtLBYKXZ3zeE1WoZMdNTZPD 5vZC11esWJzXPHd3Cy/AxiPrnw8u69E= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1746733309; x=1778269309; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=l0g+LAnddWvzoTX2shNX+O/DFhTRbmW793v8KGvd668=; b=RpG+K0mnvrVz1Wto8V5yc5sB2UCEMFmfqRZDD+w6J8CpqVyJclKdQ6wg yulI1iAR6Uyvl2sK0icxcLf+i1WbchGeanYZiwzcvYszHKWIsDY9QOhoO Ot0mUzU1eyqLvWXjm+nNB0lXmeTass4gp0d2F5ZckO04b4rryh331/igT hkyRGajYLR/eh6tL+kRZZT67hlvAWLGoT3eypq56LK6zV+mzjGxe/IhBS lljZ+qXIBF9OELjCBhXTL7/X3gDI57MlaCj+cj4um9n8Weaz1whxFUPCB lGZ8E5t5QX1ahf2Qp+G4JP20k5o3gg1NU+yH5N7YMOFdl/rnY9do/g+ns w==; X-CSE-ConnectionGUID: gPAbKnHMSg6lW6t26R5MLw== X-CSE-MsgGUID: KOmJiki0RXmXsknpRNBUEg== X-IronPort-AV: E=McAfee;i="6700,10204,11427"; a="48454762" X-IronPort-AV: E=Sophos;i="6.15,273,1739865600"; d="scan'208";a="48454762" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2025 12:41:44 -0700 X-CSE-ConnectionGUID: /clEK4/uTbivhaIBWrz6NQ== X-CSE-MsgGUID: c1sVrN5QSga1BE5y1P/+VQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,273,1739865600"; d="scan'208";a="136880878" Received: from jf5300-b11a338t.jf.intel.com ([10.242.51.115]) by fmviesa010.fm.intel.com with ESMTP; 08 May 2025 12:41:43 -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 v9 14/19] mm: zswap: Move the CPU hotplug procedures under "pool functions". Date: Thu, 8 May 2025 12:41:29 -0700 Message-Id: <20250508194134.28392-15-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20250508194134.28392-1-kanchana.p.sridhar@intel.com> References: <20250508194134.28392-1-kanchana.p.sridhar@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Queue-Id: 499191C0003 X-Rspamd-Server: rspam04 X-Stat-Signature: 3qcmikth7sqirnb198g1wa8duds98uzk X-HE-Tag: 1746733309-331388 X-HE-Meta: U2FsdGVkX1/xIrdRP+okzMcy6ipUVsXYlbUB/QTulZVX9dpdVu+A1fUD6168Fw/bloVRyvNM3Q7OKs3QVs8yZmWcyq3GLPTiSFDXxCkhAqLdfBtUID6CYA377eM60D0KLzlK676oDQE2AND3xSvoW38z5KbavfvVFMsWnbNu1wUL+H+qIBz2MZFaJ4A7Xh9UiHGfhyJ0lCjelv5YlnXXFAll0NeIjI7K+uehMQfCBpjtyp636zD53dAXYlPEIS/7QSY/U2WajrWt2yhm2H+wpLlBABKo2GBPCQEJ3S327C54IBOag+AoAL5qpUYZXU5odXW3oEDQWRO2F6R+d+D0ZHqCEkdc29eAPL4voNsFbxi7li9H7zi3d5hcWezqAtvSomDuAoDNZn3HdJn2Dx772FEv9sj0DKGJ0Qn358BwO8WI1cQMv/2EuhTNHj8xQzf50jxE8dv2qi1mjwa+v8w0r21L2M/0dTxj8p+x+libumx9e6zUBdCc2NgY2+Bfnpcw8UjrBBNwNZVb3swrFXpHUwRCBTjGF9DL3Dig5mFtvb2Fb9zd8+HBtModoiMUvLgSRNxoqYPAy2mG9Tz+ZsgIdXLcQl4zCN9FYPs4sEdlRQF6wJ4PaFCFPOIr8YEdJBrkNPPvKKrIdhpsEIqjBbkmgReNj9g7jZGOJwHEHBGZud5YMg+gcjGb+yUH+FugDFT9gns/fYKTuW0jTxhNShf4q1ATYpavkRH4q7/v9rQ3d+qRJmJFxNknGERr+EHZmK6fm340PhFswLL8uSuX8dYq1ZJD58KP1tLvA1ypTT/4yQ3nAGZAgiF+JfxvVX3dQENvGwE0Og8P3ciOfYFN3+Eyb1v5vPcHztRKf1uYO+VRmMclTiL0dNv8kSzXLNZ0iaKgiwUDLcSarPgl9YWb66r94aBgfh55Wby7q3afKPGSghh9ZdYBpQdmqyBbqBxzpuKlFajmvWzAq1QESdp0Sju K6IV/sy9 BhVoxAoqTkt1C3a940qZ9rlqZ6AF4dzV+1Mz4DoV9vEzXN9CWfABqcPHw0yFuUxSxDAzFicCPN68tGsX8+KPz+O2VDsLobmlbsz+DwebBrdMjYLMTBr8fZpFMuOFLpTeYcGCkaJ1NrE3Nf1W66+4K0r4G1KZq346qO0HVR7+izXoThQ3yghnlcDmwCQ== 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 455e9425c5f5..358dad3e612a 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