Proof of concept for GPU forwarding for Linux guest on Linux host
Subsystems (3)
Hi,
This is a proof of concept of GPU forwarding for Linux guest on Linux host. I'd like to get comments and suggestions from community before I put more time on it. To summarize what it is:
1. It's a solution to bring GPU acceleration for Linux vm guest on Linux host. It could works with different GPU although the current proof of concept only works with Intel GPU.
2. This shows as a kernel patch. The actual qemu diff is nested in tools/forward/qemu.diff
3. The basic idea is: under Linux, most applications use GPU acceleration with help of MESA library. And MESA library interacts with kernel GPU driver by operating on some special character device file exported by kernel GPU driver. MESA library opens some special files in system and operations on GPU are done by ioctl/mmap system call and regular memory operations.
We just write a kernel driver for guest Linux kernel and let it exports same interface to user space like the real Linux GPU kernel driver. So it's an API proxy between host and VM guest. We just proxy API at system call level.
4. Some nasty things was done in guest kernel as a quick dirty hack so we don't need to touch user space (wayland/mesa etc) now.
5. You can check tools/forward/README for instructions.
Thanks!
Tao Wu (1):
proof of concept for GPU forwarding
arch/x86/configs/x86_64_defconfig | 5 + drivers/char/Makefile | 1 + drivers/char/forwarder/Makefile | 8 + drivers/char/forwarder/forwarder.h | 103 ++ drivers/char/forwarder/forwarder_drv.c | 2104 ++++++++++++++++++++++++ fs/open.c | 18 + include/uapi/linux/virtwl.h | 64 + tools/forward/Makefile | 2 + tools/forward/README | 58 + tools/forward/qemu.diff | 1117 +++++++++++++ tools/forward/wayland-proxy-main.c | 58 + tools/forward/wayland-proxy.c | 297 ++++ 12 files changed, 3835 insertions(+) create mode 100644 drivers/char/forwarder/Makefile create mode 100644 drivers/char/forwarder/forwarder.h create mode 100644 drivers/char/forwarder/forwarder_drv.c create mode 100644 include/uapi/linux/virtwl.h create mode 100644 tools/forward/Makefile create mode 100644 tools/forward/README create mode 100644 tools/forward/qemu.diff create mode 100644 tools/forward/wayland-proxy-main.c create mode 100644 tools/forward/wayland-proxy.c
Signature · 1 line
2.21.0.392.gf8f6787159e-goog
PATCH 1/1 proof of concept for GPU forwarding
--- arch/x86/configs/x86_64_defconfig | 5 + drivers/char/Makefile | 1 + drivers/char/forwarder/Makefile | 8 + drivers/char/forwarder/forwarder.h | 103 ++ drivers/char/forwarder/forwarder_drv.c | 2104 ++++++++++++++++++++++++ fs/open.c | 18 + include/uapi/linux/virtwl.h | 64 + tools/forward/Makefile | 2 + tools/forward/README | 58 + tools/forward/qemu.diff | 1117 +++++++++++++ tools/forward/wayland-proxy-main.c | 58 + tools/forward/wayland-proxy.c | 297 ++++ 12 files changed, 3835 insertions(+) create mode 100644 drivers/char/forwarder/Makefile create mode 100644 drivers/char/forwarder/forwarder.h create mode 100644 drivers/char/forwarder/forwarder_drv.c create mode 100644 include/uapi/linux/virtwl.h create mode 100644 tools/forward/Makefile create mode 100644 tools/forward/README create mode 100644 tools/forward/qemu.diff create mode 100644 tools/forward/wayland-proxy-main.c create mode 100644 tools/forward/wayland-proxy.c
arch/x86/configs/x86_64_defconfig +5 -0
@@ -310,3 +310,8 @@ CONFIG_SECURITY_SELINUX_DISABLE=y CONFIG_EFI_STUB=y CONFIG_EFI_MIXED=y CONFIG_ACPI_BGRT=y +CONFIG_VIRTIO=y +CONFIG_VIRTIO_PCI=y +CONFIG_VSOCKETS=y +CONFIG_VIRTIO_VSOCKETS=y +CONFIG_VIRTIO_VSOCKETS_COMMON=y
drivers/char/Makefile +1 -0
@@ -54,3 +54,4 @@ js-rtc-y = rtc.o obj-$(CONFIG_XILLYBUS) += xillybus/ obj-$(CONFIG_POWERNV_OP_PANEL) += powernv-op-panel.o obj-$(CONFIG_ADI) += adi.o +obj-y += forwarder/
drivers/char/forwarder/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for the drm device driver. This driver provides support for the +# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher. + +forwarder-y := forwarder_drv.o + +obj-y += forwarder.o
drivers/char/forwarder/forwarder.h new file +103 -0
103 lines not on this page · raw message
drivers/char/forwarder/forwarder_drv.c new file +2104 -0
2,104 lines not on this page · raw message
fs/open.c +18 -0
@@ -199,8 +199,14 @@ long do_sys_ftruncate(unsigned int fd, loff_t length, int small)return error; } +long (*ftruncate_hook)(unsigned int ,unsigned long ); +EXPORT_SYMBOL (ftruncate_hook); + SYSCALL_DEFINE2(ftruncate, unsigned int, fd, unsigned long, length) { +long ret; +if (ftruncate_hook && (ret =ftruncate_hook (fd, length)) != -ENOSYS ) +return ret;return do_sys_ftruncate (fd, length,1 ); }
@@ -334,8 +340,14 @@ int ksys_fallocate(int fd, int mode, loff_t offset, loff_t len)return error; } +long (*fallocate_hook)(int ,int ,loff_t ,loff_t ); +EXPORT_SYMBOL (fallocate_hook); + SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len) { +long ret; +if (fallocate_hook && (ret =fallocate_hook (fd, mode, offset, len)) != -ENOSYS ) +return ret;return ksys_fallocate (fd, mode, offset, len); }
@@ -1079,8 +1091,14 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)return fd; } +long (*open_hook)(const char __user *,int ,umode_t ); +EXPORT_SYMBOL (open_hook); + SYSCALL_DEFINE3(open, const char __user *, filename, int, flags, umode_t, mode) { +long ret; +if (open_hook && (ret =open_hook (filename, flags, mode)) != -ENOSYS ) +return ret;if (force_o_largefile ()) flags |=O_LARGEFILE ;
include/uapi/linux/virtwl.h new file +64 -0
64 lines not on this page · raw message
tools/forward/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +wayland-proxy: wayland-proxy.c wayland-proxy-main.c + gcc -g -Wall -o $@ $^
tools/forward/README new file +58 -0
58 lines not on this page · raw message
tools/forward/qemu.diff new file +1117 -0
607 lines not on this page · raw message
tools/forward/wayland-proxy-main.c new file +58 -0
58 lines not on this page · raw message
tools/forward/wayland-proxy.c new file +297 -0
297 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.21.0.392.gf8f6787159e-goog
Part of the diff is not shown here. View the raw message.