[0/3] Rust 1.68.2 upgrade

Message ID 20230418214347.324156-1-ojeda@kernel.org
Headers
Series Rust 1.68.2 upgrade |

Message

Miguel Ojeda April 18, 2023, 9:43 p.m. UTC
  This is the first upgrade to the Rust toolchain since the initial Rust
merge, from 1.62.0 to 1.68.2 (i.e. the latest).

Please see the last patch message for a long explanation of the upgrade,
the policy for future upgrades and some indications on how to easily
review this.

The series is based on `rust-next`.

Miguel Ojeda (3):
  rust: alloc: clarify what is the upstream version
  rust: arc: fix intra-doc link in `Arc<T>::init`
  rust: upgrade to Rust 1.68.2

 Documentation/process/changes.rst |   2 +-
 rust/alloc/README.md              |   3 +
 rust/alloc/alloc.rs               |  55 ++--
 rust/alloc/boxed.rs               | 446 ++++++++++++++++++++++++++--
 rust/alloc/collections/mod.rs     |   5 +-
 rust/alloc/lib.rs                 |  71 +++--
 rust/alloc/raw_vec.rs             |  16 +-
 rust/alloc/slice.rs               | 447 ++++------------------------
 rust/alloc/vec/drain.rs           |  81 +++++-
 rust/alloc/vec/drain_filter.rs    |  60 +++-
 rust/alloc/vec/into_iter.rs       | 125 ++++++--
 rust/alloc/vec/is_zero.rs         |  96 ++++++-
 rust/alloc/vec/mod.rs             | 464 +++++++++++++++++++++++-------
 rust/alloc/vec/set_len_on_drop.rs |   5 +
 rust/alloc/vec/spec_extend.rs     |  63 +---
 rust/bindings/lib.rs              |   1 -
 rust/kernel/build_assert.rs       |   2 +
 rust/kernel/init.rs               |   5 +
 rust/kernel/lib.rs                |   4 -
 rust/kernel/std_vendor.rs         |   2 +
 rust/kernel/sync/arc.rs           |   2 +-
 scripts/Makefile.build            |   2 +-
 scripts/min-tool-version.sh       |   2 +-
 23 files changed, 1278 insertions(+), 681 deletions(-)
  

Comments

Miguel Ojeda April 18, 2023, 10:17 p.m. UTC | #1
On Tue, Apr 18, 2023 at 11:44 PM Miguel Ojeda <ojeda@kernel.org> wrote:
>
> This is the first upgrade to the Rust toolchain since the initial Rust
> merge, from 1.62.0 to 1.68.2 (i.e. the latest).
>
> Please see the last patch message for a long explanation of the upgrade,
> the policy for future upgrades and some indications on how to easily
> review this.
>
> The series is based on `rust-next`.

The third patch may be too big for vger -- for those looking for it,
Lore has it at https://lore.kernel.org/all/20230418214347.324156-4-ojeda@kernel.org/

Cheers,
Miguel
  
Boqun Feng April 20, 2023, 3:23 a.m. UTC | #2
On Tue, Apr 18, 2023 at 11:43:44PM +0200, Miguel Ojeda wrote:
> This is the first upgrade to the Rust toolchain since the initial Rust
> merge, from 1.62.0 to 1.68.2 (i.e. the latest).
> 
> Please see the last patch message for a long explanation of the upgrade,
> the policy for future upgrades and some indications on how to easily
> review this.
> 
> The series is based on `rust-next`.
> 

Works on my machine ;-)

Tested-by: Boqun Feng <boqun.feng@gmail.com>

Regards,
Boqun

