diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 79abf0f70940cc..acc22f61a551ee 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -11,7 +11,6 @@ jobs: strategy: matrix: mode: [debug, release] - module: [builtin, loadable] outputdir: [src, build] steps: @@ -24,13 +23,11 @@ jobs: - run: rustup default nightly-2020-08-27 - run: rustup component add rustfmt - run: rustup component add rust-src + - run: git clone --depth 1 --branch 0.1.36 https://github.com/rust-lang/compiler-builtins.git $(rustc --print sysroot)/lib/rustlib/src/compiler-builtins # Build - run: cp .github/workflows/kernel-${{ matrix.mode }}.config .config - - if: matrix.module == 'loadable' - run: sed -i -E 's/^(CONFIG_RUST_EXAMPLE=)(y)$/\1m/g' .config - - if: matrix.outputdir == 'build' run: mkdir build && mv .config build/.config @@ -40,9 +37,6 @@ jobs: run: make O=build CC=clang-11 LLVM_CONFIG_PATH=llvm-config-11 -j3 # Run - - if: matrix.module == 'builtin' - run: sed -i '/rust_example/d' .github/workflows/qemu-initramfs.desc - - if: matrix.outputdir == 'build' run: sed -i 's:drivers/:build/drivers/:' .github/workflows/qemu-initramfs.desc @@ -52,28 +46,31 @@ jobs: run: build/usr/gen_init_cpio .github/workflows/qemu-initramfs.desc > qemu-initramfs.img - if: matrix.outputdir == 'src' - run: qemu-system-x86_64 -kernel arch/x86/boot/bzImage -initrd qemu-initramfs.img -cpu Cascadelake-Server -smp 2 -nographic -no-reboot -append "console=ttyS0 ${{ matrix.module == 'builtin' && 'rust_example.my_i32=123321' || '' }}" | tee qemu-stdout.log + run: qemu-system-x86_64 -kernel arch/x86/boot/bzImage -initrd qemu-initramfs.img -cpu Cascadelake-Server -smp 2 -nographic -no-reboot -append "console=ttyS0 rust_example.my_i32=123321 rust_example_2.my_i32=234432" | tee qemu-stdout.log - if: matrix.outputdir == 'build' - run: qemu-system-x86_64 -kernel build/arch/x86/boot/bzImage -initrd qemu-initramfs.img -cpu Cascadelake-Server -smp 2 -nographic -no-reboot -append "console=ttyS0 ${{ matrix.module == 'builtin' && 'rust_example.my_i32=123321' || '' }}" | tee qemu-stdout.log + run: qemu-system-x86_64 -kernel build/arch/x86/boot/bzImage -initrd qemu-initramfs.img -cpu Cascadelake-Server -smp 2 -nographic -no-reboot -append "console=ttyS0 rust_example.my_i32=123321 rust_example_2.my_i32=234432" | tee qemu-stdout.log # Check - - run: grep -F 'Rust Example (init)' qemu-stdout.log - - run: "grep 'my_i32: \\+123321' qemu-stdout.log" - - if: matrix.module == 'loadable' - run: grep -F 'Rust Example (exit)' qemu-stdout.log + - run: grep -F '] Rust Example (init)' qemu-stdout.log + - run: grep -F '] [2] Rust Example (init)' qemu-stdout.log + - run: grep -F '] [3] Rust Example (init)' qemu-stdout.log + - run: grep -F '] [4] Rust Example (init)' qemu-stdout.log - # Report - - if: matrix.outputdir == 'src' && matrix.module == 'loadable' - run: ls -l drivers/char/rust_example/rust_example.ko - - if: matrix.outputdir == 'build' && matrix.module == 'loadable' - run: ls -l build/drivers/char/rust_example/rust_example.ko + - run: "grep -F '] my_i32: 123321' qemu-stdout.log" + - run: "grep -F '] [2] my_i32: 234432' qemu-stdout.log" + - run: "grep -F '] [3] my_i32: 345543' qemu-stdout.log" + - run: "grep -F '] [4] my_i32: 456654' qemu-stdout.log" + - run: grep -F '] [3] Rust Example (exit)' qemu-stdout.log + - run: grep -F '] [4] Rust Example (exit)' qemu-stdout.log + + # Report - if: matrix.outputdir == 'src' - run: ls -l vmlinux arch/x86/boot/bzImage + run: ls -l drivers/char/rust_example.o drivers/char/rust_example_3.ko rust/*.o vmlinux arch/x86/boot/bzImage - if: matrix.outputdir == 'build' - run: ls -l build/vmlinux build/arch/x86/boot/bzImage + run: ls -l build/drivers/char/rust_example.o build/drivers/char/rust_example_3.ko build/rust/*.o build/vmlinux build/arch/x86/boot/bzImage - if: matrix.outputdir == 'src' - run: size vmlinux + run: size drivers/char/rust_example.o drivers/char/rust_example_3.ko rust/*.o vmlinux - if: matrix.outputdir == 'build' - run: size build/vmlinux + run: size build/drivers/char/rust_example.o build/drivers/char/rust_example_3.ko build/rust/*.o build/vmlinux diff --git a/.github/workflows/kernel-debug.config b/.github/workflows/kernel-debug.config index de7c7905ecb3c4..358ccdaf0eab92 100644 --- a/.github/workflows/kernel-debug.config +++ b/.github/workflows/kernel-debug.config @@ -1,18 +1,21 @@ # # Automatically generated file; DO NOT EDIT. -# Linux/x86 5.9.0-rc2 Kernel Configuration +# Linux/x86 5.9.0 Kernel Configuration # CONFIG_CC_VERSION_TEXT="clang version 10.0.1" CONFIG_GCC_VERSION=0 CONFIG_LD_VERSION=230000000 CONFIG_CC_IS_CLANG=y +CONFIG_LD_IS_LLD=y CONFIG_CLANG_VERSION=100001 CONFIG_HAS_RUST=y CONFIG_RUSTC_VERSION=14800 -CONFIG_CARGO_VERSION=14800 CONFIG_CC_CAN_LINK=y CONFIG_CC_CAN_LINK_STATIC=y CONFIG_CC_HAS_ASM_GOTO=y +CONFIG_CC_HAS_ASM_GOTO_OUTPUT=y +CONFIG_TOOLS_SUPPORT_RELR=y +CONFIG_CC_HAS_ASM_INLINE=y CONFIG_CONSTRUCTORS=y CONFIG_IRQ_WORK=y CONFIG_BUILDTIME_TABLE_SORT=y @@ -199,10 +202,11 @@ CONFIG_SLUB=y # CONFIG_SLOB is not set # CONFIG_SLAB_MERGE_DEFAULT is not set # CONFIG_SLAB_FREELIST_RANDOM is not set -# CONFIG_SLAB_FREELIST_HARDENED is not set +CONFIG_SLAB_FREELIST_HARDENED=y # CONFIG_SHUFFLE_PAGE_ALLOCATOR is not set CONFIG_SLUB_CPU_PARTIAL=y # CONFIG_PROFILING is not set +CONFIG_RUST=y CONFIG_TRACEPOINTS=y # end of General setup @@ -328,13 +332,8 @@ CONFIG_HZ=1000 # CONFIG_KEXEC is not set # CONFIG_CRASH_DUMP is not set CONFIG_PHYSICAL_START=0x1000000 -CONFIG_RELOCATABLE=y -CONFIG_RANDOMIZE_BASE=y -CONFIG_X86_NEED_RELOCS=y +# CONFIG_RELOCATABLE is not set CONFIG_PHYSICAL_ALIGN=0x200000 -CONFIG_DYNAMIC_MEMORY_LAYOUT=y -CONFIG_RANDOMIZE_MEMORY=y -CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING=0x0 CONFIG_HOTPLUG_CPU=y # CONFIG_BOOTPARAM_HOTPLUG_CPU0 is not set # CONFIG_DEBUG_HOTPLUG_CPU0 is not set @@ -349,7 +348,6 @@ CONFIG_HAVE_LIVEPATCH=y CONFIG_ARCH_HAS_ADD_PAGES=y CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y CONFIG_ARCH_ENABLE_SPLIT_PMD_PTLOCK=y -CONFIG_ARCH_ENABLE_THP_MIGRATION=y # # Power management and ACPI options @@ -554,9 +552,7 @@ CONFIG_PHYS_ADDR_T_64BIT=y CONFIG_VIRT_TO_BUS=y # CONFIG_KSM is not set CONFIG_DEFAULT_MMAP_MIN_ADDR=4096 -CONFIG_TRANSPARENT_HUGEPAGE=y -CONFIG_TRANSPARENT_HUGEPAGE_ALWAYS=y -# CONFIG_TRANSPARENT_HUGEPAGE_MADVISE is not set +# CONFIG_TRANSPARENT_HUGEPAGE is not set CONFIG_ARCH_WANTS_THP_SWAP=y # CONFIG_CLEANCACHE is not set # CONFIG_CMA is not set @@ -603,7 +599,9 @@ CONFIG_PREVENT_FIRMWARE_BUILD=y # CONFIG_DEBUG_DRIVER is not set # CONFIG_DEBUG_DEVRES is not set # CONFIG_DEBUG_TEST_DRIVER_REMOVE is not set +# CONFIG_PM_QOS_KUNIT_TEST is not set # CONFIG_TEST_ASYNC_DRIVER_PROBE is not set +# CONFIG_KUNIT_DRIVER_PE_TEST is not set CONFIG_GENERIC_CPU_AUTOPROBE=y CONFIG_GENERIC_CPU_VULNERABILITIES=y # end of Generic Driver Options @@ -736,9 +734,11 @@ CONFIG_SERIAL_8250_RUNTIME_UARTS=1 # # Non-8250 serial port support # +# CONFIG_SERIAL_KGDB_NMI is not set # CONFIG_SERIAL_UARTLITE is not set CONFIG_SERIAL_CORE=y CONFIG_SERIAL_CORE_CONSOLE=y +CONFIG_CONSOLE_POLL=y # CONFIG_SERIAL_LANTIQ is not set # CONFIG_SERIAL_SCCNXP is not set # CONFIG_SERIAL_ALTERA_JTAGUART is not set @@ -763,6 +763,9 @@ CONFIG_SERIAL_CORE_CONSOLE=y # CONFIG_TCG_TPM is not set # CONFIG_TELCLOCK is not set CONFIG_RUST_EXAMPLE=y +CONFIG_RUST_EXAMPLE_2=y +CONFIG_RUST_EXAMPLE_3=m +CONFIG_RUST_EXAMPLE_4=m # end of Character devices # CONFIG_RANDOM_TRUST_BOOTLOADER is not set @@ -1093,11 +1096,11 @@ CONFIG_LSM="lockdown,yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,appar # CONFIG_CC_HAS_AUTO_VAR_INIT_PATTERN=y CONFIG_CC_HAS_AUTO_VAR_INIT_ZERO=y -CONFIG_INIT_STACK_NONE=y -# CONFIG_INIT_STACK_ALL_PATTERN is not set +# CONFIG_INIT_STACK_NONE is not set +CONFIG_INIT_STACK_ALL_PATTERN=y # CONFIG_INIT_STACK_ALL_ZERO is not set -# CONFIG_INIT_ON_ALLOC_DEFAULT_ON is not set -# CONFIG_INIT_ON_FREE_DEFAULT_ON is not set +CONFIG_INIT_ON_ALLOC_DEFAULT_ON=y +CONFIG_INIT_ON_FREE_DEFAULT_ON=y # end of Memory initialization # end of Kernel hardening options # end of Security options @@ -1137,7 +1140,6 @@ CONFIG_CRC32_SLICEBY8=y # CONFIG_CRC8 is not set # CONFIG_RANDOM32_SELFTEST is not set # CONFIG_XZ_DEC is not set -CONFIG_XARRAY_MULTI=y CONFIG_HAS_IOMEM=y CONFIG_HAS_IOPORT_MAP=y CONFIG_HAS_DMA=y @@ -1146,6 +1148,7 @@ CONFIG_NEED_DMA_MAP_STATE=y CONFIG_ARCH_DMA_ADDR_T_64BIT=y CONFIG_SWIOTLB=y # CONFIG_DMA_API_DEBUG is not set +# CONFIG_CPUMASK_OFFSTACK is not set CONFIG_GLOB=y # CONFIG_GLOB_SELFTEST is not set # CONFIG_IRQ_POLL is not set @@ -1184,29 +1187,44 @@ CONFIG_DEBUG_BUGVERBOSE=y # # Compile-time checks and compiler options # -# CONFIG_DEBUG_INFO is not set +CONFIG_DEBUG_INFO=y +# CONFIG_DEBUG_INFO_REDUCED is not set +# CONFIG_DEBUG_INFO_COMPRESSED is not set +# CONFIG_DEBUG_INFO_SPLIT is not set +CONFIG_DEBUG_INFO_DWARF4=y +# CONFIG_DEBUG_INFO_BTF is not set +# CONFIG_GDB_SCRIPTS is not set CONFIG_ENABLE_MUST_CHECK=y CONFIG_FRAME_WARN=2048 # CONFIG_STRIP_ASM_SYMS is not set -# CONFIG_READABLE_ASM is not set +CONFIG_READABLE_ASM=y # CONFIG_HEADERS_INSTALL is not set # CONFIG_DEBUG_SECTION_MISMATCH is not set # CONFIG_SECTION_MISMATCH_WARN_ONLY is not set -# CONFIG_DEBUG_FORCE_FUNCTION_ALIGN_32B is not set +CONFIG_DEBUG_FORCE_FUNCTION_ALIGN_32B=y CONFIG_STACK_VALIDATION=y +CONFIG_VMLINUX_VALIDATION=y # CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set # end of Compile-time checks and compiler options # # Generic Kernel Debugging Instruments # -# CONFIG_MAGIC_SYSRQ is not set +CONFIG_MAGIC_SYSRQ=y +CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE=0x1 +CONFIG_MAGIC_SYSRQ_SERIAL=y +CONFIG_MAGIC_SYSRQ_SERIAL_SEQUENCE="" CONFIG_DEBUG_FS=y # CONFIG_DEBUG_FS_ALLOW_ALL is not set # CONFIG_DEBUG_FS_DISALLOW_MOUNT is not set CONFIG_DEBUG_FS_ALLOW_NONE=y CONFIG_HAVE_ARCH_KGDB=y -# CONFIG_KGDB is not set +CONFIG_KGDB=y +CONFIG_KGDB_SERIAL_CONSOLE=y +# CONFIG_KGDB_TESTS is not set +# CONFIG_KGDB_LOW_LEVEL_TRAP is not set +# CONFIG_KGDB_KDB is not set +CONFIG_ARCH_HAS_EARLY_DEBUG=y CONFIG_ARCH_HAS_UBSAN_SANITIZE_ALL=y CONFIG_UBSAN=y CONFIG_UBSAN_TRAP=y @@ -1214,6 +1232,8 @@ CONFIG_UBSAN_BOUNDS=y CONFIG_UBSAN_MISC=y CONFIG_UBSAN_SANITIZE_ALL=y # CONFIG_TEST_UBSAN is not set +CONFIG_HAVE_ARCH_KCSAN=y +CONFIG_HAVE_KCSAN_COMPILER=y # end of Generic Kernel Debugging Instruments CONFIG_DEBUG_KERNEL=y @@ -1252,18 +1272,18 @@ CONFIG_DEBUG_KMEMLEAK_MEM_POOL_SIZE=16000 # CONFIG_DEBUG_KMEMLEAK_TEST is not set # CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF is not set CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN=y -# CONFIG_DEBUG_STACK_USAGE is not set +CONFIG_DEBUG_STACK_USAGE=y CONFIG_SCHED_STACK_END_CHECK=y CONFIG_ARCH_HAS_DEBUG_VM_PGTABLE=y CONFIG_DEBUG_VM=y CONFIG_DEBUG_VM_VMACACHE=y CONFIG_DEBUG_VM_RB=y CONFIG_DEBUG_VM_PGFLAGS=y -# CONFIG_DEBUG_VM_PGTABLE is not set +CONFIG_DEBUG_VM_PGTABLE=y CONFIG_ARCH_HAS_DEBUG_VIRTUAL=y CONFIG_DEBUG_VIRTUAL=y CONFIG_DEBUG_MEMORY_INIT=y -# CONFIG_DEBUG_PER_CPU_MAPS is not set +CONFIG_DEBUG_PER_CPU_MAPS=y CONFIG_HAVE_ARCH_KASAN=y CONFIG_HAVE_ARCH_KASAN_VMALLOC=y CONFIG_CC_HAS_KASAN_GENERIC=y @@ -1348,7 +1368,7 @@ CONFIG_DEBUG_NOTIFIERS=y CONFIG_BUG_ON_DATA_CORRUPTION=y # end of Debug kernel data structures -# CONFIG_DEBUG_CREDENTIALS is not set +CONFIG_DEBUG_CREDENTIALS=y # # RCU Debugging @@ -1384,7 +1404,6 @@ CONFIG_TRACING=y CONFIG_TRACING_SUPPORT=y # CONFIG_FTRACE is not set # CONFIG_SAMPLES is not set -CONFIG_HAVE_ARCH_KCSAN=y CONFIG_ARCH_HAS_DEVMEM_IS_ALLOWED=y # CONFIG_STRICT_DEVMEM is not set @@ -1404,7 +1423,7 @@ CONFIG_HAVE_MMIOTRACE_SUPPORT=y CONFIG_IO_DELAY_NONE=y # CONFIG_DEBUG_BOOT_PARAMS is not set # CONFIG_CPA_DEBUG is not set -# CONFIG_DEBUG_ENTRY is not set +CONFIG_DEBUG_ENTRY=y # CONFIG_DEBUG_NMI_SELFTEST is not set # CONFIG_X86_DEBUG_FPU is not set CONFIG_UNWINDER_ORC=y @@ -1414,13 +1433,64 @@ CONFIG_UNWINDER_ORC=y # # Kernel Testing and Coverage # -# CONFIG_KUNIT is not set +CONFIG_KUNIT=y +# CONFIG_KUNIT_DEBUGFS is not set +# CONFIG_KUNIT_TEST is not set +# CONFIG_KUNIT_EXAMPLE_TEST is not set +# CONFIG_KUNIT_ALL_TESTS is not set # CONFIG_NOTIFIER_ERROR_INJECTION is not set # CONFIG_FAULT_INJECTION is not set CONFIG_ARCH_HAS_KCOV=y CONFIG_CC_HAS_SANCOV_TRACE_PC=y # CONFIG_KCOV is not set -# CONFIG_RUNTIME_TESTING_MENU is not set +CONFIG_RUNTIME_TESTING_MENU=y +# CONFIG_LKDTM is not set +# CONFIG_TEST_LIST_SORT is not set +# CONFIG_TEST_MIN_HEAP is not set +# CONFIG_TEST_SORT is not set +# CONFIG_BACKTRACE_SELF_TEST is not set +# CONFIG_RBTREE_TEST is not set +# CONFIG_REED_SOLOMON_TEST is not set +# CONFIG_INTERVAL_TREE_TEST is not set +# CONFIG_PERCPU_TEST is not set +# CONFIG_ATOMIC64_SELFTEST is not set +# CONFIG_TEST_HEXDUMP is not set +# CONFIG_TEST_STRING_HELPERS is not set +# CONFIG_TEST_STRSCPY is not set +# CONFIG_TEST_KSTRTOX is not set +# CONFIG_TEST_PRINTF is not set +# CONFIG_TEST_BITMAP is not set +# CONFIG_TEST_BITFIELD is not set +# CONFIG_TEST_UUID is not set +# CONFIG_TEST_XARRAY is not set +# CONFIG_TEST_OVERFLOW is not set +# CONFIG_TEST_RHASHTABLE is not set +# CONFIG_TEST_HASH is not set +# CONFIG_TEST_IDA is not set +# CONFIG_TEST_LKM is not set +# CONFIG_TEST_BITOPS is not set +# CONFIG_TEST_VMALLOC is not set +# CONFIG_TEST_USER_COPY is not set +# CONFIG_FIND_BIT_BENCHMARK is not set +# CONFIG_SYSCTL_KUNIT_TEST is not set +# CONFIG_LIST_KUNIT_TEST is not set +# CONFIG_LINEAR_RANGES_TEST is not set +# CONFIG_BITS_TEST is not set +# CONFIG_TEST_UDELAY is not set +# CONFIG_TEST_STATIC_KEYS is not set +# CONFIG_TEST_DEBUG_VIRTUAL is not set +# CONFIG_TEST_MEMCAT_P is not set +# CONFIG_TEST_STACKINIT is not set +# CONFIG_TEST_MEMINIT is not set +# CONFIG_TEST_FPU is not set # CONFIG_MEMTEST is not set # end of Kernel Testing and Coverage + +# +# Rust hacking +# +CONFIG_RUST_DEBUG_ASSERTIONS=y +CONFIG_RUST_OVERFLOW_CHECKS=y +CONFIG_RUST_CODEGEN_UNITS=1 +# end of Rust hacking # end of Kernel hacking diff --git a/.github/workflows/kernel-release.config b/.github/workflows/kernel-release.config index 870f0f5e4caa3e..0d05efa80a21a6 100644 --- a/.github/workflows/kernel-release.config +++ b/.github/workflows/kernel-release.config @@ -1,18 +1,21 @@ # # Automatically generated file; DO NOT EDIT. -# Linux/x86 5.9.0-rc2 Kernel Configuration +# Linux/x86 5.9.0 Kernel Configuration # CONFIG_CC_VERSION_TEXT="clang version 10.0.1" CONFIG_GCC_VERSION=0 CONFIG_LD_VERSION=230000000 CONFIG_CC_IS_CLANG=y +CONFIG_LD_IS_LLD=y CONFIG_CLANG_VERSION=100001 CONFIG_HAS_RUST=y CONFIG_RUSTC_VERSION=14800 -CONFIG_CARGO_VERSION=14800 CONFIG_CC_CAN_LINK=y CONFIG_CC_CAN_LINK_STATIC=y CONFIG_CC_HAS_ASM_GOTO=y +CONFIG_CC_HAS_ASM_GOTO_OUTPUT=y +CONFIG_TOOLS_SUPPORT_RELR=y +CONFIG_CC_HAS_ASM_INLINE=y CONFIG_IRQ_WORK=y CONFIG_BUILDTIME_TABLE_SORT=y CONFIG_THREAD_INFO_IN_TASK=y @@ -41,6 +44,7 @@ CONFIG_KERNEL_GZIP=y # CONFIG_KERNEL_ZSTD is not set CONFIG_DEFAULT_INIT="" CONFIG_DEFAULT_HOSTNAME="(none)" +# CONFIG_SWAP is not set # CONFIG_SYSVIPC is not set # CONFIG_WATCH_QUEUE is not set # CONFIG_CROSS_MEMORY_ATTACH is not set @@ -73,6 +77,7 @@ CONFIG_GENERIC_CLOCKEVENTS_BROADCAST=y CONFIG_GENERIC_CLOCKEVENTS_MIN_ADJUST=y CONFIG_GENERIC_CMOS_UPDATE=y CONFIG_HAVE_POSIX_CPU_TIMERS_TASK_WORK=y +CONFIG_POSIX_CPU_TIMERS_TASK_WORK=y # # Timers subsystem @@ -96,6 +101,7 @@ CONFIG_PREEMPT_VOLUNTARY=y CONFIG_TICK_CPU_ACCOUNTING=y # CONFIG_VIRT_CPU_ACCOUNTING_GEN is not set # CONFIG_IRQ_TIME_ACCOUNTING is not set +# CONFIG_BSD_PROCESS_ACCT is not set # CONFIG_PSI is not set # end of CPU/Task time and stats accounting @@ -129,6 +135,11 @@ CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH=y CONFIG_CC_HAS_INT128=y CONFIG_ARCH_SUPPORTS_INT128=y # CONFIG_CGROUPS is not set +CONFIG_NAMESPACES=y +# CONFIG_UTS_NS is not set +# CONFIG_TIME_NS is not set +# CONFIG_USER_NS is not set +# CONFIG_PID_NS is not set # CONFIG_CHECKPOINT_RESTORE is not set # CONFIG_SCHED_AUTOGROUP is not set # CONFIG_SYSFS_DEPRECATED is not set @@ -145,61 +156,61 @@ CONFIG_INITRAMFS_SOURCE="" # CONFIG_BOOT_CONFIG is not set CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y # CONFIG_CC_OPTIMIZE_FOR_SIZE is not set +CONFIG_SYSCTL=y CONFIG_SYSCTL_EXCEPTION_TRACE=y CONFIG_HAVE_PCSPKR_PLATFORM=y -CONFIG_EXPERT=y -# CONFIG_MULTIUSER is not set -# CONFIG_SGETMASK_SYSCALL is not set -# CONFIG_SYSFS_SYSCALL is not set -# CONFIG_FHANDLE is not set -# CONFIG_POSIX_TIMERS is not set +# CONFIG_EXPERT is not set +CONFIG_MULTIUSER=y +CONFIG_SGETMASK_SYSCALL=y +CONFIG_SYSFS_SYSCALL=y +CONFIG_FHANDLE=y +CONFIG_POSIX_TIMERS=y CONFIG_PRINTK=y CONFIG_PRINTK_NMI=y CONFIG_BUG=y -# CONFIG_PCSPKR_PLATFORM is not set +CONFIG_ELF_CORE=y +CONFIG_PCSPKR_PLATFORM=y CONFIG_BASE_FULL=y -# CONFIG_FUTEX is not set -# CONFIG_EPOLL is not set -# CONFIG_SIGNALFD is not set -# CONFIG_TIMERFD is not set -# CONFIG_EVENTFD is not set -# CONFIG_SHMEM is not set -# CONFIG_AIO is not set -# CONFIG_IO_URING is not set -# CONFIG_ADVISE_SYSCALLS is not set -# CONFIG_MEMBARRIER is not set +CONFIG_FUTEX=y +CONFIG_FUTEX_PI=y +CONFIG_EPOLL=y +CONFIG_SIGNALFD=y +CONFIG_TIMERFD=y +CONFIG_EVENTFD=y +CONFIG_SHMEM=y +CONFIG_AIO=y +CONFIG_IO_URING=y +CONFIG_ADVISE_SYSCALLS=y +CONFIG_MEMBARRIER=y CONFIG_KALLSYMS=y -# CONFIG_KALLSYMS_ALL is not set CONFIG_KALLSYMS_ABSOLUTE_PERCPU=y CONFIG_KALLSYMS_BASE_RELATIVE=y # CONFIG_BPF_SYSCALL is not set CONFIG_ARCH_WANT_DEFAULT_BPF_JIT=y # CONFIG_USERFAULTFD is not set CONFIG_ARCH_HAS_MEMBARRIER_SYNC_CORE=y -# CONFIG_RSEQ is not set +CONFIG_RSEQ=y # CONFIG_EMBEDDED is not set CONFIG_HAVE_PERF_EVENTS=y -# CONFIG_PC104 is not set # # Kernel Performance Events And Counters # CONFIG_PERF_EVENTS=y -# CONFIG_DEBUG_PERF_USE_VMALLOC is not set # end of Kernel Performance Events And Counters -# CONFIG_VM_EVENT_COUNTERS is not set -# CONFIG_SLUB_DEBUG is not set +CONFIG_VM_EVENT_COUNTERS=y +CONFIG_SLUB_DEBUG=y # CONFIG_COMPAT_BRK is not set # CONFIG_SLAB is not set CONFIG_SLUB=y -# CONFIG_SLOB is not set # CONFIG_SLAB_MERGE_DEFAULT is not set # CONFIG_SLAB_FREELIST_RANDOM is not set -# CONFIG_SLAB_FREELIST_HARDENED is not set +CONFIG_SLAB_FREELIST_HARDENED=y # CONFIG_SHUFFLE_PAGE_ALLOCATOR is not set -# CONFIG_SLUB_CPU_PARTIAL is not set +CONFIG_SLUB_CPU_PARTIAL=y # CONFIG_PROFILING is not set +CONFIG_RUST=y # end of General setup CONFIG_64BIT=y @@ -214,8 +225,10 @@ CONFIG_ARCH_MMAP_RND_BITS_MIN=28 CONFIG_ARCH_MMAP_RND_BITS_MAX=32 CONFIG_ARCH_MMAP_RND_COMPAT_BITS_MIN=8 CONFIG_ARCH_MMAP_RND_COMPAT_BITS_MAX=16 +CONFIG_GENERIC_ISA_DMA=y CONFIG_GENERIC_BUG=y CONFIG_GENERIC_BUG_RELATIVE_POINTERS=y +CONFIG_ARCH_MAY_HAVE_PC_FDC=y CONFIG_GENERIC_CALIBRATE_DELAY=y CONFIG_ARCH_HAS_CPU_RELAX=y CONFIG_ARCH_HAS_CACHE_LINE_SIZE=y @@ -238,7 +251,7 @@ CONFIG_CC_HAS_SANE_STACKPROTECTOR=y # # Processor type and features # -# CONFIG_ZONE_DMA is not set +CONFIG_ZONE_DMA=y CONFIG_SMP=y CONFIG_X86_FEATURE_NAMES=y CONFIG_X86_MPPARSE=y @@ -262,15 +275,13 @@ CONFIG_X86_MINIMUM_CPU_FAMILY=64 CONFIG_X86_DEBUGCTLMSR=y CONFIG_IA32_FEAT_CTL=y CONFIG_X86_VMX_FEATURE_NAMES=y -# CONFIG_PROCESSOR_SELECT is not set CONFIG_CPU_SUP_INTEL=y CONFIG_CPU_SUP_AMD=y CONFIG_CPU_SUP_HYGON=y CONFIG_CPU_SUP_CENTAUR=y CONFIG_CPU_SUP_ZHAOXIN=y CONFIG_HPET_TIMER=y -# CONFIG_DMI is not set -# CONFIG_MAXSMP is not set +CONFIG_DMI=y CONFIG_NR_CPUS_RANGE_BEGIN=2 CONFIG_NR_CPUS_RANGE_END=512 CONFIG_NR_CPUS_DEFAULT=64 @@ -289,7 +300,9 @@ CONFIG_X86_IO_APIC=y # CONFIG_PERF_EVENTS_AMD_POWER is not set # end of Performance monitoring -# CONFIG_X86_VSYSCALL_EMULATION is not set +CONFIG_X86_16BIT=y +CONFIG_X86_ESPFIX64=y +CONFIG_X86_VSYSCALL_EMULATION=y # CONFIG_X86_IOPL_IOPERM is not set # CONFIG_I8K is not set # CONFIG_MICROCODE is not set @@ -305,10 +318,15 @@ CONFIG_ARCH_SELECT_MEMORY_MODEL=y CONFIG_ILLEGAL_POINTER_VALUE=0xdead000000000000 # CONFIG_X86_CHECK_BIOS_CORRUPTION is not set CONFIG_X86_RESERVE_LOW=64 -# CONFIG_MTRR is not set -# CONFIG_ARCH_RANDOM is not set -# CONFIG_X86_SMAP is not set -# CONFIG_X86_UMIP is not set +CONFIG_MTRR=y +CONFIG_MTRR_SANITIZER=y +CONFIG_MTRR_SANITIZER_ENABLE_DEFAULT=0 +CONFIG_MTRR_SANITIZER_SPARE_REG_NR_DEFAULT=1 +CONFIG_X86_PAT=y +CONFIG_ARCH_USES_PG_UNCACHED=y +CONFIG_ARCH_RANDOM=y +CONFIG_X86_SMAP=y +CONFIG_X86_UMIP=y # CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS is not set CONFIG_X86_INTEL_TSX_MODE_OFF=y # CONFIG_X86_INTEL_TSX_MODE_ON is not set @@ -336,7 +354,7 @@ CONFIG_HOTPLUG_CPU=y # CONFIG_LEGACY_VSYSCALL_XONLY is not set CONFIG_LEGACY_VSYSCALL_NONE=y # CONFIG_CMDLINE_BOOL is not set -# CONFIG_MODIFY_LDT_SYSCALL is not set +CONFIG_MODIFY_LDT_SYSCALL=y CONFIG_HAVE_LIVEPATCH=y # end of Processor type and features @@ -370,8 +388,7 @@ CONFIG_ARCH_SUPPORTS_ACPI=y # # Bus options (PCI etc.) # -# CONFIG_ISA_BUS is not set -# CONFIG_ISA_DMA_API is not set +CONFIG_ISA_DMA_API=y # CONFIG_X86_SYSFB is not set # end of Bus options (PCI etc.) @@ -386,7 +403,10 @@ CONFIG_ARCH_SUPPORTS_ACPI=y # Firmware Drivers # # CONFIG_EDD is not set -# CONFIG_FIRMWARE_MEMMAP is not set +CONFIG_FIRMWARE_MEMMAP=y +# CONFIG_DMIID is not set +# CONFIG_DMI_SYSFS is not set +CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK=y # CONFIG_FW_CFG_SYSFS is not set # CONFIG_GOOGLE_FIRMWARE is not set CONFIG_EFI_EARLYCON=y @@ -490,6 +510,7 @@ CONFIG_ARCH_HAS_GCOV_PROFILE_ALL=y CONFIG_HAVE_GCC_PLUGINS=y # end of General architecture-dependent options +CONFIG_RT_MUTEXES=y CONFIG_BASE_SMALL=0 CONFIG_MODULES=y # CONFIG_MODULE_FORCE_LOAD is not set @@ -503,7 +524,32 @@ CONFIG_MODULE_UNLOAD=y # CONFIG_UNUSED_SYMBOLS is not set # CONFIG_TRIM_UNUSED_KSYMS is not set CONFIG_MODULES_TREE_LOOKUP=y -# CONFIG_BLOCK is not set +CONFIG_BLOCK=y +# CONFIG_BLK_DEV_BSG is not set +# CONFIG_BLK_DEV_BSGLIB is not set +# CONFIG_BLK_DEV_INTEGRITY is not set +# CONFIG_BLK_DEV_ZONED is not set +# CONFIG_BLK_CMDLINE_PARSER is not set +# CONFIG_BLK_WBT is not set +# CONFIG_BLK_SED_OPAL is not set +# CONFIG_BLK_INLINE_ENCRYPTION is not set + +# +# Partition Types +# +# CONFIG_PARTITION_ADVANCED is not set +CONFIG_MSDOS_PARTITION=y +CONFIG_EFI_PARTITION=y +# end of Partition Types + +# +# IO Schedulers +# +# CONFIG_MQ_IOSCHED_DEADLINE is not set +# CONFIG_MQ_IOSCHED_KYBER is not set +# CONFIG_IOSCHED_BFQ is not set +# end of IO Schedulers + CONFIG_INLINE_SPIN_UNLOCK_IRQ=y CONFIG_INLINE_READ_UNLOCK=y CONFIG_INLINE_READ_UNLOCK_IRQ=y @@ -526,9 +572,10 @@ CONFIG_ARCH_HAS_SYSCALL_WRAPPER=y # CONFIG_BINFMT_ELF=y CONFIG_ELFCORE=y +CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS=y CONFIG_BINFMT_SCRIPT=y # CONFIG_BINFMT_MISC is not set -# CONFIG_COREDUMP is not set +CONFIG_COREDUMP=y # end of Executable file formats # @@ -547,6 +594,7 @@ CONFIG_COMPACTION=y # CONFIG_PAGE_REPORTING is not set CONFIG_MIGRATION=y CONFIG_PHYS_ADDR_T_64BIT=y +CONFIG_BOUNCE=y CONFIG_VIRT_TO_BUS=y # CONFIG_KSM is not set CONFIG_DEFAULT_MMAP_MIN_ADDR=4096 @@ -565,6 +613,7 @@ CONFIG_GENERIC_EARLY_IOREMAP=y CONFIG_ARCH_HAS_PTE_DEVMAP=y # CONFIG_PERCPU_STATS is not set # CONFIG_GUP_BENCHMARK is not set +# CONFIG_READ_ONLY_THP_FOR_FS is not set CONFIG_ARCH_HAS_PTE_SPECIAL=y # end of Memory Management options @@ -592,13 +641,13 @@ CONFIG_PREVENT_FIRMWARE_BUILD=y # # Firmware loader # -# CONFIG_FW_LOADER is not set +CONFIG_FW_LOADER=y +CONFIG_EXTRA_FIRMWARE="" +# CONFIG_FW_LOADER_USER_HELPER is not set +# CONFIG_FW_LOADER_COMPRESS is not set # end of Firmware loader -# CONFIG_ALLOW_DEV_COREDUMP is not set -# CONFIG_DEBUG_DRIVER is not set -# CONFIG_DEBUG_DEVRES is not set -# CONFIG_DEBUG_TEST_DRIVER_REMOVE is not set +CONFIG_ALLOW_DEV_COREDUMP=y # CONFIG_TEST_ASYNC_DRIVER_PROBE is not set CONFIG_GENERIC_CPU_AUTOPROBE=y CONFIG_GENERIC_CPU_VULNERABILITIES=y @@ -615,10 +664,12 @@ CONFIG_GENERIC_CPU_VULNERABILITIES=y # CONFIG_OF is not set CONFIG_ARCH_MIGHT_HAVE_PC_PARPORT=y # CONFIG_PARPORT is not set +# CONFIG_BLK_DEV is not set # # NVME Support # +# CONFIG_NVME_FC is not set # end of NVME Support # @@ -655,14 +706,21 @@ CONFIG_ARCH_MIGHT_HAVE_PC_PARPORT=y # end of Misc devices CONFIG_HAVE_IDE=y +# CONFIG_IDE is not set # # SCSI device support # CONFIG_SCSI_MOD=y +# CONFIG_RAID_ATTRS is not set +# CONFIG_SCSI is not set # end of SCSI device support +# CONFIG_ATA is not set +# CONFIG_MD is not set +# CONFIG_TARGET_CORE is not set # CONFIG_MACINTOSH_DRIVERS is not set +# CONFIG_NVM is not set # # Input device support @@ -706,11 +764,11 @@ CONFIG_ARCH_MIGHT_HAVE_PC_SERIO=y # CONFIG_TTY=y CONFIG_VT=y -# CONFIG_CONSOLE_TRANSLATIONS is not set +CONFIG_CONSOLE_TRANSLATIONS=y CONFIG_VT_CONSOLE=y CONFIG_HW_CONSOLE=y # CONFIG_VT_HW_CONSOLE_BINDING is not set -# CONFIG_UNIX98_PTYS is not set +CONFIG_UNIX98_PTYS=y # CONFIG_LEGACY_PTYS is not set # CONFIG_LDISC_AUTOLOAD is not set @@ -748,19 +806,23 @@ CONFIG_SERIAL_CORE_CONSOLE=y # CONFIG_NULL_TTY is not set # CONFIG_TRACE_SINK is not set # CONFIG_SERIAL_DEV_BUS is not set -# CONFIG_TTY_PRINTK is not set # CONFIG_IPMI_HANDLER is not set # CONFIG_HW_RANDOM is not set # CONFIG_MWAVE is not set # CONFIG_DEVMEM is not set # CONFIG_DEVKMEM is not set # CONFIG_NVRAM is not set +# CONFIG_RAW_DRIVER is not set # CONFIG_HANGCHECK_TIMER is not set # CONFIG_TCG_TPM is not set # CONFIG_TELCLOCK is not set CONFIG_RUST_EXAMPLE=y +CONFIG_RUST_EXAMPLE_2=y +CONFIG_RUST_EXAMPLE_3=m +CONFIG_RUST_EXAMPLE_4=m # end of Character devices +# CONFIG_RANDOM_TRUST_CPU is not set # CONFIG_RANDOM_TRUST_BOOTLOADER is not set # @@ -843,7 +905,7 @@ CONFIG_BCMA_POSSIBLE=y # # Console display driver support # -# CONFIG_VGA_CONSOLE is not set +CONFIG_VGA_CONSOLE=y CONFIG_DUMMY_CONSOLE=y CONFIG_DUMMY_CONSOLE_COLUMNS=80 CONFIG_DUMMY_CONSOLE_ROWS=25 @@ -904,6 +966,7 @@ CONFIG_RTC_MC146818_LIB=y # Clock Source drivers # CONFIG_CLKEVT_I8253=y +CONFIG_I8253_LOCK=y CONFIG_CLKBLD_I8253=y # end of Clock Source drivers @@ -1028,8 +1091,21 @@ CONFIG_CLKBLD_I8253=y # CONFIG_DCACHE_WORD_ACCESS=y # CONFIG_VALIDATE_FS_PARSER is not set +# CONFIG_EXT2_FS is not set +# CONFIG_EXT3_FS is not set +# CONFIG_EXT4_FS is not set +# CONFIG_REISERFS_FS is not set +# CONFIG_JFS_FS is not set +# CONFIG_XFS_FS is not set +# CONFIG_GFS2_FS is not set +# CONFIG_BTRFS_FS is not set +# CONFIG_NILFS2_FS is not set +# CONFIG_F2FS_FS is not set +# CONFIG_FS_DAX is not set +CONFIG_EXPORTFS=y # CONFIG_EXPORTFS_BLOCK_OPS is not set -# CONFIG_FILE_LOCKING is not set +CONFIG_FILE_LOCKING=y +# CONFIG_MANDATORY_FILE_LOCKING is not set # CONFIG_FS_ENCRYPTION is not set # CONFIG_FS_VERITY is not set # CONFIG_DNOTIFY is not set @@ -1047,13 +1123,34 @@ CONFIG_DCACHE_WORD_ACCESS=y # CONFIG_FSCACHE is not set # end of Caches +# +# CD-ROM/DVD Filesystems +# +# CONFIG_ISO9660_FS is not set +# CONFIG_UDF_FS is not set +# end of CD-ROM/DVD Filesystems + +# +# DOS/FAT/EXFAT/NT Filesystems +# +# CONFIG_MSDOS_FS is not set +# CONFIG_VFAT_FS is not set +# CONFIG_EXFAT_FS is not set +# CONFIG_NTFS_FS is not set +# end of DOS/FAT/EXFAT/NT Filesystems + # # Pseudo filesystems # -# CONFIG_PROC_FS is not set +CONFIG_PROC_FS=y +# CONFIG_PROC_KCORE is not set +CONFIG_PROC_SYSCTL=y +CONFIG_PROC_PAGE_MONITOR=y # CONFIG_PROC_CHILDREN is not set +CONFIG_PROC_PID_ARCH_STATUS=y CONFIG_KERNFS=y CONFIG_SYSFS=y +# CONFIG_TMPFS is not set # CONFIG_HUGETLBFS is not set CONFIG_ARCH_HAS_GIGANTIC_PAGE=y # CONFIG_CONFIGFS_FS is not set @@ -1062,6 +1159,7 @@ CONFIG_ARCH_HAS_GIGANTIC_PAGE=y # CONFIG_MISC_FILESYSTEMS is not set # CONFIG_NLS is not set # CONFIG_UNICODE is not set +CONFIG_IO_WQ=y # end of File systems # @@ -1069,12 +1167,12 @@ CONFIG_ARCH_HAS_GIGANTIC_PAGE=y # # CONFIG_KEYS is not set # CONFIG_SECURITY_DMESG_RESTRICT is not set +# CONFIG_SECURITY is not set # CONFIG_SECURITYFS is not set CONFIG_PAGE_TABLE_ISOLATION=y CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR=y CONFIG_HARDENED_USERCOPY=y CONFIG_HARDENED_USERCOPY_FALLBACK=y -# CONFIG_HARDENED_USERCOPY_PAGESPAN is not set CONFIG_FORTIFY_SOURCE=y # CONFIG_STATIC_USERMODEHELPER is not set CONFIG_DEFAULT_SECURITY_DAC=y @@ -1104,6 +1202,7 @@ CONFIG_INIT_STACK_NONE=y # Library routines # # CONFIG_PACKING is not set +CONFIG_BITREVERSE=y CONFIG_GENERIC_STRNCPY_FROM_USER=y CONFIG_GENERIC_STRNLEN_USER=y CONFIG_GENERIC_FIND_FIRST_BIT=y @@ -1118,7 +1217,12 @@ CONFIG_ARCH_USE_SYM_ANNOTATIONS=y # CONFIG_CRC16 is not set # CONFIG_CRC_T10DIF is not set # CONFIG_CRC_ITU_T is not set -# CONFIG_CRC32 is not set +CONFIG_CRC32=y +# CONFIG_CRC32_SELFTEST is not set +CONFIG_CRC32_SLICEBY8=y +# CONFIG_CRC32_SLICEBY4 is not set +# CONFIG_CRC32_SARWATE is not set +# CONFIG_CRC32_BIT is not set # CONFIG_CRC64 is not set # CONFIG_CRC4 is not set # CONFIG_CRC7 is not set @@ -1145,6 +1249,7 @@ CONFIG_FONT_AUTOSELECT=y CONFIG_ARCH_HAS_PMEM_API=y CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE=y CONFIG_ARCH_STACKWALK=y +CONFIG_SBITMAP=y # CONFIG_STRING_SELFTEST is not set # end of Library routines @@ -1160,7 +1265,8 @@ CONFIG_PRINTK_TIME=y CONFIG_CONSOLE_LOGLEVEL_DEFAULT=7 CONFIG_CONSOLE_LOGLEVEL_QUIET=4 CONFIG_MESSAGE_LOGLEVEL_DEFAULT=4 -# CONFIG_BOOT_PRINTK_DELAY is not set +# CONFIG_DYNAMIC_DEBUG is not set +# CONFIG_DYNAMIC_DEBUG_CORE is not set CONFIG_SYMBOLIC_ERRNAME=y CONFIG_DEBUG_BUGVERBOSE=y # end of printk and dmesg options @@ -1168,17 +1274,13 @@ CONFIG_DEBUG_BUGVERBOSE=y # # Compile-time checks and compiler options # -# CONFIG_DEBUG_INFO is not set CONFIG_ENABLE_MUST_CHECK=y CONFIG_FRAME_WARN=2048 -# CONFIG_STRIP_ASM_SYMS is not set -# CONFIG_READABLE_ASM is not set +CONFIG_STRIP_ASM_SYMS=y # CONFIG_HEADERS_INSTALL is not set # CONFIG_DEBUG_SECTION_MISMATCH is not set # CONFIG_SECTION_MISMATCH_WARN_ONLY is not set -# CONFIG_DEBUG_FORCE_FUNCTION_ALIGN_32B is not set CONFIG_STACK_VALIDATION=y -# CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set # end of Compile-time checks and compiler options # @@ -1187,38 +1289,30 @@ CONFIG_STACK_VALIDATION=y # CONFIG_MAGIC_SYSRQ is not set # CONFIG_DEBUG_FS is not set CONFIG_HAVE_ARCH_KGDB=y -# CONFIG_KGDB is not set CONFIG_ARCH_HAS_UBSAN_SANITIZE_ALL=y # CONFIG_UBSAN is not set +CONFIG_HAVE_ARCH_KCSAN=y +CONFIG_HAVE_KCSAN_COMPILER=y # end of Generic Kernel Debugging Instruments -CONFIG_DEBUG_KERNEL=y -# CONFIG_DEBUG_MISC is not set +# CONFIG_DEBUG_KERNEL is not set # # Memory Debugging # # CONFIG_PAGE_EXTENSION is not set -# CONFIG_DEBUG_PAGEALLOC is not set -# CONFIG_PAGE_OWNER is not set # CONFIG_PAGE_POISONING is not set # CONFIG_DEBUG_RODATA_TEST is not set CONFIG_ARCH_HAS_DEBUG_WX=y # CONFIG_DEBUG_WX is not set CONFIG_GENERIC_PTDUMP=y -# CONFIG_DEBUG_OBJECTS is not set +# CONFIG_SLUB_DEBUG_ON is not set # CONFIG_SLUB_STATS is not set CONFIG_HAVE_DEBUG_KMEMLEAK=y -# CONFIG_DEBUG_KMEMLEAK is not set -# CONFIG_DEBUG_STACK_USAGE is not set -# CONFIG_SCHED_STACK_END_CHECK is not set CONFIG_ARCH_HAS_DEBUG_VM_PGTABLE=y -# CONFIG_DEBUG_VM is not set # CONFIG_DEBUG_VM_PGTABLE is not set CONFIG_ARCH_HAS_DEBUG_VIRTUAL=y -# CONFIG_DEBUG_VIRTUAL is not set -# CONFIG_DEBUG_MEMORY_INIT is not set -# CONFIG_DEBUG_PER_CPU_MAPS is not set +CONFIG_DEBUG_MEMORY_INIT=y CONFIG_HAVE_ARCH_KASAN=y CONFIG_HAVE_ARCH_KASAN_VMALLOC=y CONFIG_CC_HAS_KASAN_GENERIC=y @@ -1227,19 +1321,13 @@ CONFIG_CC_HAS_WORKING_NOSANITIZE_ADDRESS=y # CONFIG_KASAN is not set # end of Memory Debugging -# CONFIG_DEBUG_SHIRQ is not set - # # Debug Oops, Lockups and Hangs # -# CONFIG_PANIC_ON_OOPS is not set -CONFIG_PANIC_ON_OOPS_VALUE=0 +CONFIG_PANIC_ON_OOPS=y +CONFIG_PANIC_ON_OOPS_VALUE=1 CONFIG_PANIC_TIMEOUT=-1 -# CONFIG_SOFTLOCKUP_DETECTOR is not set CONFIG_HARDLOCKUP_CHECK_TIMESTAMP=y -# CONFIG_HARDLOCKUP_DETECTOR is not set -# CONFIG_DETECT_HUNG_TASK is not set -# CONFIG_WQ_WATCHDOG is not set # CONFIG_TEST_LOCKUP is not set # end of Debug Oops, Lockups and Hangs @@ -1254,48 +1342,24 @@ CONFIG_HARDLOCKUP_CHECK_TIMESTAMP=y # Lock Debugging (spinlocks, mutexes, etc...) # CONFIG_LOCK_DEBUGGING_SUPPORT=y -# CONFIG_PROVE_LOCKING is not set -# CONFIG_LOCK_STAT is not set -# CONFIG_DEBUG_SPINLOCK is not set -# CONFIG_DEBUG_MUTEXES is not set -# CONFIG_DEBUG_WW_MUTEX_SLOWPATH is not set -# CONFIG_DEBUG_RWSEMS is not set -# CONFIG_DEBUG_LOCK_ALLOC is not set -# CONFIG_DEBUG_ATOMIC_SLEEP is not set -# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set -# CONFIG_LOCK_TORTURE_TEST is not set # CONFIG_WW_MUTEX_SELFTEST is not set # end of Lock Debugging (spinlocks, mutexes, etc...) # CONFIG_STACKTRACE is not set # CONFIG_WARN_ALL_UNSEEDED_RANDOM is not set -# CONFIG_DEBUG_KOBJECT is not set # # Debug kernel data structures # -# CONFIG_DEBUG_LIST is not set -# CONFIG_DEBUG_PLIST is not set -# CONFIG_DEBUG_SG is not set -# CONFIG_DEBUG_NOTIFIERS is not set # CONFIG_BUG_ON_DATA_CORRUPTION is not set # end of Debug kernel data structures -# CONFIG_DEBUG_CREDENTIALS is not set - # # RCU Debugging # -# CONFIG_RCU_PERF_TEST is not set -# CONFIG_RCU_TORTURE_TEST is not set -# CONFIG_RCU_REF_SCALE_TEST is not set CONFIG_RCU_CPU_STALL_TIMEOUT=21 -# CONFIG_RCU_TRACE is not set -# CONFIG_RCU_EQS_DEBUG is not set # end of RCU Debugging -# CONFIG_DEBUG_WQ_FORCE_RR_CPU is not set -# CONFIG_CPU_HOTPLUG_STATE_CONTROL is not set CONFIG_USER_STACKTRACE_SUPPORT=y CONFIG_HAVE_FUNCTION_TRACER=y CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y @@ -1309,7 +1373,6 @@ CONFIG_HAVE_C_RECORDMCOUNT=y CONFIG_TRACING_SUPPORT=y # CONFIG_FTRACE is not set # CONFIG_SAMPLES is not set -CONFIG_HAVE_ARCH_KCSAN=y CONFIG_ARCH_HAS_DEVMEM_IS_ALLOWED=y # CONFIG_STRICT_DEVMEM is not set @@ -1319,33 +1382,32 @@ CONFIG_ARCH_HAS_DEVMEM_IS_ALLOWED=y CONFIG_TRACE_IRQFLAGS_SUPPORT=y CONFIG_TRACE_IRQFLAGS_NMI_SUPPORT=y # CONFIG_X86_VERBOSE_BOOTUP is not set -# CONFIG_EARLY_PRINTK is not set -# CONFIG_DEBUG_TLBFLUSH is not set +CONFIG_EARLY_PRINTK=y CONFIG_HAVE_MMIOTRACE_SUPPORT=y -# CONFIG_X86_DECODER_SELFTEST is not set # CONFIG_IO_DELAY_0X80 is not set # CONFIG_IO_DELAY_0XED is not set # CONFIG_IO_DELAY_UDELAY is not set CONFIG_IO_DELAY_NONE=y -# CONFIG_CPA_DEBUG is not set -# CONFIG_DEBUG_ENTRY is not set -# CONFIG_DEBUG_NMI_SELFTEST is not set -# CONFIG_X86_DEBUG_FPU is not set CONFIG_UNWINDER_ORC=y # CONFIG_UNWINDER_FRAME_POINTER is not set -# CONFIG_UNWINDER_GUESS is not set # end of x86 Debugging # # Kernel Testing and Coverage # # CONFIG_KUNIT is not set -# CONFIG_NOTIFIER_ERROR_INJECTION is not set -# CONFIG_FAULT_INJECTION is not set CONFIG_ARCH_HAS_KCOV=y CONFIG_CC_HAS_SANCOV_TRACE_PC=y # CONFIG_KCOV is not set # CONFIG_RUNTIME_TESTING_MENU is not set # CONFIG_MEMTEST is not set # end of Kernel Testing and Coverage + +# +# Rust hacking +# +# CONFIG_RUST_DEBUG_ASSERTIONS is not set +# CONFIG_RUST_OVERFLOW_CHECKS is not set +CONFIG_RUST_CODEGEN_UNITS=1 +# end of Rust hacking # end of Kernel hacking diff --git a/.github/workflows/qemu-init.sh b/.github/workflows/qemu-init.sh index 804cd582e22e42..5d623426b2a165 100755 --- a/.github/workflows/qemu-init.sh +++ b/.github/workflows/qemu-init.sh @@ -1,8 +1,8 @@ #!/bin/sh -if [ -f rust_example.ko ]; then - busybox insmod rust_example.ko my_i32=123321 - busybox rmmod rust_example.ko -fi +busybox insmod rust_example_3.ko my_i32=345543 +busybox insmod rust_example_4.ko my_i32=456654 +busybox rmmod rust_example_3.ko +busybox rmmod rust_example_4.ko busybox reboot -f diff --git a/.github/workflows/qemu-initramfs.desc b/.github/workflows/qemu-initramfs.desc index 842bf37880b203..e15d926a1cd889 100644 --- a/.github/workflows/qemu-initramfs.desc +++ b/.github/workflows/qemu-initramfs.desc @@ -1,7 +1,8 @@ -dir /bin 0755 0 0 -dir /sys 0755 0 0 -dir /dev 0755 0 0 -file /bin/busybox /bin/busybox 0755 0 0 -slink /bin/sh /bin/busybox 0755 0 0 -file /init .github/workflows/qemu-init.sh 0755 0 0 -file /rust_example.ko drivers/char/rust_example/rust_example.ko 0755 0 0 +dir /bin 0755 0 0 +dir /sys 0755 0 0 +dir /dev 0755 0 0 +file /bin/busybox /bin/busybox 0755 0 0 +slink /bin/sh /bin/busybox 0755 0 0 +file /init .github/workflows/qemu-init.sh 0755 0 0 +file /rust_example_3.ko drivers/char/rust_example_3.ko 0755 0 0 +file /rust_example_4.ko drivers/char/rust_example_4.ko 0755 0 0 diff --git a/.gitignore b/.gitignore index c4e97ecdf7c700..41f449fec21577 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ *.o *.o.* *.patch +*.rlib *.s *.so *.so.dbg @@ -158,6 +159,3 @@ x509.genkey # Documentation toolchain sphinx_*/ - -# Rust (cargo) compilation artifacts -/target/ diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index 1238e5fbdc531f..00000000000000 --- a/Cargo.lock +++ /dev/null @@ -1,26 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "bitflags" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" - -[[package]] -name = "kernel" -version = "0.1.0" -dependencies = [ - "bitflags", - "module", -] - -[[package]] -name = "module" -version = "0.1.0" - -[[package]] -name = "rust_example" -version = "0.1.0" -dependencies = [ - "kernel", -] diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index e9a9b0f15d6293..00000000000000 --- a/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -# TODO: generate automatically -[workspace] -members = [ - "rust/module", - "rust/kernel", - "drivers/char/rust_example", -] - diff --git a/Documentation/rust/quick-start.rst b/Documentation/rust/quick-start.rst index 5444cb0a7cbd2e..6b73e156864a9c 100644 --- a/Documentation/rust/quick-start.rst +++ b/Documentation/rust/quick-start.rst @@ -3,97 +3,131 @@ Quick Start =========== -This document describes how to get started with Rust kernel development. +This document describes how to get started with kernel development in Rust. Requirements ------------ -rustc and cargo -*************** +This section explains how to fetch the requirements to work with Rust. +If you have worked previously with Rust, this will only take a moment. -A recent nightly Rust toolchain (with, at least, ``rustc`` and ``cargo``) -is required, e.g. ``nightly-2020-08-27``. In the future, this restriction -will be lifted. +Some of these requirements might be available from your Linux distribution +under names like ``rustc``, ``rust-src``, ``rust-bindgen``, etc. However, +at the time of writing, they are likely to not be recent enough. + + +rustc +***** + +A recent *nightly* Rust toolchain (with, at least, ``rustc``) is required, +e.g. ``nightly-2020-08-27``. Our goal is to use a stable toolchain as soon +as possible, but for the moment we depend on a handful of nightly features. If you are using ``rustup``, run:: rustup toolchain install nightly -Otherwise, fetch a standalone installer from: +Otherwise, fetch a standalone installer or install ``rustup`` from: https://www.rust-lang.org -rustc sources -************* +Rust standard library source +**************************** -The sources for the compiler are required to be available because the standard -library (``core`` and ``alloc``) is cross-compiled. +The Rust standard library source (``core`` and ``alloc``, at least) is required +because the build system will cross-compile it. If you are using ``rustup``, run:: rustup component add rust-src -Otherwise, if you used a standalone installer, you can clone the Rust compiler -sources and create a symlink to them in the installation folder of -your nightly toolchain:: +Otherwise, if you used a standalone installer, you can clone the Rust +repository into the installation folder of your nightly toolchain:: + + git clone https://github.com/rust-lang/rust `rustc --print sysroot`/lib/rustlib/src/rust + + +compiler-builtins source +************************ + +The source for ``compiler-builtins`` (a Rust port of LLVM's ``compiler-rt``) +is required. - git clone https://github.com/rust-lang/rust - ln -s rust .../rust-nightly/lib/rustlib/src +The build system expects the sources alongside the Rust ones we just installed, +so you can clone it into the installation folder of your nightly toolchain:: + + git clone https://github.com/rust-lang/compiler-builtins `rustc --print sysroot`/lib/rustlib/src/compiler-builtins bindgen ******* The bindings to the C side of the kernel are generated at build time using -``bindgen``. Currently we assume the latest version available, but that -may change in the future. +the ``bindgen`` tool. A recent version should work, e.g. ``0.57.0``. Install it via:: - cargo install bindgen + cargo install --locked --version 0.57.0 bindgen rustfmt ******* -Optionally, if you install ``rustfmt``, then you will get the generated -C bindings automatically formatted. It is also useful to have the tool -to format your own code, too. +Optionally, if you install the ``rustfmt`` tool, then the generated C bindings +will be automatically formatted. It is also useful to have the tool to format +your own code, too. -If you are using ``rustup``, its ``default`` profile already installs it, -so you should be good to go. If you are using another one, you can also -install the component:: +If you are using ``rustup``, its ``default`` profile already installs the tool, +so you should be good to go. If you are using another profile, you can install +the component manually:: rustup component add rustfmt The standalone installers also come with ``rustfmt``. -Testing a simple driver ------------------------ +Configuration +------------- + +``Rust support`` (``CONFIG_RUST``) needs to be enabled in the ``General setup`` +menu. The option is only shown if the build system can locate ``rustc``. +In turn, this will make visible the rest of options that depend on Rust. + +Afterwards, go to ``Character devices`` under ``Device Drivers`` and enable +the example Rust driver ``Rust example`` (``CONFIG_RUST_EXAMPLE``). -If the kernel configuration system is able to find ``rustc`` and ``cargo``, -it will enable Rust support (``CONFIG_HAS_RUST``). In turn, this will make -visible the rest of options that depend on Rust. -A simple driver you can compile to test things out is at -``drivers/char/rust_example`` (``CONFIG_RUST_EXAMPLE``). Enable it and compile -the kernel with: +Building +-------- + +Compile the kernel with:: make LLVM=1 -TODO: drop LLVM=1, allowing to mix GCC with LLVM +Hacking +------- + +If you want to dive deeper, take a look at the source code of the example +driver at ``drivers/char/rust_example.rs``, the Rust support code under +``rust/`` and the ``Rust hacking`` menu under ``Kernel hacking``. + +If you use GDB/Binutils and Rust symbols aren't getting demangled, the reason +is your toolchain doesn't support Rust's new v0 mangling scheme yet. There are +a few ways out: -Avoiding the network --------------------- + - If you don't mind building your own tools, we provide the following fork + with the support cherry-picked from GCC on top of very recent releases: -You can prefetch the dependencies that ``cargo`` will download by running:: + https://github.com/ojeda/binutils-gdb/releases/tag/gdb-10.1-release-rust + https://github.com/ojeda/binutils-gdb/releases/tag/binutils-2_35_1-rust - cargo fetch + - If you only need GDB and can enable ``CONFIG_DEBUG_INFO``, do so: + GDB will use the pre-demangled names embedded in the debug info. -in the kernel sources root. After this step, a network connection is -not needed anymore. + - If you don't need loadable module support, you may compile without + the ``-Z symbol-mangling-version=v0`` flag. However, we don't maintain + support for that, so avoid it unless you are in a hurry. diff --git a/Makefile b/Makefile index c76b3abfed0bf1..17150fad558dbb 100644 --- a/Makefile +++ b/Makefile @@ -86,11 +86,9 @@ endif ifeq ($(KBUILD_VERBOSE),1) quiet = Q = - CARGO_VERBOSE = --verbose else quiet=quiet_ Q = @ - CARGO_VERBOSE = # TODO: could be --quiet if needed endif # If the user is running make -s (silent mode), suppress echoing of @@ -447,7 +445,6 @@ READELF = $(CROSS_COMPILE)readelf STRIP = $(CROSS_COMPILE)strip endif RUSTC = rustc -CARGO = cargo BINDGEN = bindgen PAHOLE = pahole RESOLVE_BTFIDS = $(objtree)/tools/bpf/resolve_btfids/resolve_btfids @@ -474,12 +471,10 @@ CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ NOSTDINC_FLAGS := CFLAGS_MODULE = RUSTCFLAGS_MODULE = -CARGOFLAGS_MODULE = AFLAGS_MODULE = LDFLAGS_MODULE = CFLAGS_KERNEL = RUSTCFLAGS_KERNEL = -CARGOFLAGS_KERNEL = AFLAGS_KERNEL = LDFLAGS_vmlinux = @@ -507,24 +502,20 @@ KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \ -Werror=return-type -Wno-format-security \ -std=gnu89 KBUILD_CPPFLAGS := -D__KERNEL__ -KBUILD_RUSTCFLAGS := -# TODO: a simple way to update `Cargo.lock` when we add a new driver -KBUILD_CARGOFLAGS := $(CARGO_VERBOSE) --locked \ - -Z build-std=core,alloc -Z unstable-options \ - --target=$(srctree)/arch/$(SRCARCH)/rust/target.json +KBUILD_RUSTCFLAGS := --emit=dep-info,obj,link -Z binary_dep_depinfo=y \ + -C panic=abort -C embed-bitcode=n -C lto=n -C rpath=n \ + -C force-unwind-tables=n -Z symbol-mangling-version=v0 KBUILD_AFLAGS_KERNEL := KBUILD_CFLAGS_KERNEL := KBUILD_RUSTCFLAGS_KERNEL := -KBUILD_CARGOFLAGS_KERNEL := KBUILD_AFLAGS_MODULE := -DMODULE KBUILD_CFLAGS_MODULE := -DMODULE KBUILD_RUSTCFLAGS_MODULE := --cfg MODULE -KBUILD_CARGOFLAGS_MODULE := KBUILD_LDFLAGS_MODULE := KBUILD_LDFLAGS := CLANG_FLAGS := -export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC RUSTC CARGO BINDGEN +export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC RUSTC BINDGEN export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL export PERL PYTHON PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD @@ -533,10 +524,9 @@ export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE export KBUILD_RUSTCFLAGS RUSTCFLAGS_KERNEL RUSTCFLAGS_MODULE -export KBUILD_CARGOFLAGS CARGOFLAGS_KERNEL CARGOFLAGS_MODULE export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE -export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_RUSTCFLAGS_MODULE KBUILD_CARGOFLAGS_MODULE KBUILD_LDFLAGS_MODULE -export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL KBUILD_RUSTCFLAGS_KERNEL KBUILD_CARGOFLAGS_KERNEL +export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_RUSTCFLAGS_MODULE KBUILD_LDFLAGS_MODULE +export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL KBUILD_RUSTCFLAGS_KERNEL # Files to ignore in find ... statements @@ -752,23 +742,47 @@ KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation) KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow) KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) -# TODO: perhaps we could have some independent options for Rust only -KBUILD_CARGOFLAGS += --release +ifdef CONFIG_RUST_DEBUG_ASSERTIONS +KBUILD_RUSTCFLAGS += -C debug-assertions=y +else +KBUILD_RUSTCFLAGS += -C debug-assertions=n +endif + +ifdef CONFIG_RUST_OVERFLOW_CHECKS +KBUILD_RUSTCFLAGS += -C overflow-checks=y +else +KBUILD_RUSTCFLAGS += -C overflow-checks=n +endif ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE KBUILD_CFLAGS += -O2 -KBUILD_RUSTCFLAGS += # TODO: do we want -C opt-level=2 here? -KBUILD_CARGOFLAGS += +KBUILD_RUSTCFLAGS_OPT_LEVEL_MAP := 2 else ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3 KBUILD_CFLAGS += -O3 -KBUILD_RUSTCFLAGS += # flags already passed by cargo's --release -KBUILD_CARGOFLAGS += +KBUILD_RUSTCFLAGS_OPT_LEVEL_MAP := 3 else ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE KBUILD_CFLAGS += -Os +KBUILD_RUSTCFLAGS_OPT_LEVEL_MAP := z +endif + +ifdef CONFIG_RUST_OPT_LEVEL_SIMILAR_AS_CHOSEN_FOR_C +KBUILD_RUSTCFLAGS += -C opt-level=$(KBUILD_RUSTCFLAGS_OPT_LEVEL_MAP) +else ifdef CONFIG_RUST_OPT_LEVEL_0 +KBUILD_RUSTCFLAGS += -C opt-level=0 +else ifdef CONFIG_RUST_OPT_LEVEL_1 +KBUILD_RUSTCFLAGS += -C opt-level=1 +else ifdef CONFIG_RUST_OPT_LEVEL_2 +KBUILD_RUSTCFLAGS += -C opt-level=2 +else ifdef CONFIG_RUST_OPT_LEVEL_3 +KBUILD_RUSTCFLAGS += -C opt-level=3 +else ifdef CONFIG_RUST_OPT_LEVEL_S +KBUILD_RUSTCFLAGS += -C opt-level=s +else ifdef CONFIG_RUST_OPT_LEVEL_Z KBUILD_RUSTCFLAGS += -C opt-level=z -KBUILD_CARGOFLAGS += endif +KBUILD_RUSTCFLAGS += -C codegen-units=$(CONFIG_RUST_CODEGEN_UNITS) + # Tell gcc to never replace conditional load with a non-conditional one KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0) KBUILD_CFLAGS += $(call cc-option,-fno-allow-store-data-races) @@ -816,6 +830,7 @@ endif KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable) ifdef CONFIG_FRAME_POINTER KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls +KBUILD_RUSTCFLAGS += -C force-frame-pointers=y else # Some targets (ARM with Thumb2, for example), can't be built with frame # pointers. For those, we don't have FUNCTION_TRACER automatically @@ -848,9 +863,6 @@ DEBUG_CFLAGS := $(call cc-ifversion, -lt, 0500, $(call cc-option, -fno-var-track endif DEBUG_RUSTCFLAGS := -DEBUG_CARGOFLAGS := - -# TODO: see what we should set for rustc/cargo for debug ifdef CONFIG_DEBUG_INFO @@ -862,6 +874,11 @@ endif ifneq ($(LLVM_IAS),1) KBUILD_AFLAGS += -Wa,-gdwarf-2 +ifdef CONFIG_DEBUG_INFO_REDUCED +DEBUG_RUSTCFLAGS += -C debuginfo=1 +else +DEBUG_RUSTCFLAGS += -C debuginfo=2 +endif endif ifdef CONFIG_DEBUG_INFO_DWARF4 @@ -887,9 +904,6 @@ export DEBUG_CFLAGS KBUILD_RUSTCFLAGS += $(DEBUG_RUSTCFLAGS) export DEBUG_RUSTCFLAGS -KBUILD_CARGOFLAGS += $(DEBUG_CARGOFLAGS) -export DEBUG_CARGOFLAGS - ifdef CONFIG_FUNCTION_TRACER ifdef CONFIG_FTRACE_MCOUNT_RECORD # gcc 5 supports generating the mcount tables directly @@ -1008,12 +1022,11 @@ include $(addprefix $(srctree)/, $(include-y)) # Do not add $(call cc-option,...) below this line. When you build the kernel # from the clean source tree, the GCC plugins do not exist at this point. -# Add user supplied CPPFLAGS, AFLAGS, CFLAGS, RUSTCFLAGS and CARGOFLAGS as the last assignments +# Add user supplied CPPFLAGS, AFLAGS, CFLAGS and RUSTCFLAGS as the last assignments KBUILD_CPPFLAGS += $(KCPPFLAGS) KBUILD_AFLAGS += $(KAFLAGS) KBUILD_CFLAGS += $(KCFLAGS) KBUILD_RUSTCFLAGS += $(KRUSTCFLAGS) -KBUILD_CARGOFLAGS += $(KCARGOFLAGS) KBUILD_LDFLAGS_MODULE += --build-id=sha1 LDFLAGS_vmlinux += --build-id=sha1 @@ -1144,11 +1157,7 @@ export MODORDER := $(extmod-prefix)modules.order export MODULES_NSDEPS := $(extmod-prefix)modules.nsdeps ifeq ($(KBUILD_EXTMOD),) -core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ - -ifdef CONFIG_HAS_RUST -core-y += rust/ -endif +core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ rust/ vmlinux-dirs := $(patsubst %/,%,$(filter %/, \ $(core-y) $(core-m) $(drivers-y) $(drivers-m) \ @@ -1175,6 +1184,13 @@ else KBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y)) endif KBUILD_VMLINUX_OBJS += $(patsubst %/,%/built-in.a, $(drivers-y)) +ifdef CONFIG_RUST +KBUILD_VMLINUX_OBJS += \ + $(objtree)/rust/core.o \ + $(objtree)/rust/compiler_builtins.o \ + $(objtree)/rust/alloc.o \ + $(objtree)/rust/kernel.o +endif export KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds @@ -1250,6 +1266,7 @@ archprepare: outputmakefile archheaders archscripts scripts include/config/kerne prepare0: archprepare $(Q)$(MAKE) $(build)=scripts/mod $(Q)$(MAKE) $(build)=. + $(Q)$(MAKE) $(build)=rust # All the preparing.. prepare: prepare0 prepare-objtool prepare-resolve_btfids @@ -1535,17 +1552,13 @@ DISTCLEAN_FILES += tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS # clean: rm-files := $(CLEAN_FILES) -PHONY += archclean vmlinuxclean cargoclean +PHONY += archclean vmlinuxclean vmlinuxclean: $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean $(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean) -# TODO: clean particular subfolders via `Makefile.clean` -cargoclean: - $(Q)$(CARGO) clean - -clean: archclean vmlinuxclean cargoclean +clean: archclean vmlinuxclean # mrproper - Delete all generated files, including .config # @@ -1865,6 +1878,7 @@ clean: $(clean-dirs) $(call cmd,rmfiles) @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \ \( -name '*.[aios]' -o -name '*.ko' -o -name '.*.cmd' \ + -o -name '*.rlib' \ -o -name '*.ko.*' \ -o -name '*.dtb' -o -name '*.dtb.S' -o -name '*.dt.yaml' \ -o -name '*.dwo' -o -name '*.lst' \ diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index a975b045078272..ab6c55821f4e6a 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig @@ -472,7 +472,7 @@ config ADI driver include crash and makedumpfile. config RUST_EXAMPLE - depends on HAS_RUST + depends on RUST tristate "Rust Example" default n help @@ -483,6 +483,48 @@ config RUST_EXAMPLE If unsure, say N. +# XXX: Only for GitHub -- do not commit into mainline +config RUST_EXAMPLE_2 + depends on RUST + tristate "Rust Example 2" + default n + help + This option builds a second example module written in Rust. + It is intended to test several Rust modules at the same time. + + To compile this as a module, choose M here: + the module will be called rust_example_2. + + If unsure, say N. + +# XXX: Only for GitHub -- do not commit into mainline +config RUST_EXAMPLE_3 + depends on RUST + tristate "Rust Example 3" + default n + help + This option builds a third example module written in Rust. + It is intended to test several Rust modules at the same time. + + To compile this as a module, choose M here: + the module will be called rust_example_3. + + If unsure, say N. + +# XXX: Only for GitHub -- do not commit into mainline +config RUST_EXAMPLE_4 + depends on RUST + tristate "Rust Example 4" + default n + help + This option builds a fourth example module written in Rust. + It is intended to test several Rust modules at the same time. + + To compile this as a module, choose M here: + the module will be called rust_example_4. + + If unsure, say N. + endmenu config RANDOM_TRUST_CPU diff --git a/drivers/char/Makefile b/drivers/char/Makefile index b254119cb97df0..b51ec3a8345f54 100644 --- a/drivers/char/Makefile +++ b/drivers/char/Makefile @@ -48,4 +48,7 @@ obj-$(CONFIG_XILLYBUS) += xillybus/ obj-$(CONFIG_POWERNV_OP_PANEL) += powernv-op-panel.o obj-$(CONFIG_ADI) += adi.o -obj-$(CONFIG_RUST_EXAMPLE) += rust_example/ +obj-$(CONFIG_RUST_EXAMPLE) += rust_example.o +obj-$(CONFIG_RUST_EXAMPLE_2) += rust_example_2.o +obj-$(CONFIG_RUST_EXAMPLE_3) += rust_example_3.o +obj-$(CONFIG_RUST_EXAMPLE_4) += rust_example_4.o diff --git a/drivers/char/rust_example/src/lib.rs b/drivers/char/rust_example.rs similarity index 98% rename from drivers/char/rust_example/src/lib.rs rename to drivers/char/rust_example.rs index 2c15dd163ac5ac..0dbc5e7ef7beeb 100644 --- a/drivers/char/rust_example/src/lib.rs +++ b/drivers/char/rust_example.rs @@ -3,8 +3,6 @@ #![no_std] #![feature(global_asm)] -extern crate alloc; - use alloc::boxed::Box; use core::pin::Pin; use kernel::prelude::*; diff --git a/drivers/char/rust_example/Cargo.toml b/drivers/char/rust_example/Cargo.toml deleted file mode 100644 index 27232fd0634758..00000000000000 --- a/drivers/char/rust_example/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -# No need for details like `authors` here -- that goes in the modinfo -# via the `module!` macro -[package] -name = "rust_example" -version = "0.1.0" -edition = "2018" -publish = false - -[lib] -crate-type = ["staticlib"] - -[dependencies] -kernel = { path = "../../../rust/kernel" } - diff --git a/drivers/char/rust_example/Makefile b/drivers/char/rust_example/Makefile deleted file mode 100644 index f8847c8cad82c9..00000000000000 --- a/drivers/char/rust_example/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -obj-$(CONFIG_RUST_EXAMPLE) += rust_example.o diff --git a/drivers/char/rust_example_2.rs b/drivers/char/rust_example_2.rs new file mode 100644 index 00000000000000..d71272a1a1f201 --- /dev/null +++ b/drivers/char/rust_example_2.rs @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0 + +#![no_std] +#![feature(global_asm)] + +use kernel::prelude::*; + +module! { + type: RustExample2, + name: b"rust_example_2", + author: b"Rust for Linux Contributors", + description: b"An example kernel module written in Rust", + license: b"GPL v2", + params: { + my_bool: bool { + default: true, + permissions: 0, + description: b"Example of bool", + }, + my_i32: i32 { + default: 42, + permissions: 0o644, + description: b"Example of i32", + }, + }, +} + +struct RustExample2 { + message: String, +} + +impl KernelModule for RustExample2 { + fn init() -> KernelResult { + println!("[2] Rust Example (init)"); + println!("[2] Am I built-in? {}", !cfg!(MODULE)); + println!("[2] Parameters:"); + println!("[2] my_bool: {}", my_bool.read()); + println!("[2] my_i32: {}", my_i32.read()); + Ok(RustExample2 { + message: "on the heap!".to_owned(), + }) + } +} + +impl Drop for RustExample2 { + fn drop(&mut self) { + println!("[2] My message is {}", self.message); + println!("[2] Rust Example (exit)"); + } +} + +// XXX: Only for GitHub -- do not commit into mainline diff --git a/drivers/char/rust_example_3.rs b/drivers/char/rust_example_3.rs new file mode 100644 index 00000000000000..18bc1d541ee8ff --- /dev/null +++ b/drivers/char/rust_example_3.rs @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0 + +#![no_std] +#![feature(global_asm)] + +use kernel::prelude::*; + +module! { + type: RustExample3, + name: b"rust_example_3", + author: b"Rust for Linux Contributors", + description: b"An example kernel module written in Rust", + license: b"GPL v2", + params: { + my_bool: bool { + default: true, + permissions: 0, + description: b"Example of bool", + }, + my_i32: i32 { + default: 42, + permissions: 0o644, + description: b"Example of i32", + }, + }, +} + +struct RustExample3 { + message: String, +} + +impl KernelModule for RustExample3 { + fn init() -> KernelResult { + println!("[3] Rust Example (init)"); + println!("[3] Am I built-in? {}", !cfg!(MODULE)); + println!("[3] Parameters:"); + println!("[3] my_bool: {}", my_bool.read()); + println!("[3] my_i32: {}", my_i32.read()); + Ok(RustExample3 { + message: "on the heap!".to_owned(), + }) + } +} + +impl Drop for RustExample3 { + fn drop(&mut self) { + println!("[3] My message is {}", self.message); + println!("[3] Rust Example (exit)"); + } +} + +// XXX: Only for GitHub -- do not commit into mainline diff --git a/drivers/char/rust_example_4.rs b/drivers/char/rust_example_4.rs new file mode 100644 index 00000000000000..0c40d4b1e58ae7 --- /dev/null +++ b/drivers/char/rust_example_4.rs @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0 + +#![no_std] +#![feature(global_asm)] + +use kernel::prelude::*; + +module! { + type: RustExample4, + name: b"rust_example_4", + author: b"Rust for Linux Contributors", + description: b"An example kernel module written in Rust", + license: b"GPL v2", + params: { + my_bool: bool { + default: true, + permissions: 0, + description: b"Example of bool", + }, + my_i32: i32 { + default: 42, + permissions: 0o644, + description: b"Example of i32", + }, + }, +} + +struct RustExample4 { + message: String, +} + +impl KernelModule for RustExample4 { + fn init() -> KernelResult { + println!("[4] Rust Example (init)"); + println!("[4] Am I built-in? {}", !cfg!(MODULE)); + println!("[4] Parameters:"); + println!("[4] my_bool: {}", my_bool.read()); + println!("[4] my_i32: {}", my_i32.read()); + Ok(RustExample4 { + message: "on the heap!".to_owned(), + }) + } +} + +impl Drop for RustExample4 { + fn drop(&mut self) { + println!("[4] My message is {}", self.message); + println!("[4] Rust Example (exit)"); + } +} + +// XXX: Only for GitHub -- do not commit into mainline diff --git a/init/Kconfig b/init/Kconfig index c7bfc039415ba6..c778f9c1a0a730 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -52,18 +52,13 @@ config LLD_VERSION default $(shell,$(srctree)/scripts/lld-version.sh $(LD)) config HAS_RUST - def_bool $(success,$(RUSTC) --version && $(CARGO) --version) + def_bool $(success,$(RUSTC) --version) config RUSTC_VERSION depends on HAS_RUST int default $(shell,$(srctree)/scripts/rust-version.sh $(RUSTC)) -config CARGO_VERSION - depends on HAS_RUST - int - default $(shell,$(srctree)/scripts/rust-version.sh $(CARGO)) - config CC_CAN_LINK bool default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(m64-flag)) if 64BIT @@ -2039,6 +2034,24 @@ config PROFILING Say Y here to enable the extended profiling support mechanisms used by profilers such as OProfile. +config RUST + bool "Rust support" + depends on X86_64 + depends on HAS_RUST + default n + help + Enables Rust support in the kernel. + + This allows other Rust-related options, like drivers written in Rust, + to be selected. + + It is also required to be able to load external kernel modules + written in Rust. + + See Documentation/rust/ for more information. + + If unsure, say N. + # # Place an empty function call at each tracepoint site. Can be # dynamically changed for a probe function. diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index c789b39ed52717..e6603d4a79f0f0 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2446,6 +2446,119 @@ config HYPERV_TESTING endmenu # "Kernel Testing and Coverage" +menu "Rust hacking" + +config RUST_DEBUG_ASSERTIONS + bool "Debug assertions" + default n + depends on RUST + help + Enables rustc's `-C debug-assertions` codegen option. + + This flag lets you turn `cfg(debug_assertions)` conditional + compilation on or off. This can be used to enable extra debugging + code in development but not in production. For example, it controls + the behavior of the standard library's `debug_assert!` macro. + + If unsure, say N. + +config RUST_OVERFLOW_CHECKS + bool "Overflow checks" + default n + depends on RUST + help + Enables rustc's `-C overflow-checks` codegen option. + + This flag allows you to control the behavior of runtime integer + overflow. When overflow-checks are enabled, a panic will occur + on overflow. + + If unsure, say N. + +choice + prompt "Optimization level" + default RUST_OPT_LEVEL_SIMILAR_AS_CHOSEN_FOR_C + depends on RUST + help + Controls rustc's `-C opt-level` codegen option. + + This flag controls the optimization level. + + If unsure, say "Similar as chosen for C". + +config RUST_OPT_LEVEL_SIMILAR_AS_CHOSEN_FOR_C + bool "Similar as chosen for C" + help + This choice will pick a similar optimization level as chosen in + the "Compiler optimization level" for C: + + -O2 is currently mapped to -C opt-level=2 + -O3 is currently mapped to -C opt-level=3 + -Os is currently mapped to -C opt-level=z + + The mapping may change over time to follow the intended semantics + of the choice for C as sensibly as possible. + + This is the default. + +config RUST_OPT_LEVEL_0 + bool "No optimizations (-C opt-level=0)" + help + Not recommended for most purposes. It may come in handy for debugging + suspected optimizer bugs, unexpected undefined behavior, etc. + + Note that this level will *not* enable debug assertions nor overflow + checks on its own (like it happens when interacting with rustc + directly). Use the corresponding configuration options to control + that instead, orthogonally. + +config RUST_OPT_LEVEL_1 + bool "Basic optimizations (-C opt-level=1)" + help + Useful for debugging without getting too lost, but without + the overhead and boilerplate of no optimizations at all. + +config RUST_OPT_LEVEL_2 + bool "Some optimizations (-C opt-level=2)" + help + The sensible choice in most cases. + +config RUST_OPT_LEVEL_3 + bool "All optimizations (-C opt-level=3)" + help + Yet more performance (hopefully). + +config RUST_OPT_LEVEL_S + bool "Optimize for size (-C opt-level=s)" + help + Smaller kernel, ideally without too much performance loss. + +config RUST_OPT_LEVEL_Z + bool "Optimize for size, no loop vectorization (-C opt-level=z)" + help + Like the previous level, but also turn off loop vectorization. + +endchoice + +config RUST_CODEGEN_UNITS + int "Codegen units (1-256)" + range 1 256 + default "1" + depends on RUST + help + Controls rustc's `-C codegen-units` codegen option. + + This flag controls how many code generation units the crate is + split into. When a crate is split into multiple codegen units, + LLVM is able to process them in parallel. Increasing parallelism + may speed up compile times, but may also produce slower code. + Setting this to 1 may improve the performance of generated code, + but may be slower to compile. + + If unsure, say 1. + +endmenu # "Rust" + source "Documentation/Kconfig" endmenu # Kernel hacking diff --git a/rust/.gitignore b/rust/.gitignore new file mode 100644 index 00000000000000..22ac926518da5e --- /dev/null +++ b/rust/.gitignore @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +bindings_generated.rs diff --git a/rust/Makefile b/rust/Makefile index 02f2459083e4ec..db5c19a21a0404 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_HAS_RUST) = helpers.o - +obj-$(CONFIG_RUST) += helpers.o exports.o +extra-$(CONFIG_RUST) += libcore.rlib libcompiler_builtins.rlib liballoc.rlib +extra-$(CONFIG_RUST) += bindings_generated.rs libmodule.so libkernel.rlib diff --git a/rust/exports.c b/rust/exports.c new file mode 100644 index 00000000000000..7fa02d94e85c64 --- /dev/null +++ b/rust/exports.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// A hack to export Rust symbols for loadable modules without having to redo +// the entire `include/linux/export.h` logic. +// +// Note that this requires `-Z symbol-mangling-version=v0` because Rust's +// default ("legacy") mangling scheme 1) uses a hash suffix which cannot +// be predicted across compiler versions and 2) uses invalid characters +// for C identifiers (thus we cannot use the `EXPORT_SYMBOL_*` macros). +// +// For the moment, we update this list manually. In the future, we should +// have a way to handle this automatically. + +#include + +#define EXPORT_SYMBOL_RUST_GPL(sym) \ + extern int sym; \ + EXPORT_SYMBOL_GPL(sym); + +/* alloc::alloc::handle_alloc_error */ EXPORT_SYMBOL_RUST_GPL(_RNvNtCsbDqzXfLQacH_5alloc5alloc18handle_alloc_error); +/* ::fmt */ EXPORT_SYMBOL_RUST_GPL(_RNvXsb_NtCsbDqzXfLQacH_4core3fmtbNtB5_7Display3fmt); +/* ::fmt */ EXPORT_SYMBOL_RUST_GPL(_RNvXsD_NtCsbDqzXfLQacH_4core3fmtNtB5_5ErrorNtB5_5Debug3fmt); +/* core::fmt::write */ EXPORT_SYMBOL_RUST_GPL(_RNvNtCsbDqzXfLQacH_4core3fmt5write); +/* core::panicking::panic */ EXPORT_SYMBOL_RUST_GPL(_RNvNtCsbDqzXfLQacH_4core9panicking5panic); +/* core::result::unwrap_failed */ EXPORT_SYMBOL_RUST_GPL(_RNvNtCsbDqzXfLQacH_4core6result13unwrap_failed); +/* ::fmt */ EXPORT_SYMBOL_RUST_GPL(_RNvXs2_NtNtNtCsbDqzXfLQacH_4core3fmt3num3implNtB9_7Display3fmt); +/* ::to_kernel_errno */ EXPORT_SYMBOL_RUST_GPL(_RNvMNtCsbDqzXfLQacH_6kernel5errorNtB2_5Error15to_kernel_errno); +/* ::as_bytes */ EXPORT_SYMBOL_RUST_GPL(_RNvMNtCsbDqzXfLQacH_6kernel6printkNtB2_13LogLineWriter8as_bytes); +/* ::write_str */ EXPORT_SYMBOL_RUST_GPL(_RNvXs_NtCsbDqzXfLQacH_6kernel6printkNtB4_13LogLineWriterNtNtCsbDqzXfLQacH_4core3fmt5Write9write_str); +/* ::new */ EXPORT_SYMBOL_RUST_GPL(_RNvMNtCsbDqzXfLQacH_6kernel6printkNtB2_13LogLineWriter3new); +/* kernel::printk::printk */ EXPORT_SYMBOL_RUST_GPL(_RNvNtCsbDqzXfLQacH_6kernel6printk6printk); +/* __rust_alloc */ EXPORT_SYMBOL_RUST_GPL(__rust_alloc); +/* __rust_alloc_error_handler */ EXPORT_SYMBOL_RUST_GPL(__rust_alloc_error_handler); +/* __rust_alloc_zeroed */ EXPORT_SYMBOL_RUST_GPL(__rust_alloc_zeroed); +/* __rust_dealloc */ EXPORT_SYMBOL_RUST_GPL(__rust_dealloc); +/* __rust_realloc */ EXPORT_SYMBOL_RUST_GPL(__rust_realloc); +/* ::fmt */ EXPORT_SYMBOL_RUST_GPL(_RNvXsd_NtCsbDqzXfLQacH_4core3fmteNtB5_7Display3fmt); diff --git a/rust/kernel/Cargo.toml b/rust/kernel/Cargo.toml deleted file mode 100644 index bd116a6fc7db48..00000000000000 --- a/rust/kernel/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -[package] -name = "kernel" -version = "0.1.0" -authors = ["Rust for Linux Contributors"] -edition = "2018" -publish = false - -[dependencies] -bitflags = "1" -module = { path = "../module" } - diff --git a/rust/kernel/allocator.rs b/rust/kernel/allocator.rs new file mode 100644 index 00000000000000..383f85e8046e2c --- /dev/null +++ b/rust/kernel/allocator.rs @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0 + +use core::alloc::{GlobalAlloc, Layout}; +use core::ptr; + +use crate::bindings; +use crate::c_types; + +pub struct KernelAllocator; + +unsafe impl GlobalAlloc for KernelAllocator { + unsafe fn alloc(&self, layout: Layout) -> *mut u8 { + // krealloc is used instead of kmalloc because kmalloc is an inline function and can't be + // bound to as a result + bindings::krealloc(ptr::null(), layout.size(), bindings::GFP_KERNEL) as *mut u8 + } + + unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { + bindings::kfree(ptr as *const c_types::c_void); + } +} + +#[alloc_error_handler] +fn oom(_layout: Layout) -> ! { + panic!("Out of memory!"); +} + +// `rustc` only generates these for some crate types. Even then, we would need +// to extract the object file that has them from the archive. For the moment, +// let's generate them ourselves instead. +#[no_mangle] +pub fn __rust_alloc(size: usize, _align: usize) -> *mut u8 { + unsafe { bindings::krealloc(core::ptr::null(), size, bindings::GFP_KERNEL) as *mut u8 } +} + +#[no_mangle] +pub fn __rust_dealloc(ptr: *mut u8, _size: usize, _align: usize) { + unsafe { bindings::kfree(ptr as *const c_types::c_void) }; +} + +#[no_mangle] +pub fn __rust_realloc(ptr: *mut u8, _old_size: usize, _align: usize, new_size: usize) -> *mut u8 { + unsafe { bindings::krealloc(ptr as *const c_types::c_void, new_size, bindings::GFP_KERNEL) as *mut u8 } +} + +#[no_mangle] +pub fn __rust_alloc_zeroed(size: usize, _align: usize) -> *mut u8 { + unsafe { bindings::krealloc(core::ptr::null(), size, bindings::GFP_KERNEL | bindings::__GFP_ZERO) as *mut u8 } +} + +#[no_mangle] +pub fn __rust_alloc_error_handler(_size: usize, _align: usize) -> ! { + panic!("Out of memory!"); +} diff --git a/rust/kernel/src/bindings.rs b/rust/kernel/bindings.rs similarity index 86% rename from rust/kernel/src/bindings.rs rename to rust/kernel/bindings.rs index f0c31a36dc7600..0d46abfd6f23d1 100644 --- a/rust/kernel/src/bindings.rs +++ b/rust/kernel/bindings.rs @@ -14,3 +14,4 @@ mod bindings_raw { pub use bindings_raw::*; pub const GFP_KERNEL: gfp_t = BINDINGS_GFP_KERNEL; +pub const __GFP_ZERO: gfp_t = BINDINGS___GFP_ZERO; diff --git a/rust/kernel/src/bindings_helper.h b/rust/kernel/bindings_helper.h similarity index 88% rename from rust/kernel/src/bindings_helper.h rename to rust/kernel/bindings_helper.h index b4cdf67602acdc..3c2063484e003d 100644 --- a/rust/kernel/src/bindings_helper.h +++ b/rust/kernel/bindings_helper.h @@ -12,3 +12,4 @@ // bindgen gets confused at certain things const gfp_t BINDINGS_GFP_KERNEL = GFP_KERNEL; +const gfp_t BINDINGS___GFP_ZERO = __GFP_ZERO; diff --git a/rust/kernel/src/c_types.rs b/rust/kernel/c_types.rs similarity index 100% rename from rust/kernel/src/c_types.rs rename to rust/kernel/c_types.rs diff --git a/rust/kernel/src/chrdev.rs b/rust/kernel/chrdev.rs similarity index 100% rename from rust/kernel/src/chrdev.rs rename to rust/kernel/chrdev.rs diff --git a/rust/kernel/src/error.rs b/rust/kernel/error.rs similarity index 100% rename from rust/kernel/src/error.rs rename to rust/kernel/error.rs diff --git a/rust/kernel/src/file_operations.rs b/rust/kernel/file_operations.rs similarity index 97% rename from rust/kernel/src/file_operations.rs rename to rust/kernel/file_operations.rs index 5a3c1dfe7aef64..c67c2ef9c53a58 100644 --- a/rust/kernel/src/file_operations.rs +++ b/rust/kernel/file_operations.rs @@ -11,12 +11,6 @@ use crate::c_types; use crate::error::{Error, KernelResult}; use crate::user_ptr::{UserSlicePtr, UserSlicePtrReader, UserSlicePtrWriter}; -bitflags::bitflags! { - pub struct FileFlags: c_types::c_uint { - const NONBLOCK = bindings::O_NONBLOCK; - } -} - pub struct File { ptr: *const bindings::file, } @@ -29,10 +23,6 @@ impl File { pub fn pos(&self) -> u64 { unsafe { (*self.ptr).f_pos as u64 } } - - pub fn flags(&self) -> FileFlags { - FileFlags::from_bits_truncate(unsafe { (*self.ptr).f_flags }) - } } // Matches std::io::SeekFrom in the Rust stdlib diff --git a/rust/kernel/src/lib.rs b/rust/kernel/lib.rs similarity index 98% rename from rust/kernel/src/lib.rs rename to rust/kernel/lib.rs index 6b2c46c532871b..681a87054fa61c 100644 --- a/rust/kernel/src/lib.rs +++ b/rust/kernel/lib.rs @@ -7,11 +7,9 @@ // Ensure conditional compilation based on the kernel configuration works; // otherwise we may silently break things like initcall handling. -#[cfg(not(CONFIG_HAS_RUST))] +#[cfg(not(CONFIG_RUST))] compile_error!("Missing kernel configuration for conditional compilation"); -extern crate alloc; - use alloc::boxed::Box; use core::alloc::Layout; use core::mem::MaybeUninit; diff --git a/rust/kernel/src/miscdev.rs b/rust/kernel/miscdev.rs similarity index 100% rename from rust/kernel/src/miscdev.rs rename to rust/kernel/miscdev.rs diff --git a/rust/kernel/src/prelude.rs b/rust/kernel/prelude.rs similarity index 76% rename from rust/kernel/src/prelude.rs rename to rust/kernel/prelude.rs index 36d9e2104f681a..a23a54858e38ee 100644 --- a/rust/kernel/src/prelude.rs +++ b/rust/kernel/prelude.rs @@ -2,6 +2,9 @@ //! The `kernel` prelude +/// ICE if we use `--extern module` +extern crate module; + pub use alloc::{borrow::ToOwned, string::String}; pub use module::module; diff --git a/rust/kernel/src/printk.rs b/rust/kernel/printk.rs similarity index 100% rename from rust/kernel/src/printk.rs rename to rust/kernel/printk.rs diff --git a/rust/kernel/src/random.rs b/rust/kernel/random.rs similarity index 100% rename from rust/kernel/src/random.rs rename to rust/kernel/random.rs diff --git a/rust/kernel/src/allocator.rs b/rust/kernel/src/allocator.rs deleted file mode 100644 index 27647be92b5134..00000000000000 --- a/rust/kernel/src/allocator.rs +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 - -use core::alloc::{GlobalAlloc, Layout}; -use core::ptr; - -use crate::bindings; -use crate::c_types; - -pub struct KernelAllocator; - -unsafe impl GlobalAlloc for KernelAllocator { - unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - // krealloc is used instead of kmalloc because kmalloc is an inline function and can't be - // bound to as a result - bindings::krealloc(ptr::null(), layout.size(), bindings::GFP_KERNEL) as *mut u8 - } - - unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { - bindings::kfree(ptr as *const c_types::c_void); - } -} - -#[alloc_error_handler] -fn oom(_layout: Layout) -> ! { - panic!("Out of memory!"); -} diff --git a/rust/kernel/src/sysctl.rs b/rust/kernel/sysctl.rs similarity index 100% rename from rust/kernel/src/sysctl.rs rename to rust/kernel/sysctl.rs diff --git a/rust/kernel/src/types.rs b/rust/kernel/types.rs similarity index 100% rename from rust/kernel/src/types.rs rename to rust/kernel/types.rs diff --git a/rust/kernel/src/user_ptr.rs b/rust/kernel/user_ptr.rs similarity index 100% rename from rust/kernel/src/user_ptr.rs rename to rust/kernel/user_ptr.rs diff --git a/rust/module/src/lib.rs b/rust/module.rs similarity index 99% rename from rust/module/src/lib.rs rename to rust/module.rs index b8bdbc9eb847c3..051a58bac8da65 100644 --- a/rust/module/src/lib.rs +++ b/rust/module.rs @@ -2,8 +2,6 @@ //! Implements the `module!` macro magic -extern crate proc_macro; - use proc_macro::{token_stream, Delimiter, Group, TokenStream, TokenTree}; fn expect_ident(it: &mut token_stream::IntoIter) -> String { diff --git a/rust/module/Cargo.toml b/rust/module/Cargo.toml deleted file mode 100644 index c61e6d2c192cb3..00000000000000 --- a/rust/module/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -[package] -name = "module" -version = "0.1.0" -authors = ["Rust for Linux Contributors"] -edition = "2018" -publish = false - -[lib] -proc-macro = true - diff --git a/scripts/Makefile.build b/scripts/Makefile.build index dccbbe97257971..97fabc1f85f30e 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -23,14 +23,11 @@ subdir-y := subdir-m := EXTRA_AFLAGS := EXTRA_CFLAGS := -EXTRA_RUSTCFLAGS := -EXTRA_CARGOFLAGS := EXTRA_CPPFLAGS := EXTRA_LDFLAGS := asflags-y := ccflags-y := rustcflags-y := -cargoflags-y := cppflags-y := ldflags-y := @@ -299,30 +296,124 @@ quiet_cmd_cc_lst_c = MKLST $@ $(obj)/%.lst: $(src)/%.c FORCE $(call if_changed_dep,cc_lst_c) -# Compile Rust sources (.rs) via cargo +# Compile Rust sources (.rs) # --------------------------------------------------------------------------- -quiet_cmd_cargo = CARGO $(quiet_modtag) $@ - cmd_cargo = export RUST_BINDINGS_FILE=$(shell readlink -f include/generated/rust_bindings.rs) && $(CARGO) build --manifest-path $(srctree)/$(src)/Cargo.toml --out-dir $(src) $(cargo_flags) - -include/generated/rust_bindings.rs: FORCE - $(Q)$(BINDGEN) $(srctree)/rust/kernel/src/bindings_helper.h \ +quiet_cmd_bindgen_bindings = BINDGEN $(quiet_modtag) $@ + cmd_bindgen_bindings = \ + $(BINDGEN) $< \ --opaque-type xregs_state \ --opaque-type desc_struct \ --use-core \ --with-derive-default \ --ctypes-prefix c_types \ --size_t-is-usize \ - -o include/generated/rust_bindings.rs \ + -o $@ \ -- $(c_flags) -# The .o from the Rust staticlib -$(obj)/%.o: $(src)/lib%.a - $(Q)$(LD) -r -o $@ --whole-archive $< - -# The Rust staticlib from cargo -$(obj)/lib%.a: include/generated/rust_bindings.rs FORCE - $(call cmd,cargo) +$(objtree)/rust/bindings_generated.rs: $(srctree)/rust/kernel/bindings_helper.h FORCE + $(call if_changed_dep,bindgen_bindings) + +rustc_sysroot := $(shell $(RUSTC) --print sysroot) +rustc_src := $(rustc_sysroot)/lib/rustlib/src/rust +compiler_builtins_src := $(rustc_sysroot)/lib/rustlib/src/compiler-builtins +rustc_cross_flags := --target=$(srctree)/arch/$(SRCARCH)/rust/target.json + +quiet_cmd_rustc_libmodule = RUSTC $(quiet_modtag) $@ + cmd_rustc_libmodule = \ + $(RUSTC) $(rustc_flags) \ + --out-dir $(objtree)/rust/ \ + --edition=2018 \ + --crate-type=proc-macro \ + --crate-name module \ + $< \ + --extern proc_macro; \ + mv $(objtree)/rust/module.d $(depfile) + +$(objtree)/rust/libmodule.so: $(srctree)/rust/module.rs FORCE + $(call if_changed_dep,rustc_libmodule) + +quiet_cmd_rustc_libcore = RUSTC $(quiet_modtag) $@ + cmd_rustc_libcore = \ + $(RUSTC) $(rustc_flags) $(rustc_cross_flags) \ + --out-dir $(objtree)/rust/ \ + --edition=2018 \ + --crate-type=rlib \ + --crate-name core \ + $<; \ + mv $(objtree)/rust/core.d $(depfile) + +$(objtree)/rust/libcore.rlib: $(rustc_src)/library/core/src/lib.rs FORCE + $(call if_changed_dep,rustc_libcore) + +quiet_cmd_rustc_libcompiler_builtins = RUSTC $(quiet_modtag) $@ + cmd_rustc_libcompiler_builtins = \ + $(RUSTC) $(rustc_flags) $(rustc_cross_flags) \ + --out-dir $(objtree)/rust/ \ + --edition=2015 \ + --crate-type=rlib \ + --crate-name compiler_builtins \ + $< \ + -L $(objtree)/rust/ \ + --cfg 'feature="compiler-builtins"' \ + --cfg 'feature="default"'; \ + mv $(objtree)/rust/compiler_builtins.d $(depfile) + +$(objtree)/rust/libcompiler_builtins.rlib: $(compiler_builtins_src)/src/lib.rs \ + $(objtree)/rust/libcore.rlib FORCE + $(call if_changed_dep,rustc_libcompiler_builtins) + +quiet_cmd_rustc_liballoc = RUSTC $(quiet_modtag) $@ + cmd_rustc_liballoc = \ + $(RUSTC) $(rustc_flags) $(rustc_cross_flags) \ + --out-dir $(objtree)/rust/ \ + --edition=2018 \ + --crate-type=rlib \ + --crate-name alloc \ + $< \ + -L $(objtree)/rust/; \ + mv $(objtree)/rust/alloc.d $(depfile) + +$(objtree)/rust/liballoc.rlib: $(rustc_src)/library/alloc/src/lib.rs \ + $(objtree)/rust/libcompiler_builtins.rlib FORCE + $(call if_changed_dep,rustc_liballoc) + +quiet_cmd_rustc_libkernel = RUSTC $(quiet_modtag) $@ + cmd_rustc_libkernel = \ + RUST_BINDINGS_FILE=$(abspath $(objtree)/rust/bindings_generated.rs) \ + $(RUSTC) $(rustc_flags) $(rustc_cross_flags) \ + --out-dir $(objtree)/rust/ \ + --edition=2018 \ + --crate-type=rlib \ + --crate-name kernel \ + $< \ + -L $(objtree)/rust/ \ + --extern alloc; \ + mv $(objtree)/rust/kernel.d $(depfile); \ + sed -i '/^\#/d' $(depfile) + +$(objtree)/rust/libkernel.rlib: $(srctree)/rust/kernel/lib.rs \ + $(objtree)/rust/liballoc.rlib \ + $(objtree)/rust/libmodule.so \ + $(objtree)/rust/bindings_generated.rs FORCE + $(call if_changed_dep,rustc_libkernel) + +quiet_cmd_rustc_o_rs = RUSTC $(quiet_modtag) $@ + cmd_rustc_o_rs = \ + RUST_MODFILE=$(modfile) \ + $(RUSTC) $(rustc_flags) $(rustc_cross_flags) \ + --out-dir $(obj) \ + --edition=2018 \ + --crate-type=rlib \ + --crate-name $(subst .o,,$(notdir $@)) \ + $< \ + -L $(objtree)/rust/ \ + --extern alloc \ + --extern kernel; \ + mv $(obj)/$(subst .o,,$(notdir $@)).d $(depfile) + +$(obj)/%.o: $(src)/%.rs FORCE + $(call if_changed_dep,rustc_o_rs) # Compile assembler sources (.S) # --------------------------------------------------------------------------- diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 7a72565d1174f3..9c45bf628a4619 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -21,7 +21,6 @@ endif KBUILD_AFLAGS += $(subdir-asflags-y) KBUILD_CFLAGS += $(subdir-ccflags-y) KBUILD_RUSTCFLAGS += $(subdir-rustcflags-y) -KBUILD_CARGOFLAGS += $(subdir-cargoflags-y) # Figure out what we need to build from the various variables # =========================================================================== @@ -132,10 +131,6 @@ _rustc_flags = $(filter-out $(RUSTCFLAGS_REMOVE_$(target-stem).o), \ $(filter-out $(rustcflags-remove-y), \ $(KBUILD_RUSTCFLAGS) $(rustcflags-y)) \ $(RUSTCFLAGS_$(target-stem).o)) -_cargo_flags = $(filter-out $(CARGOFLAGS_REMOVE_$(target-stem).o), \ - $(filter-out $(cargoflags-remove-y), \ - $(KBUILD_CARGOFLAGS) $(cargoflags-y)) \ - $(CARGOFLAGS_$(target-stem).o)) _a_flags = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), \ $(filter-out $(asflags-remove-y), \ $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(asflags-y)) \ @@ -209,11 +204,6 @@ modkern_rustcflags = \ $(KBUILD_RUSTCFLAGS_MODULE) $(RUSTCFLAGS_MODULE), \ $(KBUILD_RUSTCFLAGS_KERNEL) $(RUSTCFLAGS_KERNEL)) -modkern_cargoflags = \ - $(if $(part-of-module), \ - $(KBUILD_CARGOFLAGS_MODULE) $(CARGOFLAGS_MODULE), \ - $(KBUILD_CARGOFLAGS_KERNEL) $(CARGOFLAGS_KERNEL)) - modkern_aflags = $(if $(part-of-module), \ $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE), \ $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL)) @@ -223,26 +213,7 @@ c_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ $(_c_flags) $(modkern_cflags) \ $(basename_flags) $(modname_flags) -# Needed for the Rust bindings -# TODO: we unconditionally pass `KBUILD_CFLAGS_MODULE` to avoid having -# dual bindings, but ideally we should generate two set of bindings -RUST_BINDGEN_CFLAGS = $(c_flags) $(KBUILD_CFLAGS_MODULE) -export RUST_BINDGEN_CFLAGS - -KCONFIG_RUSTC_CFG ?= ./include/generated/rustc_cfg - -rustc_flags = $(_rustc_flags) $(modkern_rustcflags) @$(shell readlink -f $(KCONFIG_RUSTC_CFG)) - -# Passed by cargo -RUSTFLAGS = $(rustc_flags) -export RUSTFLAGS - -# For the `module!` macro -# TODO: should be `$(modfile)`, but it is not correct for us -RUST_MODFILE = $(obj)/$(notdir $(obj)) -export RUST_MODFILE - -cargo_flags = $(_cargo_flags) $(modkern_cargoflags) +rustc_flags = $(_rustc_flags) $(modkern_rustcflags) @$(objtree)/include/generated/rustc_cfg a_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ $(_a_flags) $(modkern_aflags) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 0494111d2d98e4..cd0145e7c9da54 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -1155,9 +1155,7 @@ int conf_write_autoconf(int overwrite) if (rename(".tmpconfig", autoconf_name)) return 1; - name = getenv("KCONFIG_RUSTC_CFG"); - if (!name) - name = "include/generated/rustc_cfg"; + name = "include/generated/rustc_cfg"; if (make_parent_dir(name)) return 1; if (rename(".tmp_rustc_cfg", name))