Skip to content

Commit be75dd0

Browse files
committed
feat: Generate bindings to enable Intel AMX's TILEDATA for XSAVE
Bindings for ARCH_REQ_XCOMP_GUEST_PERM and ARCH_XCOMP_TILEDATA are required to enable Intel AMX's XTILEDATA for XSAVE. Note that the required bits were added in kernel v6.4+. Signed-off-by: Takahiro Itazuri <[email protected]>
1 parent 26a3a1e commit be75dd0

File tree

3 files changed

+164
-112
lines changed

3 files changed

+164
-112
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2025 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+
missing_debug_implementations,
14+
clippy::tests_outside_test_module
15+
)]
16+
17+
pub const ARCH_SET_GS: u32 = 4097;
18+
pub const ARCH_SET_FS: u32 = 4098;
19+
pub const ARCH_GET_FS: u32 = 4099;
20+
pub const ARCH_GET_GS: u32 = 4100;
21+
pub const ARCH_GET_CPUID: u32 = 4113;
22+
pub const ARCH_SET_CPUID: u32 = 4114;
23+
pub const ARCH_GET_XCOMP_SUPP: u32 = 4129;
24+
pub const ARCH_GET_XCOMP_PERM: u32 = 4130;
25+
pub const ARCH_REQ_XCOMP_PERM: u32 = 4131;
26+
pub const ARCH_GET_XCOMP_GUEST_PERM: u32 = 4132;
27+
pub const ARCH_REQ_XCOMP_GUEST_PERM: u32 = 4133;
28+
pub const ARCH_XCOMP_TILECFG: u32 = 17;
29+
pub const ARCH_XCOMP_TILEDATA: u32 = 18;
30+
pub const ARCH_MAP_VDSO_X32: u32 = 8193;
31+
pub const ARCH_MAP_VDSO_32: u32 = 8194;
32+
pub const ARCH_MAP_VDSO_64: u32 = 8195;
33+
pub const ARCH_GET_UNTAG_MASK: u32 = 16385;
34+
pub const ARCH_ENABLE_TAGGED_ADDR: u32 = 16386;
35+
pub const ARCH_GET_MAX_TAG_BITS: u32 = 16387;
36+
pub const ARCH_FORCE_TAGGED_SVA: u32 = 16388;
37+
pub const ARCH_SHSTK_ENABLE: u32 = 20481;
38+
pub const ARCH_SHSTK_DISABLE: u32 = 20482;
39+
pub const ARCH_SHSTK_LOCK: u32 = 20483;
40+
pub const ARCH_SHSTK_UNLOCK: u32 = 20484;
41+
pub const ARCH_SHSTK_STATUS: u32 = 20485;
42+
pub const ARCH_SHSTK_SHSTK: u32 = 1;
43+
pub const ARCH_SHSTK_WRSS: u32 = 2;

src/vmm/src/arch/x86_64/gen/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
// Use of this source code is governed by a BSD-style license that can be
66
// found in the THIRD-PARTY file.
77

8+
pub mod arch_prctl;
89
pub mod hyperv;
910
pub mod hyperv_tlfs;
1011
pub mod mpspec;
11-
1212
pub mod msr_index;
1313
pub mod perf_event;

tools/bindgen.sh

Lines changed: 120 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -41,118 +41,127 @@ EOF
4141
bindgen --no-doc-comments --disable-header-comment --constified-enum '*' --with-derive-default --with-derive-partialeq $@
4242
}
4343

