linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/etnaviv: fix perfmon domain interation
@ 2020-05-11 12:38 Christian Gmeiner
  2020-05-15 10:09 ` Christian Gmeiner
  0 siblings, 1 reply; 11+ messages in thread
From: Christian Gmeiner @ 2020-05-11 12:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Christian Gmeiner, Paul Cercueil, stable, Lucas Stach,
	Russell King, David Airlie, Daniel Vetter, etnaviv, dri-devel

The GC860 has one GPU device which has a 2d and 3d core. In this case
we want to expose perfmon information for both cores.

The driver has one array which contains all possible perfmon domains
with some meta data - doms_meta. Here we can see that for the GC860
two elements of that array are relevant:

  doms_3d: is at index 0 in the doms_meta array with 8 perfmon domains
  doms_2d: is at index 1 in the doms_meta array with 1 perfmon domain

The userspace driver wants to get a list of all perfmon domains and
their perfmon signals. This is done by iterating over all domains and
their signals. If the userspace driver wants to access the domain with
id 8 the kernel driver fails and returns invalid data from doms_3d with
and invalid offset.

This results in:
  Unable to handle kernel paging request at virtual address 00000000

On such a device it is not possible to use the userspace driver at all.

The fix for this off-by-one error is quite simple.

Reported-by: Paul Cercueil <paul@crapouillou.net>
Tested-by: Paul Cercueil <paul@crapouillou.net>
Fixes: ed1dd899baa3 ("drm/etnaviv: rework perfmon query infrastructure")
Cc: stable@vger.kernel.org
Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
---
 drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
index e6795bafcbb9..35f7171e779a 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
@@ -453,7 +453,7 @@ static const struct etnaviv_pm_domain *pm_domain(const struct etnaviv_gpu *gpu,
 		if (!(gpu->identity.features & meta->feature))
 			continue;
 
-		if (meta->nr_domains < (index - offset)) {
+		if ((meta->nr_domains - 1) < (index - offset)) {
 			offset += meta->nr_domains;
 			continue;
 		}
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] drm/etnaviv: fix perfmon domain interation
  2020-05-11 12:38 [PATCH] drm/etnaviv: fix perfmon domain interation Christian Gmeiner
@ 2020-05-15 10:09 ` Christian Gmeiner
  2020-05-15 10:12   ` Paul Cercueil
  0 siblings, 1 reply; 11+ messages in thread
From: Christian Gmeiner @ 2020-05-15 10:09 UTC (permalink / raw)
  To: LKML
  Cc: Paul Cercueil, stable, Lucas Stach, Russell King, David Airlie,
	Daniel Vetter, The etnaviv authors, DRI mailing list

Am Mo., 11. Mai 2020 um 14:38 Uhr schrieb Christian Gmeiner
<christian.gmeiner@gmail.com>:
>
> The GC860 has one GPU device which has a 2d and 3d core. In this case
> we want to expose perfmon information for both cores.
>
> The driver has one array which contains all possible perfmon domains
> with some meta data - doms_meta. Here we can see that for the GC860
> two elements of that array are relevant:
>
>   doms_3d: is at index 0 in the doms_meta array with 8 perfmon domains
>   doms_2d: is at index 1 in the doms_meta array with 1 perfmon domain
>
> The userspace driver wants to get a list of all perfmon domains and
> their perfmon signals. This is done by iterating over all domains and
> their signals. If the userspace driver wants to access the domain with
> id 8 the kernel driver fails and returns invalid data from doms_3d with
> and invalid offset.
>
> This results in:
>   Unable to handle kernel paging request at virtual address 00000000
>
> On such a device it is not possible to use the userspace driver at all.
>
> The fix for this off-by-one error is quite simple.
>
> Reported-by: Paul Cercueil <paul@crapouillou.net>
> Tested-by: Paul Cercueil <paul@crapouillou.net>
> Fixes: ed1dd899baa3 ("drm/etnaviv: rework perfmon query infrastructure")
> Cc: stable@vger.kernel.org
> Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
> ---
>  drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> index e6795bafcbb9..35f7171e779a 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> @@ -453,7 +453,7 @@ static const struct etnaviv_pm_domain *pm_domain(const struct etnaviv_gpu *gpu,
>                 if (!(gpu->identity.features & meta->feature))
>                         continue;
>
> -               if (meta->nr_domains < (index - offset)) {
> +               if ((meta->nr_domains - 1) < (index - offset)) {
>                         offset += meta->nr_domains;
>                         continue;
>                 }
> --
> 2.26.2
>

ping

-- 
greets
--
Christian Gmeiner, MSc

https://christian-gmeiner.info/privacypolicy

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] drm/etnaviv: fix perfmon domain interation
  2020-05-15 10:09 ` Christian Gmeiner
