From patchwork Fri Jul 21 15:42:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 108488 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp943956qge; Fri, 21 Jul 2017 08:43:08 -0700 (PDT) X-Received: by 10.98.73.65 with SMTP id w62mr8102885pfa.61.1500651788065; Fri, 21 Jul 2017 08:43:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500651788; cv=none; d=google.com; s=arc-20160816; b=OPx6BX6yvo+wMPP4cJd0Bs+JGZelFZxloDNVByh5NayXNzdyYib2wiVspOSzjJZ54g KGH5MEvpxe3vE8sRoT78NsKkibfwCKyB66+aNHIxbUa9jQGFw2WOfE4qJ6JMnvfoDjbt 37HIff+//51y7KQ/oLNCgJ6YXT8esbeKGDkE6asKPPKQvfHogEBf2FQZpp21WKeP7RxI oGM7l5TI8hkWAEeX6jacCRanhMgSHfMjjXgUxgBt69mSXdhK1RTYIDCUkqiD6dYz3Z2Y uzGV2BtkUduN3K+h886vUWtTWOsbakhm7H9ghcBsBwycBRHGcQri3+dxchq5+BgG0g/W amoA== 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=hqZ3r1HCHF4DUlY1SsDnOPxDmdJivPKzLq2NZGCvHiY=; b=YUF+4gk/siGPvkuA5uCtUNOqKYftGe+s4Hf1vow/s9q32cOOrO2LYZp88qwUAf6tO/ dfa87d8VOoMv83nU740Dni6PYszl0GyWaQ/M3YvojtR9Tmslmx2+lOjbbOJt9kfYVdT+ GIMgBT1AKEm0A9wwSRftvIB5J3bfICqaI9PnZxbn0I5mIxXceEOGyyYRmbtyjgjQmSpP IPAaA1HcOaBX7FOXhYSppeVvjdqw/Eh3ZwGa874lRALz6k2lAY/pqRJj916ElpNPox/R Ps0XE7DQDPwACs3H7m8Xy5pZ2DL87AoLT4CbmxZDMw2M438dhYEifGRpTNbrhEK4Q7A1 v/EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=NnuNuPuH; 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.07; Fri, 21 Jul 2017 08:43:08 -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=NnuNuPuH; 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 S1752817AbdGUPnC (ORCPT + 1 other); Fri, 21 Jul 2017 11:43:02 -0400 Received: from mail-wm0-f41.google.com ([74.125.82.41]:35653 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751760AbdGUPm7 (ORCPT ); Fri, 21 Jul 2017 11:42:59 -0400 Received: by mail-wm0-f41.google.com with SMTP id w126so15912767wme.0 for ; Fri, 21 Jul 2017 08:42:58 -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=hqZ3r1HCHF4DUlY1SsDnOPxDmdJivPKzLq2NZGCvHiY=; b=NnuNuPuH2q6YUDwDCNzqohBwKGOhs3T/eFPLzUib8MPu3+XLikfht/fzcW5e/3umTl tErAaBfQVby+MYtaUPhtVsGj+peFIQp+d5xfrdkTvQiN0QCnwqhvBmZnLNkWwZCEHi9o 1+EwUaMaQuZBDrQTUkBtg3+/DsmSY/GOFC4xg= 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=hqZ3r1HCHF4DUlY1SsDnOPxDmdJivPKzLq2NZGCvHiY=; b=Rp/1JHiqp5au8Y+gmsWYM2XX1IkoLP/DxVdmtf/vGv/V6p69MS6hPXzGU134v+oQNW 7pqIIbvpCNCXgkNQz5BZYYv1ysTY3EMR4bU0vHxvA1+1zsC0FvQ8xXJ95tcHO47JuurA 7IPTr8uZDNa532MA4jv2aI7izpXPvL/Sq98GE2EGg9IvkXD4isP7pLNXBTjyApLS6IxK eq5KlbvcU6VEC9JwvwnIbvZe6TGxE739yWmLZvoWulWvLsTY142hY+/EuuDe07/bDVGd 0vJ51Jygy0Keyp/tMtGo5oObpV4rWIgEdwDMsGBpQ6lLWJFu5DJVrc6v9xwzCk4xxAhN YLgg== X-Gm-Message-State: AIVw113alXQj57ih9Wtxhh6ktx4ZWYQBLUXbiugc/VBjKaWxiPNRgoqD lOXiKE0AjcnsY0z+i7Vwjg== X-Received: by 10.28.230.199 with SMTP id e68mr5276966wmi.139.1500651777818; Fri, 21 Jul 2017 08:42:57 -0700 (PDT) Received: from localhost.localdomain ([105.148.195.69]) by smtp.gmail.com with ESMTPSA id f203sm1498563wme.39.2017.07.21.08.42.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jul 2017 08:42:57 -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 1/3] crypto: scompress - don't sleep with preemption disabled Date: Fri, 21 Jul 2017 16:42:36 +0100 Message-Id: <20170721154238.21697-2-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 Due to the use of per-CPU buffers, scomp_acomp_comp_decomp() executes with preemption disabled, and so whether the CRYPTO_TFM_REQ_MAY_SLEEP flag is set is irrelevant, since we cannot sleep anyway. So disregard the flag, and use GFP_ATOMIC unconditionally. Cc: # v4.10+ Signed-off-by: Ard Biesheuvel --- crypto/scompress.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) -- 2.11.0 diff --git a/crypto/scompress.c b/crypto/scompress.c index ae1d3cf209e4..0b40d991d65f 100644 --- a/crypto/scompress.c +++ b/crypto/scompress.c @@ -211,9 +211,7 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) scratch_dst, &req->dlen, *ctx); if (!ret) { if (!req->dst) { - req->dst = crypto_scomp_sg_alloc(req->dlen, - req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ? - GFP_KERNEL : GFP_ATOMIC); + req->dst = crypto_scomp_sg_alloc(req->dlen, GFP_ATOMIC); if (!req->dst) goto out; } From patchwork Fri Jul 21 15:42:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 108489 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp943966qge; Fri, 21 Jul 2017 08:43:08 -0700 (PDT) X-Received: by 10.84.232.14 with SMTP id h14mr8555262plk.359.1500651788372; Fri, 21 Jul 2017 08:43:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500651788; cv=none; d=google.com; s=arc-20160816; b=cc4F6DOU2j8A3AzY5Bx9MFtwiCJT3ZUmweS1PRYy/b9DfSYt2MKXJtCYv76sA5J1yi maKP0cDsipzuQ4xncH9ReaG1yW1JNMFpE6ToUo/0BUuYuv0pA5E92lVEEeRSLC2ZF44V EHMdHSMQPDTk2lKCPR9Bz16RjayeUAbIU4nsdKNXAQsXv6hKs87OYeYt20beYHG9Tv2H 3nFBgvRvfkN6eMwvHvp216btKex6DncAPrVe4dV73sT6zfbRNa7fVgj0wkpRUax/xpvt oOO4CmNAq8v3uoblJ+5ViUuvX/RW6QMfrSAP56R1ORSz0Opqm/AUxx/YLpSfZKqPzWKI lYvg== 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=a7JNrWpnMVlUFAGuoqLTIYgtq98pCEcXjPyUDarEqzo=; b=lLkXptxvqwAq1U1Yi/T/6V9o0RP73lnyIkneD1yxjgDi0vQHn+E17cg6awblEngqQz bXjjWObkIIN7hzAVGI7iPUADetiI6gzQ7Iz6zeV3aqYjvpUZdMe497uf/PxO+KuTYGW3 Y5hH5qOYS4cATqosCR/RrRDYmJEQcIxUEVmEJhdTe/tiZu+MmeNKjzGw+HmBjXEmflOG WBbd9rl1YiuNX6ITCOC02UJn806tXhDGgyLpxvIbGRzoLo5VCGI1khc8Dnx96Gyd2+Io XSEQmM24VharB0fM1pLSmIN6NHVUpi8NxaMPaWrTBmsjZUWf2EjtZC3cEEuZ1OsrI24Q 9ZjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=Air7MSZT; 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.08; Fri, 21 Jul 2017 08:43:08 -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=Air7MSZT; 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 S1753795AbdGUPnE (ORCPT + 1 other); Fri, 21 Jul 2017 11:43:04 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:38683 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750802AbdGUPnB (ORCPT ); Fri, 21 Jul 2017 11:43:01 -0400 Received: by mail-wm0-f48.google.com with SMTP id w191so17403597wmw.1 for ; Fri, 21 Jul 2017 08:43:00 -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=a7JNrWpnMVlUFAGuoqLTIYgtq98pCEcXjPyUDarEqzo=; b=Air7MSZTH+BC2EoUQrzpSewfpOkbBqWs5/YNVdJeQYKNcGEQ+7w2UQlxVOK2FhNL4K VXiAOyxrWaLk+dhv+YtuPBxTXLSwPVh7pGehR4eAwDJMev9huG653oenQe6clrPZLDH7 N1EFRGP5U74nu4VbFkHMP88zO1tqtTiixrQio= 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=a7JNrWpnMVlUFAGuoqLTIYgtq98pCEcXjPyUDarEqzo=; b=fsfcE/a74dYl2ZGDnXwIXOqO+HXXGGlvnUaa/A+yauWVEmViiVPtz5LP7xt3eYhHFx zEg7EWE209hGw0UGarXuv9JSNfJ8bsHoMDaJYVts37rleq7zWciTBRinHgzPR2CtFB4B we53d3Uhtdr8Pr8UAQ0Eelg7EgY5pkf9VAal8zLCGE+yFXXjLmu/URv+w/SlABUCySIN jrgpeX5eAjDFqmvS2QpKI0eADxroY4pbM3JxGPiNRmJCXWRe56+r8eoVivyg2d0jBpoU V8HSumPe8pUSMMftWpTvFZdDmgtoVujC7ik7vXVtlPm01Z5oTAMETOTqM0FB5L+fAELC KVHA== X-Gm-Message-State: AIVw111Ih63Qg+P+1H+UKni0P/FTtERmHFU5uGWrxk/BD9QL0GdlPQPT h8Q50EMz1zh++IRLFC8vRg== X-Received: by 10.28.87.205 with SMTP id l196mr4975854wmb.121.1500651779957; Fri, 21 Jul 2017 08:42:59 -0700 (PDT) Received: from localhost.localdomain ([105.148.195.69]) by smtp.gmail.com with ESMTPSA id f203sm1498563wme.39.2017.07.21.08.42.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jul 2017 08:42:59 -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 2/3] crypto: scompress - free partially allocated scratch buffers on failure Date: Fri, 21 Jul 2017 16:42:37 +0100 Message-Id: <20170721154238.21697-3-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 When allocating the per-CPU scratch buffers, we allocate the source and destination buffers separately, but bail immediately if the second allocation fails, without freeing the first one. Fix that. Signed-off-by: Ard Biesheuvel --- crypto/scompress.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) -- 2.11.0 diff --git a/crypto/scompress.c b/crypto/scompress.c index 0b40d991d65f..2c07648305ad 100644 --- a/crypto/scompress.c +++ b/crypto/scompress.c @@ -125,8 +125,11 @@ static int crypto_scomp_alloc_all_scratches(void) if (!scomp_src_scratches) return -ENOMEM; scomp_dst_scratches = crypto_scomp_alloc_scratches(); - if (!scomp_dst_scratches) + if (!scomp_dst_scratches) { + crypto_scomp_free_scratches(scomp_src_scratches); + scomp_src_scratches = NULL; return -ENOMEM; + } } return 0; } 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);