From patchwork Sat Jun 22 19:34:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 167488 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2255866ilk; Sat, 22 Jun 2019 12:34:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqxNESAsMVORXmcMwXIXSdxJYV6Ku4mH++fQWzn+yKi7QoiZvBN2yDf/UTpqos0qsQDsXRwC X-Received: by 2002:a17:90a:710c:: with SMTP id h12mr14381220pjk.36.1561232089029; Sat, 22 Jun 2019 12:34:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561232089; cv=none; d=google.com; s=arc-20160816; b=Ul4jS4/k2YjvqUCPQIb3O3dOqKxfz0tI+XCUa3r12r8ASgdnjrhAoLZ57HmplzzJfX 8UVs3iDY2GT6CmqYqNnmkKemjkX2OzhaRRnMDNBDGjtuauPH0z/EeeIXCJNyZgg/ox02 JqJpvkA9U0TTcUWBwKFabYqepgo5TL8BeNQR08qOQJhanR9zFLE87Jg7EF47ZzJcvGhO gTP/nBfmtRLPEZghBuPjgGdOKNNhdcNibi8AQLBFysn3VnMqa5HfKkZQ1yxpnl/U+SMc zTf1AsTK/5vU7JKi7W1EModJJ2pTe06h2gk35897M1yuGd0Oc/Jsa4BMTU2t47wonwbv KJoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5Oqvcot1yZKpSWtboJ7OjflLCxxMos1RB3yPJW9XMLo=; b=XdLltKD9leyXwdIG9aa4iRjReDw4IykJkP7Cl6EdIv7m33IU8UB2TcQJC+61C15Oz4 neT76xtSctqbKMsWu71QZd7nVTl25XGEV6koMQghaLXZw7LJYZs96sej4XRO4HlnXkmH prRPGrip0HNQiuU1Hp87DnUFj06wmBV6XBS/tGj9CWpv7uQp7/oWDgfNqgBU8J12eFrR qcAF4RTZd07noCIRGiwk0o84I7zjOGNvmIsHxdYyNQc0S4WoqnwuaOTuanpISHoHBXw8 ny3wA0Z7kCRjT4HqnHNHhq/AW9IMoV6L2ncGVhOwswUPfYOABE8g+zi4SgMFrsPSTxJP OnIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pTL9q9uQ; 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 l21si5511699pgb.409.2019.06.22.12.34.48; Sat, 22 Jun 2019 12:34:49 -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.s=google header.b=pTL9q9uQ; 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 S1726342AbfFVTes (ORCPT + 3 others); Sat, 22 Jun 2019 15:34:48 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:33739 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726338AbfFVTes (ORCPT ); Sat, 22 Jun 2019 15:34:48 -0400 Received: by mail-wm1-f65.google.com with SMTP id h19so11351617wme.0 for ; Sat, 22 Jun 2019 12:34:46 -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 :mime-version:content-transfer-encoding; bh=5Oqvcot1yZKpSWtboJ7OjflLCxxMos1RB3yPJW9XMLo=; b=pTL9q9uQWGDoEDBmSirmxQxs1RKz+z9+olTB1MNYmmYhAR764ygt7Hfbtnioif+CTO wbpdJch9/BLv6CLdXAg7flE9434mH9Si1UpokHFmutWE7sZ2xRyR15dfKjAEBBG5IRWR ub+6GhcU0dvQO2QvblFqove/vzIFBt823QaWQ9Hk/XJx6f1YcX2p3KRZzCOMtCBcKgM6 f8raGMHokHvX67dn6ftXUPtZ8DBSUr4+nzMIoM/yOttOn3qOgCi2MGHVQWNoMl0Dn4f8 5UXcrpfNwCOrQrOkJEbcMlb86292qtKz1/sgxoaOyA+RNJh2FmkP8bBu0EzonvtQWu24 NtcA== 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:mime-version:content-transfer-encoding; bh=5Oqvcot1yZKpSWtboJ7OjflLCxxMos1RB3yPJW9XMLo=; b=TWTd6FtugXmuBlaqC+3i559EELuPu/App1Ip0h2hcIqfuOY/ZVSGlQv1UA9+aXbznB 2XK2WZcr3tb4Xps5vS06DXxJrY6rduUlpzoct97rn12H5MRuagwvYPdlvGTVb2sgCnHv h2MfPS4ql2xvCKukhnwVQgo5ay6D1KoxNNwzJnrbQGrhf2q3j3Uv8m3JyubGEAEtTFks ZGFDjDxO4vquuAGZzhiCuS9CsSQIpma8qCLBG6UhFlbl4VMcTTXnhGxeCuEDDT5yhEH0 p5czKK/LSA4fJnaReGTY+j4Db1qgIrde8ouuUUemrlaAD57xv8ghkG7+Yf0u96Jw3cQe mJFw== X-Gm-Message-State: APjAAAX5g1qeCH4NVclN2yYlDHA3OFNVyuSoA7U09Sudbjow5edQ9gAD Aa85eABA0HU6Bh3+ImDicHpO11zGxj+4Hzpy X-Received: by 2002:a05:600c:20d:: with SMTP id 13mr8680233wmi.141.1561232085469; Sat, 22 Jun 2019 12:34:45 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:4bd:3f91:4ef8:ae7e]) by smtp.gmail.com with ESMTPSA id h8sm4814494wmf.12.2019.06.22.12.34.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Jun 2019 12:34:44 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, ebiggers@google.com, Ard Biesheuvel Subject: [PATCH v2 05/26] crypto: x86/aes-ni - switch to generic for fallback and key routines Date: Sat, 22 Jun 2019 21:34:06 +0200 Message-Id: <20190622193427.20336-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190622193427.20336-1-ard.biesheuvel@linaro.org> References: <20190622193427.20336-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The AES-NI code contains fallbacks for invocations that occur from a context where the SIMD unit is unavailable, which really only occurs when running in softirq context that was entered from a hard IRQ that was taken while running kernel code that was already using the FPU. That means performance is not really a consideration, and we can just use the new library code for this use case, which has a smaller footprint and is believed to be time invariant. This will allow us to drop the non-SIMD asm routines in a subsequent patch. Signed-off-by: Ard Biesheuvel --- arch/x86/crypto/aesni-intel_glue.c | 15 +++++++-------- arch/x86/include/asm/crypto/aes.h | 12 ------------ crypto/Kconfig | 3 +-- 3 files changed, 8 insertions(+), 22 deletions(-) -- 2.20.1 diff --git a/arch/x86/crypto/aesni-intel_glue.c b/arch/x86/crypto/aesni-intel_glue.c index 836d50bd096f..42873c1f6bb4 100644 --- a/arch/x86/crypto/aesni-intel_glue.c +++ b/arch/x86/crypto/aesni-intel_glue.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -333,7 +332,7 @@ static int aes_set_key_common(struct crypto_tfm *tfm, void *raw_ctx, } if (!crypto_simd_usable()) - err = crypto_aes_expand_key(ctx, in_key, key_len); + err = aes_expandkey(ctx, in_key, key_len); else { kernel_fpu_begin(); err = aesni_set_key(ctx, in_key, key_len); @@ -353,9 +352,9 @@ static void aesni_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) { struct crypto_aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(tfm)); - if (!crypto_simd_usable()) - crypto_aes_encrypt_x86(ctx, dst, src); - else { + if (!crypto_simd_usable()) { + aes_encrypt(ctx, dst, src); + } else { kernel_fpu_begin(); aesni_enc(ctx, dst, src); kernel_fpu_end(); @@ -366,9 +365,9 @@ static void aesni_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) { struct crypto_aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(tfm)); - if (!crypto_simd_usable()) - crypto_aes_decrypt_x86(ctx, dst, src); - else { + if (!crypto_simd_usable()) { + aes_decrypt(ctx, dst, src); + } else { kernel_fpu_begin(); aesni_dec(ctx, dst, src); kernel_fpu_end(); diff --git a/arch/x86/include/asm/crypto/aes.h b/arch/x86/include/asm/crypto/aes.h deleted file mode 100644 index c508521dd190..000000000000 --- a/arch/x86/include/asm/crypto/aes.h +++ /dev/null @@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef ASM_X86_AES_H -#define ASM_X86_AES_H - -#include -#include - -void crypto_aes_encrypt_x86(struct crypto_aes_ctx *ctx, u8 *dst, - const u8 *src); -void crypto_aes_decrypt_x86(struct crypto_aes_ctx *ctx, u8 *dst, - const u8 *src); -#endif diff --git a/crypto/Kconfig b/crypto/Kconfig index 091ebbbc9655..20af58068e6b 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -1156,8 +1156,7 @@ config CRYPTO_AES_NI_INTEL tristate "AES cipher algorithms (AES-NI)" depends on X86 select CRYPTO_AEAD - select CRYPTO_AES_X86_64 if 64BIT - select CRYPTO_AES_586 if !64BIT + select CRYPTO_LIB_AES select CRYPTO_ALGAPI select CRYPTO_BLKCIPHER select CRYPTO_GLUE_HELPER_X86 if 64BIT