From nobody Sat Feb 7 13:45:56 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DF9B42AA4 for ; Sat, 30 Nov 2024 15:33:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732980807; cv=none; b=WXhlreSoGscfri3O4NHRW0hW9vqGcNFva/pN2A8B+nmNo5/yPqFrxaU8pNaU555I2qcUjPKslr2cYLCT518NbrKMOLJqzjmAY5GsjB+YkjBjtzQZLE8BFVSfFnfx/dXYTGPZoZShVga0yPZJUSs+LEb36eG+Yelv7zTboKKKiCg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732980807; c=relaxed/simple; bh=aym/4A9156Bez914Qw2rtg50lJsSoqpPIIeg7OlOfh4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=PvlPS2vwmHg2NNNalES/O5pFOH/zTFs6KGqhmtR0DpKvmmMocENAXurXoKx3QhO8AC1T/HKKcpzMIarT5lDARzFVQpFJZbWE0KD2AC5XZBoWMCBv4Pc6icK8hNDT/72kHAJM1p0DXtPAAVkok34CQMyRkI7r5xaGuyDQhTaMYY8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mhUhvnU0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mhUhvnU0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64EFCC4CECC; Sat, 30 Nov 2024 15:33:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732980807; bh=aym/4A9156Bez914Qw2rtg50lJsSoqpPIIeg7OlOfh4=; h=From:To:Cc:Subject:Date:From; b=mhUhvnU0H52swI1Xu8cVLSMTZRRh+VKLWDPNChBm8tNEYkDzvoYWQUB1Ii0/ncyAR vDYblsR5DGRzRZbIH0P1KyjE5Td08JUD8bVyYACG8e8lVuswJDxsttBB4E2aE8WEJ9 AKJtolzSYDARWN9bmxRSWejocd5Ob5KmRUV8J6pHTc/RirYH9HCMMwjkXkVXwRJpLC lKABmc/j6AS0/KTcgZwU7fkROseu9S/icCxwDvP6OfCN7dABMqyEG/eOF+z8BhyTKZ iCld/GsjmC0x3On5DsflD9dCFvISc6Qgvzfry/WhfgpBWwE3Z7FIhlDvpBfmKGY920 RRiHeiZAEgoNg== From: guoren@kernel.org To: paul.walmsley@sifive.com, palmer@dabbelt.com, guoren@kernel.org, bjorn@rivosinc.com, conor@kernel.org, leobras@redhat.com, peterz@infradead.org, parri.andrea@gmail.com, will@kernel.org, longman@redhat.com, boqun.feng@gmail.com, arnd@arndb.de, alexghiti@rivosinc.com Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Guo Ren Subject: [RESEND PATCH] riscv: Fixup boot failure when CONFIG_DEBUG_RT_MUTEXES=y Date: Sat, 30 Nov 2024 10:33:10 -0500 Message-Id: <20241130153310.3349484-1-guoren@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Guo Ren When CONFIG_DEBUG_RT_MUTEXES=3Dy, mutex_lock->rt_mutex_try_acquire would change from rt_mutex_cmpxchg_acquire to rt_mutex_slowtrylock(): raw_spin_lock_irqsave(&lock->wait_lock, flags); ret =3D __rt_mutex_slowtrylock(lock); raw_spin_unlock_irqrestore(&lock->wait_lock, flags); Because queued_spin_#ops to ticket_#ops is changed one by one by jump_label, raw_spin_lock/unlock would cause a deadlock during the changing. That means in arch/riscv/kernel/jump_label.c: 1. arch_jump_label_transform_queue() -> mutex_lock(&text_mutex); +-> raw_spin_lock -> queued_spin_lock |-> raw_spin_unlock -> queued_spin_unlock patch_insn_write -> change the raw_spin_lock to ticket_lock mutex_unlock(&text_mutex); ... 2. /* Dirty the lock value */ arch_jump_label_transform_queue() -> mutex_lock(&text_mutex); +-> raw_spin_lock -> *ticket_lock* |-> raw_spin_unlock -> *queued_spin_unlock* /* BUG: ticket_lock with queued_spin_unlock */ patch_insn_write -> change the raw_spin_unlock to ticket_unlock mutex_unlock(&text_mutex); ... 3. /* Dead lock */ arch_jump_label_transform_queue() -> mutex_lock(&text_mutex); +-> raw_spin_lock -> ticket_lock /* deadlock! */ |-> raw_spin_unlock -> ticket_unlock patch_insn_write -> change other raw_spin_#op -> ticket_#op mutex_unlock(&text_mutex); So, the solution is to disable mutex usage of arch_jump_label_transform_queue() during early_boot_irqs_disabled, just like we have done for stop_machine. Reported-by: Conor Dooley Signed-off-by: Guo Ren Signed-off-by: Guo Ren Fixes: ab83647fadae ("riscv: Add qspinlock support") Link: https://lore.kernel.org/linux-riscv/CAJF2gTQwYTGinBmCSgVUoPv0_q4EPt_+= WiyfUA1HViAKgUzxAg@mail.gmail.com/T/#mf488e6347817fca03bb93a7d34df33d8615b3= 775 Cc: Palmer Dabbelt Cc: Alexandre Ghiti Reviewed-by: Alexandre Ghiti Tested-by: Alexandre Ghiti Tested-by: Conor Dooley Tested-by: Nam Cao --- arch/riscv/kernel/jump_label.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/jump_label.c b/arch/riscv/kernel/jump_label.c index 6eee6f736f68..654ed159c830 100644 --- a/arch/riscv/kernel/jump_label.c +++ b/arch/riscv/kernel/jump_label.c @@ -36,9 +36,15 @@ bool arch_jump_label_transform_queue(struct jump_entry *= entry, insn =3D RISCV_INSN_NOP; } =20 - mutex_lock(&text_mutex); - patch_insn_write(addr, &insn, sizeof(insn)); - mutex_unlock(&text_mutex); + if (early_boot_irqs_disabled) { + riscv_patch_in_stop_machine =3D 1; + patch_insn_write(addr, &insn, sizeof(insn)); + riscv_patch_in_stop_machine =3D 0; + } else { + mutex_lock(&text_mutex); + patch_insn_write(addr, &insn, sizeof(insn)); + mutex_unlock(&text_mutex); + } =20 return true; } --=20 2.40.1