[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240905060036.5655-2-ricardo.neri-calderon@linux.intel.com>
Date: Wed, 4 Sep 2024 23:00:33 -0700
From: Ricardo Neri <ricardo.neri-calderon@...ux.intel.com>
To: x86@...nel.org
Cc: Andreas Herrmann <aherrmann@...e.com>,
Catalin Marinas <catalin.marinas@....com>,
Chen Yu <yu.c.chen@...el.com>,
Len Brown <len.brown@...el.com>,
Radu Rendec <rrendec@...hat.com>,
Pierre Gondois <Pierre.Gondois@....com>,
Pu Wen <puwen@...on.cn>,
"Rafael J. Wysocki" <rafael.j.wysocki@...el.com>,
Sudeep Holla <sudeep.holla@....com>,
Srinivas Pandruvada <srinivas.pandruvada@...ux.intel.com>,
Will Deacon <will@...nel.org>,
Zhang Rui <rui.zhang@...el.com>,
Nikolay Borisov <nik.borisov@...e.com>,
Huang Ying <ying.huang@...el.com>,
Ricardo Neri <ricardo.neri@...el.com>,
linux-kernel@...r.kernel.org
Subject: [PATCH v6 1/4] cacheinfo: Check for null last-level cache info
Before determining the validity of the last-level cache info, ensure that
it has been allocated. Simply checking for non-zero cache_leaves() is not
sufficient, as some architectures (e.g., Intel processors) have non-zero
cache_leaves() before allocation.
Dereferencing NULL cacheinfo can occur in update_per_cpu_data_slice_size().
This function iterates over all online CPUs. However, a CPU may have come
online recently, but its cacheinfo may not have been allocated yet.
Reviewed-by: Andreas Herrmann <aherrmann@...e.de>
Reviewed-by: Sudeep Holla <sudeep.holla@....com>
Tested-by: Andreas Herrmann <aherrmann@...e.de>
Signed-off-by: Ricardo Neri <ricardo.neri-calderon@...ux.intel.com>
---
Cc: Andreas Herrmann <aherrmann@...e.com>
Cc: Catalin Marinas <catalin.marinas@....com>
Cc: Chen Yu <yu.c.chen@...el.com>
Cc: Huang Ying <ying.huang@...el.com>
Cc: Len Brown <len.brown@...el.com>
Cc: Nikolay Borisov <nik.borisov@...e.com>
Cc: Radu Rendec <rrendec@...hat.com>
Cc: Pierre Gondois <Pierre.Gondois@....com>
Cc: Pu Wen <puwen@...on.cn>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@...el.com>
Cc: Sudeep Holla <sudeep.holla@....com>
Cc: Srinivas Pandruvada <srinivas.pandruvada@...ux.intel.com>
Cc: Will Deacon <will@...nel.org>
Cc: Zhang Rui <rui.zhang@...el.com>
Cc: linux-arm-kernel@...ts.infradead.org
Cc: stable@...r.kernel.org # 6.3+
---
Changes since v5:
* Added Reviewed-by and Tested-by tags from Andreas. Thanks!
Changes since v4:
* Combined checks for per_cpu_cacheinfo() and cache_leaves() in a single
line. (Sudeep)
* Added Reviewed-by tag from Sudeep. Thanks!
Changes since v3:
* Introduced this patch.
Changes since v2:
* N/A
Changes since v1:
* N/A
---
The dereference of a NULL cacheinfo is not observed today because
cache_leaves(cpu) is zero until after init_cache_level() is called
(during the CPU hotplug callback). A subsequent changeset will set
the number of cache leaves earlier and the NULL-pointer dereference
will be observed.
---
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 23b8cba4a2a3..77f2e0f91589 100644
--- a/drivers/base/cacheinfo.c
+++ b/drivers/base/cacheinfo.c
@@ -58,7 +58,7 @@ bool last_level_cache_is_valid(unsigned int cpu)
{
struct cacheinfo *llc;
- if (!cache_leaves(cpu))
+ if (!cache_leaves(cpu) || !per_cpu_cacheinfo(cpu))
return false;
llc = per_cpu_cacheinfo_idx(cpu, cache_leaves(cpu) - 1);
--
2.34.1
Powered by blists - more mailing lists