drm: Allow DRM_IOCTL_MODE_MAP_DUMB for render nodes
Subsystems (3)
RFC 1/1 drm: Allow DRM_IOCTL_MODE_MAP_DUMB for render nodes
From: Tomasz Figa <[email protected]>
There is no particular reason to prevent userspace for using this IOCTL, considering that it already has access to other, platform-specific IOCTLs. This patch makes is possible to have the same userspace code work regardless on the underlying platform, which significantly simplifies the stack.
---
I've been looking into enabling a kms_swrast based driver for mesa on the Android platform[1].
But have come up against the issue of dumb buffer related ioctls below not being flagged with DRM_RENDER_ALLOW.
DRM_IOCTL_MODE_CREATE_DUMBDRM_IOCTL_MODE_MAP_DUMB
To be more precise, I've been seeing a failure due to DRM_IOCTL_MODE_MAP_DUMB not being allowed for /dev/dri/renderD* nodes, and used in mesa kms_sw_displaytarget_map().
As I understand it the DRM_RENDER_ALLOW flag being unset is a very intentional restriction placed on dumb buffers in order to minimize its use. But as far as alternative solutions for software renderers there seems to only be VGEM and mmap()-ing DMABUFs.
While it would be convenient from the point of view of software renderers if dumb buffers had more promiscuous permissions, it may be a hard sell upstream.
If dumb buffers aren't the way forward, what is? VGEM? Or are there any other preferable ways?
[1] https://patchwork.freedesktop.org/series/45966/
drivers/gpu/drm/drm_ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_ioctl.c +2 -2
@@ -642,8 +642,8 @@ static const struct drm_ioctl_desc drm_ioctls[] = {DRM_IOCTL_DEF (DRM_IOCTL_MODE_RMFB , drm_mode_rmfb,DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_PAGE_FLIP , drm_mode_page_flip_ioctl,DRM_MASTER |DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_DIRTYFB , drm_mode_dirtyfb_ioctl,DRM_MASTER |DRM_UNLOCKED ), -DRM_IOCTL_DEF (DRM_IOCTL_MODE_CREATE_DUMB , drm_mode_create_dumb_ioctl,DRM_UNLOCKED ), -DRM_IOCTL_DEF (DRM_IOCTL_MODE_MAP_DUMB , drm_mode_mmap_dumb_ioctl,DRM_UNLOCKED ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_CREATE_DUMB , drm_mode_create_dumb_ioctl,DRM_UNLOCKED |DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_MAP_DUMB , drm_mode_mmap_dumb_ioctl,DRM_UNLOCKED |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_DESTROY_DUMB , drm_mode_destroy_dumb_ioctl,DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_OBJ_GETPROPERTIES , drm_mode_obj_get_properties_ioctl,DRM_UNLOCKED ), DRM_IOCTL_DEF(DRM_IOCTL_MODE_OBJ_SETPROPERTY, drm_mode_obj_set_property_ioctl, DRM_MASTER|DRM_UNLOCKED),
Signature · 1 line
2.17.1
Hi,
I am running into the same problem using etnaviv on i.MX6 under Android 8.1
The mesa etnaviv code uses CREATE_DUMB / MAP_DUMB for the scanout buffers and is called from the surfaceflinger process.
But, under Android 8.1 drm_hwcomposer runs in a seperate process to surfaceflinger. Since drm_hwcomposer needs to use the KMS API it must be the DRM master, that means that surface flinger cannot be DRM master too.
Adding a render node to the imx drm device and configuring mesa to user fixes the problem but requires the render node to have access rights to use CREATE_DUMB / MAP_DUMB.
Here is my full patch:
Make imx-drm export a render node so that mesa can use it to allocate
From: Martin Fuzzey <[email protected]>
Date: 2018-07-26 15:37:28 +0200
dumb memory rather than requiring the master node.
The problem with using the master node is that, on android 8.1, drm_hwcomposer is a seperate process and must be the master node (to use the KMS API), since only a single process may be master surfaceflinger cannot be master too.
With this change surfaceflinger can use just a rendernode.
Note that we also have to modify the permissions table to allow render nodes to use the dumb allocation functions. This is a hack and unlikely to be accepted upstream but it's better than the huge security hole of allowing everything we were using before.
Need to discuss an upstream acceptable way for this...
--- drivers/gpu/drm/drm_ioctl.c | 6 +++--- drivers/gpu/drm/imx/imx-drm-core.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_ioctl.c +3 -3
@@ -639,9 +639,9 @@ int drm_ioctl_permit(u32 flags, struct drm_file *file_priv)DRM_IOCTL_DEF (DRM_IOCTL_MODE_RMFB , drm_mode_rmfb,DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_PAGE_FLIP , drm_mode_page_flip_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_DIRTYFB , drm_mode_dirtyfb_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), -DRM_IOCTL_DEF (DRM_IOCTL_MODE_CREATE_DUMB , drm_mode_create_dumb_ioctl,DRM_CONTROL_ALLOW |DRM_UNLOCKED ), -DRM_IOCTL_DEF (DRM_IOCTL_MODE_MAP_DUMB , drm_mode_mmap_dumb_ioctl,DRM_CONTROL_ALLOW |DRM_UNLOCKED ), -DRM_IOCTL_DEF (DRM_IOCTL_MODE_DESTROY_DUMB , drm_mode_destroy_dumb_ioctl,DRM_CONTROL_ALLOW |DRM_UNLOCKED ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_CREATE_DUMB , drm_mode_create_dumb_ioctl,DRM_CONTROL_ALLOW |DRM_UNLOCKED |DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_MAP_DUMB , drm_mode_mmap_dumb_ioctl,DRM_CONTROL_ALLOW |DRM_UNLOCKED |DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_DESTROY_DUMB , drm_mode_destroy_dumb_ioctl,DRM_CONTROL_ALLOW |DRM_UNLOCKED |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_OBJ_GETPROPERTIES , drm_mode_obj_get_properties_ioctl,DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_OBJ_SETPROPERTY , drm_mode_obj_set_property_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), DRM_IOCTL_DEF(DRM_IOCTL_MODE_CURSOR2, drm_mode_cursor2_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
drivers/gpu/drm/imx/imx-drm-core.c +1 -1
@@ -177,7 +177,7 @@ int imx_drm_encoder_parse_of(struct drm_device *drm,static struct drm_driver imx_drm_driver = { .driver_features =DRIVER_MODESET |DRIVER_GEM |DRIVER_PRIME | -DRIVER_ATOMIC , +DRIVER_ATOMIC |DRIVER_RENDER , .lastclose = imx_drm_driver_lastclose, .gem_free_object_unlocked = drm_gem_cma_free_object, .gem_vm_ops = &drm_gem_cma_vm_ops,
If it is not acceptable to modify the access rights for the DUMB allocation functions how should this be done?
Best regards,
Martin
Hi Martin,
Quoted 19 lines · Martin Fuzzey
Hi,
I am running into the same problem using etnaviv on i.MX6 under Android 8.1
The mesa etnaviv code uses
CREATE_DUMB/MAP_DUMBfor the scanout buffers and is called from the surfaceflinger process.But, under Android 8.1
drm_hwcomposerruns in a seperate process to surfaceflinger.
Sincedrm_hwcomposerneeds to use the KMS API it must be the DRM master, that means that surface flinger cannot be DRM master too.Adding a render node to the imx drm device and configuring mesa to user fixes
the problem but requires the render node to have access rights to useCREATE_DUMB
/MAP_DUMB.
Quoted 4 lines
Here is my full patch:
Make imx-drm export a render node so that mesa can use it to allocate
Let's start with the not-so obvious question:
Why does one open the imx as render node?
Of the top of my head:
There is nothing in egl/android that should require an authenticated device. Hence, using a card node should be fine - the etnaviv code opens the render node it needs.
It's been a while since I looked at the imx/etna code, so I may be missing something.
HTH
Emil
Hi Emil,
Quoted 11 lines · Emil Velikov
Hi Martin,
On 1 August 2018 at 15:24, Martin Fuzzey <[email protected]> wrote:
Let's start with the not-so obvious question:
Why does one open the imx as render node?Of the top of my head:
There is nothing in egl/android that should require an authenticated device. Hence, using a card node should be fine - the etnaviv code opens the render node it needs.
Yes, the problem is not in egl/android but in the scanout buffer allocation code.
etnaviv opens the render node on the *GPU* (for submitting GPU commands), that part is fine.
But scanout buffers need to be allocated from imx-drm not etnaviv.
This done by renderonly_create_kms_dumb_buffer_for_resource() [src/gallium/auxiliary/renderonly/renderonly.c] Which uses DRM_IOCTL_MODE_CREATE_DUMB followed by DRM_IOCTL_PRIME_FD_TO_HANDLE
on the "kms_fd" (probably poorly named because it's not actually used for modesetting)
see imx_drm_screen_create()[ src/gallium/winsys/imx/drm/imx_drm_winsys.c]
If the card node is used DRM_IOCTL_MODE_CREATE_DUMB works but DRM_IOCTL_PRIME_FD_TO_HANDLE fails, because the permissions are DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW
In android 8.1 the hardware composer runs in a seperate process and it has to use the card node and be drm master (to use the KMS API), therefore, when the surface flinger calls renderonly_create_kms_dumb_buffer_for_resource() it is not authenticated.
Making surface flinger use a render node fixes the problem for DRM_IOCTL_PRIME_FD_TO_HANDLE (because that already has DRM_RENDER_ALLOW), but DRM_IOCTL_MODE_CREATE_DUMB now fails without the patch.
This probably worked in previous versions of Android where surface flinger and hwc were all in the same process.
Regards,
Martin
Quoted 36 lines · Martin Fuzzey
Hi Emil,
Quoted 6 lines · Emil Velikov
Hi Martin,
On 1 August 2018 at 15:24, Martin Fuzzey <[email protected]> wrote:
Quoted 8 lines
Let's start with the not-so obvious question:
Why does one open the imx as render node?Of the top of my head:
There is nothing in egl/android that should require an authenticated device.
Hence, using a card node should be fine - the etnaviv code opens the render node it needs.Yes, the problem is not in egl/android but in the scanout buffer allocation code.
etnaviv opens the render node on the *GPU* (for submitting GPU commands), that part is fine.
But scanout buffers need to be allocated from imx-drm not etnaviv.
This done by
renderonly_create_kms_dumb_buffer_for_resource()[src/gallium/auxiliary/renderonly/renderonly.c]
Which usesDRM_IOCTL_MODE_CREATE_DUMBfollowed byDRM_IOCTL_PRIME_FD_TO_HANDLE
on the "kms_fd" (probably poorly named because it's not actually used for modesetting)
see imx_drm_screen_create()[src/gallium/winsys/imx/drm/imx_drm_winsys.c]
Quoted 4 lines
If the card node is used
DRM_IOCTL_MODE_CREATE_DUMBworks butDRM_IOCTL_PRIME_FD_TO_HANDLEfails, because the permissions are DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW
Right I missed the DRM_AUTH, in the fd <> handle IOCTLs. So in order for things to work, we'd need to either:
- allow dumb buffers for render nodes, or
- drop the DRM_AUTH for fd <> handle imports
Pointing an alternative solution, for kernel developers to analyse and make a decision.
Quoted 6 lines
In android 8.1 the hardware composer runs in a seperate process and it has to use the card node and be drm master (to use the KMS API), therefore, when the surface flinger calls
renderonly_create_kms_dumb_buffer_for_resource()it is not authenticated.
Quoted 8 lines
Making surface flinger use a render node fixes the problem for
DRM_IOCTL_PRIME_FD_TO_HANDLE(because that already hasDRM_RENDER_ALLOW), butDRM_IOCTL_MODE_CREATE_DUMBnow fails without the patch.This probably worked in previous versions of Android where surface flinger and hwc were all in the same process.
There has been varying hacks for Android through the years. Bringing details into the discussion will result in a significant diversion. Something we could avoid, for the time being ;-)
Thanks
Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 60 lines · Emil Velikov
Quoted 36 lines · Martin Fuzzey
Hi Emil,
Quoted 6 lines · Emil Velikov
Hi Martin,
On 1 August 2018 at 15:24, Martin Fuzzey <[email protected]> wrote:
Quoted 8 lines
Let's start with the not-so obvious question:
Why does one open the imx as render node?Of the top of my head:
There is nothing in egl/android that should require an authenticated device.
Hence, using a card node should be fine - the etnaviv code opens the render node it needs.Yes, the problem is not in egl/android but in the scanout buffer allocation code.
etnaviv opens the render node on the *GPU* (for submitting GPU commands), that part is fine.
But scanout buffers need to be allocated from imx-drm not etnaviv.
This done by
renderonly_create_kms_dumb_buffer_for_resource()[src/gallium/auxiliary/renderonly/renderonly.c]
Which usesDRM_IOCTL_MODE_CREATE_DUMBfollowed byDRM_IOCTL_PRIME_FD_TO_HANDLE
on the "kms_fd" (probably poorly named because it's not actually used for modesetting)
see imx_drm_screen_create()[src/gallium/winsys/imx/drm/imx_drm_winsys.c]Quoted 4 lines
If the card node is used
DRM_IOCTL_MODE_CREATE_DUMBworks butDRM_IOCTL_PRIME_FD_TO_HANDLEfails, because the permissions are DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOWRight I missed the
DRM_AUTH, in the fd <> handle IOCTLs. So in order for things to work, we'd need to either:
- allow dumb buffers for render nodes, or
- drop theDRM_AUTHfor fd <> handle importsPointing an alternative solution, for kernel developers to analyse and make a decision.
Quoted 11 lines
In android 8.1 the hardware composer runs in a seperate process and it has to use the card node and be drm master (to use the KMS API), therefore, when the surface flinger calls
renderonly_create_kms_dumb_buffer_for_resource()it is not authenticated.Making surface flinger use a render node fixes the problem for
DRM_IOCTL_PRIME_FD_TO_HANDLE(because that already hasDRM_RENDER_ALLOW), butDRM_IOCTL_MODE_CREATE_DUMBnow fails without the patch.
Quoted 6 lines
Quoted 3 lines
This probably worked in previous versions of Android where surface flinger and hwc were all in the same process.
There has been varying hacks for Android through the years. Bringing details into the discussion will result in a significant diversion. Something we could avoid, for the time being ;-)
Did someone say diversion?!? The way this was handled prior to using render/control nodes in drm_hwc/[drm/gbm]_gralloc is that all modesetting was done via gralloc which was master. The hwc implementation was basically a proxy backchanneling all of the work to gralloc.
Anyways, we probably don't want to go back there.
Fwiw, I'd lean towards allowing DUMB allocation from the render nodes. I understand it limits use cases that are undesirable, but it is also limiting usecases that are desirable. So, given that people are going to get "creative" regardless of how many safety railings we put up, we shouldn't make things unnecessarily hard on other trying to Get Work Done.
Sean
[Disclaimer: I'm totally and completely biased on this issue]
Quoted 3 lines
Thanks
Emil
Signature · 5 lines
Sean Paul, Software Engineer, Google / Chromium OS _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 74 lines · Sean Paul
Quoted 60 lines · Emil Velikov
Quoted 36 lines · Martin Fuzzey
Hi Emil,
Quoted 6 lines · Emil Velikov
Hi Martin,
On 1 August 2018 at 15:24, Martin Fuzzey <[email protected]> wrote:
Quoted 8 lines
Let's start with the not-so obvious question:
Why does one open the imx as render node?Of the top of my head:
There is nothing in egl/android that should require an authenticated device.
Hence, using a card node should be fine - the etnaviv code opens the render node it needs.Yes, the problem is not in egl/android but in the scanout buffer allocation code.
etnaviv opens the render node on the *GPU* (for submitting GPU commands), that part is fine.
But scanout buffers need to be allocated from imx-drm not etnaviv.
This done by
renderonly_create_kms_dumb_buffer_for_resource()[src/gallium/auxiliary/renderonly/renderonly.c]
Which usesDRM_IOCTL_MODE_CREATE_DUMBfollowed byDRM_IOCTL_PRIME_FD_TO_HANDLE
on the "kms_fd" (probably poorly named because it's not actually used for modesetting)
see imx_drm_screen_create()[src/gallium/winsys/imx/drm/imx_drm_winsys.c]Quoted 4 lines
If the card node is used
DRM_IOCTL_MODE_CREATE_DUMBworks butDRM_IOCTL_PRIME_FD_TO_HANDLEfails, because the permissions are DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOWRight I missed the
DRM_AUTH, in the fd <> handle IOCTLs. So in order for things to work, we'd need to either:
- allow dumb buffers for render nodes, or
- drop theDRM_AUTHfor fd <> handle importsPointing an alternative solution, for kernel developers to analyse and make a decision.
Quoted 11 lines
In android 8.1 the hardware composer runs in a seperate process and it has to use the card node and be drm master (to use the KMS API), therefore, when the surface flinger calls
renderonly_create_kms_dumb_buffer_for_resource()it is not authenticated.Making surface flinger use a render node fixes the problem for
DRM_IOCTL_PRIME_FD_TO_HANDLE(because that already hasDRM_RENDER_ALLOW), butDRM_IOCTL_MODE_CREATE_DUMBnow fails without the patch.Quoted 6 lines
Quoted 3 lines
This probably worked in previous versions of Android where surface flinger and hwc were all in the same process.
There has been varying hacks for Android through the years. Bringing details into the discussion will result in a significant diversion. Something we could avoid, for the time being ;-)
Did someone say diversion?!? The way this was handled prior to using render/control nodes in drm_hwc/[drm/gbm]_gralloc is that all modesetting was done via gralloc which was master. The hwc implementation was basically a proxy backchanneling all of the work to gralloc.
Quoted 7 lines
Anyways, we probably don't want to go back there.
Fwiw, I'd lean towards allowing DUMB allocation from the render nodes. I understand it limits use cases that are undesirable, but it is also limiting usecases that are desirable. So, given that people are going to get "creative" regardless of how many safety railings we put up, we shouldn't make things unnecessarily hard on other trying to Get Work Done.
The problem with using render nodes is what if there isn't one? We require VGEM (and make VGEM allow dumb buffers) in that case?
Rob
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 8 lines · Rob Herring
Quoted 5 lines · Sean Paul
Fwiw, I'd lean towards allowing DUMB allocation from the render nodes. I understand it limits use cases that are undesirable, but it is also limiting usecases that are desirable. So, given that people are going to get "creative" regardless of how many safety railings we put up, we shouldn't make things unnecessarily hard on other trying to Get Work Done.
The problem with using render nodes is what if there isn't one? We require VGEM (and make VGEM allow dumb buffers) in that case?
Try to open the render node and fall back to the card node if it doesn't exist?
AFAICT VGEM doesn't provide contiguous buffers so it won't work for the imx-drm case.
Regards,
Martin
Quoted 68 lines · Sean Paul
Quoted 60 lines · Emil Velikov
Quoted 36 lines · Martin Fuzzey
Hi Emil,
Quoted 6 lines · Emil Velikov
Hi Martin,
On 1 August 2018 at 15:24, Martin Fuzzey <[email protected]> wrote:
Quoted 8 lines
Let's start with the not-so obvious question:
Why does one open the imx as render node?Of the top of my head:
There is nothing in egl/android that should require an authenticated device.
Hence, using a card node should be fine - the etnaviv code opens the render node it needs.Yes, the problem is not in egl/android but in the scanout buffer allocation code.
etnaviv opens the render node on the *GPU* (for submitting GPU commands), that part is fine.
But scanout buffers need to be allocated from imx-drm not etnaviv.
This done by
renderonly_create_kms_dumb_buffer_for_resource()[src/gallium/auxiliary/renderonly/renderonly.c]
Which usesDRM_IOCTL_MODE_CREATE_DUMBfollowed byDRM_IOCTL_PRIME_FD_TO_HANDLE
on the "kms_fd" (probably poorly named because it's not actually used for modesetting)
see imx_drm_screen_create()[src/gallium/winsys/imx/drm/imx_drm_winsys.c]Quoted 4 lines
If the card node is used
DRM_IOCTL_MODE_CREATE_DUMBworks butDRM_IOCTL_PRIME_FD_TO_HANDLEfails, because the permissions are DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOWRight I missed the
DRM_AUTH, in the fd <> handle IOCTLs. So in order for things to work, we'd need to either:
- allow dumb buffers for render nodes, or
- drop theDRM_AUTHfor fd <> handle importsPointing an alternative solution, for kernel developers to analyse and make a decision.
Quoted 11 lines
In android 8.1 the hardware composer runs in a seperate process and it has to use the card node and be drm master (to use the KMS API), therefore, when the surface flinger calls
renderonly_create_kms_dumb_buffer_for_resource()it is not authenticated.Making surface flinger use a render node fixes the problem for
DRM_IOCTL_PRIME_FD_TO_HANDLE(because that already hasDRM_RENDER_ALLOW), butDRM_IOCTL_MODE_CREATE_DUMBnow fails without the patch.Quoted 6 lines
Quoted 3 lines
This probably worked in previous versions of Android where surface flinger and hwc were all in the same process.
There has been varying hacks for Android through the years. Bringing details into the discussion will result in a significant diversion. Something we could avoid, for the time being ;-)
Quoted 7 lines
Did someone say diversion?!? The way this was handled prior to using render/control nodes in drm_hwc/[drm/gbm]_gralloc is that all modesetting was done via gralloc which was master. The hwc implementation was basically a proxy backchanneling all of the work to gralloc.
Anyways, we probably don't want to go back there.
Now that we got the diversion out of the way, any input on my proposal to drop the DRM_AUTH for fd <> imports.
Am I missing something pretty obvious that makes the idea a no-go?
Thanks
Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 74 lines · Emil Velikov
Quoted 73 lines · Sean Paul
Quoted 60 lines · Emil Velikov
Quoted 36 lines · Martin Fuzzey
Hi Emil,
Quoted 6 lines · Emil Velikov
Hi Martin,
On 1 August 2018 at 15:24, Martin Fuzzey <[email protected]> wrote:
Quoted 8 lines
Let's start with the not-so obvious question:
Why does one open the imx as render node?Of the top of my head:
There is nothing in egl/android that should require an authenticated device.
Hence, using a card node should be fine - the etnaviv code opens the render node it needs.Yes, the problem is not in egl/android but in the scanout buffer allocation code.
etnaviv opens the render node on the *GPU* (for submitting GPU commands), that part is fine.
But scanout buffers need to be allocated from imx-drm not etnaviv.
This done by
renderonly_create_kms_dumb_buffer_for_resource()[src/gallium/auxiliary/renderonly/renderonly.c]
Which usesDRM_IOCTL_MODE_CREATE_DUMBfollowed byDRM_IOCTL_PRIME_FD_TO_HANDLE
on the "kms_fd" (probably poorly named because it's not actually used for modesetting)
see imx_drm_screen_create()[src/gallium/winsys/imx/drm/imx_drm_winsys.c]Quoted 4 lines
If the card node is used
DRM_IOCTL_MODE_CREATE_DUMBworks butDRM_IOCTL_PRIME_FD_TO_HANDLEfails, because the permissions are DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOWRight I missed the
DRM_AUTH, in the fd <> handle IOCTLs. So in order for things to work, we'd need to either:
- allow dumb buffers for render nodes, or
- drop theDRM_AUTHfor fd <> handle importsPointing an alternative solution, for kernel developers to analyse and make a decision.
Quoted 11 lines
In android 8.1 the hardware composer runs in a seperate process and it has to use the card node and be drm master (to use the KMS API), therefore, when the surface flinger calls
renderonly_create_kms_dumb_buffer_for_resource()it is not authenticated.Making surface flinger use a render node fixes the problem for
DRM_IOCTL_PRIME_FD_TO_HANDLE(because that already hasDRM_RENDER_ALLOW), butDRM_IOCTL_MODE_CREATE_DUMBnow fails without the patch.Quoted 6 lines
Quoted 3 lines
This probably worked in previous versions of Android where surface flinger and hwc were all in the same process.
There has been varying hacks for Android through the years. Bringing details into the discussion will result in a significant diversion. Something we could avoid, for the time being ;-)
Did someone say diversion?!? The way this was handled prior to using render/control nodes in drm_hwc/[drm/gbm]_gralloc is that all modesetting was done via gralloc which was master. The hwc implementation was basically a proxy backchanneling all of the work to gralloc.
Quoted 5 lines
Quoted 2 lines
Anyways, we probably don't want to go back there.
Now that we got the diversion out of the way, any input on my proposal to drop the
DRM_AUTHfor fd <> imports.
Am I missing something pretty obvious that makes the idea a no-go?
Dropping DRM_AUTH is only relevant for the card node. And a card node might not be sufficiently isolated against concurrent other clients, which is why we don't allow it.
What we could do is essentially check whether your driver supports render nodes (indicating sufficient amounts of separation), and then allow anything for unauthenicated clients if DRM_RENDER_ALLOW is set on the ioctl.
But that's just reinventing render nodes on top of legacy card nodes, and I'm not clear on what that exactly gains us.
I think the proposal for dumb render nodes (for drivers which only do dumb kms buffers and no rendering at all) that's been discusson on irc a bit makes a lot more sense.
-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
Quoted 77 lines · Daniel Vetter
Quoted 76 lines · Emil Velikov
Quoted 75 lines · Sean Paul
Quoted 60 lines · Emil Velikov
Quoted 36 lines · Martin Fuzzey
Hi Emil,
Quoted 6 lines · Emil Velikov
Hi Martin,
On 1 August 2018 at 15:24, Martin Fuzzey <[email protected]> wrote:
Quoted 8 lines
Let's start with the not-so obvious question:
Why does one open the imx as render node?Of the top of my head:
There is nothing in egl/android that should require an authenticated device.
Hence, using a card node should be fine - the etnaviv code opens the render node it needs.Yes, the problem is not in egl/android but in the scanout buffer allocation code.
etnaviv opens the render node on the *GPU* (for submitting GPU commands), that part is fine.
But scanout buffers need to be allocated from imx-drm not etnaviv.
This done by
renderonly_create_kms_dumb_buffer_for_resource()[src/gallium/auxiliary/renderonly/renderonly.c]
Which usesDRM_IOCTL_MODE_CREATE_DUMBfollowed byDRM_IOCTL_PRIME_FD_TO_HANDLE
on the "kms_fd" (probably poorly named because it's not actually used for modesetting)
see imx_drm_screen_create()[src/gallium/winsys/imx/drm/imx_drm_winsys.c]Quoted 4 lines
If the card node is used
DRM_IOCTL_MODE_CREATE_DUMBworks butDRM_IOCTL_PRIME_FD_TO_HANDLEfails, because the permissions are DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOWRight I missed the
DRM_AUTH, in the fd <> handle IOCTLs. So in order for things to work, we'd need to either:
- allow dumb buffers for render nodes, or
- drop theDRM_AUTHfor fd <> handle importsPointing an alternative solution, for kernel developers to analyse and make a decision.
Quoted 11 lines
In android 8.1 the hardware composer runs in a seperate process and it has to use the card node and be drm master (to use the KMS API), therefore, when the surface flinger calls
renderonly_create_kms_dumb_buffer_for_resource()it is not authenticated.Making surface flinger use a render node fixes the problem for
DRM_IOCTL_PRIME_FD_TO_HANDLE(because that already hasDRM_RENDER_ALLOW), butDRM_IOCTL_MODE_CREATE_DUMBnow fails without the patch.Quoted 6 lines
Quoted 3 lines
This probably worked in previous versions of Android where surface flinger and hwc were all in the same process.
There has been varying hacks for Android through the years. Bringing details into the discussion will result in a significant diversion. Something we could avoid, for the time being ;-)
Did someone say diversion?!? The way this was handled prior to using render/control nodes in drm_hwc/[drm/gbm]_gralloc is that all modesetting was done via gralloc which was master. The hwc implementation was basically a proxy backchanneling all of the work to gralloc.
Anyways, we probably don't want to go back there.
Quoted 8 lines
Quoted 3 lines
Now that we got the diversion out of the way, any input on my proposal to drop the
DRM_AUTHfor fd <> imports.
Am I missing something pretty obvious that makes the idea a no-go?Dropping
DRM_AUTHis only relevant for the card node. And a card node might not be sufficiently isolated against concurrent other clients, which is why we don't allow it.
Right. I did not spot anything that would make a distinction based on the card vs render node used.
Quoted 8 lines
What we could do is essentially check whether your driver supports render nodes (indicating sufficient amounts of separation), and then allow anything for unauthenicated clients if
DRM_RENDER_ALLOWis set on the ioctl.But that's just reinventing render nodes on top of legacy card nodes, and I'm not clear on what that exactly gains us.
As more of a userspace person, it makes sense to keep render nodes for GPU specifics and card ones - KMS/Display Controller.
Quoted 3 lines
I think the proposal for dumb render nodes (for drivers which only do dumb kms buffers and no rendering at all) that's been discusson on irc a bit makes a lot more sense.
Ack. Thanks for shedding some light.
-Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi all,
Sharing some ideas on the topic. Personally I'm neither for, nor against this patch.
Quoted 34 lines · Robert Foss
From: Tomasz Figa <[email protected]>
There is no particular reason to prevent userspace for using this IOCTL, considering that it already has access to other, platform-specific IOCTLs. This patch makes is possible to have the same userspace code work regardless on the underlying platform, which significantly simplifies the stack.
Signed-off-by Tomasz Figa <[email protected]>Reviewed-by Zach Reizner <[email protected]>Signed-off-by Nicolas Norvez <[email protected]>Reviewed-by Tomasz Figa <[email protected]>Signed-off-by Robert Foss <[email protected]>---
I've been looking into enabling a
kms_swrastbased driver for mesa on the Android platform[1].But have come up against the issue of dumb buffer related ioctls below not being flagged with
DRM_RENDER_ALLOW.
DRM_IOCTL_MODE_CREATE_DUMBDRM_IOCTL_MODE_MAP_DUMBTo be more precise, I've been seeing a failure due to
DRM_IOCTL_MODE_MAP_DUMBnot being allowed for/dev/dri/renderD*nodes, and used in mesakms_sw_displaytarget_map().As I understand it the
DRM_RENDER_ALLOWflag being unset is a very intentional restriction placed on dumb buffers in order to minimize its use. But as far as alternative solutions for software renderers there seems to only be VGEM and mmap()-ing DMABUFs.
Quoted 6 lines
While it would be convenient from the point of view of software renderers if dumb buffers had more promiscuous permissions, it may be a hard sell upstream.
If dumb buffers aren't the way forward, what is? VGEM? Or are there any other preferable ways?
The description of VGEM says "... as used by Mesa's software renderer for enhanced performance."
Although that hasn't been the case really, since we're opening an arbitrary GPU node with kms_swrast.
I think we should fix that.
On top of that we could also use the card node, which will remove the need for this patch.
Yet again, there may be reasonable usecases where one needs the render node to support the dumb buffer ioctls.
HTH
Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel