Skip to content

Commit

Permalink
crypto: ccp - Fix SEV_VERSION_GREATER_OR_EQUAL
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
rientjes authored and herbertx committed Jul 18, 2019
1 parent 538a5a0 commit 83bf425
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions drivers/crypto/ccp/psp-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
#include "sp-dev.h"
#include "psp-dev.h"

#define SEV_VERSION_GREATER_OR_EQUAL(_maj, _min) \
((psp_master->api_major) >= _maj && \
(psp_master->api_minor) >= _min)

#define DEVICE_NAME "sev"
#define SEV_FW_FILE "amd/sev.fw"
#define SEV_FW_NAME_SIZE 64
Expand All @@ -47,6 +43,15 @@ MODULE_PARM_DESC(psp_probe_timeout, " default timeout value, in seconds, during
static bool psp_dead;
static int psp_timeout;

static inline bool sev_version_greater_or_equal(u8 maj, u8 min)
{
if (psp_master->api_major > maj)
return true;
if (psp_master->api_major == maj && psp_master->api_minor >= min)
return true;
return false;
}

static struct psp_device *psp_alloc_struct(struct sp_device *sp)
{
struct device *dev = sp->dev;
Expand Down Expand Up @@ -588,7 +593,7 @@ static int sev_ioctl_do_get_id2(struct sev_issue_cmd *argp)
int ret;

/* SEV GET_ID is available from SEV API v0.16 and up */
if (!SEV_VERSION_GREATER_OR_EQUAL(0, 16))
if (!sev_version_greater_or_equal(0, 16))
return -ENOTSUPP;

if (copy_from_user(&input, (void __user *)argp->data, sizeof(input)))
Expand Down Expand Up @@ -651,7 +656,7 @@ static int sev_ioctl_do_get_id(struct sev_issue_cmd *argp)
int ret;

/* SEV GET_ID available from SEV API v0.16 and up */
if (!SEV_VERSION_GREATER_OR_EQUAL(0, 16))
if (!sev_version_greater_or_equal(0, 16))
return -ENOTSUPP;

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

if (SEV_VERSION_GREATER_OR_EQUAL(0, 15) &&
if (sev_version_greater_or_equal(0, 15) &&
sev_update_firmware(psp_master->dev) == 0)
sev_get_api_version();

Expand Down

0 comments on commit 83bf425

Please sign in to comment.