Received: by 10.223.185.116 with SMTP id b49csp1595774wrg; Wed, 21 Feb 2018 23:10:31 -0800 (PST) X-Google-Smtp-Source: AH8x2269whhevajkxnHF7kbfSTiXevZ2S+pkMe7660fK1QEp1+W674eXt5XmPo5w82isYmVRGWkr X-Received: by 2002:a17:902:bd47:: with SMTP id b7-v6mr5728871plx.150.1519283431442; Wed, 21 Feb 2018 23:10:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519283431; cv=none; d=google.com; s=arc-20160816; b=v3PzE0WOZ6m6N3SahR0DdsFzinU7Fpy4gxI3+5tIQlT/0ZA2RKbz7YihSuW+tlzVGS Fd+j92UeG741xq7N5watbSQ/BmxbQNREJUlKJ5Rb0VqH0MA8Ec5xsyo+BbH4nwDA37il S4OtbAXiDiGei3Uj9MBM7x3ESzpQbPACOTXIZl/QY/i4/TQyMndCrsPsCIz7T/GIoe0M f3518ukIzS/P9H0mt+WPh0l/FVfx0Sxsgwbq/F8m38WCFq21n1iENBhVSWtFlJzZG7YL N4uq4iz2jn+fDRNxCbTIWIYM/C3SCHqC6Lz+wFpHvPUdKzLTXnqrS+Lgjin4RPVVdibR ZJSA== 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=ZyigSShzxSCVghjdeqjR84Wzp7psdInPABC5wijEwms=; b=McbedITZT5MHm6y9hLeNdkLTykXxlP45Nlrl2UthmwBQM+mtLp0mh7AqORUF8OtXAx R2xp955gD21mlZsmKpwH+6SYLW9VTReUIGk10EgPpsInM6G8wVnCjxDd9k61WrpBZAdY mwvYdpPuIhdENMgevPUFrZfrcLo8x86xXiMP6MKHgresBPkg4ifluc72H5ILf8l+sVB/ rzZROQ/zxvFgQHtnH9FfAHlXDmKKubS429802Y3CA4FtZ+wDSrxMDG0iN87L7yvNV46W 1RJjVF+rEc/t1U/EEZXOlOGawpGQqgEbNFLYwV3UzN4xw8+ZkuUmwBBv/gi4sjSajtXr vTpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ba85g5Rd; 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 b36-v6si702300pli.330.2018.02.21.23.10.17; Wed, 21 Feb 2018 23:10:31 -0800 (PST) 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=Ba85g5Rd; 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 S1752768AbeBVHIn (ORCPT + 99 others); Thu, 22 Feb 2018 02:08:43 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34914 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752659AbeBVHGW (ORCPT ); Thu, 22 Feb 2018 02:06:22 -0500 Received: by mail-wm0-f66.google.com with SMTP id x21so1712746wmh.0 for ; Wed, 21 Feb 2018 23:06:22 -0800 (PST) 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; bh=ZyigSShzxSCVghjdeqjR84Wzp7psdInPABC5wijEwms=; b=Ba85g5RdkZ6WsKjd4ObEpNr4SwFcLLtfnkeONezvfa1fLaI0LsIh9aNbD3N3fYNdC3 cX9RGZ43Y4k3blz3IrOCRlwKsaLQob9idz1nCmOGkUDc1J0Ob5A5E5NJw7+ysRRxwJb9 y+m+l9BnyiajX3lIyo++JoGy5DbURQQx6e2Rg45nBgYnt0dH4i9qv1AkVHW9oEk44CcE Va60IxyQtZLmaoimwmfNghQH6oQIxkKaWwp9YKdvNCxiUaRQkp9QMWnfmYzcnSs4kIDI yx2/vhHhhC65Gf9K4pgXp7emnvpd9/NLlcpGSCfnqGwmShrfvz+14jVtzAUDL45LIrEt mTlA== 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=ZyigSShzxSCVghjdeqjR84Wzp7psdInPABC5wijEwms=; b=dC1s9Q28FPJZCLnmCKzfhKuU8J78D+forgl7WuFfmTiN0ahnGm+Ktw6sjUrrowbvwA jv73JpsFQN1QtV9gRoFxZl4sWE/4RHgimegPOBTPBYtZBvqvj/VJOPXFjjWkz6wezXA9 /hunWZ5QWdepqxhUrf0tVSUWdr2owUGZtAgtw9r0yeX/y2CicLau0WlPK02ohg4cxxq+ 0VsD8204mVdsVs7vHC/5ZmNKBPmeAuIG6C9pDUw6gscHkwP/11+xBNdoal16FO86eB6e Dd2IVem/nXIfyQ8K6FhqkNu451StTYmzMdHufpR+swgkXaams828QLxxEti8gDxg2SoW BIeQ== X-Gm-Message-State: APf1xPBFBgWnuke3pPj7GtsBnq5CW002BkTWsIpob5CN+tOFn6/n/f7r KawNuiOg+PdB23+v3CgTsY8= X-Received: by 10.80.186.25 with SMTP id g25mr8121745edc.28.1519283181377; Wed, 21 Feb 2018 23:06:21 -0800 (PST) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id w2sm25097759edb.25.2018.02.21.23.06.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 23:06:20 -0800 (PST) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailauth.nyi.internal (Postfix) with ESMTP id 3EAAB20505; Thu, 22 Feb 2018 02:06:19 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute7.internal (MEProxy); Thu, 22 Feb 2018 02:06:19 -0500 X-ME-Sender: Received: from localhost (unknown [45.32.128.109]) by mail.messagingengine.com (Postfix) with ESMTPA id B29322460B; Thu, 22 Feb 2018 02:06:18 -0500 (EST) From: Boqun Feng To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Ingo Molnar , Andrea Parri , Boqun Feng Subject: [RFC tip/locking/lockdep v5 08/17] lockdep: Fix recursive read lock related safe->unsafe detection Date: Thu, 22 Feb 2018 15:08:55 +0800 Message-Id: <20180222070904.548-9-boqun.feng@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180222070904.548-1-boqun.feng@gmail.com> References: <20180222070904.548-1-boqun.feng@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are four cases for recursive read lock realted deadlocks: (--(X..Y)--> means a strong dependency path starts with a --(X*)--> dependency and ends with a --(*Y)-- dependency.) 1. An irq-safe lock L1 has a dependency --(*..*)--> to an irq-unsafe lock L2. 2. An irq-read-safe lock L1 has a dependency --(N..*)--> to an irq-unsafe lock L2. 3. An irq-safe lock L1 has a dependency --(*..N)--> to an irq-read-unsafe lock L2. 4. An irq-read-safe lock L1 has a dependency --(N..N)--> to an irq-read-unsafe lock L2. The current check_usage() only checks 1) and 2), so this patch adds checks for 3) and 4) and makes sure when find_usage_{back,for}wards find an irq-read-{,un}safe lock, the traverse path should ends at a dependency --(*N)-->. Note when we search backwards, --(*N)--> indicates a real dependency --(N*)-->. Signed-off-by: Boqun Feng --- kernel/locking/lockdep.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 0b0ad3db78b4..bd3eef664f9d 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -1504,7 +1504,14 @@ check_redundant(struct lock_list *root, struct held_lock *target, static inline int usage_match(struct lock_list *entry, void *bit) { - return entry->class->usage_mask & (1 << (enum lock_usage_bit)bit); + enum lock_usage_bit ub = (enum lock_usage_bit)bit; + + + if (ub & 1) + return entry->class->usage_mask & (1 << ub) && + !entry->is_rr; + else + return entry->class->usage_mask & (1 << ub); } @@ -1815,6 +1822,10 @@ static int check_irq_usage(struct task_struct *curr, struct held_lock *prev, exclusive_bit(bit), state_name(bit))) return 0; + if (!check_usage(curr, prev, next, bit, + exclusive_bit(bit) + 1, state_name(bit))) + return 0; + bit++; /* _READ */ /* @@ -1827,6 +1838,10 @@ static int check_irq_usage(struct task_struct *curr, struct held_lock *prev, exclusive_bit(bit), state_name(bit))) return 0; + if (!check_usage(curr, prev, next, bit, + exclusive_bit(bit) + 1, state_name(bit))) + return 0; + return 1; } -- 2.16.1