2021-07-06 09:09:11

by Alexander Antonov

[permalink] [raw]
Subject: [PATCH] perf/x86/intel/uncore: Fix IIO cleanup mapping procedure for SNR/ICX

From: Alexander Antonov <[email protected]>

Cleanup mapping procedure for IIO PMU is needed to free memory which was
allocated for topology data and for attributes in IIO mapping
attribute_group.
Current implementation of this procedure for Snowridge and Icelake Server
platforms doesn't free allocated memory that can be a reason for memory
leak issue.
Fix the issue with IIO cleanup mapping procedure for these platforms
to release allocated memory.

Fixes: 10337e95e04c ("perf/x86/intel/uncore: Enable I/O stacks to IIO PMON mapping on ICX")

Signed-off-by: Alexander Antonov <[email protected]>
---
arch/x86/events/intel/uncore_snbep.c | 40 +++++++++++++++++++---------
1 file changed, 28 insertions(+), 12 deletions(-)

diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c
index bb6eb1e5569c..54cdbb96e628 100644
--- a/arch/x86/events/intel/uncore_snbep.c
+++ b/arch/x86/events/intel/uncore_snbep.c
@@ -3836,26 +3836,32 @@ pmu_iio_set_mapping(struct intel_uncore_type *type, struct attribute_group *ag)
return ret;
}

-static int skx_iio_set_mapping(struct intel_uncore_type *type)
-{
- return pmu_iio_set_mapping(type, &skx_iio_mapping_group);
-}
-
-static void skx_iio_cleanup_mapping(struct intel_uncore_type *type)
+static void
+pmu_iio_cleanup_mapping(struct intel_uncore_type *type, struct attribute_group *ag)
{
- struct attribute **attr = skx_iio_mapping_group.attrs;
+ struct attribute **attr = ag->attrs;

if (!attr)
return;

for (; *attr; attr++)
kfree((*attr)->name);
- kfree(attr_to_ext_attr(*skx_iio_mapping_group.attrs));
- kfree(skx_iio_mapping_group.attrs);
- skx_iio_mapping_group.attrs = NULL;
+ kfree(attr_to_ext_attr(*ag->attrs));
+ kfree(ag->attrs);
+ ag->attrs = NULL;
kfree(type->topology);
}

+static int skx_iio_set_mapping(struct intel_uncore_type *type)
+{
+ return pmu_iio_set_mapping(type, &skx_iio_mapping_group);
+}
+
+static void skx_iio_cleanup_mapping(struct intel_uncore_type *type)
+{
+ pmu_iio_cleanup_mapping(type, &skx_iio_mapping_group);
+}
+
static struct intel_uncore_type skx_uncore_iio = {
.name = "iio",
.num_counters = 4,
@@ -4499,6 +4505,11 @@ static int snr_iio_set_mapping(struct intel_uncore_type *type)
return pmu_iio_set_mapping(type, &snr_iio_mapping_group);
}

