Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1013881rdg; Fri, 13 Oct 2023 07:52:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFzx/XDKE2DMnWTmN7LDL6BVHUXYcGzNcZVXBkm/rUeSnRVHUJIhLuMay2Ljvo0ZEoRCfgA X-Received: by 2002:a17:902:e195:b0:1c9:fb76:42f9 with SMTP id y21-20020a170902e19500b001c9fb7642f9mr1631528pla.69.1697208769514; Fri, 13 Oct 2023 07:52:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697208769; cv=none; d=google.com; s=arc-20160816; b=Yb4rYLjRqbWWDJFZMbwGwP0XLZJcOo49CH0SkSMLZhoWh2mxKzoDWGg+ZP7KICie5r F+ErmWL4pNwflwBEjmT5ArdOdxLhpiEpUEjJTYg56N0EoV9jgdPCpVSSSOhfLcC/izkK 9slCl8bSp2u+c9OVnVZohyw1bFXx41f2G7t2Fe5ep1S0iG58rSpYD2FNCr5QwvG2XfJd KdyjBzPcX1RQO4t1Sdxv6jQ0Jhch3VtRaGzTl7gT9HYRNBXwWzfdHEqJ8Py71FT7oEJJ Zx8WgcypKpji46zYC74Awysweu1rZ1GptvYoc76REv8JLJ1DRbeUBNketiii9R9ZtlF4 lUfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:subject:from:cc:to :content-language:user-agent:mime-version:date:message-id; bh=4n4thDtte3YLZS4tsKFNWy7hf/pfBd9jej3wW1eClfE=; fh=Xve8OBVtF73ceFoObOlVIPSONTU6i0gm/uQ0YNqwVDM=; b=hTOaTSUc3iXjrOoZ9oUo7d/hWJl66C3KkvoR2lUrs5uXPO6k9FBMCc/VLWouYL6p9n vuO+OnHKbFs8DlVOWtD8am4GgIrDtWjbcjXIyyanhRBo9IHe3sjqNmXaNjOxZhe6OO6u 2Scs+gI4f5tdeuKTirNlqWwndsO1QKZLCWi6NqdJjaKVy6lrTvRWwW3As3GFY7S6vmiC 1sBfe1/3DL+CLlRMn5f4GJ+vF3Lu0ZMGJVc7lGrluxJtZuDfYap0ClU914A24WYz4SA0 P8sl1AvSqe0B5LeAaWJ+5zPTxBtLfo0/hWzNHrqhrNUwF3asH2WC7e4LiTxatljsIvAn 2+lg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id d3-20020a170902cec300b001c9ad94f614si4797749plg.244.2023.10.13.07.52.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 07:52:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 1EBE8809ABD0; Fri, 13 Oct 2023 07:52:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232214AbjJMOv5 (ORCPT + 99 others); Fri, 13 Oct 2023 10:51:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229937AbjJMOvz (ORCPT ); Fri, 13 Oct 2023 10:51:55 -0400 Received: from www262.sakura.ne.jp (www262.sakura.ne.jp [202.181.97.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AF1BD8 for ; Fri, 13 Oct 2023 07:51:53 -0700 (PDT) Received: from fsav114.sakura.ne.jp (fsav114.sakura.ne.jp [27.133.134.241]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 39DEpUBj005234; Fri, 13 Oct 2023 23:51:30 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav114.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav114.sakura.ne.jp); Fri, 13 Oct 2023 23:51:30 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav114.sakura.ne.jp) Received: from [192.168.1.6] (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 39DEpTr6005229 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Fri, 13 Oct 2023 23:51:30 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Message-ID: <80ff5036-8449-44a6-ba2f-0130d3be6b57@I-love.SAKURA.ne.jp> Date: Fri, 13 Oct 2023 23:51:29 +0900 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: John Stultz , Thomas Gleixner , Stephen Boyd Cc: LKML From: Tetsuo Handa Subject: [PATCH] clocksource: disable irq when holding watchdog_lock. Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 13 Oct 2023 07:52:03 -0700 (PDT) Lockdep found that spin_lock(&watchdog_lock) from call_timer_fn() is not safe. Use spin_lock_irqsave(&watchdog_lock, flags) instead. [ 0.378387] TSC synchronization [CPU#0 -> CPU#1]: [ 0.378387] Measured 55060 cycles TSC warp between CPUs, turning off TSC clock. [ 0.378387] tsc: Marking TSC unstable due to check_tsc_sync_source failed [ 0.926101] [ 0.926387] ================================ [ 0.926387] WARNING: inconsistent lock state [ 0.926387] 6.6.0-rc5-00192-g10a6e5feccb8 #2 Not tainted [ 0.926387] -------------------------------- [ 0.926387] inconsistent {IN-HARDIRQ-W} -> {HARDIRQ-ON-W} usage. [ 0.926387] swapper/0/0 [HC0[0]:SC1[1]:HE1:SE0] takes: [ 0.926387] ffffffff8cfa1c78 (watchdog_lock){?.-.}-{2:2}, at: clocksource_watchdog+0x23/0x5a0 [ 0.926387] {IN-HARDIRQ-W} state was registered at: [ 0.926387] lock_acquire+0xc1/0x2c0 [ 0.926387] _raw_spin_lock_irqsave+0x3f/0x60 [ 0.926387] clocksource_mark_unstable+0x1b/0x90 [ 0.926387] mark_tsc_unstable+0x41/0x50 [ 0.926387] check_tsc_sync_source+0x14f/0x180 [ 0.926387] __flush_smp_call_function_queue+0x16f/0x560 [ 0.926387] __sysvec_call_function_single+0x36/0x110 [ 0.926387] sysvec_call_function_single+0x69/0x90 [ 0.926387] asm_sysvec_call_function_single+0x1a/0x20 [ 0.926387] default_idle+0xf/0x20 [ 0.926387] default_idle_call+0x7f/0x180 [ 0.926387] do_idle+0x1e1/0x220 [ 0.926387] cpu_startup_entry+0x2a/0x30 [ 0.926387] rest_init+0xf4/0x190 [ 0.926387] arch_call_rest_init+0xe/0x30 [ 0.926387] start_kernel+0x763/0x910 [ 0.926387] x86_64_start_reservations+0x18/0x30 [ 0.926387] x86_64_start_kernel+0xca/0xe0 [ 0.926387] secondary_startup_64_no_verify+0x178/0x17b [ 0.926387] irq event stamp: 138774 [ 0.926387] hardirqs last enabled at (138774): [] _raw_spin_unlock_irq+0x28/0x50 [ 0.926387] hardirqs last disabled at (138773): [] _raw_spin_lock_irq+0x47/0x50 [ 0.926387] softirqs last enabled at (138216): [] irq_exit_rcu+0x7f/0xa0 [ 0.926387] softirqs last disabled at (138267): [] irq_exit_rcu+0x7f/0xa0 [ 0.926387] [ 0.926387] other info that might help us debug this: [ 0.926387] Possible unsafe locking scenario: [ 0.926387] [ 0.926387] CPU0 [ 0.926387] ---- [ 0.926387] lock(watchdog_lock); [ 0.926387] [ 0.926387] lock(watchdog_lock); [ 0.926387] [ 0.926387] *** DEADLOCK *** [ 0.926387] [ 0.926387] 1 lock held by swapper/0/0: [ 0.926387] #0: ffffa2d680003ea0 ((&watchdog_timer)){+.-.}-{0:0}, at: call_timer_fn+0x77/0x220 [ 0.926387] [ 0.926387] stack backtrace: [ 0.926387] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 6.6.0-rc5-00192-g10a6e5feccb8 #2 [ 0.926387] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 [ 0.926387] Call Trace: [ 0.926387] [ 0.926387] dump_stack_lvl+0x4b/0x80 [ 0.926387] mark_lock.part.0+0xa1c/0xf30 [ 0.926387] __lock_acquire+0x3a9/0x2550 [ 0.926387] lock_acquire+0xc1/0x2c0 [ 0.926387] ? clocksource_watchdog+0x23/0x5a0 [ 0.926387] ? __pfx_clocksource_watchdog+0x10/0x10 [ 0.926387] ? __pfx_clocksource_watchdog+0x10/0x10 [ 0.926387] _raw_spin_lock+0x30/0x40 [ 0.926387] ? clocksource_watchdog+0x23/0x5a0 [ 0.926387] clocksource_watchdog+0x23/0x5a0 [ 0.926387] ? __run_timers.part.0+0x30/0x2c0 [ 0.926387] ? __pfx_clocksource_watchdog+0x10/0x10 [ 0.926387] ? __pfx_clocksource_watchdog+0x10/0x10 [ 0.926387] call_timer_fn+0xa5/0x220 [ 0.926387] __run_timers.part.0+0x200/0x2c0 [ 0.926387] run_timer_softirq+0x2a/0x50 [ 0.926387] __do_softirq+0xc4/0x3c8 [ 0.926387] irq_exit_rcu+0x7f/0xa0 [ 0.926387] sysvec_apic_timer_interrupt+0x6e/0x90 [ 0.926387] [ 0.926387] [ 0.926387] asm_sysvec_apic_timer_interrupt+0x1a/0x20 [ 0.926387] RIP: 0010:default_idle+0xf/0x20 [ 0.926387] Code: 4c 01 c7 4c 29 c2 e9 72 ff ff ff 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 f3 0f 1e fa eb 07 0f 00 2d 03 a9 27 00 fb f4 c3 cc cc cc cc 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 [ 0.926387] RSP: 0000:ffffffff8c803e70 EFLAGS: 00010206 [ 0.926387] RAX: 0000000000021bed RBX: ffffffff8c8369c0 RCX: 4000000000000000 [ 0.926387] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffffff8b0f0091 [ 0.926387] RBP: 0000000000000000 R08: 0000000000000001 R09: 0000000000000001 [ 0.926387] R10: 0000000000000028 R11: 0000000000000000 R12: 0000000000000000 [ 0.926387] R13: 0000000000000000 R14: ffffffff8c836038 R15: 0000000000000095 [ 0.926387] ? do_idle+0x1e1/0x220 [ 0.926387] default_idle_call+0x7f/0x180 [ 0.926387] do_idle+0x1e1/0x220 [ 0.926387] cpu_startup_entry+0x2a/0x30 [ 0.926387] rest_init+0xf4/0x190 [ 0.926387] arch_call_rest_init+0xe/0x30 [ 0.926387] start_kernel+0x763/0x910 [ 0.926387] x86_64_start_reservations+0x18/0x30 [ 0.926387] x86_64_start_kernel+0xca/0xe0 [ 0.926387] secondary_startup_64_no_verify+0x178/0x17b [ 0.926387] Signed-off-by: Tetsuo Handa --- kernel/time/clocksource.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index c108ed8a9804..4e8fc0a5ca9d 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -405,8 +405,9 @@ static void clocksource_watchdog(struct timer_list *unused) enum wd_read_status read_ret; unsigned long extra_wait = 0; u32 md; + unsigned long flags; - spin_lock(&watchdog_lock); + spin_lock_irqsave(&watchdog_lock, flags); if (!watchdog_running) goto out; @@ -554,7 +555,7 @@ static void clocksource_watchdog(struct timer_list *unused) add_timer_on(&watchdog_timer, next_cpu); } out: - spin_unlock(&watchdog_lock); + spin_unlock_irqrestore(&watchdog_lock, flags); } static inline void clocksource_start_watchdog(void) -- 2.34.1