Skip to content

Commit 991ef6b

Browse files
committed
chore(firecracker): generate prctl.rs
From Takahiro Itazuri <[email protected]> Generates Rust code from `prctl.h` and removes TODO. Signed-off-by: Takahiro Itazuri <[email protected]> Signed-off-by: Patrick Roy <[email protected]>
1 parent 1b27112 commit 991ef6b

File tree

5 files changed

+170
-12
lines changed

5 files changed

+170
-12
lines changed

src/firecracker/src/gen/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
pub mod prctl;

src/firecracker/src/gen/prctl.rs

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// automatically generated by tools/bindgen.sh
5+
6+
#![allow(
7+
non_camel_case_types,
8+
non_upper_case_globals,
9+
dead_code,
10+
non_snake_case,
11+
clippy::ptr_as_ptr,
12+
clippy::undocumented_unsafe_blocks,
13+
clippy::cast_lossless,
14+
missing_debug_implementations,
15+
clippy::tests_outside_test_module
16+
)]
17+
18+
pub const PR_SET_PDEATHSIG: u32 = 1;
19+
pub const PR_GET_PDEATHSIG: u32 = 2;
20+
pub const PR_GET_DUMPABLE: u32 = 3;
21+
pub const PR_SET_DUMPABLE: u32 = 4;
22+
pub const PR_GET_UNALIGN: u32 = 5;
23+
pub const PR_SET_UNALIGN: u32 = 6;
24+
pub const PR_UNALIGN_NOPRINT: u32 = 1;
25+
pub const PR_UNALIGN_SIGBUS: u32 = 2;
26+
pub const PR_GET_KEEPCAPS: u32 = 7;
27+
pub const PR_SET_KEEPCAPS: u32 = 8;
28+
pub const PR_GET_FPEMU: u32 = 9;
29+
pub const PR_SET_FPEMU: u32 = 10;
30+
pub const PR_FPEMU_NOPRINT: u32 = 1;
31+
pub const PR_FPEMU_SIGFPE: u32 = 2;
32+
pub const PR_GET_FPEXC: u32 = 11;
33+
pub const PR_SET_FPEXC: u32 = 12;
34+
pub const PR_FP_EXC_SW_ENABLE: u32 = 128;
35+
pub const PR_FP_EXC_DIV: u32 = 65536;
36+
pub const PR_FP_EXC_OVF: u32 = 131072;
37+
pub const PR_FP_EXC_UND: u32 = 262144;
38+
pub const PR_FP_EXC_RES: u32 = 524288;
39+
pub const PR_FP_EXC_INV: u32 = 1048576;
40+
pub const PR_FP_EXC_DISABLED: u32 = 0;
41+
pub const PR_FP_EXC_NONRECOV: u32 = 1;
42+
pub const PR_FP_EXC_ASYNC: u32 = 2;
43+
pub const PR_FP_EXC_PRECISE: u32 = 3;
44+
pub const PR_GET_TIMING: u32 = 13;
45+
pub const PR_SET_TIMING: u32 = 14;
46+
pub const PR_TIMING_STATISTICAL: u32 = 0;
47+
pub const PR_TIMING_TIMESTAMP: u32 = 1;
48+
pub const PR_SET_NAME: u32 = 15;
49+
pub const PR_GET_NAME: u32 = 16;
50+
pub const PR_GET_ENDIAN: u32 = 19;
51+
pub const PR_SET_ENDIAN: u32 = 20;
52+
pub const PR_ENDIAN_BIG: u32 = 0;
53+
pub const PR_ENDIAN_LITTLE: u32 = 1;
54+
pub const PR_ENDIAN_PPC_LITTLE: u32 = 2;
55+
pub const PR_GET_SECCOMP: u32 = 21;
56+
pub const PR_SET_SECCOMP: u32 = 22;
57+
pub const PR_CAPBSET_READ: u32 = 23;
58+
pub const PR_CAPBSET_DROP: u32 = 24;
59+
pub const PR_GET_TSC: u32 = 25;
60+
pub const PR_SET_TSC: u32 = 26;
61+
pub const PR_TSC_ENABLE: u32 = 1;
62+
pub const PR_TSC_SIGSEGV: u32 = 2;
63+
pub const PR_GET_SECUREBITS: u32 = 27;
64+
pub const PR_SET_SECUREBITS: u32 = 28;
65+
pub const PR_SET_TIMERSLACK: u32 = 29;
66+
pub const PR_GET_TIMERSLACK: u32 = 30;
67+
pub const PR_TASK_PERF_EVENTS_DISABLE: u32 = 31;
68+
pub const PR_TASK_PERF_EVENTS_ENABLE: u32 = 32;
69+
pub const PR_MCE_KILL: u32 = 33;
70+
pub const PR_MCE_KILL_CLEAR: u32 = 0;
71+
pub const PR_MCE_KILL_SET: u32 = 1;
72+
pub const PR_MCE_KILL_LATE: u32 = 0;
73+
pub const PR_MCE_KILL_EARLY: u32 = 1;
74+
pub const PR_MCE_KILL_DEFAULT: u32 = 2;
75+
pub const PR_MCE_KILL_GET: u32 = 34;
76+
pub const PR_SET_MM: u32 = 35;
77+
pub const PR_SET_MM_START_CODE: u32 = 1;
78+
pub const PR_SET_MM_END_CODE: u32 = 2;
79+
pub const PR_SET_MM_START_DATA: u32 = 3;
80+
pub const PR_SET_MM_END_DATA: u32 = 4;
81+
pub const PR_SET_MM_START_STACK: u32 = 5;
82+
pub const PR_SET_MM_START_BRK: u32 = 6;
83+
pub const PR_SET_MM_BRK: u32 = 7;
84+
pub const PR_SET_MM_ARG_START: u32 = 8;
85+
pub const PR_SET_MM_ARG_END: u32 = 9;
86+
pub const PR_SET_MM_ENV_START: u32 = 10;
87+
pub const PR_SET_MM_ENV_END: u32 = 11;
88+
pub const PR_SET_MM_AUXV: u32 = 12;
89+
pub const PR_SET_MM_EXE_FILE: u32 = 13;
90+
pub const PR_SET_MM_MAP: u32 = 14;
91+
pub const PR_SET_MM_MAP_SIZE: u32 = 15;
92+
pub const PR_SET_PTRACER: u32 = 1499557217;
93+
pub const PR_SET_CHILD_SUBREAPER: u32 = 36;
94+
pub const PR_GET_CHILD_SUBREAPER: u32 = 37;
95+
pub const PR_SET_NO_NEW_PRIVS: u32 = 38;
96+
pub const PR_GET_NO_NEW_PRIVS: u32 = 39;
97+
pub const PR_GET_TID_ADDRESS: u32 = 40;
98+
pub const PR_SET_THP_DISABLE: u32 = 41;
99+
pub const PR_GET_THP_DISABLE: u32 = 42;
100+
pub const PR_MPX_ENABLE_MANAGEMENT: u32 = 43;
101+
pub const PR_MPX_DISABLE_MANAGEMENT: u32 = 44;
102+
pub const PR_SET_FP_MODE: u32 = 45;
103+
pub const PR_GET_FP_MODE: u32 = 46;
104+
pub const PR_FP_MODE_FR: u32 = 1;
105+
pub const PR_FP_MODE_FRE: u32 = 2;
106+
pub const PR_CAP_AMBIENT: u32 = 47;
107+
pub const PR_CAP_AMBIENT_IS_SET: u32 = 1;
108+
pub const PR_CAP_AMBIENT_RAISE: u32 = 2;
109+
pub const PR_CAP_AMBIENT_LOWER: u32 = 3;
110+
pub const PR_CAP_AMBIENT_CLEAR_ALL: u32 = 4;
111+
pub const PR_SVE_SET_VL: u32 = 50;
112+
pub const PR_SVE_SET_VL_ONEXEC: u32 = 262144;
113+
pub const PR_SVE_GET_VL: u32 = 51;
114+
pub const PR_SVE_VL_LEN_MASK: u32 = 65535;
115+
pub const PR_SVE_VL_INHERIT: u32 = 131072;
116+
pub const PR_GET_SPECULATION_CTRL: u32 = 52;
117+
pub const PR_SET_SPECULATION_CTRL: i32 = 53;
118+
pub const PR_SPEC_STORE_BYPASS: u32 = 0;
119+
pub const PR_SPEC_INDIRECT_BRANCH: u32 = 1;
120+
pub const PR_SPEC_L1D_FLUSH: u32 = 2;
121+
pub const PR_SPEC_NOT_AFFECTED: u32 = 0;
122+
pub const PR_SPEC_PRCTL: u32 = 1;
123+
pub const PR_SPEC_ENABLE: u32 = 2;
124+
pub const PR_SPEC_DISABLE: u32 = 4;
125+
pub const PR_SPEC_FORCE_DISABLE: u32 = 8;
126+
pub const PR_SPEC_DISABLE_NOEXEC: u32 = 16;
127+
pub const PR_PAC_RESET_KEYS: u32 = 54;
128+
pub const PR_PAC_APIAKEY: u32 = 1;
129+
pub const PR_PAC_APIBKEY: u32 = 2;
130+
pub const PR_PAC_APDAKEY: u32 = 4;
131+
pub const PR_PAC_APDBKEY: u32 = 8;
132+
pub const PR_PAC_APGAKEY: u32 = 16;
133+
pub const PR_SET_TAGGED_ADDR_CTRL: u32 = 55;
134+
pub const PR_GET_TAGGED_ADDR_CTRL: u32 = 56;
135+
pub const PR_TAGGED_ADDR_ENABLE: u32 = 1;
136+
pub const PR_MTE_TCF_NONE: u32 = 0;
137+
pub const PR_MTE_TCF_SYNC: u32 = 2;
138+
pub const PR_MTE_TCF_ASYNC: u32 = 4;
139+
pub const PR_MTE_TCF_MASK: u32 = 6;
140+
pub const PR_MTE_TAG_SHIFT: u32 = 3;
141+
pub const PR_MTE_TAG_MASK: u32 = 524280;
142+
pub const PR_MTE_TCF_SHIFT: u32 = 1;
143+
pub const PR_SET_IO_FLUSHER: u32 = 57;
144+
pub const PR_GET_IO_FLUSHER: u32 = 58;
145+
pub const PR_SET_SYSCALL_USER_DISPATCH: u32 = 59;
146+
pub const PR_SYS_DISPATCH_OFF: u32 = 0;
147+
pub const PR_SYS_DISPATCH_ON: u32 = 1;
148+
pub const PR_PAC_SET_ENABLED_KEYS: u32 = 60;
149+
pub const PR_PAC_GET_ENABLED_KEYS: u32 = 61;
150+
pub const PR_SCHED_CORE: u32 = 62;
151+
pub const PR_SCHED_CORE_GET: u32 = 0;
152+
pub const PR_SCHED_CORE_CREATE: u32 = 1;
153+
pub const PR_SCHED_CORE_SHARE_TO: u32 = 2;
154+
pub const PR_SCHED_CORE_SHARE_FROM: u32 = 3;
155+
pub const PR_SCHED_CORE_MAX: u32 = 4;

