File u_Don-t-access-hardware-register-while-switched-away.patch of Package xf86-input-vmmouse
From: Egbert Eich <eich@freedesktop.org>
Date: Mon May 12 23:00:03 2014 +0200
Subject: [PATCH]Don't access hardware register while switched away
Patch-mainline: to be upstreamed
Git-commit: d7507f2225ddc71b8f1dc7d8b7f326d3f3fb1a0c
Git-repo: git://anongit.freedesktop.org/git/xorg/driver/xf86-input-vmmouse
References: bnc#877132
Signed-off-by: Egbert Eich <eich@suse.com>
Hotplug events for the vmmouse may come in while the Xserver is
switched away. In this case PreInit() iscalled which normally
accesses the hardware (ie. enables and disables the vmmouse)
to determine if it is there.
It is not a good idea to do this while the Xserver is switched
away and therefore not the owner of the device:
1. The state change due to enabling/disabling the device may
affect the owner at that time.
2. The Xserver may crash since enabling/disabling the vmmouse
will do PIO accesses. This is not an issue on VMWare but
on KVM.
The current solution is still slightly racy but since hotplug
events should be rather infrequent this race should be quite
rare.
Signed-off-by: Egbert Eich <eich@freedesktop.org>
---
src/vmmouse.c | 41 ++++++++++++++++++++++++++---------------
1 file changed, 26 insertions(+), 15 deletions(-)
diff --git a/src/vmmouse.c b/src/vmmouse.c
index cac8306..c53f369 100644
--- a/src/vmmouse.c
+++ b/src/vmmouse.c
@@ -354,25 +354,36 @@ VMMousePreInit(InputDriverPtr drv, IDevPtr dev, int flags)
}
/*
- * try to enable vmmouse here
+ * We must not fiddle with the VMmouse when switched away:
+ * - we may 'disable' someone elses mouse ie put it into a
+ * different state.
+ * - we may even crash ourselves as we do direct PIO access.
+ * This is not an issue with vmware but with KVM.
*/
- if (!VMMouseClient_Enable()) {
+ if (xf86VTOwner()) {
/*
- * vmmouse failed
- * Fall back to normal mouse module
+ * try to enable vmmouse here
*/
- xf86Msg(X_ERROR, "VMWARE(0): vmmouse enable failed\n");
- return VMMouseInitPassthru(drv, dev, flags);
+ if (!VMMouseClient_Enable()) {
+ /*
+ * vmmouse failed
+ * Fall back to normal mouse module
+ */
+ xf86Msg(X_ERROR, "VMWARE(0): vmmouse enable failed\n");
+ return VMMouseInitPassthru(drv, dev, flags);
+ } else {
+ /*
+ * vmmouse is available
+ */
+ xf86Msg(X_INFO, "VMWARE(0): vmmouse is available\n");
+ /*
+ * Disable the absolute pointing device for now
+ * It will be enabled during DEVICE_ON phase
+ */
+ VMMouseClient_Disable();
+ }
} else {
- /*
- * vmmouse is available
- */
- xf86Msg(X_INFO, "VMWARE(0): vmmouse is available\n");
- /*
- * Disable the absolute pointing device for now
- * It will be enabled during DEVICE_ON phase
- */
- VMMouseClient_Disable();
+ xf86Msg(X_WARNING, "VMWARE(0): Plugged while switched away: Cannot check for Passthrough - VM pointer might not work.\n");
}
if (!(pInfo = xf86AllocateInput(drv, 0))) {
@@ -427,12 +427,14 @@ VMMousePreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 12
/* For ABI < 12, we need to return the wrapped driver's pInfo (see
* above). ABI 12, we call NIDR and are done */
- if (!VMMouseClient_Enable()) {
- xf86Msg(X_ERROR, "VMWARE(0): vmmouse enable failed\n");
- return VMMouseInitPassthru(drv, pInfo, flags);
- } else {
- xf86Msg(X_INFO, "VMWARE(0): vmmouse is available\n");
- VMMouseClient_Disable();
+ if (xf86VTOwner()) {
+ if (!VMMouseClient_Enable()) {
+ xf86Msg(X_ERROR, "VMWARE(0): vmmouse enable failed\n");
+ return VMMouseInitPassthru(drv, pInfo, flags);
+ } else {
+ xf86Msg(X_INFO, "VMWARE(0): vmmouse is available\n");
+ VMMouseClient_Disable();
+ }
}
#endif