Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2202502yba; Mon, 6 May 2019 01:23:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqw9fS+aJ9yNG7xRHjHR1fbhiOYeXBwDei7BNfeiDbbru7xLicYl//0fYEHUONnTce+z5tQK X-Received: by 2002:aa7:9214:: with SMTP id 20mr31268609pfo.202.1557131023977; Mon, 06 May 2019 01:23:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557131023; cv=none; d=google.com; s=arc-20160816; b=L3YGmSNxAQs+sztsz29Fpd5QllngAwpK7l/RMq4nkCB1lcme7TQ0yzatB4e3Bvgp5P mEZ4lYxYLJPBLz0K4JkJkmY/ypzvCmTTXZxGsdq4myFq2Zyx+tED8ssBqMkYWroHDWBU jXsfbRmL4bCarwaZbHIAZaSDT2pmx8ZNcVgr5xMby0UIGssS8s0egWEgQiszjLUCqt3J FCrym8hp9J0wFf57t/IfvwfcmCd8NNT/7q0htO858nk9JIasDvSpZFb8Q9YEFzWRs7WI 2Pz3huzyw3+inybLCdR+VjhKkFNMuS33vNhS3RVXFye5xRJB+r2kTmHD/HXzocm9RfNu f3xQ== 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=QxG1O4WWZxwFIRqkhxWEPqmVT9qEXuTD/gGlj/tlLpY=; b=mQ6Z9w4xTVcRNMvwmgIEizvVyl9dwYeEouNTywuH4NJfqU7mcEtgiMGI+PamppS751 Dr/a4om3K7dlJ48zunzVYke/tilMVnraDGmP9f7ey5oXUeSm3KaNwPcvA760krUdmG02 G+/yM5Y/5pDxtR2yam7F7cuSAp15b/x80Dihova0z1sfXZh9/BZiywexs4CtqvgyF5cW q1HjNQU3kgWCe79EQJ45tE89qbpHVPWRfEpzAC46zcT5tK8lVfQrQDuaLN0V0ZCbXx/e w2DpKj6OQQsAk3NLu4F6K1mahP6cyRtvcF1kukodbnJ5BvsjdE8nNShn4krg59tNAOzS Au4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rNlEyEgK; 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 g69si13535092pgc.408.2019.05.06.01.23.28; Mon, 06 May 2019 01:23:43 -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=rNlEyEgK; 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 S1726751AbfEFIVC (ORCPT + 99 others); Mon, 6 May 2019 04:21:02 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:43950 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726739AbfEFIVA (ORCPT ); Mon, 6 May 2019 04:21:00 -0400 Received: by mail-pg1-f196.google.com with SMTP id t22so6082241pgi.10 for ; Mon, 06 May 2019 01:20:59 -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=QxG1O4WWZxwFIRqkhxWEPqmVT9qEXuTD/gGlj/tlLpY=; b=rNlEyEgKW6hDoDHLX1fSr9fvlWUxtHa2VzHauzurG1LLg2qyLoh6pvJ+9Hx4oWzRbM FvSdAuMncfV9vcjlZDNcgXwOgntveG6ft1R7AeFmpe04Fx9ke6OWChd/OzJJcs+1pGmA /EOlea2I/IYveP8rNmifPzg4aVKduwNJA+5flBQilwBSutmZAOziGf+WIrVODD0jeDDc HJJTfpcvHI8rzB1RGSaVe9AUPFsdoMu32gb/OvGDrYiGO+c3gMCfHSPr0GBfCIXmdVTD J3DjOCwiqOAcdbe92gI04Ar1jIrM6yQuwmMYCeDRw1wnY3qvDKYVwvJNFSnFrKm7FZ1y Lknw== 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=QxG1O4WWZxwFIRqkhxWEPqmVT9qEXuTD/gGlj/tlLpY=; b=ehFgqr39nfSg8OkqK/4pnEwHhh+z/nTGXIuiFyrbqDkFc+/2elri9OLbdOxJ/7Qvkq 7YjhwONUpNlAKw2yyQncA/5qxbD+X80LhGI0y+MeG0MiF8yRlLVZ4QQBRUYmjg0cGK12 DRyXUj0QjHQGiCmEDNtEo1zxdtbW8IzAuJZiTLg0l4Dg0HTS2RDyVqrY/DeSlsjge1SP PTaCntSMgICcXy0EptraSOHGK6AsZbXnAQXck5SjGt8c7d7r6MoxRDTtQx6g3xBEfyJ2 4YBAygfcoDNgF//lXAR+GqWl7fZ5IMFJk0/e9c1i+VUSSKnCkvObgDTgONEL4KiFRGDk tQtw== X-Gm-Message-State: APjAAAVSbTD1pnyxlRLDskA8s6yUSMzZ+sY8xzpNsD9J06Gc/mqMKzXM ZvK0OelX5oc3fjhAJCpQwm0= X-Received: by 2002:aa7:80d0:: with SMTP id a16mr32496632pfn.206.1557130859204; Mon, 06 May 2019 01:20:59 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id v19sm20958013pfa.138.2019.05.06.01.20.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 01:20:58 -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, Yuyang Du Subject: [PATCH v2 22/23] locking/lockdep: Adjust new bit cases in mark_lock Date: Mon, 6 May 2019 16:19:38 +0800 Message-Id: <20190506081939.74287-23-duyuyang@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20190506081939.74287-1-duyuyang@gmail.com> References: <20190506081939.74287-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 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 --- 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 79bc6cd..24e3bca 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -3581,6 +3581,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: @@ -3604,25 +3609,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(); -- 1.8.3.1