From patchwork Mon Oct 31 15:36:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 9405717 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 665A460234 for ; Mon, 31 Oct 2016 15:36:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 612B2292E9 for ; Mon, 31 Oct 2016 15:36:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 53FA32932C; Mon, 31 Oct 2016 15:36:28 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 1E107292E9 for ; Mon, 31 Oct 2016 15:36:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 517FD89A35; Mon, 31 Oct 2016 15:36:26 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id CC61A89A35 for ; Mon, 31 Oct 2016 15:36:24 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id m83so18911873wmc.0 for ; Mon, 31 Oct 2016 08:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=JEiyUN6tkcwx6Hwt2KEoMy5t3/LJxFZ+ftCe41FuKdI=; b=UOBobh9qXgXXq0tNh6wlPuT8WViyKHGpKO8FIpDURxWXZa18So9yFOsr7LlVIQk17x nELAwu8odiPr4MdO4Dj3rTq+rbIfrZxrSxm8kEEzQUnM70JrvviZxSrM7+WCHRAdy5K0 qg3+JztjFXv74ABj4SA26KfcEVvEaUXSdJHDo6o+3hnTzrsj9gHOJh9hZqaU3m5cYs0d vkgLjcwG4wUY0lSNf1tyhOvi9dJXgyy/nrkl/l3dqjsqfmR4U9LknaqDelTUwz9DFGXR lqm7sxIewcDZZBRTX+aI+XCeZtMcRNvCrJghEZEdzc4s6UDjGga+xvAt82rhtRUD3OVC TmpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=JEiyUN6tkcwx6Hwt2KEoMy5t3/LJxFZ+ftCe41FuKdI=; b=I95gOKbCLQacwjV9riHqSTZ13GdD0EA9jhMKwmru0zO9WLag8ISx9Y+qKaCyzkhUEx Q508vmuHCNxYixE73aHhgYQD45i9a9OtfKJenjPp/Bw7ezSPq+AoCZKKC1DwUe0EfOmR 1Iql7+MqC9rg+P2zbtYSpL03Iv+4o/SMatOU4uStMsBy5fIcI/dtm939bieKu6smxDOV 5uKnlxmKv1JzkYmtXGjcmKHypMk4pd5HFnc9qnxGx8n7PKjcQ1OF2H5TrVK0ACpM/oa0 qtizJ91S+2AjqWNXVJGRCgsi3GicwrYnAyckRzzlA2H3ZLLUdmLofquyp97/e7to9hfA 0i8g== X-Gm-Message-State: ABUngvfFpd3vvljcaUJ2RrC2/U1B8ePshP3wtriq8+vUFJWLO1WtVeQCkBRat7MLfQgTiQ== X-Received: by 10.28.159.16 with SMTP id i16mr11938296wme.122.1477928183189; Mon, 31 Oct 2016 08:36:23 -0700 (PDT) Received: from t460p.intel ([2a02:c7d:9bd6:b000:f37e:1e07:a7d8:46cd]) by smtp.gmail.com with ESMTPSA id 70sm25282688wmv.1.2016.10.31.08.36.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Oct 2016 08:36:22 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Mon, 31 Oct 2016 15:36:15 +0000 Message-Id: <1477928175-11391-1-git-send-email-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.7.4 Subject: [Intel-gfx] [PATCH i-g-t] tests/gem_userptr_blits: Test object invalidation more thoroughly 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-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin Verify that the userspace will get told if it changes to what the userptr object backing store points to, *after* having created the GEM object. Two variants are tested: 1. One where the object is used after it has been invalidated but while the address space for the backing store is still invalid. 2. Second one where the backing store becomes valid immediately after the object has been invalidated. In both cases we want the kernel to give us -EFAULT on the buffer object in question since the userspace is acting strangely so the driver does not want to take part in corrupting memory. Signed-off-by: Tvrtko Ursulin Cc: Chris Wilson --- tests/gem_userptr_blits.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/tests/gem_userptr_blits.c b/tests/gem_userptr_blits.c index f30e14360727..11a29ff5fdde 100644 --- a/tests/gem_userptr_blits.c +++ b/tests/gem_userptr_blits.c @@ -1151,6 +1151,58 @@ static void test_unmap_cycles(int fd, int expected) test_unmap(fd, expected); } +/* + * Verify that the userspace will get told if it changes to what the userptr + * object backing store points to, *after* having created the GEM object. + * + * Two variants are tested: + * 1. One where the object is used after it has been invalidated but while + * the address space for the backing store is still invalid. + * 2. Second one where the backing store becomes valid immediately after the + * object has been invalidated. + * + * In both cases we want the kernel to give us -EFAULT on the buffer object in + * question since the userspace is acting strangely so the driver does not want + * to take part in corrupting memory. + */ +static void test_remap(int fd, bool midaccess, int expected) +{ + char *ptr, *ptr2, *bo_ptr; + uint32_t bo[2]; + size_t map_size = sizeof(linear) + (PAGE_SIZE - 1); + int ret; + + ptr = mmap(NULL, map_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + igt_assert(ptr != MAP_FAILED); + + bo_ptr = (char *)ALIGN((unsigned long)ptr, PAGE_SIZE); + gem_userptr(fd, bo_ptr, sizeof(linear), 0, userptr_flags, &bo[0]); + + bo[1] = create_bo(fd, 0); + + copy(fd, bo[1], bo[0], 0); + + ret = munmap(ptr, map_size); + igt_assert_eq(ret, 0); + + if (midaccess) + copy(fd, bo[1], bo[0], expected); + + ptr2 = mmap(ptr, map_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0); + igt_assert(ptr2 != MAP_FAILED); + igt_assert(ptr2 == ptr); + + copy(fd, bo[1], bo[0], expected); + + gem_close(fd, bo[1]); + gem_close(fd, bo[0]); + + ret = munmap(ptr, map_size); + igt_assert_eq(ret, 0); +} + #define MM_STRESS_LOOPS 100000 struct stress_thread_data { @@ -1354,6 +1406,12 @@ int main(int argc, char **argv) igt_subtest("unsync-unmap-after-close") test_unmap_after_close(fd); + igt_subtest("unsync-remap") + test_remap(fd, false, 0); + + igt_subtest("unsync-remap-access") + test_remap(fd, true, 0); + igt_subtest("coherency-unsync") test_coherency(fd, count); @@ -1452,6 +1510,12 @@ int main(int argc, char **argv) igt_subtest("sync-unmap-after-close") test_unmap_after_close(fd); + igt_subtest("sync-remap") + test_remap(fd, false, EFAULT); + + igt_subtest("sync-remap-access") + test_remap(fd, true, EFAULT); + igt_subtest("stress-mm") test_stress_mm(fd);