@ 2020-05-15 10:12   ` Paul Cercueil
  2020-05-15 10:24     ` Lucas Stach
  2020-05-15 10:26     ` Christian Gmeiner
  0 siblings, 2 replies; 11+ messages in thread
From: Paul Cercueil @ 2020-05-15 10:12 UTC (permalink / raw)
  To: Christian Gmeiner
  Cc: LKML, stable, Lucas Stach, Russell King, David Airlie,
	Daniel Vetter, The etnaviv authors, DRI mailing list

Hi Christian,

Le ven. 15 mai 2020 à 12:09, Christian Gmeiner 
<christian.gmeiner@gmail.com> a écrit :
> Am Mo., 11. Mai 2020 um 14:38 Uhr schrieb Christian Gmeiner
> <christian.gmeiner@gmail.com>:
>> 
>>  The GC860 has one GPU device which has a 2d and 3d core. In this 
>> case
>>  we want to expose perfmon information for both cores.
>> 
>>  The driver has one array which contains all possible perfmon domains
>>  with some meta data - doms_meta. Here we can see that for the GC860
>>  two elements of that array are relevant:
>> 
>>    doms_3d: is at index 0 in the doms_meta array with 8 perfmon 
>> domains
>>    doms_2d: is at index 1 in the doms_meta array with 1 perfmon 
>> domain
>> 
>>  The userspace driver wants to get a list of all perfmon domains and
>>  their perfmon signals. This is done by iterating over all domains 
>> and
>>  their signals. If the userspace driver wants to access the domain 
>> with
>>  id 8 the kernel driver fails and returns invalid data from doms_3d 
>> with
>>  and invalid offset.
>> 
>>  This results in:
>>    Unable to handle kernel paging request at virtual address 00000000
>> 
>>  On such a device it is not possible to use the userspace driver at 
>> all.
>> 
>>  The fix for this off-by-one error is quite simple.
>> 
>>  Reported-by: Paul Cercueil <paul@crapouillou.net>
>>  Tested-by: Paul Cercueil <paul@crapouillou.net>
>>  Fixes: ed1dd899baa3 ("drm/etnaviv: rework perfmon query 
>> infrastructure")
>>  Cc: stable@vger.kernel.org
>>  Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
>>  ---
>>   drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>>  diff --git a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c 
>> b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
>>  index e6795bafcbb9..35f7171e779a 100644
>>  --- a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
>>  +++ b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
>>  @@ -453,7 +453,7 @@ static const struct etnaviv_pm_domain 
>> *pm_domain(const struct etnaviv_gpu *gpu,
>>                  if (!(gpu->identity.features & meta->feature))
>>                          continue;
>> 
>>  -               if (meta->nr_domains < (index - offset)) {
>>  +               if ((meta->nr_domains - 1) < (index - offset)) {
>>                          offset += meta->nr_domains;
>>                          continue;
>>                  }
>>  --
>>  2.26.2
>> 
> 
> ping

I'll merge it tomorrow if there's no further feedback.

-Paul



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] drm/etnaviv: fix perfmon domain interation
  2020-05-15 10:12   ` Paul Cercueil
