]> git.baikalelectronics.ru Git - kernel.git/commit
HID: hidraw: Replace hidraw device table mutex with a rwsem
authorAndré Almeida <andrealmeid@collabora.com>
Tue, 30 Nov 2021 13:29:57 +0000 (10:29 -0300)
committerBenjamin Tissoires <benjamin.tissoires@redhat.com>
Tue, 14 Dec 2021 09:52:18 +0000 (10:52 +0100)
commit5695b8cc981db99866c550b9acf83e83777f8a1b
treecd85e87395f205ee52421e0c1badf001291288de
parentb0427e7943758725902576a531923902a4587fbd
HID: hidraw: Replace hidraw device table mutex with a rwsem

Currently, the table that stores information about the connected hidraw
devices has a mutex to prevent concurrent hidraw users to manipulate the
hidraw table (e.g. delete an entry) while someone is trying to use
the table (e.g. issuing an ioctl to the device), preventing the kernel
to referencing a NULL pointer. However, since that every user that wants
to access the table for both manipulating it and reading it content,
this prevents concurrent access to the table for read-only operations
for different or the same device (e.g. two hidraw ioctls can't happen at
the same time, even if they are completely unrelated).

This proves to be a bottleneck and gives performance issues when using
multiple HID devices at same time, like VR kits where one can have two
controllers, the headset and some tracking sensors.

To improve the performance, replace the table mutex with a read-write
semaphore, enabling multiple threads to issue parallel syscalls to
multiple devices at the same time while protecting the table for
concurrent modifications.

Signed-off-by: André Almeida <andrealmeid@collabora.com>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Link: https://lore.kernel.org/r/20211130132957.8480-2-andrealmeid@collabora.com
drivers/hid/hidraw.c