Re: [PATCH 0/3] Rust 1.68.2 upgrade

From: Ariel Miculas
Date: Thu Apr 20 2023 - 13:18:29 EST


Yes, I've edited the commands since I've run them out of order, let me
include the output of commands and my general setup.
Since I've already run these steps previously, most of the commands
just say that it's already configured.

❯ rustup override set $(scripts/min-tool-version.sh rustc)
info: using existing install for '1.68.2-x86_64-unknown-linux-gnu'
info: override toolchain for '/home/amiculas/work/linux' set to
'1.68.2-x86_64-unknown-linux-gnu'

1.68.2-x86_64-unknown-linux-gnu unchanged - rustc 1.68.2 (9eb3afe9e
2023-03-27)

❯ rustup override list
/home/amiculas/work/linux 1.68.2-x86_64-unknown-linux-gnu

❯ rustup component add rust-src
info: component 'rust-src' is up to date

❯ cargo install --locked --version $(scripts/min-tool-version.sh
bindgen) bindgen
Ignored package `bindgen v0.56.0` is already installed, use
--force to override

❯ make LLVM=1 rustavailable
Rust is available!

❮ rg -i '[^a-zA-Z]rust' .config
14:CONFIG_RUST_IS_AVAILABLE=y
279:CONFIG_RUST=y
280:CONFIG_RUSTC_VERSION_TEXT="rustc 1.68.2 (9eb3afe9e 2023-03-27)"
687:CONFIG_HAVE_RUST=y
5093:CONFIG_SAMPLES_RUST=y
5094:CONFIG_SAMPLE_RUST_MINIMAL=m
5095:CONFIG_SAMPLE_RUST_PRINT=m
5096:CONFIG_SAMPLE_RUST_HOSTPROGS=y
5185:# Rust hacking
5187:# CONFIG_RUST_DEBUG_ASSERTIONS is not set
5188:CONFIG_RUST_OVERFLOW_CHECKS=y
5189:# CONFIG_RUST_BUILD_ASSERT_ALLOW is not set
5190:# end of Rust hacking

