* [PATCH -next v3 0/1] drivers: base: cacheinfo: fix shared_cpu_map @ 2022-12-28 3:24 Yong-Xuan Wang 2022-12-28 3:24 ` [PATCH -next v3] " Yong-Xuan Wang 0 siblings, 1 reply; 4+ messages in thread From: Yong-Xuan Wang @ 2022-12-28 3:24 UTC (permalink / raw To: Greg Kroah-Hartman, Rafael J. Wysocki, linux-kernel Cc: Pierre Gondois, Sudeep Holla, Vincent Chen, Greentime Hu, Yong-Xuan Wang Thank Pierre for the semicolon ;) Changelog: --- v3 --- Remove unneeded semicolon --- v2 --- Rebase to the latest Linux codebase Yong-Xuan Wang (1): drivers: base: cacheinfo: fix shared_cpu_map drivers/base/cacheinfo.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) -- 2.17.1 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH -next v3] drivers: base: cacheinfo: fix shared_cpu_map 2022-12-28 3:24 [PATCH -next v3 0/1] drivers: base: cacheinfo: fix shared_cpu_map Yong-Xuan Wang @ 2022-12-28 3:24 ` Yong-Xuan Wang 2023-01-04 10:59 ` Sudeep Holla 0 siblings, 1 reply; 4+ messages in thread From: Yong-Xuan Wang @ 2022-12-28 3:24 UTC (permalink / raw To: Greg Kroah-Hartman, Rafael J. Wysocki, linux-kernel Cc: Pierre Gondois, Sudeep Holla, Vincent Chen, Greentime Hu, Yong-Xuan Wang The cacheinfo sets up the shared_cpu_map by checking whether the caches with the same index are shared between CPUs. However, this will trigger slab-out-of-bounds access if the CPUs do not have the same cache hierarchy. Another problem is the mismatched shared_cpu_map when the shared cache does not have the same index between CPUs. CPU0 I D L3 index 0 1 2 x ^ ^ ^ ^ index 0 1 2 3 CPU1 I D L2 L3 This patch checks each cache is shared with all caches on other CPUs. Reviewed-by: Pierre Gondois <pierre.gondois@arm.com> Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> --- drivers/base/cacheinfo.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c index 950b22cdb5f7..dfa804bcf3cc 100644 --- a/drivers/base/cacheinfo.c +++ b/drivers/base/cacheinfo.c @@ -256,7 +256,7 @@ static int cache_shared_cpu_map_setup(unsigned int cpu) { struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); struct cacheinfo *this_leaf, *sib_leaf; - unsigned int index; + unsigned int index, sib_index; int ret = 0; if (this_cpu_ci->cpu_map_populated) @@ -284,11 +284,12 @@ static int cache_shared_cpu_map_setup(unsigned int cpu) if (i == cpu || !sib_cpu_ci->info_list) continue;/* skip if itself or no cacheinfo */ - - sib_leaf = per_cpu_cacheinfo_idx(i, index); - if (cache_leaves_are_shared(this_leaf, sib_leaf)) { - cpumask_set_cpu(cpu, &sib_leaf->shared_cpu_map); - cpumask_set_cpu(i, &this_leaf->shared_cpu_map); + for (sib_index = 0; sib_index < cache_leaves(i); sib_index++) { + sib_leaf = per_cpu_cacheinfo_idx(i, sib_index); + if (cache_leaves_are_shared(this_leaf, sib_leaf)) { + cpumask_set_cpu(cpu, &sib_leaf->shared_cpu_map); + cpumask_set_cpu(i, &this_leaf->shared_cpu_map); + } } } /* record the maximum cache line size */ @@ -302,7 +303,7 @@ static int cache_shared_cpu_map_setup(unsigned int cpu) static void cache_shared_cpu_map_remove(unsigned int cpu) { struct cacheinfo *this_leaf, *sib_leaf; - unsigned int sibling, index; + unsigned int sibling, index, sib_index; for (index = 0; index < cache_leaves(cpu); index++) { this_leaf = per_cpu_cacheinfo_idx(cpu, index); @@ -313,9 +314,13 @@ static void cache_shared_cpu_map_remove(unsigned int cpu) if (sibling == cpu || !sib_cpu_ci->info_list) continue;/* skip if itself or no cacheinfo */ - sib_leaf = per_cpu_cacheinfo_idx(sibling, index); - cpumask_clear_cpu(cpu, &sib_leaf->shared_cpu_map); - cpumask_clear_cpu(sibling, &this_leaf->shared_cpu_map); + for (sib_index = 0; sib_index < cache_leaves(sibling); sib_index++) { + sib_leaf = per_cpu_cacheinfo_idx(sibling, sib_index); + if (cache_leaves_are_shared(this_leaf, sib_leaf)) { + cpumask_clear_cpu(cpu, &sib_leaf->shared_cpu_map); + cpumask_clear_cpu(sibling, &this_leaf->shared_cpu_map); + } + } } } } base-commit: c76083fac3bae1a87ae3d005b5cb1cbc761e31d5 -- 2.17.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH -next v3] drivers: base: cacheinfo: fix shared_cpu_map 2022-12-28 3:24 ` [PATCH -next v3] " Yong-Xuan Wang @ 2023-01-04 10:59 ` Sudeep Holla 2023-01-17 10:02 ` Yong Xuan Wang 0 siblings, 1 reply; 4+ messages in thread From: Sudeep Holla @ 2023-01-04 10:59 UTC (permalink / raw To: Yong-Xuan Wang Cc: Greg Kroah-Hartman, Rafael J. Wysocki, linux-kernel, Sudeep Holla, Pierre Gondois, Vincent Chen, Greentime Hu On Wed, Dec 28, 2022 at 03:24:19AM +0000, Yong-Xuan Wang wrote: > The cacheinfo sets up the shared_cpu_map by checking whether the caches > with the same index are shared between CPUs. However, this will trigger > slab-out-of-bounds access if the CPUs do not have the same cache hierarchy. > Another problem is the mismatched shared_cpu_map when the shared cache does > not have the same index between CPUs. > > CPU0 I D L3 > index 0 1 2 x > ^ ^ ^ ^ > index 0 1 2 3 > CPU1 I D L2 L3 > > This patch checks each cache is shared with all caches on other CPUs. > Just curious to know if this is just Qemu config or a real platform. I had intentionally not supported this to just to get to know when such h/w appears in the real world 😁. > Reviewed-by: Pierre Gondois <pierre.gondois@arm.com> > Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> > --- > drivers/base/cacheinfo.c | 25 +++++++++++++++---------- > 1 file changed, 15 insertions(+), 10 deletions(-) > > diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c > index 950b22cdb5f7..dfa804bcf3cc 100644 > --- a/drivers/base/cacheinfo.c > +++ b/drivers/base/cacheinfo.c > @@ -256,7 +256,7 @@ static int cache_shared_cpu_map_setup(unsigned int cpu) > { > struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); > struct cacheinfo *this_leaf, *sib_leaf; > - unsigned int index; > + unsigned int index, sib_index; > int ret = 0; > > if (this_cpu_ci->cpu_map_populated) > @@ -284,11 +284,12 @@ static int cache_shared_cpu_map_setup(unsigned int cpu) > > if (i == cpu || !sib_cpu_ci->info_list) > continue;/* skip if itself or no cacheinfo */ > - > - sib_leaf = per_cpu_cacheinfo_idx(i, index); > - if (cache_leaves_are_shared(this_leaf, sib_leaf)) { > - cpumask_set_cpu(cpu, &sib_leaf->shared_cpu_map); > - cpumask_set_cpu(i, &this_leaf->shared_cpu_map); > + for (sib_index = 0; sib_index < cache_leaves(i); sib_index++) { > + sib_leaf = per_cpu_cacheinfo_idx(i, sib_index); > + if (cache_leaves_are_shared(this_leaf, sib_leaf)) { > + cpumask_set_cpu(cpu, &sib_leaf->shared_cpu_map); > + cpumask_set_cpu(i, &this_leaf->shared_cpu_map); Does it make sense to break here once we match as it is unlikely to match with any other indices ? > + } > } > } > /* record the maximum cache line size */ > @@ -302,7 +303,7 @@ static int cache_shared_cpu_map_setup(unsigned int cpu) > static void cache_shared_cpu_map_remove(unsigned int cpu) > { > struct cacheinfo *this_leaf, *sib_leaf; > - unsigned int sibling, index; > + unsigned int sibling, index, sib_index; > > for (index = 0; index < cache_leaves(cpu); index++) { > this_leaf = per_cpu_cacheinfo_idx(cpu, index); > @@ -313,9 +314,13 @@ static void cache_shared_cpu_map_remove(unsigned int cpu) > if (sibling == cpu || !sib_cpu_ci->info_list) > continue;/* skip if itself or no cacheinfo */ > > - sib_leaf = per_cpu_cacheinfo_idx(sibling, index); > - cpumask_clear_cpu(cpu, &sib_leaf->shared_cpu_map); > - cpumask_clear_cpu(sibling, &this_leaf->shared_cpu_map); > + for (sib_index = 0; sib_index < cache_leaves(sibling); sib_index++) { > + sib_leaf = per_cpu_cacheinfo_idx(sibling, sib_index); > + if (cache_leaves_are_shared(this_leaf, sib_leaf)) { > + cpumask_clear_cpu(cpu, &sib_leaf->shared_cpu_map); > + cpumask_clear_cpu(sibling, &this_leaf->shared_cpu_map); Same comment as above. -- Regards, Sudeep ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH -next v3] drivers: base: cacheinfo: fix shared_cpu_map 2023-01-04 10:59 ` Sudeep Holla @ 2023-01-17 10:02 ` Yong Xuan Wang 0 siblings, 0 replies; 4+ messages in thread From: Yong Xuan Wang @ 2023-01-17 10:02 UTC (permalink / raw To: Sudeep Holla Cc: Greg Kroah-Hartman, Rafael J. Wysocki, linux-kernel, Pierre Gondois, Vincent Chen, Greentime Hu Hi Sudeep, > On Wed, Jan 4, 2023 at 6:59 PM Sudeep Holla <sudeep.holla@arm.com> wrote: > > On Wed, Dec 28, 2022 at 03:24:19AM +0000, Yong-Xuan Wang wrote: > > The cacheinfo sets up the shared_cpu_map by checking whether the caches > > with the same index are shared between CPUs. However, this will trigger > > slab-out-of-bounds access if the CPUs do not have the same cache hierarchy. > > Another problem is the mismatched shared_cpu_map when the shared cache does > > not have the same index between CPUs. > > > > CPU0 I D L3 > > index 0 1 2 x > > ^ ^ ^ ^ > > index 0 1 2 3 > > CPU1 I D L2 L3 > > > > This patch checks each cache is shared with all caches on other CPUs. > > > > Just curious to know if this is just Qemu config or a real platform. > I had intentionally not supported this to just to get to know when such > h/w appears in the real world 😁. > We are trying to build such kind of config in QEMU. > > Reviewed-by: Pierre Gondois <pierre.gondois@arm.com> > > Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> > > --- > > drivers/base/cacheinfo.c | 25 +++++++++++++++---------- > > 1 file changed, 15 insertions(+), 10 deletions(-) > > > > diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c > > index 950b22cdb5f7..dfa804bcf3cc 100644 > > --- a/drivers/base/cacheinfo.c > > +++ b/drivers/base/cacheinfo.c > > @@ -256,7 +256,7 @@ static int cache_shared_cpu_map_setup(unsigned int cpu) > > { > > struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); > > struct cacheinfo *this_leaf, *sib_leaf; > > - unsigned int index; > > + unsigned int index, sib_index; > > int ret = 0; > > > > if (this_cpu_ci->cpu_map_populated) > > @@ -284,11 +284,12 @@ static int cache_shared_cpu_map_setup(unsigned int cpu) > > > > if (i == cpu || !sib_cpu_ci->info_list) > > continue;/* skip if itself or no cacheinfo */ > > - > > - sib_leaf = per_cpu_cacheinfo_idx(i, index); > > - if (cache_leaves_are_shared(this_leaf, sib_leaf)) { > > - cpumask_set_cpu(cpu, &sib_leaf->shared_cpu_map); > > - cpumask_set_cpu(i, &this_leaf->shared_cpu_map); > > + for (sib_index = 0; sib_index < cache_leaves(i); sib_index++) { > > + sib_leaf = per_cpu_cacheinfo_idx(i, sib_index); > > + if (cache_leaves_are_shared(this_leaf, sib_leaf)) { > > + cpumask_set_cpu(cpu, &sib_leaf->shared_cpu_map); > > + cpumask_set_cpu(i, &this_leaf->shared_cpu_map); > > Does it make sense to break here once we match as it is unlikely to match > with any other indices ? > Yeah. We can break here once we find the shared instance. I'll send a new version to fix it. Thank you! > > + } > > } > > } > > /* record the maximum cache line size */ > > @@ -302,7 +303,7 @@ static int cache_shared_cpu_map_setup(unsigned int cpu) > > static void cache_shared_cpu_map_remove(unsigned int cpu) > > { > > struct cacheinfo *this_leaf, *sib_leaf; > > - unsigned int sibling, index; > > + unsigned int sibling, index, sib_index; > > > > for (index = 0; index < cache_leaves(cpu); index++) { > > this_leaf = per_cpu_cacheinfo_idx(cpu, index); > > @@ -313,9 +314,13 @@ static void cache_shared_cpu_map_remove(unsigned int cpu) > > if (sibling == cpu || !sib_cpu_ci->info_list) > > continue;/* skip if itself or no cacheinfo */ > > > > - sib_leaf = per_cpu_cacheinfo_idx(sibling, index); > > - cpumask_clear_cpu(cpu, &sib_leaf->shared_cpu_map); > > - cpumask_clear_cpu(sibling, &this_leaf->shared_cpu_map); > > + for (sib_index = 0; sib_index < cache_leaves(sibling); sib_index++) { > > + sib_leaf = per_cpu_cacheinfo_idx(sibling, sib_index); > > + if (cache_leaves_are_shared(this_leaf, sib_leaf)) { > > + cpumask_clear_cpu(cpu, &sib_leaf->shared_cpu_map); > > + cpumask_clear_cpu(sibling, &this_leaf->shared_cpu_map); > > Same comment as above. > > -- > Regards, > Sudeep Regards, Yong-Xuan ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-01-17 10:03 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-12-28 3:24 [PATCH -next v3 0/1] drivers: base: cacheinfo: fix shared_cpu_map Yong-Xuan Wang 2022-12-28 3:24 ` [PATCH -next v3] " Yong-Xuan Wang 2023-01-04 10:59 ` Sudeep Holla 2023-01-17 10:02 ` Yong Xuan Wang
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.