drm/drm_fb_helper: fix fbdev with sparc64
Subsystems (2)
PATCH v2 1/1 drm/drm_fb_helper: fix fbdev with sparc64
From 1323a7433691aee112a9b2df8041b5024895a77e Mon Sep 17 00:00:00 2001
From: Sam Ravnborg <[email protected]>
Date: Thu, 9 Jul 2020 21:30:16 +0200
Subject: [PATCH v2 1/1] drm/drm_fb_helper: fix fbdev with sparc64
Recent kernels have been reported to panic using the bochs_drm framebuffer under qemu-system-sparc64 which was bisected to commit 7a0483ac4ffc "drm/bochs: switch to generic drm fbdev emulation". The backtrace indicates that the shadow framebuffer copy in drm_fb_helper_dirty_blit_real() is trying to access the real framebuffer using a virtual address rather than use an IO access typically implemented using a physical (ASI_PHYS) access on SPARC.
The fix is to replace the memcpy with memcpy_toio() from io.h.
memcpy_toio() uses writeb() where the original fbdev code used sbus_memcpy_toio(). The latter uses sbus_writeb().
The difference between writeb() and sbus_memcpy_toio() is that writeb() writes bytes in little-endian, where sbus_writeb() writes bytes in big-endian. As endian does not matter for byte writes they are the same. So we can safely use memcpy_toio() here.
For many architectures memcpy_toio() is a simple memcpy(). One side-effect that is unknown is if this has any impact on other architectures.
So far the analysis tells that this change is OK for other arch's. but testing would be good.
v2:
- Added missing __iomem cast (kernel test robot)
- Made changelog readable and fix typos (Mark)
- Add flag to select iomem - and set it in the bochs driver
---
This fix introducing a flag in mode_config is at best a band-aid solution until we have a proper fix.
We need to propagate the info about iomem so it is not a driver flag thing.
There is also the issue with sys* versus cfb* functions, where cfb* functions are used for iomem.
I did not manage to make the bochs driver work with the cfb* functions, for some unknown reason booting would be stuck waiting for the console mutex when usign the cfb* functions.
I consider this fix OK to get the kernel working for sparc64 with the bochs driver for now. And with the fbdev_uses_iomem flag no other drivers will see any changes.
Sam
drivers/gpu/drm/bochs/bochs_kms.c | 1 + drivers/gpu/drm/drm_fb_helper.c | 6 +++++- include/drm/drm_mode_config.h | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/gpu/drm/bochs/bochs_kms.c +1 -0
@@ -146,6 +146,7 @@ int bochs_kms_init(struct bochs_device *bochs) bochs->dev->mode_config.preferred_depth =24 ; bochs->dev->mode_config.prefer_shadow =0 ; bochs->dev->mode_config.prefer_shadow_fbdev =1 ; + bochs->dev->mode_config.fbdev_use_iomem = true; bochs->dev->mode_config.quirk_addfb_prefer_host_byte_order = true; bochs->dev->mode_config.funcs = &bochs_mode_funcs;
drivers/gpu/drm/drm_fb_helper.c +5 -1
@@ -399,7 +399,11 @@ static void drm_fb_helper_dirty_blit_real(struct drm_fb_helper *fb_helper,unsigned int y;for (y = clip->y1; y < clip->y2; y++) { -memcpy (dst, src, len); +if (!fb_helper->dev->mode_config.fbdev_use_iomem) +memcpy (dst, src, len); +else +memcpy_toio ((void __iomem *)dst, src, len); + src += fb->pitches[0 ]; dst += fb->pitches[0 ]; }
include/drm/drm_mode_config.h +9 -0
@@ -865,6 +865,15 @@ struct drm_mode_config {*/ bool prefer_shadow_fbdev; +/** +* @fbdev_use_iomem: +* +* Set to true if framebuffer reside in iomem. +* When set to true memcpy_toio() is used when copying the framebuffer in +* drm_fb_helper.drm_fb_helper_dirty_blit_real() +*/ +bool fbdev_use_iomem; +/** * @quirk_addfb_prefer_xbgr_30bpp: *
Signature · 1 line
2.25.1
Quoted 23 lines · Sam Ravnborg
From
1323a7433691aee112a9b2df8041b5024895a77eMon Sep 17 00:00:00 2001
From: Sam Ravnborg <[email protected]>
Date: Thu, 9 Jul 2020 21:30:16 +0200
Subject: [PATCH v2 1/1] drm/drm_fb_helper: fix fbdev with sparc64Recent kernels have been reported to panic using the
bochs_drmframebuffer under qemu-system-sparc64 which was bisected to commit7a0483ac4ffc"drm/bochs: switch to generic drm fbdev emulation". The backtrace indicates that the shadow framebuffer copy indrm_fb_helper_dirty_blit_real()is trying to access the real framebuffer using a virtual address rather than use an IO access typically implemented using a physical (ASI_PHYS) access on SPARC.The fix is to replace the memcpy with
memcpy_toio()fromio.h.
memcpy_toio()useswriteb()where the original fbdev code usedsbus_memcpy_toio(). The latter usessbus_writeb().The difference between
writeb()andsbus_memcpy_toio()is thatwriteb()writes bytes in little-endian, wheresbus_writeb()writes bytes in big-endian. As endian does not matter for byte writes they are the same. So we can safely usememcpy_toio()here.
Quoted 5 lines
For many architectures
memcpy_toio()is a simplememcpy(). One side-effect that is unknown is if this has any impact on other architectures.
So far the analysis tells that this change is OK for other arch's. but testing would be good.
The rules are that officially we have to use the io functions for __mmio pointers. We just drop these sparse annotations on the floor. I'd replace this with something like:
"Note that this only fixes bochs, in general fbdev helpers still have issues with mixing up system memory and mmio space. Fixing that will require a lot more work."
Quoted 73 lines
v2:
- Added missing__iomemcast (kernel test robot)
- Made changelog readable and fix typos (Mark)
- Add flag to select iomem - and set it in the bochs driverSigned-off-by Sam Ravnborg <[email protected]>Reported-by Mark Cave-Ayland <[email protected]>Reported-by kernel test robot <[email protected]>Tested-by Mark Cave-Ayland <[email protected]>Cc Mark Cave-Ayland <[email protected]>Cc Thomas Zimmermann <[email protected]>Cc Gerd Hoffmann <[email protected]>Cc "David S. Miller" <[email protected]>---
This fix introducing a flag in
mode_configis at best a band-aid solution until we have a proper fix.
We need to propagate the info about iomem so it is not a driver flag thing.There is also the issue with sys* versus cfb* functions, where cfb* functions are used for iomem.
I did not manage to make the bochs driver work with the cfb* functions, for some unknown reason booting would be stuck waiting for the console mutex when usign the cfb* functions.I consider this fix OK to get the kernel working for sparc64 with the bochs driver for now. And with the
fbdev_uses_iomemflag no other drivers will see any changes.Sam
drivers/gpu/drm/bochs/bochs_kms.c | 1 + drivers/gpu/drm/drm_fb_helper.c | 6 +++++- include/drm/drm_mode_config.h | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-)drivers/gpu/drm/bochs/bochs_kms.c +1
-0@@ -146,6 +146,7 @@ int bochs_kms_init(struct bochs_device *bochs) bochs->dev->mode_config.preferred_depth =24 ; bochs->dev->mode_config.prefer_shadow =0 ; bochs->dev->mode_config.prefer_shadow_fbdev =1 ; + bochs->dev->mode_config.fbdev_use_iomem = true; bochs->dev->mode_config.quirk_addfb_prefer_host_byte_order = true; bochs->dev->mode_config.funcs = &bochs_mode_funcs;drivers/gpu/drm/drm_fb_helper.c +5
-1@@ -399,7 +399,11 @@ static void drm_fb_helper_dirty_blit_real(struct drm_fb_helper *fb_helper,unsigned int y;for (y = clip->y1; y < clip->y2; y++) { -memcpy (dst, src, len); +if (!fb_helper->dev->mode_config.fbdev_use_iomem) +memcpy (dst, src, len); +else +memcpy_toio ((void __iomem *)dst, src, len); + src += fb->pitches[0 ]; dst += fb->pitches[0 ]; }include/drm/drm_mode_config.h +0
-0
include/drm/drm_mode_config.h struct drm_mode_config { · line 873
Quoted 9 lines
include/drm/drm_mode_config.h +6
-0@@ -865,6 +865,15 @@ struct drm_mode_config {*/ bool prefer_shadow_fbdev; +/** +* @fbdev_use_iomem: +* +* Set to true if framebuffer reside in iomem. +* When set to true memcpy_toio() is used when copying the framebuffer in +* drm_fb_helper.drm_fb_helper_dirty_blit_real()
I'd add a "FIXME: This should be replaced with a per-mapping is_iomem flag (like ttm does), and then used everywhere in fbdev code."
With those two nits: Reviewed-by: Daniel Vetter <[email protected]>
Quoted 9 lines
include/drm/drm_mode_config.h +3
-1+*/ +bool fbdev_use_iomem; +/** * @quirk_addfb_prefer_xbgr_30bpp: * -- 2.25.1
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Hi Daniel
Quoted 30 lines · Daniel Vetter
Quoted 23 lines · Sam Ravnborg
From
1323a7433691aee112a9b2df8041b5024895a77eMon Sep 17 00:00:00 2001
From: Sam Ravnborg <[email protected]>
Date: Thu, 9 Jul 2020 21:30:16 +0200
Subject: [PATCH v2 1/1] drm/drm_fb_helper: fix fbdev with sparc64Recent kernels have been reported to panic using the
bochs_drmframebuffer under qemu-system-sparc64 which was bisected to commit7a0483ac4ffc"drm/bochs: switch to generic drm fbdev emulation". The backtrace indicates that the shadow framebuffer copy indrm_fb_helper_dirty_blit_real()is trying to access the real framebuffer using a virtual address rather than use an IO access typically implemented using a physical (ASI_PHYS) access on SPARC.The fix is to replace the memcpy with
memcpy_toio()fromio.h.
memcpy_toio()useswriteb()where the original fbdev code usedsbus_memcpy_toio(). The latter usessbus_writeb().The difference between
writeb()andsbus_memcpy_toio()is thatwriteb()writes bytes in little-endian, wheresbus_writeb()writes bytes in big-endian. As endian does not matter for byte writes they are the same. So we can safely usememcpy_toio()here.Quoted 5 lines
For many architectures
memcpy_toio()is a simplememcpy(). One side-effect that is unknown is if this has any impact on other architectures.
So far the analysis tells that this change is OK for other arch's. but testing would be good.
Quoted 7 lines
The rules are that officially we have to use the io functions for
__mmiopointers. We just drop these sparse annotations on the floor. I'd replace this with something like:"Note that this only fixes bochs, in general fbdev helpers still have issues with mixing up system memory and mmio space. Fixing that will require a lot more work."
OK, done.
Quoted 77 lines
Quoted 77 lines
v2:
- Added missing__iomemcast (kernel test robot)
- Made changelog readable and fix typos (Mark)
- Add flag to select iomem - and set it in the bochs driverSigned-off-by Sam Ravnborg <[email protected]>Reported-by Mark Cave-Ayland <[email protected]>Reported-by kernel test robot <[email protected]>Tested-by Mark Cave-Ayland <[email protected]>Cc Mark Cave-Ayland <[email protected]>Cc Thomas Zimmermann <[email protected]>Cc Gerd Hoffmann <[email protected]>Cc "David S. Miller" <[email protected]>---
This fix introducing a flag in
mode_configis at best a band-aid solution until we have a proper fix.
We need to propagate the info about iomem so it is not a driver flag thing.There is also the issue with sys* versus cfb* functions, where cfb* functions are used for iomem.
I did not manage to make the bochs driver work with the cfb* functions, for some unknown reason booting would be stuck waiting for the console mutex when usign the cfb* functions.I consider this fix OK to get the kernel working for sparc64 with the bochs driver for now. And with the
fbdev_uses_iomemflag no other drivers will see any changes.Sam
drivers/gpu/drm/bochs/bochs_kms.c | 1 + drivers/gpu/drm/drm_fb_helper.c | 6 +++++- include/drm/drm_mode_config.h | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-)drivers/gpu/drm/bochs/bochs_kms.c +1
-0@@ -146,6 +146,7 @@ int bochs_kms_init(struct bochs_device *bochs) bochs->dev->mode_config.preferred_depth =24 ; bochs->dev->mode_config.prefer_shadow =0 ; bochs->dev->mode_config.prefer_shadow_fbdev =1 ; + bochs->dev->mode_config.fbdev_use_iomem = true; bochs->dev->mode_config.quirk_addfb_prefer_host_byte_order = true; bochs->dev->mode_config.funcs = &bochs_mode_funcs;drivers/gpu/drm/drm_fb_helper.c +5
-1@@ -399,7 +399,11 @@ static void drm_fb_helper_dirty_blit_real(struct drm_fb_helper *fb_helper,unsigned int y;for (y = clip->y1; y < clip->y2; y++) { -memcpy (dst, src, len); +if (!fb_helper->dev->mode_config.fbdev_use_iomem) +memcpy (dst, src, len); +else +memcpy_toio ((void __iomem *)dst, src, len); + src += fb->pitches[0 ]; dst += fb->pitches[0 ]; }include/drm/drm_mode_config.h +0
-0@@ -865,6 +865,15 @@ struct drm_mode_config {*/ bool prefer_shadow_fbdev;
Quoted 10 lines
include/drm/drm_mode_config.h struct drm_mode_config { · line 873
Quoted 6 lines
include/drm/drm_mode_config.h +6
-0+/** +* @fbdev_use_iomem: +* +* Set to true if framebuffer reside in iomem. +* When set to true memcpy_toio() is used when copying the framebuffer in +* drm_fb_helper.drm_fb_helper_dirty_blit_real() I'd add a "FIXME: This should be replaced with a per-mapping
is_iomemflag (like ttm does), and then used everywhere in fbdev code."
OK.
Quoted 1 line
With those two nits: Reviewed-by: Daniel Vetter <[email protected]>
Thanks.
Applied to drm-misc-fixes and will push out when build testing finish.
Sam
Quoted 20 lines
Quoted 10 lines
include/drm/drm_mode_config.h +3
-1+*/ +bool fbdev_use_iomem; +/** * @quirk_addfb_prefer_xbgr_30bpp: * -- 2.25.1
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