src/firecracker/src/main.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
mod api_server;
55
mod api_server_adapter;
6+
mod gen;
67
mod metrics;
78
mod seccomp;
89

@@ -489,22 +490,15 @@ fn resize_fdtable() -> Result<(), ResizeFdTableError> {
489490
/// Enable SSBD mitigation through `prctl`.
490491
#[cfg(target_arch = "aarch64")]
491492
pub fn enable_ssbd_mitigation() {
492-
// Parameters for `prctl`
493-
// TODO: generate bindings for these from the kernel sources.
494-
// https://elixir.bootlin.com/linux/v4.17/source/include/uapi/linux/prctl.h#L212
495-
const PR_SET_SPECULATION_CTRL: i32 = 53;
496-
const PR_SPEC_STORE_BYPASS: u64 = 0;
497-
const PR_SPEC_FORCE_DISABLE: u64 = 1u64 << 3;
498-
499493
// SAFETY: Parameters are valid since they are copied verbatim
500494
// from the kernel's UAPI.
501495
// PR_SET_SPECULATION_CTRL only uses those 2 parameters, so it's ok
502496
// to leave the latter 2 as zero.
503497
let ret = unsafe {
504498
libc::prctl(
505-
PR_SET_SPECULATION_CTRL,
506-
PR_SPEC_STORE_BYPASS,
507-
PR_SPEC_FORCE_DISABLE,
499+
gen::prctl::PR_SET_SPECULATION_CTRL,
500+
gen::prctl::PR_SPEC_STORE_BYPASS,
501+
gen::prctl::PR_SPEC_FORCE_DISABLE,
508502
0,
509503
0,
510504
)

src/vmm/src/devices/virtio/net/gen/iff.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,6 @@ pub const net_device_flags_IFF_DYNAMIC: net_device_flags = 32768;
549549
pub const net_device_flags_IFF_LOWER_UP: net_device_flags = 65536;
550550
pub const net_device_flags_IFF_DORMANT: net_device_flags = 131072;
551551
pub const net_device_flags_IFF_ECHO: net_device_flags = 262144;
552-
#[doc = " enum net_device_flags - &struct net_device flags\n\n These are the &struct net_device flags, they can be set by drivers, the\n kernel and some can be triggered by userspace. Userspace can query and\n set these flags using userspace utilities but there is also a sysfs\n entry available for all dev flags which can be queried and set. These flags\n are shared for all types of net_devices. The sysfs entries are available\n via /sys/class/net/<dev>/flags. Flags which can be toggled through sysfs\n are annotated below, note that only a few flags can be toggled and some\n other flags are always preserved from the original net_device flags\n even if you try to set them via sysfs. Flags which are always preserved\n are kept under the flag grouping @IFF_VOLATILE. Flags which are __volatile__\n are annotated below as such.\n\n You should have a pretty good reason to be extending these flags.\n\n @IFF_UP: interface is up. Can be toggled through sysfs.\n @IFF_BROADCAST: broadcast address valid. Volatile.\n @IFF_DEBUG: turn on debugging. Can be toggled through sysfs.\n @IFF_LOOPBACK: is a loopback net. Volatile.\n @IFF_POINTOPOINT: interface is has p-p link. Volatile.\n @IFF_NOTRAILERS: avoid use of trailers. Can be toggled through sysfs.\n\tVolatile.\n @IFF_RUNNING: interface RFC2863 OPER_UP. Volatile.\n @IFF_NOARP: no ARP protocol. Can be toggled through sysfs. Volatile.\n @IFF_PROMISC: receive all packets. Can be toggled through sysfs.\n @IFF_ALLMULTI: receive all multicast packets. Can be toggled through\n\tsysfs.\n @IFF_MASTER: master of a load balancer. Volatile.\n @IFF_SLAVE: slave of a load balancer. Volatile.\n @IFF_MULTICAST: Supports multicast. Can be toggled through sysfs.\n @IFF_PORTSEL: can set media type. Can be toggled through sysfs.\n @IFF_AUTOMEDIA: auto media select active. Can be toggled through sysfs.\n @IFF_DYNAMIC: dialup device with changing addresses. Can be toggled\n\tthrough sysfs.\n @IFF_LOWER_UP: driver signals L1 up. Volatile.\n @IFF_DORMANT: driver signals dormant. Volatile.\n @IFF_ECHO: echo sent packets. Volatile."]
553552
pub type net_device_flags = ::std::os::raw::c_uint;
554553
pub const IF_OPER_UNKNOWN: _bindgen_ty_4 = 0;
555554
pub const IF_OPER_NOTPRESENT: _bindgen_ty_4 = 1;

tools/bindgen.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function fc-bindgen {
3939
)]
4040
4141
EOF
42-
bindgen --disable-header-comment --constified-enum '*' --with-derive-default --with-derive-partialeq $@
42+
bindgen --no-doc-comments --disable-header-comment --constified-enum '*' --with-derive-default --with-derive-partialeq $@
4343
}
4444

4545
KERNEL_HEADERS_HOME="/usr"
@@ -90,6 +90,12 @@ fc-bindgen \
9090
--allowlist-var "VIRTIO_F_.*" \
9191
"$KERNEL_HEADERS_HOME/include/linux/virtio_rng.h" >src/vmm/src/devices/virtio/gen/virtio_rng.rs
9292

93+
info "BINDGEN prctl.h"
94+
fc-bindgen \
95+
--allowlist-var "PR_.*" \
96+
"$KERNEL_HEADERS_HOME/include/linux/prctl.h" >src/firecracker/src/gen/prctl.rs
97+
sed -i '/PR_SET_SPECULATION_CTRL/s/u32/i32/g' src/firecracker/src/gen/prctl.rs
98+
9399
# https://www.kernel.org/doc/Documentation/kbuild/headers_install.txt
94100
# The Linux repo is huge. Just copy what we need.
95101
# git clone --branch v5.10 --depth 1 https://github.com/torvalds/linux.git linux

0 commit comments

Comments
 (0)