drm: introduce DRM_MODE_FB_PERSIST
Subsystems (2)
RFC PATCH 1/1 drm: introduce DRM_MODE_FB_PERSIST
This new ADDFB2 flag allows callers to mark a framebuffer as "persistent", and no longer have RMFB semantics when the DRM file is closed.
[1]: https://lore.kernel.org/dri-devel/YTJypepF1Hpc2YYT@reader/
---
I'm not sure this is enough, but posting this to get initial feedback and allow to start e.g. Plymouth experiments. I'll follow up with an IGT test soon.
drivers/gpu/drm/drm_framebuffer.c | 6 ++++-- include/uapi/drm/drm_mode.h | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_framebuffer.c +4 -2
@@ -292,7 +292,8 @@ drm_internal_framebuffer_create(struct drm_device *dev,struct drm_framebuffer *fb;int ret; -if (r->flags & ~(DRM_MODE_FB_INTERLACED |DRM_MODE_FB_MODIFIERS )) { +if (r->flags & ~(DRM_MODE_FB_INTERLACED |DRM_MODE_FB_MODIFIERS | +DRM_MODE_FB_PERSIST )) {DRM_DEBUG_KMS ("bad framebuffer flags 0x%08x\n" , r->flags);return ERR_PTR (-EINVAL ); }
@@ -789,7 +790,8 @@ void drm_fb_release(struct drm_file *priv)* at it any more. */ list_for_each_entry_safe (fb, tfb, &priv->fbs, filp_head) { -if (drm_framebuffer_read_refcount (fb) >1 ) { +if (drm_framebuffer_read_refcount (fb) >1 && + !(fb->flags &DRM_MODE_FB_PERSIST )) {list_move_tail (&fb->filp_head, &arg.fbs); }else {list_del_init (&fb->filp_head);
include/uapi/drm/drm_mode.h +15 -0
@@ -662,6 +662,21 @@ struct drm_mode_fb_cmd {#define DRM_MODE_FB_INTERLACED (1<<0)/* for interlaced framebuffers */ #define DRM_MODE_FB_MODIFIERS (1<<1)/* enables ->modifer[] */ +/** +* DRM_MODE_FB_PERSIST +* +* DRM framebuffers are normally implicitly removed when their owner closes the +* DRM FD. Passing this flag will make the framebuffer persistent: it will not +* be implicitly removed. This is useful to implement flicker-free transitions +* between two processes. +* +* This flag doesn't change the behavior of &DRM_IOCTL_MODE_RMFB. +* +* User-space should ensure the framebuffer doesn't expose any sensitive user +* information: persistent framebuffers can be read back by the next DRM +* master. +*/ +#define DRM_MODE_FB_PERSIST (1 << 2)struct drm_mode_fb_cmd2 {__u32 fb_id;
Signature · 1 line
2.33.0
Quoted 56 lines · Simon Ser
This new ADDFB2 flag allows callers to mark a framebuffer as "persistent", and no longer have RMFB semantics when the DRM file is closed.
[1]: https://lore.kernel.org/dri-devel/YTJypepF1Hpc2YYT@reader/
Signed-off-by Simon Ser <[email protected]>Cc Hans de Goede <[email protected]>Cc Dennis Filder <[email protected]>Cc Daniel Vetter <[email protected]>Cc Pekka Paalanen <[email protected]>---
I'm not sure this is enough, but posting this to get initial feedback and allow to start e.g. Plymouth experiments. I'll follow up with an IGT test soon.
drivers/gpu/drm/drm_framebuffer.c | 6 ++++-- include/uapi/drm/drm_mode.h | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_framebuffer.c +4
-2@@ -292,7 +292,8 @@ drm_internal_framebuffer_create(struct drm_device *dev,struct drm_framebuffer *fb;int ret; -if (r->flags & ~(DRM_MODE_FB_INTERLACED |DRM_MODE_FB_MODIFIERS )) { +if (r->flags & ~(DRM_MODE_FB_INTERLACED |DRM_MODE_FB_MODIFIERS | +DRM_MODE_FB_PERSIST )) {DRM_DEBUG_KMS ("bad framebuffer flags 0x%08x\n" , r->flags);return ERR_PTR (-EINVAL ); }@@ -789,7 +790,8 @@ void drm_fb_release(struct drm_file *priv)* at it any more. */ list_for_each_entry_safe (fb, tfb, &priv->fbs, filp_head) { -if (drm_framebuffer_read_refcount (fb) >1 ) { +if (drm_framebuffer_read_refcount (fb) >1 && + !(fb->flags &DRM_MODE_FB_PERSIST )) {list_move_tail (&fb->filp_head, &arg.fbs); }else {list_del_init (&fb->filp_head);include/uapi/drm/drm_mode.h +3
-0@@ -662,6 +662,21 @@ struct drm_mode_fb_cmd {#define DRM_MODE_FB_INTERLACED (1<<0)/* for interlaced framebuffers */ #define DRM_MODE_FB_MODIFIERS (1<<1)/* enables ->modifer[] */ +/** +* DRM_MODE_FB_PERSIST +*
include/uapi/drm/drm_mode.h struct drm_mode_fb_cmd { · line 677
Quoted 10 lines
include/uapi/drm/drm_mode.h +10
-0+* DRM framebuffers are normally implicitly removed when their owner closes the +* DRM FD. Passing this flag will make the framebuffer persistent: it will not +* be implicitly removed. This is useful to implement flicker-free transitions +* between two processes. +* +* This flag doesn't change the behavior of &DRM_IOCTL_MODE_RMFB. +* +* User-space should ensure the framebuffer doesn't expose any sensitive user +* information: persistent framebuffers can be read back by the next DRM +* master.
Should probably explain here that the persistent fb stays around for as long as it's still in use by a plane, but will disappear automatically when it's no longer in active use.
Also I guess there was some discussion I've missed on why we exclude rmfb from this (unlike the CLOSEFB thing robclark proposed ages ago). The nice thing about closefb is that you can give it persistent semantics retroactively, so don't need to re-wrap an gem_bo and do a page flip when you quit.
-Daniel
Quoted 9 lines
include/uapi/drm/drm_mode.h +2
-1+*/ +#define DRM_MODE_FB_PERSIST (1 << 2)struct drm_mode_fb_cmd2 {__u32 fb_id; --2.33.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Quoted 63 lines · On Wed, 6 Oct 2021 21:24:44 +0200 Daniel Vetter <[email protected]> wrote:
Quoted 62 lines · Simon Ser
This new ADDFB2 flag allows callers to mark a framebuffer as "persistent", and no longer have RMFB semantics when the DRM file is closed.
[1]: https://lore.kernel.org/dri-devel/YTJypepF1Hpc2YYT@reader/
Signed-off-by Simon Ser <[email protected]>Cc Hans de Goede <[email protected]>Cc Dennis Filder <[email protected]>Cc Daniel Vetter <[email protected]>Cc Pekka Paalanen <[email protected]>---
I'm not sure this is enough, but posting this to get initial feedback and allow to start e.g. Plymouth experiments. I'll follow up with an IGT test soon.
drivers/gpu/drm/drm_framebuffer.c | 6 ++++-- include/uapi/drm/drm_mode.h | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_framebuffer.c +4
-2@@ -292,7 +292,8 @@ drm_internal_framebuffer_create(struct drm_device *dev,struct drm_framebuffer *fb;int ret; -if (r->flags & ~(DRM_MODE_FB_INTERLACED |DRM_MODE_FB_MODIFIERS )) { +if (r->flags & ~(DRM_MODE_FB_INTERLACED |DRM_MODE_FB_MODIFIERS | +DRM_MODE_FB_PERSIST )) {DRM_DEBUG_KMS ("bad framebuffer flags 0x%08x\n" , r->flags);return ERR_PTR (-EINVAL ); }@@ -789,7 +790,8 @@ void drm_fb_release(struct drm_file *priv)* at it any more. */ list_for_each_entry_safe (fb, tfb, &priv->fbs, filp_head) { -if (drm_framebuffer_read_refcount (fb) >1 ) { +if (drm_framebuffer_read_refcount (fb) >1 && + !(fb->flags &DRM_MODE_FB_PERSIST )) {list_move_tail (&fb->filp_head, &arg.fbs); }else {list_del_init (&fb->filp_head);include/uapi/drm/drm_mode.h +9
-0@@ -662,6 +662,21 @@ struct drm_mode_fb_cmd {#define DRM_MODE_FB_INTERLACED (1<<0)/* for interlaced framebuffers */ #define DRM_MODE_FB_MODIFIERS (1<<1)/* enables ->modifer[] */ +/** +* DRM_MODE_FB_PERSIST +* +* DRM framebuffers are normally implicitly removed when their owner closes the +* DRM FD. Passing this flag will make the framebuffer persistent: it will not +* be implicitly removed. This is useful to implement flicker-free transitions +* between two processes. +* +* This flag doesn't change the behavior of &DRM_IOCTL_MODE_RMFB.
Quoted 8 lines
include/uapi/drm/drm_mode.h struct drm_mode_fb_cmd { · line 677
Quoted 4 lines
include/uapi/drm/drm_mode.h +4
-0+* +* User-space should ensure the framebuffer doesn't expose any sensitive user +* information: persistent framebuffers can be read back by the next DRM +* master. Should probably explain here that the persistent fb stays around for as long as it's still in use by a plane, but will disappear automatically when it's no longer in active use.
Yes, I think that is an important detail.
Quoted 2 lines
Also I guess there was some discussion I've missed on why we exclude rmfb from this (unlike the CLOSEFB thing robclark proposed ages ago).
What does that mean? Was the CLOSEFB proposal saying that doing an RMFB on a persistent FB does not actually RM the FB? If so, what effect did it have, did it only invalidate the userspace FB ID?
That is an interesting thought. Userspace would not need to deliberately "leak" the FB ID, it could still RMFB it which feels more clean to me.
What if persistence was a flag on RMFB instead? If userspace forgets to call RMFB at all, then closing the device removes the FB and avoids information leaks. Only by doing special RMFB would allow the FB to remain after closing the device. That should also encourage userspace to track their FBs better.
Quoted 3 lines
The nice thing about closefb is that you can give it persistent semantics retroactively, so don't need to re-wrap an
gem_boand do a page flip when you quit.
When you quit, you are going to need to draw once more anyway to get rid of any potentially sensitive information for sure, so the re-wrap does not seem much extra to me. OTOH, I guess userspace code would be a little simpler if it does not need to re-wrap (assuming the code already keeps FB IDs around and does not re-ADDFB on every flip - weston does this caching).
I think my order of favourites is:
1. RMFB flag
2. ioctl to set an existing FB as persistent
3. ADDFB flag
They all seem workable to me.
Thanks,
pq
Quoted 13 lines
-Daniel
Quoted 9 lines
include/uapi/drm/drm_mode.h +2
-1+*/ +#define DRM_MODE_FB_PERSIST (1 << 2)struct drm_mode_fb_cmd2 {__u32 fb_id; --2.33.0
Hi,
Quoted 94 lines · Pekka Paalanen
Quoted 63 lines · On Wed, 6 Oct 2021 21:24:44 +0200 Daniel Vetter <[email protected]> wrote:
Quoted 62 lines · Simon Ser
This new ADDFB2 flag allows callers to mark a framebuffer as "persistent", and no longer have RMFB semantics when the DRM file is closed.
[1]: https://lore.kernel.org/dri-devel/YTJypepF1Hpc2YYT@reader/
Signed-off-by Simon Ser <[email protected]>Cc Hans de Goede <[email protected]>Cc Dennis Filder <[email protected]>Cc Daniel Vetter <[email protected]>Cc Pekka Paalanen <[email protected]>---
I'm not sure this is enough, but posting this to get initial feedback and allow to start e.g. Plymouth experiments. I'll follow up with an IGT test soon.
drivers/gpu/drm/drm_framebuffer.c | 6 ++++-- include/uapi/drm/drm_mode.h | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_framebuffer.c +4
-2@@ -292,7 +292,8 @@ drm_internal_framebuffer_create(struct drm_device *dev,struct drm_framebuffer *fb;int ret; -if (r->flags & ~(DRM_MODE_FB_INTERLACED |DRM_MODE_FB_MODIFIERS )) { +if (r->flags & ~(DRM_MODE_FB_INTERLACED |DRM_MODE_FB_MODIFIERS | +DRM_MODE_FB_PERSIST )) {DRM_DEBUG_KMS ("bad framebuffer flags 0x%08x\n" , r->flags);return ERR_PTR (-EINVAL ); }@@ -789,7 +790,8 @@ void drm_fb_release(struct drm_file *priv)* at it any more. */ list_for_each_entry_safe (fb, tfb, &priv->fbs, filp_head) { -if (drm_framebuffer_read_refcount (fb) >1 ) { +if (drm_framebuffer_read_refcount (fb) >1 && + !(fb->flags &DRM_MODE_FB_PERSIST )) {list_move_tail (&fb->filp_head, &arg.fbs); }else {list_del_init (&fb->filp_head);include/uapi/drm/drm_mode.h +9
-0@@ -662,6 +662,21 @@ struct drm_mode_fb_cmd {#define DRM_MODE_FB_INTERLACED (1<<0)/* for interlaced framebuffers */ #define DRM_MODE_FB_MODIFIERS (1<<1)/* enables ->modifer[] */ +/** +* DRM_MODE_FB_PERSIST +* +* DRM framebuffers are normally implicitly removed when their owner closes the +* DRM FD. Passing this flag will make the framebuffer persistent: it will not +* be implicitly removed. This is useful to implement flicker-free transitions +* between two processes. +* +* This flag doesn't change the behavior of &DRM_IOCTL_MODE_RMFB. Quoted 8 lines
include/uapi/drm/drm_mode.h struct drm_mode_fb_cmd { · line 677
Quoted 4 lines
include/uapi/drm/drm_mode.h +4
-0+* +* User-space should ensure the framebuffer doesn't expose any sensitive user +* information: persistent framebuffers can be read back by the next DRM +* master. Should probably explain here that the persistent fb stays around for as long as it's still in use by a plane, but will disappear automatically when it's no longer in active use.
Yes, I think that is an important detail.
Quoted 2 lines
Also I guess there was some discussion I've missed on why we exclude rmfb from this (unlike the CLOSEFB thing robclark proposed ages ago).
What does that mean? Was the CLOSEFB proposal saying that doing an RMFB on a persistent FB does not actually RM the FB? If so, what effect did it have, did it only invalidate the userspace FB ID?
That is an interesting thought. Userspace would not need to deliberately "leak" the FB ID, it could still RMFB it which feels more clean to me.
What if persistence was a flag on RMFB instead? If userspace forgets to call RMFB at all, then closing the device removes the FB and avoids information leaks. Only by doing special RMFB would allow the FB to remain after closing the device. That should also encourage userspace to track their FBs better.
Quoted 7 lines
Quoted 3 lines
The nice thing about closefb is that you can give it persistent semantics retroactively, so don't need to re-wrap an
gem_boand do a page flip when you quit.When you quit, you are going to need to draw once more anyway to get rid of any potentially sensitive information for sure, so the re-wrap does not seem much extra to me.
Right that was my though too.
Quoted 11 lines
OTOH, I guess userspace code would be a
little simpler if it does not need to re-wrap (assuming the code already keeps FB IDs around and does not re-ADDFB on every flip - weston does this caching).I think my order of favourites is:
1. RMFB flag
2. ioctl to set an existing FB as persistent
3. ADDFB flagThey all seem workable to me.
I fully agree with the above.
Regards,
Hans
Quoted 8 lines · Hans de Goede
Quoted 6 lines
I think my order of favourites is:
1. RMFB flag
2. ioctl to set an existing FB as persistent
3. ADDFB flagThey all seem workable to me.
I fully agree with the above.
Thanks for the feedback! It seems like everyone agrees Rob Clark's CLOSEFB is the best solution. Sent a new RFC at [1].