Skip to contentSkip to conversation

drm: Fix fbcon blank on QEMU graphics drivers

PATCH In review Takashi Iwai 3 participants 5 messages Apr 16, 2021 – Apr 20, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm: Fix fbcon blank on QEMU graphics drivers

Currently the DRM fbcon helper for console blank, drm_fb_helper_blank(), simply calls drm_fb_helper_dpms() and always returns zero, supposing the driver dealing with DPMS or atomic crtc->active flip to handle blanking the screen. It works on most of devices, but broken on most of KVM/QEMU graphics: bochs, qxl and cirrus drivers just ignore crtc->active state change as blanking (or cirrus ignoring DPMS). In practice, when you run like
% setterm --blank force
on a VT console, the screen freezes without actually blanking.

A simple fix for this problem would be not to rely on DPMS but let fbcon performs the generic blank code. This can be achieved just by returning an error from drm_fb_helper_blank().

In this patch, we add a flag, no_dpms_blank, to drm_fb_helper for indicating that the driver doesn't handle blank via DPMS or crtc->active flip. When this flag is set, drm_fb_helper_blank() simply returns an error, so that fbcon falls back to its generic blank handler. The flag is set to both bochs and qxl drivers in this patch, while cirrus is left untouched as it's declared as to-be-deprecated.

---

Here I whip a dead horse again, revisiting the long-standing issue stated in the previous patch set in 2017:
https://lore.kernel.org/dri-devel/[email protected]/

I thought to refresh the previous patch set at first, but it seems invalid for the atomic modeset case. And for the atomic, it's even more difficult to propagate the return from the bottom to up. So I ended up with this approach as it's much simpler.

But if there is any better way (even simpler or more robust), I'd happily rewrite, too.

---
 drivers/gpu/drm/bochs/bochs_drv.c | 3 +++
 drivers/gpu/drm/drm_fb_helper.c   | 5 +++++
 drivers/gpu/drm/qxl/qxl_drv.c     | 3 +++
 include/drm/drm_fb_helper.h       | 8 ++++++++
 4 files changed, 19 insertions(+)
