Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1975639ybl; Thu, 29 Aug 2019 01:34:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqxcV7VD7cosWZVeIp9iXA0F8iteWNgYaezTRK+mR8T1m9rEGcfD6y2UpdloLVCovb9XWgtZ X-Received: by 2002:aa7:85d6:: with SMTP id z22mr9547665pfn.262.1567067674185; Thu, 29 Aug 2019 01:34:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567067674; cv=none; d=google.com; s=arc-20160816; b=ZBMOgO/8QU446WPWYn3ebbIK4tC5uGNX33nABkUlCxLkIP9F+29IrXD1RZvCwraDnS wV5dVZ1Gu7GjIZhJDmGzWuB2lhm8uinuo8FoHpX8Nf7OTPZ/3w4CYdFp25LsgwThT6hA LHOAsZi+s3Y+DG33daIOdq+rTF9FLEQ+0JISbRoa9DavsXmM+0JvvGyxNS/UbTi8TVCv 51jsR5ZE4Nv563FxS/OUuocSgUXlWZo5Uhsxn0Ek6o+lrOxhAmFHg71zBptjvcKRyKXs FG9FNAQoZTEilUaH8fEIUcPM3KLYaf5D6MgX+W069hXgU0DFohCtDyxvNc6urFCZyYh7 XncQ== 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=zlq2IBLuceVbdXIR+sbqYK0JGHzJ0OSTvlG77al8JWo=; b=a0Kr+MhivRjXMblapaBfVCkDTZ6nVs/ydvrtUogv5ZoAZo6bAqnB+0aVRxdBy81NUg 5ApUqyNfQvVsX0o5YctaeWx+MvDz8Wpcg1zaoIKkfo0NdMIHGjxi/fVErj/033a7010C ztf86atZusPl3yL4H43EiRm7wMTNxl7CkzhX3BcdadU1opnhh822WTcxN0Do2Wqt1J02 nbMc8Qqb9dCxCuh1EGawGYnq9gnMp9fvVulUQrDvbh/fyXCt0Ob1kfaJCwPMT4wmBcLx C5fbBEdehUNdacx4/CnIpXdxJZ4okONZnVPunXvv1TmuP/PolUHdm8dkJ1nNVSeGbwR9 ng5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="X/G1nb0C"; 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 r145si1378766pgr.553.2019.08.29.01.34.19; Thu, 29 Aug 2019 01:34:34 -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="X/G1nb0C"; 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 S1727888AbfH2Ic7 (ORCPT + 99 others); Thu, 29 Aug 2019 04:32:59 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:33039 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727746AbfH2Ic4 (ORCPT ); Thu, 29 Aug 2019 04:32:56 -0400 Received: by mail-pl1-f195.google.com with SMTP id go14so1251508plb.0 for ; Thu, 29 Aug 2019 01:32:55 -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=zlq2IBLuceVbdXIR+sbqYK0JGHzJ0OSTvlG77al8JWo=; b=X/G1nb0CpuyCr2vmt/DOG4mIhMEOEUjXfMvBys+/IGiUF0k6kUnuGuGLHnh3X4pnVT NRujSQX1YQFG5dGedXWlF/01SrXfRBUrB7BVEUOLALNY4YQB7co6JbhIons6rdpHuC4M 4Z7mNXM3vCQCj3GWmRz7/mrjscfOw683/VyIFlRDr5oG33fmTJZrownWVwKMwmNQHU87 mpkz3zs1jpgoQi2KUfoyGAwnnAsOLYTylN8H7MV15NBn0j0Q1drjROO2+sro6zxuDyYy buyWSZYDsxQ0X61IjGrW9eRdsDjetddKwFEU0nsF49GUX3HovMB0XYMF53KQTRHoItsP c/Kg== 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=zlq2IBLuceVbdXIR+sbqYK0JGHzJ0OSTvlG77al8JWo=; b=tDVFGHuNNo2M/SuDCZFf9TQHKDVaP5wGfgJpQGPvj4gOepHunsPANvc0WrYAtsmfgN wRbNdHjN54Lb1Vo42DN935ub/2E5Y3e+jrNvGMdglfs+K7PRySA01SJVdD48Hduys+WA 8ZS243E/HSNiGryk9GqQrkwGTngczjZROH46tIKyMN9JOofmx2YE2CF/INOYpHOE9R22 ISkW5y6BwcU5oQ52qyqULf/b3UGQ9V+/OE1jw4FWA8q9bk/wzxEWfmJe2PcGgAH6mQIf raT8rKPK63YaCjyFWNn66+uKDE14vjRpqpkLUNvkWPN/sYUEuUJgr6qfuAn9CR1qbZ1V l7iw== X-Gm-Message-State: APjAAAXF0dlVAPh7sT1MqNYS5erc2PaKZVrmz6h+mi19LHBGwy7t3XJH 1s+EmPGLZWy/MR+utRvkOO8= X-Received: by 2002:a17:902:8a87:: with SMTP id p7mr8633372plo.240.1567067575250; Thu, 29 Aug 2019 01:32:55 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id v22sm1260155pgk.69.2019.08.29.01.32.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Aug 2019 01:32:54 -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 18/30] ocking/lockdep: Add read-write type for a lock dependency Date: Thu, 29 Aug 2019 16:31:20 +0800 Message-Id: <20190829083132.22394-19-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 Direct dependencies need to keep track of their read-write lock types. Two bit fields, which share the distance field, are added to lock_list struct to store the types. With a dependecy lock1 -> lock2, lock_type1 has the type for lock1 and lock_type2 has the type for lock2, where the values are one of the lock_type enums. Signed-off-by: Yuyang Du --- include/linux/lockdep.h | 15 ++++++++++++++- kernel/locking/lockdep.c | 25 +++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index 2335447..eab8a90 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -182,6 +182,8 @@ static inline void lockdep_copy_map(struct lockdep_map *to, to->class_cache[i] = NULL; } +#define LOCK_TYPE_BITS 2 + /* * Every lock has a list of other locks that were taken after or before * it as lock dependencies. These dependencies constitute a graph, which @@ -204,7 +206,17 @@ struct lock_list { struct list_head chains; struct lock_class *class[2]; const struct lock_trace *trace; - int distance; + + /* + * The lock_type fields keep track of the lock type of this + * dependency. + * + * With L1 -> L2, lock_type1 stores the lock type of L1, and + * lock_type2 stores that of L2. + */ + unsigned int lock_type1 : LOCK_TYPE_BITS, + lock_type2 : LOCK_TYPE_BITS, + distance : 32 - 2*LOCK_TYPE_BITS; /* * The parent field is used to implement breadth-first search. @@ -359,6 +371,7 @@ enum lock_type { LOCK_TYPE_WRITE = 0, LOCK_TYPE_READ, LOCK_TYPE_RECURSIVE, + NR_LOCK_TYPE, }; /* diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index bdc7e94..18303ff 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -1379,9 +1379,17 @@ static int add_lock_to_list(struct lock_class *lock1, struct lock_class *lock2, unsigned long ip, int distance, const struct lock_trace *trace, - struct lock_chain *chain) + struct lock_chain *chain, + int lock_type1, int lock_type2) { struct lock_list *entry; + + /* + * The distance bit field in struct lock_list must be large + * enough to hold the maximum lock depth. + */ + BUILD_BUG_ON((1 << (32 - 2*LOCK_TYPE_BITS)) < MAX_LOCK_DEPTH); + /* * Lock not present yet - get a new dependency struct and * add it to the list: @@ -1394,6 +1402,8 @@ static int add_lock_to_list(struct lock_class *lock1, entry->class[1] = lock2; entry->distance = distance; entry->trace = trace; + entry->lock_type1 = lock_type1; + entry->lock_type2 = lock_type2; /* * Both allocation and removal are done under the graph lock; but @@ -1537,6 +1547,16 @@ static inline struct list_head *get_dep_list(struct lock_list *lock, int forward return &class->dep_list[forward]; } +static inline int get_lock_type1(struct lock_list *lock) +{ + return lock->lock_type1; +} + +static inline int get_lock_type2(struct lock_list *lock) +{ + return lock->lock_type2; +} + /* * Forward- or backward-dependency search, used for both circular dependency * checking and hardirq-unsafe/softirq-unsafe checking. @@ -2580,7 +2600,8 @@ static inline void inc_chains(void) * dependency list of the previous lock : */ ret = add_lock_to_list(hlock_class(prev), hlock_class(next), - next->acquire_ip, distance, *trace, chain); + next->acquire_ip, distance, *trace, chain, + prev->read, next->read); if (!ret) return 0; -- 1.8.3.1