Skip to contentSkip to conversation

drm/malidp: Use struct drm_gem_object_funcs.get_sg_table internally

PATCH In review Thomas Zimmermann 3 participants 12 messages Aug 7, 2020 – Aug 19, 2020

Subsystems (3)
lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

PATCH 1/1 drm/malidp: Use struct drm_gem_object_funcs.get_sg_table internally

The malidp driver uses GEM object functions for callbacks. Fix it to use them internally as well.

Fixes ecdd6474644f ("drm/malidp: Use GEM CMA object functions")
Cc Thomas Zimmermann <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Liviu Dudau <[email protected]>
Cc Brian Starkey <[email protected]>
---
 drivers/gpu/drm/arm/malidp_planes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/arm/malidp_planes.c +1 -1
index ab45ac445045..351a85088d0e 100644
@@ -346,7 +346,7 @@ static bool malidp_check_pages_threshold(struct malidp_plane_state *ms,
 		if (cma_obj->sgt)
 			sgt = cma_obj->sgt;
 		else
-			sgt = obj->dev->driver->gem_prime_get_sg_table(obj);
+			sgt = obj->funcs->get_sg_table(obj);
 
 		if (!sgt)
 			return false;
Signature · 6 lines
2.28.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 18 lines · Thomas Zimmermann

The malidp driver uses GEM object functions for callbacks. Fix it to use them internally as well.

Fixes ecdd6474644f ("drm/malidp: Use GEM CMA object functions")
Cc Thomas Zimmermann <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Liviu Dudau <[email protected]>
Cc Brian Starkey <[email protected]>
---
 drivers/gpu/drm/arm/malidp_planes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/arm/malidp_planes.c +0 -0
index ab45ac445045..351a85088d0e 100644

drivers/gpu/drm/arm/malidp_planes.c static bool malidp_check_pages_threshold(struct malidp_plane_state *ms, · line 349

Quoted 5 lines
drivers/gpu/drm/arm/malidp_planes.c +1 -1
@@ -346,7 +346,7 @@ static bool malidp_check_pages_threshold(struct malidp_plane_state *ms,
 		if (cma_obj->sgt)
 			sgt = cma_obj->sgt;
 		else
-			sgt = obj->dev->driver->gem_prime_get_sg_table(obj);
+			sgt = obj->funcs->get_sg_table(obj);

Uh if there's not a switch somewhere I'd just call the right function directly. Or call the right wrapper for this, this feels a bit fishy ... -Daniel

Quoted 6 lines
drivers/gpu/drm/arm/malidp_planes.c +0 -0
 		if (!sgt)
 			return false;
Signature · 1 line
2.28.0
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#2 lore raw

Hi

Am 07.08.20 um 15:12 schrieb Daniel Vetter:

Quoted 14 lines · Thomas Zimmermann
Quoted 13 lines

The malidp driver uses GEM object functions for callbacks. Fix it to use them internally as well.

Fixes ecdd6474644f ("drm/malidp: Use GEM CMA object functions")
Cc Thomas Zimmermann <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Liviu Dudau <[email protected]>
Cc Brian Starkey <[email protected]>
---
 drivers/gpu/drm/arm/malidp_planes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/gpu/drm/arm/malidp_planes.c static bool malidp_check_pages_threshold(struct malidp_plane_state *ms, · line 349

Quoted 10 lines
drivers/gpu/drm/arm/malidp_planes.c +1 -1
index ab45ac445045..351a85088d0e 100644
@@ -346,7 +346,7 @@ static bool malidp_check_pages_threshold(struct malidp_plane_state *ms,
 		if (cma_obj->sgt)
 			sgt = cma_obj->sgt;
 		else
-			sgt = obj->dev->driver->gem_prime_get_sg_table(obj);
+			sgt = obj->funcs->get_sg_table(obj);

Uh if there's not a switch somewhere I'd just call the right function directly. Or call the right wrapper for this, this feels a bit fishy ...

The driver initializes the pointer via CMA helper macro to an CMA-internal default. Calling the actual function here is fragile if the CMA-internal default ever changes.

But I have no strong feelings. I'll go with whatever the driver's maintainer prefers.

Best regards
Thomas

Quoted 9 lines

-Daniel

Quoted 6 lines
drivers/gpu/drm/arm/malidp_planes.c +0 -0
 		if (!sgt)
 			return false;
Signature · 1 line
2.28.0
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw
Quoted 32 lines · Thomas Zimmermann

Hi

Am 07.08.20 um 15:12 schrieb Daniel Vetter:

Quoted 14 lines · Thomas Zimmermann
Quoted 13 lines

The malidp driver uses GEM object functions for callbacks. Fix it to use them internally as well.

Fixes ecdd6474644f ("drm/malidp: Use GEM CMA object functions")
Cc Thomas Zimmermann <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Liviu Dudau <[email protected]>
Cc Brian Starkey <[email protected]>
---
 drivers/gpu/drm/arm/malidp_planes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/gpu/drm/arm/malidp_planes.c static bool malidp_check_pages_threshold(struct malidp_plane_state *ms, · line 349

Quoted 10 lines
drivers/gpu/drm/arm/malidp_planes.c +1 -1
index ab45ac445045..351a85088d0e 100644
@@ -346,7 +346,7 @@ static bool malidp_check_pages_threshold(struct malidp_plane_state *ms,
             if (cma_obj->sgt)
                     sgt = cma_obj->sgt;
             else
-                    sgt = obj->dev->driver->gem_prime_get_sg_table(obj);
+                    sgt = obj->funcs->get_sg_table(obj);

Uh if there's not a switch somewhere I'd just call the right function directly. Or call the right wrapper for this, this feels a bit fishy ...

Quoted 6 lines

The driver initializes the pointer via CMA helper macro to an CMA-internal default. Calling the actual function here is fragile if the CMA-internal default ever changes.

But I have no strong feelings. I'll go with whatever the driver's maintainer prefers.

What I meant is: There should be an exported helper to get at the sgt. Drivers using helpers shouldn't need to do this kind of stuff here.

Also the entire code is fairly suspect, getting at the sgt from plane_check is a bit iffy. But that's a different kind of problem. -Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#4 lore raw

Hi

Am 07.08.20 um 18:10 schrieb Daniel Vetter:

Quoted 37 lines · Thomas Zimmermann
Quoted 36 lines

Hi

Am 07.08.20 um 15:12 schrieb Daniel Vetter:

Quoted 14 lines · Thomas Zimmermann
Quoted 13 lines

The malidp driver uses GEM object functions for callbacks. Fix it to use them internally as well.

Fixes ecdd6474644f ("drm/malidp: Use GEM CMA object functions")
Cc Thomas Zimmermann <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Liviu Dudau <[email protected]>
Cc Brian Starkey <[email protected]>
---
 drivers/gpu/drm/arm/malidp_planes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/gpu/drm/arm/malidp_planes.c static bool malidp_check_pages_threshold(struct malidp_plane_state *ms, · line 349

Quoted 10 lines
drivers/gpu/drm/arm/malidp_planes.c +1 -1
index ab45ac445045..351a85088d0e 100644
@@ -346,7 +346,7 @@ static bool malidp_check_pages_threshold(struct malidp_plane_state *ms,
             if (cma_obj->sgt)
                     sgt = cma_obj->sgt;
             else
-                    sgt = obj->dev->driver->gem_prime_get_sg_table(obj);
+                    sgt = obj->funcs->get_sg_table(obj);

Uh if there's not a switch somewhere I'd just call the right function directly. Or call the right wrapper for this, this feels a bit fishy ...

The driver initializes the pointer via CMA helper macro to an CMA-internal default. Calling the actual function here is fragile if the CMA-internal default ever changes.

Quoted 8 lines
Quoted 2 lines

But I have no strong feelings. I'll go with whatever the driver's maintainer prefers.

What I meant is: There should be an exported helper to get at the sgt. Drivers using helpers shouldn't need to do this kind of stuff here.

Also the entire code is fairly suspect, getting at the sgt from plane_check is a bit iffy. But that's a different kind of problem.

I tried to somehow move the code to CMA, but it's not easy. There's no good place to put the look-up code of sgt. And sgt is later being freed iff it came from the callback (and not freed if it was stored in the object). AFIACT the best options are to either keep the code here or move the entire function to CMA helpers.

Best regards
Thomas

Quoted 2 lines

-Daniel

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw
Quoted 46 lines · Thomas Zimmermann

Hi

Am 07.08.20 um 18:10 schrieb Daniel Vetter:

Quoted 43 lines · Thomas Zimmermann
Quoted 32 lines

Hi

Am 07.08.20 um 15:12 schrieb Daniel Vetter:

Quoted 14 lines · Thomas Zimmermann
Quoted 13 lines

The malidp driver uses GEM object functions for callbacks. Fix it to use them internally as well.

Fixes ecdd6474644f ("drm/malidp: Use GEM CMA object functions")
Cc Thomas Zimmermann <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Liviu Dudau <[email protected]>
Cc Brian Starkey <[email protected]>
---
 drivers/gpu/drm/arm/malidp_planes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/gpu/drm/arm/malidp_planes.c static bool malidp_check_pages_threshold(struct malidp_plane_state *ms, · line 349

Quoted 10 lines
drivers/gpu/drm/arm/malidp_planes.c +1 -1
index ab45ac445045..351a85088d0e 100644
@@ -346,7 +346,7 @@ static bool malidp_check_pages_threshold(struct malidp_plane_state *ms,
             if (cma_obj->sgt)
                     sgt = cma_obj->sgt;
             else
-                    sgt = obj->dev->driver->gem_prime_get_sg_table(obj);
+                    sgt = obj->funcs->get_sg_table(obj);

Uh if there's not a switch somewhere I'd just call the right function directly. Or call the right wrapper for this, this feels a bit fishy ...

Quoted 6 lines

The driver initializes the pointer via CMA helper macro to an CMA-internal default. Calling the actual function here is fragile if the CMA-internal default ever changes.

But I have no strong feelings. I'll go with whatever the driver's maintainer prefers.

What I meant is: There should be an exported helper to get at the sgt. Drivers using helpers shouldn't need to do this kind of stuff here.

Quoted 8 lines
Quoted 2 lines

Also the entire code is fairly suspect, getting at the sgt from plane_check is a bit iffy. But that's a different kind of problem.

I tried to somehow move the code to CMA, but it's not easy. There's no good place to put the look-up code of sgt. And sgt is later being freed iff it came from the callback (and not freed if it was stored in the object). AFIACT the best options are to either keep the code here or move the entire function to CMA helpers.

Ok I read some code ... I'm confused. From the control flow it looks like malidp is using cma helpers. Otherwise why does the upcasting not blow up sometimes.

But cma helpers already check at import time that any imported dma-buf is contiguous, and they guarantee to fill out the cma_obj->sgt.

So really no idea what this code is doing here.

It's also not correct, since it doesn't coalesce sgt entries, since a range might be split up, but still mapped into a contiguous dma_addr_t range when you take it all together. The code in drm_gem_cma_prime_import_sg_table() gets this more right.

So maybe right fix is to just ditch this all, and use cma helpers fully? -Daniel

Quoted 15 lines

Best regards
Thomas

Quoted 2 lines

-Daniel

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#6 lore raw

Am 13.08.20 um 11:48 schrieb Daniel Vetter:

Quoted 63 lines · Thomas Zimmermann
Quoted 46 lines

Hi

Am 07.08.20 um 18:10 schrieb Daniel Vetter:

Quoted 43 lines · Thomas Zimmermann
Quoted 32 lines

Hi

Am 07.08.20 um 15:12 schrieb Daniel Vetter:

Quoted 14 lines · Thomas Zimmermann
Quoted 13 lines

The malidp driver uses GEM object functions for callbacks. Fix it to use them internally as well.

Fixes ecdd6474644f ("drm/malidp: Use GEM CMA object functions")
Cc Thomas Zimmermann <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Liviu Dudau <[email protected]>
Cc Brian Starkey <[email protected]>
---
 drivers/gpu/drm/arm/malidp_planes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/gpu/drm/arm/malidp_planes.c static bool malidp_check_pages_threshold(struct malidp_plane_state *ms, · line 349

Quoted 10 lines
drivers/gpu/drm/arm/malidp_planes.c +1 -1
index ab45ac445045..351a85088d0e 100644
@@ -346,7 +346,7 @@ static bool malidp_check_pages_threshold(struct malidp_plane_state *ms,
             if (cma_obj->sgt)
                     sgt = cma_obj->sgt;
             else
-                    sgt = obj->dev->driver->gem_prime_get_sg_table(obj);
+                    sgt = obj->funcs->get_sg_table(obj);

Uh if there's not a switch somewhere I'd just call the right function directly. Or call the right wrapper for this, this feels a bit fishy ...

Quoted 6 lines

The driver initializes the pointer via CMA helper macro to an CMA-internal default. Calling the actual function here is fragile if the CMA-internal default ever changes.

But I have no strong feelings. I'll go with whatever the driver's maintainer prefers.

What I meant is: There should be an exported helper to get at the sgt. Drivers using helpers shouldn't need to do this kind of stuff here.

Quoted 8 lines
Quoted 2 lines

Also the entire code is fairly suspect, getting at the sgt from plane_check is a bit iffy. But that's a different kind of problem.

I tried to somehow move the code to CMA, but it's not easy. There's no good place to put the look-up code of sgt. And sgt is later being freed iff it came from the callback (and not freed if it was stored in the object). AFIACT the best options are to either keep the code here or move the entire function to CMA helpers.

Ok I read some code ... I'm confused. From the control flow it looks like malidp is using cma helpers. Otherwise why does the upcasting not blow up sometimes.

But cma helpers already check at import time that any imported dma-buf is contiguous, and they guarantee to fill out the cma_obj->sgt.

Quoted 8 lines

So really no idea what this code is doing here.

It's also not correct, since it doesn't coalesce sgt entries, since a range might be split up, but still mapped into a contiguous dma_addr_t range when you take it all together. The code in drm_gem_cma_prime_import_sg_table() gets this more right.

So maybe right fix is to just ditch this all, and use cma helpers fully?

The driver already does use CMA, including
drm_gem_cma_prime_import_sg_table().

The patched code is not about importing/exporting sg tables. It configures the MMU's prefetching pattern by looking at some of the page sizes. I don't feel confident enough with this code to alter it. I'd expect to break the heuristics.

Best regards
Thomas

Quoted 21 lines

-Daniel

Quoted 15 lines

Best regards
Thomas

Quoted 2 lines

-Daniel

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#7 lore raw
Quoted 75 lines · Thomas Zimmermann

Am 13.08.20 um 11:48 schrieb Daniel Vetter:

Quoted 63 lines · Thomas Zimmermann
Quoted 46 lines

Hi

Am 07.08.20 um 18:10 schrieb Daniel Vetter:

Quoted 43 lines · Thomas Zimmermann
Quoted 32 lines

Hi

Am 07.08.20 um 15:12 schrieb Daniel Vetter:

Quoted 14 lines · Thomas Zimmermann
Quoted 13 lines

The malidp driver uses GEM object functions for callbacks. Fix it to use them internally as well.

Fixes ecdd6474644f ("drm/malidp: Use GEM CMA object functions")
Cc Thomas Zimmermann <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Liviu Dudau <[email protected]>
Cc Brian Starkey <[email protected]>
---
 drivers/gpu/drm/arm/malidp_planes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/gpu/drm/arm/malidp_planes.c static bool malidp_check_pages_threshold(struct malidp_plane_state *ms, · line 349

Quoted 10 lines
drivers/gpu/drm/arm/malidp_planes.c +1 -1
index ab45ac445045..351a85088d0e 100644
@@ -346,7 +346,7 @@ static bool malidp_check_pages_threshold(struct malidp_plane_state *ms,
             if (cma_obj->sgt)
                     sgt = cma_obj->sgt;
             else
-                    sgt = obj->dev->driver->gem_prime_get_sg_table(obj);
+                    sgt = obj->funcs->get_sg_table(obj);

Uh if there's not a switch somewhere I'd just call the right function directly. Or call the right wrapper for this, this feels a bit fishy ...

Quoted 6 lines

The driver initializes the pointer via CMA helper macro to an CMA-internal default. Calling the actual function here is fragile if the CMA-internal default ever changes.

But I have no strong feelings. I'll go with whatever the driver's maintainer prefers.

What I meant is: There should be an exported helper to get at the sgt. Drivers using helpers shouldn't need to do this kind of stuff here.

Quoted 8 lines
Quoted 2 lines

Also the entire code is fairly suspect, getting at the sgt from plane_check is a bit iffy. But that's a different kind of problem.

I tried to somehow move the code to CMA, but it's not easy. There's no good place to put the look-up code of sgt. And sgt is later being freed iff it came from the callback (and not freed if it was stored in the object). AFIACT the best options are to either keep the code here or move the entire function to CMA helpers.

Ok I read some code ... I'm confused. From the control flow it looks like malidp is using cma helpers. Otherwise why does the upcasting not blow up sometimes.

But cma helpers already check at import time that any imported dma-buf is contiguous, and they guarantee to fill out the cma_obj->sgt.

Quoted 8 lines

So really no idea what this code is doing here.

It's also not correct, since it doesn't coalesce sgt entries, since a range might be split up, but still mapped into a contiguous dma_addr_t range when you take it all together. The code in drm_gem_cma_prime_import_sg_table() gets this more right.

So maybe right fix is to just ditch this all, and use cma helpers fully?

Quoted 7 lines

The driver already does use CMA, including
drm_gem_cma_prime_import_sg_table().

The patched code is not about importing/exporting sg tables. It configures the MMU's prefetching pattern by looking at some of the page sizes. I don't feel confident enough with this code to alter it. I'd expect to break the heuristics.

Hm ok, no idea either.

But then we can just assume that cma_obj->sgt is always set, and we don't have to call anything. If a driver uses cma helpers, and cma doesn't set ->sgt over the lifetime of the buffer, that breaks a cma helper assumption since cma doens't support swap-out.

So converting the if to a WARN_ON and failing with an error, and then remove the else should work.
-Daniel

Quoted 34 lines

Best regards
Thomas

Quoted 21 lines

-Daniel

Quoted 15 lines

Best regards
Thomas

Quoted 2 lines

-Daniel

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#8 lore raw

Hi

Am 13.08.20 um 12:31 schrieb Daniel Vetter:

Quoted 84 lines · Thomas Zimmermann
Quoted 75 lines

Am 13.08.20 um 11:48 schrieb Daniel Vetter:

Quoted 63 lines · Thomas Zimmermann
Quoted 46 lines

Hi

Am 07.08.20 um 18:10 schrieb Daniel Vetter:

Quoted 43 lines · Thomas Zimmermann
Quoted 32 lines

Hi

Am 07.08.20 um 15:12 schrieb Daniel Vetter:

Quoted 14 lines · Thomas Zimmermann
Quoted 13 lines

The malidp driver uses GEM object functions for callbacks. Fix it to use them internally as well.

Fixes ecdd6474644f ("drm/malidp: Use GEM CMA object functions")
Cc Thomas Zimmermann <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Liviu Dudau <[email protected]>
Cc Brian Starkey <[email protected]>
---
 drivers/gpu/drm/arm/malidp_planes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/gpu/drm/arm/malidp_planes.c static bool malidp_check_pages_threshold(struct malidp_plane_state *ms, · line 349

Quoted 10 lines
drivers/gpu/drm/arm/malidp_planes.c +1 -1
index ab45ac445045..351a85088d0e 100644
@@ -346,7 +346,7 @@ static bool malidp_check_pages_threshold(struct malidp_plane_state *ms,
             if (cma_obj->sgt)
                     sgt = cma_obj->sgt;
             else
-                    sgt = obj->dev->driver->gem_prime_get_sg_table(obj);
+                    sgt = obj->funcs->get_sg_table(obj);

Uh if there's not a switch somewhere I'd just call the right function directly. Or call the right wrapper for this, this feels a bit fishy ...

Quoted 6 lines

The driver initializes the pointer via CMA helper macro to an CMA-internal default. Calling the actual function here is fragile if the CMA-internal default ever changes.

But I have no strong feelings. I'll go with whatever the driver's maintainer prefers.

What I meant is: There should be an exported helper to get at the sgt. Drivers using helpers shouldn't need to do this kind of stuff here.

Quoted 8 lines
Quoted 2 lines

Also the entire code is fairly suspect, getting at the sgt from plane_check is a bit iffy. But that's a different kind of problem.

I tried to somehow move the code to CMA, but it's not easy. There's no good place to put the look-up code of sgt. And sgt is later being freed iff it came from the callback (and not freed if it was stored in the object). AFIACT the best options are to either keep the code here or move the entire function to CMA helpers.

Ok I read some code ... I'm confused. From the control flow it looks like malidp is using cma helpers. Otherwise why does the upcasting not blow up sometimes.

But cma helpers already check at import time that any imported dma-buf is contiguous, and they guarantee to fill out the cma_obj->sgt.

Quoted 8 lines

So really no idea what this code is doing here.

It's also not correct, since it doesn't coalesce sgt entries, since a range might be split up, but still mapped into a contiguous dma_addr_t range when you take it all together. The code in drm_gem_cma_prime_import_sg_table() gets this more right.

So maybe right fix is to just ditch this all, and use cma helpers fully?

Quoted 7 lines

The driver already does use CMA, including
drm_gem_cma_prime_import_sg_table().

The patched code is not about importing/exporting sg tables. It configures the MMU's prefetching pattern by looking at some of the page sizes. I don't feel confident enough with this code to alter it. I'd expect to break the heuristics.

Quoted 6 lines

Hm ok, no idea either.

But then we can just assume that cma_obj->sgt is always set, and we don't have to call anything. If a driver uses cma helpers, and cma doesn't set ->sgt over the lifetime of the buffer, that breaks a cma helper assumption since cma doens't support swap-out.

Really? I just looked at drm_gem_cma_helper.c and ->sgt is only ever set on imports, and only freed for imported memory. I'm confused now...

Best regards
Thomas

Quoted 43 lines

So converting the if to a WARN_ON and failing with an error, and then remove the else should work.
-Daniel

Quoted 34 lines

Best regards
Thomas

Quoted 21 lines

-Daniel

Quoted 15 lines

Best regards
Thomas

Quoted 2 lines

-Daniel

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by
#9 lore raw
Quoted 90 lines · Thomas Zimmermann

Hi

Am 13.08.20 um 12:31 schrieb Daniel Vetter:

Quoted 86 lines · Thomas Zimmermann
Quoted 75 lines

Am 13.08.20 um 11:48 schrieb Daniel Vetter:

Quoted 63 lines · Thomas Zimmermann
Quoted 46 lines

Hi

Am 07.08.20 um 18:10 schrieb Daniel Vetter:

Quoted 43 lines · Thomas Zimmermann
Quoted 32 lines

Hi

Am 07.08.20 um 15:12 schrieb Daniel Vetter:

Quoted 14 lines · Thomas Zimmermann
Quoted 13 lines

The malidp driver uses GEM object functions for callbacks. Fix it to use them internally as well.

Fixes ecdd6474644f ("drm/malidp: Use GEM CMA object functions")
Cc Thomas Zimmermann <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Liviu Dudau <[email protected]>
Cc Brian Starkey <[email protected]>
---
 drivers/gpu/drm/arm/malidp_planes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/gpu/drm/arm/malidp_planes.c static bool malidp_check_pages_threshold(struct malidp_plane_state *ms, · line 349

Quoted 10 lines
drivers/gpu/drm/arm/malidp_planes.c +1 -1
index ab45ac445045..351a85088d0e 100644
@@ -346,7 +346,7 @@ static bool malidp_check_pages_threshold(struct malidp_plane_state *ms,
             if (cma_obj->sgt)
                     sgt = cma_obj->sgt;
             else
-                    sgt = obj->dev->driver->gem_prime_get_sg_table(obj);
+                    sgt = obj->funcs->get_sg_table(obj);

Uh if there's not a switch somewhere I'd just call the right function directly. Or call the right wrapper for this, this feels a bit fishy ...

Quoted 6 lines

The driver initializes the pointer via CMA helper macro to an CMA-internal default. Calling the actual function here is fragile if the CMA-internal default ever changes.

But I have no strong feelings. I'll go with whatever the driver's maintainer prefers.

What I meant is: There should be an exported helper to get at the sgt. Drivers using helpers shouldn't need to do this kind of stuff here.

Quoted 8 lines
Quoted 2 lines

Also the entire code is fairly suspect, getting at the sgt from plane_check is a bit iffy. But that's a different kind of problem.

I tried to somehow move the code to CMA, but it's not easy. There's no good place to put the look-up code of sgt. And sgt is later being freed iff it came from the callback (and not freed if it was stored in the object). AFIACT the best options are to either keep the code here or move the entire function to CMA helpers.

Ok I read some code ... I'm confused. From the control flow it looks like malidp is using cma helpers. Otherwise why does the upcasting not blow up sometimes.

But cma helpers already check at import time that any imported dma-buf is contiguous, and they guarantee to fill out the cma_obj->sgt.

Quoted 8 lines

So really no idea what this code is doing here.

It's also not correct, since it doesn't coalesce sgt entries, since a range might be split up, but still mapped into a contiguous dma_addr_t range when you take it all together. The code in drm_gem_cma_prime_import_sg_table() gets this more right.

So maybe right fix is to just ditch this all, and use cma helpers fully?

Quoted 7 lines

The driver already does use CMA, including
drm_gem_cma_prime_import_sg_table().

The patched code is not about importing/exporting sg tables. It configures the MMU's prefetching pattern by looking at some of the page sizes. I don't feel confident enough with this code to alter it. I'd expect to break the heuristics.

Hm ok, no idea either.

Quoted 7 lines
Quoted 4 lines

But then we can just assume that cma_obj->sgt is always set, and we don't have to call anything. If a driver uses cma helpers, and cma doesn't set ->sgt over the lifetime of the buffer, that breaks a cma helper assumption since cma doens't support swap-out.

Really? I just looked at drm_gem_cma_helper.c and ->sgt is only ever set on imports, and only freed for imported memory. I'm confused now...

Hm right this works differently than I thought, for native cma objects we just store padd/vaddr and that's it. Still feels wrong that malidp digs around in an internal helper that's meant for exporting as a dma-buf.

Oh well I guess this is just a very special special case.

Quoted 56 lines

Best regards
Thomas

Quoted 43 lines

So converting the if to a WARN_ON and failing with an error, and then remove the else should work.
-Daniel

Quoted 34 lines

Best regards
Thomas

Quoted 21 lines

-Daniel

Quoted 15 lines

Best regards
Thomas

Quoted 2 lines

-Daniel

--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer Acked-by
#10 lore raw
Quoted 46 lines · Daniel Vetter
Quoted 45 lines · Thomas Zimmermann

Hi

Am 13.08.20 um 12:31 schrieb Daniel Vetter:

Quoted 41 lines · Thomas Zimmermann
Quoted 40 lines

Am 13.08.20 um 11:48 schrieb Daniel Vetter:

Quoted 37 lines · Thomas Zimmermann
Quoted 36 lines

Hi

Am 07.08.20 um 18:10 schrieb Daniel Vetter:

Quoted 33 lines · Thomas Zimmermann
Quoted 32 lines

Hi

Am 07.08.20 um 15:12 schrieb Daniel Vetter:

Quoted 27 lines · Thomas Zimmermann
Quoted 18 lines

The malidp driver uses GEM object functions for callbacks. Fix it to use them internally as well.

Fixes ecdd6474644f ("drm/malidp: Use GEM CMA object functions")
Cc Thomas Zimmermann <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Liviu Dudau <[email protected]>
Cc Brian Starkey <[email protected]>
---
 drivers/gpu/drm/arm/malidp_planes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/arm/malidp_planes.c +0 -0
index ab45ac445045..351a85088d0e 100644

drivers/gpu/drm/arm/malidp_planes.c static bool malidp_check_pages_threshold(struct malidp_plane_state *ms, · line 349

Quoted 5 lines
drivers/gpu/drm/arm/malidp_planes.c +1 -1
@@ -346,7 +346,7 @@ static bool malidp_check_pages_threshold(struct malidp_plane_state *ms,
             if (cma_obj->sgt)
                     sgt = cma_obj->sgt;
             else
-                    sgt = obj->dev->driver->gem_prime_get_sg_table(obj);
+                    sgt = obj->funcs->get_sg_table(obj);

Uh if there's not a switch somewhere I'd just call the right function directly. Or call the right wrapper for this, this feels a bit fishy ...

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

The driver initializes the pointer via CMA helper macro to an CMA-internal default. Calling the actual function here is fragile if the CMA-internal default ever changes.

But I have no strong feelings. I'll go with whatever the driver's maintainer prefers.

Hi,

Sorry for the silence, I was on holiday.

Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
Quoted 4 lines
Quoted 4 lines

What I meant is: There should be an exported helper to get at the sgt. Drivers using helpers shouldn't need to do this kind of stuff here.

Quoted 8 lines
Quoted 2 lines

Also the entire code is fairly suspect, getting at the sgt from plane_check is a bit iffy. But that's a different kind of problem.

I tried to somehow move the code to CMA, but it's not easy. There's no good place to put the look-up code of sgt. And sgt is later being freed iff it came from the callback (and not freed if it was stored in the object). AFIACT the best options are to either keep the code here or move the entire function to CMA helpers.

Ok I read some code ... I'm confused. From the control flow it looks like malidp is using cma helpers. Otherwise why does the upcasting not blow up sometimes.

But cma helpers already check at import time that any imported dma-buf is contiguous, and they guarantee to fill out the cma_obj->sgt.

So really no idea what this code is doing here.

It's also not correct, since it doesn't coalesce sgt entries, since a range might be split up, but still mapped into a contiguous dma_addr_t range when you take it all together. The code in drm_gem_cma_prime_import_sg_table() gets this more right.

So maybe right fix is to just ditch this all, and use cma helpers fully?

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

The driver already does use CMA, including
drm_gem_cma_prime_import_sg_table().

The patched code is not about importing/exporting sg tables. It configures the MMU's prefetching pattern by looking at some of the page sizes. I don't feel confident enough with this code to alter it. I'd expect to break the heuristics.

That's right, this piece of code has nothing to do with importing dma-buf or checking if things are contiguous. Mali DP hardware has a prefetcher block that can generate some fake requests during vblank to get the MMU pagetables cached so that reads from the buffers can be done without waiting for page walks. The block supports two modes, a full page or partial page request (to cater for the ends of the buffer that might not be a full page).

The patch proposed looks good to me, so:

I will push the patch into drm-misc-next if Daniel has no other comments.

Best regards,
Liviu

Quoted 82 lines
Quoted 10 lines
Quoted 7 lines

Hm ok, no idea either.

But then we can just assume that cma_obj->sgt is always set, and we don't have to call anything. If a driver uses cma helpers, and cma doesn't set ->sgt over the lifetime of the buffer, that breaks a cma helper assumption since cma doens't support swap-out.

Really? I just looked at drm_gem_cma_helper.c and ->sgt is only ever set on imports, and only freed for imported memory. I'm confused now...

Hm right this works differently than I thought, for native cma objects we just store padd/vaddr and that's it. Still feels wrong that malidp digs around in an internal helper that's meant for exporting as a dma-buf.

Oh well I guess this is just a very special special case.

Quoted 56 lines

Best regards
Thomas

Quoted 43 lines

So converting the if to a WARN_ON and failing with an error, and then remove the else should work.
-Daniel

Quoted 34 lines

Best regards
Thomas

Quoted 21 lines

-Daniel

Quoted 15 lines

Best regards
Thomas

Quoted 2 lines

-Daniel

--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 12 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#11 lore raw

Hi

Am 18.08.20 um 19:15 schrieb Liviu Dudau:

Quoted 102 lines · Daniel Vetter
Quoted 46 lines · Thomas Zimmermann
Quoted 45 lines

Hi

Am 13.08.20 um 12:31 schrieb Daniel Vetter:

Quoted 41 lines · Thomas Zimmermann
Quoted 40 lines

Am 13.08.20 um 11:48 schrieb Daniel Vetter:

Quoted 37 lines · Thomas Zimmermann
Quoted 36 lines

Hi

Am 07.08.20 um 18:10 schrieb Daniel Vetter:

Quoted 33 lines · Thomas Zimmermann
Quoted 32 lines

Hi

Am 07.08.20 um 15:12 schrieb Daniel Vetter:

Quoted 27 lines · Thomas Zimmermann
Quoted 18 lines

The malidp driver uses GEM object functions for callbacks. Fix it to use them internally as well.

Fixes ecdd6474644f ("drm/malidp: Use GEM CMA object functions")
Cc Thomas Zimmermann <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Liviu Dudau <[email protected]>
Cc Brian Starkey <[email protected]>
---
 drivers/gpu/drm/arm/malidp_planes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/arm/malidp_planes.c +0 -0
index ab45ac445045..351a85088d0e 100644

drivers/gpu/drm/arm/malidp_planes.c static bool malidp_check_pages_threshold(struct malidp_plane_state *ms, · line 349

Quoted 5 lines
drivers/gpu/drm/arm/malidp_planes.c +1 -1
@@ -346,7 +346,7 @@ static bool malidp_check_pages_threshold(struct malidp_plane_state *ms,
             if (cma_obj->sgt)
                     sgt = cma_obj->sgt;
             else
-                    sgt = obj->dev->driver->gem_prime_get_sg_table(obj);
+                    sgt = obj->funcs->get_sg_table(obj);

Uh if there's not a switch somewhere I'd just call the right function directly. Or call the right wrapper for this, this feels a bit fishy ...

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

The driver initializes the pointer via CMA helper macro to an CMA-internal default. Calling the actual function here is fragile if the CMA-internal default ever changes.

But I have no strong feelings. I'll go with whatever the driver's maintainer prefers.

Hi,

Sorry for the silence, I was on holiday.

Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
Quoted 4 lines
Quoted 4 lines

What I meant is: There should be an exported helper to get at the sgt. Drivers using helpers shouldn't need to do this kind of stuff here.

Quoted 8 lines
Quoted 2 lines

Also the entire code is fairly suspect, getting at the sgt from plane_check is a bit iffy. But that's a different kind of problem.

I tried to somehow move the code to CMA, but it's not easy. There's no good place to put the look-up code of sgt. And sgt is later being freed iff it came from the callback (and not freed if it was stored in the object). AFIACT the best options are to either keep the code here or move the entire function to CMA helpers.

Ok I read some code ... I'm confused. From the control flow it looks like malidp is using cma helpers. Otherwise why does the upcasting not blow up sometimes.

But cma helpers already check at import time that any imported dma-buf is contiguous, and they guarantee to fill out the cma_obj->sgt.

So really no idea what this code is doing here.

It's also not correct, since it doesn't coalesce sgt entries, since a range might be split up, but still mapped into a contiguous dma_addr_t range when you take it all together. The code in drm_gem_cma_prime_import_sg_table() gets this more right.

So maybe right fix is to just ditch this all, and use cma helpers fully?

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

The driver already does use CMA, including
drm_gem_cma_prime_import_sg_table().

The patched code is not about importing/exporting sg tables. It configures the MMU's prefetching pattern by looking at some of the page sizes. I don't feel confident enough with this code to alter it. I'd expect to break the heuristics.

That's right, this piece of code has nothing to do with importing dma-buf or checking if things are contiguous. Mali DP hardware has a prefetcher block that can generate some fake requests during vblank to get the MMU pagetables cached so that reads from the buffers can be done without waiting for page walks. The block supports two modes, a full page or partial page request (to cater for the ends of the buffer that might not be a full page).

Quoted 5 lines

The patch proposed looks good to me, so:

I will push the patch into drm-misc-next if Daniel has no other comments.

Thanks for explaining. The patch has already been merged.

Best regards
Thomas

Quoted 87 lines

Best regards,
Liviu

Quoted 82 lines
Quoted 10 lines
Quoted 7 lines

Hm ok, no idea either.

But then we can just assume that cma_obj->sgt is always set, and we don't have to call anything. If a driver uses cma helpers, and cma doesn't set ->sgt over the lifetime of the buffer, that breaks a cma helper assumption since cma doens't support swap-out.

Really? I just looked at drm_gem_cma_helper.c and ->sgt is only ever set on imports, and only freed for imported memory. I'm confused now...

Hm right this works differently than I thought, for native cma objects we just store padd/vaddr and that's it. Still feels wrong that malidp digs around in an internal helper that's meant for exporting as a dma-buf.

Oh well I guess this is just a very special special case.

Quoted 56 lines

Best regards
Thomas

Quoted 43 lines

So converting the if to a WARN_ON and failing with an error, and then remove the else should work.
-Daniel

Quoted 34 lines

Best regards
Thomas

Quoted 21 lines

-Daniel

Quoted 15 lines

Best regards
Thomas

Quoted 2 lines

-Daniel

--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel