Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1975291ybl; Thu, 29 Aug 2019 01:34:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqz/6RiqPWLU80JBidtSHw2NqwAKChUmfn8xLG34l+52SpemTVzdPsH+21aPG/pgD5cjV8aU X-Received: by 2002:a63:6888:: with SMTP id d130mr6890331pgc.197.1567067649713; Thu, 29 Aug 2019 01:34:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567067649; cv=none; d=google.com; s=arc-20160816; b=Pr5EfbGiRM5Y06pbLAXzsJSUBK5GuRe+nsCaIU0ulp0CCI4YeJJkfrH6z1sNdyilX6 PPK4JKlzI+TAqtus2Z+gXT2+V0leAfUuQ6QUA4ePWBzgnt/1MMeclh29jERJgtMJJq4L 0CYgJauELZO6VEbUnaI23Iq+Pkkyggsdv3AK5LN8L7Gh7m3AzOXZFkaq4OIS0yadGF+8 96jmD6zhAoJb9WcDj7nRcTmSnz5zTQCu0kX08I3aPBialP+yReKf98WkAzGz8Zo+Y88T E2sfuzJn5Hf/4DBPY5mzA/iNxkx8xRrE4QkEmptzN60TNJDEJ4vp0/wdocC7nhkdh1UP UIhg== 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=FxiVEPtu6ZDNIk6WhpXgSn0K0xNIq2CZdadCX82YRPQ=; b=wL2rzanlVidcORxA1/ppDcGBgw5u5zR55whdfYzq7wxcRB/4ZXW4Ho6t4RLk4ctDUC SdB6znVg+qZ+cSOaQWLfEDKIT5QijeOzg28rwuBFw458Nc8nCJoh1DcRA/V+k5vgWlPF ealjqY21jselA5s4m+kCyBpbT6WxgFXV3v7c1MxZ48Z5OK53mqFBchdajMXmqu02DRw4 5D5SgTWxy4oblSyaCgk/3kyF8uq9gdn39IvYyActXXo8g9UhhIyeRW01l4P4MgEl8g/1 R4ffpp93FhhmFsHzKMcvm2VgHfI1p+cAD3J1DMs1gGURKMQfi95scOMxIG879UT3pM0C dRXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gqzK8+xE; 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 s9si1384272pgc.305.2019.08.29.01.33.53; Thu, 29 Aug 2019 01:34:09 -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=gqzK8+xE; 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 S1727403AbfH2Ice (ORCPT + 99 others); Thu, 29 Aug 2019 04:32:34 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:42885 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727087AbfH2Icc (ORCPT ); Thu, 29 Aug 2019 04:32:32 -0400 Received: by mail-pg1-f194.google.com with SMTP id p3so1199243pgb.9 for ; Thu, 29 Aug 2019 01:32:32 -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=FxiVEPtu6ZDNIk6WhpXgSn0K0xNIq2CZdadCX82YRPQ=; b=gqzK8+xEt0LoWy3IRD1qfTggiF5uMxIZO1h1m9QYQ8uRqNWI3Vl7lw7u9D0QDD0bKh HEI65lGSPPP9lFdLK47GUWooJZVSALjZMFkgHCrJOrVA8VfPNEQYTT5nrBL3N7pjzpWu zov2MQdmt07AMmF8kPArL3NFsiWxYqF7L9wpM0djcA/K4WGaQHSbd/3qk0A8nYYXcrCM j2YQcaIYWubvLgF7ckHBBmAjT5uBTlUulqrZ+Bj4+poBhD1pz7jrSF0cqGY+NpVBVrnn NwSWmp+b7rAegIgGag5Cv4k6l+6v0gNsOOzd3zOYvt9leRu+O7B4BE3UAWqZ9GlY/s+i VnnA== 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=FxiVEPtu6ZDNIk6WhpXgSn0K0xNIq2CZdadCX82YRPQ=; b=qolX1Vn5p10sF5z0451n1SO2wRxS4aUuivg2Ie85tRz9eDww5KYy7X2vqCqlkeiCWV D+5TnsHfa6aXcYQoTPKmzC4Vm6nARFX0eL7Fzh/k/B3ejRM09OzBe7/umdhnItsXnhKi KPEue1sNTXNf7SBqgfKHrwGO4bPqsGu//gxKHj+xIp1n4p8/LDcBFY51qD1uoQE5sBzk yD4K6G7/+eywovVHS3pOsNdlHDwHjSyuplCpiqqbTy+UKtuo1EUABKGV6gMGzFi9KOKp RDcf1IIk7kUjSSa8DZ9UI6PGMsroO/pXiIRKKDTFm3hyQ0tomsWlEAbnMYTnGyP5FUba eRWQ== X-Gm-Message-State: APjAAAVbp5lFUBMJwkg8NshRFTMXTIL9aQGUbzMiJgTCVIRjWStmBbSM V8LwnWQSzhxpThtQU8wj2fA= X-Received: by 2002:a17:90a:f0c9:: with SMTP id fa9mr8556651pjb.137.1567067551707; Thu, 29 Aug 2019 01:32:31 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id v22sm1260155pgk.69.2019.08.29.01.32.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Aug 2019 01:32:31 -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 v4 12/30] locking/lockdep: Specify the depth of current lock stack in lookup_chain_cache_add() Date: Thu, 29 Aug 2019 16:31:14 +0800 Message-Id: <20190829083132.22394-13-duyuyang@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20190829083132.22394-1-duyuyang@gmail.com> References: <20190829083132.22394-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 When looking up and adding a chain (i.e., in lookup_chain_cache_add() and only in it), explicitly specify the depth of the held lock stack as the chain. The depth now only equals curr->lockdep_depth. No functional change. Signed-off-by: Yuyang Du --- kernel/locking/lockdep.c | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 1dda9de..569d3c1 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -2600,12 +2600,12 @@ struct lock_class *lock_chain_get_class(struct lock_chain *chain, int i) * Returns the index of the first held_lock of the current chain */ static inline int get_first_held_lock(struct task_struct *curr, - struct held_lock *hlock) + struct held_lock *hlock, int depth) { int i; struct held_lock *hlock_curr; - for (i = curr->lockdep_depth - 1; i >= 0; i--) { + for (i = depth - 1; i >= 0; i--) { hlock_curr = curr->held_locks + i; if (hlock_curr->irq_context != hlock->irq_context) break; @@ -2630,12 +2630,12 @@ static u64 print_chain_key_iteration(int class_idx, u64 chain_key) } static void -print_chain_keys_held_locks(struct task_struct *curr, struct held_lock *hlock_next) +print_chain_keys_held_locks(struct task_struct *curr, + struct held_lock *hlock_next, int depth) { struct held_lock *hlock; u64 chain_key = INITIAL_CHAIN_KEY; - int depth = curr->lockdep_depth; - int i = get_first_held_lock(curr, hlock_next); + int i = get_first_held_lock(curr, hlock_next, depth); printk("depth: %u (irq_context %u)\n", depth - i + 1, hlock_next->irq_context); @@ -2667,8 +2667,8 @@ static void print_chain_keys_chain(struct lock_chain *chain) } static void print_collision(struct task_struct *curr, - struct held_lock *hlock_next, - struct lock_chain *chain) + struct held_lock *hlock_next, + struct lock_chain *chain, int depth) { pr_warn("\n"); pr_warn("============================\n"); @@ -2679,7 +2679,7 @@ static void print_collision(struct task_struct *curr, pr_warn("Hash chain already cached but the contents don't match!\n"); pr_warn("Held locks:"); - print_chain_keys_held_locks(curr, hlock_next); + print_chain_keys_held_locks(curr, hlock_next, depth); pr_warn("Locks in cached chain:"); print_chain_keys_chain(chain); @@ -2695,17 +2695,16 @@ static void print_collision(struct task_struct *curr, * that there was a collision during the calculation of the chain_key. * Returns: 0 not passed, 1 passed */ -static int check_no_collision(struct task_struct *curr, - struct held_lock *hlock, - struct lock_chain *chain) +static int check_no_collision(struct task_struct *curr, struct held_lock *hlock, + struct lock_chain *chain, int depth) { #ifdef CONFIG_DEBUG_LOCKDEP int i, j, id; - i = get_first_held_lock(curr, hlock); + i = get_first_held_lock(curr, hlock, depth); - if (DEBUG_LOCKS_WARN_ON(chain->depth != curr->lockdep_depth - (i - 1))) { - print_collision(curr, hlock, chain); + if (DEBUG_LOCKS_WARN_ON(chain->depth != depth - (i - 1))) { + print_collision(curr, hlock, chain, depth); return 0; } @@ -2713,7 +2712,7 @@ static int check_no_collision(struct task_struct *curr, id = curr->held_locks[i].class_idx; if (DEBUG_LOCKS_WARN_ON(chain_hlocks[chain->base + j] != id)) { - print_collision(curr, hlock, chain); + print_collision(curr, hlock, chain, depth); return 0; } } @@ -2757,7 +2756,7 @@ static struct lock_chain *alloc_lock_chain(void) */ static inline struct lock_chain *add_chain_cache(struct task_struct *curr, struct held_lock *hlock, - u64 chain_key) + u64 chain_key, int depth) { struct lock_class *class = hlock_class(hlock); struct hlist_head *hash_head = chainhashentry(chain_key); @@ -2783,8 +2782,8 @@ static inline struct lock_chain *add_chain_cache(struct task_struct *curr, } chain->chain_key = chain_key; chain->irq_context = hlock->irq_context; - i = get_first_held_lock(curr, hlock); - chain->depth = curr->lockdep_depth + 1 - i; + i = get_first_held_lock(curr, hlock, depth); + chain->depth = depth + 1 - i; BUILD_BUG_ON((1UL << 24) <= ARRAY_SIZE(chain_hlocks)); BUILD_BUG_ON((1UL << 6) <= ARRAY_SIZE(curr->held_locks)); @@ -2837,17 +2836,21 @@ static inline struct lock_chain *lookup_chain_cache(u64 chain_key) * add it and return the chain - in this case the new dependency * chain will be validated. If the key is already hashed, return * NULL. (On return with the new chain graph_lock is held.) + * + * If the key is not hashed, the new chain is composed of @hlock + * and @depth worth of the current held lock stack, of which the + * held locks are in the same context as @hlock. */ static inline struct lock_chain * lookup_chain_cache_add(struct task_struct *curr, struct held_lock *hlock, - u64 chain_key) + u64 chain_key, int depth) { struct lock_class *class = hlock_class(hlock); struct lock_chain *chain = lookup_chain_cache(chain_key); if (chain) { cache_hit: - if (!check_no_collision(curr, hlock, chain)) + if (!check_no_collision(curr, hlock, chain, depth)) return NULL; if (very_verbose(class)) { @@ -2877,7 +2880,7 @@ static inline struct lock_chain *lookup_chain_cache(u64 chain_key) goto cache_hit; } - return add_chain_cache(curr, hlock, chain_key); + return add_chain_cache(curr, hlock, chain_key, depth); } static int validate_chain(struct task_struct *curr, struct held_lock *hlock, @@ -2895,7 +2898,8 @@ static int validate_chain(struct task_struct *curr, struct held_lock *hlock, * graph_lock for us) */ if (!hlock->trylock && hlock->check && - (chain = lookup_chain_cache_add(curr, hlock, chain_key))) { + (chain = lookup_chain_cache_add(curr, hlock, chain_key, + curr->lockdep_depth))) { /* * Check whether last held lock: * -- 1.8.3.1