Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4384512ybi; Mon, 3 Jun 2019 09:59:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqxWCYoiVVgY+IZhA4yo36Z0I0NJ/ppYdwnXR0/9ANEZsHU4Md0rhEzz9W4ZVJYTha3WU0Dx X-Received: by 2002:a62:5a47:: with SMTP id o68mr31944345pfb.149.1559581157327; Mon, 03 Jun 2019 09:59:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559581157; cv=none; d=google.com; s=arc-20160816; b=AuS2tP9vvYaPSlEddcg+0ZRHvaom3C77d/gAmOlmNEYSB119DB9dRsfXBRwkAdSTXj FVfXT3+QKVkKWnuELOKfiyXCBREU1o8qc+PECyqo7bxSZ4ZyTP2MGWASoCE87dyQFRn3 xBbBHOSevYhmhhwylouS1KF9KZOL6Y2aqrFFt5fIvAGdR/+i+ht9CD7719mqdOlz5sVG t8qElzXYOmM69aPzWVSo/eDiot1tfjQI/16QszNp4NffCwKo3vxsP7NJKDymidVEUHuo waIuoKXtCNjaHKcanXEabV2VXiilWlBpfmLyLx6VnrRfvYRqwoDlNCTWLLggWDyPY2Vk lATA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:dkim-signature:dkim-filter; bh=RN2wDhoFLq6ABqLxgEME/VQcliZo+R93w8KdtFHEgTo=; b=Bjnxv3MZ0aGodmJX7Bz9CaXqp5zqKqcSRP/Yw5EXywuAa7cpAVHU5Ee3Ak4WDvYjgp xJOIcqzVmNRXrAul9mDVaOOVWCczahbgMEjjN0y4ZJCdXKwemU8/oehyZ/v0053YGIxS zdmp4iwWZpw8EUvd9RFsm/eRFVrno3fyaPz8IeDusavC913xoseqQ/iWKd6cQ12MZHNn o0RGyo9Ddg0GSQ4fbnkBmrqArUQp8W3wyU1k6AGB4pSq291S+PL+uI/gZxOSE433ZZ7s 4TF5rIN568IAXzOlf/fLLhXWqcE/Y+LE9LfR3lcUoAId5dpiVWBZ/zOMB8pjmKC5roaM YrSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019051801 header.b=fcHr2hRT; 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=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v89si17981350pjb.14.2019.06.03.09.59.01; Mon, 03 Jun 2019 09:59:17 -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=@zytor.com header.s=2019051801 header.b=fcHr2hRT; 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=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728597AbfFCNVv (ORCPT + 99 others); Mon, 3 Jun 2019 09:21:51 -0400 Received: from terminus.zytor.com ([198.137.202.136]:44251 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726336AbfFCNVv (ORCPT ); Mon, 3 Jun 2019 09:21:51 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x53DLeso607066 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 3 Jun 2019 06:21:40 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x53DLeso607066 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019051801; t=1559568100; bh=RN2wDhoFLq6ABqLxgEME/VQcliZo+R93w8KdtFHEgTo=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=fcHr2hRTwMOaX1y+aJr3L3AP6c+MX52XBxnjU+Jjw2xgSUzPPpTXh2fpwUHfkSGM5 9fUx7fCKO8u32nMgVZsjYuBW1T4wvnPhOExFQG2OwFuydRMGVqpJXCavtbohHVGO5g SmkOxRVR+/uielN8iiNDy7aCY/ln9IHwpAhjDGKmcr7LAkZTyU7UnNj38M42MdYbeb WWtf3L1zyaohpfFzh02Xs3cbbuNN9eVwQDDafsccI/AiVqLLu3m/vK5jpWvueNU0Pr 0P1gloB5rzpqqv8uFLTTI2lMR15Inf/Yb12Tf2PVSu4KvffVkbvgBhNCORSOYefFjc JUviDy11Y/MRQ== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x53DLedE607063; Mon, 3 Jun 2019 06:21:40 -0700 Date: Mon, 3 Jun 2019 06:21:40 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Yuyang Du Message-ID: Cc: hpa@zytor.com, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, tglx@linutronix.de, mingo@kernel.org, peterz@infradead.org, duyuyang@gmail.com Reply-To: hpa@zytor.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@kernel.org, torvalds@linux-foundation.org, peterz@infradead.org, duyuyang@gmail.com In-Reply-To: <20190506081939.74287-23-duyuyang@gmail.com> References: <20190506081939.74287-23-duyuyang@gmail.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/core] locking/lockdep: Adjust new bit cases in mark_lock Git-Commit-ID: 4d56330df22dd9dd9a24f147014f60ee4c914fb8 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-0.3 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, FREEMAIL_FORGED_REPLYTO autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 4d56330df22dd9dd9a24f147014f60ee4c914fb8 Gitweb: https://git.kernel.org/tip/4d56330df22dd9dd9a24f147014f60ee4c914fb8 Author: Yuyang Du AuthorDate: Mon, 6 May 2019 16:19:38 +0800 Committer: Ingo Molnar CommitDate: Mon, 3 Jun 2019 11:55:52 +0200 locking/lockdep: Adjust new bit cases in mark_lock The new bit can be any possible lock usage except it is garbage, so the cases in switch can be made simpler. Warn early on if wrong usage bit is passed without taking locks. No functional change. Signed-off-by: Yuyang Du Signed-off-by: Peter Zijlstra (Intel) Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: bvanassche@acm.org Cc: frederic@kernel.org Cc: ming.lei@redhat.com Cc: will.deacon@arm.com Link: https://lkml.kernel.org/r/20190506081939.74287-23-duyuyang@gmail.com Signed-off-by: Ingo Molnar --- kernel/locking/lockdep.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 1123e7e6c78d..9c4e2a7547d3 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -3582,6 +3582,11 @@ static int mark_lock(struct task_struct *curr, struct held_lock *this, { unsigned int new_mask = 1 << new_bit, ret = 1; + if (new_bit >= LOCK_USAGE_STATES) { + DEBUG_LOCKS_WARN_ON(1); + return 0; + } + /* * If already set then do not dirty the cacheline, * nor do any checks: @@ -3605,25 +3610,13 @@ static int mark_lock(struct task_struct *curr, struct held_lock *this, return 0; switch (new_bit) { -#define LOCKDEP_STATE(__STATE) \ - case LOCK_USED_IN_##__STATE: \ - case LOCK_USED_IN_##__STATE##_READ: \ - case LOCK_ENABLED_##__STATE: \ - case LOCK_ENABLED_##__STATE##_READ: -#include "lockdep_states.h" -#undef LOCKDEP_STATE - ret = mark_lock_irq(curr, this, new_bit); - if (!ret) - return 0; - break; case LOCK_USED: debug_atomic_dec(nr_unused_locks); break; default: - if (!debug_locks_off_graph_unlock()) + ret = mark_lock_irq(curr, this, new_bit); + if (!ret) return 0; - WARN_ON(1); - return 0; } graph_unlock();