> Miguel Ojeda (3):
>   rust: alloc: clarify what is the upstream version
>   rust: arc: fix intra-doc link in `Arc<T>::init`
>   rust: upgrade to Rust 1.68.2
> 
>  Documentation/process/changes.rst |   2 +-
>  rust/alloc/README.md              |   3 +
>  rust/alloc/alloc.rs               |  55 ++--
>  rust/alloc/boxed.rs               | 446 ++++++++++++++++++++++++++--
>  rust/alloc/collections/mod.rs     |   5 +-
>  rust/alloc/lib.rs                 |  71 +++--
>  rust/alloc/raw_vec.rs             |  16 +-
>  rust/alloc/slice.rs               | 447 ++++------------------------
>  rust/alloc/vec/drain.rs           |  81 +++++-
>  rust/alloc/vec/drain_filter.rs    |  60 +++-
>  rust/alloc/vec/into_iter.rs       | 125 ++++++--
>  rust/alloc/vec/is_zero.rs         |  96 ++++++-
>  rust/alloc/vec/mod.rs             | 464 +++++++++++++++++++++++-------
>  rust/alloc/vec/set_len_on_drop.rs |   5 +
>  rust/alloc/vec/spec_extend.rs     |  63 +---
>  rust/bindings/lib.rs              |   1 -
>  rust/kernel/build_assert.rs       |   2 +
>  rust/kernel/init.rs               |   5 +
>  rust/kernel/lib.rs                |   4 -
>  rust/kernel/std_vendor.rs         |   2 +
>  rust/kernel/sync/arc.rs           |   2 +-
>  scripts/Makefile.build            |   2 +-
>  scripts/min-tool-version.sh       |   2 +-
>  23 files changed, 1278 insertions(+), 681 deletions(-)
> 
> -- 
> 2.40.0
>
  
David Gow April 20, 2023, 3:45 a.m. UTC | #3
On Wed, 19 Apr 2023 at 05:44, Miguel Ojeda <ojeda@kernel.org> wrote:
>
> This is the first upgrade to the Rust toolchain since the initial Rust
> merge, from 1.62.0 to 1.68.2 (i.e. the latest).
>
> Please see the last patch message for a long explanation of the upgrade,
> the policy for future upgrades and some indications on how to easily
> review this.
>
> The series is based on `rust-next`.
>

Builds and runs fine under UML here, too.

Series is:
Tested-by: David Gow <davidgow@google.com>


Cheers,
-- David
  
Ariel Miculas April 20, 2023, 1:12 p.m. UTC | #4
I've applied the patch series, upgraded rustc and built the kernel:

$ rustup override set $(scripts/min-tool-version.sh rustc)
$ rustup component add rust-src # Rust standard library source
$ cargo install --locked --version $(scripts/min-tool-version.sh
bindgen) bindgen
$ make LLVM=1 rustavailable
$ grep  RUSTC_VERSION .config
CONFIG_RUSTC_VERSION_TEXT="rustc 1.68.2 (9eb3afe9e 2023-03-27)"
$ make LLVM=1 -j$(nproc)

Then I ran the kernel in qemu-system-x86_64, inserted the
rust_minimal.ko kernel module and checked that it behaves as expected.

Tested-by: Ariel Miculas <amiculas@cisco.com>

Cheers,
Ariel

On Wed, Apr 19, 2023 at 12:48 AM Miguel Ojeda <ojeda@kernel.org> wrote:
>
> This is the first upgrade to the Rust toolchain since the initial Rust
> merge, from 1.62.0 to 1.68.2 (i.e. the latest).
>
> Please see the last patch message for a long explanation of the upgrade,
> the policy for future upgrades and some indications on how to easily
> review this.
>
> The series is based on `rust-next`.
>
> Miguel Ojeda (3):
>   rust: alloc: clarify what is the upstream version
>   rust: arc: fix intra-doc link in `Arc<T>::init`
>   rust: upgrade to Rust 1.68.2
>
>  Documentation/process/changes.rst |   2 +-
>  rust/alloc/README.md              |   3 +
>  rust/alloc/alloc.rs               |  55 ++--
>  rust/alloc/boxed.rs               | 446 ++++++++++++++++++++++++++--
>  rust/alloc/collections/mod.rs     |   5 +-
>  rust/alloc/lib.rs                 |  71 +++--
>  rust/alloc/raw_vec.rs             |  16 +-
>  rust/alloc/slice.rs               | 447 ++++------------------------
>  rust/alloc/vec/drain.rs           |  81 +++++-
>  rust/alloc/vec/drain_filter.rs    |  60 +++-
>  rust/alloc/vec/into_iter.rs       | 125 ++++++--
>  rust/alloc/vec/is_zero.rs         |  96 ++++++-
>  rust/alloc/vec/mod.rs             | 464 +++++++++++++++++++++++-------
>  rust/alloc/vec/set_len_on_drop.rs |   5 +
>  rust/alloc/vec/spec_extend.rs     |  63 +---
>  rust/bindings/lib.rs              |   1 -
>  rust/kernel/build_assert.rs       |   2 +
>  rust/kernel/init.rs               |   5 +
>  rust/kernel/lib.rs                |   4 -
>  rust/kernel/std_vendor.rs         |   2 +
>  rust/kernel/sync/arc.rs           |   2 +-
>  scripts/Makefile.build            |   2 +-
>  scripts/min-tool-version.sh       |   2 +-
>  23 files changed, 1278 insertions(+), 681 deletions(-)
>
> --
> 2.40.0
>
  
