Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp104098pxy; Sat, 31 Jul 2021 01:29:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVWzKNWuz6Stcd1tzOECBfejiwQCRa9no2+IWyPlUww8QME7ey5V9s2ultcl5YA46SDvHi X-Received: by 2002:a05:6402:361:: with SMTP id s1mr7874180edw.172.1627720142880; Sat, 31 Jul 2021 01:29:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627720142; cv=none; d=google.com; s=arc-20160816; b=Pw+tOaqLG49SND5Rg6YF4/rPcJ0eyTTOQTydn15fHJ2iv+sHVTxmqHIrZZuOfT83+Q RjuDFJXZkWRuzueNkKeC03hhsPtSMFbdKFSCwgCygLnsgdzFoh6zkHebAp6tG1X6Oct1 VRG/XF6I8JFwByktpX8x/fcJgOB6bBDvgCrqNw5gcUdGYC+O7+ZACr2qnyIb3JfXAEb2 +uoJbE28Pxvwuye7Bkec6eyFymn1OeE7nTVt2wjXU81c/xYTfQ7XWMILpkoWj7C2Gihs lj/Uv6rFV9IOR4jrzIxnYKjZGyyz3A1gbgMMM/hlbVA+6Jeh31lrBdg+MrQTRBtlEaKc aqzQ== 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=nd7PzJX7+jqe7frYn0qs43GsaGl8y9GB3YlzBIkjvSg=; b=MuiWfB9jmOfjrjKBLqRqn3Dgd6E7e+EQKV7HoWGnH3ZvnvC2X9SHW1OlZRb8YdG9e7 ckbD4ichR1+6eIg+3s4Du78lU2z6Co/7gooTLrxzU2CBBAdQMrlRQe1lCAhctlgWJzKv dk/yyGFGnLvCCtIM+HjkwKRHfdw878O0OaI9xzUxU5opFkE81u3264rcur84tCCfvufv xUv2QUOT5RVI3+0GynuP2hNSfVApIu1iQuazoYpTy/AbJhElsFlKqXDt8NFnxV+xDue7 nsVCSB0e+seaA7yKZf7nhbXz7IClvh23O9OFVf+feXWlcGXKAcy079k/Kl70Al8GTrcn uM0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=In1GBHET; 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 r27si4602941ejb.365.2021.07.31.01.28.36; Sat, 31 Jul 2021 01:29:02 -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=In1GBHET; 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 S232297AbhGaI1F (ORCPT + 99 others); Sat, 31 Jul 2021 04:27:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232258AbhGaI1D (ORCPT ); Sat, 31 Jul 2021 04:27:03 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DCD7C06175F for ; Sat, 31 Jul 2021 01:26:57 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id o44-20020a17090a0a2fb0290176ca3e5a2fso17764123pjo.1 for ; Sat, 31 Jul 2021 01:26:57 -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=nd7PzJX7+jqe7frYn0qs43GsaGl8y9GB3YlzBIkjvSg=; b=In1GBHETrUvRO4qRIm5DeTr9wI4tS2t8opQEALIP1jBGe5Hu90iJag5PLov6HIl1u3 PsaE8ivBkT4IPi1OBmBP9lkMKhJM5IySeGgBbhAmYeYBqDAXkZyOfrRbYJ7bUOCGYubO 2h1ukuENnKKN88E5Gjv1NNTiWDiEdqPFzUIKvb0U3bB9CkChgYkQPBNSUZ2u1hMLPTpT EV/v/VKQe6tVFygm/++UjyeifcIF0XfeLUMQlRSCL/lDd/q2v2WMaeBqXjfSPpcN585/ VEhCZwXYxH0vyppwdU0adJ6agqAk6Ia8+tg5zR4hoW81+xyc2Tanpp52FQZ5UPt3WC1i Xzfw== 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=nd7PzJX7+jqe7frYn0qs43GsaGl8y9GB3YlzBIkjvSg=; b=HVaSP2uCzqcERcmu2MYHvb7lZCYLETekxsq8Bm/SS9UgZNvsJ5VReTzDvUz7kKhDXL K9CIkwPBlTbwDkPNz0MMtTwwiFMqa4HP5xYrfnXie8ZojHWorUJah2LOHpe4H2+frgw9 6x25LIUyWbPLjL/7NRkypUsnuocQp5evSWYsam7CXnFhp0Fj9QsHu0kYyuQg13OLTd+i 15lT+nySS7o/6bwQqN5McSnEzwkS/uTRbs0jceeFGS0lU8HvaPrWuO7aV5dsbrYh2dig 87eWwSglt/ufpoCD+M+nFfwoGbfJVy7X3HFWY8Lg5Iv5TxedqBf048J67gteamRLsB0v lYcw== X-Gm-Message-State: AOAM5313rnzdVs82zZ0fBoFfvH5XDk7VeqNiJ1tbJOShEVbMD7ELPnui uZsJf5nImt9aHDqVlckiRpc= X-Received: by 2002:a63:4b0a:: with SMTP id y10mr5827758pga.437.1627720016657; Sat, 31 Jul 2021 01:26:56 -0700 (PDT) Received: from localhost.localdomain ([118.200.190.93]) by smtp.gmail.com with ESMTPSA id mq7sm3182124pjb.50.2021.07.31.01.26.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Jul 2021 01:26:56 -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 v2 1/2] locking/lockdep: Provide lockdep_assert{,_once}() helpers Date: Sat, 31 Jul 2021 16:24:57 +0800 Message-Id: <20210731082458.1962043-2-desmondcheongzx@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210731082458.1962043-1-desmondcheongzx@gmail.com> References: <20210731082458.1962043-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 Acked-by: Boqun Feng Acked-by: Waiman Long --- 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