From patchwork Tue Aug 7 18:11:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 10559063 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2B9F21390 for ; Tue, 7 Aug 2018 18:11:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F78D2A7DD for ; Tue, 7 Aug 2018 18:11:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13DD22A7FC; Tue, 7 Aug 2018 18:11:22 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED 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 5105F2A7DD for ; Tue, 7 Aug 2018 18:11:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5EB4D6E220; Tue, 7 Aug 2018 18:11:15 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [109.228.58.192]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1BC806E220 for ; Tue, 7 Aug 2018 18:11:13 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 12689131-1500050 for multiple; Tue, 07 Aug 2018 19:11:02 +0100 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Tue, 7 Aug 2018 19:11:00 +0100 Message-Id: <20180807181101.14696-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.18.0 Subject: [Intel-gfx] [PATCH 1/2] drm/i915/selftests: Exercise invalidation of dmabuf import from shrinker X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 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 Check that we can invalidate an object created for an imported dmabuf (i.e. that we release the obj->mm.pages, and so its associated mapping of the dmabuf) under memory pressure invoking the shrinker for direct reclaim. This is using our mock_dmabuf as the exporter, so while we may miss intricate lock dependencies of a real device, we should capture any and all core dependencies. Signed-off-by: Chris Wilson Cc: Tvrtko Ursulin Cc: Daniel Vetter --- .../gpu/drm/i915/selftests/i915_gem_dmabuf.c | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/selftests/i915_gem_dmabuf.c index a7055b12e53c..105eaeb09ca7 100644 --- a/drivers/gpu/drm/i915/selftests/i915_gem_dmabuf.c +++ b/drivers/gpu/drm/i915/selftests/i915_gem_dmabuf.c @@ -22,6 +22,8 @@ * */ +#include + #include "../i915_selftest.h" #include "mock_gem_device.h" @@ -370,6 +372,73 @@ static int igt_dmabuf_export_kmap(void *arg) return err; } +static int igt_dmabuf_import_shrink(void *arg) +{ + struct drm_i915_private *i915 = arg; + struct drm_i915_gem_object *obj; + struct dma_buf *dmabuf; + bool has_pages; + int err; + + dmabuf = mock_dmabuf(1); + if (IS_ERR(dmabuf)) + return PTR_ERR(dmabuf); + + obj = to_intel_bo(i915_gem_prime_import(&i915->drm, dmabuf)); + dma_buf_put(dmabuf); + if (IS_ERR(obj)) { + pr_err("i915_gem_prime_import failed with err=%d\n", + (int)PTR_ERR(obj)); + return PTR_ERR(obj); + } + + if (obj->base.dev != &i915->drm) { + pr_err("i915_gem_prime_import created a non-i915 object!\n"); + err = -EINVAL; + goto out_obj; + } + + if (obj->base.size != PAGE_SIZE) { + pr_err("i915_gem_prime_import is wrong size found %lld, expected %ld\n", + (long long)obj->base.size, PAGE_SIZE); + err = -EINVAL; + goto out_obj; + } + + err = i915_gem_object_pin_pages(obj); + if (err) + goto out_obj; + + i915_gem_object_unpin_pages(obj); + + if (!i915_gem_object_has_pages(obj)) { + pr_err("Failed to acquire dma-buf pages\n"); + err = -EINVAL; + goto out_obj; + } + + /* Fake the shrinker invocation for direct-reclaim */ + fs_reclaim_acquire(GFP_KERNEL); + i915_gem_shrink_all(i915); + fs_reclaim_release(GFP_KERNEL); + + has_pages = i915_gem_object_has_pages(obj); + if (has_pages == i915_gem_object_is_shrinkable(obj)) { + if (has_pages) + pr_err("Failed to release dma-buf from shrinker!\n"); + else + pr_err("Released unshrinkable dma-buf from shrinker!\n"); + + err = -EINVAL; + goto out_obj; + } + + err = 0; +out_obj: + i915_gem_object_put(obj); + return err; +} + int i915_gem_dmabuf_mock_selftests(void) { static const struct i915_subtest tests[] = { @@ -397,6 +466,7 @@ int i915_gem_dmabuf_live_selftests(struct drm_i915_private *i915) { static const struct i915_subtest tests[] = { SUBTEST(igt_dmabuf_export), + SUBTEST(igt_dmabuf_import_shrink), }; return i915_subtests(tests, i915);