From patchwork Fri Dec 16 07:46:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9477437 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1314F6047D for ; Fri, 16 Dec 2016 07:50:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 064882880C for ; Fri, 16 Dec 2016 07:50:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB92928810; Fri, 16 Dec 2016 07:50:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6AD442880A for ; Fri, 16 Dec 2016 07:50:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C1C4D6EB44; Fri, 16 Dec 2016 07:50:37 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id AB15A6EB1B; Fri, 16 Dec 2016 07:47:33 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id a20so3537424wme.2; Thu, 15 Dec 2016 23:47:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=nstyjKfDPjG2TscVAJcNmWQFq9PFMgK22ANXpdeqGjU=; b=IH7oTqwiwUvUaq45t27eHnWAjv+HcXgE+KzES5UOxyqOb6LX5BDPebjJKpkSUJLo1p +3LNo0Tt1y+xLMhDZksyFWZcFIaX7yI8MVpp6nnZdgDNoMb3FrLlwHYk4K6xs3grICXy eabvNIYWQEoTF48fsjiSwDgrfCCtXiiXIG79WZ18nYaRmCaUu6Bl3YuGgTMqNZnwgECY VYReXxJRso27PhBdkj/Y4M2L8yiAvgaJlF9qBggPiimiVq8xZ2k4DAci4QP2sOnY3Eae bQdsdPqVxBQyifvJMEzLrHqZjJD31Bh88UpZfSu/QkuYr9uUwUEpXH6ncJeSHS9uTrrA 1rrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=nstyjKfDPjG2TscVAJcNmWQFq9PFMgK22ANXpdeqGjU=; b=A8vsb02EMps8MXmWoZchxqZQnLmxcKWVBgcyPSsYx4CCvrBkpgB0xFGGMMb33N/D+2 muQl+s9JkVVsirp+W/+gayMfCpOUC0dwwjIh9jNNaok/yyvcYQOCXH32Rnh7CVCv5p2P DFLG4MSk/d+Fwa8Nm5yJ87eDW/4iJHGzgvgQkZ1T2hUxUxJPyHjjud9oC8Vug1OyK6kM zKVWIRtNaS6b0b3cs8DIENINDh4D/30z6+r5VBjMOLDyjnB9Vt6SDulrqaFz19SrREz7 E+2xphFp5ED8h+hYWw28bwDbQQc+m3Hcm0n+KWCrZZJ5f3K0Gk9ZSzoV1mAh3fwR5K3m 5ieg== X-Gm-Message-State: AIkVDXIBjcJUr6h1OmikzRUSv99h3bb35vFUaFIa5lxejQFSu7jCHPe8Xp6Dkvk5SB5hvQ== X-Received: by 10.28.154.140 with SMTP id c134mr1465766wme.25.1481874451831; Thu, 15 Dec 2016 23:47:31 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id c202sm2792407wme.1.2016.12.15.23.47.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Dec 2016 23:47:31 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 05/40] drm: Compile time enabling for asserts in drm_mm Date: Fri, 16 Dec 2016 07:46:43 +0000 Message-Id: <20161216074718.32500-6-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161216074718.32500-1-chris@chris-wilson.co.uk> References: <20161216074718.32500-1-chris@chris-wilson.co.uk> Cc: intel-gfx@lists.freedesktop.org, joonas.lahtinen@linux.intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Use CONFIG_DRM_DEBUG_MM to conditionally enable the internal and validation checking using BUG_ON. Ideally these paths should all be exercised by CI selftests (with the asserts enabled). Signed-off-by: Chris Wilson Reviewed-by: Joonas Lahtinen --- drivers/gpu/drm/drm_mm.c | 45 +++++++++++++++++++++++---------------------- include/drm/drm_mm.h | 8 +++++++- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c index 7573661302a4..2b76167ef39f 100644 --- a/drivers/gpu/drm/drm_mm.c +++ b/drivers/gpu/drm/drm_mm.c @@ -237,7 +237,7 @@ static void drm_mm_insert_helper(struct drm_mm_node *hole_node, u64 adj_start = hole_start; u64 adj_end = hole_end; - BUG_ON(node->allocated); + DRM_MM_BUG_ON(node->allocated); if (mm->color_adjust) mm->color_adjust(hole_node, color, &adj_start, &adj_end); @@ -258,8 +258,8 @@ static void drm_mm_insert_helper(struct drm_mm_node *hole_node, } } - BUG_ON(adj_start < hole_start); - BUG_ON(adj_end > hole_end); + DRM_MM_BUG_ON(adj_start < hole_start); + DRM_MM_BUG_ON(adj_end > hole_end); if (adj_start == hole_start) { hole_node->hole_follows = 0; @@ -276,7 +276,7 @@ static void drm_mm_insert_helper(struct drm_mm_node *hole_node, drm_mm_interval_tree_add_node(hole_node, node); - BUG_ON(node->start + node->size > adj_end); + DRM_MM_BUG_ON(node->start + node->size > adj_end); node->hole_follows = 0; if (__drm_mm_hole_node_start(node) < hole_end) { @@ -409,7 +409,7 @@ static void drm_mm_insert_helper_range(struct drm_mm_node *hole_node, u64 adj_start = hole_start; u64 adj_end = hole_end; - BUG_ON(!hole_node->hole_follows || node->allocated); + DRM_MM_BUG_ON(!hole_node->hole_follows || node->allocated); if (adj_start < start) adj_start = start; @@ -450,10 +450,10 @@ static void drm_mm_insert_helper_range(struct drm_mm_node *hole_node, drm_mm_interval_tree_add_node(hole_node, node); - BUG_ON(node->start < start); - BUG_ON(node->start < adj_start); - BUG_ON(node->start + node->size > adj_end); - BUG_ON(node->start + node->size > end); + DRM_MM_BUG_ON(node->start < start); + DRM_MM_BUG_ON(node->start < adj_start); + DRM_MM_BUG_ON(node->start + node->size > adj_end); + DRM_MM_BUG_ON(node->start + node->size > end); node->hole_follows = 0; if (__drm_mm_hole_node_start(node) < hole_end) { @@ -519,22 +519,21 @@ void drm_mm_remove_node(struct drm_mm_node *node) struct drm_mm *mm = node->mm; struct drm_mm_node *prev_node; - if (WARN_ON(!node->allocated)) - return; - - BUG_ON(node->scanned_block || node->scanned_prev_free - || node->scanned_next_free); + DRM_MM_BUG_ON(!node->allocated); + DRM_MM_BUG_ON(node->scanned_block || + node->scanned_prev_free || + node->scanned_next_free); prev_node = list_entry(node->node_list.prev, struct drm_mm_node, node_list); if (node->hole_follows) { - BUG_ON(__drm_mm_hole_node_start(node) == - __drm_mm_hole_node_end(node)); + DRM_MM_BUG_ON(__drm_mm_hole_node_start(node) == + __drm_mm_hole_node_end(node)); list_del(&node->hole_stack); } else - BUG_ON(__drm_mm_hole_node_start(node) != - __drm_mm_hole_node_end(node)); + DRM_MM_BUG_ON(__drm_mm_hole_node_start(node) != + __drm_mm_hole_node_end(node)); if (!prev_node->hole_follows) { @@ -578,7 +577,7 @@ static struct drm_mm_node *drm_mm_search_free_generic(const struct drm_mm *mm, u64 adj_end; u64 best_size; - BUG_ON(mm->scanned_blocks); + DRM_MM_BUG_ON(mm->scanned_blocks); best = NULL; best_size = ~0UL; @@ -622,7 +621,7 @@ static struct drm_mm_node *drm_mm_search_free_in_range_generic(const struct drm_ u64 adj_end; u64 best_size; - BUG_ON(mm->scanned_blocks); + DRM_MM_BUG_ON(mm->scanned_blocks); best = NULL; best_size = ~0UL; @@ -668,6 +667,8 @@ static struct drm_mm_node *drm_mm_search_free_in_range_generic(const struct drm_ */ void drm_mm_replace_node(struct drm_mm_node *old, struct drm_mm_node *new) { + DRM_MM_BUG_ON(!old->allocated); + list_replace(&old->node_list, &new->node_list); list_replace(&old->hole_stack, &new->hole_stack); rb_replace_node(&old->rb, &new->rb, &old->mm->interval_tree); @@ -798,7 +799,7 @@ bool drm_mm_scan_add_block(struct drm_mm_node *node) mm->scanned_blocks++; - BUG_ON(node->scanned_block); + DRM_MM_BUG_ON(node->scanned_block); node->scanned_block = 1; prev_node = list_entry(node->node_list.prev, struct drm_mm_node, @@ -859,7 +860,7 @@ bool drm_mm_scan_remove_block(struct drm_mm_node *node) mm->scanned_blocks--; - BUG_ON(!node->scanned_block); + DRM_MM_BUG_ON(!node->scanned_block); node->scanned_block = 0; prev_node = list_entry(node->node_list.prev, struct drm_mm_node, diff --git a/include/drm/drm_mm.h b/include/drm/drm_mm.h index 5c7f15875b6a..0b0485aff9df 100644 --- a/include/drm/drm_mm.h +++ b/include/drm/drm_mm.h @@ -48,6 +48,12 @@ #include #endif +#ifdef CONFIG_DRM_DEBUG_MM +#define DRM_MM_BUG_ON(expr) BUG_ON(expr) +#else +#define DRM_MM_BUG_ON(expr) BUILD_BUG_ON_INVALID(expr) +#endif + enum drm_mm_search_flags { DRM_MM_SEARCH_DEFAULT = 0, DRM_MM_SEARCH_BEST = 1 << 0, @@ -155,7 +161,7 @@ static inline u64 __drm_mm_hole_node_start(const struct drm_mm_node *hole_node) */ static inline u64 drm_mm_hole_node_start(const struct drm_mm_node *hole_node) { - BUG_ON(!hole_node->hole_follows); + DRM_MM_BUG_ON(!hole_node->hole_follows); return __drm_mm_hole_node_start(hole_node); }