From patchwork Fri Dec 16 19:25:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9478379 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 19B0C601C2 for ; Fri, 16 Dec 2016 19:29:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 09DA828772 for ; Fri, 16 Dec 2016 19:29:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F060B287DB; Fri, 16 Dec 2016 19:29:43 +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=ham 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 5651B28772 for ; Fri, 16 Dec 2016 19:29:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0D6D86ECD9; Fri, 16 Dec 2016 19:29:42 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 45E476ECDB; Fri, 16 Dec 2016 19:26:20 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id g23so7268299wme.1; Fri, 16 Dec 2016 11:26:20 -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=rBNKDLFG1pPKqGgkMeV21Hsxt8icrzgxjBqVlNjm1RI=; b=PyiLLt7K2Qwc7Kb6bfhU1ZznnTKdqUFxUGoq69aB5/4ZphbH5OCoi+0+tRB+cbxuZ8 zH5AE36g1hWcmIMdXAVpAlN+jFF6WHAa0NuT/BwZ1q1Jl31FFluJDdDVwa5cDNchcrLg v/ybmEz+oEUXbstHNTDAsToRlvzXHOPBt4dARlFPgmgotsq2beFCLYFxgIf2sgGkDfF7 yO8qOSm8Hi5InufCYGQh/ugcRzi8zOfqXLJofSGZlRVXhS2DXVxXSiLbTHS1mIjdXKBS LNPIoASQNjL7Iyh0APWeBWCUsyD4B5bWMq8Bp4kFp8cH2msuftbkSzUadghYfsy/jZi6 hNIg== 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=rBNKDLFG1pPKqGgkMeV21Hsxt8icrzgxjBqVlNjm1RI=; b=CyubNEJm+A9RxfNqfbridkTnvOPEmQlPfVhCGR+xlUQzZVLctnCZ6w1pZpmpF2aCKd nTYL+svqcHTu4MzYGI1NUEl2o7a049tAmuwvmpfISmN+zU3CYOgx7Xif9pyP6vq5Aoqa OHDD5vVMZXmjmAyyMg71rmU9Mju9869T7lpa/c/f8ASRu3wxq5PITNCqLthw7M58VUzQ hcHKZFEKhK71kz7O287YkDmGsWeeULqNEx7PSwUj6rryYl3CzN2OSkIUN62Z8rkWMNoR 1t/iubVdBdtZ9oIjvgD6r+//rKfBj7CPTaZzEuUmpGuirZgt2YIOyFBikTWao1SusvNq 2gEw== X-Gm-Message-State: AIkVDXJl9mq2QP4NIZ62rYfgeL8CXPl/+zLNFXJTc6c9LhYVxGM9Xxjrc7b+eETx0ZQC2w== X-Received: by 10.28.87.84 with SMTP id l81mr4720500wmb.48.1481916378384; Fri, 16 Dec 2016 11:26:18 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id v2sm8125856wja.41.2016.12.16.11.26.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Dec 2016 11:26:17 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 25/38] drm: Add asserts to catch overflow in drm_mm_init() and drm_mm_init_scan() Date: Fri, 16 Dec 2016 19:25:37 +0000 Message-Id: <20161216192550.8352-26-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161216192550.8352-1-chris@chris-wilson.co.uk> References: <20161216192550.8352-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 A simple assert to ensure that we don't overflow start + size when initialising the drm_mm, or its scanner. In future, we may want to switch to tracking the value of ranges (rather than size) so that we can cover the full u64, for example like resource tracking. Signed-off-by: Chris Wilson Reviewed-by: Joonas Lahtinen --- drivers/gpu/drm/drm_mm.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c index e0419cf09bbb..b80305484124 100644 --- a/drivers/gpu/drm/drm_mm.c +++ b/drivers/gpu/drm/drm_mm.c @@ -729,6 +729,8 @@ void drm_mm_init_scan(struct drm_mm *mm, u64 alignment, unsigned long color) { + DRM_MM_BUG_ON(!size); + mm->scan_color = color; mm->scan_alignment = alignment; mm->scan_size = size; @@ -764,6 +766,9 @@ void drm_mm_init_scan_with_range(struct drm_mm *mm, u64 start, u64 end) { + DRM_MM_BUG_ON(start >= end); + DRM_MM_BUG_ON(!size || size > end - start); + mm->scan_color = color; mm->scan_alignment = alignment; mm->scan_size = size; @@ -882,6 +887,8 @@ EXPORT_SYMBOL(drm_mm_scan_remove_block); */ void drm_mm_init(struct drm_mm *mm, u64 start, u64 size) { + DRM_MM_BUG_ON(start + size <= start); + INIT_LIST_HEAD(&mm->hole_stack); mm->scanned_blocks = 0;