Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6636301pxv; Thu, 29 Jul 2021 21:18:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1H9OtH7K0wrIk+kb5IAZzQnbcM6zQjVoPt2qqIhnF5HMtAIuHbIx+/7TLuPQM4hWnL916 X-Received: by 2002:a6b:e706:: with SMTP id b6mr115189ioh.202.1627618727279; Thu, 29 Jul 2021 21:18:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627618727; cv=none; d=google.com; s=arc-20160816; b=UzaZ0Y13TnJ+KNXIVwUi2eJEYvuH6A9gn/i1XlqGvILmpqPsvRsbaZi8dGxvNyt5vh 8I4sa7iurqimAnZWfzhSPahqsKMWLsEIC2X/eaLW7LBNpSTYZ97AL6sdwozbdYIpafed GjYygtqUtnlhkfBMqRYOlmVHHCE6YvdMp5sMDnQ7M75CHfNUPe46sCJnnsP1aScAuA/b JIdOKWf1+hEr8tYK/TplQ4sP+YKNY1aJDyA9GJrMYiBIStVVFzH9VY5iuglwOX3HzaT6 7hUqixqmsD15ZHp7a85bp567sjyspLtxlarYx2hAQJ5OQ4157zcDi+7mMwGMDa3Tm0uN b8Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sNpsX16ewG1iiORmtZLS9PvQb+EIL7dKmm9U42mmA8Q=; b=gT/bt22N6Y7ElTESvUcd+RstlrP+9MRkUaoBrl6zJJsKhZWQ3wStg2p9MVLrP1aSHM 2Ale3DXAQJW4UJzC4gOlhb86FPaOonNuBcvcgrxk1UeSc3ZZeC4ziEy4S8e0ONl8MKJV TgGlmja5IVL0ZH4kAYikiiLrqWd/heEzK04EFigyZ5yp3rn2jqgqnK4GP6oFnm7Eb0Hb z3kF/wYaGw7EjEHJFauoaEU5x3qTXvfhbEf9slDRW9gVL15FxGn/jy0fYGG3re0aZ/d4 edCuCrT1GaS3ZrNDeWvNqnwxcpVm5gIhdKNlOYgHeXjgP1SZJ9aDqGQbo6HqtDC+UPLx M8fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ud7pUpMB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id a6si497832ilv.81.2021.07.29.21.18.35; Thu, 29 Jul 2021 21:18:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ud7pUpMB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S233424AbhG3EQr (ORCPT + 99 others); Fri, 30 Jul 2021 00:16:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231897AbhG3EQa (ORCPT ); Fri, 30 Jul 2021 00:16:30 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51A0AC061796 for ; Thu, 29 Jul 2021 21:16:08 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id z3so8208140plg.8 for ; Thu, 29 Jul 2021 21:16:08 -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=sNpsX16ewG1iiORmtZLS9PvQb+EIL7dKmm9U42mmA8Q=; b=Ud7pUpMBgAV45KErEo5arYi0ZcWV1YkNk6F+QLPSB30bGRKkONHEmqIRmG2KMw2Azu kVhstTDTB5rjbdYv9QPkLWm+Rv1i1WwKTb7RvgVzPu5mkfgNZF20GrQi+jAVE5f3+azw oMPXalcmC0aS0bc8T7aHFlZKblk/EC7SyVGAHOTjrc9rXv9ddnfTK5dDuTYK+eSIwlPz uCrh5ASccN6GsO8hrS+WeI5tu9+Ra1jfnSg+dqn/oZBjIbgVW+lbnuOIJcEBG1TeB/g3 8fqUS5eZXhV41aBF5xyk4RcX7dLEPjYXcR1TsbCCREqiAStlfropXNwTEa2dJCERam7V Py9w== 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=sNpsX16ewG1iiORmtZLS9PvQb+EIL7dKmm9U42mmA8Q=; b=eDoEUbmYEi1lJK5SwEq2SrswRKbYpPjNZb/jppcu15H2oj0I7hrVDOU+zHjWMKDyTf TMOlhmoHazM+fVMER0eWdIhn1PcXb6uULGRdgD45svv4M8CFVzVjbTClvZVeHtmmfhzW igzJG+JZh48XYteTszJNQeee7/zEl9JpkdASeYcjMNHwgpLJUlaz3VozRS1U+ieKaN2k dXiop53MGGyOEDi1OjejqBpIoinTaLLqfWEDA/Paf8nEZeEYJnDc30CuaGcSHiX6G6IK 2NvTatOoWQ8+y+PDSSAePhlU6oi4+PVRoCzJe7rzNX28L6rx7253nUn5MlN3xCmRO4Ri 0TOw== X-Gm-Message-State: AOAM533EYiVK1SeT1eqhQERw/5EAyai2ugk6HlkT3VYq4mD67+E8UNOm gtZHWVSymnhl4F9nXMVaEUg= X-Received: by 2002:a63:dc15:: with SMTP id s21mr505834pgg.281.1627618567842; Thu, 29 Jul 2021 21:16:07 -0700 (PDT) Received: from localhost.localdomain ([118.200.190.93]) by smtp.gmail.com with ESMTPSA id t19sm439322pfg.216.2021.07.29.21.16.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jul 2021 21:16:07 -0700 (PDT) From: Desmond Cheong Zhi Xi To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@linux.ie, daniel@ffwll.ch, peterz@infradead.org, mingo@redhat.com, will@kernel.org, longman@redhat.com, boqun.feng@gmail.com Cc: Desmond Cheong Zhi Xi , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, skhan@linuxfoundation.org, gregkh@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org Subject: [PATCH 1/2] locking/lockdep: Provide lockdep_assert{,_once}() helpers Date: Fri, 30 Jul 2021 12:15:14 +0800 Message-Id: <20210730041515.1430237-2-desmondcheongzx@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210730041515.1430237-1-desmondcheongzx@gmail.com> References: <20210730041515.1430237-1-desmondcheongzx@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra Extract lockdep_assert{,_once}() helpers to more easily write composite assertions like, for example: lockdep_assert(lockdep_is_held(&drm_device.master_mutex) || lockdep_is_held(&drm_file.master_lookup_lock)); Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Desmond Cheong Zhi Xi --- include/linux/lockdep.h | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index 5cf387813754..9fe165beb0f9 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -306,31 +306,29 @@ extern void lock_unpin_lock(struct lockdep_map *lock, struct pin_cookie); #define lockdep_depth(tsk) (debug_locks ? (tsk)->lockdep_depth : 0) -#define lockdep_assert_held(l) do { \ - WARN_ON(debug_locks && \ - lockdep_is_held(l) == LOCK_STATE_NOT_HELD); \ - } while (0) +#define lockdep_assert(cond) \ + do { WARN_ON(debug_locks && !(cond)); } while (0) -#define lockdep_assert_not_held(l) do { \ - WARN_ON(debug_locks && \ - lockdep_is_held(l) == LOCK_STATE_HELD); \ - } while (0) +#define lockdep_assert_once(cond) \ + do { WARN_ON_ONCE(debug_locks && !(cond)); } while (0) -#define lockdep_assert_held_write(l) do { \ - WARN_ON(debug_locks && !lockdep_is_held_type(l, 0)); \ - } while (0) +#define lockdep_assert_held(l) \ + lockdep_assert(lockdep_is_held(l) != LOCK_STATE_NOT_HELD) -#define lockdep_assert_held_read(l) do { \ - WARN_ON(debug_locks && !lockdep_is_held_type(l, 1)); \ - } while (0) +#define lockdep_assert_not_held(l) \ + lockdep_assert(lockdep_is_held(l) != LOCK_STATE_HELD) -#define lockdep_assert_held_once(l) do { \ - WARN_ON_ONCE(debug_locks && !lockdep_is_held(l)); \ - } while (0) +#define lockdep_assert_held_write(l) \ + lockdep_assert(lockdep_is_held_type(l, 0)) -#define lockdep_assert_none_held_once() do { \ - WARN_ON_ONCE(debug_locks && current->lockdep_depth); \ - } while (0) +#define lockdep_assert_held_read(l) \ + lockdep_assert(lockdep_is_held_type(l, 1)) + +#define lockdep_assert_held_once(l) \ + lockdep_assert_once(lockdep_is_held(l) != LOCK_STATE_NOT_HELD) + +#define lockdep_assert_none_held_once() \ + lockdep_assert_once(!current->lockdep_depth) #define lockdep_recursing(tsk) ((tsk)->lockdep_recursion) @@ -407,6 +405,9 @@ extern int lock_is_held(const void *); extern int lockdep_is_held(const void *); #define lockdep_is_held_type(l, r) (1) +#define lockdep_assert(c) do { } while (0) +#define lockdep_assert_once(c) do { } while (0) + #define lockdep_assert_held(l) do { (void)(l); } while (0) #define lockdep_assert_not_held(l) do { (void)(l); } while (0) #define lockdep_assert_held_write(l) do { (void)(l); } while (0) -- 2.25.1