Bug 213912

Summary: x11/nvidia-driver: Can't switch to the terminal in 367.44
Product: Ports & Packages Reporter: Yuri Victorovich <yuri>
Component: Individual Port(s)Assignee: Alexey Dokuchaev <danfe>
Status: In Progress ---    
Severity: Affects Only Me CC: agh, avg, grahamperrin, iwtcex, rigoletto
Priority: --- Keywords: needs-qa, regression
Version: LatestFlags: bugzilla: maintainer-feedback? (danfe)
koobs: merge-quarterly?
Hardware: Any   
OS: Any   
See Also: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=213908
Attachments:
Description Flags
patch none

Description Yuri Victorovich freebsd_committer freebsd_triage 2016-10-30 09:06:11 UTC
Ctrl+Alt+F1 switches to the screen with some colored squares and not to the terminal.
It worked in 367.44

GT610.
Comment 1 Yuri Victorovich freebsd_committer freebsd_triage 2016-10-30 09:10:35 UTC
It worked in 346.96
Comment 2 Yuri Victorovich freebsd_committer freebsd_triage 2016-10-30 09:19:26 UTC
It worked in nvidia-driver-346.96, but is broken in 367.44.
Comment 3 Alexey Dokuchaev freebsd_committer freebsd_triage 2016-11-22 03:05:06 UTC
Could you also try versions 367.57, 375.10, and 375.20 (the latest to date) to see if any of them makes a difference?  The following should be sufficient:

> make DISTVERSION=xxx.xx -DNO_CHECKSUM all check-plist install
(If there are errors during the build or packaging, correct them before installation.)
Comment 4 Yuri Victorovich freebsd_committer freebsd_triage 2016-11-22 03:54:58 UTC
375.20 is also broken.
Comment 5 Alexey Dokuchaev freebsd_committer freebsd_triage 2017-04-03 12:25:03 UTC
What about version 375.39 (per ports r437618)?
Comment 6 Yuri Victorovich freebsd_committer freebsd_triage 2017-04-03 13:41:56 UTC
375.39 also has this problem.
Comment 7 Yuri Victorovich freebsd_committer freebsd_triage 2017-07-09 00:32:41 UTC
Same with 375.66.

Is there any way to report this to NVidia? Do they have bugzilla or something like that?

How can this issue ever be solved?
Comment 8 Alexey Dokuchaev freebsd_committer freebsd_triage 2019-11-11 06:50:14 UTC
> Same with 375.66.
Recently, nVidia drivers had been updated to their latest versions, can you try them out and see if the problem went away?

