From patchwork Thu May 1 12:37:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 886719 Received: from abb.hmeau.com (abb.hmeau.com [144.6.53.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A54962248AE for ; Thu, 1 May 2025 12:37:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=144.6.53.87 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746103058; cv=none; b=hadD1rwLNN7FrpM9V+SgszRa5yqP7QyUb8bRC0WMTlrhBEIkpdV0DG5A9mQdq/Du68MdiNNspOB5gVzTZSeJkqdNDGw81DZ5TsW8INymDZ26rnfdIDJaJ/lIVnYV2rr+6TE/9hwz7u6pZV4pM2vmOrkRfzZlFPh99qjxVO8QHCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746103058; c=relaxed/simple; bh=W2HUkw3YBx7Qd1iCrjXGH8Jo8OA9m64ohF6kXNHkwVc=; h=Date:Message-Id:In-Reply-To:References:From:Subject:To:Cc; b=aEDA1D6nS4IPyrXxVqLOH8ZHyzZcodckciW+IEnUUJK1hcJ7BuY7ndHPGTbPtMFGNjPVwBc6t02FB1UPKArsd2+gt7fRiKVDSfZUhthjTgOmWd4SQbIyA7Og5ZNPxa8b5b3qxReU/MkoH/dF3mA1cqaiG+fvtDj+ePUohvi+OXc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gondor.apana.org.au; spf=pass smtp.mailfrom=gondor.apana.org.au; dkim=pass (2048-bit key) header.d=hmeau.com header.i=@hmeau.com header.b=U0vVjg3i; arc=none smtp.client-ip=144.6.53.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gondor.apana.org.au Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gondor.apana.org.au Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hmeau.com header.i=@hmeau.com header.b="U0vVjg3i" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hmeau.com; s=formenos; h=Cc:To:Subject:From:References:In-Reply-To:Message-Id:Date: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=5dIz5b7WcCLt4p5i2lsHoHnuE2nLHmE0hnLqMFtnS2E=; b=U0vVjg3if4wsiv2fwmaU1GHtWi W6Gf3PXSZvMYpIZkz2AH4gXJyQil4GHomDADoIBiJdphiHVCndMCj3LIzsf6+wVSwOU4DO1y3giMa pmBVBr5yzqgiS7mYiOJBN9Zl0KtjgKhGQV8koutmOgLHRqpCVeY5G91fSci+gJuFO+0UnaGHRTw2r NI7jbB8RKMpTtAhBsALUgrAndrIkbU3vjZGhtI0tr8JnXH6VDdSxWBiARgFbTrmDQ7joadY1TP5t6 EbJsUTWAt3QSPCZlqc5MrU6msx8HqKiWHVdxvGqOMUQAhJ0gm72cP/j1MrKjh4qhPxli/9ocpJ0EO JT1oeD9A==; Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.96 #2 (Debian)) id 1uATAQ-002bEr-1h; Thu, 01 May 2025 20:37:31 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Thu, 01 May 2025 20:37:30 +0800 Date: Thu, 01 May 2025 20:37:30 +0800 Message-Id: In-Reply-To: References: From: Herbert Xu Subject: [PATCH 1/4] crypto: acomp - Clone folios properly To: Linux Crypto Mailing List Cc: Kanchana P Sridhar Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The folios contain references to the request itself so they must be setup again in the cloned request. Fixes: 5f3437e9c89e ("crypto: acomp - Simplify folio handling") Signed-off-by: Herbert Xu --- crypto/acompress.c | 18 ++++++++++++++++++ include/crypto/acompress.h | 8 ++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/crypto/acompress.c b/crypto/acompress.c index 9dea76ed4513..6ecbfc49bfa8 100644 --- a/crypto/acompress.c +++ b/crypto/acompress.c @@ -566,5 +566,23 @@ int acomp_walk_virt(struct acomp_walk *__restrict walk, } EXPORT_SYMBOL_GPL(acomp_walk_virt); +struct acomp_req *acomp_request_clone(struct acomp_req *req, + size_t total, gfp_t gfp) +{ + struct acomp_req *nreq; + + nreq = container_of(crypto_request_clone(&req->base, total, gfp), + struct acomp_req, base); + if (nreq == req) + return req; + + if (req->src == &req->chain.ssg) + nreq->src = &nreq->chain.ssg; + if (req->dst == &req->chain.dsg) + nreq->dst = &nreq->chain.dsg; + return nreq; +} +EXPORT_SYMBOL_GPL(acomp_request_clone); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Asynchronous compression type"); diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h index f1812e92d3e3..9eacb9fa375d 100644 --- a/include/crypto/acompress.h +++ b/include/crypto/acompress.h @@ -551,11 +551,7 @@ static inline struct acomp_req *acomp_request_on_stack_init( return req; } -static inline struct acomp_req *acomp_request_clone(struct acomp_req *req, - size_t total, gfp_t gfp) -{ - return container_of(crypto_request_clone(&req->base, total, gfp), - struct acomp_req, base); -} +struct acomp_req *acomp_request_clone(struct acomp_req *req, + size_t total, gfp_t gfp); #endif From patchwork Thu May 1 12:37:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 886540 Received: from abb.hmeau.com (abb.hmeau.com [144.6.53.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCE00224AFC for ; Thu, 1 May 2025 12:37:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=144.6.53.87 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746103059; cv=none; b=pMAVgZx5sI+hGv6C/ulTNMpvR7EB6S8miQqhf0f8OTE4XFWIAUrd5VV+JsXUaqrw9D1y94MO1SwDKbVdJ/39Jmo81/QaeHKiSOOMbtH0BmpVo7EoGSRb9gIUpIRMt6QVv0nL1EXz/ow+ulB1C9ERV7QYn8Fk8AxPNMTksHwyMfI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746103059; c=relaxed/simple; bh=Y1ehkO6lLOWop9gpF6nPFqCpKc9qbplnyuRvwfFDUaY=; h=Date:Message-Id:In-Reply-To:References:From:Subject:To:Cc; b=XLa2cRcxk77zX0s3tX71HF7e4Cug9dri+NT8ccQBAShi3cO0jN6/8jvPpXC6BB9zV4i0VnZi0dNmDYJoIBxhBUvfqz3gCZj5dwTV3g8YHM/+0k2XZKvqRitx/d64JmjM64pqcmiwBhG6cNl54kzY2x7xIwrDNa1E1X86Jz1Ntkg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gondor.apana.org.au; spf=pass smtp.mailfrom=gondor.apana.org.au; dkim=pass (2048-bit key) header.d=hmeau.com header.i=@hmeau.com header.b=PFdS/EbC; arc=none smtp.client-ip=144.6.53.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gondor.apana.org.au Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gondor.apana.org.au Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hmeau.com header.i=@hmeau.com header.b="PFdS/EbC" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hmeau.com; s=formenos; h=Cc:To:Subject:From:References:In-Reply-To:Message-Id:Date: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Yp6BStKeFcoflRofEm2DavhhaNHO7afewA9e43DywK8=; b=PFdS/EbC0Z9pYp82tRDpsiE86X PyI9DWz2jGcZi/8Zaq48oW4DfHeWC6y1AD3qQ7j7UVBI2A2rgQ0uafcKzddCQZltx4ct9MIZxyaAa f2tVGVk14p+JMOHpUv7YhXVYV80eAPk5AyXncd+IUoXvCQ3MgAgCXtbcj1KzFUhng3REI/QmpMFGo PGIVKRzWnaO4oF5FYSjgeribqtZSw2FqRLVDxqH0mlqDCgZVUs0l5U1a/trHnCW3VpjEbsM8OwGKi C5oadmtelHqZeB1ViuNFlnz9w5ns89cAwBFf7eO6RVOEty8ovwMz58+1K1hDLQ9fRV1yeGeCwZOt8 oxOpDLcw==; Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.96 #2 (Debian)) id 1uATAS-002bF4-2i; Thu, 01 May 2025 20:37:33 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Thu, 01 May 2025 20:37:32 +0800 Date: Thu, 01 May 2025 20:37:32 +0800 Message-Id: <4be83ed9da46eb4e8a309fa37e3050766ea2784c.1746102673.git.herbert@gondor.apana.org.au> In-Reply-To: References: From: Herbert Xu Subject: [PATCH 2/4] crypto: api - Rename CRYPTO_ALG_REQ_CHAIN to CRYPTO_ALG_REQ_VIRT To: Linux Crypto Mailing List Cc: Kanchana P Sridhar Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: As chaining has been removed, all that remains of REQ_CHAIN is just virtual address support. Rename it before the reintroduction of batching creates confusion. Signed-off-by: Herbert Xu --- crypto/acompress.c | 4 ++-- crypto/ahash.c | 6 +++--- crypto/deflate.c | 2 +- crypto/scompress.c | 2 +- include/crypto/algapi.h | 4 ++-- include/crypto/internal/acompress.h | 4 ++-- include/crypto/internal/hash.h | 4 ++-- include/linux/crypto.h | 4 ++-- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/crypto/acompress.c b/crypto/acompress.c index 6ecbfc49bfa8..be28cbfd22e3 100644 --- a/crypto/acompress.c +++ b/crypto/acompress.c @@ -287,7 +287,7 @@ int crypto_acomp_compress(struct acomp_req *req) if (acomp_req_on_stack(req) && acomp_is_async(tfm)) return -EAGAIN; - if (crypto_acomp_req_chain(tfm) || acomp_request_issg(req)) + if (crypto_acomp_req_virt(tfm) || acomp_request_issg(req)) return crypto_acomp_reqtfm(req)->compress(req); return acomp_do_req_chain(req, true); } @@ -299,7 +299,7 @@ int crypto_acomp_decompress(struct acomp_req *req) if (acomp_req_on_stack(req) && acomp_is_async(tfm)) return -EAGAIN; - if (crypto_acomp_req_chain(tfm) || acomp_request_issg(req)) + if (crypto_acomp_req_virt(tfm) || acomp_request_issg(req)) return crypto_acomp_reqtfm(req)->decompress(req); return acomp_do_req_chain(req, false); } diff --git a/crypto/ahash.c b/crypto/ahash.c index cc9885d5cfd2..57c131a13067 100644 --- a/crypto/ahash.c +++ b/crypto/ahash.c @@ -407,7 +407,7 @@ static int ahash_do_req_chain(struct ahash_request *req, u8 *page = NULL; int err; - if (crypto_ahash_req_chain(tfm) || + if (crypto_ahash_req_virt(tfm) || !update || !ahash_request_isvirt(req)) return op(req); @@ -550,7 +550,7 @@ int crypto_ahash_finup(struct ahash_request *req) if (ahash_req_on_stack(req) && ahash_is_async(tfm)) return -EAGAIN; if (!crypto_ahash_alg(tfm)->finup || - (!crypto_ahash_req_chain(tfm) && ahash_request_isvirt(req))) + (!crypto_ahash_req_virt(tfm) && ahash_request_isvirt(req))) return ahash_def_finup(req); return ahash_do_req_chain(req, crypto_ahash_alg(tfm)->finup); } @@ -622,7 +622,7 @@ int crypto_ahash_digest(struct ahash_request *req) return shash_ahash_digest(req, prepare_shash_desc(req, tfm)); if (ahash_req_on_stack(req) && ahash_is_async(tfm)) return -EAGAIN; - if (!crypto_ahash_req_chain(tfm) && ahash_request_isvirt(req)) + if (!crypto_ahash_req_virt(tfm) && ahash_request_isvirt(req)) return ahash_def_digest(req); if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY) return -ENOKEY; diff --git a/crypto/deflate.c b/crypto/deflate.c index 0d2b64d96d6e..5f9fe51636ef 100644 --- a/crypto/deflate.c +++ b/crypto/deflate.c @@ -228,7 +228,7 @@ static struct acomp_alg acomp = { .init = deflate_init, .base.cra_name = "deflate", .base.cra_driver_name = "deflate-generic", - .base.cra_flags = CRYPTO_ALG_REQ_CHAIN, + .base.cra_flags = CRYPTO_ALG_REQ_VIRT, .base.cra_module = THIS_MODULE, }; diff --git a/crypto/scompress.c b/crypto/scompress.c index 15148c58d648..c651e7f2197a 100644 --- a/crypto/scompress.c +++ b/crypto/scompress.c @@ -355,7 +355,7 @@ static void scomp_prepare_alg(struct scomp_alg *alg) comp_prepare_alg(&alg->calg); - base->cra_flags |= CRYPTO_ALG_REQ_CHAIN; + base->cra_flags |= CRYPTO_ALG_REQ_VIRT; } int crypto_register_scomp(struct scomp_alg *alg) diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index f5f730969d72..423e57eca351 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h @@ -255,9 +255,9 @@ static inline u32 crypto_tfm_alg_type(struct crypto_tfm *tfm) return tfm->__crt_alg->cra_flags & CRYPTO_ALG_TYPE_MASK; } -static inline bool crypto_tfm_req_chain(struct crypto_tfm *tfm) +static inline bool crypto_tfm_req_virt(struct crypto_tfm *tfm) { - return tfm->__crt_alg->cra_flags & CRYPTO_ALG_REQ_CHAIN; + return tfm->__crt_alg->cra_flags & CRYPTO_ALG_REQ_VIRT; } static inline u32 crypto_request_flags(struct crypto_async_request *req) diff --git a/include/crypto/internal/acompress.h b/include/crypto/internal/acompress.h index b72bb7a6a2b2..ffffd88bbbad 100644 --- a/include/crypto/internal/acompress.h +++ b/include/crypto/internal/acompress.h @@ -186,9 +186,9 @@ static inline bool acomp_request_isnondma(struct acomp_req *req) CRYPTO_ACOMP_REQ_DST_NONDMA); } -static inline bool crypto_acomp_req_chain(struct crypto_acomp *tfm) +static inline bool crypto_acomp_req_virt(struct crypto_acomp *tfm) { - return crypto_tfm_req_chain(&tfm->base); + return crypto_tfm_req_virt(&tfm->base); } void crypto_acomp_free_streams(struct crypto_acomp_streams *s); diff --git a/include/crypto/internal/hash.h b/include/crypto/internal/hash.h index 33d45275f5bd..e911f32f46dc 100644 --- a/include/crypto/internal/hash.h +++ b/include/crypto/internal/hash.h @@ -267,9 +267,9 @@ static inline bool ahash_request_isvirt(struct ahash_request *req) return req->base.flags & CRYPTO_AHASH_REQ_VIRT; } -static inline bool crypto_ahash_req_chain(struct crypto_ahash *tfm) +static inline bool crypto_ahash_req_virt(struct crypto_ahash *tfm) { - return crypto_tfm_req_chain(&tfm->base); + return crypto_tfm_req_virt(&tfm->base); } static inline struct crypto_ahash *crypto_ahash_fb(struct crypto_ahash *tfm) diff --git a/include/linux/crypto.h b/include/linux/crypto.h index b8d875b11193..b50f1954d1bb 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h @@ -133,8 +133,8 @@ */ #define CRYPTO_ALG_FIPS_INTERNAL 0x00020000 -/* Set if the algorithm supports request chains and virtual addresses. */ -#define CRYPTO_ALG_REQ_CHAIN 0x00040000 +/* Set if the algorithm supports virtual addresses. */ +#define CRYPTO_ALG_REQ_VIRT 0x00040000 /* The high bits 0xff000000 are reserved for type-specific flags. */ From patchwork Thu May 1 12:37:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 886718 Received: from abb.hmeau.com (abb.hmeau.com [144.6.53.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E34E22253FD for ; Thu, 1 May 2025 12:37:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=144.6.53.87 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746103062; cv=none; b=pLC+r8a6k40ZRBqk7F+TaPkB2Xi/2yqWYN5XSnu9Dpqd28dJwOaqfcHRsJsj+5R1qafPYZ2bBmiYRaWHoICNUhMvSLZmuyNvHjOER1B6SrKwYalz5/b8cV1+5N5IJGmSuZSPP4eL9v+hWy/IU/+09AIr3ITsL9Q1IaR8vwcZLLI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746103062; c=relaxed/simple; bh=GKShZ+4esPP6JFokUTLEw9AsB2RDr6rnJ6/MoqGwT3E=; h=Date:Message-Id:In-Reply-To:References:From:Subject:To:Cc; b=kRhANdtgamwUZA07/2hbgl0dj6HQIIJN85X3jpsOu3l9CmB+oHIXDIV7HJAE+q8qjHwM0j7pZHfdDZsLdxmRgihKaDlMQBlSLMovF8IvATbr8yeOV4g+s1W4hWxvIr8BEiehB2TqOE/94beL5fA3G2wjL6E90ZSH5ezT5Sn/3A4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gondor.apana.org.au; spf=pass smtp.mailfrom=gondor.apana.org.au; dkim=pass (2048-bit key) header.d=hmeau.com header.i=@hmeau.com header.b=sf7ocQFb; arc=none smtp.client-ip=144.6.53.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gondor.apana.org.au Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gondor.apana.org.au Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hmeau.com header.i=@hmeau.com header.b="sf7ocQFb" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hmeau.com; s=formenos; h=Cc:To:Subject:From:References:In-Reply-To:Message-Id:Date: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=IG1NXODoAPSeiMfeVbkg8+4OeRbyOHOxiq38CzJfrsU=; b=sf7ocQFbeKhYTLQm48Awslu6mL XNqrtThJ2Vae/IB0F5AJl/vdzRaSpqU7Lh18Fd8r1Kov86YJLyFWYkIame9CyJiiqgH1c2f43vWsJ Vrad26jZQ4LOiq3hKWmsG2YxSexZYXggEPCVyItvXl3B1UzAbCmtE4YaeaI9ZZJT5uvevqO9/iaHx QuSG1317yarhV+CEZDvOdxAHOQGHgJSD9L3ZtGYG5ZsE15gMKqzKjoG7KlK6irIQDyp7jR4xHMdDC OZHd0LmYRsbYW2w5YryVYCTSYWF+YjAvnmSmn64ot6t2ApkS62c/y9qy7wnfWl0ehViFSfhGVHirI a/xRes8w==; Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.96 #2 (Debian)) id 1uATAV-002bFI-0U; Thu, 01 May 2025 20:37:36 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Thu, 01 May 2025 20:37:35 +0800 Date: Thu, 01 May 2025 20:37:35 +0800 Message-Id: In-Reply-To: References: From: Herbert Xu Subject: [PATCH 3/4] crypto: acomp - Add compression segmentation support To: Linux Crypto Mailing List Cc: Kanchana P Sridhar Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Add support for compression after segmentation. The caller shall specify a unit size, and the API will divide the source SG list into the units of that size, before compression. That caller shall supply a single page in a 2-entry SG list for output to seed the operation. The API will allocate more pages if necessary and extend the SG list by chaining. If there is an allocation failure the operation will stop and partial results can be processed with the rest continued in a new operation with an updated offset in the source SG list. Signed-off-by: Herbert Xu --- crypto/acompress.c | 152 ++++++++++++++++++++++++++-- crypto/algapi.c | 3 + include/crypto/acompress.h | 103 +++++++++++++++++-- include/crypto/algapi.h | 5 + include/crypto/internal/acompress.h | 10 ++ include/linux/crypto.h | 3 + 6 files changed, 263 insertions(+), 13 deletions(-) diff --git a/crypto/acompress.c b/crypto/acompress.c index be28cbfd22e3..821de2010089 100644 --- a/crypto/acompress.c +++ b/crypto/acompress.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -234,7 +235,7 @@ static int acomp_do_nondma(struct acomp_req *req, bool comp) return err; } -static int acomp_do_one_req(struct acomp_req *req, bool comp) +static int acomp_do_linear(struct acomp_req *req, bool comp) { if (acomp_request_isnondma(req)) return acomp_do_nondma(req, comp); @@ -244,9 +245,100 @@ static int acomp_do_one_req(struct acomp_req *req, bool comp) crypto_acomp_reqtfm(req)->decompress(req); } +static void acomp_restore_cur(struct acomp_req *req) +{ + req->src->length += req->src->offset - req->chain.osoff; + req->src->offset = req->chain.osoff; +} + +static void acomp_restore_unit(struct acomp_req *req) +{ + acomp_restore_cur(req); + req->src = req->chain.ossg; + req->dst = req->chain.odsg; + req->slen = req->chain.oslen; + req->dlen = req->chain.unit; + req->base.flags |= CRYPTO_ACOMP_REQ_SRC_SEG; +} + static int acomp_reqchain_finish(struct acomp_req *req, int err) { - acomp_reqchain_virt(req); + if (!req->chain.unit) { + acomp_reqchain_virt(req); + goto out; + } + + for (;;) { + unsigned int dlen = err ? 0 : req->dlen; + unsigned int todo = req->slen; + struct page *page = NULL; + struct scatterlist *sg; + unsigned int remain; + + req->dst->dma_address = 0; + if (req->dst->length < dlen) { + dlen -= req->dst->length; + req->dst->dma_address = 1; + req->dst = sg_next(req->dst); + } + req->dst->length = dlen; + + if (!(req->chain.slen -= todo)) + break; + + if (req->src->length > todo) { + req->src->length -= todo; + req->src->offset += todo; + } + + remain = todo - req->src->length; + acomp_restore_cur(req); + req->src = sg_next(req->src); + req->chain.osoff = req->src->offset; + req->src->length -= remain; + req->src->offset += remain; + + todo = min(req->chain.unit, req->chain.slen); + req->slen = todo; + + remain = PAGE_SIZE - req->dst->offset - req->dst->length; + if (!sg_is_last(req->dst)) + page = sg_page(req->dst + 1); + else if (remain < todo) { + page = alloc_page(GFP_ATOMIC); + if (!page) + break; + } + + sg = kmalloc_array(2 - !remain + !!page, + sizeof(*sg), GFP_ATOMIC); + if (!sg) { + __free_page(page); + break; + } + + sg_unmark_end(req->dst); + sg_chain(req->dst, 2, sg); + + sg_init_table(sg, !!remain + !!page); + if (remain) + sg_set_page(sg, sg_page(req->dst), + remain, PAGE_SIZE - remain); + if (page) + sg_set_page(sg + !!remain, page, PAGE_SIZE, 0); + + req->dst = sg; + req->dlen = todo; + + err = crypto_acomp_reqtfm(req)->compress(req); + if (err == -EINPROGRESS || err == -EBUSY) + return err; + } + + acomp_restore_unit(req); + err = 0; + +out: acomp_restore_req(req); return err; } @@ -268,16 +360,61 @@ static void acomp_reqchain_done(void *data, int err) compl(data, err); } +void acomp_free_sgl(struct scatterlist *sg) +{ + struct page *page0; + + page0 = sg_page(sg); + sg = sg_next(sg); + while (sg) { + struct scatterlist *nsg = sg_next(sg); + struct page *page = sg_page(sg); + + if (page != page0) + __free_page(page); + + kfree(sg); + sg = nsg; + } +} +EXPORT_SYMBOL_GPL(acomp_free_sgl); + static int acomp_do_req_chain(struct acomp_req *req, bool comp) { + unsigned int todo; int err; acomp_save_req(req, acomp_reqchain_done); + if (!acomp_request_isunit(req)) { + req->chain.unit = 0; + err = acomp_do_linear(req, comp); + goto out; + } - err = acomp_do_one_req(req, comp); - if (err == -EBUSY || err == -EINPROGRESS) + if (req->dst->offset || req->dst->length != PAGE_SIZE) + return -EINVAL; + if (!req->dlen) + return -EINVAL; + + req->base.flags &= ~CRYPTO_ACOMP_REQ_SRC_SEG; + + req->chain.ossg = req->src; + req->chain.odsg = req->dst; + req->chain.oslen = req->slen; + req->chain.unit = req->dlen; + + req->chain.osoff = req->src->offset; + req->chain.slen = req->slen; + + todo = min(req->chain.unit, req->chain.slen); + req->slen = todo; + req->dlen = todo; + + err = crypto_acomp_reqtfm(req)->compress(req); + +out: + if (err == -EINPROGRESS || err == -EBUSY) return err; - return acomp_reqchain_finish(req, err); } @@ -287,7 +424,8 @@ int crypto_acomp_compress(struct acomp_req *req) if (acomp_req_on_stack(req) && acomp_is_async(tfm)) return -EAGAIN; - if (crypto_acomp_req_virt(tfm) || acomp_request_issg(req)) + if ((crypto_acomp_req_virt(tfm) || acomp_request_issg(req)) && + (crypto_acomp_req_seg(tfm) || !acomp_request_isunit(req))) return crypto_acomp_reqtfm(req)->compress(req); return acomp_do_req_chain(req, true); } @@ -299,6 +437,8 @@ int crypto_acomp_decompress(struct acomp_req *req) if (acomp_req_on_stack(req) && acomp_is_async(tfm)) return -EAGAIN; + if (acomp_request_isunit(req)) + return -ENOSYS; if (crypto_acomp_req_virt(tfm) || acomp_request_issg(req)) return crypto_acomp_reqtfm(req)->decompress(req); return acomp_do_req_chain(req, false); diff --git a/crypto/algapi.c b/crypto/algapi.c index 532d3efc3c7d..88f63aac5b74 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c @@ -59,6 +59,9 @@ static int crypto_check_alg(struct crypto_alg *alg) if (alg->cra_priority < 0) return -EINVAL; + if (alg->cra_flags & CRYPTO_ALG_REQ_SEG) + alg->cra_flags |= CRYPTO_ALG_REQ_VIRT; + refcount_set(&alg->cra_refcnt, 1); return 0; diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h index 9eacb9fa375d..0b503396fe5f 100644 --- a/include/crypto/acompress.h +++ b/include/crypto/acompress.h @@ -32,9 +32,13 @@ /* Set this bit for if virtual address destination cannot be used for DMA. */ #define CRYPTO_ACOMP_REQ_DST_NONDMA 0x00000010 +/* Set this bit if request source needs segmentation. */ +#define CRYPTO_ACOMP_REQ_SRC_SEG 0x00000020 + /* Private flags that should not be touched by the user. */ #define CRYPTO_ACOMP_REQ_PRIVATE \ (CRYPTO_ACOMP_REQ_SRC_VIRT | CRYPTO_ACOMP_REQ_SRC_NONDMA | \ + CRYPTO_ACOMP_REQ_SRC_SEG | \ CRYPTO_ACOMP_REQ_DST_VIRT | CRYPTO_ACOMP_REQ_DST_NONDMA) #define CRYPTO_ACOMP_DST_MAX 131072 @@ -50,7 +54,6 @@ #define ACOMP_REQUEST_CLONE(name, gfp) \ acomp_request_clone(name, sizeof(__##name##_req), gfp) -struct acomp_req; struct folio; struct acomp_req_chain { @@ -59,12 +62,18 @@ struct acomp_req_chain { struct scatterlist ssg; struct scatterlist dsg; union { - const u8 *src; - struct folio *sfolio; - }; - union { - u8 *dst; - struct folio *dfolio; + struct { + const u8 *src; + u8 *dst; + }; + struct { + struct scatterlist *ossg; + struct scatterlist *odsg; + unsigned int oslen; + unsigned int osoff; + unsigned int unit; + unsigned int slen; + }; }; u32 flags; }; @@ -357,10 +366,53 @@ static inline void acomp_request_set_params(struct acomp_req *req, req->base.flags &= ~(CRYPTO_ACOMP_REQ_SRC_VIRT | CRYPTO_ACOMP_REQ_SRC_NONDMA | + CRYPTO_ACOMP_REQ_SRC_SEG | CRYPTO_ACOMP_REQ_DST_VIRT | CRYPTO_ACOMP_REQ_DST_NONDMA); } +/** + * acomp_request_set_src_unit() -- Sets source segmented scatterlist + * + * Sets source segmented scatterlist required by an acomp operation. + * + * This is only supported for compression. The input will be + * segmented into units of the specified size, before being sent + * for compression. The output can be retrieved from req->dst. + * Each entry in req->dst shall correspond to one input unit, unless + * acomp_sgl_split() returns true on that SG entry, in which case + * that entry and the next shall correspond to the same input unit. + * A zero-length entry in req->dst means that the corresponding input + * unit is incompressible. If the number of entries in req->dst is + * less than the number of input units, then the rest were not + * processed due to a memory allocation failure. The caller may + * retry the operation with an adjusted src offset. + * + * @req: asynchronous compress request + * @src: pointer to input buffer scatterlist + * @slen: size of the input buffer + * @dst: 2-element scatterlist, first with a single page and the + * second is reserved for chaining. + * @unit: unit size + */ +static inline void acomp_request_set_src_unit(struct acomp_req *req, + struct scatterlist *src, + unsigned int slen, + struct scatterlist dst[2], + int unit) +{ + req->src = src; + req->slen = slen; + req->dst = dst; + req->dlen = unit; + + req->base.flags &= ~(CRYPTO_ACOMP_REQ_SRC_VIRT | + CRYPTO_ACOMP_REQ_SRC_NONDMA | + CRYPTO_ACOMP_REQ_DST_VIRT | + CRYPTO_ACOMP_REQ_DST_NONDMA); + req->base.flags |= CRYPTO_ACOMP_REQ_SRC_SEG; +} + /** * acomp_request_set_src_sg() -- Sets source scatterlist * @@ -379,6 +431,7 @@ static inline void acomp_request_set_src_sg(struct acomp_req *req, req->base.flags &= ~CRYPTO_ACOMP_REQ_SRC_NONDMA; req->base.flags &= ~CRYPTO_ACOMP_REQ_SRC_VIRT; + req->base.flags &= ~CRYPTO_ACOMP_REQ_SRC_SEG; } /** @@ -398,6 +451,7 @@ static inline void acomp_request_set_src_dma(struct acomp_req *req, req->slen = slen; req->base.flags &= ~CRYPTO_ACOMP_REQ_SRC_NONDMA; + req->base.flags &= ~CRYPTO_ACOMP_REQ_SRC_SEG; req->base.flags |= CRYPTO_ACOMP_REQ_SRC_VIRT; } @@ -418,6 +472,7 @@ static inline void acomp_request_set_src_nondma(struct acomp_req *req, req->svirt = src; req->slen = slen; + req->base.flags &= ~CRYPTO_ACOMP_REQ_SRC_SEG; req->base.flags |= CRYPTO_ACOMP_REQ_SRC_NONDMA; req->base.flags |= CRYPTO_ACOMP_REQ_SRC_VIRT; } @@ -441,6 +496,31 @@ static inline void acomp_request_set_src_folio(struct acomp_req *req, acomp_request_set_src_sg(req, &req->chain.ssg, len); } +/** + * acomp_request_set_src_folio_unit() -- Sets source segmented folio + * + * Sets source segmented folio required by an acomp operation. + * + * @req: asynchronous compress request + * @folio: pointer to input folio + * @off: input folio offset + * @len: size of the input buffer + * @dst: 2-element scatterlist, first with a single page and the + * second is reserved for chaining. + * @unit: unit size + */ +static inline void acomp_request_set_src_folio_unit(struct acomp_req *req, + struct folio *folio, + size_t off, + unsigned int len, + struct scatterlist dst[2], + unsigned int unit) +{ + sg_init_table(&req->chain.ssg, 1); + sg_set_folio(&req->chain.ssg, folio, len, off); + acomp_request_set_src_unit(req, &req->chain.ssg, len, dst, unit); +} + /** * acomp_request_set_dst_sg() -- Sets destination scatterlist * @@ -554,4 +634,13 @@ static inline struct acomp_req *acomp_request_on_stack_init( struct acomp_req *acomp_request_clone(struct acomp_req *req, size_t total, gfp_t gfp); +/* True if the result entry spans two SG entries. */ +static inline bool acomp_sgl_split(struct scatterlist *sg) +{ + return !!sg->dma_address; +} + +/* Free segmented SGL list returned in req->dst. */ +void acomp_free_sgl(struct scatterlist *sg); + #endif diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index 423e57eca351..8f29c636f644 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h @@ -260,6 +260,11 @@ static inline bool crypto_tfm_req_virt(struct crypto_tfm *tfm) return tfm->__crt_alg->cra_flags & CRYPTO_ALG_REQ_VIRT; } +static inline bool crypto_tfm_req_seg(struct crypto_tfm *tfm) +{ + return tfm->__crt_alg->cra_flags & CRYPTO_ALG_REQ_SEG; +} + static inline u32 crypto_request_flags(struct crypto_async_request *req) { return req->flags & ~CRYPTO_TFM_REQ_ON_STACK; diff --git a/include/crypto/internal/acompress.h b/include/crypto/internal/acompress.h index ffffd88bbbad..20b505d0a10a 100644 --- a/include/crypto/internal/acompress.h +++ b/include/crypto/internal/acompress.h @@ -154,6 +154,11 @@ static inline bool acomp_request_issg(struct acomp_req *req) CRYPTO_ACOMP_REQ_DST_VIRT)); } +static inline bool acomp_request_isunit(struct acomp_req *req) +{ + return req->base.flags & CRYPTO_ACOMP_REQ_SRC_SEG; +} + static inline bool acomp_request_src_isvirt(struct acomp_req *req) { return req->base.flags & CRYPTO_ACOMP_REQ_SRC_VIRT; @@ -191,6 +196,11 @@ static inline bool crypto_acomp_req_virt(struct crypto_acomp *tfm) return crypto_tfm_req_virt(&tfm->base); } +static inline bool crypto_acomp_req_seg(struct crypto_acomp *tfm) +{ + return crypto_tfm_req_seg(&tfm->base); +} + void crypto_acomp_free_streams(struct crypto_acomp_streams *s); int crypto_acomp_alloc_streams(struct crypto_acomp_streams *s); diff --git a/include/linux/crypto.h b/include/linux/crypto.h index b50f1954d1bb..ed1595e1eb0f 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h @@ -136,6 +136,9 @@ /* Set if the algorithm supports virtual addresses. */ #define CRYPTO_ALG_REQ_VIRT 0x00040000 +/* Set if the algorithm supports segmentation (implies REQ_VIRT). */ +#define CRYPTO_ALG_REQ_SEG 0x00080000 + /* The high bits 0xff000000 are reserved for type-specific flags. */ /* From patchwork Thu May 1 12:37:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 886539 Received: from abb.hmeau.com (abb.hmeau.com [144.6.53.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36F5A225779 for ; Thu, 1 May 2025 12:37:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=144.6.53.87 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746103063; cv=none; b=Vyk8YEz4Zc5pfcByrCWnKdfgG4lnG0yYXkntVT9v6pLnmsxD8wFOurQUdW1ivUIcI1/0Ay+TjWJwSwFJmWaOqv+LVDCTEQ2PocROdceM5hUiA33t/8SXAj9i/gY4o533QOyhYJTw9bS4YJeZi6sxvCkd62keuPt7VDaV2FjBfI4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746103063; c=relaxed/simple; bh=HM6EgddskCXkChxjeffRHjfo09SxOqTMaeSYRUxITqg=; h=Date:Message-Id:In-Reply-To:References:From:Subject:To:Cc; b=VItQIJ1Wq+CmqBPHYcmz22++cNeViMNCtzHrqUtPahBdTbfM0p14gUrtToVP8P7zaYUOpArYOZXxVaPiAD3r9FsHyeO9op69jIFwQi6m1NDsbBIboLGd6d657IwbAQUFshiPTt23uaIDhpAU2jZPSPpMPIjn9JW4c7J3MZGcQQ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gondor.apana.org.au; spf=pass smtp.mailfrom=gondor.apana.org.au; dkim=pass (2048-bit key) header.d=hmeau.com header.i=@hmeau.com header.b=D3pJjDYU; arc=none smtp.client-ip=144.6.53.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gondor.apana.org.au Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gondor.apana.org.au Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hmeau.com header.i=@hmeau.com header.b="D3pJjDYU" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hmeau.com; s=formenos; h=Cc:To:Subject:From:References:In-Reply-To:Message-Id:Date: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=2Nq7gFsQkFTi60kydWjc5/MHbyTJyziFWtOylmEcKLM=; b=D3pJjDYU3P/OuWj6JRC5hkkYoc bjTMPz+2Yp6jaql9BAs5RKyv0u3U8j7yY7h9GzZAK+LxL6OUtYWhSH12phJ6FuVVYVmlzGpEQpMrS oyQBJJ7IvQY/85XbUSI8GF7xotudtRaDWyHe0pzlC/9Jvx4XTDSvgTvHdp/FgdJRsiwEciSQYWQhk 2Ek54Pe5LmYGNVew2a461INn8Tj/KR44HQl6uPVpOXhNkm+eHK/80Y40EX3H5iz/zwDybx1Wkzg+O kcP704yXBgKx2yUHiCOsLkP9Wmg8iaAQk7ZcLW4reQ0QKfwNZvDQUDO1J9dIRZQrQjkmuOTcFoZlN PHnIpbsQ==; Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.96 #2 (Debian)) id 1uATAX-002bFW-1T; Thu, 01 May 2025 20:37:38 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Thu, 01 May 2025 20:37:37 +0800 Date: Thu, 01 May 2025 20:37:37 +0800 Message-Id: <79dc6c03779a179e3cf9eae95142e3858d5979ee.1746102673.git.herbert@gondor.apana.org.au> In-Reply-To: References: From: Herbert Xu Subject: [PATCH 4/4] crypto: testmgr - Add multibuffer acomp testing To: Linux Crypto Mailing List Cc: Kanchana P Sridhar Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Add rudimentary multibuffer acomp testing. Testing coverage is extended to compression vectors only. Signed-off-by: Herbert Xu --- crypto/testmgr.c | 145 +++++++++++++++++++++++------------------------ 1 file changed, 72 insertions(+), 73 deletions(-) diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 82977ea25db3..68f295923ea7 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -58,6 +58,9 @@ module_param(fuzz_iterations, uint, 0644); MODULE_PARM_DESC(fuzz_iterations, "number of fuzz test iterations"); #endif +/* Multibuffer is unlimited. Set arbitrary limit for testing. */ +#define MAX_MB_MSGS 16 + #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS /* a perfect nop */ @@ -3326,14 +3329,19 @@ static int test_acomp(struct crypto_acomp *tfm, int ctcount, int dtcount) { const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm)); - unsigned int i; + struct scatterlist src[MAX_MB_MSGS], dst[2]; + ACOMP_REQUEST_ON_STACK(req, tfm); char *output, *decomp_out; - int ret; - struct scatterlist src, dst; - struct acomp_req *req; struct crypto_wait wait; + int ret = -ENOMEM; + unsigned int i; - output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL); + acomp_request_set_callback(req, + CRYPTO_TFM_REQ_MAY_SLEEP | + CRYPTO_TFM_REQ_MAY_BACKLOG, + NULL, NULL); + + output = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!output) return -ENOMEM; @@ -3346,7 +3354,9 @@ static int test_acomp(struct crypto_acomp *tfm, for (i = 0; i < ctcount; i++) { unsigned int dlen = COMP_BUF_SIZE; int ilen = ctemplate[i].inlen; + struct scatterlist *sg; void *input_vec; + int j; input_vec = kmemdup(ctemplate[i].input, ilen, GFP_KERNEL); if (!input_vec) { @@ -3354,70 +3364,74 @@ static int test_acomp(struct crypto_acomp *tfm, goto out; } - memset(output, 0, dlen); crypto_init_wait(&wait); - sg_init_one(&src, input_vec, ilen); - sg_init_one(&dst, output, dlen); - req = acomp_request_alloc(tfm); - if (!req) { - pr_err("alg: acomp: request alloc failed for %s\n", - algo); - kfree(input_vec); - ret = -ENOMEM; - goto out; + sg_init_table(src, MAX_MB_MSGS); + for (j = 0; j < MAX_MB_MSGS; j++) + sg_set_buf(src + j, input_vec, ilen); + + sg_init_one(dst, output, PAGE_SIZE); + acomp_request_set_src_unit(req, src, MAX_MB_MSGS * ilen, + dst, ilen); + + ret = crypto_acomp_compress(req); + if (ret == -EAGAIN) { + req = ACOMP_REQUEST_CLONE(req, GFP_KERNEL); + acomp_request_set_callback(req, + CRYPTO_TFM_REQ_MAY_SLEEP | + CRYPTO_TFM_REQ_MAY_BACKLOG, + crypto_req_done, &wait); + ret = crypto_acomp_compress(req); + ret = crypto_wait_req(ret, &wait); } - - acomp_request_set_params(req, &src, &dst, ilen, dlen); - acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - crypto_req_done, &wait); - - ret = crypto_wait_req(crypto_acomp_compress(req), &wait); if (ret) { pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n", i + 1, algo, -ret); kfree(input_vec); - acomp_request_free(req); goto out; } - ilen = req->dlen; + sg = dst; + ilen = sg->length; dlen = COMP_BUF_SIZE; - sg_init_one(&src, output, ilen); - sg_init_one(&dst, decomp_out, dlen); - crypto_init_wait(&wait); - acomp_request_set_params(req, &src, &dst, ilen, dlen); + for (j = 0; j < MAX_MB_MSGS; j++) { + sg_init_one(src, decomp_out, dlen); + acomp_request_set_params(req, sg, src, ilen, dlen); + crypto_init_wait(&wait); + ret = crypto_wait_req(crypto_acomp_decompress(req), &wait); + if (ret) { + pr_err("alg: acomp: re-decompression failed on test %d (%d) for %s: ret=%d\n", + i + 1, j, algo, -ret); + acomp_free_sgl(dst); + kfree(input_vec); + goto out; + } - ret = crypto_wait_req(crypto_acomp_decompress(req), &wait); - if (ret) { - pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n", - i + 1, algo, -ret); - kfree(input_vec); - acomp_request_free(req); - goto out; - } - - if (req->dlen != ctemplate[i].inlen) { - pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n", - i + 1, algo, req->dlen); - ret = -EINVAL; - kfree(input_vec); - acomp_request_free(req); - goto out; - } - - if (memcmp(input_vec, decomp_out, req->dlen)) { - pr_err("alg: acomp: Compression test %d failed for %s\n", - i + 1, algo); - hexdump(output, req->dlen); - ret = -EINVAL; - kfree(input_vec); - acomp_request_free(req); - goto out; + if (req->dlen != ctemplate[i].inlen) { + pr_err("alg: acomp: Compression test %d (%d) failed for %s: output len = %d\n", + i + 1, j, algo, req->dlen); + ret = -EINVAL; + acomp_free_sgl(dst); + kfree(input_vec); + goto out; + } + + if (memcmp(input_vec, decomp_out, req->dlen)) { + pr_err("alg: acomp: Compression test %d (%d) failed for %s\n", + i + 1, j, algo); + hexdump(output, req->dlen); + ret = -EINVAL; + acomp_free_sgl(dst); + kfree(input_vec); + goto out; + } + if (acomp_sgl_split(sg)) + sg = sg_next(sg); + sg = sg_next(sg); } + acomp_free_sgl(dst); kfree(input_vec); - acomp_request_free(req); } for (i = 0; i < dtcount; i++) { @@ -3431,30 +3445,17 @@ static int test_acomp(struct crypto_acomp *tfm, goto out; } - memset(output, 0, dlen); crypto_init_wait(&wait); - sg_init_one(&src, input_vec, ilen); - sg_init_one(&dst, output, dlen); + sg_init_one(src, input_vec, ilen); + sg_init_one(dst, output, dlen); - req = acomp_request_alloc(tfm); - if (!req) { - pr_err("alg: acomp: request alloc failed for %s\n", - algo); - kfree(input_vec); - ret = -ENOMEM; - goto out; - } - - acomp_request_set_params(req, &src, &dst, ilen, dlen); - acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - crypto_req_done, &wait); + acomp_request_set_params(req, src, dst, ilen, dlen); ret = crypto_wait_req(crypto_acomp_decompress(req), &wait); if (ret) { pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n", i + 1, algo, -ret); kfree(input_vec); - acomp_request_free(req); goto out; } @@ -3463,7 +3464,6 @@ static int test_acomp(struct crypto_acomp *tfm, i + 1, algo, req->dlen); ret = -EINVAL; kfree(input_vec); - acomp_request_free(req); goto out; } @@ -3473,17 +3473,16 @@ static int test_acomp(struct crypto_acomp *tfm, hexdump(output, req->dlen); ret = -EINVAL; kfree(input_vec); - acomp_request_free(req); goto out; } kfree(input_vec); - acomp_request_free(req); } ret = 0; out: + acomp_request_free(req); kfree(decomp_out); kfree(output); return ret;