drivers/gpu/drm/bochs/bochs_drv.c +3 -0
index b469624fe40d..816899a266ff 100644
@@ -132,6 +132,9 @@ static int bochs_pci_probe(struct pci_dev *pdev,
 		goto err_unload;
 
 	drm_fbdev_generic_setup(dev, 32);
+	if (dev->fb_helper)
+		dev->fb_helper->no_dpms_blank = true;
+
 	return ret;
 
 err_unload:
drivers/gpu/drm/drm_fb_helper.c +5 -0
index f6baa2046124..b892f02ff2f1 100644
@@ -332,9 +332,14 @@ static void drm_fb_helper_dpms(struct fb_info *info, int dpms_mode)
  */
 int drm_fb_helper_blank(int blank, struct fb_info *info)
 {
+	struct drm_fb_helper *fb_helper = info->par;
+
 	if (oops_in_progress)
 		return -EBUSY;
 
+	if (fb_helper->no_dpms_blank)
+		return -EINVAL;
+
 	switch (blank) {
 	/* Display: On; HSync: On, VSync: On */
 	case FB_BLANK_UNBLANK:
drivers/gpu/drm/qxl/qxl_drv.c +3 -0
index 1864467f1063..58ecfaeed7c1 100644
@@ -120,6 +120,9 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 		goto modeset_cleanup;
 
 	drm_fbdev_generic_setup(&qdev->ddev, 32);
+	if (qdev->fb_helper)
+		qdev->fb_helper->no_dpms_blank = true;
+
 	return 0;
 
 modeset_cleanup:
include/drm/drm_fb_helper.h +8 -0
index 3b273f9ca39a..151be4219c32 100644
@@ -176,6 +176,14 @@ struct drm_fb_helper {
 	 */
 	bool deferred_setup;
 
+	/**
+	 * @no_dpms_blank:
+	 *
+	 * A flag indicating that the driver doesn't support blanking.
+	 * Then fbcon core code falls back to its generic handler.
+	 */
+	bool no_dpms_blank;
+
 	/**
 	 * @preferred_bpp:
 	 *
Signature · 6 lines
2.26.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
I love your patch! Yet something to improve:

Hi Takashi,

I love your patch! Yet something to improve:

[auto build test ERROR on drm-intel/for-linux-next]
[also build test ERROR on drm-tip/drm-tip drm-exynos/exynos-drm-next tegra-drm/drm/tegra/for-next linus/master v5.12-rc7 next-20210416] [cannot apply to drm/drm-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Takashi-Iwai/drm-Fix-fbcon-blank-on-QEMU-graphics-drivers/20210416-205539
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: x86_64-randconfig-a003-20210416 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 6a18cc23efad410db48a3ccfc233d215de7d4cb9)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/4b1a07505589e5f12ae52f249fa93b400e35e602
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Takashi-Iwai/drm-Fix-fbcon-blank-on-QEMU-graphics-drivers/20210416-205539 git checkout 4b1a07505589e5f12ae52f249fa93b400e35e602
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

>> drivers/gpu/drm/qxl/qxl_drv.c:123:12: error: no member named 'fb_helper' in 'struct qxl_device'
           if (qdev->fb_helper)
               ~~~~  ^
   drivers/gpu/drm/qxl/qxl_drv.c:124:9: error: no member named 'fb_helper' in 'struct qxl_device'
                   qdev->fb_helper->no_dpms_blank = true;
                   ~~~~  ^

2 errors generated.

vim +123 drivers/gpu/drm/qxl/qxl_drv.c

    71	
    72	static int
    73	qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
    74	{
    75		struct qxl_device *qdev;
    76		int ret;
    77	
    78		if (pdev->revision < 4) {
    79			DRM_ERROR("qxl too old, doesn't support client_monitors_config,"
    80				  " use xf86-video-qxl in user mode");
    81			return -EINVAL; /* TODO: ENODEV ? */
    82		}
    83	
    84		qdev = devm_drm_dev_alloc(&pdev->dev, &qxl_driver,
    85					  struct qxl_device, ddev);
    86		if (IS_ERR(qdev)) {
    87			pr_err("Unable to init drm dev");
    88			return -ENOMEM;
    89		}
    90	
    91		ret = pci_enable_device(pdev);
    92		if (ret)
    93			return ret;
    94	
    95		ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "qxl");
    96		if (ret)
    97			goto disable_pci;
    98	
    99		if (is_vga(pdev) && pdev->revision < 5) {
   100			ret = vga_get_interruptible(pdev, VGA_RSRC_LEGACY_IO);
   101			if (ret) {
   102				DRM_ERROR("can't get legacy vga ioports\n");
   103				goto disable_pci;
   104			}
   105		}
   106	
   107		ret = qxl_device_init(qdev, pdev);
   108		if (ret)
   109			goto put_vga;
   110	
   111		ret = qxl_modeset_init(qdev);
   112		if (ret)
   113			goto unload;
   114	
   115		drm_kms_helper_poll_init(&qdev->ddev);
   116	
   117		/* Complete initialization. */
   118		ret = drm_dev_register(&qdev->ddev, ent->driver_data);
   119		if (ret)
   120			goto modeset_cleanup;
   121	
   122		drm_fbdev_generic_setup(&qdev->ddev, 32);
 > 123		if (qdev->fb_helper)

124 qdev->fb_helper->no_dpms_blank = true;
125
126 return 0;
127
128 modeset_cleanup:
129 qxl_modeset_fini(qdev);
130 unload:
131 qxl_device_fini(qdev);
132 put_vga:
133 if (is_vga(pdev) && pdev->revision < 5)
134 vga_put(pdev, VGA_RSRC_LEGACY_IO);
135 disable_pci:
136 pci_disable_device(pdev);
137
138 return ret;
139 }
140

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

#2 lore raw
In reply to Takashi Iwai
I love your patch! Yet something to improve:

Hi Takashi,

I love your patch! Yet something to improve:

[auto build test ERROR on drm-intel/for-linux-next]
[also build test ERROR on drm-tip/drm-tip drm-exynos/exynos-drm-next tegra-drm/drm/tegra/for-next linus/master v5.12-rc7 next-20210416] [cannot apply to drm/drm-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Takashi-Iwai/drm-Fix-fbcon-blank-on-QEMU-graphics-drivers/20210416-205539
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: mips-randconfig-r001-20210416 (attached as .config)
compiler: mips64el-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/4b1a07505589e5f12ae52f249fa93b400e35e602
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Takashi-Iwai/drm-Fix-fbcon-blank-on-QEMU-graphics-drivers/20210416-205539 git checkout 4b1a07505589e5f12ae52f249fa93b400e35e602
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross W=1 ARCH=mips

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

drivers/gpu/drm/qxl/qxl_drv.c: In function 'qxl_pci_probe':

>> drivers/gpu/drm/qxl/qxl_drv.c:123:10: error: 'struct qxl_device' has no member named 'fb_helper'
     123 |  if (qdev->fb_helper)
         |          ^~
   drivers/gpu/drm/qxl/qxl_drv.c:124:7: error: 'struct qxl_device' has no member named 'fb_helper'
     124 |   qdev->fb_helper->no_dpms_blank = true;
         |       ^~

vim +123 drivers/gpu/drm/qxl/qxl_drv.c

    71	
    72	static int
    73	qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
    74	{
    75		struct qxl_device *qdev;
    76		int ret;
    77	
    78		if (pdev->revision < 4) {
    79			DRM_ERROR("qxl too old, doesn't support client_monitors_config,"
    80				  " use xf86-video-qxl in user mode");
    81			return -EINVAL; /* TODO: ENODEV ? */
    82		}
    83	
    84		qdev = devm_drm_dev_alloc(&pdev->dev, &qxl_driver,
    85					  struct qxl_device, ddev);
    86		if (IS_ERR(qdev)) {
    87			pr_err("Unable to init drm dev");
    88			return -ENOMEM;
    89		}
    90	
    91		ret = pci_enable_device(pdev);
    92		if (ret)
    93			return ret;
    94	
    95		ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "qxl");
    96		if (ret)
    97			goto disable_pci;
    98	
    99		if (is_vga(pdev) && pdev->revision < 5) {
   100			ret = vga_get_interruptible(pdev, VGA_RSRC_LEGACY_IO);
   101			if (ret) {
   102				DRM_ERROR("can't get legacy vga ioports\n");
   103				goto disable_pci;
   104			}
   105		}
   106	
   107		ret = qxl_device_init(qdev, pdev);
   108		if (ret)
   109			goto put_vga;
   110	
   111		ret = qxl_modeset_init(qdev);
   112		if (ret)
   113			goto unload;
   114	
   115		drm_kms_helper_poll_init(&qdev->ddev);
   116	
   117		/* Complete initialization. */
   118		ret = drm_dev_register(&qdev->ddev, ent->driver_data);
   119		if (ret)
   120			goto modeset_cleanup;
   121	
   122		drm_fbdev_generic_setup(&qdev->ddev, 32);
 > 123		if (qdev->fb_helper)

124 qdev->fb_helper->no_dpms_blank = true;
125
126 return 0;
127
128 modeset_cleanup:
129 qxl_modeset_fini(qdev);
130 unload:
131 qxl_device_fini(qdev);
132 put_vga:
133 if (is_vga(pdev) && pdev->revision < 5)
134 vga_put(pdev, VGA_RSRC_LEGACY_IO);
135 disable_pci:
136 pci_disable_device(pdev);
137
138 return ret;
139 }
140

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

#3 lore raw
In reply to Takashi Iwai
Quoted 22 lines · Takashi Iwai

Currently the DRM fbcon helper for console blank, drm_fb_helper_blank(), simply calls drm_fb_helper_dpms() and always returns zero, supposing the driver dealing with DPMS or atomic crtc->active flip to handle blanking the screen. It works on most of devices, but broken on most of KVM/QEMU graphics: bochs, qxl and cirrus drivers just ignore crtc->active state change as blanking (or cirrus ignoring DPMS). In practice, when you run like
% setterm --blank force
on a VT console, the screen freezes without actually blanking.

A simple fix for this problem would be not to rely on DPMS but let fbcon performs the generic blank code. This can be achieved just by returning an error from drm_fb_helper_blank().

In this patch, we add a flag, no_dpms_blank, to drm_fb_helper for indicating that the driver doesn't handle blank via DPMS or crtc->active flip. When this flag is set, drm_fb_helper_blank() simply returns an error, so that fbcon falls back to its generic blank handler. The flag is set to both bochs and qxl drivers in this patch, while cirrus is left untouched as it's declared as to-be-deprecated.

Quoted 3 lines

Uh we're supposed to fix these drivers to actually blank (scan out black, worst case), not paper over it in higher levels. Atomic kms is meant to be a somewhat useful abstraction. So now fbcon blanks, but your desktop still just freezes.

Quoted 10 lines

---

Here I whip a dead horse again, revisiting the long-standing issue stated in the previous patch set in 2017:
https://lore.kernel.org/dri-devel/[email protected]/

I thought to refresh the previous patch set at first, but it seems invalid for the atomic modeset case. And for the atomic, it's even more difficult to propagate the return from the bottom to up. So I ended up with this approach as it's much simpler.

Yeah that's because atomic assume you can at least blank your screen to black. -Daniel

Quoted 83 lines

But if there is any better way (even simpler or more robust), I'd happily rewrite, too.

---
 drivers/gpu/drm/bochs/bochs_drv.c | 3 +++
 drivers/gpu/drm/drm_fb_helper.c   | 5 +++++
 drivers/gpu/drm/qxl/qxl_drv.c     | 3 +++
 include/drm/drm_fb_helper.h       | 8 ++++++++
 4 files changed, 19 insertions(+)
drivers/gpu/drm/bochs/bochs_drv.c +3 -0
index b469624fe40d..816899a266ff 100644
@@ -132,6 +132,9 @@ static int bochs_pci_probe(struct pci_dev *pdev,
                goto err_unload;
 
        drm_fbdev_generic_setup(dev, 32);
+       if (dev->fb_helper)
+               dev->fb_helper->no_dpms_blank = true;
+
        return ret;
 
 err_unload:
drivers/gpu/drm/drm_fb_helper.c +5 -0
index f6baa2046124..b892f02ff2f1 100644
@@ -332,9 +332,14 @@ static void drm_fb_helper_dpms(struct fb_info *info, int dpms_mode)
  */
 int drm_fb_helper_blank(int blank, struct fb_info *info)
 {
+       struct drm_fb_helper *fb_helper = info->par;
+
        if (oops_in_progress)
                return -EBUSY;
 
+       if (fb_helper->no_dpms_blank)
+               return -EINVAL;
+
        switch (blank) {
        /* Display: On; HSync: On, VSync: On */
        case FB_BLANK_UNBLANK:
drivers/gpu/drm/qxl/qxl_drv.c +3 -0
index 1864467f1063..58ecfaeed7c1 100644
@@ -120,6 +120,9 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                goto modeset_cleanup;
 
        drm_fbdev_generic_setup(&qdev->ddev, 32);
+       if (qdev->fb_helper)
+               qdev->fb_helper->no_dpms_blank = true;
+
        return 0;
 
 modeset_cleanup:
include/drm/drm_fb_helper.h +8 -1
index 3b273f9ca39a..151be4219c32 100644
@@ -176,6 +176,14 @@ struct drm_fb_helper {
         */
        bool deferred_setup;
 
+       /**
+        * @no_dpms_blank:
+        *
+        * A flag indicating that the driver doesn't support blanking.
+        * Then fbcon core code falls back to its generic handler.
+        */
+       bool no_dpms_blank;
+
        /**
         * @preferred_bpp:
         *
--

2.26.2

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

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
#4 lore raw
Quoted 39 lines · Daniel Vetter
Quoted 22 lines · Takashi Iwai

Currently the DRM fbcon helper for console blank, drm_fb_helper_blank(), simply calls drm_fb_helper_dpms() and always returns zero, supposing the driver dealing with DPMS or atomic crtc->active flip to handle blanking the screen. It works on most of devices, but broken on most of KVM/QEMU graphics: bochs, qxl and cirrus drivers just ignore crtc->active state change as blanking (or cirrus ignoring DPMS). In practice, when you run like
% setterm --blank force
on a VT console, the screen freezes without actually blanking.

A simple fix for this problem would be not to rely on DPMS but let fbcon performs the generic blank code. This can be achieved just by returning an error from drm_fb_helper_blank().

In this patch, we add a flag, no_dpms_blank, to drm_fb_helper for indicating that the driver doesn't handle blank via DPMS or crtc->active flip. When this flag is set, drm_fb_helper_blank() simply returns an error, so that fbcon falls back to its generic blank handler. The flag is set to both bochs and qxl drivers in this patch, while cirrus is left untouched as it's declared as to-be-deprecated.

Quoted 3 lines

Uh we're supposed to fix these drivers to actually blank (scan out black, worst case), not paper over it in higher levels. Atomic kms is meant to be a somewhat useful abstraction. So now fbcon blanks, but your desktop still just freezes.

Quoted 6 lines

---

Here I whip a dead horse again, revisiting the long-standing issue stated in the previous patch set in 2017:
https://lore.kernel.org/dri-devel/[email protected]/

Quoted 6 lines
Quoted 4 lines

I thought to refresh the previous patch set at first, but it seems invalid for the atomic modeset case. And for the atomic, it's even more difficult to propagate the return from the bottom to up. So I ended up with this approach as it's much simpler.

Yeah that's because atomic assume you can at least blank your screen to black.

OK, then there is no other way than fixing those drivers to deal with the blanking...

I cooked up an experimental patch for bochs, and will submit later.

thanks,

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