System is unusable after upgrade to 20.10 - i915 GPU hang

I have a Lenovo G710 laptop that ran Ubuntu flawlessly since 15.04.

After updating to 20.04 there were occasional random complete freezes of the desktop. Having updated to 20.10, it now boots okay and the login screen appears normal. The desktop is fine until I try to open any application. The application name appears at the top, and then the desktop completely freezes. In some cases the app icon in the dock becomes pixelated. Sometimes a portion of the desktop flickers to solid black.

The mouse still moves occasionally, and I can CTRL+ALT+F3 to a command line.

Various searches suggest a graphics driver problem. It's an Intel Haswell graphics chip.

I've tried both the Ubuntuand Ubuntu on Wayland options at log in, both give the same results.

What is the best way to approach this?

EDIT:

Output of ls -al ~/.local/share/gnome-shell/extensions

drwxrwxr-x 4 carl carl 4096 Oct 26 18:29 gTile@vibou
drwxrwxr-x 3 carl carl 4096 Aug 13 18:55 [email protected]
drwxrwxr-x 3 carl carl 4096 Oct 30 14:53 [email protected]
drwxrwxr-x 2 carl carl 4096 Sep 10 18:11 [email protected]
drwxrwxr-x 3 carl carl 4096 Oct 30 14:53 [email protected]

Output of ls -al /usr/share/gnome-shell/extensions

drwxr-xr-x 2 root root 4096 Oct 30 13:53 desktop-icons@csoriano
drwxr-xr-x 3 root root 4096 Oct 30 13:53 [email protected]
drwxr-xr-x 3 root root 4096 Oct 30 13:53 [email protected]

Output of free -h

              total        used        free      shared  buff/cache   available
Mem:          5.7Gi       735Mi       4.2Gi        73Mi       855Mi       4.7Gi
Swap:         2.0Gi          0B       2.0Gi

Output of sysctl vm.swappiness

vm.swappiness = 60

EDIT 2 Output of dmesg includes i915 GPU HANG


UPDATE : Ubuntu 21.04 current ISO image was tested, it includes kernel 5.11.0-11 and the installation proceeded normally.

The 5.11 Ubuntu distribution kernels are causing the same instability problems with Gnome, KDE, XFCE (at least) like the home-compiled 5.11 kernels, if you are facing the same problems stay with kernels before 5.11 .

UPDATE 2 : Kernel was upgraded to 5.11.0-22, everything works fine.

TIP : You can download and test the Latest Development ISO by synchronizing with the following command.

zsync http://cdimage.ubuntu.com/daily-live/current/jammy-desktop-amd64.iso.zsync

The first time you run the command the ISO will be downloaded, any other time you run the same command in the ISO's directory the system will check whether there are any changes and it will update the ISO if necessary.


Recommended Solution : Install a kernel version that works, from your distribution's repository

Note : If you want to perform a fresh installation from an image that crashes the graphical installation environment due to this i915 problem, select (Safe Graphics) in the ISO's boot menu and after the installation perform the necessary steps.

For example a Focal Fossa user will download and install the following packages from

https://packages.ubuntu.com/focal/kernel/

  1. linux-image-(kernel_version)-generic
  2. linux-modules-(kernel_version)-generic
  3. linux-modules-extra-(kernel_version)-generic

Install with command,

sudo apt install <package>

Reboot.

The system will automatically boot with the new kernel if you haven't installed any newer kernel, in any other case select the kernel from the GRUB menu.


Advanced approach

The solution for kernels before 5.11 is here Red Hat Bugzilla – Bug 1843274

The GUI system can become usable if you boot with your old kernel 5.4.0 . The terminal is still usable with 5.8.0 kernel, try CTRL+ALT+F3.

The solution is to patch the i915 module. Download the patch from here

To understand the patch have a look at Intel's Manual page 50, it has to do with the command MEDIA_VFE_STATE which has to be provided with the right number of threads according to the model of the GPU.

First method: Patch and recompile a new kernel

