[Devel] [PATCH RHEL9 COMMIT] x86/cpu: init_cpu_flags -- use raw spinlock

Konstantin Khorenko khorenko at virtuozzo.com
Thu Oct 14 19:37:00 MSK 2021


The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-4.vz9.10.7
------>
commit 1f7b66c334884ee928f2f65f4354b9e375eac089
Author: Cyrill Gorcunov <gorcunov at gmail.com>
Date:   Thu Oct 14 19:36:59 2021 +0300

    x86/cpu: init_cpu_flags -- use raw spinlock
    
    The @cpu_flags_lock spinlock guards manipulations with
    per-cpu @cpu_flags which is used to hide some features
    in cpuinfo output inside VE. Still the init_cpu_flags
    is called from irq context leading to the following
    
     | [   13.827635] =============================
     | [   13.827636] [ BUG: Invalid wait context ]
     | [   13.827637] 5.14.0.ovz9.10.1+ #41 Tainted: G         C     X --------- ---
     | [   13.827638] -----------------------------
     | [   13.827638] systemd/1 is trying to lock:
     | [   13.827639] ffffffffa4c9d258 (cpu_flags_lock){....}-{3:3}, at: init_cpu_flags+0xc8/0x220
     | [   13.827649] other info that might help us debug this:
     | [   13.827651] context-{2:2}
     | [   13.827651] 3 locks held by systemd/1:
     | [   13.827652]  #0: ffffffffa56e8c60 (dup_mmap_sem){.+.+}-{0:0}, at: dup_mm+0x83/0x5f0
     | [   13.827660]  #1: ffff97574a37d138 (&mm->mmap_lock#2){++++}-{4:4}, at: dup_mm+0x9c/0x5f0
     | [   13.827664]  #2: ffff97574489c138 (&mm->mmap_lock/1){+.+.}-{4:4}, at: dup_mm+0xd5/0x5f0
     | [   13.827667] stack backtrace:
     | [   13.827668] CPU: 0 PID: 1 Comm: systemd ve: / Tainted: G         C     X --------- ---
     | [   13.827670] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-4.fc34 04/01/2014
     | [   13.827672] Call Trace:
     | [   13.827673]  <IRQ>
     | [   13.827675]  dump_stack_lvl+0x57/0x7d
     | [   13.827686]  __lock_acquire.cold+0x28b/0x2cd
     | [   13.827694]  lock_acquire+0xca/0x300
     | [   13.827700]  ? init_cpu_flags+0xc8/0x220
     | [   13.827703]  _raw_spin_lock+0x34/0x80
     | [   13.827708]  ? init_cpu_flags+0xc8/0x220
     | [   13.827710]  init_cpu_flags+0xc8/0x220
     | [   13.827713]  flush_smp_call_function_queue+0x13f/0x1e0
     | [   13.827717]  __sysvec_call_function_single+0x43/0x1c0
     | [   13.827722]  sysvec_call_function_single+0x9d/0xd0
     | [   13.827724]  </IRQ>
     | [   13.827724]  asm_sysvec_call_function_single+0x12/0x20
     | [   13.827728] RIP: 0010:lock_release+0x178/0x460
     | ...
     | [   13.827741]  up_write+0x2f/0x1c0
     | [   13.827743]  anon_vma_clone+0x158/0x1f0
     | [   13.827749]  anon_vma_fork+0x33/0x180
     | [   13.827751]  dup_mm+0x45b/0x5f0
     | [   13.827755]  copy_process+0x1e5a/0x2050
     | [   13.827758]  kernel_clone+0x9b/0x3f0
     | [   13.827760]  ? vfs_statx+0x74/0x130
     | [   13.827766]  __do_sys_clone+0x60/0x80
     | [   13.827769]  do_syscall_64+0x3b/0x90
     | [   13.827771]  entry_SYSCALL_64_after_hwframe+0x44/0xae
    
    The problem is rather coming from rt camp where splinlocks
    become sleepable thus can't be used in irq context (and for our kernel
    it requires the CONFIG_PROVE_RAW_LOCK_NESTING to be set), thus since
    we know that we're operating in irq context lets use raw spinlocks
    instead.
    
    https://jira.sw.ru/browse/PSBM-134761
    
    Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
    Reviewed-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 arch/x86/kernel/cpu/proc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/cpu/proc.c b/arch/x86/kernel/cpu/proc.c
index dd9d0811e379..a06281fcbd5c 100644
--- a/arch/x86/kernel/cpu/proc.c
+++ b/arch/x86/kernel/cpu/proc.c
@@ -69,7 +69,7 @@ struct cpu_flags {
 };
 
 static DEFINE_PER_CPU(struct cpu_flags, cpu_flags);
-static DEFINE_SPINLOCK(cpu_flags_lock);
+static DEFINE_RAW_SPINLOCK(cpu_flags_lock);
 
 static void init_cpu_flags(void *dummy)
 {
@@ -107,9 +107,9 @@ static void init_cpu_flags(void *dummy)
 		flags.val[10] &= eax;
 	}
 
-	spin_lock(&cpu_flags_lock);
+	raw_spin_lock(&cpu_flags_lock);
 	memcpy(&per_cpu(cpu_flags, cpu), &flags, sizeof(flags));
-	spin_unlock(&cpu_flags_lock);
+	raw_spin_unlock(&cpu_flags_lock);
 }
 
 static int show_cpuinfo(struct seq_file *m, void *v)
@@ -158,9 +158,9 @@ static int show_cpuinfo(struct seq_file *m, void *v)
 	show_cpuinfo_misc(m, c);
 
 	if (!is_super) {
-		spin_lock_irq(&cpu_flags_lock);
+		raw_spin_lock_irq(&cpu_flags_lock);
 		memcpy(&ve_flags, &per_cpu(cpu_flags, cpu), sizeof(ve_flags));
-		spin_unlock_irq(&cpu_flags_lock);
+		raw_spin_unlock_irq(&cpu_flags_lock);
 	}
 
 


More information about the Devel mailing list