* [Intel-gfx] [PATCH i-g-t] intel_gpu_top: Fix cleanup on old kernels / unsupported GPU
@ 2023-01-19 15:54 Tvrtko Ursulin
2023-01-20 14:29 ` Das, Nirmoy
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Tvrtko Ursulin @ 2023-01-19 15:54 UTC (permalink / raw)
To: igt-dev, Intel-gfx
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Avoid trying to dereference null engines on exit when there are either
none which are supported, or kernel does not have i915 PMU support.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
tools/intel_gpu_top.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
index 7aa233570463..517dc2995d26 100644
--- a/tools/intel_gpu_top.c
+++ b/tools/intel_gpu_top.c
@@ -448,6 +448,9 @@ static void free_engines(struct engines *engines)
};
unsigned int i;
+ if (!engines)
+ return;
+
for (pmu = &free_list[0]; *pmu; pmu++) {
if ((*pmu)->present)
free((char *)(*pmu)->units);
@@ -2568,7 +2571,7 @@ int main(int argc, char **argv)
"Failed to detect engines! (%s)\n(Kernel 4.16 or newer is required for i915 PMU support.)\n",
strerror(errno));
ret = EXIT_FAILURE;
- goto err;
+ goto err_engines;
}
ret = pmu_init(engines);
@@ -2585,7 +2588,7 @@ int main(int argc, char **argv)
"More information can be found at 'Perf events and tool security' document:\n"
"https://www.kernel.org/doc/html/latest/admin-guide/perf-security.html\n");
ret = EXIT_FAILURE;
- goto err;
+ goto err_pmu;
}
ret = EXIT_SUCCESS;
@@ -2699,8 +2702,9 @@ int main(int argc, char **argv)
free_clients(clients);
free(codename);
-err:
+err_pmu:
free_engines(engines);
+err_engines:
free(pmu_device);
exit:
igt_devices_free();
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Intel-gfx] [PATCH i-g-t] intel_gpu_top: Fix cleanup on old kernels / unsupported GPU
2023-01-19 15:54 [Intel-gfx] [PATCH i-g-t] intel_gpu_top: Fix cleanup on old kernels / unsupported GPU Tvrtko Ursulin
@ 2023-01-20 14:29 ` Das, Nirmoy
2023-01-23 10:24 ` Tvrtko Ursulin
2023-01-23 11:15 ` Das, Nirmoy
2023-01-23 11:31 ` [Intel-gfx] [PATCH i-g-t v2] " Tvrtko Ursulin
2 siblings, 1 reply; 7+ messages in thread
From: Das, Nirmoy @ 2023-01-20 14:29 UTC (permalink / raw)
To: Tvrtko Ursulin, igt-dev, Intel-gfx
Hi Tvrtko,
On 1/19/2023 4:54 PM, Tvrtko Ursulin wrote:
> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>
> Avoid trying to dereference null engines on exit when there are either
> none which are supported, or kernel does not have i915 PMU support.
>
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> ---
> tools/intel_gpu_top.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
> index 7aa233570463..517dc2995d26 100644
> --- a/tools/intel_gpu_top.c
> +++ b/tools/intel_gpu_top.c
> @@ -448,6 +448,9 @@ static void free_engines(struct engines *engines)
> };
> unsigned int i;
>
> + if (!engines)
> + return;
> +
This check should happen before the struct pmu_counter free_list
generation.
Regards,
Nirmoy
> for (pmu = &free_list[0]; *pmu; pmu++) {
> if ((*pmu)->present)
> free((char *)(*pmu)->units);
> @@ -2568,7 +2571,7 @@ int main(int argc, char **argv)
> "Failed to detect engines! (%s)\n(Kernel 4.16 or newer is required for i915 PMU support.)\n",
> strerror(errno));
> ret = EXIT_FAILURE;
> - goto err;
> + goto err_engines;
> }
>
> ret = pmu_init(engines);
> @@ -2585,7 +2588,7 @@ int main(int argc, char **argv)
> "More information can be found at 'Perf events and tool security' document:\n"
> "https://www.kernel.org/doc/html/latest/admin-guide/perf-security.html\n");
> ret = EXIT_FAILURE;
> - goto err;
> + goto err_pmu;
> }
>
> ret = EXIT_SUCCESS;
> @@ -2699,8 +2702,9 @@ int main(int argc, char **argv)
> free_clients(clients);
>
> free(codename);
> -err:
> +err_pmu:
> free_engines(engines);
> +err_engines:
> free(pmu_device);
> exit:
> igt_devices_free();
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Intel-gfx] [PATCH i-g-t] intel_gpu_top: Fix cleanup on old kernels / unsupported GPU
2023-01-20 14:29 ` Das, Nirmoy
@ 2023-01-23 10:24 ` Tvrtko Ursulin
2023-01-23 11:09 ` Das, Nirmoy
0 siblings, 1 reply; 7+ messages in thread
From: Tvrtko Ursulin @ 2023-01-23 10:24 UTC (permalink / raw)
To: Das, Nirmoy, igt-dev, Intel-gfx
On 20/01/2023 14:29, Das, Nirmoy wrote:
> Hi Tvrtko,
>
> On 1/19/2023 4:54 PM, Tvrtko Ursulin wrote:
>> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>>
>> Avoid trying to dereference null engines on exit when there are either
>> none which are supported, or kernel does not have i915 PMU support.
>>
>> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>> ---
>> tools/intel_gpu_top.c | 10 +++++++---
>> 1 file changed, 7 insertions(+), 3 deletions(-)
>>
>> diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
>> index 7aa233570463..517dc2995d26 100644
>> --- a/tools/intel_gpu_top.c
>> +++ b/tools/intel_gpu_top.c
>> @@ -448,6 +448,9 @@ static void free_engines(struct engines *engines)
>> };
>> unsigned int i;
>> + if (!engines)
>> + return;
>> +
>
>
> This check should happen before the struct pmu_counter free_list
> generation.
I could, but it doesn't have to, not sure what reasons for should you
have in mind?
Regards,
Tvrtko
>
> Regards,
>
> Nirmoy
>
>> for (pmu = &free_list[0]; *pmu; pmu++) {
>> if ((*pmu)->present)
>> free((char *)(*pmu)->units);
>> @@ -2568,7 +2571,7 @@ int main(int argc, char **argv)
>> "Failed to detect engines! (%s)\n(Kernel 4.16 or newer
>> is required for i915 PMU support.)\n",
>> strerror(errno));
>> ret = EXIT_FAILURE;
>> - goto err;
>> + goto err_engines;
>> }
>> ret = pmu_init(engines);
>> @@ -2585,7 +2588,7 @@ int main(int argc, char **argv)
>> "More information can be found at 'Perf events and tool security'
>> document:\n"
>>
>> "https://www.kernel.org/doc/html/latest/admin-guide/perf-security.html\n");
>> ret = EXIT_FAILURE;
>> - goto err;
>> + goto err_pmu;
>> }
>> ret = EXIT_SUCCESS;
>> @@ -2699,8 +2702,9 @@ int main(int argc, char **argv)
>> free_clients(clients);
>> free(codename);
>> -err:
>> +err_pmu:
>> free_engines(engines);
>> +err_engines:
>> free(pmu_device);
>> exit:
>> igt_devices_free();
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Intel-gfx] [PATCH i-g-t] intel_gpu_top: Fix cleanup on old kernels / unsupported GPU
2023-01-23 10:24 ` Tvrtko Ursulin
@ 2023-01-23 11:09 ` Das, Nirmoy
2023-01-23 11:13 ` Das, Nirmoy
0 siblings, 1 reply; 7+ messages in thread
From: Das, Nirmoy @ 2023-01-23 11:09 UTC (permalink / raw)
To: Tvrtko Ursulin, igt-dev, Intel-gfx
Hi Tvrtko,
On 1/23/2023 11:24 AM, Tvrtko Ursulin wrote:
>
> On 20/01/2023 14:29, Das, Nirmoy wrote:
>> Hi Tvrtko,
>>
>> On 1/19/2023 4:54 PM, Tvrtko Ursulin wrote:
>>> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>>>
>>> Avoid trying to dereference null engines on exit when there are either
>>> none which are supported, or kernel does not have i915 PMU support.
>>>
>>> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>>> ---
>>> tools/intel_gpu_top.c | 10 +++++++---
>>> 1 file changed, 7 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
>>> index 7aa233570463..517dc2995d26 100644
>>> --- a/tools/intel_gpu_top.c
>>> +++ b/tools/intel_gpu_top.c
>>> @@ -448,6 +448,9 @@ static void free_engines(struct engines *engines)
>>> };
>>> unsigned int i;
>>> + if (!engines)
>>> + return;
>>> +
>>
>>
>> This check should happen before the struct pmu_counter free_list
>> generation.
>
> I could, but it doesn't have to, not sure what reasons for should you
> have in mind?
In my tree, I see:
"
static void free_engines(struct engines *engines)
{
struct pmu_counter **pmu, *free_list[] = {
&engines->r_gpu,
&engines->r_pkg,
&engines->imc_reads,
&engines->imc_writes,
NULL
};
unsigned int i;
"
Maybe I am missing something here, wouldn't those dereferences of
"engines" segfault if the engines is NULL.
Regards,
Nirmoy
>
> Regards,
>
> Tvrtko
>
>>
>> Regards,
>>
>> Nirmoy
>>
>>> for (pmu = &free_list[0]; *pmu; pmu++) {
>>> if ((*pmu)->present)
>>> free((char *)(*pmu)->units);
>>> @@ -2568,7 +2571,7 @@ int main(int argc, char **argv)
>>> "Failed to detect engines! (%s)\n(Kernel 4.16 or newer
>>> is required for i915 PMU support.)\n",
>>> strerror(errno));
>>> ret = EXIT_FAILURE;
>>> - goto err;
>>> + goto err_engines;
>>> }
>>> ret = pmu_init(engines);
>>> @@ -2585,7 +2588,7 @@ int main(int argc, char **argv)
>>> "More information can be found at 'Perf events and tool security'
>>> document:\n"
>>> "https://www.kernel.org/doc/html/latest/admin-guide/perf-security.html\n");
>>> ret = EXIT_FAILURE;
>>> - goto err;
>>> + goto err_pmu;
>>> }
>>> ret = EXIT_SUCCESS;
>>> @@ -2699,8 +2702,9 @@ int main(int argc, char **argv)
>>> free_clients(clients);
>>> free(codename);
>>> -err:
>>> +err_pmu:
>>> free_engines(engines);
>>> +err_engines:
>>> free(pmu_device);
>>> exit:
>>> igt_devices_free();
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Intel-gfx] [PATCH i-g-t] intel_gpu_top: Fix cleanup on old kernels / unsupported GPU
2023-01-23 11:09 ` Das, Nirmoy
@ 2023-01-23 11:13 ` Das, Nirmoy
0 siblings, 0 replies; 7+ messages in thread
From: Das, Nirmoy @ 2023-01-23 11:13 UTC (permalink / raw)
To: Tvrtko Ursulin, igt-dev, Intel-gfx
On 1/23/2023 12:09 PM, Das, Nirmoy wrote:
> Hi Tvrtko,
>
> On 1/23/2023 11:24 AM, Tvrtko Ursulin wrote:
>>
>> On 20/01/2023 14:29, Das, Nirmoy wrote:
>>> Hi Tvrtko,
>>>
>>> On 1/19/2023 4:54 PM, Tvrtko Ursulin wrote:
>>>> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>>>>
>>>> Avoid trying to dereference null engines on exit when there are either
>>>> none which are supported, or kernel does not have i915 PMU support.
>>>>
>>>> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>>>> ---
>>>> tools/intel_gpu_top.c | 10 +++++++---
>>>> 1 file changed, 7 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
>>>> index 7aa233570463..517dc2995d26 100644
>>>> --- a/tools/intel_gpu_top.c
>>>> +++ b/tools/intel_gpu_top.c
>>>> @@ -448,6 +448,9 @@ static void free_engines(struct engines *engines)
>>>> };
>>>> unsigned int i;
>>>> + if (!engines)
>>>> + return;
>>>> +
>>>
>>>
>>> This check should happen before the struct pmu_counter free_list
>>> generation.
>>
>> I could, but it doesn't have to, not sure what reasons for should you
>> have in mind?
>
> In my tree, I see:
>
> "
>
> static void free_engines(struct engines *engines)
>
> {
> struct pmu_counter **pmu, *free_list[] = {
> &engines->r_gpu,
> &engines->r_pkg,
> &engines->imc_reads,
> &engines->imc_writes,
> NULL
> };
>
> unsigned int i;
>
> "
>
> Maybe I am missing something here, wouldn't those dereferences of
> "engines" segfault if the engines is NULL.
Ah never mind it shouldn't matter.
>
>
> Regards,
>
> Nirmoy
>
>>
>> Regards,
>>
>> Tvrtko
>>
>>>
>>> Regards,
>>>
>>> Nirmoy
>>>
>>>> for (pmu = &free_list[0]; *pmu; pmu++) {
>>>> if ((*pmu)->present)
>>>> free((char *)(*pmu)->units);
>>>> @@ -2568,7 +2571,7 @@ int main(int argc, char **argv)
>>>> "Failed to detect engines! (%s)\n(Kernel 4.16 or
>>>> newer is required for i915 PMU support.)\n",
>>>> strerror(errno));
>>>> ret = EXIT_FAILURE;
>>>> - goto err;
>>>> + goto err_engines;
>>>> }
>>>> ret = pmu_init(engines);
>>>> @@ -2585,7 +2588,7 @@ int main(int argc, char **argv)
>>>> "More information can be found at 'Perf events and tool security'
>>>> document:\n"
>>>> "https://www.kernel.org/doc/html/latest/admin-guide/perf-security.html\n");
>>>>
>>>> ret = EXIT_FAILURE;
>>>> - goto err;
>>>> + goto err_pmu;
>>>> }
>>>> ret = EXIT_SUCCESS;
>>>> @@ -2699,8 +2702,9 @@ int main(int argc, char **argv)
>>>> free_clients(clients);
>>>> free(codename);
>>>> -err:
>>>> +err_pmu:
>>>> free_engines(engines);
>>>> +err_engines:
>>>> free(pmu_device);
>>>> exit:
>>>> igt_devices_free();
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Intel-gfx] [PATCH i-g-t] intel_gpu_top: Fix cleanup on old kernels / unsupported GPU
2023-01-19 15:54 [Intel-gfx] [PATCH i-g-t] intel_gpu_top: Fix cleanup on old kernels / unsupported GPU Tvrtko Ursulin
2023-01-20 14:29 ` Das, Nirmoy
@ 2023-01-23 11:15 ` Das, Nirmoy
2023-01-23 11:31 ` [Intel-gfx] [PATCH i-g-t v2] " Tvrtko Ursulin
2 siblings, 0 replies; 7+ messages in thread
From: Das, Nirmoy @ 2023-01-23 11:15 UTC (permalink / raw)
To: Tvrtko Ursulin, igt-dev, Intel-gfx
On 1/19/2023 4:54 PM, Tvrtko Ursulin wrote:
> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>
> Avoid trying to dereference null engines on exit when there are either
> none which are supported, or kernel does not have i915 PMU support.
>
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Acked-by: Nirmoy Das <nirmoy.das@intel.com>
> ---
> tools/intel_gpu_top.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
> index 7aa233570463..517dc2995d26 100644
> --- a/tools/intel_gpu_top.c
> +++ b/tools/intel_gpu_top.c
> @@ -448,6 +448,9 @@ static void free_engines(struct engines *engines)
> };
> unsigned int i;
>
> + if (!engines)
> + return;
> +
> for (pmu = &free_list[0]; *pmu; pmu++) {
> if ((*pmu)->present)
> free((char *)(*pmu)->units);
> @@ -2568,7 +2571,7 @@ int main(int argc, char **argv)
> "Failed to detect engines! (%s)\n(Kernel 4.16 or newer is required for i915 PMU support.)\n",
> strerror(errno));
> ret = EXIT_FAILURE;
> - goto err;
> + goto err_engines;
> }
>
> ret = pmu_init(engines);
> @@ -2585,7 +2588,7 @@ int main(int argc, char **argv)
> "More information can be found at 'Perf events and tool security' document:\n"
> "https://www.kernel.org/doc/html/latest/admin-guide/perf-security.html\n");
> ret = EXIT_FAILURE;
> - goto err;
> + goto err_pmu;
> }
>
> ret = EXIT_SUCCESS;
> @@ -2699,8 +2702,9 @@ int main(int argc, char **argv)
> free_clients(clients);
>
> free(codename);
> -err:
> +err_pmu:
> free_engines(engines);
> +err_engines:
> free(pmu_device);
> exit:
> igt_devices_free();
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Intel-gfx] [PATCH i-g-t v2] intel_gpu_top: Fix cleanup on old kernels / unsupported GPU
2023-01-19 15:54 [Intel-gfx] [PATCH i-g-t] intel_gpu_top: Fix cleanup on old kernels / unsupported GPU Tvrtko Ursulin
2023-01-20 14:29 ` Das, Nirmoy
2023-01-23 11:15 ` Das, Nirmoy
@ 2023-01-23 11:31 ` Tvrtko Ursulin
2 siblings, 0 replies; 7+ messages in thread
From: Tvrtko Ursulin @ 2023-01-23 11:31 UTC (permalink / raw)
To: igt-dev, Intel-gfx; +Cc: Nirmoy Das
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Avoid trying to dereference null engines on exit when there are either
none which are supported, or kernel does not have i915 PMU support.
Also fix a memory leak on the same failure path just so Valgrind runs are
quite.
v2:
* Fix a memory leak in the same failure mode too.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Acked-by: Nirmoy Das <nirmoy.das@intel.com> # v1
---
tools/intel_gpu_top.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
index 7aa233570463..0a1de41b3374 100644
--- a/tools/intel_gpu_top.c
+++ b/tools/intel_gpu_top.c
@@ -340,7 +340,7 @@ static struct engines *discover_engines(char *device)
d = opendir(sysfs_root);
if (!d)
- return NULL;
+ goto err;
while ((dent = readdir(d)) != NULL) {
const char *endswith = "-busy";
@@ -423,10 +423,8 @@ static struct engines *discover_engines(char *device)
}
if (ret) {
- free(engines);
errno = ret;
-
- return NULL;
+ goto err;
}
qsort(engine_ptr(engines, 0), engines->num_engines,
@@ -435,6 +433,11 @@ static struct engines *discover_engines(char *device)
engines->root = d;
return engines;
+
+err:
+ free(engines);
+
+ return NULL;
}
static void free_engines(struct engines *engines)
@@ -448,6 +451,9 @@ static void free_engines(struct engines *engines)
};
unsigned int i;
+ if (!engines)
+ return;
+
for (pmu = &free_list[0]; *pmu; pmu++) {
if ((*pmu)->present)
free((char *)(*pmu)->units);
@@ -2568,7 +2574,7 @@ int main(int argc, char **argv)
"Failed to detect engines! (%s)\n(Kernel 4.16 or newer is required for i915 PMU support.)\n",
strerror(errno));
ret = EXIT_FAILURE;
- goto err;
+ goto err_engines;
}
ret = pmu_init(engines);
@@ -2585,7 +2591,7 @@ int main(int argc, char **argv)
"More information can be found at 'Perf events and tool security' document:\n"
"https://www.kernel.org/doc/html/latest/admin-guide/perf-security.html\n");
ret = EXIT_FAILURE;
- goto err;
+ goto err_pmu;
}
ret = EXIT_SUCCESS;
@@ -2699,8 +2705,9 @@ int main(int argc, char **argv)
free_clients(clients);
free(codename);
-err:
+err_pmu:
free_engines(engines);
+err_engines:
free(pmu_device);
exit:
igt_devices_free();
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-01-23 11:31 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-19 15:54 [Intel-gfx] [PATCH i-g-t] intel_gpu_top: Fix cleanup on old kernels / unsupported GPU Tvrtko Ursulin
2023-01-20 14:29 ` Das, Nirmoy
2023-01-23 10:24 ` Tvrtko Ursulin
2023-01-23 11:09 ` Das, Nirmoy
2023-01-23 11:13 ` Das, Nirmoy
2023-01-23 11:15 ` Das, Nirmoy
2023-01-23 11:31 ` [Intel-gfx] [PATCH i-g-t v2] " Tvrtko Ursulin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox