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 BDF0FC8303D for ; Fri, 4 Jul 2025 18:39:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1DF216B806C; Fri, 4 Jul 2025 14:39:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1900F6B8067; Fri, 4 Jul 2025 14:39:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0A6D96B806C; Fri, 4 Jul 2025 14:39:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EE5B26B8067 for ; Fri, 4 Jul 2025 14:39:42 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 945CD57855 for ; Fri, 4 Jul 2025 18:39:42 +0000 (UTC) X-FDA: 83627445804.11.97521DD Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) by imf21.hostedemail.com (Postfix) with ESMTP id A98801C0008 for ; Fri, 4 Jul 2025 18:39:40 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WMjrMLwU; spf=pass (imf21.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.219.51 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751654380; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ZLSI4jmhCdQ92xJmwXMCUX4eg1LhZKqmG9IrE2rHlKE=; b=sOXzJCkdHErT1mmtg0p/4qgq9X3mh1LliFQkZsbjBOwDME3fPv8hxDKmxtL7k/a70lAYfS AnuPbjgm0EGp280p8CDUuUuFITv5fdot4qEXg1tUv0Va7k/a57qhlQhpzcjPkSu+/0oi6a V8VmZQIqmHVZsJ4tu7o0FHGhoPg1b4c= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751654380; a=rsa-sha256; cv=none; b=eigpbOoMEj+GJmMbtuELPrZy3Dfav52RdVV4Fm1fafjrf6hoqZblUC9DUnNTItJeDVJbwU mp0DepeOd4O2wcw0/sDlQnpXcqUMu0KYfB1mnrnWO4icXztVYRNtOaSKLxfuhpyqf9/4Ab Q+Oj65zIE2N3A8s+tZYDYlmko76chds= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WMjrMLwU; spf=pass (imf21.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.219.51 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-qv1-f51.google.com with SMTP id 6a1803df08f44-6fad4e6d949so7690926d6.0 for ; Fri, 04 Jul 2025 11:39:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751654380; x=1752259180; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ZLSI4jmhCdQ92xJmwXMCUX4eg1LhZKqmG9IrE2rHlKE=; b=WMjrMLwUYAHAxCM7m2ayaKr4LO7kNC1Ppj8bsEef2SVeEGUZ7ei6CBDV2kC9AXS8mU 9viUuNdSsgS0xOoYwniT9VVc53CAWRlJW0HhMEyPPNlPfP1NWgxKme7FoGcg4X5pdITg bVsDqgW5bGU21jpC0sR04QtQd6UkInzUpd/ap4v7NjkGkwbXbtmtRLlqVLvfR7zMRZnZ eKCr1qSRbmmLzy6DKdvXVG038fJ6XBi0FKLtLbBtJ7XZ1RxjIpd9uRuH/UwsIGUcR/+r GpzWSgxWxYF9d9lBC+gzCgZfaHoep1X05ZQKRiXf7RifqfBx5ZkdBYbaamhvWRYJAt3h B03g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751654380; x=1752259180; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZLSI4jmhCdQ92xJmwXMCUX4eg1LhZKqmG9IrE2rHlKE=; b=hPbcW9dswkfulLemZq9tZdQbMN/F1n5HGCk1HFfQ9cOtNFZLPbHVxy0tIy3zu9tKzv mIA5vJULElnui4z8L1XqiiOXUSfFItJCdyrh3OnkUDp1UToGJsqwARG7QsAGlVfr3yOY f2kUkl+JCwrXk96klkJzYS1hBeKOthlRrLCLycqDbVHdyfdEhDHl4HTu2frg+jj6IqT6 SU1rQfnCrs0RxYFxXlNfxliuqLfK/fS8ZYZXJvgnKuCxn2pOgPcZJMM4NDZaE1zAdcvf xZ6UZOM31aIs9hdIipKF10k5b0tCpB1WHT0lHamlZMod7ykaWPZFsJL7dudOhVvW11S1 YOWw== X-Forwarded-Encrypted: i=1; AJvYcCXzLacTSGjcyTvVB40WtIbFaXQUg/d7NWQtu61wBW4fjJ7J+sUs358hdxnlr5NOMeX+p5oFlREnKQ==@kvack.org X-Gm-Message-State: AOJu0Yz3sYllKUtgmnhGuTLdUY0MpdLZKAvau72OtX8kRXis09Rbosv2 FHsaDHojSmt4pREV5FiRcBRhvxm2Q29LQoeMfSeTNktN3npuwHn7tF8SPZbhEld2Ec17KdfmeLy Gk5unYUr88Fv5YWVRpLRfNDPw231Oh4g= X-Gm-Gg: ASbGncvaY9vqugCWdCO3gY6WdPPHipx4npnePb8TjTkkoDmFt1Off5UMUyUDI9YMJDp Qq09un4Ld19I4hvxywLup0EqwaCJA5sUTJlqG1kYLVr/F5OrAlgN9VTWS8sSeF4l9EQg01N7ZJs Lnna+3vECjFoftMpvnFHp2fty9zOVTdLi9xIiEyQ77PJw= X-Google-Smtp-Source: AGHT+IH+JWc+g38J/FXavoBpRFG4t26kf9xdnO56cRpAbEuqXLbNRw6f7/YaTbEFWCoX0zCKHZqZhrMJuqELKkmF+OE= X-Received: by 2002:ad4:5dcb:0:b0:6fa:fbde:7e23 with SMTP id 6a1803df08f44-702c8b71f2fmr45565996d6.8.1751654379557; Fri, 04 Jul 2025 11:39:39 -0700 (PDT) MIME-Version: 1.0 References: <20250704042323.10318-1-kanchana.p.sridhar@intel.com> <20250704042323.10318-21-kanchana.p.sridhar@intel.com> In-Reply-To: <20250704042323.10318-21-kanchana.p.sridhar@intel.com> From: Nhat Pham Date: Fri, 4 Jul 2025 11:39:28 -0700 X-Gm-Features: Ac12FXwCQLsXq5LlRFraBt2YLteHvlw4htbXYU6u9qy7Z6Cs1ldYzuebXMyBqvg Message-ID: Subject: Re: [PATCH v10 20/25] mm: zswap: Move the CPU hotplug procedures under "pool functions". To: Kanchana P Sridhar Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, hannes@cmpxchg.org, yosry.ahmed@linux.dev, 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, wajdi.k.feghali@intel.com, vinodh.gopal@intel.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-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QUwa3e7+KdL1/nDZGKogLz91BUBiyMkS13HeGgrWd57+blJ4yJlfxTHdNnm4CWRXzHOor0+6dBXLVXQJsYrIk1bGyXfVgz3LdfWK4/YB6Q1hZMoXC3uHTgP5IWId0gjNo4F25YiPFeXwpdHY+QDFad/s7BS2lTNGcPG2OCK7/DCsexjj44V47BhQ2HdoRAYOfKy5dSpck/hy/IoN4IZfmzI7pbrkjK/4ozcHbCwE7lD87CgY3Zi5wotIxTssdS70Mo6NxGASs6Hu8qYESS/5HrnjU7J7tXHOsr19qqwL5kjmciFKSjWeYNaBFFTFOWfQY2ngrQApD8GjlQOIcny4yhfzwiochuEe9aE8A1oAxCqE9dwcRw1WPAHUUlf+yTBgfkwECant6LW95/C6IVCVFfNAxyy2TdtabTB+5 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: On Thu, Jul 3, 2025 at 9:23=E2=80=AFPM Kanchana P Sridhar wrote: > > 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. Hmm idk, "compressed storage" section seems fitting for zswap_cpu_comp_prepare() and zswap_cpu_comp_dead(). Is this patch necessary? > > 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_en= try_t swp) > **********************************/ > static void __zswap_pool_empty(struct percpu_ref *ref); > > +static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *n= ode) > +{ > + struct zswap_pool *pool =3D hlist_entry(node, struct zswap_pool, = node); > + struct crypto_acomp_ctx *acomp_ctx =3D per_cpu_ptr(pool->acomp_ct= x, 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(cp= u)); > + if (!buffer) { > + ret =3D -ENOMEM; > + goto fail; > + } > + > + acomp =3D crypto_alloc_acomp_node(pool->tfm_name, 0, 0, cpu_to_no= de(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 mut= ex > + * 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 w= akeup > + * crypto_wait_req(); if the backend of acomp is scomp, the callb= ack > + * won't be called, crypto_wait_req() will return without blockin= g. > + */ > + 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_ct= x, 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 subtl= e > + * 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 *en= try) > /********************************* > * compressed storage functions > **********************************/ > -static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *n= ode) > -{ > - struct zswap_pool *pool =3D hlist_entry(node, struct zswap_pool, = node); > - struct crypto_acomp_ctx *acomp_ctx =3D per_cpu_ptr(pool->acomp_ct= x, 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(cp= u)); > - if (!buffer) { > - ret =3D -ENOMEM; > - goto fail; > - } > - > - acomp =3D crypto_alloc_acomp_node(pool->tfm_name, 0, 0, cpu_to_no= de(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 mut= ex > - * 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 w= akeup > - * crypto_wait_req(); if the backend of acomp is scomp, the callb= ack > - * won't be called, crypto_wait_req() will return without blockin= g. > - */ > - 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_ct= x, 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 subtl= e > - * 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 >