NetBSD Problem Report #57035

From ryo_on@yk.rim.or.jp  Thu Sep 29 14:30:05 2022
Return-Path: <ryo_on@yk.rim.or.jp>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id C59981A923D
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 29 Sep 2022 14:30:05 +0000 (UTC)
Message-Id: <4MdYfx5zTSzlg2jP@mail.SiriusCloud.jp>
Date: Thu, 29 Sep 2022 22:12:08 +0900
From: ryoon@NetBSD.org
Reply-To: ryoon@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: On UEFI-booted NetBSD/amd64, genfb(4) freezes when WSDISPLAYIO_MODE_EMUL is set
X-Send-Pr-Version: 3.95

>Number:         57035
>Category:       kern
>Synopsis:       On UEFI-booted NetBSD/amd64, genfb(4) freezes when WSDISPLAYIO_MODE_EMUL is set
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          needs-pullups
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Sep 29 14:35:00 +0000 2022
>Closed-Date:    
>Last-Modified:  Fri Mar 31 10:01:28 +0000 2023
>Originator:     Ryo ONODERA
>Release:        NetBSD 9.99.100
>Organization:
Ryo ONODERA // ryo@tetera.org
PGP fingerprint = 82A2 DC91 76E0 A10A 8ABB  FD1B F404 27FA C7D1 15F3
>Environment:


System: NetBSD brownie 9.99.100 NetBSD 9.99.100 (DTRACE8) #8: Tue Sep 27 23:15:54 JST 2022 ryoon@brownie:/usr/world/9.99/amd64/obj/sys/arch/amd64/compile/DTRACE8 amd64
Architecture: x86_64
Machine: amd64
>Description:
On my Dell XPS 13 9300 (Intel Ice Lake internal GPU) and HP Envy 13-ay1052AU
laptops, genfb(4) freezes forever just after the following ioctl.

mode =  WSDISPLAYIO_MODE_EMUL;
ioctl(wd, WSDISPLAYIO_SMODE, &mode);

So xf86-video-wsfb from pkgsrc/x11/xf86-video-wsfb and mlterm-wscons from
pkgsrc/x11/mlterm cause blank screen after their exits.

Keyboard works fine even when screen is frozen.
You can reboot your machine with shutdown command.

The laptops have no BIOS/CSM boot mode. And I have no laptop with both of
BIOS/CSM and UEFI boots.

>How-To-Repeat:
Boot with genfb(4), for example 'disable i915drmkms' in kernel userconf is
specified, and run the following program. Your screen will get frozen.

=== === === === === === === === === === === === === === ===
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <string.h>
#include <dev/wscons/wsconsio.h>

#define WSDISPLAYDEV "/dev/ttyE0"

int
main(void)
{
        int mode;
        int wd;

        wd=open(WSDISPLAYDEV, O_RDWR);
        if(wd < 0)
        {
                printf("Cannot open wdsiaplay device: %s\n", strerror(errno));
        }
        mode =  WSDISPLAYIO_MODE_EMUL;
        if(ioctl(wd, WSDISPLAYIO_SMODE, &mode) == -1)
        {
                printf("Cannot change mode back to EMUL: %s\n", strerror(errno))
;
        }

        close(wd);
}
=== === === === === === === === === === === === === === ===

>Fix:
For my laptops, the following patch for genfb_pci.c fixes the problem.
However I have no idea how to detect whether current boot is BIOS/CMS or UEFI
in genfb_pci.c.

Index: sys/dev/pci/genfb_pci.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/genfb_pci.c,v
retrieving revision 1.40
diff -u -r1.40 genfb_pci.c
--- sys/dev/pci/genfb_pci.c	7 Aug 2021 16:19:14 -0000	1.40
+++ sys/dev/pci/genfb_pci.c	27 Sep 2022 13:44:38 -0000
@@ -227,7 +227,9 @@
 		return wsdisplayio_busid_pci(sc->sc_gen.sc_dev, sc->sc_pc,
 		    sc->sc_pcitag, data);

-	case WSDISPLAYIO_SMODE: {
+	case WSDISPLAYIO_SMODE:
+#if 0
+		{
 		int new_mode = *(int*)data, i;
 		if (new_mode == WSDISPLAYIO_MODE_EMUL) {
 			for (i = 0; i < 9; i++)
@@ -237,6 +239,7 @@
 				     sc->sc_bars[i]);
 		}
 		}
