From 3fdfc69269f1f6c61868568bae2a918e8228ef57 Mon Sep 17 00:00:00 2001 From: Daniel Fullmer Date: Thu, 25 Apr 2024 18:01:28 -0700 Subject: [PATCH] kernel: add patch to fix Xavier NX crashes It's unclear the reason, but randomly, Xavier NX systems would crash immediately upon booting into the kernel. This would happen while initial entropy from the UEFI RNG table. This appears to be working in 35.5.0, and this patch from the stable kernel is what is needed. --- ...dom-use-static-branch-for-crng_ready.patch | 68 +++++++++++++++++++ kernel/default.nix | 5 ++ 2 files changed, 73 insertions(+) create mode 100644 kernel/0009-Revert-random-use-static-branch-for-crng_ready.patch diff --git a/kernel/0009-Revert-random-use-static-branch-for-crng_ready.patch b/kernel/0009-Revert-random-use-static-branch-for-crng_ready.patch new file mode 100644 index 0000000..bd730ad --- /dev/null +++ b/kernel/0009-Revert-random-use-static-branch-for-crng_ready.patch @@ -0,0 +1,68 @@ +From 72268945b124cd61336f9b4cac538b0516399a2d Mon Sep 17 00:00:00 2001 +From: "Jason A. Donenfeld" +Date: Tue, 7 Jun 2022 10:40:05 +0200 +Subject: [PATCH] Revert "random: use static branch for crng_ready()" + +This reverts upstream commit f5bda35fba615ace70a656d4700423fa6c9bebee +from stable. It's not essential and will take some time during 5.19 to +work out properly. + +Signed-off-by: Jason A. Donenfeld +--- + drivers/char/random.c | 12 ++---------- + 1 file changed, 2 insertions(+), 10 deletions(-) + +diff --git a/drivers/char/random.c b/drivers/char/random.c +index c206db96f60a..5776dfd4a6fc 100644 +--- a/drivers/char/random.c ++++ b/drivers/char/random.c +@@ -79,8 +79,7 @@ static enum { + CRNG_EARLY = 1, /* At least POOL_EARLY_BITS collected */ + CRNG_READY = 2 /* Fully initialized with POOL_READY_BITS collected */ + } crng_init __read_mostly = CRNG_EMPTY; +-static DEFINE_STATIC_KEY_FALSE(crng_is_ready); +-#define crng_ready() (static_branch_likely(&crng_is_ready) || crng_init >= CRNG_READY) ++#define crng_ready() (likely(crng_init >= CRNG_READY)) + /* Various types of waiters for crng_init->CRNG_READY transition. */ + static DECLARE_WAIT_QUEUE_HEAD(crng_init_wait); + static struct fasync_struct *fasync; +@@ -110,11 +109,6 @@ bool rng_is_initialized(void) + } + EXPORT_SYMBOL(rng_is_initialized); + +-static void __cold crng_set_ready(struct work_struct *work) +-{ +- static_branch_enable(&crng_is_ready); +-} +- + /* Used by wait_for_random_bytes(), and considered an entropy collector, below. */ + static void try_to_generate_entropy(void); + +@@ -268,7 +262,7 @@ static void crng_reseed(void) + ++next_gen; + WRITE_ONCE(base_crng.generation, next_gen); + WRITE_ONCE(base_crng.birth, jiffies); +- if (!static_branch_likely(&crng_is_ready)) ++ if (!crng_ready()) + crng_init = CRNG_READY; + spin_unlock_irqrestore(&base_crng.lock, flags); + memzero_explicit(key, sizeof(key)); +@@ -711,7 +705,6 @@ static void extract_entropy(void *buf, size_t len) + + static void __cold _credit_init_bits(size_t bits) + { +- static struct execute_work set_ready; + unsigned int new, orig, add; + unsigned long flags; + +@@ -727,7 +720,6 @@ static void __cold _credit_init_bits(size_t bits) + + if (orig < POOL_READY_BITS && new >= POOL_READY_BITS) { + crng_reseed(); /* Sets crng_init to CRNG_READY under base_crng.lock. */ +- execute_in_process_context(crng_set_ready, &set_ready); + process_random_ready_list(); + wake_up_interruptible(&crng_init_wait); + kill_fasync(&fasync, SIGIO, POLL_IN); +-- +2.44.0 + diff --git a/kernel/default.nix b/kernel/default.nix index 8adf253..3838478 100644 --- a/kernel/default.nix +++ b/kernel/default.nix @@ -89,6 +89,11 @@ pkgsAarch64.buildLinux (args // { # Lower priority of tegra-se crypto modules since they're slow and flaky { patch = ./0008-Lower-priority-of-tegra-se-crypto.patch; } + + # Include patch from linux-stable that (for some reason) appears to fix + # random crashes very early in boot process on Xavier NX specifically + # Remove when updating to 35.5.0 + { patch = ./0009-Revert-random-use-static-branch-for-crng_ready.patch; } ] ++ kernelPatches; structuredExtraConfig = with lib.kernel; {