[PATCH] x86/virt/vmx/tdx: Use raw spin lock instead of spin lock
From: Isaku Yamahata
Date: Wed Mar 15 2023 - 17:26:37 EST
tdx_cpu_enable() can be called by IPI handler. The lockdep complains about
spin lock as follows. Use raw spin lock.
=============================
[ BUG: Invalid wait context ]
6.3.0-rc1-tdx-kvm-upstream+ #389 Not tainted
-----------------------------
swapper/154/0 is trying to lock:
ffffffffa7875e58 (tdx_global_init_lock){....}-{3:3}, at: tdx_cpu_enable+0x67/0x180
other info that might help us debug this:
context-{2:2}
no locks held by swapper/154/0.
stack backtrace:
Call Trace:
<IRQ>
dump_stack_lvl+0x64/0xb0
dump_stack+0x10/0x20
__lock_acquire+0x912/0xc30
lock_acquire.part.0+0x99/0x220
lock_acquire+0x60/0x170
_raw_spin_lock_irqsave+0x43/0x70
tdx_cpu_enable+0x67/0x180
vt_hardware_enable+0x3b/0x60
kvm_arch_hardware_enable+0xe7/0x2e0
hardware_enable_nolock+0x33/0x80
__flush_smp_call_function_queue+0xc4/0x590
generic_smp_call_function_single_interrupt+0x1a/0xb0
__sysvec_call_function+0x48/0x200
sysvec_call_function+0xad/0xd0
</IRQ>
Signed-off-by: Isaku Yamahata <isaku.yamahata@xxxxxxxxx>
---
arch/x86/virt/vmx/tdx/tdx.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
index 2ee37a5dedcf..e1c8ffad7406 100644
--- a/arch/x86/virt/vmx/tdx/tdx.c
+++ b/arch/x86/virt/vmx/tdx/tdx.c
@@ -41,7 +41,7 @@ static u32 tdx_guest_keyid_start __ro_after_init;
static u32 tdx_nr_guest_keyids __ro_after_init;
static unsigned int tdx_global_init_status;
-static DEFINE_SPINLOCK(tdx_global_init_lock);
+static DEFINE_RAW_SPINLOCK(tdx_global_init_lock);
#define TDX_GLOBAL_INIT_DONE _BITUL(0)
#define TDX_GLOBAL_INIT_FAILED _BITUL(1)
@@ -349,6 +349,7 @@ static void tdx_trace_seamcalls(u64 level)
static int try_init_module_global(void)
{
+ unsigned long flags;
u64 tsx_ctrl;
int ret;
@@ -356,7 +357,7 @@ static int try_init_module_global(void)
* The TDX module global initialization only needs to be done
* once on any cpu.
*/
- spin_lock(&tdx_global_init_lock);
+ raw_spin_lock_irqsave(&tdx_global_init_lock, flags);
if (tdx_global_init_status & TDX_GLOBAL_INIT_DONE) {
ret = tdx_global_init_status & TDX_GLOBAL_INIT_FAILED ?
@@ -373,7 +374,7 @@ static int try_init_module_global(void)
if (ret)
tdx_global_init_status |= TDX_GLOBAL_INIT_FAILED;
out:
- spin_unlock(&tdx_global_init_lock);
+ raw_spin_unlock_irqrestore(&tdx_global_init_lock, flags);
if (ret) {
if (trace_boot_seamcalls)
--
2.25.1
--
Isaku Yamahata <isaku.yamahata@xxxxxxxxx>