linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next v2 0/3] cacheinfo: Fix misbehaviours around init_cache_level()
@ 2023-01-24 15:40 Pierre Gondois
  2023-01-24 15:40 ` [PATCH -next v2 1/3] cacheinfo: Initialize variables in fetch_cache_info() Pierre Gondois
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Pierre Gondois @ 2023-01-24 15:40 UTC (permalink / raw)
  To: linux-kernel
  Cc: Geert Uytterhoeven, Conor Dooley, Dan Carpenter, Pierre Gondois,
	Catalin Marinas, Will Deacon, Greg Kroah-Hartman,
	Rafael J. Wysocki, Sudeep Holla, Jeremy Linton, Akihiko Odaki,
	Palmer Dabbelt, Gavin Shan, linux-arm-kernel

v2:
https://lore.kernel.org/all/20230124123450.321852-1-pierre.gondois@arm.com/
- Split initial patch in 3.
- Add links to static-analysis reports.

Some cases were not correctly evaluated when updating
init_cache_level()'s prototype, in particular if CONFIG_ACPI_PPTT is
not defined. Fix them.

The initial diagnostic was done thanks to:
- the kernel test robot <lkp@intel.com>
Link: https://lore.kernel.org/all/202301052307.JYt1GWaJ-lkp@intel.com/
- Dan Carpenter <error27@gmail.com>
Link: https://lore.kernel.org/all/Y86iruJPuwNN7rZw@kili/

Pierre Gondois (3):
  cacheinfo: Initialize variables in fetch_cache_info()
  cacheinfo: Make default acpi_get_cache_info() return an error
  cacheinfo: Remove unused check in init_cache_level()

 arch/arm64/kernel/cacheinfo.c | 5 +----
 drivers/base/cacheinfo.c      | 2 +-
 include/linux/cacheinfo.h     | 2 +-
 3 files changed, 3 insertions(+), 6 deletions(-)

-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH -next v2 1/3] cacheinfo: Initialize variables in fetch_cache_info()
  2023-01-24 15:40 [PATCH -next v2 0/3] cacheinfo: Fix misbehaviours around init_cache_level() Pierre Gondois
@ 2023-01-24 15:40 ` Pierre Gondois
  2023-01-24 17:19   ` Conor Dooley
  2023-01-24 15:40 ` [PATCH -next v2 2/3] cacheinfo: Make default acpi_get_cache_info() return an error Pierre Gondois
  2023-01-24 15:40 ` [PATCH -next v2 3/3] cacheinfo: Remove unused check in init_cache_level() Pierre Gondois
  2 siblings, 1 reply; 7+ messages in thread
From: Pierre Gondois @ 2023-01-24 15:40 UTC (permalink / raw)
  To: linux-kernel
  Cc: Geert Uytterhoeven, Conor Dooley, Dan Carpenter, Pierre Gondois,
	kernel test robot, Catalin Marinas, Will Deacon,
	Greg Kroah-Hartman, Rafael J. Wysocki, Sudeep Holla,
	Palmer Dabbelt, Oliver Upton, Akihiko Odaki, Gavin Shan,
	Jeremy Linton, linux-arm-kernel

Set potentially uninitialized variables to 0. This is particularly
relevant when CONFIG_ACPI_PPTT is not set.

Reported-by: kernel test robot <lkp@intel.com>
Link: https://lore.kernel.org/all/202301052307.JYt1GWaJ-lkp@intel.com/
Reported-by: Dan Carpenter <error27@gmail.com>
Link: https://lore.kernel.org/all/Y86iruJPuwNN7rZw@kili/
Fixes: 5944ce092b97 ("arch_topology: Build cacheinfo from primary CPU")
Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
---
 drivers/base/cacheinfo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c
index 418a18acc8f9..f6573c335f4c 100644
--- a/drivers/base/cacheinfo.c
+++ b/drivers/base/cacheinfo.c
@@ -424,7 +424,7 @@ int allocate_cache_info(int cpu)
 int fetch_cache_info(unsigned int cpu)
 {
 	struct cpu_cacheinfo *this_cpu_ci;
-	unsigned int levels, split_levels;
+	unsigned int levels = 0, split_levels = 0;
 	int ret;
 
 	if (acpi_disabled) {
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH -next v2 2/3] cacheinfo: Make default acpi_get_cache_info() return an error
  2023-01-24 15:40 [PATCH -next v2 0/3] cacheinfo: Fix misbehaviours around init_cache_level() Pierre Gondois
  2023-01-24 15:40 ` [PATCH -next v2 1/3] cacheinfo: Initialize variables in fetch_cache_info() Pierre Gondois
