Thread (19 messages) 19 messages, 4 authors, 2012-06-20

Re: [PATCH] crypto: serpent - add x86_64/avx assembler implementation

From: Andi Kleen <hidden>
Date: 2012-05-30 02:27:50
Also in: lkml

Possibly related (same subject, not in this thread)

Johannes Goetzfried
[off-list ref] writes:
+
+static int __init serpent_init(void)
+{
+	u64 xcr0;
+
+	if (!cpu_has_avx || !cpu_has_osxsave) {
+		printk(KERN_INFO "AVX instructions are not detected.\n");
+		return -ENODEV;
+	}
+
+	xcr0 = xgetbv(XCR_XFEATURE_ENABLED_MASK);
+	if ((xcr0 & (XSTATE_SSE | XSTATE_YMM)) != (XSTATE_SSE | XSTATE_YMM)) {
+		printk(KERN_INFO "AVX detected but unusable.\n");
+		return -ENODEV;
+	}
+
+	return crypto_register_algs(serpent_algs, ARRAY_SIZE(serpent_algs));
+}
+
+static void __exit serpent_exit(void)
+{
+	crypto_unregister_algs(serpent_algs, ARRAY_SIZE(serpent_algs));
+}
+
+module_init(serpent_init);
+module_exit(serpent_exit);
+
+MODULE_DESCRIPTION("Serpent Cipher Algorithm, AVX optimized");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("serpent");
The driver needs CPUID annotations now (since 3.3), so that it can be 
autoloaded.  Something like:

#include <asm/cpu_device_id.h>


static const struct x86_cpu_id avx_cpu_id[] = {
        X86_FEATURE_MATCH(X86_FEATURE_AVX),
        {}
};
MODULE_DEVICE_TABLE(x86cpu, avx_cpu_id);


Replace the manual check in init with

            if (!x86_match_cpu(avx_cpu_id))
                return -ENODEV;

Also drivers should never print anything when they cannot find hardware.
Remove that printk.

-Andi

-- 
ak@linux.intel.com -- Speaking for myself only
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help