public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/3] platform/x86/amd/pmf: Add missing __iomem attribute to policy_base
@ 2024-02-23 16:38 Armin Wolf
  2024-02-23 16:39 ` [PATCH v2 2/3] platform/x86/amd/pmf: Do not use readl() for policy buffer access Armin Wolf
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Armin Wolf @ 2024-02-23 16:38 UTC (permalink / raw)
  To: Shyam-sundar.S-k, mika.westerberg
  Cc: sathyanarayanan.kuppuswamy, hdegoede, ilpo.jarvinen,
	platform-driver-x86, linux-kernel

The value of policy_base is the return value of a devm_ioremap call,
which returns a __iomem pointer instead of an regular pointer.
Add the missing __iomem attribute.

Compile-tested only.

Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
 drivers/platform/x86/amd/pmf/pmf.h    | 2 +-
 drivers/platform/x86/amd/pmf/tee-if.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h
index 16999c5b334f..bcf777a5659a 100644
--- a/drivers/platform/x86/amd/pmf/pmf.h
+++ b/drivers/platform/x86/amd/pmf/pmf.h
@@ -229,7 +229,7 @@ struct amd_pmf_dev {
 	struct delayed_work pb_work;
 	struct pmf_action_table *prev_data;
 	u64 policy_addr;
-	void *policy_base;
+	void __iomem *policy_base;
 	bool smart_pc_enabled;
 };

diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c
index f8c0177afb0d..16973bebf55f 100644
--- a/drivers/platform/x86/amd/pmf/tee-if.c
+++ b/drivers/platform/x86/amd/pmf/tee-if.c
@@ -346,7 +346,7 @@ static int amd_pmf_get_bios_buffer(struct amd_pmf_dev *dev)
 	if (!dev->policy_base)
 		return -ENOMEM;

-	memcpy(dev->policy_buf, dev->policy_base, dev->policy_sz);
+	memcpy_fromio(dev->policy_buf, dev->policy_base, dev->policy_sz);

 	amd_pmf_hex_dump_pb(dev);
 	if (pb_side_load)
--
2.39.2


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

* [PATCH v2 2/3] platform/x86/amd/pmf: Do not use readl() for policy buffer access
  2024-02-23 16:38 [PATCH v2 1/3] platform/x86/amd/pmf: Add missing __iomem attribute to policy_base Armin Wolf
@ 2024-02-23 16:39 ` Armin Wolf
  2024-02-27 12:59   ` Ilpo Järvinen
  2024-02-23 16:39 ` [PATCH v2 3/3] platform/x86: intel_scu_ipcutil: Make scu static Armin Wolf
  2024-02-26  6:41 ` [PATCH v2 1/3] platform/x86/amd/pmf: Add missing __iomem attribute to policy_base Kuppuswamy Sathyanarayanan
  2 siblings, 1 reply; 8+ messages in thread
From: Armin Wolf @ 2024-02-23 16:39 UTC (permalink / raw)
  To: Shyam-sundar.S-k, mika.westerberg
  Cc: sathyanarayanan.kuppuswamy, hdegoede, ilpo.jarvinen,
	platform-driver-x86, linux-kernel

The policy buffer is allocated using normal memory allocation
functions, so readl() should not be used on it.

Use get_unaligned_le32() instead.

Compile-tested only.

Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
 drivers/platform/x86/amd/pmf/tee-if.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c
index 16973bebf55f..3220b6580270 100644
--- a/drivers/platform/x86/amd/pmf/tee-if.c
+++ b/drivers/platform/x86/amd/pmf/tee-if.c
@@ -11,6 +11,7 @@
 #include <linux/debugfs.h>
 #include <linux/tee_drv.h>
 #include <linux/uuid.h>
+#include <asm/unaligned.h>
 #include "pmf.h"

 #define MAX_TEE_PARAM	4
@@ -249,8 +250,8 @@ static int amd_pmf_start_policy_engine(struct amd_pmf_dev *dev)
 	u32 cookie, length;
 	int res;

-	cookie = readl(dev->policy_buf + POLICY_COOKIE_OFFSET);
-	length = readl(dev->policy_buf + POLICY_COOKIE_LEN);
+	cookie = get_unaligned_le32(dev->policy_buf + POLICY_COOKIE_OFFSET);
+	length = get_unaligned_le32(dev->policy_buf + POLICY_COOKIE_LEN);

 	if (cookie != POLICY_SIGN_COOKIE || !length)
 		return -EINVAL;
--
2.39.2


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

* [PATCH v2 3/3] platform/x86: intel_scu_ipcutil: Make scu static
  2024-02-23 16:38 [PATCH v2 1/3] platform/x86/amd/pmf: Add missing __iomem attribute to policy_base Armin Wolf
  2024-02-23 16:39 ` [PATCH v2 2/3] platform/x86/amd/pmf: Do not use readl() for policy buffer access Armin Wolf
