From patchwork Mon Feb 27 12:38:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 9593083 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8E2BF604AB for ; Mon, 27 Feb 2017 12:42:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83CE8282ED for ; Mon, 27 Feb 2017 12:42:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7747E283ED; Mon, 27 Feb 2017 12:42:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B9E5282ED for ; Mon, 27 Feb 2017 12:42:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751391AbdB0Mjs (ORCPT ); Mon, 27 Feb 2017 07:39:48 -0500 Received: from mail-qk0-f182.google.com ([209.85.220.182]:35438 "EHLO mail-qk0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751395AbdB0Mi6 (ORCPT ); Mon, 27 Feb 2017 07:38:58 -0500 Received: by mail-qk0-f182.google.com with SMTP id u188so94257971qkc.2 for ; Mon, 27 Feb 2017 04:38:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=u8bA9TZJXSaoIhc0j34bENMtSoVIyOFr2jzXpwIE9sY=; b=DUBsvSaLky6Oiap6vBFZsZv5iMm3zeQSpnrBiYlURk7rt1XbVlyFDLZxxDtz9FHV5e ICgi6RYA+XV0ucCa5w4/7Cq8DA8un/TxMdu/xrTeR0GpeySiDnyUt2o4mc3mD0QBTwyi xHxHUD3CdQ8M1ZgcNvJMkw22W1eqFdm7uyZI1U5MNmhnGOcztP4yb33Q14xFsDN1Mc3F Y+BaEVXnshRoUO1y4rSL6Qs2E66exquLFLsx0xdOPVdMCQAuExk3d+f+eHyvIvrzqyXL B7xcNDxxwu8qLVShR4c2d7q/7zC0GPenDnjIS9GZbBmWUvmFNAK+RL6flOd/x43CG7nO BVbA== 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=u8bA9TZJXSaoIhc0j34bENMtSoVIyOFr2jzXpwIE9sY=; b=KQ5v3/WWt2nIlW2tm7l0i2RVm1+IsQzuWiIr2xZG7Gt99Pncw4NpCzwG+LDYn/xasy LBqjMZybWy8KRBQstdFpop4O71Z92v3/VoM2gYe0cXg8TLECmsvGYfAGL5NFEd/LjQ4m Kk5kWCo5FO9RpxxkK00yHP5v0B63IO2YDF705uUuRPsKMFD+rXHDvABToEoqvpBB2IxK YrNa2Uw9A4NFWTbUYYskWO6URlcVpK7sHCQu39ZVt6Pq9Oex5k9XPq+iyu1Jc8mR0KHI h1g+J/3PPdbC/HjxCNS+CneSpTBtcLcU69qUdyWu+b8X7F//AFlo+JTchaUQ7+81OciL Jc3Q== X-Gm-Message-State: AMke39ltGMKXwok8P7YN++MRKNJlD0VKFoTWOwUoBqtPYKsd3UamXYwCyOMVx53FK3epCDc2 X-Received: by 10.55.33.71 with SMTP id h68mr5740995qkh.287.1488199137169; Mon, 27 Feb 2017 04:38:57 -0800 (PST) Received: from localhost.localdomain (201-68-147-134.dsl.telesp.net.br. [201.68.147.134]) by smtp.gmail.com with ESMTPSA id 136sm10307106qkg.34.2017.02.27.04.38.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Feb 2017 04:38:56 -0800 (PST) From: Marcelo Henrique Cerri To: Herbert Xu Cc: "David S. Miller" , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Marcelo Henrique Cerri Subject: [PATCH v2 2/2] crypto: ctr - Propagate NEED_FALLBACK bit Date: Mon, 27 Feb 2017 09:38:26 -0300 Message-Id: <1488199106-16061-3-git-send-email-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488199106-16061-1-git-send-email-marcelo.cerri@canonical.com> References: <1488199106-16061-1-git-send-email-marcelo.cerri@canonical.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When requesting a fallback algorithm, we should propagate the NEED_FALLBACK bit when search for the underlying algorithm. This will prevents drivers from allocating unnecessary fallbacks that are never called. For instance, currently the vmx-crypto driver will use the following chain of calls when calling the fallback implementation: p8_aes_ctr -> ctr(p8_aes) -> aes-generic However p8_aes will always delegate its calls to aes-generic. With this patch, p8_aes_ctr will be able to use ctr(aes-generic) directly as its fallback. The same applies to aes_s390. Signed-off-by: Marcelo Henrique Cerri --- crypto/ctr.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/crypto/ctr.c b/crypto/ctr.c index a4f4a89..477d922 100644 --- a/crypto/ctr.c +++ b/crypto/ctr.c @@ -181,15 +181,24 @@ static void crypto_ctr_exit_tfm(struct crypto_tfm *tfm) static struct crypto_instance *crypto_ctr_alloc(struct rtattr **tb) { struct crypto_instance *inst; + struct crypto_attr_type *algt; struct crypto_alg *alg; + u32 mask; int err; err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_BLKCIPHER); if (err) return ERR_PTR(err); - alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_CIPHER, - CRYPTO_ALG_TYPE_MASK); + algt = crypto_get_attr_type(tb); + if (IS_ERR(algt)) + return ERR_CAST(algt); + + mask = CRYPTO_ALG_TYPE_MASK | + crypto_requires_off(algt->type, algt->mask, + CRYPTO_ALG_NEED_FALLBACK); + + alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_CIPHER, mask); if (IS_ERR(alg)) return ERR_CAST(alg); @@ -350,6 +359,8 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl, struct skcipher_alg *alg; struct crypto_skcipher_spawn *spawn; const char *cipher_name; + u32 mask; + int err; algt = crypto_get_attr_type(tb); @@ -367,12 +378,14 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl, if (!inst) return -ENOMEM; + mask = crypto_requires_sync(algt->type, algt->mask) | + crypto_requires_off(algt->type, algt->mask, + CRYPTO_ALG_NEED_FALLBACK); + spawn = skcipher_instance_ctx(inst); crypto_set_skcipher_spawn(spawn, skcipher_crypto_instance(inst)); - err = crypto_grab_skcipher(spawn, cipher_name, 0, - crypto_requires_sync(algt->type, - algt->mask)); + err = crypto_grab_skcipher(spawn, cipher_name, 0, mask); if (err) goto err_free_inst;