From patchwork Wed Aug 10 11:54:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9272945 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 9A8F3600CB for ; Wed, 10 Aug 2016 11:54:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C4B827D5E for ; Wed, 10 Aug 2016 11:54:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8116828066; Wed, 10 Aug 2016 11:54:52 +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 3A3EB27D5E for ; Wed, 10 Aug 2016 11:54:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 948A16E744; Wed, 10 Aug 2016 11:54:51 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id C10D66E741 for ; Wed, 10 Aug 2016 11:54:50 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id q128so9060122wma.1 for ; Wed, 10 Aug 2016 04:54:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=dszOevb6S11sm2EJCLT0aRuqwZ3lHYsQyRg8QNI3WRo=; b=AB0gStFuDXwxWY5wluH1tX5Tjiz1Cr+RjXhxUKBOZ+Mv1JVp02sMJFOSBi6MZ7VkxU g30ddgDXbsoNsh/fqj5OUGTgw6KMcRDrSbQGqcu69Vs2hUANtJTS1OA4/tZu0IArHqtU VuHV/TCLACPDy3ON2xvJtW5RuTUMZh40AhzgJZWLA7Sgfc/sUGC2c/9HiWKB0+kgQUi/ obiv79V7UPUfKY/DxB8fBfgzmLBTNZDJaxOyuhYkoEcnfNeAPuA/UQBEKpQTXyID2CXM Vle9AE85+jpC262wr1BtRDrgTeYF8oVl6B0RorA/4zsQYSlh82pvqD7SHt3y9jd2LnBd tMyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=dszOevb6S11sm2EJCLT0aRuqwZ3lHYsQyRg8QNI3WRo=; b=aOcoEMr4cgTm+oSddSaUkNPwFyqzkg1IQs0yNOJXkvzSd9xE3WvbLYMjUnUfoYl30G vW2N3t7vw9zroQiogoLDPptYYqax5hMnpRE4cbCpn+I00H71GohqRbzkww6outIY2drD +bDuNqpSy4avNiqAZ5KzyRoYcHciYGKLoP76Ahmv0AWyTFMShXhmssfU8XLIu/xgaLye +hVWttuIUvQZXUInP9HrhjT1XLnL99kUDkxjuwwlkuvq5wyCb2aZIWFi5aj15T/8llX1 7N+HJ4qaMk9malCKy2KQargCaVa0dxxTDgrCRvA0z8ZVXHtMdVg8Nj1ruovRgbwLwBze IXZA== X-Gm-Message-State: AEkoouv9EEyKOCLf/6QyQ3wQv1bdVwH7KcT8dZpXe1JdDW/rATAh83FrXuu8TsNCQkw5GQ== X-Received: by 10.28.14.68 with SMTP id 65mr2733448wmo.68.1470830089357; Wed, 10 Aug 2016 04:54:49 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id ex14sm42711844wjc.30.2016.08.10.04.54.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Aug 2016 04:54:48 -0700 (PDT) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Wed, 10 Aug 2016 12:54:29 +0100 Message-Id: <1470830073-7407-6-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1470830073-7407-1-git-send-email-chris@chris-wilson.co.uk> References: <1470830073-7407-1-git-send-email-chris@chris-wilson.co.uk> Cc: mika.kuoppala@intel.com Subject: [Intel-gfx] [PATCH 5/9] drm/i915: Pin the pages first in shmem prepare read/write 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 There is an improbable, but not impossible, case that if we leave the pages unpin as we operate on the object, then somebody may steal the lock and change the cache domains after we have already inspected them. (Whilst here, avail ourselves of the opportunity to take a couple of steps to make the two functions look more similar.) Signed-off-by: Chris Wilson --- drivers/gpu/drm/i915/i915_gem.c | 48 ++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index da4b266fce72..e18f0d2df883 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -613,6 +613,12 @@ int i915_gem_obj_prepare_shmem_read(struct drm_i915_gem_object *obj, if (ret) return ret; + ret = i915_gem_object_get_pages(obj); + if (ret) + return ret; + + i915_gem_object_pin_pages(obj); + i915_gem_object_flush_gtt_write_domain(obj); /* If we're not in the cpu read domain, set ourself into the gtt @@ -624,22 +630,20 @@ int i915_gem_obj_prepare_shmem_read(struct drm_i915_gem_object *obj, *needs_clflush = !cpu_cache_is_coherent(obj->base.dev, obj->cache_level); - ret = i915_gem_object_get_pages(obj); - if (ret) - return ret; - - i915_gem_object_pin_pages(obj); - if (*needs_clflush && !static_cpu_has(X86_FEATURE_CLFLUSH)) { ret = i915_gem_object_set_to_cpu_domain(obj, false); - if (ret) { - i915_gem_object_unpin_pages(obj); - return ret; - } + if (ret) + goto err_unpin; + *needs_clflush = 0; } + /* return with the pages pinned */ return 0; + +err_unpin: + i915_gem_object_unpin_pages(obj); + return ret; } int i915_gem_obj_prepare_shmem_write(struct drm_i915_gem_object *obj, @@ -655,6 +659,12 @@ int i915_gem_obj_prepare_shmem_write(struct drm_i915_gem_object *obj, if (ret) return ret; + ret = i915_gem_object_get_pages(obj); + if (ret) + return ret; + + i915_gem_object_pin_pages(obj); + i915_gem_object_flush_gtt_write_domain(obj); /* If we're not in the cpu write domain, set ourself into the @@ -672,18 +682,11 @@ int i915_gem_obj_prepare_shmem_write(struct drm_i915_gem_object *obj, *needs_clflush |= !cpu_cache_is_coherent(obj->base.dev, obj->cache_level); - ret = i915_gem_object_get_pages(obj); - if (ret) - return ret; - - i915_gem_object_pin_pages(obj); - if (*needs_clflush && !static_cpu_has(X86_FEATURE_CLFLUSH)) { ret = i915_gem_object_set_to_cpu_domain(obj, true); - if (ret) { - i915_gem_object_unpin_pages(obj); - return ret; - } + if (ret) + goto err_unpin; + *needs_clflush = 0; } @@ -692,7 +695,12 @@ int i915_gem_obj_prepare_shmem_write(struct drm_i915_gem_object *obj, intel_fb_obj_invalidate(obj, ORIGIN_CPU); obj->dirty = 1; + /* return with the pages pinned */ return 0; + +err_unpin: + i915_gem_object_unpin_pages(obj); + return ret; } /* Per-page copy function for the shmem pread fastpath.