From patchwork Wed Jun 12 12:48:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 166551 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp3640692ilk; Wed, 12 Jun 2019 05:48:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqwDSmU3wG54L1PrrhqgHxrFzb24UlziKgwDjFqloyMVD/Cnp7x5DFtZClEmDgUVlYSD+RiS X-Received: by 2002:a63:91c4:: with SMTP id l187mr23469791pge.95.1560343736622; Wed, 12 Jun 2019 05:48:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560343736; cv=none; d=google.com; s=arc-20160816; b=JuI+7C4iL/6qYZUGct07nSkNUD0DcalUw+4bzYBTVLBElWPWq2/Wh8TRqSkkS7g/pv yIvPnEJCx7NiY+arbvcOnkGqlBuY0WkIa5o1FQyfrLmoK2ZhOyhBk/a2ainsOD3UsjJn 1JBWLn6+gQ6HhTnSKzQGULSzOS9Tlx9dZexME9tg6k3OMirYAPXXn8lWsUBa3OVzRo2z qMT6hl32Q66G92M4GuabuyfCvpUQBjCApnn0L94VqYAp7fORbWQTZLdtQwRHInNCKBvm 0WMO5qI5BWHXUgESI8siMid5PiXVDvC1Td1ekJiQuJJLFy36VZna0LaG++4zyuW21Ipa 7+5w== 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=kYNNbe+mFt8Q+RY9DxwwFbhQEO3KEw5kT4vc21gIvDg=; b=RYt8VU+rxX/YnCeKLhgy8yfs4uj3snnHgzJ7YWWIE35hWEzRsdgYX9dTPLK0kSv43+ zV45dfvLrOdRX/7KnhPxAHrujD7sfbu0eb+GSTKAMoBdytaJLuxONB04RwZcRZsfiMSN LQhOwyZx9kMNsksCCydA9/JSELTkVnadIyU5kFyxLPxZ+l8N/XkqlskA/gmUkK1BIVzR kVEaYavM93E+mhV3af9f48h8Bw6kvbvJ88nbGJuBztUpEtTyMRew+u9Cf/369IZ3xnaz JpcnqUwQgo12sZvaEnwEWwFQT7i6fLONlXLA4hU+1hKHLlTP9fCNdRli6RdqXg2PrfDk X+lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M+2h4fD4; 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 b14si16011497pgk.423.2019.06.12.05.48.56; Wed, 12 Jun 2019 05:48:56 -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=M+2h4fD4; 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 S2409160AbfFLMsz (ORCPT + 3 others); Wed, 12 Jun 2019 08:48:55 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:40633 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2409157AbfFLMsz (ORCPT ); Wed, 12 Jun 2019 08:48:55 -0400 Received: by mail-wm1-f67.google.com with SMTP id v19so6389255wmj.5 for ; Wed, 12 Jun 2019 05:48:53 -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=kYNNbe+mFt8Q+RY9DxwwFbhQEO3KEw5kT4vc21gIvDg=; b=M+2h4fD46HUC4cJ4KOuokanGoNSZ7xsT1Q+jGhMcs61l2SOksGa3I5dHZJ786fc1qX hwWLnCna9N+1lAxU3P9SSJn8TKRYJxcyR9J6luCq5uqa+ygm7ntsNvI+jDsfVTh4wuO7 zLE28BI+hzPxUPqD4vUvwEXFBseb3e31yDKoID1mSHjLQa3Tl8iQZQHALHnCA0AjKWgX SAgnb6jlklnhZemcReGewK60rQ1ilAj72SyvQVQ35FgVVKPpAV+BYMtkHEOLnVCkUw0w C3t3tpAJqsEyHzbbjEelLLw/QJ8s+1v8JuGhRkVHs7D2rYPWmbLqi5m8rcPZLpUPDtUo 3jTA== 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=kYNNbe+mFt8Q+RY9DxwwFbhQEO3KEw5kT4vc21gIvDg=; b=cdxOuqOeL9ETOjOaO0ZvATtonhw8PB0vud7+W5Z20sXcXbL1tGDoWejy3/rPAUwMo8 Q2jui4WHjGZjUlti5RFc8YkZ9+iU51VbsiYcWurE4AHgkxxy50UdFpU6pMgE1k7yCsOD rS6NoprcIjAN6h92P+zTY96C91y7DujfT7UDWTyaXPRPYTj7YGp27FilyM5GqfJrlA2p Yk/26SK1C5xrbKNr4xwP9ETpyXrZ9kT4Plm5HfIkNTG7PDIBo1aFPq5JsI+fxZshBXci y/4A0kzZwGpv82Y2zwkUmjJhDU6Q1aZ2fH0FZr4ygL2FOhDmp5WUNb/hMV5S6hO6Erx+ J3wA== X-Gm-Message-State: APjAAAV9FD5I1Wafj+GfuvowXtJcuNJ2rt1Z4t1NUufXG0s3elcAY5B1 civF4xp9MkQP+1cYSQlPJVuHfY8rEoRzrA== X-Received: by 2002:a05:600c:2243:: with SMTP id a3mr21220424wmm.83.1560343732621; Wed, 12 Jun 2019 05:48:52 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:353a:f33a:a393:3ada]) by smtp.gmail.com with ESMTPSA id s8sm28505480wra.55.2019.06.12.05.48.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jun 2019 05:48:52 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, ebiggers@kernel.org, Ard Biesheuvel Subject: [RFC PATCH 05/20] crypto: x86/aes-ni - switch to generic for fallback and key routines Date: Wed, 12 Jun 2019 14:48:23 +0200 Message-Id: <20190612124838.2492-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190612124838.2492-1-ard.biesheuvel@linaro.org> References: <20190612124838.2492-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 e9b866e87d48..9952bd312ddc 100644 --- a/arch/x86/crypto/aesni-intel_glue.c +++ b/arch/x86/crypto/aesni-intel_glue.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -329,7 +328,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); @@ -349,9 +348,9 @@ static void aes_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(); @@ -362,9 +361,9 @@ static void aes_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 dc6f93ef3ead..0d80985016bf 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -1149,8 +1149,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