From patchwork Fri Jul 30 04:15:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Desmond Cheong Zhi Xi X-Patchwork-Id: 12410387 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E5AAC4338F for ; Fri, 30 Jul 2021 04:16:10 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DE38C6101C for ; Fri, 30 Jul 2021 04:16:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DE38C6101C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 709306F3B5; Fri, 30 Jul 2021 04:16:09 +0000 (UTC) Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3C98B6F3B5 for ; Fri, 30 Jul 2021 04:16:08 +0000 (UTC) Received: by mail-pl1-x631.google.com with SMTP id e21so9541850pla.5 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=N2R0GcLa6kK6Jo4+YXM7jt/d29bK3nZ1/Jt9fVARlf5OY3Jh7tLckOdDGJrSyfNWx8 WGpnfDM+hsHbG8fenBk0vE9BRydakCTgKtIcj+7faufS4RC1BuPIZut5+jMNoZgtwSkp WLgt4Bq68fuitnXRles2tluytpS8gNqWvgWwkf1MSlMc2OZ33Wf0xiMvoJZMFtdNsZNW EKOGsSbzybjiIVQc9WBnphkPf4jtoNXwFvDzj1rb7eWf8dR9+nCreE2reZ4kCpnkKr6w KLr+xOOba01wJCZdMZWv4q0WxPS9QTUwi3MkKfvBWIPGGRs1vGnZyLQivDHgWhpoaxoI VFvw== X-Gm-Message-State: AOAM531tgmvYg1AaPKvTs52ujABqmht/4BEA5Wq6d9nBJGsn/ka1DCGz 1YooCQbuCUA/xmxGO2zgAlw= X-Google-Smtp-Source: ABdhPJy+yWGhf7xYZLTwb/KaVBrcXdWzABuAHT54038pNIzOFNYsKZwvgkD1vj1A8p77hKqIWyKIFA== 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 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 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, skhan@linuxfoundation.org, Desmond Cheong Zhi Xi , linux-kernel-mentees@lists.linuxfoundation.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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) From patchwork Fri Jul 30 04:15:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Desmond Cheong Zhi Xi X-Patchwork-Id: 12410389 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B6A1C432BE for ; Fri, 30 Jul 2021 04:16:17 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C9DEA6101C for ; Fri, 30 Jul 2021 04:16:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C9DEA6101C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5ED1B6F3C2; Fri, 30 Jul 2021 04:16:16 +0000 (UTC) Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1F14B6F3C2 for ; Fri, 30 Jul 2021 04:16:15 +0000 (UTC) Received: by mail-pl1-x62f.google.com with SMTP id e5so9528588pld.6 for ; Thu, 29 Jul 2021 21:16:15 -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=RTjOUqNyS9qJHqvoohAwX/XHxdbP/hKwu8NmsnUvkUk=; b=ItslYacy27SJ4b7GiYhiajuZEYDADEadcPkuVsgi5WwJUhoyfK0Fl2xViA03tu0kop YdJ0lTZBf+On7uMIIM+OHbuG9nZnIlLenhsE/iUM8XkK53u9wqJdWCDVg46dSeIngd1X RstZYnskselzkrui5eZNfmEWGgWx4WBFYPxMsXP8D4Ur1kB9Y4G7Lc277PPWCzdflaoD Hxhm7XmzD7MMuvNdefGKbIBEWlvC/j5kvm2e+qnktZoFc61TY5xvkU+OGjC66YyUzlC6 VvOqZyQM0KN4tEz9HvpWC9HqPOppbLQOinWaUFMzeIAlFkgfClRV1Xnr4vTzp6r09Sap EOoA== 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=RTjOUqNyS9qJHqvoohAwX/XHxdbP/hKwu8NmsnUvkUk=; b=EfOISlxVdMV4NPYzHZxmY4HplTX783ab9JUZaosVe2xJp+9Gs6GCvmmOB5aLn6f/aU oiD9dbnuT1yccvIXzXXWh3HzeKmNuRcXVJxRYPP+WpmuHuyDq/1CM9jNosDkFgRbaOvL A629aPJ7zxwbpf6GscK4rVyikheGPzd0dNVxd0J51VgKYZWKk7zO0ORaZRUz02n+hpQa E6FKtONM8cJlV0z1ohC4rtf5ecVs9DDqRmiP7Yl2iswVaUhccQjLDVIQcXQulFZ2Zw8D YI1GWwj9LXCqt5ZxYZlnPkBDYQ7xkGBjJFSc1viRPx+QtUBgFjcqCCeQfPaNoDoDYrKh +rnA== X-Gm-Message-State: AOAM532HNGHbeeeXeBrr7LZALSNy+WnbEakfVuXXtZzQfaaVfeT9zEm8 lnE1ctYXclLRESxCFK/g1So= X-Google-Smtp-Source: ABdhPJx1Cyvaf1G7x7xeUkAAew6ARMZZiaOrBSX3yqgurse9uuMelADmfCI/veBFqg5uqoygkaJFYg== X-Received: by 2002:a17:90b:1645:: with SMTP id il5mr878098pjb.113.1627618574806; Thu, 29 Jul 2021 21:16:14 -0700 (PDT) Received: from localhost.localdomain ([118.200.190.93]) by smtp.gmail.com with ESMTPSA id t19sm439322pfg.216.2021.07.29.21.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jul 2021 21:16:14 -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 Subject: [PATCH 2/2] drm: add lockdep assert to drm_is_current_master_locked Date: Fri, 30 Jul 2021 12:15:15 +0800 Message-Id: <20210730041515.1430237-3-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 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, skhan@linuxfoundation.org, Desmond Cheong Zhi Xi , linux-kernel-mentees@lists.linuxfoundation.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In drm_is_current_master_locked, accessing drm_file.master should be protected by either drm_file.master_lookup_lock or drm_device.master_mutex. This was previously awkward to assert with lockdep. Following patch ("locking/lockdep: Provide lockdep_assert{,_once}() helpers"), this assertion is now convenient so we add it in. Signed-off-by: Desmond Cheong Zhi Xi Acked-by: Boqun Feng --- drivers/gpu/drm/drm_auth.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_auth.c b/drivers/gpu/drm/drm_auth.c index 9c24b8cc8e36..6f4d7ff23c80 100644 --- a/drivers/gpu/drm/drm_auth.c +++ b/drivers/gpu/drm/drm_auth.c @@ -63,9 +63,9 @@ static bool drm_is_current_master_locked(struct drm_file *fpriv) { - /* Either drm_device.master_mutex or drm_file.master_lookup_lock - * should be held here. - */ + lockdep_assert_once(lockdep_is_held(&fpriv->master_lookup_lock) || + lockdep_is_held(&fpriv->minor->dev->master_mutex)); + return fpriv->is_master && drm_lease_owner(fpriv->master) == fpriv->minor->dev->master; }