Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4932978yba; Mon, 13 May 2019 02:17:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqx5+dbGlGEyDc/EE3FzDNFtISlbME/652lxnpUhgKxoHU3UXc0sXVQ6g2UC2Ozi/IVjlOE/ X-Received: by 2002:aa7:99dd:: with SMTP id v29mr32740237pfi.252.1557739030771; Mon, 13 May 2019 02:17:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557739030; cv=none; d=google.com; s=arc-20160816; b=bCNDmxyIBiSIPeUbhvpc2UZDGc95oupPcJuh8e2rlYstotEkgjYpKAKtv79kisYNem 76/vrvVP77hI/RqACx39NuHdyCqRVB+OZsY5DUgqyPG7Zp5ML+0hfsT6aBTRikVKeEP0 iZ2eWqjXMdoACgGfDFpmHHy3lWa788C5hf0s7P2szMS/tTtVXXSPIxnF5/cLlgd5+UGM i5oq6l3hGpIWb+uLMNyI7HjIH19y6GC2o47V95srmsJrRMKqLn1wT7uVLOSRjldI9mLm XscsjOSclp0KlIsrqW229JMpxL90KvXnHQbc2XqWI050cCb2/1fPPY1zw6OU6EJfjpms TaOQ== 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=XquRGMdkWaM/DcOHkh5rTCme/nLS8Vh3kbKhYIl4Twg=; b=H4nzXPjBD8tV9B+f6gL6XPPO/uIDZT3DBgSeCEo/jNRV14OuTxuOymkUKBV4yfKZKt cWjifRXnXfd0GAIS6tYYFyJQ8AZhqDZ4thy7PcQDjjevgvGRb5OmlSmTQ9VM6kla5B7l d6Z+a7duvpb1SUw1DqEeOOoO0pDhThHbJX8X/urdtyLjn1BJ+W3tSsOuBhozc2Hwsgmn 2nHPMn0Pp09qxER2eIPYb7u2g7ZHDisVnEv7JfUs/Z8OObltxlqZ/MZdOduCX5lMipRz laXFbgHKP6XTjVTpxBdWfHRy7lYwl+zLyUySJtsGXxnCn2hcnV+NiGAExsidxjFlAmbx 9AWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="gz/tnqju"; 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 h12si15051948pgs.151.2019.05.13.02.16.54; Mon, 13 May 2019 02:17:10 -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="gz/tnqju"; 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 S1728800AbfEMJOQ (ORCPT + 99 others); Mon, 13 May 2019 05:14:16 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:44379 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728793AbfEMJOO (ORCPT ); Mon, 13 May 2019 05:14:14 -0400 Received: by mail-pf1-f195.google.com with SMTP id g9so6850860pfo.11 for ; Mon, 13 May 2019 02:14:14 -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=XquRGMdkWaM/DcOHkh5rTCme/nLS8Vh3kbKhYIl4Twg=; b=gz/tnqjukIUD4RWThkSaxWdDlmQh8HywQm3QrUdGpOG5v4q6hy+r35pZBmCLpNBvP1 VysEnCoJv098YRymkvsVjA+XH6rkRFBQXsGU1til8+7jkjk23m0Zn+foSPF25SDsT2lG fGDmhPTdzTFzZTSiuS9neZvUS96xjKdCie9CQdRMtOuH4K9VNuALxjoiGObDmNYBlu6i Sde909IVUyXG1EYqxDALrJ2m4pKXKNO3slb58x2WrxBcnjvi3Q9efNZLmiG8d9WK6IAx FNIxQPYHLSDb+zGFh7HJrH4a8OMPz4Xn6b+wLFGQsLbn4RnpNt8hEU+DeNezPjNHWa7O E+DQ== 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=XquRGMdkWaM/DcOHkh5rTCme/nLS8Vh3kbKhYIl4Twg=; b=BPBV+RWSMQOCwWUouEQH00d4CVhEBEke3a+cQwVUb/dYEgMXXgE3GXIbUsL5/1ETu6 AgE1/6i5irEkkEzT8YC6k7ClJq+Dt+/RK9A7waXrAUJCjXd1IyNvea64tvDbhhvbdI0q CTbje8DYn6MIER+bLbSk/WH134zfgrwcBT94G3iQABXqfyQ0TlsvpxcpqHq9nbsXQulF BE5z4M1Ib07q9S8cFtDCXfrnI2YyWp/CaG9oenvIO8mC5arbwHcYuD9Rf1ixfPviu+UI nQrILEmJq36nl1hVbIxwb2gkVdgcbluOGe4kIUP7gFfdkr5mYnL3pbHXxrOHAbelkCzx JEPw== X-Gm-Message-State: APjAAAWbFI9ZnCxPHI3Q1TZZV+Lt5Il/6CjPX53ire+n5Dng1vU+w42e 4tBlYqh3Ium8drrgeCqBr2Y= X-Received: by 2002:a63:555a:: with SMTP id f26mr29982607pgm.197.1557738853804; Mon, 13 May 2019 02:14:13 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id n18sm35500837pfi.48.2019.05.13.02.14.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 02:14:13 -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, boqun.feng@gmail.com, linux-kernel@vger.kernel.org, Yuyang Du Subject: [PATCH 17/17] locking/lockdep: Remove irq-safe to irq-unsafe read check Date: Mon, 13 May 2019 17:12:03 +0800 Message-Id: <20190513091203.7299-18-duyuyang@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20190513091203.7299-1-duyuyang@gmail.com> References: <20190513091203.7299-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 69d6bd6..62b454c 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -3446,8 +3446,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, @@ -3493,7 +3491,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; @@ -3504,7 +3502,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