From patchwork Wed Nov 6 19:20:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sridhar, Kanchana P" X-Patchwork-Id: 13865316 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 7538DD59F6B for ; Wed, 6 Nov 2024 19:21:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A82E56B0082; Wed, 6 Nov 2024 14:21:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A31F36B0085; Wed, 6 Nov 2024 14:21:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F9EA6B0088; Wed, 6 Nov 2024 14:21:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5EB726B0082 for ; Wed, 6 Nov 2024 14:21:12 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DDD45140DCB for ; Wed, 6 Nov 2024 19:21:11 +0000 (UTC) X-FDA: 82756637334.30.74CB1AB Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) by imf18.hostedemail.com (Postfix) with ESMTP id 567A81C0022 for ; Wed, 6 Nov 2024 19:20:54 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=XyzWp1nd; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf18.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 198.175.65.11 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=1730920785; 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=eAOM1k5eBgatCXxcKi5hWs7e/Nc/Gb2n04WWWLD5dIE=; b=D0OKh1Yg7LOftSyqelZUdS6Tjbkxba2cEhNBV+5GAuTAw840gpjmLCZQnfGgfYkiLZcWM9 NFl2iFv9QaoeQSwbg3695plcaIUdwbde6L5KBDCOW+7IqzMM1yY6b4RCef5NwtZr2btJYo r2hi5LbaBzIvL9cpBQGRAreLDRTG0co= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=XyzWp1nd; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf18.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 198.175.65.11 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730920785; a=rsa-sha256; cv=none; b=m9SGV+ZMhpJG+0tziZZwYHjI13fp4zLpbRPhybu3zTq8L2/SP52OWfsYg6H/8trnc9B+lK QQIG/hihDIXEwL+iVKUsCzzdIKHE38E325pvtKdEdYwr1s9agK5NuVvhnvfqbPr/OzcG4i tHnTDgVHwM7QIym+tHo4nN4Y9l+Pdy0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730920870; x=1762456870; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8jyV13JKHn0vIl+wBpuhM8EZ+NN4RHEftxJMCaIna00=; b=XyzWp1ndO0TYHtEeV6th812s3RVdRyzCyiVdDJVhuXwbW2t/rlBiNclq vdwEOLOczbHg1bOJqg8wX5MaolMtMraIKo5vvzHezogFvmbsM8cmutzQH AgJ59UZN+cO8T7hePCNISJojEwkxaKhnOQQoPSyqAcbjbcrMPoBpA33C7 G9vDu+YDtDTV/GMgIRvSL1YqV3YBINEg5PKTDsOuJ3PJJ62bcEEN3gTLB 1sm6vxwKdgO/g9v7RxgVZShbT4NLpeRp5L0SaquHb56WyiKs1YHSCbny0 uMFI0T53n0XcC46o6IdNsTeLPmjN7AclOuu3P1ErcF+3+U2xsNbnc+u0R w==; X-CSE-ConnectionGUID: oITy57RURtmkJOUFOEB+5g== X-CSE-MsgGUID: kMJxIU8tQ62qDTJZ3HhZww== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="41291935" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="41291935" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2024 11:21:07 -0800 X-CSE-ConnectionGUID: 7GLWqB4ETRmTzg1kJtlu0g== X-CSE-MsgGUID: NcmQoX70Qnihkta38JlJxQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,263,1725346800"; d="scan'208";a="88695359" Received: from unknown (HELO JF5300-B11A338T.jf.intel.com) ([10.242.51.115]) by fmviesa003.fm.intel.com with ESMTP; 06 Nov 2024 11:21:06 -0800 From: Kanchana P Sridhar To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, hannes@cmpxchg.org, yosryahmed@google.com, nphamcs@gmail.com, chengming.zhou@linux.dev, usamaarif642@gmail.com, ryan.roberts@arm.com, ying.huang@intel.com, 21cnbao@gmail.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, zanussi@kernel.org Cc: wajdi.k.feghali@intel.com, vinodh.gopal@intel.com, kanchana.p.sridhar@intel.com Subject: [PATCH v3 01/13] crypto: acomp - Define two new interfaces for compress/decompress batching. Date: Wed, 6 Nov 2024 11:20:53 -0800 Message-Id: <20241106192105.6731-2-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20241106192105.6731-1-kanchana.p.sridhar@intel.com> References: <20241106192105.6731-1-kanchana.p.sridhar@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 567A81C0022 X-Stat-Signature: haqh6khfkqto8qkm6bqijmfun6scp5rx X-HE-Tag: 1730920854-380760 X-HE-Meta: U2FsdGVkX19WjzT/jdBaZGVk7N1i9U2Xye6Qat0+oNMXH9gPWmN6+6QqbzsgpTY4P73Rp/1nUpbGhdiWm1es0e3f9wLCy1n2yUKjoEpnpewgAbsx3wdWQqNte8Dw1oJN0PrBMl6PwDGJcm6spUiO9N2hb0YAGyC4QM8z8NL/j6bxue00I2ysdcOZOd60fAwTrbgnl3p04o/vXPYIcwRyo09n7Ku2cqsllhrxbQIPaubDnH4R2rc+tzw7eWEU8WnsSJb+qD4AweOhnZx5AdRNQ853U2mkqnA7w5/NmEbFwk6WfK6sg525/FhhunAOa0inkwV9fadx2I7FNvFNf9FMKkntBScRWQkCd9CQ9YMwl69MdE1wAhkR1AyN/znkZ1xvHrXkUjU+9dbk2M3XKx7Sj/4kzMhxnL/fQC+MYO5JgOeW62jz6jQtXW7NnALgFhH8cUfI3cQJKkaBOJLottrxFaK2vH2I15+7RTPAA5dHZJLoyXiNkUT/tvyCDozw4yGQN4uQkZpIyyGzUI6hgvMu/V3XUtgV7ByLG3OT6BMnMAp49NYBbK2TqwRrWe3F/mIEMihwrzlgcZf3pjDsXIWO7qvqKN8pY2VKmQnYGg6ON0hMgPuUgO8Jn1MgVSLaBhjEffJmTkhyKKika7WKDyC+5LUUjjTiOyfKGFEZ6o1RAETIt6yT4sAmqlL79+iLJh6fyoWxFRRBMuupmjNXwwg2+Hf3Kr2NON8tcAg9lJDg8MqWuNvvSoRbHaa+ceNVHYU7+Vxo0x+N9GWeTpF7lwmOhgTFzxG6fqdlsoN/cPRxZCJnXjUzu49qAtqJh3hC+7AN9NEPvvPgX5Go3Mgnd3Eqwt72zcZL0fyCXedEQqVGGY8S1OpOKDbNCcJocchbDt8ozDVZJgC3N/qxe2lzIKh6b4c0Jw1f8HWdy2eL69dpEEv2NAbXjcUa/NRoMX+zntTlrSQdHA4sXxNOQz7QemW 8imInu/Q RxsmS5osglnE1gheeood7cN/GNTP7pO/ujRYtCoNnMKhAiHD/bn5Z8rJC3dalVx5UBl2ujDPYdvYfhBv2+Py4Z1cAqNShTTsuyrHd6NuPIFz4MXx06clBxmurBxaO33srlHFzoy4IQf2aRVQFFjWODsS4Uh2b2X53zpK/4K6TiWjhKf0Jeq0SncA9Vg== 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 batch_compress() and batch_decompress() interfaces to: struct acomp_alg struct crypto_acomp This allows the iaa_crypto Intel IAA driver to register implementation for batch_compress() and batch_decompress() API, that can subsequently be invoked from the kernel zswap/zram swap modules to compress/decompress up to CRYPTO_BATCH_SIZE (i.e. 8) pages in parallel in the IAA hardware accelerator to improve swapout/swapin performance. Signed-off-by: Kanchana P Sridhar --- crypto/acompress.c | 2 + include/crypto/acompress.h | 82 +++++++++++++++++++++++++++++ include/crypto/internal/acompress.h | 16 ++++++ 3 files changed, 100 insertions(+) diff --git a/crypto/acompress.c b/crypto/acompress.c index 6fdf0ff9f3c0..a506db499a37 100644 --- a/crypto/acompress.c +++ b/crypto/acompress.c @@ -71,6 +71,8 @@ static int crypto_acomp_init_tfm(struct crypto_tfm *tfm) acomp->compress = alg->compress; acomp->decompress = alg->decompress; + acomp->batch_compress = alg->batch_compress; + acomp->batch_decompress = alg->batch_decompress; acomp->dst_free = alg->dst_free; acomp->reqsize = alg->reqsize; diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h index 54937b615239..ab0d9987bde1 100644 --- a/include/crypto/acompress.h +++ b/include/crypto/acompress.h @@ -37,12 +37,20 @@ struct acomp_req { void *__ctx[] CRYPTO_MINALIGN_ATTR; }; +/* + * The max compress/decompress batch size, for crypto algorithms + * that support batch_compress and batch_decompress API. + */ +#define CRYPTO_BATCH_SIZE 8UL + /** * struct crypto_acomp - user-instantiated objects which encapsulate * algorithms and core processing logic * * @compress: Function performs a compress operation * @decompress: Function performs a de-compress operation + * @batch_compress: Function performs a batch compress operation + * @batch_decompress: Function performs a batch decompress operation * @dst_free: Frees destination buffer if allocated inside the * algorithm * @reqsize: Context size for (de)compression requests @@ -51,6 +59,20 @@ struct acomp_req { struct crypto_acomp { int (*compress)(struct acomp_req *req); int (*decompress)(struct acomp_req *req); + void (*batch_compress)(struct acomp_req *reqs[], + struct crypto_wait *wait, + struct page *pages[], + u8 *dsts[], + unsigned int dlens[], + int errors[], + int nr_pages); + void (*batch_decompress)(struct acomp_req *reqs[], + struct crypto_wait *wait, + u8 *srcs[], + struct page *pages[], + unsigned int slens[], + int errors[], + int nr_pages); void (*dst_free)(struct scatterlist *dst); unsigned int reqsize; struct crypto_tfm base; @@ -265,4 +287,64 @@ static inline int crypto_acomp_decompress(struct acomp_req *req) return crypto_acomp_reqtfm(req)->decompress(req); } +/** + * crypto_acomp_batch_compress() -- compress a batch of requests + * + * Function invokes the batch compress operation + * + * @reqs: @nr_pages asynchronous compress requests. + * @wait: crypto_wait for synchronous acomp batch compress. If NULL, the + * driver must provide a way to process completions asynchronously. + * @pages: Pages to be compressed. + * @dsts: Pre-allocated destination buffers to store results of compression. + * @dlens: Will contain the compressed lengths. + * @errors: zero on successful compression of the corresponding + * req, or error code in case of error. + * @nr_pages: The number of pages, up to CRYPTO_BATCH_SIZE, + * to be compressed. + */ +static inline void crypto_acomp_batch_compress(struct acomp_req *reqs[], + struct crypto_wait *wait, + struct page *pages[], + u8 *dsts[], + unsigned int dlens[], + int errors[], + int nr_pages) +{ + struct crypto_acomp *tfm = crypto_acomp_reqtfm(reqs[0]); + + return tfm->batch_compress(reqs, wait, pages, dsts, + dlens, errors, nr_pages); +} + +/** + * crypto_acomp_batch_decompress() -- decompress a batch of requests + * + * Function invokes the batch decompress operation + * + * @reqs: @nr_pages asynchronous decompress requests. + * @wait: crypto_wait for synchronous acomp batch decompress. If NULL, the + * driver must provide a way to process completions asynchronously. + * @srcs: The src buffers to be decompressed. + * @pages: The pages to store the decompressed buffers. + * @slens: Compressed lengths of @srcs. + * @errors: zero on successful compression of the corresponding + * req, or error code in case of error. + * @nr_pages: The number of pages, up to CRYPTO_BATCH_SIZE, + * to be decompressed. + */ +static inline void crypto_acomp_batch_decompress(struct acomp_req *reqs[], + struct crypto_wait *wait, + u8 *srcs[], + struct page *pages[], + unsigned int slens[], + int errors[], + int nr_pages) +{ + struct crypto_acomp *tfm = crypto_acomp_reqtfm(reqs[0]); + + return tfm->batch_decompress(reqs, wait, srcs, pages, + slens, errors, nr_pages); +} + #endif diff --git a/include/crypto/internal/acompress.h b/include/crypto/internal/acompress.h index 8831edaafc05..acfe2d9d5a83 100644 --- a/include/crypto/internal/acompress.h +++ b/include/crypto/internal/acompress.h @@ -17,6 +17,8 @@ * * @compress: Function performs a compress operation * @decompress: Function performs a de-compress operation + * @batch_compress: Function performs a batch compress operation + * @batch_decompress: Function performs a batch decompress operation * @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 +39,20 @@ struct acomp_alg { int (*compress)(struct acomp_req *req); int (*decompress)(struct acomp_req *req); + void (*batch_compress)(struct acomp_req *reqs[], + struct crypto_wait *wait, + struct page *pages[], + u8 *dsts[], + unsigned int dlens[], + int errors[], + int nr_pages); + void (*batch_decompress)(struct acomp_req *reqs[], + struct crypto_wait *wait, + u8 *srcs[], + struct page *pages[], + unsigned int slens[], + int errors[], + int nr_pages); void (*dst_free)(struct scatterlist *dst); int (*init)(struct crypto_acomp *tfm); void (*exit)(struct crypto_acomp *tfm);