Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@michael2012z
Copy link
Member

@michael2012z michael2012z commented May 13, 2020

This PR is splitted from #1126.
It prepares for upcoming PR's to enable AArch64. All building issues were fixed, but no functionality was introduced. A lot of #[cfg(target_arch = "xxx")] were used in source files to separate architecture specific code. Some utility files were updated as well.

For X86, the logic of code was not changed at all. Nothing should be broken.

For ARM, the architecture specific part is still empty. Some new added ARM-specific code may looks weird, because they were added temporarily to workaround lint warnings. But they will be replaced later by other commits with real functionality.

A workflow for "Checks" was setup to cross-build for AArch64. But now the cross-build fails, which is related to Serde in kvm-bindings. The reason is that CH forked kvm-bindings to add the support of Serde, the modification was mainly for X86 and a little was modified for ARM, but it is not ready for ARM. A workaround is to revert the modification for ARM totally. A PR for this has been issued to cloud-hypervisor/kvm-bindings

@rbradford
Copy link
Member

@michael2012z Yes please feel free to send a PR to the appropriate fork repos targetting the "ch" branch. Make sure to mark it for review by @rbradford and @sboeuf

@michael2012z
Copy link
Member Author

michael2012z commented May 19, 2020

Hi, @rbradford , @sboeuf

Regarding the build error of kvm-bindings with feature with-serde, I tried an alternative workaround in the new added cross-build workflow: update vmm/Cargo.toml file before building (https://github.com/cloud-hypervisor/cloud-hypervisor/pull/1168/files#diff-2f78b1ca0982fac40f2687f73fc9dcabR26), now we don't have to pend on the progress of cloud-hypervisor/kvm-bindings#1.

Now cross-build jobs have passed. This PR is ready for review. Would you like to take a look?

@michael2012z michael2012z force-pushed the aarch64-enable-build branch from a2cb466 to 9a2215f Compare May 19, 2020 08:22
Copy link
Member

@rbradford rbradford left a comment

Choose a reason for hiding this comment

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

Looking nice so far. Just some comments to help reduce some of the conditionals

}

#[cfg(target_arch = "aarch64")]
pub fn get_host_cpu_phys_bits() -> u8 {
Copy link
Member

Choose a reason for hiding this comment

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

Please move get_host_cpu_phys_bits to the arch/ crate.

vmm/src/cpu.rs Outdated
guest_memory: GuestMemoryAtomic<GuestMemoryMmap>,
kvm: &Kvm,
#[cfg(target_arch = "x86_64")] kvm: &Kvm,
#[cfg(target_arch = "aarch64")] _kvm: &Kvm,
Copy link
Member

Choose a reason for hiding this comment

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

#[cfg_attr(target_arch = "aarch64", allow(dead_code)]

vmm/src/cpu.rs Outdated
_inserting: bool,
_snapshot: Option<Snapshot>,
) -> Result<()> {
// temporary code to mute "unused variable" warnings
Copy link
Member

Choose a reason for hiding this comment

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

Put this as unimplemented! and then use #[cfg_attr(target_arch = "aarch64", allow(dead_code)] on the fields instead,

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea!

fn add_ioapic(&mut self) -> DeviceManagerResult<Arc<Mutex<ioapic::Ioapic>>> {
// temporary code to mute "unused variable" warnings
let _ = &self.msi_interrupt_manager;
panic!("impossible for aarch64");
Copy link
Member

Choose a reason for hiding this comment

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

unreachable!()

};

#[cfg(target_arch = "aarch64")]
let start_addr = GuestAddress((mem_end.0 + 1 + (256 << 20)) & !((128 << 20) - 1));
Copy link
Member

Choose a reason for hiding this comment

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

Refactor out into a start_addr() function.

Copy link
Member Author

Choose a reason for hiding this comment

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

I refactored more to cover the similar calculation for the start address of device space in new().

vmm/src/vm.rs Outdated

if !kvm.check_extension(Cap::TscDeadlineTimer) {
return Err(Error::CapabilityMissing(Cap::TscDeadlineTimer));
#[cfg(target_arch = "x86_64")]
Copy link
Member

Choose a reason for hiding this comment

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

Refactor out into a function in the arch crate check_required_kvm_extensions() ?

@michael2012z michael2012z force-pushed the aarch64-enable-build branch from 9a2215f to 888028a Compare May 21, 2020 07:33
@michael2012z
Copy link
Member Author

Hi, @rbradford Thanks for reviewing. I updated the PR as per the comments, and rebased to latest code. Please take a look again.

Copy link
Member

@rbradford rbradford left a comment

Choose a reason for hiding this comment

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

Almost ready to approve. Just want to see some commit message changes.

@@ -1,5 +1,6 @@
FROM ubuntu:18.04 as dev

Copy link
Member

Choose a reason for hiding this comment

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

For b40aea0 please prefix first line of commit message with "build:" and drop trailing full-stop.

Please remove the Gerrit Change-Id.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done for all commits.

// SPDX-License-Identifier: Apache-2.0

pub mod layout;

Copy link
Member

Choose a reason for hiding this comment

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

For 24e62df please prefix with "build:" and drop gerrit Change-Id.

@@ -0,0 +1,32 @@
name: Cloud Hypervisor Cross Build
Copy link
Member

Choose a reason for hiding this comment

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

For 888028a please prefix first commit message line with "build: " and drop gerrit Change-Id

Updated Dockerfile to work with multiple architectures.
Updated dev_cli.sh to:
1. Build container image before AArch64 image is ready in public.
2. Adjust default feature collection on AArch64.
3. Workaround a build problem with musl on AArch64.

Signed-off-by: Michael Zhao <[email protected]>
This is a preparing commit to build and test CH on AArch64. All building
issues were fixed, but no functionality was introduced.
For X86, the logic of code was not changed at all.
For ARM, the architecture specific part is still empty. And we applied
some tricks to workaround lint warnings. But such code will be replaced
later by other commits with real functionality.

Signed-off-by: Michael Zhao <[email protected]>
The result of the workflow can be seen in Checks tab of a PR.
Two targets have been added:
- stable aarch64-unknown-linux-gnu
- stable aarch64-unknown-linux-musl

Note: a temporary step was added before building. We used "sed" command
to remove "with-serde" feature of kvm-bindings in vmm/Cargo.toml.
This step should be removed in future when kvm-bindings is ready.

Signed-off-by: Michael Zhao <[email protected]>
@michael2012z michael2012z force-pushed the aarch64-enable-build branch from 888028a to 07f3c9d Compare May 21, 2020 09:27
target: ${{ matrix.target }}
override: true
- name: Disable "with-serde" in kvm-bindings
run: sed -i 's/"with-serde",\ //g' vmm/Cargo.toml
Copy link
Member

Choose a reason for hiding this comment

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

This is a reasonable solution for the time being.

@rbradford rbradford merged commit 4f5c8be into cloud-hypervisor:master May 21, 2020
@michael2012z michael2012z mentioned this pull request May 21, 2020
15 tasks
Copy link
Member

@sboeuf sboeuf left a comment

Choose a reason for hiding this comment

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

Nice PR!

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.

3 participants