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

Add driverdog to link and load kernel modules at runtime #1867

Merged
merged 2 commits into from
Jan 11, 2022
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
17 changes: 17 additions & 0 deletions packages/binutils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "binutils"
version = "0.1.0"
edition = "2018"
publish = false
build = "build.rs"

[lib]
path = "pkg.rs"

[[package.metadata.build-package.external-files]]
url = "https://ftp.gnu.org/gnu/binutils/binutils-2.35.2.tar.xz"
sha512 = "9974ede5978d32e0d68fef23da48fa00bd06b0bff7ec45b00ca075c126d6bbe0cf2defc03ecc3f17bc6cc85b64271a13009c4049d7ba17de26e84e3a6e2c0348"

[build-dependencies]
glibc = { path = "../glibc" }
libz = { path = "../libz" }
67 changes: 67 additions & 0 deletions packages/binutils/binutils.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
Name: %{_cross_os}binutils
Version: 2.35.2
Release: 1%{?dist}
Summary: Tools for working with binaries
URL: https://sourceware.org/binutils
License: GPL-2.0-or-later AND LGPL-2.0-or-later AND GPL-3.0-or-later
Source0: https://ftp.gnu.org/gnu/binutils/binutils-%{version}.tar.xz
Requires: %{_cross_os}libz
BuildRequires: %{_cross_os}glibc-devel
BuildRequires: %{_cross_os}libz-devel

%description
%{summary}.

%package devel
Summary: Files for development using tools for working with binaries
Requires: %{name}

%description devel
%{summary}.

%prep
%autosetup -n binutils-%{version} -p1

%build
# Fail if the SDK version is different than the one provided in the image
[ %{version} = $(%{_cross_target}-ld -v | awk '{print $NF}') ] || exit 1

%cross_configure \
--disable-gold \
--disable-gdb \
--with-system-zlib \
--without-gnu-as \
--disable-plugins \
--disable-static
%make_build MAKEINFO=true tooldir=%{_cross_prefix}

%install
%make_install MAKEINFO=true tooldir=%{_cross_prefix}

%files
%license COPYING COPYING3.LIB COPYING3
%{_cross_attribution_file}
%{_cross_bindir}/ld
%{_cross_bindir}/strip
%exclude %{_cross_infodir}
%exclude %{_cross_mandir}
%exclude %{_cross_localedir}
%exclude %{_cross_libdir}/ldscripts
%exclude %{_cross_libdir}/lib*.la
%exclude %{_cross_bindir}/addr2line
%exclude %{_cross_bindir}/ar
%exclude %{_cross_bindir}/c++filt
%exclude %{_cross_bindir}/elfedit
%exclude %{_cross_bindir}/gprof
%exclude %{_cross_bindir}/ld.bfd
%exclude %{_cross_bindir}/nm
%exclude %{_cross_bindir}/objcopy
%exclude %{_cross_bindir}/objdump
%exclude %{_cross_bindir}/ranlib
%exclude %{_cross_bindir}/readelf
%exclude %{_cross_bindir}/size
%exclude %{_cross_bindir}/strings

