From 3bf9c88c1d8200f17c69bddb0b7dc047e6dfc6fe Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sat, 12 Oct 2024 16:41:54 +0200 Subject: [PATCH 1/3] linux_testing: enable Rust by default for aarch64-linux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The first assumption[1] we had was that the `aarch64-unknown-none` target was missing from rustc and that this was the cause for the regression. However, it turns out that the relevant code from `rustc` wasn't used anyways because the Makefile does `--sysroot /dev/null`[2] which prevents rustc from using its own libcore. So luckily we don't have to patch the Rust bootstrap to get aarch64-linux back working[3]. In fact, the Rust part seems broken for both 6.10 and 6.11[4], but I decided to not bother since none of those are longterm versions. So all that's left here is to enable Rust for aarch64-linux because it clearly works[5]. [1] https://github.com/NixOS/nixpkgs/pull/315121#issuecomment-2135805876 [2] https://lore.kernel.org/all/20231031201752.1189213-1-mmaurer@google.com/ [3] Of course I only realized this _after_ I spent some time hacking a rustc patch together 🙃 [4] This broke with error[E0463]: can't find crate for `core` | = note: the `aarch64-unknown-none` target may not be installed = help: consider downloading the target with `rustup target add aarch64-unknown-none` = help: consider building the standard library from source with `cargo build -Zbuild-std` [5] While the build is fine, the VM tests are still panicking, but that's also the case for `kernel-generic` because of a 9p regression: switch_root: can't execute '/nix/store/zv87gw0yxfsslq0mcc35a99k54da9a4z-nixos-system-machine-test/init': Exec format error [ 1.734997] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000100 [ 1.736002] CPU: 0 UID: 0 PID: 1 Comm: switch_root Not tainted 6.12.0-rc1 #1-NixOS [...] Reported as https://lore.kernel.org/all/D4LHHUNLG79Y.12PI0X6BEHRHW@mbosch.me/T/#u --- pkgs/os-specific/linux/kernel/common-config.nix | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkgs/os-specific/linux/kernel/common-config.nix b/pkgs/os-specific/linux/kernel/common-config.nix index 9d024b539d83..91b57676abca 100644 --- a/pkgs/os-specific/linux/kernel/common-config.nix +++ b/pkgs/os-specific/linux/kernel/common-config.nix @@ -33,10 +33,8 @@ let kernelSupportsRust = lib.versionAtLeast version "6.7"; # Currently only enabling Rust by default on kernel 6.12+, - # which actually has features that use Rust that we want, - # and only on x86_64, because of a nixpkgs rustc issue: - # https://github.com/NixOS/nixpkgs/pull/315121#issuecomment-2135805876 - defaultRust = lib.versionAtLeast version "6.12" && stdenv.hostPlatform.isx86_64; + # which actually has features that use Rust that we want. + defaultRust = lib.versionAtLeast version "6.12" && (stdenv.hostPlatform.isx86_64 || stdenv.hostPlatform.isAarch64); withRust = (forceRust || defaultRust) && kernelSupportsRust; options = { From bda6c82a8162ebbf3c25e028992a4b8a9c323065 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sat, 12 Oct 2024 16:43:31 +0200 Subject: [PATCH 2/3] linux_testing: disable NFS_LOCALIO on aarch64-linux This breaks the build like this: /nix/store/f3k0rdhcd2cx57phx755c2xixgifw5m5-binutils-2.42/bin/ld: Unexpected GOT/PLT entries detected! /nix/store/f3k0rdhcd2cx57phx755c2xixgifw5m5-binutils-2.42/bin/ld: Unexpected run-time procedure linkages detected! /nix/store/f3k0rdhcd2cx57phx755c2xixgifw5m5-binutils-2.42/bin/ld: fs/nfs/localio.o: in function `nfs_local_iocb_alloc': /build/source/build/../fs/nfs/localio.c:290:(.text+0x324): undefined reference to `nfs_to' [...] Reported as https://lore.kernel.org/all/D4OUJRP8YWRM.ATQ7KASTYX5H@mbosch.me/ --- pkgs/os-specific/linux/kernel/common-config.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkgs/os-specific/linux/kernel/common-config.nix b/pkgs/os-specific/linux/kernel/common-config.nix index 91b57676abca..e60513b57095 100644 --- a/pkgs/os-specific/linux/kernel/common-config.nix +++ b/pkgs/os-specific/linux/kernel/common-config.nix @@ -639,7 +639,10 @@ let NFS_V4_1 = yes; # NFSv4.1 client support NFS_V4_2 = yes; NFS_V4_SECURITY_LABEL = yes; - NFS_LOCALIO = whenAtLeast "6.12" yes; + + # Fails with + # `fs/nfs/localio.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `nfs_to' which may bind externally can not be used when making a shared object; recompile with -fPIC` + NFS_LOCALIO = lib.mkIf (!stdenv.hostPlatform.isAarch64) (whenAtLeast "6.12" yes); CIFS_XATTR = yes; CIFS_POSIX = option yes; From d3e6c8fc751a9be31e0f68400c835ac1534aaabb Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sun, 6 Oct 2024 16:48:44 +0200 Subject: [PATCH 3/3] linux: implement `rustAvailable` condition * It doesn't matter if `rustc` is available, but if rustc can compile to the hostPlatform. So use a custom condition instead of `availableOn`. * Explicitly exclude the combination of GCC and riscv which is known to be broken[1]. [1] https://lore.kernel.org/lkml/31885EDD-EF6D-4EF1-94CA-276BA7A340B7@kernel.org/T/ Co-authored-by: Alyssa Ross --- pkgs/os-specific/linux/kernel/common-config.nix | 3 ++- pkgs/os-specific/linux/kernel/generic.nix | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkgs/os-specific/linux/kernel/common-config.nix b/pkgs/os-specific/linux/kernel/common-config.nix index e60513b57095..523bcb63d1e6 100644 --- a/pkgs/os-specific/linux/kernel/common-config.nix +++ b/pkgs/os-specific/linux/kernel/common-config.nix @@ -11,6 +11,7 @@ # Configuration { lib, stdenv, version +, rustAvailable , features ? {} }: @@ -34,7 +35,7 @@ let # Currently only enabling Rust by default on kernel 6.12+, # which actually has features that use Rust that we want. - defaultRust = lib.versionAtLeast version "6.12" && (stdenv.hostPlatform.isx86_64 || stdenv.hostPlatform.isAarch64); + defaultRust = lib.versionAtLeast version "6.12" && rustAvailable; withRust = (forceRust || defaultRust) && kernelSupportsRust; options = { diff --git a/pkgs/os-specific/linux/kernel/generic.nix b/pkgs/os-specific/linux/kernel/generic.nix index fdfc78235226..49c9594f8f7f 100644 --- a/pkgs/os-specific/linux/kernel/generic.nix +++ b/pkgs/os-specific/linux/kernel/generic.nix @@ -108,6 +108,11 @@ let commonStructuredConfig = import ./common-config.nix { inherit lib stdenv version; + rustAvailable = + lib.any (lib.meta.platformMatch stdenv.hostPlatform) rustc.targetPlatforms + && lib.all (p: !lib.meta.platformMatch stdenv.hostPlatform p) rustc.badTargetPlatforms + # Known to be broken: https://lore.kernel.org/lkml/31885EDD-EF6D-4EF1-94CA-276BA7A340B7@kernel.org/T/ + && !(stdenv.hostPlatform.isRiscV && stdenv.cc.isGNU); features = kernelFeatures; # Ensure we know of all extra patches, etc. };