Received: by 10.192.165.156 with SMTP id m28csp1395265imm; Mon, 16 Apr 2018 21:09:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/eYO/YUKgHEd+3ZhpdsUJF43Sl1sGgkoPyQhfAYbOxKyad2rR5bvpNxp982D3gX4Z+YGaR X-Received: by 10.98.204.214 with SMTP id j83mr532612pfk.182.1523938187460; Mon, 16 Apr 2018 21:09:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523938187; cv=none; d=google.com; s=arc-20160816; b=SN9CKOeB63stgJVMIol8ZggTbhg39zjq1POdApWOwGI4js6j+x+Sq35hhB6pf707WN XxDZ61LuMBXHsVhzEsw/XfaVgCCcwK5Mi2R6KiYwUi11JDb5En6tKUSxJb+WKgTanLFj q7yIMGj2ZXvAADZGjOZu0s8DESpgUEDJjcVtOA1w61sCLA1Iwrf2ntJtN3ll9Cs2HhLJ 1SL09+IPV32LSXTLBdy7OHBTczxZ7hFyJAyHErAuK9sT3OfVK0NxnIhlmsg+jdvUWSWZ NJNqg3pJDu7oKn5gqx+NrDVVznOtFpEQeNC/6yuVNDlzaHiaKojg0V2JLFs+FFnssaK0 Z4ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=wQ9pAUng/6lsWzkZnVMtuony89x+fW5Jfb1S8hGWFoY=; b=JPrX++qU+JHpJzfxnxqf1iysUFEctbT/Vhrxg+IJ8aStNdpVs1jsRohFhBukviV1Y6 Xtsi8PQr0aqGZ29bLtPeBUYVL3Wv/c5D3IsDT44FPWruw9Y+VTvPcCDPP90fgmrL1esZ QMRfp1Qnt4gfBl2QUgs8aPVKolxVHGNAYXrS5Ht6ZYfuzd0PcQ91p/vCWlttRIvCPXNM yQhyF1layalnNKn4hHj6XE2QhyJKiEgsLk93f1ACC6umAWtLtVxVHi84WAGTnQDUqsjQ io/70uFfJx9Wx+6pLzCKjC57+AfXXEP8geycW1kUQ73q+ZlkTtpCqfx8K8xox+Z7iaRy GgwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=UWFy9WPv; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i186si12208549pfg.218.2018.04.16.21.09.31; Mon, 16 Apr 2018 21:09:47 -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=@google.com header.s=20161025 header.b=UWFy9WPv; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751907AbeDQEIS (ORCPT + 99 others); Tue, 17 Apr 2018 00:08:18 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:33727 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750744AbeDQEIN (ORCPT ); Tue, 17 Apr 2018 00:08:13 -0400 Received: by mail-pg0-f66.google.com with SMTP id i194so4810630pgd.0 for ; Mon, 16 Apr 2018 21:08: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=wQ9pAUng/6lsWzkZnVMtuony89x+fW5Jfb1S8hGWFoY=; b=UWFy9WPvHu4FOd7Hlzh7uwIjk5y3dXcJA3S0kJPvqgQ+V0wvT6IoST7JiN0eFwKBcq Fl+auXE5Wrk64wKxkXAxDgIZuTrwslA7S3T5mSpZklAAZkouAj/5bnSWrp1CXqlrsAux TNUv/ue9/S1A8OATtrI2ruXl1lWARSN3CVttJWpVLWza2WKWzn4nsYvZ/swtdGKnDsrC AKUjv1ifSuZw94bR1OM7cVv62Dx4x8tvyKjzu69hXnR8yoINetfyDTYizHU8zq2O8wPt JK7qzKjnPu2u6HqQpR4eACYb5BZgjA4ELNPRvVhsaPdeUfBaOt5NsccDZORlnlA0BMrJ gdVg== 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=wQ9pAUng/6lsWzkZnVMtuony89x+fW5Jfb1S8hGWFoY=; b=b2kKD8z+8ts5kPfHrTeNsg6cPM4O74anbpSYRRVn35nSEZLz4A1ZRaa+FloQFx12wB HnOzmah/7EL+2Rf4qKWv8eTHDg+vmyB/B+EQVLVND+mDXKXXUvcCmeQDJCogprHqemeg kHUrMUr8EgrRm3gJCJzZDltWVNMSUOu2cRoBJU53SZK3OgYSq1IkkkzTOJ/mYZuQrL/E qQnioYoSt8VMOeBT64+jo4EwhjOI105K5Yfexr+KXzTqyJ5HBWaKlJYU06dU7t7RlvIg 5E9rStFHLHGjROREifdLoXVGpHQDHxE4ewvbUKNf90cpHw5mLULDFAQT9WW3btaI3kpA LFLw== X-Gm-Message-State: ALQs6tAC566GZcILcZGdTklGXVW3JOhUzXlEeyxapTg30NuvdmH5W/E9 /v21nFDp2IFq33EXiRT7k6zBSskV8xs= X-Received: by 10.98.157.199 with SMTP id a68mr498182pfk.237.1523938092097; Mon, 16 Apr 2018 21:08:12 -0700 (PDT) Received: from joelaf.mtv.corp.google.com ([2620:0:1000:1611:2dd1:700f:d2f3:1711]) by smtp.gmail.com with ESMTPSA id j11sm23504686pgc.91.2018.04.16.21.08.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Apr 2018 21:08:11 -0700 (PDT) From: Joel Fernandes To: linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org Cc: Joel Fernandes , Steven Rostedt , Peter Zilstra , Ingo Molnar , Mathieu Desnoyers , Tom Zanussi , Namhyung Kim , Thomas Glexiner , Boqun Feng , Paul McKenney , Frederic Weisbecker , Randy Dunlap , Masami Hiramatsu , Fenguang Wu , Baohong Liu , Vedang Patel Subject: [RFC v4 2/4] softirq: reorder trace_softirqs_on to prevent lockdep splat Date: Mon, 16 Apr 2018 21:07:46 -0700 Message-Id: <20180417040748.212236-3-joelaf@google.com> X-Mailer: git-send-email 2.17.0.484.g0c8726318c-goog In-Reply-To: <20180417040748.212236-1-joelaf@google.com> References: <20180417040748.212236-1-joelaf@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently there's an issue which is not always reproducible, where the softirqs annotation in lockdep goes out of sync with the reality of the world and causes a lockdep splat. This is because the preemptoff tracer calls into lockdep which can cause a softirqs invalid annotation splat. The same issue was fixed in local_bh_disable_ip. /* * The preempt tracer hooks into preempt_count_add and will break * lockdep because it calls back into lockdep after SOFTIRQ_OFFSET * is set and before current->softirq_enabled is cleared. * We must manually increment preempt_count here and manually * call the trace_preempt_off later. */ I am not fully sure why the issue is reproducible with my patches easily, but it seems like the same ordering issue can exist so we ought to fix it. Cc: Steven Rostedt Cc: Peter Zilstra Cc: Ingo Molnar Cc: Mathieu Desnoyers Cc: Tom Zanussi Cc: Namhyung Kim Cc: Thomas Glexiner Cc: Boqun Feng Cc: Paul McKenney Cc: Frederic Weisbecker Cc: Randy Dunlap Cc: Masami Hiramatsu Cc: Fenguang Wu Cc: Baohong Liu Cc: Vedang Patel Signed-off-by: Joel Fernandes --- 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); } /* -- 2.17.0.484.g0c8726318c-goog