From patchwork Fri Sep 18 05:19:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joonsoo Kim X-Patchwork-Id: 7213051 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 15970BEEC1 for ; Fri, 18 Sep 2015 05:22:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C50B6208AD for ; Fri, 18 Sep 2015 05:22:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 68CC1208AB for ; Fri, 18 Sep 2015 05:22:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751418AbbIRFTx (ORCPT ); Fri, 18 Sep 2015 01:19:53 -0400 Received: from mail-pa0-f44.google.com ([209.85.220.44]:36478 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752010AbbIRFTv (ORCPT ); Fri, 18 Sep 2015 01:19:51 -0400 Received: by padhk3 with SMTP id hk3so40133745pad.3; Thu, 17 Sep 2015 22:19:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=58wErRgwzVa5C/0POBEUddEL8Zkzkh2Vb9C0xGMSB1E=; b=PhFmRfAIpFXU7XRkoD7lRgre0388tAvJjRFLvrB4vUMy6MfniImQQeAJOGGohIFSQQ zr6zi7xLfpBqPMWItXYTehel5ZqktY/uqpuGWCu93CLjvxXgVXyL4sNI3Uo3jEXYE5QN ejSuKidMOoWKpROiiAO9TTw+1UqopUse/npJsElunvT/huoDkTCZcZgIIjTik24hhYUl +5iVu1Zjrez+LBkF50ofq1NprgrT2uH67CR3WUt0qij6AfTan2h4F01Vkn/f78hn6szX xiZY8adjFQ+DarSy9sTLRcj25yxeLi4YtP5cOrwMlsALTkeTYRbSWD/SmsXN+/LLVczO 2IFw== X-Received: by 10.68.113.37 with SMTP id iv5mr5041398pbb.2.1442553590446; Thu, 17 Sep 2015 22:19:50 -0700 (PDT) Received: from localhost.localdomain ([119.69.155.252]) by smtp.gmail.com with ESMTPSA id bi2sm6443526pbb.45.2015.09.17.22.19.47 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Sep 2015 22:19:49 -0700 (PDT) From: Joonsoo Kim X-Google-Original-From: Joonsoo Kim To: Andrew Morton Cc: Minchan Kim , Nitin Gupta , Sergey Senozhatsky , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, Herbert Xu , "David S. Miller" , Stephan Mueller , Joonsoo Kim Subject: [PATCH v3 1/9] crypto: introduce decompression API that can be called via sharable tfm object Date: Fri, 18 Sep 2015 14:19:16 +0900 Message-Id: <1442553564-3476-2-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1442553564-3476-1-git-send-email-iamjoonsoo.kim@lge.com> References: <1442553564-3476-1-git-send-email-iamjoonsoo.kim@lge.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Until now, tfm object embeds (de)compression context in it and (de)compression in crypto API requires tfm object to use this context. But, there are some algorithms that doesn't need such context to operate. Therefore, this patch introduce new crypto decompression API that calls decompression function via sharable tfm object. Concurrent calls to decompress_noctx function through sharable tfm object will be okay because caller don't need any context in tfm and tfm is only used for fetching function pointer to decompress_noctx function. This can reduce overhead of maintaining multiple tfm if decompression doesn't require any context to operate. Signed-off-by: Joonsoo Kim --- crypto/842.c | 3 ++- crypto/compress.c | 36 ++++++++++++++++++++++++++++++++++++ crypto/crypto_null.c | 3 ++- crypto/deflate.c | 3 ++- crypto/lz4.c | 3 ++- crypto/lz4hc.c | 3 ++- crypto/lzo.c | 3 ++- include/linux/crypto.h | 20 ++++++++++++++++++++ 8 files changed, 68 insertions(+), 6 deletions(-) diff --git a/crypto/842.c b/crypto/842.c index 98e387e..1b6cdab 100644 --- a/crypto/842.c +++ b/crypto/842.c @@ -61,7 +61,8 @@ static struct crypto_alg alg = { .cra_module = THIS_MODULE, .cra_u = { .compress = { .coa_compress = crypto842_compress, - .coa_decompress = crypto842_decompress } } + .coa_decompress = crypto842_decompress, + .coa_decompress_noctx = NULL } } }; static int __init crypto842_mod_init(void) diff --git a/crypto/compress.c b/crypto/compress.c index c33f076..abb36a8 100644 --- a/crypto/compress.c +++ b/crypto/compress.c @@ -33,12 +33,21 @@ static int crypto_decompress(struct crypto_tfm *tfm, dlen); } +static int crypto_decompress_noctx(struct crypto_tfm *tfm, + const u8 *src, unsigned int slen, + u8 *dst, unsigned int *dlen) +{ + return tfm->__crt_alg->cra_compress.coa_decompress_noctx(src, slen, + dst, dlen); +} + int crypto_init_compress_ops(struct crypto_tfm *tfm) { struct compress_tfm *ops = &tfm->crt_compress; ops->cot_compress = crypto_compress; ops->cot_decompress = crypto_decompress; + ops->cot_decompress_noctx = NULL; return 0; } @@ -46,3 +55,30 @@ int crypto_init_compress_ops(struct crypto_tfm *tfm) void crypto_exit_compress_ops(struct crypto_tfm *tfm) { } + +struct crypto_comp *crypto_alloc_comp_noctx(const char *alg_name, + u32 type, u32 mask) +{ + struct crypto_comp *comp; + struct crypto_tfm *tfm; + struct compress_tfm *ops; + + comp = crypto_alloc_comp(alg_name, type, mask); + if (IS_ERR(comp)) + return comp; + + tfm = crypto_comp_tfm(comp); + if (!tfm->__crt_alg->cra_compress.coa_decompress_noctx) { + crypto_free_comp(comp); + return ERR_PTR(-EINVAL); + } + + ops = &tfm->crt_compress; + + /* Only allow noctx ops to comp_noctx */ + ops->cot_compress = NULL; + ops->cot_decompress = NULL; + ops->cot_decompress_noctx = crypto_decompress_noctx; + + return comp; +} diff --git a/crypto/crypto_null.c b/crypto/crypto_null.c index 941c9a4..3560b75 100644 --- a/crypto/crypto_null.c +++ b/crypto/crypto_null.c @@ -146,7 +146,8 @@ static struct crypto_alg null_algs[3] = { { .cra_module = THIS_MODULE, .cra_u = { .compress = { .coa_compress = null_compress, - .coa_decompress = null_compress } } + .coa_decompress = null_compress, + .coa_decompress_noctx = NULL } } } }; MODULE_ALIAS_CRYPTO("compress_null"); diff --git a/crypto/deflate.c b/crypto/deflate.c index 95d8d37..c0b0a40 100644 --- a/crypto/deflate.c +++ b/crypto/deflate.c @@ -203,7 +203,8 @@ static struct crypto_alg alg = { .cra_exit = deflate_exit, .cra_u = { .compress = { .coa_compress = deflate_compress, - .coa_decompress = deflate_decompress } } + .coa_decompress = deflate_decompress, + .coa_decompress_noctx = NULL } } }; static int __init deflate_mod_init(void) diff --git a/crypto/lz4.c b/crypto/lz4.c index aefbcea..d38ce2a 100644 --- a/crypto/lz4.c +++ b/crypto/lz4.c @@ -86,7 +86,8 @@ static struct crypto_alg alg_lz4 = { .cra_exit = lz4_exit, .cra_u = { .compress = { .coa_compress = lz4_compress_crypto, - .coa_decompress = lz4_decompress_crypto } } + .coa_decompress = lz4_decompress_crypto, + .coa_decompress_noctx = NULL } } }; static int __init lz4_mod_init(void) diff --git a/crypto/lz4hc.c b/crypto/lz4hc.c index a1d3b5b..0cb38a7 100644 --- a/crypto/lz4hc.c +++ b/crypto/lz4hc.c @@ -86,7 +86,8 @@ static struct crypto_alg alg_lz4hc = { .cra_exit = lz4hc_exit, .cra_u = { .compress = { .coa_compress = lz4hc_compress_crypto, - .coa_decompress = lz4hc_decompress_crypto } } + .coa_decompress = lz4hc_decompress_crypto, + .coa_decompress_noctx = NULL } } }; static int __init lz4hc_mod_init(void) diff --git a/crypto/lzo.c b/crypto/lzo.c index 4b3e925..ec0f7b3 100644 --- a/crypto/lzo.c +++ b/crypto/lzo.c @@ -89,7 +89,8 @@ static struct crypto_alg alg = { .cra_exit = lzo_exit, .cra_u = { .compress = { .coa_compress = lzo_compress, - .coa_decompress = lzo_decompress } } + .coa_decompress = lzo_decompress, + .coa_decompress_noctx = NULL } } }; static int __init lzo_mod_init(void) diff --git a/include/linux/crypto.h b/include/linux/crypto.h index e71cb70..31152b1 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h @@ -355,6 +355,8 @@ struct compress_alg { unsigned int slen, u8 *dst, unsigned int *dlen); int (*coa_decompress)(struct crypto_tfm *tfm, const u8 *src, unsigned int slen, u8 *dst, unsigned int *dlen); + int (*coa_decompress_noctx)(const u8 *src, unsigned int slen, + u8 *dst, unsigned int *dlen); }; @@ -538,6 +540,9 @@ struct compress_tfm { int (*cot_decompress)(struct crypto_tfm *tfm, const u8 *src, unsigned int slen, u8 *dst, unsigned int *dlen); + int (*cot_decompress_noctx)(struct crypto_tfm *tfm, + const u8 *src, unsigned int slen, + u8 *dst, unsigned int *dlen); }; #define crt_ablkcipher crt_u.ablkcipher @@ -1836,6 +1841,14 @@ static inline void crypto_free_comp(struct crypto_comp *tfm) crypto_free_tfm(crypto_comp_tfm(tfm)); } +struct crypto_comp *crypto_alloc_comp_noctx(const char *alg_name, + u32 type, u32 mask); + +static inline void crypto_free_comp_noctx(struct crypto_comp *tfm) +{ + crypto_free_comp(tfm); +} + static inline int crypto_has_comp(const char *alg_name, u32 type, u32 mask) { type &= ~CRYPTO_ALG_TYPE_MASK; @@ -1871,5 +1884,12 @@ static inline int crypto_comp_decompress(struct crypto_comp *tfm, src, slen, dst, dlen); } +static inline int crypto_comp_decompress_noctx(struct crypto_comp *tfm, + const u8 *src, unsigned int slen, + u8 *dst, unsigned int *dlen) +{ + return crypto_comp_crt(tfm)->cot_decompress_noctx(crypto_comp_tfm(tfm), + src, slen, dst, dlen); +} #endif /* _LINUX_CRYPTO_H */