From patchwork Mon Feb 27 01:03:18 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: 9592583 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 905EB60471 for ; Mon, 27 Feb 2017 01:03:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8289C283F6 for ; Mon, 27 Feb 2017 01:03:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7730A283FD; Mon, 27 Feb 2017 01:03:49 +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=ham 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 EE3D1283F6 for ; Mon, 27 Feb 2017 01:03:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751117AbdB0BDs (ORCPT ); Sun, 26 Feb 2017 20:03:48 -0500 Received: from mail-qk0-f180.google.com ([209.85.220.180]:36240 "EHLO mail-qk0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751284AbdB0BDr (ORCPT ); Sun, 26 Feb 2017 20:03:47 -0500 Received: by mail-qk0-f180.google.com with SMTP id n186so445834qkb.3 for ; Sun, 26 Feb 2017 17:03:46 -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=h/8yjrV/JbbK/X36nlN11HokX4lUCgFAWbzQ9PbsJDE=; b=zIqR0eRjMzem11KRs3wi3iTemMZ+7fGXAyoQrHgUWqis3XgkgwQEjReIHwUBukHlFq cB8QNP0ygxOCIj5m/G7Ve2K9nxsGrreGy9MqtrMVLpH/Wbt7jdYWVv7CAy20TcjWRDWk ssV9YRT4s096kw0vSIe83go0EjTK/UEO7VgXoTQb4Pewf0tbppDDWrvDRFAGRotKQ6/f /TThjjrnjHo7c+LmbRdx9Y7b5yfRofAYJg/BPx8XnT7VjSWYh9Uuk13PqhS/uq2elrdK RshQ5bUEZYvsBi+qvsxtePVEuM2qr2MyuEkfNQmOEsOoN7JgUquAjC9KgenqbILxG2rv c3xA== 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=h/8yjrV/JbbK/X36nlN11HokX4lUCgFAWbzQ9PbsJDE=; b=dnfiHJDZCmwVN9qO5in4lIrhl/DsmeZdjPkOCRO9yq2g200fEkguWxK76tWNbGssCl CKa3mLkNQxc6E7wYHogv2xfei6E8CTHLKw2ylHU6LkcTC/+v7m8vTM19CHex9oBuYeCl vKqEFWFlq7E4cX/b7sfoMTMNmB6kV+gyPJSdilnUj0ptv763Q9Qhm9p62LnLn0j619Ab M7gRK0Rl8fhP6m5tcJv3qaMMz/1nuO2enq6pJeww/rS1XheB+kfUh29NjkbLY1MDaYhp tq52nmtONh08fI/SAfAsPOktQaD8Vvofob4Maz2OiyJJfAbytP/cigfNBUCrrY2YNarj o4Jg== X-Gm-Message-State: AMke39miVfAaG0QeeOjc62IquGtVcuGKp/Y5J4JE47oEEXiYNcQ9gK+DjjtEne4/kDmgkobk X-Received: by 10.200.57.106 with SMTP id t39mr14219634qtb.20.1488157426338; Sun, 26 Feb 2017 17:03:46 -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 x125sm9503495qkd.17.2017.02.26.17.03.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 26 Feb 2017 17:03:45 -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 1/2] crypto: cbc - Propagate NEED_FALLBACK bit Date: Sun, 26 Feb 2017 22:03:18 -0300 Message-Id: <1488157399-3587-2-git-send-email-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488157399-3587-1-git-send-email-marcelo.cerri@canonical.com> References: <1488157399-3587-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_cbc -> cbc(p8_aes) -> aes-generic However p8_aes will always delegate its calls to aes-generic. With this patch, p8_aes_cbc will be able to use cbc(aes-generic) directly as its fallback. The same applies to aes_s390. Signed-off-by: Marcelo Henrique Cerri --- crypto/cbc.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/crypto/cbc.c b/crypto/cbc.c index bc160a3..7147842 100644 --- a/crypto/cbc.c +++ b/crypto/cbc.c @@ -108,24 +108,32 @@ static void crypto_cbc_free(struct skcipher_instance *inst) static int crypto_cbc_create(struct crypto_template *tmpl, struct rtattr **tb) { struct skcipher_instance *inst; + struct crypto_attr_type *algt; struct crypto_spawn *spawn; struct crypto_alg *alg; + u32 mask; int err; err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SKCIPHER); if (err) return err; + algt = crypto_get_attr_type(tb); + if (IS_ERR(algt)) + return PTR_ERR(algt); + + mask = CRYPTO_ALG_TYPE_MASK | + crypto_requires_off(algt->type, algt->mask, + CRYPTO_ALG_NEED_FALLBACK); + + alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER, mask); + if (IS_ERR(alg)) + return PTR_ERR(alg); + inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); if (!inst) return -ENOMEM; - alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER, - CRYPTO_ALG_TYPE_MASK); - err = PTR_ERR(alg); - if (IS_ERR(alg)) - goto err_free_inst; - spawn = skcipher_instance_ctx(inst); err = crypto_init_spawn(spawn, alg, skcipher_crypto_instance(inst), CRYPTO_ALG_TYPE_MASK);