Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp244389pxb; Thu, 21 Apr 2022 23:01:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5TAvpOHMeKb//wBlf93LejfjwnV9pXBQO4zFmkRENputompGIdABw5wT0ED4Dwj6GfS7p X-Received: by 2002:a17:902:8ec2:b0:156:9d2c:9ec5 with SMTP id x2-20020a1709028ec200b001569d2c9ec5mr2926128plo.170.1650607262825; Thu, 21 Apr 2022 23:01:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650607262; cv=none; d=google.com; s=arc-20160816; b=0BOc9X+80sYsrvbbJ/ZoAc6Qlw63LBZ5fnFdA7C5UL3xCy5gg6OWOmOe0ZJ308dFVB 9AQ265CR+ia3DUF8zvqiIcdCQV34bkSDOwoSqhXpi+KfOB1swZ6+2ihJCL6nsAfYi+Gw sM1Orwxg7hEzzRumeyUaCQn1wCP2OV+MrLG5TjEBfrrk2Tv2O00dTMrpR+eDDS6ktkK0 EjNczm6kzob7ypue9hsYgC1t7qJGWJDmv8WDlo2yjfTW2z9FQQCgUB15J4y22/y/TQzG pG8B4g2cK5LLrsBphlLftS6H8Y+6WHVIQU3rOb4JMbrn8W6aSK+niFDjamjdqygoPQJG 4kqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9IWw6caPmh/cj4EUJKCnBGFKB+XL3WhMIaj/HxoDjsw=; b=WiF0hhKK80QcQiYQ3R+9GP/dfFEGNkF2Ax5nAVw7ZDf24mIo0iwqWyuNdYzrxhOoJI Vifx9uR3p7HG+tW9WCD5zWvnaYtcaT4R3OgweBe/FolbeizcBSZB/wkScMK2TzlBikAR eyB8HZ3Y3WQcamL4iz8actHnoKjDo7AoAOi0l6cM4nSMrt2CaMmSmJYO/peP5KvU9Qt2 v37UfoOiUv2EiGHNSiO/PAKHqqnW3glcH6HyfUIjTBHRf2hBGVFB0lwNTATSmkLOq1wX uPfDtpvU/f62nL+rZA3FbBFUN//TJ8im2brmBEdC2HqY3flpocW0W12Y0IhUjdaw/mKu zVkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=oSejeR8m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a192-20020a6390c9000000b003aa6d422fd2si5975277pge.57.2022.04.21.23.00.48; Thu, 21 Apr 2022 23:01:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=oSejeR8m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1391555AbiDUSwy (ORCPT + 99 others); Thu, 21 Apr 2022 14:52:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1391548AbiDUSww (ORCPT ); Thu, 21 Apr 2022 14:52:52 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 880CE65E8 for ; Thu, 21 Apr 2022 11:50:01 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: bbeckett) with ESMTPSA id 3847F1F45CF0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1650567000; bh=yZDfYMtfaZRY0QUffB9LSGM0LIHt1Kf7UYxXwd7bE5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oSejeR8mZo48sUCSg/D19AOa9v17fg1XWYSUwTud1NFSX7ncRKnUYStorKm256GtP kNesIRHC+glAR72Mn1axW8iVOr23cWVszvJobO4N4erIO0u+hqwFX2mZfX7PdTJzWd NCHniphsK/xrgvlqnJ7GHC9J/USnexT8jySpEMCy8etj3mf7X+A7znen0rHuKFyCaw Lab9hIvvFcyRmTUuWeJ3G2O2oEXQFnC7sHIgffNZ9qw1T5s7It0sZM7wJYP4ivEAuH mQuAK9OuMygrMAk3pQqaeHdMqurM9JmJ07WWxIOa3iH7As0229ikVR7StqUwVztn1U 9jUszKkxIgagg== From: Robert Beckett To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter Cc: Robert Beckett , Matthew Auld , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , linux-kernel@vger.kernel.org Subject: [PATCH v4 4/6] drm/i915: ttm backend dont provide mmap_offset for kernel buffers Date: Thu, 21 Apr 2022 18:49:39 +0000 Message-Id: <20220421184941.428639-5-bob.beckett@collabora.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220421184941.428639-1-bob.beckett@collabora.com> References: <20220421184941.428639-1-bob.beckett@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org stolen/kernel buffers should not be mmapable by userland. do not provide callbacks to facilitate this for these buffers. Signed-off-by: Robert Beckett --- drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 32 +++++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c index a878910a563c..b20f81836c54 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c @@ -1092,8 +1092,8 @@ static void i915_ttm_unmap_virtual(struct drm_i915_gem_object *obj) ttm_bo_unmap_virtual(i915_gem_to_ttm(obj)); } -static const struct drm_i915_gem_object_ops i915_gem_ttm_obj_ops = { - .name = "i915_gem_object_ttm", +static const struct drm_i915_gem_object_ops i915_gem_ttm_user_obj_ops = { + .name = "i915_gem_object_ttm_user", .flags = I915_GEM_OBJECT_IS_SHRINKABLE | I915_GEM_OBJECT_SELF_MANAGED_SHRINK_LIST, @@ -1111,6 +1111,21 @@ static const struct drm_i915_gem_object_ops i915_gem_ttm_obj_ops = { .mmap_ops = &vm_ops_ttm, }; +static const struct drm_i915_gem_object_ops i915_gem_ttm_kern_obj_ops = { + .name = "i915_gem_object_ttm_kern", + .flags = I915_GEM_OBJECT_IS_SHRINKABLE | + I915_GEM_OBJECT_SELF_MANAGED_SHRINK_LIST, + + .get_pages = i915_ttm_get_pages, + .put_pages = i915_ttm_put_pages, + .truncate = i915_ttm_truncate, + .shrink = i915_ttm_shrink, + + .adjust_lru = i915_ttm_adjust_lru, + .delayed_free = i915_ttm_delayed_free, + .migrate = i915_ttm_migrate, +}; + void i915_ttm_bo_destroy(struct ttm_buffer_object *bo) { struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo); @@ -1165,10 +1180,19 @@ int __i915_gem_ttm_object_init(struct intel_memory_region *mem, .no_wait_gpu = false, }; enum ttm_bo_type bo_type; + const struct drm_i915_gem_object_ops *ops; int ret; drm_gem_private_object_init(&i915->drm, &obj->base, size); - i915_gem_object_init(obj, &i915_gem_ttm_obj_ops, &lock_class, flags); + + if (flags & I915_BO_ALLOC_USER && intel_region_to_ttm_type(mem) != I915_PL_STOLEN) { + bo_type = ttm_bo_type_device; + ops = &i915_gem_ttm_user_obj_ops; + } else { + bo_type = ttm_bo_type_kernel; + ops = &i915_gem_ttm_kern_obj_ops; + } + i915_gem_object_init(obj, ops, &lock_class, flags); obj->bo_offset = offset; @@ -1178,8 +1202,6 @@ int __i915_gem_ttm_object_init(struct intel_memory_region *mem, INIT_RADIX_TREE(&obj->ttm.get_io_page.radix, GFP_KERNEL | __GFP_NOWARN); mutex_init(&obj->ttm.get_io_page.lock); - bo_type = (obj->flags & I915_BO_ALLOC_USER) ? ttm_bo_type_device : - ttm_bo_type_kernel; obj->base.vma_node.driver_private = i915_gem_to_ttm(obj); -- 2.25.1