On 12/02/2020 11:30, Suzuki Kuruppassery Poulose wrote: >> +static bool has_amu(const struct arm64_cpu_capabilities *cap, >> + int __unused) >> +{ >> + /* >> + * The AMU extension is a non-conflicting feature: the kernel can >> + * safely run a mix of CPUs with and without support for the >> + * activity monitors extension. Therefore, if not disabled through >> + * the kernel command line early parameter, enable the capability >> + * to allow any late CPU to use the feature. >> + * >> + * With this feature enabled, the cpu_enable function will be called >> + * for all CPUs that match the criteria, including secondary and >> + * hotplugged, marking this feature as present on that respective CPU. >> + * The enable function will also print a detection message. >> + */ >> + >> + if (!disable_amu && !zalloc_cpumask_var(&amu_cpus, GFP_KERNEL)) { > > This looks problematic. Don't we end up in allocating the memory during > "each CPU" check and thus leaking memory ? Do we really need to allocate > this dynamically ? > For the static vs dynamic thing, I think it's not *too* important here since we don't risk pwning the stack because of the cpumask. That said, if we are somewhat pedantic about memory usage, the static allocation is done against NR_CPUS whereas the dynamic one is done against nr_cpu_ids. Pretty inconsequential for a single cpumask, but I guess it all adds up eventually...