Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1214845ybn; Tue, 24 Sep 2019 16:53:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqzvCEyOl7sITK3Lx2EDchJmhdwiS6v7efh9TF28//THOffuBg/C54Afj4bPA7seVfTJI7Q4 X-Received: by 2002:adf:cf0c:: with SMTP id o12mr5477443wrj.30.1569369186910; Tue, 24 Sep 2019 16:53:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569369186; cv=none; d=google.com; s=arc-20160816; b=aLMBM0S4BGIgeX73QQMum+yZ6J9dtxUDE1tITB9VrVpRqLKsSRICF6m4o7LXYa+vZc 7XXnPhCQW6ValgLxL1lQ2N37JXNOFYTA+Oep0cF42pt1o1/X7fZmrDRu32xsQJDWsYI4 ZsliEXef5cYdBiEXmwzFT7ILJhib0MuZ8jpFVn3PZlHZCcbaZz/1a6BVBacBl9M17ZO8 d78K8FCK1LeLomIVbRDUlUXIObVOdSOTcM8idG58tyBBuTHde9Qz6vj3MScTLczsJt3l VJD3yjGmt4oSedyo+IBRbqyjco8hrw9HyoO2vrrsCM1bo/XOjWQBaxrgeD8vcngcEh+y So+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4Tv3snr1zSoy/FL+Lxyf39qfLSRgWexEX03euNVhszE=; b=1AjxQH2dI6LkaBko1RF9CjEehoyD+Wf7LVIVMX7YYIyB+lM9o6cwncM2C59p0Wqdyv 2tqdYbvdQjoVcS5glwC/D2uWzOSKXvz5TMOa2ZFFsqITg+8OEL7PopuIhfcpCupHvqVR Hhx0/2nDYc1A15VN7LObbqtuvpICUANoRLCze+R6+e4s3drk1mPYc5HY1UxpwN5FK0dY HHceesMI1RQdj9NF6rQ9mQDGMiFDCxZrTxvILcrGypCEiDXH+T9QN3/H0+EMj7WbVD1p I8wbU2R6L/nUL5JiaJnGIGtTsFQd+Lx73pmlbIveoRRTgQ2FdK5tV+SiTt/JGr3rxoVf NOFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=buPNM9uV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v22si1983845ejk.297.2019.09.24.16.52.16; Tue, 24 Sep 2019 16:53:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=buPNM9uV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439238AbfIVTg4 (ORCPT + 99 others); Sun, 22 Sep 2019 15:36:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:41940 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389775AbfIVSqC (ORCPT ); Sun, 22 Sep 2019 14:46:02 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ADD9A20882; Sun, 22 Sep 2019 18:46:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569177961; bh=TO36sxAHD4Bn+D3eeOaeB/DIge7EXOLy0Ew7V3AN8EU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=buPNM9uVZrKkoVnYUQaR088r2iZnA/BL9A/P8THMGvHJ7YSjEb+YE9rTOINGlerYs 6rJ0vLQebfSBevVNE2hIDL8Sayx84W7slfmgkqf8VuyY2Z2mi3sLAEyP4q/zqukM9Q kziZBgykktNmfQ16h3bCOkqjscUOf7jlr+SXCO/c= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Peter Zijlstra , Frederic Weisbecker , Thomas Gleixner , Ingo Molnar , "Paul E . McKenney" , Sasha Levin Subject: [PATCH AUTOSEL 5.3 065/203] idle: Prevent late-arriving interrupts from disrupting offline Date: Sun, 22 Sep 2019 14:41:31 -0400 Message-Id: <20190922184350.30563-65-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190922184350.30563-1-sashal@kernel.org> References: <20190922184350.30563-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra [ Upstream commit e78a7614f3876ac649b3df608789cb6ef74d0480 ] Scheduling-clock interrupts can arrive late in the CPU-offline process, after idle entry and the subsequent call to cpuhp_report_idle_dead(). Once execution passes the call to rcu_report_dead(), RCU is ignoring the CPU, which results in lockdep complaints when the interrupt handler uses RCU: ------------------------------------------------------------------------ ============================= WARNING: suspicious RCU usage 5.2.0-rc1+ #681 Not tainted ----------------------------- kernel/sched/fair.c:9542 suspicious rcu_dereference_check() usage! other info that might help us debug this: RCU used illegally from offline CPU! rcu_scheduler_active = 2, debug_locks = 1 no locks held by swapper/5/0. stack backtrace: CPU: 5 PID: 0 Comm: swapper/5 Not tainted 5.2.0-rc1+ #681 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS Bochs 01/01/2011 Call Trace: dump_stack+0x5e/0x8b trigger_load_balance+0xa8/0x390 ? tick_sched_do_timer+0x60/0x60 update_process_times+0x3b/0x50 tick_sched_handle+0x2f/0x40 tick_sched_timer+0x32/0x70 __hrtimer_run_queues+0xd3/0x3b0 hrtimer_interrupt+0x11d/0x270 ? sched_clock_local+0xc/0x74 smp_apic_timer_interrupt+0x79/0x200 apic_timer_interrupt+0xf/0x20 RIP: 0010:delay_tsc+0x22/0x50 Code: ff 0f 1f 80 00 00 00 00 65 44 8b 05 18 a7 11 48 0f ae e8 0f 31 48 89 d6 48 c1 e6 20 48 09 c6 eb 0e f3 90 65 8b 05 fe a6 11 48 <41> 39 c0 75 18 0f ae e8 0f 31 48 c1 e2 20 48 09 c2 48 89 d0 48 29 RSP: 0000:ffff8f92c0157ed0 EFLAGS: 00000212 ORIG_RAX: ffffffffffffff13 RAX: 0000000000000005 RBX: ffff8c861f356400 RCX: ffff8f92c0157e64 RDX: 000000321214c8cc RSI: 00000032120daa7f RDI: 0000000000260f15 RBP: 0000000000000005 R08: 0000000000000005 R09: 0000000000000000 R10: 0000000000000001 R11: 0000000000000001 R12: 0000000000000000 R13: 0000000000000000 R14: ffff8c861ee18000 R15: ffff8c861ee18000 cpuhp_report_idle_dead+0x31/0x60 do_idle+0x1d5/0x200 ? _raw_spin_unlock_irqrestore+0x2d/0x40 cpu_startup_entry+0x14/0x20 start_secondary+0x151/0x170 secondary_startup_64+0xa4/0xb0 ------------------------------------------------------------------------ This happens rarely, but can be forced by happen more often by placing delays in cpuhp_report_idle_dead() following the call to rcu_report_dead(). With this in place, the following rcutorture scenario reproduces the problem within a few minutes: tools/testing/selftests/rcutorture/bin/kvm.sh --cpus 8 --duration 5 --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y" --configs "TREE04" This commit uses the crude but effective expedient of moving the disabling of interrupts within the idle loop to precede the cpu_is_offline() check. It also invokes tick_nohz_idle_stop_tick() instead of tick_nohz_idle_stop_tick_protected() to shut off the scheduling-clock interrupt. Signed-off-by: Peter Zijlstra Cc: Frederic Weisbecker Cc: Thomas Gleixner Cc: Ingo Molnar [ paulmck: Revert tick_nohz_idle_stop_tick_protected() removal, new callers. ] Signed-off-by: Paul E. McKenney Signed-off-by: Sasha Levin --- kernel/sched/idle.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index 80940939b7336..e4bc4aa739b83 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -241,13 +241,14 @@ static void do_idle(void) check_pgt_cache(); rmb(); + local_irq_disable(); + if (cpu_is_offline(cpu)) { - tick_nohz_idle_stop_tick_protected(); + tick_nohz_idle_stop_tick(); cpuhp_report_idle_dead(); arch_cpu_idle_dead(); } - local_irq_disable(); arch_cpu_idle_enter(); /* -- 2.20.1