Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp430197img; Thu, 21 Mar 2019 00:59:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqyQ2RrtuUm5xKEnU5F9ZSD9khheIvTRZlye2c89zSLFJGG5o05BbpgGQHM3erawkNPoqnFb X-Received: by 2002:a17:902:a413:: with SMTP id p19mr2198869plq.337.1553155154099; Thu, 21 Mar 2019 00:59:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553155154; cv=none; d=google.com; s=arc-20160816; b=jcV5V5B2njUeCn+3bVTXbhhw6Cq1DmcmaswioJ+0spW07rcpk2JlzkjN9nQIMq1AJX aSukG0+K5U+CQSXHOQeJTbqQddHcOcSkVP7BTBHMWIt8uWLPiplljN4gOdilTHvbroap mSi6GfPqldGKRe78TfperqquC8rKAr0uBnC9qLyJHvP0Nw+3y0dAgLKd06hlVED9RvNm tOk6zj/13IEVyp36dKQOhDmYqhHAZIQsQ682OxublHwx1KRRJsSj3PbHZ+bTKFIztQeD 3ze4UdehGIUa8b9CmDdctjo5nKK5vf0b4iUI4HKIsKgyGuSEeK4w5MF1Rprfy7jHZwYN 5HHw== 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; bh=gddGIs+Ptm+HnR6q5I4pJ5I5ClRxXb5o/V70RK6sM6s=; b=ZsUeUniS0u5Eli1j3K0bx3yiNUYrGawOkzlMkPAdvHFVIidLRJYur73+MIIk0ZWWhS EMOGZ6h1F1KjLhiWDa8ctNaEuhsNzGTZNw4EkgaeFderLNwCpWEE5+9OhMZRDLizFtL0 w9ZhMNeH9YXeeJZSO7uxGpS/zsUxXNCSMsaAwE+RuG9pXAMnnsV3MXtmfrQBbJDCpAot H3sD85jLOKxRwSEX9vAsSaJuG0ubV4fdms7r/D/tB/IbyBOjfuPmGBQfiNNcocMS+w3z s/N1yYhe9oN+xuCJJzO1TbkQDX6PYYrvBsR3NPDh1mLUMVfvUpspC9yYYPMCmeIPc3S6 AXHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qxJGVriY; 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 q20si3643680pgi.499.2019.03.21.00.58.58; Thu, 21 Mar 2019 00:59:14 -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=qxJGVriY; 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 S1728018AbfCUH56 (ORCPT + 99 others); Thu, 21 Mar 2019 03:57:58 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:34981 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728005AbfCUH56 (ORCPT ); Thu, 21 Mar 2019 03:57:58 -0400 Received: by mail-pf1-f196.google.com with SMTP id t21so3036204pfe.2 for ; Thu, 21 Mar 2019 00:57:57 -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; bh=gddGIs+Ptm+HnR6q5I4pJ5I5ClRxXb5o/V70RK6sM6s=; b=qxJGVriY6g6Tl/DFWm6OyulCaftQdogoSc67v0KLncSK2/HcMRNUoF8rFbo34QB/HI aUO/o5T0K/VavS8dlKXOMazIkgzOb5zlIWKCSWwdwrZ6O6DPcyL0u5CdwY2F3Bn5tfVc GlEzr8U+z4Y1ZSkooqBnlRA24mLrBKYFIEcaTDl4OGP7Ce2mSZXr92Q6jssM8rORgDpm XgeOkr1q4tlRZ3Wv8UL3t1R/g6QNtCGOxYsvYWZfohtu+adGUGDullK2qgHbg14Q01ko 418DONmiJQtmtJelf+HCnYxAWfsLUSgPKuFCXfI41cM35DUbW2RzETKVzAXZ43X2SRTG ouVg== 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=gddGIs+Ptm+HnR6q5I4pJ5I5ClRxXb5o/V70RK6sM6s=; b=IfOw3wJvKnGkCaR47HvagQgXmZukqL4XiqoyU+Kd9GYmdlHiQMXhyGgVFjMIg5rVlr 6FJHpR9vIOrlqdMN8Ono+qJRsHPW5W7QLVYdl3tSiF+45CD8RANGts+A/kkwKxJG9yf6 L4ZbvQJRnl7M9+9D+p3NJp8sLmDANlAA9rspfmtS1zICd82XRvTx9LXImrqAcL172Zqc sqMS02Apie/TrXP/VyKW465sXIiTCcmWmwD2S98pd39pGy/ep1YUg1E4D1ndcA8W2u0r TYmUYLvDMJOpAXMrUigI3Tw8YwZLyetRyQdhJOG4aWp/f+eJ6MDxH8b83bVt2C9TYzXR X+WQ== X-Gm-Message-State: APjAAAVNW8Lzl8F6VCweiVhDFRx0GL6h1UNVAV1WxMKSiaQO4x+GDA/o PcEneRbShWV5FQg7u4NvUOo= X-Received: by 2002:a63:1960:: with SMTP id 32mr2094041pgz.171.1553155077098; Thu, 21 Mar 2019 00:57:57 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id e184sm6467148pfc.143.2019.03.21.00.57.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Mar 2019 00:57:56 -0700 (PDT) From: Yuyang Du To: peterz@infradead.org, will.deacon@arm.com, mingo@kernel.org Cc: bvanassche@acm.org, ming.lei@redhat.com, linux-kernel@vger.kernel.org, joe@perches.com, Yuyang Du Subject: [PATCH v3 08/18] locking/lockdep: Define INITIAL_CHAIN_KEY for chain keys to start with Date: Thu, 21 Mar 2019 15:57:15 +0800 Message-Id: <20190321075725.14054-9-duyuyang@gmail.com> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <20190321075725.14054-1-duyuyang@gmail.com> References: <20190321075725.14054-1-duyuyang@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Chain keys are computed using Jenkins hash function, which needs an initial hash to start with. Dedicate a macro to make this clear and configurable. A later patch changes this initial chain key. Signed-off-by: Yuyang Du --- include/linux/lockdep.h | 1 + init/init_task.c | 2 +- kernel/locking/lockdep.c | 18 +++++++++--------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index 267087e..64d4565 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -224,6 +224,7 @@ struct lock_chain { * bitfield and hitting the BUG in hlock_class(). */ #define MAX_LOCKDEP_KEYS ((1UL << MAX_LOCKDEP_KEYS_BITS) - 1) +#define INITIAL_CHAIN_KEY 0 struct held_lock { /* diff --git a/init/init_task.c b/init/init_task.c index 9460878..ff3e8bf 100644 --- a/init/init_task.c +++ b/init/init_task.c @@ -166,7 +166,7 @@ struct task_struct init_task #endif #ifdef CONFIG_LOCKDEP .lockdep_depth = 0, /* no locks held yet */ - .curr_chain_key = 0, + .curr_chain_key = INITIAL_CHAIN_KEY, .lockdep_recursion = 0, #endif #ifdef CONFIG_FUNCTION_GRAPH_TRACER diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index ef59651..c6363f7 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -361,7 +361,7 @@ static inline u64 iterate_chain_key(u64 key, u32 idx) inline void lockdep_init_task(struct task_struct *task) { task->lockdep_depth = 0; /* no locks held yet */ - task->curr_chain_key = 0; + task->curr_chain_key = INITIAL_CHAIN_KEY; task->lockdep_recursion = 0; } @@ -867,7 +867,7 @@ static bool class_lock_list_valid(struct lock_class *c, struct list_head *h) static bool check_lock_chain_key(struct lock_chain *chain) { #ifdef CONFIG_PROVE_LOCKING - u64 chain_key = 0; + u64 chain_key = INITIAL_CHAIN_KEY; int i; for (i = chain->base; i < chain->base + chain->depth; i++) @@ -2433,7 +2433,7 @@ static u64 print_chain_key_iteration(int class_idx, u64 chain_key) print_chain_keys_held_locks(struct task_struct *curr, struct held_lock *hlock_next) { struct held_lock *hlock; - u64 chain_key = 0; + u64 chain_key = INITIAL_CHAIN_KEY; int depth = curr->lockdep_depth; int i = get_first_held_lock(curr, hlock_next); @@ -2453,7 +2453,7 @@ static u64 print_chain_key_iteration(int class_idx, u64 chain_key) static void print_chain_keys_chain(struct lock_chain *chain) { int i; - u64 chain_key = 0; + u64 chain_key = INITIAL_CHAIN_KEY; int class_id; printk("depth: %u\n", chain->depth); @@ -2757,7 +2757,7 @@ static void check_chain_key(struct task_struct *curr) #ifdef CONFIG_DEBUG_LOCKDEP struct held_lock *hlock, *prev_hlock = NULL; unsigned int i; - u64 chain_key = 0; + u64 chain_key = INITIAL_CHAIN_KEY; for (i = 0; i < curr->lockdep_depth; i++) { hlock = curr->held_locks + i; @@ -2781,7 +2781,7 @@ static void check_chain_key(struct task_struct *curr) if (prev_hlock && (prev_hlock->irq_context != hlock->irq_context)) - chain_key = 0; + chain_key = INITIAL_CHAIN_KEY; chain_key = iterate_chain_key(chain_key, hlock->class_idx); prev_hlock = hlock; } @@ -3694,14 +3694,14 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, /* * How can we have a chain hash when we ain't got no keys?! */ - if (DEBUG_LOCKS_WARN_ON(chain_key != 0)) + if (DEBUG_LOCKS_WARN_ON(chain_key != INITIAL_CHAIN_KEY)) return 0; chain_head = 1; } hlock->prev_chain_key = chain_key; if (separate_irq_context(curr, hlock)) { - chain_key = 0; + chain_key = INITIAL_CHAIN_KEY; chain_head = 1; } chain_key = iterate_chain_key(chain_key, class_idx); @@ -4543,7 +4543,7 @@ static void remove_class_from_lock_chain(struct pending_free *pf, return; recalc: - chain_key = 0; + chain_key = INITIAL_CHAIN_KEY; for (i = chain->base; i < chain->base + chain->depth; i++) chain_key = iterate_chain_key(chain_key, chain_hlocks[i] + 1); if (chain->depth && chain->chain_key == chain_key) -- 1.8.3.1