All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: maarten.lankhorst@linux.intel.com, mripard@kernel.org,
	airlied@gmail.com, daniel@ffwll.ch, lucas.demarchi@intel.com,
	rodrigo.vivi@intel.com, jani.nikula@linux.intel.com,
	ray.huang@amd.com, christian.koenig@amd.com, kraxel@redhat.com,
	airlied@redhat.com, suijingfeng@loongson.cn
Cc: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
	intel-gfx@lists.freedesktop.org,
	Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH 4/6] drm/ttm: Support kmap for single-page mappings in ttm_bo_vmap()
Date: Fri, 14 Jun 2024 15:21:58 +0200	[thread overview]
Message-ID: <20240614133556.11378-5-tzimmermann@suse.de> (raw)
In-Reply-To: <20240614133556.11378-1-tzimmermann@suse.de>

In ttm_bo_vmap(), set up single-page mappings with kmap() in certain
cases. The feature is already present in ttm_bo_kmap().

This functionality is require by DRM's xe driver, which claims that
using kmap() is an optimization over vmap(). [1] Reading the commit
at [2] indicates otherwise. It is not possible to use kmap_local_page()
and kunmap_local_page(), as TTM cannot guarantee the requirements for
ordering these calls. [3]

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://elixir.bootlin.com/linux/v6.9/source/drivers/gpu/drm/xe/xe_bo.c#L1870 # 1
Link: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com/T/#u # 2
Link: https://elixir.bootlin.com/linux/v6.9/source/include/linux/highmem.h#L70 # 3
---
 drivers/gpu/drm/ttm/ttm_bo_util.c | 33 ++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index 31f9772f05dac..c06cfccace39d 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -516,6 +516,8 @@ int ttm_bo_vmap(struct ttm_buffer_object *bo,
 			.no_wait_gpu = false
 		};
 		struct ttm_tt *ttm = bo->ttm;
+		struct ttm_resource_manager *man =
+			ttm_manager_type(bo->bdev, bo->resource->mem_type);
 		unsigned long start_page = offset >> PAGE_SHIFT;
 		unsigned long aligned_size = size + (offset - (start_page << PAGE_SHIFT));
 		unsigned long num_pages = DIV_ROUND_UP(aligned_size, PAGE_SIZE);
@@ -527,15 +529,25 @@ int ttm_bo_vmap(struct ttm_buffer_object *bo,
 		if (ret)
 			return ret;
 
-		/*
-		 * We need to use vmap to get the desired page protection
-		 * or to make the buffer object look contiguous.
-		 */
-		prot = ttm_io_prot(bo, mem, PAGE_KERNEL);
-		vaddr = vmap(ttm->pages + start_page, num_pages, 0, prot);
-		if (!vaddr)
-			return -ENOMEM;
-		alloc_flags = ttm_bo_map_vmap;
+		if (num_pages == 1 && ttm->caching == ttm_cached &&
+		    !(man->use_tt && (ttm->page_flags & TTM_TT_FLAG_DECRYPTED))) {
+			/*
+			 * We're mapping a single page, and the desired
+			 * page protection is consistent with the bo.
+			 */
+			vaddr = kmap(ttm->pages[start_page]);
+			alloc_flags = ttm_bo_map_kmap;
+		} else {
+			/*
+			 * We need to use vmap to get the desired page protection
+			 * or to make the buffer object look contiguous.
+			 */
+			prot = ttm_io_prot(bo, mem, PAGE_KERNEL);
+			vaddr = vmap(ttm->pages + start_page, num_pages, 0, prot);
+			if (!vaddr)
+				return -ENOMEM;
+			alloc_flags = ttm_bo_map_vmap;
+		}
 
 		iosys_map_set_vaddr(map, vaddr);
 		map->alloc_flags = alloc_flags;
@@ -567,6 +579,9 @@ void ttm_bo_vunmap(struct ttm_buffer_object *bo, struct iosys_map *map)
 	case ttm_bo_map_vmap:
 		vunmap(map->vaddr);
 		break;
+	case ttm_bo_map_kmap:
+		kunmap(kmap_to_page(map->vaddr));
+		break;
 	case ttm_bo_map_premapped:
 		break;
 	default:
-- 
2.45.2


  parent reply	other threads:[~2024-06-14 13:36 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-14 13:21 [PATCH 0/6] drm/{ttm,xe}: Improve ttm_bo_vmap() and update xe Thomas Zimmermann
2024-06-14 13:21 ` [PATCH 1/6] iosys-map: Add allocator flags Thomas Zimmermann
2024-06-14 13:21 ` [PATCH 2/6] drm/ttm: Store the bo_kmap_type in struct iosys_map Thomas Zimmermann
2024-06-14 14:31   ` Christian König
2024-06-17 12:32     ` Thomas Zimmermann
2024-06-17 12:56       ` Christian König
2024-06-14 13:21 ` [PATCH 3/6] drm/ttm: Support partial buffer mappings for ttm_bo_vmap() Thomas Zimmermann
2024-06-14 14:33   ` Christian König
2024-06-17 13:00     ` Thomas Zimmermann
2024-06-14 13:21 ` Thomas Zimmermann [this message]
2024-06-14 13:21 ` [PATCH 5/6] drm/xe: Remove vunmap calls object-freeing code Thomas Zimmermann
2024-06-14 13:22 ` [PATCH 6/6] drm/xe: Replace ttm_bo_kmap() with ttm_bo_vmap() Thomas Zimmermann
2024-06-14 13:41 ` ✓ CI.Patch_applied: success for drm/{ttm,xe}: Improve ttm_bo_vmap() and update xe Patchwork
2024-06-14 13:41 ` ✗ CI.checkpatch: warning " Patchwork
2024-06-14 13:42 ` ✓ CI.KUnit: success " Patchwork
2024-06-14 13:54 ` ✓ CI.Build: " Patchwork
2024-06-14 13:56 ` ✗ CI.Hooks: failure " Patchwork
2024-06-14 13:58 ` ✗ CI.checksparse: warning " Patchwork
2024-06-14 14:18 ` ✗ Fi.CI.CHECKPATCH: " Patchwork
2024-06-14 14:18 ` ✗ Fi.CI.SPARSE: " Patchwork
2024-06-14 14:28 ` ✗ CI.BAT: failure " Patchwork
2024-06-14 14:32 ` ✓ Fi.CI.BAT: success " Patchwork
2024-06-16 21:28 ` ✗ Fi.CI.IGT: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240614133556.11378-5-tzimmermann@suse.de \
    --to=tzimmermann@suse.de \
    --cc=airlied@gmail.com \
    --cc=airlied@redhat.com \
    --cc=christian.koenig@amd.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=kraxel@redhat.com \
    --cc=lucas.demarchi@intel.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=ray.huang@amd.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=suijingfeng@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.