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

vhost: Always enable vm-memory/backend-mmap #175

Merged
merged 1 commit into from
Jul 16, 2023

Conversation

slp
Copy link
Collaborator

@slp slp commented Jul 12, 2023

Since 4029089 ('vhost: Add support for Xen memory mappings') the feature backend-mmap of the vm-memory crate is no longer just a dev-dependency. Make it a formal dependency.

@slp
Copy link
Collaborator Author

slp commented Jul 12, 2023

We should probably also do a quick 0.8.1 release after merging this one.

@stefano-garzarella
Copy link
Member

@vireshk can you take a look?

Should we enable that feature depending on our xen feature or in any case?
We didn't see any error during publishing, how can we prevent it in the future?

@vireshk
Copy link
Contributor

vireshk commented Jul 13, 2023

@slp I am not sure why this change is required though. If xen feature is enabled for vhost crate, then it enables vm-memory/xen too, which eventually enables backend-mmap. Why do we need to explictly add it here ?

I tried cargo build --release --features xen and worked just fine.

Just wondering what am I missing here ..

@stefano-garzarella
Copy link
Member

@slp sorry, I can't understand the problem. What error do you see without this patch?

Maybe it's my limited knowledge of cargo, but in vm-memory/Cargo.toml the xen feature depends on backend-mmap. Here in vhost/Cargo.toml we have xen feature, which depends on vm-memory/xen, so I guess also on vm-memory/backend-mmap.

So IIUC, when we enable xen here, then we also enable backend-mmap implicitly. What did I miss?

@slp
Copy link
Collaborator Author

slp commented Jul 13, 2023

According to the cargo documentation:

Dev-dependencies are not used when compiling a package for building, but are used for compiling tests, examples, and benchmarks.

This means imports from dev-dependencies should be gated behind test or some other build-time conditional. In our case, we're now importing GuestMemoryMmap from the global namespace:

use vm_memory::{bitmap::Bitmap, Address, GuestMemoryRegion, GuestRegionMmap};

This implies backend-mmap is no longer a dev-dependency for us, but a general build dependency.

Maybe it's my limited knowledge of cargo, but in vm-memory/Cargo.toml the xen feature depends on backend-mmap. Here in vhost/Cargo.toml we have xen feature, which depends on vm-memory/xen, so I guess also on vm-memory/backend-mmap.

Even if one of your dependencies enables a feature, that feature doesn't appear in your namespace unless you also enable it in your own crate.

You can reproduce the issue by passing the -Z avoid-dev-deps flag to cargo (which some distros use to minimize the number of dependencies at build time and save some CPU cycles):

[root@f0e9515a5e2b vhost]# cd crates/vhost
[root@f0e9515a5e2b vhost]# RUSTC_BOOTSTRAP=1 cargo build -Z avoid-dev-deps
    Updating crates.io index
   Compiling proc-macro2 v1.0.64
   Compiling quote v1.0.29
   Compiling unicode-ident v1.0.10
   Compiling libc v0.2.147
   Compiling thiserror v1.0.43
   Compiling bitflags v1.3.2
   Compiling syn v2.0.25
   Compiling vmm-sys-util v0.11.1
   Compiling thiserror-impl v1.0.43
   Compiling vm-memory v0.12.0
   Compiling vhost v0.8.0 (/root/vhost/crates/vhost)
error[E0432]: unresolved import `vm_memory::GuestRegionMmap`
  --> crates/vhost/src/backend.rs:17:61
   |
17 | use vm_memory::{bitmap::Bitmap, Address, GuestMemoryRegion, GuestRegionMmap};
   |                                                             ^^^^^^^^^^^^^^^ no `GuestRegionMmap` in the root

warning: unused import: `GuestMemoryRegion`
  --> crates/vhost/src/backend.rs:17:42
   |
17 | use vm_memory::{bitmap::Bitmap, Address, GuestMemoryRegion, GuestRegionMmap};
   |                                          ^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: unused import: `Address`
  --> crates/vhost/src/backend.rs:17:33
   |
17 | use vm_memory::{bitmap::Bitmap, Address, GuestMemoryRegion, GuestRegionMmap};
   |                                 ^^^^^^^

warning: unused import: `std::os::unix::io::AsRawFd`
  --> crates/vhost/src/backend.rs:13:5
   |
