diff options
author | Jussi Kivilinna <jussi.kivilinna@mbnet.fi> | 2011-12-20 05:20:16 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2012-01-13 00:38:39 -0500 |
commit | a522ee85ba979e7897a75b1c97db1b0304b68b5c (patch) | |
tree | 79e826ab14309f8f291f6eecba929eb4d0e1fba3 | |
parent | f1df57d02a0f83e764b4dc9187f58665d70f190e (diff) |
crypto: twofish-x86_64-3way - blacklist pentium4 and atom
Performance of twofish-x86_64-3way on Intel Pentium 4 and Atom is lower than
of twofish-x86_64 module. So blacklist these CPUs.
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | arch/x86/crypto/twofish_glue_3way.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/arch/x86/crypto/twofish_glue_3way.c b/arch/x86/crypto/twofish_glue_3way.c index 7fee8c152f93..0afd134d8c9c 100644 --- a/arch/x86/crypto/twofish_glue_3way.c +++ b/arch/x86/crypto/twofish_glue_3way.c | |||
@@ -25,6 +25,7 @@ | |||
25 | * | 25 | * |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #include <asm/processor.h> | ||
28 | #include <linux/crypto.h> | 29 | #include <linux/crypto.h> |
29 | #include <linux/init.h> | 30 | #include <linux/init.h> |
30 | #include <linux/module.h> | 31 | #include <linux/module.h> |
@@ -637,10 +638,56 @@ static struct crypto_alg blk_xts_alg = { | |||
637 | }, | 638 | }, |
638 | }; | 639 | }; |
639 | 640 | ||
641 | static bool is_blacklisted_cpu(void) | ||
642 | { | ||
643 | if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) | ||
644 | return false; | ||
645 | |||
646 | if (boot_cpu_data.x86 == 0x06 && | ||
647 | (boot_cpu_data.x86_model == 0x1c || | ||
648 | boot_cpu_data.x86_model == 0x26 || | ||
649 | boot_cpu_data.x86_model == 0x36)) { | ||
650 | /* | ||
651 | * On Atom, twofish-3way is slower than original assembler | ||
652 | * implementation. Twofish-3way trades off some performance in | ||
653 | * storing blocks in 64bit registers to allow three blocks to | ||
654 | * be processed parallel. Parallel operation then allows gaining | ||
655 | * more performance than was trade off, on out-of-order CPUs. | ||
656 | * However Atom does not benefit from this parallellism and | ||
657 | * should be blacklisted. | ||
658 | */ | ||
659 | return true; | ||
660 | } | ||
661 | |||
662 | if (boot_cpu_data.x86 == 0x0f) { | ||
663 | /* | ||
664 | * On Pentium 4, twofish-3way is slower than original assembler | ||
665 | * implementation because excessive uses of 64bit rotate and | ||
666 | * left-shifts (which are really slow on P4) needed to store and | ||
667 | * handle 128bit block in two 64bit registers. | ||
668 | */ | ||
669 | return true; | ||
670 | } | ||
671 | |||
672 | return false; | ||
673 | } | ||
674 | |||
675 | static int force; | ||
676 | module_param(force, int, 0); | ||
677 | MODULE_PARM_DESC(force, "Force module load, ignore CPU blacklist"); | ||
678 | |||
640 | int __init init(void) | 679 | int __init init(void) |
641 | { | 680 | { |
642 | int err; | 681 | int err; |
643 | 682 | ||
683 | if (!force && is_blacklisted_cpu()) { | ||
684 | printk(KERN_INFO | ||
685 | "twofish-x86_64-3way: performance on this CPU " | ||
686 | "would be suboptimal: disabling " | ||
687 | "twofish-x86_64-3way.\n"); | ||
688 | return -ENODEV; | ||
689 | } | ||
690 | |||
644 | err = crypto_register_alg(&blk_ecb_alg); | 691 | err = crypto_register_alg(&blk_ecb_alg); |
645 | if (err) | 692 | if (err) |
646 | goto ecb_err; | 693 | goto ecb_err; |