@ 2023-01-24 15:40 ` Pierre Gondois
  2023-01-24 17:15   ` Conor Dooley
  2023-01-24 15:40 ` [PATCH -next v2 3/3] cacheinfo: Remove unused check in init_cache_level() Pierre Gondois
  2 siblings, 1 reply; 7+ messages in thread
From: Pierre Gondois @ 2023-01-24 15:40 UTC (permalink / raw)
  To: linux-kernel
  Cc: Geert Uytterhoeven, Conor Dooley, Dan Carpenter, Pierre Gondois,
	Catalin Marinas, Will Deacon, Greg Kroah-Hartman,
	Rafael J. Wysocki, Sudeep Holla, Akihiko Odaki, Palmer Dabbelt,
	Gavin Shan, linux-arm-kernel

commit bd500361a937 ("ACPI: PPTT: Update acpi_find_last_cache_level()
to acpi_get_cache_info()")
updates the prototype of acpi_get_cache_info(). The cache 'levels'
is update through a pointer and not the return value of the function.

If CONFIG_ACPI_PPTT is not defined, acpi_get_cache_info() doesn't
update its *levels and *split_levels parameters and returns 0.
This can lead to a faulty behaviour.

Make acpi_get_cache_info() return an error code if CONFIG_ACPI_PPTT
is not defined.
Also,

In init_cache_level(), if no PPTT is present or CONFIG_ACPI_PPTT is
not defined, instead of aborting if acpi_get_cache_info() returns an
error code, just continue. This allows to try fetching the cache
information from clidr_el1.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
---
 arch/arm64/kernel/cacheinfo.c | 2 +-
 include/linux/cacheinfo.h     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/cacheinfo.c b/arch/arm64/kernel/cacheinfo.c
index d3fe9542c370..bf348b8d321f 100644
--- a/arch/arm64/kernel/cacheinfo.c
+++ b/arch/arm64/kernel/cacheinfo.c
@@ -59,7 +59,7 @@ int init_cache_level(unsigned int cpu)
 	} else {
 		ret = acpi_get_cache_info(cpu, &fw_level, NULL);
 		if (ret < 0)
-			return ret;
+			fw_level = 0;
 	}
 
 	if (fw_level < 0)
diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h
index dfef57077cd0..908e19d17f49 100644
--- a/include/linux/cacheinfo.h
+++ b/include/linux/cacheinfo.h
@@ -100,7 +100,7 @@ static inline
 int acpi_get_cache_info(unsigned int cpu,
 			unsigned int *levels, unsigned int *split_levels)
 {
-	return 0;
+	return -ENOENT;
 }
 #else
 int acpi_get_cache_info(unsigned int cpu,
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH -next v2 3/3] cacheinfo: Remove unused check in init_cache_level()
  2023-01-24 15:40 [PATCH -next v2 0/3] cacheinfo: Fix misbehaviours around init_cache_level() Pierre Gondois
  2023-01-24 15:40 ` [PATCH -next v2 1/3] cacheinfo: Initialize variables in fetch_cache_info() Pierre Gondois
  2023-01-24 15:40 ` [PATCH -next v2 2/3] cacheinfo: Make default acpi_get_cache_info() return an error Pierre Gondois
@ 2023-01-24 15:40 ` Pierre Gondois
  2023-01-24 17:01   ` Conor Dooley
  2 siblings, 1 reply; 7+ messages in thread
From: Pierre Gondois @ 2023-01-24 15:40 UTC (permalink / raw)
  To: linux-kernel
  Cc: Geert Uytterhoeven, Conor Dooley, Dan Carpenter, Pierre Gondois,
	Catalin Marinas, Will Deacon, Greg Kroah-Hartman,
	Rafael J. Wysocki, Sudeep Holla, Akihiko Odaki, Palmer Dabbelt,
	Gavin Shan, linux-arm-kernel

commit e75d18cecbb3 ("arm64: cacheinfo: Fix incorrect assignment
of signed error value to unsigned fw_level")
checks the fw_level value in init_cache_level() in case the value is
negative.
Remove this check as the error code is not returned through
fw_level anymore, and reset fw_level if acpi_get_cache_info()
failed. This allows to try fetching the cache information from
clidr_el1.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
---
 arch/arm64/kernel/cacheinfo.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/arch/arm64/kernel/cacheinfo.c b/arch/arm64/kernel/cacheinfo.c
index bf348b8d321f..c307f69e9b55 100644
--- a/arch/arm64/kernel/cacheinfo.c
+++ b/arch/arm64/kernel/cacheinfo.c
@@ -62,9 +62,6 @@ int init_cache_level(unsigned int cpu)
 			fw_level = 0;
 	}
 
-	if (fw_level < 0)
-		return fw_level;
-
 	if (level < fw_level) {
 		/*
 		 * some external caches not specified in CLIDR_EL1
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH -next v2 3/3] cacheinfo: Remove unused check in init_cache_level()
  2023-01-24 15:40 ` [PATCH -next v2 3/3] cacheinfo: Remove unused check in init_cache_level() Pierre Gondois
