Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Certificate of Origin and signing off your commits, please check
## PR Checklist

- [ ] I have read and understand [CONTRIBUTING.md][3].
- [ ] I have run `tools/devtool checkbuild --all` to verify that the PR passes
build checks on all supported architectures.
- [ ] I have run `tools/devtool checkstyle` to verify that the PR passes the
automated style checks.
- [ ] I have described what is done in these changes, why they are needed, and
Expand Down
11 changes: 7 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,16 @@ following in the Firecracker root directory:
```
cat >> .git/hooks/pre-commit << EOF
./tools/devtool checkstyle || exit 1
./tools/devtool checkbuild --all || exit 1
EOF
```

This will automatically lint your Rust, markdown and python changes when running
`git commit`, as well as running any other checks our CI validates as part of
its 'Style' step. Most reported violations can be automatically fixed using
`./tools/devtool fmt`.
The first command will automatically lint your Rust, markdown and python changes
when running `git commit`, as well as running any other checks our CI validates
as part of its 'Style' step. Most reported violations can be automatically fixed
using `./tools/devtool fmt`. The second command will then check that the code
correctly compiles on all supported architectures, and that it passes Rust
clippy rules defined for the project.

Your contribution needs to meet the following standards:

Expand Down
6 changes: 6 additions & 0 deletions src/clippy-tracing/tests/integration_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// Allow test functions outside of test modules
#![allow(clippy::tests_outside_test_module)]

use std::fs::{OpenOptions, remove_file};
use std::io::{Read, Write};
use std::process::Command;
Expand All @@ -14,6 +17,7 @@ fn setup(text: &str) -> String {
let path = format!("/tmp/{id}.rs");
let mut file = OpenOptions::new()
.create(true)
.truncate(true)
.read(false)
.write(true)
.open(&path)
Expand Down Expand Up @@ -203,6 +207,7 @@ fn exclude() {

let mut file_one = OpenOptions::new()
.create(true)
.truncate(true)
.read(false)
.write(true)
.open(&file_path_one)
Expand All @@ -211,6 +216,7 @@ fn exclude() {

let mut file_two = OpenOptions::new()
.create(true)
.truncate(true)
.read(false)
.write(true)
.open(&file_path_two)
Expand Down
2 changes: 2 additions & 0 deletions src/firecracker/examples/seccomp/harmless.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
fn main() {
// SAFETY: This is just an example to demonstrate syscall filtering.
// The syscall is safe because we're only writing a static string to a file descriptor.
unsafe {
// Harmless print to standard output.
libc::syscall(libc::SYS_write, libc::STDOUT_FILENO, "Hello, world!\n", 14);
Expand Down
2 changes: 2 additions & 0 deletions src/firecracker/examples/seccomp/malicious.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
fn main() {
// SAFETY: This is just an example to demonstrate syscall filtering.
// The syscall is safe because we're only writing a static string to a file descriptor.
unsafe {
// In this example, the malicious component is outputting to standard input.
libc::syscall(libc::SYS_write, libc::STDIN_FILENO, "Hello, world!\n", 14);
Expand Down
25 changes: 12 additions & 13 deletions src/firecracker/examples/uffd/uffd_utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// Not everything is used by both binaries
#![allow(dead_code)]
#![allow(
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
clippy::undocumented_unsafe_blocks,
// Not everything is used by both binaries
dead_code
)]

use std::collections::{HashMap, HashSet};
use std::ffi::c_void;
Expand Down Expand Up @@ -290,12 +295,9 @@ impl Runtime {
revents: 0,
});

// We can skip polling on stream fd if
// the connection is closed.
let mut skip_stream: usize = 0;
loop {
let pollfd_ptr = pollfds[skip_stream..].as_mut_ptr();
let pollfd_size = pollfds[skip_stream..].len() as u64;
let pollfd_ptr = pollfds.as_mut_ptr();
let pollfd_size = pollfds.len() as u64;

// # Safety:
// Pollfds vector is valid
Expand All @@ -305,7 +307,7 @@ impl Runtime {
panic!("Could not poll for events!")
}

for i in skip_stream..pollfds.len() {
for i in 0..pollfds.len() {
if nready == 0 {
break;
}
Expand All @@ -324,17 +326,14 @@ impl Runtime {
revents: 0,
});
self.uffds.insert(handler.uffd.as_raw_fd(), handler);

// If connection is closed, we can skip the socket from being polled.
if pollfds[i].revents & (libc::POLLRDHUP | libc::POLLHUP) != 0 {
skip_stream = 1;
}
} else {
// Handle one of uffd page faults
pf_event_dispatch(self.uffds.get_mut(&pollfds[i].fd).unwrap());
}
}
}
// If connection is closed, we can skip the socket from being polled.
pollfds.retain(|pollfd| pollfd.revents & (libc::POLLRDHUP | libc::POLLHUP) == 0);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/firecracker/tests/verify_dependencies.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::tests_outside_test_module)]

use std::collections::HashMap;
use std::fmt::Debug;
use std::path::Path;
Expand Down
2 changes: 2 additions & 0 deletions src/vmm/benches/memory_access.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::undocumented_unsafe_blocks)]

