2

Background:

I have bought myself a thunderbolt eGPU case (Razer Core) and I want to use it with my AMD GPU (Rx480) on Linux. I use Kernel 5.0. Plugging in the eGPU while the PC is running seems to work.

> DRI_PRIME=1 glxinfo | grep "OpenGL renderer"
OpenGL renderer string: AMD Radeon (TM) RX 480 Graphics (POLARIS10, DRM 3.27.0, 5.0.16-050016-generic, LLVM 7.0.0)

However, unplugging the GPU freezes the system. Disabling the PCI device with the following command also leads to a freeze:

> sudo sh -c 'echo 1 > /sys/bus/pci/devices/0000:06:04.0/remove'

Apparently the reason for this is, that the graphics driver (amdgpu) is still using the device. So I tried to end the graphics driver:

> sudo modprobe -r amdgpu
modprobe: FATAL: Module amdgpu is in use

The application that uses the driver module is the display manager (lightdm 1.26.0).

What works is to switch to one of the Ctrl-Alt-F1 consoles and execute:

> sudo service lightdm stop
> sudo modprobe -r amdgpu
> sudo sh -c 'echo 1 > /sys/bus/pci/devices/0000:06:04.0/remove'

[Unpluging the eGPU]

> sudo service lightdm start

and then switching back to the desktop (Ctrl-Alt-F7). However, all desktop applications are lost this way.

Question:

Can I somehow remove the amdgpu driver without shutting down lightdm? Or can I restart lightdm without loosing all desktop applications?

Jounathaen
  • 629
  • 1
  • 5
  • 18

2 Answers2

3

Technically it is possible. However, AMD didn't implement it for Linux.

static void
amdgpu_pci_remove(struct pci_dev *pdev)
{
    struct drm_device *dev = pci_get_drvdata(pdev);

#ifdef MODULE
    if (THIS_MODULE->state != MODULE_STATE_GOING)
#endif
        DRM_ERROR("Hotplug removal is not supported\n");
    drm_dev_unplug(dev);
    amdgpu_driver_unload_kms(dev);
    pci_disable_device(pdev);
    pci_set_drvdata(pdev, NULL);
    drm_dev_put(dev);
}

Source: https://cgit.freedesktop.org/~agd5f/linux/tree/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c?h=drm-next-5.7

0

Maybe you will have luck with unbinding the GPU:

echo -n "0000:06:04.0" > /sys/bus/pci/drivers/amdgpu/unbind

and after that remove.

According to this bug: https://bugs.freedesktop.org/show_bug.cgi?id=111229 unbinding was possible on kernel 4.19 and is fixed on kernel 5.3.