From patchwork Thu Jan 19 11:41:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9525571 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 BFCC060113 for ; Thu, 19 Jan 2017 11:43:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE41728500 for ; Thu, 19 Jan 2017 11:43:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A35F728507; Thu, 19 Jan 2017 11:43:25 +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 4845628500 for ; Thu, 19 Jan 2017 11:43:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CE2DE6E9FB; Thu, 19 Jan 2017 11:42:45 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id F1D0B6E129 for ; Thu, 19 Jan 2017 11:42:39 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id c85so11365454wmi.1 for ; Thu, 19 Jan 2017 03:42:39 -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=Tk9ETahGw+yjti9Oik2xOESSvvIadBgotEVcQgyGqCM=; b=GQfpcXaWskbGb8L+xEfwGFaNtdV8jOpPda9Jxilo+pqvgZMGfHcV8QQ8PSQw4vnMSL qYr6+9phs7a2k4u2gvep5pzgN89rYJ2HZqEuSFu8hW5p1xZv++Wlo8a0N8etUwq4knH4 Lh5GFfycqmGpleGiK1yWFgrFONTMkAKR42qQgCSxS1EgvCigALneXHQRsRpGCR3TnzHy ZZLiI0dsaYy+2W4Kc+nU9aj8zXFenXfOT6JPKItCugXr3MvLpXyi9zE57BiH3CaxTNV0 p514B2JbvGiwm5KsdUS3DPYBWyNVJ62WPJCKQgJ5unG6tOLegtMI3JE04TlsYIcLne+6 Acww== 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=Tk9ETahGw+yjti9Oik2xOESSvvIadBgotEVcQgyGqCM=; b=DXSoxLBx5QmyFmqd7FrimnihUepyqdOFpMZzW8W8ME+nUW0KbLW4SYDPhMrL8C8/pQ 5GYLYJ6nPUN58V/Iz2aBDCNkkAlyuoscHr8T6zd3Eqteeon6Djsd63+ftsteyYFVYw/N 7UYHT1kRWEmbLnJLnd9HK+BhieUOYgGRW6A1PIKb+j0oBiSAm3iNMmloPdNYboGmF9vb IuRGcBA+w/I/FzhDhzZdjEwxZX/MVIVLn9KGSquq0PQJEw/M1ZzKEuQASih9wyxwoob+ 9ugjnsFaHhiStLy4e8BPf0oIWr5S7ve72xq2am13VHpDa0e5FA3RK5LcSlG+5hms6YQA ZzRA== X-Gm-Message-State: AIkVDXLdVFrwVuJmQqN0gymS2pW/AxJ0MPAvC0px+8OMqcgcVboCNmVv7Whi8IO1p3Rh0Q== X-Received: by 10.28.68.10 with SMTP id r10mr7014093wma.68.1484826158328; Thu, 19 Jan 2017 03:42:38 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id t194sm5102702wmd.1.2017.01.19.03.42.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jan 2017 03:42:37 -0800 (PST) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Thu, 19 Jan 2017 11:41:53 +0000 Message-Id: <20170119114158.17941-34-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170119114158.17941-1-chris@chris-wilson.co.uk> References: <20170119114158.17941-1-chris@chris-wilson.co.uk> Subject: [Intel-gfx] [PATCH v2 33/38] drm/i915: Test creation of partial VMA X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Mock testing to ensure we can create and lookup partial VMA. Signed-off-by: Chris Wilson Reviewed-by: Joonas Lahtinen --- drivers/gpu/drm/i915/selftests/i915_vma.c | 191 ++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) diff --git a/drivers/gpu/drm/i915/selftests/i915_vma.c b/drivers/gpu/drm/i915/selftests/i915_vma.c index 2bda93f53b47..8287a863ad17 100644 --- a/drivers/gpu/drm/i915/selftests/i915_vma.c +++ b/drivers/gpu/drm/i915/selftests/i915_vma.c @@ -486,12 +486,203 @@ static int igt_vma_rotate(void *arg) return err; } +static bool assert_partial(struct drm_i915_gem_object *obj, + struct i915_vma *vma, + unsigned long offset, + unsigned long size) +{ + struct sgt_iter sgt; + dma_addr_t dma; + + for_each_sgt_dma(dma, sgt, vma->pages) { + dma_addr_t src; + + if (!size) { + pr_err("Partial scattergather list too long\n"); + return false; + } + + src = i915_gem_object_get_dma_address(obj, offset); + if (src != dma) { + pr_err("DMA mismatch for partial page offset %lu\n", + offset); + return false; + } + + offset++; + size--; + } + + return true; +} + +static int igt_vma_partial(void *arg) +{ + struct drm_i915_private *i915 = arg; + const unsigned int npages = 1021; /* prime! */ + struct drm_i915_gem_object *obj; + unsigned int sz, offset, loop; + struct i915_vma *vma; + int err = -ENOMEM; + + /* Create lots of different VMA for the object and check that + * we are returned the same VMA when we later request the same range. + */ + + obj = i915_gem_object_create_internal(i915, npages*PAGE_SIZE); + if (IS_ERR(obj)) + goto err; + + for (loop = 0; loop <= 1; loop++) { /* exercise both create/lookup */ + unsigned int count, nvma; + + nvma = loop; + for_each_prime_number_from(sz, 1, npages) { + for_each_prime_number_from(offset, 0, npages - sz) { + struct i915_address_space *vm = + &i915->ggtt.base; + struct i915_ggtt_view view; + + view.type = I915_GGTT_VIEW_PARTIAL; + view.partial.offset = offset; + view.partial.size = sz; + + if (sz == npages) + view.type = I915_GGTT_VIEW_NORMAL; + + vma = i915_vma_instance(obj, vm, &view); + if (IS_ERR(vma)) { + err = PTR_ERR(vma); + goto err_object; + } + + if (!i915_vma_is_ggtt(vma) || vma->vm != vm) { + pr_err("VMA is not in the GGTT!\n"); + err = -EINVAL; + goto err_object; + } + + if (i915_vma_compare(vma, + vma->vm, + &vma->ggtt_view)) { + pr_err("VMA compare failed with itself\n"); + err = -EINVAL; + goto err_object; + } + + err = i915_vma_pin(vma, 0, 0, PIN_GLOBAL); + if (err) + goto err_object; + + if (vma->size != sz*PAGE_SIZE) { + pr_err("VMA is wrong size, expected %lu, found %llu\n", + sz*PAGE_SIZE, vma->size); + err = -EINVAL; + goto err_object; + } + + if (vma->node.size < vma->size) { + pr_err("VMA binding too small, expected %llu, found %llu\n", + vma->size, vma->node.size); + err = -EINVAL; + goto err_object; + } + + if (view.type != I915_GGTT_VIEW_NORMAL) { + if (memcmp(&vma->ggtt_view, &view, sizeof(view))) { + pr_err("VMA mismatch upon creation!\n"); + err = -EINVAL; + goto err_object; + } + + if (vma->pages == obj->mm.pages) { + pr_err("VMA using unrotated object pages!\n"); + err = -EINVAL; + goto err_object; + } + } + + if (!assert_partial(obj, vma, offset, sz)) { + pr_err("Inconsistent partial pages for (offset=%d, size=%d)\n", offset, sz); + err = -EINVAL; + goto err_object; + } + + i915_vma_unpin(vma); + nvma++; + } + } + + count = loop; + list_for_each_entry(vma, &obj->vma_list, obj_link) + count++; + if (count != nvma) { + pr_err("All partial vma were not recorded on the obj->vma_list: found %u, expected %u\n", + count, nvma); + err = -EINVAL; + goto err_object; + } + + /* Create a mapping for the entire object, just for extra fun */ + vma = i915_vma_instance(obj, &i915->ggtt.base, NULL); + if (IS_ERR(vma)) { + err = PTR_ERR(vma); + goto err_object; + } + + if (!i915_vma_is_ggtt(vma)) { + pr_err("VMA is not in the GGTT!\n"); + err = -EINVAL; + goto err_object; + } + + err = i915_vma_pin(vma, 0, 0, PIN_GLOBAL); + if (err) + goto err_object; + + if (vma->size != obj->base.size) { + pr_err("VMA is wrong size, expected %lu, found %llu\n", + sz*PAGE_SIZE, vma->size); + err = -EINVAL; + goto err_object; + } + + if (vma->node.size < vma->size) { + pr_err("VMA binding too small, expected %llu, found %llu\n", + vma->size, vma->node.size); + err = -EINVAL; + goto err_object; + } + + if (vma->ggtt_view.type != I915_GGTT_VIEW_NORMAL) { + pr_err("Not the normal ggtt view! Found %d\n", + vma->ggtt_view.type); + err = -EINVAL; + goto err_object; + } + + if (vma->pages != obj->mm.pages) { + pr_err("VMA not using object pages!\n"); + err = -EINVAL; + goto err_object; + } + + i915_vma_unpin(vma); + } + +err_object: + i915_gem_object_put(obj); +err: + return err; +} + int i915_vma_mock_selftests(void) { static const struct i915_subtest tests[] = { SUBTEST(igt_vma_create), SUBTEST(igt_vma_pin1), SUBTEST(igt_vma_rotate), + SUBTEST(igt_vma_partial), }; struct drm_i915_private *i915; int err;