virtio_input: Prevent EV_MSC/MSC_TIMESTAMP loop storm for MT.
authorColin Xu <colin.xu@intel.com>
Tue, 2 Feb 2021 00:19:23 +0000 (08:19 +0800)
committerMichael S. Tsirkin <mst@redhat.com>
Tue, 23 Feb 2021 12:52:59 +0000 (07:52 -0500)
In 'commit 29cc309d8bf1 ("HID: hid-multitouch: forward MSC_TIMESTAMP")',
EV_MSC/MSC_TIMESTAMP is added to each before EV_SYN event. EV_MSC is
configured as INPUT_PASS_TO_ALL.
In case of a touch device which report MSC_TIMESTAMP:
  BE pass EV_MSC/MSC_TIMESTAMP to FE on receiving event from evdev.
  FE pass EV_MSC/MSC_TIMESTAMP back to BE.
  BE writes EV_MSC/MSC_TIMESTAMP to evdev due to INPUT_PASS_TO_ALL.
  BE receives extra EV_MSC/MSC_TIMESTAMP and pass to FE.
>>> Each new frame becomes larger and larger.

Disable EV_MSC/MSC_TIMESTAMP forwarding for MT.

V2: Rebase.

Signed-off-by: Colin Xu <colin.xu@intel.com>
Link: https://lore.kernel.org/r/20210202001923.6227-1-colin.xu@intel.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
drivers/virtio/virtio_input.c

index f1f6208..244965c 100644 (file)
@@ -64,6 +64,21 @@ static int virtinput_send_status(struct virtio_input *vi,
        unsigned long flags;
        int rc;
 
+       /*
+        * Since 29cc309d8bf1 (HID: hid-multitouch: forward MSC_TIMESTAMP),
+        * EV_MSC/MSC_TIMESTAMP is added to each before EV_SYN event.
+        * EV_MSC is configured as INPUT_PASS_TO_ALL.
+        * In case of touch device:
+        *   BE pass EV_MSC/MSC_TIMESTAMP to FE on receiving event from evdev.
+        *   FE pass EV_MSC/MSC_TIMESTAMP back to BE.
+        *   BE writes EV_MSC/MSC_TIMESTAMP to evdev due to INPUT_PASS_TO_ALL.
+        *   BE receives extra EV_MSC/MSC_TIMESTAMP and pass to FE.
+        *   >>> Each new frame becomes larger and larger.
+        * Disable EV_MSC/MSC_TIMESTAMP forwarding for MT.
+        */
+       if (vi->idev->mt && type == EV_MSC && code == MSC_TIMESTAMP)
+               return 0;
+
        stsbuf = kzalloc(sizeof(*stsbuf), GFP_ATOMIC);
        if (!stsbuf)
                return -ENOMEM;