]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit - arch/x86/crypto/aesni-intel_asm.S
crypto: x86 - make constants readonly, allow linker to merge them
authorDenys Vlasenko <dvlasenk@redhat.com>
Thu, 19 Jan 2017 21:33:04 +0000 (22:33 +0100)
committerHerbert Xu <herbert@gondor.apana.org.au>
Mon, 23 Jan 2017 14:50:29 +0000 (22:50 +0800)
commite183914af00e15eb41ae666d44e323bfa154be13
tree177ded54a5bd45ec1ae6c544d28b0a45a31118f1
parent587d531b8f67ebe62f8326849a7a685a03cbc904
crypto: x86 - make constants readonly, allow linker to merge them

A lot of asm-optimized routines in arch/x86/crypto/ keep its
constants in .data. This is wrong, they should be on .rodata.

Mnay of these constants are the same in different modules.
For example, 128-bit shuffle mask 0x000102030405060708090A0B0C0D0E0F
exists in at least half a dozen places.

There is a way to let linker merge them and use just one copy.
The rules are as follows: mergeable objects of different sizes
should not share sections. You can't put them all in one .rodata
section, they will lose "mergeability".

GCC puts its mergeable constants in ".rodata.cstSIZE" sections,
or ".rodata.cstSIZE.<object_name>" if -fdata-sections is used.
This patch does the same:

.section .rodata.cst16.SHUF_MASK, "aM", @progbits, 16

It is important that all data in such section consists of
16-byte elements, not larger ones, and there are no implicit
use of one element from another.

When this is not the case, use non-mergeable section:

.section .rodata[.VAR_NAME], "a", @progbits

This reduces .data by ~15 kbytes:

    text    data     bss     dec      hex filename
11097415 2705840 2630712 16433967  fac32f vmlinux-prev.o
11112095 2690672 2630712 16433479  fac147 vmlinux.o

Merged objects are visible in System.map:

ffffffff81a28810 r POLY
ffffffff81a28810 r POLY
ffffffff81a28820 r TWOONE
ffffffff81a28820 r TWOONE
ffffffff81a28830 r PSHUFFLE_BYTE_FLIP_MASK <- merged regardless of
ffffffff81a28830 r SHUF_MASK   <------------- the name difference
ffffffff81a28830 r SHUF_MASK
ffffffff81a28830 r SHUF_MASK
..
ffffffff81a28d00 r K512 <- merged three identical 640-byte tables
ffffffff81a28d00 r K512
ffffffff81a28d00 r K512

Use of object names in section name suffixes is not strictly necessary,
but might help if someday link stage will use garbage collection
to eliminate unused sections (ld --gc-sections).

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
CC: Herbert Xu <herbert@gondor.apana.org.au>
CC: Josh Poimboeuf <jpoimboe@redhat.com>
CC: Xiaodong Liu <xiaodong.liu@intel.com>
CC: Megha Dey <megha.dey@intel.com>
CC: linux-crypto@vger.kernel.org
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
33 files changed:
arch/x86/crypto/aesni-intel_asm.S
arch/x86/crypto/aesni-intel_avx-x86_64.S
arch/x86/crypto/camellia-aesni-avx-asm_64.S
arch/x86/crypto/camellia-aesni-avx2-asm_64.S
arch/x86/crypto/cast5-avx-x86_64-asm_64.S
arch/x86/crypto/cast6-avx-x86_64-asm_64.S
arch/x86/crypto/chacha20-avx2-x86_64.S
arch/x86/crypto/chacha20-ssse3-x86_64.S
arch/x86/crypto/crct10dif-pcl-asm_64.S
arch/x86/crypto/des3_ede-asm_64.S
arch/x86/crypto/ghash-clmulni-intel_asm.S
arch/x86/crypto/poly1305-avx2-x86_64.S
arch/x86/crypto/poly1305-sse2-x86_64.S
arch/x86/crypto/serpent-avx-x86_64-asm_64.S
arch/x86/crypto/serpent-avx2-asm_64.S
arch/x86/crypto/sha1-mb/sha1_mb_mgr_flush_avx2.S
arch/x86/crypto/sha1-mb/sha1_mb_mgr_submit_avx2.S
arch/x86/crypto/sha1-mb/sha1_x8_avx2.S
arch/x86/crypto/sha1_ni_asm.S
arch/x86/crypto/sha256-avx-asm.S
arch/x86/crypto/sha256-avx2-asm.S
arch/x86/crypto/sha256-mb/sha256_mb_mgr_flush_avx2.S
arch/x86/crypto/sha256-mb/sha256_mb_mgr_submit_avx2.S
arch/x86/crypto/sha256-mb/sha256_x8_avx2.S
arch/x86/crypto/sha256-ssse3-asm.S
arch/x86/crypto/sha256_ni_asm.S
arch/x86/crypto/sha512-avx-asm.S
arch/x86/crypto/sha512-avx2-asm.S
arch/x86/crypto/sha512-mb/sha512_mb_mgr_flush_avx2.S
arch/x86/crypto/sha512-mb/sha512_mb_mgr_submit_avx2.S
arch/x86/crypto/sha512-mb/sha512_x4_avx2.S
arch/x86/crypto/sha512-ssse3-asm.S
arch/x86/crypto/twofish-avx-x86_64-asm_64.S