Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel+SystemServer+DeviceMapper: Add propagation mechanism for hotplug events between userspace programs #24210

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

supercomputer7
Copy link
Member

@supercomputer7 supercomputer7 commented May 4, 2024

Relies on #24203.

The idea is very simple - we could utilize the inode_watcher facility to inform user programs which are interested to get hotplug events, on removal or insertion of device nodes.

I still need to implement the actual usage of this in a main Service, which I think WindowServer would be an excellent option to start with.

The first userspace program to use this mechanism is WindowServer, to support hotplug events of keyboard and mouse devices.

cc @Hendiadyoin1 @spholz

@supercomputer7 supercomputer7 requested a review from gmta as a code owner May 4, 2024 17:16
@supercomputer7 supercomputer7 marked this pull request as draft May 4, 2024 17:17
@github-actions github-actions bot added 👀 pr-needs-review PR needs review from a maintainer or community member and removed 👀 pr-needs-review PR needs review from a maintainer or community member labels May 4, 2024
@supercomputer7
Copy link
Member Author

Here's a video demo to show the WindowServer support:
https://github.com/SerenityOS/serenity/assets/51659396/6053cc28-cd81-475c-9274-02b4815887b4

I booted with PS/2 mouse being disabled, and added a USB mouse during the SerenityOS VM runtime. :)

@supercomputer7 supercomputer7 force-pushed the devicemapper-hotplug-events branch 3 times, most recently from bfa07f7 to 13007b2 Compare May 4, 2024 18:57
Kernel/Arch/aarch64/RPi/MiniUART.cpp Outdated Show resolved Hide resolved
Kernel/Devices/DeviceManagement.cpp Outdated Show resolved Hide resolved
Userland/Services/SystemServer/main.cpp Outdated Show resolved Hide resolved
Kernel/CMakeLists.txt Show resolved Hide resolved
@supercomputer7 supercomputer7 force-pushed the devicemapper-hotplug-events branch 2 times, most recently from a30f537 to b0799ac Compare May 7, 2024 19:12
@supercomputer7 supercomputer7 marked this pull request as ready for review May 10, 2024 05:22
@github-actions github-actions bot added the 👀 pr-needs-review PR needs review from a maintainer or community member label May 10, 2024
@supercomputer7
Copy link
Member Author

I rebased this and force-pushed to see if the CI flakiness is resolved.

I accidentally marked them as char devices, so they're not usable on
their own when trying to mount with them.
There is simply no advantage with putting both virtual console devices
and serial TTY devices on the same major number.

Putting them on separate major numbers greatly simplifies the allocation
mechanism on the DeviceMapper code, because it no longer needs to
calculate offsets of minor numbers, and should start from number 0 to
theoretically infinite amount of device nodes.
Instead of putting everything in one hash map, let's distinguish between
the devices based on their type.

This change makes the devices semantically separated, and is considered
a preparation before we could expose a comprehensive list of allocations
per major numbers and their purpose.
Having a separate enum is pointless, and opens the possibility of having
duplicates elsewhere. Therefore, just unify everything under one known
enum.
We used to allocate major numbers quite randomly, with no common place
to look them up if needed.
This commit is changing that by placing all major number allocations
under a new C++ namespace, in the Devices/MajorNumberAllocation.h file.

We also add the foundations of what is needed before we can publish this
information (allocated numbers for block and char devices) to userspace.
After the previous commit, we are able to create a comprehensive list of
all devices' major number allocations.

To help userspace to distinguish between character and block devices, we
expose 2 sysfs nodes so userspace can decide which list it needs to open
in order to iterate on it.
Contributors that want to add new types of character or block devices
must follow these guidelines in order to keep everything intact.
The new mechanism is basically adding or removing symbolic links to
device nodes in /dev. These symbolic links are located in the directory
of /tmp/system/devicemap/nodes/{block,char} which contain subdirectories
for major number allocation, which then hold these symbolic links.

An interested userspace program could then open an inode watcher on the
subdirectories which hold the symbolic link for added or removed links
to indicate hotplug events of insertion or removal of a device.
This utility lists all devices' major number allocations, for character
and block devices. It can help the user to figure out the DeviceMapper
service manages spawning of device nodes in /dev and other associated
files under the /tmp/system/devicemap directory.
Add inode watchers on the /tmp/system/devicemap/family/{mouse,keyboard}/
directories.

Then instruct those watchers to dispatch a refresh call to the vectors
which hold references to these devices.
We are going to remove this device from the kernel in the next commit,
so prepare for that by not creating a device node.
This device was a short-lived solution to allow userspace (WindowServer)
to easily support hotplugging mouse devices with presumably very small
modifications on userspace side.

Now that we have a proper mechanism to propagate hotplug events from the
DeviceMapper program to any program that needs to get such events, we no
longer need this device, so let's remove it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👀 pr-needs-review PR needs review from a maintainer or community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants