bindgen: use upstream Linux headers

Move the ChromeOS-specific kernel header modifications into the
corresponding bindgen.sh patch sections.

This also downloads the Linux source rather than relying on the ChromeOS
kernel source tree, so it should work without having a chromiumos
checkout.

BUG=b:402466294
TEST=tools/bindgen-all-the-things

Change-Id: I8cb00cdaf847a0a9442722ec9e69e8c6b47cf437
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6345302
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Daniel Verkamp 2025-03-11 13:14:41 -07:00 committed by crosvm LUCI
parent 94f9dd5085
commit 8948174ef3
7 changed files with 22 additions and 22 deletions

View file

@ -20,6 +20,8 @@ use zerocopy::KnownLayout;
// The original index (236) used in the ChromeOS v6.6 kernel was reused upstream for another
// capability, so this may return incorrect information on some kernels.
pub const KVM_CAP_USER_CONFIGURE_NONCOHERENT_DMA_CROS: u32 = 236;
pub const KVM_CAP_USER_CONFIGURE_NONCOHERENT_DMA: u32 = 239;
pub const KVM_MEM_NON_COHERENT_DMA: u32 = 8;
// TODO(qwandor): Update this once the pKVM patches are merged upstream with a stable capability ID.
pub const KVM_CAP_ARM_PROTECTED_VM: u32 = 0xffbadab1;

View file

@ -18,6 +18,8 @@ use zerocopy::KnownLayout;
// The original index (236) used in the ChromeOS v6.6 kernel was reused upstream for another
// capability, so this may return incorrect information on some kernels.
pub const KVM_CAP_USER_CONFIGURE_NONCOHERENT_DMA_CROS: u32 = 236;
pub const KVM_CAP_USER_CONFIGURE_NONCOHERENT_DMA: u32 = 239;
pub const KVM_MEM_NON_COHERENT_DMA: u32 = 8;
// TODO(qwandor): Update this once the pKVM patches are merged upstream with a stable capability ID.
pub const KVM_CAP_ARM_PROTECTED_VM: u32 = 0xffbadab1;
@ -418,7 +420,6 @@ pub const KVM_API_VERSION: u32 = 12;
pub const KVM_MEM_LOG_DIRTY_PAGES: u32 = 1;
pub const KVM_MEM_READONLY: u32 = 2;
pub const KVM_MEM_GUEST_MEMFD: u32 = 4;
pub const KVM_MEM_NON_COHERENT_DMA: u32 = 8;
pub const KVM_PIT_SPEAKER_DUMMY: u32 = 1;
pub const KVM_EXIT_HYPERV_SYNIC: u32 = 1;
pub const KVM_EXIT_HYPERV_HCALL: u32 = 2;
@ -738,10 +739,6 @@ pub const KVM_CAP_VM_TYPES: u32 = 235;
pub const KVM_CAP_PRE_FAULT_MEMORY: u32 = 236;
pub const KVM_CAP_X86_APIC_BUS_CYCLES_NS: u32 = 237;
pub const KVM_CAP_X86_GUEST_MODE: u32 = 238;
pub const KVM_CAP_USER_CONFIGURE_NONCOHERENT_DMA: u32 = 239;
pub const KVM_CAP_GET_CUR_CPUFREQ: u32 = 512;
pub const KVM_CAP_UTIL_HINT: u32 = 513;
pub const KVM_CAP_GET_CPUFREQ_TBL: u32 = 514;
pub const KVM_IRQ_ROUTING_IRQCHIP: u32 = 1;
pub const KVM_IRQ_ROUTING_MSI: u32 = 2;
pub const KVM_IRQ_ROUTING_S390_ADAPTER: u32 = 3;

View file

@ -18,6 +18,8 @@ use zerocopy::KnownLayout;
// The original index (236) used in the ChromeOS v6.6 kernel was reused upstream for another
// capability, so this may return incorrect information on some kernels.
pub const KVM_CAP_USER_CONFIGURE_NONCOHERENT_DMA_CROS: u32 = 236;
pub const KVM_CAP_USER_CONFIGURE_NONCOHERENT_DMA: u32 = 239;
pub const KVM_MEM_NON_COHERENT_DMA: u32 = 8;
// TODO(qwandor): Update this once the pKVM patches are merged upstream with a stable capability ID.
pub const KVM_CAP_ARM_PROTECTED_VM: u32 = 0xffbadab1;
@ -148,7 +150,6 @@ pub const KVM_API_VERSION: u32 = 12;
pub const KVM_MEM_LOG_DIRTY_PAGES: u32 = 1;
pub const KVM_MEM_READONLY: u32 = 2;
pub const KVM_MEM_GUEST_MEMFD: u32 = 4;
pub const KVM_MEM_NON_COHERENT_DMA: u32 = 8;
pub const KVM_PIT_SPEAKER_DUMMY: u32 = 1;
pub const KVM_EXIT_HYPERV_SYNIC: u32 = 1;
pub const KVM_EXIT_HYPERV_HCALL: u32 = 2;
@ -467,10 +468,6 @@ pub const KVM_CAP_VM_TYPES: u32 = 235;
pub const KVM_CAP_PRE_FAULT_MEMORY: u32 = 236;
pub const KVM_CAP_X86_APIC_BUS_CYCLES_NS: u32 = 237;
pub const KVM_CAP_X86_GUEST_MODE: u32 = 238;
pub const KVM_CAP_USER_CONFIGURE_NONCOHERENT_DMA: u32 = 239;
pub const KVM_CAP_GET_CUR_CPUFREQ: u32 = 512;
pub const KVM_CAP_UTIL_HINT: u32 = 513;
pub const KVM_CAP_GET_CPUFREQ_TBL: u32 = 514;
pub const KVM_IRQ_ROUTING_IRQCHIP: u32 = 1;
pub const KVM_IRQ_ROUTING_MSI: u32 = 2;
pub const KVM_IRQ_ROUTING_S390_ADAPTER: u32 = 3;

View file

@ -18,6 +18,8 @@ use zerocopy::KnownLayout;
// The original index (236) used in the ChromeOS v6.6 kernel was reused upstream for another
// capability, so this may return incorrect information on some kernels.
pub const KVM_CAP_USER_CONFIGURE_NONCOHERENT_DMA_CROS: u32 = 236;
pub const KVM_CAP_USER_CONFIGURE_NONCOHERENT_DMA: u32 = 239;
pub const KVM_MEM_NON_COHERENT_DMA: u32 = 8;
// TODO(qwandor): Update this once the pKVM patches are merged upstream with a stable capability ID.
pub const KVM_CAP_ARM_PROTECTED_VM: u32 = 0xffbadab1;
@ -340,7 +342,6 @@ pub const KVM_API_VERSION: u32 = 12;
pub const KVM_MEM_LOG_DIRTY_PAGES: u32 = 1;
pub const KVM_MEM_READONLY: u32 = 2;
pub const KVM_MEM_GUEST_MEMFD: u32 = 4;
pub const KVM_MEM_NON_COHERENT_DMA: u32 = 8;
pub const KVM_PIT_SPEAKER_DUMMY: u32 = 1;
pub const KVM_EXIT_HYPERV_SYNIC: u32 = 1;
pub const KVM_EXIT_HYPERV_HCALL: u32 = 2;
@ -668,10 +669,6 @@ pub const KVM_CAP_VM_TYPES: u32 = 235;
pub const KVM_CAP_PRE_FAULT_MEMORY: u32 = 236;
pub const KVM_CAP_X86_APIC_BUS_CYCLES_NS: u32 = 237;
pub const KVM_CAP_X86_GUEST_MODE: u32 = 238;
pub const KVM_CAP_USER_CONFIGURE_NONCOHERENT_DMA: u32 = 239;
pub const KVM_CAP_GET_CUR_CPUFREQ: u32 = 512;
pub const KVM_CAP_UTIL_HINT: u32 = 513;
pub const KVM_CAP_GET_CPUFREQ_TBL: u32 = 514;
pub const KVM_IRQ_ROUTING_IRQCHIP: u32 = 1;
pub const KVM_IRQ_ROUTING_MSI: u32 = 2;
pub const KVM_IRQ_ROUTING_S390_ADAPTER: u32 = 3;

View file

@ -4,7 +4,7 @@
# Helper functions for bindgen scripts sourced by tools/bindgen-all-the-things.
BINDGEN_LINUX="${PWD}/../../third_party/kernel/v6.12"
LINUX_VERSION="6.12.18"
export BINDGEN_OPTS=(
'--disable-header-comment'
@ -48,6 +48,7 @@ bindgen_generate() {
}
bindgen_cleanup() {
rm -rf "${BINDGEN_TEMP}"
rm -rf "${BINDGEN_LINUX_X86_HEADERS}" "${BINDGEN_LINUX_ARM64_HEADERS}" "${BINDGEN_LINUX_RISCV_HEADERS}"
}
@ -64,14 +65,18 @@ if [[ -z "${BINDGEN_LINUX_X86_HEADERS+x}" || ! -d "${BINDGEN_LINUX_X86_HEADERS}"
echo -n "Installing Linux headers for x86, arm64, and riscv..."
(
cd "${BINDGEN_LINUX}"
BINDGEN_LINUX_TARBALL="https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-${LINUX_VERSION}.tar.xz"
export BINDGEN_TEMP=$(mktemp -d)
cd "${BINDGEN_TEMP}"
# TODO: consider caching the downloaded file
curl "${BINDGEN_LINUX_TARBALL}" | tar xfJ -
cd "linux-${LINUX_VERSION}"
nproc=$(nproc)
make -s headers_install ARCH=x86 INSTALL_HDR_PATH="${BINDGEN_LINUX_X86_HEADERS}" -j "${nproc}"
make -s headers_install ARCH=arm64 INSTALL_HDR_PATH="${BINDGEN_LINUX_ARM64_HEADERS}" -j "${nproc}"
make -s headers_install ARCH=riscv INSTALL_HDR_PATH="${BINDGEN_LINUX_RISCV_HEADERS}" -j "${nproc}"
make -s mrproper ARCH=x86
make -s mrproper ARCH=arm64
make -s mrproper ARCH=riscv
)
echo " done."
fi

View file

@ -57,6 +57,8 @@ VIRTIO_IDS_EXTRAS="
//! from 63) are nonstandard and not defined by the virtio specification.
// Added by virtio_sys/bindgen.sh - do not edit the generated file.
pub const VIRTIO_ID_WL: u32 = 63;
pub const VIRTIO_ID_TPM: u32 = 62;
// TODO(b/236144983): Fix this id when an official virtio-id is assigned to this device.
pub const VIRTIO_ID_PVCLOCK: u32 = 61;
// TODO: Remove this once the ID is included in the Linux headers.

View file

@ -12,6 +12,8 @@
//! from 63) are nonstandard and not defined by the virtio specification.
// Added by virtio_sys/bindgen.sh - do not edit the generated file.
pub const VIRTIO_ID_WL: u32 = 63;
pub const VIRTIO_ID_TPM: u32 = 62;
// TODO(b/236144983): Fix this id when an official virtio-id is assigned to this device.
pub const VIRTIO_ID_PVCLOCK: u32 = 61;
// TODO: Remove this once the ID is included in the Linux headers.
@ -56,5 +58,3 @@ pub const VIRTIO_ID_PARAM_SERV: u32 = 38;
pub const VIRTIO_ID_AUDIO_POLICY: u32 = 39;
pub const VIRTIO_ID_BT: u32 = 40;
pub const VIRTIO_ID_GPIO: u32 = 41;
pub const VIRTIO_ID_WL: u32 = 63;
pub const VIRTIO_ID_TPM: u32 = 62;