@ 2023-01-24 17:01   ` Conor Dooley
  0 siblings, 0 replies; 7+ messages in thread
From: Conor Dooley @ 2023-01-24 17:01 UTC (permalink / raw)
  To: Pierre Gondois
  Cc: linux-kernel, Geert Uytterhoeven, Conor Dooley, Dan Carpenter,
	Catalin Marinas, Will Deacon, Greg Kroah-Hartman,
	Rafael J. Wysocki, Sudeep Holla, Akihiko Odaki, Palmer Dabbelt,
	Gavin Shan, linux-arm-kernel


[-- Attachment #1.1: Type: text/plain, Size: 1249 bytes --]

On Tue, Jan 24, 2023 at 04:40:48PM +0100, Pierre Gondois wrote:
> commit e75d18cecbb3 ("arm64: cacheinfo: Fix incorrect assignment
> of signed error value to unsigned fw_level")
> checks the fw_level value in init_cache_level() in case the value is
> negative.
> Remove this check as the error code is not returned through
> fw_level anymore, and reset fw_level if acpi_get_cache_info()
> failed. This allows to try fetching the cache information from
> clidr_el1.

I dunno anything about clidr_el1, but the mechanics of the change seem
fair. There is a non-acpi path too, which shouldn't return negative
numbers either so LGTM.

> Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
> ---
>  arch/arm64/kernel/cacheinfo.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/arch/arm64/kernel/cacheinfo.c b/arch/arm64/kernel/cacheinfo.c
> index bf348b8d321f..c307f69e9b55 100644
> --- a/arch/arm64/kernel/cacheinfo.c
> +++ b/arch/arm64/kernel/cacheinfo.c
> @@ -62,9 +62,6 @@ int init_cache_level(unsigned int cpu)
>  			fw_level = 0;
>  	}
>  
> -	if (fw_level < 0)
> -		return fw_level;
> -
>  	if (level < fw_level) {
>  		/*
>  		 * some external caches not specified in CLIDR_EL1
> -- 
> 2.25.1
> 

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH -next v2 2/3] cacheinfo: Make default acpi_get_cache_info() return an error
  2023-01-24 15:40 ` [PATCH -next v2 2/3] cacheinfo: Make default acpi_get_cache_info() return an error Pierre Gondois
@ 2023-01-24 17:15   ` Conor Dooley
  0 siblings, 0 replies; 7+ messages in thread
From: Conor Dooley @ 2023-01-24 17:15 UTC (permalink / raw)
  To: Pierre Gondois
  Cc: linux-kernel, Geert Uytterhoeven, Conor Dooley, Dan Carpenter,
	Catalin Marinas, Will Deacon, Greg Kroah-Hartman,
	Rafael J. Wysocki, Sudeep Holla, Akihiko Odaki, Palmer Dabbelt,
	Gavin Shan, linux-arm-kernel


[-- Attachment #1.1: Type: text/plain, Size: 2383 bytes --]

On Tue, Jan 24, 2023 at 04:40:47PM +0100, Pierre Gondois wrote:
> commit bd500361a937 ("ACPI: PPTT: Update acpi_find_last_cache_level()
> to acpi_get_cache_info()")
> updates the prototype of acpi_get_cache_info(). The cache 'levels'
> is update through a pointer and not the return value of the function.
> 
> If CONFIG_ACPI_PPTT is not defined, acpi_get_cache_info() doesn't
> update its *levels and *split_levels parameters and returns 0.
> This can lead to a faulty behaviour.
> 
> Make acpi_get_cache_info() return an error code if CONFIG_ACPI_PPTT
> is not defined.
> Also,
> 
> In init_cache_level(), if no PPTT is present or CONFIG_ACPI_PPTT is
> not defined, instead of aborting if acpi_get_cache_info() returns an
> error code, just continue. This allows to try fetching the cache
> information from clidr_el1.

Again, dunno jack about clidr_el1. But the change here seems sane once
more? I was going to suggest throwing away ret entirely and just
initialising fw_level to zero, since the function inside
acpi_get_cache_level() that actually modifies it comes after the last
error return anyway - but that probably would just leave you exposed to
a change in the core code that doesn't also update the callsites.
Plus this looks more deliberate IMO. On that basis, LGTM.

> Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
> ---
>  arch/arm64/kernel/cacheinfo.c | 2 +-
>  include/linux/cacheinfo.h     | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/kernel/cacheinfo.c b/arch/arm64/kernel/cacheinfo.c
> index d3fe9542c370..bf348b8d321f 100644
> --- a/arch/arm64/kernel/cacheinfo.c
> +++ b/arch/arm64/kernel/cacheinfo.c
> @@ -59,7 +59,7 @@ int init_cache_level(unsigned int cpu)
>  	} else {
>  		ret = acpi_get_cache_info(cpu, &fw_level, NULL);
>  		if (ret < 0)
> -			return ret;
> +			fw_level = 0;
>  	}
>  
>  	if (fw_level < 0)
> diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h
> index dfef57077cd0..908e19d17f49 100644
> --- a/include/linux/cacheinfo.h
> +++ b/include/linux/cacheinfo.h
> @@ -100,7 +100,7 @@ static inline
>  int acpi_get_cache_info(unsigned int cpu,
>  			unsigned int *levels, unsigned int *split_levels)
>  {
> -	return 0;
> +	return -ENOENT;
>  }
>  #else
>  int acpi_get_cache_info(unsigned int cpu,
> -- 
> 2.25.1
> 

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH -next v2 1/3] cacheinfo: Initialize variables in fetch_cache_info()
  2023-01-24 15:40 ` [PATCH -next v2 1/3] cacheinfo: Initialize variables in fetch_cache_info() Pierre Gondois
