Skip to content

Commit 4c58464

Browse files
jkivilinherbertx
authored andcommitted
crypto: blowfish-x86_64 - blacklist Pentium 4
Implementation in blowfish-x86_64 uses 64bit rotations which are slow on P4, making blowfish-x86_64 slower than generic C implementation. Therefore blacklist P4. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent a522ee8 commit 4c58464

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎arch/x86/crypto/blowfish_glue.c‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*
2626
*/
2727

28+
#include <asm/processor.h>
2829
#include <crypto/blowfish.h>
2930
#include <linux/crypto.h>
3031
#include <linux/init.h>
@@ -446,10 +447,39 @@ static struct crypto_alg blk_ctr_alg = {
446447
},
447448
};
448449

450+
static bool is_blacklisted_cpu(void)
451+
{
452+
if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
453+
return false;
454+
455+
if (boot_cpu_data.x86 == 0x0f) {
456+
/*
457+
* On Pentium 4, blowfish-x86_64 is slower than generic C
458+
* implementation because use of 64bit rotates (which are really
459+
* slow on P4). Therefore blacklist P4s.
460+
*/
461+
return true;
462+
}
463+
464+
return false;
465+
}
466+
467+
static int force;
468+
module_param(force, int, 0);
469+
MODULE_PARM_DESC(force, "Force module load, ignore CPU blacklist");
470+
449471
static int __init init(void)
450472
{
451473
int err;
452474

475+
if (!force && is_blacklisted_cpu()) {
476+
printk(KERN_INFO
477+
"blowfish-x86_64: performance on this CPU "
478+
"would be suboptimal: disabling "
479+
"blowfish-x86_64.\n");
480+
return -ENODEV;
481+
}
482+
453483
err = crypto_register_alg(&bf_alg);
454484
if (err)
455485
goto bf_err;

0 commit comments

Comments
 (0)