Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp318643yba; Thu, 16 May 2019 01:03:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqyTuib4+eH4lkX3+j94kFE6oFefSgujB7ZWtXoU0TSys2C4jPG/Nwqdcvh54jsyRZ/4/g4Q X-Received: by 2002:a62:a511:: with SMTP id v17mr25694860pfm.129.1557993799765; Thu, 16 May 2019 01:03:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557993799; cv=none; d=google.com; s=arc-20160816; b=SyHrLchZenZHuFSiTRn396qwJaL9tEbcB8bjfLWM+0HbuT0tK2m/x5k0E2yThIXF4G Oq7DjOxWM/Q6ABc84fThbD6TSPM4slq0d5F3q+g+gjS9qQF/11wnSuCCXuOqe17ylqqX ar8+oHIpQpTvxE1sAGafy+W5YAxJgoe0ZwV0CE1PBlHMUpdLz6soe8MjSKgA09oFFNfn 5XFVb2KMSXUWUh+CnIa3lkc/Sk+XbdzZBOuo/a2UyN97tKEHPnRsiNOZ9i/G7BZSCU1d 9wALTaWqFssX25CecGM1c0sVsNUlaQr1El30UkUzJmEWZGlOLfMbZr4tSmOZhMnoKf2O 5czQ== 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=Sq2YROOG33D+u2oBi0Lgr2XAulwfC9GYtiKatyA1xOs=; b=u6IrusLvRaTiE0j/aKifs9CwYOfTO4pqHeeikoHOUNbucxK2EA/wAuUWnbk2Hz0qjw DceIJ2qvmZCdbLYlrTQQ7zl4zoNzBB+xuuFfW1X0/8jS3f/q4eHrsEHMACiEwvOMO8EM rxFfHyboeP3/such1PVCZGWBO8OHY5k1lxwkiGWmyLH1R1PBWJTEYR8hNX4RklcIwwXJ Rtsuqjvb1kgcxYS0gKyzqLVo67IGIboDN29G9cQteebGIrxAPIsR4lw859XteRc38E/7 1X9ImqtScQNi1Pp2r52DpOp6XBFEqtR6nPEkMr9L5OiBD2wcsDJl9enoVXalNmm/OJ6m gkxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bSrlzhhM; 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 q8si4203131pgf.3.2019.05.16.01.03.04; Thu, 16 May 2019 01:03:19 -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=bSrlzhhM; 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 S1727120AbfEPIBZ (ORCPT + 99 others); Thu, 16 May 2019 04:01:25 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:34486 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726537AbfEPIBY (ORCPT ); Thu, 16 May 2019 04:01:24 -0400 Received: by mail-pg1-f194.google.com with SMTP id c13so1174243pgt.1 for ; Thu, 16 May 2019 01:01:24 -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=Sq2YROOG33D+u2oBi0Lgr2XAulwfC9GYtiKatyA1xOs=; b=bSrlzhhMwBpQBQXKjnZlbAg/vnr5pwaiYuEH8pV1TQZNY2YiptYkc4UTPWn/fo6jzb b+or5p2NMw7B793zcbrKaL0IBpygyfctAYMA7wCEMNC3z2KKRvtdmqWdv9aYzAk9Wclr HjMnX0hwdwGAteJiGeAvzgEhTpMnLF09sRQxFRStRTNYC8fciBGNTX0scVs9c898jcTd ks8GoEk8V5EaJc7U9vxSbTcYl3YG3oI40aAlLmaD2v2aMNb3kblkfr5PjhAC8FGxSzvh GRe3Fa7E5NMAUyD3hNZG7If3s2bIF/WdZ18KpXfwKa30Rx/YCttyfXOGVNA+SH88eiXI IZJA== 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=Sq2YROOG33D+u2oBi0Lgr2XAulwfC9GYtiKatyA1xOs=; b=BG+RXfdHjYgXs7vgwh+i6+7qHocSPinHzS95DlkTttnceKabbZGzjae1o/rcW+MHr6 RFPB8DxtiguGGXgunU1SnDEGGNE6Aav5sylzEud+Db+Dmzy6DOJCaV0Z5iUZS9NgWrGv HpjLyl8LatcdV74ehgfNrl6mwnQ+HIDZwI3z8JQBWE9a11G+UF7uBktuFJ4iKvI24diq yf9PEcyw9iHeMin5N33m+7cgdWiDSEynl7o3Rf2QSe273A68heEjXsRc6xrH2OOnOmbh tg79bY8Ol/sWKjVdMLl6T66fJVL6vLzQVGLGRQt+ptpSZgGsNzZyOpu47I+9GJMMCeQm WHng== X-Gm-Message-State: APjAAAUlofGHZwY+Ku2eBbUiS00FsXuTI7wyAuLks2ZT4lsbnldnNDTK Mhu2Ynix9rBnkm5jZiYrCqM= X-Received: by 2002:aa7:8e0d:: with SMTP id c13mr53533990pfr.193.1557993683860; Thu, 16 May 2019 01:01:23 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id p7sm2051471pgb.92.2019.05.16.01.01.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 May 2019 01:01:23 -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, paulmck@linux.ibm.com, linux-kernel@vger.kernel.org, Yuyang Du Subject: [PATCH v2 17/17] locking/lockdep: Remove irq-safe to irq-unsafe read check Date: Thu, 16 May 2019 16:00:15 +0800 Message-Id: <20190516080015.16033-18-duyuyang@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20190516080015.16033-1-duyuyang@gmail.com> References: <20190516080015.16033-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 cd1d515..bc36fbf 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -3450,8 +3450,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, @@ -3497,7 +3495,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; @@ -3508,7 +3506,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