+static void snr_iio_cleanup_mapping(struct intel_uncore_type *type)
+{
+ pmu_iio_cleanup_mapping(type, &snr_iio_mapping_group);
+}
+
static struct intel_uncore_type snr_uncore_iio = {
.name = "iio",
.num_counters = 4,
@@ -4515,7 +4526,7 @@ static struct intel_uncore_type snr_uncore_iio = {
.attr_update = snr_iio_attr_update,
.get_topology = snr_iio_get_topology,
.set_mapping = snr_iio_set_mapping,
- .cleanup_mapping = skx_iio_cleanup_mapping,
+ .cleanup_mapping = snr_iio_cleanup_mapping,
};

static struct intel_uncore_type snr_uncore_irp = {
@@ -5090,6 +5101,11 @@ static int icx_iio_set_mapping(struct intel_uncore_type *type)
return pmu_iio_set_mapping(type, &icx_iio_mapping_group);
}

+static void icx_iio_cleanup_mapping(struct intel_uncore_type *type)
+{
+ pmu_iio_cleanup_mapping(type, &icx_iio_mapping_group);
+}
+
static struct intel_uncore_type icx_uncore_iio = {
.name = "iio",
.num_counters = 4,
@@ -5107,7 +5123,7 @@ static struct intel_uncore_type icx_uncore_iio = {
.attr_update = icx_iio_attr_update,
.get_topology = icx_iio_get_topology,
.set_mapping = icx_iio_set_mapping,
- .cleanup_mapping = skx_iio_cleanup_mapping,
+ .cleanup_mapping = icx_iio_cleanup_mapping,
};

static struct intel_uncore_type icx_uncore_irp = {

base-commit: 3dbdb38e286903ec220aaf1fb29a8d94297da246
--
2.21.3


2021-07-06 14:42:52

by Liang, Kan

[permalink] [raw]
Subject: Re: [PATCH] perf/x86/intel/uncore: Fix IIO cleanup mapping procedure for SNR/ICX



On 7/6/2021 5:07 AM, [email protected] wrote:
> From: Alexander Antonov <[email protected]>
>
> Cleanup mapping procedure for IIO PMU is needed to free memory which was
> allocated for topology data and for attributes in IIO mapping
> attribute_group.
> Current implementation of this procedure for Snowridge and Icelake Server
> platforms doesn't free allocated memory that can be a reason for memory
> leak issue.
> Fix the issue with IIO cleanup mapping procedure for these platforms
> to release allocated memory.
>
> Fixes: 10337e95e04c ("perf/x86/intel/uncore: Enable I/O stacks to IIO PMON mapping on ICX")
>
> Signed-off-by: Alexander Antonov <[email protected]>

The patch looks good to me.

Reviewed-by: Kan Liang <[email protected]>


With this fix, there will be several similar codes repeat, e.g.,
XXX_iio_set_mapping() and XXX_iio_cleanup_mapping(), for SKX, ICX, and
SNR for now.
I guess there will be more for the future platforms. Have you considered
to add a macro or something to reduce the code repetition?

Thanks,
Kan

> ---
> arch/x86/events/intel/uncore_snbep.c | 40 +++++++++++++++++++---------
> 1 file changed, 28 insertions(+), 12 deletions(-)
>
> diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c
> index bb6eb1e5569c..54cdbb96e628 100644
> --- a/arch/x86/events/intel/uncore_snbep.c
> +++ b/arch/x86/events/intel/uncore_snbep.c
> @@ -3836,26 +3836,32 @@ pmu_iio_set_mapping(struct intel_uncore_type *type, struct attribute_group *ag)
> return ret;
> }
>
> -static int skx_iio_set_mapping(struct intel_uncore_type *type)
> -{
> - return pmu_iio_set_mapping(type, &skx_iio_mapping_group);
> -}
> -
> -static void skx_iio_cleanup_mapping(struct intel_uncore_type *type)
> +static void
> +pmu_iio_cleanup_mapping(struct intel_uncore_type *type, struct attribute_group *ag)
> {
> - struct attribute **attr = skx_iio_mapping_group.attrs;
> + struct attribute **attr = ag->attrs;
>
> if (!attr)
> return;
>
> for (; *attr; attr++)
> kfree((*attr)->name);
> - kfree(attr_to_ext_attr(*skx_iio_mapping_group.attrs));
> - kfree(skx_iio_mapping_group.attrs);
> - skx_iio_mapping_group.attrs = NULL;
> + kfree(attr_to_ext_attr(*ag->attrs));
> + kfree(ag->attrs);
> + ag->attrs = NULL;
> kfree(type->topology);
> }
>
> +static int skx_iio_set_mapping(struct intel_uncore_type *type)
> +{
> + return pmu_iio_set_mapping(type, &skx_iio_mapping_group);
> +}
> +
> +static void skx_iio_cleanup_mapping(struct intel_uncore_type *type)
> +{
> + pmu_iio_cleanup_mapping(type, &skx_iio_mapping_group);
> +}
> +
> static struct intel_uncore_type skx_uncore_iio = {
> .name = "iio",
> .num_counters = 4,
> @@ -4499,6 +4505,11 @@ static int snr_iio_set_mapping(struct intel_uncore_type *type)
> return pmu_iio_set_mapping(type, &snr_iio_mapping_group);
> }
>
> +static void snr_iio_cleanup_mapping(struct intel_uncore_type *type)
> +{
> + pmu_iio_cleanup_mapping(type, &snr_iio_mapping_group);
> +}
> +
> static struct intel_uncore_type snr_uncore_iio = {
> .name = "iio",
> .num_counters = 4,
> @@ -4515,7 +4526,7 @@ static struct intel_uncore_type snr_uncore_iio = {
> .attr_update = snr_iio_attr_update,
> .get_topology = snr_iio_get_topology,
> .set_mapping = snr_iio_set_mapping,
> - .cleanup_mapping = skx_iio_cleanup_mapping,
> + .cleanup_mapping = snr_iio_cleanup_mapping,
> };
>
> static struct intel_uncore_type snr_uncore_irp = {
> @@ -5090,6 +5101,11 @@ static int icx_iio_set_mapping(struct intel_uncore_type *type)
> return pmu_iio_set_mapping(type, &icx_iio_mapping_group);
> }
>
> +static void icx_iio_cleanup_mapping(struct intel_uncore_type *type)
> +{
> + pmu_iio_cleanup_mapping(type, &icx_iio_mapping_group);
> +}
> +
> static struct intel_uncore_type icx_uncore_iio = {
> .name = "iio",
> .num_counters = 4,
> @@ -5107,7 +5123,7 @@ static struct intel_uncore_type icx_uncore_iio = {
> .attr_update = icx_iio_attr_update,
> .get_topology = icx_iio_get_topology,
> .set_mapping = icx_iio_set_mapping,
> - .cleanup_mapping = skx_iio_cleanup_mapping,
> + .cleanup_mapping = icx_iio_cleanup_mapping,
> };
>
> static struct intel_uncore_type icx_uncore_irp = {
>
> base-commit: 3dbdb38e286903ec220aaf1fb29a8d94297da246
>

2021-07-06 14:52:08

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH] perf/x86/intel/uncore: Fix IIO cleanup mapping procedure for SNR/ICX

On Tue, Jul 06, 2021 at 12:07:23PM +0300, [email protected] wrote:
> From: Alexander Antonov <[email protected]>
>
> Cleanup mapping procedure for IIO PMU is needed to free memory which was
> allocated for topology data and for attributes in IIO mapping
> attribute_group.
> Current implementation of this procedure for Snowridge and Icelake Server
> platforms doesn't free allocated memory that can be a reason for memory
> leak issue.
> Fix the issue with IIO cleanup mapping procedure for these platforms
> to release allocated memory.
>
> Fixes: 10337e95e04c ("perf/x86/intel/uncore: Enable I/O stacks to IIO PMON mapping on ICX")
>
> Signed-off-by: Alexander Antonov <[email protected]>
> ---
> arch/x86/events/intel/uncore_snbep.c | 40 +++++++++++++++++++---------
> 1 file changed, 28 insertions(+), 12 deletions(-)
>
> diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c
> index bb6eb1e5569c..54cdbb96e628 100644
> --- a/arch/x86/events/intel/uncore_snbep.c
> +++ b/arch/x86/events/intel/uncore_snbep.c
> @@ -3836,26 +3836,32 @@ pmu_iio_set_mapping(struct intel_uncore_type *type, struct attribute_group *ag)
> return ret;
> }
>
> -static int skx_iio_set_mapping(struct intel_uncore_type *type)
> -{
> - return pmu_iio_set_mapping(type, &skx_iio_mapping_group);
> -}
> -
> -static void skx_iio_cleanup_mapping(struct intel_uncore_type *type)
> +static void
> +pmu_iio_cleanup_mapping(struct intel_uncore_type *type, struct attribute_group *ag)
> {
> - struct attribute **attr = skx_iio_mapping_group.attrs;
> + struct attribute **attr = ag->attrs;
>
> if (!attr)
> return;
>
> for (; *attr; attr++)
> kfree((*attr)->name);
> - kfree(attr_to_ext_attr(*skx_iio_mapping_group.attrs));
> - kfree(skx_iio_mapping_group.attrs);
> - skx_iio_mapping_group.attrs = NULL;
> + kfree(attr_to_ext_attr(*ag->attrs));
> + kfree(ag->attrs);
> + ag->attrs = NULL;
> kfree(type->topology);
> }
>
> +static int skx_iio_set_mapping(struct intel_uncore_type *type)
> +{
> + return pmu_iio_set_mapping(type, &skx_iio_mapping_group);
> +}
> +
> +static void skx_iio_cleanup_mapping(struct intel_uncore_type *type)
> +{
> + pmu_iio_cleanup_mapping(type, &skx_iio_mapping_group);
> +}
> +
> static struct intel_uncore_type skx_uncore_iio = {
> .name = "iio",
> .num_counters = 4,
> @@ -4499,6 +4505,11 @@ static int snr_iio_set_mapping(struct intel_uncore_type *type)
> return pmu_iio_set_mapping(type, &snr_iio_mapping_group);
> }
>
> +static void snr_iio_cleanup_mapping(struct intel_uncore_type *type)
> +{
> + pmu_iio_cleanup_mapping(type, &snr_iio_mapping_group);
> +}
> +
> static struct intel_uncore_type snr_uncore_iio = {
> .name = "iio",
> .num_counters = 4,
> @@ -4515,7 +4526,7 @@ static struct intel_uncore_type snr_uncore_iio = {
> .attr_update = snr_iio_attr_update,
> .get_topology = snr_iio_get_topology,
> .set_mapping = snr_iio_set_mapping,
> - .cleanup_mapping = skx_iio_cleanup_mapping,
> + .cleanup_mapping = snr_iio_cleanup_mapping,
> };
>
> static struct intel_uncore_type snr_uncore_irp = {
> @@ -5090,6 +5101,11 @@ static int icx_iio_set_mapping(struct intel_uncore_type *type)
> return pmu_iio_set_mapping(type, &icx_iio_mapping_group);
> }
>
> +static void icx_iio_cleanup_mapping(struct intel_uncore_type *type)
> +{
> + pmu_iio_cleanup_mapping(type, &icx_iio_mapping_group);
> +}
> +
> static struct intel_uncore_type icx_uncore_iio = {
> .name = "iio",
> .num_counters = 4,
> @@ -5107,7 +5123,7 @@ static struct intel_uncore_type icx_uncore_iio = {
> .attr_update = icx_iio_attr_update,
> .get_topology = icx_iio_get_topology,
> .set_mapping = icx_iio_set_mapping,
> - .cleanup_mapping = skx_iio_cleanup_mapping,
> + .cleanup_mapping = icx_iio_cleanup_mapping,
> };
>
> static struct intel_uncore_type icx_uncore_irp = {
>
> base-commit: 3dbdb38e286903ec220aaf1fb29a8d94297da246
> --
> 2.21.3
>

<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>

2021-07-06 16:21:14

by Alexander Antonov

[permalink] [raw]
Subject: Re: [PATCH] perf/x86/intel/uncore: Fix IIO cleanup mapping procedure for SNR/ICX


On 7/6/2021 5:12 PM, Liang, Kan wrote:
>
>
> On 7/6/2021 5:07 AM, [email protected] wrote:
>> From: Alexander Antonov <[email protected]>
>>
>> Cleanup mapping procedure for IIO PMU is needed to free memory which was
>> allocated for topology data and for attributes in IIO mapping
>> attribute_group.
>> Current implementation of this procedure for Snowridge and Icelake
>> Server
>> platforms doesn't free allocated memory that can be a reason for memory
>> leak issue.
>> Fix the issue with IIO cleanup mapping procedure for these platforms
>> to release allocated memory.
>>
>> Fixes: 10337e95e04c ("perf/x86/intel/uncore: Enable I/O stacks to IIO
>> PMON mapping on ICX")
>>
>> Signed-off-by: Alexander Antonov <[email protected]>
>
> The patch looks good to me.
>
> Reviewed-by: Kan Liang <[email protected]>
>
>
> With this fix, there will be several similar codes repeat, e.g.,
> XXX_iio_set_mapping() and XXX_iio_cleanup_mapping(), for SKX, ICX, and
> SNR for now.
> I guess there will be more for the future platforms. Have you
> considered to add a macro or something to reduce the code repetition?
>
> Thanks,
> Kan

That's a good idea.
I suggest to do it together with enabling of mapping on future
platforms. What do you think?

Thanks,
Alexander

>
>> ---
>>   arch/x86/events/intel/uncore_snbep.c | 40 +++++++++++++++++++---------
>>   1 file changed, 28 insertions(+), 12 deletions(-)
>>
>> diff --git a/arch/x86/events/intel/uncore_snbep.c
>> b/arch/x86/events/intel/uncore_snbep.c
>> index bb6eb1e5569c..54cdbb96e628 100644
>> --- a/arch/x86/events/intel/uncore_snbep.c
>> +++ b/arch/x86/events/intel/uncore_snbep.c
>> @@ -3836,26 +3836,32 @@ pmu_iio_set_mapping(struct intel_uncore_type
>> *type, struct attribute_group *ag)
>>       return ret;
>>   }
>>   -static int skx_iio_set_mapping(struct intel_uncore_type *type)
>> -{
>> -    return pmu_iio_set_mapping(type, &skx_iio_mapping_group);
>> -}
>> -
>> -static void skx_iio_cleanup_mapping(struct intel_uncore_type *type)
>> +static void
>> +pmu_iio_cleanup_mapping(struct intel_uncore_type *type, struct
>> attribute_group *ag)
>>   {
>> -    struct attribute **attr = skx_iio_mapping_group.attrs;
>> +    struct attribute **attr = ag->attrs;
>>         if (!attr)
>>           return;
>>         for (; *attr; attr++)
>>           kfree((*attr)->name);
>> -    kfree(attr_to_ext_attr(*skx_iio_mapping_group.attrs));
>> -    kfree(skx_iio_mapping_group.attrs);
>> -    skx_iio_mapping_group.attrs = NULL;
>> +    kfree(attr_to_ext_attr(*ag->attrs));
>> +    kfree(ag->attrs);
>> +    ag->attrs = NULL;
>>       kfree(type->topology);
>>   }
>>   +static int skx_iio_set_mapping(struct intel_uncore_type *type)
>> +{
>> +    return pmu_iio_set_mapping(type, &skx_iio_mapping_group);
>> +}
>> +
>> +static void skx_iio_cleanup_mapping(struct intel_uncore_type *type)
>> +{
>> +    pmu_iio_cleanup_mapping(type, &skx_iio_mapping_group);
>> +}
>> +
>>   static struct intel_uncore_type skx_uncore_iio = {
>>       .name            = "iio",
>>       .num_counters        = 4,
>> @@ -4499,6 +4505,11 @@ static int snr_iio_set_mapping(struct
>> intel_uncore_type *type)
>>       return pmu_iio_set_mapping(type, &snr_iio_mapping_group);
>>   }
>>   +static void snr_iio_cleanup_mapping(struct intel_uncore_type *type)
>> +{
>> +    pmu_iio_cleanup_mapping(type, &snr_iio_mapping_group);
>> +}
>> +
>>   static struct intel_uncore_type snr_uncore_iio = {
>>       .name            = "iio",
>>       .num_counters        = 4,
>> @@ -4515,7 +4526,7 @@ static struct intel_uncore_type snr_uncore_iio = {
>>       .attr_update        = snr_iio_attr_update,
>>       .get_topology        = snr_iio_get_topology,
>>       .set_mapping        = snr_iio_set_mapping,
>> -    .cleanup_mapping    = skx_iio_cleanup_mapping,
>> +    .cleanup_mapping    = snr_iio_cleanup_mapping,
>>   };
>>     static struct intel_uncore_type snr_uncore_irp = {
>> @@ -5090,6 +5101,11 @@ static int icx_iio_set_mapping(struct
>> intel_uncore_type *type)
>>       return pmu_iio_set_mapping(type, &icx_iio_mapping_group);
>>   }
>>   +static void icx_iio_cleanup_mapping(struct intel_uncore_type *type)
>> +{
>> +    pmu_iio_cleanup_mapping(type, &icx_iio_mapping_group);
>> +}
>> +
>>   static struct intel_uncore_type icx_uncore_iio = {
>>       .name            = "iio",
>>       .num_counters        = 4,
>> @@ -5107,7 +5123,7 @@ static struct intel_uncore_type icx_uncore_iio = {
>>       .attr_update        = icx_iio_attr_update,
>>       .get_topology        = icx_iio_get_topology,
>>       .set_mapping        = icx_iio_set_mapping,
>> -    .cleanup_mapping    = skx_iio_cleanup_mapping,
>> +    .cleanup_mapping    = icx_iio_cleanup_mapping,
>>   };
>>     static struct intel_uncore_type icx_uncore_irp = {
>>
>> base-commit: 3dbdb38e286903ec220aaf1fb29a8d94297da246
>>

2021-07-06 18:44:16

by Liang, Kan

[permalink] [raw]
Subject: Re: [PATCH] perf/x86/intel/uncore: Fix IIO cleanup mapping procedure for SNR/ICX



On 7/6/2021 12:17 PM, Alexander Antonov wrote:
>
> On 7/6/2021 5:12 PM, Liang, Kan wrote:
>>
>>
>> On 7/6/2021 5:07 AM, [email protected] wrote:
>>> From: Alexander Antonov <[email protected]>
>>>
>>> Cleanup mapping procedure for IIO PMU is needed to free memory which was
>>> allocated for topology data and for attributes in IIO mapping
>>> attribute_group.
>>> Current implementation of this procedure for Snowridge and Icelake
>>> Server
>>> platforms doesn't free allocated memory that can be a reason for memory
>>> leak issue.
>>> Fix the issue with IIO cleanup mapping procedure for these platforms
>>> to release allocated memory.
>>>
>>> Fixes: 10337e95e04c ("perf/x86/intel/uncore: Enable I/O stacks to IIO
>>> PMON mapping on ICX")
>>>
>>> Signed-off-by: Alexander Antonov <[email protected]>
>>
>> The patch looks good to me.
>>
>> Reviewed-by: Kan Liang <[email protected]>
>>
>>
>> With this fix, there will be several similar codes repeat, e.g.,
>> XXX_iio_set_mapping() and XXX_iio_cleanup_mapping(), for SKX, ICX, and
>> SNR for now.
>> I guess there will be more for the future platforms. Have you
>> considered to add a macro or something to reduce the code repetition?
>>
>> Thanks,
>> Kan
>
> That's a good idea.
> I suggest to do it together with enabling of mapping on future
> platforms. What do you think?
>

It's OK for me.

Thanks.
Kan
>
>>
>>> ---
>>>   arch/x86/events/intel/uncore_snbep.c | 40 +++++++++++++++++++---------
>>>   1 file changed, 28 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/arch/x86/events/intel/uncore_snbep.c
>>> b/arch/x86/events/intel/uncore_snbep.c
>>> index bb6eb1e5569c..54cdbb96e628 100644
>>> --- a/arch/x86/events/intel/uncore_snbep.c
>>> +++ b/arch/x86/events/intel/uncore_snbep.c
>>> @@ -3836,26 +3836,32 @@ pmu_iio_set_mapping(struct intel_uncore_type
>>> *type, struct attribute_group *ag)
>>>       return ret;
>>>   }
>>>   -static int skx_iio_set_mapping(struct intel_uncore_type *type)
>>> -{
>>> -    return pmu_iio_set_mapping(type, &skx_iio_mapping_group);
>>> -}
>>> -
>>> -static void skx_iio_cleanup_mapping(struct intel_uncore_type *type)
>>> +static void
>>> +pmu_iio_cleanup_mapping(struct intel_uncore_type *type, struct
>>> attribute_group *ag)
>>>   {
>>> -    struct attribute **attr = skx_iio_mapping_group.attrs;
>>> +    struct attribute **attr = ag->attrs;
>>>         if (!attr)
>>>           return;
>>>         for (; *attr; attr++)
>>>           kfree((*attr)->name);
>>> -    kfree(attr_to_ext_attr(*skx_iio_mapping_group.attrs));
>>> -    kfree(skx_iio_mapping_group.attrs);
>>> -    skx_iio_mapping_group.attrs = NULL;
>>> +    kfree(attr_to_ext_attr(*ag->attrs));
>>> +    kfree(ag->attrs);
>>> +    ag->attrs = NULL;
>>>       kfree(type->topology);
>>>   }
>>>   +static int skx_iio_set_mapping(struct intel_uncore_type *type)
>>> +{
>>> +    return pmu_iio_set_mapping(type, &skx_iio_mapping_group);
>>> +}
>>> +
>>> +static void skx_iio_cleanup_mapping(struct intel_uncore_type *type)
>>> +{
>>> +    pmu_iio_cleanup_mapping(type, &skx_iio_mapping_group);
>>> +}
>>> +
>>>   static struct intel_uncore_type skx_uncore_iio = {
>>>       .name            = "iio",
>>>       .num_counters        = 4,
>>> @@ -4499,6 +4505,11 @@ static int snr_iio_set_mapping(struct
>>> intel_uncore_type *type)
>>>       return pmu_iio_set_mapping(type, &snr_iio_mapping_group);
>>>   }
>>>   +static void snr_iio_cleanup_mapping(struct intel_uncore_type *type)
>>> +{
>>> +    pmu_iio_cleanup_mapping(type, &snr_iio_mapping_group);
>>> +}
>>> +
>>>   static struct intel_uncore_type snr_uncore_iio = {
>>>       .name            = "iio",
>>>       .num_counters        = 4,
>>> @@ -4515,7 +4526,7 @@ static struct intel_uncore_type snr_uncore_iio = {
>>>       .attr_update        = snr_iio_attr_update,
>>>       .get_topology        = snr_iio_get_topology,
>>>       .set_mapping        = snr_iio_set_mapping,
>>> -    .cleanup_mapping    = skx_iio_cleanup_mapping,
>>> +    .cleanup_mapping    = snr_iio_cleanup_mapping,
>>>   };
>>>     static struct intel_uncore_type snr_uncore_irp = {
>>> @@ -5090,6 +5101,11 @@ static int icx_iio_set_mapping(struct
>>> intel_uncore_type *type)
>>>       return pmu_iio_set_mapping(type, &icx_iio_mapping_group);
>>>   }
>>>   +static void icx_iio_cleanup_mapping(struct intel_uncore_type *type)
>>> +{
>>> +    pmu_iio_cleanup_mapping(type, &icx_iio_mapping_group);
>>> +}
>>> +
>>>   static struct intel_uncore_type icx_uncore_iio = {
>>>       .name            = "iio",
>>>       .num_counters        = 4,
>>> @@ -5107,7 +5123,7 @@ static struct intel_uncore_type icx_uncore_iio = {
>>>       .attr_update        = icx_iio_attr_update,
>>>       .get_topology        = icx_iio_get_topology,
>>>       .set_mapping        = icx_iio_set_mapping,
>>> -    .cleanup_mapping    = skx_iio_cleanup_mapping,
>>> +    .cleanup_mapping    = icx_iio_cleanup_mapping,
>>>   };
>>>     static struct intel_uncore_type icx_uncore_irp = {
>>>
>>> base-commit: 3dbdb38e286903ec220aaf1fb29a8d94297da246
>>>

2021-07-07 11:45:52

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [PATCH] perf/x86/intel/uncore: Fix IIO cleanup mapping procedure for SNR/ICX

On Tue, Jul 06, 2021 at 10:12:55AM -0400, Liang, Kan wrote:
>
>
> On 7/6/2021 5:07 AM, [email protected] wrote:
> > From: Alexander Antonov <[email protected]>
> >
> > Cleanup mapping procedure for IIO PMU is needed to free memory which was
> > allocated for topology data and for attributes in IIO mapping
> > attribute_group.
> > Current implementation of this procedure for Snowridge and Icelake Server
> > platforms doesn't free allocated memory that can be a reason for memory
> > leak issue.
> > Fix the issue with IIO cleanup mapping procedure for these platforms
> > to release allocated memory.
> >
> > Fixes: 10337e95e04c ("perf/x86/intel/uncore: Enable I/O stacks to IIO PMON mapping on ICX")
> >
> > Signed-off-by: Alexander Antonov <[email protected]>
>
> The patch looks good to me.
>
> Reviewed-by: Kan Liang <[email protected]>

Thanks!

---
Subject: perf/x86/intel/uncore: Fix IIO cleanup mapping procedure for SNR/ICX
From: Alexander Antonov <[email protected]>
Date: Tue, 06 Jul 2021 12:07:23 +0300

From: Alexander Antonov <[email protected]>

skx_iio_cleanup_mapping() is re-used for snr and icx, but in those
cases it fails to use the appropriate XXX_iio_mapping_group and as
such fails to free previously allocated resources, leading to memory
leaks.

Fixes: 10337e95e04c ("perf/x86/intel/uncore: Enable I/O stacks to IIO PMON mapping on ICX")
Signed-off-by: Alexander Antonov <[email protected]>
[peterz: Changelog]
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Reviewed-by: Kan Liang <[email protected]>
Cc: [email protected]
Link: https://lore.kernel.org/r/[email protected]
---

Subject: [tip: perf/core] perf/x86/intel/uncore: Fix IIO cleanup mapping procedure for SNR/ICX

The following commit has been merged into the perf/core branch of tip:

Commit-ID: 3f2cbe3810a60111a33f5f6267bd5a237b826fc9
Gitweb: https://git.kernel.org/tip/3f2cbe3810a60111a33f5f6267bd5a237b826fc9
Author: Alexander Antonov <[email protected]>
AuthorDate: Tue, 06 Jul 2021 12:07:23 +03:00
Committer: Peter Zijlstra <[email protected]>
CommitterDate: Fri, 16 Jul 2021 18:46:48 +02:00

perf/x86/intel/uncore: Fix IIO cleanup mapping procedure for SNR/ICX

skx_iio_cleanup_mapping() is re-used for snr and icx, but in those
cases it fails to use the appropriate XXX_iio_mapping_group and as
such fails to free previously allocated resources, leading to memory
leaks.

Fixes: 10337e95e04c ("perf/x86/intel/uncore: Enable I/O stacks to IIO PMON mapping on ICX")
Signed-off-by: Alexander Antonov <[email protected]>
[peterz: Changelog]
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Reviewed-by: Kan Liang <[email protected]>
Cc: [email protected]
Link: https://lore.kernel.org/r/[email protected]
---
arch/x86/events/intel/uncore_snbep.c | 40 ++++++++++++++++++---------
1 file changed, 28 insertions(+), 12 deletions(-)

diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c
index 2558e26..f665b16 100644
--- a/arch/x86/events/intel/uncore_snbep.c
+++ b/arch/x86/events/intel/uncore_snbep.c
@@ -3847,26 +3847,32 @@ clear_attr_update:
return ret;
}

-static int skx_iio_set_mapping(struct intel_uncore_type *type)
-{
- return pmu_iio_set_mapping(type, &skx_iio_mapping_group);
-}
-
-static void skx_iio_cleanup_mapping(struct intel_uncore_type *type)
+static void
+pmu_iio_cleanup_mapping(struct intel_uncore_type *type, struct attribute_group *ag)
{
- struct attribute **attr = skx_iio_mapping_group.attrs;
+ struct attribute **attr = ag->attrs;

if (!attr)
return;

for (; *attr; attr++)
kfree((*attr)->name);
- kfree(attr_to_ext_attr(*skx_iio_mapping_group.attrs));
- kfree(skx_iio_mapping_group.attrs);
- skx_iio_mapping_group.attrs = NULL;
+ kfree(attr_to_ext_attr(*ag->attrs));
+ kfree(ag->attrs);
+ ag->attrs = NULL;
kfree(type->topology);
}

+static int skx_iio_set_mapping(struct intel_uncore_type *type)
+{
+ return pmu_iio_set_mapping(type, &skx_iio_mapping_group);
+}
+
+static void skx_iio_cleanup_mapping(struct intel_uncore_type *type)
+{
+ pmu_iio_cleanup_mapping(type, &skx_iio_mapping_group);
+}
+
static struct intel_uncore_type skx_uncore_iio = {
.name = "iio",
.num_counters = 4,
@@ -4510,6 +4516,11 @@ static int snr_iio_set_mapping(struct intel_uncore_type *type)
return pmu_iio_set_mapping(type, &snr_iio_mapping_group);
}

+static void snr_iio_cleanup_mapping(struct intel_uncore_type *type)
+{
+ pmu_iio_cleanup_mapping(type, &snr_iio_mapping_group);
+}
+
static struct intel_uncore_type snr_uncore_iio = {
.name = "iio",
.num_counters = 4,
@@ -4526,7 +4537,7 @@ static struct intel_uncore_type snr_uncore_iio = {
.attr_update = snr_iio_attr_update,
.get_topology = snr_iio_get_topology,
.set_mapping = snr_iio_set_mapping,
- .cleanup_mapping = skx_iio_cleanup_mapping,
+ .cleanup_mapping = snr_iio_cleanup_mapping,
};

static struct intel_uncore_type snr_uncore_irp = {
@@ -5113,6 +5124,11 @@ static int icx_iio_set_mapping(struct intel_uncore_type *type)
return pmu_iio_set_mapping(type, &icx_iio_mapping_group);
}

+static void icx_iio_cleanup_mapping(struct intel_uncore_type *type)
+{
+ pmu_iio_cleanup_mapping(type, &icx_iio_mapping_group);
+}
+
static struct intel_uncore_type icx_uncore_iio = {
.name = "iio",
.num_counters = 4,
@@ -5130,7 +5146,7 @@ static struct intel_uncore_type icx_uncore_iio = {
.attr_update = icx_iio_attr_update,
.get_topology = icx_iio_get_topology,
.set_mapping = icx_iio_set_mapping,
- .cleanup_mapping = skx_iio_cleanup_mapping,
+ .cleanup_mapping = icx_iio_cleanup_mapping,
};

static struct intel_uncore_type icx_uncore_irp = {