+#endif
 		return 0;
 	}


>Release-Note:

>Audit-Trail:
From: Rin Okuyama <rokuyama.rk@gmail.com>
To: gnats-bugs@netbsd.org, kern-bug-people@netbsd.org,
 gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, ryoon@netbsd.org
Cc: 
Subject: Re: kern/57035: On UEFI-booted NetBSD/amd64, genfb(4) freezes when
 WSDISPLAYIO_MODE_EMUL is set
Date: Fri, 30 Sep 2022 16:47:59 +0900

 Hi,

 Although I could not reproduce the problem on my amd64 machine with
 genfb(4), I've found two bugs possibly related to this problem.

 When the mode is set to WSDISPLAYIO_MODE_EMUL:

 - if the device has 64-bit BARs, their lower words are zero-cleared
 - if its expansion ROM was disabled by default, it is disabled again

 Can you try this patch?
 https://gist.github.com/rokuyama/9c50609396df00882b57be2cc2f0bc52

 Thanks,
 rin

From: Ryo ONODERA <ryo@tetera.org>
To: Rin Okuyama <rokuyama.rk@gmail.com>, gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/57035: On UEFI-booted NetBSD/amd64, genfb(4) freezes when
 WSDISPLAYIO_MODE_EMUL is set
Date: Fri, 30 Sep 2022 18:31:23 +0900

 Hi,

 Rin Okuyama <rokuyama.rk@gmail.com> writes:

 > Hi,
 >
 > Although I could not reproduce the problem on my amd64 machine with
 > genfb(4), I've found two bugs possibly related to this problem.
 >
 > When the mode is set to WSDISPLAYIO_MODE_EMUL:
 >
 > - if the device has 64-bit BARs, their lower words are zero-cleared
 > - if its expansion ROM was disabled by default, it is disabled again
 >
 > Can you try this patch?
 > https://gist.github.com/rokuyama/9c50609396df00882b57be2cc2f0bc52

 Thank you very much.
 Your patch fixes my problems on Dell XPS 13 9300 and HP Envy 13-at1052AU.

 Thanks again.

 > Thanks,
 > rin

 -- 
 Ryo ONODERA // ryo@tetera.org
 PGP fingerprint = 82A2 DC91 76E0 A10A 8ABB  FD1B F404 27FA C7D1 15F3

From: "Rin Okuyama" <rin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/57035 CVS commit: src/sys/dev/pci
Date: Sat, 1 Oct 2022 11:40:08 +0000

 Module Name:	src
 Committed By:	rin
 Date:		Sat Oct  1 11:40:08 UTC 2022

 Modified Files:
 	src/sys/dev/pci: genfb_pci.c

 Log Message:
 PR kern/57035

 genfb(4): Fix blank screen after switching to WSDISPLAYIO_MODE_EMUL for
 some GPU models like Ice Lake integrated GPU:

 - Restore lower words of 64-bit BARs correctly.
 - Do not disable expansion ROM if exists.

 Thanks ryoon@ for testing!


 To generate a diff of this commit:
 cvs rdiff -u -r1.40 -r1.41 src/sys/dev/pci/genfb_pci.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->pending-pullups
State-Changed-By: rin@NetBSD.org
State-Changed-When: Sat, 01 Oct 2022 11:45:52 +0000
State-Changed-Why:
I will request to pull this up to netbsd-[89] after a while
if no regression is reported.


From: "Rin Okuyama" <rin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/57035 CVS commit: src/sys/dev/pci
Date: Sun, 2 Oct 2022 02:37:27 +0000

 Module Name:	src
 Committed By:	rin
 Date:		Sun Oct  2 02:37:27 UTC 2022

 Modified Files:
 	src/sys/dev/pci: genfb_pci.c

 Log Message:
 PR kern/57035

 s/lower/higher/ in comment; for little endian, 2nd word is higher
 both in numeric and address. It seems that I'm too absorbed into
 big endian machines these days ;)

 No binary changes.


 To generate a diff of this commit:
 cvs rdiff -u -r1.44 -r1.45 src/sys/dev/pci/genfb_pci.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: pending-pullups->needs-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Fri, 31 Mar 2023 10:01:28 +0000
State-Changed-Why:
no pullups submitted yet, still needed


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.