From patchwork Fri Jul 21 15:42:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 108490 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp944000qge; Fri, 21 Jul 2017 08:43:10 -0700 (PDT) X-Received: by 10.99.181.7 with SMTP id y7mr7807242pge.212.1500651790028; Fri, 21 Jul 2017 08:43:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500651790; cv=none; d=google.com; s=arc-20160816; b=o5G97KbJPjBd2zF4wB1h76kLvRDRi7Io2l0dB7BrQ4fU6U1OtM4GxVehS1wG5uSFAt LWlYyXQnru0WJVNvDpstlojiNuYLhbP9rnt11+zKOcavpYfaHrV4AZ8kwtKyjFjYkhSK 2GdFMjfnCRA+dugRBqM344sHTHP9Sl/YSlX31gwy04+xbG6N3zb3ut0rF/ng9ZwORgHV +48Fhr1QknzZAnh+Ca5r4E3Vac6Hxw64wPw7mcnV1nrQsDU5lDXQ2dxc+d8DOSwf35Tn NkeBdJGyCGFgdfV0KsTInO7gzLCdS+qw8WuIdgD/ndna0YaseG3m3BMPKMBohP7lnYoT hopQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=1aVPYRKZma76T36xO2vNljE8ab0VKXEoaxfcy/2k31c=; b=spEDSAhvOM8yFApPubz8p04HBW9tCNjFLuzsauqXfZv4N5Rcc+Y6zVaV7SG8GBdX/I QcN2iAx2rLwECbB19q8O8TAtm7vZRu9EA9iVM6TIwRkr5hykHFavIciydtpP/QPcvAsN GUMlckf67zUSFGAgwufAF4LC0pH99bS4ig7xlxq9xfi/P2tGpGWBLWtfXJqCHpP7GK/3 bM07vk6QMLnoRDKhZZOzSwAJyOD2HrDFm2xs1za8xQZ3xDHJ2/+ksd8tZW30uyj4R3K9 yiNSfAq4VfPBRKWyG4PQ+ex1nUlUjUB/9dZsIdJvLudLZ7NFhdwc0fSVDYsaV4pS/Q7A kYBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=dnuHGUpL; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o1si1422656pld.973.2017.07.21.08.43.09; Fri, 21 Jul 2017 08:43:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=dnuHGUpL; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750802AbdGUPnG (ORCPT + 1 other); Fri, 21 Jul 2017 11:43:06 -0400 Received: from mail-wm0-f52.google.com ([74.125.82.52]:38698 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751760AbdGUPnD (ORCPT ); Fri, 21 Jul 2017 11:43:03 -0400 Received: by mail-wm0-f52.google.com with SMTP id w191so17404304wmw.1 for ; Fri, 21 Jul 2017 08:43:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1aVPYRKZma76T36xO2vNljE8ab0VKXEoaxfcy/2k31c=; b=dnuHGUpL7m3MsuHNgQolJ73SQmqhJPbJpbd8VlqKsNZ+Ygo+RgKDIzU71/xRoO5nOL ijPfZZGIUVbmtRaHZ6PnbQ+TMA3nHOSktJPpkcDnuZRCDYpO80FjlOBokbnEMlXbiK3B vH5SgWk0UnX/38/xJ4COp4QBI17ogKPp4Cexg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1aVPYRKZma76T36xO2vNljE8ab0VKXEoaxfcy/2k31c=; b=oHfn1dUTwTGqnINvq/m/j345zFX0qvNd7qRABp9+SONxpMd//3K4owVfjzMSmMevKK i0UUZKeIuksUIkKRjypwt/qu0nfxDx4wdKsuc8dUFm7pBaXJ5L2NrJGxANvFLV0g6zRO 6Q7InuXlgf3z2+pEm/SZlVjnAtfPCzSHvK6/hMhv+tpyWLFfEhXRvC3WgWGXYKGyflRf KwS3h5NiMKG297WgC+ZDHNvsM/nA28o0GTO8x9EV27AQ1HG1FO3wlmPkhQ+ErSGfKrqH 0py2GtgVFEHGKSblgq0iwOOyhmiZV3H5gYWTU6zIq87ZEhazNxL8+D7UX+Nnlj5AcWNH yNRw== X-Gm-Message-State: AIVw110wR3ucBp44AS3mSFiTFJcQO93QhqaFZ5O0Es2jvCy8C269NKXF 2hThrNp9QL2ZzPc94w/Szw== X-Received: by 10.28.185.141 with SMTP id j135mr5309519wmf.44.1500651781801; Fri, 21 Jul 2017 08:43:01 -0700 (PDT) Received: from localhost.localdomain ([105.148.195.69]) by smtp.gmail.com with ESMTPSA id f203sm1498563wme.39.2017.07.21.08.43.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jul 2017 08:43:00 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au, giovanni.cabiddu@intel.com Cc: Ard Biesheuvel Subject: [PATCH v2 3/3] crypto: scompress - defer allocation of scratch buffer to first use Date: Fri, 21 Jul 2017 16:42:38 +0100 Message-Id: <20170721154238.21697-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170721154238.21697-1-ard.biesheuvel@linaro.org> References: <20170721154238.21697-1-ard.biesheuvel@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The scompress code allocates 2 x 128 KB of scratch buffers for each CPU, so that clients of the async API can use synchronous implementations even from atomic context. However, on systems such as Cavium Thunderx (which has 96 cores), this adds up to a non-negligible 24 MB. Also, 32-bit systems may prefer to use their precious vmalloc space for other things,especially since there don't appear to be any clients for the async compression API yet. So let's defer allocation of the scratch buffers until the first time we allocate an acompress cipher based on an scompress implementation. Signed-off-by: Ard Biesheuvel --- crypto/scompress.c | 46 ++++++++------------ 1 file changed, 17 insertions(+), 29 deletions(-) -- 2.11.0 diff --git a/crypto/scompress.c b/crypto/scompress.c index 2c07648305ad..2075e2c4e7df 100644 --- a/crypto/scompress.c +++ b/crypto/scompress.c @@ -65,11 +65,6 @@ static void crypto_scomp_show(struct seq_file *m, struct crypto_alg *alg) seq_puts(m, "type : scomp\n"); } -static int crypto_scomp_init_tfm(struct crypto_tfm *tfm) -{ - return 0; -} - static void crypto_scomp_free_scratches(void * __percpu *scratches) { int i; @@ -134,6 +129,17 @@ static int crypto_scomp_alloc_all_scratches(void) return 0; } +static int crypto_scomp_init_tfm(struct crypto_tfm *tfm) +{ + int ret; + + mutex_lock(&scomp_lock); + ret = crypto_scomp_alloc_all_scratches(); + mutex_unlock(&scomp_lock); + + return ret; +} + static void crypto_scomp_sg_free(struct scatterlist *sgl) { int i, n; @@ -241,6 +247,10 @@ static void crypto_exit_scomp_ops_async(struct crypto_tfm *tfm) struct crypto_scomp **ctx = crypto_tfm_ctx(tfm); crypto_free_scomp(*ctx); + + mutex_lock(&scomp_lock); + crypto_scomp_free_all_scratches(); + mutex_unlock(&scomp_lock); } int crypto_init_scomp_ops_async(struct crypto_tfm *tfm) @@ -317,40 +327,18 @@ static const struct crypto_type crypto_scomp_type = { int crypto_register_scomp(struct scomp_alg *alg) { struct crypto_alg *base = &alg->base; - int ret = -ENOMEM; - - mutex_lock(&scomp_lock); - if (crypto_scomp_alloc_all_scratches()) - goto error; base->cra_type = &crypto_scomp_type; base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK; base->cra_flags |= CRYPTO_ALG_TYPE_SCOMPRESS; - ret = crypto_register_alg(base); - if (ret) - goto error; - - mutex_unlock(&scomp_lock); - return ret; - -error: - crypto_scomp_free_all_scratches(); - mutex_unlock(&scomp_lock); - return ret; + return crypto_register_alg(base); } EXPORT_SYMBOL_GPL(crypto_register_scomp); int crypto_unregister_scomp(struct scomp_alg *alg) { - int ret; - - mutex_lock(&scomp_lock); - ret = crypto_unregister_alg(&alg->base); - crypto_scomp_free_all_scratches(); - mutex_unlock(&scomp_lock); - - return ret; + return crypto_unregister_alg(&alg->base); } EXPORT_SYMBOL_GPL(crypto_unregister_scomp);