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 8C903C19776 for ; Fri, 28 Feb 2025 10:00:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3AAD7280004; Fri, 28 Feb 2025 05:00:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3552A280002; Fri, 28 Feb 2025 05:00:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A78B280004; Fri, 28 Feb 2025 05:00:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id EF1F4280002 for ; Fri, 28 Feb 2025 05:00:31 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A2A078069F for ; Fri, 28 Feb 2025 10:00:31 +0000 (UTC) X-FDA: 83168908662.09.99F39A3 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by imf08.hostedemail.com (Postfix) with ESMTP id 73530160019 for ; Fri, 28 Feb 2025 10:00:29 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=MUmAdtcy; spf=pass (imf08.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 192.198.163.18 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=1740736829; 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=Ms2/OmM3n4gs5eeF3YqdiC/vRV2Q9z8SVn1htLBnVcc=; b=bJNwXnrZsDOooTlfEGoAXd5cWhbbVkXTNB/Eyyuyw4IB2CTP5v7pIWDs0u0gh4QXfcVt0k +D39ql8KRdm8eb3HTD4mkSsxQpphxzx1wYIteKtpT7ud12IM0TTr7kToaOVq0FsbEOuYWI rKnT+7C4FEyVBr66a8zUEllFWSZJneY= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=MUmAdtcy; spf=pass (imf08.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 192.198.163.18 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=1740736829; a=rsa-sha256; cv=none; b=KT2xlHMw79ORZg/kDry+ccIxl5BW/yTDx6V0yy0zlQLaob1tp9x8pAcGVOLsgAbOAe2Baq 8fAP2Rd464tOsVbUkqA460Ngqvfp9TLYQvqdXvCz7ypWKqHPwdqaQyBygdpPsBZq2OnQFA oh9q/GVERsj75kiTBZfvSe3lOWmU+8U= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1740736829; x=1772272829; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2yHMsDkER4HjRnd6CZHCqrmnfsYRe9xtFBscYIAxqhQ=; b=MUmAdtcy3OLZQJXtL4H8L3I9HPg8SCaIOCViiizqLjm6at99eARpm5/5 Ruo4Mm3VDTgqPIVhDrNbjQinaABuTj/acfQgDoUElAulA+9xZ2hKzNjOc /52tQlv4RtcHyNATrIyydlDQg5rSiP5+11n07q+qbhO8/gkWF+NADReXF cK3dU1eYYuzUAO8dX+rnSRbgEtPRto9aCaK7+IxXlkpxUOe41LJwJaF5+ LgU6A9nQ/QuK/DgZi3wJyEk/ybbcUb8v7crUP/n7aKa0stSS9gTYMprg1 c0wM/BYjAlulvobzQWAoJoB/0FEJmd23XwBleKnCS0GfXMzWS8JD4iu8Q Q==; X-CSE-ConnectionGUID: qAwdbi4lS1+SIT+Iy983Kw== X-CSE-MsgGUID: 5RhCkpXxRu2WFUh7d+GT5Q== X-IronPort-AV: E=McAfee;i="6700,10204,11358"; a="40902578" X-IronPort-AV: E=Sophos;i="6.13,322,1732608000"; d="scan'208";a="40902578" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2025 02:00:26 -0800 X-CSE-ConnectionGUID: QvtWhEWqRwmK+E0N1RUkWg== X-CSE-MsgGUID: eTAuQPsfQM6G6JzddUkWLA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,322,1732608000"; d="scan'208";a="117325694" Received: from jf5300-b11a338t.jf.intel.com ([10.242.51.115]) by orviesa006.jf.intel.com with ESMTP; 28 Feb 2025 02:00:25 -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 v7 02/15] crypto: acomp - New interfaces to facilitate batching support in acomp & drivers. Date: Fri, 28 Feb 2025 02:00:11 -0800 Message-Id: <20250228100024.332528-3-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20250228100024.332528-1-kanchana.p.sridhar@intel.com> References: <20250228100024.332528-1-kanchana.p.sridhar@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 73530160019 X-Stat-Signature: gh4fd4xjrreiczgpkhec9jaf8neknpdi X-HE-Tag: 1740736829-4951 X-HE-Meta: U2FsdGVkX1/gG+T/Rf3EBVQMNaOkYHRVZrpVgANou1G8kK3fxS/S3RfNeLA4Xc2Jp2+3oRK8SqUfhDdX+ZNeV4SvonKN4OXb9V9UfSmzT2JhR2E1bgQhk15fQvHPt3BXiqbDtSI3nTZfm178eOP2CMJHtlXVhj9PZ2YKo3BWUCOD719GiCfBT5tBpn03dMrnjDqGqwRzfTKVZR2WqYEi6/KVkWPHjsSaJByHN2yp+M5tS5rau+JpbnNqMc2kC1hayxELuqhyUgtKx9660TkuHwap8U3iDvbjTytq/pzs/b/zM59zZ//A5SkrRxnji+o9xAmKcZhOie9vlO30rWT/geDPv/FgCrx3ZWM7CQzp1JkFAo6yvzmvvpWKLYT3jSVQtOMCA/mKMxhVZM/Vq3oSIcNxosMFArUSdgWNfist49WxvRMCNa4qGFnO7BATZzsIuZ4fnIyWq4t8Gclv3fqYfrVD4tMwdLi0t/yHIOoMgobNSdRnUF0SB9eE79bDVxFUw31xn5wlqLxNTOB8hwhNTnmkbGlDZvKs0lmuAYNI11pLgAQNkXIBOTAmQXk85tVWKixyNx9D5P2w/y2hnbMSlIifVWIaHjwm98tBavGjdCsGRZvfAWQpGhp+zR+ePVITA2nNY+Vpp8lH+/nJ6R+5gTTQRZnKhTHO0T6L8bT0pHZy0btoVLnOe/zsfTdz80o6TmmcbNz8UJBzftwKl/aZIQBaeZK6bz/ELUGOJs7lXD+m4Dc8QUXfaf5C1PVL2buedjFm26cEIhQ4tmXLFH6PaLCzvTR9vppAetDFIgELRA5F3DQPjVDvj+BQKmOK+6CqdcH4EwEqPpaek2ytehN27GMJalFavsX7Dhc1NqoXUkczm2Tnc1CPKeV8pmk5pyeqJwhfVZ8VPTTu0qCoLSHcZFzpp2nBTfpjUyJh0uLmSZrc0BJ+sqm3Vg+GP9pEZ/lahv9l+1Cn430+TQ6xMED is0yLqCR 8wHU2n3M5ko5zNHC4txiLN92DxUf11WW6KKImuB/JejvldBiC6lbsfFZw651PjU0bMbeOMiUlweoVBlaQt7gaq2oYBzxyMRDztQwabes3qOf6YuxNGe/0DSjO1n1PZGF6qAduKS1fjW3yTvOTfoCI/KdGqcAvjrqZnS+/gxDTEDYtL0Xwwwa3s7NtJA== 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. 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); -- 2.27.0