FreeBSDDesktop / DEPRECATED-freebsd-base-graphics

Fork of FreeBSD's base repository to work on graphics-stack-related projects
Other
49 stars 13 forks source link

32bit DRM ioctls don't work on amd64 #166

Closed jbeich closed 7 years ago

jbeich commented 7 years ago

32bit OpenGL/OpenCL apps (e.g., Wine) either crash, don't work or are very slow because device-specific DRI driver fails on DRM ioctls. Here's an example from Skylake GT2:

$ nm /boot/kernel/i915kms.ko | fgrep compat_ioctl
$ sysctl kern.conftxt | fgrep COMPAT_
options COMPAT_FREEBSD11
options COMPAT_FREEBSD10
options COMPAT_FREEBSD32

$ ABI=FreeBSD:12:i386 pkg install mesa-dri mesa-demos
$ LIBGL_DEBUG=verbose MESA_DEBUG=context glxgears
libGL: OpenDriver: trying /usr/local/lib/dri/i965_dri.so
Mesa warning: drm_i915_getparam: -14
i965_dri.so does not support the 0xffffffff PCI ID.
libGL error: failed to create dri screen
libGL error: failed to load driver: i965
libGL: OpenDriver: trying /usr/local/lib/dri/swrast_dri.so
libGL: Can't open configuration file /home/foo/.drirc: No such file or directory.
libGL: Can't open configuration file /home/foo/.drirc: No such file or directory.
602 frames in 5.0 seconds = 120.249 FPS
^C

drivers/gpu/drm/drm_os_config.h doesn't include opt_compat.h, otherwise build would fail like the following:

sys/dev/drm/i915/i915_drv.c:2576:3: error: field designator 'compat_ioctl' does not refer to any field in type 'const struct file_operations'
        .compat_ioctl = i915_compat_ioctl,
         ^
1 error generated.

which can be fixed by moving compat_ioctl out of #if 0 in sys/compat/linuxkpi/common/include/linux/fs.h except linuxkpi never calls .compat_ioctl.

hselasky commented 7 years ago

I think some defines are missing in the compilation process to turn on 32-bit support.

valpackett commented 7 years ago

linuxkpi never calls .compat_ioctl

This is fixable, just submitted 222504.

The harder problem is the usage of compat_alloc_user_space in *_ioc32.c files. I've tried to implement that function (which got a CVE back in the day, BTW :D) but failed. Well, that function "worked", the copyin/copyout (__put_user, __get_user) stuff didn't. I guess redefining compat_alloc_user_space as a normal allocation and __put_user/__get_user as normal copies could work… but I can't think of a way to insert the frees just by defining macros.

So I'm working on a terrible patch that replaces that allocation with just having the struct on the stack, just like this 2014 patch.

Already managed to run some GL applications on Wine :) Also Steam on Linuxulator now shows the login UI (but doesn't communicate with the network, net.cpp (1913) : Assertion Failed: Unable to set default socket options, error 22) instead of, well, not showing it.

valpackett commented 7 years ago

Also, the current version in linux doesn't use compat_alloc_user_space anymore, it's actually kinda more similar to what I'm doing, but it has new weirdness: compat_ptr.