Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1976599ybl; Thu, 29 Aug 2019 01:35:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqz/coEBPCj8RRoPtIUopNo6dEkabyF+/recvioHrqKzT0N/KNg2OCe5EABDM9kbhLrJBS8o X-Received: by 2002:a17:90a:9a90:: with SMTP id e16mr8771615pjp.71.1567067745036; Thu, 29 Aug 2019 01:35:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567067745; cv=none; d=google.com; s=arc-20160816; b=M8H0Ma5ZbUkR41JZdb+F4GltG3YjgZ6laLOXxmBpfGoegN96mhdGSPr6bPDZ1eY+UR h+RVGuMm/pnjC2rf15c5pHHQ7gK0R5j2Bh1PxBp7c7q/oiGOMGpmA6/gkna9aeYc4iP/ Zl+S+893WtxVVnsnB5s4fkdRcdQfTG0D4rtLnFNFZJ+getPYHR5BjGFFjkzp5SfsymdW MjuWmpw1DxtXlORjya8/Ho5BIwsA6NsJZXmttVIvpbqEVtjeewOCo3AzeeHSAyvNLsHs lQPo9CrGJ0+ouU6rOnTJFrBCpfM7LuvuzsNNfdtqsm7jaBnuJSgTLCoCcKbVYhoslKXS lI7Q== 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=Y9B4vIKEkG7WXy/phP6YFI7YjChHBUGCsTMIBlPmEiQ=; b=td6JmH9iHin/RRcxBgrdV/2UWsRhVIxJmyziE/BFSYO9IltdHq5ch1soAFkyO5FKyW Aafn4W5l/g3ClLGJTA5FuLbHySASrudJch0k8J/trZ79kvFVXK3IvteL385ucCq8LFh0 681v+rLIN2BD9FMNntRy4US0QJVguvDTLKf3nSBI7Ew8JwqgzUccmYRjKiLe5xUzCF7/ 38IMmAOgrp+R3rFgPkDo3GkCL+cxYvITt9pi1JKsrZvU+iDWR/xWBK2WEpjBU8Fxjb+e /v5Tpm5Mp3jmryAD+y2sSHK+AhVkI9k86pkwsU6DEcM9hdWwynUIaHAZRo9dRMRwq4vk LBlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UetEJf1R; 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 x26si1869589pfn.78.2019.08.29.01.35.29; Thu, 29 Aug 2019 01:35:45 -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=UetEJf1R; 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 S1727781AbfH2Icy (ORCPT + 99 others); Thu, 29 Aug 2019 04:32:54 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:34201 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727746AbfH2Icv (ORCPT ); Thu, 29 Aug 2019 04:32:51 -0400 Received: by mail-pf1-f196.google.com with SMTP id b24so1594539pfp.1 for ; Thu, 29 Aug 2019 01:32:51 -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=Y9B4vIKEkG7WXy/phP6YFI7YjChHBUGCsTMIBlPmEiQ=; b=UetEJf1RJj6y7WkCUoLnGZwe6tuOeLPBq9CDt5Fcv0wzEO8uxDaUoNQrz3Tz9vF9Yk kdlnVIAt1PvY/Na8/UVZ8bNk/9nte3kq8lRMC3iASNEQ3g1evWGVGraNzjTwTuHpwoj3 FnoR0oeKUbmxjgUV5vpv6k2xcl8MA+B625Y5NIXPNEzhfD9rsudgnRlmzLWktilPCcly Mn7zrgyGaHJyj4yQQH8YLvUaPZyJ7yks2OIFW5IhRFuy8zpEVwNe5I7r1M9tYfWTyYK1 o1neNFv+MaNaRsu7vpCN3U20ROzFYoBhZMHsEyQel0mk78HYbe49QqAcfeXlGktvWfHj m10A== 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=Y9B4vIKEkG7WXy/phP6YFI7YjChHBUGCsTMIBlPmEiQ=; b=Tr5Fb5g0p4mIYu73NypBmrrXa54kuGJoMjXuLUq4dVC0WWeRUNgp67duWGLS2NL+CQ KQzNuD2djhOcQuRP1geV48JFTKMTP/nn4t7665PEZ3JrDD50uOZVbrDhtF5PLanOVNts Nkdoe9kbkOnThhip3HcBqb8onFx8ZlEfRtYW27vew9mwCUhPF4HVULKbB3BYKgOwZlg/ 8U2GoXqEvBYmaq/T4Qta7KBcGER5PklHhi/v/2Ub5sybvuVg4nIcdB6XpO7B+PUcPmYk lLFoj/53ZGvvHtNzHb7etaT5lS5HTgHpGzmuS6Dz8iTUaCOEjdae2cCdzjVMXwuayxrQ SVFA== X-Gm-Message-State: APjAAAWHGbFpsq5OPBOwwM0QeU305VqLVMqQyfLu2tKb8vQx8mFJ5Vj3 yzTx8gvoyj6F0zQcnuO3Yvs= X-Received: by 2002:aa7:9a81:: with SMTP id w1mr9930060pfi.24.1567067571141; Thu, 29 Aug 2019 01:32:51 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id v22sm1260155pgk.69.2019.08.29.01.32.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Aug 2019 01:32:50 -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 17/30] locking/lockdep: Use lock type enum to explicitly specify read or write locks Date: Thu, 29 Aug 2019 16:31:19 +0800 Message-Id: <20190829083132.22394-18-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 Add an enum to formally quantify lock types. No functional change. Signed-off-by: Yuyang Du --- include/linux/lockdep.h | 27 ++++++++++++++++++++------- include/linux/rcupdate.h | 2 +- kernel/locking/lockdep.c | 19 +++++++++++-------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index fcfc1dd..2335447 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -350,10 +350,18 @@ static inline int lockdep_match_key(struct lockdep_map *lock, * * Values for "read": * - * 0: exclusive (write) acquire - * 1: read-acquire (no recursion allowed) - * 2: read-acquire with same-instance recursion allowed - * + * LOCK_TYPE_EXCLUSIVE (LOCK_TYPE_WRITE): exclusive (write) acquire + * LOCK_TYPE_READ: read-acquire (no recursion allowed) + * LOCK_TYPE_RECURSIVE: read-acquire with same-instance recursion allowed + */ +enum lock_type { + LOCK_TYPE_EXCLUSIVE = 0, + LOCK_TYPE_WRITE = 0, + LOCK_TYPE_READ, + LOCK_TYPE_RECURSIVE, +}; + +/* * Values for check: * * 0: simple checks (freeing, held-at-exit-time, etc.) @@ -599,9 +607,14 @@ static inline void print_irqtrace_events(struct task_struct *curr) * on the per lock-class debug mode: */ -#define lock_acquire_exclusive(l, s, t, n, i) lock_acquire(l, s, t, 0, 1, n, i) -#define lock_acquire_shared(l, s, t, n, i) lock_acquire(l, s, t, 1, 1, n, i) -#define lock_acquire_shared_recursive(l, s, t, n, i) lock_acquire(l, s, t, 2, 1, n, i) +#define lock_acquire_exclusive(l, s, t, n, i) \ + lock_acquire(l, s, t, LOCK_TYPE_EXCLUSIVE, 1, n, i) + +#define lock_acquire_shared(l, s, t, n, i) \ + lock_acquire(l, s, t, LOCK_TYPE_READ, 1, n, i) + +#define lock_acquire_shared_recursive(l, s, t, n, i) \ + lock_acquire(l, s, t, LOCK_TYPE_RECURSIVE, 1, n, i) #define spin_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i) #define spin_acquire_nest(l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i) diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index c4f76a3..09128d5 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h @@ -205,7 +205,7 @@ static inline void destroy_rcu_head_on_stack(struct rcu_head *head) { } static inline void rcu_lock_acquire(struct lockdep_map *map) { - lock_acquire(map, 0, 0, 2, 0, NULL, _THIS_IP_); + lock_acquire(map, 0, 0, LOCK_TYPE_RECURSIVE, 0, NULL, _THIS_IP_); } static inline void rcu_lock_release(struct lockdep_map *map) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 754a718..bdc7e94 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -2430,7 +2430,10 @@ static inline void inc_chains(void) * (Note that this has to be done separately, because the graph cannot * detect such classes of deadlocks.) * - * Returns: 0 on deadlock detected, 1 on OK, 2 on recursive read + * Returns: + * 0: on deadlock detected; + * 1: on OK; + * LOCK_TYPE_RECURSIVE: on recursive read */ static int check_deadlock_current(struct task_struct *curr, struct held_lock *next) @@ -2452,15 +2455,15 @@ static inline void inc_chains(void) * Allow read-after-read recursion of the same * lock class (i.e. read_lock(lock)+read_lock(lock)): */ - if ((next->read == 2) && prev->read) - return 2; + if ((next->read == LOCK_TYPE_RECURSIVE) && prev->read) + return LOCK_TYPE_RECURSIVE; /* * We're holding the nest_lock, which serializes this lock's * nesting behaviour. */ if (nest) - return 2; + return LOCK_TYPE_RECURSIVE; print_deadlock_bug(curr, prev, next); return 0; @@ -2563,7 +2566,7 @@ static inline void inc_chains(void) * write-lock never takes any other locks, then the reads are * equivalent to a NOP. */ - if (next->read == 2 || prev->read == 2) + if (next->read == LOCK_TYPE_RECURSIVE || prev->read == LOCK_TYPE_RECURSIVE) return 1; if (!*trace) { @@ -2946,7 +2949,7 @@ static int validate_chain(struct task_struct *curr, struct held_lock *next, * chain, and if it's not a second recursive-read lock. If * not, there is no need to check further. */ - if (!(chain->depth > 1 && ret != 2)) + if (!(chain->depth > 1 && ret != LOCK_TYPE_RECURSIVE)) goto out_unlock; } @@ -2955,7 +2958,7 @@ static int validate_chain(struct task_struct *curr, struct held_lock *next, * added: */ if (chain) { - if (hlock->read != 2 && hlock->check) { + if (hlock->read != LOCK_TYPE_RECURSIVE && hlock->check) { int distance = curr->lockdep_depth - depth + 1; if (!check_prev_add(curr, hlock, next, distance, @@ -4208,7 +4211,7 @@ static int __lock_downgrade(struct lockdep_map *lock, unsigned long ip) curr->curr_chain_key = hlock->prev_chain_key; WARN(hlock->read, "downgrading a read lock"); - hlock->read = 1; + hlock->read = LOCK_TYPE_READ; hlock->acquire_ip = ip; if (reacquire_held_locks(curr, depth, i, &merged)) -- 1.8.3.1