@ 2023-01-24 17:19   ` Conor Dooley
  0 siblings, 0 replies; 7+ messages in thread
From: Conor Dooley @ 2023-01-24 17:19 UTC (permalink / raw)
  To: Pierre Gondois
  Cc: linux-kernel, Geert Uytterhoeven, Conor Dooley, Dan Carpenter,
	kernel test robot, Catalin Marinas, Will Deacon,
	Greg Kroah-Hartman, Rafael J. Wysocki, Sudeep Holla,
	Palmer Dabbelt, Oliver Upton, Akihiko Odaki, Gavin Shan,
	Jeremy Linton, linux-arm-kernel


[-- Attachment #1.1: Type: text/plain, Size: 1228 bytes --]

On Tue, Jan 24, 2023 at 04:40:46PM +0100, Pierre Gondois wrote:
> Set potentially uninitialized variables to 0. This is particularly
> relevant when CONFIG_ACPI_PPTT is not set.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Link: https://lore.kernel.org/all/202301052307.JYt1GWaJ-lkp@intel.com/
> Reported-by: Dan Carpenter <error27@gmail.com>
> Link: https://lore.kernel.org/all/Y86iruJPuwNN7rZw@kili/
> Fixes: 5944ce092b97 ("arch_topology: Build cacheinfo from primary CPU")
> Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>

Reviewed-by: Conor Dooley <conor.dooley@microchip.com>

Thanks for the quick respin Pierre :)

> ---
>  drivers/base/cacheinfo.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c
> index 418a18acc8f9..f6573c335f4c 100644
> --- a/drivers/base/cacheinfo.c
> +++ b/drivers/base/cacheinfo.c
> @@ -424,7 +424,7 @@ int allocate_cache_info(int cpu)
>  int fetch_cache_info(unsigned int cpu)
>  {
>  	struct cpu_cacheinfo *this_cpu_ci;
> -	unsigned int levels, split_levels;
> +	unsigned int levels = 0, split_levels = 0;
>  	int ret;
>  
>  	if (acpi_disabled) {
> -- 
> 2.25.1
> 

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2023-01-24 17:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-24 15:40 [PATCH -next v2 0/3] cacheinfo: Fix misbehaviours around init_cache_level() Pierre Gondois
2023-01-24 15:40 ` [PATCH -next v2 1/3] cacheinfo: Initialize variables in fetch_cache_info() Pierre Gondois
2023-01-24 17:19   ` Conor Dooley
2023-01-24 15:40 ` [PATCH -next v2 2/3] cacheinfo: Make default acpi_get_cache_info() return an error Pierre Gondois
2023-01-24 17:15   ` Conor Dooley
2023-01-24 15:40 ` [PATCH -next v2 3/3] cacheinfo: Remove unused check in init_cache_level() Pierre Gondois
2023-01-24 17:01   ` Conor Dooley

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).