|
25 | 25 | * |
26 | 26 | */ |
27 | 27 |
|
| 28 | +#include <asm/processor.h> |
28 | 29 | #include <linux/crypto.h> |
29 | 30 | #include <linux/init.h> |
30 | 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 | 679 | int __init init(void) |
641 | 680 | { |
642 | 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 | 691 | err = crypto_register_alg(&blk_ecb_alg); |
645 | 692 | if (err) |
646 | 693 | goto ecb_err; |
|
0 commit comments