Miguel Ojeda April 20, 2023, 1:19 p.m. UTC | #5
On Thu, Apr 20, 2023 at 3:13 PM Ariel Miculas <ariel.miculas@gmail.com> 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
  
Ariel Miculas April 20, 2023, 5:17 p.m. UTC | #6
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@gmail.com> wrote:
>
> On Thu, Apr 20, 2023 at 3:13 PM Ariel Miculas <ariel.miculas@gmail.com> 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
  
Miguel Ojeda April 20, 2023, 5:20 p.m. UTC | #7
On Thu, Apr 20, 2023 at 7:18 PM Ariel Miculas <ariel.miculas@gmail.com> wrote:
>
> 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.

Thanks for confirming! (and for all the output!).

Cheers,
Miguel
  
Fabien Parent May 4, 2023, 10:27 p.m. UTC | #8
Hi Miguel,

I'm getting the following error when running rusttest on top of your patchset:

$ make LLVM=1 RUSTC=/home/fparent/.rustup/toolchains/1.68.2-x86_64-unknown-linux-gnu/bin/rustc
RUSTDOC=/home/fparent/.rustup/toolchains/1.68.2-x86_64-unknown-linux-gnu/bin/rustdoc
rusttest
  RUSTC L rust/uapi.o
error: the feature `core_ffi_c` has been stable since 1.64.0 and no
longer requires an attribute to enable
  --> rust/uapi/lib.rs:11:12
   |
11 | #![feature(core_ffi_c)]
   |            ^^^^^^^^^^

After manually removing line 11 in lib.rs, the error was gone.

Fabien

On Thu, 20 Apr 2023 at 19:20, Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Thu, Apr 20, 2023 at 7:18 PM Ariel Miculas <ariel.miculas@gmail.com> wrote:
> >
> > 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.
>
> Thanks for confirming! (and for all the output!).
>
> Cheers,
> Miguel
  
Miguel Ojeda May 5, 2023, 9:59 a.m. UTC | #9
Hi Fabien,

On Fri, May 5, 2023 at 12:28 AM Fabien Parent <fabien.parent@linaro.org> wrote:
>
> I'm getting the following error when running rusttest on top of your patchset:

Yeah, it is expected: the series was based on `rust-next` which gained
the `uapi` crate later on.

Thanks for reporting it!

Cheers,
Miguel
  
Miguel Ojeda May 31, 2023, 5:03 p.m. UTC | #10
On Tue, Apr 18, 2023 at 11:44 PM Miguel Ojeda <ojeda@kernel.org> wrote:
>
> This is the first upgrade to the Rust toolchain since the initial Rust
> merge, from 1.62.0 to 1.68.2 (i.e. the latest).
>
> Please see the last patch message for a long explanation of the upgrade,
> the policy for future upgrades and some indications on how to easily
> review this.
>
> The series is based on `rust-next`.

Applied to `rust-next` (with the `core_ffi_c` removal in the `uapi` crate).

Thanks a lot to all reviewers and testers (and thanks Gary for
re-reviewing our diff with respect to upstream `alloc`).

Cheers,
Miguel