From patchwork Thu May 24 01:21:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 10422607 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 7F9B96016C for ; Thu, 24 May 2018 01:24:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6670A292E9 for ; Thu, 24 May 2018 01:24:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 584C4292F2; Thu, 24 May 2018 01:24:25 +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 CDE8E292E9 for ; Thu, 24 May 2018 01:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935218AbeEXBYY (ORCPT ); Wed, 23 May 2018 21:24:24 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:41622 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935331AbeEXBW2 (ORCPT ); Wed, 23 May 2018 21:22:28 -0400 Received: by mail-pl0-f68.google.com with SMTP id az12-v6so14075996plb.8 for ; Wed, 23 May 2018 18:22:28 -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=AEGV6heGcjUpaeyw6p8+XTTxa7HsHy0/1gDIOZxxLL4=; b=Kj3KongcPCtBlTybgluhLNJBp7qNq6XTR7FhSfPz9R8iZWczQrEHF9Ll76H3D05eBs H/BX/2sVxsA3QedCN50beaUNT97pKLeVKDEdYzSozPs0+OiCU8oG3h4it9WhFZzXqd1N iwcRXx7S75lFmcn04ZEdBU/9PQy05Tkn1eGotvSgFRzBrNQmPlIwqih0pDLSpk8rgpn9 P2J40c/LUI8GXKaXM0PR5hcf5m2DIUSHA23siTECU4zTJSRBNMhHnxel48q6smm7LBXG 2dN3NOKolJ8uggS1KMTWrdaY6vy8eXGOru26lvr0Ic7jZyGlUofXQMTuievmFH/gO9Zn zsdA== 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=AEGV6heGcjUpaeyw6p8+XTTxa7HsHy0/1gDIOZxxLL4=; b=dGM6CiIZqci1Xkuc3DIjnnryojH39CY4R1PFT4yPj4VNFaFAu2jo7e0sgO/ryw1zvf hMKKgk2eXI82XDm8slCW1zu/A9ZingJgeyM4wEEGvpZuGg6dZXlkag8b1ssy/xl8IJrj fbQSwTLV8YR40JUjKO20aedTNNPvYoZgsvFuPj3vTb/kERTCvOxkfNSl9CMMLxqTnhg+ YI2PWFUkr4l3mxvjDMqhtOhD7/FBArnJL8HvzeCqqW2G0yNy3C2XyCnPD9BmjuY3ZgYp MlEaZNVIm2BolDPlOKAfu+ZOQR6ahk6f/AQHLwalH3OGH+MZxaHy81bxV78Vp84+aIzs QrxQ== X-Gm-Message-State: ALKqPweXRtqV34nfZ4oD81yNXcSCLPZSaSNDoz3u1EYJy5fydqZVCz9k igBPO/r+nwOuHJTJSFcUNxMoHw== X-Google-Smtp-Source: AB8JxZr6+Tssw51LzANFsnZX56Z829KACSQrKctUcG/E6WbE/EHk0tarOAuUyY2EHS8Mf3+foXTxJg== X-Received: by 2002:a17:902:6b09:: with SMTP id o9-v6mr952185plk.256.1527124948081; Wed, 23 May 2018 18:22:28 -0700 (PDT) Received: from joelaf.mtv.corp.google.com ([2620:0:1000:1600:3122:ea9c:d178:eb]) by smtp.gmail.com with ESMTPSA id g15-v6sm26070996pgv.58.2018.05.23.18.22.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 May 2018 18:22:27 -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 v7 1/8] softirq: reorder trace_softirqs_on to prevent lockdep splat Date: Wed, 23 May 2018 18:21:50 -0700 Message-Id: <20180524012157.181277-2-joel@joelfernandes.org> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-goog In-Reply-To: <20180524012157.181277-1-joel@joelfernandes.org> References: <20180524012157.181277-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); } /*