44-
KERNEL_HEADERS_HOME="/usr"
45-
46-
info "BINDGEN sockios.h"
47-
fc-bindgen "$KERNEL_HEADERS_HOME/include/linux/sockios.h" |replace_linux_int_types >src/vmm/src/devices/virtio/net/gen/sockios.rs
48-
49-
info "BINDGEN if.h"
50-
fc-bindgen "$KERNEL_HEADERS_HOME/include/linux/if.h" \
51-
--allowlist-var='IF.*' \
52-
--allowlist-type='if.*' \
53-
--allowlist-type="net_device.*" \
54-
-- -D __UAPI_DEF_IF_IFNAMSIZ -D __UAPI_DEF_IF_NET_DEVICE_FLAGS -D __UAPI_DEF_IF_IFREQ -D __UAPI_DEF_IF_IFMAP >src/vmm/src/devices/virtio/net/gen/iff.rs
55-
56-
info "BINDGEN if_tun.h"
57-
fc-bindgen \
58-
--allowlist-type='sock_fprog' \
59-
--allowlist-var='TUN_.*' \
60-
--allowlist-var='IFF_NO_PI' \
61-
--allowlist-var='IFF_MULTI_QUEUE' \
62-
--allowlist-var='IFF_TAP' \
63-
--allowlist-var='IFF_VNET_HDR' \
64-
--allowlist-var='ETH_.*' \
65-
--allowlist-type='ifreq' \
66-
"$KERNEL_HEADERS_HOME/include/linux/if_tun.h" >src/vmm/src/devices/virtio/net/gen/if_tun.rs
67-
68-
info "BINDGEN virtio_ring.h"
69-
fc-bindgen \
70-
--allowlist-var "VIRTIO_RING_F_EVENT_IDX" \
71-
"$KERNEL_HEADERS_HOME/include/linux/virtio_ring.h" >src/vmm/src/devices/virtio/gen/virtio_ring.rs
72-
73-
info "BINDGEN virtio_blk.h"
74-
fc-bindgen \
75-
--allowlist-var "VIRTIO_BLK_.*" \
76-
--allowlist-var "VIRTIO_F_.*" \
77-
"$KERNEL_HEADERS_HOME/include/linux/virtio_blk.h" >src/vmm/src/devices/virtio/gen/virtio_blk.rs
78-
79-
info "BINDGEN virtio_net.h"
80-
fc-bindgen \
81-
--allowlist-var "VIRTIO_NET_F_.*" \
82-
--allowlist-var "VIRTIO_F_.*" \
83-
--allowlist-type "virtio_net_hdr_v1" \
84-
"$KERNEL_HEADERS_HOME/include/linux/virtio_net.h" >src/vmm/src/devices/virtio/gen/virtio_net.rs
85-
86-
info "BINDGEN virtio_rng.h"
87-
fc-bindgen \
88-
--allowlist-var "VIRTIO_RNG_.*" \
89-
--allowlist-var "VIRTIO_F_.*" \
90-
"$KERNEL_HEADERS_HOME/include/linux/virtio_rng.h" >src/vmm/src/devices/virtio/gen/virtio_rng.rs
91-
92-
info "BINDGEN prctl.h"
93-
fc-bindgen \
94-
--allowlist-var "PR_.*" \
95-
"$KERNEL_HEADERS_HOME/include/linux/prctl.h" >src/firecracker/src/gen/prctl.rs
96-
sed -i '/PR_SET_SPECULATION_CTRL/s/u32/i32/g' src/firecracker/src/gen/prctl.rs
97-
98-
# https://www.kernel.org/doc/Documentation/kbuild/headers_install.txt
99-
# The Linux repo is huge. Just copy what we need.
100-
# git clone --branch v5.10 --depth 1 https://github.com/torvalds/linux.git linux
101-
git clone --branch linux-5.10.y --depth 1 https://github.com/amazonlinux/linux amazonlinux-v5.10.y
102-
103-
info "BINDGEN mpspec_def.h"
104-
fc-bindgen amazonlinux-v5.10.y/arch/x86/include/asm/mpspec_def.h \
105-
>src/vmm/src/arch/x86_64/gen/mpspec.rs
106-
# https://github.com/rust-lang/rust-bindgen/issues/1274
107-
108-
info "BINDGEN msr-index.h"
109-
cp -r amazonlinux-v5.10.y/include/asm-generic amazonlinux-v5.10.y/include/asm
110-
sed -i -E 's/__no_(sanitize|kasan)_or_inline//g' amazonlinux-v5.10.y/include/asm/rwonce.h
111-
fc-bindgen amazonlinux-v5.10.y/arch/x86/include/asm/msr-index.h \
112-
--allowlist-var "^MSR_.*$" \
113-
-- \
114-
-Iamazonlinux-v5.10.y/include/ \
115-
-Iamazonlinux-v5.10.y/arch/x86/include/ \
116-
-Wno-macro-redefined \
117-
>src/vmm/src/arch/x86_64/gen/msr_index.rs
118-
perl -i -pe 's/= (\d+);/sprintf("= 0x%x;",$1)/eg' src/vmm/src/arch/x86_64/gen/msr_index.rs
119-
120-
info "BINDGEN perf_event.h"
121-
grep "MSR_ARCH_PERFMON_" amazonlinux-v5.10.y/arch/x86/include/asm/perf_event.h \
122-
>amazonlinux-v5.10.y/arch/x86/include/asm/perf_event_msr.h
123-
fc-bindgen amazonlinux-v5.10.y/arch/x86/include/asm/perf_event_msr.h \
124-
--allowlist-var "^MSR_ARCH_PERFMON_.*$" \
125-
-- \
126-
>src/vmm/src/arch/x86_64/gen/perf_event.rs
127-
perl -i -pe 's/= (\d+);/sprintf("= 0x%x;",$1)/eg' src/vmm/src/arch/x86_64/gen/perf_event.rs
128-
129-
info "BINDGEN hyperv.h"
130-
grep "HV_X64_MSR_" amazonlinux-v5.10.y/arch/x86/kvm/hyperv.h \
131-
>amazonlinux-v5.10.y/arch/x86/kvm/hyperv_msr.h
132-
fc-bindgen amazonlinux-v5.10.y/arch/x86/kvm/hyperv_msr.h \
133-
--allowlist-var "^HV_X64_MSR_.*$" \
134-
-- \
135-
>src/vmm/src/arch/x86_64/gen/hyperv.rs
136-
perl -i -pe 's/= (\d+);/sprintf("= 0x%x;",$1)/eg' src/vmm/src/arch/x86_64/gen/hyperv.rs
137-
138-
info "BINDGEN hyperv-tlfs.h"
139-
grep "HV_X64_MSR_" amazonlinux-v5.10.y/arch/x86/include/asm/hyperv-tlfs.h \
140-
>amazonlinux-v5.10.y/arch/x86/include/asm/hyperv-tlfs_msr.h
141-
fc-bindgen amazonlinux-v5.10.y/arch/x86/include/asm/hyperv-tlfs_msr.h \
142-
--allowlist-var "^HV_X64_MSR_.*$" \
143-
-- \
144-
>src/vmm/src/arch/x86_64/gen/hyperv_tlfs.rs
145-
perl -i -pe 's/= (\d+);/sprintf("= 0x%x;",$1)/eg' src/vmm/src/arch/x86_64/gen/hyperv_tlfs.rs
146-
147-
info "BINDGEN io_uring.h"
44+
# KERNEL_HEADERS_HOME="/usr"
45+
46+
# info "BINDGEN sockios.h"
47+
# fc-bindgen "$KERNEL_HEADERS_HOME/include/linux/sockios.h" |replace_linux_int_types >src/vmm/src/devices/virtio/net/gen/sockios.rs
48+
49+
# info "BINDGEN if.h"
50+
# fc-bindgen "$KERNEL_HEADERS_HOME/include/linux/if.h" \
51+
# --allowlist-var='IF.*' \
52+
# --allowlist-type='if.*' \
53+
# --allowlist-type="net_device.*" \
54+
# -- -D __UAPI_DEF_IF_IFNAMSIZ -D __UAPI_DEF_IF_NET_DEVICE_FLAGS -D __UAPI_DEF_IF_IFREQ -D __UAPI_DEF_IF_IFMAP >src/vmm/src/devices/virtio/net/gen/iff.rs
55+
56+
# info "BINDGEN if_tun.h"
57+
# fc-bindgen \
58+
# --allowlist-type='sock_fprog' \
59+
# --allowlist-var='TUN_.*' \
60+
# --allowlist-var='IFF_NO_PI' \
61+
# --allowlist-var='IFF_MULTI_QUEUE' \
62+
# --allowlist-var='IFF_TAP' \
63+
# --allowlist-var='IFF_VNET_HDR' \
64+
# --allowlist-var='ETH_.*' \
65+
# --allowlist-type='ifreq' \
66+
# "$KERNEL_HEADERS_HOME/include/linux/if_tun.h" >src/vmm/src/devices/virtio/net/gen/if_tun.rs
67+
68+
# info "BINDGEN virtio_ring.h"
69+
# fc-bindgen \
70+
# --allowlist-var "VIRTIO_RING_F_EVENT_IDX" \
71+
# "$KERNEL_HEADERS_HOME/include/linux/virtio_ring.h" >src/vmm/src/devices/virtio/gen/virtio_ring.rs
72+
73+
# info "BINDGEN virtio_blk.h"
74+
# fc-bindgen \
75+
# --allowlist-var "VIRTIO_BLK_.*" \
76+
# --allowlist-var "VIRTIO_F_.*" \
77+
# "$KERNEL_HEADERS_HOME/include/linux/virtio_blk.h" >src/vmm/src/devices/virtio/gen/virtio_blk.rs
78+
79+
# info "BINDGEN virtio_net.h"
80+
# fc-bindgen \
81+
# --allowlist-var "VIRTIO_NET_F_.*" \
82+
# --allowlist-var "VIRTIO_F_.*" \
83+
# --allowlist-type "virtio_net_hdr_v1" \
84+
# "$KERNEL_HEADERS_HOME/include/linux/virtio_net.h" >src/vmm/src/devices/virtio/gen/virtio_net.rs
85+
86+
# info "BINDGEN virtio_rng.h"
87+
# fc-bindgen \
88+
# --allowlist-var "VIRTIO_RNG_.*" \
89+
# --allowlist-var "VIRTIO_F_.*" \
90+
# "$KERNEL_HEADERS_HOME/include/linux/virtio_rng.h" >src/vmm/src/devices/virtio/gen/virtio_rng.rs
91+
92+
# info "BINDGEN prctl.h"
93+
# fc-bindgen \
94+
# --allowlist-var "PR_.*" \
95+
# "$KERNEL_HEADERS_HOME/include/linux/prctl.h" >src/firecracker/src/gen/prctl.rs
96+
# sed -i '/PR_SET_SPECULATION_CTRL/s/u32/i32/g' src/firecracker/src/gen/prctl.rs
97+
98+
# # https://www.kernel.org/doc/Documentation/kbuild/headers_install.txt
99+
# # The Linux repo is huge. Just copy what we need.
100+
# # git clone --branch v5.10 --depth 1 https://github.com/torvalds/linux.git linux
101+
# git clone --branch linux-5.10.y --depth 1 https://github.com/amazonlinux/linux amazonlinux-v5.10.y
102+
103+
# info "BINDGEN mpspec_def.h"
104+
# fc-bindgen amazonlinux-v5.10.y/arch/x86/include/asm/mpspec_def.h \
105+
# >src/vmm/src/arch/x86_64/gen/mpspec.rs
106+
# # https://github.com/rust-lang/rust-bindgen/issues/1274
107+
108+
# info "BINDGEN msr-index.h"
109+
# cp -r amazonlinux-v5.10.y/include/asm-generic amazonlinux-v5.10.y/include/asm
110+
# sed -i -E 's/__no_(sanitize|kasan)_or_inline//g' amazonlinux-v5.10.y/include/asm/rwonce.h
111+
# fc-bindgen amazonlinux-v5.10.y/arch/x86/include/asm/msr-index.h \
112+
# --allowlist-var "^MSR_.*$" \
113+
# -- \
114+
# -Iamazonlinux-v5.10.y/include/ \
115+
# -Iamazonlinux-v5.10.y/arch/x86/include/ \
116+
# -Wno-macro-redefined \
117+
# >src/vmm/src/arch/x86_64/gen/msr_index.rs
118+
# perl -i -pe 's/= (\d+);/sprintf("= 0x%x;",$1)/eg' src/vmm/src/arch/x86_64/gen/msr_index.rs
119+
120+
# info "BINDGEN perf_event.h"
121+
# grep "MSR_ARCH_PERFMON_" amazonlinux-v5.10.y/arch/x86/include/asm/perf_event.h \
122+
# >amazonlinux-v5.10.y/arch/x86/include/asm/perf_event_msr.h
123+
# fc-bindgen amazonlinux-v5.10.y/arch/x86/include/asm/perf_event_msr.h \
124+
# --allowlist-var "^MSR_ARCH_PERFMON_.*$" \
125+
# -- \
126+
# >src/vmm/src/arch/x86_64/gen/perf_event.rs
127+
# perl -i -pe 's/= (\d+);/sprintf("= 0x%x;",$1)/eg' src/vmm/src/arch/x86_64/gen/perf_event.rs
128+
129+
# info "BINDGEN hyperv.h"
130+
# grep "HV_X64_MSR_" amazonlinux-v5.10.y/arch/x86/kvm/hyperv.h \
131+
# >amazonlinux-v5.10.y/arch/x86/kvm/hyperv_msr.h
132+
# fc-bindgen amazonlinux-v5.10.y/arch/x86/kvm/hyperv_msr.h \
133+
# --allowlist-var "^HV_X64_MSR_.*$" \
134+
# -- \
135+
# >src/vmm/src/arch/x86_64/gen/hyperv.rs
136+
# perl -i -pe 's/= (\d+);/sprintf("= 0x%x;",$1)/eg' src/vmm/src/arch/x86_64/gen/hyperv.rs
137+
138+
# info "BINDGEN hyperv-tlfs.h"
139+
# grep "HV_X64_MSR_" amazonlinux-v5.10.y/arch/x86/include/asm/hyperv-tlfs.h \
140+
# >amazonlinux-v5.10.y/arch/x86/include/asm/hyperv-tlfs_msr.h
141+
# fc-bindgen amazonlinux-v5.10.y/arch/x86/include/asm/hyperv-tlfs_msr.h \
142+
# --allowlist-var "^HV_X64_MSR_.*$" \
143+
# -- \
144+
# >src/vmm/src/arch/x86_64/gen/hyperv_tlfs.rs
145+
# perl -i -pe 's/= (\d+);/sprintf("= 0x%x;",$1)/eg' src/vmm/src/arch/x86_64/gen/hyperv_tlfs.rs
146+
147+
# info "BINDGEN io_uring.h"
148+
# fc-bindgen \
149+
# --allowlist-var "IORING_.+" \
150+
# --allowlist-var "IO_URING_.+" \
151+
# --allowlist-var "IOSQE_.+" \
152+
# --allowlist-type "io_uring_.+" \
153+
# --allowlist-type "io_.qring_offsets" \
154+
# "amazonlinux-v5.10.y/include/uapi/linux/io_uring.h" \
155+
# >src/vmm/src/io_uring/gen.rs
156+
157+
# Latest upstream kernel
158+
KERNEL_SRC_DIR="linux"
159+
[ -d ${KERNEL_SRC_DIR} ] || git clone --depth 1 https://github.com/amazonlinux/linux ${KERNEL_SRC_DIR}
160+
161+
info "BINDGEN asm/prctl.h"
148162
fc-bindgen \
149-
--allowlist-var "IORING_.+" \
150-
--allowlist-var "IO_URING_.+" \
151-
--allowlist-var "IOSQE_.+" \
152-
--allowlist-type "io_uring_.+" \
153-
--allowlist-type "io_.qring_offsets" \
154-
"amazonlinux-v5.10.y/include/uapi/linux/io_uring.h" \
155-
>src/vmm/src/io_uring/gen.rs
163+
--allowlist-var "ARCH_.*" \
164+
"${KERNEL_SRC_DIR}/arch/x86/include/uapi/asm/prctl.h" >src/vmm/src/arch/x86_64/gen/arch_prctl.rs
156165

157166
# Apply any patches
158167
info "Apply patches"

0 commit comments

Comments
 (0)