linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] crypto: ccp - Fix SEV_VERSION_GREATER_OR_EQUAL
@ 2019-07-10 21:28 David Rientjes
  2019-07-10 22:06 ` Lendacky, Thomas
  0 siblings, 1 reply; 6+ messages in thread
From: David Rientjes @ 2019-07-10 21:28 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Cfir Cohen, Janakarajan Natarajan, Tom Lendacky, Gary Hook,
	linux-crypto, linux-kernel

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>
---
 drivers/crypto/ccp/psp-dev.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
--- a/drivers/crypto/ccp/psp-dev.c
+++ b/drivers/crypto/ccp/psp-dev.c
@@ -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
@@ -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;
@@ -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)))
@@ -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
@@ -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();
 

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

* Re: [patch] crypto: ccp - Fix SEV_VERSION_GREATER_OR_EQUAL
  2019-07-10 21:28 [patch] crypto: ccp - Fix SEV_VERSION_GREATER_OR_EQUAL David Rientjes
@ 2019-07-10 22:06 ` Lendacky, Thomas
  2019-07-12 20:41   ` [patch v2] " David Rientjes
  0 siblings, 1 reply; 6+ messages in thread
From: Lendacky, Thomas @ 2019-07-10 22:06 UTC (permalink / raw)
  To: David Rientjes, Herbert Xu
  Cc: Cfir Cohen, Natarajan, Janakarajan, Hook, Gary, linux-crypto,
	linux-kernel

On 7/10/19 4:28 PM, David Rientjes wrote:
> 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>
> ---
>  drivers/crypto/ccp/psp-dev.c | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
> --- a/drivers/crypto/ccp/psp-dev.c
> +++ b/drivers/crypto/ccp/psp-dev.c
> @@ -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
> @@ -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)

Just a nit, but it reads a little clearer to me as:

	if (psp_master->api_major == maj && psp_master->api_minor >= min)

since you tested for major > above.

Thanks,
Tom

> +		return true;
> +	return false;
> +}
> +
>  static struct psp_device *psp_alloc_struct(struct sp_device *sp)
>  {
>  	struct device *dev = sp->dev;
> @@ -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)))
> @@ -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
> @@ -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();
>  
> 

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

* [patch v2] crypto: ccp - Fix SEV_VERSION_GREATER_OR_EQUAL
  2019-07-10 22:06 ` Lendacky, Thomas
@ 2019-07-12 20:41   ` David Rientjes
  2019-07-15 17:03     ` Lendacky, Thomas
  2019-07-18  5:41     ` Herbert Xu
  0 siblings, 2 replies; 6+ messages in thread
From: David Rientjes @ 2019-07-12 20:41 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Lendacky, Thomas, Cfir Cohen, Natarajan, Janakarajan, Hook, Gary,
	linux-crypto, linux-kernel

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>
---
 v2: no need to check api_major >= maj after checking api_major > maj
     per Thomas

 drivers/crypto/ccp/psp-dev.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
--- a/drivers/crypto/ccp/psp-dev.c
+++ b/drivers/crypto/ccp/psp-dev.c
@@ -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
@@ -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;
@@ -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)))
@@ -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
@@ -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();
 

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

* Re: [patch v2] crypto: ccp - Fix SEV_VERSION_GREATER_OR_EQUAL
  2019-07-12 20:41   ` [patch v2] " David Rientjes
@ 2019-07-15 17:03     ` Lendacky, Thomas
  2019-07-15 22:38       ` Gary R Hook
  2019-07-18  5:41     ` Herbert Xu
  1 sibling, 1 reply; 6+ messages in thread
From: Lendacky, Thomas @ 2019-07-15 17:03 UTC (permalink / raw)
  To: David Rientjes, Herbert Xu
  Cc: Cfir Cohen, Natarajan, Janakarajan, Hook, Gary, linux-crypto,
	linux-kernel

On 7/12/19 3:41 PM, David Rientjes wrote:
> 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>

> ---
>  v2: no need to check api_major >= maj after checking api_major > maj
>      per Thomas
> 
>  drivers/crypto/ccp/psp-dev.c | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
> --- a/drivers/crypto/ccp/psp-dev.c
> +++ b/drivers/crypto/ccp/psp-dev.c
> @@ -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
> @@ -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;
> @@ -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)))
> @@ -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
> @@ -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();
>  
> 

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

* Re: [patch v2] crypto: ccp - Fix SEV_VERSION_GREATER_OR_EQUAL
  2019-07-15 17:03     ` Lendacky, Thomas
@ 2019-07-15 22:38       ` Gary R Hook
  0 siblings, 0 replies; 6+ messages in thread
From: Gary R Hook @ 2019-07-15 22:38 UTC (permalink / raw)
  To: Lendacky, Thomas, David Rientjes, Herbert Xu
  Cc: Cfir Cohen, Natarajan, Janakarajan, Hook, Gary, linux-crypto,
	linux-kernel

On 7/15/19 12:03 PM, Lendacky, Thomas wrote:
> On 7/12/19 3:41 PM, David Rientjes wrote:
>> 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>

> 
>> ---
>>   v2: no need to check api_major >= maj after checking api_major > maj
>>       per Thomas
>>
>>   drivers/crypto/ccp/psp-dev.c | 19 ++++++++++++-------
>>   1 file changed, 12 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
>> --- a/drivers/crypto/ccp/psp-dev.c
>> +++ b/drivers/crypto/ccp/psp-dev.c
>> @@ -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
>> @@ -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;
>> @@ -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)))
>> @@ -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
>> @@ -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();
>>   
>>


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

* Re: [patch v2] crypto: ccp - Fix SEV_VERSION_GREATER_OR_EQUAL
  2019-07-12 20:41   ` [patch v2] " David Rientjes
  2019-07-15 17:03     ` Lendacky, Thomas
@ 2019-07-18  5:41     ` Herbert Xu
  1 sibling, 0 replies; 6+ messages in thread
From: Herbert Xu @ 2019-07-18  5:41 UTC (permalink / raw)
  To: David Rientjes
  Cc: Lendacky, Thomas, Cfir Cohen, Natarajan, Janakarajan, Hook, Gary,
	linux-crypto, linux-kernel

On Fri, Jul 12, 2019 at 01:41:58PM -0700, David Rientjes wrote:
> 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>
> ---
>  v2: no need to check api_major >= maj after checking api_major > maj
>      per Thomas
> 
>  drivers/crypto/ccp/psp-dev.c | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)

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] 6+ messages in thread

end of thread, other threads:[~2019-07-18  5:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-10 21:28 [patch] crypto: ccp - Fix SEV_VERSION_GREATER_OR_EQUAL David Rientjes
2019-07-10 22:06 ` Lendacky, Thomas
2019-07-12 20:41   ` [patch v2] " David Rientjes
2019-07-15 17:03     ` Lendacky, Thomas
2019-07-15 22:38       ` Gary R Hook
2019-07-18  5:41     ` 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).