@ 2020-05-15 10:24     ` Lucas Stach
  2020-05-15 10:27       ` Christian Gmeiner
  2020-05-15 10:26     ` Christian Gmeiner
  1 sibling, 1 reply; 11+ messages in thread
From: Lucas Stach @ 2020-05-15 10:24 UTC (permalink / raw)
  To: Paul Cercueil, Christian Gmeiner
  Cc: LKML, stable, Russell King, David Airlie, Daniel Vetter,
	The etnaviv authors, DRI mailing list

Am Freitag, den 15.05.2020, 12:12 +0200 schrieb Paul Cercueil:
> Hi Christian,
> 
> Le ven. 15 mai 2020 à 12:09, Christian Gmeiner 
> <christian.gmeiner@gmail.com> a écrit :
> > Am Mo., 11. Mai 2020 um 14:38 Uhr schrieb Christian Gmeiner
> > <christian.gmeiner@gmail.com>:
> > >  The GC860 has one GPU device which has a 2d and 3d core. In this 
> > > case
> > >  we want to expose perfmon information for both cores.
> > > 
> > >  The driver has one array which contains all possible perfmon domains
> > >  with some meta data - doms_meta. Here we can see that for the GC860
> > >  two elements of that array are relevant:
> > > 
> > >    doms_3d: is at index 0 in the doms_meta array with 8 perfmon 
> > > domains
> > >    doms_2d: is at index 1 in the doms_meta array with 1 perfmon 
> > > domain
> > > 
> > >  The userspace driver wants to get a list of all perfmon domains and
> > >  their perfmon signals. This is done by iterating over all domains 
> > > and
> > >  their signals. If the userspace driver wants to access the domain 
> > > with
> > >  id 8 the kernel driver fails and returns invalid data from doms_3d 
> > > with
> > >  and invalid offset.
> > > 
> > >  This results in:
> > >    Unable to handle kernel paging request at virtual address 00000000
> > > 
> > >  On such a device it is not possible to use the userspace driver at 
> > > all.
> > > 
> > >  The fix for this off-by-one error is quite simple.
> > > 
> > >  Reported-by: Paul Cercueil <paul@crapouillou.net>
> > >  Tested-by: Paul Cercueil <paul@crapouillou.net>
> > >  Fixes: ed1dd899baa3 ("drm/etnaviv: rework perfmon query 
> > > infrastructure")
> > >  Cc: stable@vger.kernel.org
> > >  Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
> > >  ---
> > >   drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 2 +-
> > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > >  diff --git a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c 
> > > b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > >  index e6795bafcbb9..35f7171e779a 100644
> > >  --- a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > >  +++ b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > >  @@ -453,7 +453,7 @@ static const struct etnaviv_pm_domain 
> > > *pm_domain(const struct etnaviv_gpu *gpu,
> > >                  if (!(gpu->identity.features & meta->feature))
> > >                          continue;
> > > 
> > >  -               if (meta->nr_domains < (index - offset)) {
> > >  +               if ((meta->nr_domains - 1) < (index - offset)) {
> > >                          offset += meta->nr_domains;
> > >                          continue;
> > >                  }
> > >  --
> > >  2.26.2
> > > 
> > 
> > ping
> 
> I'll merge it tomorrow if there's no further feedback.

Huh? Etnaviv patches are going through the etnaviv tree.

We now have two different solutions to the same issue. I first want to
dig into the code to see why two developers can get confused enough by
the code to come up with totally different fixes.

Regards,
Lucas


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] drm/etnaviv: fix perfmon domain interation
  2020-05-15 10:12   ` Paul Cercueil
  2020-05-15 10:24     ` Lucas Stach
@ 2020-05-15 10:26     ` Christian Gmeiner
  1 sibling, 0 replies; 11+ messages in thread
From: Christian Gmeiner @ 2020-05-15 10:26 UTC (permalink / raw)
  To: Paul Cercueil
  Cc: LKML, stable, Lucas Stach, Russell King, David Airlie,
	Daniel Vetter, The etnaviv authors, DRI mailing list

Hi Paul

