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); From patchwork Tue Aug 7 18:11:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 10559061 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 126FD14E5 for ; Tue, 7 Aug 2018 18:11:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06B302A47F for ; Tue, 7 Aug 2018 18:11:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF1F32A7DC; Tue, 7 Aug 2018 18:11:18 +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 917D92A47F for ; Tue, 7 Aug 2018 18:11:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EB9D46E432; Tue, 7 Aug 2018 18:11:17 +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 029CF6E432 for ; Tue, 7 Aug 2018 18:11:15 +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 12689132-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:01 +0100 Message-Id: <20180807181101.14696-2-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180807181101.14696-1-chris@chris-wilson.co.uk> References: <20180807181101.14696-1-chris@chris-wilson.co.uk> Subject: [Intel-gfx] [PATCH 2/2] drm/i915: Mark "page-backed" dmabuf as being shrinkable 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 We currently assume that if we import a dmabuf, it is not backed by pages (we assume it exists in video memory on a foriegn device). However, some dmabuf will be backed by ordinary struct pages (e.g. vgem) and as such they may be shrinkable from direct reclaim. Since commit 09ea0dfbf972 ("dma-buf: make map_atomic and map function pointers optional") drivers do not need to supply a kmap() vfunc if they have no convenient access to the physical backing page. We can use that information to differentiate dmabuf that are likely to be backed by struct page and so suitable for including in our shrinkable set. Signed-off-by: Chris Wilson Cc: Tvrtko Ursulin Cc: Daniel Vetter --- drivers/gpu/drm/i915/i915_gem_dmabuf.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/i915_gem_dmabuf.c index 82e2ca17a441..8bc4030059f8 100644 --- a/drivers/gpu/drm/i915/i915_gem_dmabuf.c +++ b/drivers/gpu/drm/i915/i915_gem_dmabuf.c @@ -269,7 +269,15 @@ static void i915_gem_object_put_pages_dmabuf(struct drm_i915_gem_object *obj, DMA_BIDIRECTIONAL); } -static const struct drm_i915_gem_object_ops i915_gem_object_dmabuf_ops = { +static const struct drm_i915_gem_object_ops +i915_gem_object_dmabuf_ops = { + .get_pages = i915_gem_object_get_pages_dmabuf, + .put_pages = i915_gem_object_put_pages_dmabuf, +}; + +static const struct drm_i915_gem_object_ops +i915_gem_object_dmabuf_ops__shrinkable = { + .flags = I915_GEM_OBJECT_IS_SHRINKABLE, .get_pages = i915_gem_object_get_pages_dmabuf, .put_pages = i915_gem_object_put_pages_dmabuf, }; @@ -308,7 +316,10 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev, } drm_gem_private_object_init(dev, &obj->base, dma_buf->size); - i915_gem_object_init(obj, &i915_gem_object_dmabuf_ops); + i915_gem_object_init(obj, + dma_buf->ops->map ? + &i915_gem_object_dmabuf_ops__shrinkable : + &i915_gem_object_dmabuf_ops); obj->base.import_attach = attach; obj->resv = dma_buf->resv;