summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Hellstrom <thellstrom@vmware.com>2018-02-14 08:10:41 +0100
committerThomas Hellstrom <thellstrom@vmware.com>2018-02-15 08:33:48 +0100
commit1899b0896dae4ce86c9871fa491b464f6af88526 (patch)
tree59a6a62a6ca5f1299b97e1bb1fd34e6719b29216
parentea77ce3a200bae7d97d6e45becc898765c1aa259 (diff)
vmwgfx: Fix server termination due to a mesa loader bug
Some versions of the Gallium loader close our drm file descriptor if xa_tracker_create() fails (typically 2D VMs.) While this is mostly fixed everywhere, we implement a workaround to avoid tracking down the same bug again and again on those setups where this is not fixed in mesa. Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com> Reviewed-by: Brian Paul <brianp@vmware.com> Reviewed-by: Sinclair Yeh <syeh@vmware.com> Reviewed-by: Deepak Rawat <drawat@vmware.com>
-rw-r--r--vmwgfx/vmwgfx_driver.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/vmwgfx/vmwgfx_driver.c b/vmwgfx/vmwgfx_driver.c
index caff826..24313fa 100644
--- a/vmwgfx/vmwgfx_driver.c
+++ b/vmwgfx/vmwgfx_driver.c
@@ -34,6 +34,7 @@
#endif
#include <unistd.h>
+#include <fcntl.h>
#include "xorg-server.h"
#include "xf86.h"
#include "xf86_OSproc.h"
@@ -1033,7 +1034,29 @@ drv_screen_init(SCREEN_INIT_ARGS_DECL)
vmw_ctrl_ext_init(pScrn);
if (ms->accelerate_render) {
+ /*
+ * Some versions of the Gallium loader close our drm file
+ * descriptor if xa_tracker_create() fails (typically 2D VMs.)
+ * While this is mostly fixed everywhere we implement a
+ * workaround to avoid tracking down the same bug again and again
+ * on those setups where this is not fixed in mesa.
+ */
+
+ int tmp_fd = dup(ms->fd);
+ long flags = fcntl(ms->fd, F_GETFD);
+
ms->xat = xa_tracker_create(ms->fd);
+ if (fcntl(ms->fd, F_GETFD) == -1) {
+ if (tmp_fd == -1 || flags == -1 || fcntl(tmp_fd, F_SETFD, flags)) {
+ xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+ "XA closed our DRM file descriptor. Giving up.\n");
+ return FALSE;
+ }
+ ms->fd = tmp_fd;
+ } else {
+ close(tmp_fd);
+ }
+
if (!ms->xat) {
xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
"Failed to initialize Gallium3D Xa. "