13 | use std::os::unix::io::AsRawFd;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0432`.
warning: `vhost` (lib) generated 3 warnings
error: could not compile `vhost` (lib) due to previous error; 3 warnings emitted
[root@f0e9515a5e2b vhost]# 

@stefano-garzarella
Copy link
Member

Maybe it's my limited knowledge of cargo, but in vm-memory/Cargo.toml the xen feature depends on backend-mmap. Here in vhost/Cargo.toml we have xen feature, which depends on vm-memory/xen, so I guess also on vm-memory/backend-mmap.

Even if one of your dependencies enables a feature, that feature doesn't appear in your namespace unless you also enable it in your own crate.

Sure, of course I missed that we are now using GuestMemoryMmap without a guard, but it seems it is needed.
@vireshk can you confirm that?

@slp can you include in the commit description that the feature is needed because of GuestMemoryMmap?

Maybe we should add a test in rust-vmm-ci to cover this scenario.

@slp
Copy link
Collaborator Author

slp commented Jul 13, 2023

@slp can you include in the commit description that the feature is needed because of GuestMemoryMmap?

Done :-)

Since 4029089 ('vhost: Add support for Xen memory mappings') the
feature backend-mmap of the vm-memory crate is no longer just a
dev-dependency, as we're unconditionally importing GuestMemoryMmap from
'src/backend.rs'. Make it a general build dependency.

Signed-off-by: Sergio Lopez <slp@redhat.com>
@vireshk
Copy link
Contributor

vireshk commented Jul 13, 2023

Hi,

I am somehow not able to reproduce it on commit 900b9a5c4197a.

$ RUSTC_BOOTSTRAP=1  cargo +nightly build -Z avoid-dev-deps
    Updating crates.io index
   Compiling proc-macro2 v1.0.64
   Compiling unicode-ident v1.0.10
   Compiling quote v1.0.29
   Compiling libc v0.2.147
   Compiling thiserror v1.0.43
   Compiling arc-swap v1.6.0
   Compiling bitflags v1.3.2
   Compiling log v0.4.19
   Compiling virtio-bindings v0.2.1
   Compiling syn v2.0.25
   Compiling vmm-sys-util v0.11.1
   Compiling thiserror-impl v1.0.43
   Compiling vm-memory v0.12.0
   Compiling virtio-queue v0.9.0
   Compiling vhost v0.8.0 (/mnt/ssd/all/work/repos/virtio/rust/rust-vmm/vhost/crates/vhost)
   Compiling vhost-user-backend v0.10.0 (/mnt/ssd/all/work/repos/virtio/rust/rust-vmm/vhost/crates/vhost-user-backend)
    Finished dev [unoptimized + debuginfo] target(s) in 4.17s

@stefano-garzarella
Copy link
Member

@vireshk I can reproduce adding -p vhost:

cargo +nightly build -Z avoid-dev-deps -p vhost   
   Compiling proc-macro2 v1.0.63
   Compiling quote v1.0.29
   Compiling unicode-ident v1.0.10
   Compiling libc v0.2.147
   Compiling thiserror v1.0.41
   Compiling bitflags v1.3.2
   Compiling syn v2.0.23
   Compiling vmm-sys-util v0.11.1
   Compiling thiserror-impl v1.0.41
   Compiling vm-memory v0.12.0
   Compiling vhost v0.8.0 (/home/stefano/repos/vhost/crates/vhost)
error[E0432]: unresolved import `vm_memory::GuestRegionMmap`
  --> crates/vhost/src/backend.rs:17:61
   |
17 | use vm_memory::{bitmap::Bitmap, Address, GuestMemoryRegion, GuestRegionMmap};
   |                                                             ^^^^^^^^^^^^^^^ no `GuestRegionMmap` in the root
   |
note: found an item that was configured out
  --> /home/stefano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/vm-memory-0.12.0/src/lib.rs:60:40
   |
60 | pub use mmap::{Error, GuestMemoryMmap, GuestRegionMmap, MmapRegion};
   |                                        ^^^^^^^^^^^^^^^
   = note: the item is gated behind the `backend-mmap` feature

warning: unused import: `GuestMemoryRegion`
  --> crates/vhost/src/backend.rs:17:42
   |
17 | use vm_memory::{bitmap::Bitmap, Address, GuestMemoryRegion, GuestRegionMmap};
   |                                          ^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: unused import: `Address`
  --> crates/vhost/src/backend.rs:17:33
   |
17 | use vm_memory::{bitmap::Bitmap, Address, GuestMemoryRegion, GuestRegionMmap};
   |                                 ^^^^^^^

warning: unused import: `std::os::unix::io::AsRawFd`
  --> crates/vhost/src/backend.rs:13:5
   |
13 | use std::os::unix::io::AsRawFd;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0432`.
warning: `vhost` (lib) generated 3 warnings
error: could not compile `vhost` (lib) due to previous error; 3 warnings emitted

Maybe it doesn't show you because vhost-user-backed already have that dependency feature.

Copy link
Member

@stefano-garzarella stefano-garzarella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slp thanks!

I'll prepare v0.8.1 ASAP, but I'd wait @vireshk to understand if VhostUserMemoryRegionInfo::from_guest_region() is really needed, since it seems the only one using GuestRegionMmap.

@vireshk
Copy link
Contributor

vireshk commented Jul 13, 2023

@slp thanks!

I'll prepare v0.8.1 ASAP, but I'd wait @vireshk to understand if VhostUserMemoryRegionInfo::from_guest_region() is really needed, since it seems the only one using GuestRegionMmap.

Hey. I am trying to fix it differently, give me few minutes.

@stefano-garzarella
Copy link
Member

@slp thanks!
I'll prepare v0.8.1 ASAP, but I'd wait @vireshk to understand if VhostUserMemoryRegionInfo::from_guest_region() is really needed, since it seems the only one using GuestRegionMmap.

Hey. I am trying to fix it differently, give me few minutes.

Sure, take your time ;-)

@vireshk
Copy link
Contributor

vireshk commented Jul 13, 2023

I couldn't get much on this. Just get this merged :)

@slp
Copy link
Collaborator Author

slp commented Jul 14, 2023

@eryugey @jiangliu @sboeuf could you please take a quick look at this one?

@jiangliu jiangliu merged commit 9306ce0 into rust-vmm:main Jul 16, 2023
23 checks passed
birktj pushed a commit to birktj/virtiofsd that referenced this pull request Jan 5, 2024
This version fixes an issue on how a dependency is defined in
Cargo.toml. We need to include it to prevent build failure during
packaging.

rust-vmm/vhost#175
Signed-off-by: German Maglione <gmaglione@redhat.com>
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.

None yet

4 participants