@ 2024-02-23 16:39 ` Armin Wolf
  2024-02-26  6:39   ` Mika Westerberg
  2024-02-27 13:06   ` Ilpo Järvinen
  2024-02-26  6:41 ` [PATCH v2 1/3] platform/x86/amd/pmf: Add missing __iomem attribute to policy_base Kuppuswamy Sathyanarayanan
  2 siblings, 2 replies; 8+ messages in thread
From: Armin Wolf @ 2024-02-23 16:39 UTC (permalink / raw)
  To: Shyam-sundar.S-k, mika.westerberg
  Cc: sathyanarayanan.kuppuswamy, hdegoede, ilpo.jarvinen,
	platform-driver-x86, linux-kernel

The variable is only used internally and has no external users,
so it should me made static.

Compile-tested only.

Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
Changes since v1:
- remove Fixes tag
- add Reviewed-by tag
---
 drivers/platform/x86/intel_scu_ipcutil.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/x86/intel_scu_ipcutil.c b/drivers/platform/x86/intel_scu_ipcutil.c
index b7c10c15a3d6..7d87cbd4b9c6 100644
--- a/drivers/platform/x86/intel_scu_ipcutil.c
+++ b/drivers/platform/x86/intel_scu_ipcutil.c
@@ -22,7 +22,7 @@

 static int major;

-struct intel_scu_ipc_dev *scu;
+static struct intel_scu_ipc_dev *scu;
 static DEFINE_MUTEX(scu_lock);

 /* IOCTL commands */
--
2.39.2


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

* Re: [PATCH v2 3/3] platform/x86: intel_scu_ipcutil: Make scu static
  2024-02-23 16:39 ` [PATCH v2 3/3] platform/x86: intel_scu_ipcutil: Make scu static Armin Wolf
@ 2024-02-26  6:39   ` Mika Westerberg
  2024-02-27 13:06   ` Ilpo Järvinen
  1 sibling, 0 replies; 8+ messages in thread
From: Mika Westerberg @ 2024-02-26  6:39 UTC (permalink / raw)
  To: Armin Wolf
  Cc: Shyam-sundar.S-k, sathyanarayanan.kuppuswamy, hdegoede,
	ilpo.jarvinen, platform-driver-x86, linux-kernel

On Fri, Feb 23, 2024 at 05:39:01PM +0100, Armin Wolf wrote:
> The variable is only used internally and has no external users,
> so it should me made static.
> 
> Compile-tested only.
> 
> Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>

Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>

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

* Re: [PATCH v2 1/3] platform/x86/amd/pmf: Add missing __iomem attribute to policy_base
  2024-02-23 16:38 [PATCH v2 1/3] platform/x86/amd/pmf: Add missing __iomem attribute to policy_base Armin Wolf
  2024-02-23 16:39 ` [PATCH v2 2/3] platform/x86/amd/pmf: Do not use readl() for policy buffer access Armin Wolf
  2024-02-23 16:39 ` [PATCH v2 3/3] platform/x86: intel_scu_ipcutil: Make scu static Armin Wolf
@ 2024-02-26  6:41 ` Kuppuswamy Sathyanarayanan
  2 siblings, 0 replies; 8+ messages in thread
From: Kuppuswamy Sathyanarayanan @ 2024-02-26  6:41 UTC (permalink / raw)
  To: Armin Wolf, Shyam-sundar.S-k, mika.westerberg
  Cc: hdegoede, ilpo.jarvinen, platform-driver-x86, linux-kernel


On 2/23/24 8:38 AM, Armin Wolf wrote:
> The value of policy_base is the return value of a devm_ioremap call,
> which returns a __iomem pointer instead of an regular pointer.
> Add the missing __iomem attribute.
>
> Compile-tested only.
>
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
> ---
Looks good to me.

Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
>  drivers/platform/x86/amd/pmf/pmf.h    | 2 +-
>  drivers/platform/x86/amd/pmf/tee-if.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h
> index 16999c5b334f..bcf777a5659a 100644
> --- a/drivers/platform/x86/amd/pmf/pmf.h
> +++ b/drivers/platform/x86/amd/pmf/pmf.h
> @@ -229,7 +229,7 @@ struct amd_pmf_dev {
>  	struct delayed_work pb_work;
>  	struct pmf_action_table *prev_data;
>  	u64 policy_addr;
> -	void *policy_base;
> +	void __iomem *policy_base;
>  	bool smart_pc_enabled;
>  };
>
> diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c
> index f8c0177afb0d..16973bebf55f 100644
> --- a/drivers/platform/x86/amd/pmf/tee-if.c
> +++ b/drivers/platform/x86/amd/pmf/tee-if.c
> @@ -346,7 +346,7 @@ static int amd_pmf_get_bios_buffer(struct amd_pmf_dev *dev)
>  	if (!dev->policy_base)
>  		return -ENOMEM;
>
> -	memcpy(dev->policy_buf, dev->policy_base, dev->policy_sz);
> +	memcpy_fromio(dev->policy_buf, dev->policy_base, dev->policy_sz);
>
>  	amd_pmf_hex_dump_pb(dev);
>  	if (pb_side_load)
> --
> 2.39.2
>
-- 
Sathyanarayanan Kuppuswamy
Linux Kernel Developer


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

* Re: [PATCH v2 2/3] platform/x86/amd/pmf: Do not use readl() for policy buffer access
  2024-02-23 16:39 ` [PATCH v2 2/3] platform/x86/amd/pmf: Do not use readl() for policy buffer access Armin Wolf
@ 2024-02-27 12:59   ` Ilpo Järvinen
  2024-02-27 13:41     ` Armin Wolf
  0 siblings, 1 reply; 8+ messages in thread
From: Ilpo Järvinen @ 2024-02-27 12:59 UTC (permalink / raw)
  To: Armin Wolf
  Cc: Shyam-sundar.S-k, Mika Westerberg, sathyanarayanan.kuppuswamy,
	Hans de Goede, platform-driver-x86, LKML

On Fri, 23 Feb 2024, Armin Wolf wrote:

> The policy buffer is allocated using normal memory allocation
> functions, so readl() should not be used on it.
> 
> Use get_unaligned_le32() instead.
> 
> Compile-tested only.
> 
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
> ---
>  drivers/platform/x86/amd/pmf/tee-if.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c
> index 16973bebf55f..3220b6580270 100644
> --- a/drivers/platform/x86/amd/pmf/tee-if.c
> +++ b/drivers/platform/x86/amd/pmf/tee-if.c
> @@ -11,6 +11,7 @@
>  #include <linux/debugfs.h>
>  #include <linux/tee_drv.h>
>  #include <linux/uuid.h>
> +#include <asm/unaligned.h>
>  #include "pmf.h"
> 
>  #define MAX_TEE_PARAM	4
> @@ -249,8 +250,8 @@ static int amd_pmf_start_policy_engine(struct amd_pmf_dev *dev)
>  	u32 cookie, length;
>  	int res;
> 
> -	cookie = readl(dev->policy_buf + POLICY_COOKIE_OFFSET);
> -	length = readl(dev->policy_buf + POLICY_COOKIE_LEN);
> +	cookie = get_unaligned_le32(dev->policy_buf + POLICY_COOKIE_OFFSET);
> +	length = get_unaligned_le32(dev->policy_buf + POLICY_COOKIE_LEN);

I don't understand you need _unaligned_ here, the offsets should be dword 
aligned, no?

#define POLICY_COOKIE_OFFSET      0x10
#define POLICY_COOKIE_LEN         0x14

-- 
 i.


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

* Re: [PATCH v2 3/3] platform/x86: intel_scu_ipcutil: Make scu static
  2024-02-23 16:39 ` [PATCH v2 3/3] platform/x86: intel_scu_ipcutil: Make scu static Armin Wolf
  2024-02-26  6:39   ` Mika Westerberg
@ 2024-02-27 13:06   ` Ilpo Järvinen
  1 sibling, 0 replies; 8+ messages in thread
From: Ilpo Järvinen @ 2024-02-27 13:06 UTC (permalink / raw)
  To: Armin Wolf
  Cc: Shyam-sundar.S-k, Mika Westerberg, sathyanarayanan.kuppuswamy,
	Hans de Goede, platform-driver-x86, LKML

On Fri, 23 Feb 2024, Armin Wolf wrote:

> The variable is only used internally and has no external users,
> so it should me made static.
> 
> Compile-tested only.
> 
> Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
> ---
> Changes since v1:
> - remove Fixes tag
> - add Reviewed-by tag
> ---
>  drivers/platform/x86/intel_scu_ipcutil.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/platform/x86/intel_scu_ipcutil.c b/drivers/platform/x86/intel_scu_ipcutil.c
> index b7c10c15a3d6..7d87cbd4b9c6 100644
> --- a/drivers/platform/x86/intel_scu_ipcutil.c
> +++ b/drivers/platform/x86/intel_scu_ipcutil.c
> @@ -22,7 +22,7 @@
> 
>  static int major;
> 
> -struct intel_scu_ipc_dev *scu;
> +static struct intel_scu_ipc_dev *scu;
>  static DEFINE_MUTEX(scu_lock);
> 
>  /* IOCTL commands */

Thanks, I took this 3/3 and 1/3 into review-ilpo.

Please check the comment I raised against 2/3.

-- 
 i.


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

* Re: [PATCH v2 2/3] platform/x86/amd/pmf: Do not use readl() for policy buffer access
  2024-02-27 12:59   ` Ilpo Järvinen
@ 2024-02-27 13:41     ` Armin Wolf
  0 siblings, 0 replies; 8+ messages in thread
From: Armin Wolf @ 2024-02-27 13:41 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Shyam-sundar.S-k, Mika Westerberg, sathyanarayanan.kuppuswamy,
	Hans de Goede, platform-driver-x86, LKML

Am 27.02.24 um 13:59 schrieb Ilpo Järvinen:

> On Fri, 23 Feb 2024, Armin Wolf wrote:
>
>> The policy buffer is allocated using normal memory allocation
>> functions, so readl() should not be used on it.
>>
>> Use get_unaligned_le32() instead.
>>
>> Compile-tested only.
>>
>> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
>> ---
>>   drivers/platform/x86/amd/pmf/tee-if.c | 5 +++--
>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c
>> index 16973bebf55f..3220b6580270 100644
>> --- a/drivers/platform/x86/amd/pmf/tee-if.c
>> +++ b/drivers/platform/x86/amd/pmf/tee-if.c
>> @@ -11,6 +11,7 @@
>>   #include <linux/debugfs.h>
>>   #include <linux/tee_drv.h>
>>   #include <linux/uuid.h>
>> +#include <asm/unaligned.h>
>>   #include "pmf.h"
>>
>>   #define MAX_TEE_PARAM	4
>> @@ -249,8 +250,8 @@ static int amd_pmf_start_policy_engine(struct amd_pmf_dev *dev)
>>   	u32 cookie, length;
>>   	int res;
>>
>> -	cookie = readl(dev->policy_buf + POLICY_COOKIE_OFFSET);
>> -	length = readl(dev->policy_buf + POLICY_COOKIE_LEN);
>> +	cookie = get_unaligned_le32(dev->policy_buf + POLICY_COOKIE_OFFSET);
>> +	length = get_unaligned_le32(dev->policy_buf + POLICY_COOKIE_LEN);
> I don't understand you need _unaligned_ here, the offsets should be dword
> aligned, no?
>
> #define POLICY_COOKIE_OFFSET      0x10
> #define POLICY_COOKIE_LEN         0x14
>
Hi,

you are right about this.

However i just noticed that the driver does not validate that the policy buffer is big enough
before accessing the data.

I will prepare a separate patch series to address this.

Thanks,
Armin Wolf


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

end of thread, other threads:[~2024-02-27 13:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-23 16:38 [PATCH v2 1/3] platform/x86/amd/pmf: Add missing __iomem attribute to policy_base Armin Wolf
2024-02-23 16:39 ` [PATCH v2 2/3] platform/x86/amd/pmf: Do not use readl() for policy buffer access Armin Wolf
2024-02-27 12:59   ` Ilpo Järvinen
2024-02-27 13:41     ` Armin Wolf
2024-02-23 16:39 ` [PATCH v2 3/3] platform/x86: intel_scu_ipcutil: Make scu static Armin Wolf
2024-02-26  6:39   ` Mika Westerberg
2024-02-27 13:06   ` Ilpo Järvinen
2024-02-26  6:41 ` [PATCH v2 1/3] platform/x86/amd/pmf: Add missing __iomem attribute to policy_base Kuppuswamy Sathyanarayanan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox