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)
commit8590222e4b021054a7167a4dd35b152a8ed7018e
treecd85e87395f205ee52421e0c1badf001291288de
parent03090cc76ee3298cc70bce26bbe93a0cb50e42a2
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