❯ make LLVM=1 -j$(nproc)
DESCEND objtool
CALL scripts/checksyscalls.sh
make[3]: 'install_headers' is up to date.
grep: warning: stray \ before #
grep: warning: stray \ before #
Kernel: arch/x86/boot/bzImage is ready (#29)

# I have some commits on top of the patchset, but they are only for
setting up the kernel environment (an initramfs with busybox, running
inside qemu)
❯ git log --oneline
03cad1754b24 (HEAD -> ariel-rust) Add lwnfs.ko kernel module to initramfs
233183beae92 Insert rust_fs.ko module and mount a rustfs to /mnt
a1de6ad1ec15 Add other rust samples to initramfs
192ab4a5dd58 Mount /dev, /proc and insert the parrot.ko module
05d7232d50cf enable kvm
c2724fa122af Add scripts for running the kernel in qemu
3f81af042dd2 (rust-next) rust: upgrade to Rust 1.68.2
418e1087dce1 rust: arc: fix intra-doc link in `Arc<T>::init`
ee16705fb79f rust: alloc: clarify what is the upstream version
1944caa8e8dc (rust-for-linux/rust-next) rust: sync: add functions for
initializing `UniqueArc<MaybeUninit<T>>`
701608bd030a rust: sync: reduce stack usage of `UniqueArc::try_new_uninit`
692e8935e23e rust: types: add `Opaque::ffi_init`

❯ git --no-pager diff
diff --git a/samples/rust/rust_minimal.rs b/samples/rust/rust_minimal.rs
index dc05f4bbe27e..1ca75c85f161 100644
--- a/samples/rust/rust_minimal.rs
+++ b/samples/rust/rust_minimal.rs
@@ -19,6 +19,7 @@ struct RustMinimal {
impl kernel::Module for RustMinimal {
fn init(_module: &'static ThisModule) -> Result<Self> {
pr_info!("Rust minimal sample (init)\n");
+ pr_info!("Ariel was here");
pr_info!("Am I built-in? {}\n", !cfg!(MODULE));

let mut numbers = Vec::new();

❯ cd linux-environment
❯ ls
busybox Makefile qemu-initramfs.desc qemu-initramfs.img
qemu-init.sh run_qemu.sh

❯ file busybox
busybox: ELF 64-bit LSB executable, x86-64, version 1 (SYSV),
statically linked, stripped

❯ /usr/bin/cat Makefile
.PHONY: all clean

all: qemu-initramfs.img

qemu-initramfs.img:
../usr/gen_init_cpio qemu-initramfs.desc > qemu-initramfs.img

clean:
rm qemu-initramfs.img

run: qemu-initramfs.img
sudo ./run_qemu.sh

❯ /usr/bin/cat qemu-init.sh
#!/bin/sh

busybox mount -t devtmpfs none /dev
busybox mount -t proc none /proc
busybox mount -t sysfs none /sys

busybox insmod rust_minimal.ko
busybox rmmod rust_minimal.ko
busybox setsid sh -c 'exec sh -l </dev/ttyS0 >/dev/ttyS0 2>&1'

❯ /usr/bin/cat qemu-initramfs.desc
dir /bin 0755 0 0
dir /sys 0755 0 0
dir /dev 0755 0 0
dir /proc 0755 0 0
file /bin/busybox busybox 0755 0 0
slink /bin/sh /bin/busybox 0755 0 0
file /init qemu-init.sh 0755 0 0

file /rust_minimal.ko ../samples/rust/rust_minimal.ko
0755 0 0
file /rust_print.ko ../samples/rust/rust_print.ko
0755 0 0

❯ make
../usr/gen_init_cpio qemu-initramfs.desc > qemu-initramfs.img

❯ /usr/bin/cat run_qemu.sh
sudo qemu-system-x86_64 \
-kernel ../arch/x86/boot/bzImage \
-initrd qemu-initramfs.img \
-M pc \
-m 4G \
-accel kvm \
-cpu host \
-smp $(nproc) \
-nographic \
-vga none \
-no-reboot \
-append 'console=ttyS0'

❯ ./run_qemu.sh
[sudo] password for amiculas:
SeaBIOS (version Arch Linux 1.16.2-1-1)


iPXE (http://ipxe.org) 00:02.0 C000 PCI2.10 PnP PMM+BEFD31B0+BEF331B0 C000



Booting from ROM..
[ 0.000000] Linux version 6.3.0-rc6-00039-g03cad1754b24-dirty
(amiculas@archlinux-cisco) (clang version 15.0.7, LLD 15.0.7) #29 SMP
PREEMPT_DYNAMIC Thu Apr 20 15:54:18 EEST 2023
[ 0.000000] Command line: console=ttyS0
...
[ 0.802414] Run /init as init process
[ 0.803185] busybox (89) used greatest stack depth: 13848 bytes left
[ 0.805450] rust_minimal: Rust minimal sample (init)
[ 0.805736] rust_minimal: Ariel was here
[ 0.805737] rust_minimal: Am I built-in? false
[ 0.806304] busybox (92) used greatest stack depth: 13696 bytes left
[ 0.806591] rust_minimal: My numbers are [72, 108, 200]
[ 0.807021] rust_minimal: Rust minimal sample (exit)

Cheers,
Ariel

On Thu, Apr 20, 2023 at 4:20 PM Miguel Ojeda
<miguel.ojeda.sandonis@xxxxxxxxx> wrote:
>
> On Thu, Apr 20, 2023 at 3:13 PM Ariel Miculas <ariel.miculas@xxxxxxxxx> wrote:
> >
> > $ make LLVM=1 rustavailable
>
> Since you showed the output of the other commands, did this one show
> "Rust is available!"? I guess so -- I imagine you edited the commands
> for the email, e.g. the config changed too.
>
> That is fine, as long as it works as expected :) Thanks a lot for testing!
>
> Cheers,
> Miguel