From: Maxim Levitsky <mlevitsk@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)),
linux-crypto@vger.kernel.org (open list:CRYPTO API),
Dave Hansen <dave.hansen@linux.intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
Herbert Xu <herbert@gondor.apana.org.au>,
Borislav Petkov <bp@alien8.de>,
Paolo Bonzini <pbonzini@redhat.com>,
Ingo Molnar <mingo@redhat.com>,
"David S. Miller" <davem@davemloft.net>,
"H. Peter Anvin" <hpa@zytor.com>,
Tim Chen <tim.c.chen@linux.intel.com>,
Maxim Levitsky <mlevitsk@redhat.com>
Subject: [PATCH] crypto: x86/aes-ni: fix AVX detection
Date: Wed, 3 Nov 2021 14:46:14 +0200 [thread overview]
Message-ID: <20211103124614.499580-1-mlevitsk@redhat.com> (raw)
Fix two semi-theoretical issues that are present.
1. AVX is assumed to be present when AVX2 is present.
That can be false in a VM.
This can be considered a hypervisor bug,
but the kernel should not crash in this case if this is possible.
2. YMM state can be soft disabled in XCR0.
Fix both issues by using 'cpu_has_xfeatures(XFEATURE_MASK_YMM')
to check for usable AVX support.
Fixes: d764593af9249 ("crypto: aesni - AVX and AVX2 version of AESNI-GCM encode and decode")
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
---
arch/x86/crypto/aesni-intel_glue.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/arch/x86/crypto/aesni-intel_glue.c b/arch/x86/crypto/aesni-intel_glue.c
index 0fc961bef299c..20db1e500ef6f 100644
--- a/arch/x86/crypto/aesni-intel_glue.c
+++ b/arch/x86/crypto/aesni-intel_glue.c
@@ -1147,24 +1147,25 @@ static int __init aesni_init(void)
if (!x86_match_cpu(aesni_cpu_id))
return -ENODEV;
#ifdef CONFIG_X86_64
- if (boot_cpu_has(X86_FEATURE_AVX2)) {
- pr_info("AVX2 version of gcm_enc/dec engaged.\n");
- static_branch_enable(&gcm_use_avx);
- static_branch_enable(&gcm_use_avx2);
- } else
- if (boot_cpu_has(X86_FEATURE_AVX)) {
- pr_info("AVX version of gcm_enc/dec engaged.\n");
+ if (cpu_has_xfeatures(XFEATURE_MASK_YMM, NULL)) {
+
static_branch_enable(&gcm_use_avx);
- } else {
- pr_info("SSE version of gcm_enc/dec engaged.\n");
- }
- if (boot_cpu_has(X86_FEATURE_AVX)) {
+
+ if (boot_cpu_has(X86_FEATURE_AVX2)) {
+ static_branch_enable(&gcm_use_avx2);
+ pr_info("AVX2 version of gcm_enc/dec engaged.\n");
+ } else {
+ pr_info("AVX version of gcm_enc/dec engaged.\n");
+ }
+
/* optimize performance of ctr mode encryption transform */
static_call_update(aesni_ctr_enc_tfm, aesni_ctr_enc_avx_tfm);
pr_info("AES CTR mode by8 optimization enabled\n");
+
+ } else {
+ pr_info("SSE version of gcm_enc/dec engaged.\n");
}
#endif
-
err = crypto_register_alg(&aesni_cipher_alg);
if (err)
return err;
--
2.26.3
next reply other threads:[~2021-11-03 12:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-03 12:46 Maxim Levitsky [this message]
2021-11-03 12:49 ` [PATCH] crypto: x86/aes-ni: fix AVX detection Maxim Levitsky
2021-11-03 14:43 ` Dave Hansen
2021-11-03 14:52 ` Herbert Xu
2021-11-04 10:00 ` Paolo Bonzini
2022-06-08 11:29 ` Maxim Levitsky
2022-06-08 14:00 ` Dave Hansen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211103124614.499580-1-mlevitsk@redhat.com \
--to=mlevitsk@redhat.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=hpa@zytor.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=tglx@linutronix.de \
--cc=tim.c.chen@linux.intel.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox