Skip to content

Use mio to replace Epoll#316

Draft
uran0sH wants to merge 3 commits into
rust-vmm:mainfrom
uran0sH:mio
Draft

Use mio to replace Epoll#316
uran0sH wants to merge 3 commits into
rust-vmm:mainfrom
uran0sH:mio

Conversation

@uran0sH

@uran0sH uran0sH commented Aug 19, 2025

Copy link
Copy Markdown
Contributor

Summary of the PR

Epoll is linux-specific. So we use mio, which is a cross-platform event notification, to replace Epoll.

Requirements

Before submitting your PR, please make sure you addressed the following
requirements:

  • [ x ] All commits in this PR have Signed-Off-By trailers (with
    git commit -s), and the commit message has max 60 characters for the
    summary and max 75 characters for each description line.
  • [ x ] All added/changed functionality has a corresponding unit/integration
    test.
  • [ x ] All added/changed public-facing functionality has entries in the "Upcoming
    Release" section of CHANGELOG.md (if no such section exists, please create one).
  • [ x ] Any newly added unsafe code is properly documented.

Comment thread vhost-user-backend/src/event_loop.rs Outdated
Comment thread vhost-user-backend/src/backend.rs Outdated
@uran0sH uran0sH force-pushed the mio branch 3 times, most recently from 2b19107 to e53a34c Compare August 19, 2025 17:02
Comment thread vhost-user-backend/src/event_loop.rs Outdated
Comment thread vhost-user-backend/src/event_loop.rs Outdated
Comment thread vhost-user-backend/src/event_loop.rs Outdated
Comment thread vhost-user-backend/src/event_loop.rs Outdated
Comment thread vhost-user-backend/src/event_loop.rs Outdated
Comment thread vhost-user-backend/src/event_loop.rs Outdated
Comment thread vhost-user-backend/src/event_loop.rs Outdated
Comment thread vhost-user-backend/src/event_loop.rs
@uran0sH uran0sH force-pushed the mio branch 3 times, most recently from be19e30 to 158ca1d Compare August 27, 2025 16:46
@uran0sH uran0sH force-pushed the mio branch 2 times, most recently from 44e7bb3 to 77ba627 Compare September 3, 2025 17:05
germag
germag previously approved these changes Sep 12, 2025
Comment thread vhost-user-backend/src/handler.rs Outdated
@germag

germag commented Sep 12, 2025

Copy link
Copy Markdown
Collaborator

this LGTM

@uran0sH

uran0sH commented Oct 8, 2025

Copy link
Copy Markdown
Contributor Author

@stefano-garzarella @germag any problems about this?

@name1e5s

Copy link
Copy Markdown

Hi @uran0sH , I'm trying to build the vhost crate on macOS and came across this PR. It seems this PR hasn't been updated for a while, are you still working on it? If not, I'd be happy to take over and continue the work to help get it merged. Let me know what you think. Thanks!

@uran0sH

uran0sH commented Feb 27, 2026

Copy link
Copy Markdown
Contributor Author

Hi @uran0sH , I'm trying to build the vhost crate on macOS and came across this PR. It seems this PR hasn't been updated for a while, are you still working on it? If not, I'd be happy to take over and continue the work to help get it merged. Let me know what you think. Thanks!

Yeah I will update this pr as soon as possible

@uran0sH uran0sH force-pushed the mio branch 3 times, most recently from 6dde03e to fbc40ce Compare February 28, 2026 08:35
@stefano-garzarella

Copy link
Copy Markdown
Member

@uran0sH thanks for restarting this work! Please, can you rebase this on current main.

FYI I'll be off from March 7 to 29 with limited internet access, so not sure I can review this before leaving, I'll do my best, but I'll leave to @germag and others handle it.

uran0sH added 3 commits March 5, 2026 16:16
When register_event we pass in the value of u32/u64, so we don't
need to convert it to u16 and then pass it to handle_event.

Signed-off-by: Wenyu Huang <huangwenyuu@outlook.com>
We can safely use usize instead of u64, because normally we will
not register a data that exceeds the size of usize

Signed-off-by: Wenyu Huang <huangwenyuu@outlook.com>
Epoll is linux-specific. So we use mio, which is a cross-platform
event notification, to replace Epoll.

Signed-off-by: Wenyu Huang <huangwenyuu@outlook.com>
@germag

germag commented Mar 18, 2026

Copy link
Copy Markdown
Collaborator

Hi, this LGTM

@name1e5s can you try to build it again?

@germag germag marked this pull request as draft May 12, 2026 09:23
christhomas added a commit to christhomas/vhost that referenced this pull request May 15, 2026
The `VhostBackend` and `VhostBackendMut` traits in `vhost/src/backend.rs`
take `&EventFd` in `set_vring_call`, `set_vring_kick`, and
`set_vring_err`. The implementations of these traits are all Linux-only
consumers — kernel vhost drivers (`vhost_kern/`, gated on the
`vhost-kern` feature) and the vhost-user frontend (gated on
`vhost-user-frontend`). No macOS consumer ever calls these methods.

Until now, the unconditional `use vmm_sys_util::eventfd::EventFd;` at
the top of `backend.rs` forced every dependent crate (including
`vhost-user-backend` consumers like virtiofsd) to compile against
`vmm_sys_util::eventfd` even when nothing in the build path called these
methods. On macOS that meant requiring an `eventfd` shim inside
vmm-sys-util just for the type to resolve.

Gate the import, the six trait method signatures, the corresponding
methods in `impl<T: VhostBackendMut> VhostBackend for {RwLock,RefCell}<T>`,
and the test mock + test on `#[cfg(target_os = "linux")]`. The trait
becomes a smaller surface on macOS — exactly the surface that has
working consumers there. Linux behaviour is unchanged.

This unblocks dropping the macOS `eventfd` shim from vmm-sys-util
(rust-vmm/vmm-sys-util#268), and combined with the mio rewrite of
`vhost-user-backend`'s event loop (rust-vmm#316), removes the last hard
dependency between the macOS build path and `vmm_sys_util::eventfd`.

Tested: full virtiofsd → vhost-user-backend → vhost → vmm-sys-util
stack builds and tests pass on aarch64-apple-darwin with no eventfd
shim in vmm-sys-util.

Signed-off-by: Chris Thomas <chris.thomas@antimatter-studios.com>
@eric-14

eric-14 commented May 19, 2026

Copy link
Copy Markdown

@uran0sH building vhost backend on my macOs still fails due to eventfd in vhost/backend.rs. I am porting Vhostbackend trait methods to eventconsumer and eventNotifier. Are you considering taking this approach ?

@uran0sH

uran0sH commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

@uran0sH building vhost backend on my macOs still fails due to eventfd in vhost/backend.rs. I am porting Vhostbackend trait methods to eventconsumer and eventNotifier. Are you considering taking this approach ?

Yeah, but the changes still are in my own repo: uran0sH@54d673a, not submitted to the upstream. If you want to test, you can use this branch: https://github.com/uran0sH/vhost/tree/macos. And I also change the vhost-device. These changes in uran0sH/vhost-device#2

@stefano-garzarella

Copy link
Copy Markdown
Member

@uran0sH building vhost backend on my macOs still fails due to eventfd in vhost/backend.rs. I am porting Vhostbackend trait methods to eventconsumer and eventNotifier. Are you considering taking this approach ?

Yeah, but the changes still are in my own repo: uran0sH@54d673a, not submitted to the upstream. If you want to test, you can use this branch: https://github.com/uran0sH/vhost/tree/macos. And I also change the vhost-device. These changes in uran0sH/vhost-device#2

@uran0sH what is missing to submit it here?

@uran0sH

uran0sH commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

@uran0sH building vhost backend on my macOs still fails due to eventfd in vhost/backend.rs. I am porting Vhostbackend trait methods to eventconsumer and eventNotifier. Are you considering taking this approach ?

Yeah, but the changes still are in my own repo: uran0sH@54d673a, not submitted to the upstream. If you want to test, you can use this branch: https://github.com/uran0sH/vhost/tree/macos. And I also change the vhost-device. These changes in uran0sH/vhost-device#2

@uran0sH what is missing to submit it here?

I think nothing major is missing. I am not sure whether uran0sH@54d673a should be submitted in this pr or as a sperate one. What do you think?

@stefano-garzarella

Copy link
Copy Markdown
Member

I think nothing major is missing. I am not sure whether uran0sH@54d673a should be submitted in this pr or as a sperate one. What do you think?

I think better a separate PR if they are not depending on each other.

@eric-14

eric-14 commented May 19, 2026

Copy link
Copy Markdown

@uran0sH building vhost backend on my macOs still fails due to eventfd in vhost/backend.rs. I am porting Vhostbackend trait methods to eventconsumer and eventNotifier. Are you considering taking this approach ?

Yeah, but the changes still are in my own repo: uran0sH@54d673a, not submitted to the upstream. If you want to test, you can use this branch: https://github.com/uran0sH/vhost/tree/macos. And I also change the vhost-device. These changes in uran0sH/vhost-device#2

@uran0sH what is missing to submit it here?

I think nothing major is missing. I am not sure whether uran0sH@54d673a should be submitted in this pr or as a sperate one. What do you think?

@uran0sH I found the following issue with https://github.com/uran0sH/vhost/tree/macos

I have fixed it on my branch https://github.com/eric-14/rust_vhost_/tree/experimental_mac

@stefano-garzarella

Copy link
Copy Markdown
Member

@uran0sH talking with @eric-14 he would like to complete this PR since it's blocking some stuff. Is it okay for you if he will take your work (keeping your authorship of course) and complete it to upstream ASAP?

@uran0sH

uran0sH commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

@uran0sH talking with @eric-14 he would like to complete this PR since it's blocking some stuff. Is it okay for you if he will take your work (keeping your authorship of course) and complete it to upstream ASAP?

It's okay for me.

@germag

germag commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

@eric-14 Thanks!

After looking at it (honestly, just skimming) again, there are some minor issues that should be fixed and a couple not so minor:

  • poller: Mutex<Poll> - Can the mutex be removed (I know VringPollHandler needs sync maybe that's the problem we need to fix idk yet)?, epoll (and the mio impl) is designed to work with a single thread.
  • println!("ignoring unknown event set:...) -> log::warn! (or debug!?)

Less important:

  • register_/unregister_listener api data is too general name, but we do: data <= self.backend.num_queues()
  • register_event() does ...map_err(std::io::Error::other)?; while unregister_event()... .map_err(|e| std::io::Error::other(format!("Failed to deregister fd {fd}: {e}")))?;
  • We need to check if nothing important is ignored inside event_to_event_set(), for example evt.is_error().

@eric-14

eric-14 commented Jun 23, 2026

Copy link
Copy Markdown

@germag Thank you for the latest review. I will make the necessary changes and ping you.

@eric-14

eric-14 commented Jul 3, 2026

Copy link
Copy Markdown

@germag, I have completed the changes. Do you prefer I create a new PR or commit to this PR?

@stefano-garzarella

Copy link
Copy Markdown
Member

@germag, I have completed the changes. Do you prefer I create a new PR or commit to this PR?

I'd suggest to start a new PR, I'm not sure if you have rights to push on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants