Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp281073pxb; Thu, 20 Jan 2022 13:24:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJxNn1fJzzw7fEerrxbFYNm2eU+HbvRJeijjwhZ7nA5NWgVvkb9LRyI7QJtEbQjydVRZuV5n X-Received: by 2002:a17:902:c411:b0:14b:1902:2a74 with SMTP id k17-20020a170902c41100b0014b19022a74mr565279plk.133.1642713863867; Thu, 20 Jan 2022 13:24:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642713863; cv=none; d=google.com; s=arc-20160816; b=sO6dtDGK/nekbI/8Cy9OG+XBXg1cSzVgzuDUB3GgoVusOmLoc9fjFm4tpBQRRanizV nE/BQiMv3QAfAKk5q0okDsHLibePunA0hyxd2vFPMj5GGew06su2/N0RuTv+UfTyLqYC 1M1zapl8NJ2EmgpSZ045reql/HG2dcUdoinPLI2lFnNsdX7k9Xwwvh3FMlospE4wuv3v gxmdYVOMpoZKsuAQNMq2xPx64/rcA/f+JTQ+xz6oON+uuIeboWUfvqvhYsK1TijKvV8+ H/ZQErdJrVqKx9AbNLwA6iNBF8BE/oLcHv00uqEqYPnz6eCvCoGQmOdOIZUILhUM4TYI MDYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6pRlSlBfQWmOlSwH6ilqV5IMQbvpl3SAZtE6EzTz3oI=; b=wquMHXN/vzSbY3bnIBg3CW8cbFTATLdvt3qJcGQMunQhZpicTBX8rWPVzlukz63TlL xW4htx5OAcue1TH7SCx6k5UFX921M5C6L/RN5wIXFWdW/EWXH35pMmKstdyBaAM1JrV4 eTeltpv5GLHuPTlQ6Y0uDzr1An7FfVr6RPTibgJe5rtLoA5uf4qmlDj0t5GGoH0tkKdo enNsJbEx2rmfWXqxB1HKPPZJtW9srd3qLnFm018eYnGRG1D2ellS+rUsXoi91NmCxTUA 2NMPcPAzidbO8mOCm52LG7Bg3QX2wpG0jCR5sLA5LlLVk2AWwEIjSUArSD0+TDeNcQMn yu3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Jh+mUmeB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s16si5151008pfu.318.2022.01.20.13.24.11; Thu, 20 Jan 2022 13:24:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Jh+mUmeB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347676AbiARRxn (ORCPT + 99 others); Tue, 18 Jan 2022 12:53:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347633AbiARRxk (ORCPT ); Tue, 18 Jan 2022 12:53:40 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF200C061574 for ; Tue, 18 Jan 2022 09:53:39 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: bbeckett) with ESMTPSA id 591881F43F8F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1642528418; bh=qusgV1IrpWYls6MEMfHoyhKydIqb2h/EGi15Q1HGAKE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jh+mUmeBUax+TIQqME/DYcOeHS6vZJIJFonzje0jkT6/cd/ex0Tr6AKBztHjGo3EL D+ThieD8dXIg7Jwvy7C2a04iVNeDjzwg9O1VrlBdtKf8vE15397ZSD9h2ye4iJqJbP xsqCNkQhgx2bRvz9JPISR23AIRgs5JLuy1+LoBubhsaq9jSlnCnhFnSdvvmWvyhsnX /7NwYDE8VoZ7dRYisgfCk4QaNpDRbG4gp2MZbHqqFaM6w/Zjob6VJGH+3CTAMSAHVy F6NTKPwvm3PBuMon5xBZMMapIVRrc+BdoxgoVpV1sFkIlL0qxJ6DWMDkS59AAasJoM CQlxIixX4SxJw== From: Robert Beckett To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter Cc: Robert Beckett , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/4] drm/i915: add gtt misalignment test Date: Tue, 18 Jan 2022 17:50:36 +0000 Message-Id: <20220118175036.3840934-4-bob.beckett@collabora.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220118175036.3840934-1-bob.beckett@collabora.com> References: <20220118175036.3840934-1-bob.beckett@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org add test to check handling of misaligned offsets and sizes Signed-off-by: Robert Beckett --- drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c index 2f3f0c01786b..76696a5e547e 100644 --- a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +++ b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c @@ -22,10 +22,12 @@ * */ +#include "gt/intel_gtt.h" #include #include #include "gem/i915_gem_context.h" +#include "gem/i915_gem_region.h" #include "gem/selftests/mock_context.h" #include "gt/intel_context.h" #include "gt/intel_gpu_commands.h" @@ -1067,6 +1069,120 @@ static int shrink_boom(struct i915_address_space *vm, return err; } +static int misaligned_case(struct i915_address_space *vm, struct intel_memory_region *mr, + u64 addr, u64 size, unsigned long flags) +{ + struct drm_i915_gem_object *obj; + struct i915_vma *vma; + int err = 0; + u64 expected_vma_size, expected_node_size; + + obj = i915_gem_object_create_region(mr, size, 0, 0); + if (IS_ERR(obj)) + return PTR_ERR(obj); + + vma = i915_vma_instance(obj, vm, NULL); + if (IS_ERR(vma)) { + err = PTR_ERR(vma); + goto err_put; + } + + err = i915_vma_pin(vma, 0, 0, addr | flags); + if (err) + goto err_put; + i915_vma_unpin(vma); + + if (!drm_mm_node_allocated(&vma->node)) { + err = -EINVAL; + goto err_put; + } + + if (i915_vma_misplaced(vma, 0, 0, addr | flags)) { + err = -EINVAL; + goto err_put; + } + + expected_vma_size = round_up(size, 1 << (ffs(vma->resource->page_sizes_gtt) - 1)); + expected_node_size = expected_vma_size; + + if (IS_DG2(vm->i915) && i915_gem_object_is_lmem(obj)) { + /* dg2 should expand lmem node to 2MB */ + expected_vma_size = round_up(size, I915_GTT_PAGE_SIZE_64K); + expected_node_size = round_up(size, I915_GTT_PAGE_SIZE_2M); + } + + if (vma->size != expected_vma_size || vma->node.size != expected_node_size) { + err = i915_vma_unbind(vma); + err = -EBADSLT; + goto err_put; + } + + err = i915_vma_unbind(vma); + if (err) + goto err_put; + + GEM_BUG_ON(drm_mm_node_allocated(&vma->node)); + +err_put: + i915_gem_object_put(obj); + cleanup_freed_objects(vm->i915); + return err; +} + +static int misaligned_pin(struct i915_address_space *vm, + u64 hole_start, u64 hole_end, + unsigned long end_time) +{ + struct intel_memory_region *mr; + enum intel_region_id id; + unsigned long flags = PIN_OFFSET_FIXED | PIN_USER; + int err = 0; + u64 hole_size = hole_end - hole_start; + + if (i915_is_ggtt(vm)) + flags |= PIN_GLOBAL; + + for_each_memory_region(mr, vm->i915, id) { + u64 min_alignment = i915_vm_min_alignment(vm, id); + u64 size = min_alignment; + u64 addr = round_up(hole_start + (hole_size / 2), min_alignment); + + /* we can't test < 4k alignment due to flags being encoded in lower bits */ + if (min_alignment != I915_GTT_PAGE_SIZE_4K) { + err = misaligned_case(vm, mr, addr + (min_alignment / 2), size, flags); + /* misaligned should error with -EINVAL*/ + if (!err) + err = -EBADSLT; + if (err != -EINVAL) + return err; + } + + /* test for vma->size expansion to min page size */ + err = misaligned_case(vm, mr, addr, PAGE_SIZE, flags); + if (min_alignment > hole_size) { + if (!err) + err = -EBADSLT; + else if (err == -ENOSPC) + err = 0; + } + if (err) + return err; + + /* test for intermediate size not expanding vma->size for large alignments */ + err = misaligned_case(vm, mr, addr, size / 2, flags); + if (min_alignment > hole_size) { + if (!err) + err = -EBADSLT; + else if (err == -ENOSPC) + err = 0; + } + if (err) + return err; + } + + return 0; +} + static int exercise_ppgtt(struct drm_i915_private *dev_priv, int (*func)(struct i915_address_space *vm, u64 hole_start, u64 hole_end, @@ -1136,6 +1252,12 @@ static int igt_ppgtt_shrink_boom(void *arg) return exercise_ppgtt(arg, shrink_boom); } +static int igt_ppgtt_misaligned_pin(void *arg) +{ + return exercise_ppgtt(arg, misaligned_pin); +} + + static int sort_holes(void *priv, const struct list_head *A, const struct list_head *B) { @@ -1208,6 +1330,12 @@ static int igt_ggtt_lowlevel(void *arg) return exercise_ggtt(arg, lowlevel_hole); } +static int igt_ggtt_misaligned_pin(void *arg) +{ + return exercise_ggtt(arg, misaligned_pin); +} + + static int igt_ggtt_page(void *arg) { const unsigned int count = PAGE_SIZE/sizeof(u32); @@ -2180,12 +2308,14 @@ int i915_gem_gtt_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_ppgtt_fill), SUBTEST(igt_ppgtt_shrink), SUBTEST(igt_ppgtt_shrink_boom), + SUBTEST(igt_ppgtt_misaligned_pin), SUBTEST(igt_ggtt_lowlevel), SUBTEST(igt_ggtt_drunk), SUBTEST(igt_ggtt_walk), SUBTEST(igt_ggtt_pot), SUBTEST(igt_ggtt_fill), SUBTEST(igt_ggtt_page), + SUBTEST(igt_ggtt_misaligned_pin), SUBTEST(igt_cs_tlb), }; -- 2.25.1