Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: ccp - check whether PSP supports SEV or TEE before initialization

Read PSP feature register to check for TEE (Trusted Execution Environment)
support.

If neither SEV nor TEE is supported by PSP, then skip PSP initialization.

Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Jens Wiklander <jens.wiklander@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Co-developed-by: Devaraj Rangasamy <Devaraj.Rangasamy@amd.com>
Signed-off-by: Devaraj Rangasamy <Devaraj.Rangasamy@amd.com>
Signed-off-by: Rijo Thomas <Rijo-john.Thomas@amd.com>
Acked-by: Gary R Hook <gary.hook@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Rijo Thomas and committed by
Herbert Xu
f100ab62 6eb0cc72

+41 -5
+41 -5
drivers/crypto/ccp/psp-dev.c
··· 53 53 return IRQ_HANDLED; 54 54 } 55 55 56 - static int psp_check_sev_support(struct psp_device *psp) 56 + static unsigned int psp_get_capability(struct psp_device *psp) 57 57 { 58 58 unsigned int val = ioread32(psp->io_regs + psp->vdata->feature_reg); 59 59 ··· 66 66 */ 67 67 if (val == 0xffffffff) { 68 68 dev_notice(psp->dev, "psp: unable to access the device: you might be running a broken BIOS.\n"); 69 - return -ENODEV; 69 + return 0; 70 70 } 71 71 72 - if (!(val & 1)) { 73 - /* Device does not support the SEV feature */ 72 + return val; 73 + } 74 + 75 + static int psp_check_sev_support(struct psp_device *psp, 76 + unsigned int capability) 77 + { 78 + /* Check if device supports SEV feature */ 79 + if (!(capability & 1)) { 74 80 dev_dbg(psp->dev, "psp does not support SEV\n"); 75 81 return -ENODEV; 76 82 } 83 + 84 + return 0; 85 + } 86 + 87 + static int psp_check_tee_support(struct psp_device *psp, 88 + unsigned int capability) 89 + { 90 + /* Check if device supports TEE feature */ 91 + if (!(capability & 2)) { 92 + dev_dbg(psp->dev, "psp does not support TEE\n"); 93 + return -ENODEV; 94 + } 95 + 96 + return 0; 97 + } 98 + 99 + static int psp_check_support(struct psp_device *psp, 100 + unsigned int capability) 101 + { 102 + int sev_support = psp_check_sev_support(psp, capability); 103 + int tee_support = psp_check_tee_support(psp, capability); 104 + 105 + /* Return error if device neither supports SEV nor TEE */ 106 + if (sev_support && tee_support) 107 + return -ENODEV; 77 108 78 109 return 0; 79 110 } ··· 113 82 { 114 83 struct device *dev = sp->dev; 115 84 struct psp_device *psp; 85 + unsigned int capability; 116 86 int ret; 117 87 118 88 ret = -ENOMEM; ··· 132 100 133 101 psp->io_regs = sp->io_map; 134 102 135 - ret = psp_check_sev_support(psp); 103 + capability = psp_get_capability(psp); 104 + if (!capability) 105 + goto e_disable; 106 + 107 + ret = psp_check_support(psp, capability); 136 108 if (ret) 137 109 goto e_disable; 138 110