From patchwork Sat Nov 23 07:01:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kanchana P Sridhar X-Patchwork-Id: 13883776 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 EFA34E6ADE8 for ; Sat, 23 Nov 2024 07:01:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3A1B66B0082; Sat, 23 Nov 2024 02:01:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 350FE6B0083; Sat, 23 Nov 2024 02:01:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F2046B0085; Sat, 23 Nov 2024 02:01:33 -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 0257E6B0082 for ; Sat, 23 Nov 2024 02:01:32 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7D7321A1672 for ; Sat, 23 Nov 2024 07:01:32 +0000 (UTC) X-FDA: 82816464024.24.3865328 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) by imf07.hostedemail.com (Postfix) with ESMTP id 2E0A840011 for ; Sat, 23 Nov 2024 07:01:28 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=UqSpIx6w; spf=pass (imf07.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 198.175.65.21 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=1732345290; 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=Osorv8u+OBgpaj9fcDkKQgl4zsmQ4E8Qigs/uA0MTYo=; b=pUFaYj8bxRjKEimZYQukMSQWu0h5T7/Zl7SaXsX2qG7cXKf76byZQZdsJfewWP07TkZeOA 7/SoGZxBsDUw1CVy/64a8s5VqF7uc2fDi4iHVeZbQ+lni3E67jHT8+/xcOdBjsYMmn8njg 2nHatVwi+S/cGq0445L2pnj3fsP/QJQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732345290; a=rsa-sha256; cv=none; b=1UJcso39ha5pCpBwrNmeIa5jcM2dOEp6OxGCFF3XDKSBJ3XZr7hO4KJXa46qMTf5ep+Pt4 YJUg15KhJRF8Lo1jD/DYjG9NWhSGZxGnSPBdcWljdmKslJs9+rQoCUucL/oAd5Hfebm84v gV2q7XV0QtaFD/RxxYVQOool5N1SSBc= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=UqSpIx6w; spf=pass (imf07.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 198.175.65.21 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1732345290; x=1763881290; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eLUZRvzAb/JMAqXqi3XSFoRGRNFvuqn37EsysAuIq7I=; b=UqSpIx6wIx9T7IbVkWmwMtT/RuzTZvXJgkOFZZ2jUMxfmvdEEYdx6Htw O4LmqUNohoklyD1YjtMaQNCPkpU/0wCTEGwa9qpZL+laarCs+UWFEXIF0 2c66Pnl4g5pZLkLB+JXaBJjzbfeHhaOz/6BsOdlp/WPQUyeF6KvKrbFYx +5/HjEFbGKJaLyBElzQxPReFR7JS8/PrWpHvohPAVCYW2la8u7sMeicoM wei+/ZHrQZXqPBBWwMEIYEvtVBnZvwuwYDslL+hubJV5BX8AxwwVYDZ2O R411H7rwR+f7t1G1WsSc6UFEwMFS35/PrBVGnqLp1m5ZyBygzSURHKyPq Q==; X-CSE-ConnectionGUID: UBRR9X6mT7iaPUV9sFq6lA== X-CSE-MsgGUID: ASHZfkVtThWZOhxrA2ClOA== X-IronPort-AV: E=McAfee;i="6700,10204,11264"; a="32435462" X-IronPort-AV: E=Sophos;i="6.12,178,1728975600"; d="scan'208";a="32435462" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Nov 2024 23:01:28 -0800 X-CSE-ConnectionGUID: nicOeVJqS2iI9cBEFnDBKg== X-CSE-MsgGUID: +RhtWcv3QkidP9LiFSjxvw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,178,1728975600"; d="scan'208";a="91573547" Received: from unknown (HELO JF5300-B11A338T.jf.intel.com) ([10.242.51.115]) by orviesa008.jf.intel.com with ESMTP; 22 Nov 2024 23:01:28 -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 Cc: wajdi.k.feghali@intel.com, vinodh.gopal@intel.com, kanchana.p.sridhar@intel.com Subject: [PATCH v4 01/10] crypto: acomp - Define two new interfaces for compress/decompress batching. Date: Fri, 22 Nov 2024 23:01:18 -0800 Message-Id: <20241123070127.332773-2-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20241123070127.332773-1-kanchana.p.sridhar@intel.com> References: <20241123070127.332773-1-kanchana.p.sridhar@intel.com> MIME-Version: 1.0 X-Stat-Signature: tmqbifpi7bac8pqt8h9ao9xjwofd4uif X-Rspam-User: X-Rspamd-Queue-Id: 2E0A840011 X-Rspamd-Server: rspam02 X-HE-Tag: 1732345288-902859 X-HE-Meta: U2FsdGVkX1+PIgHEaTV1pePxjZQMKpNWTQeFUwW/YEGq5J8pQInXTr0N6TvEWPXrfZzVvfhxEbrGk45y6TBx71ze6PwnWRvPzOsgCx0NKMYJJMzjWrfb1DH5RtT8HIDVmtGcHqxL2Y78YyJqvtpshkDg+BIQ23q0XyEZ24hKQFvpYvjD6okxF24+fMbco1uzZ9gn8heF4CyQsXTWB197BhcSwe/rnZRYMzqxe/0NPyXK+31tFFsy+nrOw4YPd/rQyAGY08mb1ZnDGo5eWTs+abuadBRmzIR/dwJQJgRSawUVt4usky/9bDpsZqQbk8Sv9KxJ9FuaZkJ3QFonFfFTqxBw13xmUsZFiGLo6FA/bnYBE/HetyX0JQLXcvYiT9VEXGWi8VQ2+mNbF9xNrMNdIeOI6XGAzTS0qOdGZ0UZT2I9CM/19ZIboXkRfiapiSiMnjkfu5fY7Qj1U9MxJBz5jtdFT5UW2bNXHU9SXtwZkjKEvPg3Mw6Jd8kdaOrPty/6NRLSR2tYKMXpz5Ntty3OJJ5u2tN4qcCH8efuyCQl8hi4gy+KCdLptp3C0Cwonr8vY4gD67H2+wI7S83+KZuiyoEklxSD0IP9OMWDEuVNt0VqdsbtnlzGQBJQuC/0O5zF1VghowS5QyCGUAVuBB5wt+Dhcp83eR3Hr4KIDjZNa7qHnSJ2+xUup29HWPS9c3r9Zqvc10T1W8OgOLkpbuIahuuVqnxOqCyx1T43Hysn5/hWRSOs9fyzzTKuYHuhHVj9PKFdXSqBu5S2fk9bEU3xFLsSNU9TdyCn7x77zYGq26U49179IY6lTwJKrELy9Y+ZUUfbj/FhuILNKnPniPq2HlWreuvzn1NYEn8xQgs0N6/GwmOGXYeUOyqdyobexb2WUQSIgt1FXe+XdAqBOSCO/iG70aeZu7S69Oo0LwnJ4bd+Ox34xRExnjMtk5v+ghJR8DhQPXR5wj4CaZCXoqd tZRBqAKZ oI6k5T3cMrDp3b+g4/7Jyygacu9oJN3oLkmR8YPxea7MYBq5BI6c87ZMX6dPx2xEIAn6HWKwc6X4UfNWtfr1skW7qupN1k5QRtx7UW9Jjh4Qh6n9L9DepL7E3BxByUDrCJnccLMY/qY50jk94+9TnLl98cUJh7Yj13AIAJvBQuoOg1Phxspccx8w3eA== 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 implementations for the 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. A new helper function acomp_has_async_batching() can be invoked to query if a crypto_acomp has registered these batch_compress and batch_decompress interfaces. Signed-off-by: Kanchana P Sridhar --- crypto/acompress.c | 2 + include/crypto/acompress.h | 91 +++++++++++++++++++++++++++++ include/crypto/internal/acompress.h | 16 +++++ 3 files changed, 109 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..4252bab3d0e1 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; @@ -142,6 +164,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->batch_compress && tfm->batch_decompress); +} + static inline struct crypto_acomp *crypto_acomp_reqtfm(struct acomp_req *req) { return __crypto_acomp_tfm(req->base.tfm); @@ -265,4 +294,66 @@ static inline int crypto_acomp_decompress(struct acomp_req *req) return crypto_acomp_reqtfm(req)->decompress(req); } +/** + * crypto_acomp_batch_compress() -- Invoke asynchronous compress of + * a batch of requests + * + * Function invokes the asynchronous 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() -- Invoke asynchronous decompress of + * a batch of requests + * + * Function invokes the asynchronous 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);