%files devel
%{_cross_libdir}/*.a
%{_cross_includedir}/*.h
9 changes: 9 additions & 0 deletions packages/binutils/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::process::{exit, Command};

fn main() -> Result<(), std::io::Error> {
let ret = Command::new("buildsys").arg("build-package").status()?;
if !ret.success() {
exit(1);
}
Ok(())
}
1 change: 1 addition & 0 deletions packages/binutils/pkg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// not used
5 changes: 4 additions & 1 deletion packages/os/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ source-groups = [
"models",
"imdsclient",
"retry-read",
"shimpei"
"shimpei",
"driverdog"
]

[lib]
Expand All @@ -40,5 +41,7 @@ glibc = { path = "../glibc" }
# kexec-tools and makedumpfile required for prairiedog functionality
# kexec-tools = { path = "../kexec-tools" }
# makedumpfile = { path = "../makedumpfile" }
# binutils required for driverdog functionality
# binutils = { path = "../binutils" }
# oci-add-hooks required for shimpei functionality
# oci-add-hooks = { path = "../oci-add-hooks" }
17 changes: 17 additions & 0 deletions packages/os/link-kernel-modules.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Link additional kernel modules
# Rerunning this service after the system is fully loaded will override
# the already linked kernel modules. This doesn't affect the running system,
# since kernel modules are linked early in the boot sequence, but we still
# disable manual restarts to prevent unnecessary kernel modules rewrites.
RefuseManualStart=true
webern marked this conversation as resolved.
Show resolved Hide resolved
RefuseManualStop=true

[Service]
Type=oneshot
ExecStart=/usr/bin/driverdog link-modules
RemainAfterExit=true
StandardError=journal+console

[Install]
RequiredBy=preconfigured.target
17 changes: 17 additions & 0 deletions packages/os/load-kernel-modules.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Load additional kernel modules
After=link-kernel-modules.service
Requires=link-kernel-modules.service
# Disable manual restarts to prevent loading kernel modules
# that weren't linked by the running system
RefuseManualStart=true
RefuseManualStop=true

[Service]
Type=oneshot
ExecStart=/usr/bin/driverdog load-modules
RemainAfterExit=true
StandardError=journal+console

[Install]
RequiredBy=preconfigured.target
31 changes: 31 additions & 0 deletions packages/os/os.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
%global _cross_first_party 1
%global _is_k8s_variant %(if echo %{_cross_variant} | grep -Fqw "k8s"; then echo 1; else echo 0; fi)
%global _is_aws_variant %(if echo %{_cross_variant} | grep -Fqw "aws"; then echo 1; else echo 0; fi)
%global _is_vendor_variant %(if echo %{_cross_variant} | grep -Fqw "nvidia"; then echo 1; else echo 0; fi)
%undefine _debugsource_packages

Name: %{_cross_os}os
Expand Down Expand Up @@ -39,6 +40,8 @@ Source111: metricdog.service
Source112: metricdog.timer
Source113: send-boot-success.service
Source114: [email protected]
Source115: link-kernel-modules.service
Source116: load-kernel-modules.service

# 2xx sources: tmpfilesd configs
Source200: migration-tmpfiles.conf
Expand Down Expand Up @@ -91,6 +94,10 @@ Requires: %{_cross_os}shibaken
Requires: %{_cross_os}ecs-settings-applier
%endif

%if %{_is_vendor_variant}
Requires: %{_cross_os}driverdog
%endif

%description
%{summary}.

Expand Down Expand Up @@ -251,6 +258,14 @@ Requires: %{_cross_os}hotdog
%description -n %{_cross_os}shimpei
%{summary}.

%if %{_is_vendor_variant}
%package -n %{_cross_os}driverdog
Summary: Tool to load additional drivers
Requires: %{_cross_os}binutils
%description -n %{_cross_os}driverdog
%{summary}.
%endif

%package -n %{_cross_os}bootstrap-containers
Summary: Manages bootstrap-containers
%description -n %{_cross_os}bootstrap-containers
Expand Down Expand Up @@ -327,6 +342,9 @@ echo "** Output from non-static builds:"
-p pluto \
%endif
-p static-pods \
%endif
%if %{_is_vendor_variant}
-p driverdog \
%endif
%{nil}

Expand Down Expand Up @@ -361,6 +379,9 @@ for p in \
%endif
static-pods \
%endif
%if %{_is_vendor_variant}
driverdog \
%endif
; do
install -p -m 0755 ${HOME}/.cache/%{__cargo_target}/release/${p} %{buildroot}%{_cross_bindir}
done
Expand Down Expand Up @@ -413,6 +434,9 @@ install -p -m 0644 \
%{S:100} %{S:101} %{S:102} %{S:103} %{S:105} \
%{S:106} %{S:107} %{S:110} %{S:111} %{S:112} \
%{S:113} %{S:114} \
%if %{_is_vendor_variant}
%{S:115} %{S:116} \
%endif
%{buildroot}%{_cross_unitdir}

install -d %{buildroot}%{_cross_tmpfilesdir}
Expand Down Expand Up @@ -540,6 +564,13 @@ install -p -m 0644 %{S:300} %{buildroot}%{_cross_udevrulesdir}/80-ephemeral-stor
%{_cross_datadir}/eks/eni-max-pods
%endif

%if %{_is_vendor_variant}
%files -n %{_cross_os}driverdog
%{_cross_bindir}/driverdog
%{_cross_unitdir}/link-kernel-modules.service
%{_cross_unitdir}/load-kernel-modules.service
%endif

%files -n %{_cross_os}static-pods
%{_cross_bindir}/static-pods
%endif
Expand Down
1 change: 1 addition & 0 deletions packages/release/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ path = "pkg.rs"
# RPM Requires
[dependencies]
acpid = { path = "../acpid" }
binutils = { path = "../binutils" }
ca-certificates = { path = "../ca-certificates" }
chrony = { path = "../chrony" }
conntrack-tools = { path = "../conntrack-tools" }
Expand Down
14 changes: 14 additions & 0 deletions sources/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions sources/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ members = [

"imdsclient",

"driverdog",

"ghostdog",

"growpart",
Expand Down
21 changes: 21 additions & 0 deletions sources/driverdog/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "driverdog"
version = "0.1.0"
authors = ["Arnaldo Garcia Rincon <[email protected]>"]
license = "Apache-2.0 OR MIT"
edition = "2018"
publish = false
# Don't rebuild crate just because of changes to README.
exclude = ["README.md"]

[dependencies]
argh = "0.1.3"
log = "0.4"
simplelog = "0.10"
snafu = "0.6"
serde = { version = "1.0", features = ["derive"] }
tempfile = "3.2.0"
toml = "0.5.8"

[build-dependencies]
cargo-readme = "3.1"
14 changes: 14 additions & 0 deletions sources/driverdog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# driverdog

Current version: 0.1.0

driverdog is a tool to link kernel modules at runtime. It uses a toml configuration file with the following shape:

`lib-modules-path`: destination path for the .ko linked files
`objects-source`: path where the objects used to link the kernel module are
`object-files`: hash with the object files to be linked, each object in the map should include the files used to link it
`kernel-modules`: hash with the kernel modules to be linked, each kernel module in the map should include the files used to link it

## Colophon

This text was generated from `README.tpl` using [cargo-readme](https://crates.io/crates/cargo-readme), and includes the rustdoc from `src/main.rs`.
9 changes: 9 additions & 0 deletions sources/driverdog/README.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# {{crate}}

Current version: {{version}}

{{readme}}

## Colophon

This text was generated from `README.tpl` using [cargo-readme](https://crates.io/crates/cargo-readme), and includes the rustdoc from `src/main.rs`.
32 changes: 32 additions & 0 deletions sources/driverdog/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Automatically generate README.md from rustdoc.

use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;

fn main() {
// Check for environment variable "SKIP_README". If it is set,
// skip README generation
if env::var_os("SKIP_README").is_some() {
return;
}

let mut source = File::open("src/main.rs").unwrap();
let mut template = File::open("README.tpl").unwrap();

let content = cargo_readme::generate_readme(
&PathBuf::from("."), // root
&mut source, // source
Some(&mut template), // template
// The "add x" arguments don't apply when using a template.
true, // add title
false, // add badges
false, // add license
true, // indent headings
)
.unwrap();

let mut readme = File::create("README.md").unwrap();
readme.write_all(content.as_bytes()).unwrap();
}
Loading