crypto: ccp - Don't initialize SEV support without the SEV feature
authorTom Lendacky <thomas.lendacky@amd.com>
Wed, 3 Mar 2021 22:31:09 +0000 (16:31 -0600)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 12 Mar 2021 13:04:02 +0000 (00:04 +1100)
If SEV has been disabled (e.g. through BIOS), the driver probe will still
issue SEV firmware commands. The SEV INIT firmware command will return an
error in this situation, but the error code is a general error code that
doesn't highlight the exact reason.

Add a check for X86_FEATURE_SEV in sev_dev_init() and emit a meaningful
message and skip attempting to initialize the SEV firmware if the feature
is not enabled. Since building the SEV code is dependent on X86_64, adding
the check won't cause any build problems.

Cc: John Allen <john.allen@amd.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Reviewed-By: Brijesh Singh <brijesh.singh@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/ccp/sev-dev.c

index cb9b4c4e371edb43a4d2b593ba39bda330189a0f..da3872c48308e176550bd03becfe584501482294 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/ccp.h>
 #include <linux/firmware.h>
 #include <linux/gfp.h>
+#include <linux/cpufeature.h>
 
 #include <asm/smp.h>
 
@@ -972,6 +973,11 @@ int sev_dev_init(struct psp_device *psp)
        struct sev_device *sev;
        int ret = -ENOMEM;
 
+       if (!boot_cpu_has(X86_FEATURE_SEV)) {
+               dev_info_once(dev, "SEV: memory encryption not enabled by BIOS\n");
+               return 0;
+       }
+
        sev = devm_kzalloc(dev, sizeof(*sev), GFP_KERNEL);
        if (!sev)
                goto e_err;