From patchwork Wed May 30 00:04:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 10437429 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 180D4601E9 for ; Wed, 30 May 2018 00:07:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06B7527FB0 for ; Wed, 30 May 2018 00:07:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF4992877B; Wed, 30 May 2018 00:07:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D3F627FB0 for ; Wed, 30 May 2018 00:07:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755154AbeE3AG6 (ORCPT ); Tue, 29 May 2018 20:06:58 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:33384 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755182AbeE3AFN (ORCPT ); Tue, 29 May 2018 20:05:13 -0400 Received: by mail-pl0-f65.google.com with SMTP id n10-v6so9904665plp.0 for ; Tue, 29 May 2018 17:05:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JwxwcAPWwnBlYHc59c7Ee8T5mpLOyXsJtUYjzMM323A=; b=IDOr40kS5sqtwd+xbMBbBRk1bt8f//rpJl0B2dYUob3+S4dKkMnrnZ1EpMLamRWwEx msm4jO9nozrSixEFG8+vt8lhBSyaTBblCU3D/f600GncHODPUdyPoy+BdAm8kHPi9n80 cNxYLxi5Q4dg2q0nv8UumBGLjB+cZ9EO0S8C9mGXdCOqbubtDJFtR1oEoKHmaGK54wdq zbuqI7V1fxpvRVqyguCTW+mDcq/Z1HpxTbFjBBNsd9b1LRnaE1zkQAaLdMsqOZ+EjUwl rYmlS9PTvjxkI7Dvq3IXXJZMLGWUsmGF15W+AeAlRvCyhZjXfVONqooMbue93RD+uY0r U5/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JwxwcAPWwnBlYHc59c7Ee8T5mpLOyXsJtUYjzMM323A=; b=gaH9zFBTO7QhzTzqTeBrPq66iVjdUfel9Qvfe9vX4GitMLzUHhEVyRv50vjMOWBWfu C2O78WsTSsrIafUojxQji/CfgU7vQdFhpmDrS9LAnWK0AvpH+ogTEY63SiPZJfenl/iU G+vI8hRSSPAouYfZCH3RKBhJiPVquj5jYRtvJlmW6wPbEhxGd286ioGLro5UdxeMFKHO 4Rkw7Bw9ZHxYZEep8gOGl8JGotWa6vdra6kR1mCL7htq9HOA4WFk78n8I2TEgkrMOV24 iqj5pSiYR7zUkr8CT8Zmg0qPtAGjCWbpCeWefsR7iK51C/FziE5f9NuxBG7c9uiclkGt pcaQ== X-Gm-Message-State: ALKqPweyFPbVixhft/VkgqoAN+M/FMtlEs5aTP+qKOMBE56RQwKQ7Ps0 ALUIg4FiZFhRacRIVilYVB57gA== X-Google-Smtp-Source: ADUXVKJyyq2YjkCMn4cZO9H1wg3n4uf3S+8VH1Noh1McadFu6lHZg12x5x9Zn3MrF71C8Z/BJ9ICKA== X-Received: by 2002:a17:902:b701:: with SMTP id d1-v6mr510826pls.121.1527638712022; Tue, 29 May 2018 17:05:12 -0700 (PDT) Received: from joelaf.mtv.corp.google.com ([2620:0:1000:1600:3122:ea9c:d178:eb]) by smtp.gmail.com with ESMTPSA id w12-v6sm86979211pfi.158.2018.05.29.17.05.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 May 2018 17:05:11 -0700 (PDT) From: Joel Fernandes X-Google-Original-From: Joel Fernandes To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, "Joel Fernandes (Google)" , stable@vger.kernel.org, Boqun Feng , Byungchul Park , Erick Reyes , Ingo Molnar , Julia Cartwright , linux-kselftest@vger.kernel.org, Masami Hiramatsu , Mathieu Desnoyers , Namhyung Kim , Paul McKenney , Peter Zijlstra , Shuah Khan , Steven Rostedt , Thomas Glexiner , Todd Kjos , Tom Zanussi Subject: [PATCH v8 1/8] softirq: reorder trace_softirqs_on to prevent lockdep splat Date: Tue, 29 May 2018 17:04:53 -0700 Message-Id: <20180530000500.257225-2-joel@joelfernandes.org> X-Mailer: git-send-email 2.17.0.921.gf22659ad46-goog In-Reply-To: <20180530000500.257225-1-joel@joelfernandes.org> References: <20180530000500.257225-1-joel@joelfernandes.org> Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "Joel Fernandes (Google)" I'm able to reproduce a lockdep splat with config options: CONFIG_PROVE_LOCKING=y, CONFIG_DEBUG_LOCK_ALLOC=y and CONFIG_PREEMPTIRQ_EVENTS=y $ echo 1 > /d/tracing/events/preemptirq/preempt_enable/enable [ 26.112609] DEBUG_LOCKS_WARN_ON(current->softirqs_enabled) [ 26.112636] WARNING: CPU: 0 PID: 118 at kernel/locking/lockdep.c:3854 [...] [ 26.144229] Call Trace: [ 26.144926] [ 26.145506] lock_acquire+0x55/0x1b0 [ 26.146499] ? __do_softirq+0x46f/0x4d9 [ 26.147571] ? __do_softirq+0x46f/0x4d9 [ 26.148646] trace_preempt_on+0x8f/0x240 [ 26.149744] ? trace_preempt_on+0x4d/0x240 [ 26.150862] ? __do_softirq+0x46f/0x4d9 [ 26.151930] preempt_count_sub+0x18a/0x1a0 [ 26.152985] __do_softirq+0x46f/0x4d9 [ 26.153937] irq_exit+0x68/0xe0 [ 26.154755] smp_apic_timer_interrupt+0x271/0x280 [ 26.156056] apic_timer_interrupt+0xf/0x20 [ 26.157105] The issue was this: preempt_count = 1 << SOFTIRQ_SHIFT __local_bh_enable(cnt = 1 << SOFTIRQ_SHIFT) { if (softirq_count() == (cnt && SOFTIRQ_MASK)) { trace_softirqs_on() { current->softirqs_enabled = 1; } } preempt_count_sub(cnt) { trace_preempt_on() { tracepoint() { rcu_read_lock_sched() { // jumps into lockdep Where preempt_count still has softirqs disabled, but current->softirqs_enabled is true, and we get a splat. Cc: stable@vger.kernel.org Reviewed-by: Steven Rostedt (VMware) Fixes: d59158162e032 ("tracing: Add support for preempt and irq enable/disable events") Signed-off-by: Joel Fernandes (Google) --- kernel/softirq.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/softirq.c b/kernel/softirq.c index 177de3640c78..8a040bcaa033 100644 --- a/kernel/softirq.c +++ b/kernel/softirq.c @@ -139,9 +139,13 @@ static void __local_bh_enable(unsigned int cnt) { lockdep_assert_irqs_disabled(); + if (preempt_count() == cnt) + trace_preempt_on(CALLER_ADDR0, get_lock_parent_ip()); + if (softirq_count() == (cnt & SOFTIRQ_MASK)) trace_softirqs_on(_RET_IP_); - preempt_count_sub(cnt); + + __preempt_count_sub(cnt); } /*