From patchwork Tue Nov 19 14:26:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 11252197 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E72E714E5 for ; Tue, 19 Nov 2019 14:26:57 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CFA2A222A9 for ; Tue, 19 Nov 2019 14:26:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CFA2A222A9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=chris-wilson.co.uk Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A2FB16E974; Tue, 19 Nov 2019 14:26:56 +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 8B44C6E060 for ; Tue, 19 Nov 2019 14:26:54 +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 19258908-1500050 for multiple; Tue, 19 Nov 2019 14:26:37 +0000 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Tue, 19 Nov 2019 14:26:36 +0000 Message-Id: <20191119142636.3261286-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t] i915/gem_mmap_gtt: Exercise many, many mappings of the same objects 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: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Fork and remap the same object into a new process space under a new file descriptor. Principally to check list management and find scaling issues in using such lists. Signed-off-by: Chris Wilson Cc: Abdiel Janulgue --- tests/i915/gem_mmap_gtt.c | 72 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/tests/i915/gem_mmap_gtt.c b/tests/i915/gem_mmap_gtt.c index a5f9d934e..756940ca4 100644 --- a/tests/i915/gem_mmap_gtt.c +++ b/tests/i915/gem_mmap_gtt.c @@ -34,8 +34,9 @@ #include #include #include -#include #include +#include +#include #include "drm.h" #include "igt.h" @@ -323,6 +324,73 @@ test_pf_nonblock(int i915) igt_spin_free(i915, spin); } +static void +test_fork_bomb(int i915) +{ + uint32_t *control; + uint32_t handle; + int dmabuf; + + /* Rebind the same object into many different process adress spaces. */ + + control = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + igt_assert(control != MAP_FAILED); + + handle = gem_create(i915, 4096); + dmabuf = prime_handle_to_fd(i915, handle); + gem_close(i915, handle); + + igt_fork(child, 1) { + int fd[512]; + + atomic_fetch_add(&control[1], 1); + while (!READ_ONCE(control[0])) { + int children; + + atomic_fetch_add(&control[2], 1); + + for (int i = 0; i < ARRAY_SIZE(fd); i++) { + fd[i] = gem_reopen_driver(i915); + + handle = prime_fd_to_handle(fd[i], dmabuf); + gem_mmap__gtt(fd[i], handle, 4096, PROT_WRITE); + gem_close(fd[i], handle); + + /* leave the fd + mmap for process cleanup */ + } + + for (children = 0; children < 2; children++) { + if (fork() > 0) { /* child */ + atomic_fetch_add(&control[1], 1); + for (int i = 0; i < ARRAY_SIZE(fd); i++) + close(fd[i]); + break; + } + } + if (children == 2) { /* parent */ + sched_yield(); + break; + } + } + atomic_fetch_add(&control[1], -1); + } + + sleep(30); + + *control = 1; + igt_waitchildren(); + + while (READ_ONCE(control[1])) { + int status = 0; + wait(&status); + } + + igt_info("Spawned %d children\n", control[2]); + + close(dmabuf); + munmap(control, 4096); +} + static void test_isolation(int i915) { @@ -1097,6 +1165,8 @@ igt_main test_flink_race(fd); igt_subtest("pf-nonblock") test_pf_nonblock(fd); + igt_subtest("fork-bomb") + test_fork_bomb(fd); igt_subtest("basic-small-bo") test_huge_bo(fd, -1, I915_TILING_NONE);