Quick guide

  1. The basic dependencies to build the kernel are sudo apt install libncurses-dev flex bison openssl libssl-dev dkms libelf-dev libudev-dev libpci-dev libiberty-dev autoconf
  2. Download the kernel source of your choice from www.kernel.org and extract it.
  3. Go inside the kernel source directory.
  4. Clean the kernel with sudo make mrproper in the kernel's directory.
  5. Download the patch into the kernel's source code parent directory.
  6. Apply the patch with patch -p1 < ../drm-i915-gt-Limit-VFE-threads-based-on-GT.patch
  7. Configure the kernel or run sudo make localmodconfig to finish quickly, hold the Enter key until all the questions are answered
  8. Compile the kernel with sudo make -j (# of CPU threads) bindeb-pkg
  9. Install the linux-image and the linux-headers deb packages produced in the parent directory of the kernel source directory
  10. Reboot and if necessary choose the new kernel from the GRUB menu

Optimize the above procedure according to your preferences, your hardware etc

Second method: Patch and recompile the module only

It is also possible to rebuild the patched module for an already installed kernel so as to be able to use the official distribution kernels or any other precompiled kernels.

The official i915 compilation guide from Intel is here, if you download it as a PDF go to page 41.

You can follow the steps exactly as they are presented but notice the following.

  1. If you are going to recompile the module for another kernel version than the one you are running then you have to replace $(uname -r) with the version you are targeting, for example 5.8.0-29-generic .

  2. If you use the /tmp/kernel directory as in the guide then this directory will be lost after a reboot.

  3. After step 5 you have to patch the kernel with patch -p1 < ../drm-i915-gt-Limit-VFE-threads-based-on-GT.patch assuming the patch is located into the kernel's source code parent directory

  4. Step 9 can be skipped.

  5. After step 12 you may get an error concerning the cryptographic verification of the module, there is no problem, the module has been installed in /lib/modules/5.8.0-29-generic/extradrivers and the system knows that it is there and should be loaded through step 13.

  6. Step 14 should be performed stating the target kernel version, for 5.8.0-29-generic alter the commands like this sudo depmod -v 5.8.0-29-generic and sudo update-initramfs -k 5.8.0-29-generic -u .

After a reboot your system will be usable again.

This procedure should be performed for any new kernel until the problem is solved by Ubuntu.


I migrated from Kubuntu 20.04 to 20.10 and have the same "GPU Hang" bug with an Acer 720p. While waiting fro a fix I downgraded the kernel from 5.8 to 5.4 and it's now working well.


This is an existing bug with the i915 driver in recent Linux kernels.

See https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1872001 and https://gitlab.freedesktop.org/drm/intel/-/issues/673

As yet, there is no solution or workaround. I have replaced Ubuntu 20.10 with Ubuntu 18.04.

UPDATE - I've accepted the other answer as judging by the upvotes it is correct, which should be more useful to anyone else having this problem.
(Disclaimer - I haven't tried it myself)


This issue is caused due to a bug in the kernel. You can easily get this resolved, by booting Ubuntu in previous kernels wherein the terminal is usable. You can do this by reaching the grub menu, and selecting 'advanced options' and then selecting any of the previous kernel for booting in.

Once you boot in and terminal is open, type in the following commands to upgrade your kernel to latest version available (5.10.13 and above will solve this issue)

  1. This command installs the wget utility that will be used for downloading a kernel upgrader script:

    sudo apt install wget
    
  2. This command will pull the script from github and store it in your home directory

    wget https://raw.githubusercontent.com/pimlie/ubuntu-mainline-kernel.sh/master/ubuntu-mainline-kernel.sh 
    
  3. This command will install the script in your bin directory, so that its easier to execute in the terminal with the following command:

    sudo install ubuntu-mainline-kernel.sh /usr/local/bin/
    
  4. Install the latest mainline kernel:

    sudo ubuntu-mainline-kernel.sh -i 
    

Alternatively, you can even install a particular kernel version:

sudo ubuntu-mainline-kernel.sh -i 5.10.13 

After executing this command, it will take a few minutes to install the kernel headers and images, post which you need to reboot your system

sudo reboot

After reboot, confirm the kernel version by executing the following command:

uname -r 

You should see an output similar to:

5.10.13-051013-generic

Done. Bug resolved!