Am Fr., 15. Mai 2020 um 12:12 Uhr schrieb Paul Cercueil <paul@crapouillou.net>:
>
> Hi Christian,
>
> Le ven. 15 mai 2020 à 12:09, Christian Gmeiner
> <christian.gmeiner@gmail.com> a écrit :
> > Am Mo., 11. Mai 2020 um 14:38 Uhr schrieb Christian Gmeiner
> > <christian.gmeiner@gmail.com>:
> >>
> >>  The GC860 has one GPU device which has a 2d and 3d core. In this
> >> case
> >>  we want to expose perfmon information for both cores.
> >>
> >>  The driver has one array which contains all possible perfmon domains
> >>  with some meta data - doms_meta. Here we can see that for the GC860
> >>  two elements of that array are relevant:
> >>
> >>    doms_3d: is at index 0 in the doms_meta array with 8 perfmon
> >> domains
> >>    doms_2d: is at index 1 in the doms_meta array with 1 perfmon
> >> domain
> >>
> >>  The userspace driver wants to get a list of all perfmon domains and
> >>  their perfmon signals. This is done by iterating over all domains
> >> and
> >>  their signals. If the userspace driver wants to access the domain
> >> with
> >>  id 8 the kernel driver fails and returns invalid data from doms_3d
> >> with
> >>  and invalid offset.
> >>
> >>  This results in:
> >>    Unable to handle kernel paging request at virtual address 00000000
> >>
> >>  On such a device it is not possible to use the userspace driver at
> >> all.
> >>
> >>  The fix for this off-by-one error is quite simple.
> >>
> >>  Reported-by: Paul Cercueil <paul@crapouillou.net>
> >>  Tested-by: Paul Cercueil <paul@crapouillou.net>
> >>  Fixes: ed1dd899baa3 ("drm/etnaviv: rework perfmon query
> >> infrastructure")
> >>  Cc: stable@vger.kernel.org
> >>  Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
> >>  ---
> >>   drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 2 +-
> >>   1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >>  diff --git a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> >> b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> >>  index e6795bafcbb9..35f7171e779a 100644
> >>  --- a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> >>  +++ b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> >>  @@ -453,7 +453,7 @@ static const struct etnaviv_pm_domain
> >> *pm_domain(const struct etnaviv_gpu *gpu,
> >>                  if (!(gpu->identity.features & meta->feature))
> >>                          continue;
> >>
> >>  -               if (meta->nr_domains < (index - offset)) {
> >>  +               if ((meta->nr_domains - 1) < (index - offset)) {
> >>                          offset += meta->nr_domains;
> >>                          continue;
> >>                  }
> >>  --
> >>  2.26.2
> >>
> >
> > ping
>
> I'll merge it tomorrow if there's no further feedback.
>

Works for me too.. as far as Lucas (the maintainer) is happy with it.

-- 
greets
--
Christian Gmeiner, MSc

https://christian-gmeiner.info/privacypolicy

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] drm/etnaviv: fix perfmon domain interation
  2020-05-15 10:24     ` Lucas Stach
@ 2020-05-15 10:27       ` Christian Gmeiner
  2020-05-15 10:33         ` Lucas Stach
  0 siblings, 1 reply; 11+ messages in thread
From: Christian Gmeiner @ 2020-05-15 10:27 UTC (permalink / raw)
  To: Lucas Stach
  Cc: Paul Cercueil, LKML, stable, Russell King, David Airlie,
	Daniel Vetter, The etnaviv authors, DRI mailing list

Am Fr., 15. Mai 2020 um 12:24 Uhr schrieb Lucas Stach <l.stach@pengutronix.de>:
>
> Am Freitag, den 15.05.2020, 12:12 +0200 schrieb Paul Cercueil:
> > Hi Christian,
> >
> > Le ven. 15 mai 2020 à 12:09, Christian Gmeiner
> > <christian.gmeiner@gmail.com> a écrit :
> > > Am Mo., 11. Mai 2020 um 14:38 Uhr schrieb Christian Gmeiner
> > > <christian.gmeiner@gmail.com>:
> > > >  The GC860 has one GPU device which has a 2d and 3d core. In this
> > > > case
> > > >  we want to expose perfmon information for both cores.
> > > >
> > > >  The driver has one array which contains all possible perfmon domains
> > > >  with some meta data - doms_meta. Here we can see that for the GC860
> > > >  two elements of that array are relevant:
> > > >
> > > >    doms_3d: is at index 0 in the doms_meta array with 8 perfmon
> > > > domains
> > > >    doms_2d: is at index 1 in the doms_meta array with 1 perfmon
> > > > domain
> > > >
> > > >  The userspace driver wants to get a list of all perfmon domains and
> > > >  their perfmon signals. This is done by iterating over all domains
> > > > and
> > > >  their signals. If the userspace driver wants to access the domain
> > > > with
> > > >  id 8 the kernel driver fails and returns invalid data from doms_3d
> > > > with
> > > >  and invalid offset.
> > > >
> > > >  This results in:
> > > >    Unable to handle kernel paging request at virtual address 00000000
> > > >
> > > >  On such a device it is not possible to use the userspace driver at
> > > > all.
> > > >
> > > >  The fix for this off-by-one error is quite simple.
> > > >
> > > >  Reported-by: Paul Cercueil <paul@crapouillou.net>
> > > >  Tested-by: Paul Cercueil <paul@crapouillou.net>
> > > >  Fixes: ed1dd899baa3 ("drm/etnaviv: rework perfmon query
> > > > infrastructure")
> > > >  Cc: stable@vger.kernel.org
> > > >  Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
> > > >  ---
> > > >   drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 2 +-
> > > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > >  diff --git a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > > > b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > > >  index e6795bafcbb9..35f7171e779a 100644
> > > >  --- a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > > >  +++ b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > > >  @@ -453,7 +453,7 @@ static const struct etnaviv_pm_domain
> > > > *pm_domain(const struct etnaviv_gpu *gpu,
> > > >                  if (!(gpu->identity.features & meta->feature))
> > > >                          continue;
> > > >
> > > >  -               if (meta->nr_domains < (index - offset)) {
> > > >  +               if ((meta->nr_domains - 1) < (index - offset)) {
> > > >                          offset += meta->nr_domains;
> > > >                          continue;
> > > >                  }
> > > >  --
> > > >  2.26.2
> > > >
> > >
> > > ping
> >
> > I'll merge it tomorrow if there's no further feedback.
>
> Huh? Etnaviv patches are going through the etnaviv tree.
>
> We now have two different solutions to the same issue. I first want to
> dig into the code to see why two developers can get confused enough by
> the code to come up with totally different fixes.
>

You will see that the solutions are not totally different. I really hoped to
get this fixed in the 5.7 release.. but I think its now too late.

-- 
greets
--
Christian Gmeiner, MSc

https://christian-gmeiner.info/privacypolicy

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] drm/etnaviv: fix perfmon domain interation
  2020-05-15 10:27       ` Christian Gmeiner
@ 2020-05-15 10:33         ` Lucas Stach
  2020-05-15 10:44           ` Christian Gmeiner
  0 siblings, 1 reply; 11+ messages in thread
From: Lucas Stach @ 2020-05-15 10:33 UTC (permalink / raw)
  To: Christian Gmeiner
  Cc: Paul Cercueil, LKML, stable, Russell King, David Airlie,
	Daniel Vetter, The etnaviv authors, DRI mailing list

Am Freitag, den 15.05.2020, 12:27 +0200 schrieb Christian Gmeiner:
> Am Fr., 15. Mai 2020 um 12:24 Uhr schrieb Lucas Stach <l.stach@pengutronix.de>:
> > Am Freitag, den 15.05.2020, 12:12 +0200 schrieb Paul Cercueil:
> > > Hi Christian,
> > > 
> > > Le ven. 15 mai 2020 à 12:09, Christian Gmeiner
> > > <christian.gmeiner@gmail.com> a écrit :
> > > > Am Mo., 11. Mai 2020 um 14:38 Uhr schrieb Christian Gmeiner
> > > > <christian.gmeiner@gmail.com>:
> > > > >  The GC860 has one GPU device which has a 2d and 3d core. In this
> > > > > case
> > > > >  we want to expose perfmon information for both cores.
> > > > > 
> > > > >  The driver has one array which contains all possible perfmon domains
> > > > >  with some meta data - doms_meta. Here we can see that for the GC860
> > > > >  two elements of that array are relevant:
> > > > > 
> > > > >    doms_3d: is at index 0 in the doms_meta array with 8 perfmon
> > > > > domains
> > > > >    doms_2d: is at index 1 in the doms_meta array with 1 perfmon
> > > > > domain
> > > > > 
> > > > >  The userspace driver wants to get a list of all perfmon domains and
> > > > >  their perfmon signals. This is done by iterating over all domains
> > > > > and
> > > > >  their signals. If the userspace driver wants to access the domain
> > > > > with
> > > > >  id 8 the kernel driver fails and returns invalid data from doms_3d
> > > > > with
> > > > >  and invalid offset.
> > > > > 
> > > > >  This results in:
> > > > >    Unable to handle kernel paging request at virtual address 00000000
> > > > > 
> > > > >  On such a device it is not possible to use the userspace driver at
> > > > > all.
> > > > > 
> > > > >  The fix for this off-by-one error is quite simple.
> > > > > 
> > > > >  Reported-by: Paul Cercueil <paul@crapouillou.net>
> > > > >  Tested-by: Paul Cercueil <paul@crapouillou.net>
> > > > >  Fixes: ed1dd899baa3 ("drm/etnaviv: rework perfmon query
> > > > > infrastructure")
> > > > >  Cc: stable@vger.kernel.org
> > > > >  Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
> > > > >  ---
> > > > >   drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 2 +-
> > > > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > > > > 
> > > > >  diff --git a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > > > > b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > > > >  index e6795bafcbb9..35f7171e779a 100644
> > > > >  --- a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > > > >  +++ b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > > > >  @@ -453,7 +453,7 @@ static const struct etnaviv_pm_domain
> > > > > *pm_domain(const struct etnaviv_gpu *gpu,
> > > > >                  if (!(gpu->identity.features & meta->feature))
> > > > >                          continue;
> > > > > 
> > > > >  -               if (meta->nr_domains < (index - offset)) {
> > > > >  +               if ((meta->nr_domains - 1) < (index - offset)) {
> > > > >                          offset += meta->nr_domains;
> > > > >                          continue;
> > > > >                  }
> > > > >  --
> > > > >  2.26.2
> > > > > 
> > > > 
> > > > ping
> > > 
> > > I'll merge it tomorrow if there's no further feedback.
> > 
> > Huh? Etnaviv patches are going through the etnaviv tree.
> > 
> > We now have two different solutions to the same issue. I first want to
> > dig into the code to see why two developers can get confused enough by
> > the code to come up with totally different fixes.
> > 
> 
> You will see that the solutions are not totally different. I really hoped to
> get this fixed in the 5.7 release.. but I think its now too late.

I didn't have time to look at the full picture, yet. We still have at
least a week until the final 5.7 release, why would it be too late to
get a fix upstream?

Regards,
Lucas


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] drm/etnaviv: fix perfmon domain interation
  2020-05-15 10:33         ` Lucas Stach
@ 2020-05-15 10:44           ` Christian Gmeiner
  0 siblings, 0 replies; 11+ messages in thread
From: Christian Gmeiner @ 2020-05-15 10:44 UTC (permalink / raw)
  To: Lucas Stach
  Cc: Paul Cercueil, LKML, stable, Russell King, David Airlie,
	Daniel Vetter, The etnaviv authors, DRI mailing list

Am Fr., 15. Mai 2020 um 12:33 Uhr schrieb Lucas Stach <l.stach@pengutronix.de>:
>
> Am Freitag, den 15.05.2020, 12:27 +0200 schrieb Christian Gmeiner:
> > Am Fr., 15. Mai 2020 um 12:24 Uhr schrieb Lucas Stach <l.stach@pengutronix.de>:
> > > Am Freitag, den 15.05.2020, 12:12 +0200 schrieb Paul Cercueil:
> > > > Hi Christian,
> > > >
> > > > Le ven. 15 mai 2020 à 12:09, Christian Gmeiner
> > > > <christian.gmeiner@gmail.com> a écrit :
> > > > > Am Mo., 11. Mai 2020 um 14:38 Uhr schrieb Christian Gmeiner
> > > > > <christian.gmeiner@gmail.com>:
> > > > > >  The GC860 has one GPU device which has a 2d and 3d core. In this
> > > > > > case
> > > > > >  we want to expose perfmon information for both cores.
> > > > > >
> > > > > >  The driver has one array which contains all possible perfmon domains
> > > > > >  with some meta data - doms_meta. Here we can see that for the GC860
> > > > > >  two elements of that array are relevant:
> > > > > >
> > > > > >    doms_3d: is at index 0 in the doms_meta array with 8 perfmon
> > > > > > domains
> > > > > >    doms_2d: is at index 1 in the doms_meta array with 1 perfmon
> > > > > > domain
> > > > > >
> > > > > >  The userspace driver wants to get a list of all perfmon domains and
> > > > > >  their perfmon signals. This is done by iterating over all domains
> > > > > > and
> > > > > >  their signals. If the userspace driver wants to access the domain
> > > > > > with
> > > > > >  id 8 the kernel driver fails and returns invalid data from doms_3d
> > > > > > with
> > > > > >  and invalid offset.
> > > > > >
> > > > > >  This results in:
> > > > > >    Unable to handle kernel paging request at virtual address 00000000
> > > > > >
> > > > > >  On such a device it is not possible to use the userspace driver at
> > > > > > all.
> > > > > >
> > > > > >  The fix for this off-by-one error is quite simple.
> > > > > >
> > > > > >  Reported-by: Paul Cercueil <paul@crapouillou.net>
> > > > > >  Tested-by: Paul Cercueil <paul@crapouillou.net>
> > > > > >  Fixes: ed1dd899baa3 ("drm/etnaviv: rework perfmon query
> > > > > > infrastructure")
> > > > > >  Cc: stable@vger.kernel.org
> > > > > >  Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
> > > > > >  ---
> > > > > >   drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 2 +-
> > > > > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > > > > >
> > > > > >  diff --git a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > > > > > b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > > > > >  index e6795bafcbb9..35f7171e779a 100644
> > > > > >  --- a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > > > > >  +++ b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > > > > >  @@ -453,7 +453,7 @@ static const struct etnaviv_pm_domain
> > > > > > *pm_domain(const struct etnaviv_gpu *gpu,
> > > > > >                  if (!(gpu->identity.features & meta->feature))
> > > > > >                          continue;
> > > > > >
> > > > > >  -               if (meta->nr_domains < (index - offset)) {
> > > > > >  +               if ((meta->nr_domains - 1) < (index - offset)) {
> > > > > >                          offset += meta->nr_domains;
> > > > > >                          continue;
> > > > > >                  }
> > > > > >  --
> > > > > >  2.26.2
> > > > > >
> > > > >
> > > > > ping
> > > >
> > > > I'll merge it tomorrow if there's no further feedback.
> > >
> > > Huh? Etnaviv patches are going through the etnaviv tree.
> > >
> > > We now have two different solutions to the same issue. I first want to
> > > dig into the code to see why two developers can get confused enough by
> > > the code to come up with totally different fixes.
> > >
> >
> > You will see that the solutions are not totally different. I really hoped to
> > get this fixed in the 5.7 release.. but I think its now too late.
>
> I didn't have time to look at the full picture, yet. We still have at
> least a week until the final 5.7 release, why would it be too late to
> get a fix upstream?
>

Great - so I count on you that we will have a fix in 5.7 release.

-- 
greets
--
Christian Gmeiner, MSc

https://christian-gmeiner.info/privacypolicy

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] drm/etnaviv: fix perfmon domain interation
  2020-05-17 12:03 ` Lucas Stach
@ 2020-05-18  8:49   ` Christian Gmeiner
  0 siblings, 0 replies; 11+ messages in thread
From: Christian Gmeiner @ 2020-05-18  8:49 UTC (permalink / raw)
  To: Lucas Stach
  Cc: LKML, Paul Cercueil, Russell King, David Airlie, Daniel Vetter,
	The etnaviv authors, DRI mailing list

Hi Lucas,

Am So., 17. Mai 2020 um 14:03 Uhr schrieb Lucas Stach <l.stach@pengutronix.de>:
>
> Hi Christian,
>
> Am Montag, den 11.05.2020, 14:37 +0200 schrieb Christian Gmeiner:
> > The GC860 has one GPU device which has a 2d and 3d core. In this case
> > we want to expose perfmon information for both cores.
> >
> > The driver has one array which contains all possible perfmon domains
> > with some meta data - doms_meta. Here we can see that for the GC860
> > two elements of that array are relevant:
> >
> >   doms_3d: is at index 0 in the doms_meta array with 8 perfmon domains
> >   doms_2d: is at index 1 in the doms_meta array with 1 perfmon domain
> >
> > The userspace driver wants to get a list of all perfmon domains and
> > their perfmon signals. This is done by iterating over all domains and
> > their signals. If the userspace driver wants to access the domain with
> > id 8 the kernel driver fails and returns invalid data from doms_3d with
> > and invalid offset.
> >
> > This results in:
> >   Unable to handle kernel paging request at virtual address 00000000
> >
> > On such a device it is not possible to use the userspace driver at all.
> >
> > The fix for this off-by-one error is quite simple.
> >
> > Reported-by: Paul Cercueil <paul@crapouillou.net>
> > Tested-by: Paul Cercueil <paul@crapouillou.net>
> > Fixes: ed1dd899baa3 ("drm/etnaviv: rework perfmon query infrastructure")
> > Cc: stable@vger.kernel.or
>
> Missing last letter of the TLD.
>
> > Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
> > ---
> >  drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > index e6795bafcbb9..35f7171e779a 100644
> > --- a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > +++ b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > @@ -453,7 +453,7 @@ static const struct etnaviv_pm_domain *pm_domain(const struct etnaviv_gpu *gpu,
> >               if (!(gpu->identity.features & meta->feature))
> >                       continue;
> >
> > -             if (meta->nr_domains < (index - offset)) {
> > +             if ((meta->nr_domains - 1) < (index - offset)) {
>
> While the logic is correct, I find this quite hard to read. A more
> idiomatic way to write this (which is much easier to grok when reading
> the code IMHO) would be:
>
> if (index - offset >= meta->nr_domains)
>
> If you agree, please send a v2 of this patch.
>

Works for me - will send a v2 in the evening.

-- 
greets
--
Christian Gmeiner, MSc

https://christian-gmeiner.info/privacypolicy

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] drm/etnaviv: fix perfmon domain interation
  2020-05-11 12:37 Christian Gmeiner
@ 2020-05-17 12:03 ` Lucas Stach
  2020-05-18  8:49   ` Christian Gmeiner
  0 siblings, 1 reply; 11+ messages in thread
From: Lucas Stach @ 2020-05-17 12:03 UTC (permalink / raw)
  To: Christian Gmeiner, linux-kernel
  Cc: Paul Cercueil, Russell King, David Airlie, Daniel Vetter,
	etnaviv, dri-devel

Hi Christian,

Am Montag, den 11.05.2020, 14:37 +0200 schrieb Christian Gmeiner:
> The GC860 has one GPU device which has a 2d and 3d core. In this case
> we want to expose perfmon information for both cores.
> 
> The driver has one array which contains all possible perfmon domains
> with some meta data - doms_meta. Here we can see that for the GC860
> two elements of that array are relevant:
> 
>   doms_3d: is at index 0 in the doms_meta array with 8 perfmon domains
>   doms_2d: is at index 1 in the doms_meta array with 1 perfmon domain
> 
> The userspace driver wants to get a list of all perfmon domains and
> their perfmon signals. This is done by iterating over all domains and
> their signals. If the userspace driver wants to access the domain with
> id 8 the kernel driver fails and returns invalid data from doms_3d with
> and invalid offset.
> 
> This results in:
>   Unable to handle kernel paging request at virtual address 00000000
> 
> On such a device it is not possible to use the userspace driver at all.
> 
> The fix for this off-by-one error is quite simple.
> 
> Reported-by: Paul Cercueil <paul@crapouillou.net>
> Tested-by: Paul Cercueil <paul@crapouillou.net>
> Fixes: ed1dd899baa3 ("drm/etnaviv: rework perfmon query infrastructure")
> Cc: stable@vger.kernel.or

Missing last letter of the TLD.

> Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
> ---
>  drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> index e6795bafcbb9..35f7171e779a 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> @@ -453,7 +453,7 @@ static const struct etnaviv_pm_domain *pm_domain(const struct etnaviv_gpu *gpu,
>  		if (!(gpu->identity.features & meta->feature))
>  			continue;
>  
> -		if (meta->nr_domains < (index - offset)) {
> +		if ((meta->nr_domains - 1) < (index - offset)) {

While the logic is correct, I find this quite hard to read. A more
idiomatic way to write this (which is much easier to grok when reading
the code IMHO) would be:

if (index - offset >= meta->nr_domains)

If you agree, please send a v2 of this patch.

Regards,
Lucas
>  			offset += meta->nr_domains;
>  			continue;
>  		}


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] drm/etnaviv: fix perfmon domain interation
@ 2020-05-11 12:37 Christian Gmeiner
  2020-05-17 12:03 ` Lucas Stach
  0 siblings, 1 reply; 11+ messages in thread
From: Christian Gmeiner @ 2020-05-11 12:37 UTC (permalink / raw)
  To: linux-kernel
  Cc: Christian Gmeiner, Paul Cercueil, stable, Lucas Stach,
	Russell King, David Airlie, Daniel Vetter, etnaviv, dri-devel

The GC860 has one GPU device which has a 2d and 3d core. In this case
we want to expose perfmon information for both cores.

The driver has one array which contains all possible perfmon domains
with some meta data - doms_meta. Here we can see that for the GC860
two elements of that array are relevant:

  doms_3d: is at index 0 in the doms_meta array with 8 perfmon domains
  doms_2d: is at index 1 in the doms_meta array with 1 perfmon domain

The userspace driver wants to get a list of all perfmon domains and
their perfmon signals. This is done by iterating over all domains and
their signals. If the userspace driver wants to access the domain with
id 8 the kernel driver fails and returns invalid data from doms_3d with
and invalid offset.

This results in:
  Unable to handle kernel paging request at virtual address 00000000

On such a device it is not possible to use the userspace driver at all.

The fix for this off-by-one error is quite simple.

Reported-by: Paul Cercueil <paul@crapouillou.net>
Tested-by: Paul Cercueil <paul@crapouillou.net>
Fixes: ed1dd899baa3 ("drm/etnaviv: rework perfmon query infrastructure")
Cc: stable@vger.kernel.or
Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
---
 drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
index e6795bafcbb9..35f7171e779a 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
@@ -453,7 +453,7 @@ static const struct etnaviv_pm_domain *pm_domain(const struct etnaviv_gpu *gpu,
 		if (!(gpu->identity.features & meta->feature))
 			continue;
 
-		if (meta->nr_domains < (index - offset)) {
+		if ((meta->nr_domains - 1) < (index - offset)) {
 			offset += meta->nr_domains;
 			continue;
 		}
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-05-18  8:49 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-11 12:38 [PATCH] drm/etnaviv: fix perfmon domain interation Christian Gmeiner
2020-05-15 10:09 ` Christian Gmeiner
2020-05-15 10:12   ` Paul Cercueil
2020-05-15 10:24     ` Lucas Stach
2020-05-15 10:27       ` Christian Gmeiner
2020-05-15 10:33         ` Lucas Stach
2020-05-15 10:44           ` Christian Gmeiner
2020-05-15 10:26     ` Christian Gmeiner
  -- strict thread matches above, loose matches on Subject: below --
2020-05-11 12:37 Christian Gmeiner
2020-05-17 12:03 ` Lucas Stach
2020-05-18  8:49   ` Christian Gmeiner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).