Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp740854imi; Fri, 22 Jul 2022 08:26:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sOhHwLXRb231Ge2f9M9PCLzfDXBcx/DApYRqsfu0q0DY+l4oJ82rURrhCrcOCVEOAvw16s X-Received: by 2002:a17:907:2d08:b0:72f:1dff:edf5 with SMTP id gs8-20020a1709072d0800b0072f1dffedf5mr333039ejc.391.1658503587369; Fri, 22 Jul 2022 08:26:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658503587; cv=none; d=google.com; s=arc-20160816; b=yZv7TrjxvZoLJWrlyytEkfak+A06JF0SAzpQIw3voosF/zpScKjYuF0qxpdq6L1vYz Xhf+TFfI0rUhDswnGq0iH6k8KuBV4LKXdFQWrYFhjyy73/ukgrnz7Z5SOUF6XzE9YZ5M 7UjmktojBJnJ/VkV3zswKRL9lr9VqmVz3bowyEHxx6NK1tjy3p5V01URuoPSkyFOKryk ixWSSwJ9CzR5YUj+tpoEwd4wMMu2b9yIVIHkdzf7/iUCQQtKhsP+5maVprv66yDRaadO dP25A3UkzY2xTd8rxi+a1qvVbku9Aq70c6tf8oF1OKnMXjFLDj+dkla+/EGgxtzrJYKV pSHg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=JXgHIyX6pNyp7XfLh/ThjW6jeYahFEZ7o/Gns35reEM=; b=jo+QEJe1yLPqYruzI66r5Wt5XcM4sO2nSCfbgfbYbsfazwRPyFjOWFaSj66FuUjhzj rFXDheAB5E9BmPHv1QtLUcCiWtTtHbv7AZDVSLfZXjQFoGxAdiHMLR+ZUIlOfa8w1eIQ ic4N32rIU3S7j7q2tUVhP/tMBARbNIjCkfrlsW4AT44Z0gV1XXg+Pxb/rbpfkCfNxYM2 9eP8ZecLdW8pS0BpkElmxVT3q6shFU8LVycegMCi3SazgX138hFWfhqH7ke73mBTh/eG 2n8HmxqfWJ4PDlZ14nb08tBtaRZHoNZQpqJvqqedd5oEZQdOwjch8YTDLgpUO8ia6RtT GlRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=A0Xo+vsk; 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 h2-20020a0564020e0200b0043bca751775si4189028edh.363.2022.07.22.08.26.02; Fri, 22 Jul 2022 08:26:27 -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=A0Xo+vsk; 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 S235664AbiGVPMt (ORCPT + 99 others); Fri, 22 Jul 2022 11:12:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235720AbiGVPMi (ORCPT ); Fri, 22 Jul 2022 11:12:38 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D34409E7A7 for ; Fri, 22 Jul 2022 08:12:37 -0700 (PDT) Received: from hermes-devbox.fritz.box (82-71-8-225.dsl.in-addr.zen.co.uk [82.71.8.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bbeckett) by madras.collabora.co.uk (Postfix) with ESMTPSA id 1C81E6601ACC; Fri, 22 Jul 2022 16:12:36 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1658502756; bh=7kxqIhkpFGzA8g1mO3RcDy33zlRVQ9b4n6SfLajQTFE=; h=From:To:Cc:Subject:Date:From; b=A0Xo+vsk5A7BpQmmpevs9QUudkjsBbh+Gs+ldVahhj8C3krro4cuyAhRA+EGu1FQd 5dSBKbg1zLYaGhWcna+yNwCVe/SvMhrMsZk0UGa3wDUfpR5aKR5mhBONvUXK3+9ycQ qvcwIZRCq1gAyDgTelNtWY9518J2Z2aHk57hcvrfgCZBIv932HxJy3UnXA7ez1dlWP qOozJJSHKTMZdWbSYI1Zyh2yujAlEZtbmrKnNALjRX7QgNAO5OB1/C2UtplFW7PWK6 ty92vThvDBl8oGwwhFRS5llMve0kdaYRVGJkwVJLensPn37nVt0LkN9H7MCa2QXCUq VW4GWbFUM7Ebw== From: Robert Beckett To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter Cc: kernel@collabora.com, Robert Beckett , Christoph Hellwig , Thomas Hellstrom , Matthew Auld , Tvrtko Ursulin , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] drm/i915: stop using swiotlb Date: Fri, 22 Jul 2022 16:12:04 +0100 Message-Id: <20220722151204.1534489-1-bob.beckett@collabora.com> X-Mailer: git-send-email 2.25.1 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_NONE,SPF_PASS 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 Calling swiotlb functions directly is nowadays considered harmful. See https://lore.kernel.org/intel-gfx/20220711082614.GA29487@lst.de/ Replace swiotlb_max_segment() calls with dma_max_mapping_size(). In i915_gem_object_get_pages_internal() no longer consider max_segment only if CONFIG_SWIOTLB is enabled. There can be other (iommu related) causes of specific max segment sizes. Cc: Christoph Hellwig Cc: Tvrtko Ursulin Cc: Thomas Hellstrom Cc: Matthew Auld v2: - restore UINT_MAX clamp in i915_sg_segment_size() - drop PAGE_SIZE check as it will always be >= PAGE_SIZE v3: - actually clamp to UINT_MAX in i915_sg_segment_size() Reviewed-by: Christoph Hellwig Reviewed-by: Tvrtko Ursulin Signed-off-by: Robert Beckett --- drivers/gpu/drm/i915/gem/i915_gem_internal.c | 19 ++++--------------- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 4 ++-- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 2 +- drivers/gpu/drm/i915/i915_scatterlist.h | 16 +++------------- 5 files changed, 11 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_internal.c b/drivers/gpu/drm/i915/gem/i915_gem_internal.c index c698f95af15f..24f37658f1bb 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_internal.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_internal.c @@ -6,7 +6,6 @@ #include #include -#include #include "i915_drv.h" #include "i915_gem.h" @@ -38,22 +37,12 @@ static int i915_gem_object_get_pages_internal(struct drm_i915_gem_object *obj) struct scatterlist *sg; unsigned int sg_page_sizes; unsigned int npages; - int max_order; + int max_order = MAX_ORDER; + unsigned int max_segment; gfp_t gfp; - max_order = MAX_ORDER; -#ifdef CONFIG_SWIOTLB - if (is_swiotlb_active(obj->base.dev->dev)) { - unsigned int max_segment; - - max_segment = swiotlb_max_segment(); - if (max_segment) { - max_segment = max_t(unsigned int, max_segment, - PAGE_SIZE) >> PAGE_SHIFT; - max_order = min(max_order, ilog2(max_segment)); - } - } -#endif + max_segment = i915_sg_segment_size(i915->drm.dev) >> PAGE_SHIFT; + max_order = min(max_order, ilog2(max_segment)); gfp = GFP_KERNEL | __GFP_HIGHMEM | __GFP_RECLAIMABLE; if (IS_I965GM(i915) || IS_I965G(i915)) { diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c index 4eed3dd90ba8..34b9c76cd8e6 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c @@ -194,7 +194,7 @@ static int shmem_get_pages(struct drm_i915_gem_object *obj) struct intel_memory_region *mem = obj->mm.region; struct address_space *mapping = obj->base.filp->f_mapping; const unsigned long page_count = obj->base.size / PAGE_SIZE; - unsigned int max_segment = i915_sg_segment_size(); + unsigned int max_segment = i915_sg_segment_size(i915->drm.dev); struct sg_table *st; struct sgt_iter sgt_iter; struct page *page; diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c index 5a5cf332d8a5..7a828c9c0f6d 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c @@ -189,7 +189,7 @@ static int i915_ttm_tt_shmem_populate(struct ttm_device *bdev, struct drm_i915_private *i915 = container_of(bdev, typeof(*i915), bdev); struct intel_memory_region *mr = i915->mm.regions[INTEL_MEMORY_SYSTEM]; struct i915_ttm_tt *i915_tt = container_of(ttm, typeof(*i915_tt), ttm); - const unsigned int max_segment = i915_sg_segment_size(); + const unsigned int max_segment = i915_sg_segment_size(i915->drm.dev); const size_t size = (size_t)ttm->num_pages << PAGE_SHIFT; struct file *filp = i915_tt->filp; struct sgt_iter sgt_iter; @@ -568,7 +568,7 @@ static struct i915_refct_sgt *i915_ttm_tt_get_st(struct ttm_tt *ttm) ret = sg_alloc_table_from_pages_segment(st, ttm->pages, ttm->num_pages, 0, (unsigned long)ttm->num_pages << PAGE_SHIFT, - i915_sg_segment_size(), GFP_KERNEL); + i915_sg_segment_size(i915_tt->dev), GFP_KERNEL); if (ret) { st->sgl = NULL; return ERR_PTR(ret); diff --git a/drivers/gpu/drm/i915/gem/i915_gem_userptr.c b/drivers/gpu/drm/i915/gem/i915_gem_userptr.c index 094f06b4ce33..dfc35905dba2 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_userptr.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_userptr.c @@ -129,7 +129,7 @@ static void i915_gem_object_userptr_drop_ref(struct drm_i915_gem_object *obj) static int i915_gem_userptr_get_pages(struct drm_i915_gem_object *obj) { const unsigned long num_pages = obj->base.size >> PAGE_SHIFT; - unsigned int max_segment = i915_sg_segment_size(); + unsigned int max_segment = i915_sg_segment_size(obj->base.dev->dev); struct sg_table *st; unsigned int sg_page_sizes; struct page **pvec; diff --git a/drivers/gpu/drm/i915/i915_scatterlist.h b/drivers/gpu/drm/i915/i915_scatterlist.h index 9ddb3e743a3e..48a8ce67371a 100644 --- a/drivers/gpu/drm/i915/i915_scatterlist.h +++ b/drivers/gpu/drm/i915/i915_scatterlist.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include "i915_gem.h" @@ -127,19 +127,9 @@ static inline unsigned int i915_sg_dma_sizes(struct scatterlist *sg) return page_sizes; } -static inline unsigned int i915_sg_segment_size(void) +static inline unsigned int i915_sg_segment_size(struct device *dev) { - unsigned int size = swiotlb_max_segment(); - - if (size == 0) - size = UINT_MAX; - - size = rounddown(size, PAGE_SIZE); - /* swiotlb_max_segment_size can return 1 byte when it means one page. */ - if (size < PAGE_SIZE) - size = PAGE_SIZE; - - return size; + return min_t(size_t, UINT_MAX, dma_max_mapping_size(dev)); } bool i915_sg_trim(struct sg_table *orig_st); -- 2.25.1