Re: [PATCH v3 1/7] arm64: add support for the AMU extension v1

From: Valentin Schneider
Date: Wed Feb 12 2020 - 09:54:50 EST


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