From patchwork Thu Sep 24 11:05:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 7256081 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0639C9F32B for ; Thu, 24 Sep 2015 11:05:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 105CB208F5 for ; Thu, 24 Sep 2015 11:05:14 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id EAD3A208E6 for ; Thu, 24 Sep 2015 11:05:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 505B46E74D; Thu, 24 Sep 2015 04:05:12 -0700 (PDT) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTP id C01A66E74D for ; Thu, 24 Sep 2015 04:05:10 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 24 Sep 2015 04:05:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,580,1437462000"; d="scan'208";a="812234555" Received: from tursulin-linux.isw.intel.com ([10.102.226.64]) by orsmga002.jf.intel.com with ESMTP; 24 Sep 2015 04:05:09 -0700 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Thu, 24 Sep 2015 12:05:07 +0100 Message-Id: <1443092707-18327-1-git-send-email-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.5.1 Cc: Thomas Wood Subject: [Intel-gfx] [PATCH i-g-t v3] gem_ppgtt: Test VMA leak on context destruction 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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin Test that VMAs associated with a context are cleaned up when contexts are destroyed. In practice this emulates the leak seen between fbcon and X server. Every time the X server exits we gain one VMA on the fbcon frame buffer object as externally visible via for example /sys/kernel/debug/dri/0/i915_gem_gtt. v2: Use igt_debugfs_open, getline and strstr instead of home-brewed string matching. (Thomas Wood) v3: Rebase for drm_open_driver. Signed-off-by: Tvrtko Ursulin Cc: Thomas Wood --- tests/gem_ppgtt.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/tests/gem_ppgtt.c b/tests/gem_ppgtt.c index 22adf805f0ac..f891411ab0c2 100644 --- a/tests/gem_ppgtt.c +++ b/tests/gem_ppgtt.c @@ -37,6 +37,7 @@ #include #include "intel_bufmgr.h" +#include "igt_debugfs.h" #define WIDTH 512 #define STRIDE (WIDTH*4) @@ -265,6 +266,88 @@ static void flink_and_close(void) close(fd2); } +static bool grep_name(const char *fname, const char *match) +{ + int fd; + FILE *fh; + size_t n = 0; + char *line = NULL; + char *matched = NULL; + + fd = igt_debugfs_open(fname, O_RDONLY); + igt_assert(fd >= 0); + + fh = fdopen(fd, "r"); + igt_assert(fh); + + while (getline(&line, &n, fh) >= 0) { + matched = strstr(line, match); + if (line) { + free(line); + line = NULL; + } + if (matched) + break; + } + + if (line) + free(line); + fclose(fh); + + return matched != NULL; +} + +static void flink_and_exit(void) +{ + uint32_t fd, fd2; + uint32_t bo, flinked_bo, name; + char match[100]; + int to_match; + bool matched; + int retry = 0; + const int retries = 50; + + fd = drm_open_driver(DRIVER_INTEL); + igt_require(uses_full_ppgtt(fd)); + + bo = gem_create(fd, 4096); + name = gem_flink(fd, bo); + + to_match = snprintf(match, sizeof(match), "(name: %u)", name); + igt_assert(to_match < sizeof(match)); + + fd2 = drm_open_driver(DRIVER_INTEL); + + flinked_bo = gem_open(fd2, name); + exec_and_get_offset(fd2, flinked_bo); + gem_sync(fd2, flinked_bo); + + /* Verify looking for string works OK. */ + matched = grep_name("i915_gem_gtt", match); + igt_assert_eq(matched, true); + + gem_close(fd2, flinked_bo); + + /* Close the context. */ + close(fd2); + +retry: + /* Give cleanup some time to run. */ + usleep(100000); + + /* The flinked bo VMA should have been cleared now, so list of VMAs + * in debugfs should not contain the one for the imported object. + */ + matched = grep_name("i915_gem_gtt", match); + if (matched && retry++ < retries) + goto retry; + + igt_assert_eq(matched, false); + + gem_close(fd, bo); + close(fd); +} + #define N_CHILD 8 int main(int argc, char **argv) { @@ -297,5 +380,8 @@ int main(int argc, char **argv) igt_subtest("flink-and-close-vma-leak") flink_and_close(); + igt_subtest("flink-and-exit-vma-leak") + flink_and_exit(); + igt_exit(); }