linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: ccp - Don't initialize SEV support without the SEV feature
@ 2021-03-03 22:31 Tom Lendacky
  2021-03-05  0:04 ` Brijesh Singh
  2021-03-12 13:12 ` Herbert Xu
  0 siblings, 2 replies; 3+ messages in thread
From: Tom Lendacky @ 2021-03-03 22:31 UTC (permalink / raw)
  To: linux-crypto, linux-kernel
  Cc: Herbert Xu, David S. Miller, John Allen, Brijesh Singh

From: Tom Lendacky <thomas.lendacky@amd.com>

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>
---
 drivers/crypto/ccp/sev-dev.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index 476113e12489..b9fc8d7aca73 100644
--- a/drivers/crypto/ccp/sev-dev.c
+++ b/drivers/crypto/ccp/sev-dev.c
@@ -21,6 +21,7 @@
 #include <linux/ccp.h>
 #include <linux/firmware.h>
 #include <linux/gfp.h>
+#include <linux/cpufeature.h>
 
 #include <asm/smp.h>
 
@@ -971,6 +972,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;
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] crypto: ccp - Don't initialize SEV support without the SEV feature
  2021-03-03 22:31 [PATCH] crypto: ccp - Don't initialize SEV support without the SEV feature Tom Lendacky
@ 2021-03-05  0:04 ` Brijesh Singh
  2021-03-12 13:12 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Brijesh Singh @ 2021-03-05  0:04 UTC (permalink / raw)
  To: Tom Lendacky, linux-crypto, linux-kernel
  Cc: brijesh.singh, Herbert Xu, David S. Miller, John Allen


On 3/3/21 4:31 PM, Tom Lendacky wrote:
> From: Tom Lendacky <thomas.lendacky@amd.com>
>
> 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>

> ---
>  drivers/crypto/ccp/sev-dev.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
> index 476113e12489..b9fc8d7aca73 100644
> --- a/drivers/crypto/ccp/sev-dev.c
> +++ b/drivers/crypto/ccp/sev-dev.c
> @@ -21,6 +21,7 @@
>  #include <linux/ccp.h>
>  #include <linux/firmware.h>
>  #include <linux/gfp.h>
> +#include <linux/cpufeature.h>
>  
>  #include <asm/smp.h>
>  
> @@ -971,6 +972,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;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] crypto: ccp - Don't initialize SEV support without the SEV feature
  2021-03-03 22:31 [PATCH] crypto: ccp - Don't initialize SEV support without the SEV feature Tom Lendacky
  2021-03-05  0:04 ` Brijesh Singh
@ 2021-03-12 13:12 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2021-03-12 13:12 UTC (permalink / raw)
  To: Tom Lendacky
  Cc: linux-crypto, linux-kernel, David S. Miller, John Allen, Brijesh Singh

On Wed, Mar 03, 2021 at 04:31:09PM -0600, Tom Lendacky wrote:
> From: Tom Lendacky <thomas.lendacky@amd.com>
> 
> 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>
> ---
>  drivers/crypto/ccp/sev-dev.c | 6 ++++++
>  1 file changed, 6 insertions(+)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-12 13:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-03 22:31 [PATCH] crypto: ccp - Don't initialize SEV support without the SEV feature Tom Lendacky
2021-03-05  0:04 ` Brijesh Singh
2021-03-12 13:12 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).