Skip to content

Commit 83bf425

Browse files
rientjesherbertx
authored andcommitted
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: edd303f ("crypto: ccp - Add DOWNLOAD_FIRMWARE SEV command") Reported-by: Cfir Cohen <[email protected]> Signed-off-by: David Rientjes <[email protected]> Acked-by: Tom Lendacky <[email protected]> Acked-by: Gary R Hook <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 538a5a0 commit 83bf425

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

drivers/crypto/ccp/psp-dev.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
#include "sp-dev.h"
2525
#include "psp-dev.h"
2626

27-
#define SEV_VERSION_GREATER_OR_EQUAL(_maj, _min) \
28-
((psp_master->api_major) >= _maj && \
29-
(psp_master->api_minor) >= _min)
30-
3127
#define DEVICE_NAME "sev"
3228
#define SEV_FW_FILE "amd/sev.fw"
3329
#define SEV_FW_NAME_SIZE 64
@@ -47,6 +43,15 @@ MODULE_PARM_DESC(psp_probe_timeout, " default timeout value, in seconds, during
4743
static bool psp_dead;
4844
static int psp_timeout;
4945

46+
static 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+
5055
static struct psp_device *psp_alloc_struct(struct sp_device *sp)
5156
{
5257
struct device *dev = sp->dev;
@@ -588,7 +593,7 @@ static int sev_ioctl_do_get_id2(struct sev_issue_cmd *argp)
588593
int ret;
589594

590595
/* 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))
592597
return -ENOTSUPP;
593598

594599
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)
651656
int ret;
652657

653658
/* 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))
655660
return -ENOTSUPP;
656661

657662
/* SEV FW expects the buffer it fills with the ID to be
@@ -1053,7 +1058,7 @@ void psp_pci_init(void)
10531058
psp_master->sev_state = SEV_STATE_UNINIT;
10541059
}
10551060

1056-
if (SEV_VERSION_GREATER_OR_EQUAL(0, 15) &&
1061+
if (sev_version_greater_or_equal(0, 15) &&
10571062
sev_update_firmware(psp_master->dev) == 0)
10581063
sev_get_api_version();
10591064

0 commit comments

Comments
 (0)