use criterion::{BatchSize, Criterion, criterion_group, criterion_main};
use vmm::resources::VmResources;
use vmm::vmm_config::machine_config::{HugePageConfig, MachineConfig};
Expand Down
2 changes: 2 additions & 0 deletions src/vmm/benches/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// * `Queue.add_used`
// * `DescriptorChain.next_descriptor`

#![allow(clippy::cast_possible_truncation)]

use std::num::Wrapping;

use criterion::{Criterion, criterion_group, criterion_main};
Expand Down
6 changes: 5 additions & 1 deletion src/vmm/tests/devices.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::undocumented_unsafe_blocks)]
#![allow(
clippy::cast_possible_truncation,
clippy::tests_outside_test_module,
clippy::undocumented_unsafe_blocks
)]
use std::os::raw::{c_int, c_void};
use std::os::unix::io::{AsRawFd, RawFd};
use std::sync::{Arc, Mutex};
Expand Down
2 changes: 2 additions & 0 deletions src/vmm/tests/integration_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::cast_possible_truncation, clippy::tests_outside_test_module)]

use std::io::{Seek, SeekFrom};
use std::thread;
use std::time::Duration;
Expand Down
2 changes: 2 additions & 0 deletions src/vmm/tests/io_uring.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::cast_possible_truncation, clippy::tests_outside_test_module)]

use std::os::unix::fs::FileExt;
use std::os::unix::io::AsRawFd;
use std::thread;
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/build/test_clippy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ def test_rust_clippy(target):
"""
Test that clippy does not generate any errors/warnings.
"""
cargo("clippy", f"--target {target} --all --profile test", "-D warnings")
cargo("clippy", f"--target {target} --all --all-targets", "-D warnings")
19 changes: 18 additions & 1 deletion tools/devctr/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ RUN apt-get update \
&& pip3 install --upgrade poetry

ARG VENV="/opt/venv"
COPY tools/devctr /tmp/poetry
COPY tools/devctr/poetry.lock /tmp/poetry/
COPY tools/devctr/pyproject.toml /tmp/poetry/
RUN cd /tmp/poetry \
&& virtualenv $VENV \
&& . $VENV/bin/activate \
Expand Down Expand Up @@ -195,6 +196,22 @@ RUN cd /usr/local/bin \
&& chmod +x codecov \
&& cd -

# Add cross-compile toolchain for devtool checkbuild command
RUN case "${ARCH}" in \
"aarch64") \
apt install -y gcc-x86-64-linux-gnu libc6-dev-amd64-cross linux-libc-dev-amd64-cross && \
rustup target add x86_64-unknown-linux-gnu \
;; \
"x86_64") \
apt install -y gcc-aarch64-linux-gnu libc6-dev-arm64-cross linux-libc-dev-arm64-cross && \
rustup target add aarch64-unknown-linux-gnu \
;; \
*) \
echo "Unsupported arch ${ARCH}" && \
exit 1 \
;; \
esac

ADD tools/devctr/ctr_gitconfig /root/.gitconfig

ENTRYPOINT ["/usr/bin/tini", "--"]
Loading