From patchwork Mon Mar 3 08:47:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sridhar, Kanchana P" X-Patchwork-Id: 13998347 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 11084C282C6 for ; Mon, 3 Mar 2025 08:47:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA49F6B008A; Mon, 3 Mar 2025 03:47:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D54DE6B008C; Mon, 3 Mar 2025 03:47:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5842280002; Mon, 3 Mar 2025 03:47:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 95A0B6B008A for ; Mon, 3 Mar 2025 03:47:35 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 280C3A29F8 for ; Mon, 3 Mar 2025 08:47:35 +0000 (UTC) X-FDA: 83179611270.21.FD6CE1F Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by imf24.hostedemail.com (Postfix) with ESMTP id 0848318000E for ; Mon, 3 Mar 2025 08:47:32 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="gzN1p/tw"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf24.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 192.198.163.14 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740991653; a=rsa-sha256; cv=none; b=KL9MQdMuwfzba6LBnsaLVkrVZH6tvzphUCHzvN5mPx8hod2X8uiT3nz20avmce0kvydxPH l63PCS3MNhs0xMH3GkIH82KP6wgD69AyufBb+rM5IeBB+3GzNdb/zro84n6xJ8wAo7gFxU c/RFW+n5dAu0khwFQMa6R5zx9g3Nx4c= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="gzN1p/tw"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf24.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 192.198.163.14 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=1740991653; 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=JtvTbH4VmdHwlkmr8zXqJcNEcW2lb6PzPo4UCOAYcHk=; b=ji5ZDrgu4EoEI8wNeAfTZFa8sgc109wl2vgF1g0pT5BDE/NThoBig73n/jQSAt7vWUT8Hu zp7cn07/Ppd41hBJXng92LzmzijyJzyilgKw7QX4DtOALyE9doTkPRxZHzGRyfyiw32dum iOirTYX1/aYzZbB8FXIAX+iE0HFtwCE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1740991653; x=1772527653; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LJoG0hwzy11IwSS0GA7f2KkCoIWMhfdeKs7bZI/C2Jg=; b=gzN1p/twAPSBcx2k7Sag9nV2Wv+TMSqDr+gADkyYbwoMyPHRg60yBe2s pPcgxDYxM9xjlw6YNRgl9PzMr95ZkRqauMGtQfLsVqtt/zEfbWdNVXVLV g7qQcvfEjbHB0qRzhcWhIScAJAYuVOiMA79XBtFmi2AE7Hn706u5bY9tW 0xlHH6D8ITVPiGk4kv9xslCCBBnadjJBoNAcZtat3XDWHeOJXta1zGvKs n+u5Avzt4QRG2U2OhiFQ1QMqVt32GJqYcer19PJU4LUgFcpHAZZI3gZaU kEYlUEs4DqZjLmYBt9HjtwR4soPCiQUpRR3Bp6plT3ayPJN9m8ijFVsW+ w==; X-CSE-ConnectionGUID: 2d+JgNSMRHuoAaDAzJJDCQ== X-CSE-MsgGUID: p2pShVO8QZSKbNJ9THJI4g== X-IronPort-AV: E=McAfee;i="6700,10204,11361"; a="42111871" X-IronPort-AV: E=Sophos;i="6.13,329,1732608000"; d="scan'208";a="42111871" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2025 00:47:28 -0800 X-CSE-ConnectionGUID: BqnvijDaScOzKITX7vs36w== X-CSE-MsgGUID: yCwbwk1qQtu2vMCztNB7sg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,329,1732608000"; d="scan'208";a="118426765" Received: from jf5300-b11a338t.jf.intel.com ([10.242.51.115]) by fmviesa010.fm.intel.com with ESMTP; 03 Mar 2025 00:47:26 -0800 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, 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 Cc: wajdi.k.feghali@intel.com, vinodh.gopal@intel.com, kanchana.p.sridhar@intel.com Subject: [PATCH v8 02/14] crypto: acomp - New interfaces to facilitate batching support in acomp & drivers. Date: Mon, 3 Mar 2025 00:47:12 -0800 Message-Id: <20250303084724.6490-3-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20250303084724.6490-1-kanchana.p.sridhar@intel.com> References: <20250303084724.6490-1-kanchana.p.sridhar@intel.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 0848318000E X-Stat-Signature: 87w88h57ynodjy7yycdyguk58b4sqx15 X-Rspam-User: X-HE-Tag: 1740991652-76333 X-HE-Meta: U2FsdGVkX1/kgearBGKoKmk6szIe58Nr8AAUq45DVKqWe1yQHdnc3cHR7CgFbZS01NtxwFvoWTDd3UZj0Yxxz4kObirnfDoflso9bM0ECYCSbgvVJhtnVzzGMNV7lIfLi8ad1r7GPrewG5SO96cCA6TnamwUOUw950gj9Oi92a/9tG96zjNjvGAIynImUIwZcskCoh9yYlXswMb8QkAHkA7PA3rXX+87EzvAlsixMot6a0Hu9IJj6OZ30MRyFMn4G1e01fc2TIW/ux9VScGXC4w9nl1Jp1J2wIMWd140eQLtpqmM1xgR33+b/2ycmogEKgaVSpo8FgHoIjmzIy7wgduAbAb03N2z3ugArfipVM3t/U3nV/XJzt6PSqPO1Fu1IX5Vqn/eq1bNt3I2PA9kr3DnTEOU7x9kTcx+FCdVZljWhXBEmHLlUGlNEz+Q74gRG89verTUV5iriuxnATGJPNvWSrFRKYPMWQDIcpcQP7HBHqNfK5QW5T3OxSNVBbC55fvnENomDZ3l8L/meMnbd4+/QGrUbuvNGzqm23fTmYPHvELkFvJSXQobIKxzrS4ClLAxYz4oVbH655pO9KGrdKeDOY5pAZOxWDlhBjQ7Xvp/P/jIyYSTpoKc3mmtChS93Ms8Mjqd6UwdGQOf4Hu8x8eklndHE72VfU/7UTqOOZTorEy8Frdvy7QvCwJs/sLqMqXfLr1aMRRXcYtwyCxqmlRRfPpHMic/OYlK7CkCGyZr42F8Td7EggYyBUT+L/yT3JvTfuryR/7Xvf6c3S70ydaGY9HjeWXwpigua9vL6qqIHTqCYtY8xKBbwLDvw+Od3qJVjH5+kr0iv2A3w7LXKdEAqLHmfdMDdlg7SmP26UIMA4iEGsQcjnvklC1pNdIIs8mi5MvX3uPQZFARp6ki5RIxp4wsLYfsFkHtQuccC8HDGCMp0Aqn35KqFiHYEk/PvkC0wNiu5qYGvtLb95/ jyvVZC/3 zJdzW3gOpPJIN4k2AY4jLgSaSxkghPY0Z+nYioFbCUGX8izOswUfqR58sUarvn4u+dVelcvI6Iu6b13Yy7Mx6JC1SwQnQINnztNBcuYzh0XQokI6V11sj1QjoFZcyLMB3xGhxI27fMlCdHMkky+pV399Lxmtr2uSnO/ZVStastSUhWGCSSOxFM5aG/g== 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 commit adds a get_batch_size() interface to: struct acomp_alg struct crypto_acomp A crypto_acomp compression algorithm that supports batching of compressions and decompressions must register and provide an implementation for this API, so that higher level modules such as zswap and zram can allocate resources for submitting multiple compress/decompress jobs that can be batched. In addition, the compression algorithm must register itself to use request chaining (cra_flags |= CRYPTO_ALG_REQ_CHAIN). A new helper function acomp_has_async_batching() can be invoked to query if a crypto_acomp has registered this API. Further, the newly added crypto_acomp API "crypto_acomp_batch_size()" is provided for use by higher level modules like zswap and zram. crypto_acomp_batch_size() returns 1 if the acomp has not provided an implementation for get_batch_size(). For instance, zswap can call crypto_acomp_batch_size() to get the maximum batch-size supported by the compressor. Based on this, zswap can use the minimum of any zswap-specific upper limits for batch-size and the compressor's max batch-size, to allocate batching resources. Further, the way that zswap can avail of the compressor's batching capability is by using request chaining to create a list requests chained to a head request. zswap can call crypto_acomp_compress() or crypto_acomp_decompress() with the head request in the chain for processing the chain as a batch. The call into crypto for compress/decompress will thus remain the same from zswap's perspective for both, batching and sequential compressions/decompressions. An acomp_is_reqchain() API is introduced, that a driver can call to query if a request received from compress/decompress represents a request chain, and accordingly, process the request chain using either one of: acomp_do_req_chain() acomp_do_async_req_chain() These capabilities allow the iaa_crypto Intel IAA driver to register and implement the get_batch_size() acomp_alg interface, that can subsequently be invoked from the kernel zswap/zram modules to construct a request chain to compress/decompress pages in parallel in the IAA hardware accelerator to improve swapout/swapin performance. Signed-off-by: Kanchana P Sridhar --- crypto/acompress.c | 1 + include/crypto/acompress.h | 28 ++++++++++++++++++++++++++++ include/crypto/internal/acompress.h | 4 ++++ 3 files changed, 33 insertions(+) diff --git a/crypto/acompress.c b/crypto/acompress.c index cb6444d09dd7..b2a6c06d7262 100644 --- a/crypto/acompress.c +++ b/crypto/acompress.c @@ -84,6 +84,7 @@ static int crypto_acomp_init_tfm(struct crypto_tfm *tfm) acomp->compress = alg->compress; acomp->decompress = alg->decompress; + acomp->get_batch_size = alg->get_batch_size; acomp->dst_free = alg->dst_free; acomp->reqsize = alg->reqsize; diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h index e6783deba3ac..147f184b6bea 100644 --- a/include/crypto/acompress.h +++ b/include/crypto/acompress.h @@ -43,6 +43,9 @@ struct acomp_req { * * @compress: Function performs a compress operation * @decompress: Function performs a de-compress operation + * @get_batch_size: Maximum batch-size for batching compress/decompress + * operations. If registered, the acomp must provide + * a batching implementation using request chaining. * @dst_free: Frees destination buffer if allocated inside the * algorithm * @reqsize: Context size for (de)compression requests @@ -51,6 +54,7 @@ struct acomp_req { struct crypto_acomp { int (*compress)(struct acomp_req *req); int (*decompress)(struct acomp_req *req); + unsigned int (*get_batch_size)(void); void (*dst_free)(struct scatterlist *dst); unsigned int reqsize; struct crypto_tfm base; @@ -142,6 +146,13 @@ static inline bool acomp_is_async(struct crypto_acomp *tfm) CRYPTO_ALG_ASYNC; } +static inline bool acomp_has_async_batching(struct crypto_acomp *tfm) +{ + return (acomp_is_async(tfm) && + (crypto_comp_alg_common(tfm)->base.cra_flags & CRYPTO_ALG_TYPE_ACOMPRESS) && + tfm->get_batch_size); +} + static inline struct crypto_acomp *crypto_acomp_reqtfm(struct acomp_req *req) { return __crypto_acomp_tfm(req->base.tfm); @@ -311,4 +322,21 @@ static inline int crypto_acomp_decompress(struct acomp_req *req) return crypto_acomp_reqtfm(req)->decompress(req); } +/** + * crypto_acomp_batch_size() -- Get the algorithm's batch size + * + * Function returns the algorithm's batch size for batching operations + * + * @tfm: ACOMPRESS tfm handle allocated with crypto_alloc_acomp() + * + * Return: crypto_acomp's batch size. + */ +static inline unsigned int crypto_acomp_batch_size(struct crypto_acomp *tfm) +{ + if (acomp_has_async_batching(tfm)) + return tfm->get_batch_size(); + + return 1; +} + #endif diff --git a/include/crypto/internal/acompress.h b/include/crypto/internal/acompress.h index 53b4ef59b48c..24b63db56dfb 100644 --- a/include/crypto/internal/acompress.h +++ b/include/crypto/internal/acompress.h @@ -17,6 +17,9 @@ * * @compress: Function performs a compress operation * @decompress: Function performs a de-compress operation + * @get_batch_size: Maximum batch-size for batching compress/decompress + * operations. If registered, the acomp must provide + * a batching implementation using request chaining. * @dst_free: Frees destination buffer if allocated inside the algorithm * @init: Initialize the cryptographic transformation object. * This function is used to initialize the cryptographic @@ -37,6 +40,7 @@ struct acomp_alg { int (*compress)(struct acomp_req *req); int (*decompress)(struct acomp_req *req); + unsigned int (*get_batch_size)(void); void (*dst_free)(struct scatterlist *dst); int (*init)(struct crypto_acomp *tfm); void (*exit)(struct crypto_acomp *tfm);