From patchwork Thu Dec 22 08:36:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9484543 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 2EA4B601D3 for ; Thu, 22 Dec 2016 08:44:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28CEF27DE0 for ; Thu, 22 Dec 2016 08:44:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DC6D281C3; Thu, 22 Dec 2016 08:44:28 +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 C076B27DE0 for ; Thu, 22 Dec 2016 08:44:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BCC2E6F1BF; Thu, 22 Dec 2016 08:44:21 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wj0-x244.google.com (mail-wj0-x244.google.com [IPv6:2a00:1450:400c:c01::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8708D6F16E; Thu, 22 Dec 2016 08:36:51 +0000 (UTC) Received: by mail-wj0-x244.google.com with SMTP id j10so35200034wjb.3; Thu, 22 Dec 2016 00:36:51 -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=jb0G1AUBs0wFYLhMWeXLDwvdo9ZeBL/6dveyyxpBe9I=; b=oDRSpjqolStts9wqdXtBBsT0yDhzDqLzjZemwares6aybWBuTrmSm2Xon7Bwmt+uFT QwrVtT3qgfPpIH/qBGswY/boPitbf5gkGiz5HJXQKuuqwoH9yGbjj8Aa1XBLxdyW9L87 YyzqcOiXur3t+9W2bHAZoHSbZ2c4kZsZJJ1dfTKruYJOmwfIL/tuAa2z6g6+Hbizenun 1HnmCg9/VECfw67MTyTtLMtc53PdaRlplkbpYJTtDv+6LV631b2JAwtm/AOH+fBn0C9E tKfwr6Y4ojtvchx6O1DmN0Me5NscBOaBDZWXXWUVh0XIAxvAxksUhJ4Bcef0/4foH+Vn uk7Q== 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=jb0G1AUBs0wFYLhMWeXLDwvdo9ZeBL/6dveyyxpBe9I=; b=IjQoEG5kGMClYpR29FtoyzzQoCiWazMYanKg6f1I7AIZzEjXYiEHtLSzwZ9SnUwA1w m0NmY/e+OpGRaUfWF1XLLqx4pRslrCOVcxGewhaZ6+nw3TbhLFg+XgOYmYerRGa0rp4v cYmYwFKt/79TlC2AA/pZg+FeYMT18aV4WWaynF0Rc9ZmrxSMonygfZs4w01/XL9grw/x kZhd4ndqXXHvFszf7+pPO5LNwbLUzbwBzbrJEZ8D1gGAVheo/ludJhTHhLFuyq7bBwsX lXBiMBF4AHj3WicqECNgRDSdn/U+6o58XrAGkQ+ug1aUZE8yx556cAfEFo0zf5l0J0rf Ke5w== X-Gm-Message-State: AIkVDXIUZSKdNCwCKB4EkfnSQB9dBGvl8laKroz7zFCftHowU74EhizbssHPKegwUAN8ow== X-Received: by 10.194.9.34 with SMTP id w2mr7674840wja.24.1482395809179; Thu, 22 Dec 2016 00:36:49 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id di9sm34442318wjc.37.2016.12.22.00.36.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Dec 2016 00:36:48 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 03/38] drm: Compile time enabling for asserts in drm_mm Date: Thu, 22 Dec 2016 08:36:06 +0000 Message-Id: <20161222083641.2691-4-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161222083641.2691-1-chris@chris-wilson.co.uk> References: <20161222083641.2691-1-chris@chris-wilson.co.uk> Cc: intel-gfx@lists.freedesktop.org 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 4257c86cc305..9756542abe4c 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 f6a68ed5ecaf..525543019896 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); }