mirror of
https://github.com/torvalds/linux.git
synced 2024-11-22 04:02:20 +00:00
148b974dee
While testing other changes, I discovered that gcc-7.2.1 produces badly optimized code for aes_encrypt/aes_decrypt. This is especially true when CONFIG_UBSAN_SANITIZE_ALL is enabled, where it leads to extremely large stack usage that in turn might cause kernel stack overflows: crypto/aes_generic.c: In function 'aes_encrypt': crypto/aes_generic.c:1371:1: warning: the frame size of 4880 bytes is larger than 2048 bytes [-Wframe-larger-than=] crypto/aes_generic.c: In function 'aes_decrypt': crypto/aes_generic.c:1441:1: warning: the frame size of 4864 bytes is larger than 2048 bytes [-Wframe-larger-than=] I verified that this problem exists on all architectures that are supported by gcc-7.2, though arm64 in particular is less affected than the others. I also found that gcc-7.1 and gcc-8 do not show the extreme stack usage but still produce worse code than earlier versions for this file, apparently because of optimization passes that generally provide a substantial improvement in object code quality but understandably fail to find any shortcuts in the AES algorithm. Possible workarounds include a) disabling -ftree-pre and -ftree-sra optimizations, this was an earlier patch I tried, which reliably fixed the stack usage, but caused a serious performance regression in some versions, as later testing found. b) disabling UBSAN on this file or all ciphers, as suggested by Ard Biesheuvel. This would lead to massively better crypto performance in UBSAN-enabled kernels and avoid the stack usage, but there is a concern over whether we should exclude arbitrary files from UBSAN at all. c) Forcing the optimization level in a different way. Similar to a), but rather than deselecting specific optimization stages, this now uses "gcc -Os" for this file, regardless of the CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE/SIZE option. This is a reliable workaround for the stack consumption on all architecture, and I've retested the performance results now on x86, cycles/byte (lower is better) for cbc(aes-generic) with 256 bit keys: -O2 -Os gcc-6.3.1 14.9 15.1 gcc-7.0.1 14.7 15.3 gcc-7.1.1 15.3 14.7 gcc-7.2.1 16.8 15.9 gcc-8.0.0 15.5 15.6 This implements the option c) by enabling forcing -Os on all compiler versions starting with gcc-7.1. As a workaround for PR83356, it would only be needed for gcc-7.2+ with UBSAN enabled, but since it also shows better performance on gcc-7.1 without UBSAN, it seems appropriate to use the faster version here as well. Side note: during testing, I also played with the AES code in libressl, which had a similar performance regression from gcc-6 to gcc-7.2, but was three times slower overall. It might be interesting to investigate that further and possibly port the Linux implementation into that. Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83356 Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83651 Cc: Richard Biener <rguenther@suse.de> Cc: Jakub Jelinek <jakub@gcc.gnu.org> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
155 lines
5.7 KiB
Makefile
155 lines
5.7 KiB
Makefile
# SPDX-License-Identifier: GPL-2.0
|
|
#
|
|
# Cryptographic API
|
|
#
|
|
|
|
obj-$(CONFIG_CRYPTO) += crypto.o
|
|
crypto-y := api.o cipher.o compress.o memneq.o
|
|
|
|
obj-$(CONFIG_CRYPTO_WORKQUEUE) += crypto_wq.o
|
|
|
|
obj-$(CONFIG_CRYPTO_ENGINE) += crypto_engine.o
|
|
obj-$(CONFIG_CRYPTO_FIPS) += fips.o
|
|
|
|
crypto_algapi-$(CONFIG_PROC_FS) += proc.o
|
|
crypto_algapi-y := algapi.o scatterwalk.o $(crypto_algapi-y)
|
|
obj-$(CONFIG_CRYPTO_ALGAPI2) += crypto_algapi.o
|
|
|
|
obj-$(CONFIG_CRYPTO_AEAD2) += aead.o
|
|
|
|
crypto_blkcipher-y := ablkcipher.o
|
|
crypto_blkcipher-y += blkcipher.o
|
|
crypto_blkcipher-y += skcipher.o
|
|
obj-$(CONFIG_CRYPTO_BLKCIPHER2) += crypto_blkcipher.o
|
|
obj-$(CONFIG_CRYPTO_SEQIV) += seqiv.o
|
|
obj-$(CONFIG_CRYPTO_ECHAINIV) += echainiv.o
|
|
|
|
crypto_hash-y += ahash.o
|
|
crypto_hash-y += shash.o
|
|
obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o
|
|
|
|
obj-$(CONFIG_CRYPTO_AKCIPHER2) += akcipher.o
|
|
obj-$(CONFIG_CRYPTO_KPP2) += kpp.o
|
|
|
|
dh_generic-y := dh.o
|
|
dh_generic-y += dh_helper.o
|
|
obj-$(CONFIG_CRYPTO_DH) += dh_generic.o
|
|
|
|
$(obj)/rsapubkey-asn1.o: $(obj)/rsapubkey-asn1.c $(obj)/rsapubkey-asn1.h
|
|
$(obj)/rsaprivkey-asn1.o: $(obj)/rsaprivkey-asn1.c $(obj)/rsaprivkey-asn1.h
|
|
$(obj)/rsa_helper.o: $(obj)/rsapubkey-asn1.h $(obj)/rsaprivkey-asn1.h
|
|
clean-files += rsapubkey-asn1.c rsapubkey-asn1.h
|
|
clean-files += rsaprivkey-asn1.c rsaprivkey-asn1.h
|
|
|
|
rsa_generic-y := rsapubkey-asn1.o
|
|
rsa_generic-y += rsaprivkey-asn1.o
|
|
rsa_generic-y += rsa.o
|
|
rsa_generic-y += rsa_helper.o
|
|
rsa_generic-y += rsa-pkcs1pad.o
|
|
obj-$(CONFIG_CRYPTO_RSA) += rsa_generic.o
|
|
|
|
crypto_acompress-y := acompress.o
|
|
crypto_acompress-y += scompress.o
|
|
obj-$(CONFIG_CRYPTO_ACOMP2) += crypto_acompress.o
|
|
|
|
cryptomgr-y := algboss.o testmgr.o
|
|
|
|
obj-$(CONFIG_CRYPTO_MANAGER2) += cryptomgr.o
|
|
obj-$(CONFIG_CRYPTO_USER) += crypto_user.o
|
|
obj-$(CONFIG_CRYPTO_CMAC) += cmac.o
|
|
obj-$(CONFIG_CRYPTO_HMAC) += hmac.o
|
|
obj-$(CONFIG_CRYPTO_VMAC) += vmac.o
|
|
obj-$(CONFIG_CRYPTO_XCBC) += xcbc.o
|
|
obj-$(CONFIG_CRYPTO_NULL2) += crypto_null.o
|
|
obj-$(CONFIG_CRYPTO_MD4) += md4.o
|
|
obj-$(CONFIG_CRYPTO_MD5) += md5.o
|
|
obj-$(CONFIG_CRYPTO_RMD128) += rmd128.o
|
|
obj-$(CONFIG_CRYPTO_RMD160) += rmd160.o
|
|
obj-$(CONFIG_CRYPTO_RMD256) += rmd256.o
|
|
obj-$(CONFIG_CRYPTO_RMD320) += rmd320.o
|
|
obj-$(CONFIG_CRYPTO_SHA1) += sha1_generic.o
|
|
obj-$(CONFIG_CRYPTO_SHA256) += sha256_generic.o
|
|
obj-$(CONFIG_CRYPTO_SHA512) += sha512_generic.o
|
|
obj-$(CONFIG_CRYPTO_SHA3) += sha3_generic.o
|
|
obj-$(CONFIG_CRYPTO_SM3) += sm3_generic.o
|
|
obj-$(CONFIG_CRYPTO_WP512) += wp512.o
|
|
CFLAGS_wp512.o := $(call cc-option,-fno-schedule-insns) # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79149
|
|
obj-$(CONFIG_CRYPTO_TGR192) += tgr192.o
|
|
obj-$(CONFIG_CRYPTO_GF128MUL) += gf128mul.o
|
|
obj-$(CONFIG_CRYPTO_ECB) += ecb.o
|
|
obj-$(CONFIG_CRYPTO_CBC) += cbc.o
|
|
obj-$(CONFIG_CRYPTO_PCBC) += pcbc.o
|
|
obj-$(CONFIG_CRYPTO_CTS) += cts.o
|
|
obj-$(CONFIG_CRYPTO_LRW) += lrw.o
|
|
obj-$(CONFIG_CRYPTO_XTS) += xts.o
|
|
obj-$(CONFIG_CRYPTO_CTR) += ctr.o
|
|
obj-$(CONFIG_CRYPTO_KEYWRAP) += keywrap.o
|
|
obj-$(CONFIG_CRYPTO_GCM) += gcm.o
|
|
obj-$(CONFIG_CRYPTO_CCM) += ccm.o
|
|
obj-$(CONFIG_CRYPTO_CHACHA20POLY1305) += chacha20poly1305.o
|
|
obj-$(CONFIG_CRYPTO_PCRYPT) += pcrypt.o
|
|
obj-$(CONFIG_CRYPTO_CRYPTD) += cryptd.o
|
|
obj-$(CONFIG_CRYPTO_MCRYPTD) += mcryptd.o
|
|
obj-$(CONFIG_CRYPTO_DES) += des_generic.o
|
|
obj-$(CONFIG_CRYPTO_FCRYPT) += fcrypt.o
|
|
obj-$(CONFIG_CRYPTO_BLOWFISH) += blowfish_generic.o
|
|
obj-$(CONFIG_CRYPTO_BLOWFISH_COMMON) += blowfish_common.o
|
|
obj-$(CONFIG_CRYPTO_TWOFISH) += twofish_generic.o
|
|
obj-$(CONFIG_CRYPTO_TWOFISH_COMMON) += twofish_common.o
|
|
obj-$(CONFIG_CRYPTO_SERPENT) += serpent_generic.o
|
|
CFLAGS_serpent_generic.o := $(call cc-option,-fsched-pressure) # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79149
|
|
obj-$(CONFIG_CRYPTO_AES) += aes_generic.o
|
|
CFLAGS_aes_generic.o := $(call cc-ifversion, -ge, 0701, -Os) # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83356
|
|
obj-$(CONFIG_CRYPTO_AES_TI) += aes_ti.o
|
|
obj-$(CONFIG_CRYPTO_CAMELLIA) += camellia_generic.o
|
|
obj-$(CONFIG_CRYPTO_CAST_COMMON) += cast_common.o
|
|
obj-$(CONFIG_CRYPTO_CAST5) += cast5_generic.o
|
|
obj-$(CONFIG_CRYPTO_CAST6) += cast6_generic.o
|
|
obj-$(CONFIG_CRYPTO_ARC4) += arc4.o
|
|
obj-$(CONFIG_CRYPTO_TEA) += tea.o
|
|
obj-$(CONFIG_CRYPTO_KHAZAD) += khazad.o
|
|
obj-$(CONFIG_CRYPTO_ANUBIS) += anubis.o
|
|
obj-$(CONFIG_CRYPTO_SEED) += seed.o
|
|
obj-$(CONFIG_CRYPTO_SALSA20) += salsa20_generic.o
|
|
obj-$(CONFIG_CRYPTO_CHACHA20) += chacha20_generic.o
|
|
obj-$(CONFIG_CRYPTO_POLY1305) += poly1305_generic.o
|
|
obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o
|
|
obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o
|
|
obj-$(CONFIG_CRYPTO_CRC32C) += crc32c_generic.o
|
|
obj-$(CONFIG_CRYPTO_CRC32) += crc32_generic.o
|
|
obj-$(CONFIG_CRYPTO_CRCT10DIF) += crct10dif_common.o crct10dif_generic.o
|
|
obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o authencesn.o
|
|
obj-$(CONFIG_CRYPTO_LZO) += lzo.o
|
|
obj-$(CONFIG_CRYPTO_LZ4) += lz4.o
|
|
obj-$(CONFIG_CRYPTO_LZ4HC) += lz4hc.o
|
|
obj-$(CONFIG_CRYPTO_842) += 842.o
|
|
obj-$(CONFIG_CRYPTO_RNG2) += rng.o
|
|
obj-$(CONFIG_CRYPTO_ANSI_CPRNG) += ansi_cprng.o
|
|
obj-$(CONFIG_CRYPTO_DRBG) += drbg.o
|
|
obj-$(CONFIG_CRYPTO_JITTERENTROPY) += jitterentropy_rng.o
|
|
CFLAGS_jitterentropy.o = -O0
|
|
jitterentropy_rng-y := jitterentropy.o jitterentropy-kcapi.o
|
|
obj-$(CONFIG_CRYPTO_TEST) += tcrypt.o
|
|
obj-$(CONFIG_CRYPTO_GHASH) += ghash-generic.o
|
|
obj-$(CONFIG_CRYPTO_USER_API) += af_alg.o
|
|
obj-$(CONFIG_CRYPTO_USER_API_HASH) += algif_hash.o
|
|
obj-$(CONFIG_CRYPTO_USER_API_SKCIPHER) += algif_skcipher.o
|
|
obj-$(CONFIG_CRYPTO_USER_API_RNG) += algif_rng.o
|
|
obj-$(CONFIG_CRYPTO_USER_API_AEAD) += algif_aead.o
|
|
|
|
ecdh_generic-y := ecc.o
|
|
ecdh_generic-y += ecdh.o
|
|
ecdh_generic-y += ecdh_helper.o
|
|
obj-$(CONFIG_CRYPTO_ECDH) += ecdh_generic.o
|
|
|
|
#
|
|
# generic algorithms and the async_tx api
|
|
#
|
|
obj-$(CONFIG_XOR_BLOCKS) += xor.o
|
|
obj-$(CONFIG_ASYNC_CORE) += async_tx/
|
|
obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += asymmetric_keys/
|
|
obj-$(CONFIG_CRYPTO_HASH_INFO) += hash_info.o
|
|
obj-$(CONFIG_CRYPTO_ABLK_HELPER) += ablk_helper.o
|
|
crypto_simd-y := simd.o
|
|
obj-$(CONFIG_CRYPTO_SIMD) += crypto_simd.o
|