> Is there any way to report this to NVidia?
Well, you may consider reporting it at their official forums at https://devtalk.nvidia.com/default/board/97/freebsd/.
Comment 9 Alex S 2019-11-11 07:18:26 UTC
(In reply to Alexey Dokuchaev from comment #8)

Let me get this straight, you don't see any corruption with vt in graphics mode? Supposedly this is a very common issue.

> if the problem went away?
No, it's still happening. I thought this might have been fixed in bug #237050, but apparently not.
Comment 10 Alexey Dokuchaev freebsd_committer freebsd_triage 2019-11-17 15:31:12 UTC
(In reply to Alex S from comment #9)

> Let me get this straight, you don't see any corruption with vt in
> graphics mode?
That's right: with TU102 (GeForce RTX 2080 Ti Rev. A), GENERIC kernel, and the latest driver installed I can switch back and forth between X.org and text consoles without seeing weird artefacts (colored squares) or other problems.

> Supposedly this is a very common issue.
Unfortunately, I do not have GT610 or similar card ATM to test the legacy driver version, so I can only rely on users' reports.
Comment 11 Alex S 2019-11-17 16:54:12 UTC
(In reply to Alexey Dokuchaev from comment #10)

> Unfortunately, I do not have GT610 or similar card ATM to test the legacy driver version
Well, I have a GTX 1660, so neither an old GPU nor a legacy driver are necessary. Still on CSM boot, though. (Which means bug #237050 is not applicable, maybe a similar patch to vt's vga backend will fix it, but I'm too lazy to check.)

> so I can only rely on users' reports.
You don't hear anything from users because they usually switch to sc or vt in textmode. Here a few random mentions:

1. https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=201461#c19
2. https://github.com/project-trident/trident-core/blob/81a7593c37cbad43f120d49045a593ae21dee210/core-files/boot/loader.conf.local#L28
3. https://markmail.org/message/lmhxuq2yotfajsmj
4. https://twitter.com/ibilimov/status/1029041347947311106
5. https://forums.freebsd.org/threads/using-freebsd-as-desktop-os.57329/page-12#post-382439

There is also a great deal of confusion between suspend/resume, black screen and colored squares issues, so it's a bit difficult to assess how often each one happens.
Comment 12 Yuri Victorovich freebsd_committer freebsd_triage 2019-11-19 02:11:32 UTC
(In reply to Alexey Dokuchaev from comment #8)

The latest NVidia driver 440.31 refused to load with this card, and recommended to use nvidia-driver-390-390.129, which has the same behavior.

I'll throw away this card, because it is really old. Please feel free to close this bug, because it isn't going to be fixed anyway.
Comment 13 Yuri Victorovich freebsd_committer freebsd_triage 2020-09-12 05:20:21 UTC
Alexey,

You can close this bug, IMO, because it is related to a very old hardware/driver, and realistically this will likely never be fixed.


Cheers,
Yuri
Comment 14 Alex S 2020-09-12 08:42:05 UTC
(In reply to Yuri Victorovich from comment #13)
> this will likely never be fixed

This is almost certainly _not_ an Nvidia's issue, but rather a FreeBSD bug, so "never fixed" is entirely self inflicted.
Comment 15 Yuri Victorovich freebsd_committer freebsd_triage 2020-09-12 09:05:42 UTC
(In reply to Alex S from comment #14)

Does this problem only exist with the old hardware/driver, or with the latest too?
Comment 16 Alex S 2020-09-12 09:16:15 UTC
(In reply to Yuri Victorovich from comment #15)

> Does this problem only exist with the old hardware/driver, or with the latest too?

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=213912#c11:

> Well, I have a GTX 1660, so neither an old GPU nor a legacy driver are necessary. Still on CSM boot
Comment 17 Alex S 2021-04-18 12:42:44 UTC
FWIW, now that vt has the vbe framebuffer mode, which has the same interface as efi framebuffer, switching should work after the following adjustment:

--- src/nvidia/nvidia_os.c.orig	2021-04-08 21:02:56.000000000 +0300
+++ src/nvidia/nvidia_os.c	2021-04-18 15:38:19.188555000 +0300
@@ -810,6 +810,28 @@
             *pFbPitch = efifb->fb_stride * (bpp / NBBY);
             return;
         }
+
+        const struct vbe_fb *vbefb =
+            (const struct vbe_fb *)preload_search_info(kmdp, MODINFO_METADATA |
+                                                             MODINFOMD_VBE_FB);
+
+        /* Make sure base address is mapped to GPU BAR */
+        if ((vbefb != NULL) &&
+            ((vbefb->fb_addr == consoleBar1Address) ||
+             (vbefb->fb_addr == consoleBar2Address)))
+        {
+            int depth = fls(vbefb->fb_mask_red | vbefb->fb_mask_green |
+                            vbefb->fb_mask_blue | vbefb->fb_mask_reserved);
+            int bpp = roundup2(depth, NBBY);
+
+            *pPhysicalAddress = vbefb->fb_addr;
+            *pFbWidth = vbefb->fb_width;
+            *pFbHeight = vbefb->fb_height;
+            *pFbDepth = depth;
+            /* fb_stride is in pixels. Convert to bytes */
+            *pFbPitch = vbefb->fb_stride * (bpp / NBBY);
+            return;
+        }
     }
     {

(This is a verbatim copy of the preceding code with s/efi/vbe/.)
Comment 18 Yuri Victorovich freebsd_committer freebsd_triage 2022-12-27 23:16:53 UTC
(In reply to Alex S from comment #17)

I tried this patch with nvidia-driver-510.60.02 on 13.1 STABLE stable/13-n253229-dd7b7807c32a and it didn't help - still can't switch to the black terminal.
Comment 19 Alex S 2022-12-28 07:40:45 UTC
(In reply to Yuri Victorovich from comment #18)

Did you switch vt into the vbe framebuffer mode? Put `vbe_max_resolution="720p"` in /boot/loader.conf if you didn't.
Comment 20 Yuri Victorovich freebsd_committer freebsd_triage 2022-12-28 08:13:16 UTC
Created attachment 239080 [details]
patch

(In reply to Alex S from comment #19)

Alex,

I confirm that it works. Thank you for providing a way to fix this problem.

I combined your patch and your recommendation to add vbe_max_resolution="720p" to /boot/loader.conf into the attached patch.

@danfe Alexey, could you please either commit or approve the patch?


Thank you,
Yuri
Comment 21 commit-hook freebsd_committer freebsd_triage 2023-01-16 06:39:24 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=010b19127cc848d585ab515ea2db29796b441929

commit 010b19127cc848d585ab515ea2db29796b441929
Author:     Yuri Victorovich <yuri@FreeBSD.org>
AuthorDate: 2023-01-16 06:35:56 +0000
Commit:     Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2023-01-16 06:38:30 +0000

    x11/nvidia-driver: Fix bug that switching to the terminal wasn't possible

    Tested with NVidia RTX 2060 on FreeBSD 13.1 STABLE.

    PR:             213912
    Approved by:    danfe@ (maintainer's timeout; 18 days)

 x11/nvidia-driver/Makefile                         |  2 +-
 .../files/patch-src_nvidia_nvidia__os.c (new)      | 34 ++++++++++++++++++++++
 x11/nvidia-driver/pkg-message (new)                | 10 +++++++
 3 files changed, 45 insertions(+), 1 deletion(-)
Comment 22 Yuri Victorovich freebsd_committer freebsd_triage 2023-01-16 06:40:26 UTC
Not closing because older driver generations might need to be patched in a similar fashion.

Leaving this to the maintainer.
Comment 23 Alexey Dokuchaev freebsd_committer freebsd_triage 2023-01-16 08:29:48 UTC
Sorry, but I had to revert ports 010b19127cc8 as it breaks legacy drivers.  Please thoroughly test all nVidia driver ports when committing even trivial patches, or better wait for approval which was not given here for a reason.  While I'm happy to hear that this particular patch helps some users, I'd like to see it being sent and reviewed upstream first.
Comment 24 Yuri Victorovich freebsd_committer freebsd_triage 2023-01-16 08:31:48 UTC
(In reply to Alexey Dokuchaev from comment #23)

The port maintainer should do this.