Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp3072470ybd; Fri, 28 Jun 2019 02:20:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqy1SZxzzKJyqFJtvTYo504JNl2J7CI/VawYLgQjd9NXf+gRWuq38eqEX37YhWJyKPwFsvnI X-Received: by 2002:a65:5c88:: with SMTP id a8mr8115977pgt.388.1561713637036; Fri, 28 Jun 2019 02:20:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561713637; cv=none; d=google.com; s=arc-20160816; b=vCLwb0AfJm9jPTvs4Cdhkk6WMCdOBp5BefInvgdp2obOxZuT2oaR39D8nkJDlV45NC NWeSKwini6fGu+K6kQ2VvbYeNI1/C2xtMfLgyyGfwiycoO23yV6dcwKWwkgi3rM43IzW vRNNi2B84BRuFZjUKFT6PrCHiMEInwFw10WwazwkH8TogXLjpJttCIhbDmaDqA/J1J6m 1fum/rVr7Kyu92K0AOURKOIUU/U9cIEI9SzjychWbX4mo6BjQA9g5uvJ9aZwvOW24+LD SgCYO+Wm07NoJmn0ITRHxcg440nzZGs/roaOuEuitFRKuDZVrvZwU0HTof08JxRQJqlS tnEw== 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=kx50gKxxvtisjg2F9jTuTtWq9FlFRr48sDE6Gi1A0+k=; b=U+3PD1K/JCN0zKmHQzU6ozZtgh67x2aElFK2kDdqw4H8PaxPTpLwfP1j/JbieKhdgQ 57TYBLSnfX/tiETP+aPqs+THStR9q2rMUkwVDPfOVJCqynaqGmLmuPKOkVn8dO0bYue9 DVXbz97RXk8rF74IzTdfCokNC+VFMBU9d/MoFI/rHYrLPdD9DK7GCzrshoihD0jrOtAZ I3vkVMGROUXYan9nj1LzyK4jLnQkHowsjS6FbxBbBK/x9iFG9QDGSbtDNm+gzRxpXK/D 8OAI8Flwxy6G2OuciiEedqr5IZwROntfuYnPgdWaBwXrssWlMWY/fW87YCsoJY+d4lx3 DbDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=W1fXxgpa; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b19si1913770pfi.175.2019.06.28.02.20.21; Fri, 28 Jun 2019 02:20:37 -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=@gmail.com header.s=20161025 header.b=W1fXxgpa; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727185AbfF1JR7 (ORCPT + 99 others); Fri, 28 Jun 2019 05:17:59 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:45109 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726781AbfF1JR5 (ORCPT ); Fri, 28 Jun 2019 05:17:57 -0400 Received: by mail-pf1-f193.google.com with SMTP id r1so2652661pfq.12 for ; Fri, 28 Jun 2019 02:17:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kx50gKxxvtisjg2F9jTuTtWq9FlFRr48sDE6Gi1A0+k=; b=W1fXxgpa2QJmCiq0E/w5BYay+5rnTBm7AlUrJnOR69m2kZJVJTxibswftMXUZH9Nz9 2M5VerT/2/t9Hb/RwULHuBcwHXDD2K+yi0hZGhZdhlSfZXUKV+nPZgRccHQzfNt2n5j4 d7iwpNdXM1L52U3h+QJelMxmHL2TWk1AcKcM/NynCHSG7/B1OGG/g7zvzkgOkE3LQbmx PASUcNdRlxAjVx13w7mZqxV/jXXXUAHeZdz/JO4mVTlY95AfNAlPsUhF/BH4nY8HFrvv QSY2t7CO67m53JdmjfMd7jl22cpCRHDbFk42JBn5TbGn/YmHh43kKXnD1FqWQ2nSzLj/ VVOg== 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:mime-version:content-transfer-encoding; bh=kx50gKxxvtisjg2F9jTuTtWq9FlFRr48sDE6Gi1A0+k=; b=D1lIbfbUziaqVXFolZLhC21WLY9s0UfvIoJNdu7+2xOqa3JMyn5gYbIDHZoEbQ1Nd2 XFXtrCFn4khkLy0KKU6KS82fj9lN6zMLttL+WW90CC+G3Xsowiykalh6HhUiz2Crt8N/ e1iD3eOY9mPjkof/FcGlqPgFBbErszHX6aSEHrP6OnTL594d/BzIH1ojXuodj0EUTVco VRplYVzuLQwRS4py0vNGFVye539QuF2FY1SIq4eEdwPdQArWFaJuKStRDTD8ALw97Egg 6M6BegUPpFYWNI5POm5RLylDZME3nfmxgsGElu9l7vZaJ19q4VkbA/2fJkNFjstV3a7o Ygkg== X-Gm-Message-State: APjAAAVbkRpzrEwVNBv+Hw2bbQQVs8XEwvPWN3qc3W4zHD2IBr0UTiWq 2cDpdbUMX7+c0VY3yq4/vBs= X-Received: by 2002:a63:6155:: with SMTP id v82mr8132865pgb.304.1561713476075; Fri, 28 Jun 2019 02:17:56 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id x65sm1754521pfd.139.2019.06.28.02.17.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Jun 2019 02:17:55 -0700 (PDT) From: Yuyang Du To: peterz@infradead.org, will.deacon@arm.com, mingo@kernel.org Cc: bvanassche@acm.org, ming.lei@redhat.com, frederic@kernel.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, longman@redhat.com, paulmck@linux.vnet.ibm.com, boqun.feng@gmail.com, Yuyang Du Subject: [PATCH v3 30/30] locking/lockdep: Remove irq-safe to irq-unsafe read check Date: Fri, 28 Jun 2019 17:15:28 +0800 Message-Id: <20190628091528.17059-31-duyuyang@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20190628091528.17059-1-duyuyang@gmail.com> References: <20190628091528.17059-1-duyuyang@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We have a lockdep warning: ======================================================== WARNING: possible irq lock inversion dependency detected 5.1.0-rc7+ #141 Not tainted -------------------------------------------------------- kworker/8:2/328 just changed the state of lock: 0000000007f1a95b (&(&host->lock)->rlock){-...}, at: ata_bmdma_interrupt+0x27/0x1c0 [libata] but this lock took another, HARDIRQ-READ-unsafe lock in the past: (&trig->leddev_list_lock){.+.?} and interrupts could create inverse lock ordering between them. other info that might help us debug this: Possible interrupt unsafe locking scenario: CPU0 CPU1 ---- ---- lock(&trig->leddev_list_lock); local_irq_disable(); lock(&(&host->lock)->rlock); lock(&trig->leddev_list_lock); lock(&(&host->lock)->rlock); *** DEADLOCK *** This splat is a false positive, which is enabled by the addition of recursive read locks in the graph. Specifically, trig->leddev_list_lock is a rwlock_t type, which was not in the graph before recursive read lock support was added in lockdep. This false positve is caused by a "false-positive" check in IRQ usage check. In mark_lock_irq(), the following checks are currently performed: ---------------------------------- | -> | unsafe | read unsafe | |----------------------------------| | safe | F B | F* B* | |----------------------------------| | read safe | F* B* | - | ---------------------------------- Where: F: check_usage_forwards B: check_usage_backwards *: check enabled by STRICT_READ_CHECKS But actually the safe -> unsafe read dependency does not create a deadlock scenario. Fix this by simply removing those two checks, and since safe read -> unsafe is indeed a problem, these checks are not actually strict per se, so remove the macro STRICT_READ_CHECKS, and we have the following checks: ---------------------------------- | -> | unsafe | read unsafe | |----------------------------------| | safe | F B | - | |----------------------------------| | read safe | F B | - | ---------------------------------- Signed-off-by: Yuyang Du --- kernel/locking/lockdep.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index c7ba647..d12ab0e 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -3558,8 +3558,6 @@ static int SOFTIRQ_verbose(struct lock_class *class) return 0; } -#define STRICT_READ_CHECKS 1 - static int (*state_verbose_f[])(struct lock_class *class) = { #define LOCKDEP_STATE(__STATE) \ __STATE##_verbose, @@ -3605,7 +3603,7 @@ typedef int (*check_usage_f)(struct task_struct *, struct held_lock *, * Validate that the lock dependencies don't have conflicting usage * states. */ - if ((!read || STRICT_READ_CHECKS) && + if ((!read || !dir) && !usage(curr, this, excl_bit, state_name(new_bit & ~LOCK_USAGE_READ_MASK))) return 0; @@ -3616,7 +3614,7 @@ typedef int (*check_usage_f)(struct task_struct *, struct held_lock *, if (!valid_state(curr, this, new_bit, excl_bit + LOCK_USAGE_READ_MASK)) return 0; - if (STRICT_READ_CHECKS && + if (dir && !usage(curr, this, excl_bit + LOCK_USAGE_READ_MASK, state_name(new_bit + LOCK_USAGE_READ_MASK))) return 0; -- 1.8.3.1