aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Rientjes <rientjes@google.com>2019-07-12 16:41:58 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2019-07-18 01:39:54 -0400
commit83bf42510d7f7e1daa692c096e8e9919334d7b57 (patch)
treed7b1ccc9672d03abc0a3465755716e7c0b0d24d7
parent538a5a072e6ef04377b180ee9b3ce5bae0a85da4 (diff)
crypto: ccp - Fix SEV_VERSION_GREATER_OR_EQUAL
SEV_VERSION_GREATER_OR_EQUAL() will fail if upgrading from 2.2 to 3.1, for example, because the minor version is not equal to or greater than the major. Fix this and move to a static inline function for appropriate type checking. Fixes: edd303ff0e9e ("crypto: ccp - Add DOWNLOAD_FIRMWARE SEV command") Reported-by: Cfir Cohen <cfir@google.com> Signed-off-by: David Rientjes <rientjes@google.com> Acked-by: Tom Lendacky <thomas.lendacky@amd.com> Acked-by: Gary R Hook <gary.hook@amd.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--drivers/crypto/ccp/psp-dev.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
index 3e712f385bc1..2ff87b4d9348 100644
--- a/drivers/crypto/ccp/psp-dev.c
+++ b/drivers/crypto/ccp/psp-dev.c
@@ -24,10 +24,6 @@
24#include "sp-dev.h" 24#include "sp-dev.h"
25#include "psp-dev.h" 25#include "psp-dev.h"
26 26
27#define SEV_VERSION_GREATER_OR_EQUAL(_maj, _min) \
28 ((psp_master->api_major) >= _maj && \
29 (psp_master->api_minor) >= _min)
30
31#define DEVICE_NAME "sev" 27#define DEVICE_NAME "sev"
32#define SEV_FW_FILE "amd/sev.fw" 28#define SEV_FW_FILE "amd/sev.fw"
33#define SEV_FW_NAME_SIZE 64 29#define SEV_FW_NAME_SIZE 64
@@ -47,6 +43,15 @@ MODULE_PARM_DESC(psp_probe_timeout, " default timeout value, in seconds, during
47static bool psp_dead; 43static bool psp_dead;
48static int psp_timeout; 44static int psp_timeout;
49 45
46static inline bool sev_version_greater_or_equal(u8 maj, u8 min)
47{
48 if (psp_master->api_major > maj)
49 return true;
50 if (psp_master->api_major == maj && psp_master->api_minor >= min)
51 return true;
52 return false;
53}
54
50static struct psp_device *psp_alloc_struct(struct sp_device *sp) 55static struct psp_device *psp_alloc_struct(struct sp_device *sp)
51{ 56{
52 struct device *dev = sp->dev; 57 struct device *dev = sp->dev;
@@ -588,7 +593,7 @@ static int sev_ioctl_do_get_id2(struct sev_issue_cmd *argp)
588 int ret; 593 int ret;
589 594
590 /* SEV GET_ID is available from SEV API v0.16 and up */ 595 /* SEV GET_ID is available from SEV API v0.16 and up */
591 if (!SEV_VERSION_GREATER_OR_EQUAL(0, 16)) 596 if (!sev_version_greater_or_equal(0, 16))
592 return -ENOTSUPP; 597 return -ENOTSUPP;
593 598
594 if (copy_from_user(&input, (void __user *)argp->data, sizeof(input))) 599 if (copy_from_user(&input, (void __user *)argp->data, sizeof(input)))
@@ -651,7 +656,7 @@ static int sev_ioctl_do_get_id(struct sev_issue_cmd *argp)
651 int ret; 656 int ret;
652 657
653 /* SEV GET_ID available from SEV API v0.16 and up */ 658 /* SEV GET_ID available from SEV API v0.16 and up */
654 if (!SEV_VERSION_GREATER_OR_EQUAL(0, 16)) 659 if (!sev_version_greater_or_equal(0, 16))
655 return -ENOTSUPP; 660 return -ENOTSUPP;
656 661
657 /* SEV FW expects the buffer it fills with the ID to be 662 /* SEV FW expects the buffer it fills with the ID to be
@@ -1053,7 +1058,7 @@ void psp_pci_init(void)
1053 psp_master->sev_state = SEV_STATE_UNINIT; 1058 psp_master->sev_state = SEV_STATE_UNINIT;
1054 } 1059 }
1055 1060
1056 if (SEV_VERSION_GREATER_OR_EQUAL(0, 15) && 1061 if (sev_version_greater_or_equal(0, 15) &&
1057 sev_update_firmware(psp_master->dev) == 0) 1062 sev_update_firmware(psp_master->dev) == 0)
1058 sev_get_api_version(); 1063 sev_get_api_version();
1059 1064